Skip to content

Commit

Permalink
Qbert: Initial enemy experiments
Browse files Browse the repository at this point in the history
  • Loading branch information
visrealm committed Aug 27, 2023
1 parent dcd7db2 commit 8e615d7
Show file tree
Hide file tree
Showing 11 changed files with 423 additions and 160 deletions.
172 changes: 111 additions & 61 deletions code/6502/qbert/audio.asm
Original file line number Diff line number Diff line change
Expand Up @@ -6,101 +6,151 @@
;
; https://github.com/visrealm/hbc-56
;
; plays 4-bit .pcm files which are generated from RAW 8-bit audio samples
; using: python ..\..\..\tools\raw2pcm.py *.raw
;

ENV_TEST_FREQ = 211.07992
ENV_TEST_PERIOD = 681*2





audioInit:
jsr ayInit
+ayWrite AY_PSG0, AY_CHA_AMPL, $0a
+ayWrite AY_PSG0, AY_CHB_AMPL, $0a

+ayWrite AY_PSG0, AY_CHA_AMPL, $00
+ayWrite AY_PSG0, AY_CHB_AMPL, $00
+ayWrite AY_PSG0, AY_CHC_AMPL, $00
+ayWrite AY_PSG0, AY_ENV_PERIOD_L, 0
+ayWrite AY_PSG0, AY_ENV_PERIOD_H, 0
+ayWrite AY_PSG0, AY_ENV_SHAPE, AY_ENV_SHAPE_SAW1
+ayWrite AY_PSG0, AY_ENV_PERIOD_L, $00
+ayWrite AY_PSG0, AY_ENV_PERIOD_H, $00
+ayWrite AY_PSG0, AY_ENV_SHAPE, AY_ENV_SHAPE_FADE_OUT
+ayWrite AY_PSG0, AY_ENABLES, $3e

+ayWrite AY_PSG1, AY_CHA_AMPL, $00
+ayWrite AY_PSG1, AY_CHB_AMPL, $00
+ayWrite AY_PSG1, AY_CHC_AMPL, $00
+ayWrite AY_PSG1, AY_ENV_PERIOD_L, $00
+ayWrite AY_PSG1, AY_ENV_PERIOD_H, $08
+ayWrite AY_PSG1, AY_ENV_SHAPE, $0e
+ayWrite AY_PSG1, AY_ENV_PERIOD_H, $00
+ayWrite AY_PSG1, AY_ENV_SHAPE, AY_ENV_SHAPE_FADE_OUT
+ayWrite AY_PSG1, AY_ENABLES, $3e

+memset AUDIO_PCM_STATE, 0, 16
; clear all AUDIO_* ZP
+memset AUDIO_CH0_PCM_STATE, 0, 16

rts

.pcmAudio
!bin "jump.pcm"
.pcmAudioEnd

audioJumpInit:
lda AUDIO_PCM_STATE
beq +
audioTick:
jsr audioTickCh0
jsr audioTickCh1
jsr audioTickCh2
rts
+
+ayWrite AY_PSG0, AY_CHC_TONE_L,0
+ayWrite AY_PSG0, AY_CHC_TONE_H,0
+ayWrite AY_PSG0, AY_ENABLES, $3a

+store16 AUDIO_CH0_PCM_ADDR_L, .pcmAudio

!macro audioPlayPcm .channel, .start, .size {
lda .channel
bne .end

!if .channel == AUDIO_CH0_PCM_STATE {
+ayToneEnable AY_PSG0, AY_CHC
}
!if .channel == AUDIO_CH1_PCM_STATE {
+ayToneEnable AY_PSG1, AY_CHC
}
!if .channel == AUDIO_CH2_PCM_STATE {
+ayToneEnable AY_PSG0, AY_CHA
}
+store16 .channel + 1, .start
+store16 .channel + 3, .size

lda #1
sta AUDIO_PCM_STATE
rts
sta .channel
.end:
}


audioEnvTest:
+ayWrite AY_PSG0, AY_CHA_TONE_L, 211
+ayWrite AY_PSG0, AY_CHA_TONE_H, 0
+ayWrite AY_PSG0, AY_CHA_AMPL, $10
+ayWrite AY_PSG0, AY_ENV_PERIOD_L, <ENV_TEST_PERIOD
+ayWrite AY_PSG0, AY_ENV_PERIOD_H, >ENV_TEST_PERIOD
+ayWrite AY_PSG0, AY_ENV_SHAPE, AY_ENV_SHAPE_FADE_OUT
+ayWrite AY_PSG0, AY_ENABLES, $3a
!macro audioTickSubroutine .ayDev, .ayChan, .qbChanAddr {
lda .qbChanAddr
bne +
rts
+
bit #2
beq .loadHighNibble
bra .loadLowNibble

.loadHighNibble:
inc AUDIO_PCM_STATE
lda (AUDIO_CH0_PCM_ADDR_L)
inc .qbChanAddr
lda (.qbChanAddr + 1)
+lsr4
bra .playNibble

.loadLowNibble
dec AUDIO_PCM_STATE
lda (AUDIO_CH0_PCM_ADDR_L)
.loadLowNibble:
dec .qbChanAddr
lda (.qbChanAddr + 1)
and #$0f
+inc16 AUDIO_CH0_PCM_ADDR_L
bra .playNibble
pha
+inc16 .qbChanAddr + 1
+dec16 .qbChanAddr + 3
pla

audioJumpTick:
lda AUDIO_PCM_STATE
bne +
rts
+
bit #2
beq .loadHighNibble
bra .loadLowNibble
.playNibble
+aySetVolumeAcc .ayDev, .ayChan
+beq16 .qbChanAddr + 3, .stop
rts

+ayWriteA AY_PSG0, AY_CHC_AMPL
.stop:
lda #0
sta .qbChanAddr
+ayPlayNote .ayDev, .ayChan, 0
+aySetVolumeAcc .ayDev, .ayChan
+ayToneDisable .ayDev, .ayChan
rts
}

+cmp16i AUDIO_CH0_PCM_ADDR_L, .pcmAudioEnd
bne +
beq audioJumpStop
+
audioPlayJump:
+audioPlayPcm AUDIO_CH0_PCM_STATE, .jumpPcmStart, .jumpPcmSize
jsr audioTickCh0
rts

audioJumpStop:
lda #0
sta AUDIO_PCM_STATE
+ayWrite AY_PSG0, AY_CHC_TONE_L,0
+ayWrite AY_PSG0, AY_CHC_TONE_H,0
+ayWrite AY_PSG1, AY_CHA_AMPL, $00
+ayWrite AY_PSG1, AY_ENABLES, $3e
rts
audioPlayBadBallJump:
+audioPlayPcm AUDIO_CH1_PCM_STATE, .jumpBadBallPcmStart, .jumpBadBallPcmSize
jsr audioTickCh1
rts

audioPlayCoilyEggJump:
+audioPlayPcm AUDIO_CH2_PCM_STATE, .jumpCoilyEggPcmStart, .jumpCoilyEggPcmSize
jsr audioTickCh1
rts

;audioPlayQbertFall:
;+audioPlayPcm AUDIO_CH2_PCM_STATE, .qbertFallPcmStart, .qbertFallPcmSize
;jsr audioTickCh2
;rts

audioTickCh0:
+audioTickSubroutine AY_PSG0, AY_CHC, AUDIO_CH0_PCM_STATE

audioTickCh1:
+audioTickSubroutine AY_PSG1, AY_CHC, AUDIO_CH1_PCM_STATE

audioTickCh2:
+audioTickSubroutine AY_PSG0, AY_CHA, AUDIO_CH2_PCM_STATE


.jumpPcmStart
!bin "jump.pcm"
.jumpPcmEnd
.jumpPcmSize = * - .jumpPcmStart

.jumpBadBallPcmStart
!bin "jump-badball.pcm"
.jumpBadBallPcmEnd
.jumpBadBallPcmSize = * - .jumpBadBallPcmStart

.jumpCoilyEggPcmStart
!bin "jump-coily-egg.pcm"
.jumpCoilyEggPcmEnd
.jumpCoilyEggPcmSize = * - .jumpCoilyEggPcmStart

;.qbertFallPcmStart
;!bin "qbert-fall.pcm"
;.qbertFallPcmEnd
;.qbertFallPcmSize = * - .qbertFallPcmStart
80 changes: 79 additions & 1 deletion code/6502/qbert/badball.asm
Original file line number Diff line number Diff line change
@@ -1,7 +1,85 @@

BADBALL_PATT_IDX = 96

BADBALL_START_X = 136
BADBALL_START_Y = 33
BADBALL_HIGHLIGH_OFFSET = 8

badBallInit:
+tmsSetAddrSpritePattTable BADBALL_PATT_IDX
+tmsSendData .badBallSquatPatt, 8 * 4 * 3

lda #0
sta BADBALL_STATE
sta BADBALL_DIR
sta BADBALL_ANIM

lda #BADBALL_START_X
sta BADBALL_X
lda #BADBALL_START_Y
sta BADBALL_Y

+tmsCreateSprite 3, BADBALL_PATT_IDX, BADBALL_START_X, BADBALL_START_Y, TMS_DK_RED
+tmsCreateSprite 4, BADBALL_PATT_IDX + 8, BADBALL_START_X, BADBALL_START_Y + BADBALL_HIGHLIGH_OFFSET, TMS_WHITE

jsr .moveBall
rts

.initJumpCountdown:
lda #30
sta BADBALL_STATE
rts

.initJump:
dec BADBALL_STATE
stz BADBALL_ANIM
+tmsSpriteIndex 3, BADBALL_PATT_IDX + 4
rts

.jumpTick:
ldx BADBALL_ANIM

lda BADBALL_X
sec
sbc .bertJumpAnimX,X
sta BADBALL_X

lda BADBALL_Y
clc
adc .bertJumpAnimY,X
sta BADBALL_Y

jsr .moveBall

inc BADBALL_ANIM
lda BADBALL_ANIM
cmp #32
bne +
lda #0
sta BADBALL_STATE
+tmsSpriteIndex 3, BADBALL_PATT_IDX
jsr audioPlayBadBallJump
+

rts

badBallTick:
lda BADBALL_STATE
beq .initJumpCountdown
bmi .jumpTick
dec BADBALL_STATE
beq .initJump
rts

.moveBall:
ldx BADBALL_X
ldy BADBALL_Y
+tmsSpritePosXYReg 3
tya
clc
adc #BADBALL_HIGHLIGH_OFFSET
tay
+tmsSpritePosXYReg 4
rts


Expand All @@ -20,7 +98,7 @@ badBallInit:
!byte $fc,$fe,$fe,$fe,$fe,$fc,$f8,$e0

.badBallHighlightPatt
!byte $00,$03,$04,$00,$00,$00,$00,$00
!byte $03,$07,$07,$04,$00,$00,$00,$00
!byte $00,$00,$00,$00,$00,$00,$00,$00
!byte $00,$00,$00,$00,$00,$00,$00,$00
!byte $00,$00,$00,$00,$00,$00,$00,$00
6 changes: 3 additions & 3 deletions code/6502/qbert/blocks.asm
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ BLOCKS_LEFT_PATTERN_INDEX = 254
BLOCKS_RIGHT_PATTERN_INDEX = BLOCKS_LEFT_PATTERN_INDEX + 1

blocksInit:
lda #TMS_DK_BLUE
lda #TMS_LT_BLUE
sta COLOR_TOP1
lda #TMS_MAGENTA
lda #TMS_CYAN
sta COLOR_TOP2
lda #TMS_DK_GREEN
lda #TMS_LT_GREEN
sta COLOR_TOP3
lda #TMS_LT_YELLOW
sta COLOR_LEFT
Expand Down
Loading

0 comments on commit 8e615d7

Please sign in to comment.