01

Today starts December Adventure ✨ a month of cozy coding. See @eli_oat@tenforward.social‘s page for details. I want to get something small done with Minicube64 this time, to learn how games for the 6502 were made. I look at some assembly last year, mainly Nick Morgan’s 6502 and compudanzas’ uxn tutorials. But most is lost by now and I had already had some problems following Minicube64’s code.

For now I just tried to paint the screen a bit through a loop, and I learned about the difference between the main loop and the VBLANK interrupt, although I have to look that up the later. So updates to the screen need to be done in the IRQ routine if I want to have something frame based. Minicube64 offer some macros to work easier with such common things.

ldx #$01
_setw IRQ, VBLANK_IRQ
 
IRQ:
	inx
	rti

The other thing I struggled with were adressing modes. Need to get them into my head again.

02

Ehrm. Frustration. I tried to implement grabbing the arrow keys and moving that pixel on screen around but I run into so many problems that I need to take two steps back and than maybe another three or four. I tried to cross-reference my problems with Skilldrick’s tutorial and Masswerk’s 6502 instruction set, but to no avail. There is a lot I didn’t understand and maybe I should just go through Skilldrick’s tutorial again. The Minicube64 documentation is not very beginner’s friendly, so that might be a thing that could grow out of this :)


I got myself together, researched a bit more and was at least able to properly paint the screen, one pixel per interrupt.

The magic part was hidden in the indirect indexed adressing mode. First I set up the low and high byte of the video adress.

    PIXELS_PER_ROW  = 64
    VIDEO_MEM       = $00
 
    lda #$00                        ; Low byte
    sta VIDEO_MEM                   ; Store low byte of VIDEO_MEM
    lda #$F0                        ; High byte
    sta VIDEO_MEM+1                 ; Store high byte of VIDEO_MEM
 
    ldy #$00

Then I use that when drawing my pixel.

IRQ:	    						; Set 'IRQ' label
    jsr Draw
	rti	    						; Return from interrupt
 
Draw:
 
    lda #$20                                ; Load A with a value (e.g., pixel color)
    sta (VIDEO_MEM),y                       ; Store A at current pixel position
 
    iny                                     ; Increment X (move to next column)
    cpy #PIXELS_PER_ROW * #PIXELS_PER_ROW   ; Check if end of row is reached
    bne Continue                            ; If not, loop back for next column
 
    clc
    lda VIDEO_MEM+1
    adc #$01
    sta VIDEO_MEM+1
 
    ldy #$00                                ; reset X
    rts
 
    Continue:
    rts

I’m pretty sure there are better ways to do that, but that’s good enough for today.

03

Continued with the sketch from yesterday and concentrated on grabing the arrow keys and moving a pixel around. Worked quite charming and I could actually concentrate on learning problems of math in assembly, branching and the carry flag.

The thing moved around as it should although I’m not understand why it works downwards but not upwards. But I know it has to do with the carry and negative flags and the way I calculate the new position.

    VIDEO_MEM = $00                ; holds the high byte for the position
	                               ; VIDEO_MEM+1 holds the low byte

Ah! The problem is that I position the thing by offsetting from VIDEO_MEM by sta (VIDEO_MEM),y. Actually I should work on the stored position in VIDEO_MEM+1 and just use indirect adressing.