;*****************************************************************
; Procedure Name  : put_mega_tile
;
; Author          : Marc Gale (Xalthorn or Eldara)
;
; Description     : Places a single 2x2 tile on the background or
;                   window (depending upon where you tell it the
;                   base address of the tile map is)
;
; On Entry        : A  = Tile bank for the tile
;                   B  = Y position (0-31)
;                   C  = Base tile number
;                   D  = Palette number
;                   E  = X position (0-31)
;                   HL = Base address of tile map
;
; During          : All registers are used
;
; On Exit         : Nothing intentional
;*****************************************************************
put_mega_tile:
 sla    a               ; move the ...
 sla    a               ; ... bank number to the ...
 sla    a               ; correct bit
 or     d               ; mix it with the palette number
 ld     d,a             ; store the result in d
 push   de              ; preserve d for later

 ld     a,0             ; select ...
 ldh    [$4F],a         ; ... data bank 0

 ld     d,0             ; set the high byte of DE to 0
 add    hl,de           ; increase the map pointer

 ld     a,b             ; grab the y position
 ld     b,32            ; put 32 (a row width) into b
 call   multiply_8      ; multiply a x b
 add    hl,de           ; add the result to the map pointer

 push   hl              ; preserve the map pointer
 ld     a,c             ; get the first tile number
 ld     [hli],a         ; place it on the map and increase HL
 inc    a               ; next tile number
 ld     [hli],a         ; place it on the map
 inc    a               ; next tile number
 ld     [hli],a         ; place it on the map
 inc    a               ; next tile number
 ld     [hl],a          ; place it on the map
 inc    a               ; next tile number

 ld     d,0             ; set up DE ...
 ld     e,29            ; ... to hold 29
 add    hl,de           ; add 29 to map pointer (one row down,
                        ; three tiles back)
 ld     [hli],a         ; place it on the map and increase HL
 inc    a               ; next tile number
 ld     [hli],a         ; place it on the map
 inc    a               ; next tile number
 ld     [hli],a         ; place it on the map
 inc    a               ; next tile number
 ld     [hl],a          ; place it on the map
 inc    a               ; next tile number

 add    hl,de           ; add 29 to map pointer (one row down,
                        ; three tiles back)
 ld     [hli],a         ; place it on the map and increase HL
 inc    a               ; next tile number
 ld     [hli],a         ; place it on the map
 inc    a               ; next tile number
 ld     [hli],a         ; place it on the map
 inc    a               ; next tile number
 ld     [hl],a          ; place it on the map
 inc    a               ; next tile number

 add    hl,de           ; add 29 to map pointer (one row down,
                        ; three tiles back)
 ld     [hli],a         ; place it on the map and increase HL
 inc    a               ; next tile number
 ld     [hli],a         ; place it on the map
 inc    a               ; next tile number
 ld     [hli],a         ; place it on the map
 inc    a               ; next tile number
 ld     [hl],a          ; place it on the map

 ld     a,1             ; switch to data ...
 ldh    [$4F],a         ; ... bank 1

 pop    hl              ; restore map pointer
 pop    de              ; restore bank 1 data
 ld     a,d             ; get the bank 1 data
 ld	b,a		; preserve the data
 ld     [hli],a         ; place it on the map, increase HL
 ld     [hli],a         ; place it on the map, increase HL
 ld     [hli],a         ; place it on the map, increase HL
 ld     [hli],a         ; place it on the map, increase HL
 ld     d,0             ; set up DE ...
 ld     e,29            ; ... to hold 29
 add    hl,de           ; add 29 to map pointer (one row down,
                        ; three tiles back)
 ld	a,b		; restore the data
 ld     [hli],a         ; place it on the map, increase HL
 ld     [hli],a         ; place it on the map, increase HL
 ld     [hli],a         ; place it on the map, increase HL
 ld     [hli],a         ; place it on the map, increase HL
 ld     d,0             ; set up DE ...
 ld     e,29            ; ... to hold 29
 add    hl,de           ; add 29 to map pointer (one row down,
                        ; three tiles back)
 ld	a,b		; restore the data
 ld     [hli],a         ; place it on the map, increase HL
 ld     [hli],a         ; place it on the map, increase HL
 ld     [hli],a         ; place it on the map, increase HL
 ld     [hli],a         ; place it on the map, increase HL
 ld     d,0             ; set up DE ...
 ld     e,29            ; ... to hold 29
 add    hl,de           ; add 29 to map pointer (one row down,
                        ; three tiles back)
 ld	a,b		; restore the data
 ld     [hli],a         ; place it on the map, increase HL
 ld     [hli],a         ; place it on the map, increase HL
 ld     [hli],a         ; place it on the map, increase HL
 ld     [hli],a         ; place it on the map, increase HL
 ld     d,0             ; set up DE ...
 ld     e,29            ; ... to hold 29
 add    hl,de           ; add 29 to map pointer (one row down,
                        ; three tiles back)

 ret                    ; we're done
