make nintendo logo fly off like a rocket

This commit is contained in:
2019-01-04 16:50:29 +01:00
parent b2cdcc65fe
commit 99922c35f7
5 changed files with 125 additions and 30 deletions

View File

@@ -13,10 +13,6 @@ ENDR
SECTION "Main", ROM0[$150] SECTION "Main", ROM0[$150]
Start: Start:
; shut sound off
xor a
ld [rNR52], a
; enable v-blank interrupt ; enable v-blank interrupt
ld a, IEF_VBLANK ld a, IEF_VBLANK
ld [rIE], a ld [rIE], a

View File

@@ -1,26 +1,116 @@
INCLUDE "hardware.inc" INCLUDE "hardware.inc"
SECTION "NintendoLogo", ROM0 SECTION "Random", ROM0, ALIGN[4]
Random:
db -1, 1, 2, -1, 4, 3, -2, -1, -4, 3, -1, 5, 2
RandomEnd:
HaltAndClearIF: MACRO
halt
xor a
ld [rIF], a
ENDM
EXPORT ScrollNintendoOut EXPORT ScrollNintendoOut
SECTION "Scroll Nintendo Out", ROM0 SECTION "Scroll Nintendo Out", ROM0
ScrollNintendoOut: ScrollNintendoOut:
ld b, 30
; wait a moment
ld b, 32
.wait .wait
halt HaltAndClearIF
xor a
ld [rIF], a
dec b dec b
jr nz, .wait jr nz, .wait
.scrollup ; sound ON
halt ld a, $80
ldh [rNR52], a ; sound ON with noise channel
ld a, $77
ldh [rNR50], a ; max volume on both speakers
ld a, $88
ldh [rNR51], a ; noise channel on both speakers
; make noise
ld a, 0
ldh [rNR41], a ; set sound duration
ld a, $F0
ldh [rNR42], a ; set volume
ld a, $72
ldh [rNR43], a ; set frequency
ld a, $80
ldh [rNR44], a ; turn on
; nudge nintendo logo
ld d, HIGH(Random)
ld e, 0
ld b, 42
.noise
HaltAndClearIF
HaltAndClearIF
ld a, [de]
ldh [rSCY], a
inc e
ld a, e
cp a, RandomEnd - Random
jr nz, .next
ld e, 0
.next
ld a, [de]
ldh [rSCX], a
inc e
ld a, e
cp a, RandomEnd - Random
jr nz, .next2
ld e, 0
.next2
dec b
jr nz, .noise
xor a xor a
ld [rIF], a ldh [rSCY], a
; change noise
ld a, $62
ldh [rNR43], a ; set frequency
ld b, 4 ; number of frames before reducing volume
ld c, 16 ; number of steps before volume is 0
; nintendo logo lift-off!
.scrollup
HaltAndClearIF
; scroll up
ldh a, [rSCY] ldh a, [rSCY]
inc a inc a
ldh [rSCY], a ldh [rSCY], a
; fade out
ld a, c
or a
jr z, .novolumechange
dec b
jr nz, .novolumechange
; decrement volume by 1
; see http://gbdev.gg8.se/wiki/articles/Gameboy_sound_hardware obscure behavior...
ld a, $08
REPT 15
ldh [rNR42], a
ENDR
ld b, 4
dec c
.novolumechange
; loop until nintendo logo is out of screen
ldh a, [rSCY]
cp a, 88 cp a, 88
jp nz, .scrollup jp nz, .scrollup
; sound off
xor a
ldh [rNR52], a
ret ret

View File

@@ -28,20 +28,3 @@ MemorySet:
or c or c
jr nz, MemorySet jr nz, MemorySet
ret ret
; \1: sprite ID
; \2: X position
; \3: Y position
; \4: tile number
; \5: flags
SetSprite: MACRO
ld hl, _OAMRAM + \1 * 4
ld a, \3
ld [hl+], a
ld a, \2
ld [hl+], a
ld a, \4
ld [hl+], a
ld a, \5
ld [hl+], a
ENDM

26
Code/utils.inc Normal file
View File

@@ -0,0 +1,26 @@
INCLUDE "hardware.inc"
; destroys A
ClearAndEnableInterrupts: MACRO
xor a
ei ; will take effect AFTER next instruction
ldh a, [rIF]
ENDM
; \1: sprite ID
; \2: X position
; \3: Y position
; \4: tile number
; \5: flags
; destroys A and HL
SetSprite: MACRO
ld hl, _OAMRAM + \1 * 4
ld a, \3
ld [hl+], a
ld a, \2
ld [hl+], a
ld a, \4
ld [hl+], a
ld a, \5
ld [hl+], a
ENDM

BIN
rom.gb

Binary file not shown.