Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; Define hardware macros/shortcuts
- INCLUDE "hardware.inc"
- ; Setup Header of memory type ROM0, start at 100h
- ; 100h is where execution of code begins.
- SECTION "Header", ROM0[$100]
- EntryPoint:
- di ; Disable Interupts
- jp Begin ; Begin our program!
- REPT $150 - $104
- db 0
- ENDR
- ; The section of code that'll contain our actual game.
- ; Start location isn't specified, doesn't need to be.
- SECTION "Game", ROM0
- Begin:
- ; Turn off the LCD
- .waitVBlank
- ld a, [rLY] ; Load LCD draw status
- cp 144 ; Check if LCD is past VBlank time.
- jr c, .waitVBlank
- ; Past VBlank, reset LCD mode
- xor a ; == ld a, 0
- ld [rLCDC], a
- ; Now that the LCD is off so is the PPU
- ; We can now access VRAM freely.
- ld hl, _VRAM+$1000 ; Tile RAM
- ; Get size of Font in bytes
- ld de, tiFnt
- ld bc, tiFntEd - tiFnt
- .copyFont
- ld a, [de] ; Grab byte from Font
- ld [hli], a ; *HL = a; HL++;
- inc de ; Move to next byte in font
- dec bc ; Decrease bytes to load.
- ld a, b ; 16bit inc/dec don't update flags. Update flags using load.
- or c ; a or c, if b and c are both zero, our copy is done.
- jr nz, .copyFont
- ; Copy string to print
- ld hl, _SCRN0 ; Start print at X:0,Y:0 tiles
- ld de, HelloStr ; Load 1st byte of string
- .copyString
- ld a, [de] ; a = (char) *de
- ld [hli], a ; *hl = a, hl++
- inc de ; de++
- or a ; == cp 0
- jr nz, .copyString ; If a != 0 then; get next char
- ; Init display regs
- ld a, %11100100 ; Load palette, 11 10 01 00. Black,Gray,LightGray,White
- ld [rBGP], a ; Background Palette Data
- ; Reset BG scroll X/Y
- xor a ; == ld a, 0
- ld [rSCY], a
- ld [rSCX], a
- ; Shut off APU (Sound)
- ; bit7 is all that matters, although other bits don't do anything
- ; and 7 ends up controlling all the other channels so, meh set it to 0.
- ld [rNR52], a
- ; Turn screen on, display the background!
- ld a, %10000001 ; LCDCF_ON | LCDCF_BGON
- ld [rLCDC], a ; Set display flags
- ; Lock the CPU for safety reasons.
- .lockcpu
- jr .lockcpu
- ; Finally, actually making the font!
- SECTION "Font", ROM0
- tiFnt:
- INCBIN "font.chr" ; Tells RGBDS to copy the contents of font.chr into this ROM section.
- tiFntEd:
- Section "Text", ROM0
- HelloStr:
- db "Hello GBZ80 World!", 0 ; End with byte 0 as string return (\0 in C)
- ; db for bytes, alternatively -
- ; dw for words (16bits) and
- ; dl for longs (32bits).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement