Calculator Community > ASM
Working on Textbox program for asm [Complete]
Xeda112358:
It looks like you are only displaying the first ASCII character of the token, btw. When you use Get_Tok_Strng, it returns how many characters there are in BC (alternatively, you can use C, since B=0 always). If vPutMap preserves HL and C, you can loop through like this:
--- Code: ---puttokloop:
ld a,(hl)
inc hl
bcall(_VPutMap)
dec c
jr nz,puttokloop
--- End code ---
Yeong:
Now I can grab from both Str1 and Ans (that contains list of 4 numbers) correctly!
--- Code: ---#include "ti83plus.inc"
.org $9D93
.db t2ByteTok,tAsmCmp
bcall(_RclAns)
dec a
ret nz ;quit if answer is non-list
inc de
inc de ;oh look size is 2 bytes silly TI
ex de,hl
ld ix,cX ;apparently I do need ix here because my HL DE BCs are used a lot
ld b,4 ;list should have 4 numbers
loop4times:
push bc
rst 20h
push hl
bcall(_ConvOP1)
pop hl
ld (ix),a
inc ix
pop bc
djnz loop4times
bcall(_ClrLCDFull)
ld hl,0
ld (penCol),hl
ld hl,StringData
rst 20h;rMov9ToOP1
rst 10h;rFindSym
ret c;quit if string is not found
ex de,hl
ld c,(hl);grab string size
inc hl
ld b,(hl)
inc hl
loop:
ld a,(hl)
bcall(_IsA2ByteTok);Check if first token is 2 bytes z=two bytes
jr z, _
ld d,h
ld e,l
jr __
_:
ld d,h
ld e,l
inc hl;increase hl for next calc since token was 2-bytes
dec bc;decrease bc since token was 2-bytes
__:
push hl;need these for cpi
push bc;
push de;
ex de,hl
bcall(_Get_Tok_Strng)
ld hl,op3
tokenloop:
ld a,(hl)
inc hl
bcall(_VPutMap)
dec c
jr nz,tokenloop
ld a,1
ld (curRow),a
ld (curCol),a
ld b,4
ld hl,cX
displaynum:
push hl
ld a,(hl)
ld h,0
ld l,a
bcall(_DispHL)
pop hl
inc hl
ld a,(curRow) ;because DispHL is not pretty
inc a
ld (curRow),a
ld a,0
ld (curCol),a
djnz displaynum
pop de
pop bc
pop hl
cpi
jp pe,loop; pe is used to test if BC reached 0.
bcall(_getKey)
ret
StringData:
.db StrngObj,tVarStrng,tStr1,0
cX:
.db 0
cY:
.db 0
width:
.db 0
height:
.db 0
--- End code ---
Yeong:
So I got into some sort of problem.
From above, I added a rectangle drawing for the textbox and a little routine for moving cursor to next row when the program detects the end of the designated pixel limit (stored in mX)
However, this screenshot is the result I get.
I assume the problem lies somewhere in my CheckXPos part, but I can't seem to pinpoint where the problem is.
EDIT: Fixed. Apparently I needed size bytes before the string before I could use SStringLength. Fixed code.
--- Code: ---#include "ti83plus.inc"
.org $9D93
.db t2ByteTok,tAsmCmp
bcall(_RclAns)
dec a
ret nz ;quit if answer is non-list
inc de
inc de ;oh look size is 2 bytes silly TI
ex de,hl
ld ix,cX ;apparently I do need ix here because my HL DE BCs are used a lot
ld b,4 ;list should have 4 numbers
loop4times:
push bc
rst 20h
push hl
bcall(_ConvOP1)
pop hl
ld (ix),a
inc ix
pop bc
djnz loop4times
bcall(_ClrLCDFull)
call Resetrect
ld hl,StringData
rst 20h;rMov9ToOP1
rst 10h;rFindSym
ret c;quit if string is not found
ex de,hl
ld c,(hl);grab string size
inc hl
ld b,(hl)
inc hl
loop:
ld a,(hl)
bcall(_IsA2ByteTok);Check if first token is 2 bytes z=two bytes
jr z, _
ld d,h
ld e,l
jr __
_:
ld d,h
ld e,l
inc hl;increase hl for next calc since token was 2-bytes
dec bc;decrease bc since token was 2-bytes
__:
push hl;need these for cpi
push bc;
ex de,hl
bcall(_Get_Tok_Strng)
ld hl,op3
tokenloop:
call CheckXPos
inc hl
ld a,(hl)
inc hl
bcall(_VPutMap)
dec c
jr nz,tokenloop
pop bc
pop hl
cpi
jp pe,loop; pe is used to test if BC reached 0.
bcall(_getKey)
ret
CheckXPos:
push de
push bc ; I should have hl as pointer for string still
dec hl
ld (hl),1 ; Put size byte. This string should always be 1 byte long.
bcall(_SStringLength) ;This destroys all but HL
ld d,a
ld a,(penCol)
add a,d ; Grab the future penCol position
push af
ld a,(mX)
ld d,a
pop af
inc d
cp d ; call Resetcur if pencol > mX
call nc,Resetcur
pop bc
pop de
ret
Resetcur:
ld a,(cX)
inc a ;if pencol > mX, change the cursor position
inc a ;to next line before writing
ld (penCol),a
ld a,(penRow)
add a,6
ld (penRow),a
ret
Resetrect:
push hl;Long push list yeah but I'll remove some
push de;when I see that I don't need to save them
push bc;later on when I code more
push af;
ld a,(cX)
ld l,a ;start setting rect boundary
ld a,(cY)
ld h,a
ld a,(cX)
inc a
inc a
ld (penCol),a ;set cursor column
dec a
dec a
ld d,a
ld a,(width)
ld b,a
ld a,d
add a,b
dec a
ld e,a
dec a
dec a
ld (mX),a ;set max c-length for x
ld a,(cY)
inc a
ld (penRow),a ;set cursor row
dec a
ld d,a
ld a,(height)
ld b,a
ld a,d
add a,b
dec a
ld d,a
dec a
dec a
ld (mY),a ;set max c-length for y
bcall(_DrawRectBorderClear)
pop af
pop bc
pop de
pop hl
ret
StringData:
.db StrngObj,tVarStrng,tStr1,0
cX:
.db 0
cY:
.db 0
width:
.db 0
height:
.db 0
mX:
.db 0
mY:
.db 0
--- End code ---
Xeda112358:
Here is my take on it (not the whole code):
--- Code: --- ld c,(hl);grab string size
inc hl
ld b,(hl)
inc hl
loop:
ld a,(hl) ;Need to check if it is a two-byte token, later
push af ;Save A for later
push hl
push bc
bcall(_Get_Tok_Strng)
ld hl,op3-1 ;point to the byte *before* the output characters.
tokenloop:
push hl ;save HL
push bc ;and BC
call CheckXPos
pop bc
pop hl
inc hl ;Need to increment first to get to the character since we started one byte behind
ld a,(hl)
bcall(_VPutMap)
dec c
jr nz,tokenloop
pop bc
pop hl
pop af
bcall(_IsA2ByteTok) ;Check if it was a 2 byte token
jr nz,+_
inc hl ;increment hl for next calc since token was 2 bytes
dec bc ;decrement bc since token was 2 bytes
_:
cpi
jp pe,loop ; pe is used to test if BC reached 0.
bcall(_getKey)
ret
CheckXPos:
ld (hl),1 ;Just want a 1-byte string. HL points to an already drawn char, so no need to save it
bcall(_SStringLength) ;Returns length in A and B
ld a,(penCol)
add a,b ; Grab the future penCol position
ld b,a
dec b
dec b
ld a,(mX)
cp b ; call Resetcur if pencol > mX
ret nc
Resetcur:
ld a,(cX)
inc a ;if pencol > mX, change the cursor position
inc a ;to next line before writing
ld (penCol),a
ld a,(penRow)
add a,6
ld (penRow),a
ret
--- End code ---
Yeong:
All right I think it is almost finished.
Now it will auto advance to next line / reset to top line depends on if the text fit the box or not.
Using a degree sign (o) will force a newline and using a radian sign (r) will force a new box.
When the screen is paused due to transitioning to new box, press any key to continue.
--- Code: ---#include "ti83plus.inc"
.org $9D93
.db t2ByteTok,tAsmCmp
bcall(_RclAns)
dec a
ret nz ;quit if answer is non-list
inc de
inc de ;oh look size is 2 bytes silly TI
ex de,hl
ld ix,cX ;apparently I do need ix here because my HL DE BCs are used a lot
ld b,4 ;list should have 4 numbers
loop4times:
push bc
rst 20h
push hl
bcall(_ConvOP1)
pop hl
ld (ix),a
inc ix
pop bc
djnz loop4times
bcall(_ClrLCDFull)
call Resetrect
ld hl,StringData
rst 20h;rMov9ToOP1
rst 10h;rFindSym
ret c;quit if string is not found
ex de,hl
ld c,(hl);grab string size
inc hl
ld b,(hl)
inc hl
loop:
ld a,(hl) ;Need to check if it is a two-byte token, later
push af ;Save A for later
push hl
push bc
bcall(_Get_Tok_Strng)
ld hl,op3-1 ;point to the byte *before* the output characters.
push hl
inc hl
ld a,(hl)
cp 14h ;check if string is degree sign. deg = newline
pop hl
jr nz,notdegree ;skip if not degree sign
call Resetcur
pop bc
pop hl
pop af
jr +_
notdegree:
push hl
inc hl
ld a,(hl)
cp 15h ;check if string is radian sign. rad = resetrect
pop hl
jr nz,tokenloop ;skip if not radian sign
bcall(_getKey)
call Resetrect
pop bc
pop hl
pop af
jr +_
tokenloop:
push hl ;save HL
push bc ;and BC
call CheckXPos
pop bc
pop hl
inc hl ;Need to increment first to get to the character since we started one byte behind
ld a,(hl)
bcall(_VPutMap)
dec c
jr nz,tokenloop
pop bc
pop hl
pop af
bcall(_IsA2ByteTok) ;Check if it was a 2 byte token
jr nz,+_
inc hl ;increment hl for next calc since token was 2 bytes
dec bc ;decrement bc since token was 2 bytes
_:
cpi
jp pe,loop ; pe is used to test if BC reached 0.
bcall(_getKey)
ret
CheckXPos:
ld (hl),1 ; Put size byte. This string should always be 1 byte long.
bcall(_SStringLength) ;This destroys all but HL
ld a,(penCol)
add a,b ; Grab the future penCol position
ld b,a
dec b
dec b
ld a,(mX)
cp b
ret nc
Resetcur:
ld a,(cX)
inc a ;if pencol > mX, change the cursor position
inc a ;to next line before writing
ld (penCol),a
ld a,(penRow)
add a,6
ld (penRow),a
ld b,a ;check the YPos
ld a,(mY)
sub 6
cp b ; test if penRow > mY
ret nc ; skip if penRow <= mY
bcall(_getKey)
call Resetrect
ret
Resetrect:
push hl;Long push list yeah but I'll remove some
push de;when I see that I don't need to save them
push bc;later on when I code more
push af;
ld a,(cX)
ld l,a ;start setting rect boundary
ld a,(cY)
ld h,a
ld a,(cX)
inc a
inc a
ld (penCol),a ;set cursor column
dec a
dec a
ld d,a
ld a,(width)
ld b,a
ld a,d
add a,b
dec a
ld e,a
dec a
dec a
ld (mX),a ;set max c-length for x
ld a,(cY)
inc a
ld (penRow),a ;set cursor row
dec a
ld d,a
ld a,(height)
ld b,a
ld a,d
add a,b
dec a
ld d,a
dec a
dec a
ld (mY),a ;set max c-length for y
bcall(_DrawRectBorderClear)
pop af
pop bc
pop de
pop hl
ret
StringData:
.db StrngObj,tVarStrng,tStr1,0
cX:
.db 0
cY:
.db 0
width:
.db 0
height:
.db 0
mX:
.db 0
mY:
.db 0
--- End code ---
EDIT: Huge thanks to Zeda and Runer. I couldn't have made it this far if it weren't for them.
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version