--- uae/src/cia.c 2018/04/24 17:10:48 1.1.1.16 +++ uae/src/cia.c 2018/04/24 17:16:34 1.1.1.19 @@ -11,7 +11,6 @@ #include "sysdeps.h" #include -#include "config.h" #include "options.h" #include "threaddep/thread.h" #include "events.h" @@ -21,6 +20,7 @@ #include "serial.h" #include "disk.h" #include "xwin.h" +#include "inputdevice.h" #include "keybuf.h" #include "gui.h" #include "savestate.h" @@ -69,6 +69,7 @@ static int kbstate, kback, ciaasdr_unrea static int prtopen; static FILE *prttmp; +static int warned = 10; static void setclr (unsigned int *p, unsigned int val) { @@ -83,7 +84,7 @@ static void RethinkICRA (void) { if (ciaaimask & ciaaicr) { ciaaicr |= 0x80; - INTREQ_0 (0x8008); + INTREQ_0 (0x8000 | 0x0008); } else { ciaaicr &= 0x7F; /* custom_bank.wput(0xDFF09C,0x0008);*/ @@ -92,17 +93,11 @@ static void RethinkICRA (void) static void RethinkICRB (void) { -#if 0 /* ??? What's this then? */ - if (ciabicr & 0x10) { - custom_bank.wput(0xDFF09C,0x9000); - } -#endif if (ciabimask & ciabicr) { ciabicr |= 0x80; - INTREQ_0 (0xA000); + INTREQ_0 (0x8000 | 0x2000); } else { ciabicr &= 0x7F; -/* custom_bank.wput(0xDFF09C,0x2000);*/ } } @@ -162,14 +157,16 @@ static void CIA_update (void) if ((ciaata+1) == ciaclocks) { aovfla = 1; if ((ciaacrb & 0x61) == 0x41) { - if (ciaatb-- == 0) aovflb = 1; + if (ciaatb-- == 0) + aovflb = 1; } } ciaata -= ciaclocks; } if ((ciaacrb & 0x61) == 0x01) { assert ((ciaatb+1) >= ciaclocks); - if ((ciaatb+1) == ciaclocks) aovflb = 1; + if ((ciaatb+1) == ciaclocks) + aovflb = 1; ciaatb -= ciaclocks; } @@ -179,14 +176,16 @@ static void CIA_update (void) if ((ciabta+1) == ciaclocks) { bovfla = 1; if ((ciabcrb & 0x61) == 0x41) { - if (ciabtb-- == 0) bovflb = 1; + if (ciabtb-- == 0) + bovflb = 1; } } ciabta -= ciaclocks; } if ((ciabcrb & 0x61) == 0x01) { assert ((ciabtb+1) >= ciaclocks); - if ((ciabtb+1) == ciaclocks) bovflb = 1; + if ((ciabtb+1) == ciaclocks) + bovflb = 1; ciabtb -= ciaclocks; } if (aovfla) { @@ -215,7 +214,7 @@ static void CIA_update (void) static void CIA_calctimers (void) { - long ciaatimea = -1, ciaatimeb = -1, ciabtimea = -1, ciabtimeb = -1; + long int ciaatimea = -1, ciaatimeb = -1, ciabtimea = -1, ciabtimeb = -1; eventtab[ev_cia].oldcycles = get_cycles (); if ((ciaacra & 0x21) == 0x01) { @@ -300,7 +299,7 @@ void CIA_hsync_handler (void) if (doreadser) doreadser = SERDATS(); - if (keys_available() && kback && (++keytime & 15) == 0) { + if (keys_available() && kback && (ciaacra & 0x40) == 0 && (++keytime & 15) == 0) { /* * This hack lets one possible ciaaicr cycle go by without any key * being read, for every cycle in which a key is pulled out of the @@ -313,9 +312,9 @@ void CIA_hsync_handler (void) * or no lossage, and the mouse doesn't get stuck. The tradeoff is * that the total slowness of typing appearing on screen is worse. */ - if (ciaasdr_unread == 2) + if (ciaasdr_unread == 2) { ciaasdr_unread = 0; - else if (ciaasdr_unread == 0) { + } else if (ciaasdr_unread == 0) { switch (kbstate) { case 0: ciaasdr = (uae_s8)~0xFB; /* aaarghh... stupid compiler */ @@ -333,8 +332,9 @@ void CIA_hsync_handler (void) ciaaicr |= 8; RethinkICRA(); sleepyhead = 0; - } else if (!(++sleepyhead & 15)) + } else if (!(++sleepyhead & 15)) { ciaasdr_unread = 0; /* give up on this key event after unread for a long time */ + } } } @@ -357,18 +357,19 @@ static uae_u8 ReadCIAA (unsigned int add unsigned int tmp; compute_passed_time (); - + switch (addr & 0xf) { case 0: if (currprefs.use_serial && (serstat < 0)) /* Only read status when needed */ serstat=serial_readstatus(); /* and only once per frame */ tmp = (DISK_status() & 0x3C); - if ((JSEM_ISMOUSE (0, &currprefs) && !buttonstate[0]) - || (!JSEM_ISMOUSE (0, &currprefs) && !(joy0button & 1))) - tmp |= 0x40; - if (!(joy1button & 1)) - tmp |= 0x80; + tmp |= handle_joystick_buttons (ciaadra); + tmp |= (ciaapra | (ciaadra ^ 3)) & 0x03; + if (ciaadra & 0x40) + tmp = (tmp & ~0x40) | (ciaapra & 0x40); + if (ciaadra & 0x80) + tmp = (tmp & ~0x80) | (ciaapra & 0x80); return tmp; case 1: /* Returning 0xFF is necessary for Tie Break - otherwise its joystick @@ -402,10 +403,12 @@ static uae_u8 ReadCIAA (unsigned int add ciaatol = ciaatod; /* ??? only if not already latched? */ return (ciaatol >> 16) & 0xff; case 12: - if (ciaasdr == 1) ciaasdr_unread = 2; + if (ciaasdr_unread == 1) + ciaasdr_unread = 2; return ciaasdr; case 13: - tmp = ciaaicr; ciaaicr = 0; RethinkICRA(); return tmp; + tmp = ciaaicr; ciaaicr = 0; RethinkICRA(); + return tmp; case 14: return ciaacra; case 15: @@ -485,7 +488,7 @@ static void WriteCIAA (uae_u16 addr,uae_ gui_led (0, !(ciaapra & 2)); if ((ciaapra & 1) != oldovl) { int i = (allocated_chipmem>>16) > 32 ? allocated_chipmem >> 16 : 32; - + if (oldovl || ersatzkickfile) { map_banks (&chipmem_bank, 0, i, allocated_chipmem); } else { @@ -530,9 +533,11 @@ static void WriteCIAA (uae_u16 addr,uae_ ciaaicr |= 0x10; break; case 2: - ciaadra = val; break; + ciaadra = val; + break; case 3: - ciaadrb = val; break; + ciaadrb = val; + break; case 4: CIA_update (); ciaala = (ciaala & 0xff00) | val; @@ -590,9 +595,11 @@ static void WriteCIAA (uae_u16 addr,uae_ } break; case 12: - ciaasdr = val; break; + ciaasdr = val; + break; case 13: - setclr(&ciaaimask,val); break; /* ??? call RethinkICR() ? */ + setclr(&ciaaimask,val); + break; case 14: CIA_update (); ciaacra = val; @@ -600,9 +607,8 @@ static void WriteCIAA (uae_u16 addr,uae_ ciaacra &= ~0x10; ciaata = ciaala; } - if (ciaacra & 0x40) { + if (ciaacra & 0x40) kback = 1; - } CIA_calctimers (); break; case 15: @@ -738,7 +744,7 @@ void CIA_reset (void) map_banks (&kickmem_bank, 0, i, 0x80000); } - if (currprefs.use_serial && !savestate_state) + if (currprefs.use_serial && !savestate_state) serial_dtr_off (); /* Drop DTR at reset */ if (savestate_state) { @@ -788,35 +794,56 @@ static void cia_wait (void) uae_u32 REGPARAM2 cia_bget (uaecptr addr) { int r = (addr & 0xf00) >> 8; + uae_u8 v; + special_mem |= S_READ; cia_wait (); + v = 0xff; switch ((addr >> 12) & 3) { case 0: - return (addr & 1) ? ReadCIAA (r) : ReadCIAB (r); + v = (addr & 1) ? ReadCIAA (r) : ReadCIAB (r); + break; case 1: - return (addr & 1) ? 0xff : ReadCIAB (r); + v = (addr & 1) ? 0xff : ReadCIAB (r); + break; case 2: - return (addr & 1) ? ReadCIAA (r) : 0xff; + v = (addr & 1) ? ReadCIAA (r) : 0xff; + break; +#if 0 + case 3: + if (currprefs.cpu_level == 0 && currprefs.cpu_compatible) + v = (addr & 1) ? regs.irc : regs.irc >> 8; + if (warned > 0) { + write_log ("cia_bget: unknown CIA address %x PC=%x\n", addr, m68k_getpc()); + warned--; + } + break; +#endif } - return 0xff; + return v; } uae_u32 REGPARAM2 cia_wget (uaecptr addr) { int r = (addr & 0xf00) >> 8; + uae_u16 v; special_mem |= S_READ; cia_wait (); + v = 0xffff; switch ((addr >> 12) & 3) { case 0: - return (ReadCIAB (r) << 8) | ReadCIAA (r); + v = (ReadCIAB (r) << 8) | ReadCIAA (r); + break; case 1: - return (ReadCIAB (r) << 8) | 0xff; + v = (ReadCIAB (r) << 8) | 0xff; + break; case 2: - return (0xff << 8) | ReadCIAA (r); + v = (0xff << 8) | ReadCIAA (r); + break; } - return 0xffff; + return v; } uae_u32 REGPARAM2 cia_lget (uaecptr addr) @@ -938,7 +965,7 @@ void REGPARAM2 clock_bput (uaecptr addr, /* CIA-A and CIA-B save/restore code */ -uae_u8 *restore_cia (int num, uae_u8 *src) +const uae_u8 *restore_cia (int num, const uae_u8 *src) { uae_u8 b; uae_u16 w; @@ -998,12 +1025,15 @@ uae_u8 *restore_cia (int num, uae_u8 *sr return src; } -uae_u8 *save_cia (int num, int *len) +uae_u8 *save_cia (int num, int *len, uae_u8 *dstptr) { uae_u8 *dstbak,*dst, b; uae_u16 t; - dstbak = dst = malloc (16 + 12 + 1); + if (dstptr) + dstbak = dst = dstptr; + else + dstbak = dst = malloc (16 + 12 + 1); compute_passed_time (); @@ -1014,7 +1044,7 @@ uae_u8 *save_cia (int num, int *len) b = num ? ciabprb : ciaaprb; /* 1 PRB */ save_u8 (b); b = num ? ciabdra : ciaadra; /* 2 DDRA */ - save_u8 (b); + save_u8 (b); b = num ? ciabdrb : ciaadrb; /* 3 DDRB */ save_u8 (b); t = (num ? ciabta - ciabta_passed : ciaata - ciaata_passed);/* 4 TA */