; vi:ft=rgbasm:
REG_LCDC	equ $ff40
REG_STAT	equ $ff41
REG_SCY		equ $ff42
REG_SCX		equ $ff43
REG_LY		equ $ff44
REG_LYC		equ $ff45
REG_BGP		equ $ff47
REG_OBP0	equ $ff48
REG_OBP1	equ $ff49
REG_WY		equ $ff4a
REG_WX		equ $ff4b

LCDC_BGON	equ $01
LCDC_OBJON	equ $02
LCDC_OBJ16	equ $04
LCDC_BGMAP_9C00	equ $08
LCDC_CHAR_8000	equ $10
LCDC_WON	equ $20
LCDC_WMAP_9C00	equ $40
LCDC_DISPON	equ $80

section "hdr", ROM0[$100]
	nop
	jp main

rept $150 - $104
	db 0
endr

section "text", ROM0

main:
	ldh a, [REG_LY]
	cp a, 144
	jr c, main

	; disable the display
	xor a, a
	ldh [REG_LCDC], a

	ld hl, $8000	; point hl to character data area (tiles)
	ld de, tile0
	ld c, tiles_end - tile0
.copytile:
	ld a, [de]
	ld [hl+], a
	inc de
	dec c
	jr nz, .copytile

	ld hl, $9800	; point hl to BG vram
	ld b, 18
.fillscr:
	ld c, 32
.fillrow:
	ld a, b
	add a, c
	and a, 1

	ld [hl+], a
	dec c
	jr nz, .fillrow

	dec b
	jr nz, .fillscr

	; setup identity palette
	ld a, $e4  ; 0:00 1:01 2:10 3:11
	ldh [REG_BGP], a

	; reset scroll to 0
	xor a, a
	ldh [REG_SCY], a
	ldh [REG_SCX], a

	; setup the LCDC and enable the display
	ld a, LCDC_DISPON | LCDC_CHAR_8000 | LCDC_BGON
	ldh [REG_LCDC], a

	di
.end:	halt
	nop
	jp .end

section "data", ROM0

	; lower bit,upper bit, for each row of 8 pixels
tile0: db $55,$00
	db $aa,$00
	db $55,$00
	db $aa,$00
	db $55,$00
	db $aa,$00
	db $55,$00
	db $aa,$00
tile1: db $ff,$aa
	db $ff,$55
	db $ff,$aa
	db $ff,$55
	db $ff,$aa
	db $ff,$55
	db $ff,$aa
	db $ff,$55
tiles_end: