41 if (cia->ICRmask & cia->ICRdata & 31) { \
42 cia->ICRdata |= 128; \
43 if (!cia->intLevel) { cia->intLevel = 1; cia->setint(1); DEBUG("%s IRQ to 1" NL, cia->name); } \
45 cia->ICRdata &= 127; \
46 if ( cia->intLevel) { cia->intLevel = 0; cia->setint(0); DEBUG("%s IRQ to 0" NL, cia->name); } \
49 #define ICR_SET(mask) \
51 cia->ICRdata |= (mask) & 31; \
52 DEBUG("%s ICR set to data $%02X, mask is $%02X" NL, cia->name, cia->ICRdata, cia->ICRmask); \
55 #define ICR_CLEAR(mask) \
57 cia->ICRdata &= 255 - (mask); \
66 for (a = 0; a < 16; a++)
74 cia->
tod[0] = cia->
tod[1] = cia->
tod[2] = cia->
tod[3] = 0;
92 static Uint8 def_ina (
void ) {
return 0xFF; }
93 static Uint8 def_inb (
void) {
return 0xFF; }
94 static Uint8 def_insr (
void) {
return 0xFF; }
95 static void def_setint(
int level) {}
106 void (*setint)(
int level)
109 cia->
outa = outa ? outa : def_outa;
110 cia->
outb = outb ? outb : def_outb;
111 cia->
outsr = outsr ? outsr : def_outsr;
112 cia->
ina = ina ? ina : def_ina;
113 cia->
inb = inb ? inb : def_inb;
114 cia->
insr = insr ? insr : def_insr;
115 cia->
setint = setint ? setint : def_setint;
124 switch (
addr & 0xF) {
137 return cia->
TCA & 0xFF;
139 return cia->
TCA >> 8;
141 return cia->
TCB & 0xFF;
143 return cia->
TCB >> 8;
171 switch (
addr & 0xF) {
203 if (!(cia->
CRA & 1) || (cia->
CRA & 16))
211 if (!(cia->
CRB & 1) || (cia->
CRB & 16))
254 cia->
CRA &= 255 - 16;
261 cia->
CRB &= 255 - 16;
275 cia->
tod[1] = XEMU_BYTE_TO_BCD(t->tm_sec);
276 cia->
tod[2] = XEMU_BYTE_TO_BCD(t->tm_min);
283 int timer_a_underflow = 0;
288 timer_a_underflow = 1;
301 if ((cia->
CRB & 64)) {
302 if (timer_a_underflow)
326 DEBUG(
"%s registers written:", cia->
name);
327 for (a = 0; a < 16; a++)
339 #ifdef XEMU_SNAPSHOT_SUPPORT
343 #define SNAPSHOT_CIA_BLOCK_VERSION 0
344 #define SNAPSHOT_CIA_BLOCK_SIZE 256
346 int cia_snapshot_load_state (
const struct xemu_snapshot_definition_st *def,
struct xemu_snapshot_block_st *
block )
348 Uint8 buffer[SNAPSHOT_CIA_BLOCK_SIZE];
351 if (
block->block_version != SNAPSHOT_CIA_BLOCK_VERSION ||
block->sub_counter ||
block->sub_size !=
sizeof buffer)
352 RETURN_XSNAPERR_USER(
"Bad CIA block syntax");
353 a = xemusnap_read_file(buffer,
sizeof buffer);
356 for (a = 0; a < 16; a++) {
359 cia->
TCA = (int)P_AS_BE32(buffer + 128);
360 cia->
TCB = (int)P_AS_BE32(buffer + 132);
361 cia->
intLevel = (int)P_AS_BE32(buffer + 136);
362 cia->
CRA = buffer[140];
363 cia->
CRB = buffer[141];
374 int cia_snapshot_save_state (
const struct xemu_snapshot_definition_st *def )
376 Uint8 buffer[SNAPSHOT_CIA_BLOCK_SIZE];
378 int a = xemusnap_write_block_header(def->idstr, SNAPSHOT_CIA_BLOCK_VERSION);
380 memset(buffer, 0xFF,
sizeof buffer);
382 for (a = 0; a < 16; a++) {
384 buffer[a + 16] = cia->
regWritten[a] == -1 ? 0xFF : 0x00;
386 U32_AS_BE(buffer + 128, (
Uint32)cia->
TCA);
387 U32_AS_BE(buffer + 132, (
Uint32)cia->
TCB);
389 buffer[140] = cia->
CRA;
390 buffer[141] = cia->
CRB;
393 return xemusnap_write_sub_block(buffer,
sizeof buffer);