mirror of https://git.cro.wtf/kip.git
kip-io:keyboard
This commit is contained in:
parent
87b17f603e
commit
7dc8759204
|
@ -9,3 +9,4 @@ X(io_display_blit)
|
|||
X(io_display_out)
|
||||
X(io_mouse_pos)
|
||||
X(io_mouse_but)
|
||||
X(io_keeb)
|
||||
|
|
|
@ -14,7 +14,7 @@ _ B layer[4][wid*hig]={0},redraw;
|
|||
_ W computed[wid*hig]={0};
|
||||
|
||||
_ H mx,my,mb,px,py;
|
||||
_ W blit,out,pal;
|
||||
_ W blit,out,pal,keeb;
|
||||
|
||||
_ NR V err(V){die("sdl:%s\n",SDL_GetError());}
|
||||
|
||||
|
@ -30,6 +30,7 @@ DEV(display_blit,(blit=x),(R blit))
|
|||
DEV(display_out,(W c;B m,l;out=x,m=0xf&x,l=(0xf0&x)>>4,c=x>>8,outs[m](l,c,px,py)),(R out))
|
||||
DEV(mouse_pos,(mx=x<<16,my=x),(R mx<<16|my))
|
||||
DEV(mouse_but,((V)x),(R mb))
|
||||
DEV(keeb,((V)x),(R keeb))
|
||||
|
||||
V front_init(V){
|
||||
Q(SDL_Init(SDL_INIT_VIDEO),err())
|
||||
|
@ -45,6 +46,8 @@ V front_events(V){_ SDL_Event ev;W t;
|
|||
Q(SDL_MOUSEMOTION==t,mx=SDL_clamp(ev.motion.x,0,wid),my=SDL_clamp(ev.motion.y,0,hig))OR
|
||||
Q(SDL_MOUSEBUTTONDOWN==t,mb|=1<<(ev.button.button-1),vec(0x04))OR
|
||||
Q(SDL_MOUSEBUTTONUP==t, mb^=1<<(ev.button.button-1),vec(0x08))OR
|
||||
Q(SDL_KEYDOWN==t,keeb=ev.key.keysym.sym,vec(0x0c))OR
|
||||
Q(SDL_KEYUP==t, keeb=ev.key.keysym.sym,vec(0x10))OR
|
||||
Q(SDL_QUIT==t,kip_deinit(),exit(0)))}
|
||||
|
||||
V front_redraw(V){W i,j,k;
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
!disp:out pb #08 ;
|
||||
!mouse:pos pb #09 ;
|
||||
!mouse:but pb #0a ;
|
||||
!keeb pb #0b ;
|
||||
|
||||
{ivt defs}
|
||||
!disp:vsync pb #00 ;
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
-inc "x/dev.inc"
|
||||
!+1 pb #1 ad ;
|
||||
!nl #0a ;
|
||||
!ret mr ju ;
|
||||
|
||||
-org #100
|
||||
:entry
|
||||
pw @ivt/keeb-down `keeb:down mw
|
||||
pw @ivt/keeb-up `keeb:up mw
|
||||
ex
|
||||
;
|
||||
:ivt
|
||||
:keeb-down
|
||||
pw @data/keeb-down pw @s0/put ca
|
||||
`keeb ii pw @key/put ca
|
||||
pb `nl `term:0 io
|
||||
`ret
|
||||
;
|
||||
:keeb-up
|
||||
pw @data/keeb-up pw @s0/put ca
|
||||
`keeb ii pw @key/put ca
|
||||
pb `nl `term:0 io
|
||||
`ret
|
||||
;
|
||||
;
|
||||
:key
|
||||
:ascii? du pb #80 lt sw pb #1f gt an `ret ;
|
||||
:put du pw @ascii? ca pw @ascii jc dd `ret :ascii `term:0 io ; `ret ;
|
||||
;
|
||||
:s0
|
||||
:put du fb du no pw @end jc `term:0 io `+1 pw @put ju :end dd dd ; `ret ;
|
||||
;
|
||||
:data
|
||||
:keeb-down "keyboard down: " #00 ;
|
||||
:keeb-up "keyboard up: " #00 ;
|
||||
;
|
Loading…
Reference in New Issue