From f70f21789b45611f79fd689a012c6115d7d36db1 Mon Sep 17 00:00:00 2001 From: Peter Evans Date: Sun, 31 Dec 2017 15:50:59 -0600 Subject: [PATCH] Add flash memory, disassemble options --- include/mos6502.h | 1 + include/option.h | 7 +++++++ src/apple2.c | 13 +++++++++++++ src/mos6502.c | 6 ++++++ src/option.c | 22 ++++++++++++++++++++++ 5 files changed, 49 insertions(+) diff --git a/include/mos6502.h b/include/mos6502.h index 4289a79..701ce1e 100644 --- a/include/mos6502.h +++ b/include/mos6502.h @@ -122,6 +122,7 @@ extern vm_16bit mos6502_pop_stack(mos6502 *); extern vm_8bit mos6502_next_byte(mos6502 *); extern vm_8bit mos6502_read_byte(mos6502 *); extern void mos6502_execute(mos6502 *, vm_8bit); +extern void mos6502_flash_memory(mos6502 *, vm_segment *); extern void mos6502_free(mos6502 *); extern void mos6502_modify_status(mos6502 *, vm_8bit, vm_8bit); extern void mos6502_push_stack(mos6502 *, vm_16bit); diff --git a/include/option.h b/include/option.h index bf315e3..3787d53 100644 --- a/include/option.h +++ b/include/option.h @@ -1,13 +1,20 @@ #ifndef _OPTIONS_H_ #define _OPTIONS_H_ +#include #include +enum option_flags { + OPTION_FLASH = 1, + OPTION_DISASSEMBLE = 2, +}; + /* * These are the most possible number of disk inputs we can accept */ #define OPTION_MAX_DISKS 2 +extern bool option_flag(int); extern FILE *option_get_input(int); extern const char *option_get_error(); extern int option_get_height(); diff --git a/src/apple2.c b/src/apple2.c index 1b6efa9..3ec7b80 100644 --- a/src/apple2.c +++ b/src/apple2.c @@ -7,6 +7,7 @@ #include "apple2.h" #include "apple2.draw.h" +#include "mos6502.dis.h" #include "option.h" #include "vm_segment.h" @@ -121,6 +122,14 @@ apple2_boot(apple2 *mach) } } + if (option_flag(OPTION_FLASH)) { + mos6502_flash_memory(mach->cpu, mach->drive1->data); + } + + if (option_flag(OPTION_DISASSEMBLE)) { + mos6502_dis_scan(mach->cpu, stdout, 0, mach->cpu->memory->size); + } + return OK; } @@ -195,6 +204,10 @@ apple2_release_key(apple2 *mach) void apple2_run_loop(apple2 *mach) { + if (option_flag(OPTION_DISASSEMBLE)) { + return; + } + while (vm_screen_active(mach->screen)) { vm_screen_refresh(mach->screen); } diff --git a/src/mos6502.c b/src/mos6502.c index 3d286d4..13c3a31 100644 --- a/src/mos6502.c +++ b/src/mos6502.c @@ -423,3 +423,9 @@ mos6502_would_jump(int inst_code) inst_code == JMP || inst_code == JSR; } + +void +mos6502_flash_memory(mos6502 *cpu, vm_segment *segment) +{ + vm_segment_copy(cpu->memory, segment, 0, 0, cpu->memory->size - 1); +} diff --git a/src/option.c b/src/option.c index fd1561b..41d11e7 100644 --- a/src/option.c +++ b/src/option.c @@ -41,6 +41,8 @@ static char error_buffer[ERRBUF_SIZE] = ""; static int width = 700; static int height = 480; +static int flags = 0; + /* * These are all of the options we allow in our long-form options. It's * a bit faster to identify them by integer symbols than to do string @@ -51,14 +53,18 @@ enum options { DISK2, HELP, SIZE, + FLASH, + DISASSEMBLE, }; /* * Here are the options we support for program execution. */ static struct option long_options[] = { + { "disassemble", 0, NULL, DISASSEMBLE }, { "disk1", 1, NULL, DISK1 }, { "disk2", 1, NULL, DISK2 }, + { "flash", 0, NULL, FLASH }, { "help", 0, NULL, HELP }, { "size", 1, NULL, SIZE }, }; @@ -111,6 +117,10 @@ option_parse(int argc, char **argv) opt = getopt_long_only(argc, argv, "", long_options, &index); switch (opt) { + case DISASSEMBLE: + flags |= OPTION_DISASSEMBLE; + break; + case DISK1: input_source = 1; break; @@ -119,6 +129,10 @@ option_parse(int argc, char **argv) input_source = 2; break; + case FLASH: + flags |= OPTION_FLASH; + break; + case HELP: option_print_help(); @@ -216,8 +230,10 @@ option_print_help() fprintf(stderr, "Usage: erc [options...]\n"); fprintf(stderr, "Options:\n"); fprintf(stderr, "\ + --disassemble Print assembly notation from CPU memory\n\ --disk1=FILE Load FILE into disk drive 1\n\ --disk2=FILE Load FILE into disk drive 2\n\ + --flash Flash CPU memory with contents of drive 1\n\ --help Print this help message\n\ --size=WIDTHxHEIGHT Use WIDTH and HEIGHT for window size\n\ (only 700x480 and 875x600 are supported)\n"); @@ -263,3 +279,9 @@ option_get_height() { return height; } + +bool +option_flag(int flag) +{ + return flags & flag; +}