Author Topic: SpriteFont  (Read 3275 times)

0 Members and 1 Guest are viewing this topic.

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
SpriteFont
« 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:
  • During program execution, you can change the homescreen font.
  • Upon exiting, the previous font hook is restored
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:

Offline TIfanx1999

  • ಠ_ಠ ( ͡° ͜ʖ ͡°)
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 6173
  • Rating: +191/-9
    • View Profile
Re: SpriteFont
« Reply #1 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.

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: SpriteFont
« Reply #2 on: March 17, 2014, 09:53:32 am »
Yes, it was a lot easier than I expected (changing two byte).

Offline TIfanx1999

  • ಠ_ಠ ( ͡° ͜ʖ ͡°)
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 6173
  • Rating: +191/-9
    • View Profile
Re: SpriteFont
« Reply #3 on: March 17, 2014, 09:57:27 am »
:O Awesome! ;D Thanks again!

Offline Sorunome

  • Fox Fox Fox Fox Fox Fox Fox!
  • Support Staff
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 7920
  • Rating: +374/-13
  • Derpy Hooves
    • View Profile
    • My website! (You might lose the game)
Re: SpriteFont
« Reply #4 on: March 17, 2014, 01:08:52 pm »
So many font hooks, but nice :P

THE GAME
Also, check out my website
If OmnomIRC is screwed up, blame me!
Click here to give me an internet!

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: SpriteFont
« Reply #5 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.

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: SpriteFont
« Reply #6 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.