uxn/cli.c

98 lines
1.7 KiB
C
Raw Normal View History

2021-02-09 00:59:46 -05: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 13:06:55 -05:00
Uint8
2021-02-09 13:58:06 -05:00
console_onread(Device *d, Uint8 b)
2021-02-09 00:59:46 -05:00
{
2021-02-09 13:58:06 -05:00
(void)d;
2021-02-09 12:00:27 -05:00
(void)b;
2021-02-09 13:06:55 -05:00
return 0;
2021-02-09 00:59:46 -05:00
}
2021-02-09 13:06:55 -05:00
Uint8
2021-02-09 13:58:06 -05:00
console_onwrite(Device *d, Uint8 b)
2021-02-09 00:59:46 -05:00
{
2021-02-09 13:58:06 -05:00
(void)d;
2021-02-09 13:06:55 -05:00
if(b)
printf("%c", b);
return 0;
2021-02-09 00:59:46 -05: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 13:06:55 -05:00
printf("\nEnded @ %d steps | hf: %x sf: %x sf: %x cf: %x\n",
2021-02-09 00:59:46 -05: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 12:05:01 -05:00
Uxn u;
2021-02-09 00:59:46 -05: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 13:06:55 -05:00
portuxn(&u, "console", console_onread, console_onwrite);
2021-02-09 00:59:46 -05:00
evaluxn(&u, u.vreset);
evaluxn(&u, u.vframe);
2021-02-09 13:06:55 -05:00
/*
2021-02-09 00:59:46 -05:00
echos(&u.wst, 0x40, "stack");
echom(&u.ram, 0x40, "ram");
2021-02-09 12:05:01 -05:00
*/
2021-02-09 13:06:55 -05:00
echof(&u);
2021-02-09 00:59:46 -05:00
return 0;
}