document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. ; Copies data to the SNES RAM
  2. ; @input    DE: Packet data
  3. ; @input    HL: Graphical data address
  4. ; @input    [_AUXVAR]: Flag that indicates if we are copying 2bbp tile data
  5. copysnes:
  6.     di
  7.     push    de
  8.     call    display_off             ; We disble interruptions and turn off the LCD because we are going to modify the VRAM data
  9.     ld      a%11100100
  10.     ld      [rBGP], a               ; VRAM-transfer background palette value
  11.     ld      de, _VRAM + 2048
  12.     ld      a[_AUXVAR]
  13.     and     a
  14.     jr      z,  .copysnes_0
  15.     call    parsesgbbordertiles     ; Turns the 2bpp graphics into 4bpp
  16.     jr      .copysnes_1
  17. .copysnes_0:
  18.     ld      bc, 4096
  19.     call    copymem                 ; We copy to the Game Boy VRAM the 4KB data that is going to be transferred to the SNES RAM
  20. .copysnes_1:
  21.     ; We copy to the visible _SCRN0 background the 4KB data that is going to be transferred to the SNES RAM by VRAM-transfer
  22.     ld      hl, _SCRN0
  23.     ld      de, 12                  ; Background additional width
  24.     ld      a$80                 ; VRAM address of the first tile
  25.     ld      c13                  ; Rows of data to be copied
  26. .copysnes_2:
  27.     ld      b20                  ; Visible background width
  28. .copysnes_3:
  29.     ld      [hli]a               ; Tile set
  30.     inc     a
  31.     dec     b
  32.     jr      nz, .copysnes_3
  33.     add     hl, de                  ; Next visible background tile row
  34.     dec     c
  35.     jr      nz, .copysnes_2
  36.     ld      a,  LCDCF_DEFAULT
  37.     ld      [rLCDC],    a           ; We turn on the LCD so the transfer can be made
  38.     pop     hl                      ; Packet definition
  39.     call    sgbpackettransfer       ; We send the packet that will produce the transfer
  40.     xor     a
  41.     ld      [rBGP], a               ; We restore the background palette
  42.     ret
  43.  
  44. ; Turns the 2bbp graphics pointed by HL to 4bpp and stores them in the address pointed by DE
  45. parsesgbbordertiles:
  46.     ld      b128
  47. .parsesgbbordertiles_0:
  48.     ; We copy the data of the 1 and 2 bit planes of the tiles
  49.     ld      c16
  50. .parsesgbbordertiles_1:
  51.     ld      a[hli]
  52.     ld      [de],   a
  53.     inc     de
  54.     dec     c
  55.     jr      nz, .parsesgbbordertiles_1
  56.     ; The 3 and 4 bit planes are set to zero
  57.     ld      c16
  58.     xor     a
  59. .parsesgbbordertiles_2:
  60.     ld      [de],   a
  61.     inc     de
  62.     dec     c
  63.     jr      nz, .parsesgbbordertiles_2
  64.     dec     b
  65.     jr      nz, .parsesgbbordertiles_0
  66.     ret
');