
SECTION "header", ROM0[$100]
    jp MyCode       ;; jump to where my code starts
    ds $150 - @, 0  ;; reserve space for header data
MyCode:
    ;; first we need to wait till rendering is done.
    ;; We'll do that by looping until the line counter is 144.
    ldh a, [$FF44]  ;; load the line counter value
    cp 144          ;; compare it to 144
    jp nz, MyCode   ;; if the cp was non-zero, meaning the line counter isn't 144, jump back to the start

    xor a           ;; fancy version of ld a, 0
    ldh [$ff40], a  ;; turn off the display

    ld a, %11100100 ;; put a value to use as the background colour palette 
    ld [$FF47], a   ;; copy the value to the background palette memory location

    ;; copy a tile to VRAM
    ld hl, $8000    ;; this is the start address of where to copy to
    ld BC, .TileData;; this is the start address of where to copy from
    ld D, 16        ;; set a counter, we need to copy 16 bytes
    
.copyLoop
    ld a, [BC]      ;; load data from the source address into a
    inc BC          ;; increment the source address to the next byte
    ld [hli], a     ;; load the data to the destination and increment the destination address
    dec D           ;; decrement D
    jp nz, .copyLoop;; check if we reached zero, if not keep looping

    ld a, %10010001 ;; this value will turn the screen on and set some display properties
    ld [$ff40], a   ;; store that value to the LCD control register

    ;; we're done, loop forever
.infLoop
    jp .infLoop

    ;; this is the tile we'll copy
    ;; it uses the ` prefix to make it easy to hardcode graphics data.
.TileData
    dw `00030000
    dw `00333330
    dw `00111000
    dw `00111000
    dw `02222200
    dw `20222020
    dw `00333000
    dw `03303300