Even after fixing the problem with bus contention my computer still would not boot each time correctly. That caused some head banging - until I noticed that the problems would not go away even if neither address- nor data-bus nor any control lines were connected. The problem persisted as soon as the power lines were connected. So I concluded my power distribution is not clean enough. I routed therefore 2 thick cables around the breadboards, and connected each short power strip at least twice to the main lines. And hurra - the system now boots successfully even when completely wired.
I also wrote code to initialize the sync ram. For each pixel in a 640x350 image (or 800x449 pixel including the porches) I have one byte in the sync ram - fitting neatly in 10bit x and 9 bit y counters, aka 19bit (512kbyte) DRAM. The same bytes also generate counter signals for y, reset for x and y counters and the blank signal. The bits are defined as:
Code:
hsync bit 0
vsync bit 1
Blank bit 2
not used
not used
yreset bit 5
y-clock bit 6
xreset bit 7
All bits except hsync default to logic low. The definition of the VGA signal I want to create is:
Code:
Scanline part Pixels
Visible area 640
Front porch 16
Sync pulse 96
Back porch 48
Whole line 800
Vertical timing (frame)
Polarity of vertical sync pulse is positive.
Frame part Lines
Visible area 400
Front porch 12
Sync pulse 2
Back porch 35
Whole frame 449
That means some of the building blocks are larger than 256 lines and do not fit into a single byte. So I split all of them into groups
Code:
Horizontal >> Visible area Visible area Visible area Front Porch Sync Pulse Back Porch Back Porch Fillup
v Vertical v 0/0 | 255 511 639 655 751 767 798 1023
---------------------------------------------------------------------------------------------------------------------------------
Visible area 255 | 1 1 1 5 4 5 5 197
Visible area 399 | 1 1 1 5 4 5 5 197
Front porch 411 | 5 5 5 5 4 5 5 197
Sync pulse 413 | 7 7 7 7 6 7 7 199
Back porch 448 | 5 5 5 5 4 5 5 197
Fillup 511 | 165 165 165 133 133 165 165 229
For instance - I have a visible block going from x=0/y=0 to x=255/y=255 and all the bytes in that block must be equal to 1. Another block goes from x=0/y=256 to x=255/y=399. And so on.
This is the code I came up with:
Code:
loop3: ;--------------------------------------|
ldy VGA_Y_BLK_INDEX ; which Y group are we working on? |
lda YVALS,y ; load the number of lines |
clc ; |
adc VGA_TARGET_Y ; add new number of lines to target |
sta VGA_TARGET_Y ; |
; |
loop2: ; ---------------|------------| |
stx VGA_Y_REG ; | | |
ldy VGA_X_BLK_INDEX ; | | |
lda (VGA_SYNC_DATA),y ; | | |
pha ; | | |
lda (VGA_XBLKS),y ; | | |
sta VGA_CUR_X_BLK_VALUE ; | | |
tay ; | | |
pla ; | loop | loop | loop
loop1: ; | over | over | over
sta (VGA_VIDMEM_PTR),y ;--| main loop | all | all | all
DEY ; | over single | X groups | lines | y
bne loop1 ;--| X group | in | in | groups
lda VGA_VIDMEM_PTR ; | single | single |
clc ; | Y line | y |
adc VGA_CUR_X_BLK_VALUE ; | | group |
sta VGA_VIDMEM_PTR ; | | |
bne noincp ; | | |
inc VGA_VIDMEM_PTR+1 ; | | |
noincp: ; | | |
inc VGA_X_BLK_INDEX ; | | |
lda VGA_X_BLK_INDEX ; | | |
cmp #8 ; | | |
bne loop2 ; ---------------| | |
lda VGA_VIDMEM_PTR_SAVEL ; restore VGA_VIDMEM_PTR | |
sta VGA_VIDMEM_PTR ; to saved value | |
lda VGA_VIDMEM_PTR_SAVEH ; | |
sta VGA_VIDMEM_PTR+1 ; | |
lda #0 ; set X-group index to 0 | |
sta VGA_X_BLK_INDEX ; | |
inx ; increase line counter | |
bne SKIPINCREASE_LC ; in case y lines roll over | |
lda VGA_VIDMEM_PTR_SAVEH ; increase high byte of | |
clc ; VGA_VIDMEM_PTR_SAVE by 4 | |
adc #4 ; | |
sta VGA_VIDMEM_PTR_SAVEH ; | |
SKIPINCREASE_LC: ; | |
cpx VGA_TARGET_Y ; | |
; brk ; | |
; nop ; | |
; nop ; | |
bne loop2 ; ----------------------------| |
lda #'x' ; |
jsr printChar ; |
lda VGA_SYNC_DATA ; increase VGA SYNC_DATA |
clc ; pointer to next row |
adc #8 ; |
sta VGA_SYNC_DATA ; |
inc VGA_Y_BLK_INDEX ; increase Y block index |
lda VGA_Y_BLK_INDEX ; |
cmp #6 ; if still blocks to work, loop |
bne loop3 ; -------------------------------------|
jsr printEOL
.linecont + ; Allow line continuations
XVALS: .byte 0,0,128,16,96,16,31,225
YVALS: .byte 0,144,12,2,35,63
DATA: .byte 1,1,1,5,4,5,5,197, \
1,1,1,5,4,5,5,197, \
5,5,5,5,4,5,5,197, \
7,7,7,7,6,7,7,197, \
5,5,5,5,4,5,5,197, \
165,165,165,133,133,165,165,229
Any suggestions how to improve on hat would be welcome!