; --- Data Stack --- ; ; on this channel we love garth wilson: https://wilsonminesco.com/stacks/StackOps.ASM ; data stack is built up of 2-byte cells ; TODO: this is broken, jumping here does nothing to the stack and skips several instructions, could be an emulator problem tho ; push_lit: ; this bad boy lets you inline a literal (low byte first) right after `jsr push_lit` and put it on the stack, once again, on this channel we love garth wilson ; push2 ; phx ; tsx ; txa ; tay ; plx ; lda $102, y ; sta 0, x ; clc ; adc #2 ; sta $102, y ; lda $103, y ; sta 1, x ; adc #0 ; sta $103, y ; fetch: ; lda (0, x) ; pha ; inc 0, x ; bne .1 ; inc 1, x ; .1: ; lda (0, x) ; bra put ; push ; put: ; sta 1, x ; pla ; sta 0, x ; rts plus: ; add: (n1 n2 -- n1+n2) clc lda 0, x adc 2, x sta 2, x lda 1, x adc 3, x sta 3, x pop rts mult: ; multiply: (n1 n2 -- n1*n2), frankly, i don't know how this works, but TODO: will try to figure it out later phy stz n ldy #0 .1: lsr 3, x ror 2, x bcc .2 clc lda n adc 0, x sta n tya adc 1, x tay .2: asl 0, x rol 1, x lda 2, x ora 3, x bne .1 lda n sta 2, x sty 3, x pop ply rts