6502 Assembly Language #12: 10 PRINT

With the Game of Life working at the end of the last session, I thought we’d do something a little different this time, converting a famous one-line BASIC program into assembly. In the process, we had to write code to scroll the screen as new lines appear at the bottom. Enjoy several minutes in the middle of me rubbing my furrowed brow as I struggle to figure out why it’s broken at one point. Technical details below the video.

I didn’t explain in the video how I found the problem, so I’ll do that here. First, here was the problem code:

        ldy #0                  ; loop 40 spaces
yloop:
        lda (NLINE),y
        sta (CLINE),y
        iny
        cmp #40
        bne yloop

I meant it to loop on the Y register, incrementing it from 0 up to 40, then falling out of the loop when Y==40. However, because I used CMP instead of CPY, it was comparing the accumulator (A) to 40 instead of Y. That seemed to work on the first few lines of the screen because 40 is the character code for a left parenthesis, and there was one of those in each line. So when it loaded that left parenthesis into A, that caused the loop to end so it could go on to the next line. On the fourth line, there were no left parentheses, so it looped forever.

What clued me in was when I let the code run and broke into it several times, and it was always somewhere in this loop, and then I noticed the Y register had all sorts of values, usually greater than 40. So I realized somehow it was getting past that comparison. Then it hit me I had the wrong opcode.

A technical note: For a webcam, I use my phone with an app called DroidCam that transmits the video to a web browser via wireless, and then I can capture that browser window in OBS and stick it in a corner of the screen. That’s handy, but it adds about a half-second delay, so my face is about a half-second behind the audio. It’s not a big deal, but it’s annoying. It annoys me anyway when I watch them to verify everything worked. So I fixed that by running the full video through an ffmpeg filter to crop that part of the video out, dropping the first 0.5 seconds, then another filter to overlay that cropped portion back over the full thing. I don’t know if it matches exactly yet, but it’s much better than it was. Only problem is that late in the video I expanded the C128 screen large enough to get into that space a bit, so it affected the bottom-right corner of that too. I’ll have to be more careful not to run them into each other next time.

Another note: I recorded this one the full size of the screen, with no shrinkage. These compress pretty well, since most of the screen isn’t changing most of the time. They’re larger at this size, but not too large to upload. I hope that makes them clearer for anyone who watches or downloads them in high quality.

One more: I noticed my last couple 6502 videos showed up twice on Bitchute. Turns out that’s because I’d given them my YouTube channel ID when I signed up, and at some point they started automatically pulling over videos that show up on my YouTube channel. That’s convenient, except that I really want to put them on Bitchute first to encourage people to use it. Also, the ones they get from YouTube seem to be lower quality. So I took the channel ID out to keep them from getting doubled-up.