Skip to content

Commit

Permalink
Don't track string length in GetTokenInput, reduce frame pointer save…
Browse files Browse the repository at this point in the history
…s/restores
  • Loading branch information
calc84maniac committed Jan 30, 2024
1 parent 65d7def commit 3236154
Showing 1 changed file with 21 additions and 34 deletions.
55 changes: 21 additions & 34 deletions src/ce/gettokeninput.src
Original file line number Diff line number Diff line change
Expand Up @@ -29,32 +29,29 @@ _ClrTxtShd := $20818
public _os_GetTokenInput
_os_GetTokenInput:
push ix
ld ix,0
add ix,sp
ld iy,flags
ld l,(iy + $0d)
ld h,(iy + $4c)
push hl ; save text flags
set 1,(iy + $0d) ; use text buffer
res 5,(iy + $4c) ; use text buffer
call _ClrTxtShd
ld ix,0
add ix,sp
ld hl,(ix+3+6) ; hl -> input string prompt
ld hl,(ix+6) ; hl -> input string prompt
add hl,de
xor a,a
sbc hl,de
call nz,_PutS
ld hl,(curRow)
.start:
push hl ; save initial row/column
or a,a
sbc hl,hl
push hl ; save string length
ld hl,(ix+3+12) ; buffer size
push ix
ld hl,(ix+12) ; buffer size
push hl ; save remaining size
ld hl,(ix+3+9)
ld hl,(ix+9)
push hl ; save buf pointer
.loop:
push ix
call _CursorOn
.getkey:
call _GetKey
Expand All @@ -64,7 +61,6 @@ _os_GetTokenInput:
call _CursorOn
pop af
jr c,.getkey
pop ix
cp a,kQuit
jr z,.done_trampoline
dec a ; kRight=1
Expand All @@ -84,9 +80,7 @@ _os_GetTokenInput:
ld (keyExtend),a
ld a,$FE
.conv_key:
push ix
call _ConvKeyToTok
pop ix
pop hl ; restore buf pointer
ex (sp),hl
ld bc,$80
Expand All @@ -101,25 +95,13 @@ _os_GetTokenInput:
ld (hl),e
inc hl
push hl ; save buf pointer
push ix
call _GetTokString
pop ix
ld b,(hl) ; token string length
ld de,(ix-6)
.draw_string:
inc de ; increment string length
inc hl
ld a,(hl)
call _PutC
djnz .draw_string
ld (ix-6),de
call _PutPS
jr .loop
.full:
push hl ; save buf pointer
.full_loop:
push ix
call _GetKey
pop ix
cp a,kEnter
.done_trampoline:
jr z,.done
Expand All @@ -128,28 +110,33 @@ _os_GetTokenInput:
.clear:
pop hl ; buf pointer
pop hl ; remaining size
pop hl ; string length
inc hl
pop ix
pop de ; initial row/column
ld (curRow),de
ld hl,curRow
ld bc,(hl)
ld (hl),de
.clear_loop:
push hl
ld hl,(hl)
ld a,' '
call _PutC
add hl,de
scf
sbc hl,de ; decrement and compare to zero
or a,a
sbc hl,bc ; check the row/column before the print
pop hl
jr nz,.clear_loop
ld (hl),de
ex de,hl
ld (curRow),hl
jp .start
.done:
call _ClrTxtShd
call _CursorOff
pop hl ; restore buf pointer
ld de,(ix+3+9)
pop de ; remaining size
pop ix
pop de ; initial row/column
ld de,(ix+9)
or a,a
sbc hl,de
ld sp,ix
pop de ; restore text flags
ld (iy + $0d),e
ld (iy + $4c),d
Expand Down

0 comments on commit 3236154

Please sign in to comment.