From 707fc5de7d014f3a7b27d7472031e78639491c1b Mon Sep 17 00:00:00 2001 From: Vince Weaver Date: Sat, 14 Aug 2021 21:10:56 -0400 Subject: [PATCH] peasant: make hgr_text_box routine optimizes things, though only saves 100 bytes or so --- games/peasant/Makefile | 2 +- games/peasant/hgr_text_box.s | 88 +++++++++++++++++ games/peasant/intro.s | 1 + games/peasant/intro_cottage.s | 176 +++++++++------------------------- games/peasant/intro_knight.s | 49 ++++------ games/peasant/intro_lake_e.s | 39 ++------ games/peasant/intro_lake_w.s | 38 +++----- games/peasant/intro_river.s | 47 +++------ games/peasant/zp.inc | 1 + 9 files changed, 184 insertions(+), 257 deletions(-) create mode 100644 games/peasant/hgr_text_box.s diff --git a/games/peasant/Makefile b/games/peasant/Makefile index f4ccad71..d6a18acd 100644 --- a/games/peasant/Makefile +++ b/games/peasant/Makefile @@ -71,7 +71,7 @@ INTRO: intro.o intro.o: intro.s graphics/graphics.inc sprites/peasant_sprite.inc \ draw_box.s hgr_rectangle.s hgr_font.s hgr_input.s \ hgr_7x30_sprite.s hgr_1x5_sprite.s hgr_save_restore.s \ - wait_a_bit.s draw_peasant.s \ + wait_a_bit.s draw_peasant.s hgr_text_box.s \ title.s directions.s \ intro_cottage.s intro_lake_w.s intro_lake_e.s \ intro_river.s intro_knight.s diff --git a/games/peasant/hgr_text_box.s b/games/peasant/hgr_text_box.s new file mode 100644 index 00000000..cd5f48cc --- /dev/null +++ b/games/peasant/hgr_text_box.s @@ -0,0 +1,88 @@ + ;=========================== + ; hgr text box + ;=========================== + ; point OUTL:OUTH at it + ; x1h,x1l,y1 x2h,x2l,y2 + ; then X,Y of text + ; CR moves to next line + ; 0 ends + +hgr_text_box: + ldy #0 + + ;==================== + ; draw text box + + lda (OUTL),Y + sta BOX_X1H + iny + lda (OUTL),Y + sta BOX_X1L + iny + lda (OUTL),Y + sta BOX_Y1 + iny + + lda (OUTL),Y + sta BOX_X2H + iny + lda (OUTL),Y + sta BOX_X2L + iny + lda (OUTL),Y + sta BOX_Y2 + + jsr draw_box + + clc + lda OUTL + adc #6 + sta OUTL + lda OUTH + adc #0 + sta OUTH + +; +; +; + + ldy #0 + lda (OUTL),Y + sta CURSOR_X + sta SAVED_X + + jsr inc_outl + lda (OUTL),Y + sta CURSOR_Y + jsr inc_outl +disp_put_string_loop: + ldy #0 + lda (OUTL),Y + beq disp_put_string_done + cmp #13 + beq disp_end_of_line + + jsr hgr_put_char_cursor + + inc CURSOR_X + jsr inc_outl + jmp disp_put_string_loop + +disp_end_of_line: + clc + lda CURSOR_Y + adc #8 + sta CURSOR_Y + + lda SAVED_X + sta CURSOR_X + + jsr inc_outl + + jmp disp_put_string_loop + +disp_put_string_done: + + rts + + diff --git a/games/peasant/intro.s b/games/peasant/intro.s index dd166cc8..68ebc8a3 100644 --- a/games/peasant/intro.s +++ b/games/peasant/intro.s @@ -94,6 +94,7 @@ peasant_quest: .include "hgr_save_restore.s" .include "hgr_input.s" .include "hgr_tables.s" +.include "hgr_text_box.s" .include "wait_a_bit.s" diff --git a/games/peasant/intro_cottage.s b/games/peasant/intro_cottage.s index 294439be..aad32285 100644 --- a/games/peasant/intro_cottage.s +++ b/games/peasant/intro_cottage.s @@ -1,4 +1,5 @@ ; THATCHED ROOF COTTAGES +; More specifically, the Dashing Residence cottage: @@ -65,21 +66,42 @@ cottage_walk_loop: check_cottage_action1: cmp #0 bne check_cottage_action2 - jsr display_cottage_text1 - jmp done_cottage_action + + ; display cottage text 1 + + lda #cottage_text1 + + jmp finish_cottage_action check_cottage_action2: cmp #1 bne check_cottage_action3 jsr hgr_restore - jsr display_cottage_text2 - jmp done_cottage_action + + ; display cottage text 2 + + lda #cottage_text2 + + jmp finish_cottage_action check_cottage_action3: cmp #13 bne done_cottage_action jsr hgr_restore - jsr display_cottage_text3 + + ; display cottage text 3 + + lda #cottage_text3 + +finish_cottage_action: + sta OUTH + jsr hgr_text_box done_cottage_action: @@ -131,150 +153,44 @@ done_cottage: rts - ;============================ - ; display cottage text 1 - ;============================ -display_cottage_text1: - - ;==================== - ; draw text box - - lda #0 - sta BOX_X1H - lda #53 - sta BOX_X1L - lda #24 - sta BOX_Y1 - - lda #0 - sta BOX_X2H - lda #253 - sta BOX_X2L - lda #82 - sta BOX_Y2 - - jsr draw_box - - lda #cottage_text1 - sta OUTH - - jsr hgr_put_string - jsr hgr_put_string - jsr hgr_put_string - jsr hgr_put_string - - rts - - - ;============================ - ; display cottage text 2 - ;============================ -display_cottage_text2: - - ;==================== - ; draw text box - - lda #0 - sta BOX_X1H - lda #40 - sta BOX_X1L - lda #15 - sta BOX_Y1 - - lda #0 - sta BOX_X2H - lda #255 - sta BOX_X2L - lda #96 - sta BOX_Y2 - - jsr draw_box - - lda #cottage_text2 - sta OUTH - - jsr hgr_put_string - jsr hgr_put_string - jsr hgr_put_string - jsr hgr_put_string - jsr hgr_put_string - jsr hgr_put_string - jsr hgr_put_string - - rts - - ;============================ - ; display cottage text 3 - ;============================ -display_cottage_text3: - - ;==================== - ; draw text box - - lda #0 - sta BOX_X1H - lda #30 - sta BOX_X1L - lda #20 - sta BOX_Y1 - - lda #0 - sta BOX_X2H - lda #253 - sta BOX_X2L - lda #86 - sta BOX_Y2 - - jsr draw_box - lda #cottage_text3 - sta OUTH - jsr hgr_put_string - jsr hgr_put_string - jsr hgr_put_string - jsr hgr_put_string - jsr hgr_put_string - rts peasant_text: .byte 25,2,"Peasant's Quest",0 cottage_text1: - .byte 9,35,"YOU are Rather Dashing, a",0 - .byte 9,44,"humble peasant living in",0 - .byte 9,53,"the peasant kingdom of",0 - .byte 9,62,"Peasantry.",0 + .byte 0,53,24, 0,253,82 + .byte 9,35,"YOU are Rather Dashing, a",13 + .byte "humble peasant living in",13 + .byte "the peasant kingdom of",13 + .byte "Peasantry.",0 ; wait a few seconds cottage_text2: - .byte 8,25,"You return home from a",0 - .byte 8,33,"vacation on Scalding Lake",0 - .byte 8,41,"only to find that TROGDOR",0 - .byte 8,49,"THE BURNINATOR has",0 - .byte 8,57,"burninated your thatched",0 - .byte 8,65,"roof cottage along with all",0 - .byte 8,73,"your goods and services.",0 + .byte 0,40,15, 0,255,96 + .byte 8,25,"You return home from a",13 + .byte "vacation on Scalding Lake",13 + .byte "only to find that TROGDOR",13 + .byte "THE BURNINATOR has",13 + .byte "burninated your thatched",13 + .byte "roof cottage along with all",13 + .byte "your goods and services.",0 ; wait a few seconds, then start walking toward cottage cottage_text3: - .byte 7,33,"With nothing left to lose,",0 - .byte 7,41,"you swear to get revenge on",0 - .byte 7,49,"the Wingaling Dragon in the",0 - .byte 7,57,"name of burninated peasants",0 - .byte 7,65,"everywhere.",0 + .byte 0,30,20, 0,253,86 + .byte 7,33,"With nothing left to lose,",13 + .byte "you swear to get revenge on",13 + .byte "the Wingaling Dragon in the",13 + .byte "name of burninated peasants",13 + .byte "everywhere.",0 ; Walk to edge of screen diff --git a/games/peasant/intro_knight.s b/games/peasant/intro_knight.s index 5f2897fc..df7c7073 100644 --- a/games/peasant/intro_knight.s +++ b/games/peasant/intro_knight.s @@ -62,7 +62,14 @@ knight_walk_loop: check_knight_action1: cmp #0 bne check_knight_action2 - jsr display_river_text1 + + lda #river_message1 + sta OUTH + + jsr hgr_text_box + jmp done_knight_action check_knight_action2: @@ -74,7 +81,13 @@ check_knight_action2: check_knight_action3: cmp #17 bne done_knight_action - jsr display_knight_text1 + + lda #knight_message1 + sta OUTH + + jsr hgr_text_box done_knight_action: @@ -186,40 +199,10 @@ done_knight: ; stops as approach knight knight_message1: + .byte 0,35,34, 0,253,72 .byte 7,49,"OK go for it.",0 - ;============================ - ; display lake_e text 1 - ;============================ -display_knight_text1: - - ;==================== - ; draw text box - - lda #0 - sta BOX_X1H - lda #35 - sta BOX_X1L - lda #34 - sta BOX_Y1 - - lda #0 - sta BOX_X2H - lda #253 - sta BOX_X2L - lda #72 - sta BOX_Y2 - - jsr draw_box - - lda #knight_message1 - sta OUTH - jsr hgr_put_string - - rts knight_path: .byte 0,107 diff --git a/games/peasant/intro_lake_e.s b/games/peasant/intro_lake_e.s index c3bdab09..6d25e7e8 100644 --- a/games/peasant/intro_lake_e.s +++ b/games/peasant/intro_lake_e.s @@ -59,7 +59,13 @@ lake_e_walk_loop: check_lake_e_action1: cmp #10 bne check_lake_e_action2 - jsr display_lake_e_text1 + + lda #lake_e_message1 + sta OUTH + jsr hgr_text_box + jmp done_lake_e_action check_lake_e_action2: @@ -113,42 +119,13 @@ done_lake_e: ; walk sideways, near corner lake_e_message1: + .byte 0,35,34, 0,253,72 .byte 7,49,"That's a nice looking lake.",0 ; nearly hit head on sign, it goes away, walk off screen - ;============================ - ; display lake_e text 1 - ;============================ -display_lake_e_text1: - ;==================== - ; draw text box - - lda #0 - sta BOX_X1H - lda #35 - sta BOX_X1L - lda #34 - sta BOX_Y1 - - lda #0 - sta BOX_X2H - lda #253 - sta BOX_X2L - lda #72 - sta BOX_Y2 - - jsr draw_box - - lda #lake_e_message1 - sta OUTH - jsr hgr_put_string - - rts lake_e_path: .byte 7,151 diff --git a/games/peasant/intro_lake_w.s b/games/peasant/intro_lake_w.s index 6d73fedf..3fdb232f 100644 --- a/games/peasant/intro_lake_w.s +++ b/games/peasant/intro_lake_w.s @@ -60,7 +60,13 @@ lake_w_walk_loop: check_lake_w_action1: cmp #0 bne check_lake_w_action2 - jsr display_cottage_text3 + + ; re-display cottage text 3 + lda #cottage_text3 + sta OUTH + jsr hgr_text_box jmp done_lake_w_action check_lake_w_action2: @@ -116,9 +122,10 @@ done_lake_w: ; walk halfway across the screen lake_w_message1: - .byte 8,41,"You head east toward the",0 - .byte 8,49,"mountain atop which",0 - .byte 8,57,"TROGDOR lives.",0 + .byte 0,43,24, 0,253,82 + .byte 8,41,"You head east toward the",13 + .byte "mountain atop which",13 + .byte "TROGDOR lives.",0 ; walk to edge @@ -128,33 +135,12 @@ lake_w_message1: ;============================ display_lake_w_text1: - ;==================== - ; draw text box - - lda #0 - sta BOX_X1H - lda #43 - sta BOX_X1L - lda #24 - sta BOX_Y1 - - lda #0 - sta BOX_X2H - lda #253 - sta BOX_X2L - lda #82 - sta BOX_Y2 - - jsr draw_box - lda #lake_w_message1 sta OUTH - jsr hgr_put_string - jsr hgr_put_string - jsr hgr_put_string + jsr hgr_text_box rts diff --git a/games/peasant/intro_river.s b/games/peasant/intro_river.s index fa61f1d1..b59847b5 100644 --- a/games/peasant/intro_river.s +++ b/games/peasant/intro_river.s @@ -62,7 +62,14 @@ river_walk_loop: check_river_action1: cmp #10 bne check_river_action2 - jsr display_river_text1 + + lda #river_message1 + sta OUTH + + jsr hgr_text_box + jmp done_river_action check_river_action2: @@ -117,45 +124,13 @@ done_river: ; walk up a bit river_message1: - .byte 7,49,"You can start playing in a",0 - .byte 7,57,"second here.",0 + .byte 0,35,34, 0,253,82 + .byte 7,49,"You can start playing in a",13 + .byte "second here.",0 ; walks behind tree - ;============================ - ; display river text 1 - ;============================ -display_river_text1: - - ;==================== - ; draw text box - - lda #0 - sta BOX_X1H - lda #35 - sta BOX_X1L - lda #34 - sta BOX_Y1 - - lda #0 - sta BOX_X2H - lda #253 - sta BOX_X2L - lda #82 - sta BOX_Y2 - - jsr draw_box - - lda #river_message1 - sta OUTH - - jsr hgr_put_string - jsr hgr_put_string - - rts river_path: .byte 32,157 diff --git a/games/peasant/zp.inc b/games/peasant/zp.inc index 130a4aec..64ec5ffe 100644 --- a/games/peasant/zp.inc +++ b/games/peasant/zp.inc @@ -25,6 +25,7 @@ FRAME = $65 ALTFIRE = $66 ALTL = $67 ALTH = $68 +SAVED_X = $69 ; pt3 player registers AY_REGISTERS = $70