uxn11/src/uxncli.c

77 lines
1.9 KiB
C
Raw Normal View History

2022-03-26 22:58:48 -04:00
#include <stdio.h>
#include <stdlib.h>
#include "uxn.h"
#include "devices/system.h"
2023-04-10 14:32:16 -04:00
#include "devices/console.h"
2022-03-26 22:58:48 -04:00
#include "devices/file.h"
#include "devices/datetime.h"
/*
2023-01-28 19:47:41 -05:00
Copyright (c) 2021-2023 Devine Lu Linvega, Andrew Alderwick
2022-03-26 22:58:48 -04:00
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.
*/
2023-04-10 14:32:16 -04:00
Uint16 deo_mask[] = {0x6a08, 0x0300, 0xc028, 0x8000, 0x8000, 0x8000, 0x8000, 0x0000, 0x0000, 0x0000, 0xa260, 0xa260, 0x0000, 0x0000, 0x0000, 0x0000};
Uint16 dei_mask[] = {0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x07ff, 0x0000, 0x0000, 0x0000};
2022-03-26 22:58:48 -04:00
static int
2022-04-05 22:13:14 -04:00
emu_error(char *msg, const char *err)
2022-03-26 22:58:48 -04:00
{
fprintf(stderr, "Error %s: %s\n", msg, err);
2023-02-13 12:34:30 -05:00
return 1;
2022-03-26 22:58:48 -04:00
}
2023-04-10 14:32:16 -04:00
Uint8
uxn_dei(Uxn *u, Uint8 addr)
2022-03-26 22:58:48 -04:00
{
2023-04-10 14:32:16 -04:00
switch(addr & 0xf0) {
case 0xc0: return datetime_dei(u, addr);
2022-04-05 15:08:49 -04:00
}
return u->dev[addr];
2022-03-26 22:58:48 -04:00
}
2023-04-10 14:32:16 -04:00
void
uxn_deo(Uxn *u, Uint8 addr)
2022-03-26 22:58:48 -04:00
{
2022-04-05 15:08:49 -04:00
Uint8 p = addr & 0x0f, d = addr & 0xf0;
switch(d) {
case 0x00: system_deo(u, &u->dev[d], p); break;
case 0x10: console_deo(&u->dev[d], p); break;
case 0xa0: file_deo(0, u->ram, &u->dev[d], p); break;
case 0xb0: file_deo(1, u->ram, &u->dev[d], p); break;
}
2022-03-26 22:58:48 -04:00
}
int
main(int argc, char **argv)
{
Uxn u;
int i;
if(argc < 2)
2022-04-05 22:13:14 -04:00
return emu_error("Usage", "uxncli game.rom args");
2023-04-10 14:32:16 -04:00
if(!uxn_boot(&u, (Uint8 *)calloc(0x10000 * RAM_PAGES, sizeof(Uint8))))
2022-04-05 22:13:14 -04:00
return emu_error("Boot", "Failed");
2023-02-02 11:45:03 -05:00
if(!system_load(&u, argv[1]))
2022-04-05 22:13:14 -04:00
return emu_error("Load", "Failed");
2022-03-26 22:58:48 -04:00
if(!uxn_eval(&u, PAGE_PROGRAM))
2023-02-13 12:34:30 -05:00
return u.dev[0x0f] & 0x7f;
2022-03-26 22:58:48 -04:00
for(i = 2; i < argc; i++) {
char *p = argv[i];
while(*p) console_input(&u, *p++);
console_input(&u, '\n');
}
2022-04-05 22:13:14 -04:00
while(!u.dev[0x0f]) {
int c = fgetc(stdin);
if(c != EOF)
console_input(&u, (Uint8)c);
}
2023-02-13 12:34:30 -05:00
return u.dev[0x0f] & 0x7f;
2022-03-26 22:58:48 -04:00
}