Omnimaga
Calculator Community => TI Calculators => ASM => Topic started by: Eeems on January 02, 2011, 02:25:53 am
-
Here is a monospaced text routine I made :)
;Monospaced text
;inputs: penRow=y, penCol=x, hl=pointer to null (0) terminated text
DrawMonospaceString:
ld a, (hl)
inc hl
cp '\n'
jr z, monoWrapLine
cp '\r'
jr z, monoWrapLine
cp '\t'
jr z,monoTab
or a
ret z
push af
ld a,(penCol)
ld b,a
pop af
push bc
b_call _VPutMap
pop bc
ld a,b
add a,6
ld (penCol),a
cp 92
jr nc,monoWrapLine
jr DrawMonospaceString
monoTab:
ld a,(penCol)
add a,12
ld (penCol),a
cp 55
call nc,Newline
jr DrawMonospaceString
monoWrapLine:
call Newline
jr DrawMonospaceString
;newline, wrapps screen if necessary
;preserves af
Newline:
push af
xor a
ld (penCol),a
ld a,(penRow)
add a, 6
cp 55
jr nc,NewLine_top
ld (penRow),a
pop af
ret
NewLine_top:
xor a
ld (penRow),a
pop af
ret
It also parses \n and \r as a newline, which it wraps to the top of the screen if you go off the edge. \t is replaced with a double space as well. Hope some people find this useful :)
(Oh and credit goes to SirCmpwn because I got a bunch of the code from KOS, but it is modified for TI-OS's font and to make it monospaced. I use this in TBP for text input)
-
Pretty nifty Eeems!
-
Thanks :) I hope someone has some use for it, or some ways to make it better :P
edit: oh and I forgot to mention, it also wraps the text when it reaches the edge of the screen :)
-
Nice! Does it wrap text by letters or words?
-
Letters. Words would require a much larger routine.
-
Nice, this should hopefully be useful for other ASM coders. :D
-
Yeah :) that's my hope :)
I like making these little routines I make available to others. Maybe I should release my menu code for TBP too, since it makes making menus pretty simple. Menu:
.db "Menu",0,2
.db "Item 1",0
.db "Item 2",0
.dw Item_1_goto
.dw Item_2_goto
.dw clear_button_goto
-
That looks quite easy to read actually, code-wise.
-
Yep :) Takes up hardly any space too :)