From ef52e61be3dc174d10aecb545a7e1cbd326976e8 Mon Sep 17 00:00:00 2001 From: Rob McMullen Date: Wed, 20 Sep 2017 09:55:27 -0700 Subject: [PATCH] Font demo program comparing my transposed font character generator to standard type character generators --- Makefile | 13 +++--- drawfont.s | 113 +++++++++++++++++++++++++++++++++++++++++++++++++++++ fonttest.s | 105 +++++++++++++++++++++++++++++++++++++++++++++++++ slowfont.s | 57 +++++++++++++++++++++++++++ 4 files changed, 283 insertions(+), 5 deletions(-) create mode 100644 drawfont.s create mode 100644 fonttest.s create mode 100644 slowfont.s diff --git a/Makefile b/Makefile index 03e7c06..6658b29 100644 --- a/Makefile +++ b/Makefile @@ -26,16 +26,19 @@ colortest.dsk: asmgen.py colortest.s bwsprite.s atasm -ocolortest.xex colortest.s -Lcolortest.var -gcolortest.lst atrcopy colortest.dsk boot -b colortest.xex --brun 6000 -f -cpbg-sprite-driver.s: asmgen.py $(BWSPRITE) +cpbg-asmgen-driver.s: asmgen.py $(BWSPRITE) python asmgen.py -a mac65 -p 6502 -s hgrbw -m -k -d -g -f fatfont128.dat -o cpbg $(BWSPRITE) $(COLORSPRITE) -cpbg.xex: cpbg.s cpbg-sprite-driver.s +cpbg.xex: cpbg.s cpbg-asmgen-driver.s atasm -mae -ocpbg.xex cpbg.s -Lcpbg.var -gcpbg.lst cpbg.dsk: asmgen.py cpbg.xex atrcopy cpbg.dsk boot -b cpbg.xex --brun 6000 -f -fonttest.dsk: fonttest.s fatfont.s +fonttest-asmgen-driver.s: asmgen.py fatfont128.dat + python asmgen.py -a mac65 -p 6502 -s hgrbw -f fatfont128.dat -r -o fonttest + +fonttest.dsk: fonttest.s fatfont.s fonttest-asmgen-driver.s slowfont.s atasm -ofonttest.xex fonttest.s -Lfonttest.var -gfonttest.lst atrcopy fonttest.dsk boot -b fonttest.xex --brun 6000 -f @@ -43,5 +46,5 @@ clean: rm -f rowlookup.s collookupbw.s collookupcolor.s rm -f bwtest.dsk bwtest.xex bwtest.var bwtest.lst rm -f colortest.dsk colortest.xex colortest.var colortest.lst - rm -f cpbg.dsk cpbg.xex cpbg.var cpbg.lst cpbg-sprite-driver.s cpbg-bwsprite.s cpbg-hgrcols-7x1.s cpbg-hgrrows.s - rm -f fonttest.dsk fonttest.xex fonttest.var fonttest.lst + rm -f cpbg.dsk cpbg.xex cpbg.var cpbg.lst cpbg-asmgen-driver.s cpbg-bwsprite.s cpbg-hgrcols-7x1.s cpbg-hgrrows.s + rm -f fonttest.dsk fonttest.xex fonttest-asmgen-driver.s fonttest.var fonttest.lst diff --git a/drawfont.s b/drawfont.s new file mode 100644 index 0000000..320a9b7 --- /dev/null +++ b/drawfont.s @@ -0,0 +1,113 @@ +DrawHexByte + PHA ; save low nibble + ROR ; shift high nibble + ROR ; to low nibble + ROR ; + ROR ; + JSR DrawHexNib ; print high nib in hex + PLA ; pritn low nib in hex +DrawHexNib + AND #$F ; base 16 + TAX ; + LDA NIB2HEX,X ; nibble to ASCII +; ORG $0310 ; Listing 5 +DrawChar + JMP DrawCharCol +; ORG $0313 ; Listing 9 +SetCursorRow + LDA TEXTROW_L,X ; TEXTROW_L[ row ] + STA hgrptr + LDA TEXTROW_H,X ; TEXTROW_H[ row ] + ORA HgrHi + STA hgrptr+1 + RTS +; ORG $0321 ; Listing 11 + + + + +SetCursorColRow + STX hgrptr + LDA TEXTROW_L,Y ; TEXTROW_L[ row ] + CLC + ADC hgrptr ; add column + STA hgrptr + LDA TEXTROW_H,Y ; TEXTROW_H[ row ] + ORA HgrHi + STA hgrptr+1 + RTS + NOP ; pad +; ORG $0335 ; Listing 6 +DrawCharColRow + PHA + JSR SetCursorRow + PLA +; ORG $033A ; Listing 7 +DrawCharCol ; A=%PQRstuvw + ROL ; C=P A=%QRstuvw? + ROL ; C=Q A=%Rstuvw?P + ROL ; C=R A=%stuvw?PQ + TAX ; X=%stuvw?PQ push glyph + AND #$F8 ; A=%stuvw000 + STA _LoadFont+1; AddressLo = (c*8) + TXA ; A=%stuvw?PQ pop glyph + AND #3 ; Optimization: s=0 implicit CLC ! + ROL ; C=s A=%00000PQR and 1 last ROL to get R + ADC #>FatFont ; += FontHi; Carry=0 since s=0 from above + STA _LoadFont+2; AddressHi = FontHi + (c/32) +; ORG $034C ; Listing 4a +_DrawChar1 + LDX hgrptr+1 + STX scratch_0 +; ORG $0350 ; Listing 1 +_DrawChar + LDX #7 +_LoadFont ; A = font[ offset ] + LDA FatFont,X + STA (hgrptr),Y ; screen[col] = A + CLC + LDA hgrptr+1 ; + ADC #4 ; screen += 0x400 + STA hgrptr+1 + DEX + BPL _LoadFont +; ORG $0363 ; Listing 4a +IncCursorCol + INY + LDX scratch_0 ; Move cursor back to top of scanline + STX hgrptr+1 + RTS +; ORG $0369 ; Listing 10 +SetCursorColRowYX + JSR SetCursorRow + CLC + TYA + ADC hgrptr + STA hgrptr + RTS +; ORG $037E ; Listing 12 +DrawString + STY tempaddr+0 + STX tempaddr+1 + LDY #0 +_ds1 LDA (tempaddr),Y + BEQ _ds2 ; null byte? Done + SEC + SBC #$20 + JSR DrawChar ; or DrawCharCol for speed + CPY #40 ; col < 40? + BCC _ds1 +_ds2 RTS + +; ORG $0390 ; Listing 8 +NIB2HEX + .byte "0123456789ABCDEF" +; ORG $03A0 ; Listing 9a +TEXTROW_L + .byte $00,$80,$00,$80,$00,$80,$00,$80 + .byte $28,$A8,$28,$A8,$28,$A8,$28,$A8 + .byte $50,$D0,$50,$D0,$50,$D0,$50,$D0 +TEXTROW_H + .byte $00,$00,$01,$01,$02,$02,$03,$03 + .byte $00,$00,$01,$01,$02,$02,$03,$03 + .byte $00,$00,$01,$01,$02,$02,$03,$03 diff --git a/fonttest.s b/fonttest.s new file mode 100644 index 0000000..9e1d699 --- /dev/null +++ b/fonttest.s @@ -0,0 +1,105 @@ +; os memory map +CLRTEXT = $c050 +SETTEXT = $c051 +CLRMIXED = $c052 +SETMIXED = $c053 +TXTPAGE1 = $c054 +TXTPAGE2 = $c055 +CLRHIRES = $c056 +SETHIRES = $c057 + +; Zero page locations we use (unused by Monitor, Applesoft, or ProDOS) +hgr_ptr = $06 +font_ptr = $08 +temp_row = $19 +temp_col = $1a +text_ptr = $1b +counter = $ce +scratch_0 = $d7 +start_char = $fc + + *= $6000 + +start + lda #0 + sta start_char + jsr filltext + +loop + ; copy the normal way + lda #slowfont + sta copytexthgr_dest_smc+2 + jsr copytexthgr + + ; copy using the fast font traspose + lda #FASTFONT_H1 + sta copytexthgr_dest_smc+2 + jsr copytexthgr + + jmp loop + + +copytexthgr + ldy #0 ; y is rows +copytexthgr_outer + lda textrow_h,y + ora #4 + sta copytexthgr_src_smc+2 + lda textrow_l,y + sta copytexthgr_src_smc+1 + ldx #0 ; x is columns +copytexthgr_src_smc + lda $ffff,x +copytexthgr_dest_smc + jsr $ffff + inx + cpx #32 + bcc copytexthgr_src_smc + iny + cpy #24 + bcc copytexthgr_outer + rts + + +filltext + ldy #0 ; Loop a bit + sty counter +ib_outer + lda textrow_h,y + sta text_ptr+1 + lda textrow_l,y + sta text_ptr + ldx start_char + ldy #0 +ib_inner + txa + adc #32 + sta (text_ptr),y + inx + iny + cpy #40 + bcc ib_inner + ldy counter + iny + sty counter + cpy #24 + bcc ib_outer + inc start_char ; change starting char for next time + rts + +textrow_l + .byte $00,$80,$00,$80,$00,$80,$00,$80 + .byte $28,$A8,$28,$A8,$28,$A8,$28,$A8 + .byte $50,$D0,$50,$D0,$50,$D0,$50,$D0 +textrow_h + .byte $04,$04,$05,$05,$06,$06,$07,$07 + .byte $04,$04,$05,$05,$06,$06,$07,$07 + .byte $04,$04,$05,$05,$06,$06,$07,$07 + +.include fatfont.s +.include slowfont.s +.include fonttest-asmgen-driver.s diff --git a/slowfont.s b/slowfont.s new file mode 100644 index 0000000..4ca068b --- /dev/null +++ b/slowfont.s @@ -0,0 +1,57 @@ +; traditional font renderer using normal font tables + +slowfont ; A = character, X = column, Y = row; A is clobbered, X&Y are not + stx temp_col ; save col to be returned to caller + sty temp_row ; save row to be returned to caller + + ; find address of glyph + sta font_ptr + lda #0 + sta font_ptr + 1 + asl font_ptr ; multiply by 8 + rol font_ptr + 1 + asl font_ptr + rol font_ptr + 1 + asl font_ptr + rol font_ptr + 1 + + clc ; add font table address to get pointer inside font table + lda #fatfont + adc font_ptr+1 + sta slowfont_loop_smc+2 + + lda hgrtextrow_l,y ; load address of first line of hgr text + sta hgr_ptr + lda hgrtextrow_h,y + sta hgr_ptr+1 + + ldx #0 + ldy temp_col ; col goes in y +slowfont_loop +slowfont_loop_smc + lda $ffff,x + sta (hgr_ptr),y + clc + lda #4 + adc hgr_ptr+1 + sta hgr_ptr+1 + inx + cpx #8 + bcc slowfont_loop + + ldx temp_col + ldy temp_row + rts + + +hgrtextrow_l + .byte $00,$80,$00,$80,$00,$80,$00,$80 + .byte $28,$A8,$28,$A8,$28,$A8,$28,$A8 + .byte $50,$D0,$50,$D0,$50,$D0,$50,$D0 +hgrtextrow_h + .byte $20,$20,$21,$21,$22,$22,$23,$23 + .byte $20,$20,$21,$21,$22,$22,$23,$23 + .byte $20,$20,$21,$21,$22,$22,$23,$23