Skip to content

Instantly share code, notes, and snippets.

@tobiasvl
Last active January 16, 2020 23:18
Show Gist options
  • Save tobiasvl/121e133a7a3f71784f3b9965618e2a65 to your computer and use it in GitHub Desktop.
Save tobiasvl/121e133a7a3f71784f3b9965618e2a65 to your computer and use it in GitHub Desktop.
# switch/case macro, should be followed by a jump table with the same number of entries as cases
:macro switch REG {
v0 := REG
v0 <<= v0
:calc table { HERE + 10 }
# for Super-CHIP compatibility, we also load VX for use with jump0 where X is the upper digit of the table's address
# note that if the table is located at address 0xA00 or above, we'll clobber necessary registers here!
:calc table-reg { table >> 8 }
v9 := 0x9
v9 -= v0
if vf == 0 then
:breakpoint switch-uses-reserved-registers
:byte { 0x80 | table-reg } 0x00 # 8X00, VX := V0
jump0 table
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment