You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
160 lines
2.2 KiB
160 lines
2.2 KiB
include "hardware.inc"
|
|
include "defines.inc"
|
|
|
|
NULL equ 0
|
|
export NULL
|
|
|
|
section "home/start.asm@wram0", wram0
|
|
ds $100 - 1
|
|
w_stack:
|
|
ds 1
|
|
|
|
section "home/start.asm@hram", hram
|
|
h_console:: db
|
|
|
|
section "home/start.asm", rom0[$100]
|
|
nop
|
|
jp _start
|
|
|
|
rept $150 - $104
|
|
db 0
|
|
endr
|
|
|
|
_start:
|
|
di
|
|
|
|
; Attempt to detect console model
|
|
ld c, console_agb
|
|
cp $11
|
|
jr z, .console_cgb
|
|
dec c
|
|
dec c ; console_mgb
|
|
cp $ff
|
|
jr z, .console_end
|
|
dec c ; console_dmg
|
|
jr .console_end
|
|
|
|
.console_cgb
|
|
dec b
|
|
jr z, .console_end
|
|
dec c ; console_cgb
|
|
|
|
.console_end
|
|
ld a, c
|
|
ldh [h_console], a
|
|
|
|
xor a
|
|
ldh [r_ie], a
|
|
ldh [r_if], a
|
|
|
|
if def(ENABLE_CLEAR)
|
|
; Clear wram0
|
|
ld hl, mmap_wram0
|
|
ld bc, mmap_wram0_end - mmap_wram0
|
|
call memset
|
|
endc
|
|
|
|
ld sp, w_stack
|
|
|
|
if def(ENABLE_CLEAR)
|
|
; Clear the hram and wram1
|
|
ldh a, [h_console]
|
|
push af
|
|
xor a
|
|
ld hl, mmap_hram
|
|
ld bc, mmap_hram_end - mmap_hram
|
|
call memset
|
|
pop af
|
|
ldh [h_console], a
|
|
ld hl, mmap_wramx
|
|
ld bc, mmap_wramx_end - mmap_wramx
|
|
call memset
|
|
endc
|
|
|
|
if def(ENABLE_CGB) && def(ENABLE_CLEAR)
|
|
; Clear the different wram banks
|
|
cp console_cgb
|
|
jr c, .end
|
|
|
|
ld d, 8
|
|
.cgb_loop
|
|
dec d
|
|
ld a, d
|
|
ldh [r_svbk], a
|
|
cp 2
|
|
jr c, .end
|
|
|
|
ld hl, mmap_wramx
|
|
ld bc, mmap_wramx_end - mmap_wramx
|
|
call memset
|
|
|
|
jr .cgb_loop
|
|
.end
|
|
endc
|
|
|
|
call audio_disable
|
|
if def(ENABLE_CLEAR)
|
|
call vram_clear
|
|
endc
|
|
|
|
ei
|
|
jp main
|
|
|
|
_halt_::
|
|
halt
|
|
jr _halt_
|
|
|
|
_stop_::
|
|
; Save registers
|
|
ldh a, [r_ie]
|
|
ld b, a
|
|
ldh a, [r_lcdc]
|
|
ld c, a
|
|
|
|
; Turn everything off
|
|
xor a
|
|
ldh [r_ie], a
|
|
ldh [r_if], a
|
|
ldh [r_joyp], a
|
|
call lcd_vblank_wait
|
|
xor a
|
|
ldh [r_lcdc], a
|
|
|
|
; Make sure the joypad doesn't inmediately trigger anything.
|
|
ld d, $ff
|
|
.wait
|
|
ldh a, [r_joyp]
|
|
cpl
|
|
and r_joyp_data
|
|
jr nz, .wait
|
|
dec d
|
|
jr nz, .wait
|
|
|
|
stop
|
|
|
|
; Restore registers
|
|
ld a, c
|
|
ldh [r_lcdc], a
|
|
ld a, b
|
|
ldh [r_ie], a
|
|
ret
|
|
|
|
_hl_::
|
|
jp hl
|
|
|
|
_bc_::
|
|
push bc
|
|
ret
|
|
|
|
_de_::
|
|
push de
|
|
ret
|
|
|
|
swap_hl_de::
|
|
ld a, h
|
|
ld h, d
|
|
ld d, a
|
|
ld a, l
|
|
ld l, e
|
|
ld e, a
|
|
ret
|
|
|