-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmotion.asm
656 lines (560 loc) · 9.33 KB
/
motion.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
;
; VI65 (c) 2010-2013 Soci/Singular ([email protected])
;
; This program is free software; you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation; either version 2 of the License, or
; (at your option) any later version.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with this program; if not, write to the Free Software
; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
;
;m; <h4>j or <Right></h4>
;m; [count] characters to the right. exclusive motion.
motion_l .proc
jsr normcolumn
tax
clc
adc oneless
bcs +
cmp (cursorline),y
blt +
err lsr error
rts
+ stx column
txa
ldx repeat+1
bne tolastchar
clc
adc repeat
bcc tochar
gcs tolastchar
.pend
tolastchar .proc
lda #255
gne tochar
.pend
tochar .proc
jsr normcolumn2
in2 sta column
rts
mode = *-1
.byte 1
.pend
;m; <h4>h or <Left> or CTRL-H</h4>
;m; [count] characters to the left. exclusive motion.
motion_h .proc
jsr normcolumn
cmp #0
beq motion_l.err
ldx repeat+1
bne motion_0
sec
sbc repeat
bcs tochar.in2
gcc motion_0
.pend
;m; <h4>0 or <Home></h4>
;m; To the first character of the line. exclusive
;m; motion.
motion_0 .proc
lda #0
geq tochar.in2
.pend
;m; <h4>g$ or g<End></h4>
;m; To the rightmost
;m; character of the current line that is visible on the
;m; screen. Differs from "$" when the last character of
;m; the line is not on the screen.
;m; Additionally, vertical movements keep the column,
;m; instead of going to the end of the line. inclusive.
motion_gdollar .proc
inc inclusive
lda #width-1
.byte $2c
.cerror motion_g0 & 0
.pend
;m; <h4>g0 or g<Home></h4>
;m; To the leftmost
;m; character of the current line that is on the screen.
;m; Differs from "0" when the first character of the line
;m; is not on the screen. exclusive motion.
motion_g0 .proc
lda #0
.byte $2c
.cerror motion_gm & 0
.pend
;m; <h4>gm</h4>
;m; Like "g0", but half a screenwidth to the right (or as
;m; much as possible). exclusive.
motion_gm .proc
lda #width/2-1
clc
adc column2
bcs tolastchar
gcc tochar
.pend
;m; <h4>^</h4>
;m; To the first non-blank character of the line. exclusive.
motion_uparrow .proc
ldy #4
lda (cursorline),y
tax
inx
lda #32
- iny
dex
beq +
cmp (cursorline),y
beq -
+ tya
sec
sbc #5
gcs tochar
.pend
;m; <h4>|</h4>
;m; To screen column [count] in the current line.
;m; exclusive motion.
motion_bar .proc
lda repeat+1
bne line_end
ldx repeat
dex
.byte $2c
.cerror line_end & 0
.pend
line_end .proc
ldx #255
stx column
rts
.pend
.if SIMPLE
motion_dollar = line_end
.else
;m; <h4>$ or <End></h4>
;m; To the end of the line. When a count is given also go
;m; [count - 1] lines downward inclusive.
motion_dollar .proc
inc inclusive
jsr line_end
lda #0
jsr sbcrepeat
ora repeat
bne motion_j
rts
.pend
;m; <h4>t{char}</h4>
;m; Till before [count]'th occurrence of {char} to the
;m; right. The cursor is placed on the character left of
;m; {char}. inclusive.
motion_t .proc
clc
.byte $a9
.pend
;m; <h4>f{char}</h4>
;m; To [count]'th occurrence of {char} to the right. The
;m; cursor is placed on {char}. inclusive.
motion_f .proc
sec
in php
jsr waitkey
tax
lda repeat+1
bne x2
ldy #4
tya
sec
adc (cursorline),y
sta m+1
tya
sec
adc column
tay
txa
- iny
m cpy #0
bge x2
cmp (cursorline),y
bne -
dec repeat
bne -
tya
plp
sbc #5
inc inclusive
gcs tochar
x2 lsr error
plp
rts
.pend
.fi
.if !SIMPLE
;m; <h4>T</h4>
;m; Till after [count]'th occurrence of {char} to the
;m; left. The cursor is placed on the character right of
;m; {char} exclusive.
motion_T .proc
sec
.byte $a9
.pend
;m; <h4>F</h4>
;m; To the [count]'th occurrence of {char} to the left.
;m; The cursor is placed on {char} exclusive.
motion_F .proc
clc
in php
jsr waitkey
tax
lda repeat+1
bne motion_f.x2
lda column
clc
adc #5
tay
txa
- dey
cpy #5
blt motion_f.x2
cmp (cursorline),y
bne -
dec repeat
bne -
tya
plp
sbc #4
gcs tochar
.pend
.fi
.if !SIMPLE
;m; <h4>L</h4>
;m; To line [count] from bottom of window (default: Last
;m; line on the window) on the first non-blank character
;m; linewise.
motion_L .proc
lda repeat+1
bne +
lda #height-1
sec
sbc repeat
bcs motion_M.in
+ lda #0
geq motion_M.in
.pend
;m; <h4>H</h4>
;m; To line [count] from top (Home) of window (default:
;m; first line on the window) on the first non-blank
;m; character linewise.
motion_H .proc
lda repeat+1
bne j
lda repeat
cmp #height
blt +
j lda #height-2
+ sbc #0
.byte $2c
.cerror motion_M & 0
.pend
;m; <h4>M</h4>
;m; To Middle line of window, on the first non-blank
;m; character linewise.
motion_M .proc
lda #height/2-1
in inc linewise
clc
adc line2
tax
lda #0
adc line2+1
jsr tolineadd
jmp motion_uparrow
.pend
.fi
;m; <h4>G</h4>
;m; Goto line [count], default last line, on the first
;m; non-blank character linewise.
motion_G .proc
ldx waitkeyrepeat.norepeat
beq motion_gg
ldx lines
lda lines+1
jmp motion_gg.in
.pend
;m; <h4>gg</h4>
;m; Goto line [count], default first line, on the first
;m; non-blank character linewise.
motion_gg .proc
ldx repeat
lda repeat+1
in cpx #1
dex
sbc #0
jsr toline
inc linewise
jmp motion_uparrow
.pend
tolinesub bge toline
lda #0
tax
tolineadd bge toline.max
toline .proc
tay
cpx lines
sbc lines+1
blt +
max ldy lines+1
ldx lines
bne r
tya
beq +
dey
r dex
+ stx l1+1
sty l2+1
- lda line
sec
l1 sbc #0
tax
lda line+1
l2 sbc #0
blt f
bne b
txa
bne b
err rts
b jsr cursorprev
jmp -
f jsr cursornext
jmp -
.pend
cursorprev .proc
lda line
bne +
dec line+1
+ dec line
- ldy #2
lda (cursorline),y
tax
iny
lda (cursorline),y
sta cursorline+1
stx cursorline
iny
lda (cursorline),y
cmp #255 ;reference? skip
beq -
rts
.pend
cursornext .proc
inc line
bne +
inc line+1
+
- ldy #1
lda (cursorline),y
tax
dey
lda (cursorline),y
sta cursorline
stx cursorline+1
ldy #4
lda (cursorline),y
cmp #255 ;reference? skip
beq -
rts
.pend
islastline .proc
lda lines
clc
sbc line
bne +
lda lines+1
sbc line+1
+ rts
.pend
;m; <h4>j or <Down> or CTRL-J or CTRL-N or <NL></h4>
;m; [count] lines downward linewise.
motion_j .proc
jsr islastline
bne +
err lsr error
rts
+ lda line
clc
adc repeat
tax
lda line+1
adc repeat+1
jsr tolineadd
inc linewise
rts
.pend
;m; <h4>k or <Up> or CTRL-P</h4>
;m; [count] lines upward linewise.
motion_k .proc
lda line
ora line+1
beq motion_j.err
inc linewise
lda line
sec
sbc repeat
tax
lda line+1
sbc repeat+1
jsr tolinesub
inc linewise
rts
.pend
;m; <h4>- <minus></h4>
;m; [count] lines upward, on the first non-blank
;m; character linewise.
motion_minus .proc
jsr motion_k
jmp motion_plus.in
.pend
;m; <h4>+ or CTRL-M or <CR></h4>
;m; [count] lines downward, on the first non-blank
;m; character linewise.
motion_plus .proc
jsr motion_j
in bit error
bmi motion_uparrow
rts
.pend
;n; <h4>m{a-z}</h4>
;n; Set mark {a-z} at cursor position
motion_m .proc ;A-Z?
jsr waitkey
sec
sbc #"a"
blt setmark.x
cmp #"z"-"a"+1
bge setmark.x
sta r+1
asl
r adc #0
tax
.cerror setmark & 0
.pend
setmark .proc
lda line
sta marks,x
lda line+1
sta marks+1,x
jsr normcolumn
sta marks+2,x
x rts
.pend
;m; <h4>'{a-z}</h4>
;m; The cursor is positioned on the first non-blank
;m; character in the line of the specified location and
;m; the motion is linewise.
motion_tick .proc
inc linewise
.cerror motion_backtick & 0
.pend
;m; <h4>`{a-z[]} or <-{a-z[]}</h4>
;m; The cursor is positioned at the specified location
;m; and the motion is exclusive.
motion_backtick .proc
jsr waitkey
cmp #"["
beq st
cmp #"]"
beq en
+ sec
sbc #"a"
blt baj
cmp #"z"-"a"+1
bge baj
sta r+1
asl
r adc #0
tay
.byte $2c
st ldy #marks.start
.byte $2c
en ldy #marks.end
lda marks+2,y
cmp #255
beq baj
pha
ldx marks,y
lda marks+1,y
jsr toline
pla
jmp tochar
baj rts
.pend
;n; <h4><backspace></h4>
;n; Move backward.
motion_backspace .proc
jsr normcolumn
ora line
ora line+1
bne do
lsr error
rts
- lda line
ora line+1
beq veg
jsr cursorprev
jsr tolastchar
do pha column
jsr motion_h
pla
sec
sbc column
jsr sbcrepeat
bge -
veg sec
ror error
rts
.pend
sbcrepeat .proc
eor #255
clc
adc repeat
sta repeat
lda #255
adc repeat+1
sta repeat+1
rts
.pend
;n; <h4><space></h4>
;n; Move forward.
motion_space .proc
jsr normcolumn
tax
clc
adc oneless
bcs do
cmp (cursorline),y
blt do
jsr islastline
bne do
lsr error
rts
- jsr islastline
beq veg
jsr cursornext
jsr motion_0
do pha column
jsr motion_l
pla
eor #255
sec
adc column
jsr sbcrepeat
bge -
veg sec
ror error
rts
.pend