INCLUDE "hardware.inc" INCLUDE "game/game.asm" INCLUDE "tools.asm" SECTION "Header", ROM0[$100] EntryPoint: ; di ; Disable interrupts. That way we can avoid dealing with them, especially since we didn't talk about them yet jp Start ; Leave this tiny space REPT $150 - $104 db 0 ENDR SECTION "Intro code", ROM0 Start: ; First step is to access the VRAM to insert our graphics data. ; To do so, we must wait until we are in VBLANK period. ; Loop until we find ourselves in VBLANK ; Turn off the LCD .waitVBlank ld a, [rLY] ; Load the current vertical line being rendered cp 144 ; Check if we're past VBlank (1 to 144 = carry bit set) jr c, .waitVBlank ; Jump back to waitVBlank if rLY is less than 144 xor a ; ld a, 0 ; Reset the accumilator register ; Our target is to set bit 7 reset on the LDC to turn it off ld [rLCDC], a ; We will have to write to LCDC again later, so it's not a bother, really. ; ----------- Font Begin copying to VRAM ----------- ; Start copying our font to vram ld de, FontTiles ; The start of the font tiles ld hl, $9000 ; Set registers hl to $9000 which is the beginning of vram ld bc, FontTilesEnd - FontTiles ; The total length of font tiles call Memcpy ; ----------- Begin copying string to palette ----------- ld hl, $9800 ; This will print the string at the top-left corner of screen ld de, HelloWorldStr .copyString ld a, [de] ; Read the first byte in the string to accumilator ld [hli], a ; Write the byte from the accumilator to the destination while incrementing destination address inc de ; Move to next byte in string and a ; AND a with A, Checking if we copied a zero (end of string) jr nz, .copyString ; Continue copying while not zero ; ----------- Start the display ----------- ; Init the display register ld a, %11100100 ; Load the palette of white, light gray, dark gray, black ld a, %00011011 ; Load the palette of white, light gray, dark gray, black ld [rBGP], a ; Store the palette to display xor a ; ld a, 0 ; Reset the accumilator ld [rSCY], a ; Set our scroll Y position to 0 ld [rSCX], a ; Set our scroll X position to 0 ld [rNR52], a ; Turn off sound ; Turn the screen on, display background ld a, %10000001 ; screen on = 8th bit, background display = 1st bit ld [rLCDC], a ; Set the screen flags jp GameLoop SECTION "Font", ROM0 FontTiles: INCBIN "font.chr" FontTilesEnd: Section "Hello wrold string", ROM0 HelloWorldStr: db "Hello World!", 0