First hypervisor
This commit is contained in:
parent
b9a37077c3
commit
3cc2ba98f0
4
build.sh
4
build.sh
|
@ -4,6 +4,7 @@ echo "Cleaning.."
|
|||
rm -f ./bin/uxnasm
|
||||
rm -f ./bin/uxnemu
|
||||
rm -f ./bin/uxncli
|
||||
rm -f ./bin/hypervisor.rom
|
||||
rm -f ./bin/boot.rom
|
||||
rm -f ./bin/asma.rom
|
||||
|
||||
|
@ -73,8 +74,9 @@ then
|
|||
cp bin/uxnemu bin/uxnasm bin/uxncli $HOME/bin/
|
||||
fi
|
||||
|
||||
echo "Assembling(boot).."
|
||||
echo "Assembling(boot+hypervisor).."
|
||||
./bin/uxnasm projects/software/boot.tal bin/boot.rom
|
||||
./bin/uxnasm projects/software/hypervisor.tal bin/hypervisor.rom
|
||||
echo "Assembling(asma).."
|
||||
./bin/uxnasm projects/software/asma.tal bin/asma.rom
|
||||
|
||||
|
|
|
@ -0,0 +1,192 @@
|
|||
( launcher )
|
||||
|
||||
%+ { ADD } %- { SUB } %* { MUL } %/ { DIV }
|
||||
%< { LTH } %> { GTH } %= { EQU } %! { NEQ }
|
||||
%++ { ADD2 } %-- { SUB2 } %** { MUL2 } %// { DIV2 }
|
||||
%<< { LTH2 } %>> { GTH2 } %== { EQU2 } %!! { NEQ2 }
|
||||
|
||||
%RTN { JMP2r }
|
||||
%TOS { #00 SWP }
|
||||
|
||||
%DEBUG { ;print-hex/byte JSR2 #0a18 DEO }
|
||||
%DEBUG2 { ;print-hex JSR2 #0a18 DEO }
|
||||
%AUTO-YADDR { #06 .Screen/auto DEO }
|
||||
|
||||
( devices )
|
||||
|
||||
|10 @Console &vector $2 &read $1 &pad $5 &write $1 &error $1
|
||||
|20 @Screen &vector $2 &width $2 &height $2 &auto $1 &pad $1 &x $2 &y $2 &addr $2 &pixel $1 &sprite $1
|
||||
|
||||
( variables )
|
||||
|
||||
|0000
|
||||
|
||||
( init )
|
||||
|
||||
|0100 ( -> )
|
||||
|
||||
#0010 .Screen/x DEO2
|
||||
#0010 .Screen/y DEO2
|
||||
|
||||
AUTO-YADDR
|
||||
|
||||
#0010 #0000
|
||||
&wst
|
||||
( color ) DUP #fe00 LDA EQU #41 + STH
|
||||
DUP2 #fe01 ++ LDA STHr ;draw-hex JSR2
|
||||
.Screen/x DEI2k #0008 ++ ROT DEO2
|
||||
INC2 GTH2k ,&wst JCN
|
||||
POP2 POP2
|
||||
|
||||
#0010 .Screen/x DEO2
|
||||
#0020 .Screen/y DEO2
|
||||
|
||||
#0010 #0000
|
||||
&rst
|
||||
( color ) DUP #ff00 LDA EQU #41 + STH
|
||||
DUP2 #ff01 ++ LDA STHr ;draw-hex JSR2
|
||||
.Screen/x DEI2k #0008 ++ ROT DEO2
|
||||
INC2 GTH2k ,&rst JCN
|
||||
POP2 POP2
|
||||
|
||||
BRK
|
||||
|
||||
@draw-hex ( byte color -- )
|
||||
|
||||
STH
|
||||
|
||||
DUP #04 SFT ;print-hex/parse JSR2 STHkr ;draw-char JSR2
|
||||
#0f AND ;print-hex/parse JSR2 STHr ;draw-char JSR2
|
||||
|
||||
RTN
|
||||
|
||||
@print-hex ( value* -- )
|
||||
|
||||
SWP ,&byte JSR
|
||||
&byte ( byte -- )
|
||||
STHk #04 SFT ,&parse JSR #18 DEO
|
||||
STHr #0f AND ,&parse JSR #18 DEO
|
||||
JMP2r
|
||||
&parse ( byte -- char ) DUP #09 GTH ,&above JCN #30 ADD JMP2r
|
||||
&above #57 ADD JMP2r
|
||||
|
||||
JMP2r
|
||||
|
||||
@hello-str "Hello $1
|
||||
|
||||
@draw-str ( str* color -- )
|
||||
|
||||
STH
|
||||
&while
|
||||
LDAk STHkr ,draw-char JSR
|
||||
INC2 LDAk ,&while JCN
|
||||
POP2
|
||||
POPr
|
||||
|
||||
JMP2r
|
||||
|
||||
@draw-char ( char color -- )
|
||||
|
||||
SWP
|
||||
[ #20 - #00 SWP #40 SFT2 ;font ++ ] .Screen/addr DEO2
|
||||
.Screen/sprite DEOk DEO
|
||||
.Screen/y DEI2 #0010 -- .Screen/y DEO2
|
||||
.Screen/x DEI2 #0008 ++ .Screen/x DEO2
|
||||
|
||||
JMP2r
|
||||
|
||||
@font
|
||||
0000 0000 0000 0000 0000 0000 0000 0000
|
||||
0000 183c 3c3c 1818 1800 1818 0000 0000
|
||||
0066 6666 2400 0000 0000 0000 0000 0000
|
||||
0000 006c 6cfe 6c6c 6cfe 6c6c 0000 0000
|
||||
1818 7cc6 c2c0 7c06 0686 c67c 1818 0000
|
||||
0000 0000 c2c6 0c18 3060 c686 0000 0000
|
||||
0000 386c 6c38 76dc cccc cc76 0000 0000
|
||||
0030 3030 6000 0000 0000 0000 0000 0000
|
||||
0000 0c18 3030 3030 3030 180c 0000 0000
|
||||
0000 3018 0c0c 0c0c 0c0c 1830 0000 0000
|
||||
0000 0000 0066 3cff 3c66 0000 0000 0000
|
||||
0000 0000 0018 187e 1818 0000 0000 0000
|
||||
0000 0000 0000 0000 0018 1818 3000 0000
|
||||
0000 0000 0000 00fe 0000 0000 0000 0000
|
||||
0000 0000 0000 0000 0000 1818 0000 0000
|
||||
0000 0000 0206 0c18 3060 c080 0000 0000
|
||||
0000 386c c6c6 d6d6 c6c6 6c38 0000 0000
|
||||
0000 1838 7818 1818 1818 187e 0000 0000
|
||||
0000 7cc6 060c 1830 60c0 c6fe 0000 0000
|
||||
0000 7cc6 0606 3c06 0606 c67c 0000 0000
|
||||
0000 0c1c 3c6c ccfe 0c0c 0c1e 0000 0000
|
||||
0000 fec0 c0c0 fc06 0606 c67c 0000 0000
|
||||
0000 3860 c0c0 fcc6 c6c6 c67c 0000 0000
|
||||
0000 fec6 0606 0c18 3030 3030 0000 0000
|
||||
0000 7cc6 c6c6 7cc6 c6c6 c67c 0000 0000
|
||||
0000 7cc6 c6c6 7e06 0606 0c78 0000 0000
|
||||
0000 0000 1818 0000 0018 1800 0000 0000
|
||||
0000 0000 1818 0000 0018 1830 0000 0000
|
||||
0000 0006 0c18 3060 3018 0c06 0000 0000
|
||||
0000 0000 007e 0000 7e00 0000 0000 0000
|
||||
0000 0060 3018 0c06 0c18 3060 0000 0000
|
||||
0000 7cc6 c60c 1818 1800 1818 0000 0000
|
||||
0000 007c c6c6 dede dedc c07c 0000 0000
|
||||
0000 1038 6cc6 c6fe c6c6 c6c6 0000 0000
|
||||
0000 fc66 6666 7c66 6666 66fc 0000 0000
|
||||
0000 3c66 c2c0 c0c0 c0c2 663c 0000 0000
|
||||
0000 f86c 6666 6666 6666 6cf8 0000 0000
|
||||
0000 fe66 6268 7868 6062 66fe 0000 0000
|
||||
0000 fe66 6268 7868 6060 60f0 0000 0000
|
||||
0000 3c66 c2c0 c0de c6c6 663a 0000 0000
|
||||
0000 c6c6 c6c6 fec6 c6c6 c6c6 0000 0000
|
||||
0000 3c18 1818 1818 1818 183c 0000 0000
|
||||
0000 1e0c 0c0c 0c0c cccc cc78 0000 0000
|
||||
0000 e666 666c 7878 6c66 66e6 0000 0000
|
||||
0000 f060 6060 6060 6062 66fe 0000 0000
|
||||
0000 c6ee fefe d6c6 c6c6 c6c6 0000 0000
|
||||
0000 c6e6 f6fe dece c6c6 c6c6 0000 0000
|
||||
0000 7cc6 c6c6 c6c6 c6c6 c67c 0000 0000
|
||||
0000 fc66 6666 7c60 6060 60f0 0000 0000
|
||||
0000 7cc6 c6c6 c6c6 c6d6 de7c 0c0e 0000
|
||||
0000 fc66 6666 7c6c 6666 66e6 0000 0000
|
||||
0000 7cc6 c660 380c 06c6 c67c 0000 0000
|
||||
0000 7e7e 5a18 1818 1818 183c 0000 0000
|
||||
0000 c6c6 c6c6 c6c6 c6c6 c67c 0000 0000
|
||||
0000 c6c6 c6c6 c6c6 c66c 3810 0000 0000
|
||||
0000 c6c6 c6c6 d6d6 d6fe ee6c 0000 0000
|
||||
0000 c6c6 6c7c 3838 7c6c c6c6 0000 0000
|
||||
0000 6666 6666 3c18 1818 183c 0000 0000
|
||||
0000 fec6 860c 1830 60c2 c6fe 0000 0000
|
||||
0000 3c30 3030 3030 3030 303c 0000 0000
|
||||
0000 0080 c0e0 7038 1c0e 0602 0000 0000
|
||||
0000 3c0c 0c0c 0c0c 0c0c 0c3c 0000 0000
|
||||
1038 6cc6 0000 0000 0000 0000 0000 0000
|
||||
0000 0000 0000 0000 0000 0000 00ff 0000
|
||||
3030 1800 0000 0000 0000 0000 0000 0000
|
||||
0000 0000 0078 0c7c cccc cc76 0000 0000
|
||||
0000 e060 6078 6c66 6666 667c 0000 0000
|
||||
0000 0000 007c c6c0 c0c0 c67c 0000 0000
|
||||
0000 1c0c 0c3c 6ccc cccc cc76 0000 0000
|
||||
0000 0000 007c c6fe c0c0 c67c 0000 0000
|
||||
0000 386c 6460 f060 6060 60f0 0000 0000
|
||||
0000 0000 0076 cccc cccc cc7c 0ccc 7800
|
||||
0000 e060 606c 7666 6666 66e6 0000 0000
|
||||
0000 1818 0038 1818 1818 183c 0000 0000
|
||||
0000 0606 000e 0606 0606 0606 6666 3c00
|
||||
0000 e060 6066 6c78 786c 66e6 0000 0000
|
||||
0000 3818 1818 1818 1818 183c 0000 0000
|
||||
0000 0000 00ec fed6 d6d6 d6c6 0000 0000
|
||||
0000 0000 00dc 6666 6666 6666 0000 0000
|
||||
0000 0000 007c c6c6 c6c6 c67c 0000 0000
|
||||
0000 0000 00dc 6666 6666 667c 6060 f000
|
||||
0000 0000 0076 cccc cccc cc7c 0c0c 1e00
|
||||
0000 0000 00dc 7666 6060 60f0 0000 0000
|
||||
0000 0000 007c c660 380c c67c 0000 0000
|
||||
0000 1030 30fc 3030 3030 361c 0000 0000
|
||||
0000 0000 00cc cccc cccc cc76 0000 0000
|
||||
0000 0000 0066 6666 6666 3c18 0000 0000
|
||||
0000 0000 00c6 c6d6 d6d6 fe6c 0000 0000
|
||||
0000 0000 00c6 6c38 3838 6cc6 0000 0000
|
||||
0000 0000 00c6 c6c6 c6c6 c67e 060c f800
|
||||
0000 0000 00fe cc18 3060 c6fe 0000 0000
|
||||
0000 0e18 1818 7018 1818 180e 0000 0000
|
||||
0000 1818 1818 0018 1818 1818 0000 0000
|
||||
0000 7018 1818 0e18 1818 1870 0000 0000
|
|
@ -22,24 +22,6 @@ static Uint8 blending[5][16] = {
|
|||
{2, 3, 1, 2, 2, 3, 1, 2, 2, 3, 1, 2, 2, 3, 1, 2},
|
||||
{1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0}};
|
||||
|
||||
static Uint8 font[][8] = {
|
||||
{0x00, 0x7c, 0x82, 0x82, 0x82, 0x82, 0x82, 0x7c},
|
||||
{0x00, 0x30, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10},
|
||||
{0x00, 0x7c, 0x82, 0x02, 0x7c, 0x80, 0x80, 0xfe},
|
||||
{0x00, 0x7c, 0x82, 0x02, 0x1c, 0x02, 0x82, 0x7c},
|
||||
{0x00, 0x0c, 0x14, 0x24, 0x44, 0x84, 0xfe, 0x04},
|
||||
{0x00, 0xfe, 0x80, 0x80, 0x7c, 0x02, 0x82, 0x7c},
|
||||
{0x00, 0x7c, 0x82, 0x80, 0xfc, 0x82, 0x82, 0x7c},
|
||||
{0x00, 0x7c, 0x82, 0x02, 0x1e, 0x02, 0x02, 0x02},
|
||||
{0x00, 0x7c, 0x82, 0x82, 0x7c, 0x82, 0x82, 0x7c},
|
||||
{0x00, 0x7c, 0x82, 0x82, 0x7e, 0x02, 0x82, 0x7c},
|
||||
{0x00, 0x7c, 0x82, 0x02, 0x7e, 0x82, 0x82, 0x7e},
|
||||
{0x00, 0xfc, 0x82, 0x82, 0xfc, 0x82, 0x82, 0xfc},
|
||||
{0x00, 0x7c, 0x82, 0x80, 0x80, 0x80, 0x82, 0x7c},
|
||||
{0x00, 0xfc, 0x82, 0x82, 0x82, 0x82, 0x82, 0xfc},
|
||||
{0x00, 0x7c, 0x82, 0x80, 0xf0, 0x80, 0x82, 0x7c},
|
||||
{0x00, 0x7c, 0x82, 0x80, 0xf0, 0x80, 0x80, 0x80}};
|
||||
|
||||
static void
|
||||
screen_write(UxnScreen *p, Layer *layer, Uint16 x, Uint16 y, Uint8 color)
|
||||
{
|
||||
|
@ -125,35 +107,6 @@ screen_redraw(UxnScreen *p, Uint32 *pixels)
|
|||
p->fg.changed = p->bg.changed = 0;
|
||||
}
|
||||
|
||||
void
|
||||
screen_debug(UxnScreen *p, Uint8 *stack, Uint8 wptr, Uint8 rptr, Uint8 *memory)
|
||||
{
|
||||
Uint8 i, x, y, b;
|
||||
for(i = 0; i < 0x20; i++) {
|
||||
x = ((i % 8) * 3 + 1) * 8, y = (i / 8 + 1) * 8, b = stack[i];
|
||||
/* working stack */
|
||||
screen_blit(p, &p->fg, x, y, font[(b >> 4) & 0xf], 1 + (wptr == i) * 0x7, 0, 0, 0);
|
||||
screen_blit(p, &p->fg, x + 8, y, font[b & 0xf], 1 + (wptr == i) * 0x7, 0, 0, 0);
|
||||
y = 0x28 + (i / 8 + 1) * 8;
|
||||
b = memory[i];
|
||||
/* return stack */
|
||||
screen_blit(p, &p->fg, x, y, font[(b >> 4) & 0xf], 3, 0, 0, 0);
|
||||
screen_blit(p, &p->fg, x + 8, y, font[b & 0xf], 3, 0, 0, 0);
|
||||
}
|
||||
/* return pointer */
|
||||
screen_blit(p, &p->fg, 0x8, y + 0x10, font[(rptr >> 4) & 0xf], 0x2, 0, 0, 0);
|
||||
screen_blit(p, &p->fg, 0x10, y + 0x10, font[rptr & 0xf], 0x2, 0, 0, 0);
|
||||
/* guides */
|
||||
for(x = 0; x < 0x10; x++) {
|
||||
screen_write(p, &p->fg, x, p->height / 2, 2);
|
||||
screen_write(p, &p->fg, p->width - x, p->height / 2, 2);
|
||||
screen_write(p, &p->fg, p->width / 2, p->height - x, 2);
|
||||
screen_write(p, &p->fg, p->width / 2, x, 2);
|
||||
screen_write(p, &p->fg, p->width / 2 - 0x10 / 2 + x, p->height / 2, 2);
|
||||
screen_write(p, &p->fg, p->width / 2, p->height / 2 - 0x10 / 2 + x, 2);
|
||||
}
|
||||
}
|
||||
|
||||
/* IO */
|
||||
|
||||
Uint8
|
||||
|
|
|
@ -34,7 +34,6 @@ void screen_palette(UxnScreen *p, Uint8 *addr);
|
|||
void screen_resize(UxnScreen *p, Uint16 width, Uint16 height);
|
||||
void screen_clear(UxnScreen *p, Layer *layer);
|
||||
void screen_redraw(UxnScreen *p, Uint32 *pixels);
|
||||
void screen_debug(UxnScreen *p, Uint8 *stack, Uint8 wptr, Uint8 rptr, Uint8 *memory);
|
||||
|
||||
Uint8 screen_dei(Device *d, Uint8 port);
|
||||
void screen_deo(Device *d, Uint8 port);
|
|
@ -26,7 +26,7 @@ typedef unsigned int Uint32;
|
|||
|
||||
typedef struct {
|
||||
Uint8 ptr;
|
||||
Uint8 dat[256];
|
||||
Uint8 dat[255];
|
||||
} Stack;
|
||||
|
||||
typedef struct Device {
|
||||
|
|
22
src/uxnemu.c
22
src/uxnemu.c
|
@ -124,10 +124,8 @@ set_size(Uint16 width, Uint16 height, int is_resize)
|
|||
}
|
||||
|
||||
static void
|
||||
redraw(Uxn *u)
|
||||
redraw(void)
|
||||
{
|
||||
if(devsystem->dat[0xe])
|
||||
screen_debug(&uxn_screen, u->wst->dat, u->wst->ptr, u->rst->ptr, u->ram);
|
||||
screen_redraw(&uxn_screen, uxn_screen.pixels);
|
||||
if(SDL_UpdateTexture(gTexture, NULL, uxn_screen.pixels, uxn_screen.width * sizeof(Uint32)) != 0)
|
||||
error("SDL_UpdateTexture", SDL_GetError());
|
||||
|
@ -281,12 +279,14 @@ start(Uxn *u, char *rom)
|
|||
memory = (Uint8 *)calloc(0xffff, sizeof(Uint8));
|
||||
shadow = (Uint8 *)calloc(0xffff, sizeof(Uint8));
|
||||
|
||||
if(!uxn_boot(&hypervisor, (Stack *)(shadow + 0x600), (Stack *)(shadow + 0x800), shadow))
|
||||
if(!uxn_boot(&hypervisor, (Stack *)(shadow + 0xfc00), (Stack *)(shadow + 0xfd00), shadow))
|
||||
return error("Boot", "Failed to start uxn.");
|
||||
if(!uxn_boot(u, (Stack *)(shadow + 0x200), (Stack *)(shadow + 0x400), memory))
|
||||
if(!uxn_boot(u, (Stack *)(shadow + 0xfe00), (Stack *)(shadow + 0xff00), memory))
|
||||
return error("Boot", "Failed to start uxn.");
|
||||
if(!load(u, rom))
|
||||
return error("Boot", "Failed to load rom.");
|
||||
if(!load(&hypervisor, "hypervisor.rom"))
|
||||
error("Hypervisor", "No debugger found.");
|
||||
|
||||
/* system */ devsystem = uxn_port(u, 0x0, system_dei, system_deo);
|
||||
/* console */ devconsole = uxn_port(u, 0x1, nil_dei, console_deo);
|
||||
|
@ -305,6 +305,10 @@ start(Uxn *u, char *rom)
|
|||
/* unused */ uxn_port(u, 0xe, nil_dei, nil_deo);
|
||||
/* unused */ uxn_port(u, 0xf, nil_dei, nil_deo);
|
||||
|
||||
/* Hypervisor */
|
||||
uxn_port(&hypervisor, 0x1, nil_dei, console_deo);
|
||||
uxn_port(&hypervisor, 0x2, screen_dei, screen_deo);
|
||||
|
||||
if(!uxn_eval(u, PAGE_PROGRAM))
|
||||
return error("Boot", "Failed to start rom.");
|
||||
|
||||
|
@ -415,7 +419,7 @@ console_input(Uxn *u, char c)
|
|||
static int
|
||||
run(Uxn *u)
|
||||
{
|
||||
redraw(u);
|
||||
redraw();
|
||||
while(!devsystem->dat[0xf]) {
|
||||
SDL_Event event;
|
||||
double elapsed, begin;
|
||||
|
@ -426,7 +430,7 @@ run(Uxn *u)
|
|||
if(event.type == SDL_QUIT)
|
||||
return error("Run", "Quit.");
|
||||
else if(event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_EXPOSED)
|
||||
redraw(u);
|
||||
redraw();
|
||||
else if(event.type == SDL_DROPFILE) {
|
||||
set_size(WIDTH, HEIGHT, 0);
|
||||
start(u, event.drop.file);
|
||||
|
@ -480,9 +484,11 @@ run(Uxn *u)
|
|||
else if(event.type == stdin_event)
|
||||
console_input(u, event.cbutton.button);
|
||||
}
|
||||
if(devsystem->dat[0xe])
|
||||
uxn_eval(&hypervisor, PAGE_PROGRAM);
|
||||
uxn_eval(u, devscreen->vector);
|
||||
if(uxn_screen.fg.changed || uxn_screen.bg.changed || devsystem->dat[0xe])
|
||||
redraw(u);
|
||||
redraw();
|
||||
if(!BENCH) {
|
||||
elapsed = (SDL_GetPerformanceCounter() - begin) / (double)SDL_GetPerformanceFrequency() * 1000.0f;
|
||||
SDL_Delay(clamp(16.666f - elapsed, 0, 1000));
|
||||
|
|
Loading…
Reference in New Issue