mirror of
https://github.com/pevans/erc-c.git
synced 2025-08-15 18:27:37 +00:00
Move screen run logic into apple run_loop and create
This commit is contained in:
@@ -1,8 +1,9 @@
|
|||||||
#ifndef _APPLE2_H_
|
#ifndef _APPLE2_H_
|
||||||
#define _APPLE2_H_
|
#define _APPLE2_H_
|
||||||
|
|
||||||
#include "mos6502.h"
|
|
||||||
#include "apple2.dd.h"
|
#include "apple2.dd.h"
|
||||||
|
#include "mos6502.h"
|
||||||
|
#include "vm_screen.h"
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
/*
|
/*
|
||||||
@@ -17,6 +18,11 @@ typedef struct {
|
|||||||
*/
|
*/
|
||||||
vm_segment *memory;
|
vm_segment *memory;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The screen wherein we shall render all of our graphics.
|
||||||
|
*/
|
||||||
|
vm_screen *screen;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Our two disk drives.
|
* Our two disk drives.
|
||||||
*/
|
*/
|
||||||
@@ -24,11 +30,12 @@ typedef struct {
|
|||||||
apple2dd *drive2;
|
apple2dd *drive2;
|
||||||
} apple2;
|
} apple2;
|
||||||
|
|
||||||
extern apple2 *apple2_create();
|
extern apple2 *apple2_create(int, int);
|
||||||
extern void apple2_free(apple2 *);
|
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 *);
|
extern int apple2_boot(apple2 *);
|
||||||
|
extern void apple2_run_loop(apple2 *);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
30
src/apple2.c
30
src/apple2.c
@@ -25,9 +25,10 @@
|
|||||||
* Create the basic apple2 structure.
|
* Create the basic apple2 structure.
|
||||||
*/
|
*/
|
||||||
apple2 *
|
apple2 *
|
||||||
apple2_create()
|
apple2_create(int width, int height)
|
||||||
{
|
{
|
||||||
apple2 *mach;
|
apple2 *mach;
|
||||||
|
int err;
|
||||||
|
|
||||||
mach = malloc(sizeof(apple2));
|
mach = malloc(sizeof(apple2));
|
||||||
if (mach == NULL) {
|
if (mach == NULL) {
|
||||||
@@ -37,12 +38,39 @@ apple2_create()
|
|||||||
mach->cpu = mos6502_create();
|
mach->cpu = mos6502_create();
|
||||||
mach->memory = mach->cpu->memory;
|
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->drive1 = apple2dd_create();
|
||||||
mach->drive2 = 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;
|
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.
|
* 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.
|
// successfully or if we run `exit()` from elsewhere in the program.
|
||||||
atexit(finish);
|
atexit(finish);
|
||||||
|
|
||||||
mach = apple2_create();
|
// Let's build the basic machine, using the width and height
|
||||||
err = apple2_boot(mach);
|
// 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) {
|
if (err != OK) {
|
||||||
fprintf(stderr, "Bootup failed!\n");
|
fprintf(stderr, "Bootup failed!\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
screen = vm_screen_create();
|
// This will run for as long as we want to hang out in the emulated
|
||||||
if (screen == NULL) {
|
// machine.
|
||||||
fprintf(stderr, "Screen creation failed!\n");
|
apple2_run_loop(mach);
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
err = vm_screen_add_window(screen,
|
// We're all done, so let's tear everything down.
|
||||||
option_get_width(),
|
apple2_free(mach);
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ha ha ha ha #nervous #laughter
|
// ha ha ha ha #nervous #laughter
|
||||||
printf("Hello, world\n");
|
printf("Hello, world\n");
|
||||||
|
Reference in New Issue
Block a user