0
0
Fork 0
mirror of https://git.sr.ht/~rabbits/uxn synced 2024-11-19 12:25:11 +00:00
uxn/cli.c

96 lines
1.7 KiB
C
Raw Normal View History

2021-02-09 05:59:46 +00:00
#include <stdio.h>
/*
Copyright (c) 2021 Devine Lu Linvega
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.
*/
#include "uxn.h"
int
error(char *msg, const char *err)
{
printf("Error %s: %s\n", msg, err);
return 0;
}
2021-02-09 18:06:55 +00:00
Uint8
console_onread(Uint8 b)
2021-02-09 05:59:46 +00:00
{
2021-02-09 17:00:27 +00:00
(void)b;
2021-02-09 18:06:55 +00:00
return 0;
2021-02-09 05:59:46 +00:00
}
2021-02-09 18:06:55 +00:00
Uint8
console_onwrite(Uint8 b)
2021-02-09 05:59:46 +00:00
{
2021-02-09 18:06:55 +00:00
if(b)
printf("%c", b);
return 0;
2021-02-09 05:59:46 +00:00
}
void
echos(Stack8 *s, Uint8 len, char *name)
{
int i;
printf("\n%s\n", name);
for(i = 0; i < len; ++i) {
if(i % 16 == 0)
printf("\n");
printf("%02x%c", s->dat[i], s->ptr == i ? '<' : ' ');
}
printf("\n\n");
}
void
echom(Memory *m, Uint16 len, char *name)
{
int i;
printf("\n%s\n", name);
for(i = 0; i < len; ++i) {
if(i % 16 == 0)
printf("\n");
printf("%02x ", m->dat[i]);
}
printf("\n\n");
}
void
echof(Uxn *c)
{
2021-02-09 18:06:55 +00:00
printf("\nEnded @ %d steps | hf: %x sf: %x sf: %x cf: %x\n",
2021-02-09 05:59:46 +00:00
c->counter,
getflag(&c->status, FLAG_HALT) != 0,
getflag(&c->status, FLAG_SHORT) != 0,
getflag(&c->status, FLAG_SIGN) != 0,
getflag(&c->status, FLAG_COND) != 0);
}
int
main(int argc, char **argv)
{
2021-02-09 17:05:01 +00:00
Uxn u;
2021-02-09 05:59:46 +00:00
if(argc < 2)
return error("Input", "Missing");
if(!bootuxn(&u))
return error("Boot", "Failed");
if(!loaduxn(&u, argv[1]))
return error("Load", "Failed");
2021-02-09 18:06:55 +00:00
portuxn(&u, "console", console_onread, console_onwrite);
2021-02-09 05:59:46 +00:00
evaluxn(&u, u.vreset);
evaluxn(&u, u.vframe);
2021-02-09 18:06:55 +00:00
/*
2021-02-09 05:59:46 +00:00
echos(&u.wst, 0x40, "stack");
echom(&u.ram, 0x40, "ram");
2021-02-09 17:05:01 +00:00
*/
2021-02-09 18:06:55 +00:00
echof(&u);
2021-02-09 05:59:46 +00:00
return 0;
}