Implemented devctrl

This commit is contained in:
neauoire 2021-02-26 16:53:09 -08:00
parent b014a73bcd
commit 527d6508e2
5 changed files with 34 additions and 48 deletions

View File

@ -297,9 +297,10 @@ dotext(SDL_Event *event)
}
void
doctrl(SDL_Event *event, int z)
doctrl(Uxn *u, SDL_Event *event, int z)
{
Uint8 flag = 0x00;
Uint16 addr = 0xff30; /* TODO: get dynamically */
if(z && event->key.keysym.sym == SDLK_h)
GUIDES = !GUIDES;
if(SDL_GetModState() & KMOD_LCTRL || SDL_GetModState() & KMOD_RCTRL)
@ -320,7 +321,7 @@ doctrl(SDL_Event *event, int z)
case SDLK_LEFT: flag = 0x40; break;
case SDLK_RIGHT: flag = 0x80; break;
}
setflag(&devcontroller->mem[0], flag, z);
setflag(&u->ram.dat[addr], flag, z);
}
#pragma mark - Devices
@ -439,8 +440,8 @@ start(Uxn *u)
case SDL_MOUSEBUTTONDOWN:
case SDL_MOUSEMOTION: domouse(u, &event); break;
case SDL_TEXTINPUT: dotext(&event); break;
case SDL_KEYDOWN: doctrl(&event, 1); break;
case SDL_KEYUP: doctrl(&event, 0); break;
case SDL_KEYDOWN: doctrl(u, &event, 1); break;
case SDL_KEYUP: doctrl(u, &event, 0); break;
case SDL_WINDOWEVENT:
if(event.window.event == SDL_WINDOWEVENT_EXPOSED)
redraw(pixels, u);

View File

@ -1,9 +1,10 @@
( blank )
&Console { pad 8 stdio 1 }
&Screen { width 2 height 2 pad 4 y 2 x 2 color 1 }
&Sprite { pad 8 y 2 x 2 addr 2 color 1 }
&Mouse { x 2 y 2 state 1 chord 1 }
&Console { pad 8 stdio 1 }
&Screen { width 2 height 2 pad 4 y 2 x 2 color 1 }
&Sprite { pad 8 y 2 x 2 addr 2 color 1 }
&Controller { buttons 1 }
&Mouse { x 2 y 2 state 1 chord 1 }
|0100 @RESET BRK
|c000 @FRAME BRK
@ -12,6 +13,7 @@
|FF00 ;dev/console Console
|FF10 ;dev/screen Screen
|FF20 ;dev/sprite Sprite
|FF30 ;dev/ctrl Controller
|FF50 ;dev/mouse Mouse
|FFF0 [ f2ac 35bb 2b53 ] ( palette )

View File

@ -1,7 +1,8 @@
( controller )
:dev/r fff8 ( const read port )
:dev/w fff9 ( const write port )
&Screen { width 2 height 2 pad 4 y 2 x 2 color 1 }
&Sprite { pad 8 x 2 y 2 addr 2 color 1 }
&Controller { buttons 1 }
&Point2d { x 2 y 2 }
@ -10,38 +11,36 @@
|0100 @RESET
#03 =dev/r ( set dev/read to controller )
#02 =dev/w ( set dev/write to sprite )
#0080 =pos.x #0040 =pos.y ( origin )
( set origin )
~dev/screen.width #0002 DIV2 =pos.x
~dev/screen.height #0002 DIV2 =pos.y
#12 ,up_icn ~pos.x ~pos.y ,draw-sprite JSR
#12 ,up_icn ~pos.y ~pos.x ,draw-sprite JSR
BRK
|c000 @FRAME
#03 =dev/r ( set dev/read to controller )
,default_icn =sprite
#00 IOR #10 NEQ ,next1 ROT JMP? POP2
~dev/ctrl.buttons #10 NEQ ,next1 ROT JMP? POP2
,up_icn =sprite
~pos.y #0001 SUB2 =pos.y
@next1
#00 IOR #20 NEQ ,next2 ROT JMP? POP2
~dev/ctrl.buttons #20 NEQ ,next2 ROT JMP? POP2
,down_icn =sprite
~pos.y #0001 ADD2 =pos.y
@next2
#00 IOR #40 NEQ ,next3 ROT JMP? POP2
~dev/ctrl.buttons #40 NEQ ,next3 ROT JMP? POP2
,left_icn =sprite
~pos.x #0001 SUB2 =pos.x
@next3
#00 IOR #80 NEQ ,end ROT JMP? POP2
~dev/ctrl.buttons #80 NEQ ,end ROT JMP? POP2
,right_icn =sprite
~pos.x #0001 ADD2 =pos.x
@end
( redraw )
#13 ~sprite ~pos.x ~pos.y ,draw-sprite JSR
#13 ~sprite ~pos.y ~pos.x ,draw-sprite JSR
BRK
@ -52,13 +51,17 @@ BRK
@right_icn [ 3c7e f7f8 f8f7 7e3c ]
@draw-sprite
IOW2 ( y byte )
IOW2 ( x byte )
IOW2 ( sprite address )
IOW ( layer-color )
=dev/sprite.x
=dev/sprite.y
=dev/sprite.addr
=dev/sprite.color
RTS
|d000 @ERROR BRK
|FF10 ;dev/screen Screen
|FF20 ;dev/sprite Sprite
|FF30 ;dev/ctrl Controller
|FFF0 [ 02ac 05bb 0b53 ] ( palette )
|FFFA .RESET .FRAME .ERROR

View File

@ -1,7 +1,7 @@
( mouse )
&Screen { width 2 height 2 pad 4 y 2 x 2 color 1 }
&Sprite { pad 8 y 2 x 2 addr 2 color 1 }
&Sprite { pad 8 x 2 y 2 addr 2 color 1 }
&Mouse { x 2 y 2 state 1 chord 1 }
&Point2d { x 2 y 2 }
@ -91,15 +91,15 @@ RTS
RTS
@draw-sprite
=dev/sprite.x
=dev/sprite.y
=dev/sprite.x
=dev/sprite.addr
=dev/sprite.color
RTS
@draw-sprite-chr
=dev/sprite.x
=dev/sprite.y
=dev/sprite.x
=dev/sprite.addr
#20 =dev/sprite.color
RTS

View File

@ -1,20 +0,0 @@
( blank )
:dev/r fff8 ( std read port )
:dev/w fff9 ( std write port )
&Console { stdout 1 }
|0100 @RESET
BRK
|c000 @FRAME BRK
|d000 @ERROR BRK
|FF00 ;dev/console Console
|FF08 ;device2 Device
|FFF0 [ f2ac 35bb 2b53 ] ( palette )
|FFFA .RESET .FRAME .ERROR