chilledgamer wrote: ↑Thu Jun 25, 2020 4:20 pmStill stuck on exactly why rst 16 is used in the example, and also my main challenge right at this moment is just creating a loop (in my own project) so that I can control when it ends. I'll have to try again after work
Well, according to my favourite table, here's what those instructions do. RST 16 is RST 10H:
Code: Select all
RST 0 1 C7 11 ------ -SP,-SP,[SP+1,SP]=PC,PC=00
RST 8H 1 CF 11 ------ -SP,-SP,[SP+1,SP]=PC,PC=08
RST 10H 1 D7 11 ------ -SP,-SP,[SP+1,SP]=PC,PC=10
RST 18H 1 DF 11 ------ -SP,-SP,[SP+1,SP]=PC,PC=18
RST 20H 1 E7 11 ------ -SP,-SP,[SP+1,SP]=PC,PC=20
RST 28H 1 EF 11 ------ -SP,-SP,[SP+1,SP]=PC,PC=28
RST 30H 1 F7 11 ------ -SP,-SP,[SP+1,SP]=PC,PC=30
RST 38H 1 FF 11 ------ -SP,-SP,[SP+1,SP]=PC,PC=38
What they do is make calls to functions in the ROM. The current address is saved on the stack (for a RETurn) then they just jump to the given address. If they're not in the ROM by design, then whoever sets up the system should pre-program some jumps in at the right place to catch these.
They're designed to make it easy to call operating system functions that may move around with different versions of the operating system. So you PUSH some instruction data onto the stack to say exactly what function you want and what you want it to do, then call the relevant 'RST' function.
Look at the first 11 entries under the ROM disassembly from 'Skoolkit':
https://skoolkid.github.io/rom/maps/all.html
e.g. at address $10 (16 in decimal) is a JUMP that takes you to the character print routine. You could call it directly at its address in ROM, but RST 16 is a lot simpler.