@@ 19,17 19,21 @@ PPUSCROLL .equ $2005
PPUADDR .equ $2006
PPUDATA .equ $2007
APUCH1VOL .equ $4000 ; APU
-APUCH1SWP .equ $4001
-APUCH1FRQ .equ $4002
-APUCH1LEN .equ $4003
-APUCH2VOL .equ $4004
-APUCH2SWP .equ $4005
-APUCH2FRQ .equ $4006
-APUCH2LEN .equ $4007
-APUCH4VOL .equ $400c
-APUCH4SWP .equ $400d
-APUCH4FRQ .equ $400e
-APUCH4LEN .equ $400f
+APUCH1SWP .equ $4001 ; APU
+APUCH1FRQ .equ $4002 ; APU
+APUCH1LEN .equ $4003 ; APU
+APUCH2VOL .equ $4004 ; APU
+APUCH2SWP .equ $4005 ; APU
+APUCH2FRQ .equ $4006 ; APU
+APUCH2LEN .equ $4007 ; APU
+APUCH3CNT .equ $4008 ; APU
+APUCH3SWP .equ $4009 ; APU
+APUCH3FRQ .equ $400a ; APU
+APUCH3LEN .equ $400b ; APU
+APUCH4VOL .equ $400c ; APU
+APUCH4SWP .equ $400d ; APU
+APUCH4FRQ .equ $400e ; APU
+APUCH4LEN .equ $400f ; APU
SPRDMA .equ $4014
APUCTRL .equ $4015
JOY1 .equ $4016
@@ 49,7 53,7 @@ BUTTON_A .equ #$80
position .dsb 1
cursor .dsb 1
note .dsb 1
-octave .dsb 1
+marker .dsb 1
btndown .dsb 1
btnlast .dsb 1
btnqueue .dsb 1
@@ 137,22 141,34 @@ SetupSequence:
SetupVariables:
LDA #$08
STA rate ; default rate = 08
- LDA #$00
+ LDA #$20
STA note ; default note = C
- LDA #$01
- STA octave ; default octave = 2
SetupAudio:
- LDA #%00001011 ; ch1 + ch2 + ch4
- STA APUCTRL
-
-SetupSprite:
+ LDY #$0f ; init $4000-4013
+@loop:
+ LDA ApuStates,y
+ STA $4000,y
+ DEY
+ BPL @loop
+ LDA #$0f ; skip over $4014 (OAMDMA)
+ STA $4015
+ LDA #$40
+ STA $4017
+
+SetupInterface:
LDA #$88
STA $0200 ; set tile.y pos
LDA #$02
STA $0201 ; set tile.id
LDA #$00
STA $0202 ; set tile.attribute
+ LDA #$88
+ STA $0204 ; set tile.y pos
+ LDA #$03
+ STA $0205 ; set tile.id
+ LDA #$00
+ STA $0206 ; set tile.attribute
EnableSprites:
LDA #%10010000 ; enableNMI sprites0 background1
@@ 164,7 180,7 @@ EnableSprites:
MAIN:
LDA btnqueue
- ; style1
+@style1:
CMP BUTTON_LEFT
BEQ MoveLeft
CMP BUTTON_RIGHT
@@ 173,11 189,11 @@ MAIN:
BEQ MoveUp
CMP BUTTON_DOWN
BEQ MoveDown
- ; style2
+@style2:
CMP BUTTON_SELECT
BEQ ResetSequence
CMP BUTTON_START
- BEQ MoveRight
+ BEQ MoveMarker
CMP BUTTON_A
BEQ MoveUp
CMP BUTTON_B
@@ 228,22 244,28 @@ MoveUp:
@done:
JMP MoveEnd
-MoveEnd:
- LDA #$00
- STA btnqueue
- STA RedrawTimeline
- JMP MAIN
+MoveMarker:
+ LDA cursor
+ STA marker
+ STA RedrawInterface
+ JMP MoveEnd
ResetSequence:
LDX #$00
@loop:
- LDA $00 ; set entire sequence to "+"
+ LDA #$01 ; set entire sequence to "+"
STA $10,x ; store on zeropage second row
INX
CPX #$10
BNE @loop
JMP MoveEnd
+MoveEnd:
+ LDA #$00
+ STA btnqueue
+ STA RedrawTimeline
+ JMP MAIN
+
;; interface
RedrawTimeline:
@@ 253,13 275,13 @@ RedrawTimeline:
STA PPUADDR
TXA ; sprite x pos
STA PPUADDR
- LDA #$10, x ; find selectionselection
+ LDA #$10, x ; find selection
CLC
ADC #$10
- CPX cursor
+ CPX cursor ; if cursor
BNE @continue
CLC
- ADC #$08
+ ADC #$08 ; then, highlight
@continue:
STA PPUDATA ; sprite id
INX
@@ 277,70 299,24 @@ RedrawInterface:
CLC
ADC #$40
STA $0203 ; set tile.x pos
-@position:
- LDA timer
- CLC
- ADC #$20
- LDX #$40
- LDY #$22
- JSR DrawAt
-@rate:
- LDA rate
- CLC
- ADC #$20
- LDX #$41
- LDY #$22
- JSR DrawAt
-@octave:
- LDA octave
- CLC
- ADC #$20
- LDX #$4e
- LDY #$22
- JSR DrawAt
-@note:
- LDA note
+@marker:
+ LDA marker
+ ASL
+ ASL
+ ASL
CLC
- ADC #$30
- LDX #$4f
- LDY #$22
- JSR DrawAt
- RTS
-
-DrawAt: ; (a:id,x,y)
- STY PPUADDR
- STX PPUADDR
- STA PPUDATA
- RTS
-
-IncOct:
- INC octave ; increment octave
- LDA octave ; load octave
- CMP #$04 ; check if max
- BCC @done
- LDA #$00 ; reset octave
- STA octave
-@done:
- RTS
-
-DecOct:
- DEC octave ; decrement octave
- LDA octave ; load octave
- CMP #$0ff ; check if min
- BCC @done
- LDA #$03 ; reset octave
- STA octave
+ ADC #$40
+ STA $0207 ; set tile.x pos
@done:
RTS
IncNote:
INC note
LDA note
- CMP #$0c
+ CMP #$48
BNE @done
LDA #$00 ; when reached end
STA note ; reset note
- JSR IncOct
@done:
RTS
@@ 349,54 325,60 @@ DecNote:
LDA note
CMP #$ff
BNE @done
- LDA #$0b
+ LDA #$47
STA note
- JSR DecOct
@done:
RTS
+PlaySnare:
+ LDA #<$3f8
+ STA APUCH4LEN
+ LDA #>$3f8
+ STA APUCH4FRQ
+ LDA #%11000100
+ STA APUCH4VOL
+ RTS
+
;; operators
DoInc:
+ LDX #$00
+@loop:
JSR IncNote
+ CPX marker
+ INX
+ BCC @loop
JMP DoOperationEnd
DoDec:
+ LDX #$00
+@loop:
JSR DecNote
+ CPX marker
+ INX
+ BCC @loop
JMP DoOperationEnd
DoTop:
- LDA #$00
+ LDA #$24
STA note
- JSR IncOct
- INC seed
-@done:
JMP DoOperationEnd
DoBottom:
LDA #$00
STA note
- JSR DecOct
- DEC seed
-@done:
JMP DoOperationEnd
DoRandomNote:
LDA seed
@loop:
SEC
- SBC #$0c
- CMP #$0c
+ SBC #$48
+ CMP #$48
BCS @loop
STA note
INC seed
- ; snare
- LDA #<$3f8
- STA APUCH4LEN
- LDA #>$3f8
- STA APUCH4FRQ
- LDA #%11000100
- STA APUCH4VOL
+ JSR PlaySnare
JMP DoOperationEnd
DoIncMetro:
@@ 420,12 402,7 @@ DoDecMetro:
JMP DoOperationEnd
DoRandomPosition:
- LDA seed
-@loop:
- SEC
- SBC #$10
- CMP #$10
- BCS @loop
+ LDA marker
STA position
JMP DoOperationEnd
@@ 437,9 414,9 @@ DoOperation:
CMP #$01
BEQ DoDec
CMP #$02
- BEQ DoTop
- CMP #$03
BEQ DoBottom
+ CMP #$03
+ BEQ DoTop
CMP #$04
BEQ DoRandomNote
CMP #$05
@@ 453,31 430,28 @@ DoOperationEnd: ; return from operations
RTS
DoSound:
- ; calculate note position, store in x
- LDX octave ; get oct in x
- LDA Octaves,x ; get octave offset in y
- CLC
- ADC note
- TAY
- LDA Notes,y ; get note0 with oct
- TAX
- ; ch1
- LDA #%10100001
- STA APUCH1VOL
- STX APUCH1SWP
- STX APUCH1FRQ
- LDA #%01101011
- SEC
- SBC note
+ LDX note
+@ch1:
+ LDA NotesHi,x
STA APUCH1LEN
- ; ch2
- LDA #%10100001
- STA APUCH2VOL
- LDA position
- STA APUCH2SWP
- STX APUCH2FRQ
- LDA #%01101011
- STX APUCH2LEN
+ LDA NotesLo,x
+ STA APUCH1FRQ
+ LDY seed
+ STY APUCH1SWP
+@ch2:
+ LDA NotesHi,x
+ STA APUCH2LEN
+ LDA NotesLo,x
+ STA APUCH2FRQ
+ LDY marker
+ STY APUCH2SWP
+@ch3:
+ LDA NotesHi,x
+ STA APUCH3LEN
+ LDA NotesLo,x
+ STA APUCH3FRQ
+ LDY timer
+ STY APUCH3SWP
RTS
;; nmi phase
@@ 513,18 487,16 @@ SaveJoy:
RunTimer:
INC seed
INC timer
- ; check if timer has reached rate
LDA timer
- CMP rate
+ CMP rate ; check if timer has reached rate
BNE @done ; skip if timer is less than rate
LDA #$00
STA timer ; reset timer
JSR DoOperation
JSR DoSound
INC position
- ; check if position has reached 16
LDA position
- CMP #$10
+ CMP #$10 ; check if position has reached 16
BNE @done
LDA #$00
STA position
@@ 546,17 518,29 @@ Cleanup:
Palettes: ;
.db $0F,$3B,$16,$30, $3B,$3B,$0F,$0F, $0F,$3B,$0F,$0F, $0F,$3B,$0F,$0F
- .db $0F,$10,$17,$07, $0F,$3B,$0F,$0F, $0F,$0F,$0F,$0F, $0F,$0F,$0F,$0F
-
-Notes: ;
- .db $d2,$c9,$b3,$bd,$a9,$9f,$96,$8e,$86 ; oct 5
- .db $7e,$77,$70,$6a,$64,$5e,$59,$54,$4f,$4b,$46,$42 ; oct 4
- .db $3f,$3b,$38,$34,$31,$2f,$2c,$29,$27,$25,$23,$21 ; oct 3
- .db $1f,$1d,$1b,$1a,$18,$17,$15,$14,$13,$12,$11,$10 ; oct 2
- .db $d2,$c9,$b3
-
-Octaves:
- .db $24,$18,$0c,$00
+ .db $0F,$3B,$16,$3B, $0F,$3B,$0F,$0F, $0F,$0F,$0F,$0F, $0F,$0F,$0F,$0F
+
+ApuStates:
+ .db #%10100111,$08,$00,$00
+ .db #%00011101,$08,$00,$00
+ .db #%01011101,$08,$00,$00
+ .db #%01011011,$08,$00,$00
+
+NotesHi:
+ .db $07,$07,$07,$06,$06,$05,$05,$05,$05,$04,$04,$04
+ .db $03,$03,$03,$03,$03,$02,$02,$02,$02,$02,$02,$02
+ .db $01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01
+ .db $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
+ .db $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
+ .db $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
+
+NotesLo:
+ .db $f1,$7f,$13,$ad,$4d,$f3,$9d,$4c,$00,$b8,$74,$34
+ .db $f8,$bf,$89,$56,$26,$f9,$ce,$a6,$80,$5c,$3a,$1a
+ .db $fb,$df,$c4,$ab,$93,$7c,$67,$52,$3f,$2d,$1c,$0c
+ .db $fd,$ef,$e1,$d5,$c9,$bd,$b3,$a9,$9f,$96,$8e,$86
+ .db $7e,$77,$70,$6a,$64,$5e,$59,$54,$4f,$4b,$46,$42
+ .db $3f,$3b,$38,$34,$31,$2f,$2c,$29,$27,$25,$23,$21
;; Vectors