static void sh_serial_ioport_write(void *opaque, uint32_t offs, uint32_t val)

{

    sh_serial_state *s = opaque;

    unsigned char ch;



#ifdef DEBUG_SERIAL

    printf("sh_serial: write offs=0x%02x val=0x%02x\n",

	   offs, val);

#endif

    switch(offs) {

    case 0x00: /* SMR */

        s->smr = val & ((s->feat & SH_SERIAL_FEAT_SCIF) ? 0x7b : 0xff);

        return;

    case 0x04: /* BRR */

        s->brr = val;

	return;

    case 0x08: /* SCR */

        /* TODO : For SH7751, SCIF mask should be 0xfb. */

        s->scr = val & ((s->feat & SH_SERIAL_FEAT_SCIF) ? 0xfa : 0xff);

        if (!(val & (1 << 5)))

            s->flags |= SH_SERIAL_FLAG_TEND;

        if ((s->feat & SH_SERIAL_FEAT_SCIF) && s->txi) {

	    qemu_set_irq(s->txi, val & (1 << 7));

        }

        if (!(val & (1 << 6))) {

	    qemu_set_irq(s->rxi, 0);

        }

        return;

    case 0x0c: /* FTDR / TDR */

        if (s->chr) {

            ch = val;

            qemu_chr_write(s->chr, &ch, 1);

	}

	s->dr = val;

	s->flags &= ~SH_SERIAL_FLAG_TDE;

        return;

#if 0

    case 0x14: /* FRDR / RDR */

        ret = 0;

        break;

#endif

    }

    if (s->feat & SH_SERIAL_FEAT_SCIF) {

        switch(offs) {

        case 0x10: /* FSR */

            if (!(val & (1 << 6)))

                s->flags &= ~SH_SERIAL_FLAG_TEND;

            if (!(val & (1 << 5)))

                s->flags &= ~SH_SERIAL_FLAG_TDE;

            if (!(val & (1 << 4)))

                s->flags &= ~SH_SERIAL_FLAG_BRK;

            if (!(val & (1 << 1)))

                s->flags &= ~SH_SERIAL_FLAG_RDF;

            if (!(val & (1 << 0)))

                s->flags &= ~SH_SERIAL_FLAG_DR;



            if (!(val & (1 << 1)) || !(val & (1 << 0))) {

                if (s->rxi) {

                    qemu_set_irq(s->rxi, 0);

                }

            }

            return;

        case 0x18: /* FCR */

            s->fcr = val;

            switch ((val >> 6) & 3) {

            case 0:

                s->rtrg = 1;

                break;

            case 1:

                s->rtrg = 4;

                break;

            case 2:

                s->rtrg = 8;

                break;

            case 3:

                s->rtrg = 14;

                break;

            }

            if (val & (1 << 1)) {

                sh_serial_clear_fifo(s);

                s->sr &= ~(1 << 1);

            }



            return;

        case 0x20: /* SPTR */

            s->sptr = val & 0xf3;

            return;

        case 0x24: /* LSR */

            return;

        }

    }

    else {

#if 0

        switch(offs) {

        case 0x0c:

            ret = s->dr;

            break;

        case 0x10:

            ret = 0;

            break;

        case 0x1c:

            ret = s->sptr;

            break;

        }

#endif

    }



    fprintf(stderr, "sh_serial: unsupported write to 0x%02x\n", offs);

    assert(0);

}

static void sh_serial_ioport_write(void *opaque, uint32_t offs, uint32_t val)

{

    sh_serial_state *s = opaque;

    unsigned char ch;



#ifdef DEBUG_SERIAL

    printf("sh_serial: write offs=0x%02x val=0x%02x\n",

	   offs, val);

#endif

    switch(offs) {

    case 0x00: 

        s->smr = val & ((s->feat & SH_SERIAL_FEAT_SCIF) ? 0x7b : 0xff);

        return;

    case 0x04: 

        s->brr = val;

	return;

    case 0x08: 

        

        s->scr = val & ((s->feat & SH_SERIAL_FEAT_SCIF) ? 0xfa : 0xff);

        if (!(val & (1 << 5)))

            s->flags |= SH_SERIAL_FLAG_TEND;

        if ((s->feat & SH_SERIAL_FEAT_SCIF) && s->txi) {

	    qemu_set_irq(s->txi, val & (1 << 7));

        }

        if (!(val & (1 << 6))) {

	    qemu_set_irq(s->rxi, 0);

        }

        return;

    case 0x0c: 

        if (s->chr) {

            ch = val;

            qemu_chr_write(s->chr, &ch, 1);

	}

	s->dr = val;

	s->flags &= ~SH_SERIAL_FLAG_TDE;

        return;

#if 0

    case 0x14: 

        ret = 0;

        break;

#endif

    }

    if (s->feat & SH_SERIAL_FEAT_SCIF) {

        switch(offs) {

        case 0x10: 

            if (!(val & (1 << 6)))

                s->flags &= ~SH_SERIAL_FLAG_TEND;

            if (!(val & (1 << 5)))

                s->flags &= ~SH_SERIAL_FLAG_TDE;

            if (!(val & (1 << 4)))

                s->flags &= ~SH_SERIAL_FLAG_BRK;

            if (!(val & (1 << 1)))

                s->flags &= ~SH_SERIAL_FLAG_RDF;

            if (!(val & (1 << 0)))

                s->flags &= ~SH_SERIAL_FLAG_DR;



            if (!(val & (1 << 1)) || !(val & (1 << 0))) {

                if (s->rxi) {

                    qemu_set_irq(s->rxi, 0);

                }

            }

            return;

        case 0x18: 

            s->fcr = val;

            switch ((val >> 6) & 3) {

            case 0:

                s->rtrg = 1;

                break;

            case 1:

                s->rtrg = 4;

                break;

            case 2:

                s->rtrg = 8;

                break;

            case 3:

                s->rtrg = 14;

                break;

            }

            if (val & (1 << 1)) {

                sh_serial_clear_fifo(s);

                s->sr &= ~(1 << 1);

            }



            return;

        case 0x20: 

            s->sptr = val & 0xf3;

            return;

        case 0x24: 

            return;

        }

    }

    else {

#if 0

        switch(offs) {

        case 0x0c:

            ret = s->dr;

            break;

        case 0x10:

            ret = 0;

            break;

        case 0x1c:

            ret = s->sptr;

            break;

        }

#endif

    }



    fprintf(stderr, "sh_serial: unsupported write to 0x%02x\n", offs);

    assert(0);

}

#if 0             ret = s->sptr;             break; #endif #if 0 #endif
static void FUNC_0(void *VAR_0, uint32_t VAR_1, uint32_t VAR_2)

{

    sh_serial_state *s = VAR_0;

    unsigned char VAR_3;



#ifdef DEBUG_SERIAL

    printf("sh_serial: write VAR_1=0x%02x VAR_2=0x%02x\n",

	   VAR_1, VAR_2);

#endif

    switch(VAR_1) {

    case 0x00: 

        s->smr = VAR_2 & ((s->feat & SH_SERIAL_FEAT_SCIF) ? 0x7b : 0xff);

        return;

    case 0x04: 

        s->brr = VAR_2;

	return;

    case 0x08: 

        

        s->scr = VAR_2 & ((s->feat & SH_SERIAL_FEAT_SCIF) ? 0xfa : 0xff);

        if (!(VAR_2 & (1 << 5)))

            s->flags |= SH_SERIAL_FLAG_TEND;

        if ((s->feat & SH_SERIAL_FEAT_SCIF) && s->txi) {

	    qemu_set_irq(s->txi, VAR_2 & (1 << 7));

        }

        if (!(VAR_2 & (1 << 6))) {

	    qemu_set_irq(s->rxi, 0);

        }

        return;

    case 0x0c: 

        if (s->chr) {

            VAR_3 = VAR_2;

            qemu_chr_write(s->chr, &VAR_3, 1);

	}

	s->dr = VAR_2;

	s->flags &= ~SH_SERIAL_FLAG_TDE;

        return;

#if 0

    case 0x14: 

        ret = 0;

        break;

#endif

    }

    if (s->feat & SH_SERIAL_FEAT_SCIF) {

        switch(VAR_1) {

        case 0x10: 

            if (!(VAR_2 & (1 << 6)))

                s->flags &= ~SH_SERIAL_FLAG_TEND;

            if (!(VAR_2 & (1 << 5)))

                s->flags &= ~SH_SERIAL_FLAG_TDE;

            if (!(VAR_2 & (1 << 4)))

                s->flags &= ~SH_SERIAL_FLAG_BRK;

            if (!(VAR_2 & (1 << 1)))

                s->flags &= ~SH_SERIAL_FLAG_RDF;

            if (!(VAR_2 & (1 << 0)))

                s->flags &= ~SH_SERIAL_FLAG_DR;



            if (!(VAR_2 & (1 << 1)) || !(VAR_2 & (1 << 0))) {

                if (s->rxi) {

                    qemu_set_irq(s->rxi, 0);

                }

            }

            return;

        case 0x18: 

            s->fcr = VAR_2;

            switch ((VAR_2 >> 6) & 3) {

            case 0:

                s->rtrg = 1;

                break;

            case 1:

                s->rtrg = 4;

                break;

            case 2:

                s->rtrg = 8;

                break;

            case 3:

                s->rtrg = 14;

                break;

            }

            if (VAR_2 & (1 << 1)) {

                sh_serial_clear_fifo(s);

                s->sr &= ~(1 << 1);

            }



            return;

        case 0x20: 

            s->sptr = VAR_2 & 0xf3;

            return;

        case 0x24: 

            return;

        }

    }

    else {

#if 0

        switch(VAR_1) {

        case 0x0c:

            ret = s->dr;

            break;

        case 0x10:

            ret = 0;

            break;

        case 0x1c:

            ret = s->sptr;

            break;

        }

#endif

    }



    fprintf(stderr, "sh_serial: unsupported write to 0x%02x\n", VAR_1);

    assert(0);

}

static void FUNC_0(void *VAR_0, uint32_t VAR_1, uint32_t VAR_2)
{ sh_serial_state *s = VAR_0; unsigned char VAR_3; #ifdef DEBUG_SERIAL
printf("sh_serial: write VAR_1=0x%02x VAR_2=0x%02x\n",
VAR_1, VAR_2); #endif
switch(VAR_1) { case 0x00:
s->smr = VAR_2 & ((s->feat & SH_SERIAL_FEAT_SCIF) ? 0x7b : 0xff); return; case 0x04:
s->brr = VAR_2; return; case 0x08:
s->scr = VAR_2 & ((s->feat & SH_SERIAL_FEAT_SCIF) ? 0xfa : 0xff); if (!(VAR_2 & (1 << 5)))
s->flags |= SH_SERIAL_FLAG_TEND; if ((s->feat & SH_SERIAL_FEAT_SCIF) && s->txi) { qemu_set_irq(s->txi, VAR_2 & (1 << 7)); } if (!(VAR_2 & (1 << 6))) { qemu_set_irq(s->rxi, 0); } return; case 0x0c:
if (s->chr) { VAR_3 = VAR_2; qemu_chr_write(s->chr, &VAR_3, 1); } s->dr = VAR_2; s->flags &= ~SH_SERIAL_FLAG_TDE; return; #if 0
case 0x14:
ret = 0; break; #endif
} if (s->feat & SH_SERIAL_FEAT_SCIF) { switch(VAR_1) { case 0x10:
if (!(VAR_2 & (1 << 6)))
s->flags &= ~SH_SERIAL_FLAG_TEND; if (!(VAR_2 & (1 << 5)))
s->flags &= ~SH_SERIAL_FLAG_TDE; if (!(VAR_2 & (1 << 4)))
s->flags &= ~SH_SERIAL_FLAG_BRK; if (!(VAR_2 & (1 << 1)))
s->flags &= ~SH_SERIAL_FLAG_RDF; if (!(VAR_2 & (1 << 0)))
s->flags &= ~SH_SERIAL_FLAG_DR; if (!(VAR_2 & (1 << 1)) || !(VAR_2 & (1 << 0))) { if (s->rxi) { qemu_set_irq(s->rxi, 0); } } return; case 0x18:
s->fcr = VAR_2; switch ((VAR_2 >> 6) & 3) { case 0:
s->rtrg = 1; break; case 1:
s->rtrg = 4; break; case 2:
s->rtrg = 8; break; case 3:
s->rtrg = 14; break; } if (VAR_2 & (1 << 1)) { sh_serial_clear_fifo(s); s->sr &= ~(1 << 1); } return; case 0x20:
s->sptr = VAR_2 & 0xf3; return; case 0x24:
return; } } else { #if 0
switch(VAR_1) { case 0x0c:
ret = s->dr; break; case 0x10:
ret = 0; break; case 0x1c:
ret = s->sptr; break; } #endif
} fprintf(stderr, "sh_serial: unsupported write to 0x%02x\n", VAR_1); assert(0); }