2017-09-13 01:58:18 -04:00
|
|
|
/*
|
2018-03-19 01:02:04 +01:00
|
|
|
* VARCem Virtual ARchaeological Computer EMulator.
|
|
|
|
|
* An emulator of (mostly) x86-based PC systems and devices,
|
|
|
|
|
* using the ISA,EISA,VLB,MCA and PCI system buses, roughly
|
|
|
|
|
* spanning the era between 1981 and 1995.
|
2017-09-13 01:58:18 -04:00
|
|
|
*
|
2018-03-19 01:02:04 +01:00
|
|
|
* This file is part of the VARCem Project.
|
2017-09-13 01:58:18 -04:00
|
|
|
*
|
|
|
|
|
* Implementation of the PCjs JSON floppy image format.
|
|
|
|
|
*
|
2019-12-05 21:36:28 +01:00
|
|
|
* Version: @(#)fdd_json.c 1.0.7 2019/12/05
|
2017-09-13 01:58:18 -04:00
|
|
|
*
|
|
|
|
|
* Author: Fred N. van Kempen, <decwiz@yahoo.com>
|
2017-10-12 14:25:17 -04:00
|
|
|
*
|
2019-12-05 21:36:28 +01:00
|
|
|
* Copyright 2017-2019 Fred N. van Kempen.
|
2018-03-19 01:02:04 +01:00
|
|
|
*
|
|
|
|
|
* Redistribution and use in source and binary forms, with
|
|
|
|
|
* or without modification, are permitted provided that the
|
|
|
|
|
* following conditions are met:
|
|
|
|
|
*
|
|
|
|
|
* 1. Redistributions of source code must retain the entire
|
|
|
|
|
* above notice, this list of conditions and the following
|
|
|
|
|
* disclaimer.
|
|
|
|
|
*
|
|
|
|
|
* 2. Redistributions in binary form must reproduce the above
|
|
|
|
|
* copyright notice, this list of conditions and the
|
|
|
|
|
* following disclaimer in the documentation and/or other
|
|
|
|
|
* materials provided with the distribution.
|
|
|
|
|
*
|
|
|
|
|
* 3. Neither the name of the copyright holder nor the names
|
|
|
|
|
* of its contributors may be used to endorse or promote
|
|
|
|
|
* products derived from this software without specific
|
|
|
|
|
* prior written permission.
|
|
|
|
|
*
|
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
|
|
|
|
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
|
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
2017-09-13 01:58:18 -04:00
|
|
|
*/
|
2018-05-21 19:04:05 +02:00
|
|
|
#include <stdarg.h>
|
2017-09-25 04:31:20 -04:00
|
|
|
#include <stdint.h>
|
2018-05-21 19:04:05 +02:00
|
|
|
#include <stdio.h>
|
2017-09-25 04:31:20 -04:00
|
|
|
#include <string.h>
|
2017-09-13 01:58:18 -04:00
|
|
|
#include <stdlib.h>
|
2017-09-25 04:31:20 -04:00
|
|
|
#include <wchar.h>
|
2018-05-21 19:04:05 +02:00
|
|
|
#define HAVE_STDARG_H
|
2017-10-17 01:59:09 -04:00
|
|
|
#include "../86box.h"
|
Added the IBM 5161 ISA expansion for PC and XT;
Cleaned up the parallel port emulation, added IRQ support, and made enabling/disabling per port;
Added the Award 430NX and the Intel Classic/PCI (Alfredo, 420TX);
Finished the 586MC1;
Added 8087 emulation;
Moved Cyrix 6x86'es to the Dev branch;
Sanitized/cleaned up memregs.c/h and intel.c/h;
Split the chipsets from machines and sanitized Port 92 emulation;
Added support for the 15bpp mode to the Compaq ATI 28800;
Moved the MR 386DX and 486 machines to the Dev branch;
Ported the new dynamic recompiler from PCem, but it remains in Dev branch until after v2.00;
Ported the new timer code from PCem;
Cleaned up the CPU table of unused stuff and better optimized its structure;
Ported the Open-XT and Open-AT from VARCem, the Open-AT is in the Dev branch;
Ported the XT MFM controller rewrite and adding of more controllers (incl. two RLL ones), from VARCem;
Added the AHA-1540A and the BusTek BT-542B;
Moved the Sumo SCSI-AT to the Dev branch;
Minor IDE, FDC, and floppy drive code clean-ups;
Made NCR 5380/53C400-based cards' BIOS address configurable;
Got rid of the legacy romset variable;
Unified (video) buffer and buffer32 into one and make the unified buffer 32-bit;
Added the Amstead PPC512 per PCem patch by John Elliott;
Switched memory mapping granularity from 16k to 4k (less than 1k not possible due to internal pages);
Rewrote the CL-GD 54xx blitter, fixes Win-OS/2 on the 54x6 among other thing;
Added the Image Manager 1024 and Professional Graphics Controller per PCem patch by John Elliott and work done on VARCem;
Added Headland HT-216, GC-205 and Video 7 VGA 1024i emulation based on PCem commit;
Implemented the fuction keys for the Toshiba T1000/T1200/T3100 enhancement;
Amstrad MegaPC does now works correctly with non-internal graphics card;
The SLiRP code no longer casts a packed struct type to a non-packed struct type;
The Xi8088 and PB410a no longer hang on 86Box when PS/2 mouse is not present;
The S3 Virge on BeOS is no longer broken (was broken by build #1591);
OS/2 2.0 build 6.167 now sees key presses again;
Xi8088 now work on CGA again;
86F images converted from either the old or new variants of the HxC MFM format now work correctly;
Hardware interrupts with a vector of 0xFF are now handled correctly;
OPTi 495SX boards no longer incorrectly have 64 MB maximum RAM when 32 MB is correct;
Fixed VNC keyboard input bugs;
Fixed AT RTC periodic interrupt - Chicago 58s / 73f / 73g / 81 MIDI play no longer hangs with the build's own VTD driver;
Fixed mouse polling with internal mice - Amstrad and Olivetti mice now work correctly;
Triones ATAPI DMA driver now correctly reads a file at the end of a CD image with a sectors number not divisible by 4;
Compaq Portable now works with all graphics cards;
Fixed various MDSI Genius bugs;
Added segment limit checks and improved page fault checks for several CPU instructions - Memphis 15xx WINSETUP and Chicago 58s WINDISK.CPL no longer issue a GPF, and some S3 drivers that used to have glitches, now work correctly;
Further improved the 808x emulation, also fixes the noticably choppy sound when using 808x CPU's, also fixes #355;
OS/2 installer no logner locks up on splash screen on PS/2 Model 70 and 80, fixes #400.
Fixed several Amstead bugs, GEM no longer crashes on the Amstrad 1640, fixes #391.
Ported John Elliott's Amstrad fixes and improvement from PCem, and fixed the default language so it's correctly Engliish, fixes #278, fixes #389.
Fixed a minor IDE timing bug, fixes #388.
Fixed Toshiba T1000 RAM issues, fixes #379.
Fixed EGA/(S)VGA overscan border handling, fixes #378;
Got rid of the now long useless IDE channel 2 auto-removal, fixes #370;
Fixed the BIOS files used by the AMSTRAD PC1512, fixes #366;
Ported the Unicode CD image file name fix from VARCem, fixes #365;
Fixed high density floppy disks on the Xi8088, fixes #359;
Fixed some bugs in the Hercules emulation, fixes #346, fixes #358;
Fixed the SCSI hard disk mode sense pages, fixes #356;
Removed the AMI Unknown 386SX because of impossibility to identify the chipset, closes #349;
Fixed bugs in the serial mouse emulation, fixes #344;
Compiled 86Box binaries now include all the required .DLL's, fixes #341;
Made some combo boxes in the Settings dialog slightly wider, fixes #276.
2019-09-20 14:02:30 +02:00
|
|
|
#include "../timer.h"
|
2017-10-12 14:25:17 -04:00
|
|
|
#include "../plat.h"
|
2017-09-13 01:58:18 -04:00
|
|
|
#include "fdd.h"
|
2019-12-05 21:36:28 +01:00
|
|
|
#include "fdd_86f.h"
|
2018-01-17 18:43:36 +01:00
|
|
|
#include "fdc.h"
|
|
|
|
|
#include "fdd_common.h"
|
|
|
|
|
#include "fdd_json.h"
|
2017-09-13 01:58:18 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
#define NTRACKS 256
|
|
|
|
|
#define NSIDES 2
|
2017-10-07 16:45:54 +02:00
|
|
|
#define NSECTORS 256
|
2017-09-13 01:58:18 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
|
uint8_t track, /* ID: track number */
|
|
|
|
|
side, /* side number */
|
|
|
|
|
sector; /* sector number 1.. */
|
|
|
|
|
uint16_t size; /* encoded size of sector */
|
|
|
|
|
uint8_t *data; /* allocated data for it */
|
|
|
|
|
} sector_t;
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
|
FILE *f;
|
|
|
|
|
|
|
|
|
|
/* Geometry. */
|
|
|
|
|
uint8_t tracks, /* number of tracks */
|
|
|
|
|
sides, /* number of sides */
|
|
|
|
|
sectors, /* number of sectors per track */
|
|
|
|
|
spt[NTRACKS][NSIDES]; /* number of sectors per track */
|
|
|
|
|
|
|
|
|
|
uint8_t track, /* current track */
|
|
|
|
|
side, /* current side */
|
|
|
|
|
sector[NSIDES]; /* current sector */
|
|
|
|
|
|
|
|
|
|
uint8_t dmf; /* disk is DMF format */
|
|
|
|
|
uint8_t interleave;
|
|
|
|
|
#if 0
|
|
|
|
|
uint8_t skew;
|
|
|
|
|
#endif
|
|
|
|
|
uint8_t gap2_len;
|
|
|
|
|
uint8_t gap3_len;
|
|
|
|
|
int track_width;
|
|
|
|
|
|
|
|
|
|
uint16_t disk_flags, /* flags for the entire disk */
|
|
|
|
|
track_flags; /* flags for the current track */
|
|
|
|
|
|
|
|
|
|
uint8_t interleave_ordered[NTRACKS][NSIDES];
|
|
|
|
|
|
|
|
|
|
sector_t sects[NTRACKS][NSIDES][NSECTORS];
|
|
|
|
|
} json_t;
|
|
|
|
|
|
|
|
|
|
|
2018-03-19 01:02:04 +01:00
|
|
|
static json_t *images[FDD_NUM];
|
2017-09-13 01:58:18 -04:00
|
|
|
|
|
|
|
|
|
2018-05-21 19:04:05 +02:00
|
|
|
#ifdef ENABLE_JSON_LOG
|
|
|
|
|
int json_do_log = ENABLE_JSON_LOG;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
json_log(const char *fmt, ...)
|
|
|
|
|
{
|
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
|
|
if (json_do_log)
|
|
|
|
|
{
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
|
pclog_ex(fmt, ap);
|
|
|
|
|
va_end(ap);
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-10-19 00:39:32 +02:00
|
|
|
#else
|
|
|
|
|
#define json_log(fmt, ...)
|
|
|
|
|
#endif
|
2018-05-21 19:04:05 +02:00
|
|
|
|
|
|
|
|
|
2017-09-13 01:58:18 -04:00
|
|
|
static void
|
2018-03-19 01:02:04 +01:00
|
|
|
handle(json_t *dev, char *name, char *str)
|
2017-09-13 01:58:18 -04:00
|
|
|
{
|
|
|
|
|
sector_t *sec = NULL;
|
|
|
|
|
uint32_t l, pat;
|
|
|
|
|
uint8_t *p;
|
|
|
|
|
char *sp;
|
|
|
|
|
int i, s;
|
|
|
|
|
|
|
|
|
|
/* Point to the currently selected sector. */
|
2018-03-19 01:02:04 +01:00
|
|
|
sec = &dev->sects[dev->track][dev->side][dev->dmf-1];
|
2017-09-13 01:58:18 -04:00
|
|
|
|
|
|
|
|
/* If no name given, assume sector is done. */
|
|
|
|
|
if (name == NULL) {
|
|
|
|
|
/* If no buffer, assume one with 00's. */
|
|
|
|
|
if (sec->data == NULL) {
|
|
|
|
|
sec->data = (uint8_t *)malloc(sec->size);
|
|
|
|
|
memset(sec->data, 0x00, sec->size);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Encode the sector size. */
|
2018-01-17 18:43:36 +01:00
|
|
|
sec->size = fdd_sector_size_code(sec->size);
|
2017-09-13 01:58:18 -04:00
|
|
|
|
|
|
|
|
/* Set up the rest of the Sector ID. */
|
2018-03-19 01:02:04 +01:00
|
|
|
sec->track = dev->track;
|
|
|
|
|
sec->side = dev->side;
|
2017-09-13 01:58:18 -04:00
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (! strcmp(name, "sector")) {
|
|
|
|
|
sec->sector = atoi(str);
|
|
|
|
|
sec->size = 512;
|
|
|
|
|
} else if (! strcmp(name, "length")) {
|
|
|
|
|
sec->size = atoi(str);
|
|
|
|
|
} else if (! strcmp(name, "pattern")) {
|
|
|
|
|
pat = atol(str);
|
|
|
|
|
|
|
|
|
|
if (sec->data == NULL)
|
|
|
|
|
sec->data = (uint8_t *)malloc(sec->size);
|
|
|
|
|
p = sec->data;
|
|
|
|
|
s = (sec->size / sizeof(uint32_t));
|
|
|
|
|
for (i=0; i<s; i++) {
|
|
|
|
|
l = pat;
|
|
|
|
|
*p++ = (l & 0x000000ff);
|
|
|
|
|
l >>= 8;
|
|
|
|
|
*p++ = (l & 0x000000ff);
|
|
|
|
|
l >>= 8;
|
|
|
|
|
*p++ = (l & 0x000000ff);
|
|
|
|
|
l >>= 8;
|
|
|
|
|
*p++ = (l & 0x000000ff);
|
|
|
|
|
}
|
|
|
|
|
} else if (! strcmp(name, "data")) {
|
|
|
|
|
if (sec->data == NULL)
|
|
|
|
|
sec->data = (uint8_t *)malloc(sec->size);
|
|
|
|
|
p = sec->data;
|
|
|
|
|
while (str && *str) {
|
|
|
|
|
sp = strchr(str, ',');
|
|
|
|
|
if (sp != NULL) *sp++ = '\0';
|
|
|
|
|
l = atol(str);
|
|
|
|
|
|
|
|
|
|
*p++ = (l & 0x000000ff);
|
|
|
|
|
l >>= 8;
|
|
|
|
|
*p++ = (l & 0x000000ff);
|
|
|
|
|
l >>= 8;
|
|
|
|
|
*p++ = (l & 0x000000ff);
|
|
|
|
|
l >>= 8;
|
|
|
|
|
*p++ = (l & 0x000000ff);
|
|
|
|
|
|
|
|
|
|
str = sp;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
unexpect(int c, int state, int level)
|
|
|
|
|
{
|
2018-05-21 19:04:05 +02:00
|
|
|
json_log("JSON: Unexpected '%c' in state %d/%d.\n", c, state, level);
|
2017-09-13 01:58:18 -04:00
|
|
|
|
|
|
|
|
return(-1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2018-03-19 01:02:04 +01:00
|
|
|
load_image(json_t *dev)
|
2017-09-13 01:58:18 -04:00
|
|
|
{
|
|
|
|
|
char buff[4096], name[32];
|
|
|
|
|
int c, i, j, state, level;
|
|
|
|
|
char *ptr;
|
|
|
|
|
|
2018-03-19 01:02:04 +01:00
|
|
|
if (dev->f == NULL) {
|
2018-05-21 19:04:05 +02:00
|
|
|
json_log("JSON: no file loaded!\n");
|
2017-09-13 01:58:18 -04:00
|
|
|
return(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Initialize. */
|
|
|
|
|
for (i=0; i<NTRACKS; i++) {
|
|
|
|
|
for (j=0; j<NSIDES; j++)
|
2018-03-19 01:02:04 +01:00
|
|
|
memset(dev->sects[i][j], 0x00, sizeof(sector_t));
|
2017-09-13 01:58:18 -04:00
|
|
|
}
|
2018-03-19 01:02:04 +01:00
|
|
|
dev->track = dev->side = dev->dmf = 0; /* "dmf" is "sector#" */
|
2017-09-13 01:58:18 -04:00
|
|
|
|
|
|
|
|
/* Now run the state machine. */
|
|
|
|
|
ptr = NULL;
|
|
|
|
|
level = state = 0;
|
|
|
|
|
while (state >= 0) {
|
|
|
|
|
/* Get a character from the input. */
|
2018-03-19 01:02:04 +01:00
|
|
|
c = fgetc(dev->f);
|
|
|
|
|
if ((c == EOF) || ferror(dev->f)) {
|
2017-09-13 01:58:18 -04:00
|
|
|
state = -1;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Process it. */
|
|
|
|
|
switch(state) {
|
|
|
|
|
case 0: /* read level header */
|
2018-03-19 01:02:04 +01:00
|
|
|
dev->dmf = 1;
|
2017-09-13 01:58:18 -04:00
|
|
|
if (c != '[') {
|
|
|
|
|
state = unexpect(c, state, level);
|
|
|
|
|
} else {
|
|
|
|
|
if (++level == 3)
|
|
|
|
|
state++;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 1: /* read sector header */
|
|
|
|
|
if (c != '{')
|
|
|
|
|
state = unexpect(c, state, level);
|
|
|
|
|
else
|
|
|
|
|
state++;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 2: /* begin sector data name */
|
|
|
|
|
if (c != '\"') {
|
|
|
|
|
state = unexpect(c, state, level);
|
|
|
|
|
} else {
|
|
|
|
|
ptr = name;
|
|
|
|
|
state++;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 3: /* read sector data name */
|
|
|
|
|
if (c == '\"') {
|
|
|
|
|
*ptr = '\0';
|
|
|
|
|
state++;
|
|
|
|
|
} else {
|
|
|
|
|
*ptr++ = c;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 4: /* end of sector data name */
|
|
|
|
|
if (c != ':') {
|
|
|
|
|
state = unexpect(c, state, level);
|
|
|
|
|
} else {
|
|
|
|
|
ptr = buff;
|
|
|
|
|
state++;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 5: /* read sector value data */
|
|
|
|
|
switch(c) {
|
|
|
|
|
case ',':
|
|
|
|
|
case '}':
|
|
|
|
|
*ptr = '\0';
|
2018-03-19 01:02:04 +01:00
|
|
|
handle(dev, name, buff);
|
2017-09-13 01:58:18 -04:00
|
|
|
|
|
|
|
|
if (c == '}')
|
|
|
|
|
state = 7; /* done */
|
|
|
|
|
else
|
|
|
|
|
state = 2; /* word */
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case '[':
|
|
|
|
|
state++;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
*ptr++ = c;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 6: /* read sector data complex */
|
|
|
|
|
if (c != ']')
|
|
|
|
|
*ptr++ = c;
|
|
|
|
|
else
|
|
|
|
|
state = 5;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 7: /* sector done */
|
2018-03-19 01:02:04 +01:00
|
|
|
handle(dev, NULL, NULL);
|
2017-09-13 01:58:18 -04:00
|
|
|
switch(c) {
|
|
|
|
|
case ',': /* next sector */
|
2018-03-19 01:02:04 +01:00
|
|
|
dev->dmf++;
|
2017-09-13 01:58:18 -04:00
|
|
|
state = 1;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case ']': /* all sectors done */
|
|
|
|
|
if (--level == 0)
|
|
|
|
|
state = -1;
|
|
|
|
|
else state++;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
state = unexpect(c, state, level);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 8: /* side done */
|
|
|
|
|
switch(c) {
|
|
|
|
|
case ',': /* next side */
|
|
|
|
|
state = 0;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case ']': /* all sides done */
|
|
|
|
|
if (--level == 0)
|
|
|
|
|
state = -1;
|
|
|
|
|
else state++;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
state = unexpect(c, state, level);
|
|
|
|
|
}
|
2018-03-19 01:02:04 +01:00
|
|
|
dev->spt[dev->track][dev->side] = dev->dmf;
|
|
|
|
|
dev->side++;
|
2017-09-13 01:58:18 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 9: /* track done */
|
|
|
|
|
switch(c) {
|
|
|
|
|
case ',': /* next track */
|
2018-03-19 01:02:04 +01:00
|
|
|
dev->side = 0;
|
2017-09-13 01:58:18 -04:00
|
|
|
state = 0;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case ']': /* all tracks done */
|
|
|
|
|
if (--level == 0)
|
|
|
|
|
state = -1;
|
|
|
|
|
else state++;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
state = unexpect(c, state, level);
|
|
|
|
|
}
|
2018-03-19 01:02:04 +01:00
|
|
|
dev->track++;
|
2017-09-13 01:58:18 -04:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Save derived values. */
|
2018-03-19 01:02:04 +01:00
|
|
|
dev->tracks = dev->track;
|
|
|
|
|
dev->sides = dev->side;
|
2017-09-13 01:58:18 -04:00
|
|
|
|
|
|
|
|
return(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Seek the heads to a track, and prepare to read data from that track. */
|
|
|
|
|
static void
|
|
|
|
|
json_seek(int drive, int track)
|
|
|
|
|
{
|
|
|
|
|
uint8_t id[4] = { 0,0,0,0 };
|
2018-03-19 01:02:04 +01:00
|
|
|
json_t *dev = images[drive];
|
2017-09-13 01:58:18 -04:00
|
|
|
int side, sector;
|
|
|
|
|
int rate, gap2, gap3, pos;
|
|
|
|
|
int ssize, rsec, asec;
|
|
|
|
|
|
2018-03-19 01:02:04 +01:00
|
|
|
if (dev->f == NULL) {
|
2018-05-21 19:04:05 +02:00
|
|
|
json_log("JSON: seek: no file loaded!\n");
|
2017-09-13 01:58:18 -04:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Allow for doublestepping tracks. */
|
2018-03-19 01:02:04 +01:00
|
|
|
if (! dev->track_width && fdd_doublestep_40(drive)) track /= 2;
|
2017-09-13 01:58:18 -04:00
|
|
|
|
|
|
|
|
/* Set the new track. */
|
2018-03-19 01:02:04 +01:00
|
|
|
dev->track = track;
|
2018-01-17 18:43:36 +01:00
|
|
|
d86f_set_cur_track(drive, track);
|
2017-09-13 01:58:18 -04:00
|
|
|
|
|
|
|
|
/* Reset the 86F state machine. */
|
|
|
|
|
d86f_reset_index_hole_pos(drive, 0);
|
2018-03-15 00:02:19 +01:00
|
|
|
d86f_destroy_linked_lists(drive, 0);
|
2018-03-19 01:02:04 +01:00
|
|
|
d86f_reset_index_hole_pos(drive, 1);
|
2018-03-15 00:02:19 +01:00
|
|
|
d86f_destroy_linked_lists(drive, 1);
|
2017-09-13 01:58:18 -04:00
|
|
|
|
2018-03-19 01:02:04 +01:00
|
|
|
if (track > dev->tracks) {
|
2018-01-17 18:43:36 +01:00
|
|
|
d86f_zero_track(drive);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-19 01:02:04 +01:00
|
|
|
for (side=0; side<dev->sides; side++) {
|
2017-09-13 01:58:18 -04:00
|
|
|
/* Get transfer rate for this side. */
|
2018-03-19 01:02:04 +01:00
|
|
|
rate = dev->track_flags & 0x07;
|
|
|
|
|
if (!rate && (dev->track_flags & 0x20)) rate = 4;
|
2017-09-13 01:58:18 -04:00
|
|
|
|
|
|
|
|
/* Get correct GAP3 value for this side. */
|
2018-01-17 18:43:36 +01:00
|
|
|
gap3 = fdd_get_gap3_size(rate,
|
2018-03-19 01:02:04 +01:00
|
|
|
dev->sects[track][side][0].size,
|
|
|
|
|
dev->spt[track][side]);
|
2017-09-13 01:58:18 -04:00
|
|
|
|
|
|
|
|
/* Get correct GAP2 value for this side. */
|
2018-03-19 01:02:04 +01:00
|
|
|
gap2 = ((dev->track_flags & 0x07) >= 3) ? 41 : 22;
|
2017-09-13 01:58:18 -04:00
|
|
|
|
|
|
|
|
pos = d86f_prepare_pretrack(drive, side, 0);
|
|
|
|
|
|
2018-03-19 01:02:04 +01:00
|
|
|
for (sector=0; sector<dev->spt[track][side]; sector++) {
|
2020-01-14 20:46:43 +01:00
|
|
|
rsec = dev->sects[track][side][sector].sector;
|
|
|
|
|
asec = sector;
|
|
|
|
|
|
2017-09-13 01:58:18 -04:00
|
|
|
id[0] = track;
|
|
|
|
|
id[1] = side;
|
|
|
|
|
id[2] = rsec;
|
2018-03-19 01:02:04 +01:00
|
|
|
if (dev->sects[track][side][asec].size > 255)
|
|
|
|
|
perror("fdd_json.c: json_seek: sector size too big.");
|
|
|
|
|
id[3] = dev->sects[track][side][asec].size & 0xff;
|
|
|
|
|
ssize = fdd_sector_code_size(dev->sects[track][side][asec].size & 0xff);
|
2017-09-13 01:58:18 -04:00
|
|
|
|
|
|
|
|
pos = d86f_prepare_sector(
|
|
|
|
|
drive, side, pos, id,
|
2018-03-19 01:02:04 +01:00
|
|
|
dev->sects[track][side][asec].data,
|
2017-09-13 01:58:18 -04:00
|
|
|
ssize, gap2, gap3,
|
2019-12-05 21:36:28 +01:00
|
|
|
0 /*flags*/
|
2017-09-13 01:58:18 -04:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (sector == 0)
|
|
|
|
|
d86f_initialize_last_sector_id(drive,id[0],id[1],id[2],id[3]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static uint16_t
|
|
|
|
|
disk_flags(int drive)
|
|
|
|
|
{
|
2018-03-19 01:02:04 +01:00
|
|
|
json_t *dev = images[drive];
|
|
|
|
|
|
|
|
|
|
return(dev->disk_flags);
|
2017-09-13 01:58:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static uint16_t
|
|
|
|
|
track_flags(int drive)
|
|
|
|
|
{
|
2018-03-19 01:02:04 +01:00
|
|
|
json_t *dev = images[drive];
|
|
|
|
|
|
|
|
|
|
return(dev->track_flags);
|
2017-09-13 01:58:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
set_sector(int drive, int side, uint8_t c, uint8_t h, uint8_t r, uint8_t n)
|
|
|
|
|
{
|
2018-03-19 01:02:04 +01:00
|
|
|
json_t *dev = images[drive];
|
2017-09-13 01:58:18 -04:00
|
|
|
int i;
|
|
|
|
|
|
2018-03-19 01:02:04 +01:00
|
|
|
dev->sector[side] = 0;
|
2017-09-13 01:58:18 -04:00
|
|
|
|
|
|
|
|
/* Make sure we are on the desired track. */
|
2018-03-19 01:02:04 +01:00
|
|
|
if (c != dev->track) return;
|
2017-09-13 01:58:18 -04:00
|
|
|
|
|
|
|
|
/* Set the desired side. */
|
2018-03-19 01:02:04 +01:00
|
|
|
dev->side = side;
|
2017-09-13 01:58:18 -04:00
|
|
|
|
|
|
|
|
/* Now loop over all sector ID's on this side to find our sector. */
|
2018-03-19 01:02:04 +01:00
|
|
|
for (i=0; i<dev->spt[c][side]; i++) {
|
|
|
|
|
if ((dev->sects[dev->track][side][i].track == c) &&
|
|
|
|
|
(dev->sects[dev->track][side][i].side == h) &&
|
|
|
|
|
(dev->sects[dev->track][side][i].sector == r) &&
|
|
|
|
|
(dev->sects[dev->track][side][i].size == n)) {
|
|
|
|
|
dev->sector[side] = i;
|
2017-09-13 01:58:18 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static uint8_t
|
|
|
|
|
poll_read_data(int drive, int side, uint16_t pos)
|
|
|
|
|
{
|
2018-03-19 01:02:04 +01:00
|
|
|
json_t *dev = images[drive];
|
|
|
|
|
uint8_t sec = dev->sector[side];
|
2017-09-13 01:58:18 -04:00
|
|
|
|
2018-03-19 01:02:04 +01:00
|
|
|
return(dev->sects[dev->track][side][sec].data[pos]);
|
2017-09-13 01:58:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
json_init(void)
|
|
|
|
|
{
|
|
|
|
|
memset(images, 0x00, sizeof(images));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
json_load(int drive, wchar_t *fn)
|
|
|
|
|
{
|
|
|
|
|
double bit_rate;
|
|
|
|
|
int temp_rate;
|
2018-03-19 01:02:04 +01:00
|
|
|
sector_t *sec;
|
|
|
|
|
json_t *dev;
|
2017-09-13 01:58:18 -04:00
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
/* Just in case- remove ourselves from 86F. */
|
|
|
|
|
d86f_unregister(drive);
|
|
|
|
|
|
2018-03-19 01:02:04 +01:00
|
|
|
/* Allocate a drive block. */
|
|
|
|
|
dev = (json_t *)malloc(sizeof(json_t));
|
|
|
|
|
memset(dev, 0x00, sizeof(json_t));
|
2017-09-13 01:58:18 -04:00
|
|
|
|
|
|
|
|
/* Open the image file. */
|
2018-03-19 01:02:04 +01:00
|
|
|
dev->f = plat_fopen(fn, L"rb");
|
|
|
|
|
if (dev->f == NULL) {
|
|
|
|
|
free(dev);
|
2017-09-13 01:58:18 -04:00
|
|
|
memset(fn, 0x00, sizeof(wchar_t));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Our images are always RO. */
|
|
|
|
|
writeprot[drive] = 1;
|
|
|
|
|
|
2018-03-19 01:02:04 +01:00
|
|
|
/* Set up the drive unit. */
|
|
|
|
|
images[drive] = dev;
|
|
|
|
|
|
2017-09-13 01:58:18 -04:00
|
|
|
/* Load all sectors from the image file. */
|
2018-03-19 01:02:04 +01:00
|
|
|
if (! load_image(dev)) {
|
2018-05-21 19:04:05 +02:00
|
|
|
json_log("JSON: failed to initialize\n");
|
2018-03-19 01:02:04 +01:00
|
|
|
(void)fclose(dev->f);
|
|
|
|
|
free(dev);
|
|
|
|
|
images[drive] = NULL;
|
2017-09-13 01:58:18 -04:00
|
|
|
memset(fn, 0x00, sizeof(wchar_t));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-21 19:04:05 +02:00
|
|
|
json_log("JSON(%d): %ls (%i tracks, %i sides, %i sectors)\n",
|
2018-03-19 01:02:04 +01:00
|
|
|
drive, fn, dev->tracks, dev->sides, dev->spt[0][0]);
|
2017-09-13 01:58:18 -04:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* If the image has more than 43 tracks, then
|
|
|
|
|
* the tracks are thin (96 tpi).
|
|
|
|
|
*/
|
2018-03-19 01:02:04 +01:00
|
|
|
dev->track_width = (dev->tracks > 43) ? 1 : 0;
|
2017-09-13 01:58:18 -04:00
|
|
|
|
|
|
|
|
/* If the image has 2 sides, mark it as such. */
|
2018-03-19 01:02:04 +01:00
|
|
|
dev->disk_flags = 0x00;
|
|
|
|
|
if (dev->sides == 2)
|
|
|
|
|
dev->disk_flags |= 0x08;
|
2017-09-13 01:58:18 -04:00
|
|
|
|
|
|
|
|
/* JSON files are always assumed to be MFM-encoded. */
|
2018-03-19 01:02:04 +01:00
|
|
|
dev->track_flags = 0x08;
|
2017-09-13 01:58:18 -04:00
|
|
|
|
2018-03-19 01:02:04 +01:00
|
|
|
dev->interleave = 0;
|
2017-09-13 01:58:18 -04:00
|
|
|
#if 0
|
2018-03-19 01:02:04 +01:00
|
|
|
dev->skew = 0;
|
2017-09-13 01:58:18 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
temp_rate = 0xff;
|
2018-03-19 01:02:04 +01:00
|
|
|
sec = &dev->sects[0][0][0];
|
2017-09-13 01:58:18 -04:00
|
|
|
for (i=0; i<6; i++) {
|
2018-03-19 01:02:04 +01:00
|
|
|
if (dev->spt[0][0] > fdd_max_sectors[sec->size][i]) continue;
|
2017-09-13 01:58:18 -04:00
|
|
|
|
2018-01-17 18:43:36 +01:00
|
|
|
bit_rate = fdd_bit_rates_300[i];
|
|
|
|
|
temp_rate = fdd_rates[i];
|
2018-03-19 01:02:04 +01:00
|
|
|
dev->disk_flags |= (fdd_holes[i] << 1);
|
2017-09-13 01:58:18 -04:00
|
|
|
|
2018-03-19 01:02:04 +01:00
|
|
|
if ((bit_rate == 500.0) && (dev->spt[0][0] == 21) &&
|
|
|
|
|
(sec->size == 2) && (dev->tracks >= 80) &&
|
|
|
|
|
(dev->tracks <= 82) && (dev->sides == 2)) {
|
2017-09-13 01:58:18 -04:00
|
|
|
/*
|
|
|
|
|
* This is a DMF floppy, set the flag so
|
|
|
|
|
* we know to interleave the sectors.
|
|
|
|
|
*/
|
2018-03-19 01:02:04 +01:00
|
|
|
dev->dmf = 1;
|
2017-09-13 01:58:18 -04:00
|
|
|
} else {
|
2018-03-19 01:02:04 +01:00
|
|
|
if ((bit_rate == 500.0) && (dev->spt[0][0] == 22) &&
|
|
|
|
|
(sec->size == 2) && (dev->tracks >= 80) &&
|
|
|
|
|
(dev->tracks <= 82) && (dev->sides == 2)) {
|
2017-09-13 01:58:18 -04:00
|
|
|
/*
|
|
|
|
|
* This is marked specially because of the
|
|
|
|
|
* track flag (a RPM slow down is needed).
|
|
|
|
|
*/
|
2018-03-19 01:02:04 +01:00
|
|
|
dev->interleave = 2;
|
2017-09-13 01:58:18 -04:00
|
|
|
}
|
|
|
|
|
|
2018-03-19 01:02:04 +01:00
|
|
|
dev->dmf = 0;
|
2017-09-13 01:58:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (temp_rate == 0xff) {
|
2018-05-21 19:04:05 +02:00
|
|
|
json_log("JSON: invalid image (temp_rate=0xff)\n");
|
2018-03-19 01:02:04 +01:00
|
|
|
(void)fclose(dev->f);
|
|
|
|
|
dev->f = NULL;
|
|
|
|
|
free(dev);
|
|
|
|
|
images[drive] = NULL;
|
2017-09-13 01:58:18 -04:00
|
|
|
memset(fn, 0x00, sizeof(wchar_t));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-19 01:02:04 +01:00
|
|
|
if (dev->interleave == 2) {
|
|
|
|
|
dev->interleave = 1;
|
|
|
|
|
dev->disk_flags |= 0x60;
|
2017-09-13 01:58:18 -04:00
|
|
|
}
|
|
|
|
|
|
2018-03-19 01:02:04 +01:00
|
|
|
dev->gap2_len = (temp_rate == 3) ? 41 : 22;
|
|
|
|
|
if (dev->dmf)
|
|
|
|
|
dev->gap3_len = 8;
|
|
|
|
|
else
|
|
|
|
|
dev->gap3_len = fdd_get_gap3_size(temp_rate,sec->size,dev->spt[0][0]);
|
2017-09-13 01:58:18 -04:00
|
|
|
|
2018-03-19 01:02:04 +01:00
|
|
|
if (! dev->gap3_len) {
|
2018-05-21 19:04:05 +02:00
|
|
|
json_log("JSON: image of unknown format was inserted into drive %c:!\n",
|
2017-09-13 01:58:18 -04:00
|
|
|
'C'+drive);
|
2018-03-19 01:02:04 +01:00
|
|
|
(void)fclose(dev->f);
|
|
|
|
|
dev->f = NULL;
|
|
|
|
|
free(dev);
|
|
|
|
|
images[drive] = NULL;
|
2017-09-13 01:58:18 -04:00
|
|
|
memset(fn, 0x00, sizeof(wchar_t));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-19 01:02:04 +01:00
|
|
|
dev->track_flags |= (temp_rate & 0x03); /* data rate */
|
2017-09-13 01:58:18 -04:00
|
|
|
if (temp_rate & 0x04)
|
2018-03-19 01:02:04 +01:00
|
|
|
dev->track_flags |= 0x20; /* RPM */
|
2017-09-13 01:58:18 -04:00
|
|
|
|
2018-05-21 19:04:05 +02:00
|
|
|
json_log(" disk_flags: 0x%02x, track_flags: 0x%02x, GAP3 length: %i\n",
|
2018-03-19 01:02:04 +01:00
|
|
|
dev->disk_flags, dev->track_flags, dev->gap3_len);
|
2018-05-21 19:04:05 +02:00
|
|
|
json_log(" bit rate 300: %.2f, temporary rate: %i, hole: %i, DMF: %i\n",
|
2018-03-19 01:02:04 +01:00
|
|
|
bit_rate, temp_rate, (dev->disk_flags >> 1), dev->dmf);
|
2017-09-13 01:58:18 -04:00
|
|
|
|
|
|
|
|
/* Set up handlers for 86F layer. */
|
|
|
|
|
d86f_handler[drive].disk_flags = disk_flags;
|
|
|
|
|
d86f_handler[drive].side_flags = track_flags;
|
|
|
|
|
d86f_handler[drive].writeback = null_writeback;
|
|
|
|
|
d86f_handler[drive].set_sector = set_sector;
|
|
|
|
|
d86f_handler[drive].read_data = poll_read_data;
|
|
|
|
|
d86f_handler[drive].write_data = null_write_data;
|
|
|
|
|
d86f_handler[drive].format_conditions = null_format_conditions;
|
|
|
|
|
d86f_handler[drive].extra_bit_cells = null_extra_bit_cells;
|
|
|
|
|
d86f_handler[drive].encoded_data = common_encoded_data;
|
|
|
|
|
d86f_handler[drive].read_revolution = common_read_revolution;
|
|
|
|
|
d86f_handler[drive].index_hole_pos = null_index_hole_pos;
|
|
|
|
|
d86f_handler[drive].get_raw_size = common_get_raw_size;
|
|
|
|
|
d86f_handler[drive].check_crc = 1;
|
|
|
|
|
d86f_set_version(drive, 0x0063);
|
|
|
|
|
|
|
|
|
|
d86f_common_handlers(drive);
|
|
|
|
|
|
|
|
|
|
drives[drive].seek = json_seek;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Close the image. */
|
|
|
|
|
void
|
|
|
|
|
json_close(int drive)
|
|
|
|
|
{
|
2018-03-19 01:02:04 +01:00
|
|
|
json_t *dev = images[drive];
|
2017-09-13 01:58:18 -04:00
|
|
|
int t, h, s;
|
|
|
|
|
|
2018-03-19 01:02:04 +01:00
|
|
|
if (dev == NULL) return;
|
|
|
|
|
|
2017-09-13 01:58:18 -04:00
|
|
|
/* Unlink image from the system. */
|
|
|
|
|
d86f_unregister(drive);
|
|
|
|
|
|
|
|
|
|
/* Release all the sector buffers. */
|
|
|
|
|
for (t=0; t<256; t++) {
|
|
|
|
|
for (h=0; h<2; h++) {
|
2018-03-19 01:02:04 +01:00
|
|
|
memset(dev->sects[t][h], 0x00, sizeof(sector_t));
|
2017-09-13 01:58:18 -04:00
|
|
|
for (s=0; s<256; s++) {
|
2018-03-19 01:02:04 +01:00
|
|
|
if (dev->sects[t][h][s].data != NULL)
|
|
|
|
|
free(dev->sects[t][h][s].data);
|
|
|
|
|
dev->sects[t][h][s].data = NULL;
|
2017-09-13 01:58:18 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-19 01:02:04 +01:00
|
|
|
if (dev->f != NULL)
|
|
|
|
|
(void)fclose(dev->f);
|
|
|
|
|
|
|
|
|
|
/* Release the memory. */
|
|
|
|
|
free(dev);
|
|
|
|
|
images[drive] = NULL;
|
2017-09-13 01:58:18 -04:00
|
|
|
}
|