Basically we have a double buffer that needs to be block moved into the display memory.
The code should be for a standard 6502 CPU. A 160x160 pixel buffer has to be transferred into a 256x256 monochrome pixel display
So we are talking about 3200 bytes.
My code example takes about 52ms for the transfer (or 16.25 usec per byte) and that is three times the frame rate at 60Hz.
The 160x160 pixel buffer needs to be position on the display in Y- and X-direction in line/byte increments.
Hope to find a faster method that may be obvious, but I can't figure out.
Thomas
Code: Select all
; Double buffer fast block move for standard 6502 CPU
; Transfer of an 160x160 pixel buffer into a 256x256 pixel display (monochrome)
; 60 Hz full frame time is about 16.6ms (60Hz)
Hires=$8000+512 ; pixel display 256x256 (8kb) start at line 16
Buffer=$6c00 ; double buffer size 5120 bytes, 3200 bytes used (160x160 pixel)
source=$13 ; Source address pointer
target=$15 ; Target address pointer
shift=5 ; shift byte offset of source data (variable)
offset=2 ; horizontal output display offset 2=16 pixel (basically fixed)
.org $1000 ; transfer time 51950 cycles (almost 52msec) needed for 3200 bytes
lda #>Buffer
sta source+1
lda #>Hires
sta target+1
ldx #19 ; 20*8 lines to transfer
L1: lda #20+shift ; variable source offset for horizonlal shifts to display output
sta source
lda #20+offset ; Output at display + 16 pixel
sta target
jsr transfer
inc source+1 ; next eight lines + 256 byte
inc target+1
dex
bpl L1
brk
transfer: ; transfer group of 8 lines
ldy #$00
lda (source),y
sta (target),y
ldy #$20
lda (source),y
sta (target),y
ldy #$40
lda (source),y
sta (target),y
ldy #$60
lda (source),y
sta (target),y
ldy #$80
lda (source),y
sta (target),y
ldy #$A0
lda (source),y
sta (target),y
ldy #$C0
lda (source),y
sta (target),y
ldy #$E0
lda (source),y
sta (target),y
dec source
dec target ; dec lower byte of address
lda target
cmp #offset-1
bne transfer
rts