; Copies data to the SNES RAM
; @input DE: Packet data
; @input HL: Graphical data address
; @input [_AUXVAR]: Flag that indicates if we are copying 2bbp tile data
copysnes:
di
push de
call display_off ; We disble interruptions and turn off the LCD because we are going to modify the VRAM data
ld a, %11100100
ld [rBGP], a ; VRAM-transfer background palette value
ld de, _VRAM + 2048
ld a, [_AUXVAR]
and a
jr z, .copysnes_0
call parsesgbbordertiles ; Turns the 2bpp graphics into 4bpp
jr .copysnes_1
.copysnes_0:
ld bc, 4096
call copymem ; We copy to the Game Boy VRAM the 4KB data that is going to be transferred to the SNES RAM
.copysnes_1:
; We copy to the visible _SCRN0 background the 4KB data that is going to be transferred to the SNES RAM by VRAM-transfer
ld hl, _SCRN0
ld de, 12 ; Background additional width
ld a, $80 ; VRAM address of the first tile
ld c, 13 ; Rows of data to be copied
.copysnes_2:
ld b, 20 ; Visible background width
.copysnes_3:
ld [hli], a ; Tile set
inc a
dec b
jr nz, .copysnes_3
add hl, de ; Next visible background tile row
dec c
jr nz, .copysnes_2
ld a, LCDCF_DEFAULT
ld [rLCDC], a ; We turn on the LCD so the transfer can be made
pop hl ; Packet definition
call sgbpackettransfer ; We send the packet that will produce the transfer
xor a
ld [rBGP], a ; We restore the background palette
ret
; Turns the 2bbp graphics pointed by HL to 4bpp and stores them in the address pointed by DE
parsesgbbordertiles:
ld b, 128
.parsesgbbordertiles_0:
; We copy the data of the 1 and 2 bit planes of the tiles
ld c, 16
.parsesgbbordertiles_1:
ld a, [hli]
ld [de], a
inc de
dec c
jr nz, .parsesgbbordertiles_1
; The 3 and 4 bit planes are set to zero
ld c, 16
xor a
.parsesgbbordertiles_2:
ld [de], a
inc de
dec c
jr nz, .parsesgbbordertiles_2
dec b
jr nz, .parsesgbbordertiles_0
ret