Skip to content

Commit

Permalink
Implement size optimizations in GetTokenInput
Browse files Browse the repository at this point in the history
  • Loading branch information
calc84maniac authored Jan 30, 2024
1 parent a81e807 commit e909dfd
Showing 1 changed file with 54 additions and 100 deletions.
154 changes: 54 additions & 100 deletions src/ce/gettokeninput.src
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ kQuit := $40
kIns := $0B
curLock := 4
flags := $D00080
keyExtend := $D0058E
curRow := $D00595 ; also includes curCol
curUnder := $D00599
_PutS := $207C0
Expand All @@ -27,9 +28,6 @@ _ClrTxtShd := $20818
section .text
public _os_GetTokenInput
_os_GetTokenInput:
push ix
ld ix,0
add ix,sp
push ix
ld iy,flags
ld a,(iy + $0d)
Expand All @@ -39,32 +37,24 @@ _os_GetTokenInput:
set 1,(iy + $0d) ; use text buffer
res 5,(iy + $4c) ; use text buffer
call _ClrTxtShd
pop ix
ld ix,0
add ix,sp
ld hl,(ix+6) ; hl -> input string prompt
add hl,de
xor a,a
sbc hl,de
ld iy,flags
call nz,_PutS
ld hl,(curRow)
ld (.smc.curRow),hl
ld hl,(ix+12)
add hl,de
xor a,a
sbc hl,de
jr nz,.not_empty
pop ix
ret
.not_empty:
ld (ix+12),hl
ld (ix+6),hl ; save initial size
.start:
ld hl,(ix+6) ; restore initial size
ld (ix+12),hl
push hl ; save initial row/column
or a,a
sbc hl,hl
ld (.smc.tok_len),hl
ld (.smc.str_len),hl
push hl ; save string length
ld hl,(ix+12) ; buffer size
push hl ; save remaining size
ld hl,(ix+9)
push hl ; save buf pointer
.loop:
ld iy,flags
push ix
Expand All @@ -79,122 +69,83 @@ _os_GetTokenInput:
jr c,.getkey
pop ix
cp a,kQuit
jp z,.done
cp a,kLeft
jr z,.loop
cp a,kDown
jr z,.loop
cp a,kRight
jr z,.loop
cp a,kUp
jr z,.loop
cp a,kClear
jp z,.clear
cp a,kEnter
jp z,.done
jr z,.done_trampoline
dec a ; kRight=1
cp a,kEnter-kRight ; kEnter=kDown+1
jr c,.loop
jr z,.done_trampoline
inc a
cp a,kIns
jr z,.loop
ld de,(ix+9)
ld hl,(.smc.tok_len)
add hl,de
push ix
push hl ; save buf pointer
cp a,kClear
jr z,.clear
cp a,$F3 ; for lists? idk something is wrong with _PullDownChk
jr z,.sub_key
cp a,$F4
jr z,.sub_key
cp a,$F5
jr z,.sub_key
cp a,$F6
jr z,.sub_key
cp a,$F7
jr z,.sub_key
cp a,$F8
jr z,.sub_key
cp a,$F9
jr z,.sub_key
cp a,$FA
jr z,.sub_key
cp a,$FB
jr z,.sub_key
jr .conv_key
.sub_key:
jr c,.conv_key
cp a,$FB+1
jr nc,.conv_key
sub a,$7C
ld ($0D0058E),a
ld (keyExtend),a
ld a,$FE
.conv_key:
push ix
call _ConvKeyToTok
pop hl ; restore buf pointer
pop ix
ld (hl),e
push hl
ld hl,(ix+12)
pop hl ; restore buf pointer
ex (sp),hl
ld bc,1
or a,a
sbc hl,bc
ld (ix+12),hl
pop hl
jr z,.full
ld a,d
or a,a ; check if 2-byte token
xor a,a
cp a,d ; check if 2-byte token
sbc hl,bc ; subtract 1 or 2 from remaining size
ex (sp),hl
jr c,.full
or a,d ; check if 2-byte token
jr z,.one_byte_token
ld (hl),d
inc hl
ld (hl),e
ld hl,(ix+12)
ld bc,1
or a,a
sbc hl,bc
ld (ix+12),hl
jr z,.full
ld hl,(.smc.tok_len)
inc hl
ld (.smc.tok_len),hl
.one_byte_token:
ld hl,(.smc.tok_len)
ld (hl),e
inc hl
ld (.smc.tok_len),hl
push hl ; save buf pointer
push ix
call _GetTokString
pop ix
ld b,(hl) ; token string length
inc hl
.draw_string:
push hl
ld hl,(.smc.str_len)
inc hl
ld (.smc.str_len),hl
pop hl
ld de,(ix-6)
inc de ; increment string length
ld (ix-6),de
ld a,(hl)
inc hl
call _PutC
djnz .draw_string
jp .loop
jr .loop
.full:
push hl ; save buf pointer
.full_loop:
push ix
call _GetKey
pop ix
cp a,kEnter
.done_trampoline:
jr z,.done
cp a,kClear
jr nz,.full
jr nz,.full_loop
.clear:
.smc.curRow := $+1
ld hl,0
ld (curRow),hl
.smc.str_len := $+1
ld hl,0
pop hl ; buf pointer
pop hl ; remaining size
pop hl ; string length
inc hl
pop de ; initial row/column
ld (curRow),de
.clear_loop:
push hl
ld a,' '
call _PutC
pop hl
ld bc,1
or a,a
sbc hl,bc
add hl,de
scf
sbc hl,de ; decrement and compare to zero
jr nz,.clear_loop
ld hl,(.smc.curRow)
ex de,hl
ld (curRow),hl
jp .start
.done:
Expand All @@ -206,7 +157,10 @@ _os_GetTokenInput:
.smc.text_flag_1 := $+1
ld a,0
ld (iy + $4c),a
.smc.tok_len := $+1
ld hl,0
pop hl ; restore buf pointer
ld de,(ix+9)
or a,a
sbc hl,de
ld sp,ix
pop ix
ret

0 comments on commit e909dfd

Please sign in to comment.