summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpikalaxalt <PikalaxALT@gmail.com>2016-06-16 15:25:08 -0400
committerpikalaxalt <PikalaxALT@gmail.com>2016-06-16 15:25:08 -0400
commit845d8b2854074d02b737e8abf02fbb60d1b9b55c (patch)
tree273c89f78ff5dc528b21ef058466e547006869e4
parentee84a2a0e4e1fee53feaa5a33c4b4eb5317dfcbc (diff)
home/init.asm
-rw-r--r--home.asm37
-rw-r--r--home/init.asm202
-rw-r--r--home/lcd.asm61
-rw-r--r--home/time.asm233
-rw-r--r--main.asm27
-rw-r--r--wram.asm106
6 files changed, 209 insertions, 457 deletions
diff --git a/home.asm b/home.asm
index 48f79ef8..db303ea4 100644
--- a/home.asm
+++ b/home.asm
@@ -7,22 +7,16 @@ INCLUDE "interrupts.asm"
SECTION "start", HOME[$100]
Start::
nop
- jp Start_
+ jp _Start
SECTION "bank0", HOME[$150]
INCLUDE "home/vblank.asm"
INCLUDE "home/delay.asm"
INCLUDE "home/rtc.asm"
INCLUDE "home/fade.asm"
-
-LCD::
- dr $41b, $467
-
-UpdateTime::
- dr $467, $5c6
-
-Start_::
- dr $5c6, $6aa
+INCLUDE "home/lcd.asm"
+INCLUDE "home/time.asm"
+INCLUDE "home/init.asm"
Serial::
dr $6aa, $8df
@@ -71,4 +65,25 @@ Function1efa::
dr $1efa, $2e27
FarCall_hl::
- dr $2e27, $3fee
+ dr $2e27, $2e49
+
+Function2e49::
+ dr $2e49, $30e1
+
+OpenSRAM::
+ dr $30e1, $30f1
+
+CloseSRAM::
+ dr $30f1, $30ff
+
+Function30ff::
+ dr $30ff, $314c
+
+Function314c::
+ dr $314c, $3564
+
+Function3564::
+ dr $3564, $3d4f
+
+Function3d4f::
+ dr $3d4f, $3fee
diff --git a/home/init.asm b/home/init.asm
index dacc5ff7..0dc19063 100644
--- a/home/init.asm
+++ b/home/init.asm
@@ -1,45 +1,25 @@
-Reset:: ; 150
- di
- call MapSetup_Sound_Off
+Reset:: ; 5b0 (0:05b0)
+ call Function3d4f
xor a
ld [hMapAnims], a
- call ClearPalettes
- xor a
- ld [rIF], a
- ld a, 1 ; VBlank int
- ld [rIE], a
+ call Function3564
ei
-
- ld hl, wcfbe
+ ld hl, wd8ba
set 7, [hl]
-
ld c, 32
call DelayFrames
-
jr Init
-; 16e
-
-
-_Start:: ; 16e
+_Start:: ; 5c6 (0:05c6)
cp $11
jr z, .cgb
xor a
jr .load
-
.cgb
ld a, $1
-
.load
ld [hCGB], a
- ld a, $1
- ld [hFFEA], a
-; 17d
-
-
-Init:: ; 17d
-
+Init:: ; 5d1 (0:05d1)
di
-
xor a
ld [rIF], a
ld [rIE], a
@@ -55,168 +35,112 @@ Init:: ; 17d
ld [rOBP1], a
ld [rTMA], a
ld [rTAC], a
- ld [$d000], a
-
- ld a, %100 ; Start timer at 4096Hz
+ ld [wceeb], a
+ ld a, $4
ld [rTAC], a
-
.wait
ld a, [rLY]
cp 145
jr nz, .wait
-
xor a
ld [rLCDC], a
-; Clear WRAM bank 0
+; Clear WRAM
ld hl, wc000
- ld bc, wd000 - wc000
+ ld bc, $2000
.ByteFill
- ld [hl], 0
+ ld [hl], $0
inc hl
dec bc
ld a, b
or c
jr nz, .ByteFill
- ld sp, Stack
+ ld sp, wStackTop
-; Clear HRAM
+ call ClearVRAM
ld a, [hCGB]
push af
- ld a, [hFFEA]
- push af
xor a
ld hl, HRAM_START
ld bc, HRAM_END - HRAM_START
- call ByteFill
- pop af
- ld [hFFEA], a
+ call Function314c
pop af
ld [hCGB], a
-
- call ClearWRAM
- ld a, 1
- ld [rSVBK], a
- call ClearVRAM
- call ClearSprites
- call Function270
-
-
- ld a, BANK(LoadPushOAM)
+ call Function30ff
+ ld a, $1
rst Bankswitch
-
- call LoadPushOAM
-
+ call Function4032
xor a
ld [hMapAnims], a
ld [hSCX], a
ld [hSCY], a
ld [rJOYP], a
-
- ld a, $8 ; HBlank int enable
+ ld a, $8
ld [rSTAT], a
-
ld a, $90
ld [hWY], a
ld [rWY], a
-
- ld a, 7
+ ld a, $7
ld [hWX], a
ld [rWX], a
-
- ld a, %11100011
- ; LCD on
- ; Win tilemap 1
- ; Win on
- ; BG/Win tiledata 0
- ; BG Tilemap 0
- ; OBJ 8x8
- ; OBJ on
- ; BG on
- ld [rLCDC], a
-
- ld a, -1
+ ld a, $ff
ld [hLinkPlayerNumber], a
+ ld h, $98
+ call Function699
+ ld h, $9c
+ call Function699
- callba Function9890
+ callab Function9cfd
+ ld a, $9c
- ld a, VBGMap1 / $100
ld [hBGMapAddress + 1], a
- xor a ; VBGMap1 % $100
- ld [hBGMapAddress], a
-
- callba StartClock
-
xor a
+ ld [hBGMapAddress], a
+ callba Function14089
+ ld a, $a
+ ld [MBC3SRamEnable], a
+ ld a, $0
ld [MBC3LatchClock], a
ld [MBC3SRamEnable], a
-
- ld a, [hCGB]
- and a
- jr z, .asm_22b
- call NormalSpeed
-.asm_22b
-
- xor a
- ld [rIF], a
- ld a, %1111 ; VBlank, LCDStat, Timer, Serial interrupts
+ ld a, $e3
+ ld [rLCDC], a
+ ld a, $1f
ld [rIE], a
ei
-
call DelayFrame
-
- predef Function9853
-
- call MapSetup_Sound_Off
- xor a
- ld [wMapMusic], a
- jp GameInit
-; 245
-
-
-ClearVRAM:: ; 245
-; Wipe VRAM banks 0 and 1
-
- ld a, 1
- ld [rVBK], a
- call .clear
-
+ ld a, $30
+ call Function2e49
+ call Function3d4f
xor a
- ld [rVBK], a
-.clear
- ld hl, VTiles0
+ ld [wc1c0], a
+IF DEF(GOLD)
+ jp Function6545
+ENDC
+IF DEF(SILVER)
+ jp Function650b
+ENDC
+
+ClearVRAM:: ; 68e (0:068e)
+ ld hl, $8000
ld bc, $2000
xor a
- call ByteFill
+ call Function314c
ret
-; 25a
-ClearWRAM:: ; 25a
-; Wipe swappable WRAM banks (1-7)
-
- ld a, 1
-.asm_25c
- push af
- ld [rSVBK], a
- xor a
- ld hl, $d000
- ld bc, $1000
- call ByteFill
- pop af
- inc a
- cp 8
- jr nc, .asm_25c
- ret
-; 270
-
-Function270:: ; 270
- ld a, $0
- call GetSRAMBank
- ld hl, $a000
- ld bc, $0020
- xor a
- call ByteFill
- call CloseSRAM
+Function699:: ; 699 (0:0699)
+ ld a, $7f
+ jr asm_69e
+
+Function69d:: ; 69d
+ ld a, l
+asm_69e
+ ld de, $400
+ ld l, e
+.loop
+ ld [hli], a
+ dec e
+ jr nz, .loop
+ dec d
+ jr nz, .loop
ret
-; 283
diff --git a/home/lcd.asm b/home/lcd.asm
index 875043bc..b488cbec 100644
--- a/home/lcd.asm
+++ b/home/lcd.asm
@@ -1,58 +1,38 @@
-; LCD handling
-
-
-Function547:: ; 547
-; Unreferenced
- ld a, [hFFC6]
- cp rSCX - $ff00
- ret nz
- ld c, a
- ld a, [LYOverrides]
- ld [$ff00+c], a
- ret
-; 552
-
-
-LCD:: ; 552
+LCD:: ; 41b (0:041b)
push af
- ld a, [hFFC6]
+ ld a, [hLCDCPointer]
and a
jr z, .done
-
-; At this point it's assumed we're in WRAM bank 5!
- push bc
+ push hl
ld a, [rLY]
- ld c, a
- ld b, LYOverrides >> 8
- ld a, [bc]
- ld b, a
- ld a, [hFFC6]
- ld c, a
- ld a, b
- ld [$ff00+c], a
- pop bc
-
+ ld l, a
+ ld h, wLYOverrides >> 8
+ ld h, [hl]
+ ld a, [hLCDCPointer]
+ ld l, a
+ ld a, h
+ ld h, rSCY >> 8
+ ld [hl], a
+ pop hl
.done
pop af
reti
-; 568
-
-DisableLCD:: ; 568
+DisableLCD::
; Turn the LCD off
; Don't need to do anything if the LCD is already off
ld a, [rLCDC]
- bit 7, a ; lcd enable
+ bit 7, a
ret z
xor a
ld [rIF], a
ld a, [rIE]
ld b, a
-
+
; Disable VBlank
- res 0, a ; vblank
+ res 0, a
ld [rIE], a
.wait
@@ -62,7 +42,7 @@ DisableLCD:: ; 568
jr nz, .wait
ld a, [rLCDC]
- and %01111111 ; lcd enable off
+ and %01111111
ld [rLCDC], a
xor a
@@ -70,12 +50,9 @@ DisableLCD:: ; 568
ld a, b
ld [rIE], a
ret
-; 58a
-
-EnableLCD:: ; 58a
+EnableLCD::
ld a, [rLCDC]
- set 7, a ; lcd enable
+ set 7, a
ld [rLCDC], a
ret
-; 591
diff --git a/home/time.asm b/home/time.asm
index 2d432be3..309daa01 100644
--- a/home/time.asm
+++ b/home/time.asm
@@ -1,95 +1,54 @@
-; Functions relating to the timer interrupt and the real-time-clock.
-
-
-AskTimer:: ; 591
- push af
- ld a, [hMobile]
- and a
- jr z, .not_mobile
- call Timer
-
-.not_mobile
- pop af
+AskTimer:: ; 45b (0:045b)
reti
-; 59c
-
-LatchClock:: ; 59c
-; latch clock counter data
- ld a, 0
+LatchClock:: ; 45c (0:045c)
+ ld a, $0
ld [MBC3LatchClock], a
- ld a, 1
+ ld a, $1
ld [MBC3LatchClock], a
ret
-; 5a7
-
-UpdateTime:: ; 5a7
+UpdateTime:: ; 467 (0:0467)
call GetClock
call FixDays
call FixTime
- callba GetTimeOfDay
+ callba Function14032
ret
-; 5b7
-
-
-GetClock:: ; 5b7
-; store clock data in hRTCDayHi-hRTCSeconds
-; enable clock r/w
+GetClock:: ; 477 (0:0477)
ld a, SRAM_ENABLE
ld [MBC3SRamEnable], a
-
-; clock data is 'backwards' in hram
-
call LatchClock
ld hl, MBC3SRamBank
ld de, MBC3RTC
-
ld [hl], RTC_S
ld a, [de]
and $3f
ld [hRTCSeconds], a
-
ld [hl], RTC_M
ld a, [de]
and $3f
ld [hRTCMinutes], a
-
ld [hl], RTC_H
ld a, [de]
and $1f
ld [hRTCHours], a
-
ld [hl], RTC_DL
ld a, [de]
ld [hRTCDayLo], a
-
ld [hl], RTC_DH
ld a, [de]
ld [hRTCDayHi], a
-
-; unlatch clock / disable clock r/w
call CloseSRAM
ret
-; 5e8
-
-
-FixDays:: ; 5e8
-; fix day count
-; mod by 140
-; check if day count > 255 (bit 8 set)
- ld a, [hRTCDayHi] ; DH
+FixDays:: ; 4a8 (0:04a8)
+ ld a, [hRTCDayHi]
bit 0, a
jr z, .daylo
-; reset dh (bit 8)
res 0, a
- ld [hRTCDayHi], a ; DH
-
-; mod 140
-; mod twice since bit 8 (DH) was set
- ld a, [hRTCDayLo] ; DL
+ ld [hRTCDayHi], a
+ ld a, [hRTCDayLo]
.modh
sub 140
jr nc, .modh
@@ -97,127 +56,95 @@ FixDays:: ; 5e8
sub 140
jr nc, .modl
add 140
-
-; update dl
- ld [hRTCDayLo], a ; DL
-
-; flag for sRTCStatusFlags
- ld a, %01000000
+ ld [hRTCDayLo], a
+ ld a, $40
jr .set
-
.daylo
-; quit if fewer than 140 days have passed
- ld a, [hRTCDayLo] ; DL
+ ld a, [hRTCDayLo]
cp 140
jr c, .quit
-
-; mod 140
.mod
sub 140
jr nc, .mod
add 140
-
-; update dl
- ld [hRTCDayLo], a ; DL
-
-; flag for sRTCStatusFlags
- ld a, %00100000
-
+ ld [hRTCDayLo], a
+ ld a, $20
.set
-; update clock with modded day value
push af
call SetClock
pop af
scf
ret
-
.quit
+ ccf
xor a
ret
-; 61d
-
-
-FixTime:: ; 61d
-; add ingame time (set at newgame) to current time
-; day hr min sec
-; store time in CurDay, hHours, hMinutes, hSeconds
-; second
- ld a, [hRTCSeconds] ; S
+FixTime:: ; 4de (0:04de)
+ ld a, [hRTCSeconds]
ld c, a
- ld a, [StartSecond]
+ ld a, [wd1df]
add c
sub 60
- jr nc, .updatesec
+ jr nc, .asm_4eb
add 60
-.updatesec
+.asm_4eb
ld [hSeconds], a
-
-; minute
- ccf ; carry is set, so turn it off
- ld a, [hRTCMinutes] ; M
+ ccf
+ ld a, [hRTCMinutes]
ld c, a
- ld a, [StartMinute]
+ ld a, [wd1de]
adc c
sub 60
- jr nc, .updatemin
+ jr nc, .asm_4fb
add 60
-.updatemin
+.asm_4fb
ld [hMinutes], a
-
-; hour
- ccf ; carry is set, so turn it off
- ld a, [hRTCHours] ; H
+ ccf
+ ld a, [hRTCHours]
ld c, a
- ld a, [StartHour]
+ ld a, [wd1dd]
adc c
sub 24
- jr nc, .updatehr
+ jr nc, .asm_50b
add 24
-.updatehr
+.asm_50b
ld [hHours], a
-
-; day
- ccf ; carry is set, so turn it off
- ld a, [hRTCDayLo] ; DL
+ ccf
+ ld a, [hRTCDayLo]
ld c, a
- ld a, [StartDay]
+ ld a, [wd1dc]
adc c
- ld [CurDay], a
+ ld [wd1f2], a
ret
-; 658
-SetTimeOfDay:: ; 658
+SetTimeOfDay::
xor a
- ld [StringBuffer2], a
- ld a, $0 ; useless
- ld [StringBuffer2 + 3], a
+ ld [wStringBuffer2], a
+ ld a, $0
+ ld [wStringBuffer2 + 3], a
jr InitTime
-SetDayOfWeek:: ; 663
+SetDayOfWeek::
call UpdateTime
ld a, [hHours]
- ld [StringBuffer2 + 1], a
+ ld [wStringBuffer2 + 1], a
ld a, [hMinutes]
- ld [StringBuffer2 + 2], a
+ ld [wStringBuffer2 + 2], a
ld a, [hSeconds]
- ld [StringBuffer2 + 3], a
- jr InitTime ; useless
+ ld [wStringBuffer2 + 3], a
+ jr InitTime
-InitTime:: ; 677
- callba _InitTime
+InitTime::
+ callba Function140ff
ret
-; 67e
-
-
-PanicResetClock:: ; 67e
- call .ClearhRTC
+PanicResetClock::
+ call ClearhRTC
call SetClock
ret
-; 685
-.ClearhRTC ; 685
+ClearhRTC:: ; 546 (0:0546)
xor a
ld [hRTCSeconds], a
ld [hRTCMinutes], a
@@ -225,88 +152,60 @@ PanicResetClock:: ; 67e
ld [hRTCDayLo], a
ld [hRTCDayHi], a
ret
-; 691
-
-SetClock:: ; 691
-; set clock data from hram
-
-; enable clock r/w
+SetClock:: ; 552 (0:0552)
ld a, SRAM_ENABLE
ld [MBC3SRamEnable], a
-
-; set clock data
-; stored 'backwards' in hram
-
call LatchClock
ld hl, MBC3SRamBank
ld de, MBC3RTC
-
-; seems to be a halt check that got partially commented out
-; this block is totally pointless
ld [hl], RTC_DH
ld a, [de]
- bit 6, a ; halt
+ bit 6, a
ld [de], a
-
-; seconds
ld [hl], RTC_S
ld a, [hRTCSeconds]
ld [de], a
-; minutes
ld [hl], RTC_M
ld a, [hRTCMinutes]
ld [de], a
-; hours
ld [hl], RTC_H
ld a, [hRTCHours]
ld [de], a
-; day lo
ld [hl], RTC_DL
ld a, [hRTCDayLo]
ld [de], a
-; day hi
ld [hl], RTC_DH
ld a, [hRTCDayHi]
- res 6, a ; make sure timer is active
+ res 6, a
ld [de], a
-
-; cleanup
- call CloseSRAM ; unlatch clock, disable clock r/w
+ call CloseSRAM
ret
-; 6c4
-
-ClearRTCStatus:: ; 6c4
-; clear sRTCStatusFlags
+ClearRTCStatus::
xor a
push af
- ld a, BANK(sRTCStatusFlags)
- call GetSRAMBank
+ ld a, BANK(s0_ac60)
+ call OpenSRAM
pop af
- ld [sRTCStatusFlags], a
+ ld [s0_ac60], a
call CloseSRAM
ret
-; 6d3
-RecordRTCStatus:: ; 6d3
-; append flags to sRTCStatusFlags
- ld hl, sRTCStatusFlags
+RecordRTCStatus::
+ ld hl, s0_ac60
push af
- ld a, BANK(sRTCStatusFlags)
- call GetSRAMBank
+ ld a, BANK(s0_ac60)
+ call OpenSRAM
pop af
or [hl]
ld [hl], a
call CloseSRAM
ret
-; 6e3
-CheckRTCStatus:: ; 6e3
-; check sRTCStatusFlags
- ld a, BANK(sRTCStatusFlags)
- call GetSRAMBank
- ld a, [sRTCStatusFlags]
+CheckRTCStatus::
+ ld a, BANK(s0_ac60)
+ call OpenSRAM
+ ld a, [s0_ac60]
call CloseSRAM
ret
-; 6ef
diff --git a/main.asm b/main.asm
index 5d60a609..a1eb30a6 100644
--- a/main.asm
+++ b/main.asm
@@ -1,10 +1,25 @@
INCLUDE "constants.asm"
SECTION "bank1", DATA, BANK[$1]
- dr $4000, $8000
+ dr $4000, $4032
+Function4032::
+
+IF DEF(GOLD)
+ dr $4032, $6545
+Function6545::
+ dr $6545, $8000
+ENDC
+
+IF DEF(SILVER)
+ dr $4032, $650b
+Function650b::
+ dr $650b, $8000
+ENDC
SECTION "bank2", DATA, BANK[$2]
- dr $8000, $c000
+ dr $8000, $9cfd
+Function9cfd:: ; 9cfd
+ dr $9cfd, $c000
SECTION "bank3", DATA, BANK[$3]
dr $c000, $10000
@@ -13,7 +28,13 @@ SECTION "bank4", DATA, BANK[$4]
dr $10000, $14000
SECTION "bank5", DATA, BANK[$5]
- dr $14000, $18000
+ dr $14000, $14032
+Function14032:: ; 14032
+ dr $14032, $14089
+Function14089:: ; 14089
+ dr $14089, $140ff
+Function140ff:: ; 140ff
+ dr $140ff, $18000
SECTION "bank6", DATA, BANK[$6]
dr $18000, $1c000
diff --git a/wram.asm b/wram.asm
index f823e7ba..14995342 100644
--- a/wram.asm
+++ b/wram.asm
@@ -1793,6 +1793,8 @@ wc6fc:: ds 1
wc6fd:: ds 1
wc6fe:: ds 1
wc6ff:: ds 1
+
+wLYOverrides::
wc700:: ds 1
wc701:: ds 1
wc702:: ds 1
@@ -3950,101 +3952,13 @@ wcf67:: ds 1
wcf68:: ds 1
wcf69:: ds 1
wcf6a:: ds 1
-wcf6b:: ds 1
-wcf6c:: ds 1
-wcf6d:: ds 1
-wcf6e:: ds 1
-wcf6f:: ds 1
-wcf70:: ds 1
-wcf71:: ds 1
-wcf72:: ds 1
-wcf73:: ds 1
-wcf74:: ds 1
-wcf75:: ds 1
-wcf76:: ds 1
-wcf77:: ds 1
-wcf78:: ds 1
-wcf79:: ds 1
-wcf7a:: ds 1
-wcf7b:: ds 1
-wcf7c:: ds 1
-wcf7d:: ds 1
-wcf7e:: ds 1
-wcf7f:: ds 1
-wcf80:: ds 1
-wcf81:: ds 1
-wcf82:: ds 1
-wcf83:: ds 1
-wcf84:: ds 1
-wcf85:: ds 1
-wcf86:: ds 1
-wcf87:: ds 1
-wcf88:: ds 1
-wcf89:: ds 1
-wcf8a:: ds 1
-wcf8b:: ds 1
-wcf8c:: ds 1
-wcf8d:: ds 1
-wcf8e:: ds 1
-wcf8f:: ds 1
-wcf90:: ds 1
-wcf91:: ds 1
-wcf92:: ds 1
-wcf93:: ds 1
-wcf94:: ds 1
-wcf95:: ds 1
-wcf96:: ds 1
-wcf97:: ds 1
-wcf98:: ds 1
-wcf99:: ds 1
-wcf9a:: ds 1
-wcf9b:: ds 1
-wcf9c:: ds 1
-wcf9d:: ds 1
-wcf9e:: ds 1
-wcf9f:: ds 1
-wcfa0:: ds 1
-wcfa1:: ds 1
-wcfa2:: ds 1
-wcfa3:: ds 1
-wcfa4:: ds 1
-wcfa5:: ds 1
-wcfa6:: ds 1
-wcfa7:: ds 1
-wcfa8:: ds 1
-wcfa9:: ds 1
-wcfaa:: ds 1
-wcfab:: ds 1
-wcfac:: ds 1
-wcfad:: ds 1
-wcfae:: ds 1
-wcfaf:: ds 1
-wcfb0:: ds 1
-wcfb1:: ds 1
-wcfb2:: ds 1
-wcfb3:: ds 1
-wcfb4:: ds 1
-wcfb5:: ds 1
-wcfb6:: ds 1
-wcfb7:: ds 1
-wcfb8:: ds 1
-wcfb9:: ds 1
-wcfba:: ds 1
-wcfbb:: ds 1
-wcfbc:: ds 1
-wcfbd:: ds 1
-wcfbe:: ds 1
-wcfbf:: ds 1
-wcfc0:: ds 1
-wcfc1:: ds 1
-wcfc2:: ds 1
-wcfc3:: ds 1
-wcfc4:: ds 1
-wcfc5:: ds 1
-wcfc6:: ds 1
-wcfc7:: ds 1
-wcfc8:: ds 1
-wcfc9:: ds 1
+
+wStringBuffer1:: ds 19 ; cf6b
+wStringBuffer2:: ds 19 ; cf7e
+wStringBuffer3:: ds 19 ; cf91
+wStringBuffer4:: ds 19 ; cfa4
+wStringBuffer5:: ds 19 ; cfb7
+
wcfca:: ds 1
wcfcb:: ds 1
wcfcc:: ds 1
@@ -7948,3 +7862,5 @@ wStackBottom::
wStack::
wStackTop::
ds 1
+
+INCLUDE "sram.asm"