mirror of
https://github.com/pevans/erc-c.git
synced 2024-10-14 09:23:54 +00:00
Move screen run logic into apple run_loop and create
This commit is contained in:
parent
8c23f3fa7e
commit
f55b608bee
@ -1,8 +1,9 @@
|
||||
#ifndef _APPLE2_H_
|
||||
#define _APPLE2_H_
|
||||
|
||||
#include "mos6502.h"
|
||||
#include "apple2.dd.h"
|
||||
#include "mos6502.h"
|
||||
#include "vm_screen.h"
|
||||
|
||||
typedef struct {
|
||||
/*
|
||||
@ -17,6 +18,11 @@ typedef struct {
|
||||
*/
|
||||
vm_segment *memory;
|
||||
|
||||
/*
|
||||
* The screen wherein we shall render all of our graphics.
|
||||
*/
|
||||
vm_screen *screen;
|
||||
|
||||
/*
|
||||
* Our two disk drives.
|
||||
*/
|
||||
@ -24,11 +30,12 @@ typedef struct {
|
||||
apple2dd *drive2;
|
||||
} apple2;
|
||||
|
||||
extern apple2 *apple2_create();
|
||||
extern apple2 *apple2_create(int, int);
|
||||
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 *);
|
||||
extern void apple2_run_loop(apple2 *);
|
||||
|
||||
#endif
|
||||
|
30
src/apple2.c
30
src/apple2.c
@ -25,9 +25,10 @@
|
||||
* Create the basic apple2 structure.
|
||||
*/
|
||||
apple2 *
|
||||
apple2_create()
|
||||
apple2_create(int width, int height)
|
||||
{
|
||||
apple2 *mach;
|
||||
int err;
|
||||
|
||||
mach = malloc(sizeof(apple2));
|
||||
if (mach == NULL) {
|
||||
@ -37,12 +38,39 @@ apple2_create()
|
||||
mach->cpu = mos6502_create();
|
||||
mach->memory = mach->cpu->memory;
|
||||
|
||||
// Our two drives -- we create both of them, even if we intend to
|
||||
// use only one.
|
||||
mach->drive1 = apple2dd_create();
|
||||
mach->drive2 = apple2dd_create();
|
||||
|
||||
// Let's build our screen abstraction!
|
||||
mach->screen = vm_screen_create();
|
||||
if (mach->screen == NULL) {
|
||||
log_critical("Screen creation failed!\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// We still need to add a window, since we want to render some
|
||||
// graphics.
|
||||
err = vm_screen_add_window(mach->screen, width, height);
|
||||
if (err != OK) {
|
||||
log_critical("Window creation failed!\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return mach;
|
||||
}
|
||||
|
||||
void
|
||||
apple2_run_loop(apple2 *mach)
|
||||
{
|
||||
while (vm_screen_active(mach->screen)) {
|
||||
vm_screen_set_color(mach->screen, 255, 0, 0, 255);
|
||||
vm_screen_draw_rect(mach->screen, 50, 50, 20, 20);
|
||||
vm_screen_refresh(mach->screen);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Free the memory reserved for an apple2 struct.
|
||||
*/
|
||||
|
31
src/main.c
31
src/main.c
@ -89,33 +89,24 @@ 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);
|
||||
// Let's build the basic machine, using the width and height
|
||||
// indicated by the user.
|
||||
mach = apple2_create(option_get_width(),
|
||||
option_get_height());
|
||||
|
||||
// Ok, it's time to boot this up!
|
||||
err = apple2_boot(mach);
|
||||
if (err != OK) {
|
||||
fprintf(stderr, "Bootup failed!\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
screen = vm_screen_create();
|
||||
if (screen == NULL) {
|
||||
fprintf(stderr, "Screen creation failed!\n");
|
||||
exit(1);
|
||||
}
|
||||
// This will run for as long as we want to hang out in the emulated
|
||||
// machine.
|
||||
apple2_run_loop(mach);
|
||||
|
||||
err = vm_screen_add_window(screen,
|
||||
option_get_width(),
|
||||
option_get_height());
|
||||
if (err != OK) {
|
||||
fprintf(stderr, "Window creation failed!\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
while (vm_screen_active(screen)) {
|
||||
vm_screen_set_color(screen, 255, 0, 0, 255);
|
||||
vm_screen_draw_rect(screen, 50, 50, 20, 20);
|
||||
vm_screen_refresh(screen);
|
||||
}
|
||||
// We're all done, so let's tear everything down.
|
||||
apple2_free(mach);
|
||||
|
||||
// ha ha ha ha #nervous #laughter
|
||||
printf("Hello, world\n");
|
||||
|
Loading…
Reference in New Issue
Block a user