all repos — taro @ 09ec048f5316d6eccf301eb83210e0e2d756179b

mblaze frontend in uxn + crystal

taro-ls: delete and insert characters properly in the middle of the string
Iris Lightshard nilix@nilfm.cc
PGP Signature
-----BEGIN PGP SIGNATURE-----

iQIzBAABCAAdFiEEkFh6dA+k/6CXFXU4O3+8IhROY5gFAmQamqoACgkQO3+8IhRO
Y5jeEA//c8kwWuh+ZyfyTufIydazfjdPl71govOOXSwOQvNvyzQz4hxBEphVyVF5
hjmE5+U7pNRCGoZLvT/qoZbvsfl9fxM7rFgQUZV/iN5dJeqvwCGRqYLDX/V/awIe
KPQr5VNhn3JFQEmQjiVRqIkwW3ixJg8mdnltDtOP0/FCS4ytiDvSxir9XsaauERD
KfryBI/UlwxJXBq24h6qpPgoKvLGykszvM0oLn7XLZ9cpCYJo9PnNEGZmND7PteE
JfCT23t/2JDbdOJ1LYSH+OhosxLyrj2RvjtQjzt3TVHM5DqqQTimg1wLUohJfpFo
zgaLLgQ42J3l3k4eaunUqUjFlREVDbN3g7bCAhoILZ3tKgTi/bUaumzxDpr60wr/
tKVO8IsoXEoJVZzFJSsMmCmV08QjvmzZ35ivNggY2D7Z8eshTjNsAxhbO13SoEch
E7UxJwPi8hb/lGZsOGUkGNVhUaMKhSts7ipJFZcc9ybwOSMt3/goll3uStsI9sHZ
ll9iywf7bKqZWU2Ko4uvTglVrYcoAiZs3wyZhP5kRXVWfs4eUelrphWcyEDj84CR
reqON/rYCAaFnaEcg5/hfwmmsUPq4hQRxVSoKypxaAqyCqAE/+aFxg1usjoNb6j/
U2bl8L/LJev8/F9c2yeulffutQcfPO/H5q1vi6gYlWq1COngwS4=
=fuC3
-----END PGP SIGNATURE-----
commit

09ec048f5316d6eccf301eb83210e0e2d756179b

parent

09b089fe751e58a40e2f8fb401a5023d681a322c

1 files changed, 52 insertions(+), 9 deletions(-)

jump to
M taro-ls.taltaro-ls.tal

@@ -218,11 +218,11 @@ ( -== input ==- )

@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 @@ DUP #08 NEQ ,&no_delete JCN

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

@@ -259,6 +255,53 @@ POP

&done #01 .refresh/textbox STZ +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 -- )