diff --git a/emulator.c b/emulator.c index fa153ae..a41d41a 100644 --- a/emulator.c +++ b/emulator.c @@ -111,7 +111,7 @@ void drawdebugger(Uint32 *dst, Uxn *u) { Uint8 i; - for(i = 0; i < 0x10; ++i) { /* memory */ + for(i = 0; i < 0x20; ++i) { /* memory */ Uint8 x = (i % 8) * 3 + 1, y = i / 8 + 1, b = u->ram.dat[i]; drawicn(dst, x * 8, y * 8, icons[(b >> 4) & 0xf], 1, 0); drawicn(dst, x * 8 + 8, y * 8, icons[b & 0xf], 1, 0); @@ -182,12 +182,11 @@ domouse(SDL_Event *event) devmouse->mem[1] = x & 0xff; devmouse->mem[2] = (y >> 8) & 0xff; devmouse->mem[3] = y & 0xff; + devmouse->mem[4] = event->button.button == SDL_BUTTON_LEFT; + devmouse->mem[5] = 0x00; switch(event->type) { - case SDL_MOUSEBUTTONUP: - devmouse->mem[4] = 0; - break; - case SDL_MOUSEBUTTONDOWN: - devmouse->mem[4] = event->button.button == SDL_BUTTON_LEFT; + case SDL_MOUSEBUTTONUP: devmouse->mem[5] = 0x10; break; + case SDL_MOUSEBUTTONDOWN: devmouse->mem[5] = 0x01; break; } } @@ -254,8 +253,6 @@ screenw(Device *d, Memory *m, Uint8 b) d->mem[4]); if(d->mem[5] == 1) REQDRAW = 1; - if(d->mem[5] == 2) - clear(pixels); d->ptr = 0; } (void)m; @@ -288,6 +285,8 @@ start(Uxn *u) { int ticknext = 0; evaluxn(u, u->vreset); + if(REQDRAW) + redraw(pixels, u); while(1) { int tick = SDL_GetTicks(); SDL_Event event; diff --git a/examples/drag.usm b/examples/drag.usm index d3867b7..3c5aca9 100644 --- a/examples/drag.usm +++ b/examples/drag.usm @@ -4,32 +4,53 @@ :dev/w fff9 ( std write port ) ;drawx 2 ;drawy 2 ;x 2 ;y 2 ;w 2 ;h 2 ;color 1 +;touchx 2 ;touchy 2 ;down 1 |0100 @RESET #05 =dev/r ( set dev/read mouse ) #01 =dev/w ( set dev/write to screen ) + #02 =color + #0050 =w #0080 =h ,update JSR + BRK |c000 @FRAME ( get touch ) - #04 IOR #01 NEQ ,frame-end ROT JMP? POP2 + #05 IOR #01 EQU ,on-touch ROT JMP? POP2 + #05 IOR #10 EQU ,on-release ROT JMP? POP2 + #01 ~down EQU ,on-drag ROT JMP? POP2 + BRK - ( clear ) - #00 =color - ~x ~y #0060 #0040 ,fillrect JSR + @on-touch + #01 =down + #01 =color + #00 IOR2 =touchx #02 IOR2 =touchy + ,update JSR + BRK + @on-release + #00 =down + #02 =color + ,update JSR + BRK + @on-drag + ( clear last rect ) + #00 =color + ~x ~y ~w ~h ,fillrect JSR + ( draw new rect ) + #03 =color + #00 IOR2 ~touchx SUBS2 ~x ADDS2 =x + #02 IOR2 ~touchy SUBS2 ~y ADDS2 =y + #00 IOR2 =touchx #02 IOR2 =touchy + ,update JSR + BRK - ( fill rect x y w h ) - #01 =color - #00 IOR2 ( get mouse-x ) =x - #02 IOR2 ( get mouse-y ) =y - ~x ~y #0060 #0040 ,fillrect JSR - - ,redraw JSR - - @frame-end + @update + ~x ~y ~w ~h ,fillrect JSR + ,redraw JSR + BRK BRK @@ -58,12 +79,5 @@ BRK #01 IOW RTS -@clear - #0000 IOW2 - #0000 IOW2 - #00 IOW - #02 IOW - RTS - |d000 @ERROR BRK |FFFA .RESET .FRAME .ERROR