summaryrefslogtreecommitdiff
path: root/home
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 /home
parentd63e3a21b1e743e19a9ae740497da93de1a378bf (diff)
Disassemble the delay functions and some copy functions
Diffstat (limited to 'home')
-rw-r--r--home/copy.asm110
-rw-r--r--home/delay.asm26
2 files changed, 135 insertions, 1 deletions
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