Browse code

Improved movements further

neauoire authored on 10/03/2021 04:26:33
Showing 1 changed files
... ...
@@ -4,9 +4,8 @@
4 4
 	TODO
5 5
 		- Follow cursor when moving out of the screen
6 6
 		- Save/Load
7
-		- Select blank lines
8 7
 		- Real scrolling distance
9
-		- page up/down move with ctrl+arrow
8
+		- Page up/down move with ctrl+arrow
10 9
 		- Double-click select word
11 10
 		- Right-click find next instance of selection
12 11
 		- Mouse down selection
... ...
@@ -14,6 +13,7 @@
14 13
 		- x scroll
15 14
 		- Don't scroll past oef
16 15
 		- Don't draw past eof
16
+		- Draw tab characters
17 17
 )
18 18
 
19 19
 &Console    { pad 8 stdio 1 }
... ...
@@ -162,21 +162,21 @@ BRK
162 162
 
163 163
 		( line number )
164 164
 		,no-click-line ~dev/mouse.x #0010 GTH2 JMP? POP2
165
-			~dev/mouse.y #0008 DIV2 ~scroll.y ADD2 =position.y #0001 =position.x ,select JSR
166
-			,clamp-selection JSR ,redraw JSR ,click-end JMP
165
+			~dev/mouse.y #0008 DIV2 ~scroll.y ADD2 =position.y #0000 =position.x 
166
+			,find-selection JSR DUP2 =selection.from #0001 ADD2 =selection.to
167
+			,redraw JSR ,click-end JMP
167 168
 		@no-click-line
168 169
 
169 170
 		( select body )
170 171
 		~dev/mouse.y #0008 DIV2 ~scroll.y ADD2 =position.y
171 172
 		~dev/mouse.x ~textarea.x1 SUB2 #0007 ADD2 #0007 DIV2 =position.x
172 173
 
173
-		,select JSR
174
+		,find-selection JSR DUP2 =selection.from #0001 ADD2 =selection.to
174 175
 		,redraw JSR
175 176
 
176 177
 	@click-end
177 178
 
178
-	( decr ctrl lock )
179
-	,skip-unlock ~ctrl_lock #00 EQU JMP? POP2 ~ctrl_lock #01 SUB =ctrl_lock @skip-unlock
179
+	( unlock ) ,skip-unlock ~ctrl_lock #00 EQU JMP? POP2 ~ctrl_lock #01 SUB =ctrl_lock @skip-unlock
180 180
 
181 181
 	,draw-cursor JSR
182 182
 
... ...
@@ -201,14 +201,6 @@ RTS
201 201
 
202 202
 RTS
203 203
 
204
-@scroll-up
205
-	
206
-	( clamp ) ~scroll.y #0000 EQU2 RTS?
207
-	( decr ) ~scroll.y #0001 SUB2 =scroll.y
208
-	,redraw JSR
209
-
210
-RTS
211
-
212 204
 @goto-linestart
213 205
 
214 206
 	@goto-linestart-loop
... ...
@@ -244,7 +236,8 @@ RTS
244 236
 		,find-wordstart-end ~j LDR #0a EQU JMP? POP2
245 237
 		,find-wordstart-end ~j LDR #0d EQU JMP? POP2
246 238
 		,find-wordstart-loop ~j ,document.body GTH2 JMP? POP2
247
-	@find-wordstart-end ~j #0001 SUB2
239
+	@find-wordstart-end 
240
+	( return ) ~j #0001 SUB2
248 241
 
249 242
 RTS
250 243
 
... ...
@@ -257,28 +250,39 @@ RTS
257 250
 		,find-wordend-end ~j LDR #0a EQU JMP? POP2
258 251
 		,find-wordend-end ~j LDR #0d EQU JMP? POP2
259 252
 		,find-wordend-loop ~j ,document.body GTH2 JMP? POP2
260
-	@find-wordend-end ~j #0001 ADD2
253
+	@find-wordend-end 
254
+	( return ) ~j #0001 ADD2
261 255
 
262 256
 RTS
263 257
 
264
-@get-position ( selection -> position )
258
+@find-line ( position -> addr )
265 259
 
266
-	,document.body =j #0000 =position.x #0000 =position.y
260
+	,document.body =j #0000 =pt.y
261
+	@find-line-loop
262
+		,find-line-end ~pt.y ~position.y #0001 SUB2 GTH2 JMP? POP2
263
+		,find-line-no-space ~j LDR #0a NEQ ~j LDR #0d NEQ #0101 EQU2 JMP? POP2
264
+			( incr ) ~pt.y #0001 ADD2 =pt.y
265
+		@find-line-no-space
266
+		( incr ) ~j #0001 ADD2 =j
267
+	,find-line-loop ~j LDR #00 NEQ JMP? POP2
268
+	@find-line-end
269
+	( return ) ~j
267 270
 
268
-	@get-position-loop
271
+RTS
269 272
 
270
-		,no-position-space ~j LDR #0a NEQ ~j LDR #0d NEQ #0101 EQU2 JMP? POP2
271
-			( incr ) ~position.y #0001 ADD2 =position.y
272
-			#0000 =position.x
273
-		@no-position-space
273
+@find-selection ( position -> addr )
274 274
 
275
-		,no-position-reached ~j ~selection.from NEQ2 JMP? POP2
276
-			RTS
277
-		@no-position-reached
275
+	,find-line JSR ( find line )
278 276
 
279
-		( incr ) ~position.x #0001 ADD2 =position.x
280
-		( incr ) ~j #0001 ADD2 =j
281
-	,get-position-loop ~j LDR #00 NEQ JMP? POP2
277
+	#0000 =pt.x
278
+
279
+	@find-selection-loop
280
+		,find-selection-end ~j ~pt.x ADD2 LDR #0a EQU JMP? POP2
281
+		,find-selection-end ~j ~pt.x ADD2 LDR #0d EQU JMP? POP2
282
+		( incr ) ~pt.x #0001 ADD2 =pt.x
283
+		,find-selection-loop ~pt.x ~position.x #0001 SUB2 LTH2 JMP? POP2
284
+	@find-selection-end
285
+	( return ) ~pt.x ADD2
282 286
 
283 287
 RTS
284 288
 
... ...
@@ -304,10 +308,11 @@ RTS
304 308
 
305 309
 RTS
306 310
 
311
+( drawing functions )
312
+
307 313
 @redraw
308 314
 
309 315
 	,draw-lines JSR
310
-
311 316
 	,draw-textarea JSR
312 317
 	,draw-scrollbar JSR
313 318
 	,draw-titlebar JSR
... ...
@@ -329,22 +334,18 @@ RTS
329 334
 @draw-lines
330 335
 	
331 336
 	#0000 =j
332
-	#0000 =dev/sprite.x
333
-	#0000 =dev/sprite.y
334
-
337
+	#0000 =dev/sprite.x #0000 =dev/sprite.y
335 338
 	@draw-lines-loop
336
-
337
-		#0000 =dev/sprite.x
338
-		
339 339
 		~scroll.y ~j ADD2 =addr
340
+		#0000 =dev/sprite.x
340 341
 		,font_hex #00 ,addr #0001 ADD2 LDR #f0 AND #04 ROR #08 MUL ADD2 =dev/sprite.addr
341
-		( draw ) #02 ~addr ~position.y EQU2 ADD =dev/sprite.color
342
-		~dev/sprite.x #0008 ADD2 =dev/sprite.x
342
+		( draw ) #02 ~addr ~position.y EQU2 #06 MUL ADD =dev/sprite.color
343
+		#0008 =dev/sprite.x
343 344
 		,font_hex #00 ,addr #0001 ADD2 LDR #0f AND #08 MUL ADD2 =dev/sprite.addr
344
-		( draw ) #02 ~addr ~position.y EQU2 ADD =dev/sprite.color
345
+		( draw ) #02 ~addr ~position.y EQU2 #06 MUL ADD =dev/sprite.color
345 346
 		( incr ) ~j #0001 ADD2 =j
346 347
 		( incr ) ~dev/sprite.y #0008 ADD2 =dev/sprite.y
347
-		,draw-lines-loop ~j ~dev/screen.height #0008 DIV2 NEQ2 JMP? POP2
348
+		,draw-lines-loop ~j ~dev/screen.height #0008 SUB2 #0008 DIV2 NEQ2 JMP? POP2
348 349
 
349 350
 RTS
350 351
 
... ...
@@ -413,11 +414,23 @@ RTS
413 414
 
414 415
 	@draw-textarea-loop
415 416
 
417
+		,draw-textarea-end ~dev/sprite.y ~dev/screen.height #0010 SUB2 GTH2 JMP? POP2
418
+
419
+		( get character )
420
+		,font #00 ~j LDR #20 SUB #0008 MUL2 ADD2 =dev/sprite.addr
421
+
422
+		( draw ) #01 
423
+		~j ~selection.from #0001 SUB2 GTH2 
424
+		~j ~selection.to LTH2 #0101 EQU2
425
+		#05 MUL ADD =dev/sprite.color
426
+
416 427
 		,no-linebreak ~j LDR #0a NEQ ~j LDR #0d NEQ #0101 EQU2 JMP? POP2
417 428
 			( draw linebreak )
418 429
 			,linebreak_icn =dev/sprite.addr
419
-			#02 =dev/sprite.color
420
-
430
+			( draw ) #03
431
+			~j ~selection.from #0001 SUB2 GTH2 
432
+			~j ~selection.to LTH2 #0101 EQU2
433
+			#05 MUL ADD =dev/sprite.color
421 434
 			( fill clear )
422 435
 			@fill-clear
423 436
 				( incr ) ~dev/sprite.x #0008 ADD2 =dev/sprite.x
... ...
@@ -428,16 +441,6 @@ RTS
428 441
 			( incr ) ~dev/sprite.y #0008 ADD2 =dev/sprite.y
429 442
 		@no-linebreak
430 443
 
431
-		,draw-textarea-end ~dev/sprite.y ~dev/screen.height #0010 SUB2 GTH2 JMP? POP2
432
-
433
-		( get character )
434
-		,font #00 ~j LDR #20 SUB #0008 MUL2 ADD2 =dev/sprite.addr
435
-
436
-		( draw ) #01 
437
-		~j ~selection.from #0001 SUB2 GTH2 
438
-		~j ~selection.to LTH2 #0101 EQU2
439
-		#05 MUL ADD =dev/sprite.color
440
-
441 444
 		( incr ) ~j #0001 ADD2 =j
442 445
 		( incr ) ~dev/sprite.x #0007 ADD2 =dev/sprite.x
443 446
 
... ...
@@ -489,10 +492,6 @@ RTS
489 492
 	( selection )
490 493
 	~selection.from ,document.body SUB2 ,draw-short JSR
491 494
 
492
-	( length )
493
-	~dev/screen.width #0040 SUB2 =dev/sprite.x
494
-	~document.eof ,document.body SUB2 ,draw-short JSR
495
-
496 495
 RTS
497 496
 
498 497
 @font_hex ( 0-F TODO: should pull from @font instead.. )