Motivated by Wilson's question Can a Commodore 64 use two screenmodes on one scanline? I tried to implement a simple example that polls the beginning of a rasterline and then switches the screen mode in the middle. My code so far:
c000 78 SEI c001 A2 19 LDX #$19 ;value for left half c003 A0 39 LDY #$39 ;value for right half c005 AD 12 D0 LDA $D012 c008 CD 12 D0 CMP $D012 c00b F0 FB BEQ $C008 ; wait until rasterline changed c00d 29 07 AND #$07 c00f F0 12 BEQ $C023 ;skip badline c011 8E 11 D0 STX $D011 ;left side with text mode c014 EA NOP ;wait 2 cycles c015 EE FF FF INC $FFFF ;wait 6 cycles c018 EE FF FF INC $FFFF ;wait 6 cycles c01b A5 FF LDA $FF ;wait 3 cycles c01d 8C 11 D0 STY $D011 ;right side with hires mode c020 4C 05 C0 JMP $C005 c023 EA NOP ;burn some cycles c024 4C 05 C0 JMP $C005
I ran into two problems here: In lines with badlines the VIC stuns the CPU during the time when the program should switch the screen mode. For that reason I skip the bad lines in above code, resulting in these horizontal lines. I tried to manipulate bits 0-2 in $D011 to surpress bad lines, but then the screen was not drawn properly. Is there a possibility to skip bad lines while still having a properly drawn screen?
Second issue: When I start the program (e.g. by
SYS 49152) I get a varying offset of some cycles from the actual start of a rasterline, because my busy waiting loop is 4+2 cycles long. This shows itself in the split line being shifted to the left or right, however within my program I don't know how to detect or correct this. Any idea how to remove this start jitter?