2021-03-23 02:04:31 +00:00
|
|
|
#include <stdio.h>
|
2022-01-01 23:20:48 +00:00
|
|
|
#include <stdlib.h>
|
2022-01-07 18:02:28 +00:00
|
|
|
|
2021-05-13 01:28:45 +00:00
|
|
|
#include "uxn.h"
|
2022-01-05 13:28:22 +00:00
|
|
|
#include "devices/system.h"
|
2023-08-08 21:13:07 +00:00
|
|
|
#include "devices/console.h"
|
2021-11-05 21:32:45 +00:00
|
|
|
#include "devices/file.h"
|
2022-01-07 18:02:28 +00:00
|
|
|
#include "devices/datetime.h"
|
2021-03-23 02:04:31 +00:00
|
|
|
|
|
|
|
/*
|
2024-01-02 19:54:12 +00:00
|
|
|
Copyright (c) 2021-2024 Devine Lu Linvega, Andrew Alderwick
|
2021-03-23 02:04:31 +00: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-05 18:44:23 +00:00
|
|
|
Uint8
|
2023-07-24 02:18:11 +00:00
|
|
|
emu_dei(Uxn *u, Uint8 addr)
|
2021-10-13 21:56:38 +00:00
|
|
|
{
|
2023-03-04 18:51:23 +00:00
|
|
|
switch(addr & 0xf0) {
|
2023-08-19 14:34:14 +00:00
|
|
|
case 0x00: return system_dei(u, addr);
|
2023-03-01 19:28:14 +00:00
|
|
|
case 0xc0: return datetime_dei(u, addr);
|
2023-01-01 21:19:40 +00:00
|
|
|
}
|
|
|
|
return u->dev[addr];
|
2021-10-13 21:56:38 +00:00
|
|
|
}
|
|
|
|
|
2023-03-05 18:44:23 +00:00
|
|
|
void
|
2023-10-30 21:14:02 +00:00
|
|
|
emu_deo(Uxn *u, Uint8 addr, Uint8 value)
|
2021-03-23 02:04:31 +00:00
|
|
|
{
|
2023-01-01 21:19:40 +00:00
|
|
|
Uint8 p = addr & 0x0f, d = addr & 0xf0;
|
2023-10-30 21:14:02 +00:00
|
|
|
u->dev[addr] = value;
|
2023-01-01 21:19:40 +00:00
|
|
|
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 23:13:12 +00:00
|
|
|
}
|
|
|
|
}
|
2021-03-23 02:04:31 +00:00
|
|
|
|
2022-01-11 23:13:12 +00:00
|
|
|
int
|
|
|
|
main(int argc, char **argv)
|
|
|
|
{
|
2023-04-17 16:59:00 +00:00
|
|
|
int i = 1;
|
2024-01-03 03:20:16 +00:00
|
|
|
Uxn u = {0};
|
2023-12-25 22:39:29 +00:00
|
|
|
Uint8 dev[0x100] = {0};
|
2024-02-19 19:33:51 +00:00
|
|
|
u.dev = dev;
|
2023-04-17 17:41:03 +00:00
|
|
|
if(i == argc)
|
2024-01-03 04:24:42 +00:00
|
|
|
return system_error("usage:", "uxncli [-v] file.rom [args..]");
|
2023-08-08 22:31:48 +00:00
|
|
|
if(argv[i][0] == '-' && argv[i][1] == 'v')
|
2024-03-18 17:44:19 +00:00
|
|
|
return system_error("Uxncli - Varvara Emulator(CLI)", "18 Mar 2024.");
|
2023-08-15 23:06:29 +00:00
|
|
|
if(!system_init(&u, (Uint8 *)calloc(0x10000 * RAM_PAGES, sizeof(Uint8)), argv[i++]))
|
|
|
|
return system_error("Init", "Failed to initialize uxn.");
|
2024-01-02 19:54:12 +00:00
|
|
|
/* eval */
|
2023-04-22 21:56:12 +00:00
|
|
|
u.dev[0x17] = argc - i;
|
2024-02-15 23:31:16 +00:00
|
|
|
if(uxn_eval(&u, PAGE_PROGRAM) && PEEK2(u.dev + 0x10)) {
|
2023-08-15 23:24:40 +00:00
|
|
|
console_listen(&u, i, argc, argv);
|
2024-01-02 19:54:12 +00:00
|
|
|
while(!u.dev[0x0f]) {
|
2024-01-14 00:50:05 +00:00
|
|
|
int c = fgetc(stdin);
|
2024-01-02 19:54:12 +00:00
|
|
|
if(c == EOF) {
|
|
|
|
console_input(&u, 0x00, CONSOLE_END);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
console_input(&u, (Uint8)c, CONSOLE_STD);
|
|
|
|
}
|
2023-01-01 21:19:40 +00:00
|
|
|
}
|
2024-01-02 19:54:12 +00:00
|
|
|
free(u.ram);
|
|
|
|
return u.dev[0x0f] & 0x7f;
|
2021-03-23 02:04:31 +00:00
|
|
|
}
|