Table of Contents
programming george
reading garth wilson's stack treatise, the idea of having a data stack seperate from the hardware stack sounds cool. starting this page to keep track of the design decisions i'm making for how george should be programmed.
init
main loop
data stack
putting a data stack on the zero page lets us use zero page indexed and zero page preindexed indirect instructions to interact with our subroutine parameters. that's a lot of words, but it just means that when we push/pull the stack, we use fewer cycles than if our stack was higher up in memory. this comes at the cost of our x register, which is now our data stack pointer.
to push a byte onto the data stack, we just:
dex ; decrement the stack pointer
lda some_value ; load the byte we want on the stack into a
sta 0, x ; put the byte on the stack!
and to pop a byte off it:
lda 0, x ; pop the top of stack off into a
inx ; increment the stack pointer
screen memory
character mode
characters are 8 dots wide by 13 scanlines high. the display is 512 dots wide by 380 scanlines high, so that's 512/8=64 characters per row and 380/13~=29 characters per column. we don't have to worry about how each individual bit maps to the screen, since vram is just a series of ascii character codes. the vram address for a character at a given X,Y coordinate will be $6000 + (64\*Y) + X
.
but i wrote a subroutine to do this for you! just push the coordinates on the data stack (x first, then y) and call jsr get_char_address
, and the memory address will be put at the top of the stack.
hires mode
misc notes
putting this here cause i get it mixed up a lot: "low byte first" means lower in memory! so to put the word $4a6f
on the stack, do this:
push ; macro for 2x dex
lda #$6f
sta 0, x
lda #$4a
sta 1, x
this means you can use the (zp, x) addressing mode to point at an address! using the same example, to store $23
at the address $4a6f
(which is on the stack), do this:
lda #$23
sta (0, x)