-
Notifications
You must be signed in to change notification settings - Fork 82
/
ed1.src
658 lines (533 loc) · 14.6 KB
/
ed1.src
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
657
658
.page
.subttl ed1 editor initialization & I/O routines (GERMAN)
;//////////////// E D I T O R J U M P T A B L E \\\\\\\\\\\\\\\\\
jmp cint ;initialize editor & screen
jmp disply ;display character in .a, color in .x
jmp lp2 ;get a key from irq buffer into .a
jmp loop5 ;get a chr from screen line into .a
jmp print ;print character in .a
jmp scrorg ;get size of current window (rows,cols) in .x, .y
jmp nat_scnkey ;scan keyboard subroutine (GERMAN)
jmp repeat ;repeat key logic & 'ckit2' to store decoded key
jmp plot ;read or set (.c) cursor position in .x, .y
jmp cursor ;move 8563 cursor subroutine
jmp escape ;execute escape function using chr in .a
jmp keyset ;redefine a programmable function key
jmp irq ;irq entry
jmp init80 ;initialize 80-column character set
jmp swapper ;swap editor local variables (40/80 mode change)
jmp window ;set top left or bottom right (.c) of window
.spare .byte $ff,$ff,$ff
.page
length = 40
linz0 = vicscn ;40 column screen lines
linz1 = linz0+length
linz2 = linz1+length
linz3 = linz2+length
linz4 = linz3+length
linz5 = linz4+length
linz6 = linz5+length
linz7 = linz6+length
linz8 = linz7+length
linz9 = linz8+length
linz10 = linz9+length
linz11 = linz10+length
linz12 = linz11+length
linz13 = linz12+length
linz14 = linz13+length
linz15 = linz14+length
linz16 = linz15+length
linz17 = linz16+length
linz18 = linz17+length
linz19 = linz18+length
linz20 = linz19+length
linz21 = linz20+length
linz22 = linz21+length
linz23 = linz22+length
linz24 = linz23+length
.page
ldtb2 ;screen lines low byte table
.byte <linz0
.byte <linz1
.byte <linz2
.byte <linz3
.byte <linz4
.byte <linz5
.byte <linz6
.byte <linz7
.byte <linz8
.byte <linz9
.byte <linz10
.byte <linz11
.byte <linz12
.byte <linz13
.byte <linz14
.byte <linz15
.byte <linz16
.byte <linz17
.byte <linz18
.byte <linz19
.byte <linz20
.byte <linz21
.byte <linz22
.byte <linz23
.byte <linz24
ldtb1 ;screen lines high byte table
.byte >linz0
.byte >linz1
.byte >linz2
.byte >linz3
.byte >linz4
.byte >linz5
.byte >linz6
.byte >linz7
.byte >linz8
.byte >linz9
.byte >linz10
.byte >linz11
.byte >linz12
.byte >linz13
.byte >linz14
.byte >linz15
.byte >linz16
.byte >linz17
.byte >linz18
.byte >linz19
.byte >linz20
.byte >linz21
.byte >linz22
.byte >linz23
.byte >linz24
.page
vectss .word contrl ;print <ctrl> indirect
.word shiftd ;print <shft> indirect
.word escape ;print <esc> indirect
.word keylog ;keyscan logic indirect
.word keyput ;key buffer indirect
vectse
keycod .word mode1 ;decode matrix for normal keys
.word mode2 ;decode matrix for shifted keys (right keycap legends)
.word mode3 ;decode matrix for C= keys (left keycap legends)
.word mode4 ;decode matrix for control keys
.word mode1 ;decode matrix for alt keys (none- default to norm)
.word mode5 ;decode matrix for caps lock
keyend
.page
;////// S C R E E N & E D I T O R I N I T I A L I Z A T I O N \\\\\\
cint lda #$03
ora d2pra ;set vic bank
sta d2pra
lda #$fb
and r6510 ;turn on character rom
ora #$02 ;point vic to text nybble bank
sta r6510
jsr _clrch ;restore default input/output devices
; initialize editor GLOBAL variables
lda #0
jsr nat_init ;patch for GERMAN keyboard init & SID volume
sta graphm ;set display to full text mode
sta mode ;set display to 40-column vic mode
sta ndx ;clear keyboard queue
sta kyndx ;clear function key index
sta crsw ;clear <cr> flag
sta pause ;clear <ctl>-S flag
sta blnon ;reset vic cursor status
sta charen ;reset vic character fetch to rom
sta vm3 ;8563 text area
lda #$14
sta vm1 ;vic text/character area
lda #$78
sta vm2 ;vic graphic area
lda #>vdccol
sta vm4 ;8563 attribute area
lda ldtb1
sta ldtb1_sa ;default high byte of vic screen lines
lda #10
sta xmax ;set maximum keyboard buffer size
sta blnct ;reset vic cursor blink count
sta blnsw ;start vic cursor blinking
sta delay ;reset delay before a key repeats
lda #4
sta kount ;reset delay between key repeats
jsr taball ;set default tab stops
sta rptflg ;enable key repeats (all keys, .a=$80)
ora mmumcr
sta mmumcr ;enable 40/80 key sense
lda #$60
sta curmod ;reset vdc cursor mode
lda #$d0
sta split ;set split screen division 5 lines up from bottom
.page
; initialize editor LOCAL variables
ldx #localabs-localzp
1$ lda localzp,x
sta .swapbeg,x ;init 40-column vic mode locals
lda localabs,x
sta .swapout,x ;init 80-column 8563 mode locals
dex
bpl 1$
ldx #vectse-vectss-1
3$ lda vectss,x
sta ctlvec,x ;initialize editor indirect vectors
dex
bpl 3$
bit init_status ;skip if nmi or user call
bvs 6$
jsr ascii_din ;GERMAN: scan ASCII/DIN key & set shflag
lda #0
sta decode+1 ;GERMAN: force next call to load key decode tables
jsr nat_scnkey ;GERMAN: download character set per ASCII/DIN key
ldx #pkyend-pkytbl-1
5$ lda pkytbl,x ;initialize programmable key definitions
sta pkybuf,x
dex
bpl 5$
lda #$40 ;flag installation
ora init_status
sta init_status
6$ jsr swapper ;swap in 80-col vars
jsr taball ;initialize 80-col tab stops
jsr sreset ;clear 80-col wrap table
jsr clsr ;clear 80-col text screen
jsr swapper ;swap in 40-col vars
jsr sreset ;clear 40-col wrap table
jsr clsr ;clear 40-col text screen
bit mmumcr ;test 40/80 key & stay in that mode
bmi 10$ ;...branch if 40 (vic) mode (current mode)
jsr swapper ;swap in 80-col mode
10$ rts
.page \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
clsr ;clear the current screen window
jsr home ;start at top of window
1$ jsr scrset ;point to a line
jsr clrln ;clear the line
cpx scbot ;done if it's the last line in the window
inx
bcc 1$
home ldx sctop ;put the cursor at top left of current window
stx tblx ;move to top of window
stx lsxp ; (for input after home or clear)
stu10 ldy sclf ;////// entry from insert/delete line routines
sty pntr ;move to left side of window
sty lstp
stupt ;////// entry to set pointers to beginning of current line
ldx tblx ;.x now points to beginning of line
scrset lda ldtb2,x ;generate pointers to current screen line
bit mode ; (double table values for 80-col mode)
bpl 10$
asl a
10$ sta pnt ;'pnt' points to screen ram
lda ldtb1,x
and #$03
bit mode
bpl 20$
rol a
ora vm3
bcc 30$ ;always
20$ ora ldtb1_sa
30$ sta pnt+1
scolor lda pnt
sta user ;'user' points to color ram
lda pnt+1
bit mode ; (different base adr for 80-col)
bpl 1$
and #$07
ora vm4
bne 2$
1$ and #$03
ora #>viccol
2$ sta user+1
rts
.page \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
;///////////////// E D I T O R I R Q R O U T I N E S \\\\\\\\\\\\\\\\\\
irq
sec
lda vicreg+25 ;is this a vic raster irq?
and #$01
beq 10$ ;...branch if not (just rts with .c=1)
sta vicreg+25 ;clear the raster interrupt bit
lda graphm ;is user controlling vic?
cmp #$ff
10$ beq irqrts ;...branch if so (rts with .c=1)
bit vicreg+17 ;assume 'middle' irq (note .c=0 here)
bmi 20$ ;...branch if not
and #$40 ;make real sure it's a split screen (serial ops may have held irq off)
bne text ;...branch if somewhere in middle of a split screen
20$ sec ;flag 'base' irq
lda graphm ;what will the next frame be?
beq text ;...branch if all text
bit graphm
bvc 30$ ;...branch if not a split screen
lda split
sta vicreg+18 ;split screen: make next irq occur in 'middle' of frame
; set up for a graphic frame
30$ lda r6510
and #$fd ;point vic to graphic (mcm) nybble bank
ora #$04 ;turn off character rom
pha
lda vm2 ;point vic to graphic area
pha
lda vicreg+17 ;turn on bit map mode
and #$7f ; (keep RC8 clear!)
ora #$20
tay
lda vicreg+22 ;turn on/off multicolor mode
bit graphm
bmi 40$
and #$ef ;off
.byte $2c
40$ ora #$10 ;on
tax
bne doit ;always
.page
; set up for a text frame
text lda #$ff ;make next irq occur at 'base' of this or next frame
sta vicreg+18
lda r6510
ora #$02 ;point vic to text nybble bank
and #$fb ;turn on character rom (if enabled)
ora charen
pha
lda vm1 ;point vic to text area
pha
lda vicreg+17 ;turn off bit map mode
and #$5f ; (keep RC8 clear!)
tay
lda vicreg+22 ;turn off multicolor mode
and #$ef
tax
bcs doit ;...branch if at 'base' (not a split screen)
ldx #7
1$ dex
bne 1$ ;delay for clean switchover
nop
nop
tax
; install all precomputed values before vic prefetch of next visible line
doit
pla
sta vicreg+24 ;set vm
pla
sta r6510 ;set charrom + vic nybble bank
sty vicreg+17 ;set bit map mode
stx vicreg+22 ;set muticolor mode
irqrts bcs 10$ ;kludge for 2MHz mode split screen:
lda vicreg+48 ;...in 2MHz mode, RC8=0 always due to faster code
and #$01 ;...and hence skips keyscan, etc.
beq 10$ ;...branch if 1MHz mode
lda graphm
and #$40
beq 10$ ;...branch if not split scren
lda vicreg+17
bpl 10$ ;...branch if raster still not at bottom
sec ;ah-ha! this has to be the 'bottom' irq of a split screen
10$ cli ;allow interruptable keyscan
bcc 20$ ;done if 'middle' irq
jsr nat_scnkey ;do general keyboard scan (GERMAN)
jsr blink ;blink vic cursor
sec ;tell kernal this was the 60hz irq
20$ rts
.page \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
;/////////////// E D I T O R I N P U T R O U T I N E S \\\\\\\\\\\\\\\\
lp2 ;fetch a character from irq key buffer
ldx kyndx ;check for function key strings first
beq 1$ ;...branch if none
ldy keyidx ;get index to current character in key string
lda pkydef,y ;get the character
dec kyndx ;one less character in string
inc keyidx ;index to next character
cli
clc ;always a good return from keyboard
rts
1$
ldy keyd ;get a key from irq buffer (.x=0 from 'lp2')
2$
lda keyd+1,x ;push down buffer contents
sta keyd,x
inx
cpx ndx
bne 2$
dec ndx ;one less key in buffer
tya ;return character in .a
cli
clc ;always a good return from keyboard
rts
loop4 ;fetch characters & display them until <cr>
jsr print ;print the character in .a
waitky jsr crsron ;enable cursor
1$ lda ndx ;wait here for any buffered keystroke
ora kyndx ; (or function key)
beq 1$
jsr crsrof ;disable cursor
jsr lp2 ;get the key from irq key buffer
cmp #cr ;return key?
bne loop4 ;no- buffer to screen until <cr>
sta crsw ;set flag to pass characters from screen
lda #0
sta qtsw ;clear quote mode
jsr fndend ;find last non-blank character in line
stx lintmp ;save last row id ('indx' = last column)
jsr fistrt ;find beginning row of this line
ldy sclf ;assume first character is at left margin
lda lsxp ;input actually began on this row
bmi 4$ ;...branch if it's on a wrapped line
cmp tblx ;is cursor still on this row?
bcc 4$ ;...branch if it's below this row
ldy lstp ;input actually began in this column
cmp lintmp ;does input begin & end on same row?
bne 2$ ;...branch if not
cpy indx ;does input begin & end in same column?
beq 3$ ;...branch if same
2$ bcs clp2 ;...branch if null input
3$ sta tblx ;start input from this row
4$ sty pntr ;start input from this column
jmp lop5 ;go pass characters
loop5 ;///// entry for kernal 'basin' routine \\\\\
tya
pha ; (save current cursor position)
txa
pha
lda crsw ;pass characters? (ie: input device = screen)
beq waitky ;no- buffer (ie: input device = keyboard)
bpl lop5 ;yes- if there're any to pass
clp2
lda #0 ;clear flag- i/o is finished
sta crsw
lda #cr
ldx #3 ;kludge for OPEN4,4 / CMD4 / LIST delemma
cpx dfltn
beq 1$ ;input is from the screen
cpx dflto
beq 2$ ;output is to the screen
1$ jsr print ;force a <cr>
2$ lda #cr ;pass a return as the last character
bne clp7 ;always
.page \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
lop5
jsr stupt ;set 'pnt' and 'user' to beginning of line
jsr get1ch ;get a screen character
sta datax
and #$3f ;convert chr from screen codes...
asl datax
bit datax
bpl 1$ ;...branch if not alt. character set
ora #$80
1$
bcc 2$ ;...branch if not rvs fld character
ldx qtsw
bne 3$
2$
bvs 3$ ;...branch if not shifted character
ora #$40
3$
jsr qtswc ;...toggle quote mode if quote chr
ldy tblx ;check for last non-blank character
cpy lintmp
bcc 4$ ;...branch if not on last input line
ldy pntr
cpy indx
bcc 4$ ;...branch if not on last input column
ror crsw ;make >0 (.c=1) to fake <cr>: this is the last chr
bmi 5$ ;always
4$
jsr nxtchr ;move 'pntr' to next character
5$
cmp #$de ;a pi ?
bne clp7 ;no
lda #$ff ;translate it to true cbm pi
clp7
sta datax
pla ; (restore cursor position for 'basin')
tax
pla
tay
lda datax ;pass character in .a
clc ;always a good return from screen or keyboard
rts
.page \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
qtswc
cmp #quote ;test for quote character
bne 1$ ;it's not
lda qtsw
eor #$01 ;toggle quote flag
sta qtsw
lda #quote
1$ rts
loop2 ;///////////// 'print' exits here \\\\\\\\\\\\\\
lda datax
sta lstchr ;save in case it's <escape> or <home> for next test
jsr cursor ;move cursor ahead of output
lda insrt
beq 1$
lsr qtsw ;clear quote mode in case quote was hit in insert mode
1$
pla ;restore all registers
tay
pla
tax
pla
clc ;good
rts ;will return to 'loop2'
nxt33 ;various entries from 'print' to output a character
ora #$40
nxt3
ldx rvs ;in rvs mode?
beq nvs ;no
nc3
ora #$80
nvs
ldx insrt ;in insert mode?
beq 1$ ;no
dec insrt ;yes- decrement insert field count
1$
bit insflg ;in auto insert mode?
bpl 2$ ;no
pha ;yes- save the character to insert
jsr insert ;make room for it
ldx #0
stx insrt ;disallow the other insert mode
pla
2$
jsr displc ;display chr & fall thru to 'movchr' (will return to 'loop2')
; cpy #69
; bne movchr
; jsr beep ;ring bell (if enabled) to flag right margin
.page \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
; movchr - move to next character position &
; insert blank line if at end of line
; entry: .y = column position
; exit: .c=1 if aborted (scroll disabled)
movchr
cpy scrt
bcc 1$ ;easy if not at end of line
ldx tblx
cpx scbot
bcc 1$ ;...skip if not last line of screen
bit scroll
bmi 3$ ;...abort if scrolling disabled
1$ jsr stupt ;set up 'pnt' and 'user' vectors
jsr nxtchr ;move to next char position
bcc 3$ ;...done if not move to new line
jsr getbit ;check if on a continued line
bcs 2$ ;...skip ahead if not
sec ;in case we abort
bit scroll
bvs 3$
jsr scrdwn ;else insert a blank line
2$ clc ;for clean exit
3$ rts
; skip to next line (wrap to top if scroll disabled)
nxln
ldx tblx
cpx scbot ;of the bottom of window ?
bcc 2$ ;no
bit scroll ;what if scrolling is disabled?
bpl 1$ ;branch if scroll is enabled
lda sctop ;wrap to top
sta tblx
bcs 3$ ;always
1$ jsr scrup ;scroll it all
clc ;indicate scroll ok
2$ inc tblx
3$ jmp stupt ;set pointers to beginning of new line
;.end