Ejemplo n.º 1
0
void csw_poll()
{
        int c;
        uint8_t dat;
        if (!csw_dat) return;
        
        for (c = 0; c < 10; c++)
        {
                dat = csw_dat[csw_point++];

                if (csw_point >= (8 * 1024 * 1024))
                {
                        csw_point = 0;
                        csw_loop = 1;
                }
                if (csw_skip)
                   csw_skip--;
                else if (csw_intone && dat > 0xD) /*Not in tone any more - data start bit*/
                {
                        csw_point++; /*Skip next half of wave*/
                        if (acia_tapespeed) csw_skip = 6;
                        csw_intone = 0;
                        csw_indat = 1;

                        csw_datbits = csw_enddat = 0;
                        dcdlow();
                        return;
                }
                else if (csw_indat && csw_datbits != -1 && csw_datbits != -2)
                {
                        csw_point++; /*Skip next half of wave*/
                        if (acia_tapespeed) csw_skip = 6;
                        csw_enddat >>= 1;

                        if (dat <= 0xD)
                        {
                                csw_point += 2;
                                if (acia_tapespeed) csw_skip += 6;
                                csw_enddat |= 0x80;
                        }
                        csw_datbits++;
                        if (csw_datbits == 8)
                        {
                                csw_receive(csw_enddat);

                                csw_datbits = -2;
                                return;
                        }
                }
                else if (csw_indat && csw_datbits == -2) /*Deal with stop bit*/
Ejemplo n.º 2
0
Archivo: uef.c Proyecto: fesh0r/b-em
void uef_poll()
{
        int c;
        uint32_t templ;
        float *tempf;
        uint8_t temp;
        if (!uef_f)
           return;
        if (!uef_inchunk)
        {
                uef_startchunk = 1;
//                printf("%i ",gztell(uef));
                gzread(uef_f, &uef_chunkid, 2);
                gzread(uef_f, &uef_chunklen, 4);
                if (gzeof(uef_f))
                {
                        gzseek(uef_f, 12, SEEK_SET);
                        gzread(uef_f, &uef_chunkid, 2);
                        gzread(uef_f, &uef_chunklen, 4);
                        uefloop = 1;
                }
                uef_inchunk = 1;
                uef_chunkpos = 0;
//                printf("Chunk ID %04X len %i\n",uef_chunkid,uef_chunklen);
        }
//        else
//           printf("Chunk %04X\n",uef_chunkid);
        switch (uef_chunkid)
        {
                case 0x000: /*Origin*/
                for (c = 0; c < uef_chunklen; c++)
                    gzgetc(uef_f);
                uef_inchunk = 0;
                return;

                case 0x005: /*Target platform*/
                for (c = 0; c < uef_chunklen; c++)
                    gzgetc(uef_f);
                uef_inchunk = 0;
                return;

                case 0x100: /*Raw data*/
                if (uef_startchunk)
                {
                        dcdlow();
                        uef_startchunk = 0;
                }
                uef_chunklen--;
                if (!uef_chunklen)
                {
                        uef_inchunk = 0;
                }
                uef_receive(gzgetc(uef_f));
                return;

                case 0x104: /*Defined data*/
                if (!uef_chunkpos)
                {
                        uef_chunkdatabits = gzgetc(uef_f);
                        gzgetc(uef_f);
                        gzgetc(uef_f);
                        uef_chunklen -= 3;
                        uef_chunkpos = 1;
                }
                else
                {
                        uef_chunklen--;
                        if (uef_chunklen <= 0)
                           uef_inchunk = 0;
                        temp = gzgetc(uef_f);
//                        printf("%i : %i %02X\n",gztell(uef),uef_chunklen,temp);
                        if (uef_chunkdatabits == 7) uef_receive(temp & 0x7F);
                        else                        uef_receive(temp);
                }
                return;

                case 0x110: /*High tone*/
                uef_toneon = 2;
                if (!uef_intone)
                {
                        dcd();
                        uef_intone = gzgetc(uef_f);
                        uef_intone |= (gzgetc(uef_f) << 8);
                        uef_intone /= 20;
                        if (!uef_intone) uef_intone = 1;
//                        printf("uef_intone %i\n",uef_intone);
                }
                else
                {
                        uef_intone--;
                        if (uef_intone == 0)
                        {
                                uef_inchunk = 0;
                        }
                }
                return;

                case 0x111: /*High tone with dummy byte*/
                uef_toneon = 2;
                if (!uef_intone)
                {
                        dcd();
                        uef_intone = gzgetc(uef_f);
                        uef_intone |= (gzgetc(uef_f)<<8);
                        uef_intone /= 20;
                        if (!uef_intone) uef_intone = 1;
                }
                else
                {
                        uef_intone--;
                        if (uef_intone == 0 && uef_inchunk == 2)
                        {
                                uef_inchunk = 0;
                        }
                        else if (!uef_intone)
                        {
                                uef_inchunk = 2;
                                uef_intone = gzgetc(uef_f);
                                uef_intone |= (gzgetc(uef_f) << 8);
                                uef_intone /= 20;
                                if (!uef_intone) uef_intone = 1;
                                uef_receive(0xAA);
                        }
                }
                return;

                case 0x112: /*Gap*/
                uef_toneon = 0;
                if (!uef_intone)
                {
//                        dcd();
                        uef_intone = gzgetc(uef_f);
                        uef_intone |= (gzgetc(uef_f) << 8);
                        uef_intone /= 20;
//                        printf("gap uef_intone %i\n",uef_intone);
                        if (!uef_intone) uef_intone = 1;
                }
                else
                {
                        uef_intone--;
                        if (uef_intone == 0)
                        {
                                uef_inchunk = 0;
                        }
                }
                return;

                case 0x113: /*Float baud rate*/
                templ = gzgetc(uef_f);
                templ |= (gzgetc(uef_f) << 8);
                templ |= (gzgetc(uef_f) << 16);
                templ |= (gzgetc(uef_f) << 24);
                tempf = (float *)&templ;
                tapellatch = (1000000 / ((*tempf) / 10)) / 64;
                pps = (*tempf) / 10;
                uef_inchunk = 0;
                return;

                case 0x116: /*Float gap*/
                uef_toneon = 0;
                if (!uef_chunkpos)
                {
                        templ = gzgetc(uef_f);
                        templ |= (gzgetc(uef_f) << 8);
                        templ |= (gzgetc(uef_f) << 16);
                        templ |= (gzgetc(uef_f) << 24);
                        tempf = (float *)&templ;
                        uef_chunkf = *tempf;
                        //printf("Gap %f %i\n",uef_chunkf,pps);
                        uef_chunkpos = 1;
//                        uef_chunkf=4;
                }
                else
                {
//                        printf("Gap now %f\n",uef_chunkf);
                        uef_chunkf -= ((float)1 / (float)pps);
                        if (uef_chunkf <= 0) uef_inchunk = 0;
                }
                return;

                case 0x114: /*Security waves*/
                case 0x115: /*Polarity change*/
//                default:
                for (c = 0; c < uef_chunklen; c++)
                    gzgetc(uef_f);
                uef_inchunk = 0;
                return;

                default:
                for (c = 0; c < uef_chunklen; c++)
                    gzgetc(uef_f);
                uef_inchunk = 0;
                return;
//116 : float gap
//113 : float baud rate

        }
//        allegro_exit();
//        printf("Bad chunk ID %04X length %i\n",uef_chunkid,uef_chunklen);
//        exit(-1);
}