05-19-2010, 02:27 PM
I ported some old code I developed with the aid of a couple of snippets published in Microhobby and some documentation for the AY chip to ZX Basic. The original was plain interpreted Sinclair BASIC. It may be useful to create simple sound effects, but nothing very fancy. Porting WYZ's replayer would be a better idea, but I have no time at the moment.
Try this:
The values in the array are pretty straightforward. The first 14 AY registers are written by the routine, just look at this table and you may create your own wacky sounds.
Try this:
Code:
Dim sonidos (4, 13) As Byte => {_
{100,50,0,0,0,0,4,216,31,0,0,10,10,0}, _
{250,250,0,0,0,0,15,248,31,0,0,10,10,0}, _
{10,10,0,0,0,0,29,216,31,0,0,4,4,0}, _
{10,100,0,0,0,0,15,248,31,0,0,50,50,0}, _
{15,1,0,0,0,0,15,248,31,0,0,50,50,0} _
}
Dim n As Byte
Cls
For n = 0 To 4 ' We'll play 4 sounds
Print "SFX #"; n ' Print which one
ayPlaySound (n) ' Play sound # i
Pause 100 ' Wait for 2 secs.
Next n
Sub ayPlaySound (sonido As Byte)
' This SUB plays the sound passed as parameter
' Sounds are taken from table "sonidos", which
' must be defined globally.
Dim i As Byte
For i = 0 To 13
Out 65533, i ' Select which AY register
Out 49149, sonidos (sonido, i) ' Write a value in it
Next i
End Sub
The values in the array are pretty straightforward. The first 14 AY registers are written by the routine, just look at this table and you may create your own wacky sounds.
Code:
AY REGISTERS
00 Channel A fine pitch 8-bit (0-255)
01 Channel A course pitch 4-bit (0-15)
02 Channel B fine pitch 8-bit (0-255)
03 Channel B course pitch 4-bit (0-15)
04 Channel C fine pitch 8-bit (0-255)
05 Channel C course pitch 4-bit (0-15)
06 Noise pitch 5-bit (0-31)
07 Mixer 8-bit (see below)
08 Channel A volume 4-bit (0-15, see below)
09 Channel B volume 4-bit (0-15, see below)
10 Channel C volume 4-bit (0-15, see below)
11 Envelope fine duration 8-bit (0-255)
12 Envelope course duration 8-bit (0-255)
13 Envelope shape 4-bit (0-15)
14 I/O port A 8-bit (0-255)
15 I/O port B 8-bit (0-255)
Bit:
7 6 5 4 3 2 1 0
_ _
I/O I/O Noise Noise Noise Tone Tone Tone
B A C B A C B A