MCPcopy Create free account
hub / github.com/BlitterStudio/amiberry / drive_write_pcdos

Function drive_write_pcdos

src/disk.cpp:2725–2828  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2723}
2724
2725static int drive_write_pcdos (drive *drv, struct zfile *zf, bool count)
2726{
2727 int i;
2728 int drvsec = drv->num_secs;
2729 int fwlen = FLOPPY_WRITE_LEN * drv->ddhd;
2730 int length = 2 * fwlen;
2731 uae_u16 *mbuf = drv->bigmfmbuf;
2732 uae_u16 *mend = mbuf + length;
2733 int secwritten = 0, seccnt = 0;
2734 int shift = 0, sector = -1;
2735 int sectable[24];
2736 uae_u8 secbuf[3 + 1 + 512];
2737 uae_u8 mark;
2738 uae_u16 crc;
2739
2740 memset (sectable, 0, sizeof sectable);
2741 memcpy (mbuf + fwlen, mbuf, fwlen * sizeof (uae_u16));
2742 mend -= 518;
2743 secbuf[0] = secbuf[1] = secbuf[2] = 0xa1;
2744 secbuf[3] = 0xfb;
2745
2746 while (seccnt < drvsec) {
2747 int mfmcount;
2748
2749 mfmcount = 0;
2750 while (getmfmword (mbuf, shift) != 0x4489) {
2751 mfmcount++;
2752 if (mbuf >= mend)
2753 return -1;
2754 shift++;
2755 if (shift == 16) {
2756 shift = 0;
2757 mbuf++;
2758 }
2759 if (sector >= 0 && mfmcount / 16 >= 43)
2760 sector = -1;
2761 }
2762
2763 mfmcount = 0;
2764 while (getmfmword (mbuf, shift) == 0x4489) {
2765 mfmcount++;
2766 if (mbuf >= mend)
2767 return -1;
2768 mbuf++;
2769 }
2770 if (mfmcount < 3) // ignore if less than 3 sync markers
2771 continue;
2772
2773 mark = mfmdecode(&mbuf, shift);
2774 if (mark == 0xfe) {
2775 uae_u8 tmp[8];
2776 uae_u8 cyl, head, size;
2777
2778 cyl = mfmdecode (&mbuf, shift);
2779 head = mfmdecode (&mbuf, shift);
2780 sector = mfmdecode (&mbuf, shift);
2781 size = mfmdecode (&mbuf, shift);
2782 crc = (mfmdecode (&mbuf, shift) << 8) | mfmdecode (&mbuf, shift);

Callers 2

drive_write_dataFunction · 0.85
disk_reserved_getinfoFunction · 0.85

Calls 6

get_crc16Function · 0.85
zfile_fseekFunction · 0.85
zfile_fwriteFunction · 0.85
getmfmwordFunction · 0.70
mfmdecodeFunction · 0.70
write_logFunction · 0.70

Tested by

no test coverage detected