formats: Use multibyte.h functions in more files

This commit is contained in:
AJR 2023-09-17 14:47:13 -04:00
parent 2dc489fb90
commit 26a310422a
35 changed files with 284 additions and 274 deletions

View File

@ -12,6 +12,8 @@ For more information see:
#include "ace_tap.h"
#include "multibyte.h"
#define SMPLO -32768
#define SILENCE 0
@ -95,11 +97,8 @@ static int ace_handle_tap(int16_t *buffer, const uint8_t *casdata)
while( data_pos < cas_size )
{
uint16_t block_size;
int i;
/* Handle a block of tape data */
block_size = casdata[data_pos] + ( casdata[data_pos + 1] << 8 );
uint16_t block_size = get_u16le( &casdata[data_pos] );
data_pos += 2;
/* Make sure there are enough bytes left */
@ -110,7 +109,7 @@ static int ace_handle_tap(int16_t *buffer, const uint8_t *casdata)
sample_count += ace_tap_silence( buffer, sample_count, 2 * 44100 );
/* Add pilot tone samples: 4096 for header, 512 for data */
for( i = ( block_size == 0x001A ) ? 4096 : 512; i; i-- )
for( int i = ( block_size == 0x001A ) ? 4096 : 512; i; i-- )
sample_count += ace_tap_cycle( buffer, sample_count, 27, 27 );
/* Sync samples */

View File

@ -12,6 +12,7 @@
#include "imageutl.h"
#include "ioprocs.h"
#include "multibyte.h"
#include <cstring>
@ -77,7 +78,7 @@ int acorn_ssd_format::find_size(util::random_read &io, uint32_t form_factor, con
// read sector count from side 0 catalogue
io.read_at(0x100, cat, 8, actual);
sectors0 = ((cat[6] & 3) << 8) + cat[7];
sectors0 = get_u16be(&cat[6]) & 0x3ff;
LOG_FORMATS("ssd: sector count 0: %d %s\n", sectors0, sectors0 % 10 != 0 ? "invalid" : "");
if ((size <= (uint64_t)compute_track_size(f) * f.track_count * f.head_count) && (sectors0 <= f.track_count * f.sector_count))
@ -86,12 +87,12 @@ int acorn_ssd_format::find_size(util::random_read &io, uint32_t form_factor, con
{
// read sector count from side 2 catalogue
io.read_at((uint64_t)compute_track_size(f) * f.track_count + 0x100, cat, 8, actual); // sequential
sectors2 = ((cat[6] & 3) << 8) + cat[7];
sectors2 = get_u16be(&cat[6]) & 0x3ff;
// exception case for Acorn CP/M System Disc 1
io.read_at(0x367ec, cat, 8, actual);
if (memcmp(cat, "/M ", 4) == 0)
sectors2 = ((cat[6] & 3) << 8) + cat[7];
sectors2 = get_u16be(&cat[6]) & 0x3ff;
LOG_FORMATS("ssd: sector count 2: %d %s\n", sectors2, sectors2 % 10 != 0 ? "invalid" : "");
}
@ -222,19 +223,19 @@ int acorn_dsd_format::find_size(util::random_read &io, uint32_t form_factor, con
// read sector count from side 0 catalogue
io.read_at(0x100, cat, 8, actual);
sectors0 = ((cat[6] & 3) << 8) + cat[7];
sectors0 = get_u16be(&cat[6]) & 0x3ff;
LOG_FORMATS("dsd: sector count 0: %d %s\n", sectors0, sectors0 % 10 != 0 ? "invalid" : "");
if ((size <= (uint64_t)compute_track_size(f) * f.track_count * f.head_count) && (sectors0 <= f.track_count * f.sector_count))
{
// read sector count from side 2 catalogue
io.read_at(0xb00, cat, 8, actual); // interleaved
sectors2 = ((cat[6] & 3) << 8) + cat[7];
sectors2 = get_u16be(&cat[6]) & 0x3ff;
// exception case for Acorn CP/M System Disc 1
io.read_at(0x97ec, cat, 8, actual);
if (memcmp(cat, "/M ", 4) == 0)
sectors2 = ((cat[6] & 3) << 8) + cat[7];
sectors2 = get_u16be(&cat[6]) & 0x3ff;
LOG_FORMATS("dsd: sector count 2: %d %s\n", sectors2, sectors2 % 10 != 0 ? "invalid" : "");
@ -313,7 +314,7 @@ int opus_ddos_format::find_size(util::random_read &io, uint32_t form_factor, con
// read sector count from side 0 catalogue
io.read_at(0x1000, cat, 8, actual);
sectors0 = (cat[1] << 8) + cat[2];
sectors0 = get_u16be(&cat[1]);
LOG_FORMATS("ddos: sector count 0: %d %s\n", sectors0, sectors0 % 18 != 0 ? "invalid" : "");
uint64_t size;
@ -335,7 +336,7 @@ int opus_ddos_format::find_size(util::random_read &io, uint32_t form_factor, con
{
// read sector count from side 2 catalogue
io.read_at((uint64_t)compute_track_size(f) * f.track_count + 0x1000, cat, 8, actual); // sequential
sectors2 = (cat[1] << 8) + cat[2];
sectors2 = get_u16be(&cat[1]);
LOG_FORMATS("ddos: sector count 2: %d %s\n", sectors2, sectors2 % 18 != 0 ? "invalid" : "");
}
else
@ -419,7 +420,7 @@ int acorn_adfs_old_format::find_size(util::random_read &io, uint32_t form_factor
// read sector count from free space map
io.read_at(0xfc, map, 3, actual);
sectors = map[0] + (map[1] << 8) + (map[2] << 16);
sectors = get_u24le(map);
LOG_FORMATS("adfs_o: sector count %d %s\n", sectors, sectors % 16 != 0 ? "invalid" : "");
// read map identifier

View File

@ -12,6 +12,7 @@
#include "basicdsk.h"
#include "ioprocs.h"
#include "multibyte.h"
#include <cassert>
#include <cstdlib>
@ -347,7 +348,7 @@ bool a2_16sect_format::save(util::random_read_write &io, const std::vector<uint3
uint8_t se = gcr4_decode(h[4],h[5]);
uint8_t chk = gcr4_decode(h[6],h[7]);
#ifdef VERBOSE_SAVE
uint32_t post = (h[8]<<16)|(h[9]<<8)|h[10];
uint32_t post = get_u24be(&h[8]);
printf("Address Mark:\tVolume %d, Track %d, Sector %2d, Checksum %02X: %s, Postamble %03X: %s\n", vl, tr, se, chk, (chk ^ vl ^ tr ^ se)==0?"OK":"BAD", post, (post&0xFFFF00)==0xDEAA00?"OK":"BAD");
#endif
// sanity check
@ -674,7 +675,7 @@ bool a2_rwts18_format::save(util::random_read_write &io, const std::vector<uint3
uint8_t tr = gcr4_decode(h[2],h[3]);
uint8_t se = gcr4_decode(h[4],h[5]);
uint8_t chk = gcr4_decode(h[6],h[7]);
uint32_t post = (h[8]<<16)|(h[9]<<8)|h[10];
uint32_t post = get_u24be(&h[8]);
printf("Address Mark:\tVolume %d, Track %d, Sector %2d, Checksum %02X: %s, Postamble %03X: %s\n", vl, tr, se, chk, (chk ^ vl ^ tr ^ se)==0?"OK":"BAD", post, (post&0xFFFF00)==0xDEAA00?"OK":"BAD");
// sanity check
if (tr == 0 && se < nsect) {
@ -834,7 +835,7 @@ bool a2_rwts18_format::save(util::random_read_write &io, const std::vector<uint3
uint8_t tr = gcr6bw_tb[h[0]];
uint8_t se = gcr6bw_tb[h[1]];
uint8_t chk = gcr6bw_tb[h[2]];
uint32_t post = (h[3]<<16)|(h[4]<<8)|h[5];
uint32_t post = get_u24be(&h[3]);
uint8_t bbundid = h[6];
printf("RWTS18 AM:\t Track %d, Sector %2d, Checksum %02X: %s, Postamble %03X: %s, BBUNDID %02x\n", tr, se, chk, (chk ^ tr ^ se)==0?"OK":"BAD", post, post==0xAAFFFF?"OK":"BAD", bbundid);
// sanity check
@ -1040,7 +1041,7 @@ int a2_edd_format::identify(util::random_read &io, uint32_t form_factor, const s
uint8_t a2_edd_format::pick(const uint8_t *data, int pos)
{
return ((data[pos>>3] << 8) | data[(pos>>3)+1]) >> (8-(pos & 7));
return get_u16be(&data[pos>>3]) >> (8-(pos & 7));
}
bool a2_edd_format::load(util::random_read &io, uint32_t form_factor, const std::vector<uint32_t> &variants, floppy_image *image) const

View File

@ -99,11 +99,14 @@
*********************************************************************/
#include "ap_dsk35.h"
#include "imageutl.h"
#include "ioprocs.h"
#include "multibyte.h"
#include "opresolv.h"
#include "eminline.h"
#include "osdcore.h" // osd_printf_error
#include <cassert>
#include <cstdio>
#include <cstring>
@ -141,8 +144,8 @@ int dc42_format::identify(util::random_read &io, uint32_t form_factor, const std
uint8_t h[0x54];
size_t actual;
io.read_at(0, h, 0x54, actual);
uint32_t dsize = (h[0x40] << 24) | (h[0x41] << 16) | (h[0x42] << 8) | h[0x43];
uint32_t tsize = (h[0x44] << 24) | (h[0x45] << 16) | (h[0x46] << 8) | h[0x47];
uint32_t dsize = get_u32be(&h[0x40]);
uint32_t tsize = get_u32be(&h[0x44]);
uint8_t encoding = h[0x50];
uint8_t format = h[0x51];
@ -160,8 +163,8 @@ bool dc42_format::load(util::random_read &io, uint32_t form_factor, const std::v
size_t actual;
uint8_t h[0x54];
io.read_at(0, h, 0x54, actual);
int dsize = (h[0x40] << 24) | (h[0x41] << 16) | (h[0x42] << 8) | h[0x43];
int tsize = (h[0x44] << 24) | (h[0x45] << 16) | (h[0x46] << 8) | h[0x47];
int dsize = get_u32be(&h[0x40]);
int tsize = get_u32be(&h[0x44]);
uint8_t encoding = h[0x50];
uint8_t format = h[0x51];
@ -237,8 +240,8 @@ bool dc42_format::load(util::random_read &io, uint32_t form_factor, const std::v
void dc42_format::update_chk(const uint8_t *data, int size, uint32_t &chk)
{
for(int i=0; i<size; i+=2) {
chk += (data[i] << 8) | data[i+1];
chk = (chk >> 1) | (chk << 31);
chk += get_u16be(&data[i]);
chk = rotr_32(chk, 1);
}
}
@ -257,14 +260,8 @@ bool dc42_format::save(util::random_read_write &io, const std::vector<uint32_t>
int nsect = 16*(12+11+10+9+8)*g_heads;
uint32_t dsize = nsect*512;
uint32_t tsize = nsect*12;
h[0x40] = dsize >> 24;
h[0x41] = dsize >> 16;
h[0x42] = dsize >> 8;
h[0x43] = dsize;
h[0x44] = tsize >> 24;
h[0x45] = tsize >> 16;
h[0x46] = tsize >> 8;
h[0x47] = tsize;
put_u32be(&h[0x40], dsize);
put_u32be(&h[0x44], tsize);
h[0x50] = g_heads == 2 ? 0x01 : 0x00;
h[0x51] = g_heads == 2 ? 0x22 : 0x02;
h[0x52] = 0x01;
@ -469,8 +466,8 @@ bool apple_2mg_format::load(util::random_read &io, uint32_t form_factor, const s
desc_gcr_sector sectors[12];
uint8_t sdata[512*12], header[64];
io.read_at(0, header, 64, actual);
uint32_t blocks = header[0x14] | (header[0x15] << 8) | (header[0x16] << 16) | (header[0x17] << 24);
uint32_t pos_data = header[0x18] | (header[0x19] << 8) | (header[0x1a] << 16) | (header[0x1b] << 24);
uint32_t blocks = get_u32le(&header[0x14]);
uint32_t pos_data = get_u32le(&header[0x18]);
if(blocks != 1600 && blocks != 16390)
return false;

View File

@ -63,6 +63,7 @@
#include "formats/apd_dsk.h"
#include "ioprocs.h"
#include "multibyte.h"
#include "osdcore.h" // osd_printf_*, little_endianize_int32
@ -148,7 +149,7 @@ bool apd_format::load(util::random_read &io, uint32_t form_factor, const std::ve
int err;
std::vector<uint8_t> gz_ptr;
z_stream d_stream;
int inflate_size = (img[size - 1] << 24) | (img[size - 2] << 16) | (img[size - 3] << 8) | img[size - 4];
int inflate_size = get_u32le(&img[size - 4]);
uint8_t *in_ptr = &img[0];
if (!memcmp(&img[0], GZ_HEADER, sizeof(GZ_HEADER))) {

View File

@ -25,6 +25,8 @@ Each byte is 8 bits (MSB first) with no start or stop bits.
#include "camplynx_cas.h"
#include "multibyte.h"
#include "osdcore.h" // osd_printf_*
@ -144,13 +146,13 @@ static int camplynx_handle_cassette(int16_t *buffer, const uint8_t *bytes)
switch (file_type)
{
case 'A':
data_size = 5 + ((bytes[byte_count + 4]) << 8 | bytes[byte_count + 3]) + 12;
data_size = 5 + get_u16le(&bytes[byte_count + 3]) + 12;
break;
case 'B':
data_size = 3 + ((bytes[byte_count + 2]) << 8 | bytes[byte_count + 1]) + 3;
data_size = 3 + get_u16le(&bytes[byte_count + 1]) + 3;
break;
case 'M':
data_size = 3 + ((bytes[byte_count + 2]) << 8 | bytes[byte_count + 1]) + 7;
data_size = 3 + get_u16le(&bytes[byte_count + 1]) + 7;
break;
}

View File

@ -97,6 +97,8 @@ below could be not working. FP ]
#include "cbm_tap.h"
#include "imageutl.h"
#include "multibyte.h"
#define CBM_WAV_FREQUENCY 44100
@ -281,7 +283,7 @@ static int cbm_tap_do_work( int16_t **buffer, int length, const uint8_t *data )
if (j >= 4)
{
over_pulse_length = ((over_pulse_bytes[2] << 16) | (over_pulse_bytes[1] << 8) | over_pulse_bytes[0]) >> 3;
over_pulse_length = get_u24le(over_pulse_bytes) >> 3;
byte_samples = tap_data_to_samplecount(over_pulse_length, tap_frequency);
/* waveamp_high = WAVE_PAUSE; */
j = 0;

View File

@ -12,6 +12,7 @@
#include "flopimg_legacy.h"
#include "ioprocs.h"
#include "multibyte.h"
#include <cstring>
@ -185,7 +186,7 @@ FLOPPY_CONSTRUCT( cqm_dsk_construct )
floppy_image_read(floppy, header, 0, CQM_HEADER_SIZE);
tag->sector_size = (header[0x04] << 8) + header[0x03];
tag->sector_size = get_u16le(&header[0x03]);
tag->sector_per_track = header[0x10];
tag->heads = header[0x12];
tag->tracks = header[0x5b];
@ -274,13 +275,13 @@ bool cqm_format::load(util::random_read &io, uint32_t form_factor, const std::ve
uint8_t header[CQM_HEADER_SIZE];
io.read_at(0, header, CQM_HEADER_SIZE, actual);
int sector_size = (header[0x04] << 8) | header[0x03];
int sector_per_track = (header[0x11] << 8) | header[0x10];
int heads = (header[0x13] << 8) | header[0x12];
int sector_size = get_u16le(&header[0x03]);
int sector_per_track = get_u16le(&header[0x10]);
int heads = get_u16le(&header[0x12]);
int tracks = header[0x5b];
// int blind = header[0x58]; // 0=DOS, 1=blind, 2=HFS
int density = header[0x59]; // 0=DD, 1=HD, 2=ED
int comment_size = (header[0x70] << 8) | header[0x6f];
int comment_size = get_u16le(&header[0x6f]);
int sector_base = header[0x71] + 1;
// int interleave = header[0x74]; // TODO
// int skew = header[0x75]; // TODO
@ -322,7 +323,7 @@ bool cqm_format::load(util::random_read &io, uint32_t form_factor, const std::ve
// decode the RLE data
for (int s = 0, pos = CQM_HEADER_SIZE + comment_size; pos < cqm_size; )
{
int16_t len = (cqmbuf[pos + 1] << 8) | cqmbuf[pos];
int16_t len = get_s16le(&cqmbuf[pos]);
pos += 2;
if(len < 0)
{

View File

@ -33,6 +33,7 @@
#include "imageutl.h"
#include "ioprocs.h"
#include "multibyte.h"
#define D88_HEADER_LEN 0x2b0
@ -71,7 +72,7 @@ static int d88_get_sector_id(floppy_image_legacy *floppy, int head, int track, i
x=0;
while(x<sector_index)
{
offset += ((sector_hdr[15] << 8) | sector_hdr[14]);
offset += get_u16le(&sector_hdr[14]);
offset += 16;
floppy_image_read(floppy,sector_hdr,offset,16);
x++;
@ -123,10 +124,10 @@ static floperr_t d88_get_sector_length(floppy_image_legacy *floppy, int head, in
if(sector == sector_hdr[2])
{
if(sector_length)
*sector_length = (sector_hdr[15] << 8) | sector_hdr[14];
*sector_length = get_u16le(&sector_hdr[14]);
return FLOPPY_ERROR_SUCCESS;
}
len = (sector_hdr[15] << 8) | sector_hdr[14];
len = get_u16le(&sector_hdr[14]);
len += 16;
offset += len;
}
@ -164,7 +165,7 @@ static uint32_t d88_get_sector_offset(floppy_image_legacy* floppy, int head, int
LOG_FORMATS("d88_get_sector_offset - track %i, side %i, sector %02x, returns %08x\n",track,head,sector,offset+16);
return offset + 16;
}
len = (sector_hdr[15] << 8) | sector_hdr[14];
len = get_u16le(&sector_hdr[14]);
len += 16;
offset += len;
}
@ -194,7 +195,7 @@ static floperr_t d88_get_indexed_sector_info(floppy_image_legacy *floppy, int he
x=0;
while(x<sector_index)
{
offset += ((sector_hdr[15] << 8) | sector_hdr[14]);
offset += get_u16le(&sector_hdr[14]);
offset += 16;
floppy_image_read(floppy,sector_hdr,offset,16);
x++;
@ -204,7 +205,7 @@ static floperr_t d88_get_indexed_sector_info(floppy_image_legacy *floppy, int he
return FLOPPY_ERROR_SEEKERROR;
if(sector_length)
*sector_length = (sector_hdr[15] << 8) | sector_hdr[14];
*sector_length = get_u16le(&sector_hdr[14]);
if(cylinder)
*cylinder = sector_hdr[0];
if(side)
@ -278,7 +279,6 @@ static floperr_t d88_write_indexed_sector(floppy_image_legacy *floppy, int head,
static void d88_get_header(floppy_image_legacy* floppy,uint32_t* size, uint8_t* prot, uint8_t* type, uint32_t* offsets)
{
uint8_t header[D88_HEADER_LEN];
int x,s;
floppy_image_read(floppy,header,0,D88_HEADER_LEN);
@ -297,25 +297,11 @@ static void d88_get_header(floppy_image_legacy* floppy,uint32_t* size, uint8_t*
if(type)
*type = header[0x1b];
if(size)
{
s = 0;
s |= header[0x1f] << 24;
s |= header[0x1e] << 16;
s |= header[0x1d] << 8;
s |= header[0x1c];
*size = s;
}
*size = get_u32le(&header[0x1c]);
if(offsets)
{
for(x=0;x<164;x++)
{
s = 0;
s |= header[0x23 + (x*4)] << 24;
s |= header[0x22 + (x*4)] << 16;
s |= header[0x21 + (x*4)] << 8;
s |= header[0x20 + (x*4)];
*(offsets+x) = s;
}
for(int x=0;x<164;x++)
*(offsets+x) = get_u32le(&header[0x20 + (x*4)]);
}
}

View File

@ -14,6 +14,7 @@
#include "dfi_dsk.h"
#include "ioprocs.h"
#include "multibyte.h"
#include "osdcore.h" // osd_printf_*
@ -89,10 +90,10 @@ bool dfi_format::load(util::random_read &io, uint32_t form_factor, const std::ve
while(pos < size) {
uint8_t h[10];
io.read_at(pos, h, 10, actual);
uint16_t track = (h[0] << 8) | h[1];
uint16_t head = (h[2] << 8) | h[3];
uint16_t track = get_u16be(&h[0]);
uint16_t head = get_u16be(&h[2]);
// Ignore sector
uint32_t tsize = (h[6] << 24) | (h[7] << 16) | (h[8] << 8) | h[9];
uint32_t tsize = get_u32be(&h[6]);
// if the position-so-far-in-file plus 10 (for the header) plus track size
// is larger than the size of the file, free buffers and bail out

View File

@ -15,6 +15,7 @@ TODO:
#include "dmk_dsk.h"
#include "coretmpl.h"
#include "multibyte.h"
#include "ioprocs.h"
@ -77,7 +78,7 @@ int dmk_format::identify(util::random_read &io, uint32_t form_factor, const std:
io.read_at(0, header, header_size, actual);
int tracks = header[1];
int track_size = ( header[3] << 8 ) | header[2];
int track_size = get_u16le(&header[2]);
int heads = (header[4] & 0x10) ? 1 : 2;
// The first header byte must be 00 or FF
@ -116,7 +117,7 @@ bool dmk_format::load(util::random_read &io, uint32_t form_factor, const std::ve
io.read_at(0, header, header_size, actual);
const int tracks = header[1];
const int track_size = ( header[3] << 8 ) | header[2];
const int track_size = get_u16le(&header[2]);
const int heads = (header[4] & 0x10) ? 1 : 2;
const bool is_sd = (header[4] & 0x40) ? true : false;
@ -172,7 +173,7 @@ bool dmk_format::load(util::random_read &io, uint32_t form_factor, const std::ve
// Find IDAM/DAM locations
uint16_t track_header_offset = 0;
uint16_t track_offset = ( ( track_data[track_header_offset + 1] << 8 ) | track_data[track_header_offset] ) & 0x3fff;
uint16_t track_offset = get_u16le(&track_data[track_header_offset]) & 0x3fff;
bool idam_is_mfm = (track_data[track_header_offset + 1] & 0x80) ? true : false;
track_header_offset += 2;
@ -204,7 +205,7 @@ bool dmk_format::load(util::random_read &io, uint32_t form_factor, const std::ve
}
idam_is_mfm = (track_data[track_header_offset + 1] & 0x80) ? true : false;
track_offset = ( ( track_data[track_header_offset + 1] << 8 ) | track_data[track_header_offset] ) & 0x3fff;
track_offset = get_u16le(&track_data[track_header_offset]) & 0x3fff;
track_header_offset += 2;
}

View File

@ -104,10 +104,10 @@ static floperr_t get_offset(floppy_image_legacy *floppy, int head, int track, in
get_tag(floppy)->sector_size = (1<<(track_info[0x014]+7));
offs = track_offset + 0x100 +sector * get_tag(floppy)->sector_size;
} else {
get_tag(floppy)->sector_size = track_info[0x18 + (sector<<3) + 6] + (track_info[0x18+(sector<<3) + 7]<<8);
get_tag(floppy)->sector_size = get_u16le(&track_info[0x18 + (sector<<3) + 6]);
offs = track_offset + 0x100;
for (i=0;i<sector;i++) {
offs += track_info[0x18 + (i<<3) + 6] + (track_info[0x18+(i<<3) + 7]<<8);
offs += get_u16le(&track_info[0x18 + (i<<3) + 6]);
}
}

View File

@ -39,6 +39,7 @@
#include "fdos_dsk.h"
#include "imageutl.h"
#include "multibyte.h"
#include "ioprocs.h"
@ -141,17 +142,17 @@ int fdos_format::find_size(util::random_read &io, uint32_t form_factor, const st
continue;
if (info.start_sector != 0)
continue;
if ((info.num_sectors[0]<<8 | info.num_sectors[1]) != 0x0014)
if (get_u16be(info.num_sectors) != 0x0014)
continue;
// $DOS File type is supposed to be $11 but some disks (FDOSMPS) have $00
if (info.file_type != 0 && info.file_type != 0x11)
continue;
if ((info.start_addr[0]<<8 | info.start_addr[1]) != 0x2400)
if (get_u16be(info.start_addr) != 0x2400)
continue;
if ((info.end_addr[0]<<8 | info.end_addr[1]) != 0x2fff)
if (get_u16be(info.end_addr) != 0x2fff)
continue;
// FDOS entry is supposed to be $2600 but some disks have $2400
uint16_t exec = info.exec_addr[0]<<8 | info.exec_addr[1];
uint16_t exec = get_u16be(info.exec_addr);
if (exec != 0x2600 && exec != 0x2400)
continue;

View File

@ -11,6 +11,7 @@
#include "flopimg.h"
#include "ioprocs.h"
#include "multibyte.h"
#include "strformat.h"
#include <cstdio>
@ -2102,7 +2103,7 @@ std::vector<std::vector<uint8_t>> floppy_image_format_t::extract_sectors_from_tr
std::vector<uint32_t> hpos;
uint32_t hstate = (nib[nib.size() - 2] << 8) | nib[nib.size() - 1];
uint32_t hstate = get_u16be(&nib[nib.size() - 2]);
for(uint32_t pos = 0; pos != nib.size(); pos++) {
hstate = ((hstate << 8) | nib[pos]) & 0xffffff;
if(hstate == 0xd5aa96)

View File

@ -6,6 +6,8 @@
#include "fm7_cas.h"
#include "multibyte.h"
#include <cstring>
#define WAVE_HIGH 0x5a9e
@ -13,9 +15,8 @@
static int cas_size; // FIXME: global variable prevents multiple instances
static int fm7_fill_wave(int16_t* buffer, uint8_t high, uint8_t low, int sample_pos)
static int fm7_fill_wave(int16_t* buffer, uint16_t data, int sample_pos)
{
uint16_t data = (high << 8) + low;
int sample_count = 0;
int x = 0;
int count = (data & 0x7fff);
@ -51,7 +52,7 @@ static int fm7_handle_t77(int16_t* buffer, const uint8_t* casdata)
while(data_pos < cas_size)
{
sample_count += fm7_fill_wave(buffer,casdata[data_pos],casdata[data_pos+1],sample_count);
sample_count += fm7_fill_wave(buffer,get_u16be(&casdata[data_pos]),sample_count);
data_pos+=2;
}

View File

@ -10,7 +10,10 @@
#include "fs_isis.h"
#include "img_dsk.h"
#include "multibyte.h"
#include "strformat.h"
#include <bitset>
using namespace fs;
@ -583,7 +586,7 @@ void isis_impl::ensure_dir_loaded()
// +11: bytes in last sector
auto remainder = i[ 11 ];
// +12..+13: size in sectors
unsigned sectors = i[ 12 ] + (unsigned(i[ 13 ]) << 8);
unsigned sectors = get_u16le(&i[ 12 ]);
if (remainder > SECTOR_SIZE) {
throw std::runtime_error("Invalid dir. entry");
}

View File

@ -102,6 +102,7 @@
#include "hxchfe_dsk.h"
#include "ioprocs.h"
#include "multibyte.h"
#include "osdcore.h" // osd_printf_*
@ -201,7 +202,7 @@ bool hfe_format::load(util::random_read &io, uint32_t form_factor, const std::ve
return false;
}
info.m_bit_rate = (header[12] & 0xff) | ((header[13] & 0xff)<<8);
info.m_bit_rate = get_u16le(&header[12]);
if (info.m_bit_rate > 500)
{
@ -211,7 +212,7 @@ bool hfe_format::load(util::random_read &io, uint32_t form_factor, const std::ve
int samplelength = 500000 / info.m_bit_rate;
// Not used in the HxC emulator
info.m_floppy_rpm = (header[14] & 0xff) | ((header[15] & 0xff)<<8);
info.m_floppy_rpm = get_u16le(&header[14]);
info.m_interface_mode = (floppymode_t)(header[16] & 0xff);
if (info.m_interface_mode > S950_HD_FLOPPYMODE)
@ -228,14 +229,14 @@ bool hfe_format::load(util::random_read &io, uint32_t form_factor, const std::ve
info.m_track0s1_encoding = (encoding_t)(header[25] & 0xff);
// read track lookup table (multiple of 512)
int table_offset = (header[18] & 0xff) | ((header[19] & 0xff)<<8);
int table_offset = get_u16le(&header[18]);
io.read_at(table_offset<<9, track_table, TRACK_TABLE_LENGTH, actual);
for (int i=0; i < info.m_cylinders; i++)
{
info.m_cyl_offset[i] = (track_table[4*i] & 0xff) | ((track_table[4*i+1] & 0xff)<<8);
info.m_cyl_length[i] = (track_table[4*i+2] & 0xff) | ((track_table[4*i+3] & 0xff)<<8);
info.m_cyl_offset[i] = get_u16le(&track_table[4*i]);
info.m_cyl_length[i] = get_u16le(&track_table[4*i+2]);
}
// Load the tracks

View File

@ -3,6 +3,7 @@
#include "ipf_dsk.h"
#include "ioprocs.h"
#include "multibyte.h"
#include <cstring>
@ -54,11 +55,6 @@ bool ipf_format::load(util::random_read &io, uint32_t form_factor, const std::ve
return dec.parse(data, image);
}
uint32_t ipf_format::ipf_decode::r32(const uint8_t *p)
{
return (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3];
}
uint32_t ipf_format::ipf_decode::rb(const uint8_t *&p, int count)
{
@ -97,24 +93,24 @@ bool ipf_format::ipf_decode::parse(std::vector<uint8_t> &data, floppy_image *ima
bool ipf_format::ipf_decode::parse_info(const uint8_t *info)
{
type = r32(info+12);
type = get_u32be(info+12);
if(type != 1)
return false;
encoder_type = r32(info+16); // 1 for CAPS, 2 for SPS
encoder_revision = r32(info+20); // 1 always
release = r32(info+24);
revision = r32(info+28);
origin = r32(info+32); // Original source reference
min_cylinder = r32(info+36);
max_cylinder = r32(info+40);
min_head = r32(info+44);
max_head = r32(info+48);
credit_day = r32(info+52); // year*1e4 + month*1e2 + day
credit_time = r32(info+56); // hour*1e7 + min*1e5 + sec*1e3 + msec
encoder_type = get_u32be(info+16); // 1 for CAPS, 2 for SPS
encoder_revision = get_u32be(info+20); // 1 always
release = get_u32be(info+24);
revision = get_u32be(info+28);
origin = get_u32be(info+32); // Original source reference
min_cylinder = get_u32be(info+36);
max_cylinder = get_u32be(info+40);
min_head = get_u32be(info+44);
max_head = get_u32be(info+48);
credit_day = get_u32be(info+52); // year*1e4 + month*1e2 + day
credit_time = get_u32be(info+56); // hour*1e7 + min*1e5 + sec*1e3 + msec
for(int i=0; i<4; i++)
platform[i] = r32(info+60+4*i);
platform[i] = get_u32be(info+60+4*i);
for(int i=0; i<5; i++)
extra[i] = r32(info+76+4*i);
extra[i] = get_u32be(info+76+4*i);
return true;
}
@ -132,50 +128,50 @@ ipf_format::ipf_decode::track_info *ipf_format::ipf_decode::get_index(uint32_t i
bool ipf_format::ipf_decode::parse_imge(const uint8_t *imge)
{
track_info *t = get_index(r32(imge+64));
track_info *t = get_index(get_u32be(imge+64));
if(!t)
return false;
t->info_set = true;
t->cylinder = r32(imge+12);
t->cylinder = get_u32be(imge+12);
if(t->cylinder < min_cylinder || t->cylinder > max_cylinder)
return false;
t->head = r32(imge+16);
t->head = get_u32be(imge+16);
if(t->head < min_head || t->head > max_head)
return false;
t->type = r32(imge+20);
t->sigtype = r32(imge+24); // 1 for 2us cells, no other value valid
t->size_bytes = r32(imge+28);
t->index_bytes = r32(imge+32);
t->index_cells = r32(imge+36);
t->datasize_cells = r32(imge+40);
t->gapsize_cells = r32(imge+44);
t->size_cells = r32(imge+48);
t->block_count = r32(imge+52);
t->process = r32(imge+56); // encoder process, always 0
t->weak_bits = r32(imge+60);
t->reserved[0] = r32(imge+68);
t->reserved[1] = r32(imge+72);
t->reserved[2] = r32(imge+76);
t->type = get_u32be(imge+20);
t->sigtype = get_u32be(imge+24); // 1 for 2us cells, no other value valid
t->size_bytes = get_u32be(imge+28);
t->index_bytes = get_u32be(imge+32);
t->index_cells = get_u32be(imge+36);
t->datasize_cells = get_u32be(imge+40);
t->gapsize_cells = get_u32be(imge+44);
t->size_cells = get_u32be(imge+48);
t->block_count = get_u32be(imge+52);
t->process = get_u32be(imge+56); // encoder process, always 0
t->weak_bits = get_u32be(imge+60);
t->reserved[0] = get_u32be(imge+68);
t->reserved[1] = get_u32be(imge+72);
t->reserved[2] = get_u32be(imge+76);
return true;
}
bool ipf_format::ipf_decode::parse_data(const uint8_t *data, uint32_t &pos, uint32_t max_extra_size)
{
track_info *t = get_index(r32(data+24));
track_info *t = get_index(get_u32be(data+24));
if(!t)
return false;
t->data_size_bits = r32(data+16);
t->data_size_bits = get_u32be(data+16);
t->data = data+28;
t->data_size = r32(data+12);
t->data_size = get_u32be(data+12);
if(t->data_size > max_extra_size)
return false;
if(crc32r(t->data, t->data_size) != r32(data+20))
if(crc32r(t->data, t->data_size) != get_u32be(data+20))
return false;
pos += t->data_size;
return true;
@ -186,10 +182,10 @@ bool ipf_format::ipf_decode::scan_one_tag(std::vector<uint8_t> &data, uint32_t &
if(data.size()-pos < 12)
return false;
tag = &data[pos];
tsize = r32(tag+4);
tsize = get_u32be(tag+4);
if(data.size()-pos < tsize)
return false;
uint32_t crc = r32(tag+8);
uint32_t crc = get_u32be(tag+8);
tag[8] = tag[9] = tag[10] = tag[11] = 0;
if(crc32r(tag, tsize) != crc)
return false;
@ -208,7 +204,7 @@ bool ipf_format::ipf_decode::scan_all_tags(std::vector<uint8_t> &data)
if(!scan_one_tag(data, pos, tag, tsize))
return false;
switch(r32(tag)) {
switch(get_u32be(tag)) {
case 0x43415053: // CAPS
if(tsize != 12)
return false;
@ -361,7 +357,7 @@ bool ipf_format::ipf_decode::generate_timings(track_info *t, std::vector<uint32_
break;
case 9: {
uint32_t mask = r32(t->data + 32*t->block_count + 12);
uint32_t mask = get_u32be(t->data + 32*t->block_count + 12);
for(uint32_t i=1; i<t->block_count; i++)
timing_set(track, data_pos[i], gap_pos[i], mask & (1 << (i-1)) ? 1900 : 2100);
break;
@ -666,8 +662,8 @@ bool ipf_format::ipf_decode::generate_block(track_info *t, uint32_t idx, uint32_
const uint8_t *data = t->data;
const uint8_t *data_end = t->data + t->data_size;
const uint8_t *thead = data + 32*idx;
uint32_t data_cells = r32(thead);
uint32_t gap_cells = r32(thead+4);
uint32_t data_cells = get_u32be(thead);
uint32_t gap_cells = get_u32be(thead+4);
if(gap_cells < 8)
gap_cells = 0;
@ -684,9 +680,9 @@ bool ipf_format::ipf_decode::generate_block(track_info *t, uint32_t idx, uint32_
pos = gpos + gap_cells;
if(pos > t->size_cells)
return false;
if(!generate_block_data(data + r32(thead+28), data_end, track.begin()+dpos, track.begin()+gpos, context))
if(!generate_block_data(data + get_u32be(thead+28), data_end, track.begin()+dpos, track.begin()+gpos, context))
return false;
if(!generate_block_gap(r32(thead+20), gap_cells, r32(thead+24), spos, ipos > gpos ? ipos-gpos : 0, data + r32(thead+8), data_end, track.begin()+gpos, context))
if(!generate_block_gap(get_u32be(thead+20), gap_cells, get_u32be(thead+24), spos, ipos > gpos ? ipos-gpos : 0, data + get_u32be(thead+8), data_end, track.begin()+gpos, context))
return false;
spos += gpos;
@ -698,8 +694,8 @@ uint32_t ipf_format::ipf_decode::block_compute_real_size(track_info *t)
uint32_t size = 0;
const uint8_t *thead = t->data;
for(unsigned int i=0; i != t->block_count; i++) {
uint32_t data_cells = r32(thead);
uint32_t gap_cells = r32(thead+4);
uint32_t data_cells = get_u32be(thead);
uint32_t gap_cells = get_u32be(thead+4);
if(gap_cells < 8)
gap_cells = 0;

View File

@ -161,6 +161,7 @@
#include "formats/jfd_dsk.h"
#include "ioprocs.h"
#include "multibyte.h"
#include "osdcore.h" // osd_printf_*
@ -244,7 +245,7 @@ bool jfd_format::load(util::random_read &io, uint32_t form_factor, const std::ve
int err;
std::vector<uint8_t> gz_ptr;
z_stream d_stream;
int inflate_size = (img[size - 1] << 24) | (img[size - 2] << 16) | (img[size - 3] << 8) | img[size - 4];
int inflate_size = get_u32le(&img[size - 4]);
if (!memcmp(&img[0], GZ_HEADER, sizeof(GZ_HEADER))) {
gz_ptr.resize(inflate_size);

View File

@ -2,6 +2,8 @@
// copyright-holders:Wilbert Pol
#include "kim1_cas.h"
#include "multibyte.h"
#include <cstring>
#define SMPLO -32768
@ -87,8 +89,8 @@ static int kim1_handle_kim(int16_t *buffer, const uint8_t *casdata)
if ( cas_size < 9 ) return -1;
if ( memcmp( casdata, "KIM1", 4 ) ) return -1;
address = casdata[4] | ( casdata[5] << 8 );
size = casdata[6] | ( casdata[7] << 8 );
address = get_u16le( &casdata[4] );
size = get_u16le( &casdata[6] );
file_id = casdata[8];
data_pos = 9;

View File

@ -53,6 +53,7 @@
#include "imageutl.h"
#include "ioprocs.h"
#include "multibyte.h"
mdos_format::mdos_format() : wd177x_format(formats)
@ -158,9 +159,7 @@ int mdos_format::find_size(util::random_read &io, uint32_t form_factor, const st
// 10 words. The area beyond the zero word is not always zero filled,
// and is ignored here. Check that it is consistent with this.
for (int i = 0; i < 10; i++) {
uint8_t high = info.rib_addr[i * 2];
uint8_t low = info.rib_addr[i * 2 + 1];
uint16_t cluster = (high << 8) | low;
uint16_t cluster = get_u16be(&info.rib_addr[i * 2]);
if (cluster == 0)
break;

View File

@ -11,6 +11,7 @@
#include "oric_dsk.h"
#include "ioprocs.h"
#include "multibyte.h"
#include <cstring>
@ -44,9 +45,9 @@ int oric_dsk_format::identify(util::random_read &io, uint32_t form_factor, const
if(memcmp(h, "MFM_DISK", 8))
return 0;
int sides = (h[11] << 24) | (h[10] << 16) | (h[ 9] << 8) | h[ 8];
int tracks = (h[15] << 24) | (h[14] << 16) | (h[13] << 8) | h[12];
int geom = (h[19] << 24) | (h[18] << 16) | (h[17] << 8) | h[16];
int sides = get_u32le(&h[ 8]);
int tracks = get_u32le(&h[12]);
int geom = get_u32le(&h[16]);
uint64_t size;
if(io.length(size))
@ -66,8 +67,8 @@ bool oric_dsk_format::load(util::random_read &io, uint32_t form_factor, const st
t[6250] = t[6251] = t[6252] = 0;
io.read_at(0, h, 256, actual);
int sides = (h[11] << 24) | (h[10] << 16) | (h[ 9] << 8) | h[ 8];
int tracks = (h[15] << 24) | (h[14] << 16) | (h[13] << 8) | h[12];
int sides = get_u32le(&h[ 8]);
int tracks = get_u32le(&h[12]);
for(int side=0; side<sides; side++)
for(int track=0; track<tracks; track++) {

View File

@ -3,6 +3,8 @@
#include "oric_tap.h"
#include "imageutl.h"
#include "multibyte.h"
#define ORIC_WAV_DEBUG 0
#define LOG(x) do { if (ORIC_WAV_DEBUG) printf x; } while (0)
@ -314,8 +316,8 @@ static int oric_cassette_calculate_size_in_samples(const uint8_t *bytes, int len
oric.cassette_state = ORIC_CASSETTE_WRITE_DATA;
oric.data_count = 0;
end = (((header[4] & 0x0ff)<<8) | (header[5] & 0x0ff));
start = (((header[6] & 0x0ff)<<8) | (header[7] & 0x0ff));
end = get_u16be(&header[4]);
start = get_u16be(&header[6]);
LOG(("start (from header): %02x\n",start));
LOG(("end (from header): %02x\n",end));
oric.data_length = end - start + 1;
@ -451,8 +453,8 @@ static int oric_cassette_fill_wave(int16_t *buffer, int length, uint8_t *bytes)
oric.cassette_state = ORIC_CASSETTE_WRITE_DATA;
oric.data_count = 0;
end = (((header[4] & 0x0ff)<<8) | (header[5] & 0x0ff));
start = (((header[6] & 0x0ff)<<8) | (header[7] & 0x0ff));
end = get_u16be(&header[4]);
start = get_u16be(&header[6]);
LOG(("start (from header): %02x\n",start));
LOG(("end (from header): %02x\n",end));
oric.data_length = end - start + 1;

View File

@ -4,6 +4,7 @@
#include "imageutl.h"
#include "ioprocs.h"
#include "multibyte.h"
#include <cstring>
@ -84,11 +85,11 @@ bool pasti_format::load(util::random_read &io, uint32_t form_factor, const std::
for(int head=0; head < heads; head++) {
uint8_t th[16];
io.read_at(pos, th, 16, actual);
int entry_len = th[0] | (th[1] << 8) | (th[2] << 16) | (th[3] << 24);
int fuzz_len = th[4] | (th[5] << 8) | (th[6] << 16) | (th[7] << 24);
int sect = th[8] | (th[9] << 8);
int flags = th[10] | (th[11] << 8);
int track_len = th[12] | (th[13] << 8);
int entry_len = get_u32le(&th[0]);
int fuzz_len = get_u32le(&th[4]);
int sect = get_u16le(&th[8]);
int flags = get_u16le(&th[10]);
int track_len = get_u16le(&th[12]);
int track_num = th[14];
int flags2 = th[15];
@ -102,13 +103,13 @@ bool pasti_format::load(util::random_read &io, uint32_t form_factor, const std::
int syncpos = -1;
if(flags & 0x0080) {
syncpos = tdata[0] | (tdata[1] << 8);
syncpos = get_u16le(tdata);
tdata += 2;
}
int tsize = 0;
if(flags & 0x0040) {
tsize = tdata[0] | (tdata[1] << 8);
tsize = get_u16le(tdata);
tdata += 2;
} else
tdata = nullptr;
@ -133,10 +134,10 @@ bool pasti_format::load(util::random_read &io, uint32_t form_factor, const std::
for(int s=0; s<sect; s++) {
uint8_t *sh = &raw_track[16*s];
int s_off = sh[0] | (sh[1] << 8) | (sh[2] << 16) | (sh[3] << 24);
int s_pos = sh[4] | (sh[5] << 8);
int s_time = sh[6] | (sh[7] << 8);
int s_flags = sh[14] | (sh[15] << 8);
int s_off = get_u32le(&sh[0]);
int s_pos = get_u16le(&sh[4]);
int s_time = get_u16le(&sh[6]);
int s_flags = get_u16le(&sh[14]);
obs.sectors[s].data = bdata + s_off;
obs.sectors[s].fuzzy_mask = nullptr;

View File

@ -12,6 +12,8 @@
#include "pmd_cas.h"
#include "multibyte.h"
#define WAVEENTRY_LOW -32768
#define WAVEENTRY_HIGH 32767
@ -89,7 +91,7 @@ static void pmd85_printf_image_info(const uint8_t *bytes, int sample_count)
#if 0
char track_name[9];
uint32_t sec = (uint32_t)(sample_count/PMD85_WAV_FREQUENCY);
uint16_t addr = (bytes[0x33]<<8) | bytes[0x32];
uint16_t addr = get_u16le(&bytes[0x32]);
strncpy(track_name, (char*)&bytes[0x36], 8);
track_name[8] = '\0';
@ -135,7 +137,7 @@ static int pmd85_handle_cassette(int16_t *buffer, const uint8_t *bytes)
int data_pos = 0;
while (data_pos < pmd85_image_size)
{
uint16_t block_size = (bytes[data_pos + 1]<<8) | bytes[data_pos];
uint16_t block_size = get_u16le(&bytes[data_pos]);
int pause_len = PMD85_PAUSE_BITS;
data_pos += 2;

View File

@ -14,6 +14,7 @@
#include "sdf_dsk.h"
#include "ioprocs.h"
#include "multibyte.h"
sdf_format::sdf_format()
@ -118,8 +119,8 @@ bool sdf_format::load(util::random_read &io, uint32_t form_factor, const std::ve
{
if (i < sector_count )
{
idam_location[i] = ((track_data[ 8 * (i+1) + 1] << 8 | track_data[ 8 * (i+1)]) & 0x3FFF) - 4;
dam_location[i] = ((track_data[ 8 * (i+1) + 1 + 2] << 8 | track_data[ 8 * (i+1) + 2]) & 0x3FFF) - 4;
idam_location[i] = (get_u16le(&track_data[ 8 * (i+1)]) & 0x3FFF) - 4;
dam_location[i] = (get_u16le(&track_data[ 8 * (i+1) + 2]) & 0x3FFF) - 4;
if (idam_location[i] > TOTAL_TRACK_SIZE) return false;
if (dam_location[i] > TOTAL_TRACK_SIZE) return false;

View File

@ -36,6 +36,8 @@ SVT - The full explanation may be found on the Solace web site,
#include "sol_cas.h"
#include "multibyte.h"
#define WAVEENTRY_LOW -32768
#define WAVEENTRY_HIGH 32767
@ -82,17 +84,16 @@ static int sol20_output_bit(int16_t *buffer, int sample_pos, bool bit)
static int sol20_output_byte(int16_t *buffer, int sample_pos, uint8_t byte)
{
int samples = 0;
uint8_t i;
/* start */
samples += sol20_output_bit (buffer, sample_pos + samples, 0);
/* data */
for (i = 0; i<8; i++)
for (uint8_t i = 0; i<8; i++)
samples += sol20_output_bit (buffer, sample_pos + samples, (byte >> i) & 1);
/* stop */
for (i = 0; i<2; i++)
for (uint8_t i = 0; i<2; i++)
samples += sol20_output_bit (buffer, sample_pos + samples, 1);
return samples;
@ -157,11 +158,10 @@ static void sol20_scan_to_hex(const uint8_t *bytes)
static int sol20_read_hex(const uint8_t *bytes, uint8_t numdigits)
{
int data = 0;
uint8_t i,chr;
for (i = 0; i < numdigits; i++)
for (uint8_t i = 0; i < numdigits; i++)
{
chr = bytes[sol20_byte_num];
uint8_t chr = bytes[sol20_byte_num];
if ((chr >= '0') && (chr <= '9'))
{
data = (data << 4) | (chr-48);
@ -196,7 +196,7 @@ static int sol20_read_dec(const uint8_t *bytes)
static int sol20_handle_cassette(int16_t *buffer, const uint8_t *bytes)
{
uint32_t sample_count = 0;
uint32_t i = 0,t = 0;
uint32_t t = 0;
uint16_t cc = 0;
sol20_byte_num = 1;
bool process_d = 0;
@ -234,7 +234,7 @@ static int sol20_handle_cassette(int16_t *buffer, const uint8_t *bytes)
sol20_byte_num+=2; // bump to parameter
t = sol20_read_dec(bytes) * 140; // convert 10th of seconds to number of ones
for (i = 0; i < t; i++)
for (uint32_t i = 0; i < t; i++)
sample_count += sol20_output_bit(buffer, sample_count, 1);
sol20_scan_to_eol(bytes);
break;
@ -248,9 +248,9 @@ static int sol20_handle_cassette(int16_t *buffer, const uint8_t *bytes)
}
sol20_byte_num+=2; // bump to file name
for (i = 0; i < 5; i++)
for (uint32_t i = 0; i < 5; i++)
sol20_header[i] = 0x20;
for (i = 0; i < 5; i++)
for (uint32_t i = 0; i < 5; i++)
{
sol20_header[i] = bytes[sol20_byte_num++];
if (sol20_header[i] == 0x20)
@ -261,29 +261,24 @@ static int sol20_handle_cassette(int16_t *buffer, const uint8_t *bytes)
sol20_header[6] = sol20_read_hex(bytes, 2);
sol20_scan_to_hex(bytes); // bump to length
length = sol20_read_hex(bytes, 4);
sol20_header[7] = length;
sol20_header[8] = length >> 8;
put_u16le(&sol20_header[7], length);
sol20_scan_to_hex(bytes); // bump to load-address
i = sol20_read_hex(bytes, 4);
sol20_header[9] = i;
sol20_header[10] = i >> 8;
put_u16le(&sol20_header[9], sol20_read_hex(bytes, 4));
sol20_scan_to_hex(bytes); // bump to exec-address
i = sol20_read_hex(bytes, 4);
sol20_header[11] = i;
sol20_header[12] = i >> 8;
put_u16le(&sol20_header[11], sol20_read_hex(bytes, 4));
sol20_header[13] = 0;
sol20_header[14] = 0;
sol20_header[15] = 0;
sol20_cksm_byte = 0;
for (i = 0; i < 16; i++)
for (uint32_t i = 0; i < 16; i++)
sol20_cksm_byte = sol20_calc_cksm(sol20_cksm_byte, sol20_header[i]);
// write leader
for (i = 0; i < 100; i++)
for (uint32_t i = 0; i < 100; i++)
sample_count += sol20_output_byte(buffer, sample_count, 0);
// write SOH
sample_count += sol20_output_byte(buffer, sample_count, 1);
// write Header
for (i = 0; i < 16; i++)
for (uint32_t i = 0; i < 16; i++)
sample_count += sol20_output_byte(buffer, sample_count, sol20_header[i]);
// write checksum
sample_count += sol20_output_byte(buffer, sample_count, sol20_cksm_byte);

View File

@ -11,6 +11,7 @@
#include "formats/st_dsk.h"
#include "ioprocs.h"
#include "multibyte.h"
#include <cstring>
@ -153,11 +154,11 @@ void msa_format::read_header(util::random_read &io, uint16_t &sign, uint16_t &se
uint8_t h[10];
size_t actual;
io.read_at(0, h, 10, actual);
sign = (h[0] << 8) | h[1];
sect = (h[2] << 8) | h[3];
head = (h[4] << 8) | h[5];
strack = (h[6] << 8) | h[7];
etrack = (h[8] << 8) | h[9];
sign = get_u16be(&h[0]);
sect = get_u16be(&h[2]);
head = get_u16be(&h[4]);
strack = get_u16be(&h[6]);
etrack = get_u16be(&h[8]);
}
bool msa_format::uncompress(uint8_t *buffer, int csize, int usize)
@ -170,7 +171,7 @@ bool msa_format::uncompress(uint8_t *buffer, int csize, int usize)
if(csize-src < 3)
return false;
c = buffer[src++];
int count = (buffer[src] << 8) | buffer[src+1];
int count = get_u16be(&buffer[src]);
src += 2;
if(usize-dst < count)
return false;
@ -201,8 +202,8 @@ bool msa_format::compress(const uint8_t *buffer, int usize, uint8_t *dest, int &
return false;
dest[dst++] = 0xe5;
dest[dst++] = c;
dest[dst++] = ncopy >> 8;
dest[dst++] = ncopy;
put_u16be(&dest[dst], ncopy);
dst += 2;
} else {
src -= ncopy-1;
dest[dst++] = c;
@ -250,7 +251,7 @@ bool msa_format::load(util::random_read &io, uint32_t form_factor, const std::ve
uint8_t th[2];
io.read_at(pos, th, 2, actual);
pos += 2;
int tsize = (th[0] << 8) | th[1];
int tsize = get_u16be(th);
io.read_at(pos, sectdata, tsize, actual);
pos += tsize;
if(tsize < track_size) {
@ -313,14 +314,12 @@ bool msa_format::save(util::random_read_write &io, const std::vector<uint32_t> &
int csize;
if(compress(sectdata, track_size, compdata, csize)) {
uint8_t th[2];
th[0] = csize >> 8;
th[1] = csize;
put_u16be(th, csize);
io.write(th, 2, actual);
io.write(compdata, csize, actual);
} else {
uint8_t th[2];
th[0] = track_size >> 8;
th[1] = track_size;
put_u16be(th, track_size);
io.write(th, 2, actual);
io.write(sectdata, track_size, actual);
}

View File

@ -17,6 +17,7 @@
#include "flopimg_legacy.h"
#include "ioprocs.h"
#include "multibyte.h"
#include <cstring>
@ -174,7 +175,7 @@ static floperr_t get_offset(floppy_image_legacy *floppy, int head, int track, in
offs+= 6;
if ((header[4] & 0x30)==0) {
offs+= 2;
offs+= header[6] + (header[7]<<8);
offs+= get_u16le(&header[6]);
}
}
// read size of sector
@ -213,7 +214,7 @@ static floperr_t internal_td0_read_sector(floppy_image_legacy *floppy, int head,
offset+=3;
// take data size
size = header[6] + (header[7]<<8)-1;
size = get_u16le(&header[6])-1;
// take real sector size
realsize = 1 << (header[3] + 7);
@ -234,7 +235,7 @@ static floperr_t internal_td0_read_sector(floppy_image_legacy *floppy, int head,
// - 2 bytes of data
// data is reapeted specified number of times
while(buff_pos<realsize) {
for (i=0;i<data[data_pos]+(data[data_pos+1] << 8);i++) {
for (i=0;i<get_u16le(&data[data_pos]);i++) {
buf[buff_pos] = data[data_pos+2];buff_pos++;
buf[buff_pos] = data[data_pos+3];buff_pos++;
}
@ -731,7 +732,7 @@ FLOPPY_CONSTRUCT( td0_dsk_construct )
// header len + comment header + comment len
position = 12;
if (header[7] & 0x80) {
position += 10 + header[14] + (header[15]<<8);
position += 10 + get_u16le(&header[14]);
}
tag->tracks = 0;
do {
@ -752,7 +753,7 @@ FLOPPY_CONSTRUCT( td0_dsk_construct )
header = tag->data + position;
position+=2;
// skip sector data
position+= header[0] + (header[1]<<8);
position+= get_u16le(&header[0]);
}
}
tag->tracks++;
@ -854,7 +855,7 @@ bool td0_format::load(util::random_read &io, uint32_t form_factor, const std::ve
// skip optional comment section
if(header[7] & 0x80)
offset = 10 + imagebuf[2] + (imagebuf[3] << 8);
offset = 10 + get_u16le(&imagebuf[2]);
track_spt = imagebuf[offset];
if(track_spt == 255) // Empty file?
@ -969,7 +970,7 @@ bool td0_format::load(util::random_read &io, uint32_t form_factor, const std::ve
offset += 4;
if(actual < offset)
return false;
k = (hs[9] + (hs[10] << 8)) * 2;
k = get_u16le(&hs[9]) * 2;
k = (k <= size) ? k : size;
for(j = 0; j < k; j += 2)
{

View File

@ -10,6 +10,8 @@
#include "tvc_cas.h"
#include "multibyte.h"
#define TVC64_BIT0_FREQ 1812
#define TVC64_BIT1_FREQ 2577
@ -93,7 +95,7 @@ static cassette_image::error tvc64_cassette_load(cassette_image *cassette)
uint8_t header[TVC64_HEADER_BYTES];
cassette->image_read(header, 0, TVC64_HEADER_BYTES);
uint16_t cas_size = (header[0x83]<<8) | header[0x82];
uint16_t cas_size = get_u16le(&header[0x82]);
// tape header
tmp_buff[buff_idx++] = 0x00;

View File

@ -30,6 +30,8 @@ TODO:
#include "tzx_cas.h"
#include "imageutl.h"
#include "multibyte.h"
#include <cmath>
@ -101,12 +103,12 @@ static void tzx_cas_get_blocks( const uint8_t *casdata, int caslen )
{
case 0x10:
pos += 2;
datasize = casdata[pos] + (casdata[pos + 1] << 8);
datasize = get_u16le(&casdata[pos]);
pos += 2 + datasize;
break;
case 0x11:
pos += 0x0f;
datasize = casdata[pos] + (casdata[pos + 1] << 8) + (casdata[pos + 2] << 16);
datasize = get_u24le(&casdata[pos]);
pos += 3 + datasize;
break;
case 0x12:
@ -118,12 +120,12 @@ static void tzx_cas_get_blocks( const uint8_t *casdata, int caslen )
break;
case 0x14:
pos += 7;
datasize = casdata[pos] + (casdata[pos + 1] << 8) + (casdata[pos + 2] << 16);
datasize = get_u24le(&casdata[pos]);
pos += 3 + datasize;
break;
case 0x15:
pos += 5;
datasize = casdata[pos] + (casdata[pos + 1] << 8) + (casdata[pos + 2] << 16);
datasize = get_u24le(&casdata[pos]);
pos += 3 + datasize;
break;
case 0x20: case 0x23:
@ -131,7 +133,7 @@ static void tzx_cas_get_blocks( const uint8_t *casdata, int caslen )
break;
case 0x24:
loopcount = casdata[pos] + (casdata[pos + 1] << 8);
loopcount = get_u16le(&casdata[pos]);
pos +=2;
loopoffset = pos;
break;
@ -152,11 +154,11 @@ static void tzx_cas_get_blocks( const uint8_t *casdata, int caslen )
break;
case 0x26:
datasize = casdata[pos] + (casdata[pos + 1] << 8);
datasize = get_u16le(&casdata[pos]);
pos += 2 + 2 * datasize;
break;
case 0x28: case 0x32:
datasize = casdata[pos] + (casdata[pos + 1] << 8);
datasize = get_u16le(&casdata[pos]);
pos += 2 + datasize;
break;
case 0x31:
@ -173,19 +175,19 @@ static void tzx_cas_get_blocks( const uint8_t *casdata, int caslen )
break;
case 0x35:
pos += 0x10;
datasize = casdata[pos] + (casdata[pos + 1] << 8) + (casdata[pos + 2] << 16) + (casdata[pos + 3] << 24);
datasize = get_u32le(&casdata[pos]);
pos += 4 + datasize;
break;
case 0x40:
pos += 1;
datasize = casdata[pos] + (casdata[pos + 1] << 8) + (casdata[pos + 2] << 16);
datasize = get_u24le(&casdata[pos]);
pos += 3 + datasize;
break;
case 0x5A:
pos += 9;
break;
default:
datasize = casdata[pos] + (casdata[pos + 1] << 8) + (casdata[pos + 2] << 16) + (casdata[pos + 3] << 24);
datasize = get_u32le(&casdata[pos]);
pos += 4 + datasize;
break;
}
@ -360,7 +362,7 @@ static inline int tzx_handle_symbol(int16_t **buffer, const uint8_t *symtable, u
for (int i = 0; i < maxp; i++)
{
uint16_t pulse_length = cursymb[1 + (i*2)] | (cursymb[2 + (i*2)] << 8);
uint16_t pulse_length = get_u16le(&cursymb[1 + (i*2)]);
// shorter lists can be terminated with a pulse_length of 0
if (pulse_length != 0)
@ -415,7 +417,7 @@ static int tzx_handle_generalized(int16_t **buffer, const uint8_t *bytes, int pa
for (int i = 0; i < totp*3; i+=3)
{
uint8_t symbol = table2[i + 0];
uint16_t repetitions = table2[i + 1] + (table2[i + 2] << 8);
uint16_t repetitions = get_u16le(&table2[i + 1]);
//printf("symbol %02x repetitions %04x\n", symbol, repetitions); // does 1 mean repeat once, or that it only occurs once?
for (int j = 0; j < repetitions; j++)
@ -523,28 +525,28 @@ static int tzx_cas_do_work( int16_t **buffer )
switch (block_type)
{
case 0x10: /* Standard Speed Data Block (.TAP block) */
pause_time = cur_block[1] + (cur_block[2] << 8);
data_size = cur_block[3] + (cur_block[4] << 8);
pause_time = get_u16le(&cur_block[1]);
data_size = get_u16le(&cur_block[3]);
pilot_length = (cur_block[5] < 128) ? 8063 : 3223;
size += tzx_cas_handle_block(buffer, &cur_block[5], pause_time, data_size, 2168, pilot_length, 667, 735, 855, 1710, 8);
current_block++;
break;
case 0x11: /* Turbo Loading Data Block */
pilot = cur_block[1] + (cur_block[2] << 8);
sync1 = cur_block[3] + (cur_block[4] << 8);
sync2 = cur_block[5] + (cur_block[6] << 8);
bit0 = cur_block[7] + (cur_block[8] << 8);
bit1 = cur_block[9] + (cur_block[10] << 8);
pilot_length = cur_block[11] + (cur_block[12] << 8);
pilot = get_u16le(&cur_block[1]);
sync1 = get_u16le(&cur_block[3]);
sync2 = get_u16le(&cur_block[5]);
bit0 = get_u16le(&cur_block[7]);
bit1 = get_u16le(&cur_block[9]);
pilot_length = get_u16le(&cur_block[11]);
bits_in_last_byte = cur_block[13];
pause_time = cur_block[14] + (cur_block[15] << 8);
data_size = cur_block[16] + (cur_block[17] << 8) + (cur_block[18] << 16);
pause_time = get_u16le(&cur_block[14]);
data_size = get_u24le(&cur_block[16]);
size += tzx_cas_handle_block(buffer, &cur_block[19], pause_time, data_size, pilot, pilot_length, sync1, sync2, bit0, bit1, bits_in_last_byte);
current_block++;
break;
case 0x12: /* Pure Tone */
pilot = cur_block[1] + (cur_block[2] << 8);
pilot_length = cur_block[3] + (cur_block[4] << 8);
pilot = get_u16le(&cur_block[1]);
pilot_length = get_u16le(&cur_block[3]);
size += tzx_cas_handle_block(buffer, cur_block, 0, 0, pilot, pilot_length, 0, 0, 0, 0, 0);
current_block++;
break;
@ -557,16 +559,16 @@ static int tzx_cas_do_work( int16_t **buffer )
current_block++;
break;
case 0x14: /* Pure Data Block */
bit0 = cur_block[1] + (cur_block[2] << 8);
bit1 = cur_block[3] + (cur_block[4] << 8);
bit0 = get_u16le(&cur_block[1]);
bit1 = get_u16le(&cur_block[3]);
bits_in_last_byte = cur_block[5];
pause_time = cur_block[6] + (cur_block[7] << 8);
data_size = cur_block[8] + (cur_block[9] << 8) + (cur_block[10] << 16);
pause_time = get_u16le(&cur_block[6]);
data_size = get_u24le(&cur_block[8]);
size += tzx_cas_handle_block(buffer, &cur_block[11], pause_time, data_size, 0, 0, 0, 0, bit0, bit1, bits_in_last_byte);
current_block++;
break;
case 0x20: /* Pause (Silence) or 'Stop the Tape' Command */
pause_time = cur_block[1] + (cur_block[2] << 8);
pause_time = get_u16le(&cur_block[1]);
if (pause_time == 0)
{
/* pause = 0 is used to let an emulator automagically stop the tape
@ -606,7 +608,7 @@ static int tzx_cas_do_work( int16_t **buffer )
break;
case 0x32: /* Archive Info */
ascii_block_common_log("Archive Info Block", block_type);
total_size = cur_block[1] + (cur_block[2] << 8);
total_size = get_u16le(&cur_block[1]);
text_size = 0;
for (data_size = 0; data_size < cur_block[3]; data_size++) // data_size = number of text blocks, in this case
{
@ -644,7 +646,7 @@ static int tzx_cas_do_work( int16_t **buffer )
LOG_FORMATS("%c", cur_block[1 + data_size]);
}
LOG_FORMATS(":\n");
text_size = cur_block[11] + (cur_block[12] << 8) + (cur_block[13] << 16) + (cur_block[14] << 24);
text_size = get_u32le(&cur_block[11]);
for (data_size = 0; data_size < text_size; data_size++)
LOG_FORMATS("%c", cur_block[15 + data_size]);
LOG_FORMATS("\n");
@ -656,7 +658,7 @@ static int tzx_cas_do_work( int16_t **buffer )
current_block++;
break;
case 0x24: /* Loop Start */
loopcount = cur_block[1] + (cur_block[2] << 8);
loopcount = get_u16le(&cur_block[1]);
current_block++;
loopoffset = current_block;
@ -690,10 +692,10 @@ static int tzx_cas_do_work( int16_t **buffer )
case 0x15: /* Direct Recording */ // used on 'bombscar' in the cpc_cass list
// having this missing is fatal
tstates = cur_block[1] + (cur_block[2] << 8);
pause_time= cur_block[3] + (cur_block[4] << 8);
tstates = get_u16le(&cur_block[1]);
pause_time = get_u16le(&cur_block[3]);
bits_in_last_byte = cur_block[5];
data_size = cur_block[6] + (cur_block[7] << 8) + (cur_block[8] << 16);
data_size = get_u24le(&cur_block[6]);
size += tzx_handle_direct(buffer, &cur_block[9], pause_time, data_size, tstates, bits_in_last_byte);
current_block++;
break;
@ -708,15 +710,15 @@ static int tzx_cas_do_work( int16_t **buffer )
{
// having this missing is fatal
// used crudely by batmanc in spectrum_cass list (which is just a redundant encoding of batmane ?)
data_size = cur_block[1] + (cur_block[2] << 8) + (cur_block[3] << 16) + (cur_block[4] << 24);
pause_time= cur_block[5] + (cur_block[6] << 8);
data_size = get_u32le(&cur_block[1]);
pause_time = get_u16le(&cur_block[5]);
uint32_t totp = cur_block[7] + (cur_block[8] << 8) + (cur_block[9] << 16) + (cur_block[10] << 24);
uint32_t totp = get_u32le(&cur_block[7]);
int npp = cur_block[11];
int asp = cur_block[12];
if (asp == 0 && totp > 0) asp = 256;
uint32_t totd = cur_block[13] + (cur_block[14] << 8) + (cur_block[15] << 16) + (cur_block[16] << 24);
uint32_t totd = get_u32le(&cur_block[13]);
int npd = cur_block[17];
int asd = cur_block[18];
if (asd == 0 && totd > 0) asd = 256;
@ -802,7 +804,7 @@ static int tap_cas_to_wav_size( const uint8_t *casdata, int caslen )
while (p < casdata + caslen)
{
int data_size = p[0] + (p[1] << 8);
int data_size = get_u16le(&p[0]);
int pilot_length = (p[2] == 0x00) ? 8063 : 3223;
LOG_FORMATS("tap_cas_to_wav_size: Handling TAP block containing 0x%X bytes", data_size);
p += 2;
@ -820,7 +822,7 @@ static int tap_cas_fill_wave( int16_t *buffer, int length, uint8_t *bytes )
while (size < length)
{
int data_size = bytes[0] + (bytes[1] << 8);
int data_size = get_u16le(&bytes[0]);
int pilot_length = (bytes[2] == 0x00) ? 8063 : 3223;
LOG_FORMATS("tap_cas_fill_wave: Handling TAP block containing 0x%X bytes\n", data_size);
bytes += 2;

View File

@ -20,6 +20,8 @@ Not nice, but it works...
#include "uef_cas.h"
#include "imageutl.h"
#include "multibyte.h"
#include <zlib.h>
#include <cmath>
@ -64,7 +66,7 @@ static const uint8_t* skip_gz_header( const uint8_t *p ) {
/* Skip the extra field */
if ( ( flags & EXTRA_FIELD ) != 0 ) {
int len = ( p[1] << 8 ) | p[0];
int len = get_u16le( &p[0] );
p += 2 + len;
}
/* Skip the original file name */
@ -94,13 +96,13 @@ static float get_uef_float( const uint8_t *Float)
was the first byte read from the UEF, Float[1] the second, etc */
/* decode mantissa */
Mantissa = Float[0] | (Float[1] << 8) | ((Float[2]&0x7f)|0x80) << 16;
Mantissa = get_u24be(&Float[0]) | 0x800000;
Result = (float)Mantissa;
Result = (float)ldexp(Result, -23);
/* decode exponent */
Exponent = ((Float[2]&0x80) >> 7) | (Float[3]&0x7f) << 1;
Exponent = (get_u16be(&Float[2])&0x7f80) >> 7;
Exponent -= 127;
Result = (float)ldexp(Result, Exponent);
@ -118,7 +120,7 @@ static int uef_cas_to_wav_size( const uint8_t *casdata, int caslen ) {
if ( casdata[0] == 0x1f && casdata[1] == 0x8b ) {
int err;
z_stream d_stream;
int inflate_size = ( casdata[ caslen - 1 ] << 24 ) | ( casdata[ caslen - 2 ] << 16 ) | ( casdata[ caslen - 3 ] << 8 ) | casdata[ caslen - 4 ];
int inflate_size = get_u32le( &casdata[ caslen - 4 ] );
const uint8_t *in_ptr = skip_gz_header( casdata );
if ( in_ptr == nullptr ) {
@ -166,8 +168,8 @@ static int uef_cas_to_wav_size( const uint8_t *casdata, int caslen ) {
size = 0;
pos = sizeof(UEF_HEADER) + 2;
while( pos < caslen ) {
int chunk_type = ( casdata[pos+1] << 8 ) | casdata[pos];
int chunk_length = ( casdata[pos+5] << 24 ) | ( casdata[pos+4] << 16 ) | ( casdata[pos+3] << 8 ) | casdata[pos+2];
int chunk_type = get_u16le( &casdata[pos] );
int chunk_length = get_u32le( &casdata[pos+2] );
int baud_length;
pos += 6;
@ -187,14 +189,14 @@ static int uef_cas_to_wav_size( const uint8_t *casdata, int caslen ) {
size += ( chunk_length * 10 ) * 4;
break;
case 0x0110: /* carrier tone (previously referred to as 'high tone') */
baud_length = ( casdata[pos+1] << 8 ) | casdata[pos];
baud_length = get_u16le( &casdata[pos] );
size += baud_length * 2;
break;
case 0x0111:
LOG_FORMATS( "Unsupported chunk type: %04x\n", chunk_type );
break;
case 0x0112: /* integer gap */
baud_length = ( casdata[pos+1] << 8 ) | casdata[pos];
baud_length = get_u16le( &casdata[pos] );
size += baud_length * 2 ;
break;
case 0x0116: /* floating point gap */
@ -259,8 +261,8 @@ static int uef_cas_fill_wave( int16_t *buffer, int length, uint8_t *bytes )
uint32_t pos = sizeof(UEF_HEADER) + 2;
length = length / 2;
while( length > 0 ) {
int chunk_type = ( bytes[pos+1] << 8 ) | bytes[pos];
int chunk_length = ( bytes[pos+5] << 24 ) | ( bytes[pos+4] << 16 ) | ( bytes[pos+3] << 8 ) | bytes[pos+2];
int chunk_type = get_u16le( &bytes[pos] );
int chunk_length = get_u32le( &bytes[pos+2] );
uint32_t baud_length, j;
uint8_t i, *c;
@ -295,14 +297,14 @@ static int uef_cas_fill_wave( int16_t *buffer, int length, uint8_t *bytes )
}
break;
case 0x0110: /* carrier tone (previously referred to as 'high tone') */
for( baud_length = ( ( bytes[pos+1] << 8 ) | bytes[pos] ) ; baud_length; baud_length-- ) {
for( baud_length = get_u16le( &bytes[pos] ) ; baud_length; baud_length-- ) {
*p = WAVE_LOW; p++;
*p = WAVE_HIGH; p++;
length -= 2;
}
break;
case 0x0112: /* integer gap */
for( baud_length = ( ( bytes[pos+1] << 8 ) | bytes[pos] ) ; baud_length; baud_length-- ) {
for( baud_length = get_u16le( &bytes[pos] ) ; baud_length; baud_length-- ) {
*p = WAVE_NULL; p++;
*p = WAVE_NULL; p++;
length -= 2;
@ -315,7 +317,7 @@ static int uef_cas_fill_wave( int16_t *buffer, int length, uint8_t *bytes )
}
break;
case 0x0117: /* change baud rate */
baud_length = ( bytes[pos+1] << 8 ) | bytes[pos];
baud_length = get_u16le( &bytes[pos] );
// These are the only supported numbers
if (baud_length == 300)
loops = 4;

View File

@ -8,6 +8,8 @@
#include "vg5k_cas.h"
#include "multibyte.h"
#define SMPLO -32768
#define SILENCE 0
@ -143,7 +145,7 @@ static int vg5k_handle_tap(int16_t *buffer, const uint8_t *casdata)
else if (casdata[data_pos] == 0xd6)
{
/* data block size is defined in head block */
block_size = (casdata[data_pos - 4] | casdata[data_pos - 3]<<8) + 20;
block_size = get_u16le(&casdata[data_pos - 4]) + 20;
/* 10000 samples of silence before the data block */
sample_count += vg5k_cas_silence(buffer, sample_count, 10000);

View File

@ -11,6 +11,7 @@
#include "formats/vt_dsk.h"
#include "ioprocs.h"
#include "multibyte.h"
#include "osdcomm.h"
@ -401,8 +402,8 @@ bool vtech_dsk_format::save(util::random_read_write &io, const std::vector<uint3
chk += src[i];
bdatax[pos++] = src[i];
}
bdatax[pos++] = chk;
bdatax[pos++] = chk >> 8;
put_u16le(&bdatax[pos], chk);
pos += 2;
}
}

View File

@ -23,6 +23,8 @@
#include "x1_tap.h"
#include "imageutl.h"
#include "multibyte.h"
#include <cstring>
@ -81,7 +83,7 @@ static int x1_cas_to_wav_size (const uint8_t *casdata, int caslen)
ret = casdata[0x20] | (casdata[0x21] << 8) | (casdata[0x22] << 16) | (casdata[0x23] << 24);
cas_size = ret;
samplerate = casdata[0x1c] | (casdata[0x1d] << 8) | (casdata[0x1e] << 16) | (casdata[0x1f] << 24);
samplerate = get_u32le(&casdata[0x1c]);
new_format = 1;
}
else // old TAP format
@ -89,7 +91,7 @@ static int x1_cas_to_wav_size (const uint8_t *casdata, int caslen)
ret = (caslen - 4) * 8; // each byte = 8 samples
cas_size = ret;
samplerate = casdata[0x00] | (casdata[0x01] << 8) | (casdata[0x02] << 16) | (casdata[0x03] << 24);
samplerate = get_u32le(&casdata[0x00]);
new_format = 0;
}