I am writing a game. When adding sound to the game I am seeing a problem with setting the frequency of sounds on the emulated SN7648 in JSBeeb only.
Some info.
The code runs after vsync fires in an interupt to play the next note in the sequence of sounds.
Data for frequency and volume is passed to the SN7648 using System Via registers A & B (see ASM below).
It works in jsBeeb and Horizon emulator in a simple test harness using the library. This runs in mode 7 with a simple text menu to trigger the sequences.
It works in Horizon when embedded into my game, however in JsBeeb the sequence plays but with one single frequency which is not intended to be in the sequence. The volume and timing in JSbeeb playback is correct which indicates I am writing the volume data to the SN7648 correctly, but not the frequency (or its somehow being modified).
If you have any thoughts on how to debug/resolve I would appreciate it!
Heres the code I use to play a sounds and then its assembler output so you can see variables and macros unrolled.
Code: Select all
.playtone {
CPX #NUM_PITCHES
BCS exit
\\ X contains note
\\ A contains channel
MULTIPLY_BY_32
CLC
ADC pitch_cmd_table_1,X
ORA #%10000000 \\ set the latch
JSR writeToSN7648
LDA pitch_cmd_table_2,X
JSR writeToSN7648
.exit
RTS
}
.writeToSN7648
\\ no interupts during this please
SEI
\\ enable writing to SN7648 (not keyboard)
LDY #&FF
STY VIA_A_6522_DIRECTION_PORT
\\ write the data
STA VIA_A_6522_OUTPUT_REGISTER_A
\\ changing these values on register b (low then hi) causes data to be pushed
\\ from the via chip to the SN7648
LDY #&00
STY VIA_A_6522_OUTPUT_REGISTER_B
DELAY_FOR_SN76489
LDY #&08
STY VIA_A_6522_OUTPUT_REGISTER_B
DELAY_FOR_SN76489 \\ doesnt seem to need this. but documentations say it does.
\\ interupts allowed again.
CLI
RTS
Code: Select all
.playtone
2252 E0 84 CPX #&84
2254 B0 14 BCS &226A
Macro MULTIPLY_BY_32:
Macro SHIFTLEFT:
2256 0A ASL A
2257 0A ASL A
2258 0A ASL A
2259 0A ASL A
225A 0A ASL A
End macro SHIFTLEFT
End macro MULTIPLY_BY_32
225B 18 CLC
225C 7D 7E 22 ADC &227E,X
225F 09 80 ORA #&80
2261 20 35 22 JSR &2235
2264 BD 02 23 LDA &2302,X
2267 20 35 22 JSR &2235
.exit
226A 60 RTS
Code: Select all
.writeToSN7648
2235 78 SEI
2236 A0 FF LDY #&FF
2238 8C 43 FE STY &FE43
223B 8D 41 FE STA &FE41
223E A0 00 LDY #&00
2240 8C 40 FE STY &FE40
Macro DELAY_FOR_SN76489:
2243 08 PHP
2244 28 PLP
2245 EA NOP
2246 EA NOP
End macro DELAY_FOR_SN76489
2247 A0 08 LDY #&08
2249 8C 40 FE STY &FE40
Macro DELAY_FOR_SN76489:
224C 08 PHP
224D 28 PLP
224E EA NOP
224F EA NOP
End macro DELAY_FOR_SN76489
2250 58 CLI
2251 60 RTS