// license:BSD-3-Clause
// copyright-holders:Curt Coder
/*********************************************************************
formats/atom_tap.h
Cassette code for Acorn Atom tap files
*********************************************************************/
#ifndef MAME_FORMATS_ATOM_TAP_H
#define MAME_FORMATS_ATOM_TAP_Hpre { line-height: 125%; }
td.linenos .normal { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
span.linenos { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
td.linenos .special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
span.linenos.special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
.highlight .hll { background-color: #ffffcc }
.highlight .c { color: #888 } /* Comment */
.highlight .err { color: #A61717; background-color: #E3D2D2 } /* Error */
.highlight .k { color: #080; font-weight: bold } /* Keyword */
.highlight .ch { color: #888 } /* Comment.Hashbang */
.highlight .cm { color: #888 } /* Comment.Multiline */
.highlight .cp { color: #C00; font-weight: bold } /* Comment.Preproc */
.highlight .cpf { color: #888 } /* Comment.PreprocFile */
.highlight .c1 { color: #888 } /* Comment.Single */
.highlight .cs { color: #C00; font-weight: bold; background-color: #FFF0F0 } /* Comment.Special */
.highlight .gd { color: #000; background-color: #FDD } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .ges { font-weight: bold; font-style: italic } /* Generic.EmphStrong */
.highlight .gr { color: #A00 } /* Generic.Error */
.highlight .gh { color: #333 } /* Generic.Heading */
.highlight .gi { color: #000; background-color: #DFD } /* Generic.Inserted */
.highlight .go { color: #888 } /* Generic.Output */
.highlight .gp { color: #555 } /* Generic.Prompt */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #666 } /* Generic.Subheading */
.highlight .gt { color: #A00 } /* Generic.Traceback */
.highlight .kc { color: #080; font-weight: bold } /* Keyword.Constant */
.highlight .kd { color: #080; font-weight: bold } /* Keyword.Declaration */
.highlight .kn { color: #080; font-weight: bold } /* Keyword.Namespace */
.highlight .kp { color: #080 } /* Keyword.Pseudo */
.highlight .kr { color: #080; font-weight: bold } /* Keyword.Reserved */
.highlight .kt { color: #888; font-weight: bold } /* Keyword.Type */
.highlight .m { color: #00D; font-weight: bold } /* Literal.Number */
.highlight .s { color: #D20; background-color: #FFF0F0 } /* Literal.String */
.highlight .na { color: #369 } /* Name.Attribute */
.highlight .nb { color: #038 } /* Name.Builtin */
.highlight .nc { color: #B06; font-weight: bold } /* Name.Class */
.highlight .no { color: #036; font-weight: bold } /* Name.Constant */
.highlight .nd { color: #555 } /* Name.Decorator */
.highlight .ne { color: #B06; font-weight: bold } /* Name.Exception */
.highlight .nf { color: #06B; font-weight: bold } /* Name.Function */
.highlight .nl { color: #369; font-style: italic } /* Name.Label */
.highlight .nn { color: #B06; font-weight: bold } /* Name.Namespace */
.highlight .py { color: #369; font-weight: bold } /* Name.Property */
.highlight .nt { color: #B06; font-weight: bold } /* Name.Tag */
.highlight .nv { color: #369 } /* Name.Variable */
.highlight .ow { color: #080 } /* Operator.Word */
.highlight .w { color: #BBB } /* Text.Whitespace */
.highlight .mb { color: #00D; font-weight: bold } /* Literal.Number.Bin */
.highlight .mf { color: #00D; font-weight: bold } /* Literal.Number.Float */
.highlight .mh { color: #00D; font-weight: bold } /* Literal.Number.Hex */
.highlight .mi { color: #00D; font-weight: bold } /* Literal.Number.Integer */
.highlight .mo { color: #00D; font-weight: bold } /* Literal.Number.Oct */
.highlight .sa { color: #D20; background-color: #FFF0F0 } /* Literal.String.Affix */
.highlight .sb { color: #D20; background-color: #FFF0F0 } /* Literal.String.Backtick */
.highlight .sc { color: #D20; background-color: #FFF0F0 } /* Literal.String.Char */
.highlight .dl { color: #D20; background-color: #FFF0F0 } /* Literal.String.Delimiter */
.highlight .sd { color: #D20; background-color: #FFF0F0 } /* Literal.String.Doc */
.highlight .s2 { color: #D20; background-color: #FFF0F0 } /* Literal.String.Double */
.highlight .se { color: #04D; background-color: #FFF0F0 } /* Literal.String.Escape */
.highlight .sh { color: #D20; background-color: #FFF0F0 } /* Literal.String.Heredoc */
.highlight .si { color: #33B; background-color: #FFF0F0 } /* Literal.String.Interpol */
.highlight .sx { color: #2B2; background-color: #F0FFF0 } /* Literal.String.Other */
.highlight .sr { color: #080; background-color: #FFF0FF } /* Literal.String.Regex */
.highlight .s1 { color: #D20; background-color: #FFF0F0 } /* Literal.String.Single */
.highlight .ss { color: #A60; background-color: #FFF0F0 } /* Literal.String.Symbol */
.highlight .bp { color: #038 } /* Name.Builtin.Pseudo */
.highlight .fm { color: #06B; font-weight: bold } /* Name.Function.Magic */
.highlight .vc { color: #369 } /* Name.Variable.Class */
.highlight .vg { color: #D70 } /* Name.Variable.Global */
.highlight .vi { color: #33B } /* Name.Variable.Instance */
.highlight .vm { color: #369 } /* Name.Variable.Magic */
.highlight .il { color: #00D; font-weight: bold } /* Literal.Number.Integer.Long */// license:BSD-3-Clause
// copyright-holders:Nigel Barnes
/***************************************************************************
BBC Micro 8271 protected disk image format
Disk image format
***************************************************************************/
#include "fsd_dsk.h"
#include "imageutl.h"
#include "ioprocs.h"
#include <cstring>
/*********************************************************************
BBC Micro 8271 protected disk image format
Header:
=======
Identifier: "FSD" string literal 3 bytes
Creator: 5 bytes; date of creation/author
Title: Character string (unlimited length; may contain any but null)
Title_End: 0x00 byte literal 1 byte
Num_Tr: xx 1 byte, number of tracks
For each track
==============
track_num: 1 byte
num_sec: 1 byte (00 == unformatted)
readable: 1 byte (00 == unreadable, ff ==readable)
If readable:
For each sector
===============
Track_ID: 1 byte
Head_number: 1 byte
Sector_ID: 1 byte
reported_size: 1 byte (2^{7+x}; 0 ==>128, 1 ==> 256, 2==>512, 3==>1024 etc)
real_size: 1 byte (2^{7+x})
error_code: 1 byte (0==No Error, &20==Deleted Data; &0E = Data CRC Error)
data: <real_size> bytes
Note that error_code matches the OSWORD &7F result byte
If unreadable:
Track_ID: 1 byte
Head_number: 1 byte
Sector_ID: 1 byte
reported_size: 1 byte
Decoding of the "creator" 5 byte field:
=======================================
(byte1 byte2 byte3 byte4 byte5)
Date_DD = (byte1 AND &F8)/8
Date_MM = (byte3 AND &0F)
Date_YYYY = (byte1 AND &07)*256+byte2
Creator_ID = (byte3 AND &F0)/16
Release_num = ((byte5 AND &C0)/64)*256 + byte4
*********************************************************************/
fsd_format::fsd_format()
{
}
const char *fsd_format::name() const
{
return "fsd";
}
const char *fsd_format::description() const
{
return "BBC Micro 8271 protected disk image";
}
const char *fsd_format::extensions() const
{
return "fsd";
}
bool fsd_format::supports_save() const
{
return false;
}
int fsd_format::identify(util::random_read &io, uint32_t form_factor, const std::vector<uint32_t> &variants)
{
uint8_t h[3];
size_t actual;
io.read_at(0, h, 3, actual);
if (memcmp(h, "FSD", 3) == 0) {
return 100;
}
LOG_FORMATS("fsd: no match\n");
return 0;
}
bool fsd_format::load(util::random_read &io, uint32_t form_factor, const std::vector<uint32_t> &variants, floppy_image *image)
{
const char* result[255];
result[0x00] = "OK";
result[0x0e] = "Data CRC Error";
result[0x20] = "Deleted Data";
uint64_t size;
if(io.length(size))
return false;
std::vector<uint8_t> img(size);
size_t actual;
io.read_at(0, &img[0], size, actual);
uint64_t pos;
std::string title;
for(pos=8; pos < size && img[pos] != '\0'; pos++)
title.append(1, img[pos]);
pos++;
if(pos >= size)
return false;
LOG_FORMATS("FSD Title: %s\n", title.c_str());
LOG_FORMATS("FSD Created: %02d/%02d/%4d\n", (img[3] & 0xf8) / 8, img[5] & 0x0f, (img[3] & 0x07) * 256 + img[4]);
LOG_FORMATS("FSD Creator: %d\n", (img[5] & 0xf0) / 16);
LOG_FORMATS("FSD Release: %d\n", ((img[7] & 0xc0) / 64) * 256 + img[6]);
desc_pc_sector sects[256];
uint8_t total_tracks = img[pos++];
uint8_t tnum, hnum, snum, ssize, error;
hnum = 0;
LOG_FORMATS("FSD Tracks: %02d\n", total_tracks+1);
LOG_FORMATS("Tr.# No.S Sec.# Tr.ID Head# SecID IDsiz REsiz Error\n");
for(int curr_track=0; curr_track <= total_tracks; curr_track++)
{
uint8_t track = img[pos++];
uint8_t spt = img[pos++];
if (spt > 0) // formatted
{
LOG_FORMATS("%02X %02X\n", track, spt);
uint8_t readable = img[pos++];
for (int i = 0; i < spt; i++)
{
tnum = img[pos++]; // logical track
hnum = img[pos++]; // head number
snum = img[pos++]; // logical sector
ssize = img[pos++]; // reported size
sects[i].track = tnum;
sects[i].head = hnum;
sects[i].sector = snum;
sects[i].size = ssize;
if (readable == 0xff)
{
sects[i].actual_size = 128 << img[pos++];
error = img[pos++];
sects[i].deleted = (error & 0x20) == 0x20;
sects[i].bad_crc = (error & 0x0e) == 0x0e;
sects[i].data = &img[pos];
pos += sects[i].actual_size;
LOG_FORMATS("Read %02X %02X %02X %02X %04X %04X %s\n", i, sects[i].track, sects[i].head, sects[i].sector, 128 << sects[i].size, sects[i].actual_size, result[error]);
}
else
{
LOG_FORMATS("Unreadable sector on track %02d sector %02X head %02d\n", track, i, hnum);
sects[i].actual_size = 0;
sects[i].deleted = false;
sects[i].bad_crc = false;
sects[i].data = nullptr;
LOG_FORMATS("Unread %02X %02X %02X %02X %04X %04X %s\n", i, sects[i].track, sects[i].head, sects[i].sector, sects[i].size, sects[i].actual_size, "Unreadable");
//return false;
}
}
}
else // unformatted
{
sects[0].track = curr_track;
sects[0].head = hnum;
sects[0].sector = 0;
sects[0].size = 0;
LOG_FORMATS("Unform %02X %02X %02X %02X %04X %04X %s\n", 0, sects[0].track, sects[0].head, sects[0].sector, sects[0].size, sects[0].actual_size, "Unformatted");
}
build_wd_track_fm(curr_track, hnum, image, 50000, spt, sects, 10, 40, 10);
}
return true;
}
const floppy_format_type FLOPPY_FSD_FORMAT = &floppy_image_format_creator<fsd_format>;