diff --git a/asmgen.py b/asmgen.py index fd532fc..fe05f71 100755 --- a/asmgen.py +++ b/asmgen.py @@ -934,15 +934,16 @@ class BackingStoreDriver(Listing): class FastFont(Listing): - def __init__(self, assembler, screen, font, double_buffer): + def __init__(self, assembler, screen, font, double_buffer, byte_width=1, byte_height=8): Listing.__init__(self, assembler) self.slug = "fastfont" - self.generate_table(screen, "H1", 0x2000) + self.row_slug = "TransposedFontRow" + self.generate_table(screen, "H1", 0x2000, byte_width, byte_height) if double_buffer: - self.generate_table(screen, "H2", 0x4000) - self.generate_transposed_font(screen, font) + self.generate_table(screen, "H2", 0x4000, byte_width, byte_height) + self.generate_transposed_font(screen, font, byte_width, byte_height) - def generate_table(self, screen, suffix, hgrbase): + def generate_table(self, screen, suffix, hgrbase, byte_width, byte_height): label = "FASTFONT_%s" % suffix self.label(label) @@ -950,46 +951,51 @@ class FastFont(Listing): # taking the hi/lo bytes of an address - 1 self.comment("A = character, X = column, Y = row; A is clobbered, X&Y are not") self.asm("pha") - self.asm("lda %s_JMP_HI,y" % label) - self.asm("sta %s_JMP+2" % label) - self.asm("lda %s_JMP_LO,y" % label) - self.asm("sta %s_JMP+1" % label) + self.asm(f"lda {label}_JMP_HI,y") + self.asm(f"sta {label}_JMP+2") + self.asm(f"lda {label}_JMP_LO,y") + self.asm(f"sta {label}_JMP+1") self.asm("sty scratch_0") self.asm("pla") self.asm("tay") - self.label("%s_JMP" % label) + self.label(f"{label}_JMP") self.asm("jmp $ffff\n") + num_rows = screen.screen_height // byte_height + # Bit-shift jump table for generic 6502 self.out() - self.label("%s_JMP_HI" % label) - for r in range(24): - self.asm(".byte >%s_%d" % (label, r)) - self.label("%s_JMP_LO" % label) - for r in range(24): - self.asm(".byte <%s_%d" % (label, r)) + self.label(f"{label}_JMP_HI") + for r in range(num_rows): + self.asm(f".byte >{label}_{r}") + self.label(f"{label}_JMP_LO") + for r in range(num_rows): + self.asm(f".byte <{label}_{r}") self.out() hgr1 = screen.generate_row_addresses(hgrbase) - for r in range(24): - self.label("%s_%d" % (label, r)) - for i in range(8): - self.asm("lda TransposedFontRow%d,y" % i) - self.asm("sta $%04x,x" % (hgr1[r*8 + i])) + for r in range(num_rows): + self.label(f"{label}_{r}") + for b in range(byte_width): + for h in range(byte_height): + self.asm(f"lda {self.row_slug}{b}_{h},y") + self.asm("sta $%04x,x" % (hgr1[r*byte_height + h] + b)) self.asm("ldy scratch_0") self.asm("rts") self.out() - def generate_transposed_font(self, screen, font): + def generate_transposed_font(self, screen, font, byte_width, byte_height): with open(font, 'rb') as fh: data = fh.read() num_bytes = len(data) - num_chars = num_bytes // 8 - for r in range(8): - self.label("TransposedFontRow%d" % r) - for i in range(num_chars): - index = i * 8 + r - self.byte("$%02x" % data[index], 16) + char_size = byte_height * byte_width + num_chars = num_bytes // char_size + for h in range(byte_height): + for b in range(byte_width): + self.label(f"{self.row_slug}{b}_{h}") + for i in range(num_chars): + index = i * char_size + (h * byte_width + b) + self.byte("$%02x" % data[index], 16) class CompiledFastFont(Listing): @@ -1522,6 +1528,7 @@ if __name__ == "__main__": parser.add_argument("-d", "--double-buffer", action="store_true", default=False, help="add code blit to either page (default: page 1 only)") parser.add_argument("-g", "--damage", action="store_true", default=False, help="add code to report size of sprite upon return. Can be used in a damage list to restore an area from a pristine source.") parser.add_argument("-f", "--font", action="store", default="", help="generate a fast font blitter for text on the hgr screen using the specified binary font file") + parser.add_argument("--font-size", "--fs", action="store", default="1x8", help="specify font dimensions in bytes (default: %(default)s)") parser.add_argument("--compiled-font", action="store", default="", help="generate a font-compiled fairly fast font blitter for text on the hgr screen using the specified binary font file") parser.add_argument("-o", "--output-prefix", default="", help="Base name to create a set of output files. If not supplied, all code will be sent to stdout.") parser.add_argument("files", metavar="IMAGE", nargs="*", help="a PNG image [or a list of them]. PNG files must not have an alpha channel!") @@ -1603,8 +1610,16 @@ if __name__ == "__main__": if options.cols: listings.append(ColLookup(assembler, screen)) + if options.font_size: + w, h = options.font_size.lower().split("x", 1) + w = int(w) + h = int(h) + else: + w = 1 + h = 8 + if options.font: - listings.append(FastFont(assembler, screen, options.font, options.double_buffer)) + listings.append(FastFont(assembler, screen, options.font, options.double_buffer, w, h)) if options.compiled_font: listings.append(CompiledFastFont(assembler, screen, options.compiled_font, options.double_buffer)) diff --git a/demo/transposed_fonts/Makefile b/demo/transposed_fonts/Makefile index c248e26..2048e5b 100644 --- a/demo/transposed_fonts/Makefile +++ b/demo/transposed_fonts/Makefile @@ -3,7 +3,7 @@ ASSEMBLER = "mac65" ASMGEN = python ../../asmgen.py -TARGETS = TEST1A.BIN TEST1B.BIN TEST1C.BIN TEST1D.BIN TEST2.BIN test3--transposed_font.s TEST3.BIN +TARGETS = TEST1A.BIN TEST1B.BIN TEST1C.BIN TEST1D.BIN TEST2.BIN test3--transposed_font.s TEST3.BIN tiles2x2a.s TILES2X2A.BIN tiles4x4a.s TILES4X4A.BIN all: $(TARGETS) @@ -50,5 +50,23 @@ TEST3.BIN: driver.s test3--transposed_font.s atrcopy . assemble -f -s temp.s -r 0x5000 -o $@ atrcopy asmsgen_font_compare.dsk add $@ -f +tiles2x2a.s: ../../tiles/tiles_ramp_2x2.dat + $(ASMGEN) -a $(ASSEMBLER) -f ../../tiles/tiles_ramp_2x2.dat --fs 2x16 > tiles2x2a.s + +TILES2X2A.BIN: driver_2x2_tiles.s tiles2x2a.s + rm -f $@ + cat $^ > temp.s + atrcopy . assemble -f -s temp.s -r 0x5000 -o $@ + atrcopy asmsgen_font_compare.dsk add $@ -f + +tiles4x4a.s: ../../tiles/tiles_ramp_4x4.dat + $(ASMGEN) -a $(ASSEMBLER) -f ../../tiles/tiles_ramp_4x4.dat --fs 4x32 > tiles4x4a.s + +TILES4X4A.BIN: driver_4x4_tiles.s tiles4x4a.s + rm -f $@ + cat $^ > temp.s + atrcopy . assemble -f -s temp.s -r 0x5000 -o $@ + atrcopy asmsgen_font_compare.dsk add $@ -f + clean: rm -f asmsgen_font_compare.dsk $(TARGETS) temp.s temp.s.lst temp.s.err diff --git a/demo/transposed_fonts/asmsgen_font_compare.dsk b/demo/transposed_fonts/asmsgen_font_compare.dsk index 0695cd3..d338976 100644 Binary files a/demo/transposed_fonts/asmsgen_font_compare.dsk and b/demo/transposed_fonts/asmsgen_font_compare.dsk differ diff --git a/demo/transposed_fonts/driver_2x2_tiles.s b/demo/transposed_fonts/driver_2x2_tiles.s new file mode 100644 index 0000000..05d1597 --- /dev/null +++ b/demo/transposed_fonts/driver_2x2_tiles.s @@ -0,0 +1,111 @@ + *= $0006 + +FIRST_CHAR_OF_SCREEN .ds 1 +FIRST_CHAR_OF_LINE .ds 1 +CURRENT_CHAR .ds 1 +FRAME_COUNT .ds 1 + + *= $00eb +hgr_ptr .ds 2 +font_ptr .ds 2 + + *= $00fa +scratch_0 .ds 1 +scratch_x .ds 1 +scratch_y .ds 1 + + + *= $5000 + +start_set + jsr set_hires + jsr clrscr + jsr driver + jsr set_text + rts + brk + +driver + lda #$00 + sta FIRST_CHAR_OF_SCREEN + lda #64 + sta FRAME_COUNT +page_loop + jsr page + dec FRAME_COUNT + bne page_loop + rts + +; os memory map +KEYBOARD = $c000 +KBDSTROBE = $c010 +CLRTEXT = $c050 +SETTEXT = $c051 +CLRMIXED = $c052 +SETMIXED = $c053 +TXTPAGE1 = $c054 +TXTPAGE2 = $c055 +CLRHIRES = $c056 +SETHIRES = $c057 + + +set_hires bit CLRTEXT ; start with HGR page 1, full screen + bit CLRMIXED + bit TXTPAGE1 + bit SETHIRES + rts + +set_text bit SETTEXT + bit CLRMIXED + bit TXTPAGE1 + bit CLRHIRES + rts + +; clear hires page 1 only +clrscr lda #$20 + sta clrscr_smc+2 + lda #0 + ldy #0 +clrscr_smc sta $ff00,y + iny + bne clrscr_smc + inc clrscr_smc+2 + ldx clrscr_smc+2 + cpx #$40 + bcc clrscr_smc + rts + + *= $5074 + +page + inc FIRST_CHAR_OF_SCREEN + lda FIRST_CHAR_OF_SCREEN + sta FIRST_CHAR_OF_LINE + + ldy #$00 +line_loop + ldx #$00 + lda FIRST_CHAR_OF_LINE + sta CURRENT_CHAR +char_loop + lda CURRENT_CHAR + jsr font_test + inc CURRENT_CHAR + lda CURRENT_CHAR + and #$1f + sta CURRENT_CHAR + inx + inx + cpx #40 + bcc char_loop + + inc FIRST_CHAR_OF_LINE + iny + cpy #12 + bcc line_loop + + rts + + + +font_test diff --git a/demo/transposed_fonts/driver_4x4_tiles.s b/demo/transposed_fonts/driver_4x4_tiles.s new file mode 100644 index 0000000..29cb8ea --- /dev/null +++ b/demo/transposed_fonts/driver_4x4_tiles.s @@ -0,0 +1,113 @@ + *= $0006 + +FIRST_CHAR_OF_SCREEN .ds 1 +FIRST_CHAR_OF_LINE .ds 1 +CURRENT_CHAR .ds 1 +FRAME_COUNT .ds 1 + + *= $00eb +hgr_ptr .ds 2 +font_ptr .ds 2 + + *= $00fa +scratch_0 .ds 1 +scratch_x .ds 1 +scratch_y .ds 1 + + + *= $5000 + +start_set + jsr set_hires + jsr clrscr + jsr driver + jsr set_text + rts + brk + +driver + lda #$00 + sta FIRST_CHAR_OF_SCREEN + lda #64 + sta FRAME_COUNT +page_loop + jsr page + dec FRAME_COUNT + bne page_loop + rts + +; os memory map +KEYBOARD = $c000 +KBDSTROBE = $c010 +CLRTEXT = $c050 +SETTEXT = $c051 +CLRMIXED = $c052 +SETMIXED = $c053 +TXTPAGE1 = $c054 +TXTPAGE2 = $c055 +CLRHIRES = $c056 +SETHIRES = $c057 + + +set_hires bit CLRTEXT ; start with HGR page 1, full screen + bit CLRMIXED + bit TXTPAGE1 + bit SETHIRES + rts + +set_text bit SETTEXT + bit CLRMIXED + bit TXTPAGE1 + bit CLRHIRES + rts + +; clear hires page 1 only +clrscr lda #$20 + sta clrscr_smc+2 + lda #0 + ldy #0 +clrscr_smc sta $ff00,y + iny + bne clrscr_smc + inc clrscr_smc+2 + ldx clrscr_smc+2 + cpx #$40 + bcc clrscr_smc + rts + + *= $5074 + +page + inc FIRST_CHAR_OF_SCREEN + lda FIRST_CHAR_OF_SCREEN + sta FIRST_CHAR_OF_LINE + + ldy #$00 +line_loop + ldx #$00 + lda FIRST_CHAR_OF_LINE + sta CURRENT_CHAR +char_loop + lda CURRENT_CHAR + jsr font_test + inc CURRENT_CHAR + lda CURRENT_CHAR + and #$0f + sta CURRENT_CHAR + inx + inx + inx + inx + cpx #40 + bcc char_loop + + inc FIRST_CHAR_OF_LINE + iny + cpy #6 + bcc line_loop + + rts + + + +font_test diff --git a/demo/transposed_fonts/test3--transposed_font.s b/demo/transposed_fonts/test3--transposed_font.s index 1435f3e..2148504 100644 --- a/demo/transposed_fonts/test3--transposed_font.s +++ b/demo/transposed_fonts/test3--transposed_font.s @@ -74,463 +74,463 @@ FASTFONT_H1_JMP_LO .byte FASTFONT_H1_0 + .byte >FASTFONT_H1_1 + .byte >FASTFONT_H1_2 + .byte >FASTFONT_H1_3 + .byte >FASTFONT_H1_4 + .byte >FASTFONT_H1_5 + .byte >FASTFONT_H1_6 + .byte >FASTFONT_H1_7 + .byte >FASTFONT_H1_8 + .byte >FASTFONT_H1_9 + .byte >FASTFONT_H1_10 + .byte >FASTFONT_H1_11 +FASTFONT_H1_JMP_LO + .byte FASTFONT_H1_0 + .byte >FASTFONT_H1_1 + .byte >FASTFONT_H1_2 + .byte >FASTFONT_H1_3 + .byte >FASTFONT_H1_4 + .byte >FASTFONT_H1_5 +FASTFONT_H1_JMP_LO + .byte