1
0
mirror of https://github.com/pevans/erc-c.git synced 2024-11-01 04:04:28 +00:00

Add boot function; modify main to use apple2 boot

This commit is contained in:
Peter Evans 2017-12-15 22:22:40 -06:00
parent 3f3210205f
commit 294fab76aa
4 changed files with 72 additions and 1 deletions

View File

@ -2,6 +2,7 @@
#define _APPLE2_H_ #define _APPLE2_H_
#include "mos6502.h" #include "mos6502.h"
#include "apple2.dd.h"
typedef struct { typedef struct {
/* /*
@ -15,6 +16,12 @@ typedef struct {
* delete function to do that. * delete function to do that.
*/ */
vm_segment *memory; vm_segment *memory;
/*
* Our two disk drives.
*/
apple2dd *drive1;
apple2dd *drive2;
} apple2; } apple2;
extern apple2 *apple2_create(); extern apple2 *apple2_create();
@ -22,5 +29,6 @@ extern void apple2_free(apple2 *);
extern void apple2_press_key(apple2 *, vm_8bit); extern void apple2_press_key(apple2 *, vm_8bit);
extern void apple2_clear_strobe(apple2 *); extern void apple2_clear_strobe(apple2 *);
extern void apple2_release_key(apple2 *); extern void apple2_release_key(apple2 *);
extern int apple2_boot(apple2 *);
#endif #endif

View File

@ -6,6 +6,7 @@
*/ */
#include "apple2.h" #include "apple2.h"
#include "option.h"
#include "vm_segment.h" #include "vm_segment.h"
/* /*
@ -35,7 +36,10 @@ apple2_create()
mach->cpu = mos6502_create(); mach->cpu = mos6502_create();
mach->memory = mach->cpu->memory; mach->memory = mach->cpu->memory;
mach->drive1 = apple2dd_create();
mach->drive2 = apple2dd_create();
return mach; return mach;
} }
@ -96,3 +100,31 @@ apple2_release_key(apple2 *mach)
{ {
vm_segment_set(mach->memory, ANY_KEY_DOWN, 0); 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;
}

View File

@ -11,6 +11,7 @@
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include "apple2.h"
#include "log.h" #include "log.h"
#include "option.h" #include "option.h"
@ -69,6 +70,9 @@ finish()
int int
main(int argc, char **argv) main(int argc, char **argv)
{ {
apple2 *mach;
int err;
init(argc, argv); init(argc, argv);
// When we exit, we want to wrap up a few loose ends. This syscall // 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. // successfully or if we run `exit()` from elsewhere in the program.
atexit(finish); 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 // ha ha ha ha #nervous #laughter
printf("Hello, world\n"); printf("Hello, world\n");
} }

View File

@ -1,6 +1,7 @@
#include <criterion/criterion.h> #include <criterion/criterion.h>
#include "apple2.h" #include "apple2.h"
#include "option.h"
static apple2 *mach; static apple2 *mach;
@ -22,6 +23,9 @@ Test(apple2, create)
{ {
cr_assert_neq(mach, NULL); cr_assert_neq(mach, NULL);
cr_assert_neq(mach->cpu, NULL); cr_assert_neq(mach->cpu, NULL);
cr_assert_neq(mach->drive1, NULL);
cr_assert_neq(mach->drive2, NULL);
} }
Test(apple2, press_key) Test(apple2, press_key)
@ -46,3 +50,18 @@ Test(apple2, release_key)
apple2_release_key(mach); apple2_release_key(mach);
cr_assert_eq(vm_segment_get(mach->memory, 0xC010), 0); 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);
}