Integrated tiny number font with font engine

This commit is contained in:
blondie7575 2023-07-16 15:18:06 -07:00
parent 7b76277030
commit 8f0db35aeb
9 changed files with 3524 additions and 2225 deletions

BIN
Art/Assets/TinyNumbers.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 215 B

BIN
Art/Assets/TinyNumbers.xcf Normal file

Binary file not shown.

View File

@ -7,13 +7,13 @@
objects = {
/* Begin PBXFileReference section */
7002647320CD78C40015B184 /* smallNumbers.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = smallNumbers.s; sourceTree = "<group>"; };
700B5E6F2069831000B31C00 /* inventory.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = inventory.s; sourceTree = "<group>"; };
700C39C51F2E5CA800C24F9C /* tables.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = tables.s; sourceTree = "<group>"; };
700F21DE1F43E31300D7007D /* input.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = input.s; sourceTree = "<group>"; };
700F21DF1F4A364600D7007D /* projectile.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = projectile.s; sourceTree = "<group>"; };
700F21E01F4A3A5500D7007D /* GenerateTrigTables.py */ = {isa = PBXFileReference; lastKnownFileType = text.script.python; path = GenerateTrigTables.py; sourceTree = "<group>"; };
700F72872112428D00225B17 /* RenumberSpriteFiles.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = RenumberSpriteFiles.sh; sourceTree = "<group>"; };
701E708A2A649A230030C35D /* tinyNumbers.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = tinyNumbers.s; sourceTree = "<group>"; };
705456862A43E03B00A2B866 /* GeneratePixelCircle.py */ = {isa = PBXFileReference; lastKnownFileType = text.script.python; path = GeneratePixelCircle.py; sourceTree = "<group>"; };
705456882A4D336200A2B866 /* animation.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = animation.s; sourceTree = "<group>"; };
7059502B1F37A0BE00BBE90F /* GenerateVRAMTable.py */ = {isa = PBXFileReference; lastKnownFileType = text.script.python; path = GenerateVRAMTable.py; sourceTree = "<group>"; };
@ -62,7 +62,6 @@
7099E3841F41022100182A82 /* gameobject.s */,
70F011D123B989B800C8873F /* random.s */,
706DF1641F2D39F700AA6680 /* loader.s */,
7002647320CD78C40015B184 /* smallNumbers.s */,
706DF1651F2D4A8100AA6680 /* terrain.s */,
705AAFA920040B0D001BB0ED /* terrain_e1.s */,
70F011D023B91B2900C8873F /* dirt.s */,
@ -83,6 +82,7 @@
70E9D8611F2BD95400555C19 /* gscats.s */,
70E9D8631F2BD95400555C19 /* Makefile */,
70BDCBC92006AD5F00CB51F1 /* linkerConfig */,
701E708A2A649A230030C35D /* tinyNumbers.s */,
7076E9232A59113F0006E295 /* font8x8.s */,
7076E9252A5F9F540006E295 /* font16x16.s */,
7076E9242A5A4A8E0006E295 /* fontEngine.s */,

View File

@ -71,8 +71,9 @@ terrain_e1:
fonts:
rm -rf $(FONTBANK)
./CompileFont.py 8 8 32 14 "font8" "Art/Assets/Font8x8.gif" > font8x8.s
./CompileFont.py 8 8 32 0 "font8" "Art/Assets/Font8x8.gif" > font8x8.s
./CompileFont.py 16 16 32 14 "font16" "Art/Assets/Font16x16.gif" > font16x16.s
./CompileFont.py 4 5 48 0 "num4" "Art/Assets/TinyNumbers.gif" > tinyNumbers.s
@PATH=$(PATH):/usr/local/bin; $(CL65) -t apple2enh -C linkerConfig --cpu 65816 --start-addr 0000 -lfonts.lst fontEngine.s -o $(FONTBANK)
rm -f fontEngine.o

4984
font8x8.s

File diff suppressed because it is too large Load Diff

View File

@ -3,8 +3,6 @@
.org $0000
FIRST_CHAR = 32
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; renderString (Far entry point)
;
@ -14,7 +12,7 @@ FIRST_CHAR = 32
; X = Font index
; Y = VRAM position of lower right corner of string at which to draw
;
; Trashes SCRATCHL,PARAML1,X, Y, A
; Trashes SCRATCHL,SCRATCHL2,PARAML1,X, Y, A
;
renderString:
NATIVE
@ -22,12 +20,15 @@ renderString:
sty SCRATCHL ; Cache VRAM position
txa ; Cache font character table
txa ; Cache font character tables
asl
tay
lda fontJumpTable,y
sta renderCharBounce+1
lda fontFirstCharTable,y
sta SCRATCHL2
lda fontCharWidthTable,y
sta PARAML1
@ -72,18 +73,19 @@ renderStringDone:
;
; A = ASCII code to draw
; Y = VRAM position of lower right corner at which to draw
; SCRATCHL2 = First char in font
;
renderChar:
SAVE_AXY
sec ; Bounce off glyph-rendering jump table
sbc #FIRST_CHAR
sec
sbc SCRATCHL2
asl
tax
FASTGRAPHICS
renderCharBounce: ; Self modifying code. Don't panic
jmp (font16characterJumpTable,x)
jmp ($1234,x)
renderCharJumpReturn: ; Compiled glyphs jump back here. Can't rts because stack is turboborked
SLOWGRAPHICS
@ -94,11 +96,19 @@ renderCharJumpReturn: ; Compiled glyphs jump back here. Can't rts because stack
fontJumpTable:
.addr font8characterJumpTable
.addr font16characterJumpTable
.addr num4characterJumpTable
fontCharWidthTable: ; In bytes
.word 4
.word 8
.word 2
fontFirstCharTable: ; ASCII codes
.word 32
.word 32
.word 48
.include "tinyNumbers.s"
.include "font8x8.s"
.include "font16x16.s"

View File

@ -38,7 +38,11 @@ renderInventory:
renderInventoryLoop:
lda PARAML1 ; renderInventory item trashes this so we need to preserve it
pha
jsr renderInventoryItem
pla
sta PARAML1
tya ; Advance VRAM pointer
clc
@ -124,12 +128,15 @@ renderInventoryItem_unselected:
sta intToStringResult
BITS16
sec
; Render tiny numbers
pla
sbc #($2000 - 160*2)-1 ; Font engine wants VRAM-relative
tax
clc
adc #6*160+4
tay
lda #intToStringPrefix
jsr DrawTinyNumber
sta PARAML0
ldx #2
jsl renderStringFar
renderInventoryItem_done:
RESTORE_AXY

View File

@ -1,168 +0,0 @@
; Mini font render dedicated to small numbers.
; Adapted from Dagen Brock's general purpose font
; engine, also in this project
;
; A= ptr to string preceded by length
; X= screen location
; Trashes zero page locations 6,7
;
F_LEN: .word 0 ;length of string (only one byte currently used)
F_DIGITIDX: .word 0 ;index of current character
F_CURRPOS: .word 0 ;current top left char position
F_NUMPTR = $06 ;pointer to string (including length byte) / DP
DrawTinyNumber:
SAVE_AXY
sta F_NUMPTR
stx F_CURRPOS
stz F_DIGITIDX
lda (F_NUMPTR)
and #$00ff ;strip off first char (len is only one byte)
sta F_LEN ;get our length byte
nextDigit:
lda F_DIGITIDX
cmp F_LEN
bne moreDigits
RESTORE_AXY
rts
moreDigits:
inc F_DIGITIDX
ldy F_DIGITIDX
lda (F_NUMPTR),y ;get next char!
and #$00FF ;mask high byte
sec
sbc #'0' ;our table starts with space ' '
asl
tay
ldx F_CURRPOS
jsr drawDigit
inc F_CURRPOS
inc F_CURRPOS ;update screen pos (1 word=4 pixels)
bra nextDigit
;x = TopLeft screen pos
;y = char table offset
drawDigit:
lda DigitTable,y ;get real address of char data
sec
sbc #DigitData ;pivot offset - now a is offset of fontdata
tay ;so we'll index with that
lda DigitData,y
sta $012000,x
lda DigitData+2,y
sta $012000+160,x
lda DigitData+4,y
sta $012000+160*2,x
lda DigitData+6,y
sta $012000+160*3,x
lda DigitData+8,y
sta $012000+160*4,x
rts
DigitTable:
.addr s_0
.addr s_1
.addr s_2
.addr s_3
.addr s_4
.addr s_5
.addr s_6
.addr s_7
.addr s_8
.addr s_9
.addr s_SmallDollar ; Use ASCII code for colon
DigitData:
s_0:
fontword $FFF0
fontword $F0F0
fontword $F0F0
fontword $F0F0
fontword $FFF0
s_1:
fontword $0F00
fontword $FF00
fontword $0F00
fontword $0F00
fontword $0F00
s_2:
fontword $FFF0
fontword $00F0
fontword $FFF0
fontword $F000
fontword $FFF0
s_3:
fontword $FFF0
fontword $00F0
fontword $FFF0
fontword $00F0
fontword $FFF0
s_4:
fontword $F0F0
fontword $F0F0
fontword $FFF0
fontword $00F0
fontword $00F0
s_5:
fontword $FFF0
fontword $F000
fontword $FFF0
fontword $00F0
fontword $FFF0
s_6:
fontword $FFF0
fontword $F000
fontword $FFF0
fontword $F0F0
fontword $FFF0
s_7:
fontword $FFF0
fontword $00F0
fontword $00F0
fontword $00F0
fontword $00F0
s_8:
fontword $FFF0
fontword $F0F0
fontword $FFF0
fontword $F0F0
fontword $FFF0
s_9:
fontword $FFF0
fontword $F0F0
fontword $FFF0
fontword $00F0
fontword $00F0
s_SmallDollar: ; Use ASCII code for colon
.dbyt $a66a
.dbyt $6F66
.dbyt $6666
.dbyt $a66a
.dbyt $aaaa

551
tinyNumbers.s Normal file
View File

@ -0,0 +1,551 @@
num4characterJumpTable:
.addr num4char48
.addr num4char49
.addr num4char50
.addr num4char51
.addr num4char52
.addr num4char53
.addr num4char54
.addr num4char55
.addr num4char56
.addr num4char57
.addr num4char58
; Chroma Key is $0
num4char48:
tya
tcs
; Line 4, Pixel values: 0e00
tsc
dec
dec
tcs
lda 1,S
and #$fff0
ora #$000e
sta 1,S
; Line 3, Pixel values: e0e0
tsc
sec
sbc #160
tcs
lda 1,S
and #$0f0f
ora #$e0e0
sta 1,S
; Line 2, Pixel values: e0e0
tsc
sec
sbc #160
tcs
lda 1,S
and #$0f0f
ora #$e0e0
sta 1,S
; Line 1, Pixel values: e0e0
tsc
sec
sbc #160
tcs
lda 1,S
and #$0f0f
ora #$e0e0
sta 1,S
; Line 0, Pixel values: 0e00
tsc
sec
sbc #160
tcs
lda 1,S
and #$fff0
ora #$000e
sta 1,S
jmp renderCharJumpReturn
num4char49:
tya
tcs
; Line 4, Pixel values: 00e0
tsc
dec
dec
tcs
lda 1,S
and #$0fff
ora #$e000
sta 1,S
; Line 3, Pixel values: 00e0
tsc
sec
sbc #160
tcs
lda 1,S
and #$0fff
ora #$e000
sta 1,S
; Line 2, Pixel values: 00e0
tsc
sec
sbc #160
tcs
lda 1,S
and #$0fff
ora #$e000
sta 1,S
; Line 1, Pixel values: 0ee0
tsc
sec
sbc #160
tcs
lda 1,S
and #$0ff0
ora #$e00e
sta 1,S
; Line 0, Pixel values: 00e0
tsc
sec
sbc #160
tcs
lda 1,S
and #$0fff
ora #$e000
sta 1,S
jmp renderCharJumpReturn
num4char50:
tya
tcs
; Line 4, Pixel values: eee0
tsc
dec
dec
tcs
lda 1,S
and #$0f00
ora #$e0ee
sta 1,S
; Line 3, Pixel values: e000
tsc
sec
sbc #160
tcs
lda 1,S
and #$ff0f
ora #$00e0
sta 1,S
; Line 2, Pixel values: 0e00
tsc
sec
sbc #160
tcs
lda 1,S
and #$fff0
ora #$000e
sta 1,S
; Line 1, Pixel values: 00e0
tsc
sec
sbc #160
tcs
lda 1,S
and #$0fff
ora #$e000
sta 1,S
; Line 0, Pixel values: ee00
tsc
sec
sbc #160
tcs
lda 1,S
and #$ff00
ora #$00ee
sta 1,S
jmp renderCharJumpReturn
num4char51:
tya
tcs
; Line 4, Pixel values: ee00
tsc
dec
dec
tcs
lda 1,S
and #$ff00
ora #$00ee
sta 1,S
; Line 3, Pixel values: 00e0
tsc
sec
sbc #160
tcs
lda 1,S
and #$0fff
ora #$e000
sta 1,S
; Line 2, Pixel values: ee00
tsc
sec
sbc #160
tcs
lda 1,S
and #$ff00
ora #$00ee
sta 1,S
; Line 1, Pixel values: 00e0
tsc
sec
sbc #160
tcs
lda 1,S
and #$0fff
ora #$e000
sta 1,S
; Line 0, Pixel values: ee00
tsc
sec
sbc #160
tcs
lda 1,S
and #$ff00
ora #$00ee
sta 1,S
jmp renderCharJumpReturn
num4char52:
tya
tcs
; Line 4, Pixel values: 00e0
tsc
dec
dec
tcs
lda 1,S
and #$0fff
ora #$e000
sta 1,S
; Line 3, Pixel values: 00e0
tsc
sec
sbc #160
tcs
lda 1,S
and #$0fff
ora #$e000
sta 1,S
; Line 2, Pixel values: eee0
tsc
sec
sbc #160
tcs
lda 1,S
and #$0f00
ora #$e0ee
sta 1,S
; Line 1, Pixel values: e0e0
tsc
sec
sbc #160
tcs
lda 1,S
and #$0f0f
ora #$e0e0
sta 1,S
; Line 0, Pixel values: e0e0
tsc
sec
sbc #160
tcs
lda 1,S
and #$0f0f
ora #$e0e0
sta 1,S
jmp renderCharJumpReturn
num4char53:
tya
tcs
; Line 4, Pixel values: ee00
tsc
dec
dec
tcs
lda 1,S
and #$ff00
ora #$00ee
sta 1,S
; Line 3, Pixel values: 00e0
tsc
sec
sbc #160
tcs
lda 1,S
and #$0fff
ora #$e000
sta 1,S
; Line 2, Pixel values: ee00
tsc
sec
sbc #160
tcs
lda 1,S
and #$ff00
ora #$00ee
sta 1,S
; Line 1, Pixel values: e000
tsc
sec
sbc #160
tcs
lda 1,S
and #$ff0f
ora #$00e0
sta 1,S
; Line 0, Pixel values: eee0
tsc
sec
sbc #160
tcs
lda 1,S
and #$0f00
ora #$e0ee
sta 1,S
jmp renderCharJumpReturn
num4char54:
tya
tcs
; Line 4, Pixel values: ee00
tsc
dec
dec
tcs
lda 1,S
and #$ff00
ora #$00ee
sta 1,S
; Line 3, Pixel values: e0e0
tsc
sec
sbc #160
tcs
lda 1,S
and #$0f0f
ora #$e0e0
sta 1,S
; Line 2, Pixel values: ee00
tsc
sec
sbc #160
tcs
lda 1,S
and #$ff00
ora #$00ee
sta 1,S
; Line 1, Pixel values: e000
tsc
sec
sbc #160
tcs
lda 1,S
and #$ff0f
ora #$00e0
sta 1,S
; Line 0, Pixel values: 0ee0
tsc
sec
sbc #160
tcs
lda 1,S
and #$0ff0
ora #$e00e
sta 1,S
jmp renderCharJumpReturn
num4char55:
tya
tcs
; Line 4, Pixel values: 0e00
tsc
dec
dec
tcs
lda 1,S
and #$fff0
ora #$000e
sta 1,S
; Line 3, Pixel values: 0e00
tsc
sec
sbc #160
tcs
lda 1,S
and #$fff0
ora #$000e
sta 1,S
; Line 2, Pixel values: 0e00
tsc
sec
sbc #160
tcs
lda 1,S
and #$fff0
ora #$000e
sta 1,S
; Line 1, Pixel values: 00e0
tsc
sec
sbc #160
tcs
lda 1,S
and #$0fff
ora #$e000
sta 1,S
; Line 0, Pixel values: eee0
tsc
sec
sbc #160
tcs
lda 1,S
and #$0f00
ora #$e0ee
sta 1,S
jmp renderCharJumpReturn
num4char56:
tya
tcs
; Line 4, Pixel values: 0e00
tsc
dec
dec
tcs
lda 1,S
and #$fff0
ora #$000e
sta 1,S
; Line 3, Pixel values: e0e0
tsc
sec
sbc #160
tcs
lda 1,S
and #$0f0f
ora #$e0e0
sta 1,S
; Line 2, Pixel values: 0e00
tsc
sec
sbc #160
tcs
lda 1,S
and #$fff0
ora #$000e
sta 1,S
; Line 1, Pixel values: e0e0
tsc
sec
sbc #160
tcs
lda 1,S
and #$0f0f
ora #$e0e0
sta 1,S
; Line 0, Pixel values: 0e00
tsc
sec
sbc #160
tcs
lda 1,S
and #$fff0
ora #$000e
sta 1,S
jmp renderCharJumpReturn
num4char57:
tya
tcs
; Line 4, Pixel values: 00e0
tsc
dec
dec
tcs
lda 1,S
and #$0fff
ora #$e000
sta 1,S
; Line 3, Pixel values: 00e0
tsc
sec
sbc #160
tcs
lda 1,S
and #$0fff
ora #$e000
sta 1,S
; Line 2, Pixel values: 0ee0
tsc
sec
sbc #160
tcs
lda 1,S
and #$0ff0
ora #$e00e
sta 1,S
; Line 1, Pixel values: e0e0
tsc
sec
sbc #160
tcs
lda 1,S
and #$0f0f
ora #$e0e0
sta 1,S
; Line 0, Pixel values: 0ee0
tsc
sec
sbc #160
tcs
lda 1,S
and #$0ff0
ora #$e00e
sta 1,S
jmp renderCharJumpReturn
num4char58:
tya
tcs
; Line 4, Pixel values: 0000
; Line 3, Pixel values: 0660
tsc
sec
sbc #162
tcs
lda 1,S
and #$0ff0
ora #$6006
sta 1,S
; Line 2, Pixel values: 6666
tsc
sec
sbc #158
tcs
pea $6666
; Line 1, Pixel values: 6f66
tsc
sec
sbc #158
tcs
pea $666f
; Line 0, Pixel values: 0660
tsc
sec
sbc #160
tcs
lda 1,S
and #$0ff0
ora #$6006
sta 1,S
jmp renderCharJumpReturn