I have completed the design for my next video project. It consists of a 320x200 pixel window with 8 bits of color for each pixel. Thats 64,000 bytes for a complete display window. I want to test/debug using a pattern generator program.
I want it to fill the display buffer ($010000 - $01FFFF) with a color pattern, wait 10 seconds, inc the color pattern (repeating all 256 patterns), and refill the buffer.
I am using a 65816 running at 7.159MHz with 512K of RAM. I'll need to run the processor in native mode in order to access RAM above 64K.
This is my first 65816 program and just want you "experts" to check my code. I'm not looking to optimize for speed or size, I just want it to work as expected. My assember does not support the 65816 opcodes so I use the .byte psuedo-op to correct it.
Will this code do what I want?
Code: Select all
ptr = $10 ; zero page pointer (2 byte)
chr = $12 ; color character
Reset SEI ; diable interupts
CLD ; clear decimal mode
LDX #$FF ;
TXS ; init stack pointer
CLC ; Clear carry flag, pre for native mode
.byte $FB ; XCE - Set native Mode ON, leave in 8 bit reg mode
lda #$00 ; init variable
sta chr
sta ptr
sta ptr+1 ; init pointer to $0000
; set Data Back register to $010000, Video display buffer
lda #$01 ; Page 1 for video mem
pha ; put on stack
.byte $AB ; PLB -> set DBR
; Fill vid buffer
Loop1 lda chr ; get color code
Loop2 sta (ptr) ; save to vid buffer
inc ptr ; inc zero page pointer
bne Loop2 ; do inner loop if not zero
inc ptr+1 ; inc zero page pointer
bne Loop2 ; do outer loop if not zero
; we exit the loop above with ptr pointing back to $0000
; done, now wait
ldx #$00 ; basic 3 stage delay loop
ldy #$00 ; all stages loop 256 times
lda #$00 ; at 7.15MHz, expect it
Loop3 dec ; to take 11.5 seconds
bne Loop3
dex
bne Loop3
dey
bne Loop3
; set next color and repeat
inc chr ; inc to next color pattern
jmp Loop1 ; repeat Fill and delay forever
Daryl