// Simple implementation of Garth Wilson's structured macros ideas for Mads Nielsen's
// Kick Assembler.
.file [name="bin/Startup.prg", segments="Startup", modify="BasicUpstart", marg1=$0900]
.var pcStack = List() // Create a program counter stack
.function pushPC() { // Pushes the current program counter
.eval pcStack.add(*) // onto the PC stack
}
.function pullPC() {
.eval var pc = pcStack.get(pcStack.size() - 1) // Pulls the last program counter off
.eval pcStack.remove(pcStack.size() - 1) // of the stack and returns it
.return pc
}
.pseudocommand ifeq { // Pushes the current PC, then emits a
.eval pushPC() // BNE * (opposite of the implied EQ
bne * // in the command name since can only
} // branch past any condition code)
.pseudocommand endeq { // This is called after the condition
.var endPC = * // code. We first store the current PC
* = pullPC() // Now point the PC up to the ifeq PC
bne endPC // Emit "bne endPC" overwriting the
* = endPC // previous * then reset the PC back
} // to the endif PC location we stored
.segment Startup [start=$0900, allowOverlap] "Startup"
lda #0 // Just a simple test
ifeq // ifeq emits "bne *" at PC
sta $0400 // The conditional code is emitted next
endeq // endif does the PC stuff resolving bne
rts