Skip to content

Instantly share code, notes, and snippets.

@LIJI32
Created June 3, 2017 10:17
Show Gist options
  • Save LIJI32/568a68e88d6670dcbd4d137838406333 to your computer and use it in GitHub Desktop.
Save LIJI32/568a68e88d6670dcbd4d137838406333 to your computer and use it in GitHub Desktop.
gb_frameskip_test
INCLUDE "gbhw.asm" ; Available at https://github.com/LIJI32/GBVideoPlayer/blob/master/gbhw.asm
SECTION "VBlank", ROM0[$40]
jp VBlank
SECTION "Header", ROM0[$100]
Start::
di
jp _Start
SECTION "Home", ROM0[$150]
_Start::
; Init the stack
ld sp, $fffe
; Other inits
call LCDOff
call LoadGraphics
call CreateMap
; Enable interrupts
ld a, 1
ldh [rIE], a
ei
call LCDOn
jp Main
WaitVBlank::
ldh a, [rLY]
cp 145
jr nz, WaitVBlank
ret
LCDOff::
call WaitVBlank
ldh a, [rLCDC]
and $7F
ldh [rLCDC], a
ret
LCDOn::
di
ldh a, [rLCDC]
or $80
ldh [rLCDC], a
call WaitVBlank
xor a
ldh [rIF], a
reti
LoadGraphics::
ld de, $8010
ld b, (GraphicsEnd - Graphics)
ld hl, Graphics
.loop
ld a, [hli]
ld [de], a
inc de
ld [de], a
inc de
dec b
jr nz, .loop
ret
CreateMap::
ld hl, $9800
ld a, 0
ld c, 16
xor a
.loopY
ld b, 32
.loopX
ld [hli], a
dec b
jr nz, .loopX
dec c
jr nz, .loopY
inc a
ld [$9911], a
ret
Graphics::
db %00011000
db %00111100
db %01111110
db %11111111
db %11111111
db %01111110
db %00111100
db %00011000
GraphicsEnd::
VBlank:
ei
ld b, 1
ld a, [$9911]
xor b
ld [$9911], a
ld a, [$98c2]
xor b
ld [$98c2], a
ret z
ldh a, [rLCDC]
xor $80
ldh [rLCDC], a
xor $80
ldh [rLCDC], a
ret
Main:
halt
jp Main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment