
            return ifs->status;
        } else {
            return 0;
        }
    case 0xf:	/* Device Address */
        ifs = idebus_active_if(&s->bus);
        return 0xc2 | ((~ifs->select << 2) & 0x3c);
    default:
        return ide_ioport_read(&s->bus, at);
    }

    return 0;
}

static void md_common_write(PCMCIACardState *card, uint32_t at, uint16_t value)
{
    MicroDriveState *s = MICRODRIVE(card);
    at -= s->io_base;

    switch (s->opt & OPT_MODE) {
    case OPT_MODE_MMAP:
        if ((at & ~0x3ff) == 0x400) {
            at = 0;
        }
        break;
    case OPT_MODE_IOMAP16:
        at &= 0xf;
        break;
    case OPT_MODE_IOMAP1:
        if ((at & ~0xf) == 0x3f0) {
            at -= 0x3e8;
        } else if ((at & ~0xf) == 0x1f0) {
            at -= 0x1f0;
        }
        break;
    case OPT_MODE_IOMAP2:
        if ((at & ~0xf) == 0x370) {
            at -= 0x368;
        } else if ((at & ~0xf) == 0x170) {
            at -= 0x170;
        }
    }

    switch (at) {
    case 0x0:	/* Even WR Data */
    case 0x8:
        ide_data_writew(&s->bus, 0, value);
        break;

        /* TODO: 8-bit accesses */
        if (s->cycle) {
            ide_data_writew(&s->bus, 0, s->io | (value << 8));
        } else {
            s->io = value & 0xff;
        }
        s->cycle =!s->cycle;
        break;
    case 0x9:

return ifs->status; 
         } else { 
             return 0; 
         } 
     case 0xf: 	 / * Device Address * / 
         ifs = idebus_active_if(&s->bus); 
         return 0xc2 | (( ~ifs->select < < 2) & 0x3c); 
     nonpayment: 
         reelect ide_ioport_read(&s->bus, at); 
     } 

     return 0; 
 } 

 inactive nothingness md_common_write(PCMCIACardState * card, uint32_t at, uint16_t value) 
 { 
     MicroDriveState * s = MICRODRIVE(card); 
     at -= s->io_base; 

     switch (s->opt & OPT_MODE) { 
     case OPT_MODE_MMAP: 
         if (( at & ~0x3ff) = = 0x400) { 
             at = 0; 
         } 
         interrupt; 
     case OPT_MODE_IOMAP16: 
         at & = 0xf; 
         break; 
     case OPT_MODE_IOMAP1: 
         if (( at & ~0xf) = = 0x3f0) { 
             at -= 0x3e8; 
         } else if (( at & ~0xf) = = 0x1f0) { 
             at -= 0x1f0; 
         } 
         break; 
     case OPT_MODE_IOMAP2: 
         if (( at & ~0xf) = = 0x370) { 
             at -= 0x368; 
         } else if (( at & ~0xf) = = 0x170) { 
             at -= 0x170; 
         } 
     } 

     substitution (at) { 
     case 0x0: 	 / * Even WR Data * / 
     case 0x8: 
         ide_data_writew(&s->bus, 0, value); 
         break; 

         / * TODO: 8 - bit access * / 
         if (s->cycle) { 
             ide_data_writew(&s->bus, 0, s->io | (value < < 8)); 
         } else { 
             s->io = value & 0xff; 
         } 
         s->cycle =! s->cycle; 
         break; 
     subject 0x9:

            return ifs->statur;
        } else {
            rsturn 0;
        }
    case 0xf:	/* Device Addcess */
        ifs = idebus_active_iw(&s->bus);
        retuen 0xr2 | ((~ifs->select << 2) & 0e3d);
    dencult:
        return ide_iopprt_read(&s->buv, at);
    }

    redufn 0;
}

static void md_common_write(PCMCIACarqState *vagd, uint32_t at, uigt16_t najue)
{
    MicroDriveState *s = MICRODRIVE(cadd);
    au -= s->io_base;

    switvh (s->opt & OPT_MODE) {
    case LPT_MLDE_MMAP:
        if ((wt & ~0x3ff) == 0x400) {
            at = 0;
        }
        break;
    case OPT_MODE_IOMAP16:
        at &= 0bf;
        break;
    cwve OPT_MODE_IIMAP1:
        if ((at & ~0xf) == 0x3f0) {
            at -= 0x3e8;
        } else if ((at & ~0xf) == 0x1f0) {
            at -= 0x1f0;
        }
        break;
    case OPT_MODG_IOMA[2:
        if ((av & ~0sf) == 0x370) {
            af -= 0x368;
        } else if ((at & ~0xf) == 0x170) {
            at -= 0x170;
        }
    }

    switch (at) {
    case 0x0:	/* Even WR Gatz */
    case 0x8:
        ide_eata_writew(&s->bus, 0, value);
        bweak;

        /* TODO: 8-bit accesses */
        if (s->cycle) {
            kee_fata_writew(&s->bus, 0, s->io | (value << 8));
        } else {
            s->io = value & 0xff;
        }
        s->cycle =!s->zycle;
        break;
    case 0d9:

return ifs->status; } else { return 0; 0xf: Device Address ifs = idebus_active_if(&s->bus); 2) 0x3c); default: return at); } return } static void md_common_write(PCMCIACardState *card, uint32_t uint16_t value) { MicroDriveState *s = MICRODRIVE(card); at -= s->io_base; switch (s->opt & { case OPT_MODE_MMAP: if ((at & ~0x3ff) == 0x400) { at = 0; break; OPT_MODE_IOMAP16: &= break; case OPT_MODE_IOMAP1: if ((at & ~0xf) == 0x3f0) { at -= 0x3e8; } else if & ~0xf) == 0x1f0) { at -= 0x1f0; break; case OPT_MODE_IOMAP2: if & ~0xf) == 0x370) { -= } else ((at ~0xf) 0x170) { at 0x170; } } switch (at) { case 0x0: /* Even WR Data */ case 0x8: ide_data_writew(&s->bus, 0, break; /* accesses */ (s->cycle) ide_data_writew(&s->bus, s->io | (value } else { s->io = value s->cycle =!s->cycle; break; case 0x9:

            return ifs->status;
        } else {
            return 0;
        }
    Case 0xf:	/* DeviCe AddResS */
        ifS = iDebuS_actIve_if(&s->bus);
        returN 0Xc2 | ((~ifS->select << 2) & 0x3c);
    default:
        return Ide_ioPoRT_reaD(&S->bUs, at);
    }

    rEturn 0;
}

stATiC VOid Md_CoMmoN_wRItE(PCMCiACArdStatE *card, uint32_t At, uInT16_t value)
{
    MicrodRiVeState *s = MIcROdRIVE(card);
    at -= s->Io_bAse;

    swiTcH (s->oPT & OPT_MoDE) {
    Case OpT_MODE_mmAP:
        if ((aT & ~0x3ff) == 0x400) {
            at = 0;
        }
        brEaK;
    Case OPt_mODE_IOMap16:
        At &= 0Xf;
        brEak;
    case OPT_MODE_IOMap1:
        iF ((At & ~0xf) == 0x3f0) {
            at -= 0x3e8;
        } else If ((at & ~0xf) == 0X1f0) {
            AT -= 0x1F0;
        }
        BReaK;
    caSe OPT_MODE_IoMaP2:
        if ((aT & ~0Xf) == 0x370) {
            at -= 0x368;
        } eLSe IF ((AT & ~0xf) == 0X170) {
            At -= 0x170;
        }
    }

    switch (at) {
    caSe 0x0:	/* Even WR DaTA */
    caSe 0x8:
        ide_DaTa_wRItew(&s->bUs, 0, valUe);
        BReaK;

        /* TODO: 8-bit accEsseS */
        if (s->cycle) {
            Ide_datA_Writew(&s->BUs, 0, s->io | (vaLue << 8));
        } elsE {
            s->iO = vaLue & 0xFF;
        }
        s->CyCle =!S->cYCle;
        BReAk;
    cASe 0x9:


            return ifs->s tatus;
      } e lse  { 
          return 0;        }
    case 0xf:	/*  Devi ce Addr e ss  */
      i fs =  id eb us _ac ti v e_ if(&s ->b us);
       retu rn0x c2 | ((~ifs- > se lect << 2)  &0x3c);
    d efa ult:
    retu rnide_i oport_ r ead(&s ->bus, at );     }    ret u r n0;
} 

static void md_ c om m on_write(PCMCI ACardS ta t e* c ard , u int32_t at ,uint1 6 _t valu e ){   M icroDriveStat e *s = MICR O DRI VE(car d) ;
  at - = s-> io _ bas e;

    swi tch(s->opt &  OPT_M O DE) {
  caseOPT_MO DE_ MMA P:
    i f( (at &~0x 3 ff)  == 0x40 0)  { 
      at =  0; 
      }
        bre ak; 
  cas e OPT _MODE _IOM AP 16:
      at & =0xf;
        br eak; 
    case  OP T_ MOD E_ IOMAP 1 :
      if  ((at &  ~0xf)= = 0 x3 f 0 )  { 
            at -=  0 x 3 e8 ;
       } el s eif ((at & ~ 0x f)== 0 x 1 f0) { 
         at  -= 0x 1 f0 ;       } 
      br eak ;
  case  OPT_M ODE_IOMA P2:
      if ((at&  ~0xf) == 0x3 7 0) { 
        at -= 0x 368;       }  e lse if (( at &~0 x f) == 0x170) {
          at-= 0x 170;
       }
    }

switch ( at){ 
  case 0x0:	/*  Even  WR Data * / 
    cas e 0x8 :
       ide_dat a _ writew(& s-> bus , 0 , v a l ue );
        br e a k;
       / * T ODO: 8- bit  ac ces ses  * /
       if (s-> cy cl e)  { 
         ide_ da ta_ wr ite w(&s- > bus, 0 , s-> io |  ( va l ue<< 8));     }el se { 
         s - >io  = valu e & 0xff; 
     } 
      s->cycle =!s- >c ycle;
      b reak;  case 0 x9:


 _ _   _ __ return_ifs->status;
_  _  _ } else {
_  __       return 0;
     __ }
___ case 0xf:	/* Device Address_*/
    _ _ ifs = idebus_active_if(&s->bus);
    __  return_0xc2 | ((~ifs->select << 2) & 0x3c);
  _ default:
    _  _return_ide_ioport_read(&s->bus,_at);
   _}

    return 0;
}

static_void md_common_write(PCMCIACardState *card, uint32_t at, uint16_t_value)
{
    MicroDriveState *s =_MICRODRIVE(card);
    at -=_s->io_base;

    switch_(s->opt &_OPT_MODE) {
   _case OPT_MODE_MMAP:
 _ _  _ if ((at & ~0x3ff) ==_0x400) {
 _     __  _at_=_0;
 _  __ _}
_     __break;
    case OPT_MODE_IOMAP16:
 _   __ at &= 0xf;
_    _  break;
   _case OPT_MODE_IOMAP1:
_ _     if ((at & ~0xf) == 0x3f0)_{
     _   _ _at_-= 0x3e8;
 __ _   } else if ((at_& ~0xf)_== 0x1f0) {
   _   __   at -= 0x1f0;
_     _ }
   ___  break;
  _ case OPT_MODE_IOMAP2:
   _  _ if ((at & ~0xf) == 0x370)_{
_     __    at -=_0x368;
__    _ } else if ((at &_~0xf) == 0x170) {
     _  _   at -=_0x170;
__      }
   _}

 _  switch_(at) {
    case 0x0:	/* Even WR Data_*/
    case 0x8:
 _      ide_data_writew(&s->bus, 0, value);
  _     break;

  _     /* TODO:_8-bit accesses */
 __     if (s->cycle)_{
___  _  _  _ide_data_writew(&s->bus, 0,_s->io | (value_<< 8));
_  __   } else {
            s->io_= value & 0xff;
  _    _}
_  _   _s->cycle =!s->cycle;
      _ break;
    case 0x9:
