summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--home/copy.asm113
-rw-r--r--home/copy2.asm177
-rw-r--r--shim.sym1
-rw-r--r--wram.asm14
4 files changed, 189 insertions, 116 deletions
diff --git a/home/copy.asm b/home/copy.asm
index b361eeb..b289aea 100644
--- a/home/copy.asm
+++ b/home/copy.asm
@@ -1,115 +1,8 @@
INCLUDE "constants.asm"
-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]
+SECTION "Copy functions", ROM0[$32F7]
+; Copy bc bytes from a:hl to de.
FarCopyBytes:: ; 32f7
ld [wBuffer], a
ldh a, [hROMBank]
@@ -120,6 +13,7 @@ FarCopyBytes:: ; 32f7
pop af
jp Bankswitch
+; Copy bc bytes from hl to de
CopyBytes:: ; 330a
ld a, b
and a
@@ -134,6 +28,7 @@ CopyBytes:: ; 330a
jr nz, .next
ret
+; Copy c bytes from hl to de
CopyBytesSmall:: ; 331a
ld a, [hli]
ld [de], a
diff --git a/home/copy2.asm b/home/copy2.asm
new file mode 100644
index 0000000..27abf08
--- /dev/null
+++ b/home/copy2.asm
@@ -0,0 +1,177 @@
+INCLUDE "constants.asm"
+
+SECTION "Video Copy functions", ROM0[$0D2A]
+
+; Identical to FarCopyBytes except for tail call optimization
+; Copy bc 2bpp bytes from a:hl to de.
+FarCopyData: ; d2a (0:d2a)
+ ld [wBuffer], a
+ ldh a, [hROMBank]
+ push af
+ ld a, [wBuffer]
+ call Bankswitch
+ call CopyBytes
+ pop af
+ call Bankswitch
+ ret
+
+; Copy and expand bc 1bpp bytes from a:hl to de.
+FarCopyDataDouble: ; d3e (0:d3e)
+ ld [wBuffer], a
+ ldh a, [hROMBank]
+ push af
+ ld a, [wBuffer]
+ call Bankswitch
+ 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, .copy_small
+ ld a, c
+ and a
+ jr z, .next
+.copy_small
+ inc b
+.next
+ ld a, [de]
+ inc de
+ ld [hli], a
+ ld [hli], a
+ dec c
+ jr nz, .next
+ dec b
+ jr nz, .next
+ pop af
+ call Bankswitch
+ ret
+
+; Wait for the next VBlank, then copy c 2bpp
+; tiles from b:de to hl, 8 tiles at a time.
+; This takes c/8 frames.
+CopyVideoData:: ; d68 (0:d68)
+ ldh a, [hBGMapMode]
+ push af
+ xor a ; disable auto-transfer while copying
+ ldh [hBGMapMode], a
+ ldh a, [hROMBank]
+ push af
+ ld a, b
+ call Bankswitch
+ ld a, e
+ ld [wVBCopySrc], a
+ ld a, d
+ ld [wVBCopySrc + 1], a
+ ld a, l
+ ld [wVBCopyDst], a
+ ld a, h
+ ld [wVBCopyDst + 1], a
+.loop
+ ld a, c
+ cp $08
+ jr nc, .keepgoing
+ ld [wVBCopySize], a
+ call DelayFrame
+ pop af
+ call Bankswitch
+ pop af
+ ldh [hBGMapMode], a
+ ret
+.keepgoing
+ ld a, $08
+ ld [wVBCopySize], a
+ call DelayFrame
+ ld a, c
+ sub $08
+ ld c, a
+ jr .loop
+
+; Wait for the next VBlank, then copy c 1bpp
+; tiles from b:de to hl, 8 tiles at a time.
+; This takes c/8 frames.
+CopyVideoDataDouble:: ; da6 (0:da6)
+ ldh a, [hBGMapMode]
+ push af
+ xor a
+ ldh [hBGMapMode], a
+ ldh a, [hROMBank]
+ push af
+ ld a, b
+ call Bankswitch
+ ld a, e
+ ld [wVBCopyDoubleSrc], a
+ ld a, d
+ ld [wVBCopyDoubleSrc + 1], a
+ ld a, l
+ ld [wVBCopyDoubleDst], a
+ ld a, h
+ ld [wVBCopyDoubleDst + 1], a
+.loop
+ ld a, c
+ cp $08
+ jr nc, .keepgoing
+ ld [wVBCopyDoubleSize], a
+ call DelayFrame
+ pop af
+ call Bankswitch
+ pop af
+ ldh [hBGMapMode], a
+ ret
+.keepgoing
+ ld a, $08
+ ld [wVBCopyDoubleSize], a
+ call DelayFrame
+ ld a, c
+ sub $08
+ ld c, a
+ jr .loop
+
+; Copy c 2bpp tiles from b:de to hl in VRAM
+; using VBlank service or direct copy in
+; case LCD is off
+CopyVideoDataOptimized:: ; de4 (0:de4)
+ ldh a, [rLCDC]
+ bit rLCDC_ENABLE, a
+ jp nz, CopyVideoData ; copy video data during vblank while screen is on
+ push hl ; convert to FarCopyData call
+ ld h, d
+ ld l, e
+ pop de
+ ld a, b
+ push af
+ swap c
+ ld a, $0f
+ and c
+ ld b, a
+ ld a, $f0
+ and c
+ ld c, a
+ pop af
+ jp FarCopyData
+
+; Copy c 1bpp tiles from b:de to hl in VRAM
+; using VBlank service or direct copy in
+; case LCD is off
+CopyVideoDataDoubleOptimized: ; dff (0:dff)
+ ldh a, [rLCDC]
+ bit rLCDC_ENABLE, a
+ jp nz, CopyVideoDataDouble
+ push de
+ ld d, h
+ ld e, l
+ ld a, b
+ push af
+ ld h, $00
+ ld l, c
+ add hl, hl
+ add hl, hl
+ add hl, hl
+ ld b, h
+ ld c, l
+ pop af
+ pop hl
+ jp FarCopyDataDouble
+; 0xe18 \ No newline at end of file
diff --git a/shim.sym b/shim.sym
index 0b5e183..2110f12 100644
--- a/shim.sym
+++ b/shim.sym
@@ -3,7 +3,6 @@
00:095E UncompressSpriteData
00:0d1a LoadFontExtra
00:0d0a LoadFont
-00:0DE4 CopyVideoDataOptimized
00:0E2A ClearTileMap
00:0e3d DrawTextBox
00:0E93 PlaceString
diff --git a/wram.asm b/wram.asm
index 15c5be6..8e0d784 100644
--- a/wram.asm
+++ b/wram.asm
@@ -85,14 +85,16 @@ SECTION "CB56", WRAM0[$CB5B]
wcb5b:: ds 1
wNameCategory:: ds 1
-SECTION "Request2bpp", WRAM0[$CB62]
+SECTION "CB62", WRAM0[$CB62]
-wRequested2bpp:: db
-wRequested2bppSource:: dw
-wRequested2bppDest:: dw
+wVBCopySize:: ds 1
+wVBCopySrc:: ds 2
+wVBCopyDst:: ds 2
+wVBCopyDoubleSize:: ds 1
+wVBCopyDoubleSrc:: ds 2
+wVBCopyDoubleDst:: ds 2
-
-SECTION "CC38", WRAM0[$CC33] ; Please merge when more is disassembled
+SECTION "CC33", WRAM0[$CC33] ; Please merge when more is disassembled
wVBlankOccurred: db