Omnimaga

Calculator Community => TI Calculators => ASM => Topic started by: Eeems on January 02, 2011, 02:25:53 am

Title: [Routine] Monospaced Text
Post by: Eeems on January 02, 2011, 02:25:53 am
Here is a monospaced text routine I made :)
Code: [Select]
;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)
Title: Re: [Routine] Monospaced Text
Post by: Ranman on January 02, 2011, 02:34:49 am
Pretty nifty Eeems!
Title: Re: [Routine] Monospaced Text
Post by: Eeems on January 02, 2011, 02:36:20 am
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 :)
Title: Re: [Routine] Monospaced Text
Post by: Builderboy on January 02, 2011, 03:22:25 am
Nice!  Does it wrap text by letters or words?
Title: Re: [Routine] Monospaced Text
Post by: Eeems on January 02, 2011, 04:31:37 am
Letters. Words would require a much larger routine.
Title: Re: [Routine] Monospaced Text
Post by: DJ Omnimaga on January 03, 2011, 07:36:50 pm
Nice, this should hopefully be useful for other ASM coders. :D
Title: Re: [Routine] Monospaced Text
Post by: Eeems on January 05, 2011, 03:36:17 am
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.
Code: [Select]
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
Title: Re: [Routine] Monospaced Text
Post by: DJ Omnimaga on January 05, 2011, 04:47:26 am
That looks quite easy to read actually, code-wise.
Title: Re: [Routine] Monospaced Text
Post by: Eeems on January 05, 2011, 10:57:14 am
Yep :) Takes up hardly any space too :)