What I have so far is a program that runs through all the notes in a note table. I'm trying to get those notes to be the different PWP waves, but it's inconsistent and I'm not sure why. I'm using this document for reference.
My code so far decrements x continually, decrementing y when x hits 0, then when y hits 0 the next note is played. This has allowed for some primitive form of timing, but what's the standard way for timing things to synchronize to screen updates on the VIC-20?
Then, the PWP waves. I have it set up so it puts $7E into the oscillator for a pretty long while, then it disables interrupts and rapidly pushes $FE, $FE, $7E, then the note frequency. According to that document that's all I should need to do, right? There's also a bit of sample code up towards the top which basically does the same thing I'm doing. And yet it only seems to have that PWP wave sound sometimes, it's not consistent. There's a routine towards the bottom of that document, but I don't understand it and I can't get it to assemble.
Any ideas what I'm doing wrong here? Attached the .prg and source, which is pasted below. Any help is greatly appreciated!
Code: Select all
processor 6502
org $1001
BASICstub
dc.w nxt_line ; Calculate pointer to next BASIC line
dc.w 2012 ; BASIC Line# (change this to any # you want)
hex 9e ; BASIC token for SYS
if ml_start ; If ml_start hasn't been defined, skip it for now
dc.b [ml_start]d ; ML start address (use any address you like here)
endif
hex 00 ; End of BASIC line
nxt_line
hex 00 00 ; The next BASIC line would start here
LOFREQ = $900A
MDFREQ = $900B
HIFREQ = $900C
NZFREQ = $900D
VOL = $900E
BORDER = $900F
RAMValues
currentNote .byte 0
ml_start ;Start your ML code here.
lda #255
sta VOL
lda #0
sta BORDER
ldx #1
ldy #1
inf
;Timing stuff!
; y--
; if (y == 0) {
dey
cpy #0
bne inf
; x--
; if (x == 10) {
; osc = $7E
dex
cpx #10
bne dontDisableFreq
lda #$7E
sta MDFREQ
dontDisableFreq
; }
; else if (x == 0) {
cpx #0
bne inf
;Oscillator stuff!
; disable interrupts
; osc = $FE
; osc = $FE
; osc = $7E
; osc = NoteTable[currentNote]
; enable interrupts
ldy currentNote
lda NoteTable,y
ldx #$7E
ldy #$FE
sei
sty MDFREQ ;1
sty MDFREQ ;1
stx MDFREQ ;0
sta MDFREQ
cli
; currentNote++
; if (currentNote == 52) {
; currentNote = 0
; }
ldy currentNote
iny
cpy #52
bne dontResetNoteTable
ldy #0
dontResetNoteTable
sty currentNote
ldx #200
; }
; }
jmp inf
NoteTable
; C C# D D# E F F# G G# A A# B
.byte 131, 138, 144, 150, 156, 162, 167, 172, 177, 181, 185 ;1
.byte 189, 193, 196, 200, 203, 206, 208, 211, 214, 216, 218, 220 ;2
.byte 222, 224, 226, 227, 229, 230, 232, 233, 234, 235, 237, 238 ;3
.byte 239, 240, 241, 242, 243, 244, 245, 246 ;4
.byte 247, 248, 249, 250 ;5
.byte 251, 252 ;6
.byte 253 ;7
.byte 254 ;8
.byte 0
z_EndOfData
org $1DFF
z_EndOfWorkspace