diff --git a/include/apple2.h b/include/apple2.h index b2f2c86..aad4b96 100644 --- a/include/apple2.h +++ b/include/apple2.h @@ -2,6 +2,7 @@ #define _APPLE2_H_ #include "mos6502.h" +#include "apple2.dd.h" typedef struct { /* @@ -15,6 +16,12 @@ typedef struct { * delete function to do that. */ vm_segment *memory; + + /* + * Our two disk drives. + */ + apple2dd *drive1; + apple2dd *drive2; } apple2; extern apple2 *apple2_create(); @@ -22,5 +29,6 @@ extern void apple2_free(apple2 *); extern void apple2_press_key(apple2 *, vm_8bit); extern void apple2_clear_strobe(apple2 *); extern void apple2_release_key(apple2 *); +extern int apple2_boot(apple2 *); #endif diff --git a/src/apple2.c b/src/apple2.c index ae05470..a6473ad 100644 --- a/src/apple2.c +++ b/src/apple2.c @@ -6,6 +6,7 @@ */ #include "apple2.h" +#include "option.h" #include "vm_segment.h" /* @@ -35,7 +36,10 @@ apple2_create() mach->cpu = mos6502_create(); mach->memory = mach->cpu->memory; - + + mach->drive1 = apple2dd_create(); + mach->drive2 = apple2dd_create(); + return mach; } @@ -96,3 +100,31 @@ apple2_release_key(apple2 *mach) { vm_segment_set(mach->memory, ANY_KEY_DOWN, 0); } + +int +apple2_boot(apple2 *mach) +{ + FILE *stream; + int err; + + // Do we have any disks? + stream = option_get_input(1); + if (stream) { + err = apple2dd_insert(mach->drive1, stream); + if (err != OK) { + log_critical("Unable to insert disk1 into drive"); + return err; + } + } + + stream = option_get_input(2); + if (stream) { + err = apple2dd_insert(mach->drive2, stream); + if (err != OK) { + log_critical("Unable to insert disk2 into drive"); + return err; + } + } + + return OK; +} diff --git a/src/main.c b/src/main.c index 1db2f03..eea527f 100644 --- a/src/main.c +++ b/src/main.c @@ -11,6 +11,7 @@ #include #include +#include "apple2.h" #include "log.h" #include "option.h" @@ -69,6 +70,9 @@ finish() int main(int argc, char **argv) { + apple2 *mach; + int err; + init(argc, argv); // When we exit, we want to wrap up a few loose ends. This syscall @@ -76,6 +80,14 @@ main(int argc, char **argv) // successfully or if we run `exit()` from elsewhere in the program. atexit(finish); + mach = apple2_create(); + err = apple2_boot(mach); + + if (err != OK) { + fprintf(stderr, "Bootup failed!\n"); + exit(1); + } + // ha ha ha ha #nervous #laughter printf("Hello, world\n"); } diff --git a/tests/apple2.c b/tests/apple2.c index 1257c98..083aa59 100644 --- a/tests/apple2.c +++ b/tests/apple2.c @@ -1,6 +1,7 @@ #include #include "apple2.h" +#include "option.h" static apple2 *mach; @@ -22,6 +23,9 @@ Test(apple2, create) { cr_assert_neq(mach, NULL); cr_assert_neq(mach->cpu, NULL); + + cr_assert_neq(mach->drive1, NULL); + cr_assert_neq(mach->drive2, NULL); } Test(apple2, press_key) @@ -46,3 +50,18 @@ Test(apple2, release_key) apple2_release_key(mach); cr_assert_eq(vm_segment_get(mach->memory, 0xC010), 0); } + +Test(apple2, boot) +{ + // A boot without any disks is technically ok... in full emulation, + // you'd just see a screen that prints out something like "Apple + // ][e" at the bottom. + cr_assert_eq(apple2_boot(mach), OK); + + // And, as you may guess, it's ok to reboot the machine. + option_read_file(1, "../data/zero.img"); + cr_assert_eq(apple2_boot(mach), OK); + + option_read_file(2, "../data/bad.img"); + cr_assert_neq(apple2_boot(mach), OK); +}