A lot of bug fixing in font compiler

This commit is contained in:
blondie7575 2023-07-13 12:08:21 -07:00
parent 5f2d128eb3
commit 75b4b1ac84
10 changed files with 17691 additions and 2074 deletions

BIN
Art/Assets/Font16x16.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

BIN
Art/Assets/Font16x16.xcf Normal file

Binary file not shown.

View File

@ -5,34 +5,35 @@ import PIL
from PIL import Image
from numpy import asarray
def labelFromCharXY(charFirst, charX, numCharX, charY):
def labelFromCharXY(prefix,charFirst, charX, numCharX, charY):
charIndex = charY*numCharX + charX
currChar = chr(charIndex+charFirst)
return "char{:d}".format(ord(currChar))
return "{:s}char{:d}".format(prefix,ord(currChar))
def main(argv):
CHAR_WIDTH = int(argv[0])
CHAR_HEIGHT = int(argv[1])
CHAR_FIRST = int(argv[2])
CHROMA = int(argv[3])
image = Image.open(argv[4])
prefix = argv[4]
image = Image.open(argv[5])
pixels = asarray(image)
numCharX = (int)(image.size[0]/CHAR_WIDTH)
numCharY = (int)(image.size[1]/CHAR_HEIGHT)
# Generate jump table for glyphs
print ("characterJumpTable:")
print ("%scharacterJumpTable:" % prefix)
for charY in range(0,numCharY):
for charX in range(0,numCharX):
print ("\t.addr %s" % labelFromCharXY(CHAR_FIRST,charX,numCharX,charY))
print ("\t.addr %s" % labelFromCharXY(prefix,CHAR_FIRST,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(CHAR_FIRST,charX,numCharX,charY), end="")
print ("%s:\n" % labelFromCharXY(prefix,CHAR_FIRST,charX,numCharX,charY), end="")
# Header for each rendering operation
print ("\ttya") # Transfer character VRAM position from Y to stack pointer
@ -43,15 +44,16 @@ def main(argv):
charOriginY = charY*CHAR_HEIGHT
for charRow in reversed(range(0,CHAR_HEIGHT)):
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]))
# Print a comment to make generated source easier to understand
print ("\t; Line %d, Pixel values: " % charRow, end="")
for grouping in range(0,CHAR_WIDTH,4):
print("%x%x%x%x " %
(pixels[charOriginY+charRow][charOriginX+0+grouping],
pixels[charOriginY+charRow][charOriginX+1+grouping],
pixels[charOriginY+charRow][charOriginX+2+grouping],
pixels[charOriginY+charRow][charOriginX+3+grouping]), end="")
print ("")
nextRowDelta = 160
localStackList = []
@ -67,20 +69,27 @@ def main(argv):
requiredStackIndex = charCol/2
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
# Case 1 : All chroma, so let stack advance with no work
pass
elif (nibbles[0]!=CHROMA and nibbles[1]!=CHROMA and nibbles[2]!=CHROMA and nibbles[3]!=CHROMA):
# Case 2 : No chroma, so fast push
offsetNeeded = (CHAR_WIDTH/2-requiredStackIndex) - rowPushTotal - 2
if (offsetNeeded>0):
print ("\ttsc") # Advance stack to position needed for our two byte push
print ("\tsec") # Note that PEA needs a little +1 to put bytes in the place we expect
print ("\tsbc #%d" % (offsetNeeded+1))
print ("\tsbc #%d" % (offsetNeeded))
print ("\ttcs")
nextRowDelta -= offsetNeeded
print ("\tpea $%04x" % word) # Case 2 : No chroma, so fast push
nextRowDelta -= 3
rowPushTotal += (3+offsetNeeded)
else:
offsetNeeded=0
print ("\tpea $%04x" % word)
nextRowDelta -= 2
rowPushTotal += (2+offsetNeeded)
else:
mask = 0xFFFF # Case 3 : Mixed chroma, so mask and or
# Case 3 : Mixed chroma, so mask and or
mask = 0xFFFF
if (nibbles[0]!=CHROMA):
mask = mask & 0xFF0F
if (nibbles[1]!=CHROMA):
@ -114,7 +123,7 @@ def main(argv):
rowPushTotal = CHAR_WIDTH/2
nextRowDelta -= cleanupPush
extraReach = rowPushTotal - CHAR_WIDTH/2
extraReach = rowPushTotal - CHAR_WIDTH/2 + 1 # Amount to "reach back" from one byte past end of row so LDA/STA can fill in skipped pixels
for stackEntry in localStackList:
print ("\tlda %d,S" % (stackEntry[0] + extraReach)) # Blend mask, sprite, and background
print ("\tand #$%04x" % stackEntry[1])

View File

@ -25,6 +25,7 @@
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>"; };
7076E9252A5F9F540006E295 /* font16x16.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = font16x16.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>"; };
@ -85,6 +86,7 @@
70E9D8631F2BD95400555C19 /* Makefile */,
70BDCBC92006AD5F00CB51F1 /* linkerConfig */,
7076E9232A59113F0006E295 /* font8x8.s */,
7076E9252A5F9F540006E295 /* font16x16.s */,
7076E9242A5A4A8E0006E295 /* fontEngine.s */,
7076E9222A57AED90006E295 /* CompileFont.py */,
70FE79D21F8814A600E0095C /* MerlinToCA65.sh */,

View File

@ -71,8 +71,9 @@ terrain_e1:
fonts:
rm -rf $(FONTBANK)
./CompileFont.py 8 8 32 14 "Art/Assets/Font8x8.gif" > font8x8.s
@PATH=$(PATH):/usr/local/bin; $(CL65) -t apple2enh --cpu 65816 --start-addr 0000 -lfonts.lst fontEngine.s -o $(FONTBANK)
./CompileFont.py 8 8 32 14 "font8" "Art/Assets/Font8x8.gif" > font8x8.s
./CompileFont.py 16 16 32 14 "font16" "Art/Assets/Font16x16.gif" > font16x16.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
clean:

15582
font16x16.s Normal file

File diff suppressed because it is too large Load Diff

4094
font8x8.s

File diff suppressed because it is too large Load Diff

View File

@ -41,7 +41,7 @@ renderStringLoop:
; Calculate VRAM pointer for position of next character
lda SCRATCHL
sec
sbc #4
sbc #8
sta SCRATCHL
bra renderStringLoop
@ -64,7 +64,7 @@ renderChar:
asl
tax
FASTGRAPHICS
jmp (characterJumpTable,x)
jmp (font16characterJumpTable,x)
renderCharJumpReturn: ; Compiled glyphs jump back here. Can't rts because stack is turboborked
SLOWGRAPHICS
@ -72,6 +72,7 @@ RESTORE_AXY
rts
.include "font8x8.s"
.include "font16x16.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

View File

@ -71,7 +71,7 @@ beginGameplay:
; Test font renderer
lda #testString
sta PARAML0
ldy #$3000
ldy #$4430 ; Correct start of line address for 16 wide: $4bc7
jsl $050000
bra gameplayLoop
testString:

View File

@ -209,6 +209,28 @@ loadData:
ldy #0
jsr copyBytes
EMULATION
; Load rest of font data into bank 0 (needed if font size exceeds BUFFERSIZE)
jsr PRODOS
.byte $ca
.addr fileRead
bne ioErrorJmp
; Close the file
jsr PRODOS
.byte $cc
.addr fileClose
NATIVE
; Copy rest of font data into bank 5 (needed if font size exceeds BUFFERSIZE)
ldx fileReadLen
txa
lda #5
ldy #BUFFERSIZE
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