Diff for /xmil/io/crtc.c between versions 1.3 and 1.20

version 1.3, 2004/08/07 07:19:56 version 1.20, 2008/06/02 20:07:31
Line 1 Line 1
 #include        "compiler.h"  #include        "compiler.h"
 #include        "scrnmng.h"  #include        "z80core.h"
 #include        "pccore.h"  #include        "pccore.h"
 #include        "iocore.h"  #include        "iocore.h"
   #include        "nevent.h"
 #include        "vram.h"  #include        "vram.h"
 #include        "palettes.h"  #include        "palettes.h"
 #include        "makescrn.h"  #include        "makescrn.h"
   
   
                 BYTE    crtc_TEXTPAL[8];  static const UINT8 defrgbp[4] = {0xaa, 0xcc, 0xf0, 0x00};
                 WORD    crtc_GRPHPAL[2][64];  static const UINT8 defreg[18] = {
                 WORD    crtc_PAL4096[4096];                                  0x37, 0x28, 0x2d, 0x34,
                                   0x1f, 0x02, 0x19, 0x1c,
                                   0x00, 0x07, 0x00, 0x00,
                                   0x00, 0x00, 0x00, 0x00,
                                   0x00, 0x00};
   
 static const UINT8 def_TEXTPAL[8] = {  #if defined(SUPPORT_TURBOZ)
   static const UINT8 defpaltext[8] = {
                                 0x00, 0x03, 0x0c, 0x0f, 0x30, 0x33, 0x3c, 0x3f};                                  0x00, 0x03, 0x0c, 0x0f, 0x30, 0x33, 0x3c, 0x3f};
   
 static const UINT16 def_GRPHPAL[64] = {  static const UINT16 defpalgrph[64] = {
                                 0x000, 0x00a, 0x0a0, 0x0aa, 0xa00, 0xa0a, 0xaa0, 0xaaa,                                  0x000, 0x00a, 0x0a0, 0x0aa, 0xa00, 0xa0a, 0xaa0, 0xaaa,
                                 0x005, 0x00f, 0x0a5, 0x0af, 0xa05, 0xa0f, 0xaa5, 0xaaf,                                  0x005, 0x00f, 0x0a5, 0x0af, 0xa05, 0xa0f, 0xaa5, 0xaaf,
                                 0x050, 0x05a, 0x0f0, 0x0fa, 0xa50, 0xa5a, 0xaf0, 0xafa,                                  0x050, 0x05a, 0x0f0, 0x0fa, 0xa50, 0xa5a, 0xaf0, 0xafa,
Line 23  static const UINT16 def_GRPHPAL[64] = { Line 29  static const UINT16 def_GRPHPAL[64] = {
                                 0x505, 0x50f, 0x5a5, 0x5af, 0xf05, 0xf0f, 0xfa5, 0xfaf,                                  0x505, 0x50f, 0x5a5, 0x5af, 0xf05, 0xf0f, 0xfa5, 0xfaf,
                                 0x550, 0x55a, 0x5f0, 0x5fa, 0xf50, 0xf5a, 0xff0, 0xffa,                                  0x550, 0x55a, 0x5f0, 0x5fa, 0xf50, 0xf5a, 0xff0, 0xffa,
                                 0x555, 0x55f, 0x5f5, 0x5ff, 0xf55, 0xf5f, 0xff5, 0xfff};                                  0x555, 0x55f, 0x5f5, 0x5ff, 0xf55, 0xf5f, 0xff5, 0xfff};
   #endif
   
 static const CRTCSTAT crtcdefault = {  
                                 0xaa,                                           // PAL_B;  
                                 0xcc,                                           // PAL_R;  
                                 0xf0,                                           // PAL_G;  
                                 0x00,                                           // PLY  
                                 {0, 1, 2, 3, 4, 5, 6, 7},       // TEXT_PAL[8]  
                                 0,                                                      // SCRN_BITS  
                                 0,                                                      // CRTC_NUM  
   
                                 0,                                                      // DISP_PAGE  
                                 8,                                                      // FNT_XL  
                                 8,                                                      // FNT_YL  
                                 40,                                                     // TXT_XL  
                                 25,                                                     // TXT_YL  
                                 28,                                                     // TXT_YS  
                                 320,                                            // GRP_XL  
                                 200,                                            // GRP_YL  
                                 0,                                                      // CPU_BANK  
                                 0,                                                      // CRT_BANK  
   
                                 200,                                            // CRT_YL  
                                 232,                                            // CRT_VS  
                                 266,                                            // CRT_VL  
   
                                 31,                                                     // TXT_VL  
                                 10,                                                     // TXT_VLA  
   
                                 0,                                                      // TXT_TOP  
                                 8,                                                      // fnty  
   
                                 0,                                                      // lastpal  
   
                                 0,                                                      // BLACKPAL  
                                 0,                                                      // EXTPALMODE  
                                 0,                                                      // EXTGRPHPAL  
                                 0,                                                      // ZPRY  
         };  
   
         BYTE    dispmode = SCRN64_INVALID;  
         BYTE    pal_bank = PAL_NORMAL;  
         BYTE    pal_disp = PAL_NORMAL;  
   
 void vrambank_patch(void) {  typedef struct {
           UINT32  clock;
           UINT    minx;
           UINT    maxx;
           UINT    miny;
           UINT    maxy;
   } GDCCLK;
   
         UINT    updatemask;  static const GDCCLK gdcclk[] = {
                           {14318180 / 8, 112 - 8, 112 + 8, 200, 300},
                           {21052600 / 8, 108 - 6, 108 + 6, 400, 575}};
   
         if (crtc.s.SCRN_BITS & 0x10) {  
                 crtc.e.gram = GRP_RAM + GRAM_BANK1;  static void crtc_bankupdate(void) {
                 crtc.e.updatebit = UPDATE_VRAM1;  
           if (!(crtc.s.SCRN_BITS & SCRN_ACCESSVRAM)) {
                   crtc.e.gramacc = gram + GRAM_BANK0;
                   crtc.e.updatebit = UPDATE_VRAM0;
         }          }
         else {          else {
                 crtc.e.gram = GRP_RAM + GRAM_BANK0;                  crtc.e.gramacc = gram + GRAM_BANK1;
                 crtc.e.updatebit = UPDATE_VRAM0;                  crtc.e.updatebit = UPDATE_VRAM1;
         }          }
         dispmode = (crtc.s.SCRN_BITS & SCRN_DISPVRAM)?SCRN_BANK1:SCRN_BANK0;  }
         pal_bank = pal_disp = PAL_NORMAL;  
   static void crtc_dispupdate(void) {
   
           REG8    scrnpage;
           REG8    dispmode;
   #if defined(SUPPORT_TURBOZ)
           UINT    updatemask;
           REG8    pal_bank;
           REG8    pal_disp;
   #endif
   
           scrnpage = (crtc.s.SCRN_BITS & SCRN_DISPVRAM)?SCRN_BANK1:SCRN_BANK0;
           if (!crtc.s.width40) {
                   scrnpage += SCRN_WIDTH80;
           }
           dispmode = scrnpage;
           dispmode += (crtc.s.SCRN_BITS & SCRN_UNDERLINE) >> 4;
           dispmode += (crtc.s.SCRN_BITS & 7);
   
   #if !defined(SUPPORT_TURBOZ)
           crtc.e.updatemask = (crtc.s.SCRN_BITS & SCRN_TEXTYx2)?0x3ff:0x7ff;
           crtc.e.dispmode = dispmode;
   #else
           pal_bank = PAL_NORMAL;
           pal_disp = PAL_NORMAL;
         if ((!(crtc.s.EXTPALMODE & 0x80)) || (crtc.s.SCRN_BITS & SCRN_UNDERLINE)) {          if ((!(crtc.s.EXTPALMODE & 0x80)) || (crtc.s.SCRN_BITS & SCRN_UNDERLINE)) {
                 updatemask = 0x7ff;                  updatemask = 0x7ff;
                 if ((crtc.s.SCRN_BITS & SCRN_24KHZ) && (crtc.s.TXT_XL == 80)) {                  if ((crtc.s.SCRN_BITS & SCRN_24KHZ) && (!crtc.s.width40)) {
                         pal_bank = pal_disp = PAL_HIGHRESO;                          pal_bank = PAL_HIGHRESO;
                           pal_disp = PAL_HIGHRESO;
                 }                  }
                 if (crtc.s.SCRN_BITS & SCRN_TEXTYx2) {                  if (crtc.s.SCRN_BITS & SCRN_TEXTYx2) {
                         updatemask = 0x3ff;                          updatemask = 0x3ff;
                 }                  }
         }          }
         else {                                                                                                  // Analog mode          else {                                                                                          /* Analog mode */
                 updatemask = 0x3ff;                  updatemask = 0x3ff;
                 if (!(crtc.s.SCRN_BITS & SCRN_TEXTYx2)) {                  if (!(crtc.s.SCRN_BITS & SCRN_TEXTYx2)) {
                         if (crtc.s.SCRN_BITS & SCRN_24KHZ) {                          if (crtc.s.SCRN_BITS & SCRN_24KHZ) {
                                 if (crtc.s.TXT_XL == 40) {                                  if (crtc.s.width40) {
                                         if (crtc.s.SCRN_BITS & SCRN_200LINE) {  // width 40,25,0,2                                          if (crtc.s.SCRN_BITS & SCRN_200LINE) {
                                                 dispmode |= SCRN64_320x200;                                                                                                                  /* width 40,25,0,2 */
                                                   dispmode = scrnpage + SCRN64_320x200;
                                         }                                          }
                                         else {                                                                  // width 40,25,1,2                                          else {                                                          /* width 40,25,1,2 */
                                                 dispmode = SCRN64_H320x400;                                                  dispmode = SCRN64_H320x400;
                                         }                                          }
                                 }                                  }
                                 else {                                                                          // width 80,25,?,2                                  else {                                                                  /* width 80,25,?,2 */
                                         updatemask = 0x7ff;                                          updatemask = 0x7ff;
                                         pal_bank = pal_disp = PAL_HIGHRESO;                                          pal_bank = PAL_HIGHRESO;
                                           pal_disp = PAL_HIGHRESO;
                                 }                                  }
                         }                          }
                         else {                          else {
                                 if (crtc.s.TXT_XL == 40) {                                      // width 40,25,0,1                                  if (crtc.s.width40) {                                   /* width 40,25,0,1 */
                                         if (crtc.s.EXTPALMODE & 0x10) {                                          if (crtc.s.EXTPALMODE & 0x10) {
                                                 if (crtc.s.ZPRY & 0x10) {                                                  if (crtc.s.ZPRY & 0x10) {
                                                         dispmode = SCRN64_L320x200x2 |                                                          dispmode = SCRN64_L320x200x2 +
                                                                 ((crtc.s.ZPRY & 8) ? SCRN_BANK1 : SCRN_BANK0);                                                                          ((crtc.s.ZPRY & 8)?SCRN_BANK1:SCRN_BANK0);
                                                         pal_disp = PAL_4096 | PAL_64x2 |                                                          pal_disp = PAL_4096 + PAL_64x2 +
                                                                 ((crtc.s.ZPRY & 8) ? PAL_4096L : PAL_4096H);                                                                          ((crtc.s.ZPRY & 8)?PAL_4096L:PAL_4096H);
                                                 }                                                  }
                                                 else {                                                  else {
                                                         dispmode |= SCRN64_320x200;                                                          dispmode = scrnpage + SCRN64_320x200;
                                                         pal_disp = PAL_4096 |                                                          pal_disp = PAL_4096 +
                                                                         ((crtc.s.SCRN_BITS & SCRN_DISPVRAM)                                                                                  ((crtc.s.SCRN_BITS & SCRN_DISPVRAM)
                                                                                                         ? PAL_4096L : PAL_4096H);                                                                                                                  ?PAL_4096L:PAL_4096H);
                                                 }                                                  }
                                                 pal_bank = PAL_4096 |                                                  pal_bank = PAL_4096 +
                                                                         ((crtc.s.SCRN_BITS & SCRN_ACCESSVRAM)                                                                                  ((crtc.s.SCRN_BITS & SCRN_ACCESSVRAM)
                                                                                                         ? PAL_4096L : PAL_4096H);                                                                                                                  ?PAL_4096L:PAL_4096H);
                                         }                                          }
                                         else {                                          else {
                                                 dispmode = SCRN64_320x200x4096 | SCRN_DRAW4096;                                                  dispmode = SCRN_DRAW4096 + SCRN64_320x200x4096;
                                                 pal_bank = pal_disp = PAL_4096 | PAL_4096FULL;                                                  pal_bank = PAL_4096 + PAL_4096FULL;
                                                   pal_disp = PAL_4096 + PAL_4096FULL;
                                         }                                          }
                                 }                                  }
                                 else {                                                                          // width 80,25,0,1                                  else {                                                                  /* width 80,25,0,1 */
                                         updatemask = 0x7ff;                                          updatemask = 0x7ff;
                                         dispmode = SCRN64_L640x200;                                          dispmode = SCRN_WIDTH80 + SCRN64_L640x200;
                                 }                                  }
                         }                          }
                 }                  }
                 else {                  else {
                         if (crtc.s.SCRN_BITS & SCRN_24KHZ) {                          if (crtc.s.SCRN_BITS & SCRN_24KHZ) {
                                 if (crtc.s.TXT_XL == 40) {                                  if (crtc.s.width40) {
                                         if (crtc.s.SCRN_BITS & SCRN_200LINE) {  // width 40,12,0,2                                          if (crtc.s.SCRN_BITS & SCRN_200LINE) {
                                                 dispmode |= SCRN64_320x100;                                                                                                                  /* width 40,12,0,2 */
                                                   dispmode = scrnpage + SCRN64_320x100;
                                         }                                          }
                                         else {                                                                  // width 40,12,1,2                                          else {                                                          /* width 40,12,1,2 */
                                                 dispmode = SCRN64_H320x200;                                                  dispmode = SCRN64_H320x200;
                                         }                                          }
                                 }                                  }
                                 else {                                                                          // width 80,12,?,2                                  else {                                                                  /* width 80,12,?,2 */
                                         pal_bank = pal_disp = PAL_HIGHRESO;                                          pal_bank = PAL_HIGHRESO;
                                           pal_disp = PAL_HIGHRESO;
                                 }                                  }
                         }                          }
                         else {                          else {
                                 if (crtc.s.TXT_XL == 40) {                                      // width 40,12,0,1                                  if (crtc.s.width40) {                                   /* width 40,12,0,1 */
                                         if (crtc.s.EXTPALMODE & 0x10) {                                          if (crtc.s.EXTPALMODE & 0x10) {
                                                 if (crtc.s.ZPRY & 0x10) {                                                  if (crtc.s.ZPRY & 0x10) {
                                                         dispmode = SCRN64_320x100x2 |                                                          dispmode = SCRN64_320x100x2 +
                                                                 ((crtc.s.ZPRY & 8) ? SCRN_BANK1 : SCRN_BANK0);                                                                          ((crtc.s.ZPRY & 8)?SCRN_BANK1:SCRN_BANK0);
                                                         pal_disp = PAL_4096 | PAL_64x2 |                                                          pal_disp = PAL_4096 + PAL_64x2 +
                                                                 ((crtc.s.ZPRY & 8) ? PAL_4096L : PAL_4096H);                                                                          ((crtc.s.ZPRY & 8)?PAL_4096L:PAL_4096H);
                                                 }                                                  }
                                                 else {                                                  else {
                                                         dispmode |= SCRN64_320x100;                                                          dispmode = scrnpage + SCRN64_320x100;
                                                         pal_disp = PAL_4096 |                                                          pal_disp = PAL_4096 +
                                                                         ((crtc.s.SCRN_BITS & SCRN_DISPVRAM)                                                                                  ((crtc.s.SCRN_BITS & SCRN_DISPVRAM)
                                                                                                         ? PAL_4096L : PAL_4096H);                                                                                                                  ?PAL_4096L:PAL_4096H);
                                                 }                                                  }
                                                 pal_bank = PAL_4096 |                                                  pal_bank = PAL_4096 +
                                                                         ((crtc.s.SCRN_BITS & SCRN_ACCESSVRAM)                                                                                  ((crtc.s.SCRN_BITS & SCRN_ACCESSVRAM)
                                                                                                         ? PAL_4096L : PAL_4096H);                                                                                                                  ?PAL_4096L:PAL_4096H);
                                         }                                          }
                                         else {                                          else {
                                                 dispmode = SCRN64_320x100x4096 | SCRN_DRAW4096;                                                  dispmode = SCRN_DRAW4096 + SCRN64_320x100x4096;
                                                 pal_bank = pal_disp = PAL_4096 | PAL_4096FULL;                                                  pal_bank = PAL_4096 + PAL_4096FULL;
                                                   pal_disp = PAL_4096 + PAL_4096FULL;
                                         }                                          }
                                 }                                  }
                                 else {                                                                          // width 80,12,0,1                                  else {                                                                  /* width 80,12,0,1 */
                                         dispmode = SCRN64_L640x100;                                          dispmode = SCRN_WIDTH80 + SCRN64_L640x100;
                                 }                                  }
                         }                          }
                 }                  }
         }          }
         crtc.e.updatemask = updatemask;          crtc.e.updatemask = updatemask;
           crtc.e.dispmode = dispmode;
           crtc.e.pal_bank = pal_bank;
           crtc.e.pal_disp = pal_disp;
   #endif
 }  }
   
 void crtc_updt(void) {  static void crtc_clkupdate(void) {
   
         if (crtc.s.SCRN_BITS & SCRN_24KHZ) {          UINT            clksync;
                 crtc.s.fnty = (crtc.s.FNT_YL >> 1) & 0xfffe;  const GDCCLK    *clk;
         }          UINT            h;
         else {          UINT            fonty;
                 crtc.s.fnty = crtc.s.FNT_YL & 0xfffe;          UINT            v;
   
           clksync = (crtc.s.SCRN_BITS & SCRN_24KHZ);
           clk = gdcclk + clksync;
           h = crtc.s.reg[CRTCREG_HSIZE] + 1;
           if (crtc.s.width40) {
                   h = h * 2;
         }          }
         if (crtc.s.TXT_YL) {          if (h < clk->minx) {
                 crtc.s.CRT_YL = crtc.s.fnty * crtc.s.TXT_YL;                  h = clk->minx;
         }          }
         else {          else if (h > clk->maxx) {
                 crtc.s.CRT_YL = crtc.s.fnty * 1;                  h = clk->maxx;
         }          }
         crtc.s.CRT_VS = crtc.s.fnty * (crtc.s.TXT_YS + 1);          crtc.e.rasterclock8 = (4000000 * h) / (clk->clock >> 8);
         crtc.s.CRT_VL = (crtc.s.TXT_VL + 1) * crtc.s.fnty + crtc.s.TXT_VLA;  
 //      TRACEOUT(("set> %d / %d / %d", crtc.s.CRT_YL, crtc.s.CRT_VS, crtc.s.CRT_VL));  
 }  
   
           fonty = crtc.s.reg[CRTCREG_CHRCY] & 0x1f;
           fonty >>= clksync;
           fonty += 1;
           crtc.e.fonty = fonty;
   
 // ---- CRTC          v = (crtc.s.reg[CRTCREG_CHRCY] & 0x1f) + 1;
           v = v * ((crtc.s.reg[CRTCREG_VSIZE] & 0x7f) + 1);
           v = v + (crtc.s.reg[CRTCREG_VSIZEA] & 0x1f);
           if (v < clk->miny) {
                   v = clk->miny;
           }
           else if (v > clk->maxy) {
                   v = clk->maxy;
           }
           crtc.e.frameclock = ((4000000 * h) / clk->clock) * v;
   }
   
 void IOOUTCALL crtc_o(UINT port, REG8 value) {  static void crtc_timingupdate(void) {
   
         if (port == 0x1800) {          UINT32  fontclock;
                 crtc.s.CRTC_NUM = value;          UINT    yl;
         }          SINT32  vsyncstart;
         else if (port == 0x1801) {  
                 switch(crtc.s.CRTC_NUM) {  
                         case 0x01:  
                                 if (value <= 40) {  
                                         crtc.s.TXT_XL = 40;  
                                 }  
                                 else {  
                                         crtc.s.TXT_XL = 80;  
                                 }  
                                 vrambank_patch();  
                                 break;  
   
                         case 0x04:          /* とりあえず…ね */
                                 crtc.s.TXT_VL = value;          crtc.e.pos = crtc.s.reg[CRTCREG_POSL]
                                 break;                                                                          + ((crtc.s.reg[CRTCREG_POSH] & 7) << 8);
   
                         case 0x05:          crtc.e.rasterdisp8 = (crtc.e.rasterclock8 * 40) / 56;
                                 crtc.s.TXT_VLA = value;  
                                 break;  
   
                         case 0x06:          fontclock = (crtc.s.reg[CRTCREG_CHRCY] & 0x1f) + 1;
                                 crtc.s.TXT_YL = value;          fontclock = (fontclock * crtc.e.rasterclock8) >> 8;
                                 break;  
   
                         case 0x07:          /* YsIIIが yl==0で disp信号見る…なんで? */
                                 crtc.s.TXT_YS = value;          yl = (crtc.s.reg[CRTCREG_VDISP] & 0x7f);
                                 break;          crtc.e.yl = yl;
           iocore.e.dispclock = fontclock * max(yl, 1);
           vsyncstart = fontclock * ((crtc.s.reg[CRTCREG_VSYNC] & 0x7f) + 1);
           iocore.e.vsyncstart = vsyncstart;
   #if !defined(MAINFRAMES_OLD)
           iocore.e.vsyncend = vsyncstart + (((crtc.s.reg[CRTCREG_PULSE] >> 4)
                                                                                                   * crtc.e.rasterclock8) >> 8);
           neitem_mainframes(NEVENT_FRAMES);
   #else
           iocore.e.vpulseclock = ((crtc.s.reg[CRTCREG_PULSE] >> 4)
                                                                                                   * crtc.e.rasterclock8) >> 8;
   #endif
   }
   
                         case 0x09:  
                                 crtc.s.FNT_YL = (WORD)value+1;  
                                 break;  
   
                         case 0x0c:  /* CRTC */
                                 crtc.s.TXT_TOP &= 0xff;  
                                 crtc.s.TXT_TOP |= (value & 7) << 8;  
                                 makescrn.remakeattr = 1;  
                                 break;  
   
                         case 0x0d:  void IOOUTCALL crtc_o(UINT port, REG8 value) {
                                 crtc.s.TXT_TOP &= 0x7ff;  
                                 crtc.s.TXT_TOP |= value;  
                                 makescrn.remakeattr = 1;  
                                 break;  
   
                         default:          port &= 0xff;
                                 return;          if (port == 0) {
                   crtc.s.regnum = value;
           }
           else if (port == 1) {
                   if (crtc.s.regnum < CRTCREG_MAX) {
                           if (crtc.s.reg[crtc.s.regnum] != value) {
                                   crtc.s.reg[crtc.s.regnum] = value;
                                   crtc_clkupdate();
                                   crtc_timingupdate();
                                   crtc.e.remakeattr = 1;
                                   crtc.e.scrnallflash = 1;
                           }
                 }                  }
                 crtc.s.GRP_XL = crtc.s.TXT_XL << 3;  
                 crtc.s.GRP_YL = 200;  
                 crtc_updt();  
                 scrnallflash = 1;                                                               /* 990220 puni */  
         }          }
 }  }
   
   
 // ---- スクリーンモード  /* スクリーンモード */
   
 void IOOUTCALL scrn_o(UINT port, REG8 value) {  void IOOUTCALL scrn_o(UINT port, REG8 value) {
   
Line 274  void IOOUTCALL scrn_o(UINT port, REG8 va Line 296  void IOOUTCALL scrn_o(UINT port, REG8 va
   
         modify = crtc.s.SCRN_BITS ^ value;          modify = crtc.s.SCRN_BITS ^ value;
         crtc.s.SCRN_BITS = value;          crtc.s.SCRN_BITS = value;
           if (modify & SCRN_ACCESSVRAM) {
                   crtc_bankupdate();
           }
         if (modify & SCRN_DISPCHANGE) {          if (modify & SCRN_DISPCHANGE) {
                 reflesh_palette();                  crtc.e.scrnallflash = 1;
                 scrnallflash = 1;                  crtc_dispupdate();
                 makescrn.palandply = 1;                  crtc_clkupdate();
                 crtc_updt();                  crtc_timingupdate();
         }                  crtc.e.palandply = 1;
         vrambank_patch();          }
         crtc.s.CPU_BANK = (BYTE)((crtc.s.SCRN_BITS & SCRN_ACCESSVRAM)?1:0);  
         crtc.s.CRT_BANK = (BYTE)((crtc.s.SCRN_BITS & SCRN_DISPVRAM)?1:0);  
         (void)port;          (void)port;
 }  }
   
Line 293  REG8 IOINPCALL scrn_i(UINT port) { Line 316  REG8 IOINPCALL scrn_i(UINT port) {
 }  }
   
   
 // ---- プライオリティ  /* プライオリティ */
   
 void IOOUTCALL ply_o(UINT port, REG8 value) {  void IOOUTCALL ply_o(UINT port, REG8 value) {
   
         if (crtc.s.PLY != value) {          if (crtc.s.rgbp[CRTC_PLY] != value) {
                 crtc.s.PLY = value;                  crtc.s.rgbp[CRTC_PLY] = value;
                 makescrn.palandply = 1;                  crtc.e.palandply = 1;
   #if defined(SUPPORT_PALEVENT)
                   if ((!corestat.vsync) && (palevent.events < SUPPORT_PALEVENT)) {
                           PAL1EVENT *e = palevent.event + palevent.events;
                           palevent.events++;
                           e->rgbp = CRTC_PLY;
                           e->value = value;
                           e->clock = nevent_getwork(NEVENT_FRAMES);
                   }
   #endif
         }          }
         (void)port;          (void)port;
 }  }
   
 REG8 IOINPCALL ply_i(UINT port) {  
   
         (void)port;  
         return(crtc.s.PLY);  
 }  
   
   /* パレット */
 // ---- パレット  
   
 void IOOUTCALL palette_o(UINT port, REG8 value) {  void IOOUTCALL palette_o(UINT port, REG8 value) {
   
           UINT    num;
   #if defined(SUPPORT_TURBOZ)
           REG8    sft;
         UINT    pal;          UINT    pal;
         BYTE    c;  #endif
   
   #if defined(SUPPORT_TURBOZ)
         crtc.s.lastpal = (value & 0xf0);          crtc.s.lastpal = (value & 0xf0);
         if (crtc.s.EXTPALMODE & 0x80) {          if (!(crtc.s.EXTPALMODE & 0x80)) {
   #endif
                   num = (port >> 8) & 3;
                   if (crtc.s.rgbp[num] != value) {
                           crtc.s.rgbp[num] = value;
                           crtc.e.palandply = 1;
   #if defined(SUPPORT_PALEVENT)
                           if ((!corestat.vsync) && (palevent.events < SUPPORT_PALEVENT)) {
                                   PAL1EVENT *e = palevent.event + palevent.events;
                                   palevent.events++;
                                   e->rgbp = (UINT8)num;
                                   e->value = value;
                                   e->clock = nevent_getwork(NEVENT_FRAMES);
                           }
   #endif
                   }
   #if defined(SUPPORT_TURBOZ)
           }
           else {
                 if ((crtc.s.EXTGRPHPAL & 0x88) != 0x80) {                  if ((crtc.s.EXTGRPHPAL & 0x88) != 0x80) {
                         return;                          return;
                 }                  }
                 if (pal_bank & PAL_4096) {                                      // use 4096palettes                  sft = (port >> (8 - 2)) & (3 << 2);
                         switch(pal_bank & (PAL_4096FULL | PAL_4096BANK)) {                  if (crtc.e.pal_bank & PAL_4096) {                               /* use 4096palettes */
                                 case 0:                          num = ((port & 0xff) << 4) + (crtc.s.lastpal >> 4);
                                         pal = ((port & 0xcc) << 4) + ((value & 0xc0) >> 4);                          if (!(crtc.e.pal_bank & PAL_4096FULL)) {
                                         break;                                  num &= 0xccc;
                                   if (crtc.e.pal_bank & PAL_4096BANK) {
                                 case 1:                                          num >>= 2;
                                         pal = ((port & 0xcc) << 2) + ((value & 0xc0) >> 6);                                  }
                                         break;  
   
                                 default:  
                                         pal = ((port & 0xff) << 4) + (crtc.s.lastpal >> 4);  
                                         break;  
                         }  
                         value &= 0xf;  
                         switch(port & 0xff00) {  
                                 case 0x1000:  
                                         crtc_PAL4096[pal] &= 0xff0;  
                                         crtc_PAL4096[pal] |= value;  
                                         break;  
   
                                 case 0x1100:  
                                         crtc_PAL4096[pal] &= 0xf0f;  
                                         crtc_PAL4096[pal] |= (value << 4);  
                                         break;  
   
                                 case 0x1200:  
                                         crtc_PAL4096[pal] &= 0x0ff;  
                                         crtc_PAL4096[pal] |= ((WORD)value << 8);  
                                         break;  
                         }                          }
                         pal_setgrph4096(pal);                          pal = crtc.p.grph4096[num];
                           pal &= ~((0x0f) << sft);
                           pal |= (value & 0x0f) << sft;
                           crtc.p.grph4096[num] = pal;
                           pal_setgrph4096(num);
                 }                  }
                 else {                  else {
                         c = ((port & 0x80) >> 5) | ((port & 0x08) >> 2) |                          num = ((port & 0x80) >> 5) | ((port & 0x08) >> 2) |
                                                                                                 ((value & 0x80) >> 7);                                                                                                  ((value & 0x80) >> 7);
                         if ((dispmode & SCRN64_MASK) == SCRN64_INVALID) {                          if (crtc.e.dispmode & SCRN64_ENABLE) {
                                 c |= (c << 3);                                  num += ((port & 0x40) >> 1) | ((port & 0x04) << 2) |
                         }  
                         else {  
                                 c += ((port & 0x40) >> 1) | ((port & 0x04) << 2) |  
                                                                                                         ((value & 0x40) >> 3);                                                                                                          ((value & 0x40) >> 3);
                         }                          }
                         value &= 0xf;                          else {
                         switch(port & 0xff00) {                                  num |= (num << 3);
                                 case 0x1000:  
                                         crtc_GRPHPAL[pal_bank][c] &= 0xff0;  
                                         crtc_GRPHPAL[pal_bank][c] |= value;  
                                         break;  
   
                                 case 0x1100:  
                                         crtc_GRPHPAL[pal_bank][c] &= 0xf0f;  
                                         crtc_GRPHPAL[pal_bank][c] |= (value << 4);  
                                         break;  
   
                                 case 0x1200:  
                                         crtc_GRPHPAL[pal_bank][c] &= 0x0ff;  
                                         crtc_GRPHPAL[pal_bank][c] |= ((WORD)value << 8);  
                                         break;  
                         }                          }
                         pal_setgrph(pal_bank, c);                          pal = crtc.p.grph[crtc.e.pal_bank][num];
                           pal &= ~((0x0f) << sft);
                           pal |= (value & 0x0f) << sft;
                           crtc.p.grph[crtc.e.pal_bank][num] = pal;
                           pal_setgrph(crtc.e.pal_bank, (REG8)num);
                 }                  }
         }          }
         else {  #endif
                 switch(port & 0xff00) {  }
                         case 0x1000:  
                                 if (crtc.s.PAL_B != value) {  
                                         crtc.s.PAL_B = value;  
                                         makescrn.palandply = 1;  
                                 }  
                                 break;  
   
                         case 0x1100:  void IOOUTCALL blackctrl_o(UINT port, REG8 value) {
                                 if (crtc.s.PAL_R != value) {  
                                         crtc.s.PAL_R = value;  
                                         makescrn.palandply = 1;  
                                 }  
                                 break;  
   
                         case 0x1200:          if (crtc.s.rgbp[CRTC_BLACK] != value) {
                                 if (crtc.s.PAL_G != value) {                  crtc.s.rgbp[CRTC_BLACK] = value;
                                         crtc.s.PAL_G = value;                  crtc.e.palandply = 1;
                                         makescrn.palandply = 1;  #if defined(SUPPORT_PALEVENT)
                                 }                  if ((!corestat.vsync) && (palevent.events < SUPPORT_PALEVENT)) {
                                 break;                          PAL1EVENT *e = palevent.event + palevent.events;
                           palevent.events++;
                           e->rgbp = CRTC_BLACK;
                           e->value = value;
                           e->clock = nevent_getwork(NEVENT_FRAMES);
                 }                  }
   #endif
         }          }
           (void)port;
 }  }
   
 REG8 IOINPCALL palette_i(UINT port) {  REG8 IOINPCALL blackctrl_i(UINT port) {
   
           (void)port;
           return(crtc.s.rgbp[CRTC_BLACK]);
   }
   
         UINT    c;  
   
         if ((crtc.s.EXTPALMODE & 0x80) && ((crtc.s.EXTGRPHPAL & 0x88) == 0x88)) {  /* turboZ */
                 if (pal_bank & PAL_4096) {                                      // use 4096palettes  
                         switch(pal_bank & (PAL_4096FULL | PAL_4096BANK)) {  #if defined(SUPPORT_TURBOZ)
                                 case 0:  REG8 IOINPCALL ply_i(UINT port) {
                                         c = ((port & 0xcc) << 4) | ((crtc.s.lastpal & 0xc0) >> 4);  
                                         break;  
   
                                 case 1:  
                                         c = ((port & 0xcc) << 2) | ((crtc.s.lastpal & 0xc0) >> 6);  
                                         break;  
   
                                 default:  
                                         c = ((port & 0xff) << 4) | (crtc.s.lastpal >> 4);  
                                         break;  
                         }  
                         switch(port & 0xff00) {  
                                 case 0x1000:  
                                         return(crtc.s.lastpal | (crtc_PAL4096[c] & 0xf));  
   
                                 case 0x1100:          (void)port;
                                         return(crtc.s.lastpal | ((crtc_PAL4096[c] & 0xf0) >> 4));          return(crtc.s.rgbp[CRTC_PLY]);
   }
   
                                 case 0x1200:  REG8 IOINPCALL palette_i(UINT port) {
                                         return(crtc.s.lastpal | ((crtc_PAL4096[c] & 0xf00) >> 8));  
           UINT    num;
           UINT    pal;
           REG8    sft;
   
           if ((crtc.s.EXTPALMODE & 0x80) && ((crtc.s.EXTGRPHPAL & 0x88) == 0x88)) {
                   if (crtc.e.pal_bank & PAL_4096) {                               /* use 4096palettes */
                           num = ((port & 0xff) << 4) + (crtc.s.lastpal >> 4);
                           if (!(crtc.e.pal_bank & PAL_4096FULL)) {
                                   num &= 0xccc;
                                   if (crtc.e.pal_bank & PAL_4096BANK) {
                                           num >>= 2;
                                   }
                         }                          }
                           pal = crtc.p.grph4096[num];
                 }                  }
                 else {                  else {
                         c = ((port & 0x80) >> 5) | ((port & 0x08) >> 2) |                          num = ((port & 0x80) >> 5) | ((port & 0x08) >> 2) |
                                                                                         ((crtc.s.lastpal & 0x80) >> 7);                                                                                          ((crtc.s.lastpal & 0x80) >> 7);
                         if ((dispmode & SCRN64_MASK) == SCRN64_INVALID) {                          if (crtc.e.dispmode & SCRN64_ENABLE) {
                                 c |= (c << 3);                                  num += ((port & 0x40) >> 1) | ((port & 0x04) << 2) |
                         }  
                         else {  
                                 c += ((port & 0x40) >> 1) | ((port & 0x04) << 2) |  
                                                                                         ((crtc.s.lastpal & 0x40) >> 3);                                                                                          ((crtc.s.lastpal & 0x40) >> 3);
                         }                          }
                         switch(port & 0xff00) {                          else {
                                 case 0x1000:                                  num |= (num << 3);
                                         return(crtc.s.lastpal |  
                                                                 (crtc_GRPHPAL[pal_bank][c] & 0xf));  
                                 case 0x1100:  
                                         return(crtc.s.lastpal |  
                                                                 ((crtc_GRPHPAL[pal_bank][c] & 0xf0) >> 4));  
                                 case 0x1200:  
                                         return(crtc.s.lastpal |  
                                                                 ((crtc_GRPHPAL[pal_bank][c] & 0xf00) >> 8));  
                         }                          }
                           pal = crtc.p.grph[crtc.e.pal_bank][num];
                 }                  }
                   sft = (port >> (8 - 2)) & (3 << 2);
                   return((REG8)(crtc.s.lastpal + ((pal >> sft) & 0xf)));
           }
           else {
                   return(0xff);
         }          }
         return(0xff);  
 }  }
   
   
 // ---- turboZ  
   
 void IOOUTCALL extpal_o(UINT port, REG8 value) {  void IOOUTCALL extpal_o(UINT port, REG8 value) {
   
         crtc.s.EXTPALMODE = value;          crtc.s.EXTPALMODE = value;
         vrambank_patch();          crtc_dispupdate();
           (void)port;
 }  }
   
 REG8 IOINPCALL extpal_i(UINT port) {  REG8 IOINPCALL extpal_i(UINT port) {
   
           (void)port;
         return(crtc.s.EXTPALMODE);          return(crtc.s.EXTPALMODE);
 }  }
   
Line 487  void IOOUTCALL extgrphpal_o(UINT port, R Line 496  void IOOUTCALL extgrphpal_o(UINT port, R
         if (crtc.s.EXTPALMODE & 0x80) {          if (crtc.s.EXTPALMODE & 0x80) {
                 crtc.s.EXTGRPHPAL = value;                  crtc.s.EXTGRPHPAL = value;
         }          }
           (void)port;
 }  }
   
 REG8 IOINPCALL extgrphpal_i(UINT port) {  REG8 IOINPCALL extgrphpal_i(UINT port) {
Line 494  REG8 IOINPCALL extgrphpal_i(UINT port) { Line 504  REG8 IOINPCALL extgrphpal_i(UINT port) {
         if (crtc.s.EXTPALMODE & 0x80) {          if (crtc.s.EXTPALMODE & 0x80) {
                 return(crtc.s.EXTGRPHPAL);                  return(crtc.s.EXTGRPHPAL);
         }          }
           (void)port;
         return(0xff);          return(0xff);
 }  }
   
 void IOOUTCALL exttextpal_o(UINT port, REG8 value) {  void IOOUTCALL exttextpal_o(UINT port, REG8 value) {
   
         if (crtc.s.EXTPALMODE & 0x80) {          if (crtc.s.EXTPALMODE & 0x80) {
                 crtc_TEXTPAL[port & 7] = value;                  crtc.p.text[port & 7] = value;
                 pal_settext((REG8)(port & 7));                  pal_settext((REG8)(port & 7));
         }          }
 }  }
Line 508  void IOOUTCALL exttextpal_o(UINT port, R Line 519  void IOOUTCALL exttextpal_o(UINT port, R
 REG8 IOINPCALL exttextpal_i(UINT port) {  REG8 IOINPCALL exttextpal_i(UINT port) {
   
         if (crtc.s.EXTPALMODE & 0x80) {          if (crtc.s.EXTPALMODE & 0x80) {
                 return(crtc_TEXTPAL[port & 7]);                  return(crtc.p.text[port & 7]);
         }          }
         return(0xff);          return(0xff);
 }  }
Line 516  REG8 IOINPCALL exttextpal_i(UINT port) { Line 527  REG8 IOINPCALL exttextpal_i(UINT port) {
 void IOOUTCALL exttextdisp_o(UINT port, REG8 value) {  void IOOUTCALL exttextdisp_o(UINT port, REG8 value) {
   
         crtc.s.ZPRY = value;          crtc.s.ZPRY = value;
         vrambank_patch();          crtc_dispupdate();
           (void)port;
 }  }
   
 REG8 IOINPCALL exttextdisp_i(UINT port) {  REG8 IOINPCALL exttextdisp_i(UINT port) {
Line 524  REG8 IOINPCALL exttextdisp_i(UINT port)  Line 536  REG8 IOINPCALL exttextdisp_i(UINT port) 
         if (crtc.s.EXTPALMODE & 0x80) {          if (crtc.s.EXTPALMODE & 0x80) {
                 return(crtc.s.ZPRY);                  return(crtc.s.ZPRY);
         }          }
           (void)port;
         return(0xff);          return(0xff);
 }  }
   #endif
   
 void IOOUTCALL blackctrl_o(UINT port, REG8 value) {  
   
         crtc.s.BLACKPAL = value;  /* extension */
         makescrn.palandply = 1;  
   void crtc_update(void) {
   
           crtc_bankupdate();
           crtc_dispupdate();
           crtc_clkupdate();
           crtc_timingupdate();
           crtc.e.palandply = 1;
           crtc.e.scrnallflash = 1;
 }  }
   
 REG8 IOINPCALL blackctrl_i(UINT port) {  void crtc_setwidth(REG8 width40) {
   
         return(crtc.s.BLACKPAL);          crtc.s.width40 = width40;
           crtc_update();
 }  }
   
   
 // ----  /* init/reset */
   
   #if defined(SUPPORT_TURBOZ)
 static void resetpal(void) {  static void resetpal(void) {
   
         CopyMemory(crtc_TEXTPAL, def_TEXTPAL, 8);          CopyMemory(crtc.p.text, defpaltext, sizeof(defpaltext));
         CopyMemory(crtc_GRPHPAL[0], def_GRPHPAL, 64*2);          CopyMemory(crtc.p.grph[0], defpalgrph, sizeof(defpalgrph));
         CopyMemory(crtc_GRPHPAL[1], def_GRPHPAL, 64*2);          CopyMemory(crtc.p.grph[1], defpalgrph, sizeof(defpalgrph));
 }  }
   #endif
   
   #if defined(SUPPORT_TURBOZ)
 void crtc_initialize(void) {  void crtc_initialize(void) {
   
         UINT    p;          UINT    p;
   
         resetpal();          resetpal();
         for (p=0; p<4096; p++) {          for (p=0; p<4096; p++) {
                 crtc_PAL4096[p] = p;                  crtc.p.grph4096[p] = p;
         }          }
 }  }
   #endif
   
 void crtc_reset(void) {  void crtc_reset(void) {
   
         crtc.s = crtcdefault;          ZeroMemory(&crtc, sizeof(crtc));
           CopyMemory(crtc.s.rgbp, defrgbp, 4);
         dispmode = SCRN64_INVALID;          CopyMemory(crtc.s.reg, defreg, 18);
         pal_bank = pal_disp = PAL_NORMAL;          crtc.s.width40 = 1;
   #if defined(SUPPORT_TURBOZ)
         if (pccore.ROM_TYPE < 3) {          if (pccore.ROM_TYPE < 3) {
                 resetpal();                  resetpal();
         }          }
   #endif
   #if 0
           /* IPLが勝手に切り替える筈である */
         if ((pccore.ROM_TYPE >= 2) && (!(pccore.DIP_SW & 1))) {          if ((pccore.ROM_TYPE >= 2) && (!(pccore.DIP_SW & 1))) {
                 crtc.s.SCRN_BITS = SCRN_200LINE;                  crtc.s.SCRN_BITS = SCRN_200LINE;
                 crtc.s.FNT_YL = 16;                  crtc.s.reg[CRTCREG_CHRCY] = 15;
         }          }
   #endif  /* 0 */
   
           pal_reset();
           crtc.e.palandply = 1;
           crtc_update();
   }
   
         reflesh_palette();  void crtc_forcesetwidth(REG8 width) {
         crtc_updt();  
   
         vrambank_patch();          crtc.s.reg[CRTCREG_HDISP] = (UINT8)width;
         makescrn.palandply = 1;          crtc_dispupdate();
         scrnallflash = 1;          crtc.e.scrnallflash = 1;
 }  }
   

Removed from v.1.3  
changed lines
  Added in v.1.20


RetroPC.NET-CVS <cvs@retropc.net>