Browse Source

Removed bios core

main
Devine Lu Linvega 1 year ago
parent
commit
b324bac097
  1. 2
      src/devices/audio.c
  2. 11
      src/devices/console.c
  3. 6
      src/devices/console.h
  4. 6
      src/devices/controller.c
  5. 8
      src/devices/mouse.c
  6. 2401
      src/devices/system.c
  7. 7
      src/devices/system.h
  8. 42
      src/uxn.c
  9. 10
      src/uxn.h
  10. 25
      src/uxncli.c
  11. 27
      src/uxnemu.c

2
src/devices/audio.c

@ -250,7 +250,7 @@ audio_handler(void *ctx, Uint8 *out_stream, int len)
Uxn *u = (Uxn *)ctx;
Uint8 *addr = &u->dev[device];
if(channel[n].duration <= 0 && PEEK2(addr)) {
uxn_eval(&uxn, PEEK2(addr));
uxn_eval(PEEK2(addr));
}
channel[n].duration -= SOUND_TIMER;
int x = 0;

11
src/devices/console.c

@ -16,11 +16,12 @@ WITH REGARD TO THIS SOFTWARE.
*/
int
console_input(Uint8 c, int type)
console_input(int c, int type)
{
uxn.dev[0x12] = c;
uxn.dev[0x17] = type;
return uxn_eval(&uxn, PEEK2(&uxn.dev[0x10]));
if(c == EOF) c = 0, type = 4;
uxn.dev[0x12] = c, uxn.dev[0x17] = type;
uxn_eval(uxn.dev[0x10] << 8 | uxn.dev[0x11]);
return type != 4;
}
void
@ -34,7 +35,7 @@ console_listen(int i, int argc, char **argv)
}
void
console_deo(Uxn *u, Uint8 addr)
console_deo(Uint8 addr)
{
FILE *fd;
switch(addr) {

6
src/devices/console.h

@ -14,7 +14,7 @@ WITH REGARD TO THIS SOFTWARE.
#define CONSOLE_EOA 0x3
#define CONSOLE_END 0x4
int console_input(Uint8 c, int type);
int console_input(int c, int type);
void console_listen(int i, int argc, char **argv);
Uint8 console_dei(Uxn *u, Uint8 addr);
void console_deo(Uxn *u, Uint8 addr);
Uint8 console_dei(Uint8 addr);
void console_deo(Uint8 addr);

6
src/devices/controller.c

@ -17,7 +17,7 @@ controller_down(Uint8 mask)
{
if(mask) {
uxn.dev[0x82] |= mask;
uxn_eval(&uxn, PEEK2(&uxn.dev[0x80]));
uxn_eval(PEEK2(&uxn.dev[0x80]));
}
}
@ -26,7 +26,7 @@ controller_up(Uint8 mask)
{
if(mask) {
uxn.dev[0x82] &= (~mask);
uxn_eval(&uxn, PEEK2(&uxn.dev[0x80]));
uxn_eval(PEEK2(&uxn.dev[0x80]));
}
}
@ -35,7 +35,7 @@ controller_key(Uint8 key)
{
if(key) {
uxn.dev[0x83] = key;
uxn_eval(&uxn, PEEK2(&uxn.dev[0x80]));
uxn_eval(PEEK2(&uxn.dev[0x80]));
uxn.dev[0x83] = 0;
}
}

8
src/devices/mouse.c

@ -16,14 +16,14 @@ void
mouse_down(Uint8 mask)
{
uxn.dev[0x96] |= mask;
uxn_eval(&uxn, PEEK2(&uxn.dev[0x90]));
uxn_eval(PEEK2(&uxn.dev[0x90]));
}
void
mouse_up(Uint8 mask)
{
uxn.dev[0x96] &= (~mask);
uxn_eval(&uxn, PEEK2(&uxn.dev[0x90]));
uxn_eval(PEEK2(&uxn.dev[0x90]));
}
void
@ -31,7 +31,7 @@ mouse_pos(Uint16 x, Uint16 y)
{
uxn.dev[0x92] = x >> 8, uxn.dev[0x93] = x;
uxn.dev[0x94] = y >> 8, uxn.dev[0x95] = y;
uxn_eval(&uxn, PEEK2(&uxn.dev[0x90]));
uxn_eval(PEEK2(&uxn.dev[0x90]));
}
void
@ -39,7 +39,7 @@ mouse_scroll(Uint16 x, Uint16 y)
{
uxn.dev[0x9a] = x >> 8, uxn.dev[0x9b] = x;
uxn.dev[0x9c] = -y >> 8, uxn.dev[0x9d] = -y;
uxn_eval(&uxn, PEEK2(&uxn.dev[0x90]));
uxn_eval(PEEK2(&uxn.dev[0x90]));
uxn.dev[0x9a] = 0, uxn.dev[0x9b] = 0;
uxn.dev[0x9c] = 0, uxn.dev[0x9d] = 0;
}

2401
src/devices/system.c

File diff suppressed because it is too large Load Diff

7
src/devices/system.h

@ -13,10 +13,9 @@ WITH REGARD TO THIS SOFTWARE.
void system_reboot(int soft);
void system_inspect(void);
void system_image(void);
int system_error(char *msg, const char *err);
int system_boot(Uint8 *ram, char *rom);
Uint8 system_dei(Uxn *u, Uint8 addr);
void system_deo(Uxn *u, Uint8 addr);
extern Uxn bios;
Uint8 system_dei(Uint8 addr);
void system_deo(Uint8 addr);

42
src/uxn.c

@ -16,20 +16,20 @@ WITH REGARD TO THIS SOFTWARE.
case 0x20|opc: {const int _2=1,_r=0;init body;} break;\
case 0x40|opc: {const int _2=0,_r=1;init body;} break;\
case 0x60|opc: {const int _2=1,_r=1;init body;} break;\
case 0x80|opc: {const int _2=0,_r=0,k=u->wst.ptr;init u->wst.ptr=k;body;} break;\
case 0xa0|opc: {const int _2=1,_r=0,k=u->wst.ptr;init u->wst.ptr=k;body;} break;\
case 0xc0|opc: {const int _2=0,_r=1,k=u->rst.ptr;init u->rst.ptr=k;body;} break;\
case 0xe0|opc: {const int _2=1,_r=1,k=u->rst.ptr;init u->rst.ptr=k;body;} break;\
case 0x80|opc: {const int _2=0,_r=0,k=uxn.wst.ptr;init uxn.wst.ptr=k;body;} break;\
case 0xa0|opc: {const int _2=1,_r=0,k=uxn.wst.ptr;init uxn.wst.ptr=k;body;} break;\
case 0xc0|opc: {const int _2=0,_r=1,k=uxn.rst.ptr;init uxn.rst.ptr=k;body;} break;\
case 0xe0|opc: {const int _2=1,_r=1,k=uxn.rst.ptr;init uxn.rst.ptr=k;body;} break;\
}
/* Microcode */
#define JMI a = u->ram[pc] << 8 | u->ram[pc + 1], pc += a + 2;
#define REM if(_r) u->rst.ptr -= 1 + _2; else u->wst.ptr -= 1 + _2;
#define INC(s) u->s.dat[u->s.ptr++]
#define DEC(s) u->s.dat[--u->s.ptr]
#define JMP(i) pc = _2 ? i : pc + (Sint8)i;
#define PO1(o) o = _r ? DEC(rst) : DEC(wst);
#define JMI a = uxn.ram[pc] << 8 | uxn.ram[pc + 1], pc += a + 2;
#define REM if(_r) uxn.rst.ptr -= 1 + _2; else uxn.wst.ptr -= 1 + _2;
#define INC(s) uxn.s.dat[uxn.s.ptr++]
#define DEC(s) uxn.s.dat[--uxn.s.ptr]
#define JMP(x) { if(_2) pc = x; else pc += (Sint8)x; }
#define PO1(o) { o = _r ? DEC(rst) : DEC(wst);}
#define PO2(o) { if(_r) o = DEC(rst), o |= DEC(rst) << 8; else o = DEC(wst), o |= DEC(wst) << 8; }
#define POx(o) { if(_2) PO2(o) else PO1(o) }
#define PU1(i) { if(_r) INC(rst) = i; else INC(wst) = i; }
@ -37,26 +37,26 @@ WITH REGARD TO THIS SOFTWARE.
#define PUx(i) { if(_2) { c = (i); PU1(c >> 8) PU1(c) } else PU1(i) }
#define GET(o) { if(_2) PO1(o[1]) PO1(o[0]) }
#define PUT(i) { PU1(i[0]) if(_2) PU1(i[1]) }
#define DEI(i,o) o[0] = emu_dei(u, i); if(_2) o[1] = emu_dei(u, i + 1); PUT(o)
#define DEO(i,j) emu_deo(u, i, j[0]); if(_2) emu_deo(u, i + 1, j[1]);
#define PEK(i,o,m) o[0] = u->ram[i]; if(_2) o[1] = u->ram[(i + 1) & m]; PUT(o)
#define POK(i,j,m) u->ram[i] = j[0]; if(_2) u->ram[(i + 1) & m] = j[1];
#define DEI(i,o) o[0] = emu_dei(i); if(_2) o[1] = emu_dei(i + 1); PUT(o)
#define DEO(i,j) emu_deo(i, j[0]); if(_2) emu_deo(i + 1, j[1]);
#define PEK(i,o,m) o[0] = uxn.ram[i]; if(_2) o[1] = uxn.ram[(i + 1) & m]; PUT(o)
#define POK(i,j,m) uxn.ram[i] = j[0]; if(_2) uxn.ram[(i + 1) & m] = j[1];
int
uxn_eval(Uxn *u, Uint16 pc)
uxn_eval(Uint16 pc)
{
unsigned int a, b, c, x[2], y[2], z[2], step;
if(!pc || u->dev[0x0f]) return 0;
if(!pc || uxn.dev[0x0f]) return 0;
for(step = STEP_MAX; step; step--) {
switch(u->ram[pc++]) {
switch(uxn.ram[pc++]) {
/* BRK */ case 0x00: return 1;
/* JCI */ case 0x20: if(DEC(wst)) { JMI break; } pc += 2; break;
/* JMI */ case 0x40: JMI break;
/* JSI */ case 0x60: c = pc + 2; INC(rst) = c >> 8; INC(rst) = c; JMI break;
/* LI2 */ case 0xa0: INC(wst) = u->ram[pc++]; /* fall-through */
/* LIT */ case 0x80: INC(wst) = u->ram[pc++]; break;
/* L2r */ case 0xe0: INC(rst) = u->ram[pc++]; /* fall-through */
/* LIr */ case 0xc0: INC(rst) = u->ram[pc++]; break;
/* LI2 */ case 0xa0: INC(wst) = uxn.ram[pc++]; /* fall-through */
/* LIT */ case 0x80: INC(wst) = uxn.ram[pc++]; break;
/* L2r */ case 0xe0: INC(rst) = uxn.ram[pc++]; /* fall-through */
/* LIr */ case 0xc0: INC(rst) = uxn.ram[pc++]; break;
/* INC */ OPC(0x01,POx(a),PUx(a + 1))
/* POP */ OPC(0x02,REM ,{})
/* NIP */ OPC(0x03,GET(x) REM ,PUT(x))

10
src/uxn.h

@ -26,16 +26,16 @@ typedef signed short Sint16;
typedef unsigned int Uint32;
typedef struct {
Uint8 *dat, ptr;
Uint8 dat[0x100], ptr;
} Stack;
typedef struct Uxn {
Uint8 *ram, *dev;
Uint8 *ram, dev[0x100];
Stack wst, rst;
} Uxn;
extern Uint8 emu_dei(Uxn *u, Uint8 addr);
extern void emu_deo(Uxn *u, Uint8 addr, Uint8 value);
extern Uint8 emu_dei(Uint8 addr);
extern void emu_deo( Uint8 addr, Uint8 value);
extern Uxn uxn;
int uxn_eval(Uxn *u, Uint16 pc);
int uxn_eval(Uint16 pc);

25
src/uxncli.c

@ -8,7 +8,7 @@
#include "devices/datetime.h"
/*
Copyright (c) 2021-2024 Devine Lu Linvega, Andrew Alderwick
Copyright (c) 2021-2025 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
@ -21,22 +21,22 @@ WITH REGARD TO THIS SOFTWARE.
Uxn uxn;
Uint8
emu_dei(Uxn *u, Uint8 addr)
emu_dei(Uint8 addr)
{
switch(addr & 0xf0) {
case 0x00: return system_dei(u, addr);
case 0x00: return system_dei(addr);
case 0xc0: return datetime_dei(addr);
}
return uxn.dev[addr];
}
void
emu_deo(Uxn *u, Uint8 addr, Uint8 value)
emu_deo(Uint8 addr, Uint8 value)
{
uxn.dev[addr] = value;
switch(addr & 0xf0) {
case 0x00: system_deo(u, addr); break;
case 0x10: console_deo(u, addr); break;
case 0x00: system_deo(addr); break;
case 0x10: console_deo(addr); break;
case 0xa0: file_deo(addr); break;
case 0xb0: file_deo(addr); break;
}
@ -47,13 +47,13 @@ main(int argc, char **argv)
{
int i = 1;
if(argc == 2 && argv[1][0] == '-' && argv[1][1] == 'v')
return !fprintf(stdout, "Uxn(cli) - Varvara Emulator, 1 Jan 2025.\n");
return !fprintf(stdout, "Uxn(cli) - Varvara Emulator, 18 Jan 2025.\n");
else if(argc == 1)
return !fprintf(stdout, "usage: %s [-v] file.rom [args..]\n", argv[0]);
else if(!system_boot((Uint8 *)calloc(0x10000 * RAM_PAGES, sizeof(Uint8)), argv[i++]))
return !fprintf(stdout, "Could not load %s.\n", argv[i - 1]);
uxn.dev[0x17] = argc > 2;
if(uxn_eval(&uxn, PAGE_PROGRAM) && uxn.dev[0x10]) {
if(uxn_eval(PAGE_PROGRAM) && uxn.dev[0x10]) {
/* arguments input */
for(; i < argc; i++) {
char *p = argv[i];
@ -61,14 +61,7 @@ main(int argc, char **argv)
console_input('\n', i == argc - 1 ? CONSOLE_END : CONSOLE_EOA);
}
/* console input */
while(!uxn.dev[0x0f]) {
int c = fgetc(stdin);
if(c == EOF) {
console_input(0x00, CONSOLE_END);
break;
}
console_input(c, CONSOLE_STD);
}
while(!uxn.dev[0x0f] && console_input(fgetc(stdin), 0x1));
}
return uxn.dev[0x0f] & 0x7f;
}

27
src/uxnemu.c

@ -80,11 +80,11 @@ audio_deo(int instance, Uint8 *d, Uint8 port)
}
Uint8
emu_dei(Uxn *u, Uint8 addr)
emu_dei(Uint8 addr)
{
Uint8 p = addr & 0x0f, d = addr & 0xf0;
switch(d) {
case 0x00: return system_dei(u, addr);
case 0x00: return system_dei(addr);
case 0x20: return screen_dei(addr);
case 0x30: return audio_dei(0, &uxn.dev[d], p);
case 0x40: return audio_dei(1, &uxn.dev[d], p);
@ -96,16 +96,16 @@ emu_dei(Uxn *u, Uint8 addr)
}
void
emu_deo(Uxn *u, Uint8 addr, Uint8 value)
emu_deo(Uint8 addr, Uint8 value)
{
Uint8 p = addr & 0x0f, d = addr & 0xf0;
uxn.dev[addr] = value;
switch(d) {
case 0x00:
system_deo(u, addr);
system_deo(addr);
if(p > 0x7 && p < 0xe) screen_palette();
break;
case 0x10: console_deo(u, addr); break;
case 0x10: console_deo(addr); break;
case 0x20: screen_deo(addr); break;
case 0x30: audio_deo(0, &uxn.dev[d], p); break;
case 0x40: audio_deo(1, &uxn.dev[d], p); break;
@ -260,7 +260,7 @@ emu_init(void)
}
static void
emu_restart(char *drop, int soft)
emu_restart(int soft)
{
screen_resize(WIDTH, HEIGHT, uxn_screen.scale);
screen_fill(uxn_screen.bg, 0);
@ -327,10 +327,6 @@ handle_events(void)
return 0;
else if(event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_EXPOSED)
emu_redraw();
else if(event.type == SDL_DROPFILE) {
emu_restart(event.drop.file, 0);
SDL_free(event.drop.file);
}
/* Mouse */
else if(event.type == SDL_MOUSEMOTION)
mouse_pos(clamp(event.motion.x - PAD, 0, uxn_screen.width - 1), clamp(event.motion.y - PAD, 0, uxn_screen.height - 1));
@ -358,9 +354,9 @@ handle_events(void)
else if(event.key.keysym.sym == SDLK_F3)
uxn.dev[0x0f] = 0xff;
else if(event.key.keysym.sym == SDLK_F4)
emu_restart(NULL, 0);
emu_restart(0);
else if(event.key.keysym.sym == SDLK_F5)
emu_restart(NULL, 1);
emu_restart(1);
else if(event.key.keysym.sym == SDLK_F11)
set_fullscreen(!fullscreen, 1);
else if(event.key.keysym.sym == SDLK_F12)
@ -434,7 +430,7 @@ emu_run(char *rom)
if(now >= next_refresh) {
now = SDL_GetPerformanceCounter();
next_refresh = now + frame_interval;
uxn_eval(&uxn, uxn_screen.vector);
uxn_eval(uxn_screen.vector);
if(screen_changed())
emu_redraw();
}
@ -458,7 +454,6 @@ emu_end(void)
close(0); /* make stdin thread exit */
#endif
SDL_Quit();
free(bios.ram);
return exitcode;
}
@ -470,7 +465,7 @@ main(int argc, char **argv)
/* flags */
if(argc > 1 && argv[i][0] == '-') {
if(!strcmp(argv[i], "-v"))
return system_error("Uxn(gui) - Varvara Emulator", "3 Jan 2025.");
return system_error("Uxn(gui) - Varvara Emulator", "18 Jan 2025.");
else if(!strcmp(argv[i], "-2x"))
set_zoom(2, 0);
else if(!strcmp(argv[i], "-3x"))
@ -487,7 +482,7 @@ main(int argc, char **argv)
return system_error("Init", "Failed to initialize varvara.");
/* loop */
uxn.dev[0x17] = argc > i;
if(uxn_eval(&uxn, PAGE_PROGRAM)) {
if(uxn_eval(PAGE_PROGRAM)) {
console_listen(i, argc, argv);
emu_run(rom);
}

Loading…
Cancel
Save