Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions disk.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,17 @@ int disk_read_block(xsm_word *page, int block_num)
}

/* Deallocate the disk */
int disk_close()
int disk_close(const char *filename)
{
int result;

/* Clean the disk */
fclose(_file);

/* Commit changes to disk */
_file = fopen(XSM_DEFAULT_DISK, "w");
_file = fopen(filename, "w");
result = fwrite(_disk_mem_copy, 1, _mem_size, _file);
fclose(_file);

return result;
}
}
4 changes: 2 additions & 2 deletions disk.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ int disk_init(const char *filename);
int disk_write_page(xsm_word *page, int block_num);
xsm_word *disk_get_block(int block);
int disk_read_block(xsm_word *page, int block_num);
int disk_close();
int disk_close(const char *filename);

#endif
#endif
24 changes: 21 additions & 3 deletions simulator.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ static const int XSM_CONSOLE_DURATION = XSM_SIMULATOR_DEFCONSOLE;
int simulator_run()
{
// Ready
disk_init(XSM_DEFAULT_DISK);
disk_init(_options_disk_file);

// Set
if (!machine_init(&_options))
Expand All @@ -31,7 +31,7 @@ int simulator_run()

// Finish
machine_destroy();
disk_close();
disk_close(_options_disk_file);
return XSM_SUCCESS;
}

Expand All @@ -46,6 +46,7 @@ int simulator_parse_args(int argc, char **argv)
_options.timer = XSM_TIMER_DURATION;
_options.console = XSM_CONSOLE_DURATION;
_options.disk = XSM_DISK_DURATION;
_options_disk_file = XSM_DEFAULT_DISK;

while (argc > 0)
{
Expand Down Expand Up @@ -106,6 +107,23 @@ int simulator_parse_args(int argc, char **argv)
argv++;
argc--;
}
else if (!strcmp(*argv, "--disk-file"))
{
argv++;
argc--;

FILE* f = fopen(*argv, "r");
if (f == NULL)
{
printf("Specified disk file can not be opened\n");
exit(0);
}
fclose(f);
_options_disk_file = *argv;

argv++;
argc--;
}
else
{
// Unrecognised option.
Expand All @@ -114,4 +132,4 @@ int simulator_parse_args(int argc, char **argv)
}

return XSM_SUCCESS;
}
}
3 changes: 2 additions & 1 deletion simulator.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
#define EXIT_FAILURE 1

static xsm_options _options;
static const char* _options_disk_file;

int simulator_run();
int simulator_parse_args(int argc, char **argv);

#endif
#endif