From f45a30dec77983d74ab1b574974a0c46485cb83b Mon Sep 17 00:00:00 2001 From: Vince Weaver Date: Fri, 22 Jan 2021 00:50:11 -0500 Subject: [PATCH] tfv: more work on textentry --- games/tfv/tfv_textentry.s | 283 +++++++++++++++++++++++++++++++------- games/tfv/zp.inc | 25 ++-- 2 files changed, 243 insertions(+), 65 deletions(-) diff --git a/games/tfv/tfv_textentry.s b/games/tfv/tfv_textentry.s index 8561d34e..fbc9dc98 100644 --- a/games/tfv/tfv_textentry.s +++ b/games/tfv/tfv_textentry.s @@ -40,6 +40,8 @@ name_loop: ; get pointer to line 2 lda gr_offsets+(2*2) + clc + adc #11 sta OUTL lda gr_offsets+(2*2)+1 clc @@ -47,10 +49,10 @@ name_loop: sta OUTH ldx #0 - ldy #11 + ldy #0 print_name_loop: - cpy NAMEX + cpx NAMEX bne print_name_name print_name_cursor: lda #'+' @@ -72,13 +74,97 @@ print_name_put_char: done_print_name_loop: inx + iny iny - cpy #25 + + cpy #16 bne print_name_loop -.if 0 + ;===================== + ; print char selector + + ldx #0 +print_char_selector_loop: + + txa + asl + asl + clc + adc #10 + tay + + ; set up y pointer + + lda gr_offsets,Y + clc + adc #11 + sta GBASL + lda gr_offsets+1,Y + clc + adc DRAW_PAGE + sta GBASH + + ldy #0 +inner_matrix_loop: + + txa ; want Ycoord*8 + asl + asl + asl + sta TEMPY + + tya + adc TEMPY + + ; adjust to numbers if ycoord>4 + + cpx #4 + bcs textentry_numbers + +textentry_alpha: + clc + adc #$40 +textentry_numbers: + + sta TEMPY ; save char for later + + ; check if Y equal + cpx YY + bne textentry_normal + cpy XX + beq textentry_inverse + +textentry_normal: + ora #$80 ; convert to NORMAL uppercase + sta (GBASL),Y + lda #' '|$80 + jmp textentry_putc + +textentry_inverse: + and #$3f ; convert to INVERSE + sta (GBASL),Y + lda #' ' + +textentry_putc: + inc GBASL + sta (GBASL),Y + + + + iny + cpy #8 + bne inner_matrix_loop + + + inx + + cpx #8 + bne print_char_selector_loop + + +.if 0 for(yy=0;yy<8;yy++) { basic_htab(12); basic_vtab(yy*2+6); @@ -105,31 +191,67 @@ done_print_name_loop: basic_print(" BACK "); .endif + ;================= + ; handle keypress + jsr get_keypress - bne done_enter_name + +check_textentry_up: + cmp #'W' + bne check_textentry_down +textentry_up: + dec YY + jmp done_textentry + +check_textentry_down: + cmp #'S' + bne check_textentry_left +textentry_down: + inc YY + jmp done_textentry + + +check_textentry_left: + cmp #'A' + bne check_textentry_right +textentry_left: + dec XX + lda YY + cmp #8 + bne textentry_left_not_bottom + dec XX + dec XX + dec XX +textentry_left_not_bottom: + jmp done_textentry + + + +check_textentry_right: + cmp #'D' + bne check_textentry_escape +textentry_right: + inc XX + lda YY + cmp #8 + bne textentry_right_not_bottom + inc XX + inc XX + inc XX +textentry_right_not_bottom: + jmp done_textentry + + +check_textentry_escape: + cmp #27 + bne done_textentry_keypress +textentry_escape: + jmp done_enter_name + + +done_textentry_keypress: .if 0 - while(1) { - ch=grsim_input(); - - if (ch==APPLE_UP) { // up - cursor_y--; - } - - else if (ch==APPLE_DOWN) { // down - cursor_y++; - } - - else if (ch==APPLE_LEFT) { // left - if (cursor_y==8) cursor_x-=4; - else cursor_x--; - } - - else if (ch==APPLE_RIGHT) { // right - if (cursor_y==8) cursor_x+=4; - cursor_x++; - } - else if (ch==13) { if (cursor_y==8) { if (cursor_x<4) { @@ -154,35 +276,83 @@ done_print_name_loop: name_x++; } - - if (name_x>7) name_x=7; - - if (cursor_x<0) { - cursor_x=7; - cursor_y--; - } - if (cursor_x>7) { - cursor_x=0; - cursor_y++; - } - - if (cursor_y<0) cursor_y=8; - if (cursor_y>8) cursor_y=0; - - if ((cursor_y==8) && (cursor_x<4)) cursor_x=0; - else if ((cursor_y==8) && (cursor_x>=4)) cursor_x=4; - - - if (ch!=0) break; - - grsim_update(); - - usleep(10000); - } - - if (ch==27) break; + ; if (ch==27) break; .endif + ;======================= + ; keep things in bounds + + ; if (name_x>7) name_x=7; + lda NAMEX + cmp #7 + bcc namex_good + lda #7 + sta NAMEX +namex_good: + +check_xx_bounds: + + ; if (cursor_x<0) { cursor_x=7; cursor_y--; } + ; if (cursor_x>7) { cursor_x=0; cursor_y++; } + +check_xx_too_small: + lda XX + bpl check_xx_too_big + lda #7 + sta XX + dec YY + jmp check_yy_bounds + +check_xx_too_big: + cmp #8 + bcc check_yy_bounds ; blt + lda #0 + sta XX + inc YY + +check_yy_bounds: + + ; if (cursor_y<0) cursor_y=8; + ; if (cursor_y>8) cursor_y=0; + +check_yy_too_small: + lda YY + bpl check_yy_too_big + lda #8 + sta YY + bne done_check_bounds ; bra + +check_yy_too_big: + cmp #8 + beq check_yy_buttons + bcc done_check_bounds + + lda #0 + sta YY + beq done_check_bounds ; bra + + ; if ((cursor_y==8) && (cursor_x<4)) cursor_x=0; + ; else if ((cursor_y==8) && (cursor_x>=4)) cursor_x=4; +check_yy_buttons: + lda XX + cmp #4 + bcc button_make_0 + lda #4 + sta XX + bne done_check_bounds ; bra + +button_make_0: + lda #0 + sta XX + + +done_check_bounds: + + + + +done_textentry: + jsr page_flip @@ -190,9 +360,16 @@ done_print_name_loop: done_enter_name: + ; FIXME: if empty, set to default + rts enter_name_string: .byte 0,0,"PLEASE ENTER A NAME:",0 +default_hero: + .byte "DEATER",0 + +default_heroine: + .byte "FROGGY",0 diff --git a/games/tfv/zp.inc b/games/tfv/zp.inc index ceed458e..21617290 100644 --- a/games/tfv/zp.inc +++ b/games/tfv/zp.inc @@ -123,22 +123,23 @@ HERO_LEVEL = $96 ; hero's level, also high byte of max hp HERO_XP = $97 ; hero's experience points HERO_MONEY = $98 ; hero's money HERO_INVENTORY = $99 ; hero's inventory -HERO_NAME = $9A ; 7 chars -HERO_NAME1 = $9B ; 7 chars -HERO_NAME2 = $9C ; 7 chars -HERO_NAME3 = $9D ; 7 chars -HERO_NAME4 = $9E ; 7 chars -HERO_NAME5 = $9F ; 7 chars -HERO_NAME6 = $A0 ; 7 chars -HERO_STATE = $A1 ; state of hero +HERO_NAME = $9A ; 8 chars +HERO_NAME1 = $9B ; 8 chars +HERO_NAME2 = $9C ; 8 chars +HERO_NAME3 = $9D ; 8 chars +HERO_NAME4 = $9E ; 8 chars +HERO_NAME5 = $9F ; 8 chars +HERO_NAME6 = $A0 ; 8 chars +HERO_NAME7 = $A1 ; 8 chars +HERO_STATE = $A2 ; state of hero HERO_ON_BIRD = $01 HERO_ODD = $02 ; stand/walk position HERO_DIRECTION = $04 ; 0=left, 1=right -HERO_STEPS = $A2 ; number of steps +HERO_STEPS = $A3 ; number of steps -TFV_X = $A3 ; location on screen -TFV_Y = $A4 ; location on screen -MAP_X = $A5 ; which map region we're on +TFV_X = $A4 ; location on screen +TFV_Y = $A5 ; location on screen +MAP_X = $A6 ; which map region we're on