Commit 7a6cd1c2 authored by Vladimir Serbinenko's avatar Vladimir Serbinenko
Browse files

Move disk init to platform-specific code

Disks are handled differently on retroarch rather than
standalone, so move code to standalone.c
parent cf666048
......@@ -13,3 +13,4 @@ extern unsigned io_sound_freq;
extern flag_t fake_tape, telegraph_enabled, fullscreen;
extern flag_t traceflag;
extern FILE * tracefile;
extern const char *floppyA, *floppyB, *floppyC, *floppyD;
......@@ -286,7 +286,6 @@ struct bk_state {
};
extern const char *printer_file;
extern const char *floppyA, *floppyB, *floppyC, *floppyD;
extern const char *rompath10, *rompath12, *rompath16;
extern const char *const bos11rom, *const diskrom, *const bos11extrom;
......@@ -502,7 +501,6 @@ typedef struct {
extern unsigned long pending_interrupts;
void disk_open(disk_t * pdt, const char * name);
void ev_register(unsigned priority, int (*handler)(d_word),
unsigned long delay, /* in clock ticks */
d_word info);
......@@ -570,4 +568,6 @@ static inline enum joystick_state JOYSTICK_BUTTON(int idx) {
return 1 << idx;
}
void platform_disk_init(disk_t *disks);
#endif
......@@ -13,83 +13,18 @@
#define O_BINARY 0
#endif
disk_t disks[4];
static disk_t disks[4];
static int selected = -1;
void do_disk_io(int drive, int blkno, int nwords, int ioaddr);
/* Pretty much had to rewrite it for portability rofl. - Gameblabla
* This does not seem to handle writes to the file.
* */
void disk_open(disk_t * pdt, const char * name)
{
FILE* fp;
int result;
/* First, we check if the file exists. */
fp = fopen(name, "rb");
if (!fp)
{
/* It doesn't so let's exit right away. */
perror(name);
return;
}
else
fclose(fp);
fp = fopen(name, "r+b");
if (!fp)
{
/* Open file as Read-only */
fp = fopen(name, "rb");
if (!fp)
{
perror(name);
return;
}
pdt->ro = 1;
}
/* Determine size of file*/
fseek(fp , 0 , SEEK_END );
pdt->length = ftell (fp);
fseek(fp , 0 , SEEK_SET );
if (pdt->length == -1) perror("seek");
if (pdt->length % SECSIZE)
{
fprintf(stderr, _("%s is not an integer number of blocks: %d bytes\n"), name, pdt->length);
fclose(fp);
return;
}
pdt->image = malloc(pdt->length);
if (pdt->image == NULL)
{
fprintf(stderr, _("Unable to malloc. Out of memory ?\n"));
fclose(fp);
perror(name);
}
result = fread (pdt->image, sizeof(unsigned char), pdt->length, fp);
if (fp) fclose(fp);
if (pdt->ro)
{
fprintf(stderr, _("%s will be read only\n"), name);
}
}
/* Are there any interrupts to open or close ? */
void disk_init() {
static char init_done = 0;
int i;
if (!init_done) {
disk_open(&disks[0], floppyA);
disk_open(&disks[1], floppyB);
disk_open(&disks[2], floppyC);
disk_open(&disks[3], floppyD);
platform_disk_init(disks);
init_done = 1;
}
for (i = 0; i < 4; i++) {
......
......@@ -57,11 +57,6 @@ const char *const bos11extrom = "B11M_EXT.ROM";
const char *const basic11arom = "BAS11M_0.ROM";
const char *const basic11brom = "BAS11M_1.ROM";
const char * floppyA = "A.img";
const char * floppyB = "B.img";
const char * floppyC = "C.img";
const char * floppyD = "D.img";
/*
* Command line flags and variables.
*/
......
......@@ -31,6 +31,11 @@
unsigned int refreshtime = 0;
static int hasgame = 0;
const char * floppyA = "A.img";
const char * floppyB = "B.img";
const char * floppyC = "C.img";
const char * floppyD = "D.img";
char init_path[BUFSIZ];
char game_path[512];
static const char *const focal10rom = "FOCAL10.ROM";
......@@ -517,3 +522,73 @@ char *monitor11help = _("BK0011M BOS commands:\n\n\
break;
}
}
/* Pretty much had to rewrite it for portability rofl. - Gameblabla
* This does not seem to handle writes to the file.
* */
static void disk_open(disk_t * pdt, const char * name)
{
FILE* fp;
int result;
/* First, we check if the file exists. */
fp = fopen(name, "rb");
if (!fp)
{
/* It doesn't so let's exit right away. */
perror(name);
return;
}
else
fclose(fp);
fp = fopen(name, "r+b");
if (!fp)
{
/* Open file as Read-only */
fp = fopen(name, "rb");
if (!fp)
{
perror(name);
return;
}
pdt->ro = 1;
}
/* Determine size of file*/
fseek(fp , 0 , SEEK_END );
pdt->length = ftell (fp);
fseek(fp , 0 , SEEK_SET );
if (pdt->length == -1) perror("seek");
if (pdt->length % 64)
{
fprintf(stderr, _("%s is not an integer number of blocks: %d bytes\n"), name, pdt->length);
fclose(fp);
return;
}
pdt->image = malloc(pdt->length);
if (pdt->image == NULL)
{
fprintf(stderr, _("Unable to malloc. Out of memory ?\n"));
fclose(fp);
perror(name);
}
result = fread (pdt->image, sizeof(unsigned char), pdt->length, fp);
if (fp) fclose(fp);
if (pdt->ro)
{
fprintf(stderr, _("%s will be read only\n"), name);
}
}
void platform_disk_init(disk_t *disks) {
disk_open(&disks[0], floppyA);
disk_open(&disks[1], floppyB);
disk_open(&disks[2], floppyC);
disk_open(&disks[3], floppyD);
}
......@@ -19,45 +19,16 @@ typedef enum {
typedef disk_t tdisk_t;
tdisk_t tdisks[4];
static tdisk_t tdisks[4];
static int selected = -1;
void tdisk_open(tdisk_t * pdt, char * name) {
int fd = open(name, O_RDWR);
if (fd == -1) {
pdt->ro = 1;
fd = open(name, O_RDONLY);
}
if (fd == -1) {
perror(name);
return;
}
pdt->length = lseek(fd, 0, SEEK_END);
if (pdt->length % SECSIZE) {
fprintf(stderr, _("%s is not an integer number of blocks\n"), name);
close(fd);
return;
}
pdt->image = mmap(0, pdt->length, PROT_READ | (pdt->ro ? 0 : PROT_WRITE), MAP_SHARED, fd, 0);
if (pdt->image == MAP_FAILED) {
pdt->image = 0;
perror(name);
}
if (pdt->ro) {
fprintf(stderr, _("%s will be read only\n"), name);
}
}
/* Are there any interrupts to open or close ? */
void tdisk_init() {
static char init_done = 0;
int i;
if (!init_done) {
disk_open(&tdisks[0], floppyA);
disk_open(&tdisks[1], floppyB);
disk_open(&tdisks[2], floppyC);
disk_open(&tdisks[3], floppyD);
platform_disk_init(tdisks);
init_done = 1;
}
for (i = 0; i < 4; i++) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment