AGDDeveloper Posted March 14, 2021 Share Posted March 14, 2021 Hello, I'm trying to get started writing some 2600 homebrew code, and I've written a very simple program to just set up a framework and get a good handle on the TIA timing. I'm using the current version of Stella to test my code. Right now, I just have it doing a simple loop where it counts down the 192 lines in the display region and stores the current value of the loop counter in PF1. When I run it in Stella, most of the time I get the predicted results, but sometimes I get the image scrunched in half. It looks like I'm inadvertently going into interlace mode, and that the resolution is cut in half, but I'm not certain that's the case or if so, why it's happening. Any insight you might offer would be greatly appreciated! Here's the code. I'm also attaching Stella screenshots of the expected and unexpected results. The unexpected results happen randomly, maybe 1 in 5 times. Thanks in advance! John init: lda #$00 ; Initialize some key registers. sta ENABL sta ENAM0 sta ENAM1 sta GRP0 sta GRP1 sta COLUBK sta PF0 sta PF1 sta PF2 sta COLUPF sta CTRLPF jmp main main: lda #$0 sta CTRLPF ; Zero out the PF control bits. lda #$2 sta VBLANK ; Turn vertical blanking on. sta WSYNC sta VSYNC ; Start VSYNC. ; The start of our main loop. .vsync: sta WSYNC sta WSYNC sta WSYNC ; There's our 3 scanlines of VSYNC. lda #$0 sta VSYNC ; Turn off VSYNC. lda #37 ; 37 scanlines in VBLANK for the upper border. clc .vblLoop: sta WSYNC sbc #1 bne .vblLoop .frame: lda #$0 sta VBLANK ; Stop vertical blanking. tya sta COLUPF ; Set a cycling Playfield color. dey lda #192 ; 192 scanlines in the visible region. clc .loop1: sta PF1 ; Store the current value of the loop counter in the PF1, to give us a pattern. sbc #1 sta WSYNC bne .loop1 lda #$2 sta VBLANK ; Start vertical blanking. lda #29 ; 29 lines of overscan (we'll do 30th line below, right before VSYNC.) clc .loop2: sta WSYNC sbc #1 bne .loop2 lda #2 sta WSYNC ; This is the 30th line of overscan. sta VSYNC ; Turn vsync on. jmp .vsync Quote Link to comment Share on other sites More sharing options...
+splendidnut Posted March 15, 2021 Share Posted March 15, 2021 Looks like PAL50 mode is being triggered. You can use Alt-L to turn on display stats in Stella to confirm. 1 Quote Link to comment Share on other sites More sharing options...
AGDDeveloper Posted March 16, 2021 Author Share Posted March 16, 2021 Thank you - I figured out the problem. I wasn't clearing the decimal flag in the 6502, so my counters were all decrementing in BCD. It looks like Stella randomizes the decimal flag on reset. Anyway, I fixed the bug - thank you! Quote Link to comment Share on other sites More sharing options...
Thomas Jentzsch Posted March 17, 2021 Share Posted March 17, 2021 On 3/16/2021 at 1:17 AM, AGDDeveloper said: Thank you - I figured out the problem. I wasn't clearing the decimal flag in the 6502, so my counters were all decrementing in BCD. It looks like Stella randomizes the decimal flag on reset. Anyway, I fixed the bug - thank you! Check Stella's developer settings and enable them. This will help you to notice the most common development problems (like clearing the BCD flag) early on. 2 Quote Link to comment Share on other sites More sharing options...
Just Jeff Posted March 18, 2021 Share Posted March 18, 2021 Nice job! Are you interested in refining this program? You have some more learning opportunities here if so. I see 8 or 9 things ranging from inefficient to incorrect here. Here are two that are actually affecting this program negatively: As spendidnut mentioned earlier, hit alt-L to see if you are displaying the proper number of lines (262). This program is running only 259 which brings us to issue #2- you're using the carry flag incorrectly. The carry flag should be set for subtraction, not cleared. If you step through the code in Stella (hit the ~ key), you will see that you are actually subtracting 2 on your first time through your loops, even though you have sbc #1. If you clear that up, you'll be running at 262 lines. There are other things too.. Let me know if you are interested in reworking them.. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.