Fixed stack balance issue

This commit is contained in:
neauoire 2021-03-19 13:41:59 -07:00
parent 83932d8847
commit 3b38421b35
6 changed files with 74 additions and 81 deletions

View File

@ -67,7 +67,6 @@ RTN
### OS Boot Disk ### OS Boot Disk
- Load external disk in disk2 - Load external disk in disk2
- Build hex editor
### Assembler ### Assembler
@ -76,15 +75,10 @@ RTN
- Jump helpers - Jump helpers
- Don't brk when return stack is not zeroed - Don't brk when return stack is not zeroed
- LDRS should load from the zeropage? - LDRS should load from the zeropage?
- Keep ref counts in macros
- A fast way(2 bytes) to read from the zero page #aa LDR. - A fast way(2 bytes) to read from the zero page #aa LDR.
## Notes ## Notes
### Conditional Jumping
I've considered automatically popping an amount of items from the stack equal to the offset between the opcode's push/pop to make the stack length more predictable, and making the pattern JMP? POP2 unecessary, but that idea would make DUP? unusable. That change was reverted.
## Palettes ## Palettes
- `[ 6a03 4a0d aa0c ]`, purple/cyan - `[ 6a03 4a0d aa0c ]`, purple/cyan

View File

@ -1,7 +1,11 @@
( (
app/noodle : illustration program app/noodle : illustration program
right-click - erase
alt-click - drag canvas alt-click - drag canvas
arrows - move zoom
space - toogle zoom
backspace - blank canvas
TODO TODO
- Only draw-canvas when mouse has changed - Only draw-canvas when mouse has changed
@ -11,6 +15,8 @@
- Limit size - Limit size
- Draw point inbetween - Draw point inbetween
- Pixel cleanup brush - Pixel cleanup brush
BUGS
- If canvas is higher than 0, mouse picking fails
) )
%RTN { JMP2r } %RTN { JMP2r }
@ -23,13 +29,13 @@
;center { x 2 y 2 } ;center { x 2 y 2 }
;toolbar { x1 2 y1 2 x2 2 y2 2 } ;toolbar { x1 2 y1 2 x2 2 y2 2 }
;cursor { x 2 y 2 x0 2 y0 2 size 1 patt 1 drag 1 zoom 1 } ;cursor { x 2 y 2 x0 2 y0 2 size 1 patt 1 drag 1 }
;zoom { x 2 y 2 } ;zoom { active 1 x 2 y 2 }
;rect { x1 2 y1 2 x2 2 y2 2 } ;rect { x1 2 y1 2 x2 2 y2 2 }
;origin { x1 2 y1 2 x2 2 y2 2 } ;origin { x1 2 y1 2 x2 2 y2 2 }
;color { byte 1 } ;color { byte 1 }
;pos { x 2 y 2 } ;pt0 { x 2 y 2 }
;pix { x 2 y 2 } ;pt1 { x 2 y 2 }
;px { x 1 y 1 } ;px { x 1 y 1 }
|0100 @RESET |0100 @RESET
@ -122,7 +128,7 @@ BRK
~Mouse.x ~Screen.width #0020 SUB2 SUB2 8/ ~Mouse.x ~Screen.width #0020 SUB2 SUB2 8/
DUP2 DUP2
#0000 NEQ2 ,$no-toggle-zoom ROT JMP2? #0000 NEQ2 ,$no-toggle-zoom ROT JMP2?
~cursor.zoom #00 EQU =cursor.zoom ~zoom.active #00 EQU =zoom.active
( release ) #00 =Mouse.state ( release ) #00 =Mouse.state
,redraw JSR2 ,redraw JSR2
$no-toggle-zoom $no-toggle-zoom
@ -143,27 +149,20 @@ BRK
$no-touch $no-touch
,$no-ctrl ~Controller #00 EQU ~cursor.zoom #00 EQU #0000 NEQ2 JMP2? ~Controller.buttons #f0 AND
DUP #04 SHR #01 AND #01 NEQ ,$no-up ROT JMP2?
,$no-ctrl-up ~Controller #10 EQU JMP2? ( move ) ~zoom.y -- =zoom.y $no-up
~zoom.y ++ =zoom.y DUP #05 SHR #01 AND #01 NEQ ,$no-down ROT JMP2?
$no-ctrl-up ( move ) ~zoom.y ++ =zoom.y $no-down
,$no-ctrl-down ~Controller #20 EQU JMP2? DUP #06 SHR #01 AND #01 NEQ ,$no-left ROT JMP2?
~zoom.y -- =zoom.y ( move ) ~zoom.x -- =zoom.x $no-left
$no-ctrl-down DUP #07 SHR #01 AND #01 NEQ ,$no-right ROT JMP2?
,$no-ctrl-left ~Controller #40 EQU JMP2? ( move ) ~zoom.x ++ =zoom.x $no-right
~zoom.x ++ =zoom.x #00 NEQ ,draw-canvas ROT JSR2?
$no-ctrl-left
,$no-ctrl-right ~Controller #80 EQU JMP2?
~zoom.x -- =zoom.x
$no-ctrl-right
,draw-canvas JSR2
$no-ctrl
,$no-keys ~Keys #00 EQU JMP2? ,$no-keys ~Keys #00 EQU JMP2?
,$no-keys-toogle-zoom ~Keys #20 NEQ JMP2? ,$no-keys-toogle-zoom ~Keys #20 NEQ JMP2?
~cursor.zoom #00 EQU =cursor.zoom ~zoom.active #00 EQU =zoom.active
,redraw JSR2 ,redraw JSR2
$no-keys-toogle-zoom $no-keys-toogle-zoom
( release ) #00 =Keys ( release ) #00 =Keys
@ -199,18 +198,18 @@ RTN
,erase ~Mouse.state #10 EQU JMP2? ,erase ~Mouse.state #10 EQU JMP2?
#0003 SUB2 =pos.y #0003 SUB2 =pos.x ( cursor offset ) #0003 SUB2 =pt0.y #0003 SUB2 =pt0.x ( cursor offset )
( trim if zoomed ) ( trim if zoomed )
,$no-zoom ~cursor.zoom #01 NEQ JMP2? ,$no-zoom ~zoom.active #01 NEQ JMP2?
~pos.x 8/ ~zoom.x ADD2 #0003 SUB2 =pos.x ~pt0.x 8/ ~zoom.x ADD2 #0003 SUB2 =pt0.x
~pos.y 8/ ~zoom.y ADD2 #0003 SUB2 =pos.y ~pt0.y 8/ ~zoom.y ADD2 #0003 SUB2 =pt0.y
$no-zoom $no-zoom
( center zoom on paint ) ( center zoom on paint )
,$no-follow ~cursor.zoom JMP2? ,$no-follow ~zoom.active JMP2?
~pos.x ~canvas.w 2/ SUB2 #0003 ADD2 =zoom.x ~pt0.x ~canvas.w 2/ SUB2 #0003 ADD2 =zoom.x
~pos.y ~canvas.h 2/ SUB2 #0003 ADD2 =zoom.y ~pt0.y ~canvas.h 2/ SUB2 #0003 ADD2 =zoom.y
$no-follow $no-follow
#00 =px.x #00 =px.y #00 =px.x #00 =px.y
@ -221,7 +220,7 @@ RTN
( byte ) #00 ~px.y ADD2 LDR #07 ~px.x SUB SHR #01 AND ( byte ) #00 ~px.y ADD2 LDR #07 ~px.x SUB SHR #01 AND
#00 EQU ,$no-pixel ROT JMP2? #00 EQU ,$no-pixel ROT JMP2?
,$no-pixel ,patternize JSR2 #00 EQU JMP2? ,$no-pixel ,patternize JSR2 #00 EQU JMP2?
~pos.x #00 ~px.x ADD2 ~pos.y #00 ~px.y ADD2 ,add-pixel JSR2 ~pt0.x #00 ~px.x ADD2 ~pt0.y #00 ~px.y ADD2 ,add-pixel JSR2
$no-pixel $no-pixel
( incr ) ~px.x #01 ADD =px.x ( incr ) ~px.x #01 ADD =px.x
,$hor ~px.x #08 LTH JMP2? ,$hor ~px.x #08 LTH JMP2?
@ -235,18 +234,18 @@ RTN
@erase ( x y ) @erase ( x y )
#0003 SUB2 =pos.y #0003 SUB2 =pos.x ( cursor offset ) #0003 SUB2 =pt0.y #0003 SUB2 =pt0.x ( cursor offset )
( trim if zoomed ) ( trim if zoomed )
,$no-zoom ~cursor.zoom #01 NEQ JMP2? ,$no-zoom ~zoom.active #01 NEQ JMP2?
~pos.x 8/ ~zoom.x ADD2 #0003 SUB2 =pos.x ~pt0.x 8/ ~zoom.x ADD2 #0003 SUB2 =pt0.x
~pos.y 8/ ~zoom.y ADD2 #0003 SUB2 =pos.y ~pt0.y 8/ ~zoom.y ADD2 #0003 SUB2 =pt0.y
$no-zoom $no-zoom
( center zoom on paint ) ( center zoom on paint )
,$no-follow ~cursor.zoom JMP2? ,$no-follow ~zoom.active JMP2?
~pos.x ~canvas.w 2/ SUB2 #0003 ADD2 =zoom.x ~pt0.x ~canvas.w 2/ SUB2 #0003 ADD2 =zoom.x
~pos.y ~canvas.h 2/ SUB2 #0003 ADD2 =zoom.y ~pt0.y ~canvas.h 2/ SUB2 #0003 ADD2 =zoom.y
$no-follow $no-follow
#00 =px.x #00 =px.y #00 =px.x #00 =px.y
@ -257,7 +256,7 @@ RTN
( byte ) #00 ~px.y ADD2 LDR #07 ~px.x SUB SHR #01 AND ( byte ) #00 ~px.y ADD2 LDR #07 ~px.x SUB SHR #01 AND
#00 EQU ,$no-pixel ROT JMP2? #00 EQU ,$no-pixel ROT JMP2?
,$no-pixel ,patternize JSR2 #00 EQU JMP2? ,$no-pixel ,patternize JSR2 #00 EQU JMP2?
~pos.x #00 ~px.x ADD2 ~pos.y #00 ~px.y ADD2 ,remove-pixel JSR2 ~pt0.x #00 ~px.x ADD2 ~pt0.y #00 ~px.y ADD2 ,remove-pixel JSR2
$no-pixel $no-pixel
( incr ) ~px.x #01 ADD =px.x ( incr ) ~px.x #01 ADD =px.x
,$hor ~px.x #08 LTH JMP2? ,$hor ~px.x #08 LTH JMP2?
@ -275,42 +274,42 @@ RTN
$noplain $noplain
,$notone1 ~cursor.patt #01 NEQ JMP2? ,$notone1 ~cursor.patt #01 NEQ JMP2?
~pos.x #00 ~px.x ADD2 ~pos.y #00 ~px.y ADD2 ADD2 #0001 AND2 #0000 EQU2 ~pt0.x #00 ~px.x ADD2 ~pt0.y #00 ~px.y ADD2 ADD2 #0001 AND2 #0000 EQU2
~pos.x #00 ~px.x ADD2 ~pos.y #00 ~px.y ADD2 SUB2 #0001 AND2 #0000 EQU2 ~pt0.x #00 ~px.x ADD2 ~pt0.y #00 ~px.y ADD2 SUB2 #0001 AND2 #0000 EQU2
#0101 EQU2 #0101 EQU2
RTN RTN
$notone1 $notone1
,$notone2 ~cursor.patt #02 NEQ JMP2? ,$notone2 ~cursor.patt #02 NEQ JMP2?
~pos.x #00 ~px.x ADD2 ~pos.y #00 ~px.y ADD2 ADD2 #0003 AND2 #0000 EQU2 ~pt0.x #00 ~px.x ADD2 ~pt0.y #00 ~px.y ADD2 ADD2 #0003 AND2 #0000 EQU2
~pos.x #00 ~px.x ADD2 ~pos.y #00 ~px.y ADD2 SUB2 #0003 AND2 #0000 EQU2 ~pt0.x #00 ~px.x ADD2 ~pt0.y #00 ~px.y ADD2 SUB2 #0003 AND2 #0000 EQU2
#0101 EQU2 #0101 EQU2
RTN RTN
$notone2 $notone2
,$notone3 ~cursor.patt #03 NEQ JMP2? ,$notone3 ~cursor.patt #03 NEQ JMP2?
~pos.x #00 ~px.x ADD2 ~pos.y #00 ~px.y ADD2 ADD2 #0005 AND2 #0000 EQU2 ~pt0.x #00 ~px.x ADD2 ~pt0.y #00 ~px.y ADD2 ADD2 #0005 AND2 #0000 EQU2
~pos.x #00 ~px.x ADD2 ~pos.y #00 ~px.y ADD2 SUB2 #0005 AND2 #0000 EQU2 ~pt0.x #00 ~px.x ADD2 ~pt0.y #00 ~px.y ADD2 SUB2 #0005 AND2 #0000 EQU2
#0101 EQU2 #0101 EQU2
RTN RTN
$notone3 $notone3
,$notone4 ~cursor.patt #04 NEQ JMP2? ,$notone4 ~cursor.patt #04 NEQ JMP2?
~pos.x #00 ~px.x ADD2 ~pos.y #00 ~px.y ADD2 ADD2 #0003 AND2 #0000 EQU2 ~pt0.x #00 ~px.x ADD2 ~pt0.y #00 ~px.y ADD2 ADD2 #0003 AND2 #0000 EQU2
RTN RTN
$notone4 $notone4
,$notone5 ~cursor.patt #05 NEQ JMP2? ,$notone5 ~cursor.patt #05 NEQ JMP2?
~pos.x #00 ~px.x ADD2 ~pos.y #00 ~px.y ADD2 SUB2 #0003 AND2 #0000 EQU2 ~pt0.x #00 ~px.x ADD2 ~pt0.y #00 ~px.y ADD2 SUB2 #0003 AND2 #0000 EQU2
RTN RTN
$notone5 $notone5
,$notone6 ~cursor.patt #06 NEQ JMP2? ,$notone6 ~cursor.patt #06 NEQ JMP2?
~pos.x #00 ~px.x ADD2 #0001 AND2 SWP POP RTN ~pt0.x #00 ~px.x ADD2 #0001 AND2 SWP POP RTN
$notone6 $notone6
,$notone7 ~cursor.patt #07 NEQ JMP2? ,$notone7 ~cursor.patt #07 NEQ JMP2?
~pos.y #00 ~px.y ADD2 #0001 AND2 SWP POP RTN ~pt0.y #00 ~px.y ADD2 #0001 AND2 SWP POP RTN
$notone7 $notone7
#00 #00
@ -321,7 +320,7 @@ RTN
SWP POP #07 AND =px.y SWP POP #07 AND =px.y
SWP POP #07 AND =px.x SWP POP #07 AND =px.x
( get tile ) ~pix.x 8/ ~pix.y 8/ ~canvas.w MUL2 ADD2 8* ( get tile ) ~pt1.x 8/ ~pt1.y 8/ ~canvas.w MUL2 ADD2 8*
( add addr ) ,data ADD2 ( add addr ) ,data ADD2
#00 ~px.y ADD2 LDR #07 ~px.x SUB SHR #01 AND #00 ~px.y ADD2 LDR #07 ~px.x SUB SHR #01 AND
@ -329,20 +328,20 @@ RTN
@add-pixel ( x y ) @add-pixel ( x y )
=pix.y =pix.x =pt1.y =pt1.x
( get tile addr ) ,data ~pix.x 8/ ~pix.y 8/ ~canvas.w MUL2 ADD2 8* ~pix.y MOD8 ADD2 ADD2 ( get tile addr ) ,data ~pt1.x 8/ ~pt1.y 8/ ~canvas.w MUL2 ADD2 8* ~pt1.y MOD8 ADD2 ADD2
( load ) DUP2 LDR ( load ) DUP2 LDR
( mask ) #01 #07 ~pix.x MOD8 SWP POP SUB SHL ORA ( mask ) #01 #07 ~pt1.x MOD8 SWP POP SUB SHL ORA
( save ) ROT ROT STR ( save ) ROT ROT STR
RTN RTN
@remove-pixel ( x y ) @remove-pixel ( x y )
=pix.y =pix.x =pt1.y =pt1.x
( get tile addr ) ,data ~pix.x 8/ ~pix.y 8/ ~canvas.w MUL2 ADD2 8* ~pix.y MOD8 ADD2 ADD2 ( get tile addr ) ,data ~pt1.x 8/ ~pt1.y 8/ ~canvas.w MUL2 ADD2 8* ~pt1.y MOD8 ADD2 ADD2
( load ) DUP2 LDR ( load ) DUP2 LDR
( mask ) #01 #07 ~pix.x MOD8 SWP POP SUB SHL #ff XOR AND ( mask ) #01 #07 ~pt1.x MOD8 SWP POP SUB SHL #ff XOR AND
( save ) ROT ROT STR ( save ) ROT ROT STR
RTN RTN
@ -359,7 +358,7 @@ RTN
@draw-canvas @draw-canvas
,draw-canvas-zoom ~cursor.zoom #01 EQU JMP2? ,draw-canvas-zoom ~zoom.active #01 EQU JMP2?
~canvas.y1 =Sprite.y ~canvas.y1 =Sprite.y
,data =Sprite.addr ,data =Sprite.addr
@ -377,20 +376,20 @@ RTN
@draw-canvas-zoom @draw-canvas-zoom
~zoom.y =pix.y ~zoom.y =pt1.y
~canvas.y1 =Sprite.y ~canvas.y1 =Sprite.y
,data =Sprite.addr ,data =Sprite.addr
$ver $ver
~canvas.x1 =Sprite.x ~canvas.x1 =Sprite.x
~zoom.x =pix.x ~zoom.x =pt1.x
$hor $hor
( incr ) ,bigpixel_icn #0008 #00 ~pix.x ~pix.y ,get-pixel JSR2 MUL2 ADD2 =Sprite.addr ( incr ) ,bigpixel_icn #0008 #00 ~pt1.x ~pt1.y ,get-pixel JSR2 MUL2 ADD2 =Sprite.addr
( draw ) #09 =Sprite.color ( draw ) #09 =Sprite.color
( incr ) ~Sprite.x 8+ =Sprite.x ( incr ) ~Sprite.x 8+ =Sprite.x
( incr ) ~pix.x ++ =pix.x ( incr ) ~pt1.x ++ =pt1.x
,$hor ~Sprite.x ~canvas.x2 NEQ2 JMP2? ,$hor ~Sprite.x ~canvas.x2 NEQ2 JMP2?
( incr ) ~Sprite.y 8+ =Sprite.y ( incr ) ~Sprite.y 8+ =Sprite.y
( incr ) ~pix.y ++ =pix.y ( incr ) ~pt1.y ++ =pt1.y
,$ver ~Sprite.y ~canvas.y2 NEQ2 JMP2? ,$ver ~Sprite.y ~canvas.y2 NEQ2 JMP2?
RTN RTN
@ -499,7 +498,7 @@ RTN
,save_icn =Sprite.addr ,save_icn =Sprite.addr
#01 =Sprite.color #01 =Sprite.color
~Screen.width #0020 SUB2 =Sprite.x ~Screen.width #0020 SUB2 =Sprite.x
,zoom_icn #00 ~cursor.zoom 8* ADD2 =Sprite.addr ,zoom_icn #00 ~zoom.active 8* ADD2 =Sprite.addr
#01 =Sprite.color #01 =Sprite.color
( draw width ) ( draw width )
@ -554,13 +553,13 @@ RTN
@size_icn @size_icn
[ 0000 0010 0000 0000 ] [ 0000 0010 0000 0000 ]
[ 0000 1038 1000 0000 ] [ 0000 1038 1000 0000 ]
[ 0000 3838 3800 0000 ] [ 0000 3838 3800 0000 ]
[ 0010 387c 3810 0000 ] [ 0010 387c 3810 0000 ]
[ 0038 7c7c 7c38 0000 ] [ 0038 7c7c 7c38 0000 ]
[ 1038 7cfe 7c38 1000 ] [ 1038 7cfe 7c38 1000 ]
[ 387c fefe fe7c 3800 ] [ 387c fefe fe7c 3800 ]
[ 7cfe fefe fefe 7c00 ] [ 7cfe fefe fefe 7c00 ]
@pattern_icn @pattern_icn
[ fe82 baba ba82 fe00 ] [ fe82 baba ba82 fe00 ]
@ -581,7 +580,7 @@ RTN
[ 1028 4482 4428 1000 ] [ 1028 4482 4428 1000 ]
[ 3844 8282 8244 3800 ] [ 3844 8282 8244 3800 ]
[ 7c82 8282 8282 7c00 ] [ 7c82 8282 8282 7c00 ]
[ 7cfe fefe fefe 7c00 ] [ 7cfe fefe fefe 7c00 ]
@zoom_icn @zoom_icn
[ 3048 8484 4834 0200 ] [ 3048 8484 4834 0200 ]
@ -599,7 +598,7 @@ RTN
@save_icn [ fe82 8282 848a f400 ] @save_icn [ fe82 8282 848a f400 ]
@blank_icn [ 0000 0000 0000 0000 ] @blank_icn [ 0000 0000 0000 0000 ]
@filepath [ projects/picture(20-10).bit 00 ] @filepath [ projects/picture2010.bit 00 ]
@font_hex @font_hex
[ [

4
uxn.c
View File

@ -103,12 +103,12 @@ void (*ops[])(Uxn *u) = {
}; };
Uint8 opr[][4] = { /* wstack-/+ rstack-/+ */ Uint8 opr[][4] = { /* wstack-/+ rstack-/+ */
{0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {2,1,0,0}, {3,0,0,0}, {1,0,0,0}, {1,0,0,2}, {0,0,2,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {2,1,0,0}, {3,0,0,0}, {1,0,0,0}, {1,0,0,0}, {1,0,0,2},
{2,1,0,0}, {2,1,0,0}, {2,1,0,0}, {2,1,0,0}, {2,1,0,0}, {2,1,0,0}, {2,1,0,0}, {2,1,0,0}, {2,1,0,0}, {2,1,0,0}, {2,1,0,0}, {2,1,0,0}, {2,1,0,0}, {2,1,0,0}, {2,1,0,0}, {2,1,0,0},
{1,0,0,0}, {0,2,0,0}, {2,2,0,0}, {2,3,0,0}, {3,3,0,0}, {0,0,0,0}, {0,0,0,1}, {0,1,1,0}, {1,0,0,0}, {0,2,0,0}, {2,2,0,0}, {2,3,0,0}, {3,3,0,0}, {0,0,0,0}, {0,0,0,1}, {0,1,1,0},
{2,1,0,0}, {2,1,0,0}, {2,1,0,0}, {2,1,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,2,0,0}, {2,1,0,0}, {2,1,0,0}, {2,1,0,0}, {2,1,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,2,0,0},
/* 16-bit */ /* 16-bit */
{0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {2,2,0,0}, {4,0,0,0}, {2,0,0,0}, {2,0,0,0}, {0,0,0,0}, /* TODO */ {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {2,2,0,0}, {4,0,0,0}, {2,0,0,0}, {2,0,0,0}, {2,0,0,2}, /* TODO */
{4,2,0,0}, {4,2,0,0}, {4,2,0,0}, {4,2,0,0}, {4,2,0,0}, {4,2,0,0}, {4,2,0,0}, {4,2,0,0}, /* TODO */ {4,2,0,0}, {4,2,0,0}, {4,2,0,0}, {4,2,0,0}, {4,2,0,0}, {4,2,0,0}, {4,2,0,0}, {4,2,0,0}, /* TODO */
{0,2,0,0}, {0,2,0,0}, {1,1,0,0}, {4,6,0,0}, {6,6,0,0}, {0,0,0,0}, {0,0,0,2}, {0,2,2,0}, /* TODO */ {0,2,0,0}, {0,2,0,0}, {1,1,0,0}, {4,6,0,0}, {6,6,0,0}, {0,0,0,0}, {0,0,0,2}, {0,2,2,0}, /* TODO */
{4,2,0,0}, {4,2,0,0}, {4,2,0,0}, {4,2,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,2,0,0} {4,2,0,0}, {4,2,0,0}, {4,2,0,0}, {4,2,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,2,0,0}