Started repairing the key example

This commit is contained in:
neauoire 2021-03-01 17:05:04 -08:00
parent 053c043bf1
commit f42a307f1f
4 changed files with 91 additions and 76 deletions

View File

@ -84,21 +84,6 @@ RTS
|FFF8 [ 13fd 1ef3 1bf2 ] ( palette )
```
## Emulator
### Controller(dev/ctrl)
A device that works like a NES controller, each button is a bit from a single byte. Press `h` to toggle debugger.
- `0x01` Ctrl
- `0x02` Alt
- `0x04` Escape
- `0x08` Return
- `0x10` Up
- `0x20` Down
- `0x40` Left
- `0x80` Right
## TODOs
### OS Boot Disk
@ -115,6 +100,7 @@ A device that works like a NES controller, each button is a bit from a single by
- Example of button pointing to a subroutine
- GUI:
- Line routine
- Extra frame buffer addressing? Mirror sprites?
### Assembler

View File

@ -20,5 +20,5 @@ cc -std=c89 -DDEBUG -Wall -Wno-unknown-pragmas -Wpedantic -Wshadow -Wextra -Werr
# cc uxn.c emulator.c -std=c89 -Os -DNDEBUG -g0 -s -Wall -Wno-unknown-pragmas -L/usr/local/lib -lSDL2 -o bin/emulator
# run
./bin/assembler examples/dev.mouse.usm bin/boot.rom
./bin/assembler examples/dev.key.usm bin/boot.rom
./bin/emulator bin/boot.rom

View File

@ -1,91 +1,120 @@
( dev/key )
&Screen { width 2 height 2 pad 4 y 2 x 2 color 1 }
&Screen { width 2 height 2 pad 4 x 2 y 2 color 1 }
&Sprite { pad 8 x 2 y 2 addr 2 color 1 }
&Keyboard { key 1 }
&Textarea2d { x1 2 y1 2 x2 2 y2 2 color 1 addr 2 cursor 1 }
&Point2d { x 2 y 2 }
&Rect2d { x1 2 y1 2 x2 2 y2 2 }
;pos Point2d
;textarea Textarea2d
;rect Rect2d
;color 1
;textlen 2
|0100 @RESET
#0010 =textarea.x1 #0040 =textarea.y1 #00c0 =textarea.x2 #0090 =textarea.y2 ,body =textarea.addr
,redraw JSR
BRK
|0200 @FRAME
~dev/key #00 EQU BRK? ( skip on no-key )
( backspace )
,on-erase ~dev/key #08 EQU JMP? POP2
( otherwise )
~dev/key ~textarea.addr #00 ~textarea.cursor ADD2 STR
( incr ) ~textarea.cursor #01 ADD =textarea.cursor
@input-end
#00 =dev/key ( release key )
,redraw JSR
BRK
|c000 @FRAME
~dev/key #00 EQU ,key-end ROT JMP? POP2
( is backspace )
~dev/key #08 NEQ ,no-key-back ROT JMP? POP2
#00 ,body ~textlen ADD2 STR
~textlen #0001 SUB2 =textlen
,key-end JMP
@no-key-back
~textlen #0001 ADD2 =textlen
~dev/key ,body ~textlen ADD2 STR
,redraw JSR
#00 =dev/key ( release key )
@key-end
BRK
@redraw
#02 =color
#0040 #0040 #0090 #0090 ,fill-rect JSR
#06 =color
,body #0040 #0040 ,draw-label-multiline JSR
~textarea.x1 ~textarea.y1 ~textarea.x2 ~textarea.y2 #01 ,fill-rect JSR
~textarea.x1 ~textarea.y1 #0f ~textarea.addr ,draw-textarea JSR
~textarea.x1 #0002 SUB2 ~textarea.y1 #0002 SUB2 ~textarea.x2 #0001 ADD2 ~textarea.y2 #0001 ADD2 #01 ,line-rect JSR
RTS
@draw-label-multiline ( text x1 y1 )
=pos.y =pos.x
@draw-label-multiline-loop
( draw ) DUP2 LDR #00 SWP #0008 MUL2 ,font ADD2 =dev/sprite.addr
~pos.y =dev/sprite.y
~pos.x =dev/sprite.x
~color =dev/sprite.color
( incr ) #0001 ADD2
( incr ) ~pos.x #0008 ADD2 =pos.x
@on-erase
( skip if cursor is at 0 )
,input-end ~textarea.cursor #01 LTH JMP? POP2
#00 ~dev/key ~textarea.addr #00 ~textarea.cursor ADD2 STR
( decr ) ~textarea.cursor #01 SUB =textarea.cursor
BRK
RTS
@fill-rect ( x1 y1 x2 y2 color )
( load ) =color =rect.y2 =rect.x2 DUP2 =dev/screen.y =rect.y1 DUP2 =dev/screen.x =rect.x1
@fill-rect-ver
~rect.x1 =dev/screen.x
@fill-rect-hor
( draw ) ~color =dev/screen.color
( incr ) ~dev/screen.x #0001 ADD2 =dev/screen.x
,fill-rect-hor ~dev/screen.x ~rect.x2 LTH2 JMP? POP2
( incr ) ~dev/screen.y #0001 ADD2 =dev/screen.y
,fill-rect-ver ~dev/screen.y ~rect.y2 LTH2 JMP? POP2
RTS
@line-rect ( x1 y1 x2 y2 color )
( load ) =color =rect.y2 =rect.x2 DUP2 =dev/screen.y =rect.y1 DUP2 =dev/screen.x =rect.x1
@line-rect-hor
( incr ) ~dev/screen.x #0001 ADD2 =dev/screen.x
( draw ) ~rect.y1 =dev/screen.y ~color =dev/screen.color
( draw ) ~rect.y2 =dev/screen.y ~color =dev/screen.color
,line-rect-hor ~dev/screen.x ~rect.x2 LTH2 JMP? POP2
~rect.y1 =dev/screen.y
@line-rect-ver
( draw ) ~rect.x1 =dev/screen.x ~color =dev/screen.color
( draw ) ~rect.x2 =dev/screen.x ~color =dev/screen.color
( incr ) ~dev/screen.y #0001 ADD2 =dev/screen.y
,line-rect-ver ~dev/screen.y ~rect.y2 #0001 ADD2 LTH2 JMP? POP2
RTS
@draw-textarea ( x y color addr )
( load ) =textarea.addr =textarea.color =dev/sprite.y =dev/sprite.x
~textarea.addr
@draw-textarea-left-loop
( draw ) DUP2 LDR #00 SWP #0008 MUL2 ,font ADD2 =dev/sprite.addr ~textarea.color =dev/sprite.color
( detect linebreaks )
DUP2 LDR #0d NEQ ,no-return ROT JMP? POP2
#0048 =pos.x
~pos.y #0008 ADD2 =pos.y
~textarea.x1 =dev/sprite.x
( incr ) ~dev/sprite.y #0008 ADD2 =dev/sprite.y
( decr ) ~dev/sprite.x #0008 SUB2 =dev/sprite.x
@no-return
DUP2 LDR #00 NEQ ,draw-label-multiline-loop ROT JMP? POP2
( incr ) #0001 ADD2
( incr ) ~dev/sprite.x #0008 ADD2 =dev/sprite.x
DUP2 LDR #00 NEQ ,draw-textarea-left-loop ROT JMP? POP2
POP2
RTS
@fill-rect ( x1 y1 x2 y2 )
=rect.y2 =rect.x2 ( stash x1 y1 ) =rect.y1 DUP2 WSR2 =rect.x1
@fill-rect-ver
RSW2 DUP2 =rect.x1 WSR2
~rect.y1 =dev/screen.y
@fill-rect-hor
( draw ) ~rect.x1 =dev/screen.x ~color =dev/screen.color
( incr ) ~rect.x1 #0001 ADD2 DUP2 =rect.x1
~rect.x2 LTH2 ,fill-rect-hor ROT JMP? POP2
~rect.y1 #0001 ADD2 DUP2 =rect.y1
~rect.y2 LTH2 ,fill-rect-ver ROT JMP? POP2
RSW2 POP2
RTS
@draw-sprite
=dev/sprite.x
=dev/sprite.y
=dev/sprite.addr
=dev/sprite.color
RTS
@font ( spectrum-zx font )
[
0000 0000 0000 0000 0000 2400 7e3c 0000 0000 2400 3c42 0000 0000 6c7c 7c38 1000
@ -122,7 +151,7 @@ RTS
0008 0808 0808 0800 0030 1008 0810 3000 0000 0032 4c00 0000 3c42 99a1 a199 423c
]
@body [ ]
@body [ ]
|d000 @ERROR BRK

View File

@ -3,7 +3,7 @@
&Screen { width 2 height 2 pad 4 x 2 y 2 color 1 }
&Sprite { pad 8 x 2 y 2 addr 2 color 1 }
&Label2d { x 2 y 2 color 1 addr 2 width 2 }
&Label2d { x 2 y 2 color 1 addr 2 }
&Rect2d { x1 2 y1 2 x2 2 y2 2 }
&Point2d { x 2 y 2 }