Ported keys example to new vectors

This commit is contained in:
neauoire 2021-04-05 13:00:55 -07:00
parent 4c370d96d1
commit 3f98a2a832
13 changed files with 85 additions and 95 deletions

View File

@ -28,7 +28,7 @@ else
fi fi
echo "Assembling.." echo "Assembling.."
./bin/assembler projects/examples/dev.controller.usm bin/boot.rom ./bin/assembler projects/examples/dev.keys.usm bin/boot.rom
echo "Running.." echo "Running.."
if [ "${2}" = '--cli' ]; if [ "${2}" = '--cli' ];

View File

@ -82,10 +82,6 @@ BRK
BRK BRK
@ERROR
BRK
@touch-trk ( -- ) @touch-trk ( -- )
,clear-notes JSR2 ,clear-notes JSR2

View File

@ -30,6 +30,3 @@ RTN
@text1 [ Welcome 20 to 20 UxnVM 0a00 ] @text1 [ Welcome 20 to 20 UxnVM 0a00 ]
@text2 [ Hello 20 World 0a00 ] @text2 [ Hello 20 World 0a00 ]
@FRAME BRK
@ERROR BRK

View File

@ -13,9 +13,9 @@
|0100 ;System { vector 2 pad 6 r 2 g 2 b 2 } |0100 ;System { vector 2 pad 6 r 2 g 2 b 2 }
|0110 ;Console { pad 8 char 1 byte 1 short 2 } |0110 ;Console { pad 8 char 1 byte 1 short 2 }
|0120 ;Screen { vector 2 width 2 height 2 pad 2 x 2 y 2 color 1 } |0120 ;Screen { vector 2 width 2 height 2 pad 2 x 2 y 2 color 1 }
|0130 ;Sprite { pad 8 x 2 y 2 addr 2 color 1 } |0130 ;Sprite { vector 2 pad 6 x 2 y 2 addr 2 color 1 }
|0140 ;Controller { p1 1 } |0140 ;Controller { vector 2 p1 1 }
|0150 ;Keys { key 1 } |0150 ;Keys { vector 2 key 1 }
|0160 ;Mouse { x 2 y 2 state 1 chord 1 change 1 } |0160 ;Mouse { x 2 y 2 state 1 chord 1 change 1 }
|0170 ;File { pad 8 name 2 length 2 load 2 save 2 } |0170 ;File { pad 8 name 2 length 2 load 2 save 2 }
|0180 ;Audio { ch1adsr 2 ch2adsr 2 ch3adsr 2 ch4adsr 2 ch1vol 1 ch1pitch 1 ch2vol 1 ch2pitch 1 ch3vol 1 ch3pitch 1 ch4vol 1 ch4pitch 1 } |0180 ;Audio { ch1adsr 2 ch2adsr 2 ch3adsr 2 ch4adsr 2 ch1vol 1 ch1pitch 1 ch2vol 1 ch2pitch 1 ch3vol 1 ch3pitch 1 ch4vol 1 ch4pitch 1 }
@ -36,12 +36,6 @@ BRK
@FRAME @FRAME
~Controller.p1 ,on-ctrl-arrows JNZ2
BRK
@on-ctrl-arrows
#0a =slime #0a =slime
,default_icn =Sprite.addr ,default_icn =Sprite.addr
@ -81,5 +75,3 @@ BRK
@left_icn [ 3c7e ef1f 1fef 7e3c ] @left_icn [ 3c7e ef1f 1fef 7e3c ]
@right_icn [ 3c7e f7f8 f8f7 7e3c ] @right_icn [ 3c7e f7f8 f8f7 7e3c ]
@slime_icn [ 0000 183c 3c18 0000 ] @slime_icn [ 0000 183c 3c18 0000 ]
@ERROR BRK

View File

@ -1,56 +1,60 @@
( Dev/Keys ) ( Dev/Keys )
%RTN { JMP2r }
%8+ { #0008 ADD2 } %8+ { #0008 ADD2 }
%8* { #0030 SFT2 } %8* { #0030 SFT2 }
%MOD2 { #03 AND } %MOD2 { #03 AND }
;cursor { x 2 y 2 blink 1 } ;cursor { x 2 y 2 }
|0100 ;Console { pad 8 char 1 byte 1 short 2 } |0100 ;System { vector 2 pad 6 r 2 g 2 b 2 }
|0110 ;Screen { width 2 height 2 pad 4 y 2 x 2 color 1 } |0110 ;Console { pad 8 char 1 byte 1 short 2 }
|0120 ;Sprite { pad 8 x 2 y 2 addr 2 color 1 } |0120 ;Screen { vector 2 width 2 height 2 pad 2 x 2 y 2 color 1 }
|0130 ;Controller { buttons 1 } |0130 ;Sprite { vector 2 pad 6 x 2 y 2 addr 2 color 1 }
|0140 ;Keys { key 1 } |0140 ;Controller { vector 2 button 1 }
|01F0 ;System { pad 8 r 2 g 2 b 2 } |0150 ;Keys { vector 2 key 1 }
|0200 ^RESET JMP
|0204 ,ERROR JMP2
|0208 ,FRAME JMP2
@RESET ( program )
( theme ) #127f =System.r #34e7 =System.g #56c4 =System.b |0200 @RESET
( theme ) #0f73 =System.r #0fe3 =System.g #0fc3 =System.b
( vectors ) ,KEY =Keys.vector
( vectors ) ,BUTTON =Controller.vector
,draw-cursor JSR2
BRK BRK
@FRAME @KEY
( theme ) #0daf =System.r #02ff =System.g #035f =System.b
( update cursor )
#02 =Sprite.color
,cursor_icn =Sprite.addr ,cursor_icn =Sprite.addr
~cursor.blink MOD2 #00 EQU =cursor.blink ,font #00 ~Keys.key 8* ADD2 =Sprite.addr
( draw ) #01 =Sprite.color
~Sprite.x 8+ =Sprite.x
( release ) #00 =Keys.key
,draw-cursor JSR2
~Keys #00 EQU ^$end JNZ BRK
@BUTTON
( enter key ) ( enter key )
~Keys #0d NEQ ^$no-return JNZ ~Controller.button #08 NEQ ^$no-return JNZ
#00 =Sprite.color
#0000 =Sprite.x #0000 =Sprite.x
( incr ) ~Sprite.y 8+ =Sprite.y ( incr ) ~Sprite.y 8+ =Sprite.y
( release ) #00 =Keys ( release ) #00 =Controller.button
BRK ,draw-cursor JSR2
$no-return $no-return
,font #00 ~Keys 8* ADD2 =Sprite.addr
( draw ) #01 =Sprite.color
( incr ) ~Sprite.x 8+ =Sprite.x
( release ) #00 =Keys
$end
BRK BRK
@draw-cursor
,cursor_icn =Sprite.addr #02 =Sprite.color
RTN
@cursor_icn [ ffff ffff ffff ffff ] @cursor_icn [ ffff ffff ffff ffff ]
@font ( spectrum-zx font ) @font ( spectrum-zx font )
@ -89,6 +93,4 @@ BRK
0008 0808 0808 0800 0030 1008 0810 3000 0000 0032 4c00 0000 3c42 99a1 a199 423c 0008 0808 0808 0800 0030 1008 0810 3000 0000 0032 4c00 0000 3c42 99a1 a199 423c
] ]
@ERROR BRK
;text { body 2 } ;text { body 2 }

View File

@ -16,13 +16,13 @@
|0150 ;Mouse { x 2 y 2 state 1 chord 1 } |0150 ;Mouse { x 2 y 2 state 1 chord 1 }
|0170 ;Audio { ch1adsr 2 ch2adsr 2 ch3adsr 2 ch4adsr 2 ch1vol 1 ch1pitch 1 ch2vol 1 ch2pitch 1 ch3vol 1 ch3pitch 1 ch4vol 1 ch4pitch 1 } |0170 ;Audio { ch1adsr 2 ch2adsr 2 ch3adsr 2 ch4adsr 2 ch1vol 1 ch1pitch 1 ch2vol 1 ch2pitch 1 ch3vol 1 ch3pitch 1 ch4vol 1 ch4pitch 1 }
|01F0 ;System { pad 8 r 2 g 2 b 2 } |01F0 ;System { pad 8 r 2 g 2 b 2 }
|0200 ^RESET JMP
|0204 ,ERROR JMP2
|0208 ,FRAME JMP2
@RESET ( program )
|0200 @RESET
( theme ) #03fd =System.r #0ef3 =System.g #0bf2 =System.b ( theme ) #03fd =System.r #0ef3 =System.g #0bf2 =System.b
( vectors ) ,FRAME =Screen.vector
#004f =Audio.ch1adsr #33 =Audio.ch1vol #004f =Audio.ch1adsr #33 =Audio.ch1vol

View File

@ -26,13 +26,13 @@
|0120 ;Sprite { pad 8 x 2 y 2 addr 2 color 1 } |0120 ;Sprite { pad 8 x 2 y 2 addr 2 color 1 }
|0150 ;Mouse { x 2 y 2 state 1 chord 1 } |0150 ;Mouse { x 2 y 2 state 1 chord 1 }
|01F0 ;System { pad 8 r 2 g 2 b 2 } |01F0 ;System { pad 8 r 2 g 2 b 2 }
|0200 ^RESET JMP
|0204 ,ERROR JMP2
|0208 ,FRAME JMP2
@RESET ( program )
|0200 @RESET
( theme ) #127f =System.r #34e7 =System.g #56c4 =System.b ( theme ) #127f =System.r #34e7 =System.g #56c4 =System.b
( vectors ) ,FRAME =Screen.vector
#00a0 =window.w #00a0 =window.w
#0050 =window.h #0050 =window.h

View File

@ -21,17 +21,12 @@
|0190 ;Time { year 2 month 1 day 1 hour 1 minute 1 second 1 dow 1 doy 2 isdst 1 get 1 } |0190 ;Time { year 2 month 1 day 1 hour 1 minute 1 second 1 dow 1 doy 2 isdst 1 get 1 }
|01F0 ;System { pad 8 r 2 g 2 b 2 } |01F0 ;System { pad 8 r 2 g 2 b 2 }
( vectors )
|0200 ^RESET JMP
|0204 ,ERROR JMP2
|0208 ,FRAME JMP2
( program ) ( program )
@RESET |0200 @RESET
( theme ) #0ff8 =System.r #0f08 =System.g #0f08 =System.b ( theme ) #0ff8 =System.r #0f08 =System.g #0f08 =System.b
( vectors ) ,FRAME =Screen.vector
#1000 =Audio.ch1adsr #1000 =Audio.ch1adsr
#66 =Audio.ch1vol #66 =Audio.ch1vol

View File

@ -14,13 +14,13 @@
|0120 ;Sprite { pad 8 x 2 y 2 addr 2 color 1 } |0120 ;Sprite { pad 8 x 2 y 2 addr 2 color 1 }
|0150 ;Mouse { x 2 y 2 state 1 chord 1 } |0150 ;Mouse { x 2 y 2 state 1 chord 1 }
|01F0 ;System { pad 8 r 2 g 2 b 2 } |01F0 ;System { pad 8 r 2 g 2 b 2 }
|0200 ^RESET JMP
|0204 ,ERROR JMP2
|0208 ,FRAME JMP2
@RESET ( program )
|0200 @RESET
( theme ) #0f0f =System.r #0fff =System.g #0ff0 =System.b ( theme ) #0f0f =System.r #0fff =System.g #0ff0 =System.b
( vectors ) ,FRAME =Screen.vector
#0020 #0030 #0060 #0060 =r1.y2 =r1.x2 =r1.y1 =r1.x1 #0020 #0030 #0060 #0060 =r1.y2 =r1.x2 =r1.y1 =r1.x1
#0058 #0050 #0090 #0080 =r2.y2 =r2.x2 =r2.y1 =r2.x1 #0058 #0050 #0090 #0080 =r2.y2 =r2.x2 =r2.y1 =r2.x1

View File

@ -10,13 +10,13 @@
|0110 ;Screen { width 2 height 2 pad 4 x 2 y 2 color 1 } |0110 ;Screen { width 2 height 2 pad 4 x 2 y 2 color 1 }
|0120 ;Sprite { pad 8 x 2 y 2 addr 2 color 1 } |0120 ;Sprite { pad 8 x 2 y 2 addr 2 color 1 }
|01F0 ;System { pad 8 r 2 g 2 b 2 } |01F0 ;System { pad 8 r 2 g 2 b 2 }
|0200 ^RESET JMP
|0204 ,ERROR JMP2
|0208 ,FRAME JMP2
@RESET ( program )
|0200 @RESET
( theme ) #0f0f =System.r #0fff =System.g #0ff0 =System.b ( theme ) #0f0f =System.r #0fff =System.g #0ff0 =System.b
( vectors ) ,FRAME =Screen.vector
( find screen center ) ( find screen center )
~Screen.width #0002 DIV2 =center.x ~Screen.width #0002 DIV2 =center.x

View File

@ -6,13 +6,13 @@
|0120 ;Sprite { pad 8 x 2 y 2 addr 2 color 1 } |0120 ;Sprite { pad 8 x 2 y 2 addr 2 color 1 }
|01F0 ;System { pad 8 r 2 g 2 b 2 } |01F0 ;System { pad 8 r 2 g 2 b 2 }
|0200 ^RESET JMP
|0204 ,ERROR JMP2
|0208 ,FRAME JMP2
@RESET ( program )
|0200 @RESET
( theme ) #0ffc =System.r #0f0b =System.g #0f03 =System.b ( theme ) #0ffc =System.r #0f0b =System.g #0f03 =System.b
( vectors ) ,FRAME =Screen.vector
#0000 #0000 #0100 #0100 #01 ,pict_large ,draw-picture JSR2 #0000 #0000 #0100 #0100 #01 ,pict_large ,draw-picture JSR2
#0098 #0060 #0080 #0080 #01 ,pict_medium ,draw-picture JSR2 #0098 #0060 #0080 #0080 #01 ,pict_medium ,draw-picture JSR2

View File

@ -16,11 +16,10 @@
|0110 ;Screen { width 2 height 2 pad 4 x 2 y 2 color 1 } |0110 ;Screen { width 2 height 2 pad 4 x 2 y 2 color 1 }
|0120 ;Sprite { pad 8 x 2 y 2 addr 2 color 1 } |0120 ;Sprite { pad 8 x 2 y 2 addr 2 color 1 }
|01F0 ;System { pad 8 r 2 g 2 b 2 } |01F0 ;System { pad 8 r 2 g 2 b 2 }
|0200 ^RESET JMP
|0204 ,ERROR JMP2
|0208 ,FRAME JMP2
@RESET ( program )
|0200 @RESET
( theme ) #13fd =System.r #1ef3 =System.g #1bf2 =System.b ( theme ) #13fd =System.r #1ef3 =System.g #1bf2 =System.b
@ -160,6 +159,3 @@ RTN
8f83 8383 8383 83ff fff7 fdff c0e2 f1ff 8f83 8383 8383 83ff fff7 fdff c0e2 f1ff
7fef bfff 07af 5fff ffff ffff ffff ffff 7fef bfff 07af 5fff ffff ffff ffff ffff
] ]
@FRAME BRK
@ERROR BRK

View File

@ -351,7 +351,7 @@ void
domouse(Uxn *u, SDL_Event *event) domouse(Uxn *u, SDL_Event *event)
{ {
Uint8 flag = 0x00; Uint8 flag = 0x00;
Uint16 addr = devmouse->addr; Uint16 addr = devmouse->addr + 2;
Uint16 x = clamp(event->motion.x / ZOOM - PAD * 8, 0, HOR * 8 - 1); Uint16 x = clamp(event->motion.x / ZOOM - PAD * 8, 0, HOR * 8 - 1);
Uint16 y = clamp(event->motion.y / ZOOM - PAD * 8, 0, VER * 8 - 1); Uint16 y = clamp(event->motion.y / ZOOM - PAD * 8, 0, VER * 8 - 1);
u->ram.dat[addr + 0] = (x >> 8) & 0xff; u->ram.dat[addr + 0] = (x >> 8) & 0xff;
@ -381,7 +381,7 @@ void
dotext(Uxn *u, SDL_Event *event) dotext(Uxn *u, SDL_Event *event)
{ {
int i; int i;
Uint16 addr = devkey->addr; Uint16 addr = devkey->addr + 2;
if(SDL_GetModState() & KMOD_LCTRL || SDL_GetModState() & KMOD_RCTRL) if(SDL_GetModState() & KMOD_LCTRL || SDL_GetModState() & KMOD_RCTRL)
return; return;
for(i = 0; i < SDL_TEXTINPUTEVENT_TEXT_SIZE; ++i) { for(i = 0; i < SDL_TEXTINPUTEVENT_TEXT_SIZE; ++i) {
@ -396,7 +396,7 @@ void
doctrl(Uxn *u, SDL_Event *event, int z) doctrl(Uxn *u, SDL_Event *event, int z)
{ {
Uint8 flag = 0x00; Uint8 flag = 0x00;
Uint16 addr = devctrl->addr; Uint16 addr = devctrl->addr + 2;
if(z && event->key.keysym.sym == SDLK_h) { if(z && event->key.keysym.sym == SDLK_h) {
if(SDL_GetModState() & KMOD_LCTRL) if(SDL_GetModState() & KMOD_LCTRL)
toggledebug(u); toggledebug(u);
@ -408,11 +408,11 @@ doctrl(Uxn *u, SDL_Event *event, int z)
case SDLK_LALT: flag = 0x02; break; case SDLK_LALT: flag = 0x02; break;
case SDLK_BACKSPACE: case SDLK_BACKSPACE:
flag = 0x04; flag = 0x04;
if(z) u->ram.dat[devkey->addr] = 0x08; if(z) u->ram.dat[devkey->addr + 2] = 0x08;
break; break;
case SDLK_RETURN: case SDLK_RETURN:
flag = 0x08; flag = 0x08;
if(z) u->ram.dat[devkey->addr] = 0x0d; if(z) u->ram.dat[devkey->addr + 2] = 0x0d;
break; break;
case SDLK_UP: flag = 0x10; break; case SDLK_UP: flag = 0x10; break;
case SDLK_DOWN: flag = 0x20; break; case SDLK_DOWN: flag = 0x20; break;
@ -592,10 +592,22 @@ start(Uxn *u)
case SDL_QUIT: quit(); break; case SDL_QUIT: quit(); break;
case SDL_MOUSEBUTTONUP: case SDL_MOUSEBUTTONUP:
case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONDOWN:
case SDL_MOUSEMOTION: domouse(u, &event); break; case SDL_MOUSEMOTION:
case SDL_TEXTINPUT: dotext(u, &event); break; domouse(u, &event);
case SDL_KEYDOWN: doctrl(u, &event, 1); break; evaluxn(u, devmouse->vector);
case SDL_KEYUP: doctrl(u, &event, 0); break; break;
case SDL_TEXTINPUT:
dotext(u, &event);
evaluxn(u, devkey->vector);
break;
case SDL_KEYDOWN:
doctrl(u, &event, 1);
evaluxn(u, devctrl->vector);
break;
case SDL_KEYUP:
doctrl(u, &event, 0);
evaluxn(u, devctrl->vector);
break;
case SDL_WINDOWEVENT: case SDL_WINDOWEVENT:
if(event.window.event == SDL_WINDOWEVENT_EXPOSED) if(event.window.event == SDL_WINDOWEVENT_EXPOSED)
redraw(pixels, u); redraw(pixels, u);