Font compiler now generates dedicated code bank

Fixed many bugs in font compiler and seems to render correctly now
This commit is contained in:
blondie7575 2023-07-09 17:58:05 -07:00
parent 1079535020
commit a1d5abb963
9 changed files with 11337 additions and 38 deletions

2
.gitignore vendored
View File

@ -4,3 +4,5 @@
/loader.lst
/terrain_e1.lst
/gscats.2mg
/fontEngine.lst
/FONTBANK\#060000

View File

@ -10,18 +10,29 @@ CHAR_HEIGHT = 8
CHAR_FIRST = 32
CHROMA = 14
def labelFromCharXY(charX, numCharX, charY):
charIndex = charY*numCharX + charX
currChar = chr(charIndex+CHAR_FIRST)
return "char{:d}".format(ord(currChar))
def main(argv):
image = Image.open('Art/Assets/Font8x8.gif')
pixels = asarray(image)
numCharX = (int)(image.size[0]/CHAR_WIDTH)
numCharY = (int)(image.size[1]/CHAR_HEIGHT)
for charY in range(0,1): #numCharY):
for charX in range(1,2): #numCharX):
charIndex = charY*numCharX + charX
currChar = chr(charIndex+CHAR_FIRST)
print ("char%d:\n" % ord(currChar), end="")
# Generate jump table for glyphs
print ("characterJumpTable:")
for charY in range(0,numCharY):
for charX in range(0,numCharX):
print ("\t.addr %s" % labelFromCharXY(charX,numCharX,charY))
print ("")
# Generate code for each glyph
for charY in range(0,numCharY):
for charX in range(0,numCharX):
print ("%s:\n" % labelFromCharXY(charX,numCharX,charY), end="")
# Header for each rendering operation
print ("\ttya") # Transfer character VRAM position from Y to stack pointer
@ -32,7 +43,15 @@ def main(argv):
charOriginY = charY*CHAR_HEIGHT
for charRow in reversed(range(0,CHAR_HEIGHT)):
print ("\t; Line %d" % charRow)
print ("\t; Line %d, Pixel values: %x,%x,%x,%x,%x,%x,%x,%x" % (charRow,
pixels[charOriginY+charRow][charOriginX+0],
pixels[charOriginY+charRow][charOriginX+1],
pixels[charOriginY+charRow][charOriginX+2],
pixels[charOriginY+charRow][charOriginX+3],
pixels[charOriginY+charRow][charOriginX+4],
pixels[charOriginY+charRow][charOriginX+5],
pixels[charOriginY+charRow][charOriginX+6],
pixels[charOriginY+charRow][charOriginX+7]))
nextRowDelta = 160
for charCol in reversed(range(0,CHAR_WIDTH,4)):
nibbles = [pixels[charOriginY+charRow][charOriginX+charCol],
@ -43,20 +62,27 @@ def main(argv):
word = nibbles[2]<<12 | nibbles[3]<<8 | nibbles[0]<<4 | nibbles[1]
if (nibbles[0]==CHROMA and nibbles[1]==CHROMA and nibbles[2]==CHROMA and nibbles[3]==CHROMA):
pass # Case 1 : All chroma, so let stack advance with no work
print ("\ttsc") # Case 1 : All chroma, so let stack advance with no work
print ("\tdec")
print ("\tdec")
print ("\ttcs")
nextRowDelta-=2
elif (nibbles[0]!=CHROMA and nibbles[1]!=CHROMA and nibbles[2]!=CHROMA and nibbles[3]!=CHROMA):
print ("\ttsc") # Advance stack 1 for two byte push
print ("\tdec")
print ("\ttcs")
print ("\tpea $%04x" % word) # Case 2 : No chroma, so fast push
nextRowDelta -= 2
nextRowDelta -= 3
else:
mask = 0 # Case 3 : Mixed chroma, so mask and or
mask = 0xFFFF # Case 3 : Mixed chroma, so mask and or
if (nibbles[0]!=CHROMA):
mask = mask | 0xFF0F
mask = mask & 0xFF0F
if (nibbles[1]!=CHROMA):
mask = mask | 0xFFF0
mask = mask & 0xFFF0
if (nibbles[2]!=CHROMA):
mask = mask | 0x0FFF
mask = mask & 0x0FFF
if (nibbles[3]!=CHROMA):
mask = mask | 0xF0FF
mask = mask & 0xF0FF
sprite = word
if (nibbles[0]==CHROMA):
@ -85,7 +111,7 @@ def main(argv):
print ("\ttcs")
# Footer for each rendering operation
print ("\tjmp returnFromTest")
print ("\tjmp renderCharJumpReturn\n")
if __name__ == "__main__":
main(sys.argv[1:])

View File

@ -22,8 +22,9 @@
705C54E62124B7F300515A6B /* fan.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = fan.s; sourceTree = "<group>"; };
706DF1641F2D39F700AA6680 /* loader.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = loader.s; sourceTree = "<group>"; };
706DF1651F2D4A8100AA6680 /* terrain.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = terrain.s; sourceTree = "<group>"; };
7076E9222A57AED90006E295 /* GenerateFont.py */ = {isa = PBXFileReference; lastKnownFileType = text.script.python; path = GenerateFont.py; sourceTree = "<group>"; };
7076E9222A57AED90006E295 /* CompileFont.py */ = {isa = PBXFileReference; lastKnownFileType = text.script.python; path = CompileFont.py; sourceTree = "<group>"; };
7076E9232A59113F0006E295 /* font8x8.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = font8x8.s; sourceTree = "<group>"; };
7076E9242A5A4A8E0006E295 /* fontEngine.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = fontEngine.s; sourceTree = "<group>"; };
7088096D1F2ECE8D00D4C950 /* GenerateRenderSpans.py */ = {isa = PBXFileReference; lastKnownFileType = text.script.python; path = GenerateRenderSpans.py; sourceTree = "<group>"; };
708D1B1E27B9A1A600909AFC /* crosshair.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = crosshair.s; sourceTree = "<group>"; };
709175C01F60D263008FAFAB /* GenerateCircles.py */ = {isa = PBXFileReference; lastKnownFileType = text.script.python; path = GenerateCircles.py; sourceTree = "<group>"; };
@ -83,10 +84,11 @@
70E9D8611F2BD95400555C19 /* gscats.s */,
70E9D8631F2BD95400555C19 /* Makefile */,
70BDCBC92006AD5F00CB51F1 /* linkerConfig */,
7076E9232A59113F0006E295 /* font8x8.s */,
7076E9242A5A4A8E0006E295 /* fontEngine.s */,
7076E9222A57AED90006E295 /* CompileFont.py */,
70FE79D21F8814A600E0095C /* MerlinToCA65.sh */,
700F72872112428D00225B17 /* RenumberSpriteFiles.sh */,
7076E9222A57AED90006E295 /* GenerateFont.py */,
7076E9232A59113F0006E295 /* font8x8.s */,
7088096D1F2ECE8D00D4C950 /* GenerateRenderSpans.py */,
7059502B1F37A0BE00BBE90F /* GenerateVRAMTable.py */,
7099E3851F4107B100182A82 /* GenerateVRAMYOffset.py */,

View File

@ -18,6 +18,7 @@ CODEBANK=CODEBANK\#060000
CODEBANKE1=CODEBANKE1\#060800
EXEC=$(PGM)\#06$(ADDR)
SOUNDBANK=SOUNDBANK\#060000
FONTBANK=FONTBANK\#060000
PGM=gscats
MRSPRITE=../MrSprite/mrsprite
@ -49,6 +50,7 @@ $(PGM):
$(CAD) ADDFILE $(PGM).2mg /$(VOLNAME) $(CODEBANK)
$(CAD) ADDFILE $(PGM).2mg /$(VOLNAME) $(SPRITEBANK)
$(CAD) ADDFILE $(PGM).2mg /$(VOLNAME) $(SOUNDBANK)
$(CAD) ADDFILE $(PGM).2mg /$(VOLNAME) $(FONTBANK)
rm -f $(CODEBANK)
rm -f $(PGM).o
@ -96,3 +98,11 @@ sound:
rm -f $(GENSOUND)/*
./GenerateSoundBank.sh Sound/CatHowl.wav 11264 Sound/Meow1.wav 5513 Sound/Meow2.wav 5513 Sound/Meow3.wav 5513 Sound/Meow4.wav 5513
rm -f $(GENSOUND)/*
.PHONY: fonts
fonts:
rm -rf $(FONTBANK)
./CompileFont.py > font8x8.s
@PATH=$(PATH):/usr/local/bin; $(CL65) -t apple2enh --cpu 65816 --start-addr 0000 -lfonts.lst fontEngine.s -o $(FONTBANK)
rm -f fontEngine.o

11164
font8x8.s

File diff suppressed because it is too large Load Diff

83
fontEngine.s Normal file
View File

@ -0,0 +1,83 @@
.include "equates.s"
.include "macros.s"
.org $0000
FIRST_CHAR = 32
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; renderString (Far entry point)
;
; Draws a Pascal string
;
; PARAM0L = Pointer to string
; Y = VRAM position of lower right corner of string at which to draw
;
; Trashes SCRATCHL, X, Y, A
;
renderString:
NATIVE
sty SCRATCHL
BITS8
lda (PARAML0)
tax
BITS16
renderStringLoop:
; Fetch and render next character in string
txy
lda #0
BITS8A
lda (PARAML0),y
BITS16
ldy SCRATCHL
jsr renderChar
dex
beq renderStringDone
; Calculate VRAM pointer for position of next character
lda SCRATCHL
sec
sbc #4
sta SCRATCHL
bra renderStringLoop
renderStringDone:
rtl
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; renderChar
;
; Draws a single character
;
; A = ASCII code to draw
; Y = VRAM position of lower right corner at which to draw
;
renderChar:
SAVE_AXY
sec ; Bounce off glyph-rendering jump table
sbc #FIRST_CHAR
asl
tax
FASTGRAPHICS
jmp (characterJumpTable,x)
renderCharJumpReturn: ; Compiled glyphs jump back here. Can't rts because stack is turboborked
SLOWGRAPHICS
RESTORE_AXY
rts
.include "font8x8.s"
; Suppress some linker warnings - Must be the last thing in the file
; This is because Quinn doesn't really know how to use ca65 properly
.SEGMENT "ZPSAVE"
.SEGMENT "EXEHDR"
.SEGMENT "STARTUP"
.SEGMENT "INIT"
.SEGMENT "LOWCODE"

View File

@ -69,12 +69,13 @@ beginGameplay:
jsr clipTerrain
; Test font renderer
; FASTGRAPHICS
; ldy #$3000 ;#$2504
; jmp char33
returnFromTest:
; SLOWGRAPHICS
; ;HARDBRK
lda #testString
sta PARAML0
ldy #$3000
jsl $050000
bra gameplayLoop
testString:
pstring "HELLO WORLD!"
gameplayLoop:
lda projectileActive

View File

@ -54,7 +54,6 @@ quitGame:
.include "inventory.s"
.include "dirt.s"
.include "crosshair.s"
.include "font8x8.s"
endMainBank2:

View File

@ -164,7 +164,7 @@ loadData:
EMULATION
; Load rest of sound data into bank 0 (needed if sound size exceeds BUFFERSIZE)
; Load rest of sound data into bank 4 (needed if sound size exceeds BUFFERSIZE)
jsr PRODOS
.byte $ca
.addr fileRead
@ -177,7 +177,7 @@ loadData:
NATIVE
; Copy rest of code into bank 2 (needed if code size exceeds BUFFERSIZE)
; Copy rest of sound data into bank 4 (needed if sound size exceeds BUFFERSIZE)
ldx fileReadLen
txa
clc
@ -187,6 +187,28 @@ loadData:
ldy #BUFFERSIZE
jsr copyBytes
EMULATION
; Open the font file
jsr PRODOS
.byte $c8
.addr fileOpenFonts
bne ioErrorJmp
; Load the font data into bank 0
jsr PRODOS
.byte $ca
.addr fileRead
bne ioErrorJmp
NATIVE
; Copy font data into bank 5
ldx fileReadLen
lda #5
ldy #0
jsr copyBytes
; Set up a long jump into bank 2, and
; a way for game code to get back here to exit
; properly to ProDOS 8
@ -200,6 +222,9 @@ returnToProDOS:
EMULATION
rts
ioErrorJmp:
jmp ioError
; This table lives here in the loader because we need to copy
; it to a specific free hole in bank E1
@ -315,6 +340,13 @@ fileOpenSound:
.byte 0 ; Result (file handle)
.byte 0 ; Padding
fileOpenFonts:
.byte 3
.addr fontPath
.addr $9200 ; 1k below BASIC.SYSTEM
.byte 0 ; Result (file handle)
.byte 0 ; Padding
codePath:
pstring "/GSAPP/CODEBANK"
codePathE1:
@ -323,3 +355,5 @@ spritePath:
pstring "/GSAPP/SPRITEBANK"
soundPath:
pstring "/GSAPP/SOUNDBANK"
fontPath:
pstring "/GSAPP/FONTBANK"