2014-02-01 17:26:39 -08:00
|
|
|
Reset:: ; 150
|
2013-08-20 00:26:37 -07:00
|
|
|
di
|
2015-11-11 20:38:57 -08:00
|
|
|
call MapSetup_Sound_Off
|
2013-08-20 00:26:37 -07:00
|
|
|
xor a
|
2015-11-05 11:06:03 -08:00
|
|
|
ld [hMapAnims], a
|
2013-08-20 00:26:37 -07:00
|
|
|
call ClearPalettes
|
|
|
|
xor a
|
|
|
|
ld [rIF], a
|
|
|
|
ld a, 1 ; VBlank int
|
|
|
|
ld [rIE], a
|
|
|
|
ei
|
|
|
|
|
2015-02-10 15:14:41 -08:00
|
|
|
ld hl, wcfbe
|
2013-08-20 00:26:37 -07:00
|
|
|
set 7, [hl]
|
|
|
|
|
|
|
|
ld c, 32
|
|
|
|
call DelayFrames
|
|
|
|
|
|
|
|
jr Init
|
|
|
|
; 16e
|
|
|
|
|
|
|
|
|
2014-02-01 17:26:39 -08:00
|
|
|
_Start:: ; 16e
|
2013-08-20 00:26:37 -07:00
|
|
|
cp $11
|
2015-12-26 15:11:55 -08:00
|
|
|
jr z, .cgb
|
2013-08-20 00:26:37 -07:00
|
|
|
xor a
|
2015-12-26 15:11:55 -08:00
|
|
|
jr .load
|
2013-08-20 00:26:37 -07:00
|
|
|
|
2015-12-26 15:11:55 -08:00
|
|
|
.cgb
|
2013-08-20 00:26:37 -07:00
|
|
|
ld a, $1
|
|
|
|
|
2015-12-26 15:11:55 -08:00
|
|
|
.load
|
2013-08-20 00:26:37 -07:00
|
|
|
ld [hCGB], a
|
|
|
|
ld a, $1
|
2015-12-26 15:11:55 -08:00
|
|
|
ld [hFFEA], a
|
2013-08-20 00:26:37 -07:00
|
|
|
; 17d
|
|
|
|
|
|
|
|
|
2014-02-01 17:26:39 -08:00
|
|
|
Init:: ; 17d
|
2013-08-20 00:26:37 -07:00
|
|
|
|
|
|
|
di
|
|
|
|
|
|
|
|
xor a
|
|
|
|
ld [rIF], a
|
|
|
|
ld [rIE], a
|
|
|
|
ld [rRP], a
|
|
|
|
ld [rSCX], a
|
|
|
|
ld [rSCY], a
|
|
|
|
ld [rSB], a
|
|
|
|
ld [rSC], a
|
|
|
|
ld [rWX], a
|
|
|
|
ld [rWY], a
|
|
|
|
ld [rBGP], a
|
|
|
|
ld [rOBP0], a
|
|
|
|
ld [rOBP1], a
|
|
|
|
ld [rTMA], a
|
|
|
|
ld [rTAC], a
|
2018-01-02 21:19:54 -08:00
|
|
|
ld [WRAM1_Begin], a
|
2013-08-20 00:26:37 -07:00
|
|
|
|
|
|
|
ld a, %100 ; Start timer at 4096Hz
|
|
|
|
ld [rTAC], a
|
|
|
|
|
|
|
|
.wait
|
|
|
|
ld a, [rLY]
|
2017-12-29 09:53:21 -08:00
|
|
|
cp LY_VBLANK + 1
|
2013-08-20 00:26:37 -07:00
|
|
|
jr nz, .wait
|
|
|
|
|
|
|
|
xor a
|
|
|
|
ld [rLCDC], a
|
|
|
|
|
|
|
|
; Clear WRAM bank 0
|
2017-12-26 20:18:05 -08:00
|
|
|
ld hl, WRAM0_Begin
|
|
|
|
ld bc, WRAM0_End - WRAM0_Begin
|
2016-04-10 11:42:14 -07:00
|
|
|
.ByteFill:
|
2013-08-20 00:26:37 -07:00
|
|
|
ld [hl], 0
|
|
|
|
inc hl
|
|
|
|
dec bc
|
|
|
|
ld a, b
|
|
|
|
or c
|
2015-12-26 15:11:55 -08:00
|
|
|
jr nz, .ByteFill
|
2013-08-20 00:26:37 -07:00
|
|
|
|
2013-08-28 23:10:32 -07:00
|
|
|
ld sp, Stack
|
2013-08-20 00:26:37 -07:00
|
|
|
|
|
|
|
; Clear HRAM
|
|
|
|
ld a, [hCGB]
|
|
|
|
push af
|
2015-12-26 15:11:55 -08:00
|
|
|
ld a, [hFFEA]
|
2013-08-20 00:26:37 -07:00
|
|
|
push af
|
|
|
|
xor a
|
2017-12-26 20:18:05 -08:00
|
|
|
ld hl, HRAM_Begin
|
|
|
|
ld bc, HRAM_End - HRAM_Begin
|
2013-08-20 00:26:37 -07:00
|
|
|
call ByteFill
|
|
|
|
pop af
|
2015-12-26 15:11:55 -08:00
|
|
|
ld [hFFEA], a
|
2013-08-20 00:26:37 -07:00
|
|
|
pop af
|
|
|
|
ld [hCGB], a
|
|
|
|
|
|
|
|
call ClearWRAM
|
2018-01-03 16:12:45 -08:00
|
|
|
ld a, BANK(wd000)
|
2013-08-20 00:26:37 -07:00
|
|
|
ld [rSVBK], a
|
|
|
|
call ClearVRAM
|
|
|
|
call ClearSprites
|
2016-05-10 09:31:49 -07:00
|
|
|
call ClearsScratch
|
2013-08-20 00:26:37 -07:00
|
|
|
|
|
|
|
|
|
|
|
ld a, BANK(LoadPushOAM)
|
|
|
|
rst Bankswitch
|
|
|
|
|
|
|
|
call LoadPushOAM
|
|
|
|
|
|
|
|
xor a
|
2015-11-05 11:06:03 -08:00
|
|
|
ld [hMapAnims], a
|
2013-08-20 00:26:37 -07:00
|
|
|
ld [hSCX], a
|
|
|
|
ld [hSCY], a
|
|
|
|
ld [rJOYP], a
|
|
|
|
|
|
|
|
ld a, $8 ; HBlank int enable
|
|
|
|
ld [rSTAT], a
|
|
|
|
|
|
|
|
ld a, $90
|
|
|
|
ld [hWY], a
|
|
|
|
ld [rWY], a
|
|
|
|
|
|
|
|
ld a, 7
|
|
|
|
ld [hWX], a
|
|
|
|
ld [rWX], a
|
|
|
|
|
2017-12-29 10:22:33 -08:00
|
|
|
ld a, LCDC_DEFAULT ; %11100011
|
2013-08-20 00:26:37 -07:00
|
|
|
; LCD on
|
|
|
|
; Win tilemap 1
|
|
|
|
; Win on
|
|
|
|
; BG/Win tiledata 0
|
|
|
|
; BG Tilemap 0
|
|
|
|
; OBJ 8x8
|
|
|
|
; OBJ on
|
|
|
|
; BG on
|
|
|
|
ld [rLCDC], a
|
|
|
|
|
2015-10-19 13:49:29 -07:00
|
|
|
ld a, -1
|
2015-11-06 06:04:27 -08:00
|
|
|
ld [hLinkPlayerNumber], a
|
2013-08-20 00:26:37 -07:00
|
|
|
|
2017-12-24 09:47:30 -08:00
|
|
|
farcall InitCGBPals
|
2013-08-20 00:26:37 -07:00
|
|
|
|
2017-12-28 04:32:33 -08:00
|
|
|
ld a, HIGH(vBGMap1)
|
2015-10-19 13:49:29 -07:00
|
|
|
ld [hBGMapAddress + 1], a
|
2017-12-28 04:32:33 -08:00
|
|
|
xor a ; LOW(vBGMap1)
|
2013-08-20 00:26:37 -07:00
|
|
|
ld [hBGMapAddress], a
|
|
|
|
|
2017-12-24 09:47:30 -08:00
|
|
|
farcall StartClock
|
2013-08-20 00:26:37 -07:00
|
|
|
|
|
|
|
xor a
|
|
|
|
ld [MBC3LatchClock], a
|
|
|
|
ld [MBC3SRamEnable], a
|
|
|
|
|
|
|
|
ld a, [hCGB]
|
|
|
|
and a
|
2016-05-05 12:07:37 -07:00
|
|
|
jr z, .no_double_speed
|
2013-09-08 00:12:48 -07:00
|
|
|
call NormalSpeed
|
2016-05-05 12:07:37 -07:00
|
|
|
.no_double_speed
|
2013-08-20 00:26:37 -07:00
|
|
|
|
|
|
|
xor a
|
|
|
|
ld [rIF], a
|
|
|
|
ld a, %1111 ; VBlank, LCDStat, Timer, Serial interrupts
|
|
|
|
ld [rIE], a
|
|
|
|
ei
|
|
|
|
|
|
|
|
call DelayFrame
|
|
|
|
|
2018-01-16 11:30:10 -08:00
|
|
|
predef InitSGBBorder ; SGB init
|
2013-08-20 00:26:37 -07:00
|
|
|
|
2015-11-11 20:38:57 -08:00
|
|
|
call MapSetup_Sound_Off
|
2013-08-20 00:26:37 -07:00
|
|
|
xor a
|
2014-05-21 13:21:46 -07:00
|
|
|
ld [wMapMusic], a
|
2013-08-20 00:26:37 -07:00
|
|
|
jp GameInit
|
|
|
|
; 245
|
|
|
|
|
|
|
|
|
2014-02-01 17:26:39 -08:00
|
|
|
ClearVRAM:: ; 245
|
2013-08-20 00:26:37 -07:00
|
|
|
; Wipe VRAM banks 0 and 1
|
|
|
|
|
|
|
|
ld a, 1
|
|
|
|
ld [rVBK], a
|
|
|
|
call .clear
|
|
|
|
|
|
|
|
xor a
|
|
|
|
ld [rVBK], a
|
|
|
|
.clear
|
2017-12-28 04:32:33 -08:00
|
|
|
ld hl, vTiles0
|
2013-08-20 00:26:37 -07:00
|
|
|
ld bc, $2000
|
|
|
|
xor a
|
|
|
|
call ByteFill
|
|
|
|
ret
|
|
|
|
; 25a
|
|
|
|
|
2014-02-01 17:26:39 -08:00
|
|
|
ClearWRAM:: ; 25a
|
2013-08-20 00:26:37 -07:00
|
|
|
; Wipe swappable WRAM banks (1-7)
|
2016-05-10 09:31:49 -07:00
|
|
|
; Assumes CGB or AGB
|
2013-08-20 00:26:37 -07:00
|
|
|
|
|
|
|
ld a, 1
|
2016-05-10 09:31:49 -07:00
|
|
|
.bank_loop
|
2013-08-20 00:26:37 -07:00
|
|
|
push af
|
|
|
|
ld [rSVBK], a
|
|
|
|
xor a
|
2017-12-26 20:18:05 -08:00
|
|
|
ld hl, WRAM1_Begin
|
|
|
|
ld bc, WRAM1_End - WRAM1_Begin
|
2013-08-20 00:26:37 -07:00
|
|
|
call ByteFill
|
|
|
|
pop af
|
|
|
|
inc a
|
|
|
|
cp 8
|
2016-05-19 05:11:44 -07:00
|
|
|
jr nc, .bank_loop ; Should be jr c
|
2013-08-20 00:26:37 -07:00
|
|
|
ret
|
|
|
|
; 270
|
|
|
|
|
2016-05-10 09:31:49 -07:00
|
|
|
ClearsScratch:: ; 270
|
|
|
|
; Wipe the first 32 bytes of sScratch
|
|
|
|
|
|
|
|
ld a, BANK(sScratch)
|
2013-08-20 00:26:37 -07:00
|
|
|
call GetSRAMBank
|
2016-05-10 09:31:49 -07:00
|
|
|
ld hl, sScratch
|
|
|
|
ld bc, $20
|
2013-08-20 00:26:37 -07:00
|
|
|
xor a
|
|
|
|
call ByteFill
|
|
|
|
call CloseSRAM
|
|
|
|
ret
|
|
|
|
; 283
|