Factor out common parts of system_dei/deo.

This commit is contained in:
Andrew Alderwick 2022-01-05 13:28:22 +00:00
parent c77799dac2
commit 646d79fff5
5 changed files with 45 additions and 33 deletions

View File

@ -14,6 +14,7 @@ then
echo "Formatting.."
clang-format -i src/uxn.h
clang-format -i src/uxn.c
clang-format -i src/devices/system.h
clang-format -i src/devices/system.c
clang-format -i src/devices/screen.h
clang-format -i src/devices/screen.c

View File

@ -1,4 +1,5 @@
#include "../uxn.h"
#include "system.h"
#include <stdio.h>
@ -27,3 +28,25 @@ uxn_halt(Uxn *u, Uint8 error, Uint16 addr)
fprintf(stderr, "Halted: %s#%04x, at 0x%04x\n", errors[error], u->ram[addr], addr);
return 0;
}
/* IO */
Uint8
system_dei(Device *d, Uint8 port)
{
switch(port) {
case 0x2: return d->u->wst.ptr;
case 0x3: return d->u->rst.ptr;
default: return d->dat[port];
}
}
void
system_deo(Device *d, Uint8 port)
{
switch(port) {
case 0x2: d->u->wst.ptr = d->dat[port]; break;
case 0x3: d->u->rst.ptr = d->dat[port]; break;
default: system_deo_special(d, port);
}
}

14
src/devices/system.h Normal file
View File

@ -0,0 +1,14 @@
/*
Copyright (c) 2022 Devine Lu Linvega, Andrew Alderwick
Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE.
*/
Uint8 system_dei(Device *d, Uint8 port);
void system_deo(Device *d, Uint8 port);
void system_deo_special(Device *d, Uint8 port);

View File

@ -3,6 +3,7 @@
#include <unistd.h>
#include <time.h>
#include "uxn.h"
#include "devices/system.h"
#include "devices/file.h"
/*
@ -45,26 +46,12 @@ inspect(Stack *s, char *name)
#pragma mark - Devices
static Uint8
system_dei(Device *d, Uint8 port)
void
system_deo_special(Device *d, Uint8 port)
{
switch(port) {
case 0x2: return d->u->wst.ptr;
case 0x3: return d->u->rst.ptr;
default: return d->dat[port];
}
}
static void
system_deo(Device *d, Uint8 port)
{
switch(port) {
case 0x2: d->u->wst.ptr = d->dat[port]; break;
case 0x3: d->u->rst.ptr = d->dat[port]; break;
case 0xe:
if(port == 0xe) {
inspect(&d->u->wst, "Working-stack");
inspect(&d->u->rst, "Return-stack");
break;
}
}

View File

@ -8,6 +8,7 @@
#pragma GCC diagnostic ignored "-Wpedantic"
#pragma clang diagnostic ignored "-Wtypedef-redefinition"
#include <SDL.h>
#include "devices/system.h"
#include "devices/screen.h"
#include "devices/audio.h"
#include "devices/file.h"
@ -169,23 +170,9 @@ init(void)
#pragma mark - Devices
static Uint8
system_dei(Device *d, Uint8 port)
void
system_deo_special(Device *d, Uint8 port)
{
switch(port) {
case 0x2: return d->u->wst.ptr;
case 0x3: return d->u->rst.ptr;
default: return d->dat[port];
}
}
static void
system_deo(Device *d, Uint8 port)
{
switch(port) {
case 0x2: d->u->wst.ptr = d->dat[port]; break;
case 0x3: d->u->rst.ptr = d->dat[port]; break;
}
if(port > 0x7 && port < 0xe)
screen_palette(&uxn_screen, &d->dat[0x8]);
}