Skip to content

Instantly share code, notes, and snippets.

@SelvinPL
Last active June 11, 2025 13:26
Show Gist options
  • Select an option

  • Save SelvinPL/4645246dbb8551b0b25bb97fbe0f6bfb to your computer and use it in GitHub Desktop.

Select an option

Save SelvinPL/4645246dbb8551b0b25bb97fbe0f6bfb to your computer and use it in GitHub Desktop.
db $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$2E,$FF,$00,$76,$89,$DB,$AD,$BD,$EB,$EB,$FF,$FF,$FF,$FF,$FF,$00,$10,$00,$38,$38,$7C,$44,$FE,$00,$7C,$00,$FF,$00,$FF,$00,$FF,$00,$11,$00,$BB,$38,$FF,$44,$FF,$00,$FF,$00,$FF,$00,$FF,$00,$FF,$00,$10,$00,$B8,$38,$FC,$44,$FE,$00,$FC,$00,$FF,$00,$FF,$00,$FF,$00,$11,$00,$BB,$BA,$FF,$45,$FF,$BA,$FF,$45,$FF,$BA,$FF,$45,$FF,$55,$FF,$BA,$FF,$45,$FF,$BA,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$3F,$3F,$40,$40,$80,$80,$80,$80,$80,$80,$80,$80,$40,$40,$3F,$3F,$FF,$FF,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$FF,$FF,$FC,$FC,$02,$02,$01,$01,$01,$01,$01,$01,$01,$01,$02,$02,$FC,$FC
db $0A,$00,$08,$09,$0A,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$08,$09,$0A,$00,$00,$00,$08,$09,$09,$00,$08,$09,$0A,$00,$00,$08,$09,$0A,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$08,$09,$09,$0A,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$0A,$00,$00,$00,$00,$00,$00,$00,$00,$08,$09,$09,$09,$09,$09,$09,$09,$0A,$00,$08,$09,$0A,$00,$00,$00,$00,$00,$00,$08,$09,$09,$09,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$08,$09,$0A,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$06,$06,$06,$06,$06,$06,$06,$06,$06,$06,$06,$06,$06,$06,$06,$06,$06,$06,$06,$06,$06,$06,$06,$06,$06,$06,$06,$06,$06,$06,$06,$06,$07,$07,$07,$07,$07,$07,$07,$07,$07,$07,$07,$07,$07,$07,$07,$07,$07,$07,$07,$07,$07,$07,$07,$07,$07,$07,$07,$07,$07,$07,$07,$07,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01
INCLUDE "hardware.inc"
DEF trees_start EQU 104
DEF ground_start EQU 120
DEF clouds_speed EQU 1
DEF trees_speed EQU 2
DEF ground_speed EQU 3
SECTION "Header", ROM0[$100]
jp EntryPoint
ds $150 - @, 0 ; Make room for the header
EntryPoint:
; Shut down audio circuitry
ld a, 0
ld [rNR52], a
; Do not turn the LCD off outside of VBlank
call WaitVBlank
; Turn the LCD off
ld a, 0
ld [rLCDC], a
; Copy the tile data
ld de, Tiles
ld hl, $9000
ld bc, TilesEnd - Tiles
call Memcpy
; Copy the tilemap
ld de, Tilemap
ld hl, $9800
ld bc, TilemapEnd - Tilemap
call Memcpy
; Initializing global variables
xor a
ld [wFrameCounter], a
ld [wCloudsYPos], a
ld [wTreesYPos], a
ld [wGroundYPos], a
; Turn the LCD on
ld a, LCDCF_ON | LCDCF_BGON
ld [rLCDC], a
; During the first (blank) frame, initialize display registers
ld a, %11100100
ld [rBGP], a
xor a
ld [rSCX], a
Main:
WaitTrees:
ldh a, [rLY]
cp a, trees_start-1
jp nz, WaitTrees
;with trees_start-1 we end in one higher than we need
;now we do some NOPs to end in mode 3
REPT 80
nop
ENDR
ld a, [wTreesYPos]
ldh [rSCX], a
WaitGround:
ldh a, [rLY]
cp a, ground_start-1
jp nz, WaitGround
;with ground_start-1 we end in one higher than we need
;now we do some NOPs to end in mode 3
REPT 80
nop
ENDR
ld a, [wGroundYPos]
ldh [rSCX], a
call WaitVBlank
ld a, [wCloudsYPos]
ldh [rSCX], a
ld a, [wFrameCounter]
inc a
;reset after every x frames
cp a, 3 ;x
jr nz, SaveFrame
xor a
SaveFrame:
ld [wFrameCounter], a
jp nz, Main
ld a, [wTreesYPos]
add a, trees_speed
ld [wTreesYPos], a
ld a, [wGroundYPos]
add a, ground_speed
ld [wGroundYPos], a
ld a, [wCloudsYPos]
add a, clouds_speed
ld [wCloudsYPos], a
jp Main
; Memcpy
; Copies memory from source address to destination address
; source de, destination hl, length bc
Memcpy:
ld a, [de]
ld [hli], a
inc de
dec bc
ld a, b
or a, c
jp nz, Memcpy
ret
WaitVBlank:
ld a, [rLY]
cp 144
jp c, WaitVBlank
ret
Tiles:
include "background.2bpp.inc"
TilesEnd:
Tilemap:
include "background.tilemap.inc"
TilemapEnd:
SECTION "Backgrond Scroll", WRAM0
wCloudsYPos: db
wTreesYPos: db
wGroundYPos: db
SECTION "Counter", WRAM0
wFrameCounter: db
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment