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.
162 lines
2.1 KiB
162 lines
2.1 KiB
4 years ago
|
include "hardware.inc"
|
||
|
include "defines.inc"
|
||
|
|
||
|
NULL equ 0
|
||
|
global 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
|
||
|
cp $ff
|
||
|
jr z, .console_mgb
|
||
|
cp $11
|
||
|
jr z, .console_cgb
|
||
|
|
||
|
ld a, console_dmg
|
||
|
jr .console_end
|
||
|
|
||
|
.console_mgb
|
||
|
ld a, console_mgb
|
||
|
jr .console_end
|
||
|
|
||
|
.console_cgb
|
||
|
dec b
|
||
|
jr z, .console_agb
|
||
|
ld a, console_cgb
|
||
|
jr .console_end
|
||
|
|
||
|
.console_agb
|
||
|
ld a, console_agb
|
||
|
|
||
|
.console_end
|
||
|
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
|
||
|
ldh a, [h_console]
|
||
|
push af
|
||
|
|
||
|
if def(ENABLE_CLEAR)
|
||
|
; Clear the hram and wram1
|
||
|
xor a
|
||
|
ld hl, mmap_hram
|
||
|
ld bc, mmap_hram_end - mmap_hram
|
||
|
call memset
|
||
|
ld hl, mmap_wramx
|
||
|
ld bc, mmap_wramx_end - mmap_wramx
|
||
|
call memset
|
||
|
endc
|
||
|
|
||
|
pop af
|
||
|
ldh [h_console], a
|
||
|
|
||
|
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
|
||
|
|
||
|
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
|