-
Notifications
You must be signed in to change notification settings - Fork 0
/
tcc1014registers.c
412 lines (349 loc) · 7.76 KB
/
tcc1014registers.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
/*
Copyright 2015 by Joseph Forgione
This file is part of VCC (Virtual Color Computer).
VCC (Virtual Color Computer) is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
VCC (Virtual Color Computer) is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with VCC (Virtual Color Computer). If not, see <http://www.gnu.org/licenses/>.
*/
#include <windows.h>
#include "defines.h"
#include "tcc1014mmu.h"
#include "tcc1014registers.h"
#include "tcc1014graphics.h"
#include "coco3.h"
#include "keyboard.h"
#include "Vcc.h"
static unsigned char VDG_Mode=0;
static unsigned char Dis_Offset=0;
static unsigned char MPU_Rate=0;
static unsigned char *rom;
static unsigned char GimeRegisters[256];
static unsigned short VerticalOffsetRegister=0;
static unsigned char EnhancedFIRQFlag=0,EnhancedIRQFlag=0;
static int InteruptTimer=0;
void SetInit0(unsigned char);
void SetInit1(unsigned char);
void SetGimeIRQStearing(unsigned char);
void SetGimeFIRQStearing(unsigned char);
void SetTimerMSB(unsigned char);
void SetTimerLSB(unsigned char);
unsigned char GetInit0(unsigned char port);
static unsigned char IRQStearing[8]={0,0,0,0,0,0,0,0};
static unsigned char FIRQStearing[8]={0,0,0,0,0,0,0,0};
static unsigned char LastIrq=0,LastFirq=0,Temp=0;
static unsigned char KeyboardInteruptEnabled = 0;
unsigned char GimeGetKeyboardInteruptState()
{
return KeyboardInteruptEnabled;
}
void GimeSetKeyboardInteruptState(unsigned char State)
{
KeyboardInteruptEnabled = !!State;
}
void GimeWrite(unsigned char port,unsigned char data)
{
GimeRegisters[port]=data;
switch (port)
{
case 0x90:
SetInit0(data);
break;
case 0x91:
SetInit1(data);
break;
case 0x92:
SetGimeIRQStearing(data);
break;
case 0x93:
SetGimeFIRQStearing(data);
break;
case 0x94:
SetTimerMSB(data);
break;
case 0x95:
SetTimerLSB(data);
break;
case 0x96:
SetTurboMode(data & 1);
break;
case 0x97:
break;
case 0x98:
SetGimeVmode(data);
break;
case 0x99:
SetGimeVres(data);
break;
case 0x9A:
SetGimeBoarderColor(data);
break;
case 0x9B:
SetDistoRamBank(data);
break;
case 0x9C:
break;
case 0x9D:
case 0x9E:
SetVerticalOffsetRegister ((GimeRegisters[0x9D]<<8) | GimeRegisters[0x9E]);
break;
case 0x9F:
SetGimeHorzOffset(data);
break;
case 0xA0:
case 0xA1:
case 0xA2:
case 0xA3:
case 0xA4:
case 0xA5:
case 0xA6:
case 0xA7:
case 0xA8:
case 0xA9:
case 0xAA:
case 0xAB:
case 0xAC:
case 0xAD:
case 0xAE:
case 0xAF:
SetMmuRegister(port,data);
break;
case 0xB0:
case 0xB1:
case 0xB2:
case 0xB3:
case 0xB4:
case 0xB5:
case 0xB6:
case 0xB7:
case 0xB8:
case 0xB9:
case 0xBA:
case 0xBB:
case 0xBC:
case 0xBD:
case 0xBE:
case 0xBF:
SetGimePallet(port-0xB0,data & 63);
break;
}
return;
}
unsigned char GimeRead(unsigned char port)
{
switch (port)
{
case 0x92:
Temp=LastIrq;
LastIrq=0;
return(Temp);
break;
case 0x93:
Temp=LastFirq;
LastFirq=0;
return(Temp);
break;
case 0x94:
case 0x95:
return(126);
break;
default:
return(GimeRegisters[port]);
}
}
void SetInit0(unsigned char data)
{
SetCompatMode ( !!(data & 128));
Set_MmuEnabled (!!(data & 64)); //MMUEN
SetRomMap ( data & 3); //MC0-MC1
SetVectors( data & 8); //MC3
EnhancedFIRQFlag=(data & 16)>>4;
EnhancedIRQFlag=(data & 32)>>5;
return;
}
void SetInit1(unsigned char data)
{
Set_MmuTask(data & 1); //TR
SetTimerClockRate (data & 32); //TINS
return;
}
unsigned char GetInit0(unsigned char port)
{
unsigned char data=0;
return(data);
}
void SetGimeIRQStearing(unsigned char data) //92
{
if ( (GimeRegisters[0x92] & 2) | (GimeRegisters[0x93] & 2) )
GimeSetKeyboardInteruptState(1);
else
GimeSetKeyboardInteruptState(0);
if ( (GimeRegisters[0x92] & 8) | (GimeRegisters[0x93] & 8) )
SetVertInteruptState(1);
else
SetVertInteruptState(0);
if ( (GimeRegisters[0x92] & 16) | (GimeRegisters[0x93] & 16) )
SetHorzInteruptState(1);
else
SetHorzInteruptState(0);
if ( (GimeRegisters[0x92] & 32) | (GimeRegisters[0x93] & 32) )
SetTimerInteruptState(1);
else
SetTimerInteruptState(0);
return;
}
void SetGimeFIRQStearing(unsigned char data) //93
{
if ( (GimeRegisters[0x92] & 2) | (GimeRegisters[0x93] & 2) )
GimeSetKeyboardInteruptState(1);
else
GimeSetKeyboardInteruptState(0);
if ( (GimeRegisters[0x92] & 8) | (GimeRegisters[0x93] & 8) )
SetVertInteruptState(1);
else
SetVertInteruptState(0);
if ( (GimeRegisters[0x92] & 16) | (GimeRegisters[0x93] & 16) )
SetHorzInteruptState(1);
else
SetHorzInteruptState(0);
// Moon Patrol Demo Using Timer for FIRQ Side Scroll
if ( (GimeRegisters[0x92] & 32) | (GimeRegisters[0x93] & 32) )
SetTimerInteruptState(1);
else
SetTimerInteruptState(0);
return;
}
void SetTimerMSB(unsigned char data) //94
{
unsigned short Temp;
Temp=((GimeRegisters[0x94] <<8)+ GimeRegisters[0x95]) & 4095;
SetInteruptTimer(Temp);
return;
}
void SetTimerLSB(unsigned char data) //95
{
unsigned short Temp;
Temp=((GimeRegisters[0x94] <<8)+ GimeRegisters[0x95]) & 4095;
SetInteruptTimer(Temp);
return;
}
void GimeAssertKeyboardInterupt(void)
{
if ( ((GimeRegisters[0x93] & 2)!=0) & (EnhancedFIRQFlag==1))
{
CPUAssertInterupt(FIRQ,0);
LastFirq=LastFirq | 2;
}
else
if ( ((GimeRegisters[0x92] & 2)!=0) & (EnhancedIRQFlag==1))
{
CPUAssertInterupt(IRQ,0);
LastIrq=LastIrq | 2;
}
return;
}
void GimeAssertVertInterupt(void)
{
if (((GimeRegisters[0x93] & 8)!=0) & (EnhancedFIRQFlag==1))
{
CPUAssertInterupt(FIRQ,0); //FIRQ
LastFirq=LastFirq | 8;
}
else
if (((GimeRegisters[0x92] & 8)!=0) & (EnhancedIRQFlag==1))
{
CPUAssertInterupt(IRQ,0); //IRQ moon patrol demo using this
LastIrq=LastIrq | 8;
}
return;
}
void GimeAssertHorzInterupt(void)
{
if (((GimeRegisters[0x93] & 16)!=0) & (EnhancedFIRQFlag==1))
{
CPUAssertInterupt(FIRQ,0);
LastFirq=LastFirq | 16;
}
else
if (((GimeRegisters[0x92] & 16)!=0) & (EnhancedIRQFlag==1))
{
CPUAssertInterupt(IRQ,0);
LastIrq=LastIrq | 16;
}
return;
}
void GimeAssertTimerInterupt(void)
{
if (((GimeRegisters[0x93] & 32)!=0) & (EnhancedFIRQFlag==1))
{
CPUAssertInterupt(FIRQ,0);
LastFirq=LastFirq | 32;
}
else
if (((GimeRegisters[0x92] & 32)!=0) & (EnhancedIRQFlag==1))
{
CPUAssertInterupt(IRQ,0);
LastIrq=LastIrq | 32;
}
return;
}
unsigned char sam_read(unsigned char port) //SAM don't talk much :)
{
if ( (port>=0xF0) & (port <=0xFF)) //IRQ vectors from rom
return( rom[0x3F00 + port]);
return(0);
}
void sam_write(unsigned char data ,unsigned char port)
{
unsigned char mask=0;
unsigned char reg=0;
if ((port >=0xC6) & (port <=0xD3)) //VDG Display offset Section
{
port=port-0xC6;
reg= ((port & 0x0E)>>1);
mask= 1<<reg;
Dis_Offset= Dis_Offset & (0xFF-mask); //Shut the bit off
if (port & 1)
Dis_Offset= Dis_Offset | mask;
SetGimeVdgOffset(Dis_Offset);
}
if ((port >=0xC0) & (port <=0xC5)) //VDG Mode
{
port=port-0xC0;
reg= ((port & 0x0E)>>1);
mask= 1<<reg;
VDG_Mode = VDG_Mode & (0xFF-mask);
if (port & 1)
VDG_Mode = VDG_Mode | mask;
SetGimeVdgMode(VDG_Mode);
}
if ( (port==0xDE) | (port ==0xDF))
SetMapType(port&1);
if ( (port==0xD7) | (port==0xD9) )
SetCPUMultiplyerFlag (1);
if ( (port==0xD6) | (port==0xD8) )
SetCPUMultiplyerFlag (0);
return;
}
void mc6883_reset()
{
VDG_Mode=0;
Dis_Offset=0;
MPU_Rate=0;
rom=Getint_rom_pointer();
return;
}
unsigned char VDG_Offset(void)
{
return(Dis_Offset);
}
unsigned char VDG_Modes(void)
{
return(VDG_Mode);
}