1 #include <ctype.h>
2 #ifdef _MSC_EXTENSIONS
3 #include <excpt.h>
4 #endif
5 #include <math.h>
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <string.h>
9 
10 #include "sapGlobals.h"
11 
12 
13 #define NAMESPACENAME	POKEY1_NAMESPACE
14 #define POKEY_INIT_FUNC			void pokeyInit1( void )
15 #define POKEY_RESET_FUNC		void pokeyReset1( void )
16 #define POKEY_UPDATESOUND_FUNC	void pokeyUpdateSound1( int n )
17 #define POKEY_UPDATECOUNT_FUNC	void pokeyUpdateSoundCounters1( void )
18 #define POKEY_WRITE_FUNC		void pokeyWriteByte1( short unsigned int address, BYTE value )
19 #define POKEY_WRITE_2FUNC(a,v)	pokeyWriteByte1(a,v)
20 #include "pokeyNamespace.h"
21 
22 POKEY_WRITE_FUNC
23 {
24 	address&=0x0F;
25 
26 	switch( address )
27 	{
28 		case 0x00:
29 			divideByN_Latch[0] = value;
30 			SetupChannels01;
31 			break;
32 		case 0x01:
33 			audioControl_Latch[0] = value;
34 			audioControl_Latch2[0] = value&15;
35 			audioControl_Latch_Digi[0] = (value>>4)&1 ? 15:0;
36 			Channel0Distortion = channelsDistorionTable0[ (value>>4)&15 ];
37 			if( !(value&0x10) )
38 				SetupChannels01;
39 			break;
40 		case 0x02:
41 			divideByN_Latch[1] = value;
42 			SetupChannels01;
43 			break;
44 		case 0x03:
45 			audioControl_Latch[1] = value;
46 			audioControl_Latch2[1] = value&15;
47 			audioControl_Latch_Digi[1] = (value>>4)&1 ? 15:0;
48 			Channel1Distortion = channelsDistorionTable1[ (value>>4)&15 ];
49 			if( !(value&0x10) )
50 				SetupChannels01;
51 			break;
52 		case 0x04:
53 			divideByN_Latch[2] = value;
54 			SetupChannels23;
55 			break;
56 		case 0x05:
57 			audioControl_Latch[2] = value;
58 			audioControl_Latch2[2] = value&15;
59 			audioControl_Latch_Digi[2] = (value>>4)&1 ? 15:0;
60 			Channel2Distortion = channelsDistorionTable2[ (value>>4)&15 ];
61 			if( !(value&0x10) )
62 				SetupChannels23;
63 			break;
64 		case 0x06:
65 			divideByN_Latch[3] = value;
66 			SetupChannels23;
67 			break;
68 		case 0x07:
69 			audioControl_Latch[3] = value;
70 			audioControl_Latch2[3] = value&15;
71 			audioControl_Latch_Digi[3] = (value>>4)&1 ? 15:0;
72 			Channel3Distortion = channelsDistorionTable3[ (value>>4)&15 ];
73 			if( !(value&0x10) )
74 				SetupChannels23;
75 			break;
76 		case 0x08:
77 		{
78 			BYTE prevAUDCTL;
79 			prevAUDCTL = AUDCTL;
80 			AUDCTL = value;
81 			pcc1564 = value & 1 ? 112:28;
82 
83 			noiseAND = AUDCTL & 128 ? 0x1FF:0x1FFFF;
84 
85 			switch_J3_Q_stateAND[0] = AUDCTL&4 ? 15:0;
86 			switch_J3_Q_stateAND[1] = AUDCTL&2 ? 15:0;
87 
88 			SetupChannels01;
89 			SetupChannels23;
90 
91 			if( (prevAUDCTL^AUDCTL)&0x10 )
92 				divideByN[1] = 2;
93 			if( (prevAUDCTL^AUDCTL)&0x8 )
94 				divideByN[3] = 2;
95 
96 			break;
97 		}
98 		case 0x0D:
99 			break;
100 		case 0x0E:
101 			break;
102 		case 0x0F:
103 			break;
104 	}
105 }
106