summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpfero <ohpee@loves.dicksinhisan.us>2018-05-31 03:45:15 +0200
committerpfero <ohpee@loves.dicksinhisan.us>2018-05-31 03:45:15 +0200
commit1af43919b11a6029d964a78e7073f362872df5fa (patch)
treeab6532a706193bb0e7925526cb97222310b4f57c
parentd63e3a21b1e743e19a9ae740497da93de1a378bf (diff)
Disassemble the delay functions and some copy functions
-rw-r--r--Makefile2
-rw-r--r--home/copy.asm110
-rw-r--r--home/delay.asm26
-rw-r--r--shim.sym4
-rw-r--r--wram.asm13
5 files changed, 148 insertions, 7 deletions
diff --git a/Makefile b/Makefile
index 52c3677..86e4925 100644
--- a/Makefile
+++ b/Makefile
@@ -8,7 +8,7 @@ RGBGFX := rgbgfx
RGBLINK := rgblink
RGBFIX := rgbfix
-RGBASMFLAGS := -E -i $(BUILD)/
+RGBASMFLAGS := -h -E -i $(BUILD)/
tools/gfx :=
ROMS := pokegold-spaceworld.gb
diff --git a/home/copy.asm b/home/copy.asm
index ab0205f..b361eeb 100644
--- a/home/copy.asm
+++ b/home/copy.asm
@@ -1,6 +1,114 @@
INCLUDE "constants.asm"
-SECTION "Copy functions", ROM0[$32F7]
+SECTION "Copy functions", ROM0[$0D2A]
+
+FarCopyData::
+; copy bc bytes from a:hl to de
+ ld [wBuffer], a
+ ldh a, [hROMBank]
+ push af
+ ld a, [wBuffer]
+ call Bankswitch
+
+ call CopyBytes
+
+ pop af
+ call Bankswitch
+ ret
+
+
+FarCopyBytesDouble:
+; Copy bc bytes from a:hl to bc*2 bytes at de,
+; doubling each byte in the process.
+
+ ld [wBuffer], a
+ ldh a, [hROMBank]
+ push af
+ ld a, [wBuffer]
+ call Bankswitch
+
+; switcheroo, de <> hl
+ ld a, h
+ ld h, d
+ ld d, a
+ ld a, l
+ ld l, e
+ ld e, a
+ ld a, b
+ and a
+ jr z, .inc
+
+ ld a, c
+ and a
+ jr z, .loop
+
+.inc
+ inc b
+
+.loop
+ ld a, [de]
+ inc de
+ ld [hli], a
+ ld [hli], a
+ dec c
+ jr nz, .loop
+
+ dec b
+ jr nz, .loop
+
+ pop af
+ call Bankswitch
+ ret
+
+
+Request2bpp::
+ ldh a, [hBGMapMode]
+ push af
+ xor a
+ ldh [hBGMapMode], a
+
+ ldh a, [hROMBank]
+ push af
+ ld a, b
+ call Bankswitch
+
+ ld a, e
+ ld [wRequested2bppSource], a
+ ld a, d
+ ld [wRequested2bppSource + 1], a
+ ld a, l
+ ld [wRequested2bppDest], a
+ ld a, h
+ ld [wRequested2bppDest + 1], a
+
+.loop
+ ; Keep looping bigcopy until we have less than 8 bytes left
+ ld a, c
+ cp 8
+ jr nc, .bigcopy
+
+ ld [wRequested2bpp], a
+ call DelayFrame
+
+ pop af
+ call Bankswitch
+ pop af
+ ldh [hBGMapMode], a
+ ret
+
+.bigcopy
+ ; Copy 8 bytes
+ ld a, 8
+ ld [wRequested2bpp], a
+ call DelayFrame
+
+ ld a, c
+ sub 8
+ ld c, a
+ jr .loop
+
+
+SECTION "Second copy functions", ROM0[$32F7]
FarCopyBytes:: ; 32f7
ld [wBuffer], a
diff --git a/home/delay.asm b/home/delay.asm
new file mode 100644
index 0000000..dc3ad40
--- /dev/null
+++ b/home/delay.asm
@@ -0,0 +1,26 @@
+INCLUDE "constants.asm"
+
+SECTION "Delay", ROM0[$0317]
+
+DelayFrame::
+; Wait for one frame
+ ld a, 1
+ ld [wVBlankOccurred], a
+
+; Wait for the next VBlank, halting to conserve battery
+.halt
+ halt ; rgbasm adds a nop after this instruction by default
+ ld a, [wVBlankOccurred]
+ and a
+ jr nz, .halt
+
+ ret
+
+
+DelayFrames::
+; Wait c frames
+ call DelayFrame
+ dec c
+ jr nz, DelayFrames
+
+ ret
diff --git a/shim.sym b/shim.sym
index c113eb1..0b5e183 100644
--- a/shim.sym
+++ b/shim.sym
@@ -1,12 +1,8 @@
; ROM0
-00:0317 DelayFrame
-00:0324 DelayFrames
00:0884 UpdateJoypad
00:095E UncompressSpriteData
00:0d1a LoadFontExtra
00:0d0a LoadFont
-00:0D2A FarCopyData
-00:0D68 CopyVideoData
00:0DE4 CopyVideoDataOptimized
00:0E2A ClearTileMap
00:0e3d DrawTextBox
diff --git a/wram.asm b/wram.asm
index 0b84002..15c5be6 100644
--- a/wram.asm
+++ b/wram.asm
@@ -85,7 +85,18 @@ SECTION "CB56", WRAM0[$CB5B]
wcb5b:: ds 1
wNameCategory:: ds 1
-SECTION "CC38", WRAM0[$CC38] ; Please merge when more is disassembled
+SECTION "Request2bpp", WRAM0[$CB62]
+
+wRequested2bpp:: db
+wRequested2bppSource:: dw
+wRequested2bppDest:: dw
+
+
+SECTION "CC38", WRAM0[$CC33] ; Please merge when more is disassembled
+
+wVBlankOccurred: db
+
+ ds 4
wcc38:: ; cc38 ; TODO: wceeb in pokegold, what is this?
db