Below is my take on a tile draw routine for the text screen, try not to be too harsh on lil old novice me .
The tiles are 2x2 characters in size and are all drawn using the same colour.
I was hoping to get some feedback/possible speed optimization suggestions before I put this to use in my projects, maybe there's a better way to store the data that would facilitate faster processing of it by a modified draw routine etc.
At the moment his code can draw approx. 5,120 tiles per second using some pretty slack loop code.
Cheers
KingTrode / Jim
Code: Select all
; ******************************************
; * Commodore VIC-20 2x2 Tile Draw Test *
; * By Richard Croskell (KingTrode) 2013 *
; * *
; * Requires no RAM Expansion *
; * *
; * Source Code Format: 64TASS Assembler *
; ******************************************
.cpu 6502
.include "..\Include\colours.asm"
.include "..\Include\macros.asm"
; *******************************
; * Zero Page Address Storage *
; *******************************
TileAddrLo = $F9
TileAddrHi = $FA
ScrAddrLo = $FB
ScrAddrHi = $FC
ClrAddrLo = $FD
ClrAddrHi = $FE
; ***********************************
; * Non Zero Page Address Storage *
; ***********************************
PenColour = $0286
VicRegs = $9000
ColourBase = $9600
ScreenBase = $1E00
CharRom = $8000
GetIn = $FFE4
; *************************
; * Some Useful Equates *
; *************************
; ***************************
; * ORG Directive options *
; ***************************
; *= $0401 ; 3k VIC
; *= $1001 ; Unexpanded VIC
; *= $1201 ; 8k+ VIC
*= $1001 ; 0k VIC-20
.word NextLine ; BASIC pointer to next line
.word 2013 ; BASIC line number = 2013
.byte $9E ; BASIC token code for "SYS" command
.byte $30 + ((SysAddr/1000)//10) ; Calculate 2nd digit of SYS_ADDRESS
.byte $30 + ((SysAddr/100)//10) ; Calculate 3rd digit of SYS_ADDRESS
.byte $30 + ((SysAddr/10)//10) ; Calculate 4th digit of SYS_ADDRESS
.byte $30 + (SysAddr//10) ; Calculate 5th digit of SYS_ADDRESS
.byte $00 ; BASIC end of line marker
NextLine
.word $0000 ; BASIC end of program
; ******************************
; * Start of executable code *
; ******************************
SysAddr
lda #3
ldx #20
ldy #21
jsr DrawTile ; Draw Tile #3 @ 20,21
rts ; Return to Caller
; *****************************
; * Draw 2x2 Tile on screen *
; * A = Tile Number *
; * X = Column 0-20 *
; * Y = Row 0-21 *
; *****************************
DrawTile
pha
jsr CalcXYAddr ; Setup screen / colour pointers
pla
tay
lda TileAddrTabLo,y
sta TileAddrLo
lda TileAddrTabHi,y
sta TileAddrHi ; Setup Tile Definition pointer
lda TileClrTab,y
pha ; Get tile colour and save
jsr DrawTileRow ; Draw top row of Tile
clc
lda ScrAddrLo
adc #22
sta ScrAddrLo
sta ClrAddrLo
bcc DrawTileSkip1
inc ScrAddrHi
inc ClrAddrHi ; Point to next screen row
DrawTileSkip1
clc
lda TileAddrLo
adc #2
sta TileAddrLo
bcc DrawTileSkip2
inc TileAddrHi ; Point to next Tile row
DrawTileSkip2
pla
jsr DrawTileRow ; Draw bottom row of tile
rts
DrawTileRow
ldy #0
sta (ClrAddrLo),y
iny
sta (ClrAddrLo),y ; Set Tile colour left/right cells
dey
lda (TileAddrLo),y
sta (ScrAddrLo),y
iny
lda (TileAddrLo),y
sta (ScrAddrLo),y ; Draw Left/Right chars
rts
; *************************************************************
; * Calculate screen/colour address from .X (Col) / .Y (Row) *
; *************************************************************
CalcXYAddr
txa
clc
adc ScrAddrTabLo,Y
sta ScrAddrLo
sta ClrAddrLo
lda ScrAddrTabHi,Y
adc #$00
sta ScrAddrHi
clc
adc #$78
sta ClrAddrHi
rts
; **********************************************
; * Screen Lo Byte address rows offset table *
; **********************************************
ScrAddrTabLo
.byte $00,$16,$2c,$42,$58,$6e,$84,$9a,$b0,$c6,$dc,$f2
.byte $08,$1e,$34,$4a,$60,$76,$8c,$a2,$b8,$ce,$e4
; **********************************************
; * Screen Hi Byte address rows offset table *
; **********************************************
ScrAddrTabHi
.byte $1e,$1e,$1e,$1e,$1e,$1e,$1e,$1e,$1e,$1e,$1e,$1e
.byte $1f,$1f,$1f,$1f,$1f,$1f,$1f,$1f,$1f,$1f,$1f
; ********************************
; * Tile Lo Byte address table *
; ********************************
TileAddrTabLo
.byte <Tile00,<Tile01,<Tile02,<Tile03,<Tile04,<Tile05
; ********************************
; * Tile Lo Byte address table *
; ********************************
TileAddrTabHi
.byte >Tile00,>Tile01,>Tile02,>Tile03,>Tile04,>Tile05
; ***********************
; * Tile Colour Table *
; ***********************
TileClrTab
.byte Yellow,Red,Blue,Black,Green,Purple
; *****************************
; * Tile Definitions (2x2) *
; * *
; * 0 = Top Left Char Code *
; * 1 = Top Right Char Cod *
; * 2 = Bot Left Char Code *
; * 3 = Bot Right Char Code *
; *****************************
Tile00
.byte $00,$01,$02,$03
Tile01
.byte $04,$05,$06,$07
Tile02
.byte $08,$09,$0a,$0b
Tile03
.byte $0c,$0d,$0e,$0f
Tile04
.byte $10,$11,$12,$13
Tile05
.byte $14,$15,$16,$17