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 ) |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 ## TODOs
### OS Boot Disk ### 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 - Example of button pointing to a subroutine
- GUI: - GUI:
- Line routine - Line routine
- Extra frame buffer addressing? Mirror sprites?
### Assembler ### 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 # cc uxn.c emulator.c -std=c89 -Os -DNDEBUG -g0 -s -Wall -Wno-unknown-pragmas -L/usr/local/lib -lSDL2 -o bin/emulator
# run # run
./bin/assembler examples/dev.mouse.usm bin/boot.rom ./bin/assembler examples/dev.key.usm bin/boot.rom
./bin/emulator bin/boot.rom ./bin/emulator bin/boot.rom

View File

@ -1,91 +1,120 @@
( dev/key ) ( 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 } &Sprite { pad 8 x 2 y 2 addr 2 color 1 }
&Keyboard { key 1 } &Keyboard { key 1 }
&Textarea2d { x1 2 y1 2 x2 2 y2 2 color 1 addr 2 cursor 1 }
&Point2d { x 2 y 2 } &Point2d { x 2 y 2 }
&Rect2d { x1 2 y1 2 x2 2 y2 2 } &Rect2d { x1 2 y1 2 x2 2 y2 2 }
;pos Point2d ;textarea Textarea2d
;rect Rect2d ;rect Rect2d
;color 1 ;color 1
;textlen 2
|0100 @RESET |0100 @RESET
#0010 =textarea.x1 #0040 =textarea.y1 #00c0 =textarea.x2 #0090 =textarea.y2 ,body =textarea.addr
,redraw JSR ,redraw JSR
BRK BRK
|c000 @FRAME |0200 @FRAME
~dev/key #00 EQU ,key-end ROT JMP? POP2 ~dev/key #00 EQU BRK? ( skip on no-key )
( is backspace )
~dev/key #08 NEQ ,no-key-back ROT JMP? POP2 ( backspace )
#00 ,body ~textlen ADD2 STR ,on-erase ~dev/key #08 EQU JMP? POP2
~textlen #0001 SUB2 =textlen
,key-end JMP ( otherwise )
@no-key-back
~dev/key ~textarea.addr #00 ~textarea.cursor ADD2 STR
( incr ) ~textarea.cursor #01 ADD =textarea.cursor
@input-end
~textlen #0001 ADD2 =textlen
~dev/key ,body ~textlen ADD2 STR
,redraw JSR
#00 =dev/key ( release key ) #00 =dev/key ( release key )
@key-end
,redraw JSR
BRK BRK
@redraw @redraw
#02 =color ~textarea.x1 ~textarea.y1 ~textarea.x2 ~textarea.y2 #01 ,fill-rect JSR
#0040 #0040 #0090 #0090 ,fill-rect JSR ~textarea.x1 ~textarea.y1 #0f ~textarea.addr ,draw-textarea JSR
#06 =color ~textarea.x1 #0002 SUB2 ~textarea.y1 #0002 SUB2 ~textarea.x2 #0001 ADD2 ~textarea.y2 #0001 ADD2 #01 ,line-rect JSR
,body #0040 #0040 ,draw-label-multiline JSR
RTS RTS
@draw-label-multiline ( text x1 y1 ) @on-erase
=pos.y =pos.x
@draw-label-multiline-loop ( skip if cursor is at 0 )
( draw ) DUP2 LDR #00 SWP #0008 MUL2 ,font ADD2 =dev/sprite.addr ,input-end ~textarea.cursor #01 LTH JMP? POP2
~pos.y =dev/sprite.y
~pos.x =dev/sprite.x #00 ~dev/key ~textarea.addr #00 ~textarea.cursor ADD2 STR
~color =dev/sprite.color
( incr ) #0001 ADD2 ( decr ) ~textarea.cursor #01 SUB =textarea.cursor
( incr ) ~pos.x #0008 ADD2 =pos.x
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 ) ( detect linebreaks )
DUP2 LDR #0d NEQ ,no-return ROT JMP? POP2 DUP2 LDR #0d NEQ ,no-return ROT JMP? POP2
#0048 =pos.x ~textarea.x1 =dev/sprite.x
~pos.y #0008 ADD2 =pos.y ( incr ) ~dev/sprite.y #0008 ADD2 =dev/sprite.y
( decr ) ~dev/sprite.x #0008 SUB2 =dev/sprite.x
@no-return @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 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 RTS
@draw-sprite
=dev/sprite.x
=dev/sprite.y
=dev/sprite.addr
=dev/sprite.color
RTS
@font ( spectrum-zx font ) @font ( spectrum-zx font )
[ [
0000 0000 0000 0000 0000 2400 7e3c 0000 0000 2400 3c42 0000 0000 6c7c 7c38 1000 0000 0000 0000 0000 0000 2400 7e3c 0000 0000 2400 3c42 0000 0000 6c7c 7c38 1000

View File

@ -3,7 +3,7 @@
&Screen { width 2 height 2 pad 4 x 2 y 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 } &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 } &Rect2d { x1 2 y1 2 x2 2 y2 2 }
&Point2d { x 2 y 2 } &Point2d { x 2 y 2 }