Subversion Repositories pentevo

Rev

Rev 796 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. #include "std.h"
  2.  
  3. #include "emul.h"
  4. #include "vars.h"
  5. #include "tape.h"
  6. #include "memory.h"
  7.  
  8. #include "util.h"
  9. #include "png/zlib.h"
  10.  
  11. #define Z80FQ 3500000
  12.  
  13. unsigned tape_pulse[0x100]; // └ыЇртшЄ шч шьяєы№ёют Ёрчэющ фышэ√ (ўшёыю ёшьтюыют рыЇртшЄр эх сюыхх 256, ёё√ыъш юфэюсрщЄют√х)
  14. static unsigned max_pulses = 0;
  15. static unsigned tape_err = 0;
  16.  
  17. u8 *tape_image = nullptr; // ╠рёёшт ёё√ыюъ эр рыЇртшЄ (ёё√ыъш юфэюсрщЄют√х)
  18. static unsigned tape_imagesize = 0;
  19.  
  20. TAPEINFO *tapeinfo;
  21. unsigned tape_infosize;
  22.  
  23. static unsigned appendable;
  24.  
  25. typedef int (__cdecl *inflateInit__ptr)(z_streamp strm, const char *version, int stream_size);
  26. typedef int (__cdecl *inflate_ptr)(z_streamp strm, int flush);
  27. typedef int (__cdecl *inflateEnd_ptr)(z_streamp strm);
  28.  
  29. static inflateInit__ptr inflateInit__p = nullptr;
  30. static inflate_ptr inflate_p = nullptr;
  31. static inflateEnd_ptr inflateEnd_p = nullptr;
  32.  
  33. static HMODULE ZlibDll = nullptr;
  34.  
  35. bool ZlibInit()
  36. {
  37.     ZlibDll = LoadLibrary("zlib1.dll");
  38.     if(!ZlibDll)
  39.         return false;
  40.     inflateInit__p = (inflateInit__ptr)GetProcAddress(ZlibDll, "inflateInit_");
  41.     if(!inflateInit__p)
  42.         return false;
  43.     inflate_p = (inflate_ptr)GetProcAddress(ZlibDll,"inflate");
  44.     if(!inflate_p)
  45.         return false;
  46.     inflateEnd_p = (inflateEnd_ptr)GetProcAddress(ZlibDll,"inflateEnd");
  47.     if(!inflateEnd_p)
  48.         return false;
  49.     return true;
  50. }
  51.  
  52. void ZlibDone()
  53. {
  54.     if(ZlibDll)
  55.         FreeLibrary(ZlibDll);
  56. }
  57.  
  58. // ╚∙хЄ фышэє шьяєы№ёр т рыЇртшЄх ш тючтЁр∙рхЄ шэфхъё эрщфхээюую ¤ыхьхэЄр
  59. // ┼ёыш шьяєы№ё ё Єръющ °шЁшэющ эх эрщфхэ, юэ фюсрты хЄё  т ъюэхЎ ш тючтЁр∙рхЄё  хую шэфхъё
  60. // tape image contains indexes in tape_pulse[]
  61. static u8 find_pulse(unsigned t)
  62. {
  63.    if (max_pulses < _countof(tape_pulse))
  64.    {
  65.       double e = 0.10 * t; // ЁрчсЁюё 10%
  66.       for (unsigned i = 0; i < max_pulses; i++)
  67.       {
  68.          if ((t - e) < tape_pulse[i] && tape_pulse[i] <= (t + e))
  69.          {
  70.              return u8(i);
  71.          }
  72.       }
  73.       tape_pulse[max_pulses] = t;
  74.       return u8(max_pulses++);
  75.    }
  76.    if (!tape_err)
  77.    {
  78.        errmsg("pulse table full");
  79.        tape_err = 1;
  80.    }
  81.    unsigned nearest = 0; int delta = 0x7FFFFFFF;
  82.    for (unsigned i = 0; i < _countof(tape_pulse); i++)
  83.    {
  84.       if (delta > abs((int)t - (int)tape_pulse[i]))
  85.       {
  86.          nearest = i;
  87.          delta = abs((int)t - (int)tape_pulse[i]);
  88.       }
  89.    }
  90.    return u8(nearest);
  91. }
  92.  
  93. void find_tape_index()
  94. {
  95.    for (unsigned i = 0; i < tape_infosize; i++)
  96.       if (comp.tape.play_pointer >= tape_image + tapeinfo[i].pos)
  97.          comp.tape.index = i;
  98.    temp.led.tape_started = -600*3500000;
  99. }
  100.  
  101. static void find_tape_sizes()
  102. {
  103.    for (unsigned i = 0; i < tape_infosize; i++) {
  104.       unsigned end = (i == tape_infosize-1) ? tape_imagesize : tapeinfo[i+1].pos;
  105.  
  106.       unsigned sz = 0;
  107.       for (unsigned j = tapeinfo[i].pos; j < end; j++)
  108.          sz += tape_pulse[tape_image[j]];
  109.       tapeinfo[i].t_size = sz;
  110.    }
  111. }
  112.  
  113. void stop_tape()
  114. {
  115.     // ╙ёыютш  фы  т√їюфр шї ЇєэъЎшш tape_bit()
  116.     comp.tape.edge_change = LLONG_MAX;
  117.     comp.tape.tape_bit = -1U;
  118.  
  119.     if(comp.tape.stopped) // ┼ёыш ыхэЄр єцх юёЄрэютыхэр, Єю эшўхую эх фхырхь
  120.     {
  121.         return;
  122.     }
  123.  
  124.     comp.tape.stopped = true;
  125.  
  126.     find_tape_index();
  127.  
  128.     const char *msg = "tape stopped";
  129.     if(comp.tape.play_pointer == comp.tape.end_of_tape) // ╧Ёш фюёЄшцхэшш ъюэЎр ыхэЄ√ эх фхырхь ртЄюяхЁхьюЄъє
  130.     {
  131.         msg = "end of tape";
  132.     }
  133.     else
  134.     {
  135.         comp.tape.play_pointer = nullptr;
  136.     }
  137.     strcpy(statusline, msg); statcnt = 40;
  138. }
  139.  
  140. void reset_tape()
  141. {
  142.    comp.tape.index = 0;
  143.    comp.tape.stopped = true;
  144.    comp.tape.play_pointer = nullptr;
  145.    comp.tape.edge_change = LLONG_MAX;
  146.    comp.tape.tape_bit = -1U;
  147. }
  148.  
  149. void start_tape()
  150. {
  151.     if(!tape_image)
  152.     {
  153.         return;
  154.     }
  155.  
  156.    comp.tape.play_pointer = tape_image + tapeinfo[comp.tape.index].pos;
  157.    comp.tape.end_of_tape = tape_image + tape_imagesize;
  158.  
  159.    if(comp.tape.play_pointer >= comp.tape.end_of_tape) // ╩юэхЎ ыхэЄ√, шуэюЁшЁєхь чряєёъ
  160.    {
  161.        return;
  162.    }
  163.    comp.tape.stopped = false;
  164.    comp.tape.edge_change = comp.t_states + cpu.t;
  165.    temp.led.tape_started = -600*3500000;
  166.    comp.tape.tape_bit = -1U;
  167.    strcpy(statusline, "tape started"); statcnt = 40;
  168. }
  169.  
  170. void closetape()
  171. {
  172.     if(tape_image)
  173.     {
  174.         free(tape_image);
  175.         tape_image = nullptr;
  176.     }
  177.     if(tapeinfo)
  178.     {
  179.         free(tapeinfo);
  180.         tapeinfo = nullptr;
  181.     }
  182.    comp.tape.play_pointer = nullptr; // stop tape
  183.    comp.tape.index = 0; // rewind tape
  184.    tape_err = max_pulses = tape_imagesize = tape_infosize = 0;
  185.    comp.tape.edge_change = LLONG_MAX;
  186.    comp.tape.tape_bit = -1U;
  187. }
  188.  
  189. static void reserve(unsigned datasize)
  190. {
  191.    const unsigned blocksize = 16384;
  192.    unsigned newsize = align_by(datasize+tape_imagesize+1, blocksize);
  193.    if (!tape_image) tape_image = (unsigned char*)malloc(newsize);
  194.    if (align_by(tape_imagesize, blocksize) < newsize) tape_image = (unsigned char*)realloc(tape_image, newsize);
  195. }
  196.  
  197. static void makeblock(const unsigned char *data, unsigned size, unsigned pilot_t,
  198.       unsigned s1_t, unsigned s2_t, unsigned zero_t, unsigned one_t,
  199.       unsigned pilot_len, unsigned pause, unsigned char last = 8)
  200. {
  201.    reserve(size*16 + pilot_len + 3);
  202.    if (pilot_len != -1U) {
  203.       u8 t = find_pulse(pilot_t);
  204.       for (unsigned i = 0; i < pilot_len; i++)
  205.          tape_image[tape_imagesize++] = t;
  206.       tape_image[tape_imagesize++] = find_pulse(s1_t);
  207.       tape_image[tape_imagesize++] = find_pulse(s2_t);
  208.    }
  209.    u8 t0 = find_pulse(zero_t), t1 = find_pulse(one_t);
  210.    for(; size > 1; size--, data++)
  211.    {
  212.        for(unsigned char j = 0x80; j; j >>= 1)
  213.        {
  214.            tape_image[tape_imagesize++] = (*data & j) ? t1 : t0;
  215.            tape_image[tape_imagesize++] = (*data & j) ? t1 : t0;
  216.        }
  217.    }
  218.    for(unsigned char j = 0x80; j != (unsigned char)(0x80 >> last); j >>= 1) // last byte
  219.    {
  220.        tape_image[tape_imagesize++] = (*data & j) ? t1 : t0;
  221.        tape_image[tape_imagesize++] = (*data & j) ? t1 : t0;
  222.    }
  223.    if (pause) tape_image[tape_imagesize++] = find_pulse(pause*3500);
  224. }
  225.  
  226. static void desc(const unsigned char *data, unsigned size, char *dst)
  227. {
  228.    unsigned char crc = 0; char prg[10];
  229.    unsigned i; //Alone Coder 0.36.7
  230.    for (/*unsigned*/ i = 0; i < size; i++) crc ^= data[i];
  231.    if (!*data && size == 19 && (data[1] == 0 || data[1] == 3)) {
  232.       for (i = 0; i < 10; i++) prg[i] = (data[i+2] < ' ' || data[i+2] >= 0x80) ? '?' : char(data[i+2]);
  233.       for (i = 9; i && prg[i] == ' '; prg[i--] = 0);
  234.       sprintf(dst, "%s: \"%s\" %d,%d", data[1] ? "Bytes":"Program", prg,
  235.          *(const unsigned short*)(data+14), *(const unsigned short*)(data+12));
  236.    } else if (*data == 0xFF) sprintf(dst, "data block, %u bytes", size-2);
  237.    else sprintf(dst, "#%02X block, %u bytes", *data, size-2);
  238.    sprintf(dst + strlen(dst), ", crc %s", crc ? "bad":"ok");
  239. }
  240.  
  241. static bool alloc_infocell()
  242. {
  243.    TAPEINFO *tmp = (TAPEINFO*)realloc(tapeinfo, (tape_infosize+1)*sizeof(TAPEINFO));
  244.    if(!tmp)
  245.    {
  246.        return false;
  247.    }
  248.    tapeinfo = tmp;
  249.    tapeinfo[tape_infosize].pos = tape_imagesize;
  250.    appendable = 0;
  251.    return true;
  252. }
  253.  
  254. static bool named_cell(const void *nm, unsigned sz = 0)
  255. {
  256.    if(!alloc_infocell())
  257.        return false;
  258.  
  259.    const size_t n = _countof(tapeinfo[tape_infosize].desc)-1;
  260.    size_t len = min(n, sz ? sz : strlen((const char*)nm));
  261.    strncpy(tapeinfo[tape_infosize].desc, (const char*)nm, len);
  262.    tapeinfo[tape_infosize].desc[len] = 0;
  263.    tape_infosize++;
  264.    return true;
  265. }
  266.  
  267. int readTAP()
  268. {
  269.    unsigned char *ptr = snbuf; closetape();
  270.    while (ptr < snbuf+snapsize) {
  271.       unsigned size = *(unsigned short*)ptr; ptr += 2;
  272.       if (!size) break;
  273.       alloc_infocell();
  274.       desc(ptr, size, tapeinfo[tape_infosize].desc);
  275.       tape_infosize++;
  276.       makeblock(ptr, size, 2168, 667, 735, 855, 1710, (*ptr < 4) ? 8064 : 3220, 1000);
  277.       ptr += size;
  278.    }
  279.    find_tape_sizes();
  280.    return (ptr == snbuf+snapsize);
  281. }
  282.  
  283. #pragma pack(push, 1)
  284. struct TCswHdr
  285. {
  286.     char Signature[22];
  287.     u8 Term;
  288.     u8 VerMajor;
  289.     u8 VerMinor;
  290.     union
  291.     {
  292.         struct
  293.         {
  294.             u16 SampleRate;
  295.             u8 CompressionType;
  296.             u8 Flags;
  297.             u8 Reserved[3];
  298.             u8 Data[];
  299.         } Ver1;
  300.  
  301.         struct
  302.         {
  303.             u32 SampleRate;
  304.             u32 PulsesAfterDecompression;
  305.             u8 CompressionType;
  306.             u8 Flags;
  307.             u8 HeaderExtLen;
  308.             char EncAppDesc[16];
  309.             u8 ExtHdr[];
  310.         } Ver2;
  311.     };
  312. };
  313. #pragma pack(pop)
  314.  
  315. int readCSW()
  316. {
  317.    closetape();
  318.    named_cell("CSW tape image");
  319.  
  320.    const TCswHdr *CswHdr = (TCswHdr *)snbuf;
  321.    u8 CompType;
  322.    u32 SampleRate;
  323.    u8 Flags;
  324.    u32 DataOffset;
  325.    u32 PulsesCount;
  326.    switch(CswHdr->VerMajor)
  327.    {
  328.    case 1:
  329.        CompType = CswHdr->Ver1.CompressionType;
  330.        SampleRate = CswHdr->Ver1.SampleRate;
  331.        Flags = CswHdr->Ver1.Flags;
  332.        DataOffset = offsetof(TCswHdr, Ver1.Data);
  333.        PulsesCount = snapsize - 0x18; // ═хяюэ Єэр  ъюэёЄрэЄр
  334.    break;
  335.  
  336.    case 2:
  337.        CompType = CswHdr->Ver2.CompressionType;
  338.        SampleRate = CswHdr->Ver2.SampleRate;
  339.        Flags = CswHdr->Ver2.Flags;
  340.        DataOffset = offsetof(TCswHdr, Ver2.ExtHdr) + CswHdr->Ver2.HeaderExtLen;
  341.        PulsesCount = CswHdr->Ver2.PulsesAfterDecompression;
  342.    break;
  343.  
  344.    default: // unknown csw version
  345.        return 0;
  346.    }
  347.  
  348.    u32 UncompressedSize = snapsize;
  349.    switch(CompType)
  350.    {
  351.    case 2: // Z-RLE
  352.        {
  353.            if(!temp.ZlibSupport)
  354.                return 0;
  355.            static const size_t out_sz = sizeof(snbuf);
  356.            void *out = malloc(out_sz);
  357.            if(!out)
  358.                return 0;
  359.  
  360.            z_stream strm;
  361.            strm.zalloc = Z_NULL;
  362.            strm.zfree = Z_NULL;
  363.            strm.opaque = Z_NULL;
  364.            strm.avail_in = snapsize - DataOffset;
  365.            strm.next_in = snbuf + DataOffset;
  366.            int ret = inflateInit__p(&strm, ZLIB_VERSION, sizeof(strm));
  367.            if(ret != Z_OK)
  368.            {
  369.                free(out);
  370.                return 0;
  371.            }
  372.  
  373.            strm.avail_out = out_sz;
  374.            strm.next_out = (Byte *)out;
  375.            ret = inflate_p(&strm, Z_FINISH);
  376.            if(ret < 0)
  377.            {
  378.                free(out);
  379.                inflateEnd_p(&strm);
  380.                return 0;
  381.            }
  382.            UncompressedSize = out_sz - strm.avail_out;
  383.            memcpy(snbuf + DataOffset, out, UncompressedSize);
  384.            UncompressedSize += DataOffset;
  385.            free(out);
  386.            inflateEnd_p(&strm);
  387.        }
  388.    case 1: // RLE
  389.    break;
  390.  
  391.    default:
  392.        return 0; // unknown compression type
  393.    }
  394.  
  395.    unsigned rate = Z80FQ / SampleRate; // usually 3.5mhz / 44khz
  396.    if (!rate)
  397.        return 0;
  398.  
  399.    reserve(PulsesCount);
  400.  
  401.    if (!(Flags & 1))
  402.        tape_image[tape_imagesize++] = find_pulse(1);
  403.  
  404.    unsigned i = 0;
  405.    for (unsigned char *ptr = snbuf + DataOffset; ptr < snbuf + UncompressedSize; i++)
  406.    {
  407.       unsigned len = *ptr++ * rate;
  408.       if (!len)
  409.       {
  410.           len = *(unsigned*)ptr * rate;
  411.           ptr += 4;
  412.       }
  413.       tape_image[tape_imagesize++] = find_pulse(len);
  414.    }
  415.  
  416.    tape_image[tape_imagesize++] = find_pulse(Z80FQ/10);
  417.    find_tape_sizes();
  418.    return 1;
  419. }
  420.  
  421. static void create_appendable_block()
  422. {
  423.    if (!tape_infosize || appendable) return;
  424.    named_cell("set of pulses"); appendable = 1;
  425. }
  426.  
  427. static void parse_hardware(const unsigned char *ptr)
  428. {
  429.    unsigned n = *ptr++;
  430.    if (!n) return;
  431.    named_cell("- HARDWARE TYPE ");
  432.    static char ids[] =
  433.      "computer\0"
  434.         "ZX Spectrum 16k\0"
  435.         "ZX Spectrum 48k, Plus\0"
  436.         "ZX Spectrum 48k ISSUE 1\0"
  437.         "ZX Spectrum 128k (Sinclair)\0"
  438.         "ZX Spectrum 128k +2 (Grey case)\0"
  439.         "ZX Spectrum 128k +2A, +3\0"
  440.         "Timex Sinclair TC-2048\0"
  441.         "Timex Sinclair TS-2068\0"
  442.         "Pentagon 128\0"
  443.         "Sam Coupe\0"
  444.         "Didaktik M\0"
  445.         "Didaktik Gama\0"
  446.         "ZX-81 or TS-1000 with  1k RAM\0"
  447.         "ZX-81 or TS-1000 with 16k RAM or more\0"
  448.         "ZX Spectrum 128k, Spanish version\0"
  449.         "ZX Spectrum, Arabic version\0"
  450.         "TK 90-X\0"
  451.         "TK 95\0"
  452.         "Byte\0"
  453.         "Elwro\0"
  454.         "ZS Scorpion\0"
  455.         "Amstrad CPC 464\0"
  456.         "Amstrad CPC 664\0"
  457.         "Amstrad CPC 6128\0"
  458.         "Amstrad CPC 464+\0"
  459.         "Amstrad CPC 6128+\0"
  460.         "Jupiter ACE\0"
  461.         "Enterprise\0"
  462.         "Commodore 64\0"
  463.         "Commodore 128\0"
  464.         "\0"
  465.      "ext. storage\0"
  466.         "Microdrive\0"
  467.         "Opus Discovery\0"
  468.         "Disciple\0"
  469.         "Plus-D\0"
  470.         "Rotronics Wafadrive\0"
  471.         "TR-DOS (BetaDisk)\0"
  472.         "Byte Drive\0"
  473.         "Watsford\0"
  474.         "FIZ\0"
  475.         "Radofin\0"
  476.         "Didaktik disk drives\0"
  477.         "BS-DOS (MB-02)\0"
  478.         "ZX Spectrum +3 disk drive\0"
  479.         "JLO (Oliger) disk interface\0"
  480.         "FDD3000\0"
  481.         "Zebra disk drive\0"
  482.         "Ramex Millenia\0"
  483.         "Larken\0"
  484.         "\0"
  485.      "ROM/RAM type add-on\0"
  486.         "Sam Ram\0"
  487.         "Multiface\0"
  488.         "Multiface 128k\0"
  489.         "Multiface +3\0"
  490.         "MultiPrint\0"
  491.         "MB-02 ROM/RAM expansion\0"
  492.         "\0"
  493.      "sound device\0"
  494.         "Classic AY hardware\0"
  495.         "Fuller Box AY sound hardware\0"
  496.         "Currah microSpeech\0"
  497.         "SpecDrum\0"
  498.         "AY ACB stereo; Melodik\0"
  499.         "AY ABC stereo\0"
  500.         "\0"
  501.      "joystick\0"
  502.         "Kempston\0"
  503.         "Cursor, Protek, AGF\0"
  504.         "Sinclair 2\0"
  505.         "Sinclair 1\0"
  506.         "Fuller\0"
  507.         "\0"
  508.      "mice\0"
  509.         "AMX mouse\0"
  510.         "Kempston mouse\0"
  511.         "\0"
  512.      "other controller\0"
  513.         "Trickstick\0"
  514.         "ZX Light Gun\0"
  515.         "Zebra Graphics Tablet\0"
  516.         "\0"
  517.      "serial port\0"
  518.         "ZX Interface 1\0"
  519.         "ZX Spectrum 128k\0"
  520.         "\0"
  521.      "parallel port\0"
  522.         "Kempston S\0"
  523.         "Kempston E\0"
  524.         "ZX Spectrum 128k +2A, +3\0"
  525.         "Tasman\0"
  526.         "DK'Tronics\0"
  527.         "Hilderbay\0"
  528.         "INES Printerface\0"
  529.         "ZX LPrint Interface 3\0"
  530.         "MultiPrint\0"
  531.         "Opus Discovery\0"
  532.         "Standard 8255 chip with ports 31,63,95\0"
  533.         "\0"
  534.      "printer\0"
  535.         "ZX Printer, Alphacom 32 & compatibles\0"
  536.         "Generic Printer\0"
  537.         "EPSON Compatible\0"
  538.         "\0"
  539.      "modem\0"
  540.         "VTX 5000\0"
  541.         "T/S 2050 or Westridge 2050\0"
  542.         "\0"
  543.      "digitaiser\0"
  544.         "RD Digital Tracer\0"
  545.         "DK'Tronics Light Pen\0"
  546.         "British MicroGraph Pad\0"
  547.         "\0"
  548.      "network adapter\0"
  549.         "ZX Interface 1\0"
  550.         "\0"
  551.      "keyboard / keypad\0"
  552.         "Keypad for ZX Spectrum 128k\0"
  553.         "\0"
  554.      "AD/DA converter\0"
  555.         "Harley Systems ADC 8.2\0"
  556.         "Blackboard Electronics\0"
  557.         "\0"
  558.      "EPROM Programmer\0"
  559.         "Orme Electronics\0"
  560.         "\0"
  561.      "\0";
  562.    for (unsigned i = 0; i < n; i++) {
  563.       unsigned char type_n = *ptr++;
  564.       unsigned char id_n = *ptr++;
  565.       unsigned char value_n = *ptr++;
  566.       const char *type = ids, *id, *value;
  567.       unsigned j; //Alone Coder 0.36.7
  568.       for (/*unsigned*/ j = 0; j < type_n; j++) {
  569.          if (!*type) break;
  570.          while (*(const short*)type) type++;
  571.          type += 2;
  572.       }
  573.       if (!*type) type = id = "??"; else {
  574.          id = type + strlen(type) + 1;
  575.          for (j = 0; j < id_n; j++) {
  576.             if (!*id) { id = "??"; break; }
  577.             id += strlen(id)+1;
  578.          }
  579.       }
  580.       switch (value_n) {
  581.          case 0: value = "compatible with"; break;
  582.          case 1: value = "uses"; break;
  583.          case 2: value = "compatible, but doesn't use"; break;
  584.          case 3: value = "incompatible with"; break;
  585.          default: value = "??";
  586.       }
  587.       char bf[512]; sprintf(bf, "%s %s: %s", value, type, id);
  588.       named_cell(bf);
  589.    }
  590.    named_cell("-");
  591. }
  592.  
  593. int readTZX()
  594. {
  595.    unsigned char *ptr = snbuf;
  596.    closetape();
  597.    unsigned size, pause, i, j, n, t, t0;
  598.    unsigned char pl, last;
  599.    unsigned char *end;
  600.    char *p;
  601.    unsigned loop_n = 0, loop_p;
  602.    unsigned TzxVer = (unsigned(ptr[8]) << 8U) | unsigned(ptr[9]);
  603.    char nm[512];
  604.  
  605.    ptr += 10; // ╧Ёюяєёъ чруюыютър
  606.  
  607.    while (ptr < snbuf+snapsize)
  608.    {
  609.       switch (*ptr++) {
  610.          case 0x10: // normal block
  611.             alloc_infocell();
  612.             size = *(unsigned short*)(ptr+2);
  613.             pause = *(unsigned short*)ptr;
  614.             ptr += 4;
  615.             desc(ptr, size, tapeinfo[tape_infosize].desc);
  616.             tape_infosize++;
  617.             makeblock(ptr, size, 2168, 667, 735, 855, 1710,
  618.                 (*ptr < 4) ? 8064 : 3220, pause);
  619.             ptr += size;
  620.             break;
  621.          case 0x11: // turbo block
  622.             alloc_infocell();
  623.             size = 0xFFFFFF & *(unsigned*)(ptr+0x0F);
  624.             desc(ptr + 0x12, size, tapeinfo[tape_infosize].desc);
  625.             tape_infosize++;
  626.             makeblock(ptr + 0x12, size,
  627.                *(unsigned short*)ptr, *(unsigned short*)(ptr+2),
  628.                *(unsigned short*)(ptr+4), *(unsigned short*)(ptr+6),
  629.                *(unsigned short*)(ptr+8), *(unsigned short*)(ptr+10),
  630.                *(unsigned short*)(ptr+13), ptr[12]);
  631.             // todo: test used bits - ptr+12
  632.             ptr += size + 0x12;
  633.             break;
  634.          case 0x12: // pure tone
  635.             create_appendable_block();
  636.             pl = u8(find_pulse(*(unsigned short*)ptr));
  637.             n = *(unsigned short*)(ptr+2);
  638.             reserve(n);
  639.             for (i = 0; i < n; i++) tape_image[tape_imagesize++] = pl;
  640.             ptr += 4;
  641.             break;
  642.          case 0x13: // sequence of pulses of different lengths
  643.             create_appendable_block();
  644.             n = *ptr++;
  645.             reserve(n);
  646.             for (i = 0; i < n; i++, ptr += 2)
  647.                tape_image[tape_imagesize++] = find_pulse(*(unsigned short*)ptr);
  648.             break;
  649.          case 0x14: // pure data block
  650.             create_appendable_block();
  651.             size = 0xFFFFFF & *(unsigned*)(ptr+7);
  652.             makeblock(ptr + 0x0A, size, 0, 0, 0, *(unsigned short*)ptr,
  653.                       *(unsigned short*)(ptr+2), -1U, *(unsigned short*)(ptr+5), ptr[4]);
  654.             ptr += size + 0x0A;
  655.             break;
  656.          case 0x15: // direct recording
  657.             size = 0xFFFFFF & *(unsigned*)(ptr+5);
  658.             t0 = *(unsigned short*)ptr;
  659.             pause = *(unsigned short*)(ptr+2);
  660.             last = ptr[4];
  661.             named_cell("direct recording");
  662.             ptr += 8;
  663.             pl = 0; n = 0;
  664.             for(i = 0; i < size; i++) // count number of pulses
  665.             {
  666.                 for(j = 0x80; j; j >>= 1)
  667.                 {
  668.                     if((ptr[i] ^ pl) & j)
  669.                     {
  670.                         n++;
  671.                         pl ^= -1;
  672.                     }
  673.                 }
  674.             }
  675.             t = 0; pl = 0;
  676.             reserve(n+2);
  677.             for (i = 1; i < size; i++, ptr++) // find pulses
  678.                for (j = 0x80; j; j >>= 1) {
  679.                   t += t0;
  680.                   if ((*ptr ^ pl) & j) {
  681.                      tape_image[tape_imagesize++] = find_pulse(t);
  682.                      pl ^= -1; t = 0;
  683.                   }
  684.                }
  685.             // find pulses - last byte
  686.             for (j = 0x80; j != (unsigned char)(0x80 >> last); j >>= 1) {
  687.                t += t0;
  688.                if ((*ptr ^ pl) & j) {
  689.                   tape_image[tape_imagesize++] = find_pulse(t);
  690.                   pl ^= -1; t = 0;
  691.                }
  692.             }
  693.             ptr++;
  694.             tape_image[tape_imagesize++] = find_pulse(t); // last pulse ???
  695.             if (pause) tape_image[tape_imagesize++] = find_pulse(pause*3500);
  696.             break;
  697.          case 0x20: // pause (silence) or 'stop the tape' command
  698.             pause = *(unsigned short*)ptr;
  699.             sprintf(nm, pause? "pause %d ms" : "stop the tape", pause);
  700.             named_cell(nm);
  701.             reserve(2); ptr += 2;
  702.             if (!pause) { // at least 1ms pulse as specified in TZX 1.13
  703.                tape_image[tape_imagesize++] = find_pulse(3500);
  704.                pause = -1U;
  705.             } else pause *= 3500;
  706.             tape_image[tape_imagesize++] = find_pulse(pause);
  707.             break;
  708.          case 0x21: // group start
  709.             n = *ptr++;
  710.             named_cell(ptr, n); ptr += n;
  711.             appendable = 1;
  712.             break;
  713.          case 0x22: // group end
  714.             break;
  715.          case 0x23: // jump to block
  716.             named_cell("* jump"); ptr += 2;
  717.             break;
  718.          case 0x24: // loop start
  719.             loop_n = *(unsigned short*)ptr; loop_p = tape_imagesize; ptr += 2;
  720.             break;
  721.          case 0x25: // loop end
  722.             if (!loop_n) break;
  723.             size = tape_imagesize - loop_p;
  724.             reserve((loop_n-1) * size);
  725.             for (i = 1; i < loop_n; i++)
  726.                memcpy(tape_image + loop_p + i*size, tape_image + loop_p, size);
  727.             tape_imagesize += (loop_n-1) * size;
  728.             loop_n = 0;
  729.             break;
  730.          case 0x26: // call
  731.             named_cell("* call"); ptr += 2 + 2 * *(unsigned short*)ptr;
  732.             break;
  733.          case 0x27: // ret
  734.             named_cell("* return");
  735.             break;
  736.          case 0x28: // select block
  737.             {
  738.                 int l = _countof(nm);
  739.                 l -= sprintf(nm, "* choice: ");
  740.                 n = ptr[2];
  741.                 p = (char*)ptr+3;
  742.  
  743.                 for (i = 0; i < n; i++)
  744.                 {
  745.                    size = *(unsigned char*)(p+2);
  746.                    l -= size;
  747.                    if(i)
  748.                        l -= 4;
  749.  
  750.                    if(l >= 0)
  751.                    {
  752.                        if (i)
  753.                            strcat(nm, " / ");
  754.  
  755.                        char *q = nm + strlen(nm);
  756.                        memcpy(q, p+3, size);
  757.                        q[size] = 0;
  758.                    }
  759.  
  760.                    p += size+3;
  761.                 }
  762.                 named_cell(nm);
  763.                 ptr += 2 + *(unsigned short*)ptr;
  764.             }
  765.             break;
  766.          case 0x2A: // stop if 48k
  767.             named_cell("* stop if 48K");
  768.             ptr += 4 + *(unsigned*)ptr;
  769.             break;
  770.          case 0x30: // text description
  771.             n = *ptr++;
  772.             named_cell(ptr, n); ptr += n;
  773.             appendable = 1;
  774.             break;
  775.          case 0x31: // message block
  776.             named_cell("- MESSAGE BLOCK ");
  777.             end = ptr + 2 + ptr[1]; pl = *end; *end = 0;
  778.             for (p = (char*)ptr+2; p < (const char*)end; p++)
  779.                if (*p == 0x0D) *p = 0;
  780.             for (p = (char*)ptr+2; p < (const char*)end; p += strlen(p)+1)
  781.                named_cell(p);
  782.             *end = pl; ptr = end;
  783.             named_cell("-");
  784.             break;
  785.          case 0x32: // archive info
  786.             named_cell("- ARCHIVE INFO ");
  787.             p = (char*)ptr + 3;
  788.             for (i = 0; i < ptr[2]; i++) {
  789.                const char *info;
  790.                switch (*p++) {
  791.                   case 0: info = "Title"; break;
  792.                   case 1: info = "Publisher"; break;
  793.                   case 2: info = "Author"; break;
  794.                   case 3: info = "Year"; break;
  795.                   case 4: info = "Language"; break;
  796.                   case 5: info = "Type"; break;
  797.                   case 6: info = "Price"; break;
  798.                   case 7: info = "Protection"; break;
  799.                   case 8: info = "Origin"; break;
  800.                   case -1:info = "Comment"; break;
  801.                   default:info = "info"; break;
  802.                }
  803.                unsigned size = *(BYTE*)p+1;
  804.                char tmp = p[size]; p[size] = 0;
  805.                sprintf(nm, "%s: %s", info, p+1);
  806.                p[size] = tmp; p += size;
  807.                named_cell(nm);
  808.             }
  809.             named_cell("-");
  810.             ptr += 2 + *(unsigned short*)ptr;
  811.             break;
  812.          case 0x33: // hardware type
  813.             parse_hardware(ptr);
  814.             ptr += 1 + 3 * *ptr;
  815.             break;
  816.          case 0x34: // emulation info
  817.             named_cell("* emulation info"); ptr += 8;
  818.             break;
  819.          case 0x35: // custom info
  820.             if (!memcmp(ptr, "POKEs           ", 16)) {
  821.                named_cell("- POKEs block ");
  822.                named_cell(ptr+0x15, ptr[0x14]);
  823.                p = (char*)ptr + 0x15 + ptr[0x14];
  824.                n = *(unsigned char*)p++;
  825.                for (i = 0; i < n; i++) {
  826.                   named_cell(p+1, *(unsigned char*)p);
  827.                   p += *p+1;
  828.                   t = *(unsigned char*)p++;
  829.                   strcpy(nm, "POKE ");
  830.                   for (j = 0; j < t; j++) {
  831.                      sprintf(nm+strlen(nm), "%d,", *(unsigned short*)(p+1));
  832.                      sprintf(nm+strlen(nm), *p & 0x10 ? "nn" : "%d", *(unsigned char*)(p+3));
  833.                      if (!(*p & 0x08)) sprintf(nm+strlen(nm), "(page %d)", *p & 7);
  834.                      strcat(nm, "; "); p += 5;
  835.                   }
  836.                   named_cell(nm);
  837.                }
  838.                *(unsigned*)nm = '-';
  839.             }
  840.             else
  841.             {
  842.                 sprintf(nm, "* custom info: %s", ptr);
  843.                 nm[15 + 16] = 0;
  844.             }
  845.             named_cell(nm);
  846.             ptr += 0x14 + *(unsigned*)(ptr+0x10);
  847.             break;
  848.          case 0x40: // snapshot
  849.             named_cell("* snapshot"); ptr += 4 + (0xFFFFFF & *(unsigned*)(ptr + 1));
  850.             break;
  851.          default:
  852.             if(TzxVer >= 0x10A)
  853.             {
  854.                 // ┬ эрўрых ърцфюую эхёЄрэфрЁЄэюую сыюър шфхЄ хую фышэр
  855.                 sprintf(nm, "* unknown id: 0x%X", ptr[-1]);
  856.                 named_cell(nm);
  857.                 u32 Skip = *(u32 *)ptr;
  858.                 ptr += Skip + sizeof(u32);
  859.             }
  860.             else
  861.             {
  862.                 ptr += snapsize;
  863.             }
  864.       }
  865.    }
  866.    for (i = 0; i < tape_infosize; i++) {
  867.       if (*(short*)tapeinfo[i].desc == WORD2('*', ' '))
  868.       {
  869.          if(strlen(tapeinfo[i].desc) < _countof(tapeinfo[i].desc) - sizeof(" [UNSUPPORTED]"))
  870.              strcat(tapeinfo[i].desc, " [UNSUPPORTED]");
  871.          else
  872.          {
  873.              strcpy(tapeinfo[i].desc + _countof(tapeinfo[i].desc) - sizeof(" [UNSUPPORTED]"), " [UNSUPPORTED]");
  874.          }
  875.       }
  876.       if (*tapeinfo[i].desc == '-')
  877.          while (strlen(tapeinfo[i].desc) < sizeof(tapeinfo[i].desc)-1)
  878.             strcat(tapeinfo[i].desc, "-");
  879.    }
  880.    if(tape_imagesize && tape_pulse[tape_image[tape_imagesize - 1]] < 350000)
  881.    {
  882.        // small pause [rqd for 3ddeathchase]
  883.        reserve(1);
  884.        tape_image[tape_imagesize++] = find_pulse(350000);
  885.    }
  886.    find_tape_sizes();
  887.    return ptr == snbuf+snapsize;
  888. }
  889.  
  890. unsigned char tape_bit() // used in io.cpp & sound.cpp
  891. {
  892.    __int64 cur = comp.t_states + cpu.t;
  893.    if (cur < comp.tape.edge_change)
  894.        return (unsigned char)comp.tape.tape_bit;
  895.    while (comp.tape.edge_change < cur)
  896.    {
  897.       if (!temp.sndblock)
  898.       {
  899.          unsigned t = (unsigned)(comp.tape.edge_change - comp.t_states - temp.cpu_t_at_frame_start);
  900.          if ((int)t >= 0)
  901.          {
  902.             unsigned tape_in = unsigned(conf.sound.micin_vol) & comp.tape.tape_bit;
  903.             comp.tape.sound.update(t, tape_in, tape_in);
  904.          }
  905.       }
  906.       unsigned pulse; comp.tape.tape_bit ^= -1U;
  907.       if (comp.tape.play_pointer == comp.tape.end_of_tape ||
  908.           (pulse = tape_pulse[*comp.tape.play_pointer++]) == -1U)
  909.               stop_tape();
  910.       else
  911.           comp.tape.edge_change += pulse;
  912.    }
  913.    return (unsigned char)comp.tape.tape_bit;
  914. }
  915.  
  916. void fast_tape()
  917. {
  918.    unsigned char *ptr = am_r(cpu.pc);
  919.    unsigned p = *(unsigned*)ptr;
  920.    if (p == WORD4(0x3D,0x20,0xFD,0xA7))
  921.    { // dec a:jr nz,$-1
  922.       cpu.t += ((unsigned char)(cpu.a-1))*16; cpu.a = 1;
  923.       return;
  924.    }
  925.    if ((unsigned short)p == WORD2(0x10,0xFE))
  926.    { // djnz $
  927.       cpu.t += ((unsigned char)(cpu.b-1))*13; cpu.b = 1;
  928.       return;
  929.    }
  930.    if ((unsigned short)p == WORD2(0x3D,0xC2) && (cpu.pc & 0xFFFF)==(p>>16))
  931.    { // dec a:jp nz,$-1
  932.       cpu.t += ((unsigned char)(cpu.a-1))*14; cpu.a = 1;
  933.       return;
  934.    }
  935.    if ((p | WORD4(0,0,0,0xFF)) == WORD4(0x04,0xC8,0x3E,0xFF))
  936.    {
  937.       if (*(unsigned*)(ptr+4) == WORD4(0xDB,0xFE,0x1F,0xD0) &&
  938.           *(unsigned*)(ptr+8) == WORD4(0xA9,0xE6,0x20,0x28) && ptr[12] == 0xF3)
  939.       { // find edge (rom routine)
  940.          for (;;)
  941.          {
  942.             if (cpu.b == 0xFF)
  943.                 return;
  944.             if ((tape_bit() ? 0x20 : 0) ^ (cpu.c & 0x20))
  945.                 return;
  946.             cpu.b++; cpu.t += 59;
  947.          }
  948.       }
  949.       if (*(unsigned*)(ptr+4) == WORD4(0xDB,0xFE,0xCB,0x1F) &&
  950.           *(unsigned*)(ptr+8) == WORD4(0xA9,0xE6,0x20,0x28) && ptr[12] == 0xF3)
  951.       { // rra,ret nc => rr a (popeye2)
  952.          for (;;)
  953.          {
  954.             if (cpu.b == 0xFF) return;
  955.             if ((tape_bit() ^ cpu.c) & 0x20) return;
  956.             cpu.b++; cpu.t += 58;
  957.          }
  958.       }
  959.       if (*(unsigned*)(ptr+4) == WORD4(0xDB,0xFE,0x1F,0x00) &&
  960.           *(unsigned*)(ptr+8) == WORD4(0xA9,0xE6,0x20,0x28) && ptr[12] == 0xF3)
  961.       { // ret nc nopped (some bleep loaders)
  962.          for (;;)
  963.          {
  964.             if (cpu.b == 0xFF) return;
  965.             if ((tape_bit() ^ cpu.c) & 0x20) return;
  966.             cpu.b++; cpu.t += 58;
  967.          }
  968.       }
  969.       if (*(unsigned*)(ptr+4) == WORD4(0xDB,0xFE,0xA9,0xE6) &&
  970.           *(unsigned*)(ptr+8) == WORD4(0x40,0xD8,0x00,0x28) && ptr[12] == 0xF3)
  971.       { // no rra, no break check (rana rama)
  972.          for (;;)
  973.          {
  974.             if (cpu.b == 0xFF) return;
  975.             if ((tape_bit() ^ cpu.c) & 0x40) return;
  976.             cpu.b++; cpu.t += 59;
  977.          }
  978.       }
  979.       if (*(unsigned*)(ptr+4) == WORD4(0xDB,0xFE,0x1F,0xA9) &&
  980.           *(unsigned*)(ptr+8) == WORD4(0xE6,0x20,0x28,0xF4))
  981.       { // ret nc skipped: routine without BREAK checking (ZeroMusic & JSW)
  982.          for (;;)
  983.          {
  984.             if (cpu.b == 0xFF) return;
  985.             if ((tape_bit() ^ cpu.c) & 0x20) return;
  986.             cpu.b++; cpu.t += 54;
  987.          }
  988.       }
  989.    }
  990.    if ((p | WORD4(0,0,0,0xFF)) == WORD4(0x04,0x20,0x03,0xFF) &&
  991.         ptr[6] == 0xDB && *(unsigned*)(ptr+8) == WORD4(0x1F,0xC8,0xA9,0xE6) &&
  992.         (*(unsigned*)(ptr+0x0C) | WORD4(0,0,0,0xFF)) == WORD4(0x20,0x28,0xF1,0xFF))
  993.    { // find edge from Donkey Kong
  994.       for (;;) {
  995.          if (cpu.b == 0xFF) return;
  996.          if ((tape_bit() ^ cpu.c) & 0x20) return;
  997.          cpu.b++; cpu.t += 59;
  998.       }
  999.    }
  1000.    if ((p | WORD4(0,0xFF,0,0)) == WORD4(0x3E,0xFF,0xDB,0xFE) &&
  1001.        *(unsigned*)(ptr+4) == WORD4(0xA9,0xE6,0x40,0x20) &&
  1002.        (*(unsigned*)(ptr+8) | WORD4(0xFF,0,0,0)) == WORD4(0xFF,0x05,0x20,0xF4))
  1003.    { // lode runner
  1004.       for (;;)
  1005.       {
  1006.          if (cpu.b == 1) return;
  1007.          if ((tape_bit() ^ cpu.c) & 0x40) return;
  1008.          cpu.t += 52; cpu.b--;
  1009.       }
  1010.    }
  1011. }
  1012.  
  1013. // ╧хЁхїтрЄ ёЄюшЄ эр рфЁхёх 0x56B (фы  яюффхЁцъш эхёЄрэфрЁЄэ√ї чруЁєчўшъют)
  1014. void tape_traps()
  1015. {
  1016.     unsigned pulse;
  1017.  
  1018.     // ┬їюф (фы  рфЁхёр 0x0556, фы  0x56B чэрўхэш  єцх шёяюЁўхэ√):
  1019.     // A - Їыруют√щ срщЄ (фюыцхэ ёютярфрЄ№ ё Їыруют√ь срщЄюь чряшёрээ√ь эр ыхэЄх)
  1020.     // IX - рфЁхё чруЁєчъш
  1021.     // DE - фышэр чруЁєцрхьюую сыюър
  1022.     // CF - 0 - verify, 1 - load
  1023.     //
  1024.     // ┬√їюф:
  1025.     // CF - 0 - ю°шсюъ эхЄ, 1 - ю°шсър чруЁєчъш
  1026.  
  1027.     /*
  1028.     0x0556 inc    d                   ; ═х ьхэ хЄ CF
  1029.            ex     af, af'             ; A ш CF ёюїЁрэ ■Єё  т af'
  1030.            dec    d
  1031.            di
  1032.            ld     a,0xF
  1033.            out    (0xFE),a
  1034.            ld     hl, 0x53F
  1035.            push   hl
  1036.            in     a,(0xFE)
  1037.     0x0564 rra
  1038.            and    0x20
  1039.            or     2
  1040.     0x056A ld     c,a
  1041.     0x056B ret    nz
  1042.     */
  1043.  
  1044.     bool IsLoad = ((cpu.alt.f & CF) != 0);
  1045.     u8 Flag = cpu.alt.a;
  1046.  
  1047.     // ─ы  чруЁєчўшъют ъюЄюЁ√х эх яЁюїюф Є ўхЁхч рфЁхё 0x0564 фхырхЄё  яЁшэєфшЄхы№э√щ чряєёъ ыхэЄ√
  1048.     // ╧ЁшьхЁ Єръшї чруЁєчўшъют - чруЁєчўшъш юЄ Bill Gilbert (єёЄрэртыштр■Є эхёЄрэфрЁЄэ√х ЎтхЄр сюЁф■Ёр ш
  1049.     // фхыр■Є яхЁхїюф эр 0x056A)
  1050.     if(!comp.tape.play_pointer)
  1051.     {
  1052.         start_tape();
  1053.     }
  1054.  
  1055.     do
  1056.     {
  1057.         if(comp.tape.play_pointer >= comp.tape.end_of_tape ||
  1058.             (pulse = tape_pulse[*comp.tape.play_pointer++]) == -1U)
  1059.         {
  1060.             stop_tape();
  1061.             return;
  1062.         }
  1063.     } while(pulse > 770);
  1064.     comp.tape.play_pointer++;
  1065.  
  1066.     // loading flag byte
  1067.     cpu.l = 0;
  1068.     cpu.h = 0;
  1069.     for(unsigned bit = 0x80; bit; bit >>= 1)
  1070.     {
  1071.         if(comp.tape.play_pointer >= comp.tape.end_of_tape ||
  1072.             (pulse = tape_pulse[*comp.tape.play_pointer++]) == -1U)
  1073.         {
  1074.             stop_tape();
  1075.             cpu.pc = 0x05DF;
  1076.             return;
  1077.         }
  1078.         cpu.l |= (pulse > 1240) ? bit : 0;
  1079.         comp.tape.play_pointer++;
  1080.     }
  1081.  
  1082.     if(cpu.l != Flag) // ╧Ёш эхёютярфхэшш Їыруютюую срщЄр яЁюяєёърхь сыюъ фрээ√ї
  1083.     {
  1084.         IsLoad = false;
  1085.     }
  1086.  
  1087.     cpu.h ^= cpu.l;
  1088.  
  1089.     // loading data
  1090.     do
  1091.     {
  1092.         cpu.l = 0;
  1093.         for(unsigned bit = 0x80; bit; bit >>= 1)
  1094.         {
  1095.             if(comp.tape.play_pointer >= comp.tape.end_of_tape ||
  1096.                 (pulse = tape_pulse[*comp.tape.play_pointer++]) == -1U)
  1097.             {
  1098.                 stop_tape();
  1099.                 cpu.pc = 0x05DF;
  1100.                 return;
  1101.             }
  1102.             cpu.l |= (pulse > 1240) ? bit : 0;
  1103.             comp.tape.play_pointer++;
  1104.         }
  1105.         cpu.h ^= cpu.l;
  1106.         if(IsLoad)
  1107.         {
  1108.             cpu.DbgMemIf->wm(cpu.ix, cpu.l);
  1109.         }
  1110.         cpu.ix++;
  1111.         cpu.de--;
  1112.     } while(cpu.de & 0xFFFF);
  1113.  
  1114.     // loading CRC
  1115.     cpu.l = 0;
  1116.     for(unsigned bit = 0x80; bit; bit >>= 1)
  1117.     {
  1118.         if(comp.tape.play_pointer >= comp.tape.end_of_tape ||
  1119.             (pulse = tape_pulse[*comp.tape.play_pointer++]) == -1U)
  1120.         {
  1121.             stop_tape();
  1122.             cpu.pc = 0x05DF;
  1123.             return;
  1124.         }
  1125.         cpu.l |= (pulse > 1240) ? bit : 0;
  1126.         comp.tape.play_pointer++;
  1127.     }
  1128.     cpu.h ^= cpu.l;
  1129.     cpu.pc = 0x05DF; // ld a,h / cp 01 / ret
  1130.     cpu.bc = 0xB001;
  1131.  
  1132.     comp.tape.play_pointer++;
  1133.     stop_tape();
  1134.  
  1135.     /*cpu.pc=0x0604; // the old one
  1136.     unsigned pulse;
  1137.     pulse = tape_pulse[*comp.tape.play_pointer++];
  1138.     if(pulse == -1) stop_tape();
  1139.     else{
  1140.       comp.t_states+=pulse;
  1141.       comp.tape.edge_change = comp.t_states + cpu.t + 520;
  1142.  
  1143.       cpu.b+=(pulse-520)/56;
  1144.       cpu.f|=CF;
  1145.     }*/
  1146. }
  1147.