2021-03-22 22:04:31 -04:00
|
|
|
#include <stdio.h>
|
2022-01-01 18:20:48 -05:00
|
|
|
#include <stdlib.h>
|
2022-01-07 13:02:28 -05:00
|
|
|
|
2021-05-12 21:28:45 -04:00
|
|
|
#include "uxn.h"
|
2022-01-05 08:28:22 -05:00
|
|
|
#include "devices/system.h"
|
2021-11-05 17:32:45 -04:00
|
|
|
#include "devices/file.h"
|
2022-01-07 13:02:28 -05:00
|
|
|
#include "devices/datetime.h"
|
2021-03-22 22:04:31 -04:00
|
|
|
|
|
|
|
/*
|
2023-01-02 09:40:23 -05:00
|
|
|
Copyright (c) 2021-2023 Devine Lu Linvega, Andrew Alderwick
|
2021-03-22 22:04:31 -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-03-06 13:36:24 -05:00
|
|
|
Uint16 deo_mask[] = {0x6a08, 0x0300, 0xc028, 0x8000, 0x8000, 0x8000, 0x8000, 0x0000, 0x0000, 0x0000, 0xa260, 0xa260, 0x0000, 0x0000, 0x0000, 0x0000};
|
2023-04-08 11:53:56 -04:00
|
|
|
Uint16 dei_mask[] = {0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x07ff, 0x0000, 0x0000, 0x0000};
|
2023-03-06 13:36:24 -05:00
|
|
|
|
2021-06-28 17:42:36 -04:00
|
|
|
static int
|
2023-01-01 16:19:40 -05:00
|
|
|
emu_error(char *msg, const char *err)
|
2021-03-22 22:04:31 -04:00
|
|
|
{
|
2021-07-14 15:11:10 -04:00
|
|
|
fprintf(stderr, "Error %s: %s\n", msg, err);
|
2023-02-13 12:33:57 -05:00
|
|
|
return 1;
|
2021-03-22 22:04:31 -04:00
|
|
|
}
|
|
|
|
|
2023-03-05 13:44:23 -05:00
|
|
|
Uint8
|
|
|
|
uxn_dei(Uxn *u, Uint8 addr)
|
2021-10-13 17:56:38 -04:00
|
|
|
{
|
2023-03-04 13:51:23 -05:00
|
|
|
switch(addr & 0xf0) {
|
2023-03-01 14:28:14 -05:00
|
|
|
case 0xc0: return datetime_dei(u, addr);
|
2023-01-01 16:19:40 -05:00
|
|
|
}
|
|
|
|
return u->dev[addr];
|
2021-10-13 17:56:38 -04:00
|
|
|
}
|
|
|
|
|
2023-03-05 13:44:23 -05:00
|
|
|
void
|
|
|
|
uxn_deo(Uxn *u, Uint8 addr)
|
2021-03-22 22:04:31 -04:00
|
|
|
{
|
2023-01-01 16:19:40 -05: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-01-11 18:13:12 -05:00
|
|
|
}
|
|
|
|
}
|
2021-03-22 22:04:31 -04:00
|
|
|
|
2022-01-11 18:13:12 -05:00
|
|
|
int
|
|
|
|
main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
Uxn u;
|
2023-04-17 12:59:00 -04:00
|
|
|
int i = 1;
|
2022-01-11 18:13:12 -05:00
|
|
|
if(argc < 2)
|
2023-01-01 16:19:40 -05:00
|
|
|
return emu_error("Usage", "uxncli game.rom args");
|
2023-03-05 13:44:23 -05:00
|
|
|
if(!uxn_boot(&u, (Uint8 *)calloc(0x10000 * RAM_PAGES, sizeof(Uint8))))
|
2023-01-01 16:19:40 -05:00
|
|
|
return emu_error("Boot", "Failed");
|
2023-04-17 12:59:00 -04:00
|
|
|
if(!system_load(&u, argv[i++]))
|
2023-01-01 16:19:40 -05:00
|
|
|
return emu_error("Load", "Failed");
|
2023-04-17 13:29:39 -04:00
|
|
|
if(i == argc)
|
|
|
|
u.dev[0x17] = CONSOLE_END;
|
2022-01-11 18:13:12 -05:00
|
|
|
if(!uxn_eval(&u, PAGE_PROGRAM))
|
2023-02-13 12:33:57 -05:00
|
|
|
return u.dev[0x0f] & 0x7f;
|
2023-04-17 12:59:00 -04:00
|
|
|
for(; i < argc; i++) {
|
2022-01-11 18:13:12 -05:00
|
|
|
char *p = argv[i];
|
2023-04-17 00:13:50 -04:00
|
|
|
while(*p) console_input(&u, *p++, CONSOLE_ARG);
|
2023-04-17 12:36:55 -04:00
|
|
|
console_input(&u, '\n', i == argc - 1 ? CONSOLE_END : CONSOLE_EOA);
|
2021-10-13 17:56:38 -04:00
|
|
|
}
|
2023-01-01 16:19:40 -05:00
|
|
|
while(!u.dev[0x0f]) {
|
|
|
|
int c = fgetc(stdin);
|
2023-04-17 00:13:50 -04:00
|
|
|
if(c != EOF) console_input(&u, (Uint8)c, CONSOLE_STD);
|
2023-01-01 16:19:40 -05:00
|
|
|
}
|
2023-02-13 12:33:57 -05:00
|
|
|
return u.dev[0x0f] & 0x7f;
|
2021-03-22 22:04:31 -04:00
|
|
|
}
|