Browse code

Started repairing the key example

neauoire authored on 02/03/2021 01:05:04
Showing 4 changed files
... ...
@@ -84,21 +84,6 @@ RTS
84 84
 |FFF8 [ 13fd 1ef3 1bf2 ] ( palette )
85 85
 ```
86 86
 
87
-## Emulator
88
-
89
-### Controller(dev/ctrl)
90
-
91
-A device that works like a NES controller, each button is a bit from a single byte. Press `h` to toggle debugger.
92
-
93
-- `0x01` Ctrl
94
-- `0x02` Alt
95
-- `0x04` Escape
96
-- `0x08` Return
97
-- `0x10` Up
98
-- `0x20` Down
99
-- `0x40` Left
100
-- `0x80` Right
101
-
102 87
 ## TODOs
103 88
 
104 89
 ### OS Boot Disk
... ...
@@ -115,6 +100,7 @@ A device that works like a NES controller, each button is a bit from a single by
115 100
 	- Example of button pointing to a subroutine
116 101
 - GUI:
117 102
 	- Line routine
103
+	- Extra frame buffer addressing? Mirror sprites?
118 104
 
119 105
 ### Assembler
120 106
 
... ...
@@ -20,5 +20,5 @@ cc -std=c89 -DDEBUG -Wall -Wno-unknown-pragmas -Wpedantic -Wshadow -Wextra -Werr
20 20
 # cc uxn.c emulator.c -std=c89 -Os -DNDEBUG -g0 -s -Wall -Wno-unknown-pragmas -L/usr/local/lib -lSDL2 -o bin/emulator
21 21
 
22 22
 # run
23
-./bin/assembler examples/dev.mouse.usm bin/boot.rom
23
+./bin/assembler examples/dev.key.usm bin/boot.rom
24 24
 ./bin/emulator bin/boot.rom
... ...
@@ -1,91 +1,120 @@
1 1
 ( dev/key )
2 2
 
3
-&Screen { width 2 height 2 pad 4 y 2 x 2 color 1 }
3
+&Screen { width 2 height 2 pad 4 x 2 y 2 color 1 }
4 4
 &Sprite { pad 8 x 2 y 2 addr 2 color 1 }
5 5
 &Keyboard { key 1 }
6 6
 
7
+&Textarea2d { x1 2 y1 2 x2 2 y2 2 color 1 addr 2 cursor 1 }
8
+
7 9
 &Point2d { x 2 y 2 }
8 10
 &Rect2d { x1 2 y1 2 x2 2 y2 2 }
9 11
 
10
-;pos Point2d
12
+;textarea Textarea2d
11 13
 ;rect Rect2d
12 14
 ;color 1
13
-;textlen 2
14 15
 
15 16
 |0100 @RESET 
16
-
17
+	
18
+	#0010 =textarea.x1 #0040 =textarea.y1 #00c0 =textarea.x2 #0090 =textarea.y2 ,body =textarea.addr
17 19
 	,redraw JSR
18 20
 
19 21
 BRK
20 22
 
21
-|c000 @FRAME
23
+|0200 @FRAME
24
+
25
+	~dev/key #00 EQU BRK? ( skip on no-key )
26
+
27
+	( backspace )
28
+	,on-erase ~dev/key #08 EQU JMP? POP2
22 29
 
23
-	~dev/key #00 EQU ,key-end ROT JMP? POP2
24
-		( is backspace )
25
-		~dev/key #08 NEQ ,no-key-back ROT JMP? POP2
26
-			#00 ,body ~textlen ADD2 STR
27
-			~textlen #0001 SUB2 =textlen
28
-			,key-end JMP
29
-		@no-key-back
30
+	( otherwise )
30 31
 
31
-		~textlen #0001 ADD2 =textlen
32
-		~dev/key ,body ~textlen ADD2 STR
33
-		,redraw JSR
34
-		#00 =dev/key ( release key )
35
-	@key-end
32
+	~dev/key ~textarea.addr #00 ~textarea.cursor ADD2 STR
33
+
34
+	( incr ) ~textarea.cursor #01 ADD =textarea.cursor
35
+
36
+	@input-end
37
+
38
+	#00 =dev/key ( release key )
39
+
40
+	,redraw JSR
36 41
 
37 42
 BRK
38 43
 
39 44
 @redraw
45
+	
46
+	~textarea.x1 ~textarea.y1 ~textarea.x2 ~textarea.y2 #01 ,fill-rect JSR
47
+	~textarea.x1 ~textarea.y1 #0f ~textarea.addr ,draw-textarea JSR
48
+	~textarea.x1 #0002 SUB2 ~textarea.y1 #0002 SUB2 ~textarea.x2 #0001 ADD2 ~textarea.y2 #0001 ADD2 #01 ,line-rect JSR
49
+
50
+RTS
51
+
52
+@on-erase
53
+	
54
+	( skip if cursor is at 0 )
55
+	,input-end ~textarea.cursor #01 LTH JMP? POP2
40 56
 
41
-	#02 =color
42
-	#0040 #0040 #0090 #0090 ,fill-rect JSR
43
-	#06 =color
44
-	,body #0040 #0040 ,draw-label-multiline JSR
57
+	#00 ~dev/key ~textarea.addr #00 ~textarea.cursor ADD2 STR
58
+
59
+	( decr ) ~textarea.cursor #01 SUB =textarea.cursor
60
+
61
+	BRK
45 62
 
46 63
 RTS
47 64
 
48
-@draw-label-multiline ( text x1 y1 )
49
-	=pos.y =pos.x
50
-	@draw-label-multiline-loop
51
-		( draw ) DUP2 LDR #00 SWP #0008 MUL2 ,font ADD2 =dev/sprite.addr 
52
-		~pos.y =dev/sprite.y
53
-		~pos.x =dev/sprite.x
54
-		~color =dev/sprite.color
55
-		( incr ) #0001 ADD2
56
-		( incr ) ~pos.x #0008 ADD2 =pos.x
65
+@fill-rect ( x1 y1 x2 y2 color )
66
+
67
+	( load ) =color =rect.y2 =rect.x2 DUP2 =dev/screen.y =rect.y1 DUP2 =dev/screen.x =rect.x1
68
+	@fill-rect-ver
69
+		~rect.x1 =dev/screen.x
70
+		@fill-rect-hor
71
+			( draw ) ~color =dev/screen.color
72
+			( incr ) ~dev/screen.x #0001 ADD2 =dev/screen.x
73
+			,fill-rect-hor ~dev/screen.x ~rect.x2 LTH2 JMP? POP2
74
+		( incr ) ~dev/screen.y #0001 ADD2 =dev/screen.y
75
+		,fill-rect-ver ~dev/screen.y ~rect.y2 LTH2 JMP? POP2
76
+
77
+RTS
78
+
79
+@line-rect ( x1 y1 x2 y2 color )
80
+
81
+	( load ) =color =rect.y2 =rect.x2 DUP2 =dev/screen.y =rect.y1 DUP2 =dev/screen.x =rect.x1
82
+	@line-rect-hor
83
+		( incr ) ~dev/screen.x #0001 ADD2 =dev/screen.x
84
+		( draw ) ~rect.y1 =dev/screen.y ~color =dev/screen.color
85
+		( draw ) ~rect.y2 =dev/screen.y ~color =dev/screen.color
86
+		,line-rect-hor ~dev/screen.x ~rect.x2 LTH2 JMP? POP2
87
+	~rect.y1 =dev/screen.y
88
+	@line-rect-ver
89
+		( draw ) ~rect.x1 =dev/screen.x ~color =dev/screen.color
90
+		( draw ) ~rect.x2 =dev/screen.x ~color =dev/screen.color
91
+		( incr ) ~dev/screen.y #0001 ADD2 =dev/screen.y
92
+		,line-rect-ver ~dev/screen.y ~rect.y2 #0001 ADD2 LTH2 JMP? POP2
93
+
94
+RTS
95
+
96
+@draw-textarea ( x y color addr )
97
+	
98
+	( load ) =textarea.addr =textarea.color =dev/sprite.y =dev/sprite.x 
99
+	~textarea.addr
100
+	@draw-textarea-left-loop
101
+		( draw ) DUP2 LDR #00 SWP #0008 MUL2 ,font ADD2 =dev/sprite.addr ~textarea.color =dev/sprite.color
57 102
 
58 103
 		( detect linebreaks )
59 104
 		DUP2 LDR #0d NEQ ,no-return ROT JMP? POP2
60
-			#0048 =pos.x
61
-			~pos.y #0008 ADD2 =pos.y
105
+			~textarea.x1 =dev/sprite.x 
106
+			( incr ) ~dev/sprite.y #0008 ADD2 =dev/sprite.y
107
+			( decr ) ~dev/sprite.x #0008 SUB2 =dev/sprite.x
62 108
 		@no-return
63 109
 
64
-		DUP2 LDR #00 NEQ ,draw-label-multiline-loop ROT JMP? POP2
110
+		( incr ) #0001 ADD2
111
+		( incr ) ~dev/sprite.x #0008 ADD2 =dev/sprite.x
112
+
113
+		DUP2 LDR #00 NEQ ,draw-textarea-left-loop ROT JMP? POP2
65 114
 	POP2
66
-RTS
67 115
 
68
-@fill-rect ( x1 y1 x2 y2 )
69
-	=rect.y2 =rect.x2 ( stash x1 y1 ) =rect.y1 DUP2 WSR2 =rect.x1
70
-	@fill-rect-ver
71
-		RSW2 DUP2 =rect.x1 WSR2
72
-		~rect.y1 =dev/screen.y
73
-		@fill-rect-hor
74
-			( draw ) ~rect.x1 =dev/screen.x ~color =dev/screen.color
75
-			( incr ) ~rect.x1 #0001 ADD2 DUP2 =rect.x1  
76
-			~rect.x2 LTH2 ,fill-rect-hor ROT JMP? POP2
77
-		~rect.y1 #0001 ADD2 DUP2 =rect.y1
78
-		~rect.y2 LTH2 ,fill-rect-ver ROT JMP? POP2
79
-	RSW2 POP2
80 116
 RTS
81 117
 
82
-@draw-sprite
83
-	=dev/sprite.x
84
-	=dev/sprite.y
85
-	=dev/sprite.addr
86
-	=dev/sprite.color
87
-	RTS
88
-
89 118
 @font ( spectrum-zx font ) 
90 119
 [
91 120
 	0000 0000 0000 0000 0000 2400 7e3c 0000 0000 2400 3c42 0000 0000 6c7c 7c38 1000
... ...
@@ -122,7 +151,7 @@ RTS
122 151
 	0008 0808 0808 0800 0030 1008 0810 3000 0000 0032 4c00 0000 3c42 99a1 a199 423c
123 152
 ]
124 153
 
125
-@body          [  ]
154
+@body          [ ]
126 155
 
127 156
 |d000 @ERROR BRK 
128 157
 
... ...
@@ -3,7 +3,7 @@
3 3
 &Screen { width 2 height 2 pad 4 x 2 y 2 color 1 }
4 4
 &Sprite { pad 8 x 2 y 2 addr 2 color 1 }
5 5
 
6
-&Label2d { x 2 y 2 color 1 addr 2 width 2 }
6
+&Label2d { x 2 y 2 color 1 addr 2 }
7 7
 &Rect2d { x1 2 y1 2 x2 2 y2 2 }
8 8
 &Point2d { x 2 y 2 }
9 9