154 lines
3.6 KiB
C
154 lines
3.6 KiB
C
/* Varvara plugin for rockbox. I have no idea what I'm doing. */
|
|
|
|
#include "uxn.h"
|
|
#include "devices/ppu.h"
|
|
#include "plugin.h"
|
|
#include <stdio.h>
|
|
#include <stdint.h>
|
|
#include <time.h>
|
|
|
|
|
|
const uint8_t uxn_rom[] = { /* hello world ROM */
|
|
0x20, 0x01, 0x0e, 0x94, 0x80, 0x18, 0x17, 0x21,
|
|
0x94, 0x80, 0xf7, 0x0d, 0x22, 0x00, 0x48, 0x65,
|
|
0x6c, 0x6c, 0x6f, 0x20, 0x55, 0x78, 0x6e, 0x21,
|
|
0x21,
|
|
};
|
|
|
|
static Uxn u;
|
|
static Device *devsystem, *devconsole;
|
|
|
|
static void
|
|
memzero8(void *src, uint64_t n)
|
|
{
|
|
uint8_t * ptr = src;
|
|
for (size_t i = 0; i < n; i++) {
|
|
ptr[i] = 0;
|
|
}
|
|
}
|
|
|
|
/* taken from uxncli */
|
|
static void
|
|
inspect(Stack *s, char *name)
|
|
{
|
|
Uint8 x, y;
|
|
DEBUGF("\n%s\n", name);
|
|
for(y = 0; y < 0x04; ++y) {
|
|
for(x = 0; x < 0x08; ++x) {
|
|
Uint8 p = y * 0x08 + x;
|
|
DEBUGF(p == s->ptr ? "[%02x]" : " %02x ",
|
|
s->dat[p]);
|
|
}
|
|
DEBUGF("\n");
|
|
}
|
|
}
|
|
|
|
/* taken from uxncli */
|
|
static int
|
|
system_talk(Device *d, Uint8 b0, Uint8 w)
|
|
{
|
|
if(!w) { /* read */
|
|
switch(b0) {
|
|
case 0x2: d->dat[0x2] = d->u->wst.ptr; break;
|
|
case 0x3: d->dat[0x3] = d->u->rst.ptr; break;
|
|
}
|
|
} else { /* write */
|
|
switch(b0) {
|
|
case 0x2: d->u->wst.ptr = d->dat[0x2]; break;
|
|
case 0x3: d->u->rst.ptr = d->dat[0x3]; break;
|
|
case 0xe:
|
|
inspect(&d->u->wst, "Working-stack");
|
|
inspect(&d->u->rst, "Return-stack");
|
|
break;
|
|
case 0xf: return 0;
|
|
}
|
|
}
|
|
return 1;
|
|
}
|
|
|
|
/* taken from uxncli */
|
|
static int
|
|
console_talk(Device *d, Uint8 b0, Uint8 w)
|
|
{
|
|
if(b0 == 0x1)
|
|
d->vector = peek16(d->dat, 0x0);
|
|
if(w && b0 > 0x7)
|
|
DEBUGF("%c",(char *)&d->dat[b0]);
|
|
return 1;
|
|
}
|
|
|
|
static int
|
|
nil_talk(Device *d, Uint8 b0, Uint8 w)
|
|
{
|
|
(void)d;
|
|
(void)b0;
|
|
(void)w;
|
|
return 1;
|
|
}
|
|
|
|
int
|
|
uxn_halt(Uxn *u, Uint8 error, char *name, int id)
|
|
{
|
|
DEBUGF("Halted");
|
|
return 0;
|
|
}
|
|
|
|
/* this is the plugin entry point */
|
|
enum plugin_status plugin_start(const void* parameter)
|
|
{
|
|
/* if you don't use the parameter, you can do like
|
|
this to avoid the compiler warning about it */
|
|
(void)parameter;
|
|
|
|
/* "rb->" marks a plugin api call. Rockbox offers many of its built-in
|
|
* functions to plugins */
|
|
/* now go ahead and have fun! */
|
|
DEBUGF("UXN init\n");
|
|
// Clear RAM and copy rom to VM.
|
|
DEBUGF("zeroing\n");
|
|
memzero8(&u, sizeof(Uxn));
|
|
DEBUGF("copying ROM\n");
|
|
memcpy(u.ram.dat + PAGE_PROGRAM, uxn_rom, sizeof(uxn_rom));
|
|
DEBUGF("registering ports\n");
|
|
// Register ports
|
|
/* system */ devsystem = uxn_port(&u, 0x0, system_talk);
|
|
/* console */ devconsole = uxn_port(&u, 0x1, console_talk);
|
|
/* screen */ uxn_port(&u, 0x2, nil_talk);
|
|
/* audio0 */ uxn_port(&u, 0x3, nil_talk);
|
|
/* audio1 */ uxn_port(&u, 0x4, nil_talk);
|
|
/* audio2 */ uxn_port(&u, 0x5, nil_talk);
|
|
/* audio3 */ uxn_port(&u, 0x6, nil_talk);
|
|
/* empty */ uxn_port(&u, 0x7, nil_talk);
|
|
/* control */ uxn_port(&u, 0x8, nil_talk);
|
|
/* mouse */ uxn_port(&u, 0x9, nil_talk);
|
|
/* file */ uxn_port(&u, 0xa, nil_talk);
|
|
/* datetime */ uxn_port(&u, 0xb, nil_talk);
|
|
/* empty */ uxn_port(&u, 0xc, nil_talk);
|
|
/* empty */ uxn_port(&u, 0xd, nil_talk);
|
|
/* empty */ uxn_port(&u, 0xe, nil_talk);
|
|
/* empty */ uxn_port(&u, 0xf, nil_talk);
|
|
|
|
// Boot
|
|
// if(!uxn_boot(&u))
|
|
// return -1;
|
|
// Run
|
|
DEBUGF("eval\n");
|
|
uxn_eval(&u, 0x0100);
|
|
|
|
rb->lcd_clear_display();
|
|
// 0x000f: blue, 0x00f0:
|
|
//rb->lcd_set_foreground(LCD_RGBPACK(0,0,255));
|
|
rb->lcd_fillrect(0,0,10,10);
|
|
//rb->lcd_set_foreground(0x00f0);
|
|
rb->lcd_fillrect(10,0,10,10);
|
|
//rb->lcd_set_foreground(0x0f00);
|
|
rb->lcd_fillrect(20,0,10,10);
|
|
//rb->lcd_set_foreground(0xf000);
|
|
rb->lcd_fillrect(30,0,10,10);
|
|
rb->lcd_update();
|
|
|
|
rb->button_get(true);
|
|
return PLUGIN_OK;
|
|
|
|
}
|