; ,'`',
; .--.,_ / * FIREWORKS!.ASM
; * *._ By Different55
; .' \
; / , First time writing for a 6502 or any kind of assembly please don't kill me. ;_;
; ; * Launches random fireworks into the sky.
; /
; ;
; /
; ;
define sysRandom $fe ; RNG
define sysInput $ff ; Input
define skipKey $20 ; Spacebar
define quitKey $71 ; Q
define fireworkLocationL $00 ; Location of firework
define fireworkLocationH $01
define fireworkColor $02 ; Color of unexploded firework
define fireColor $03 ; Color of exploded firework
define effect $04 ; Type of firework.
define effectStep $05 ; How far into the explosion we are.
define direction $06 ; Direction the firework drifts to.
define driftiness $07 ; How much the firework drifts.
define currentDrift $08 ; Storage for comparison to A.
define boomStorage $09 ; Storage for drawing explosion.
define boomStorageH $0a ; Storage for drawing explosion.
define colorStorage $0b ; Storage for undrawing fireworks.
define fireColorStorage $0c ; Storage for undrawing explosions.
define wasteDelay $0d ; How much time to waste.
main: ; The starting point of everything.
JSR init
JMP loop
init: ; Set the scene.
JSR newFirework ; First we need a new firework.
JSR draw ; We should probably draw it to the screen
JSR spinWheels ; Make sure we don't go too fast.
RTS
newFirework: ; Set up a new firework.
LDA sysRandom ; Get a random number.
AND #$07 ; Make it range between 0-7.
ADC #$eb ; Add 235 to it. This makes it land in the middle 8 pixels of whatever screen segment its placed on.
STA fireworkLocationL ; Store it as low byte of the location.
LDA #$05 ; This is the last segment of the screen.
STA fireworkLocationH ; Store it in memory.
fwColor:
LDA sysRandom ; Get and store a firework color.
AND #$f
CMP #$00
BEQ fwColor
STA fireworkColor
STA colorStorage
fColor:
LDA sysRandom ; Get and store an explosion color.
AND #$f
CMP #$00
BEQ fColor
STA fireColor
STA fireColorStorage
LDA sysRandom ; Random explosion effect.
AND #$01
STA effect
LDA #$00 ; How far into the effect we are.
STA effectStep
LDA sysRandom ; Decide which way to drift.
AND #$02
SBC #$00
STA direction
LDA sysRandom ; Decide how much to drift.
AND #$0f
ADC #$df
STA driftiness
STA currentDrift
LDA #$02
STA boomStorageH
LDA #$b0
STA wasteDelay
RTS
loop:
JSR input
JSR undraw
JSR stepFirework
JSR draw
JSR spinWheels
JMP loop
input: ; Space bar = new firework
LDA sysInput
CMP #skipKey
BNE spaceNotPressed
JSR newFirework
nothingPressed:
RTS
spaceNotPressed:
CMP #quitKey
BNE nothingPressed
JMP end
RTS
stepFirework: ; Moves the firework along.
LDA effectStep
CMP #$00
BNE getOutPls
JSR fireworkUp
JSR fireworkSide
LDA #$02
CMP fireworkLocationH
BNE getOut
LDA fireworkLocationL
CMP #$bf
BCC explosionTimeMaybe
getOut:
RTS
getOutPls:
INC effectStep
RTS
explosionTimeMaybe:
LDA #$bf
CMP sysRandom
BCS explosionTime
LDA fireworkLocationL
CMP #$3f
BCC explosionTime
RTS
explosionTime:
INC effectStep
RTS
fireworkUp:
LDA fireworkLocationL
CLC
SBC #$1f
STA fireworkLocationL
BCC bigMove
RTS
bigMove:
DEC fireworkLocationH
RTS
fireworkSide:
LDA fireworkLocationH
CMP #$04
BCC getTilty
LDA driftiness
STA currentDrift
LDA sysRandom
CMP currentDrift
BCS drift
RTS
getTilty:
CLC
LDA driftiness
SBC #$20
STA currentDrift
LDA sysRandom
CMP currentDrift
BCS drift
RTS
drift:
LDA fireworkLocationL
CLC
ADC direction
STA fireworkLocationL
RTS
draw:
LDY #$00
LDA effectStep
CMP #$00
BNE boom
LDA fireworkColor
STA (fireworkLocationL),Y
RTS
boom:
LDA effect
CMP #$01
BEQ glitter
BNE cross
returnFromBoom:
RTS
ded:
DEC effectStep
JSR undraw
JSR newFirework
LDA fireworkColor
STA (fireworkLocationL),Y
RTS
glitter:
JSR drawGlitter
CLC
BCC returnFromBoom
cross:
JSR drawCross
CLC
BCC returnFromBoom
drawGlitter:
LDX #$30
STX wasteDelay
LDA effectStep
CMP #$12
BEQ ded
AND #$01
CMP #$01
BEQ glitterFlip
BNE glitterFlop
glitterFlip:
LDA fireworkLocationL
CLC
SBC #$20
STA boomStorage
LDA fireColor
STA (boomStorage),Y
LDA fireworkLocationL
CLC
ADC #$21
STA boomStorage
LDA fireColor
STA (boomStorage),Y
STA (fireworkLocationL),Y
RTS
glitterFlop:
LDA fireworkLocationL
CLC
SBC #$1e
STA boomStorage
LDA fireColor
STA (boomStorage),Y
LDA fireworkLocationL
CLC
ADC #$1f
STA boomStorage
LDA fireColor
STA (boomStorage),Y
STA (fireworkLocationL),Y
RTS
drawCross:
LDX #$40
STX wasteDelay
LDA effectStep
CMP #$08
BEQ ded
CMP #$04
BCC crossOne
CMP #$06
BCC crossTwo
BCS crossThree
crossOne:
LDA fireworkLocationL
CLC
ADC #$ff
STA boomStorage
LDA fireColor
STA (boomStorage),Y
LDA fireworkLocationL
CLC
ADC #$1
STA boomStorage
LDA fireColor
STA (boomStorage),Y
LDA fireworkLocationL
CLC
SBC #$1f
STA boomStorage
LDA fireColor
STA (boomStorage),Y
LDA fireworkLocationL
CLC
ADC #$20
STA boomStorage
LDA fireColor
STA (boomStorage),Y
STA (fireworkLocationL),Y
RTS
crossTwo:
LDA fireworkLocationL
CLC
SBC #$40
STA boomStorage
LDA fireColor
STA (boomStorage),Y
LDA fireworkLocationL
CLC
ADC #$22
STA boomStorage
LDA fireColor
STA (boomStorage),Y
LDA fireworkLocationL
CLC
ADC #$40
STA boomStorage
LDA fireColor
STA (boomStorage),Y
CLC
LDA fireworkLocationL
SBC #$1
STA boomStorage
LDA fireColor
STA (boomStorage),Y
RTS
crossThree:
LDA fireworkLocationL
CLC
SBC #$21
STA boomStorage
LDA fireColor
STA (boomStorage),Y
LDA fireworkLocationL
CLC
ADC #$43
STA boomStorage
LDA fireColor
STA (boomStorage),Y
LDA fireworkLocationL
CLC
ADC #$3f
STA boomStorage
LDA fireColor
STA (boomStorage),Y
LDA fireworkLocationL
CLC
ADC #$1d
STA boomStorage
LDA fireColor
STA (boomStorage),Y
RTS
undraw:
LDA #$00
STA fireColor
STA fireworkColor
JSR draw
LDA fireColorStorage
STA fireColor
LDA colorStorage
STA fireworkColor
RTS
spinWheels:
LDX wasteDelay
spinloop:
NOP
NOP
DEX
bne spinloop
rts
end: