commit f3e58adc03cf36602afafe4f140b6ab3bc88deff
parent 56a3a993f45a603e45578cafcab2a4ba7dc7332e
Author: neauoire <aliceffekt@gmail.com>
Date: Tue, 13 Apr 2021 12:29:36 -0700
Implemented file vectors in nasu/noodle
Diffstat:
7 files changed, 45 insertions(+), 34 deletions(-)
diff --git a/build.sh b/build.sh
@@ -32,7 +32,7 @@ else
fi
echo "Assembling.."
-./bin/assembler projects/examples/dev.file.usm bin/boot.rom
+./bin/assembler projects/software/noodle.usm bin/boot.rom
echo "Running.."
if [ "${2}" = '--cli' ];
diff --git a/projects/examples/gui.picture.usm b/projects/examples/gui.picture.usm
@@ -8,7 +8,7 @@
|0100 ;System { vector 2 pad 6 r 2 g 2 b 2 }
|0120 ;Screen { vector 2 width 2 height 2 pad 2 x 2 y 2 addr 2 color 1 }
|0160 ;Mouse { vector 2 x 2 y 2 state 1 chord 1 }
-|0170 ;File { pad 8 name 2 length 2 load 2 save 2 }
+|0170 ;File { vector 2 pad 6 name 2 length 2 load 2 save 2 }
( program )
@@ -16,22 +16,29 @@
( theme ) #ac52 =System.r #a362 =System.g #b253 =System.b
( vectors ) ,on-mouse =Mouse.vector
+ ( vectors ) ,on-transfer =File.vector
( load )
#0000 #0000 #0100 #0100 #2c ,pict_large ,draw-picture JSR2
- ( load ) ,filepath =File.name #4000 =File.length ,img =File.load
- ( draw ) #0080 #0020 #0100 #0100 #41 ,img ,draw-chr JSR2
#0128 #0010 #0080 #0080 #2e ,pict_medium ,draw-picture JSR2
#0020 #00d0 #0020 #0020 #25 ,pict_small ,draw-picture JSR2
#0010 #0010 #0020 #0010 #25 ,dvd_icn ,draw-picture JSR2
+ ( load ) ,filepath =File.name #4000 =File.length ,img =File.load
+
+BRK
+
+@on-transfer ( -> )
+
+ ( draw ) #0080 #0020 #0100 #0100 #41 ,img ,draw-chr JSR2
+
BRK
-@on-mouse
+@on-mouse ( -> )
( clear last cursor )
,clear_icn =Screen.addr
diff --git a/projects/software/nasu.usm b/projects/software/nasu.usm
@@ -45,6 +45,7 @@
( theme ) #e0fc =System.r #30cc =System.g #30ac =System.b
( vectors ) ,on-button =Controller.vector
( vectors ) ,on-mouse =Mouse.vector
+ ( vectors ) ,on-transfer =File.vector
~Screen.width 2/ #008a SUB2 =bankview.x
~Screen.height 2/ #003f SUB2 =bankview.y
@@ -61,7 +62,13 @@
BRK
-@on-button
+@on-transfer ( -> )
+
+ ,redraw JSR2
+
+BRK
+
+@on-button ( -> )
~Controller.button
DUP #10 EQU ^$no-ctrl-up JNZ
@@ -83,7 +90,7 @@ BRK
BRK
-@on-mouse
+@on-mouse ( -> )
~Mouse.state #00 EQU ,$click-end JNZ2
diff --git a/projects/software/noodle.usm b/projects/software/noodle.usm
@@ -68,6 +68,7 @@
( vectors ) ,on-screen =Screen.vector
( vectors ) ,on-button =Controller.vector
( vectors ) ,on-mouse =Mouse.vector
+ ( vectors ) ,on-transfer =File.vector
~theme.r0 =System.r ~theme.g0 =System.g ~theme.b0 =System.b
@@ -79,7 +80,6 @@
( load file )
,untitled_txt ,path.name ,strcpy JSR2
- ,path.name ,load-file JSR2
( setup panes )
#0010 =toolpane.x1 #0010 =toolpane.y1 ~toolpane.x1 #0028 ADD2 =toolpane.x2 ~toolpane.y1 #0008 ADD2 =toolpane.y2
@@ -91,9 +91,19 @@
,center JSR2
,clear JSR2
+ ( load default file )
+ ,path.name ,load-file JSR2
+
+BRK
+
+@on-transfer ( -> )
+
+ ,draw-canvas JSR2
+ ( release ) #00 =Mouse.state
+
BRK
-@on-screen ( -- )
+@on-screen ( -> )
~document.edit #01 NEQ ^$no-edit JNZ
#0008 =Screen.x
@@ -108,7 +118,7 @@ BRK
BRK
-@on-mouse
+@on-mouse ( -> )
,draw-cursor JSR2
diff --git a/src/emulator.c b/src/emulator.c
@@ -218,15 +218,15 @@ file_poke(Uxn *u, Uint16 ptr, Uint8 b0, Uint8 b1)
{
Uint8 *m = u->ram.dat;
char *name = (char *)&m[(m[ptr + 8] << 8) + m[ptr + 8 + 1]];
- Uint16 length = (m[ptr + 8 + 2] << 8) + m[ptr + 8 + 3];
- Uint16 offset = (m[ptr + 2] << 8) + m[ptr + 3];
+ Uint16 length = mempeek16(u, ptr + 8 + 2);
+ Uint16 offset = mempeek16(u, ptr + 2);
if(b0 == 0x0d) {
Uint16 addr = (m[ptr + 8 + 4] << 8) + b1;
FILE *f = fopen(name, "r");
if(f && fseek(f, offset, SEEK_SET) != -1 && fread(&m[addr], length, 1, f)) {
fclose(f);
printf("Loaded %d bytes, at %04x from %s\n", length, addr, name);
- evaluxn(u, devfile->vector);
+ evaluxn(u, mempeek16(u, devfile->addr));
}
} else if(b0 == 0x0f) {
Uint16 addr = (m[ptr + 8 + 6] << 8) + b1;
@@ -234,7 +234,7 @@ file_poke(Uxn *u, Uint16 ptr, Uint8 b0, Uint8 b1)
if(f && fseek(f, offset, SEEK_SET) != -1 && fwrite(&m[addr], length, 1, f)) {
fclose(f);
printf("Saved %d bytes, at %04x from %s\n", length, addr, name);
- evaluxn(u, devfile->vector);
+ evaluxn(u, mempeek16(u, devfile->addr));
}
}
return b1;
@@ -293,9 +293,8 @@ datetime_poke(Uxn *u, Uint16 ptr, Uint8 b0, Uint8 b1)
Uint8
system_poke(Uxn *u, Uint16 ptr, Uint8 b0, Uint8 b1)
{
- Uint8 *m = u->ram.dat;
- m[PAGE_DEVICE + b0] = b1;
- getcolors(&ppu, &m[PAGE_DEVICE + 0x0008]);
+ u->ram.dat[ptr + b0] = b1;
+ getcolors(&ppu, &u->ram.dat[ptr + 0x0008]);
reqdraw = 1;
(void)ptr;
return b1;
@@ -315,7 +314,7 @@ ppnil(Uxn *u, Uint16 ptr, Uint8 b0, Uint8 b1)
int
start(Uxn *u)
{
- inituxn(u, 0x0200);
+ evaluxn(u, 0x0200);
redraw(ppu.output, u);
while(1) {
SDL_Event event;
@@ -333,14 +332,14 @@ start(Uxn *u)
case SDL_KEYDOWN:
case SDL_KEYUP:
doctrl(u, &event, event.type == SDL_KEYDOWN);
- evaluxn(u, devctrl->vector);
+ evaluxn(u, mempeek16(u, devctrl->addr));
u->ram.dat[devctrl->addr + 3] = 0;
break;
case SDL_MOUSEBUTTONUP:
case SDL_MOUSEBUTTONDOWN:
case SDL_MOUSEMOTION:
domouse(u, &event);
- evaluxn(u, devmouse->vector);
+ evaluxn(u, mempeek16(u, devmouse->addr));
break;
case SDL_WINDOWEVENT:
if(event.window.event == SDL_WINDOWEVENT_EXPOSED)
@@ -348,7 +347,7 @@ start(Uxn *u)
break;
}
}
- evaluxn(u, devscreen->vector);
+ evaluxn(u, mempeek16(u, devscreen->addr));
SDL_UnlockAudioDevice(audio_id);
if(reqdraw)
redraw(ppu.output, u);
diff --git a/src/uxn.c b/src/uxn.c
@@ -152,17 +152,6 @@ evaluxn(Uxn *u, Uint16 vec)
}
int
-inituxn(Uxn *u, Uint16 vec)
-{
- Uint8 i = 0;
- if(!evaluxn(u, vec))
- return 0;
- for(i = 0; i < 0x10; ++i)
- u->dev[i].vector = mempeek16(u, u->dev[i].addr);
- return 1;
-}
-
-int
bootuxn(Uxn *u)
{
size_t i;
diff --git a/src/uxn.h b/src/uxn.h
@@ -32,7 +32,7 @@ typedef struct {
struct Uxn;
typedef struct Device {
- Uint16 addr, vector;
+ Uint16 addr;
Uint8 (*poke)(struct Uxn *, Uint16, Uint8, Uint8);
} Device;
@@ -44,7 +44,6 @@ typedef struct Uxn {
int loaduxn(Uxn *c, char *filepath);
int bootuxn(Uxn *c);
-int inituxn(Uxn *u, Uint16 vec);
int evaluxn(Uxn *u, Uint16 vec);
void mempoke16(Uxn *u, Uint16 a, Uint16 b);
Uint16 mempeek16(Uxn *u, Uint16 a);