diff --git a/taro-ls.tal b/taro-ls.tal index 2393d2c..2b4aa4e 100644 --- a/taro-ls.tal +++ b/taro-ls.tal @@ -218,11 +218,11 @@ JMP2r @on_key ( -> ) .textbox/mode LDZ #00 EQU ,&no_text_entry JCN - insert_char_textbox + handle_textbox &no_text_entry BRK -@insert_char_textbox ( -> ) +@handle_textbox ( -> ) .Controller/key DEI DUP #00 EQU ,&no_key JCN DUP check_enter_or_esc @@ -230,17 +230,13 @@ BRK POP ( handle backspace ) .textbox/cursor LDZ #00 EQU ,&also_done JCN - .textbox/cursor LDZ #01 SUB .textbox/cursor STZ - .textbox/len LDZ #01 SUB .textbox/len STZ - #00 ;textbox_text .textbox/cursor LDZ #00 SWP ADD2 STA + delete_char ,&done JMP &no_delete + DUP #20 LTH OVR #7e GTH ORA ,&no_btn JCN ( TODO: handle inserting character when bone is in middle of string ) ( or when string is already max length ) - ;textbox_text .textbox/cursor LDZ #00 SWP ADD2 STA - .textbox/len LDZk INC SWP STZ - #00 ;textbox_text .textbox/len LDZ #00 SWP ADD2 STA - .textbox/cursor LDZk INC SWP STZ + insert_char &also_done ,&done JMP &no_key @@ -261,6 +257,53 @@ BRK JMP2r +@delete_char ( -- ) + + ( if cursor = len, then just decrement both and add null byte ) + .textbox/cursor LDZ .textbox/len LDZ NEQ ,&its_complicated JCN + .textbox/cursor LDZ #01 SUB .textbox/cursor STZ + .textbox/len LDZ #01 SUB .textbox/len STZ + #00 ;textbox_text .textbox/cursor LDZ #00 SWP ADD2 STA + JMP2r + &its_complicated + ( otherwise loop through characters from cursor to len, + and copy them to their location - 1 ) + .textbox/len LDZ #01 ADD .textbox/cursor LDZ &loop EQUk ,&end JCN + DUP #00 SWP ;textbox_text ADD2 LDA STH + DUP #01 SUB STHr SWP #00 SWP ;textbox_text ADD2 STA + INC + ,&loop JMP &end POP2 + ( and then decrement counters and set the null byte ) + .textbox/cursor LDZ #01 SUB .textbox/cursor STZ + .textbox/len LDZ #01 SUB .textbox/len STZ + #00 ;textbox_text .textbox/len LDZ #00 SWP ADD2 STA +JMP2r + +@insert_char ( key -- ) + STH + ( if cursor = len, then add the charater, increment both counters, and add a null byte ) + .textbox/cursor LDZ .textbox/len LDZ NEQ ,&its_complicated JCN + STHr + ;textbox_text .textbox/cursor LDZ #00 SWP ADD2 STA + .textbox/len LDZk INC SWP STZ + #00 ;textbox_text .textbox/len LDZ #00 SWP ADD2 STA + .textbox/cursor LDZk INC SWP STZ + JMP2r + &its_complicated + ( otherwise loop through characters from len to cursor, + and copy them to their location + 1 ) + .textbox/cursor LDZ .textbox/len LDZ #01 ADD &loop EQUk ,&end JCN + DUP #00 SWP ;textbox_text ADD2 LDA STH + DUP INC STHr SWP #00 SWP ;textbox_text ADD2 STA + #01 SUB + ,&loop JMP &end POP2 + STHr + ( and put the character at the cursor locaton, then increment the counts ) + ;textbox_text .textbox/cursor LDZ #00 SWP ADD2 STA + .textbox/len LDZk INC SWP STZ + .textbox/cursor LDZk INC SWP STZ +JMP2r + @check_enter_or_esc ( key -- ) POP ( check mode and either cancel or send appropriate message )