Calculator Community > ASM

Working on Textbox program for asm [Complete]

(1/3) > >>

Yeong:
EDIT: Finished product here
https://www.omnimaga.org/asm-language/working-on-textbox-program-for-asm/msg406844/#msg406844

So, I decided that the best way to learn how to z80 is by coding small things.

Basically, I want to make a program that takes 4 variables from the list {Xinitial, Yinitial, Maximum rows of text, Maximum columns of text} and Str1, and draw a textbox out of it.
I wrote a pseudocode(?) for it so far.

Any comments or feedback is appreciated because I have no idea what I'm doing.


--- Code: ---Get String from OS
Get X,Y coordinates
Get # of rows and cols
Store them to Coor

;Calc 2+maxX+4. Character is 4 pixels wide.
ld a,(tCol)
ld b,3
__:
add a,a
djnz __
add a,6
ld (mX),a
;now 2+maxY+6. Character is 6 pixels long.
ld a,(tRow)
ld b,5
___:
add a,a
djnz ___
add a,8
ld (mY),a

call DrawRect

;string starts at X+2,Y+2
call ResetLine
Put string length in bc

ld ix,String
;until it reads through all the text
Loop:
push bc ;save length
ld a,(mX)
cp (penCol)
call z,NextLine
ld a,(mY)
cp (penRow)
call z,ResetLine
ld a,(ix) ;now start checking characters
cp 'o' ;the degree sign - force cursor to next line
jr nz,Jump1
call NextLine
Jump1:
cp 'e^';e^ will make it wait for a keypress
jr nz,Jump2
call WaitForKey
Jump2:
ld (HChara),a
ld hl,HChara
bcall(_VPutS)
inc ix
call Delay ;force delay between texts
pop bc
dec bc
jr c, Loop ;if c is set, that means the loop went through all the text I think?

ret

DrawRect:
;Draw Rectangle at (X,Y,X+2+4*col,Y+2+6*row)
ld d,a
push de
;Something that clears inside the rect
ld l,(cX)
ld h,(cY)
ld a,(tCol)
sub 4
ld e,a
ld a,(tRow)
sub 6
ld d,a
bcall(_DrawRectBorder)
pop de
ld a,d
ret

NextLine:
ld d,a
ld a,(cX)
add a,2
ld (penCol),a
ld a,(penRow)
add a,6
ld (penRow),a
ld a,d
ret

ResetLine:
jr DrawRect
ld d,a
ld a,(cX)
inc a
inc a
ld (penCol),a
ld a,(cY)
inc a
inc a
ld (penRow),a
ld a,d
ret

Pause:
ld b,(Delay)
_:
nop
djnz _
ret

WaitForKey:
ld d,a
bcall(_getKey)
ld a,d
ret

Delay:
.db 40
cX:
.db x
cY:
.db y
tCol:
.db col
tRow:
.db row
mX:
.db 2+maxX+4
mY:
.db 2+maxY+6

HChara:
.db 0
--- End code ---

EDIT: routine calls changed from jr to call.
Renamed variables for easier readability

Yeong:
So this was the work of yesterday. Now I know how to grab the Str1 and pull it up in the program.
(My original code was for just grabbing the first token of the string, but Zeda did her magic and suddenly the program started to show the whole string.)


--- Code: ---#include "ti83plus.inc"
.org $9D93
.db t2ByteTok,tAsmCmp
bcall(_ClrLCDFull)
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,0
ld e,(hl)
jr __
_:
ld d,(hl)
inc hl
dec bc;decrease bc since token was 2-bytes
ld e,(hl)
__:
push hl;need these for cpi
push bc;
bcall(_PutTokString)
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
--- End code ---

Today, I've been mostly doing some research on how to convert the token to a character.
One good thing is that I don't need to specify when the string will end since this way the loop will end when it reaches the end of the string.
Bad thing is that the only easy conversion is A-Z since their token values are same as the character values :P

I thought about doing some sort of lookup table until I realized that it is probably not a smart idea with 2 bytes tokens.
I looked through the bcalls but I didn't find anything that would help me do this.

I guess I could do bunch of CPs but that didn't sound that elegant.

What would be the best way to approach this problem?

Xeda112358:
You can use the _Get_Tok_Str bcall to convert a token to it's characters. Another routine that might be useful to you later is _SStringLength which calculates how many pixels wide a string is in the variable-width (small) font.

Yeong:

--- Quote from: Xeda112358 on January 29, 2019, 10:45:58 pm ---_Get_Tok_Str bcall

--- End quote ---
Oh.

I thought this meant it simply copies the token strings to OP3.
Now everything makes sense and the world feels a bit nicer again.

Yeong:
Progress report:

Now the program converts tokens to ASCII and display them. This now takes care of my first priority of making the textbox: grabbing ASCIIs from Str1.


--- Code: ---#include "ti83plus.inc"
.org $9D93
.db t2ByteTok,tAsmCmp
bcall(_ClrLCDFull)
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
ld a,(hl)
bcall(_VPutMap)
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
--- End code ---

Navigation

[0] Message Index

[#] Next page

Go to full version