Program termination: Difference between revisions

Content added Content deleted
m (→‎{{header|6502 Assembly}}: made the example hardware-agnostic)
Line 27: Line 27:
There is no firmware or BASIC to return to, so the easiest way to do this is to "trap" the program counter with a branch back to itself. This isn't a complete termination since NMI code will still run, unless you disable the screen. In order to display a static "THE END" screen that doesn't take user input, which is what many games did once the game was beaten, you can do this:
There is no firmware or BASIC to return to, so the easiest way to do this is to "trap" the program counter with a branch back to itself. This isn't a complete termination since NMI code will still run, unless you disable the screen. In order to display a static "THE END" screen that doesn't take user input, which is what many games did once the game was beaten, you can do this:


<lang 6502asm>
<lang 6502asm>sei ;disable IRQs
sei ;disable IRQs
halt:
halt:
jmp halt ;trap the program counter</lang>
jmp halt ;trap the program counter</lang>