Use switch for console_deo

This commit is contained in:
Devine Lu Linvega 2023-03-01 12:04:05 -08:00
parent ea0d81a9b1
commit 8c4b1b0592
2 changed files with 19 additions and 15 deletions

View File

@ -17,8 +17,6 @@ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE.
*/
#define SUPPORT 0x1c03 /* devices mask */
static int
emu_error(char *msg, const char *err)
{
@ -37,11 +35,15 @@ console_input(Uxn *u, char c)
static void
console_deo(Uint8 *d, Uint8 port)
{
FILE *fd = port == 0x8 ? stdout : port == 0x9 ? stderr
: 0;
if(fd) {
fputc(d[port], fd);
fflush(fd);
switch(port) {
case 0x8:
fputc(d[port], stdout);
fflush(stdout);
return;
case 0x9:
fputc(d[port], stderr);
fflush(stderr);
return;
}
}
@ -61,7 +63,6 @@ static void
emu_deo(Uxn *u, Uint8 addr, Uint8 v)
{
Uint8 p = addr & 0x0f, d = addr & 0xf0;
Uint16 mask = 0x1 << (d >> 4);
u->dev[addr] = v;
switch(d) {
case 0x00: system_deo(u, &u->dev[d], p); break;
@ -69,8 +70,6 @@ emu_deo(Uxn *u, Uint8 addr, Uint8 v)
case 0xa0: file_deo(0, u->ram, &u->dev[d], p); break;
case 0xb0: file_deo(1, u->ram, &u->dev[d], p); break;
}
if(p == 0x01 && !(SUPPORT & mask))
fprintf(stderr, "Warning: Incompatible emulation, device: %02x.\n", d);
}
int

View File

@ -70,14 +70,19 @@ console_input(Uxn *u, char c)
return uxn_eval(u, PEEK16(d));
}
static void
console_deo(Uint8 *d, Uint8 port)
{
FILE *fd = port == 0x8 ? stdout : port == 0x9 ? stderr
: 0;
if(fd) {
fputc(d[port], fd);
fflush(fd);
switch(port) {
case 0x8:
fputc(d[port], stdout);
fflush(stdout);
return;
case 0x9:
fputc(d[port], stderr);
fflush(stderr);
return;
}
}