@@ 56,6 56,8 @@ timer .dsb 1
position .dsb 1
cursor .dsb 1
note .dsb 1
+octave .dsb 1
+selection .dsb 1
down@input .dsb 1
last@input .dsb 1
next@input .dsb 1
@@ 97,42 99,52 @@ Vblankwait2: ; Second wait for vblank, PPU is ready after this
BIT PPUSTATUS
BPL Vblankwait2
-;; begin setup
+;; setup phase
-SetupPalettes: ;
+SetupPalettes:
LDA PPUSTATUS
LDA #$3F
STA PPUADDR
LDA #$00
STA PPUADDR
LDX #$00
-@loop: ;
+@loop:
LDA Palettes, x
STA PPUDATA
INX
CPX #$20
BNE @loop
-SetupAttributes: ;
+SetupAttributes:
LDA PPUSTATUS
LDA #$23
STA PPUADDR
LDA #$C0
STA PPUADDR
LDX #$00
-@loop: ;
+@loop:
LDA #$00
STA PPUDATA
INX
CPX #$40
BNE @loop
- JSR Redraw
SetupVariables:
- LDA #$10
+ LDA #$08
STA rate
- LDA #$40
+ LDA #$01
STA note
+ LDA #$03
+ STA octave
+
+SetupSequence:
+ LDX #$00
+@loop:
+ LDA Sequence,x
+ STA $10,x ; zeropage second row
+ INX
+ CPX #$10
+ BNE @loop
SetupPlayer:
LDA #$88
@@ 143,7 155,7 @@ SetupPlayer:
LDA #$00
STA $0202 ; set tile.attribute
-EnableSprites: ;
+EnableSprites:
LDA #%10010000 ; enable NMI, sprites from Pattern Table 0, background from Pattern Table 1
STA PPUCTRL
LDA #%00011110 ; enable sprites, enable background, no clipping on left side
@@ 154,6 166,8 @@ EnableSprites: ;
STA PPUSCROLL
STA PPUSCROLL
+;; main phase
+
MAIN:
; route inputs
LDA next@input
@@ 161,6 175,10 @@ MAIN:
BEQ MoveLeft
CMP BUTTON_RIGHT
BEQ MoveRight
+ CMP BUTTON_UP
+ BEQ MoveUp
+ CMP BUTTON_DOWN
+ BEQ MoveDown
JMP MAIN ; jump back to Forever, infinite loop
;; General functions
@@ 193,6 211,36 @@ MoveRight:
STA RedrawTimeline
JMP MAIN
+MoveDown:
+ LDX cursor
+ DEC $10,x
+ LDA $10,x
+ CMP #$ff
+ BCC @done ; when greater skip
+ ; wrap around
+ LDA #$07
+ STA $10,x
+@done: ;
+ LDA #$00
+ STA next@input
+ STA RedrawTimeline
+ JMP MAIN
+
+MoveUp:
+ LDX cursor
+ INC $10,x
+ LDA $10,x
+ CMP #$08
+ BCC @done ; when greater skip
+ ; wrap around
+ LDA #$00
+ STA $10,x
+@done: ;
+ LDA #$00
+ STA next@input
+ STA RedrawTimeline
+ JMP MAIN
+
;; interface
RedrawPlayer:
@@ 205,42 253,38 @@ RedrawPlayer:
STA $0203 ; set tile.x pos
RTS
-RedrawMeter:
- ; selector
- LDA #$04
- LDX #$2d
- LDY #$22
- JSR DrawAt
- ; speed
- LDA #$24
+RedrawPosition:
+ LDA position
+ CLC
+ ADC #$20
LDX #$48
LDY #$22
JSR DrawAt
- LDA #$2a
+ RTS
+
+RedrawRate:
+ LDA rate
+ CLC
+ ADC #$20
LDX #$49
LDY #$22
JSR DrawAt
- ; note
- LDA #$2e
- LDX #$57
- LDY #$22
- JSR DrawAt
- LDA #$2f
- LDX #$58
- LDY #$22
- JSR DrawAt
- ; time
- LDA #$23
- LDX #$50
- LDY #$22
- JSR DrawAt
- LDA #$2b
- LDX #$51
+ RTS
+
+RedrawNote:
+ LDA note
+ CLC
+ ADC #$30
+ LDX #$4a
LDY #$22
JSR DrawAt
- ; selection
- LDA #$1d
- LDX #$16
+ RTS
+
+RedrawOctave:
+ LDA octave
+ CLC
+ ADC #$20
+ LDX #$4b
LDY #$22
JSR DrawAt
RTS
@@ 255,8 299,16 @@ RedrawTimeline:
STA PPUADDR
LDA TimelinePositions, x ; x pos
STA PPUADDR
- LDA #$20
- STA PPUDATA
+ LDA #$10, x
+ CLC
+ ADC #$10
+ ; selection
+ CPX cursor
+ BNE @continue
+ CLC
+ ADC #$08
+@continue:
+ STA PPUDATA ; sprite id
INX
CPX #$10
BNE @loop
@@ 265,8 317,11 @@ RedrawTimeline:
Redraw:
LDA PPUSTATUS
JSR RedrawTimeline
- JSR RedrawMeter
JSR RedrawPlayer
+ JSR RedrawPosition
+ JSR RedrawRate
+ JSR RedrawOctave
+ JSR RedrawNote
RTS
DrawAt: ; (a:id,x,y)
@@ 275,6 330,8 @@ DrawAt: ; (a:id,x,y)
STA PPUDATA
RTS
+;; nmi phase
+
NMI: ;
ReadJoy:
@@ 320,9 377,10 @@ RunTimer:
STA position
@done:
-Finish:
+RunOperator:
+@done:
+ ; cleanup
JSR Redraw
-@end:
LDA PPUSTATUS
LDA #$00 ; No background scrolling
STA PPUSCROLL
@@ 340,6 398,10 @@ Palettes: ;
TimelinePositions:
.db $08,$09,$0a,$0b,$0c,$0d,$0e,$0f,$10,$11,$12,$13,$14,$15,$16,$17
+Sequence:
+ ; .db $00,$01,$05,$01,$02,$06,$03,$04,$00,$01,$05,$01,$02,$06,$03,$07
+ .db $00,$01,$02,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
+
;; Vectors
.pad $FFFA