Omnimaga

Calculator Community => Other Calc-Related Projects and Ideas => TI Z80 => Topic started by: Xeda112358 on March 17, 2014, 09:38:44 am

Title: SpriteFont
Post by: Xeda112358 on March 17, 2014, 09:38:44 am
I threw this together after Art_of_camelot mentioned that it could be useful. It is a lightweight font hook program that does the following:
Fonts must be appvars without a header (so Omnicalc fonts won't work, for example), but they can be archived or in RAM. The "commands" are simple. A string in Ans contains the appvar name. Lowercase won't work very easily, as I don't include a tokens→ASCII routine, so use uppercase letters and numbers. For example:
Code: [Select]
"FONT":Asm(prgmSPRTFNT
If you want to swap fonts put a plus sign in front:
Code: [Select]

"+FONT":Asm(prgmSPRTFNT
If you want to disable the font hook, either pass a non-string or "-":
Code: [Select]
"-":Asm(prgmSPRTFNT


Notes- If you don't use "+" to swap fonts, the hook won't be able to load in the default font after exiting.
If you use the assembly program to allow you to use Delvar / Archive / Unarchive on a program, displaying text before setting the mode back to "program mode" will cause the font to be disabled.


EDIT: And the code:
Code: [Select]

#include    "ti83plus.inc"
#define     progStart   $9D95
.org        progStart-2
.db         $BB,$6D
name = n-SpriteFont+9872h
adjust = a-SpriteFont+9872h


SetUpFont:
bcall(_RclAns)
sub 4
jr z,Parse
deacthook1:
call Is_Hook_Active
ret nz
jp deacthook-SpriteFont+9872h
Parse:
ex de,hl
ld c,(hl)
inc hl
ld b,(hl)
inc hl
ld a,(hl)
cp 71h
jr z,deacthook1
cp 70h ;+ sign
jr nz,LoadHook
call Is_Hook_Active
inc hl
jr nz,LoadHook
ld de,name+1
ldir
xor a
ld (de),a
ret
LoadHook:
push hl
    push bc
ld hl,(fontHookPtr)
ld a,(fontHookPtr+2)
ld (prevhook),hl
ld (prevpage),a


ld hl,SpriteFont
ld de,9872h ;appbackupscreen
ld bc,SpriteFontEnd-SpriteFont
ldir
    pop bc
pop hl
ld de,name+1
ldir
xor a
ld (de),a




ld hl,9872h
ld a,l
bcall(4FE4h)         ;Sets the font hook
ret
Is_Hook_Active:
ld a,(9872h)
sub 83h
ret nz
bit 5,(iy+35h)
ret nz
push hl
ld hl,(fonthookPtr)
ld de,9872h
sbc hl,de
pop hl
ret nz
SpriteFont:
.db 83h
dec a
jr z,$+5
exithook:
xor a
inc a
ret
bit 1,(iy+8)
jr nz,locate_replace
    push hl
deacthook:
.db 21h
prevhook:
.dw 0
.db 3Eh
prevpage:
.db 0
bcall(4FE4h)         ;Sets the font hook
    pop hl
jr exithook
locate_replace:


;B is the char
ld (restoreBC-SpriteFont+9872h),bc
ld l,b
ld h,a
in a,(6)
ld (restorePage-SpriteFont+9872h),a
ld c,l
ld b,h
add hl,hl
add hl,bc
add hl,hl
add hl,bc
push hl
ld hl,name
rst 20h
bcall(_ChkFindSym)
pop hl
jr c,deacthook
ex de,hl
inc hl
inc hl
add hl,de
ld a,b
or a
jr z,ram_font+2
ld b,0
add hl,bc
ld c,10
add hl,bc
jp p,ram_font-SpriteFont+9872h
inc a \ ld h,40h
ram_font:
out (6),a
ld de,lFont_record
ld b,7


ld a,(hl) \ ld (de),a
inc e \ inc l
call z,adjust
djnz $-7


ld hl,lFont_record
.db 3Eh
restorePage:
.db 0
out (6),a
.db 1
restoreBC:
.dw 0
xor a
ret
a:
inc h
ret po
in a,(6)
inc a
out (6),a
ld h,40h
ret
n:
.db 15h,0,0,0,0,0,0,0,0
SpriteFontEnd:
Title: Re: SpriteFont
Post by: TIfanx1999 on March 17, 2014, 09:51:28 am
I was actually thinking about the graph screen, and totally didn't realize the would be different.  :-[  Sorry about that!  XD  Thanks for all the work you're putting in. As I said, you really didn't even have to do this. I just thought it might be useful. You're awesome Xeda! Anyhow, as we were talking about on IRC, maybe there is a quick(ish) fix.
Title: Re: SpriteFont
Post by: Xeda112358 on March 17, 2014, 09:53:32 am
Yes, it was a lot easier than I expected (changing two byte).
Title: Re: SpriteFont
Post by: TIfanx1999 on March 17, 2014, 09:57:27 am
:O Awesome! ;D Thanks again!
Title: Re: SpriteFont
Post by: Sorunome on March 17, 2014, 01:08:52 pm
So many font hooks, but nice :P
Title: Re: SpriteFont
Post by: DJ Omnimaga on April 04, 2014, 02:01:25 am
ooh that seems pretty useful, especially that the fonts are in RAM :D. In an RPG, for example, you could easily switch between tilesets that way. Having just 1 font set for the entire game was pretty restrictive.
Title: Re: SpriteFont
Post by: Xeda112358 on April 04, 2014, 07:55:38 am
The fonts themselves can be in RAM or archive, but the hook itself is stored in RAM and with it is the name of the fontset. It does make it easy to switch fonts as needed.