| ... | ... |
@@ -42,24 +42,21 @@ |
| 42 | 42 |
|
| 43 | 43 |
( devices ) |
| 44 | 44 |
|
| 45 |
-|0100 ;Console { pad 8 char 1 byte 1 short 2 }
|
|
| 46 |
-|0110 ;Screen { width 2 height 2 pad 4 x 2 y 2 color 1 }
|
|
| 47 |
-|0120 ;Sprite { pad 8 x 2 y 2 addr 2 color 1 }
|
|
| 48 |
-|0130 ;Controller { buttons 1 }
|
|
| 49 |
-|0140 ;Keys { key 1 }
|
|
| 50 |
-|0150 ;Mouse { x 2 y 2 state 1 chord 1 }
|
|
| 51 |
-|0160 ;File { pad 8 name 2 length 2 load 2 save 2 }
|
|
| 52 |
-|01F0 ;System { pad 8 r 2 g 2 b 2 }
|
|
| 53 |
- |
|
| 54 |
-|0200 ^RESET JMP |
|
| 55 |
-|0204 ,ERROR JMP2 |
|
| 56 |
-|0208 ,FRAME JMP2 |
|
| 45 |
+|0100 ;System { vector 2 pad 6 r 2 g 2 b 2 }
|
|
| 46 |
+|0110 ;Console { pad 8 char 1 byte 1 short 2 }
|
|
| 47 |
+|0120 ;Screen { vector 2 width 2 height 2 pad 2 x 2 y 2 color 1 }
|
|
| 48 |
+|0130 ;Sprite { pad 8 x 2 y 2 addr 2 color 1 }
|
|
| 49 |
+|0140 ;Controller { buttons 1 }
|
|
| 50 |
+|0150 ;Keys { key 1 }
|
|
| 51 |
+|0160 ;Mouse { x 2 y 2 state 1 chord 1 }
|
|
| 52 |
+|0170 ;File { pad 8 name 2 length 2 load 2 save 2 }
|
|
| 57 | 53 |
|
| 58 | 54 |
( program ) |
| 59 | 55 |
|
| 60 |
-@RESET |
|
| 56 |
+|0200 @RESET |
|
| 61 | 57 |
|
| 62 | 58 |
( theme ) #e0fa =System.r #30fa =System.g #30fa =System.b |
| 59 |
+ ( vectors ) ,FRAME =Screen.vector |
|
| 63 | 60 |
|
| 64 | 61 |
( load file ) |
| 65 | 62 |
,filepath ,load-file JSR2 |
| ... | ... |
@@ -31,24 +31,23 @@ |
| 31 | 31 |
|
| 32 | 32 |
( devices ) |
| 33 | 33 |
|
| 34 |
-|0110 ;Screen { width 2 height 2 pad 4 x 2 y 2 color 1 }
|
|
| 35 |
-|0120 ;Sprite { pad 8 x 2 y 2 addr 2 color 1 }
|
|
| 36 |
-|0130 ;Controller { buttons 1 }
|
|
| 37 |
-|0140 ;Keys { key 1 }
|
|
| 38 |
-|0150 ;Mouse { x 2 y 2 state 1 chord 1 change 1 }
|
|
| 39 |
-|0160 ;File { pad 8 name 2 length 2 load 2 save 2 }
|
|
| 40 |
-|01F0 ;System { pad 8 r 2 g 2 b 2 }
|
|
| 41 |
- |
|
| 42 |
-|0200 ^RESET JMP |
|
| 43 |
-|0204 ,ERROR JMP2 |
|
| 44 |
-|0208 ,FRAME JMP2 |
|
| 34 |
+|0100 ;System { vector 2 pad 6 r 2 g 2 b 2 }
|
|
| 35 |
+|0110 ;Console { pad 8 char 1 byte 1 short 2 }
|
|
| 36 |
+|0120 ;Screen { vector 2 width 2 height 2 pad 2 x 2 y 2 color 1 }
|
|
| 37 |
+|0130 ;Sprite { pad 8 x 2 y 2 addr 2 color 1 }
|
|
| 38 |
+|0140 ;Controller { buttons 1 }
|
|
| 39 |
+|0150 ;Keys { key 1 }
|
|
| 40 |
+|0160 ;Mouse { x 2 y 2 state 1 chord 1 change 1 }
|
|
| 41 |
+|0170 ;File { pad 8 name 2 length 2 load 2 save 2 }
|
|
| 45 | 42 |
|
| 46 | 43 |
( program ) |
| 47 | 44 |
|
| 48 |
-@RESET |
|
| 45 |
+|0200 @RESET |
|
| 49 | 46 |
|
| 50 | 47 |
( theme ) #e0fc =System.r #30cc =System.g #30ac =System.b |
| 51 | 48 |
|
| 49 |
+ ,FRAME =Screen.vector |
|
| 50 |
+ |
|
| 52 | 51 |
~Screen.width 2/ #008a SUB2 =bankview.x |
| 53 | 52 |
~Screen.height 2/ #003f SUB2 =bankview.y |
| 54 | 53 |
,bank =bankview.addr |
| ... | ... |
@@ -11,18 +11,18 @@ |
| 11 | 11 |
;neralie { n0123 2 n4 1 n5 1 n6 1 n7 1 n8 1 n9 1 color 1 x 2 y 2 w 2 h 2 }
|
| 12 | 12 |
;mul { ahi 1 alo 1 bhi 1 blo 1 }
|
| 13 | 13 |
|
| 14 |
-|0100 ;Console { pad 8 char 1 byte 1 short 2 }
|
|
| 15 |
-|0110 ;Screen { width 2 height 2 pad 4 x 2 y 2 color 1 }
|
|
| 16 |
-|0120 ;Sprite { pad 8 x 2 y 2 addr 2 color 1 }
|
|
| 17 |
-|0190 ;DateTime { year 2 month 1 day 1 hour 1 minute 1 second 1 dow 1 doy 2 isdst 1 pad 4 get 1 }
|
|
| 18 |
-|01F0 ;System { pad 8 r 2 g 2 b 2 }
|
|
| 14 |
+|0100 ;System { vector 2 pad 6 r 2 g 2 b 2 }
|
|
| 15 |
+|0110 ;Console { pad 8 char 1 byte 1 short 2 }
|
|
| 16 |
+|0120 ;Screen { vector 2 width 2 height 2 pad 2 x 2 y 2 color 1 }
|
|
| 17 |
+|0130 ;Sprite { pad 8 x 2 y 2 addr 2 color 1 }
|
|
| 18 |
+|01a0 ;DateTime { year 2 month 1 day 1 hour 1 minute 1 second 1 dow 1 doy 2 isdst 1 pad 4 get 1 }
|
|
| 19 | 19 |
|
| 20 |
-|0200 ^RESET JMP |
|
| 21 |
-|0204 ,ERROR JMP2 |
|
| 22 |
-|0208 ,FRAME JMP2 |
|
| 20 |
+( program ) |
|
| 21 |
+ |
|
| 22 |
+|0200 @RESET |
|
| 23 | 23 |
|
| 24 |
-@RESET |
|
| 25 | 24 |
( theme ) #03fd =System.r #0ef3 =System.g #0bf2 =System.b |
| 25 |
+ ( vectors ) ,FRAME =Screen.vector |
|
| 26 | 26 |
#01 =fps.current |
| 27 | 27 |
|
| 28 | 28 |
#000c |
| ... | ... |
@@ -51,25 +51,23 @@ |
| 51 | 51 |
|
| 52 | 52 |
( devices ) |
| 53 | 53 |
|
| 54 |
-|0100 ;Console { pad 8 char 1 byte 1 short 2 string 2 }
|
|
| 55 |
-|0110 ;Screen { width 2 height 2 pad 4 x 2 y 2 color 1 }
|
|
| 56 |
-|0120 ;Sprite { pad 8 x 2 y 2 addr 2 color 1 }
|
|
| 57 |
-|0130 ;Controller { p1 1 }
|
|
| 58 |
-|0140 ;Keys { key 1 }
|
|
| 59 |
-|0150 ;Mouse { x 2 y 2 state 1 chord 1 }
|
|
| 60 |
-|0160 ;File { pad 8 name 2 length 2 load 2 save 2 }
|
|
| 61 |
-|01F0 ;System { pad 8 r 2 g 2 b 2 }
|
|
| 62 |
-|0200 ^RESET JMP |
|
| 63 |
-|0204 ,ERROR JMP2 |
|
| 64 |
-|0208 ,FRAME JMP2 |
|
| 54 |
+|0100 ;System { vector 2 pad 6 r 2 g 2 b 2 }
|
|
| 55 |
+|0110 ;Console { pad 8 char 1 byte 1 short 2 }
|
|
| 56 |
+|0120 ;Screen { vector 2 width 2 height 2 pad 2 x 2 y 2 color 1 }
|
|
| 57 |
+|0130 ;Sprite { pad 8 x 2 y 2 addr 2 color 1 }
|
|
| 58 |
+|0140 ;Controller { p1 1 }
|
|
| 59 |
+|0150 ;Keys { key 1 }
|
|
| 60 |
+|0160 ;Mouse { x 2 y 2 state 1 chord 1 }
|
|
| 61 |
+|0170 ;File { pad 8 name 2 length 2 load 2 save 2 }
|
|
| 65 | 62 |
|
| 66 | 63 |
( program ) |
| 67 | 64 |
|
| 68 |
-@RESET ( -- ) |
|
| 65 |
+|0200 @RESET |
|
| 69 | 66 |
|
| 70 | 67 |
( theme ) |
| 71 | 68 |
#e0fa =theme.r0 #30fa =theme.g0 #30fa =theme.b0 ( normal mode ) |
| 72 | 69 |
#00fe =theme.r1 #00f3 =theme.g1 #00f3 =theme.b1 ( presentation mode ) |
| 70 |
+ ( vectors ) ,FRAME =Screen.vector |
|
| 73 | 71 |
|
| 74 | 72 |
~theme.r0 =System.r ~theme.g0 =System.g ~theme.b0 =System.b |
| 75 | 73 |
|
| ... | ... |
@@ -80,7 +80,7 @@ static SDL_Renderer *gRenderer; |
| 80 | 80 |
static SDL_Texture *gTexture; |
| 81 | 81 |
static SDL_AudioDeviceID audio_id; |
| 82 | 82 |
static Screen screen; |
| 83 |
-static Device *devscreen, *devmouse, *devkey, *devctrl, *devaudio; |
|
| 83 |
+static Device *devsystem, *devscreen, *devmouse, *devkey, *devctrl, *devaudio; |
|
| 84 | 84 |
|
| 85 | 85 |
#pragma mark - Helpers |
| 86 | 86 |
|
| ... | ... |
@@ -582,7 +582,7 @@ ppnil(Uxn *u, Uint16 ptr, Uint8 b0, Uint8 b1) |
| 582 | 582 |
int |
| 583 | 583 |
start(Uxn *u) |
| 584 | 584 |
{
|
| 585 |
- evaluxn(u, PAGE_VECTORS); |
|
| 585 |
+ inituxn(u, 0x0200); |
|
| 586 | 586 |
redraw(pixels, u); |
| 587 | 587 |
while(1) {
|
| 588 | 588 |
SDL_Event event; |
| ... | ... |
@@ -602,12 +602,13 @@ start(Uxn *u) |
| 602 | 602 |
break; |
| 603 | 603 |
} |
| 604 | 604 |
} |
| 605 |
- evaluxn(u, PAGE_VECTORS + 0x08); |
|
| 605 |
+ evaluxn(u, devscreen->vector); |
|
| 606 | 606 |
if(screen.reqdraw) |
| 607 | 607 |
redraw(pixels, u); |
| 608 | 608 |
elapsed = (SDL_GetPerformanceCounter() - start) / (double)SDL_GetPerformanceFrequency() * 1000.0f; |
| 609 | 609 |
SDL_Delay(clamp(16.666f - elapsed, 0, 1000)); |
| 610 | 610 |
} |
| 611 |
+ return 1; |
|
| 611 | 612 |
} |
| 612 | 613 |
|
| 613 | 614 |
int |
| ... | ... |
@@ -624,28 +625,28 @@ main(int argc, char **argv) |
| 624 | 625 |
if(!init()) |
| 625 | 626 |
return error("Init", "Failed");
|
| 626 | 627 |
|
| 627 |
- portuxn(&u, 0x00, "console", console_poke); |
|
| 628 |
- devscreen = portuxn(&u, 0x01, "screen", screen_poke); |
|
| 629 |
- portuxn(&u, 0x02, "sprite", sprite_poke); |
|
| 630 |
- devctrl = portuxn(&u, 0x03, "controller", ppnil); |
|
| 631 |
- devkey = portuxn(&u, 0x04, "key", ppnil); |
|
| 632 |
- devmouse = portuxn(&u, 0x05, "mouse", ppnil); |
|
| 633 |
- portuxn(&u, 0x06, "file", file_poke); |
|
| 634 |
- devaudio = portuxn(&u, 0x07, "audio", audio_poke); |
|
| 635 |
- portuxn(&u, 0x08, "midi", ppnil); |
|
| 636 |
- portuxn(&u, 0x09, "datetime", datetime_poke); |
|
| 637 |
- portuxn(&u, 0x0a, "---", ppnil); |
|
| 628 |
+ devsystem = portuxn(&u, 0x00, "system", system_poke); |
|
| 629 |
+ portuxn(&u, 0x01, "console", console_poke); |
|
| 630 |
+ devscreen = portuxn(&u, 0x02, "screen", screen_poke); |
|
| 631 |
+ portuxn(&u, 0x03, "sprite", sprite_poke); |
|
| 632 |
+ devctrl = portuxn(&u, 0x04, "controller", ppnil); |
|
| 633 |
+ devkey = portuxn(&u, 0x05, "key", ppnil); |
|
| 634 |
+ devmouse = portuxn(&u, 0x06, "mouse", ppnil); |
|
| 635 |
+ portuxn(&u, 0x07, "file", file_poke); |
|
| 636 |
+ devaudio = portuxn(&u, 0x08, "audio", audio_poke); |
|
| 637 |
+ portuxn(&u, 0x09, "midi", ppnil); |
|
| 638 |
+ portuxn(&u, 0x0a, "datetime", datetime_poke); |
|
| 638 | 639 |
portuxn(&u, 0x0b, "---", ppnil); |
| 639 | 640 |
portuxn(&u, 0x0c, "---", ppnil); |
| 640 | 641 |
portuxn(&u, 0x0d, "---", ppnil); |
| 641 | 642 |
portuxn(&u, 0x0e, "---", ppnil); |
| 642 |
- portuxn(&u, 0x0f, "system", system_poke); |
|
| 643 |
+ portuxn(&u, 0x0f, "---", ppnil); |
|
| 643 | 644 |
|
| 644 | 645 |
/* Write screen size to dev/screen */ |
| 645 |
- u.ram.dat[devscreen->addr + 0] = (HOR * 8 >> 8) & 0xff; |
|
| 646 |
- u.ram.dat[devscreen->addr + 1] = HOR * 8 & 0xff; |
|
| 647 |
- u.ram.dat[devscreen->addr + 2] = (VER * 8 >> 8) & 0xff; |
|
| 648 |
- u.ram.dat[devscreen->addr + 3] = VER * 8 & 0xff; |
|
| 646 |
+ u.ram.dat[devscreen->addr + 2] = (HOR * 8 >> 8) & 0xff; |
|
| 647 |
+ u.ram.dat[devscreen->addr + 3] = HOR * 8 & 0xff; |
|
| 648 |
+ u.ram.dat[devscreen->addr + 4] = (VER * 8 >> 8) & 0xff; |
|
| 649 |
+ u.ram.dat[devscreen->addr + 5] = VER * 8 & 0xff; |
|
| 649 | 650 |
|
| 650 | 651 |
start(&u); |
| 651 | 652 |
quit(); |
| ... | ... |
@@ -151,6 +151,17 @@ evaluxn(Uxn *u, Uint16 vec) |
| 151 | 151 |
return 1; |
| 152 | 152 |
} |
| 153 | 153 |
|
| 154 |
+int |
|
| 155 |
+inituxn(Uxn *u, Uint16 vec) |
|
| 156 |
+{
|
|
| 157 |
+ Uint8 i = 0; |
|
| 158 |
+ if(!evaluxn(u, vec)) |
|
| 159 |
+ return 0; |
|
| 160 |
+ for(i = 0; i < 0x10; ++i) |
|
| 161 |
+ u->dev[i].vector = mempeek16(u, u->dev[i].addr); |
|
| 162 |
+ return 1; |
|
| 163 |
+} |
|
| 164 |
+ |
|
| 154 | 165 |
int |
| 155 | 166 |
bootuxn(Uxn *u) |
| 156 | 167 |
{
|
| ... | ... |
@@ -178,6 +189,6 @@ portuxn(Uxn *u, Uint8 id, char *name, Uint8 (*pofn)(Uxn *u, Uint16 ptr, Uint8 b0 |
| 178 | 189 |
Device *d = &u->dev[id]; |
| 179 | 190 |
d->addr = PAGE_DEVICE + id * 0x10; |
| 180 | 191 |
d->poke = pofn; |
| 181 |
- printf("Device #%d: %s, at 0x%04x \n", id, name, d->addr);
|
|
| 192 |
+ printf("Device added #%d: %s, at 0x%04x \n", id, name, d->addr);
|
|
| 182 | 193 |
return d; |
| 183 | 194 |
} |
| ... | ... |
@@ -32,7 +32,7 @@ typedef struct {
|
| 32 | 32 |
struct Uxn; |
| 33 | 33 |
|
| 34 | 34 |
typedef struct Device {
|
| 35 |
- Uint16 addr; |
|
| 35 |
+ Uint16 addr, vector; |
|
| 36 | 36 |
Uint8 (*poke)(struct Uxn *, Uint16, Uint8, Uint8); |
| 37 | 37 |
} Device; |
| 38 | 38 |
|
| ... | ... |
@@ -44,5 +44,6 @@ typedef struct Uxn {
|
| 44 | 44 |
|
| 45 | 45 |
int loaduxn(Uxn *c, char *filepath); |
| 46 | 46 |
int bootuxn(Uxn *c); |
| 47 |
+int inituxn(Uxn *u, Uint16 vec); |
|
| 47 | 48 |
int evaluxn(Uxn *u, Uint16 vec); |
| 48 | 49 |
Device *portuxn(Uxn *u, Uint8 id, char *name, Uint8 (*pofn)(Uxn *, Uint16, Uint8, Uint8)); |