TM
Game Boy
CPU Manual
FA FA 34
12
3) Finally an interesting side effect
76
76
This combination hangs the cpu.
The first HALT causes the second HALT to be
repeated, which therefore causes the following
command (=itself) to be repeated - again and again.
Placing a NOP between the two halts would cause the
NOP to be repeated once, the second HALT wouldn't
lock the cpu.
Below is suggested code for Game Boy programs:
; **** Main Game Loop ****
Main:
halt
nop
ld
or
jr
xor
ld
call
call
jr
by DP
ld
a,(34FA)
ld
(de),a
halt
halt
a,(VblnkFlag)
a
z,Main
a
(VblnkFlag),a
Controls
Game
Main
2.7.3. Low-Power Mode
; stop system clock
; return from halt when
; interrupted
; (See WARNING above.)
; V-Blank interrupt ?
; No, some other
; interrupt
; Clear V-Blank flag
; button inputs
; game operation
Page 21