* PSG_registers+0,PSG_registers+2,PSG_registers+4
*
* lower 8-bits of tone to use

* PSG_registers+1,PSG_registers+3,PSG_registers+5
*
* upper 4-bits of tone to use

* PSG_registers+6
*
* Bit		Function
*
* 7..5		Not used
* 4..0		5-bit period control

* NOTE: Master frequency = clock input/16
*	For 1Mhz master frequency =  62500Hz
*	For 2Mhz master frequency = 125000Hz
*
*	Frequency used = master frequency/programmed used


* Register usage

* PSG_registers+6

* "produces a frequency modulated pseudo random pulse width square wave
* output"
*
* translated: 1) simple square wave, $7f,$80 (max-->min)
* 		 frequency square wave is played is random
*		 the random-ness is defined by the value programmed to
*		 this register

*
* NOTE: Master frequency= clock input/16
*	For 1Mhz master frequency =  62500Hz
*	For 2Mhz master frequency = 125000Hz
*
*	Frequency used=master frequency/programmed value

* PSG_registers+7
*
* Bit		Function
*
* 7		Not Used
* 6		PSG Port A (1: output, 0: input)
* 5		Channel C PSG_registers+6 control (0: enable PSG_registers+6, 1: disable PSG_registers+6)
* 4		Channel B PSG_registers+6 control
* 3		Channel A PSG_registers+6 control
* 2		Channel C tone control (0: enable tone, 1: disable tone)
* 1		Channel B tone control
* 0		Channel A tone control

* PSG_registers+8, PSG_registers+9, PSG_registers+10
*
* Basic square wave tone frequencys for each channel *done*
*
* Bit		Function
* 
* 7..5		Not used
* 4		Hardware envelope control (1: use hardware enveloping,
*					   0: use volume specified in 
*					      bits 3...0)
* 3..0		Volume (0..15)

* PSG_registers+12, PSG_registers+11
*
* 16-bit hardware envelope period
*
* NOTE: Master frequency of Hardware envelope=clock input/256
*	For 1Mhz master frequency = 3906.25Hz	(approximate to 3906Hz??)
*	For 2Mhz master frequency = 7812.5Hz	(approximate to 7813Hz??)

*	Frequency used = master frequency/programmed value

* PSG_registers+12
*
* amplitude modulation of sound *done*
*
* Bit		Function
*
* 7..4		Not used
* 3		Continue
* 2		Attack
* 1		Alternate
* 0		Hold
*
*

* 0	0	-	-	\________________________
*

* 0	1	-	-	/|_______________________
*

* 1	0	0	0	\|\|\|\|\|\|\|\|\|\|\|\|\

* 1	0	0	1	\________________________
*

* 1	0	1	0	\/\/\/\/\/\/\/\/\/\/\/\/		

*				  _______________________
* 1	0	1	1	\|

* 1	1	0	0	/|/|/|/|/|/|/|/|/|/|/|/|/|

*				 _________________________
* 1	1	0	1	/

* 1	1	1	0	/\/\/\/\/\/\/\/\/\/\/\/\/\

* 1	1	1	1	/|________________________
*

*			       ...
*
*				^ envelope period (1st rise)
*				so divide it by 16!!!


* standard fixed volume sounds.............

* since amiga volumes 8-bit, convert to 4-bit i.e

* $00,$10,$20,$30,$40,$50,$60,$70,$80,$90,$a0,$b0,$c0,$d0,$e0,$f0

* now play these volumes at the frequency determined by the note period
* taking into account the 0's. i.e.
*
* the pattern for a standard volume tone is:
*
* $x0,$00,$x0,$00		where $x0 is the volume
* and this is repeated over and over again....ok, so some filtering
* might need to be used, but this gives a basic sound, or tone, even
* if a little tinny!
*
* now, we have a tone playing, obviously, change the speed it can be played
* at, 3 channels at once...so registers 0-5 fixed, 7 just defines whether
* the tone is to be played, or a zeroised sample is to be played (quiet)
*
* so to emulate 8,9,10, we just choose a different sample data with the
* appropiate volume data, and play that at a different rate.

* we could have one sample, and just change the first byte, the second being
* zero, and of course, this being a two byte looped sample, instand tone.....
* instant volume control, registers 0,1,2,3,4,5,8,9,10 now emulated.......
* 
* and 7 partially emulated, to determine whether tone is mixed or not......
* maybe possible emulation, of the port A data to determine when it is
* acting as input or output..........simplicity 2!
* bits 2,1,0 emulated, and 6,7 emulated also
*
* how about emulating PSG_registers+6? we need a random number generator...... but what
* do we do to mix in the sound? is it random speed? or just random note to
* play???? with zeros or not???? which sounds better????????? check
*
* PSG_registers+6 emulated on extra channel..... is there a way to mix in that channel
* with the others using the amiga?????? check to see, if not, maybe a way
* to mix sound by combinging data.............
*
* note, sample pointers for all channels....... so if each channel had 
* hardware envelopes, we need to poke each byte in for every channel......
*
* okay, to emulate the hardware envelopes is easy, we store the data needed
* as a looped sample, or not looped depending on whether it is continue or
* not.............
*
* we have a pointer to the appropiate envelope data, and all it does is
* every time the volume needs to be changed indicated, by the envelope
* duration....we poke the new value into the appropiate channel data, i.e.
* those channels which have the hardware envelope bits enabled.......
* 
* so now, we have emulated 11,12,13..... simple.....
*
* so to get the tone, we change the frequency using the amiga control.....
* to get the tone normal volume, we change the 1st byte of the data
*
* to get the hardware envelope volume, we change the 1st byte every now and
* then determined by a counter (which is 11,12)



* note tone period=62500/frequency

* so to get a sound, we need to play a volume every so many seconds
* how can this be done with the amiga hardware sound????????/

* well white PSG_registers+6 is random crackles, we can get random crackles by
* generating a random number, and depending on the value in register 5
* is the range of the random number to produce.....

* or alternatively, if it sounds right, we simply have a value stored
* and we add to it, the value in register 6 then we add this value to
* the volume, and divide by two???????? will that work???????

* the higher the value, the greater the steps, or the greater the loudness
* of the value?????????

; - sometimes read fail when insert a disk image which is understood.
; - find problem and fix

; lsl.w	#2,d0 
; move.l 0(a0,d0.w),a2
;
; not the same as:
;
; move.l 0(a0,d0.w*4),a2
;
; (when D0*4 could be &7fff-&ffff)
; d0.w*4 is not sign extended! :(
;
; addq.w #1,d0
; move.l 0(a0,d0.w),a0
;
; not the same as:
;
; move.l 1(a0,d0.w),a0

