| version 1.5, 2004/08/05 04:53:15 | version 1.18, 2005/02/04 06:42:11 | 
| Line 1 | Line 1 | 
 | #include        "compiler.h" | #include        "compiler.h" | 
 |  | #include        "z80core.h" | 
 | #include        "pccore.h" | #include        "pccore.h" | 
 | #include        "iocore.h" | #include        "iocore.h" | 
 | #include        "draw.h" |  | 
 |  |  | 
 |  |  | 
 | // ---- 8255 PPI〜 | // ---- 8255 PPI〜 | 
 |  |  | 
| void IOOUTCALL ppi_o(UINT port, REG8 value) { | static REG8 getportb(void) { | 
 |  |  | 
| UINT8   bak_c; | REG8    ret; | 
| UINT8   bit; | REG8    ppib; | 
| UINT8   xl; | #if defined(MAINFRAMES_OLD) | 
|  | SINT32  clock; | 
|  | #endif | 
 |  |  | 
| if (crtc.s.TXT_XL == 40) { | //      if (subcpu.IBF) { | 
| ppi.PORT_C |= 0x40; | //              subcpu.IBF = 0; | 
|  | //              ret |= 0x40;                                            // 1:SUB-CPU BUSY | 
|  | //      } | 
|  | //      if (subcpu.OBF) { | 
|  | //              ret |= 0x20;                                            // 1:SUB-CPU Data empty | 
|  | //      } | 
|  |  | 
|  | ppib = iocore.s.ppib; | 
|  | ret = ppib; | 
|  |  | 
|  | //      ret |= cmt_test();                                              // THUNDER BALL | 
|  | //      /* -> */ ppib |= 0x01; | 
|  |  | 
|  | iocore.s.ppib = (UINT8)((ppib & (~0x40)) | 0x01); | 
|  |  | 
|  | //      ret |= cmt_read(); | 
|  |  | 
|  | #if defined(MAINFRAMES_OLD) | 
|  | clock = CPU_CLOCKCOUNT - iocore.e.framestartclock; | 
|  | if (clock < iocore.e.dispclock) { | 
|  | ret |= 0x80;                                            // 1:DISP | 
|  | } | 
|  |  | 
|  | // 実機の動きを見ると どうも 読み込んだらリセットされるようだ? | 
|  | // 有効範囲が絞れるならそうすべき(VSYNCを取りこぼすソフトがある | 
|  | clock -= iocore.e.vsyncstart; | 
|  | if ((clock >= 0) && (clock < iocore.e.vpulseclock)) { | 
|  | ret |= 0x04;                                            // 1:V-SYNC | 
 | } | } | 
| else { | #endif | 
| ppi.PORT_C &= ~0x40; | return(ret); | 
|  | } | 
|  |  | 
|  | static void setportc(REG8 dat) { | 
|  |  | 
|  | REG8    modify; | 
|  |  | 
|  | modify = ppi.portc ^ dat; | 
|  | ppi.portc = dat; | 
|  | //      cmt_write((REG8)(dat & 1)); | 
|  | if ((modify & 0x20) && (!(dat & 0x20))) { | 
|  | iocore.s.mode = 1; | 
|  | //              TRACEOUT(("iocore.s.mode = 1")); | 
 | } | } | 
| bak_c = ppi.PORT_C; | if (modify & 0x40) { | 
|  | crtc_setwidth((REG8)(dat & 0x40)); | 
|  | } | 
|  | } | 
|  |  | 
|  |  | 
|  | // ---- | 
|  |  | 
|  | void IOOUTCALL ppi_o(UINT port, REG8 value) { | 
|  |  | 
|  | REG8    bit; | 
 |  |  | 
 | switch(port & 0x0f) { | switch(port & 0x0f) { | 
 | case 0: | case 0: | 
| if (!(ppi.MODE & 0x10)) { | ppi.porta = value; | 
| ppi.PORT_A = value; |  | 
| } |  | 
 | return; | return; | 
 |  |  | 
 | case 1: | case 1: | 
| if (!(ppi.MODE & 0x02)) { | ppi.portb = value; | 
| ppi.PORT_B = value; |  | 
| } |  | 
 | return; | return; | 
 |  |  | 
 | case 2: | case 2: | 
| if (!(ppi.MODE & 0x01)) { | setportc(value); | 
| ppi.PORT_C &= 0xf0; |  | 
| ppi.PORT_C |= (value & 0x0f); |  | 
| } |  | 
| if (!(ppi.MODE & 0x08)) { |  | 
| ppi.PORT_C &= 0x0f; |  | 
| ppi.PORT_C |= (value & 0xf0); |  | 
| } |  | 
 | break; | break; | 
 |  |  | 
 | case 3: | case 3: | 
 | if (value & 0x80) { | if (value & 0x80) { | 
| ppi.MODE = value; | ppi.mode = value; | 
 | return; | return; | 
 | } | } | 
 | else { | else { | 
| bit = (UINT8)(1 << ((value >> 1) & 7)); | bit = 1 << ((value >> 1) & 7); | 
 | if (value & 0x01) { | if (value & 0x01) { | 
| ppi.PORT_C |= bit; | setportc((REG8)(ppi.portc | bit)); | 
 | } | } | 
 | else { | else { | 
| ppi.PORT_C &= ~bit; | setportc((REG8)(ppi.portc & (~bit))); | 
 | } | } | 
 | } | } | 
 | break; | break; | 
 |  |  | 
 | default: |  | 
 | return; |  | 
 | } |  | 
 |  |  | 
 | //      cmt_write(ppi.PORT_C & 1); |  | 
 | if ((bak_c & 0x20) && (!(ppi.PORT_C & 0x20))) { |  | 
 | ppi.IO_MODE = 1; |  | 
 | } |  | 
 | xl = ((ppi.PORT_C & 0x40)?40:80); |  | 
 | if (crtc.s.TXT_XL != xl) { |  | 
 | crtc.s.TXT_XL = (UINT8)xl; |  | 
 | crtc.s.GRP_XL = xl << 3; |  | 
 | vrambank_patch(); |  | 
 | scrnallflash = 1; |  | 
 | } | } | 
 | } | } | 
 |  |  | 
 | REG8 IOINPCALL ppi_i(UINT port) { | REG8 IOINPCALL ppi_i(UINT port) { | 
 |  |  | 
 | ppi.PORT_B = cmt_test(); // | cmt_read();       // THUNDER BALL |  | 
 |  |  | 
 | if (v_cnt < crtc.s.CRT_YL) { |  | 
 | ppi.PORT_B |= 0x80;                                     // 1:DISP |  | 
 | } |  | 
 | if (subcpu.IBF) { |  | 
 | subcpu.IBF = 0; |  | 
 | ppi.PORT_B |= 0x40;                                     // 1:SUB-CPU BUSY |  | 
 | } |  | 
 | if (subcpu.OBF) { |  | 
 | ppi.PORT_B |= 0x20;                                     // 1:SUB-CPU Data empty |  | 
 | } |  | 
 | if (memio.ram) { |  | 
 | ppi.PORT_B |= 0x10;                                     // 1:RAM |  | 
 | } |  | 
 | #if 1 |  | 
 | if (!(v_cnt < crtc.s.CRT_VS)) { |  | 
 | ppi.PORT_B |= 0x04;                                     // V-SYNC |  | 
 | } |  | 
 | #else                                                           // ラプラステスト…VYSNCが長すぎるらしい |  | 
 | if (v_cnt == crtc.s.CRT_VS) { |  | 
 | ppi.PORT_B |= 0x04; |  | 
 | } |  | 
 | #endif |  | 
 | if (crtc.s.TXT_XL == 40) { |  | 
 | ppi.PORT_C |= 0x40; |  | 
 | } |  | 
 | else { |  | 
 | ppi.PORT_C &= ~0x40; |  | 
 | } |  | 
 | switch(port & 0x0f) { | switch(port & 0x0f) { | 
 | case 0: | case 0: | 
| return(ppi.PORT_A); | //      if (!(ppi.mode & 0x10)) { | 
|  | //              return(ppi.porta); | 
|  | //      } | 
|  | return(ppi.porta); | 
 |  |  | 
 | case 1: | case 1: | 
| return(ppi.PORT_B); | if (!(ppi.mode & 0x02)) { | 
|  | return(ppi.portb); | 
|  | } | 
|  | return(getportb()); | 
 |  |  | 
 | case 2: | case 2: | 
| return(ppi.PORT_C); | // mode? | 
|  | return(ppi.portc); | 
 |  |  | 
 | case 3: | case 3: | 
| return(ppi.MODE); | return(ppi.mode); | 
 | } | } | 
 | return(0xff); | return(0xff); | 
 | } | } | 
| Line 130  REG8 IOINPCALL ppi_i(UINT port) { | Line 132  REG8 IOINPCALL ppi_i(UINT port) { | 
 |  |  | 
 | void ppi_initialize(void) { | void ppi_initialize(void) { | 
 |  |  | 
| ppi.PORT_A = 0x00; | ppi.porta = 0x00; | 
| ppi.PORT_B = 0xff; | ppi.portb = 0xff; | 
| ppi.PORT_C = 0xff; | ppi.portc = 0xff; | 
| ppi.MODE = 0; | ppi.mode = 0x82; | 
| ppi.IO_MODE = 0; |  | 
 | } | } | 
 |  |  | 
 | void ppi_reset(void) { | void ppi_reset(void) { | 
 |  |  | 
| ppi.MODE = 0; | ppi.porta = 0x00; | 
| ppi.PORT_A = 0; | ppi.portc |= 0x40; | 
| ppi.PORT_C |= 0x40; | ppi.mode = 0x82; | 
| ppi.IO_MODE = 0; |  | 
 | } | } | 
 |  |  |