Skip to content

Commit

Permalink
Merge branch 'issue92' into sf/integra
Browse files Browse the repository at this point in the history
  • Loading branch information
Steve Fosdick committed Sep 27, 2019
2 parents edb7be9 + 6798382 commit 8f73f4c
Show file tree
Hide file tree
Showing 11 changed files with 268 additions and 18 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,6 @@ src/jstest
src/jstest.exe
src/gtest
src/gtest.exe
src/fsmap
src/hdfmt
src/fdresize
4 changes: 3 additions & 1 deletion src/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Makefile.am for B-em

bin_PROGRAMS = b-em jstest gtest
bin_PROGRAMS = b-em hdfmt jstest gtest
noinst_SCRIPTS = ../b-em
CLEANFILES = $(noinst_SCRIPTS)

Expand Down Expand Up @@ -125,6 +125,8 @@ if NO_TSEARCH
b_em_SOURCES += tsearch.c
endif

hdfmt_SOURCES = hdfmt.c

jstest_SOURCES = jstest.c

jstest_LDADD = -lallegro -lallegro_main
Expand Down
7 changes: 5 additions & 2 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,13 @@ void config_save(void)
set_config_path("disc", "disc0", discfns[0]);
set_config_path("disc", "disc1", discfns[1]);
set_config_string("disc", "mmb", mmb_fn);
set_config_path("tape", "tape", tape_fn);

set_config_bool("disc", "defaultwriteprotect", defaultwriteprot);

if (tape_loaded)
al_set_config_value(bem_cfg, "tape", "tape", al_path_cstr(tape_fn, ALLEGRO_NATIVE_PATH_SEP));
else
al_remove_config_key(bem_cfg, "tape", "tape");

set_config_int(NULL, "model", curmodel);
set_config_int(NULL, "tube", selecttube);
set_config_int(NULL, "tubespeed", tube_speed_num);
Expand Down
50 changes: 50 additions & 0 deletions src/fsmap.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#include <errno.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(int argc, char **argv)
{
int status;

if (argc > 1) {
status = 0;
while (--argc) {
const char *fn = *++argv;
FILE *fp = fopen(fn, "rb");
if (fp) {
unsigned char fsmap[0x200];
if (fread(fsmap, sizeof fsmap, 1, fp) == 1) {
puts(fn);
unsigned char *sptr = fsmap;
unsigned char *eptr = fsmap + fsmap[0x1FE];
unsigned char *lptr = fsmap + 0x100;
while (sptr < eptr) {
uint32_t start = *sptr++;
start |= (*sptr++ << 8);
start |= (*sptr++ << 16);
uint32_t len = *lptr++;
len |= (*lptr++ << 8);
len |= (*lptr++ << 16);
if (len > 0)
printf("%06X %06X (%d)\n", start, len, len);
}
}
else {
fprintf(stderr, "fsmap: unable to read fsmap from %s: %s\n", fn, strerror(errno));
status = 3;
}
}
else {
fprintf(stderr, "fsmap: unable to open %s for reading: %s\n", fn, strerror(errno));
status = 2;
}
}
}
else {
fputs("Usage: fsmap <dat-file> [ ... ]\n", stderr);
status = 1;
}
return status;
}
16 changes: 13 additions & 3 deletions src/gui-allegro.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "6502.h"
#include "ide.h"
#include "config.h"
#include "debugger.h"
#include "ddnoise.h"
#include "disc.h"
Expand Down Expand Up @@ -178,8 +179,8 @@ static ALLEGRO_MENU *create_tape_menu(void)
ALLEGRO_MENU *speed = al_create_menu();
int nflags, fflags;
al_append_menu_item(menu, "Load tape...", IDM_TAPE_LOAD, 0, NULL, NULL);
al_append_menu_item(menu, "Rewind tape", IDM_TAPE_EJECT, 0, NULL, NULL);
al_append_menu_item(menu, "Eject tape", IDM_TAPE_REWIND, 0, NULL, NULL);
al_append_menu_item(menu, "Rewind tape", IDM_TAPE_REWIND, 0, NULL, NULL);
al_append_menu_item(menu, "Eject tape", IDM_TAPE_EJECT, 0, NULL, NULL);
al_append_menu_item(menu, "Catalogue tape", IDM_TAPE_CAT, 0, NULL, NULL);
if (fasttape) {
nflags = ALLEGRO_MENU_ITEM_CHECKBOX;
Expand Down Expand Up @@ -239,12 +240,20 @@ static ALLEGRO_MENU *create_rom_menu(void)
static void update_rom_menu(void)
{
ALLEGRO_MENU *menu = rom_menu;
int slot;
ALLEGRO_MENU *sub;
int slot, flags;
char label[ROM_LABEL_LEN];

for (slot = ROM_NSLOT-1; slot >= 0; slot--) {
gen_rom_label(slot, label);
al_set_menu_item_caption(menu, slot-ROM_NSLOT+1, label);
sub = al_find_menu(menu, slot+1);
if (sub) {
flags = rom_slots[slot].swram ? ALLEGRO_MENU_ITEM_CHECKBOX|ALLEGRO_MENU_ITEM_CHECKED : ALLEGRO_MENU_ITEM_CHECKBOX;
al_set_menu_item_flags(sub, menu_id_num(IDM_ROMS_RAM, slot), flags);
}
else
log_debug("gui-allegro: ROM sub-menu not found for slot %d", slot);
}
}

Expand Down Expand Up @@ -864,6 +873,7 @@ static void change_model(ALLEGRO_EVENT *event)
{
ALLEGRO_MENU *menu = (ALLEGRO_MENU *)(event->user.data3);
al_set_menu_item_flags(menu, menu_id_num(IDM_MODEL, curmodel), ALLEGRO_MENU_ITEM_CHECKBOX);
config_save();
oldmodel = curmodel;
curmodel = menu_get_num(event);
main_restart();
Expand Down
2 changes: 1 addition & 1 deletion src/hdfmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ int main(int argc, char **argv)
}
else
{
fprintf(stderr, "hdfmt: %s is not a valid size\n", argv[1]);
fprintf(stderr, "hdfmt: %s is not a valid size\n", argv[2]);
status = 1;
}
}
Expand Down
157 changes: 157 additions & 0 deletions src/hdresize.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
#include <errno.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

static int parse_size(const char *size)
{
int value;
char *end;

value = strtol(size, &end, 10);
switch (*end) {
case 'k':
case 'K':
value *= 1024;
break;
case 'm':
case 'M':
value *= 1024 * 1024;
break;
case 'g':
case 'G':
value *= 1024 * 1024 * 1024;
break;
}
return value;
}

static inline uint32_t read24(const unsigned char *base)
{
return base[0] | (base[1] << 8) | (base[2] << 16);
}

static inline void write24(uint8_t *base, uint32_t value)
{
base[0] = value & 0xff;
base[1] = (value >> 8) & 0xff;
base[2] = (value >> 16) & 0xff;
}

static uint8_t checksum(uint8_t *base)
{
int i = 255, c = 0;
unsigned sum = 255;
while (--i >= 0) {
sum += base[i] + c;
c = 0;
if (sum >= 256) {
sum &= 0xff;
c = 1;
}
}
return sum;
}

int main(int argc, char **argv)
{
int status;

if (argc == 3) {
int size = parse_size(argv[2]);
if (size > 0) {
const char *fn = argv[1];
size_t len = strlen(fn) + 5;
char *dat_fn = alloca(len);
snprintf(dat_fn, len, "%s.dat", fn);
FILE *dat_fp = fopen(dat_fn, "rb+");
if (dat_fp) {
unsigned char fsmap[512];
if (fread(fsmap, sizeof fsmap, 1, dat_fp) == 1) {
if (fsmap[0x1FE] <= 3) {
status = 0;
char *dsc_fn = alloca(len);
snprintf(dsc_fn, len, "%s.dsc", fn);
FILE *dsc_fp = fopen(dsc_fn, "rb+");
if (dsc_fp) {
unsigned char geom[22];
if (fread(geom, sizeof geom, 1, dsc_fp) == 1) {
int new_sects = size / 256;
int old_sects = read24(fsmap + 0x0FC);
printf("hdresize: old sectors=%d, new_sects=%d\n", old_sects, new_sects);
if (new_sects > old_sects) {
write24(fsmap + 0x0FC, new_sects);
fsmap[0x0FF] = checksum(fsmap);
unsigned char *ptr = fsmap + 0x100;
write24(ptr, read24(ptr) + (new_sects - old_sects));
fsmap[0x1ff] = checksum(ptr);
int cyl = 1 + ((new_sects - 1) / (33 * 255));
geom[13] = cyl % 256;
geom[14] = cyl / 256;
geom[15] = 255;
if (fseek(dsc_fp, 0, SEEK_SET) == 0 && fwrite(geom, sizeof geom, 1, dsc_fp) == 1) {
if (fseek(dat_fp, 0, SEEK_SET) == 0 && fwrite(fsmap, sizeof fsmap, 1, dat_fp) == 1) {
status = 0;
printf("hdresize: %s grown\n", fn);
}
else
{
fprintf(stderr, "hdresize: unable to write fsmap to %s: %s\n", dat_fn, strerror(errno));
status = 8;
}
}
else {
fprintf(stderr, "hdresize: unable to write geometry to %s: %s\n", dsc_fn, strerror(errno));
status = 7;
}
}
else {
fputs("hdresize: shrinking not implemented\n", stderr);
status = 6;
}
}
else {
fprintf(stderr, "hdresize: unable to read geometry from %s: %s\n", dsc_fn, strerror(errno));
status = 5;
}
}
else {
fprintf(stderr, "hdresize: unable to open dsc file %s: %s\n", dsc_fn, strerror(errno));
status = 2;
}
}
else {
fprintf(stderr, "hdresize: %s has more than one free entry, compact before resizing\n", fn);
status = 4;
}
}
else {
fprintf(stderr, "hdresize: unable to read fsmap from %s: %s\n", dat_fn, strerror(errno));
status = 3;
}
fclose(dat_fp);
}
else {
fprintf(stderr, "hdresize: unable to open data file %s: %s\n", dat_fn, strerror(errno));
status = 2;
}
}
else {
fprintf(stderr, "hdresize: %s is not a valid size\n", argv[2]);
status = 1;
}
}
else {
fputs("usage: hdresize <dat-file> <size>\n", stderr);
status = 1;
}
return status;
}







5 changes: 4 additions & 1 deletion src/model.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,11 @@ static void tube_init(void)
FILE *romf;

if (curtube!=-1) {
if (!tubes[curtube].bootrom[0]) // no boot ROM needed
if (!tubes[curtube].bootrom[0]) { // no boot ROM needed
tubes[curtube].init(NULL);
tube_updatespeed();
tube_reset();
}
else {
if (!tube_dir)
tube_dir = al_create_path_for_directory("roms/tube");
Expand Down
21 changes: 16 additions & 5 deletions src/sdf-geo.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ struct sdf_geometry sdf_geo_tab[] =
{ "ADFS-S", SDF_SIDES_SINGLE, SDF_DENS_DOUBLE, 40, 16, 256, new_adfs },
{ "ADFS-M", SDF_SIDES_SINGLE, SDF_DENS_DOUBLE, 80, 16, 256, new_adfs },
{ "ADFS-L", SDF_SIDES_INTERLEAVED, SDF_DENS_DOUBLE, 80, 16, 256, new_adfs },
{ "ADFS-D", SDF_SIDES_SEQUENTIAL, SDF_DENS_DOUBLE, 80, 5, 1024, NULL },
{ "ADFS-D", SDF_SIDES_INTERLEAVED, SDF_DENS_DOUBLE, 80, 5, 1024, NULL },
{ "Acorn DFS", SDF_SIDES_SINGLE, SDF_DENS_SINGLE, 40, 10, 256, new_dfs_single },
{ "Acorn DFS", SDF_SIDES_INTERLEAVED, SDF_DENS_SINGLE, 40, 10, 256, new_dfs_interleaved },
{ "Acorn DFS", SDF_SIDES_SEQUENTIAL, SDF_DENS_SINGLE, 40, 10, 256, NULL },
Expand Down Expand Up @@ -286,6 +286,10 @@ static int32_t dfs_size(FILE *fp, long offset)
base += 8;
dirsize -= 8;
new_start = ((base[6] & 0x03) << 8) | base[7];
if (new_start == 0) {
log_debug("sdf: impossible start position");
return -1;
}
if (new_start > cur_start) {
log_debug("sdf: catalogue not sorted");
return -1;
Expand Down Expand Up @@ -326,10 +330,17 @@ static const struct sdf_geometry *find_geo_dfs(const char *fn, const char *ext,
}
track_bytes = geo->sectors_per_track * geo->sector_size;
side_bytes = track_bytes * geo->tracks;
if (fsize > side_bytes && dfs_size(fp, side_bytes) >= 3)
geo += 2; // sequential sided-version.
else if (!strcasecmp(ext, "dsd") || !strcasecmp(ext, "ddd"))
geo++; // interleaved side version.
if (fsize > track_bytes) {
if (dfs_size(fp, track_bytes) >= 3) {
geo++; // interleaved side version.
if (dfs_size(fp, side_bytes) >= 3 && strcasecmp(ext, "dsd") && strcasecmp(ext, "ddd"))
geo++; // sequential side version.
}
else if (dfs_size(fp, side_bytes) >= 3)
geo += 2; // sequential side version.
else if (!strcasecmp(ext, "dsd") || !strcasecmp(ext, "ddd"))
geo++; // interleaved side version.
}
return geo;
}
return NULL;
Expand Down
Loading

0 comments on commit 8f73f4c

Please sign in to comment.