From 32b02147925566bac93bf71b002860335583574c Mon Sep 17 00:00:00 2001 From: ElectroDeoxys Date: Thu, 9 Sep 2021 08:51:12 +0100 Subject: Split home bank --- src/home/bg_map.asm | 117 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 src/home/bg_map.asm (limited to 'src/home/bg_map.asm') diff --git a/src/home/bg_map.asm b/src/home/bg_map.asm new file mode 100644 index 0000000..c49f179 --- /dev/null +++ b/src/home/bg_map.asm @@ -0,0 +1,117 @@ +; reads structs: +; x (1 byte), y (1 byte), data (n bytes), $00 +; x (1 byte), y (1 byte), data (n bytes), $00 +; ... +; $ff +; for each struct, writes data to BGMap0-translated x,y +WriteDataBlocksToBGMap0: ; 0695 (0:0695) + call WriteDataBlockToBGMap0 + bit 7, [hl] ; check for $ff + jr z, WriteDataBlocksToBGMap0 + ret + +; reads struct: +; x (1 byte), y (1 byte), data (n bytes), $00 +; writes data to BGMap0-translated x,y +WriteDataBlockToBGMap0: ; 069d (0:069d) + ld b, [hl] + inc hl + ld c, [hl] + inc hl + push hl ; hl = addr of data + push bc ; b,c = x,y + ld b, -1 +.find_zero_loop + inc b + ld a, [hli] + or a + jr nz, .find_zero_loop + ld a, b ; length of data + pop bc ; x,y + push af + call BCCoordToBGMap0Address + pop af + ld b, a ; length of data + pop hl ; addr of data + or a + jr z, .move_to_next + push bc + push hl + call SafeCopyDataHLtoDE ; copy data to de (BGMap0 translated x,y) + pop hl + pop bc + +.move_to_next + inc b ; length of data += 1 (to account for the last $0) + ld c, b + ld b, 0 + add hl, bc ; point to next structure + ret + +; writes a to [v*BGMap0 + BG_MAP_WIDTH * c + b] +WriteByteToBGMap0: ; 06c3 (0:06c3) + push af + ld a, [wLCDC] + rla + jr c, .lcd_on + pop af + push hl + push de + push bc + push af + call BCCoordToBGMap0Address + pop af + ld [de], a + pop bc + pop de + pop hl + ret +.lcd_on + pop af +; fallthrough + +; writes a to [v*BGMap0 + BG_MAP_WIDTH * c + b] during hblank +HblankWriteByteToBGMap0: ; 06d9 + push hl + push de + push bc + ld hl, wTempByte + push hl + ld [hl], a + call BCCoordToBGMap0Address + pop hl + ld b, 1 + call HblankCopyDataHLtoDE + pop bc + pop de + pop hl + ret + +; copy a bytes of data from hl to vBGMap0 address pointed to by coord at bc +CopyDataToBGMap0: ; 06ee (0:06ee) + push bc + push hl + push af + call BCCoordToBGMap0Address + pop af + ld b, a + pop hl + call SafeCopyDataHLtoDE + pop bc + ret + +; copy b bytes of data from hl to de +; if LCD on, copy during h-blank only +SafeCopyDataHLtoDE: ; 6fc (0:6fc) + ld a, [wLCDC] + rla + jr c, JPHblankCopyDataHLtoDE +.lcd_off_loop + ld a, [hli] + ld [de], a + inc de + dec b + jr nz, .lcd_off_loop + ret +JPHblankCopyDataHLtoDE: ; 0709 (0:0709) + jp HblankCopyDataHLtoDE -- cgit v1.2.3 From 0017fc2d171c87d7bab4c9be90e1069ae95a8071 Mon Sep 17 00:00:00 2001 From: ElectroDeoxys Date: Thu, 9 Sep 2021 08:54:29 +0100 Subject: Remove home bank address comments --- src/home/bg_map.asm | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/home/bg_map.asm') diff --git a/src/home/bg_map.asm b/src/home/bg_map.asm index c49f179..43dfe7b 100644 --- a/src/home/bg_map.asm +++ b/src/home/bg_map.asm @@ -4,7 +4,7 @@ ; ... ; $ff ; for each struct, writes data to BGMap0-translated x,y -WriteDataBlocksToBGMap0: ; 0695 (0:0695) +WriteDataBlocksToBGMap0: call WriteDataBlockToBGMap0 bit 7, [hl] ; check for $ff jr z, WriteDataBlocksToBGMap0 @@ -13,7 +13,7 @@ WriteDataBlocksToBGMap0: ; 0695 (0:0695) ; reads struct: ; x (1 byte), y (1 byte), data (n bytes), $00 ; writes data to BGMap0-translated x,y -WriteDataBlockToBGMap0: ; 069d (0:069d) +WriteDataBlockToBGMap0: ld b, [hl] inc hl ld c, [hl] @@ -49,7 +49,7 @@ WriteDataBlockToBGMap0: ; 069d (0:069d) ret ; writes a to [v*BGMap0 + BG_MAP_WIDTH * c + b] -WriteByteToBGMap0: ; 06c3 (0:06c3) +WriteByteToBGMap0: push af ld a, [wLCDC] rla @@ -88,7 +88,7 @@ HblankWriteByteToBGMap0: ; 06d9 ret ; copy a bytes of data from hl to vBGMap0 address pointed to by coord at bc -CopyDataToBGMap0: ; 06ee (0:06ee) +CopyDataToBGMap0: push bc push hl push af @@ -113,5 +113,5 @@ SafeCopyDataHLtoDE: ; 6fc (0:6fc) dec b jr nz, .lcd_off_loop ret -JPHblankCopyDataHLtoDE: ; 0709 (0:0709) +JPHblankCopyDataHLtoDE: jp HblankCopyDataHLtoDE -- cgit v1.2.3