Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1 | - | 1 | |
2 | ; need for include CRTC |
||
3 | _VBB_INC_ .SET 1 |
||
4 | _KBD_INC_ .SET 1 |
||
5 | |||
6 | .INCLUDE inc\global.inc |
||
7 | .LIST off |
||
8 | .INCLUDE inc\dirp00.inc |
||
9 | .INCLUDE inc\dirp01.inc |
||
10 | .LIST on |
||
11 | .INCLUDE inc\dpqedt.inc |
||
12 | |||
13 | .CODEFD |
||
14 | .LONGA off |
||
15 | .LONGI off |
||
16 | |||
17 | ;--------------------------------------------------- |
||
18 | |||
19 | ; editor main loop |
||
20 | editor: |
||
21 | jsr setcurs ; set cursor mode |
||
22 | ?10: ldy scol ; current screen column |
||
23 | jsr edcurs ; set cursor position on edit window |
||
24 | jsr showcurs ; show cursor |
||
25 | ?12: KBGETIN ; system call - get key |
||
26 | tax |
||
27 | bne ?14 ; a key was pressed |
||
28 | jsr garbc ; call garbage collection |
||
29 | lda #$02 ; update caps & num only |
||
30 | tsb slfg |
||
31 | jsr updsl |
||
32 | bra ?12 |
||
33 | ?14: sta ctmp ; store key code |
||
34 | xba |
||
35 | sta ctmp2 ; store control key flag |
||
36 | jsr hidecurs |
||
37 | lda >DP01ADDR+KbdFlag |
||
38 | sta keyfg ; flag ALT, CTL, SHIFT |
||
39 | lda ctmp ; A = key code |
||
40 | bit ctmp2 ; check control key flag |
||
41 | bpl ?22 ; no-control key |
||
42 | cmp #KB_ALTF1 ; ALT-F1..ALT-F11 switch buffer |
||
43 | bcc ?16 |
||
44 | cmp #KB_ALTF12 |
||
45 | bcs ?16 |
||
46 | sbc #KB_ALTF1-1 |
||
47 | cmp xbuf ; is the current buffer? |
||
48 | beq ?10 ; yes, skip |
||
49 | jsr ?50 ; switch to buffer |
||
50 | bra ?10 ; loop |
||
51 | ?16: ldx #KEYTBLLEN ; check control key |
||
52 | ?18: cmp >KEYTBL,x |
||
53 | beq ?20 |
||
54 | dex |
||
55 | bpl ?18 |
||
56 | bmi ?10 ; discard |
||
57 | ?20: txa |
||
58 | asl a |
||
59 | tax |
||
60 | jsr (KEYPROC,x) ; execute key control function |
||
61 | bra ?23 ; loop |
||
62 | ?22: tax ; no-control key |
||
63 | bmi ?10 ; discard if key code >= 128 |
||
64 | jsr ?80 ; no-control key process |
||
65 | ?23: bit edtfg ; test bit 7 for quit command |
||
66 | bpl ?10 ; loop |
||
67 | ?24: rts |
||
68 | |||
69 | ; switch current edit buffer |
||
70 | ?50: jsr switchb |
||
71 | bcs ?24 ; memory error |
||
72 | stz fslct ; clear select mode flag |
||
73 | lda #$01 |
||
74 | trb slfg |
||
75 | lda #$0C |
||
76 | sta srow |
||
77 | lda #$27 |
||
78 | sta scol |
||
79 | ldx xbuf |
||
80 | lda #$40 |
||
81 | trb edtfg ; clear clipboard flag |
||
82 | cpx #CLIPBRD |
||
83 | bne ?52 |
||
84 | tsb edtfg ; set clipboard flag |
||
85 | ?52: tsb slfg ; force update status line |
||
86 | lda cursmode |
||
87 | and #$BF ; mask off bit 6 |
||
88 | bit bflag |
||
89 | bvs ?54 ; overwrite mode => block cursor |
||
90 | ora #$40 ; insert mode => underline cursor |
||
91 | ?54: sta cursmode |
||
92 | jsr setcurs |
||
93 | jmp updwin |
||
94 | |||
95 | ; process key code < 128 |
||
96 | ?76: txa |
||
97 | asl a |
||
98 | tax |
||
99 | jmp (KEYPROC2,x) |
||
100 | ?80: cmp #' ' |
||
101 | bcs edkey ; printable key code, insert in buffer |
||
102 | ldx #KEYTBLLEN2 ; find function for key code < 32 |
||
103 | ?84: cmp >KEYTBL2,x |
||
104 | beq ?76 |
||
105 | dex |
||
106 | bpl ?84 |
||
107 | kpx: rts ; discard |
||
108 | |||
109 | ; P12AF: |
||
110 | edkey: |
||
111 | LDX fslct |
||
112 | bne kpx |
||
113 | LDX ccnt |
||
114 | CPX #MAXTEXTLEN-1 |
||
115 | beq kpx |
||
116 | LDX ccol |
||
117 | CPX ecol |
||
118 | bcc kpx |
||
119 | tax |
||
120 | ACC16 |
||
121 | lda cline |
||
122 | cmp #MAXLINES |
||
123 | ACC08 |
||
124 | bcs kpx |
||
125 | txa |
||
126 | JSR insert |
||
127 | bcs kpx |
||
128 | JSR incptr2 |
||
129 | LDX ccol |
||
130 | INX |
||
131 | STX ccol |
||
132 | STX xcol |
||
133 | INC ccnt |
||
134 | JSR getbyte2 |
||
135 | BCC ?02 |
||
136 | LDA #$0D ; new line |
||
137 | JSR insert |
||
138 | BCC ?01 |
||
139 | ?00: JSR decptr2 ; error |
||
140 | JMP delbyte |
||
141 | ?01: ACC16 |
||
142 | lda ncount |
||
143 | inc a |
||
144 | cmp #MAXLINES |
||
145 | ACC08 |
||
146 | bcs ?00 ; no insert a new line |
||
147 | INC scol |
||
148 | JSR mvpp2 |
||
149 | JSR nextln |
||
150 | ACC16 |
||
151 | LDA ppage |
||
152 | STA pp6 |
||
153 | inc ncount |
||
154 | ACC08 |
||
155 | LDA ixb |
||
156 | STA ix6 |
||
157 | JSR pp2mv |
||
158 | INC rcnt |
||
159 | JMP updwin0 |
||
160 | ?02: LDA scol |
||
161 | CMP #COLX |
||
162 | BCC ?03 |
||
163 | INC ecol |
||
164 | JSR scrlright |
||
165 | bra updrow8 |
||
166 | ?03: INC scol |
||
167 | |||
168 | ; P145F: |
||
169 | updrow8: |
||
170 | ACC16 |
||
171 | lda curs |
||
172 | sta stxtp |
||
173 | ora #!TXTATTR |
||
174 | sta sattp |
||
175 | ACC08 |
||
176 | LDX pp8 |
||
177 | lda pp8+1 |
||
178 | LDY ix8 |
||
179 | JSR setptr |
||
180 | lda #$01 ; no update window while indent... |
||
181 | bit edtfg ; ... blank's insertion |
||
182 | bne tbx |
||
183 | JSR updrow |
||
184 | JMP updsl |
||
185 | |||
186 | ; tasto TAB |
||
187 | ; P313E: |
||
188 | tabkey: |
||
189 | lda #0 |
||
190 | ?0: clc |
||
191 | ?1: adc deftab |
||
192 | cmp ccol |
||
193 | beq ?0 |
||
194 | bcc ?1 |
||
195 | SBC ccol |
||
196 | STA ctmp2 |
||
197 | ?02: LDA ccol |
||
198 | CMP ccnt |
||
199 | BNE ?03 |
||
200 | LDA #$20 |
||
201 | JSR edkey |
||
202 | bra ?04 |
||
203 | ?03: jsr csrrght |
||
204 | ?04: DEC ctmp2 |
||
205 | BNE ?02 |
||
206 | tbx: RTS |
||
207 | |||
208 | ; 'del' key |
||
209 | ; execute 'csrright' and after a 'backkey' |
||
210 | delkey: |
||
211 | LDX ccol |
||
212 | CPX ccnt |
||
213 | BEQ tbx |
||
214 | INX |
||
215 | STX ccol |
||
216 | STX xcol |
||
217 | JSR incptr2 |
||
218 | LDA scol |
||
219 | CMP #COLX |
||
220 | BCC ?01 |
||
221 | INC ecol |
||
222 | bra backkey |
||
223 | ?01: INC scol |
||
224 | |||
225 | ; tasto BACKSPACE |
||
226 | ; P1316: |
||
227 | backkey: |
||
228 | LDA fslct |
||
229 | bne ?02 |
||
230 | LDA ccol |
||
231 | CMP ecol |
||
232 | bcc ?02 |
||
233 | JSR decptr2 |
||
234 | bcs ?02 |
||
235 | JSR getbyte2 |
||
236 | CMP #$0D |
||
237 | BEQ ?03 |
||
238 | JSR delbyte |
||
239 | DEC ccol |
||
240 | LDA ccol |
||
241 | STA xcol |
||
242 | DEC ccnt |
||
243 | JSR nextln8 |
||
244 | JSR updrow8 |
||
245 | JSR xcount |
||
246 | INX |
||
247 | CPX scol |
||
248 | BEQ ?01 |
||
249 | DEC ecol |
||
250 | JMP scrlleft |
||
251 | ?01: DEC scol |
||
252 | ?02: RTS |
||
253 | ?03: JSR mvpp2 |
||
254 | JSR incptr2 |
||
255 | JSR startln |
||
256 | JSR nextln |
||
257 | STX ctmp |
||
258 | JSR nextln |
||
259 | JSR pp2mv |
||
260 | TXA |
||
261 | CLC |
||
262 | ADC ctmp |
||
263 | BCC ?04 |
||
264 | JMP incptr2 |
||
265 | ?04: CMP #MAXTEXTLEN |
||
266 | BCC ?05 |
||
267 | JMP incptr2 |
||
268 | ?05: JSR incptr2 |
||
269 | JSR getbyte2 |
||
270 | BCC ?08 |
||
271 | JSR decptr2 |
||
272 | JSR decptr2 |
||
273 | BCS ?09 |
||
274 | JSR getbyte2 |
||
275 | CMP #$0D |
||
276 | BEQ ?06 |
||
277 | JSR incptr2 |
||
278 | JMP incptr2 |
||
279 | ?06: JSR incptr2 |
||
280 | bra ?09 |
||
281 | ?08: JSR decptr2 |
||
282 | ?09: ACC16 |
||
283 | dec cline |
||
284 | dec ncount ; check this !! |
||
285 | ACC08 |
||
286 | JSR delbyte |
||
287 | LDA #COLX |
||
288 | STA scol |
||
289 | LDA srow |
||
290 | CMP #$0D |
||
291 | bcs ?10 |
||
292 | JSR startln4 |
||
293 | BCC ?11 |
||
294 | ?10: JSR nextln6 |
||
295 | JSR decrow |
||
296 | ?11: JMP updwin0 |
||
297 | |||
298 | ; tasto CURSORE SX |
||
299 | ; P1D31: |
||
300 | csrleft: |
||
301 | LDX ccol |
||
302 | CPX ecol |
||
303 | BCS ?01 |
||
304 | STX xcol |
||
305 | DEC ecol |
||
306 | JMP scrlleft |
||
307 | ?01: CPX #$00 |
||
308 | BEQ slt |
||
309 | DEX |
||
310 | STX ccol |
||
311 | STX xcol |
||
312 | JSR decptr2 |
||
313 | LDA scol |
||
314 | CMP #$05 |
||
315 | BCS ?02 |
||
316 | JSR xcount |
||
317 | INX |
||
318 | CPX scol |
||
319 | BEQ ?02 |
||
320 | DEC ecol |
||
321 | JSR scrlleft |
||
322 | JMP updsl |
||
323 | ?02: DEC scol |
||
324 | JMP updsl |
||
325 | |||
326 | ; tasto CURSORE DX |
||
327 | ; P1D0C: |
||
328 | csrrght: |
||
329 | LDX ccol |
||
330 | CPX ccnt |
||
331 | BEQ slt |
||
332 | INX |
||
333 | STX ccol |
||
334 | STX xcol |
||
335 | JSR incptr2 |
||
336 | LDA scol |
||
337 | CMP #COLX |
||
338 | BCC ?01 |
||
339 | INC ecol |
||
340 | JSR scrlright ; scroll right |
||
341 | JMP updsl |
||
342 | ?01: INC scol |
||
343 | JMP updsl |
||
344 | |||
345 | ; toggle select mode flag |
||
346 | ; P1F22: |
||
347 | seltxt: |
||
348 | LDA fslct |
||
349 | BEQ ?01 |
||
350 | STZ fslct ; clear if enabled |
||
351 | JMP updwin0 |
||
352 | ?01: JSR getbyte |
||
353 | BCS slt |
||
354 | INC fslct |
||
355 | LDA pp8 |
||
356 | STA pp0 |
||
357 | LDA pp8+1 |
||
358 | STA pp0+1 |
||
359 | LDA ix8 |
||
360 | STA ix0 |
||
361 | STZ nslctl |
||
362 | stz nslcth |
||
363 | jsr updsl |
||
364 | slt: RTS |
||
365 | |||
366 | ; tasto CURSORE UP |
||
367 | ; P1D66: |
||
368 | csrup: |
||
369 | LDA srow |
||
370 | CMP #$07 |
||
371 | BCC ?01 |
||
372 | JSR decrow |
||
373 | bra ?03 |
||
374 | ?01: JSR startln4 |
||
375 | BCC ?02 |
||
376 | LDA srow |
||
377 | beq slt ; exit |
||
378 | JSR decrow |
||
379 | bra ?03 |
||
380 | ?02: JSR startln6 |
||
381 | JSR scrlup |
||
382 | JSR updfst |
||
383 | ?03: JSR pp8mv |
||
384 | JSR startln |
||
385 | JSR mvpp8 |
||
386 | LDX xcol |
||
387 | JSR xcnt2 |
||
388 | LDA fslct |
||
389 | BEQ ?07 |
||
390 | ACC16CLC |
||
391 | lda curs |
||
392 | dec nslctl |
||
393 | bpl ?05 |
||
394 | ADC #MAXCOLS |
||
395 | ?05: STA stxtp |
||
396 | ACC08 |
||
397 | JSR revrow |
||
398 | ?07: ACC16 |
||
399 | dec cline |
||
400 | ACC08 |
||
401 | JMP updsl |
||
402 | |||
403 | ; tasto CURSORE DOWN |
||
404 | ; P1E62: |
||
405 | csrdwn: |
||
406 | JSR getbyte2 |
||
407 | bcs slt ; exit if end of buffer |
||
408 | LDA srow |
||
409 | CMP #$11 |
||
410 | BCS ?01 |
||
411 | JSR incrow |
||
412 | bra ?03 |
||
413 | ?01: JSR scrldown |
||
414 | JSR nextln4 |
||
415 | JSR nextln6 |
||
416 | BCS ?02 |
||
417 | JSR updlst |
||
418 | bra ?03 |
||
419 | ?02: JSR clrlst |
||
420 | ?03: JSR nextln |
||
421 | JSR mvpp8 |
||
422 | LDX xcol |
||
423 | JSR xcnt2 |
||
424 | LDA fslct |
||
425 | ACC16CLC |
||
426 | BEQ ?07 |
||
427 | lda curs |
||
428 | bit nslctl |
||
429 | bmi ?05 |
||
430 | SBC #MAXCOLS-1 ; take in account CF = 0 ! |
||
431 | ?05: sta stxtp |
||
432 | ACC08 |
||
433 | JSR revrow |
||
434 | ACC16 |
||
435 | inc nslctl |
||
436 | ?07: inc cline |
||
437 | ACC08 |
||
438 | JMP updsl |
||
439 | |||
440 | ; SHIFT+END -> fine linea |
||
441 | ; P310D: |
||
442 | goendln: |
||
443 | JSR nextln |
||
444 | BCS ?01 |
||
445 | JSR decptr2 |
||
446 | ?01: LDA #COLX |
||
447 | STA scol |
||
448 | JMP updwin0 |
||
449 | |||
450 | ; ; SHIFT+HOME -> inizio linea |
||
451 | ; P311D: |
||
452 | gostartln: |
||
453 | JSR nextln |
||
454 | BCS ?01 |
||
455 | JSR startln |
||
456 | ?01: JMP updwin0 |
||
457 | |||
458 | ; P1EC8: |
||
459 | pagedwn: |
||
460 | LDA #$14 |
||
461 | STA ctmp |
||
462 | ?01: JSR nextln |
||
463 | BCS ?03 |
||
464 | LDA fslct |
||
465 | ACC16 |
||
466 | BEQ ?02 |
||
467 | INC nslctl |
||
468 | ?02: INC cline |
||
469 | ACC08 |
||
470 | ?03: DEC ctmp |
||
471 | BNE ?01 |
||
472 | LDA #$11 |
||
473 | bra epage |
||
474 | |||
475 | ; P1EF1: |
||
476 | pageup: |
||
477 | LDA #$14 |
||
478 | STA ctmp |
||
479 | JSR pp8mv |
||
480 | ?01: JSR startln |
||
481 | BCS ?05 |
||
482 | LDA fslct |
||
483 | ACC16 |
||
484 | BEQ ?03 |
||
485 | DEC nslctl |
||
486 | ?03: DEC cline |
||
487 | ACC08 |
||
488 | ?05: DEC ctmp |
||
489 | BNE ?01 |
||
490 | LDA #$06 |
||
491 | |||
492 | ; P1F1D: |
||
493 | epage: |
||
494 | STA srow |
||
495 | jmp updwin |
||
496 | |||
497 | ; HOME - inizio buffer |
||
498 | ; P30C5: |
||
499 | gohome: |
||
500 | ACC16 |
||
501 | LDA pbuf ; set current block to first block |
||
502 | STA ppage |
||
503 | LDX #BSTART |
||
504 | STX ixb |
||
505 | LDX fslct |
||
506 | BEQ ?01 ; no selection |
||
507 | SEC |
||
508 | LDA nslctl ; update selection range |
||
509 | SBC cline |
||
510 | STA nslctl |
||
511 | ?01: STZ cline ; current line = 0 |
||
512 | ACC08 |
||
513 | bra updwin |
||
514 | |||
515 | ; END - fine buffer |
||
516 | ; P30EC: |
||
517 | goend: |
||
518 | ACC16 |
||
519 | ?00a: lda [pblk] |
||
520 | beq ?00b |
||
521 | sta ppage |
||
522 | bra ?00a |
||
523 | ?00b: ACC08 |
||
524 | ldy #BSTART |
||
525 | sty ixb |
||
526 | jsr nextln |
||
527 | bcs ?04 |
||
528 | jsr decptr2 |
||
529 | jsr decptr2 |
||
530 | ?00c: jsr nextln |
||
531 | bcc ?00c |
||
532 | ACC16 |
||
533 | lda ncount |
||
534 | ldy fslct |
||
535 | beq ?02 |
||
536 | sta wtmp |
||
537 | sec |
||
538 | sbc cline |
||
539 | clc |
||
540 | adc nslctl |
||
541 | sta nslctl |
||
542 | lda wtmp |
||
543 | ?02: sta cline |
||
544 | ACC08 |
||
545 | ?04: LDA #$11 ; set screen row |
||
546 | STA srow |
||
547 | bra updwin |
||
548 | |||
549 | ; tasto SHIFT RETURN |
||
550 | ; P3129: |
||
551 | kshenter: |
||
552 | LDA fslct |
||
553 | beq kshe |
||
554 | kshr: rts |
||
555 | kshe: JSR nextln ; find next line |
||
556 | BCS ke2 |
||
557 | JSR decptr2 ; decrement pointer |
||
558 | bra ke2 |
||
559 | |||
560 | ; tasto RETURN |
||
561 | ; P288F: |
||
562 | kenter: |
||
563 | LDX fslct |
||
564 | bne kshr |
||
565 | ke2: jsr xblank ; count of starting blanks |
||
566 | jsr inscr ; insert byte $0D (enter key code) |
||
567 | bcs kshr ; error |
||
568 | JSR incptr2 |
||
569 | LDA srow |
||
570 | CMP #$11 |
||
571 | BCS ?02 |
||
572 | JSR incrow ; increment cursor row |
||
573 | JSR startln6 |
||
574 | bra ?03 |
||
575 | ?02: JSR nextln4 |
||
576 | ?03: STZ scol ; screen column = 0 |
||
577 | ACC16 |
||
578 | INC cline ; increment current line |
||
579 | inc ncount |
||
580 | ?05: ACC08 |
||
581 | jsr indent |
||
582 | |||
583 | ; P19DB: |
||
584 | updwin0: |
||
585 | LDA #$00 ; no cursor address update |
||
586 | BEQ updatew |
||
587 | |||
588 | ; P19E0: |
||
589 | updwin: |
||
590 | LDA #$01 ; update cursor address |
||
591 | |||
592 | ; P19E3: |
||
593 | updatew: |
||
594 | PHA |
||
595 | JSR mvpp2 |
||
596 | JSR getbyte |
||
597 | BCS ?02 |
||
598 | JSR incptr |
||
599 | JSR startln |
||
600 | DEX |
||
601 | bra ?03 |
||
602 | ?02: LDX #$00 |
||
603 | ?03: STX ccol ; update current editor column |
||
604 | STX xcol |
||
605 | TXA |
||
606 | SEC |
||
607 | SBC scol |
||
608 | BCS ?04 |
||
609 | LDA ccol |
||
610 | STA scol |
||
611 | LDA #$00 |
||
612 | ?04: STA ecol |
||
613 | JSR mvpp8 |
||
614 | JSR nextln |
||
615 | STX ccnt |
||
616 | lda $01,s |
||
617 | BEQ ?05 |
||
618 | JSR pp8mv |
||
619 | JSR findrow |
||
620 | ?05: JSR chksel |
||
621 | ACC16 |
||
622 | sec |
||
623 | LDA #!TXTADDR |
||
624 | SBC #MAXCOLS |
||
625 | STA stxtp |
||
626 | sec |
||
627 | LDA #!TXTATTR |
||
628 | SBC #MAXCOLS |
||
629 | sta sattp |
||
630 | ACC08 |
||
631 | LDA #$FF |
||
632 | STA ctmp |
||
633 | LDX pp4 |
||
634 | lda pp4+1 |
||
635 | LDY ix4 |
||
636 | JSR setptr |
||
637 | ?06: ACC16CLC |
||
638 | LDA stxtp |
||
639 | ADC #MAXCOLS |
||
640 | sta stxtp |
||
641 | clc |
||
642 | LDA sattp |
||
643 | ADC #MAXCOLS |
||
644 | sta sattp |
||
645 | ACC08 |
||
646 | INC ctmp |
||
647 | LDA fslct |
||
648 | BEQ ?07 |
||
649 | LDA ctmp |
||
650 | CMP rslctl |
||
651 | BCC ?07 |
||
652 | CMP rslcth |
||
653 | BCS ?07 |
||
654 | LDA #$80 |
||
655 | STA frev |
||
656 | ?07: JSR updrow |
||
657 | BCS ?08 |
||
658 | LDA ctmp |
||
659 | CMP #$17 |
||
660 | BNE ?06 |
||
661 | CLC |
||
662 | ?08: lda $01,s |
||
663 | BEQ ?11 |
||
664 | LDA >updr1+2 ; page |
||
665 | BCS ?09 |
||
666 | STA ppage |
||
667 | lda sbank ; bank |
||
668 | STA ppage+1 |
||
669 | STX ixb |
||
670 | JSR startln |
||
671 | LDA ppage |
||
672 | STA pp6 |
||
673 | LDA ppage+1 |
||
674 | STA pp6+1 |
||
675 | LDA ixb |
||
676 | STA ix6 |
||
677 | bra ?10 |
||
678 | ?09: STA pp6 |
||
679 | lda sbank |
||
680 | sta pp6+1 |
||
681 | STX ix6 |
||
682 | ?10: LDA ctmp |
||
683 | STA rcnt |
||
684 | ?11: LDA ctmp |
||
685 | CMP #$17 |
||
686 | BEQ ?13 |
||
687 | ACC16CLC |
||
688 | LDA stxtp |
||
689 | ADC #MAXCOLS |
||
690 | STA stxtp |
||
691 | clc |
||
692 | LDA sattp |
||
693 | ADC #MAXCOLS |
||
694 | STA sattp |
||
695 | ACC08 |
||
696 | LDA #' ' |
||
697 | xba |
||
698 | lda eattr ; A = attribute, B = blank |
||
699 | LDY #MAXCOLS-1 |
||
700 | ?12: sta [sattp],y ; store attribute |
||
701 | xba |
||
702 | sta [stxtp],y ; store blank |
||
703 | xba |
||
704 | DEY |
||
705 | BPL ?12 |
||
706 | INC ctmp |
||
707 | bra ?11 |
||
708 | ?13: JSR pp2mv |
||
709 | PLA |
||
710 | beq updsl |
||
711 | STZ curs+1 |
||
712 | LDA srow |
||
713 | ASL a |
||
714 | ASL a ; srow * 4 |
||
715 | ADC srow ; srow * 5 |
||
716 | ASL a |
||
717 | ASL a ; srow * 20 |
||
718 | ROL curs+1 |
||
719 | ASL a ; * 40 |
||
720 | ROL curs+1 |
||
721 | ASL a ; * 80 |
||
722 | ROL curs+1 |
||
723 | STA curs |
||
724 | LDA curs+1 |
||
725 | ADC #>TXTADDR |
||
726 | STA curs+1 |
||
727 | bra updsl |
||
728 | |||
729 | ; print error message in status line and wait for <enter> key pressed |
||
730 | ; in: X - error number |
||
731 | ; P1C3D: |
||
732 | error: |
||
733 | lda seatt ; error attribute |
||
734 | jsr msgstr |
||
735 | jsr waitent |
||
736 | lda #$40 ; force update status line |
||
737 | ;tsb slfg |
||
738 | sta slfg |
||
739 | |||
740 | ; update status line (edit mode only) |
||
741 | ; P2989: |
||
742 | updsl: |
||
743 | bit slfg |
||
744 | bpl ?00 ; skip if in command line mode |
||
745 | rts |
||
746 | ?00: bvc ?04 ; partial update only |
||
747 | lda slattr ; status line attribute |
||
748 | xba |
||
749 | bit edtfg |
||
750 | bvc ?02 ; standard edit buffer |
||
751 | ldx #<stlstr2 ; clipboard status line string |
||
752 | ldy #>stlstr2 |
||
753 | bra ?03 |
||
754 | ?02: ldx #<stlstr ; std cbm fs buffer status line string |
||
755 | ldy #>stlstr |
||
756 | bit fsmode ; <7>: cbm fs |
||
757 | bmi ?03 |
||
758 | ldx #<stlstr1 ; std fat buffer status line string |
||
759 | ldy #>stlstr1 |
||
760 | ?03: lda #^stlstr |
||
761 | jsr outstr |
||
762 | bra ?05 |
||
763 | ?04: ACC16 |
||
764 | lda #!STLINE ; set address of last screen row |
||
765 | sta stxtp |
||
766 | lda #!STLATTR |
||
767 | sta sattp |
||
768 | ACC08 |
||
769 | ?05: lda #$02 |
||
770 | bit slfg ; test bit 1 |
||
771 | beq ?05a |
||
772 | jmp ?70 ; update caps & num only |
||
773 | ?05a: lda xbuf ; update buffer # indicator |
||
774 | cmp xbuf1 |
||
775 | bne ?06 ; changed: update |
||
776 | bit slfg ; not changed, check if forced update |
||
777 | bvc ?12 ; no forced update |
||
778 | ?06: sta xbuf1 ; store buffer # |
||
779 | bit edtfg ; skip buffer # for clipboard |
||
780 | bvs ?12 |
||
781 | ?08: ora #'0' ; buffer # = 0..9 |
||
782 | ?10: ldy #8 ; index of buffer # |
||
783 | sta [stxtp],y ; update |
||
784 | jsr ?cfn ; update filename |
||
785 | ?12: ACC16 |
||
786 | lda ncount ; update total lines count |
||
787 | cmp ncount1 |
||
788 | sta ncount1 ; save in advance for update |
||
789 | sta wtmp ; save in advance for conversion |
||
790 | ACC08 |
||
791 | bne ?14 ; changed: update |
||
792 | bit slfg ; not changed, check if forced update |
||
793 | bvc ?16 ; no forced update |
||
794 | ?14: jsr int2str ; convert in string |
||
795 | ldx #5 ; 5 digits |
||
796 | ldy #$3B ; column of N# |
||
797 | jsr ?100 |
||
798 | ?16: ACC16 |
||
799 | lda cline ; update current line # |
||
800 | cmp cline1 |
||
801 | sta cline1 ; save in advance for update |
||
802 | php |
||
803 | inc a |
||
804 | sta wtmp ; save in advance for conversion |
||
805 | plp |
||
806 | ACC08 |
||
807 | bne ?18 ; changed: update |
||
808 | bit slfg ; not changed, check if forced update |
||
809 | bvc ?20 ; no forced update |
||
810 | ?18: jsr int2str ; convert in string |
||
811 | ldx #5 ; 5 digits |
||
812 | ldy #$44 ; column of L# |
||
813 | jsr ?100 |
||
814 | ?20: lda ccol ; update current column # |
||
815 | cmp ccol1 |
||
816 | bne ?22 ; changed: update |
||
817 | bit slfg ; not changed, check if forced update |
||
818 | bvc ?24 ; no forced update |
||
819 | ?22: sta ccol1 |
||
820 | inc a |
||
821 | jsr byte2str ; convert in string |
||
822 | ldx #3 ; 3 digits |
||
823 | ldy #$4C ; column of C# |
||
824 | jsr ?100 |
||
825 | ?24: lda bflag ; update flag's indicator's |
||
826 | cmp bflag1 |
||
827 | bne ?26 ; changed: update |
||
828 | bit slfg ; not changed, check if forced update |
||
829 | bvc ?34 ; no forced update |
||
830 | ?26: sta bflag1 |
||
831 | ldx fgatt ; X = disabled flag attribute |
||
832 | clc |
||
833 | bit bflag1 ; check modified flag |
||
834 | bpl ?28 |
||
835 | sec ; enabled |
||
836 | ?28: ldy #$2E ; column of M indicator |
||
837 | jsr ?80 |
||
838 | clc |
||
839 | bit bflag1 ; check overwrite flag |
||
840 | bvc ?30 |
||
841 | sec ; enabled |
||
842 | ?30: ldy #$32 ; column of O indicator |
||
843 | jsr ?80 |
||
844 | clc |
||
845 | lda #$20 |
||
846 | bit bflag1 ; check indent mode flag |
||
847 | beq ?32 |
||
848 | sec ; enabled |
||
849 | ?32: ldy #$30 ; column of I indicator |
||
850 | jsr ?80 |
||
851 | ?34: lda fslct ; select mode flag |
||
852 | tax |
||
853 | eor slfg |
||
854 | lsr a ; bit 0 only |
||
855 | bcs ?36 ; changed: update |
||
856 | bit slfg ; not changed, check if forced update |
||
857 | bvc ?40 ; no forced update |
||
858 | ?36: lda #$FE ; set/reset bit 0 of slfg |
||
859 | and slfg |
||
860 | txy |
||
861 | beq ?38 ; reset |
||
862 | ora #$01 ; set |
||
863 | ?38: sta slfg |
||
864 | lsr a ; CF = indicator status |
||
865 | ldx fgatt ; X = disabled flag attribute |
||
866 | ldy #$34 ; column of S indicator |
||
867 | jsr ?80 |
||
868 | |||
869 | ?40: |
||
870 | ?70: ldx fgatt ; X = disabled flag attribute |
||
871 | lda >DP01ADDR+KbdToggle |
||
872 | sta tmpf |
||
873 | clc |
||
874 | bpl ?72 ; caps lock disabled |
||
875 | sec ; caps lock indicator enabled |
||
876 | ?72: ldy #$35 ; column of C indicator |
||
877 | jsr ?80 |
||
878 | clc |
||
879 | bit tmpf ; check num lock |
||
880 | bvc ?74 |
||
881 | sec ; num lock indicator enabled |
||
882 | ?74: ldy #$36 ; column of N indicator |
||
883 | jsr ?80 |
||
884 | lda #$42 ; clear forced update |
||
885 | trb slfg |
||
886 | rts |
||
887 | |||
888 | ; set/unset indicator flag on status line |
||
889 | ?80: lda slattr ; set status |
||
890 | bcs ?82 |
||
891 | txa ; unset status |
||
892 | ?82: sta [sattp],y |
||
893 | rts |
||
894 | |||
895 | ; output stringa tstr2 at column Y, X bytes |
||
896 | ?100: stx tmp6 |
||
897 | ldx #0 |
||
898 | ?102: lda <tstr2,x |
||
899 | sta [stxtp],y |
||
900 | inx |
||
901 | iny |
||
902 | dec tmp6 |
||
903 | bne ?102 |
||
904 | rts |
||
905 | |||
906 | ; update cbm filename field |
||
907 | ?cfn: |
||
908 | ldx #0 |
||
909 | ldy #$0B ; index of cbm filename |
||
910 | ?cfnl: lda >EDCURFILE,x |
||
911 | beq ?cfne |
||
912 | sta [stxtp],y |
||
913 | inx |
||
914 | iny |
||
915 | cpx #18 |
||
916 | bcc ?cfnl |
||
917 | ?cfne: rts |
||
918 | |||
919 | ; toggle insert flag |
||
920 | ; control key: insert key |
||
921 | tins: |
||
922 | lda #$40 ; insert flag |
||
923 | tax |
||
924 | eor bflag ; toggle |
||
925 | sta bflag |
||
926 | txa |
||
927 | eor cursmode ; toggle under/block cursor |
||
928 | sta cursmode |
||
929 | jsr setcurs |
||
930 | jmp updsl |
||
931 | |||
932 | ; toggle indent flag |
||
933 | ; Ctrl+TAB or Ctrl+I (control key) |
||
934 | tind: |
||
935 | lda #$20 ; indent flag |
||
936 | eor bflag |
||
937 | sta bflag |
||
938 | jmp updsl |
||
939 | |||
940 | ; indent new line |
||
941 | indent: |
||
942 | lda #$20 ; test indent flag |
||
943 | bit bflag |
||
944 | beq ?04 ; no indent |
||
945 | lda ctmp |
||
946 | beq ?04 ; no blanks |
||
947 | lda #$01 ; no update edit window while indent... |
||
948 | tsb edtfg ; ... blank's insertion |
||
949 | ?02: lda #' ' ; insert starting blanks |
||
950 | jsr edkey |
||
951 | dec ctmp |
||
952 | bne ?02 |
||
953 | lda #$01 ; restore flag |
||
954 | trb edtfg |
||
955 | ?04: rts |
||
956 | |||
957 | ;--------------------------------------------------- |
||
958 | |||
959 | ; CTRL Y |
||
960 | delline: |
||
961 | jsr mvpp2 |
||
962 | JSR nextln |
||
963 | bcc ?04 |
||
964 | ?02: jmp pp2mv |
||
965 | ?04: lda ppage |
||
966 | sta pb+1 |
||
967 | lda ppage+1 |
||
968 | sta pb+2 |
||
969 | lda ixb |
||
970 | sta tmpf |
||
971 | JSR startln ; first byte of this line |
||
972 | bcs ?02 |
||
973 | ACC16 |
||
974 | dec ncount |
||
975 | lda ppage |
||
976 | cmp pb+1 |
||
977 | ACC08 |
||
978 | beq ?10 ; whole line just in one block |
||
979 | LDA ixb |
||
980 | CMP #BSTART |
||
981 | BNE ?06 |
||
982 | LDA ppage+1 ; block can be free'd |
||
983 | xba |
||
984 | lda ppage |
||
985 | JSR delblk |
||
986 | bra ?08 |
||
987 | ?06: dec a ; just one byte less |
||
988 | LDY #BNDX |
||
989 | STA [pblk],Y |
||
990 | ?08: LDA pb+1 ; go in the next block |
||
991 | sta ppage |
||
992 | lda pb+2 |
||
993 | sta ppage+1 |
||
994 | lda #BSTART ; line continue at beginning... |
||
995 | sta ixb ; ...of next block |
||
996 | ?10: LDY #BNDX ; now move back bytes |
||
997 | lda [pblk],y |
||
998 | sta tmp6 |
||
999 | LDY tmpf |
||
1000 | DEY |
||
1001 | STY tmp7 |
||
1002 | LDX ixb |
||
1003 | DEX |
||
1004 | ?12: INC tmp7 |
||
1005 | inx |
||
1006 | LDY tmp7 |
||
1007 | lda [pblk],y |
||
1008 | txy |
||
1009 | STA [pblk],Y |
||
1010 | lda tmp6 |
||
1011 | CMP tmp7 |
||
1012 | BNE ?12 |
||
1013 | txa |
||
1014 | LDY #BNDX |
||
1015 | STA [pblk],Y |
||
1016 | JMP updwin |
||
1017 | |||
1018 | |||
1019 | copysel: |
||
1020 | lda #$02 ; copy operation: reset flag |
||
1021 | trb edtfg |
||
1022 | stz ctmp2 ; copy op (zero) |
||
1023 | bra ct1 |
||
1024 | |||
1025 | cberr: |
||
1026 | ldx #$05 |
||
1027 | jmp error ; Clipboard: illegal command |
||
1028 | |||
1029 | ; CUT |
||
1030 | ; P1F4F: |
||
1031 | cutsel: |
||
1032 | lda #$02 ; cut operation: set flag |
||
1033 | tsb edtfg |
||
1034 | sta ctmp2 ; cut op (not zero) |
||
1035 | ct1: bit edtfg |
||
1036 | bvs cberr ; clipboard error |
||
1037 | LDA fslct |
||
1038 | beq ?00a |
||
1039 | stz fslct |
||
1040 | LDA #CLIPBRD |
||
1041 | JSR freebuf |
||
1042 | STZ pb |
||
1043 | STZ pd |
||
1044 | JSR mvpp2 |
||
1045 | JSR newblk ; need at least of 2 free blocks |
||
1046 | BCS ?00 ; no free blocks |
||
1047 | ACC16 |
||
1048 | STA bka |
||
1049 | STA pb+1 |
||
1050 | lda [pb] |
||
1051 | STA pfree |
||
1052 | JSR newblk |
||
1053 | BCC ?01 ; ok |
||
1054 | LDA bka ; restore free list |
||
1055 | STA pfree |
||
1056 | ACC08 |
||
1057 | ?00: jsr updwin ; for clear selection on edit window |
||
1058 | ?00a: rts |
||
1059 | ?01: STA bkb |
||
1060 | .LONGA on ; remember here A/M 16 bit |
||
1061 | LDA pp0 |
||
1062 | STA ppage |
||
1063 | LDY ix0 |
||
1064 | STY ixb |
||
1065 | LDA nslctl |
||
1066 | BMI ?02 |
||
1067 | STA rclip |
||
1068 | LDA pp8 |
||
1069 | STA pp6 |
||
1070 | LDY ix8 |
||
1071 | STY ix6 |
||
1072 | bra ?04 |
||
1073 | ?02: EOR #$FFFF |
||
1074 | inc a |
||
1075 | STA rclip |
||
1076 | ACC08 |
||
1077 | JSR nextln |
||
1078 | LDA ppage |
||
1079 | STA pp6 |
||
1080 | LDA ppage+1 |
||
1081 | STA pp6+1 |
||
1082 | LDA ixb |
||
1083 | STA ix6 |
||
1084 | JSR pp2mv |
||
1085 | JSR nextln |
||
1086 | ACC16 |
||
1087 | ?04: ldx ctmp2 |
||
1088 | beq ?06 ; copy op: skip update cline/ncount |
||
1089 | sec |
||
1090 | lda ncount |
||
1091 | sbc rclip |
||
1092 | sta ncount |
||
1093 | LDA nslctl |
||
1094 | BMI ?05 |
||
1095 | SEC |
||
1096 | LDA cline |
||
1097 | SBC rclip |
||
1098 | STA cline |
||
1099 | bra ?06 |
||
1100 | ?05: INC cline |
||
1101 | ?06: LDA bka |
||
1102 | STA pb+1 |
||
1103 | LDX #CLIPBRD*2 |
||
1104 | STA bstart,X |
||
1105 | STA bcur,X |
||
1106 | LDA #BSTART |
||
1107 | STA bndx,X |
||
1108 | lda rclip |
||
1109 | sta btot,x |
||
1110 | stz bline,x |
||
1111 | LDA ppage |
||
1112 | CMP pp6 |
||
1113 | ACC08 |
||
1114 | BNE ?07 |
||
1115 | JMP ?13 ; all in the same block |
||
1116 | ?07: ldx ctmp2 |
||
1117 | bne ?07a ; cut op |
||
1118 | jmp ?20 ; copy op |
||
1119 | ?07a: LDY #$00 |
||
1120 | CPU16 |
||
1121 | LDA bkb ; take off bkb from free list |
||
1122 | STA pd+1 |
||
1123 | lda [pd] |
||
1124 | STA pfree |
||
1125 | lda [pblk] |
||
1126 | STA [pb] ; pb->next = cur->next |
||
1127 | STA pd+1 ; pd = cur->next |
||
1128 | TYA |
||
1129 | INY |
||
1130 | INY |
||
1131 | STA [pb],Y ; pb->prev = NULL |
||
1132 | LDA pb+1 |
||
1133 | STA [pd],Y ; cur->next->prev = pb |
||
1134 | CPU08 |
||
1135 | INY |
||
1136 | INY ; index field |
||
1137 | lda [pblk],y |
||
1138 | sta tmp6 |
||
1139 | SEC |
||
1140 | SBC ixb |
||
1141 | CLC |
||
1142 | ADC #BSTART |
||
1143 | STA [pb],Y |
||
1144 | tyx ; BNDX |
||
1145 | LDY ixb |
||
1146 | DEY |
||
1147 | STY tmp7 |
||
1148 | ?08: INC tmp7 |
||
1149 | inx |
||
1150 | LDY tmp7 |
||
1151 | lda [pblk],y |
||
1152 | txy |
||
1153 | STA [pb],Y |
||
1154 | lda tmp6 |
||
1155 | CMP tmp7 |
||
1156 | BNE ?08 |
||
1157 | ACC16 |
||
1158 | LDA bkb |
||
1159 | STA pd+1 |
||
1160 | LDA pp6 |
||
1161 | STA pb+1 |
||
1162 | lda [pb] |
||
1163 | STA [pd] |
||
1164 | ACC08 |
||
1165 | LDY #BNDX |
||
1166 | lda [pb],y |
||
1167 | sta tmp6 |
||
1168 | SEC |
||
1169 | SBC ix6 |
||
1170 | CLC |
||
1171 | ADC #BSTART |
||
1172 | STA [pd],Y |
||
1173 | tyx |
||
1174 | LDY ix6 |
||
1175 | DEY |
||
1176 | STY tmp7 |
||
1177 | ?09: INC tmp7 |
||
1178 | inx |
||
1179 | LDY tmp7 |
||
1180 | lda [pb],y |
||
1181 | txy |
||
1182 | STA [pd],Y |
||
1183 | lda tmp6 |
||
1184 | CMP tmp7 |
||
1185 | BNE ?09 |
||
1186 | LDY #BNDX |
||
1187 | LDA ix6 |
||
1188 | STA [pb],Y |
||
1189 | TAY |
||
1190 | LDA #$00 |
||
1191 | STA [pb],Y |
||
1192 | xba |
||
1193 | lda #0 |
||
1194 | ACC16 |
||
1195 | STA [pb] ; next = NULL |
||
1196 | LDY #BPREV |
||
1197 | LDA ppage |
||
1198 | STA [pd],Y |
||
1199 | LDA pd+1 |
||
1200 | STA [pblk] |
||
1201 | lda [pd] |
||
1202 | BEQ ?10 |
||
1203 | STA pb+1 |
||
1204 | LDA pd+1 |
||
1205 | STA [pb],Y |
||
1206 | ?10: ACC08 |
||
1207 | LDA ixb |
||
1208 | CMP #BSTART |
||
1209 | BNE ?11 |
||
1210 | LDA ppage+1 |
||
1211 | xba |
||
1212 | lda ppage |
||
1213 | JSR delblk |
||
1214 | bra ?12 |
||
1215 | ?11: dec a |
||
1216 | LDY #BNDX |
||
1217 | STA [pblk],Y |
||
1218 | ?12: LDA pd+1 |
||
1219 | STA ppage |
||
1220 | lda pd+2 |
||
1221 | sta ppage+1 |
||
1222 | LDA #BSTART |
||
1223 | STA ixb |
||
1224 | JMP updwin |
||
1225 | |||
1226 | ?13: LDY ixb |
||
1227 | STY tmp7 |
||
1228 | LDX #BSTART |
||
1229 | ?14: LDY tmp7 |
||
1230 | lda [pblk],y |
||
1231 | txy |
||
1232 | STA [pb],Y |
||
1233 | INC tmp7 |
||
1234 | inx |
||
1235 | LDA tmp7 |
||
1236 | CMP ix6 |
||
1237 | BNE ?14 |
||
1238 | LDY #$00 |
||
1239 | CPU16 |
||
1240 | tya |
||
1241 | STA [pb] ; next = NULL |
||
1242 | INY |
||
1243 | iny |
||
1244 | STA [pb],Y ; prev = NULL |
||
1245 | CPU08 |
||
1246 | txa |
||
1247 | INY |
||
1248 | iny |
||
1249 | STA [pb],Y ; index |
||
1250 | TAY |
||
1251 | LDA #$00 |
||
1252 | STA [pb],Y ; buffer terminator |
||
1253 | lda #$02 ; cut operation ? |
||
1254 | bit edtfg |
||
1255 | bne ?14a ; yes |
||
1256 | jsr pp2mv ; restore current buffer pointer |
||
1257 | bra ?16 |
||
1258 | ?14a: LDY #BNDX ; move back |
||
1259 | lda [pblk],y |
||
1260 | sta tmp6 |
||
1261 | LDY ix6 |
||
1262 | DEY |
||
1263 | STY tmp7 |
||
1264 | LDX ixb |
||
1265 | DEX |
||
1266 | ?15: INC tmp7 |
||
1267 | inx |
||
1268 | LDY tmp7 |
||
1269 | lda [pblk],y |
||
1270 | txy |
||
1271 | STA [pblk],Y |
||
1272 | lda tmp6 |
||
1273 | CMP tmp7 |
||
1274 | BNE ?15 |
||
1275 | txa |
||
1276 | LDY #BNDX |
||
1277 | STA [pblk],Y |
||
1278 | ?16: JMP updwin |
||
1279 | |||
1280 | ?20: ldx #0 |
||
1281 | CPU16 ; count needs block's |
||
1282 | LDA bkb ; take off bkb from free list |
||
1283 | STA pd+1 |
||
1284 | lda [pd] |
||
1285 | STA pfree |
||
1286 | lda ppage |
||
1287 | ?22: sta pd+1 |
||
1288 | lda [pd] ; next |
||
1289 | cmp pp6 ; loop until last block |
||
1290 | beq ?24 ; end loop |
||
1291 | inx |
||
1292 | bra ?22 |
||
1293 | ?24: txa |
||
1294 | beq ?28 ; no more blocks need |
||
1295 | jsr chkfree ; check needs blocks |
||
1296 | lda #0 |
||
1297 | bcc ?28 ; ok |
||
1298 | LDA bka ; restore free list |
||
1299 | STA pfree |
||
1300 | CPU08 |
||
1301 | LDX #$04 ; Not enough memory error |
||
1302 | JMP error |
||
1303 | ?28: LONG_ON ; remember here A/M and X/Y 16 bit |
||
1304 | ldy #BPREV |
||
1305 | STA [pb],Y ; prev = NULL |
||
1306 | CPU08 |
||
1307 | INY |
||
1308 | INY ; index field |
||
1309 | lda [pblk],y |
||
1310 | sta tmp6 ; copy tmp6 - ixb + 1 bytes... |
||
1311 | SEC ; ...from pblk to pb... |
||
1312 | SBC ixb ; ...starting from ixb |
||
1313 | CLC |
||
1314 | ADC #BSTART |
||
1315 | STA [pb],Y |
||
1316 | tyx ; BNDX |
||
1317 | LDY ixb |
||
1318 | DEY |
||
1319 | STY tmp7 |
||
1320 | ?30: INC tmp7 |
||
1321 | inx |
||
1322 | LDY tmp7 |
||
1323 | lda [pblk],y |
||
1324 | txy |
||
1325 | STA [pb],Y |
||
1326 | lda tmp6 |
||
1327 | CMP tmp7 |
||
1328 | BNE ?30 |
||
1329 | ACC16 |
||
1330 | LDA [pblk] ; next |
||
1331 | ?32: STA pd+1 |
||
1332 | cmp pp6 |
||
1333 | beq ?36 |
||
1334 | LDA pb+1 |
||
1335 | PHA |
||
1336 | JSR newblk ; no give error now! |
||
1337 | STA [pb] ; next |
||
1338 | STA pb+1 |
||
1339 | lda [pb] |
||
1340 | STA pfree |
||
1341 | PLA |
||
1342 | ldy #BPREV |
||
1343 | STA [pb],Y |
||
1344 | INY |
||
1345 | iny |
||
1346 | ACC08 |
||
1347 | ?34: lda [pd],y |
||
1348 | STA [pb],Y |
||
1349 | INY |
||
1350 | BNE ?34 |
||
1351 | ACC16 |
||
1352 | lda [pd] |
||
1353 | bra ?32 |
||
1354 | ?36: lda pb+1 |
||
1355 | sta bka |
||
1356 | LDA bkb |
||
1357 | sta [pb] |
||
1358 | STA pb+1 |
||
1359 | lda #0 |
||
1360 | sta [pb] |
||
1361 | ldy #BPREV |
||
1362 | lda bka |
||
1363 | sta [pb],y |
||
1364 | ACC08 |
||
1365 | LDY #BNDX |
||
1366 | ?38: iny |
||
1367 | lda [pd],y |
||
1368 | STA [pb],Y |
||
1369 | cpy ix6 |
||
1370 | BNE ?38 |
||
1371 | LDY #BNDX |
||
1372 | LDA ix6 |
||
1373 | STA [pb],Y |
||
1374 | TAY |
||
1375 | LDA #$00 |
||
1376 | STA [pb],Y |
||
1377 | jsr pp2mv |
||
1378 | jmp updwin |
||
1379 | |||
1380 | ; PASTE |
||
1381 | ; P215E: |
||
1382 | pastesel: |
||
1383 | bit edtfg |
||
1384 | bvc ?00 |
||
1385 | jmp cberr ; clipboard error |
||
1386 | ?00: LDA fslct |
||
1387 | bne ?01 ; no selection |
||
1388 | LDX #CLIPBRD*2 |
||
1389 | ACC16CLC |
||
1390 | LDA bstart,X |
||
1391 | beq ?00b ; no selected text |
||
1392 | lda btot,x ; # lines on clipboard |
||
1393 | adc ncount ; check overflow |
||
1394 | bcs ?00a ; overflow |
||
1395 | cmp #MAXLINES |
||
1396 | bcc ?02 |
||
1397 | ?00a: ACC08 |
||
1398 | ldx #6 ; can't paste text: lines count overflow |
||
1399 | jmp error |
||
1400 | ?00b: ACC08 |
||
1401 | ?01: rts |
||
1402 | ?02: .LONGA on ; remember here A/M 16 bit |
||
1403 | LDA bstart,X ; block's count |
||
1404 | JSR blkcnt |
||
1405 | inc a ; one more |
||
1406 | jsr chkfree ; check free blocks |
||
1407 | ACC08 |
||
1408 | bcc ?03 |
||
1409 | LDX #$04 ; Not enough memory error |
||
1410 | JMP error |
||
1411 | ?03: JSR pp8mv |
||
1412 | stz pb |
||
1413 | stz pd |
||
1414 | ACC16CLC |
||
1415 | LDX #CLIPBRD*2 |
||
1416 | lda btot,x |
||
1417 | sta rclip |
||
1418 | LDA cline |
||
1419 | ADC rclip |
||
1420 | STA cline |
||
1421 | clc |
||
1422 | lda ncount |
||
1423 | adc rclip |
||
1424 | sta ncount |
||
1425 | lda [pblk] ; next |
||
1426 | PHA |
||
1427 | LDA ppage |
||
1428 | STA pb+1 |
||
1429 | LDX #CLIPBRD*2 |
||
1430 | LDA bstart,X |
||
1431 | ?03a: STA pd+1 |
||
1432 | LDA pb+1 |
||
1433 | PHA |
||
1434 | JSR newblk ; no give error now! |
||
1435 | STA [pb] ; next |
||
1436 | STA pb+1 |
||
1437 | lda [pb] |
||
1438 | STA pfree |
||
1439 | PLA |
||
1440 | ldy #BPREV |
||
1441 | STA [pb],Y |
||
1442 | INY |
||
1443 | iny |
||
1444 | ACC08 |
||
1445 | ?04: lda [pd],y |
||
1446 | STA [pb],Y |
||
1447 | INY |
||
1448 | BNE ?04 |
||
1449 | ACC16 |
||
1450 | lda [pd] |
||
1451 | BNE ?03a |
||
1452 | LDA pb+1 |
||
1453 | STA bka |
||
1454 | JSR newblk |
||
1455 | STA [pb] |
||
1456 | STA pb+1 |
||
1457 | lda [pb] |
||
1458 | STA pfree |
||
1459 | LDA bka |
||
1460 | ldy #BPREV |
||
1461 | STA [pb],Y |
||
1462 | PLA |
||
1463 | STA [pb] |
||
1464 | BEQ ?05 |
||
1465 | STA pd+1 |
||
1466 | LDA pb+1 |
||
1467 | STA [pd],Y |
||
1468 | ?05: ACC08 |
||
1469 | LDY ixb |
||
1470 | DEY |
||
1471 | STY tmp7 |
||
1472 | LDX #BNDX |
||
1473 | ?06: INC tmp7 |
||
1474 | inx |
||
1475 | LDY tmp7 |
||
1476 | lda [pblk],y |
||
1477 | txy |
||
1478 | STA [pb],Y |
||
1479 | LDY #BNDX |
||
1480 | lda [pblk],y |
||
1481 | CMP tmp7 |
||
1482 | BNE ?06 |
||
1483 | txa |
||
1484 | STA [pb],Y |
||
1485 | LDA ixb |
||
1486 | CMP #BSTART |
||
1487 | BNE ?07 |
||
1488 | LDA ppage+1 |
||
1489 | xba |
||
1490 | lda ppage |
||
1491 | JSR delblk |
||
1492 | bra ?08 |
||
1493 | ?07: dec a |
||
1494 | LDY #BNDX |
||
1495 | STA [pblk],Y |
||
1496 | ?08: ACC16 |
||
1497 | LDA pb+1 |
||
1498 | STA ppage |
||
1499 | LDY #BSTART |
||
1500 | STY ixb |
||
1501 | LDA bka |
||
1502 | STA pd+1 |
||
1503 | ACC08 |
||
1504 | dey |
||
1505 | lda [pd],y |
||
1506 | CMP #BSTART |
||
1507 | BNE ?09 |
||
1508 | LDA pd+2 |
||
1509 | xba |
||
1510 | lda pd+1 |
||
1511 | JSR delblk |
||
1512 | bra ?10 |
||
1513 | ?09: dec a |
||
1514 | STA [pd],Y |
||
1515 | ?10: LDA srow |
||
1516 | CMP #$06 |
||
1517 | BCS ?11 |
||
1518 | LDA #$06 |
||
1519 | STA srow |
||
1520 | ?11: JMP updwin |
||
1521 | |||
1522 | ;--------------------------------------------------- |
||
1523 | |||
1524 | ; get new block of memory |
||
1525 | ; out: C = page pointer to new block or NULL |
||
1526 | ; CF = 1 if no left memory |
||
1527 | ; can be called in both 8/16 bit |
||
1528 | ; P230E: |
||
1529 | newblk: |
||
1530 | php ; save 8/16 bit state |
||
1531 | CPU16 |
||
1532 | LDA pfree ; get next free block |
||
1533 | BNE ?10 ; OK |
||
1534 | ?02: JSR garbc ; try to free memory |
||
1535 | BCS ?02 |
||
1536 | LDA pfree |
||
1537 | BNE ?10 ; OK |
||
1538 | lda #MINPAGE ; try to allocate pages |
||
1539 | tax ; X = # pages |
||
1540 | clc |
||
1541 | SETBRK ; increase break level |
||
1542 | bcc ?04 ; ok |
||
1543 | tax ; max. # allocable pages |
||
1544 | beq ?08 ; no room ! |
||
1545 | clc ; allocate max. available |
||
1546 | SETBRK |
||
1547 | bcs ?08 ; now will no give error in fact! |
||
1548 | ?04: sta pfree ; new free list |
||
1549 | dex |
||
1550 | stx lpte ; # pages - 1 |
||
1551 | adc lpte ; last page! (here CF = 0) |
||
1552 | sta lpte ; save last page ptr |
||
1553 | INDEX08 |
||
1554 | ldx #0 |
||
1555 | stx lptc ; clear low pointer |
||
1556 | INDEX16 ; X = 0 |
||
1557 | lda pfree |
||
1558 | ?06: sta lptc+1 ; init new free list |
||
1559 | inc a ; next page |
||
1560 | sta [lptc] ; next field in free list |
||
1561 | cmp lpte ; till last page |
||
1562 | bne ?06 |
||
1563 | sta lptc+1 |
||
1564 | txa ; end of list |
||
1565 | sta [lptc] |
||
1566 | lda pfree ; return block pointer |
||
1567 | bra ?10 |
||
1568 | ?08: CPU08 |
||
1569 | LDX #$01 ; 'out of memory' error |
||
1570 | JSR error |
||
1571 | lda #0 ; return NULL pointer |
||
1572 | xba |
||
1573 | lda #0 |
||
1574 | plp |
||
1575 | sec ; error flag |
||
1576 | rts |
||
1577 | ?10: plp ; return pointer |
||
1578 | clc |
||
1579 | LONG_OFF |
||
1580 | RTS |
||
1581 | |||
1582 | ; check if free list contain requested number of free blocks |
||
1583 | ; and add blocks allocating more memory if need |
||
1584 | ; in: C = number of requested free block |
||
1585 | ; out: CF = 0 if free list is large enough or if more blocks |
||
1586 | ; was succesfully added |
||
1587 | ; CF = 1 if free list is not large enough and more blocks |
||
1588 | ; can't be added |
||
1589 | ; C = number of blocks that can be added if CF = 1 |
||
1590 | ; can be called in both 8/16 bit |
||
1591 | chkfree: |
||
1592 | php ; save 8/16 bit status |
||
1593 | stz lptc ; clear low pointer |
||
1594 | CPU16 |
||
1595 | sta lpte+1 ; # blocks to add |
||
1596 | lda pfree |
||
1597 | beq ?02 ; free list is empty |
||
1598 | jsr blkcnt ; how much free blocks? |
||
1599 | cmp lpte+1 |
||
1600 | bcs ?08 ; ok, requested blocks are free |
||
1601 | ?02: sta lptc+1 |
||
1602 | sec |
||
1603 | lda lpte+1 ; how much blocks to add? |
||
1604 | sbc lptc+1 |
||
1605 | tax |
||
1606 | clc ; set a new break level |
||
1607 | SETBRK |
||
1608 | bcc ?04 ; ok, no error |
||
1609 | plp |
||
1610 | sec ; return an error |
||
1611 | rts |
||
1612 | ?04: tay ; new pointer |
||
1613 | dex |
||
1614 | stx lpte+1 ; # pages - 1 |
||
1615 | adc lpte+1 ; last page! (here CF = 0) |
||
1616 | sta lpte+1 ; save last page ptr |
||
1617 | tya |
||
1618 | pha ; save new free list pointer |
||
1619 | ?06: sta lptc+1 ; init new free list |
||
1620 | inc a ; next page |
||
1621 | sta [lptc] ; next field in free list |
||
1622 | cmp lpte+1 ; till last page |
||
1623 | bne ?06 |
||
1624 | sta lptc+1 |
||
1625 | lda pfree ; link old free list |
||
1626 | sta [lptc] |
||
1627 | pla |
||
1628 | sta pfree ; set new free list |
||
1629 | ?08: plp |
||
1630 | clc |
||
1631 | LONG_OFF |
||
1632 | rts |
||
1633 | |||
1634 | ; free one buffer |
||
1635 | ; in: A = buffer number |
||
1636 | ; out: CF = 1 if fail to allocate a new block |
||
1637 | ; P2D34: |
||
1638 | freebuf: |
||
1639 | sta ebtmp ; save buffer number to free |
||
1640 | asl a |
||
1641 | sta ebtmp2 ; save index |
||
1642 | TAX ; table index |
||
1643 | stz lptc ; prepare pointer |
||
1644 | ACC16 |
||
1645 | LDA bstart,X |
||
1646 | beq ?02 ; nothing to do |
||
1647 | STA lptc+1 |
||
1648 | stz bstart,x ; clear start block |
||
1649 | stz bcur,x ; and all buffer data |
||
1650 | stz bndx,x |
||
1651 | stz bline,x |
||
1652 | stz btot,x |
||
1653 | ldx ebtmp |
||
1654 | stx bka |
||
1655 | ldx #0 |
||
1656 | stx bka+1 |
||
1657 | lda bka |
||
1658 | asl a |
||
1659 | asl a |
||
1660 | adc bka |
||
1661 | asl a ; x 10 |
||
1662 | asl a |
||
1663 | asl a |
||
1664 | asl a ; x 80 |
||
1665 | adc #EDBUFNAM |
||
1666 | sta pb |
||
1667 | ACC08 |
||
1668 | lda #^EDBUFNAM |
||
1669 | sta pb+2 |
||
1670 | lda #0 |
||
1671 | sta [pb] |
||
1672 | sta >EDCURFILE |
||
1673 | ACC16 |
||
1674 | ?01: lda [lptc] ; put all buffer blocks in free list |
||
1675 | PHA ; next |
||
1676 | LDA pfree |
||
1677 | STA [lptc] ; next free |
||
1678 | LDA lptc+1 |
||
1679 | STA pfree ; update free list |
||
1680 | PLA |
||
1681 | STA lptc+1 ; next block |
||
1682 | BNE ?01 ; loop until next = NULL |
||
1683 | ldx ebtmp ; if this is not the current buffer... |
||
1684 | CPX xbuf |
||
1685 | BNE ?02 ; ...done |
||
1686 | ; ...otherwise alloc one block... |
||
1687 | JSR newblk ; ...for a new empty buffer |
||
1688 | bcs ?02 ; error: no left memory |
||
1689 | sta wtmp ; save new block |
||
1690 | ldx ebtmp2 |
||
1691 | JSR bufinit ; init new buffer |
||
1692 | LDA bstart,X ; set up new buffer |
||
1693 | STA pbuf |
||
1694 | LDA bcur,X |
||
1695 | STA ppage |
||
1696 | LDA bndx,X |
||
1697 | STA ixb |
||
1698 | LDA bline,X |
||
1699 | STA cline |
||
1700 | LDA btot,X |
||
1701 | STA ncount |
||
1702 | ldy #$00 |
||
1703 | sty srow |
||
1704 | ?02: ACC08 |
||
1705 | ?03: RTS |
||
1706 | |||
1707 | ; switch to another buffer |
||
1708 | ; in: A = buffer number |
||
1709 | ; out: CF = 1 if fail to allocate a new block |
||
1710 | ; P2D86: |
||
1711 | switchb: |
||
1712 | pha ; save new buffer number |
||
1713 | asl a |
||
1714 | tax ; X = buffer table index |
||
1715 | ACC16 |
||
1716 | lda bstart,x |
||
1717 | bne ?02 ; ok, buffer already initialized |
||
1718 | jsr newblk ; get a new block |
||
1719 | bcc ?01 ; OK |
||
1720 | ACC08 |
||
1721 | pla ; error -- no memory left |
||
1722 | rts ; exit with CF = 1 |
||
1723 | ?01: sta wtmp ; save new page pointer |
||
1724 | ?02: ACC08 |
||
1725 | ldx xbuf ; current buffer index |
||
1726 | bmi ?03 ; no current editor buffer |
||
1727 | txa |
||
1728 | asl a |
||
1729 | tax |
||
1730 | ACC16CLC |
||
1731 | lda pbuf ; save in table current buffer data |
||
1732 | sta bstart,x |
||
1733 | lda ppage |
||
1734 | sta bcur,x |
||
1735 | lda ixb ; index + flag |
||
1736 | sta bndx,x |
||
1737 | lda cline |
||
1738 | sta bline,x |
||
1739 | lda ncount |
||
1740 | sta btot,x |
||
1741 | ldx xbuf |
||
1742 | stx bka |
||
1743 | ldx #0 |
||
1744 | stx bka+1 |
||
1745 | lda bka |
||
1746 | asl a |
||
1747 | asl a |
||
1748 | adc bka |
||
1749 | asl a ; x 10 |
||
1750 | asl a |
||
1751 | asl a |
||
1752 | asl a ; x 80 |
||
1753 | adc #EDBUFNAM |
||
1754 | sta pb |
||
1755 | ACC08 |
||
1756 | lda #^EDBUFNAM |
||
1757 | sta pb+2 |
||
1758 | ldx #0 |
||
1759 | txy |
||
1760 | ?lp1: lda >EDCURFILE,x |
||
1761 | sta [pb],y |
||
1762 | beq ?03 |
||
1763 | inx |
||
1764 | iny |
||
1765 | cpy #MAXFNAME |
||
1766 | bcc ?lp1 |
||
1767 | ?03: pla |
||
1768 | sta xbuf ; set new current buffer |
||
1769 | asl a |
||
1770 | tax ; table index access |
||
1771 | ACC16CLC |
||
1772 | lda bstart,x |
||
1773 | bne ?04 |
||
1774 | jsr bufinit |
||
1775 | clc |
||
1776 | lda bstart,x |
||
1777 | ?04: sta pbuf ; start buffer |
||
1778 | lda bcur,x |
||
1779 | sta ppage ; current block |
||
1780 | lda bndx,x |
||
1781 | sta ixb ; block pointer + flag |
||
1782 | lda bline,x |
||
1783 | sta cline ; current line |
||
1784 | lda btot,x |
||
1785 | sta ncount ; total lines |
||
1786 | ldx xbuf |
||
1787 | stx bka |
||
1788 | ldx #0 |
||
1789 | stx bka+1 |
||
1790 | lda bka |
||
1791 | asl a |
||
1792 | asl a |
||
1793 | adc bka |
||
1794 | asl a ; x 10 |
||
1795 | asl a |
||
1796 | asl a |
||
1797 | asl a ; x 80 |
||
1798 | adc #EDBUFNAM |
||
1799 | sta pb |
||
1800 | ACC08 |
||
1801 | lda #^EDBUFNAM |
||
1802 | sta pb+2 |
||
1803 | ldx #0 |
||
1804 | txy |
||
1805 | ?lp2: lda [pb],y |
||
1806 | sta >EDCURFILE,x |
||
1807 | beq ?end |
||
1808 | inx |
||
1809 | iny |
||
1810 | cpy #MAXFNAME |
||
1811 | bcc ?lp2 |
||
1812 | ?end: clc ; no error |
||
1813 | rts |
||
1814 | |||
1815 | ; init a new editor buffer -- init buffer table |
||
1816 | ; in: X = buffer table index |
||
1817 | ; wtmp = new page pointer |
||
1818 | ; can be called in both 8/16 bit |
||
1819 | ; P2D05: |
||
1820 | bufinit: |
||
1821 | php |
||
1822 | CPU08 |
||
1823 | ldy #0 |
||
1824 | sty lptc |
||
1825 | CPU16 |
||
1826 | lda wtmp ; new page pointer |
||
1827 | sta bstart,x ; start buffer block |
||
1828 | sta bcur,x ; current buffer block |
||
1829 | sta lptc+1 ; temp pointer |
||
1830 | sty bline,x ; clear current line |
||
1831 | sty btot,x ; clear tot. # lines |
||
1832 | lda [lptc] ; next block will be in free list |
||
1833 | sta pfree |
||
1834 | tya |
||
1835 | sta [lptc] ; next = NULL |
||
1836 | iny |
||
1837 | iny ; Y = 2 |
||
1838 | sta [lptc],y ; prev = NULL |
||
1839 | iny |
||
1840 | iny ; Y = 4; |
||
1841 | lda #BSTART ; set pointer in block |
||
1842 | sta [lptc],y ; and mark end of buffer |
||
1843 | sta bndx,x ; flag buffer = 0 |
||
1844 | plp |
||
1845 | LONG_OFF |
||
1846 | rts |
||
1847 | |||
1848 | |||
1849 | ; insert <enter> code - check if lines overflow |
||
1850 | inscr: |
||
1851 | ACC16 |
||
1852 | lda ncount |
||
1853 | inc a |
||
1854 | cmp #MAXLINES+1 |
||
1855 | ACC08 |
||
1856 | bcs ?02 |
||
1857 | LDA #$0D |
||
1858 | bra insert ; insert byte $0D (enter key code) |
||
1859 | ?02: ldx #7 ; Can't insert a new line: lines count overflow |
||
1860 | jsr error |
||
1861 | sec |
||
1862 | rts |
||
1863 | |||
1864 | ; insert byte into buffer at position specified by ixb |
||
1865 | ; in: A = byte to insert |
||
1866 | ; A,X,Y preserved |
||
1867 | ; P227B: |
||
1868 | insert: |
||
1869 | sta ewtmp ; byte to insert |
||
1870 | phx |
||
1871 | phy |
||
1872 | bit bflag ; chek if overwrite mode |
||
1873 | bvc ?00 ; default insert mode |
||
1874 | cmp #$0D ; insert anyway code $0D |
||
1875 | beq ?00 |
||
1876 | tax |
||
1877 | ldy ixb |
||
1878 | lda [pblk],y ; A = byte at position where overwrite |
||
1879 | beq ?00 ; no overwrite null terminator |
||
1880 | cmp #$0D |
||
1881 | beq ?00 ; no overwrite line terminator |
||
1882 | txa |
||
1883 | sta [pblk],y ; overwrite |
||
1884 | bra ?08 ; exit |
||
1885 | ?00: LDY #BNDX |
||
1886 | lda [pblk],y |
||
1887 | sta ewtmp+1 ; save current pointer |
||
1888 | CMP #$FF |
||
1889 | BNE ?02 ; ok, room for move one byte ahead |
||
1890 | JSR newblk ; alloc new block... |
||
1891 | BCC ?01 ; ...for move bytes one room ahead |
||
1892 | PLY |
||
1893 | plx |
||
1894 | lda ewtmp |
||
1895 | RTS |
||
1896 | ?01: ACC16 |
||
1897 | STA wtmp ; save new block |
||
1898 | ?02: ACC16 |
||
1899 | LDA pp6 |
||
1900 | CMP ppage |
||
1901 | ACC08 |
||
1902 | BNE ?03 |
||
1903 | INC ix6 |
||
1904 | ?03 ldy ewtmp+1 |
||
1905 | INY |
||
1906 | ?04: DEY ; loop for move ahead |
||
1907 | lda [pblk],y ; A = byte to move ahead |
||
1908 | INY |
||
1909 | BNE ?06 |
||
1910 | JSR addblk ; insert new block and move byte |
||
1911 | LDY ix6 |
||
1912 | BNE ?05 |
||
1913 | LDA lptmp2+1 ; save new block in pp6 |
||
1914 | STA pp6 |
||
1915 | LDA lptmp2+2 |
||
1916 | STA pp6+1 |
||
1917 | LDA #BSTART |
||
1918 | STA ix6 |
||
1919 | ?05: LDY #$00 |
||
1920 | bra ?07 |
||
1921 | ?06: sta [pblk],y |
||
1922 | ?07: DEY |
||
1923 | CPY ixb ; move bytes until is free... |
||
1924 | BNE ?04 ; ...the position specified by ixb |
||
1925 | LDA ewtmp |
||
1926 | STA [pblk],Y ; store byte |
||
1927 | lda ewtmp+1 ; update pointer |
||
1928 | inc a |
||
1929 | BEQ ?08 |
||
1930 | LDY #BNDX |
||
1931 | STA [pblk],Y |
||
1932 | ?08: ply |
||
1933 | plx |
||
1934 | lda #$80 |
||
1935 | tsb bflag ; set modified flag |
||
1936 | lda ewtmp |
||
1937 | CLC ; no error |
||
1938 | RTS |
||
1939 | |||
1940 | ; align buffer with minimum screen row and save block on pp4 |
||
1941 | ; P1E14: |
||
1942 | findrow: |
||
1943 | LDY #$00 ; start at row = 0 |
||
1944 | ?01: CPY srow ; current screen row |
||
1945 | BEQ ?02 ; already at first row |
||
1946 | JSR startln ; find start of line |
||
1947 | BCS ?02 ; beginning of buffer |
||
1948 | INY |
||
1949 | bra ?01 ; loop |
||
1950 | ?02: STY srow ; store row |
||
1951 | LDA ppage ; save block pointer |
||
1952 | STA pp4 |
||
1953 | LDA ppage+1 |
||
1954 | STA pp4+1 |
||
1955 | LDA ixb |
||
1956 | STA ix4 |
||
1957 | RTS |
||
1958 | |||
1959 | ; get number of bytes from current column to end of line |
||
1960 | ; in: X = text column |
||
1961 | ; out: ccnt updated |
||
1962 | ; P1474: |
||
1963 | xcnt2: |
||
1964 | LDY #$00 |
||
1965 | STY scol |
||
1966 | STY ccol |
||
1967 | JSR pp8mv |
||
1968 | INX |
||
1969 | ?01: CPY ecol |
||
1970 | BEQ ?02 |
||
1971 | DEX |
||
1972 | BEQ ?06 |
||
1973 | JSR getbyte |
||
1974 | BCS ?06 |
||
1975 | CMP #$0D |
||
1976 | BEQ ?06 |
||
1977 | INY |
||
1978 | JSR incptr |
||
1979 | INC ccol |
||
1980 | bra ?01 |
||
1981 | ?02: DEX |
||
1982 | BEQ ?03 |
||
1983 | JSR getbyte |
||
1984 | BCS ?06 |
||
1985 | CMP #$0D |
||
1986 | BEQ ?06 |
||
1987 | INY |
||
1988 | JSR incptr |
||
1989 | INC scol |
||
1990 | INC ccol |
||
1991 | bra ?02 |
||
1992 | ?03: JSR mvpp2 |
||
1993 | ?04: JSR getbyte |
||
1994 | BCS ?05 |
||
1995 | CMP #$0D |
||
1996 | BEQ ?05 |
||
1997 | INY |
||
1998 | JSR incptr |
||
1999 | bra ?04 |
||
2000 | ?05: JSR pp2mv |
||
2001 | ?06: STY ccnt |
||
2002 | RTS |
||
2003 | |||
2004 | ; find beginning of line on block pointed by pp6 |
||
2005 | ; P2477: |
||
2006 | startln6: |
||
2007 | LDA rcnt |
||
2008 | CMP #$17 |
||
2009 | beq ?01 |
||
2010 | INC rcnt |
||
2011 | RTS |
||
2012 | ?01: JSR mvpp2 |
||
2013 | LDA pp6 |
||
2014 | STA ppage |
||
2015 | LDA pp6+1 |
||
2016 | STA ppage+1 |
||
2017 | LDA ix6 |
||
2018 | STA ixb |
||
2019 | JSR startln |
||
2020 | LDA ppage |
||
2021 | STA pp6 |
||
2022 | LDA ppage+1 |
||
2023 | STA pp6+1 |
||
2024 | LDA ixb |
||
2025 | STA ix6 |
||
2026 | bra pp2mv |
||
2027 | |||
2028 | ; find next line on block pointed by pp4 |
||
2029 | ; P249F: |
||
2030 | nextln4: |
||
2031 | JSR mvpp2 |
||
2032 | LDA pp4 |
||
2033 | STA ppage |
||
2034 | LDA pp4+1 |
||
2035 | STA ppage+1 |
||
2036 | LDA ix4 |
||
2037 | STA ixb |
||
2038 | JSR nextln |
||
2039 | LDA ppage |
||
2040 | STA pp4 |
||
2041 | LDA ppage+1 |
||
2042 | STA pp4+1 |
||
2043 | LDA ixb |
||
2044 | STA ix4 |
||
2045 | bra pp2mv |
||
2046 | |||
2047 | ; find beginning of line on block pointed by pp4 |
||
2048 | ; P24BC: |
||
2049 | startln4: |
||
2050 | JSR mvpp2 |
||
2051 | LDA pp4 |
||
2052 | STA ppage |
||
2053 | LDA pp4+1 |
||
2054 | STA ppage+1 |
||
2055 | LDA ix4 |
||
2056 | STA ixb |
||
2057 | JSR startln |
||
2058 | LDA ppage |
||
2059 | STA pp4 |
||
2060 | LDA ppage+1 |
||
2061 | STA pp4+1 |
||
2062 | LDA ixb |
||
2063 | STA ix4 |
||
2064 | bra pp2mv |
||
2065 | |||
2066 | ; calc the bytes count in current line |
||
2067 | ; P141A: |
||
2068 | xcount: |
||
2069 | jsr mvpp2 |
||
2070 | jsr incptr2 |
||
2071 | jsr startln |
||
2072 | dex |
||
2073 | |||
2074 | ; move pp2 to page pointer |
||
2075 | ; P236D: |
||
2076 | pp2mv: |
||
2077 | lda pp2 |
||
2078 | sta ppage |
||
2079 | lda pp2+1 |
||
2080 | sta ppage+1 |
||
2081 | lda ix2 |
||
2082 | sta ixb |
||
2083 | rts |
||
2084 | |||
2085 | ; find next line on block pointed by pp6 |
||
2086 | ; P2455: |
||
2087 | nextln6: |
||
2088 | JSR mvpp2 |
||
2089 | LDA pp6 |
||
2090 | STA ppage |
||
2091 | LDA pp6+1 |
||
2092 | STA ppage+1 |
||
2093 | LDA ix6 |
||
2094 | STA ixb |
||
2095 | JSR nextln |
||
2096 | BCC ?01 |
||
2097 | DEC rcnt |
||
2098 | ?01: LDA ppage |
||
2099 | STA pp6 |
||
2100 | LDA ppage+1 |
||
2101 | STA pp6+1 |
||
2102 | LDA ixb |
||
2103 | STA ix6 |
||
2104 | bra pp2mv |
||
2105 | |||
2106 | ; find next line and save in pp8 |
||
2107 | ; X,Y preserved |
||
2108 | ; P1447: |
||
2109 | nextln8: |
||
2110 | JSR mvpp2 |
||
2111 | phy |
||
2112 | ?01: JSR decptr2 |
||
2113 | BCS ?02 |
||
2114 | lda [pblk],y |
||
2115 | CMP #$0D |
||
2116 | BNE ?01 |
||
2117 | JSR incptr2 |
||
2118 | ?02: ply |
||
2119 | JSR mvpp8 |
||
2120 | bra pp2mv |
||
2121 | |||
2122 | ; move page pointer to pp2 |
||
2123 | ; P2362: |
||
2124 | mvpp2: |
||
2125 | lda ppage |
||
2126 | sta pp2 |
||
2127 | lda ppage+1 |
||
2128 | sta pp2+1 |
||
2129 | lda ixb |
||
2130 | sta ix2 |
||
2131 | rts |
||
2132 | |||
2133 | ; move page pointer to pp8 |
||
2134 | ; P2378: |
||
2135 | mvpp8: |
||
2136 | lda ppage |
||
2137 | sta pp8 |
||
2138 | lda ppage+1 |
||
2139 | sta pp8+1 |
||
2140 | lda ixb |
||
2141 | sta ix8 |
||
2142 | rts |
||
2143 | |||
2144 | ; move pp8 to page pointer |
||
2145 | ; P2383: |
||
2146 | pp8mv: |
||
2147 | lda pp8 |
||
2148 | sta ppage |
||
2149 | lda pp8+1 |
||
2150 | sta ppage+1 |
||
2151 | lda ix8 |
||
2152 | sta ixb |
||
2153 | rts |
||
2154 | |||
2155 | ; count blank from start of line till first non blank |
||
2156 | ; out: ctmp = starting blanks counter |
||
2157 | xblank: |
||
2158 | stz ctmp |
||
2159 | lda #$20 ; test indent flag |
||
2160 | bit bflag |
||
2161 | beq ?06 |
||
2162 | lda ppage ; save current buffer pointer |
||
2163 | sta lptc |
||
2164 | lda ppage+1 |
||
2165 | sta lptc+1 |
||
2166 | lda ixb |
||
2167 | sta lptc+2 |
||
2168 | jsr startln ; find start of line |
||
2169 | ldx #$FF ; beginning blank counter |
||
2170 | ?02: inx |
||
2171 | jsr getbyte2 |
||
2172 | bcs ?04 ; end buffer |
||
2173 | cmp #' ' |
||
2174 | bne ?04 |
||
2175 | jsr incptr2 |
||
2176 | bra ?02 |
||
2177 | ?04: stx ctmp |
||
2178 | lda lptc ; restore buffer pointer |
||
2179 | sta ppage |
||
2180 | lda lptc+1 |
||
2181 | sta ppage+1 |
||
2182 | lda lptc+2 |
||
2183 | sta ixb |
||
2184 | ?06: rts |
||
2185 | |||
2186 | ; get blocks count of buffer |
||
2187 | ; in: C = buffer start page |
||
2188 | ; out: C = blocks count |
||
2189 | ; using lptmp1 long pointer |
||
2190 | ; can be called in 8/16 bit mode |
||
2191 | ; P2262: |
||
2192 | blkcnt: |
||
2193 | php ; save 8/16 bit state |
||
2194 | INDEX08 |
||
2195 | LDX #$00 |
||
2196 | STX <lptmp1 |
||
2197 | CPU16 |
||
2198 | tay |
||
2199 | beq ?03 ; return C = 0 |
||
2200 | STA <lptmp1+1 ; page pointer |
||
2201 | ?01: INX |
||
2202 | LDA [lptmp1] |
||
2203 | BEQ ?02 ; end of buffer |
||
2204 | STA <lptmp1+1 |
||
2205 | bra ?01 |
||
2206 | ?02: TXA |
||
2207 | ?03: plp ; restore 8/16 bit mode |
||
2208 | LONG_OFF |
||
2209 | RTS |
||
2210 | |||
2211 | ; delete byte at current position from block |
||
2212 | ; A,X,Y preserved |
||
2213 | ; using lptc, lptmp1 & lptmp2 long pointer |
||
2214 | ; using wtmp |
||
2215 | ; P238E: |
||
2216 | delbyte: |
||
2217 | pha |
||
2218 | phx |
||
2219 | phy |
||
2220 | ACC16 |
||
2221 | LDA ppage |
||
2222 | sta wtmp ; save current page pointer |
||
2223 | CMP pp6 |
||
2224 | ACC08 |
||
2225 | BNE ?01 |
||
2226 | DEC ix6 ; update |
||
2227 | ?01: LDY #BNDX |
||
2228 | LDA [pblk],Y |
||
2229 | TAX ; X = pointer in block |
||
2230 | CMP ixb |
||
2231 | BNE ?04 ; not last byte in block |
||
2232 | dec a ; update pointer in block |
||
2233 | STA [pblk],Y ; this is last byte in block |
||
2234 | JSR incptr2 |
||
2235 | CPX #BSTART ; empty buffer ? |
||
2236 | BNE ?02 ; no |
||
2237 | lda wtmp+1 ; remove block |
||
2238 | xba |
||
2239 | lda wtmp ; C = page pointer |
||
2240 | JSR delblk |
||
2241 | bra ?06 ; exit |
||
2242 | ?02: lda pp8 |
||
2243 | sta lptc+1 |
||
2244 | lda pp8+1 |
||
2245 | sta lptc+2 |
||
2246 | stz lptc |
||
2247 | LDY #BNDX |
||
2248 | LDA [lptc],Y |
||
2249 | CMP ix8 |
||
2250 | BCS ?06 |
||
2251 | ACC16 |
||
2252 | LDA [lptc] |
||
2253 | STA pp8 |
||
2254 | ACC08 |
||
2255 | LDA #BSTART |
||
2256 | STA ix8 |
||
2257 | bra ?06 |
||
2258 | ?04: dec a ; update pointer |
||
2259 | STA [pblk],Y |
||
2260 | LDY ixb ; move back bytes from end of block |
||
2261 | INY ; to current position |
||
2262 | ?05: LDA [pblk],Y |
||
2263 | DEY |
||
2264 | STA [pblk],Y |
||
2265 | INY |
||
2266 | INY |
||
2267 | BNE ?05 |
||
2268 | ?06: lda #$80 |
||
2269 | tsb bflag ; set modified flag |
||
2270 | ply |
||
2271 | plx |
||
2272 | pla |
||
2273 | rts |
||
2274 | |||
2275 | ; find beginning of next line |
||
2276 | ; in: none |
||
2277 | ; out: CF = 0 if ok, CF = 1 if end of buffer |
||
2278 | ; X = count of bytes till next line |
||
2279 | ; Y preserved |
||
2280 | ; P13CA: |
||
2281 | nextln: |
||
2282 | phy |
||
2283 | ldx #0 ; bytes counter |
||
2284 | ldy ixb |
||
2285 | sec |
||
2286 | lda [pblk],y ; get next byte |
||
2287 | beq ?03 ; if end of buffer exit with CF = 1 |
||
2288 | ?01: cmp #$0D ; end of line ? |
||
2289 | beq ?02 ; yes |
||
2290 | inx |
||
2291 | jsr incptr2 ; Y = next index |
||
2292 | lda [pblk],y ; get next byte |
||
2293 | bra ?01 |
||
2294 | ?02: jsr incptr2 ; beginning of next line |
||
2295 | clc |
||
2296 | ?03: ply |
||
2297 | rts |
||
2298 | |||
2299 | ; find beginning of current line |
||
2300 | ; in: none |
||
2301 | ; out: CF = 0 if ok, CF = 1 if beginning of buffer |
||
2302 | ; X = count of bytes till start of line |
||
2303 | ; Y preserved |
||
2304 | ; P1427: |
||
2305 | startln: |
||
2306 | phy |
||
2307 | ldx #0 ; bytes counter |
||
2308 | jsr decptr2 ; decrement buffer pointer |
||
2309 | bcs ?04 ; exit with CF = 1 if beginning |
||
2310 | inx |
||
2311 | ?01: jsr decptr2 |
||
2312 | bcs ?03 ; we are at the beginning |
||
2313 | lda [pblk],y ; previous byte |
||
2314 | cmp #$0D |
||
2315 | beq ?02 ; end of prev. line |
||
2316 | inx |
||
2317 | bra ?01 |
||
2318 | ?02: jsr incptr2 ; beginning of line |
||
2319 | ?03: clc |
||
2320 | ?04: ply |
||
2321 | rts |
||
2322 | |||
2323 | ; get byte from buffer at current index |
||
2324 | ; in: none |
||
2325 | ; out: A = current byte (CF = 0 if not null, CF = 1 if null) |
||
2326 | ; X,Y preserved |
||
2327 | ; P2353: |
||
2328 | getbyte: |
||
2329 | phy |
||
2330 | ldy ixb |
||
2331 | lda [pblk],y |
||
2332 | clc |
||
2333 | bne ?01 |
||
2334 | sec |
||
2335 | ?01: ply |
||
2336 | rts |
||
2337 | |||
2338 | ; get byte from buffer at current index |
||
2339 | ; in: none |
||
2340 | ; out: A = current byte (CF = 0 if not null, CF = 1 if null) |
||
2341 | ; X preserved |
||
2342 | ; P2353: |
||
2343 | getbyte2: |
||
2344 | ldy ixb |
||
2345 | lda [pblk],y |
||
2346 | beq ?02 |
||
2347 | clc |
||
2348 | rts |
||
2349 | ?02: sec |
||
2350 | rts |
||
2351 | |||
2352 | ; increment buffer pointer |
||
2353 | ; in: none |
||
2354 | ; out: CF = 1 if change block or if end of buffer |
||
2355 | ; A,X,Y preserved |
||
2356 | ; P2333: |
||
2357 | incptr: |
||
2358 | pha |
||
2359 | phy |
||
2360 | lda ixb |
||
2361 | ldy #BNDX |
||
2362 | cmp [pblk],y |
||
2363 | bcc ?04 ; ok, increment |
||
2364 | ACC16 |
||
2365 | lda [pblk] ; next block |
||
2366 | beq ?08 ; end of buffer, exit with CF = 1 |
||
2367 | sta ppage ; update page pointer |
||
2368 | ACC08 |
||
2369 | lda #BSTART-1 ; beginning of buffer |
||
2370 | ?04: inc a |
||
2371 | sta ixb |
||
2372 | ply |
||
2373 | pla |
||
2374 | rts |
||
2375 | ?08: ACC08 |
||
2376 | ply |
||
2377 | pla |
||
2378 | rts |
||
2379 | |||
2380 | ; increment buffer pointer |
||
2381 | ; in: none |
||
2382 | ; out: CF = 1 if change block or if end of buffer |
||
2383 | ; Y = index |
||
2384 | ; X preserved |
||
2385 | incptr2: |
||
2386 | lda ixb |
||
2387 | ldy #BNDX |
||
2388 | cmp [pblk],y |
||
2389 | tay |
||
2390 | bcc ?04 ; ok, increment |
||
2391 | ACC16 |
||
2392 | lda [pblk] ; next block |
||
2393 | beq ?08 ; end of buffer, exit with CF = 1 |
||
2394 | sta ppage ; update page pointer |
||
2395 | ldy #BSTART-1 ; beginning of buffer |
||
2396 | ?04: iny |
||
2397 | sty ixb |
||
2398 | ?08: ACC08 |
||
2399 | rts |
||
2400 | |||
2401 | ; decrement buffer pointer |
||
2402 | ; in: none |
||
2403 | ; out: CF = 1 if at buffer beginning |
||
2404 | ; A,X,Y preserved |
||
2405 | ; P2430: |
||
2406 | decptr: |
||
2407 | pha |
||
2408 | lda ixb |
||
2409 | cmp #BSTART |
||
2410 | bne ?02 ; ok, decrement |
||
2411 | phy |
||
2412 | ldy #BPREV ; previous page pointer |
||
2413 | ACC16 |
||
2414 | LDA [pblk],Y |
||
2415 | beq ?08 ; exit with CF = 1 |
||
2416 | sta ppage ; update page pointer |
||
2417 | ACC08 |
||
2418 | LDY #BNDX |
||
2419 | LDA [pblk],Y |
||
2420 | ply |
||
2421 | bra ?04 |
||
2422 | ?02: dec a |
||
2423 | ?04: sta ixb |
||
2424 | clc ; ok, exit with CF = 0 |
||
2425 | pla |
||
2426 | rts |
||
2427 | ?08: ACC08SEC |
||
2428 | ply |
||
2429 | pla |
||
2430 | rts |
||
2431 | |||
2432 | ; decrement buffer pointer |
||
2433 | ; in: none |
||
2434 | ; out: CF = 1 if at buffer beginning |
||
2435 | ; Y = index |
||
2436 | ; X preserved |
||
2437 | decptr2: |
||
2438 | ldy ixb |
||
2439 | cpy #BSTART |
||
2440 | bne ?02 ; ok, decrement |
||
2441 | ldy #BPREV ; previous page pointer |
||
2442 | ACC16 |
||
2443 | LDA [pblk],Y |
||
2444 | beq ?08 ; exit with CF = 1 |
||
2445 | sta ppage ; update page pointer |
||
2446 | ACC08 |
||
2447 | LDY #BNDX |
||
2448 | LDA [pblk],Y |
||
2449 | tay |
||
2450 | iny |
||
2451 | ?02: dey |
||
2452 | ?04: sty ixb |
||
2453 | clc ; ok, exit with CF = 0 |
||
2454 | rts |
||
2455 | ?08: ACC08SEC |
||
2456 | ldy ixb |
||
2457 | rts |
||
2458 | |||
2459 | ; insert new block in buffer and store byte in new block |
||
2460 | ; in: wtmp = page pointer of new block |
||
2461 | ; A = byte to store |
||
2462 | ; out: buffer linked list modified |
||
2463 | ; using lptmp2 long pointer |
||
2464 | ; A,X preserved |
||
2465 | ; P22DF: |
||
2466 | addblk: |
||
2467 | stz lptmp2 ; using lptmp2 long pointer |
||
2468 | PHA ; save byte to store |
||
2469 | ACC16 |
||
2470 | LDA [pblk] ; next page pointer |
||
2471 | PHA ; save |
||
2472 | BEQ ?01 ; next = 0 |
||
2473 | STA lptmp2+1 ; lptmp2 = next |
||
2474 | LDA wtmp ; new page pointer |
||
2475 | LDY #BPREV |
||
2476 | STA [lptmp2],Y ; next->prev = new page pointer |
||
2477 | bra ?02 |
||
2478 | ?01: LDA wtmp ; next = new page pointer |
||
2479 | ?02: STA [pblk] |
||
2480 | STA lptmp2+1 |
||
2481 | LDA [lptmp2] ; next free page pointer |
||
2482 | STA pfree |
||
2483 | PLA |
||
2484 | STA [lptmp2] ; new page next = cur->next |
||
2485 | LDA ppage |
||
2486 | LDY #BPREV |
||
2487 | STA [lptmp2],Y ; new page prev = cur |
||
2488 | ACC08 |
||
2489 | LDA #BSTART |
||
2490 | LDY #BNDX |
||
2491 | STA [lptmp2],Y ; buffer index |
||
2492 | PLA |
||
2493 | INY |
||
2494 | STA [lptmp2],Y ; store byte |
||
2495 | RTS |
||
2496 | |||
2497 | ; remove a block from buffer and put in free blocks list |
||
2498 | ; in: C = page pointer of block to remove |
||
2499 | ; using lptmp1 & lptmp2 long pointers |
||
2500 | ; X preserved |
||
2501 | ; P23EC: |
||
2502 | delblk: |
||
2503 | stz lptmp1 ; using lptmp1 & lptmp2 long pointer |
||
2504 | stz lptmp2 |
||
2505 | ACC16 |
||
2506 | STA lptmp1+1 ; page pointer to removing block |
||
2507 | CMP pp4 |
||
2508 | BNE ?01 |
||
2509 | lda [lptmp1] |
||
2510 | STA pp4 ; next block |
||
2511 | LDY #BSTART |
||
2512 | STY ix4 |
||
2513 | ?01: lda [lptmp1] |
||
2514 | BNE ?02 |
||
2515 | LDY #BPREV ; this is the first block |
||
2516 | lda [lptmp1],y |
||
2517 | bra ?03 |
||
2518 | ?02: STA lptmp2+1 ; next block |
||
2519 | LDY #BPREV |
||
2520 | lda [lptmp1],y ; next->prev = this->prev |
||
2521 | STA [lptmp2],Y |
||
2522 | ?03: BNE ?04 ; prev != NULL |
||
2523 | LDA lptmp2+1 ; prev = NULL => next block |
||
2524 | STA pbuf ; become first block of this buffer |
||
2525 | LDX xbuf |
||
2526 | pha |
||
2527 | ACC08 |
||
2528 | txa |
||
2529 | asl a |
||
2530 | tax |
||
2531 | ACC16 |
||
2532 | pla |
||
2533 | STA bstart,X ; store first block of this buffer |
||
2534 | bra ?05 |
||
2535 | ?04: STA lptmp2+1 ; prev block |
||
2536 | lda [lptmp1] ; prev->next = this->next |
||
2537 | STA [lptmp2] |
||
2538 | ?05: LDA pfree ; insert this block on free list |
||
2539 | STA [lptmp1] |
||
2540 | LDA lptmp1+1 |
||
2541 | STA pfree |
||
2542 | ACC08 |
||
2543 | RTS |
||
2544 | |||
2545 | ; garbage collection -- free unused memory assigned to a buffer |
||
2546 | ; out: CF = 0 if completed, otherwise CF = 1 |
||
2547 | ; can be called in both 8/16 bit |
||
2548 | ; P1855: |
||
2549 | garbc: |
||
2550 | php ; save 8/16 bit mode |
||
2551 | CPU08 |
||
2552 | stz lptc ; clear used memory |
||
2553 | stz lpte ; using long pointer lptc & lpte |
||
2554 | stz tmpb |
||
2555 | stz tmpc |
||
2556 | stz tmpd |
||
2557 | stz tmpe |
||
2558 | stz tmpf |
||
2559 | ACC16CLC |
||
2560 | LDA pbuf ; first block of the buffer |
||
2561 | PHA |
||
2562 | ?00: PLA |
||
2563 | STA lptc+1 |
||
2564 | LDA [lptc] |
||
2565 | bne ?01 |
||
2566 | plp ; only this block -- done |
||
2567 | clc |
||
2568 | rts |
||
2569 | ?01: pha ; save next block |
||
2570 | ACC08 |
||
2571 | ldy #BNDX |
||
2572 | LDA [lptc],Y |
||
2573 | TAX ; X = pointer in block |
||
2574 | ACC16CLC |
||
2575 | INX ; full block? |
||
2576 | beq ?00 ; yes -- check next block |
||
2577 | STX tmp7 ; tmp7 = next free |
||
2578 | pla ; next block |
||
2579 | STA lpte+1 |
||
2580 | LDX #1 |
||
2581 | CMP ppage |
||
2582 | BNE ?02 |
||
2583 | STX tmpb ; tmpb = 1 if this block = current block |
||
2584 | ?02: CMP pp8 |
||
2585 | bne ?03 |
||
2586 | STX tmpc ; tmpc = 1 if this block = pp8 |
||
2587 | ?03: CMP pp4 |
||
2588 | bne ?04 |
||
2589 | STX tmpd ; tmpd = 1 if this block = pp4 |
||
2590 | ?04: CMP pp6 |
||
2591 | bne ?05 |
||
2592 | STX tmpe ; tmpe = 1 if this block = pp6 |
||
2593 | ?05: CMP pp0 |
||
2594 | bne ?06 |
||
2595 | STX tmpf ; tmpf = 1 if this block = pp0 |
||
2596 | ?06: ACC08 |
||
2597 | LDY #BNDX |
||
2598 | LDA [lpte],Y |
||
2599 | STA tmp9 ; tmp9 = pointer in next block |
||
2600 | iny |
||
2601 | STY tmp8 ; tmp8 = dynamic pointer in next block |
||
2602 | ?07: LDY tmp8 ; loop |
||
2603 | LDA [lpte],Y ; move first byte of next block |
||
2604 | LDY tmp7 ; to next free room in this block |
||
2605 | STA [lptc],Y |
||
2606 | ACC16 |
||
2607 | LDA lptc+1 ; C = this block |
||
2608 | LDX tmpb |
||
2609 | beq ?08 |
||
2610 | LDX ixb |
||
2611 | CPX tmp8 |
||
2612 | BNE ?08 |
||
2613 | STA ppage ; set to this block |
||
2614 | STY ixb |
||
2615 | LDX #0 |
||
2616 | STX tmpb |
||
2617 | ?08: LDX tmpc |
||
2618 | BEQ ?09 |
||
2619 | LDX ix8 |
||
2620 | CPX tmp8 |
||
2621 | BNE ?09 |
||
2622 | STA pp8 ; set to this block |
||
2623 | STY ix8 |
||
2624 | LDX #0 |
||
2625 | STX tmpc |
||
2626 | ?09: LDX tmpd |
||
2627 | BEQ ?10 |
||
2628 | LDX ix4 |
||
2629 | CPX tmp8 |
||
2630 | BNE ?10 |
||
2631 | STA pp4 ; set to this block |
||
2632 | STY ix4 |
||
2633 | LDX #0 |
||
2634 | STX tmpd |
||
2635 | ?10: LDX tmpe |
||
2636 | BEQ ?11 |
||
2637 | LDX ix6 |
||
2638 | CPX tmp8 |
||
2639 | BNE ?11 |
||
2640 | STA pp6 ; set to this block |
||
2641 | STY ix6 |
||
2642 | LDX #0 |
||
2643 | STX tmpe |
||
2644 | ?11: LDX tmpf |
||
2645 | BEQ ?12 |
||
2646 | LDX ix0 |
||
2647 | CPX tmp8 |
||
2648 | BNE ?12 |
||
2649 | STA pp0 ; set to this block |
||
2650 | STY ix0 |
||
2651 | LDX #0 |
||
2652 | STX tmpf |
||
2653 | ?12: LDX tmp8 ; X = pointer in next block |
||
2654 | LDA lpte+1 ; C = next block |
||
2655 | ACC08 |
||
2656 | CPX tmp9 ; if same pointer then next block now |
||
2657 | BEQ ?13 ; is empty and can be freed |
||
2658 | INC tmp8 |
||
2659 | INC tmp7 |
||
2660 | bne ?07 ; loop move byte |
||
2661 | BEQ ?15 ; continue |
||
2662 | ?13: JSR delblk ; remove next block (C) |
||
2663 | LDY #BNDX |
||
2664 | LDA tmp7 ; set pointer in block |
||
2665 | STA [lptc],Y |
||
2666 | plp |
||
2667 | CLC ; done |
||
2668 | RTS |
||
2669 | ?15: LDA #$FF ; full block |
||
2670 | LDY #BNDX |
||
2671 | STA [lptc],Y |
||
2672 | INY |
||
2673 | STY tmp7 |
||
2674 | LDA tmp8 |
||
2675 | SEC |
||
2676 | SBC #BSTART |
||
2677 | STA tmpa ; residue |
||
2678 | INC tmp9 ; limit pointer in next block |
||
2679 | LDY tmp8 |
||
2680 | LDX tmp7 |
||
2681 | ?16: LDA [lpte],Y ; move byte |
||
2682 | TXY |
||
2683 | STA [lpte],Y |
||
2684 | INX |
||
2685 | INC tmp8 |
||
2686 | LDY tmp8 |
||
2687 | CPY tmp9 |
||
2688 | BNE ?16 ; move all bytes |
||
2689 | LDA tmpb |
||
2690 | BEQ ?17 |
||
2691 | LDA ixb |
||
2692 | SEC |
||
2693 | SBC tmpa |
||
2694 | STA ixb |
||
2695 | ?17: LDA tmpc |
||
2696 | BEQ ?18 |
||
2697 | LDA ix8 |
||
2698 | SEC |
||
2699 | SBC tmpa |
||
2700 | STA ix8 |
||
2701 | ?18: LDA tmpd |
||
2702 | BEQ ?19 |
||
2703 | LDA ix4 |
||
2704 | SEC |
||
2705 | SBC tmpa |
||
2706 | STA ix4 |
||
2707 | ?19: LDA tmpe |
||
2708 | BEQ ?20 |
||
2709 | LDA ix6 |
||
2710 | SEC |
||
2711 | SBC tmpa |
||
2712 | STA ix6 |
||
2713 | ?20: LDA tmpf |
||
2714 | BEQ ?21 |
||
2715 | LDA ix0 |
||
2716 | SEC |
||
2717 | SBC tmpa |
||
2718 | STA ix0 |
||
2719 | ?21: LDA tmp9 |
||
2720 | CLC |
||
2721 | SBC tmpa |
||
2722 | LDY #BNDX ; update pointer in next buffer |
||
2723 | STA [lpte],Y |
||
2724 | plp |
||
2725 | SEC ; not done |
||
2726 | RTS |
||
2727 | |||
2728 | ;----------------------------------------------------------------- |
||
2729 | ; high level screen |
||
2730 | |||
2731 | ; update last edit text row on screen |
||
2732 | ; P13E5: |
||
2733 | updlst: |
||
2734 | ACC16 |
||
2735 | LDA #!LSTLINE |
||
2736 | sta stxtp |
||
2737 | ora #!TXTATTR |
||
2738 | sta sattp |
||
2739 | ACC08 |
||
2740 | LDA fslct |
||
2741 | BEQ ?01 |
||
2742 | LDA nslcth |
||
2743 | BPL ?01 |
||
2744 | LDA #$17 |
||
2745 | SEC |
||
2746 | SBC srow |
||
2747 | CLC |
||
2748 | ADC nslctl |
||
2749 | LDA #$00 |
||
2750 | ADC nslcth |
||
2751 | BPL ?01 |
||
2752 | LDA #$80 |
||
2753 | STA frev |
||
2754 | ?01: LDX pp6 |
||
2755 | lda pp6+1 |
||
2756 | LDY ix6 |
||
2757 | JSR setptr |
||
2758 | bra updrow |
||
2759 | |||
2760 | ; update first edit text row on screen |
||
2761 | ; P1E30: |
||
2762 | updfst: |
||
2763 | ACC16 |
||
2764 | LDA #!TXTADDR |
||
2765 | sta stxtp |
||
2766 | ora #!TXTATTR |
||
2767 | sta sattp |
||
2768 | ACC08 |
||
2769 | LDA fslct |
||
2770 | BEQ ?01 |
||
2771 | LDA nslcth |
||
2772 | BMI ?01 |
||
2773 | LDA srow |
||
2774 | SEC |
||
2775 | SBC nslctl |
||
2776 | LDA #$00 |
||
2777 | SBC nslcth |
||
2778 | BPL ?01 |
||
2779 | LDA #$80 |
||
2780 | STA frev |
||
2781 | ?01: LDX pp4 |
||
2782 | lda pp4+1 |
||
2783 | LDY ix4 |
||
2784 | JSR setptr |
||
2785 | |||
2786 | ; update current row on screen |
||
2787 | ; P2779: |
||
2788 | updrow: |
||
2789 | lda !$FFFF,x |
||
2790 | BNE ?04 |
||
2791 | lda #' ' ; blank row |
||
2792 | xba |
||
2793 | lda eattr ; A = attribute, B = blank |
||
2794 | ldy #MAXCOLS-1 |
||
2795 | ?02: sta [sattp],y ; store attribute |
||
2796 | xba |
||
2797 | sta [stxtp],y ; store blank |
||
2798 | xba |
||
2799 | dey |
||
2800 | bpl ?02 |
||
2801 | SEC |
||
2802 | RTS |
||
2803 | ?04: LDY ecol |
||
2804 | BEQ updr2 |
||
2805 | ; P279F: |
||
2806 | updr1: |
||
2807 | lda !$FFFF,x |
||
2808 | CMP #$0D |
||
2809 | BNE ?02 |
||
2810 | LDY #$00 |
||
2811 | bra updr9 |
||
2812 | ?02: CPX ebtmp2 |
||
2813 | BNE ?03 |
||
2814 | JSR updptr |
||
2815 | ?03: INX |
||
2816 | DEY |
||
2817 | BNE updr1 |
||
2818 | ; P27B7: |
||
2819 | updr2: |
||
2820 | lda !$FFFF,x |
||
2821 | CMP #$0D |
||
2822 | BEQ updr9 |
||
2823 | CPY #MAXCOLS |
||
2824 | BNE updr7 |
||
2825 | updr5: CPX ebtmp2 |
||
2826 | BCC ?06 |
||
2827 | JSR updptr |
||
2828 | ?06: INX |
||
2829 | ; P27CC: |
||
2830 | updr3: |
||
2831 | lda !$FFFF,x |
||
2832 | CMP #$0D |
||
2833 | BNE updr5 |
||
2834 | beq updr9 |
||
2835 | updr7: sta [stxtp],y ; store char in video ram |
||
2836 | lda eattr ; editor attribute |
||
2837 | EOR frev ; set reverse bit |
||
2838 | sta [sattp],y ; store attribute |
||
2839 | INY |
||
2840 | CPX ebtmp2 |
||
2841 | BCC ?08 |
||
2842 | JSR updptr |
||
2843 | ?08: INX |
||
2844 | bra updr2 |
||
2845 | updr9: CPX ebtmp2 |
||
2846 | BCC ?10 |
||
2847 | JSR updptr |
||
2848 | ?10: INX |
||
2849 | LDA #' ' ; pad row with blank |
||
2850 | xba ; B = char, A = attribute |
||
2851 | lda eattr ; editor attribute |
||
2852 | EOR frev ; set reverse bit |
||
2853 | ?11: CPY #MAXCOLS |
||
2854 | BEQ ?12 |
||
2855 | sta [sattp],y ; store attribute |
||
2856 | xba |
||
2857 | sta [stxtp],y ; store blank |
||
2858 | xba |
||
2859 | INY |
||
2860 | BNE ?11 |
||
2861 | ?12: STZ frev ; clear reverse flag bit |
||
2862 | CLC |
||
2863 | RTS |
||
2864 | |||
2865 | ; scroll right editor window (move window left one column) |
||
2866 | ; P24D9: |
||
2867 | scrlright: |
||
2868 | phb ; save DBR |
||
2869 | ACC16CLC |
||
2870 | lda #!TXTADDR ; set screen text pointer |
||
2871 | sta stxtp |
||
2872 | lda #!TXTATTR ; set screen attributes pointer |
||
2873 | sta sattp |
||
2874 | LDA pp4 ; buffer page pointer |
||
2875 | STA lptc+1 ; B = bank, A = page |
||
2876 | ACC08 |
||
2877 | phk |
||
2878 | plb ; DBR = PBR |
||
2879 | STZ !sclr1+1 |
||
2880 | STZ !sclr2+1 |
||
2881 | STA !sclr1+2 |
||
2882 | STA !sclr2+2 |
||
2883 | STZ lptc |
||
2884 | LDA ecol |
||
2885 | ADC #MAXCOLS-1 |
||
2886 | STA ewtmp2+1 |
||
2887 | xba ; A = bank |
||
2888 | pha |
||
2889 | plb ; set DBR to current buffer |
||
2890 | LDY #BNDX |
||
2891 | lda (lptc),y |
||
2892 | STA ebtmp |
||
2893 | JSR chksel |
||
2894 | stz ewtmp+1 ; counter 24 rows |
||
2895 | LDX ix4 |
||
2896 | ;P2512: |
||
2897 | sclr1: lda !$FFFF,x |
||
2898 | beq sclr3 |
||
2899 | LDY #$00 |
||
2900 | STY ewtmp2 |
||
2901 | ;P251D: |
||
2902 | sclr2: lda !$FFFF,x |
||
2903 | CMP #$0D |
||
2904 | BNE ?03 |
||
2905 | lda ewtmp2 |
||
2906 | BNE ?06 |
||
2907 | LDA #' ' ; blank padding |
||
2908 | sta ewtmp |
||
2909 | bra ?06 |
||
2910 | ?03: cpy ewtmp2+1 |
||
2911 | BNE ?04 |
||
2912 | sta ewtmp |
||
2913 | INC ewtmp2 |
||
2914 | ?04: CPX ebtmp |
||
2915 | BNE ?05 |
||
2916 | JSR setscrp |
||
2917 | ?05: INX |
||
2918 | INY |
||
2919 | bra sclr2 |
||
2920 | ?06: CPX ebtmp |
||
2921 | BNE ?07 |
||
2922 | JSR setscrp |
||
2923 | ?07: INX |
||
2924 | lda #^TXTADDR |
||
2925 | phb |
||
2926 | pha |
||
2927 | plb |
||
2928 | ldy #$01 ; move left text and attributes |
||
2929 | ?08: lda (stxtp),y |
||
2930 | xba |
||
2931 | lda (sattp),y ; A = attribute, B = text |
||
2932 | dey |
||
2933 | sta (sattp),y |
||
2934 | xba |
||
2935 | sta (stxtp),y |
||
2936 | iny |
||
2937 | iny |
||
2938 | cpy #MAXCOLS |
||
2939 | bcc ?08 |
||
2940 | DEY |
||
2941 | lda ewtmp |
||
2942 | sta (stxtp),y |
||
2943 | lda eattr ; editor attribute |
||
2944 | JSR tglrev ; check reverse bit |
||
2945 | sta (sattp),y |
||
2946 | plb |
||
2947 | ACC16CLC |
||
2948 | LDA stxtp |
||
2949 | ADC #MAXCOLS |
||
2950 | STA stxtp |
||
2951 | ora #!TXTATTR |
||
2952 | sta sattp |
||
2953 | ACC08 |
||
2954 | INC ewtmp+1 |
||
2955 | LDA ewtmp+1 |
||
2956 | CMP #$18 |
||
2957 | bne sclr1 |
||
2958 | sclr3: plb |
||
2959 | RTS |
||
2960 | |||
2961 | ; scroll left editor window (move window right one column) |
||
2962 | ; P25CF: |
||
2963 | scrlleft: |
||
2964 | phb ; save DBR |
||
2965 | ACC16CLC |
||
2966 | lda #!TXTADDR ; set screen text pointer |
||
2967 | sta stxtp |
||
2968 | lda #!TXTATTR ; set screen attributes pointer |
||
2969 | sta sattp |
||
2970 | LDA pp4 ; buffer page pointer |
||
2971 | STA lptc+1 ; B = bank, A = page |
||
2972 | ACC08 |
||
2973 | phk |
||
2974 | plb ; DBR = PBR |
||
2975 | STZ !scll1+1 |
||
2976 | STZ !scll2+1 |
||
2977 | STA !scll1+2 |
||
2978 | STA !scll2+2 |
||
2979 | STZ lptc |
||
2980 | xba ; A = bank |
||
2981 | pha |
||
2982 | plb ; set DBR to current buffer |
||
2983 | LDY #BNDX |
||
2984 | lda (lptc),y |
||
2985 | STA ebtmp |
||
2986 | JSR chksel |
||
2987 | STZ ewtmp+1 ; counter 24 rows |
||
2988 | LDX ix4 |
||
2989 | ;P25FF: |
||
2990 | scll1: |
||
2991 | lda !$FFFF,x |
||
2992 | beq sclr3 |
||
2993 | LDY #$00 |
||
2994 | STY ewtmp2 |
||
2995 | ;P260A: |
||
2996 | scll2: |
||
2997 | lda !$FFFF,x |
||
2998 | CMP #$0D |
||
2999 | BNE ?05 |
||
3000 | lda ewtmp2 |
||
3001 | BNE ?07a |
||
3002 | LDA #' ' |
||
3003 | sta ewtmp |
||
3004 | ?04: bra ?07a |
||
3005 | ?05: CPY ecol |
||
3006 | BNE ?06 |
||
3007 | sta ewtmp |
||
3008 | INC ewtmp2 |
||
3009 | ?06: CPX ebtmp |
||
3010 | BNE ?07 |
||
3011 | JSR setscrp |
||
3012 | ?07: INX |
||
3013 | INY |
||
3014 | bra scll2 |
||
3015 | ?07a: CPX ebtmp |
||
3016 | BNE ?08 |
||
3017 | JSR setscrp |
||
3018 | ?08: INX |
||
3019 | lda #^TXTADDR ; move right text and attributes |
||
3020 | phb |
||
3021 | pha |
||
3022 | plb |
||
3023 | ldy #MAXCOLS |
||
3024 | ?09: dey |
||
3025 | dey |
||
3026 | bmi ?10 |
||
3027 | lda (stxtp),y |
||
3028 | xba |
||
3029 | lda (sattp),y ; A = attribute, B = text |
||
3030 | iny |
||
3031 | sta (sattp),y |
||
3032 | xba |
||
3033 | sta (stxtp),y |
||
3034 | bra ?09 |
||
3035 | ?10: iny |
||
3036 | lda ewtmp |
||
3037 | sta (stxtp),y |
||
3038 | lda eattr ; editor attribute |
||
3039 | JSR tglrev ; check reverse bit |
||
3040 | sta (sattp),y |
||
3041 | plb |
||
3042 | ACC16CLC |
||
3043 | LDA stxtp |
||
3044 | ADC #MAXCOLS |
||
3045 | STA stxtp |
||
3046 | ora #!TXTATTR |
||
3047 | sta sattp |
||
3048 | ACC08 |
||
3049 | INC ewtmp+1 |
||
3050 | LDA ewtmp+1 |
||
3051 | CMP #$18 |
||
3052 | bne scll1 |
||
3053 | plb |
||
3054 | RTS |
||
3055 | |||
3056 | ; set scroll routine pointers |
||
3057 | ; this routine change DBR |
||
3058 | ; P25AF: |
||
3059 | setscrp: |
||
3060 | phy |
||
3061 | ACC16 |
||
3062 | lda [lptc] |
||
3063 | STA lptc+1 ; B = bank, A = page |
||
3064 | ACC08 |
||
3065 | phk |
||
3066 | plb ; DBR = PBR |
||
3067 | STA !sclr1+2 |
||
3068 | STA !sclr2+2 |
||
3069 | STA !scll1+2 |
||
3070 | STA !scll2+2 |
||
3071 | xba ; A = buffer bank |
||
3072 | pha |
||
3073 | plb ; DBR = buffer bank |
||
3074 | LDY #BNDX |
||
3075 | lda (lptc),y |
||
3076 | STA ebtmp |
||
3077 | tyx |
||
3078 | ply |
||
3079 | rts |
||
3080 | |||
3081 | ; set update routine pointers |
||
3082 | ; this routine change DBR |
||
3083 | ; in: A = bank, X = page, Y = index |
||
3084 | ; out: X = index |
||
3085 | ; P2751: |
||
3086 | setptr: |
||
3087 | phk |
||
3088 | plb ; DBR = PBR |
||
3089 | STZ lptc |
||
3090 | STA lptc+2 |
||
3091 | STZ !updrow+1 |
||
3092 | STZ !updr1+1 |
||
3093 | STZ !updr2+1 |
||
3094 | STZ !updr3+1 |
||
3095 | STX lptc+1 |
||
3096 | STX updrow+2 |
||
3097 | STX updr1+2 |
||
3098 | STX updr2+2 |
||
3099 | STX updr3+2 |
||
3100 | TYX |
||
3101 | pha |
||
3102 | plb ; DBR = buffer bank |
||
3103 | sta sbank ; save bank |
||
3104 | LDY #BNDX |
||
3105 | lda (lptc),y |
||
3106 | STA ebtmp2 |
||
3107 | RTS |
||
3108 | |||
3109 | ; update routine pointers to start of a block |
||
3110 | ; this routine change DBR |
||
3111 | ; out: X = index |
||
3112 | ; P282A: |
||
3113 | updptr: |
||
3114 | phy |
||
3115 | ACC16 |
||
3116 | lda [lptc] |
||
3117 | STA lptc+1 ; B = bank, A = page |
||
3118 | ACC08 |
||
3119 | phk |
||
3120 | plb ; DBR = PBR |
||
3121 | STA !updrow+2 |
||
3122 | STA !updr1+2 |
||
3123 | STA !updr2+2 |
||
3124 | STA !updr3+2 |
||
3125 | xba ; A = buffer bank |
||
3126 | pha |
||
3127 | plb ; DBR = buffer bank |
||
3128 | sta sbank ; save bank |
||
3129 | LDY #BNDX |
||
3130 | lda (lptc),y |
||
3131 | STA ebtmp2 |
||
3132 | tyx |
||
3133 | ply |
||
3134 | rts |
||
3135 | |||
3136 | ; check selected text range in screen row's |
||
3137 | ; rsctl is starting selection screen row |
||
3138 | ; rscth is ending selection screen row |
||
3139 | ; P2693: |
||
3140 | chksel: |
||
3141 | LDA fslct |
||
3142 | BEQ ?03 |
||
3143 | LDA nslcth ; if negative range |
||
3144 | BMI ?02 |
||
3145 | LDA srow |
||
3146 | STA rslcth |
||
3147 | SEC |
||
3148 | SBC nslctl |
||
3149 | STA rslctl |
||
3150 | LDA #$00 |
||
3151 | SBC nslcth |
||
3152 | BPL ?01 |
||
3153 | LDA #$00 |
||
3154 | STA rslctl |
||
3155 | ?01: rts |
||
3156 | ?02: LDA srow |
||
3157 | inc a |
||
3158 | sta rslctl |
||
3159 | SEC |
||
3160 | SBC nslctl |
||
3161 | inc a |
||
3162 | sta rslcth |
||
3163 | LDA #$FF |
||
3164 | SBC nslcth |
||
3165 | BMI ?03 |
||
3166 | LDA #$19 |
||
3167 | STA rslcth |
||
3168 | ?03: RTS |
||
3169 | |||
3170 | ; invert reverse bit attribute |
||
3171 | ; in: A = attribute |
||
3172 | ; P26D9: |
||
3173 | tglrev: |
||
3174 | PHA |
||
3175 | LDA fslct |
||
3176 | BEQ ?01 |
||
3177 | LDA ewtmp+1 ; current showed screen row |
||
3178 | CMP rslctl |
||
3179 | BCC ?01 |
||
3180 | CMP rslcth |
||
3181 | BCS ?01 |
||
3182 | PLA |
||
3183 | EOR #$80 |
||
3184 | rts |
||
3185 | ?01: PLA |
||
3186 | RTS |
||
3187 | |||
3188 | ;----------------------------------------------------------------- |
||
3189 | ; low level screen |
||
3190 | |||
3191 | ; clear last text line |
||
3192 | ; P154B: |
||
3193 | clrlst: |
||
3194 | ldx #<LSTLINE |
||
3195 | lda #>LSTLINE |
||
3196 | ldy #^LSTLINE |
||
3197 | stx lptc |
||
3198 | stx lptc1 |
||
3199 | sta lptc+1 |
||
3200 | ora #>TXTATTR |
||
3201 | sta lptc1+1 |
||
3202 | sty lptc+2 |
||
3203 | sty lptc1+2 |
||
3204 | lda #' ' |
||
3205 | xba |
||
3206 | lda eattr ; A = attribute, B = blank |
||
3207 | ldy #MAXCOLS-1 |
||
3208 | ?02: sta [lptc1],y ; store attribute |
||
3209 | xba |
||
3210 | sta [lptc],y ; store blank |
||
3211 | xba |
||
3212 | dey |
||
3213 | bpl ?02 |
||
3214 | rts |
||
3215 | |||
3216 | ; set default status line attributes |
||
3217 | ; P14C9: |
||
3218 | setstla: |
||
3219 | ldx #<STLATTR |
||
3220 | ldy #>STLATTR |
||
3221 | lda #^STLATTR |
||
3222 | stx lptc |
||
3223 | sty lptc+1 |
||
3224 | sta lptc+2 |
||
3225 | lda slattr ; status line attribute |
||
3226 | ldy #MAXCOLS-1 |
||
3227 | ?02: sta [lptc],y |
||
3228 | dey |
||
3229 | bpl ?02 |
||
3230 | rts |
||
3231 | |||
3232 | ; set default editor attributes |
||
3233 | ; P14D5: |
||
3234 | setattr: |
||
3235 | phb |
||
3236 | INDEX16 |
||
3237 | ldx #!TXTATTR |
||
3238 | lda #^TXTATTR |
||
3239 | stx lptc |
||
3240 | pha |
||
3241 | plb |
||
3242 | lda eattr ; editor attribute |
||
3243 | ldy #TXTCNT-1 |
||
3244 | ?02: sta (lptc),y |
||
3245 | dey |
||
3246 | bpl ?02 |
||
3247 | INDEX08 |
||
3248 | plb |
||
3249 | rts |
||
3250 | |||
3251 | ; increment screen row |
||
3252 | ; P1529: |
||
3253 | incrow: |
||
3254 | ACC16CLC |
||
3255 | lda curs |
||
3256 | adc #MAXCOLS |
||
3257 | sta curs |
||
3258 | ACC08 |
||
3259 | inc srow |
||
3260 | rts |
||
3261 | |||
3262 | ; decrement screen row |
||
3263 | ; P153A: |
||
3264 | decrow: |
||
3265 | ACC16CLC |
||
3266 | lda curs |
||
3267 | sbc #MAXCOLS-1 ; take account carry ! |
||
3268 | sta curs |
||
3269 | ACC08 |
||
3270 | dec srow |
||
3271 | rts |
||
3272 | |||
3273 | ; reverse screen row (invert "reverse" bit) |
||
3274 | ; P1DD3: |
||
3275 | revrow: |
||
3276 | ACC16 |
||
3277 | lda stxtp |
||
3278 | ora #!TXTATTR |
||
3279 | sta sattp |
||
3280 | ACC08 |
||
3281 | ldy #MAXCOLS-1 |
||
3282 | ?02: lda [sattp],y |
||
3283 | eor #$80 |
||
3284 | sta [sattp],y |
||
3285 | dey |
||
3286 | bpl ?02 |
||
3287 | rts |
||
3288 | |||
3289 | ; scroll down editor window (move window up one row) |
||
3290 | ; P28BD: |
||
3291 | scrldown: |
||
3292 | phb |
||
3293 | CPU16CLC |
||
3294 | lda #!TXTADDR |
||
3295 | tax |
||
3296 | sta lptc |
||
3297 | adc #MAXCOLS |
||
3298 | sta lpte |
||
3299 | txa |
||
3300 | ora #!TXTATTR |
||
3301 | sta lptc1 |
||
3302 | adc #MAXCOLS |
||
3303 | sta lpte1 |
||
3304 | CPU08 |
||
3305 | lda #^TXTADDR |
||
3306 | pha |
||
3307 | plb |
||
3308 | ldx #$17 ; move 23 rows |
||
3309 | ?02: ldy #MAXCOLS-1 |
||
3310 | ?04: lda (lpte),y |
||
3311 | sta (lptc),y |
||
3312 | lda (lpte1),y |
||
3313 | sta (lptc1),y |
||
3314 | dey |
||
3315 | bpl ?04 |
||
3316 | ACC16CLC |
||
3317 | lda lpte |
||
3318 | sta lptc |
||
3319 | adc #MAXCOLS |
||
3320 | sta lpte |
||
3321 | lda lpte1 |
||
3322 | sta lptc1 |
||
3323 | adc #MAXCOLS |
||
3324 | sta lpte1 |
||
3325 | ACC08 |
||
3326 | dex |
||
3327 | bne ?02 |
||
3328 | plb |
||
3329 | rts |
||
3330 | |||
3331 | ; scroll up editor window (move window down one row) |
||
3332 | ; P28F9: |
||
3333 | scrlup: |
||
3334 | phb |
||
3335 | CPU16CLC |
||
3336 | lda #!LSTLINE |
||
3337 | sta lptc |
||
3338 | tax |
||
3339 | sbc #MAXCOLS-1 ; take account of CF = 0 ! |
||
3340 | sta lpte |
||
3341 | txa |
||
3342 | ora #!TXTATTR |
||
3343 | sta lptc1 |
||
3344 | sbc #MAXCOLS ; now CF = 1 ! |
||
3345 | sta lpte1 |
||
3346 | CPU08 |
||
3347 | lda #^LSTLINE |
||
3348 | pha |
||
3349 | plb |
||
3350 | ldx #$17 ; move 23 rows |
||
3351 | ?02: ldy #MAXCOLS-1 |
||
3352 | ?04: lda (lpte),y |
||
3353 | sta (lptc),y |
||
3354 | lda (lpte1),y |
||
3355 | sta (lptc1),y |
||
3356 | dey |
||
3357 | bpl ?04 |
||
3358 | ACC16CLC |
||
3359 | lda lpte |
||
3360 | sta lptc |
||
3361 | sbc #MAXCOLS-1 ; take account carry ! |
||
3362 | sta lpte |
||
3363 | lda lpte1 |
||
3364 | sta lptc1 |
||
3365 | sbc #MAXCOLS ; now CF = 1 ! |
||
3366 | sta lpte1 |
||
3367 | ACC08 |
||
3368 | dex |
||
3369 | bne ?02 |
||
3370 | plb |
||
3371 | rts |
||
3372 | |||
3373 | ; wait for <enter> key pressed |
||
3374 | ; in: Y - column in last screen row |
||
3375 | ; X preserved |
||
3376 | waitent: |
||
3377 | phx |
||
3378 | ldx #0 |
||
3379 | ?02: lda >strent,x |
||
3380 | beq ?04 |
||
3381 | cpy #MAXCOLS ; not above limit |
||
3382 | bcs ?04 |
||
3383 | sta [stxtp],y |
||
3384 | inx |
||
3385 | iny |
||
3386 | bne ?02 |
||
3387 | ?04: plx |
||
3388 | |||
3389 | waitent2: |
||
3390 | jsr slgkey ; wait key pressed |
||
3391 | bcs waitent2 ; control key |
||
3392 | xba ; ALT,CTL,SHIFT |
||
3393 | bne waitent2 ; will be no pressed |
||
3394 | xba |
||
3395 | cmp #$0D |
||
3396 | bne waitent2 |
||
3397 | rts |
||
3398 | |||
3399 | ; put string in status line row (last screen row) |
||
3400 | ; in: A - attribute |
||
3401 | ; X - string number # (if $FF is cbm disk error) |
||
3402 | ; out: Y - next available column in last row |
||
3403 | msgstr: |
||
3404 | xba ; B = attribute |
||
3405 | cpx #$FF |
||
3406 | bne ?01 |
||
3407 | ldx #<EDDSKERR |
||
3408 | ldy #>EDDSKERR |
||
3409 | lda #^EDDSKERR |
||
3410 | bra outstr |
||
3411 | ?01: cpx #MAXSTR |
||
3412 | bcc ?02 |
||
3413 | ldx #0 ; blank string |
||
3414 | ?02: lda STRTBLL,x ; take string address |
||
3415 | pha |
||
3416 | lda STRTBLH,x |
||
3417 | tay ; Y = high address |
||
3418 | plx ; X = low address |
||
3419 | lda #^str01 ; A = bank address |
||
3420 | |||
3421 | ; out string in status line (last screen row) |
||
3422 | ; in: X,Y,A - address of string |
||
3423 | ; B - attribute |
||
3424 | ; out: Y - next available column in last row |
||
3425 | ; P284A: |
||
3426 | outstr: |
||
3427 | stx lptc ; store string address |
||
3428 | sty lptc+1 |
||
3429 | sta lptc+2 |
||
3430 | xba ; attribute |
||
3431 | tax ; X = attribute |
||
3432 | ACC16 |
||
3433 | lda #!STLINE ; store address of last screen row |
||
3434 | sta stxtp |
||
3435 | lda #!STLATTR |
||
3436 | sta sattp |
||
3437 | ACC08 |
||
3438 | ldy #0 ; out string |
||
3439 | ?02: lda [lptc],y |
||
3440 | beq ?04 |
||
3441 | cpy #MAXCOLS ; not above limit |
||
3442 | bcs ?10 |
||
3443 | sta [stxtp],y |
||
3444 | txa |
||
3445 | sta [sattp],y |
||
3446 | iny |
||
3447 | bne ?02 |
||
3448 | ?04: phy |
||
3449 | lda #' ' ; pad row with blanks |
||
3450 | xba |
||
3451 | txa ; A = attribute, B = blank |
||
3452 | ?06: cpy #MAXCOLS |
||
3453 | bcs ?08 |
||
3454 | sta [sattp],y |
||
3455 | xba |
||
3456 | sta [stxtp],y |
||
3457 | xba |
||
3458 | iny |
||
3459 | bne ?06 |
||
3460 | ?08: ply |
||
3461 | ?10: rts |
||
3462 | |||
3463 | ; get key for command line/status line |
||
3464 | ; in: X - number of keys stored |
||
3465 | ; Y - column |
||
3466 | ; out: A = key code |
||
3467 | ; B = flag ALT, CTL, SHIFT |
||
3468 | ; CF = 1 if control key |
||
3469 | ; X,Y preserved |
||
3470 | ; P1BBE: |
||
3471 | slgkey: |
||
3472 | jsr slcurs ; set cursor position |
||
3473 | jsr showcurs ; show cursor |
||
3474 | ?02: KBGETIN ; system call - get key |
||
3475 | cmp #0 |
||
3476 | beq ?02 ; loop -- wait pressed key |
||
3477 | cmp #' ' |
||
3478 | bne ?04 ; no blank key |
||
3479 | txa |
||
3480 | beq ?02 ; skip beginning blanks |
||
3481 | lda #' ' |
||
3482 | ?04: sta tmpe ; store key code |
||
3483 | xba |
||
3484 | sta tmpf ; store control key flag |
||
3485 | jsr hidecurs |
||
3486 | lda >DP01ADDR+KbdFlag |
||
3487 | xba ; B = flag ALT, CTL, SHIFT |
||
3488 | clc |
||
3489 | lda tmpe ; key code |
||
3490 | bit tmpf |
||
3491 | bpl ?06 |
||
3492 | sec ; control key |
||
3493 | ?06: rts |
||
3494 | |||
3495 | ; hide cursor |
||
3496 | hidecurs: |
||
3497 | lda #$10 ; bit PB4 = 1 |
||
3498 | ora >PIAVBB+PIAPRB |
||
3499 | sta >PIAVBB+PIAPRB |
||
3500 | rts |
||
3501 | |||
3502 | ; show cursor |
||
3503 | showcurs: |
||
3504 | lda >PIAVBB+PIAPRB |
||
3505 | and #$EF ; bit PB4 = 0 |
||
3506 | sta >PIAVBB+PIAPRB |
||
3507 | rts |
||
3508 | |||
3509 | ; set position of cursor in status line row |
||
3510 | ; in: Y = column |
||
3511 | ; X,Y preserved |
||
3512 | slcurs: |
||
3513 | clc |
||
3514 | lda #$0E |
||
3515 | sta >CRTAddr |
||
3516 | tya |
||
3517 | adc stxtp |
||
3518 | xba |
||
3519 | lda stxtp+1 |
||
3520 | bra pcurs |
||
3521 | |||
3522 | ; set position of cursor in edit window |
||
3523 | ; in: Y = column |
||
3524 | ; X,Y preserved |
||
3525 | edcurs: |
||
3526 | clc |
||
3527 | lda #$0E |
||
3528 | sta >CRTAddr |
||
3529 | tya |
||
3530 | adc curs |
||
3531 | xba |
||
3532 | lda curs+1 |
||
3533 | |||
3534 | pcurs: |
||
3535 | adc #0 |
||
3536 | sta >CRTData |
||
3537 | lda #$0F |
||
3538 | sta >CRTAddr |
||
3539 | xba |
||
3540 | sta >CRTData |
||
3541 | rts |
||
3542 | |||
3543 | ; set default cursor mode basis cursmode value |
||
3544 | setcurs: |
||
3545 | lda #$0B ; set 'end scan line' register |
||
3546 | sta >CRTAddr |
||
3547 | lda #$0F ; end at last line |
||
3548 | sta >CRTData |
||
3549 | lda #$0A ; set 'start scan line' register |
||
3550 | sta >CRTAddr |
||
3551 | lda #$00 ; block cursor: start scan line = 0 |
||
3552 | bit cursmode ; check bit <6> |
||
3553 | bvc ?02 ; block cursor |
||
3554 | lda #$0F ; under line cursor: start = end |
||
3555 | ?02: sta >CRTData |
||
3556 | lda >PIAVBB+PIAPRB |
||
3557 | and #$FB ; mask PB2 |
||
3558 | bit cursmode ; check bit <7> |
||
3559 | bpl ?04 ; fixed cursor => PB2 = 0 |
||
3560 | ora #$04 ; blink cursor => PB2 = 1 |
||
3561 | ?04: sta >PIAVBB+PIAPRB |
||
3562 | rts |
||
3563 | |||
3564 | ;--------------------------------------------------------------------- |
||
3565 | ; COMMAND LINE |
||
3566 | |||
3567 | ; input comand string in EDBUFLIN |
||
3568 | ; in: X,Y,A - address of prompt string |
||
3569 | ; P1AF9: |
||
3570 | inputstr: |
||
3571 | stx longp |
||
3572 | sty longp+1 |
||
3573 | sta longp+2 |
||
3574 | lda #$C0 |
||
3575 | sta slfg ; status line input mode |
||
3576 | ?lp: lda #0 ; input loop |
||
3577 | sta >EDBUFLIN |
||
3578 | lda scatt |
||
3579 | xba ; attribute |
||
3580 | ldx longp |
||
3581 | ldy longp+1 |
||
3582 | lda longp+2 |
||
3583 | jsr outstr ; print prompt |
||
3584 | ldx #0 ; buffer index |
||
3585 | ?get: jsr slgkey ; get key |
||
3586 | bcc ?key ; no control key |
||
3587 | cmp #KB_DELETE ; <DELETE> clear all input field |
||
3588 | beq ?lp ; restart input |
||
3589 | cmp #KB_BACKSPACE |
||
3590 | bne ?get ; discard others control keys |
||
3591 | txa |
||
3592 | beq ?get ; at first column do nothing |
||
3593 | dex ; decrement index and column |
||
3594 | dey |
||
3595 | lda #' ' ; put blank at column |
||
3596 | sta [stxtp],y |
||
3597 | bra ?get ; continue input |
||
3598 | ?key: xba ; check flag |
||
3599 | bit #(AALTB.OR.ACTRLB) |
||
3600 | bne ?get ; discard alt/ctl keys but shift |
||
3601 | xba |
||
3602 | cmp #KB_ESC ; <ESC> exit from command line |
||
3603 | beq ?ret ; exit with CF=1 |
||
3604 | cmp #KB_CR ; <ENTER> terminate input line |
||
3605 | beq ?end |
||
3606 | cmp #' ' |
||
3607 | bcc ?get ; discard no-printables |
||
3608 | cmp #$7F |
||
3609 | bcs ?get |
||
3610 | cpy #MAXCOLS-1 ; no store above max. column |
||
3611 | bcs ?get |
||
3612 | sta [stxtp],y ; print char at column |
||
3613 | sta >EDBUFLIN,x ; store char at index |
||
3614 | iny |
||
3615 | inx |
||
3616 | bra ?get ; continue input |
||
3617 | ?end: txa ; current index |
||
3618 | beq ?lp ; empty string: restart |
||
3619 | ?trm: dex ; trim blanks |
||
3620 | bmi ?lp ; restart |
||
3621 | lda >EDBUFLIN,x |
||
3622 | cmp #' ' |
||
3623 | beq ?trm |
||
3624 | inx |
||
3625 | lda #0 |
||
3626 | sta >EDBUFLIN,x ; terminate input |
||
3627 | clc ; exit with CF=0 |
||
3628 | ?ret: rts |
||
3629 | |||
3630 | cmdline: |
||
3631 | ldx #<CMDSTR |
||
3632 | ldy #>CMDSTR |
||
3633 | lda #^CMDSTR |
||
3634 | jsr inputstr |
||
3635 | lda #$80 |
||
3636 | trb slfg |
||
3637 | rts |
||
3638 | |||
3639 | CMDSTR: |
||
3640 | .DB 'CMD: ',0 |
||
3641 | |||
3642 | ;--------------------------------------------------------------------- |
||
3643 | |||
3644 | ; entry point (DBR and DP set by caller) |
||
3645 | ; |
||
3646 | ; stack frame |
||
3647 | ; |
||
3648 | ; --------- |
||
3649 | ; | ... | 0F |
||
3650 | ; --------- |
||
3651 | ; | DPH | 06 |
||
3652 | ; --------- |
||
3653 | ; | DPL | 05 |
||
3654 | ; --------- |
||
3655 | ; | DBR | 04 |
||
3656 | ; --------- |
||
3657 | ; | PBR | 03 |
||
3658 | ; --------- |
||
3659 | ; | PCH | 02 |
||
3660 | ; --------- |
||
3661 | ; | PCL | 01 |
||
3662 | ; --------- |
||
3663 | |||
3664 | STKPCL .SET $01 |
||
3665 | STKPCH .SET $02 |
||
3666 | STKPBR .SET $03 ; caller return address |
||
3667 | STKDBR .SET $04 ; DBR for called procedure |
||
3668 | STKDP .SET $05 ; DP for called procedure |
||
3669 | |||
3670 | .PUBLIC qedtent |
||
3671 | |||
3672 | |||
3673 | qedtent: |
||
3674 | php ; save M/X status |
||
3675 | CPU08 |
||
3676 | phb |
||
3677 | phd ; frame stack +4 |
||
3678 | pea #$4000 |
||
3679 | pld |
||
3680 | pha |
||
3681 | phx |
||
3682 | ldx #$00 |
||
3683 | ?zp: stz <$0,x ; clear DP memory |
||
3684 | inx |
||
3685 | bne ?zp |
||
3686 | INDEX16 |
||
3687 | ldx #(EDWRKEND-EDBUFNAM-1) |
||
3688 | lda #0 |
||
3689 | ?zz: sta >EDBUFNAM,x |
||
3690 | dex |
||
3691 | bpl ?zz |
||
3692 | INDEX08 |
||
3693 | stx xbuf ; force buffer allocation at start |
||
3694 | plx |
||
3695 | pla |
||
3696 | sta longp ; A,X,Y : address of command line |
||
3697 | stx longp+1 |
||
3698 | sty longp+2 |
||
3699 | xba |
||
3700 | sta fsmode ; mode |
||
3701 | ACC16 |
||
3702 | lda >pbrklv |
||
3703 | sta brksav |
||
3704 | ACC08 |
||
3705 | jsr crtsav |
||
3706 | jsr init |
||
3707 | jsr chkcmd ; check command line |
||
3708 | jsr editor ; launch editor |
||
3709 | lda saveps |
||
3710 | sta >PIAVBB+PIAPRA ; restore palette address |
||
3711 | jsr crtrest |
||
3712 | ldx embit |
||
3713 | sta >CREMEOFF,x ; restore video ram bit |
||
3714 | |||
3715 | ACC16 |
||
3716 | lda brksav |
||
3717 | sta >pbrklv |
||
3718 | ACC08 |
||
3719 | |||
3720 | pld |
||
3721 | plb |
||
3722 | plp |
||
3723 | rtl |
||
3724 | |||
3725 | ; init editor |
||
3726 | ; P1631: |
||
3727 | init: |
||
3728 | lda #MINFREE |
||
3729 | jsr chkfree |
||
3730 | lda #DEFLTAB ; default tab value |
||
3731 | sta deftab |
||
3732 | lda #EDEFCURS ; default cursor mode edit window |
||
3733 | sta cursmode |
||
3734 | lda #^TXTADDR ; bank of video ram |
||
3735 | sta stxtp+2 |
||
3736 | sta sattp+2 |
||
3737 | lda #DEFATTR ; default editor window attribute |
||
3738 | sta eattr |
||
3739 | lda #DEFSATTR ; default status line attribute |
||
3740 | sta slattr |
||
3741 | lda #DEFEATTR ; default error message attribute |
||
3742 | sta seatt |
||
3743 | lda #DEFCATTR ; default command line attribute |
||
3744 | sta scatt |
||
3745 | lda #DFGATTR ; disabled flag indicator attribute |
||
3746 | sta fgatt |
||
3747 | lda #$40 |
||
3748 | sta slfg ; update whole status line |
||
3749 | lda #0 |
||
3750 | pha |
||
3751 | plb ; DBR = 0 |
||
3752 | ldx CREMEOFF ; save current video ram bit |
||
3753 | stx embit |
||
3754 | sta !CREMEON ; enable video ram |
||
3755 | lda !PIAVBB+PIAPRA ; save current palette address |
||
3756 | sta saveps |
||
3757 | ora #$0F ; set palette address = 11 11XXX XXXX |
||
3758 | sta !PIAVBB+PIAPRA |
||
3759 | lda #0 |
||
3760 | tay ; Y = 0 |
||
3761 | xba ; B = 0 |
||
3762 | lda #$F0 ; set base address palette |
||
3763 | CPU16 |
||
3764 | asl a |
||
3765 | asl a ; this make base address = $03C0 |
||
3766 | tax |
||
3767 | ACC08 |
||
3768 | lda #$D0 ; LIGHT YELLOW/BLACK -- editor |
||
3769 | sta >VBBPALRAM,x ; palette=0 |
||
3770 | inx |
||
3771 | lda #$F2 ; WHITE/DARK BLUE -- status line |
||
3772 | sta >VBBPALRAM,x ; palette=1 |
||
3773 | inx |
||
3774 | lda #$92 ; LIGHT RED/DARK BLUE -- error line |
||
3775 | sta >VBBPALRAM,x ; palette=2 |
||
3776 | inx |
||
3777 | ;lda #$0E ; BLACK/LIGHT GRAY -- command line |
||
3778 | lda #$2F ; DARK BLUE/WHITE -- command line |
||
3779 | sta >VBBPALRAM,x ; palette=3 |
||
3780 | inx |
||
3781 | lda #$E2 ; GRAY/DARK BLUE -- status line |
||
3782 | sta >VBBPALRAM,x ; palette=4 |
||
3783 | CPU08 |
||
3784 | lda #0 ; start with buffer #0 |
||
3785 | jsr switchb |
||
3786 | lda #$20 ; enable indent |
||
3787 | tsb bflag |
||
3788 | jsr setattr |
||
3789 | jmp updwin |
||
3790 | |||
3791 | ;--------------------------------------------------------------------- |
||
3792 | |||
3793 | ; convert byte A in decimal (3 digits stored in tstr2) |
||
3794 | byte2str: |
||
3795 | sta wtmp |
||
3796 | stz wtmp+1 |
||
3797 | lda #$80 ; flag byte |
||
3798 | sta ebtmp |
||
3799 | bra int2s |
||
3800 | |||
3801 | ; convert integer in wtmp in decimal (5 digits stored in tstr2) |
||
3802 | int2str: |
||
3803 | stz ebtmp ; flag integer |
||
3804 | int2s: |
||
3805 | stz ebtmp2 ; string index |
||
3806 | phb |
||
3807 | phk ; set DBR = PBR |
||
3808 | plb |
||
3809 | ldy #8 ; power 10 table access index |
||
3810 | ?02: ldx #0 ; partial quotient |
||
3811 | sec |
||
3812 | ACC16 ; repeated subctract |
||
3813 | lda wtmp |
||
3814 | ?04: sbc P10TBL,y |
||
3815 | bcc ?06 ; stop subctract |
||
3816 | inx ; increment quotient |
||
3817 | bra ?04 |
||
3818 | ?06: adc P10TBL,y ; store result |
||
3819 | sta wtmp |
||
3820 | ACC08SEC |
||
3821 | txa ; 0..9 |
||
3822 | adc #'0'-1 ; decimal digit |
||
3823 | ldx ebtmp2 ; string index |
||
3824 | sta tstr2,x ; store digit |
||
3825 | inx |
||
3826 | stx ebtmp2 ; update string index |
||
3827 | dey |
||
3828 | dey |
||
3829 | bpl ?02 |
||
3830 | plb |
||
3831 | bit ebtmp |
||
3832 | bpl ?10 |
||
3833 | ldx #2 ; adjust for byte |
||
3834 | ldy #0 |
||
3835 | ?08: lda <tstr2,x |
||
3836 | stx tmp6 |
||
3837 | tyx |
||
3838 | sta <tstr2,x |
||
3839 | ldx tmp6 |
||
3840 | inx |
||
3841 | iny |
||
3842 | cpy #3 |
||
3843 | bcc ?08 |
||
3844 | ?10: rts |
||
3845 | |||
3846 | |||
3847 | ;------------------------ |
||
3848 | exit: |
||
3849 | lda #$80 |
||
3850 | tsb edtfg |
||
3851 | rts |
||
3852 | |||
3853 | ; ALT-O |
||
3854 | open: |
||
3855 | ldx #<?opn |
||
3856 | ldy #>?opn |
||
3857 | lda #^?opn |
||
3858 | jsr inputstr |
||
3859 | bcs ?end |
||
3860 | jsr hidecurs |
||
3861 | jsr cbmopn |
||
3862 | ;lda #$80 ; clear input mode flag |
||
3863 | ;trb slfg |
||
3864 | ;lda #$80 |
||
3865 | ;trb bflag ; not modified |
||
3866 | jsr updsl |
||
3867 | ?end: rts |
||
3868 | ?opn: .DB 'Open: ', 0 |
||
3869 | |||
3870 | ; ALT-S |
||
3871 | save: |
||
3872 | jsr chkbuf |
||
3873 | beq ?end ; clipboard or empty buffer |
||
3874 | lda #$10 ; named buffer? |
||
3875 | bit bflag |
||
3876 | beq saveas ; no, call saveas |
||
3877 | bit fsmode |
||
3878 | bpl ?fat ; save fat file |
||
3879 | jmp csave ; save cbm file |
||
3880 | ?fat: jmp fsave |
||
3881 | ?end: rts |
||
3882 | |||
3883 | saveas: |
||
3884 | ldx #<?sav |
||
3885 | ldy #>?sav |
||
3886 | lda #^?sav |
||
3887 | jsr inputstr |
||
3888 | bcs ?end |
||
3889 | bit fsmode |
||
3890 | bpl fsaveas |
||
3891 | bmi csaveas |
||
3892 | ?end: rts |
||
3893 | |||
3894 | ?sav: .DB 'Save: ', 0 |
||
3895 | |||
3896 | fsaveas: |
||
3897 | clc |
||
3898 | rts |
||
3899 | |||
3900 | csaveas: |
||
3901 | lda #^EDBUFFILE ; set pointer to filename |
||
3902 | sta longp+2 |
||
3903 | lda #<EDBUFFILE |
||
3904 | sta longp |
||
3905 | lda #>EDBUFFILE |
||
3906 | sta longp+1 |
||
3907 | ldx #0 |
||
3908 | lda #'@' |
||
3909 | sta [longp] ; replace flag |
||
3910 | ldy #1 |
||
3911 | lda >EDDSKERR+1 ; check drive |
||
3912 | cmp #':' |
||
3913 | bne ?dr ; store deafult drive '0' |
||
3914 | lda >EDDSKERR |
||
3915 | cmp #'0' ; continue if drive 0 or 1 |
||
3916 | beq ?mv |
||
3917 | cmp #'1' |
||
3918 | beq ?mv |
||
3919 | ?dr: lda #'0' ; put default drive '0' |
||
3920 | sta [longp],y |
||
3921 | iny |
||
3922 | lda #':' |
||
3923 | sta [longp],y |
||
3924 | iny |
||
3925 | ?mv: lda >EDDSKERR,x ; set filename |
||
3926 | beq ?nxt |
||
3927 | cmp #'a' ; upper case |
||
3928 | bcc ?st |
||
3929 | cmp #'z'+1 |
||
3930 | bcs ?st |
||
3931 | and #$DF |
||
3932 | ?st: sta [longp],y |
||
3933 | inx |
||
3934 | iny |
||
3935 | cpy #MAXFNAME-8 |
||
3936 | bcc ?mv |
||
3937 | ?nxt: ldx #3 |
||
3938 | phy ; save index |
||
3939 | ?lp: lda >?rdw,x |
||
3940 | sta [longp],y |
||
3941 | iny |
||
3942 | dex |
||
3943 | bpl ?lp |
||
3944 | lda #0 |
||
3945 | sta [longp],y |
||
3946 | ACC16 |
||
3947 | inc longp ; no overwrite for now |
||
3948 | ACC08 |
||
3949 | ?opn: jsr cdskopn ; open file |
||
3950 | ply |
||
3951 | bcc ?ok ; no error |
||
3952 | sty bka |
||
3953 | lda >EDDSKERR ; check error 63 (file exist) |
||
3954 | cmp #'6' |
||
3955 | bne ?derr ; error of another kind |
||
3956 | lda >EDDSKERR+1 |
||
3957 | cmp #'3' |
||
3958 | bne ?derr |
||
3959 | ldx #<?msg ; ask overwrite confirmation |
||
3960 | ldy #>?msg |
||
3961 | lda #^?msg |
||
3962 | jsr confirm ; ask confirmation |
||
3963 | bcs ?end ; no, <ESC> |
||
3964 | bne ?end ; no, <N> |
||
3965 | ACC16 |
||
3966 | dec longp |
||
3967 | ACC08 |
||
3968 | ldy bka |
||
3969 | phy |
||
3970 | bra ?opn ; try again with replace flag |
||
3971 | ?ok: jsr csave2 |
||
3972 | bcs ?end ; some error |
||
3973 | ldx #0 |
||
3974 | ?cp: lda >EDBUFFILE+1,x ; skip '@' |
||
3975 | sta >EDCURFILE,x |
||
3976 | beq ?upd |
||
3977 | inx |
||
3978 | bra ?cp |
||
3979 | ?upd: lda bflag |
||
3980 | and #$7F |
||
3981 | ora #$10 |
||
3982 | sta bflag |
||
3983 | ?end: lda #$40 |
||
3984 | sta slfg |
||
3985 | jsr updsl |
||
3986 | jmp updwin |
||
3987 | |||
3988 | ?derr: |
||
3989 | ldx #$FF ; disk error |
||
3990 | jsr error |
||
3991 | bra ?end |
||
3992 | |||
3993 | ?msg: .DB 'File exist; overwrite <Y/N>?', 0 |
||
3994 | ?rdw: .DB 'W,S,' |
||
3995 | |||
3996 | |||
3997 | ; save CBM file |
||
3998 | csave: |
||
3999 | lda #<EDBUFFILE ; prepare filename |
||
4000 | sta longp |
||
4001 | lda #>EDBUFFILE |
||
4002 | sta longp+1 |
||
4003 | lda #^EDBUFFILE |
||
4004 | sta longp+2 |
||
4005 | lda #'@' ; replace flag |
||
4006 | sta [longp] |
||
4007 | ldy #1 |
||
4008 | ldx #0 |
||
4009 | ?nam: lda >EDCURFILE,x |
||
4010 | beq ?nxt |
||
4011 | sta [longp],y |
||
4012 | iny |
||
4013 | inx |
||
4014 | cpy #18 |
||
4015 | bcc ?nam |
||
4016 | ?nxt: ldx #3 |
||
4017 | phy |
||
4018 | ?lp: lda >_?rdw,x |
||
4019 | sta [longp],y |
||
4020 | iny |
||
4021 | dex |
||
4022 | bpl ?lp |
||
4023 | lda #0 |
||
4024 | sta [longp],y |
||
4025 | jsr cdskopn ; open file |
||
4026 | ply |
||
4027 | bcs _?derr ; error |
||
4028 | csave2: |
||
4029 | lda #0 |
||
4030 | sta [longp],y |
||
4031 | lda longp+2 |
||
4032 | pha |
||
4033 | pei (longp) |
||
4034 | phk |
||
4035 | pea #_?sav |
||
4036 | lda #7 |
||
4037 | pha |
||
4038 | BSPRINTF2 ; format in local string |
||
4039 | phx ; bank that hold string |
||
4040 | tax ; low address |
||
4041 | xba |
||
4042 | tay ; hi address |
||
4043 | lda slattr ; attribute |
||
4044 | xba |
||
4045 | pla ; bank |
||
4046 | jsr outstr |
||
4047 | lda #$40 ; force update status line |
||
4048 | sta slfg |
||
4049 | jsr savbuf |
||
4050 | bcs _?derr |
||
4051 | jsr updsl |
||
4052 | clc |
||
4053 | _?end: php |
||
4054 | jsr updwin |
||
4055 | plp |
||
4056 | rts |
||
4057 | |||
4058 | _?derr: |
||
4059 | ldx #$FF ; disk error |
||
4060 | jsr error |
||
4061 | sec |
||
4062 | bra _?end |
||
4063 | |||
4064 | _?rdw: .DB 'W,S,' |
||
4065 | _?sav: .DB 'Saving "%s"...', 0 |
||
4066 | |||
4067 | ; save current buffer |
||
4068 | savbuf: |
||
4069 | jsr mvpp2 ; save buffer pointer |
||
4070 | ACC16 |
||
4071 | lda pbuf ; set pointer to start |
||
4072 | sta ppage |
||
4073 | stz bka |
||
4074 | lda #EDDSKBUF ; set disk buffer pointer |
||
4075 | sta pb |
||
4076 | ldx #^EDDSKBUF |
||
4077 | stx pb+2 |
||
4078 | ACC08 |
||
4079 | lda #BSTART |
||
4080 | sta ixb |
||
4081 | bra ?get |
||
4082 | ?nxt: jsr incptr ; inc buffer pointer |
||
4083 | ?get: jsr getbyte ; get next byte |
||
4084 | bcs ?end ; end of text |
||
4085 | jsr ?put ; put into disk buffer |
||
4086 | bcs ?rst ; error |
||
4087 | cmp #$0D |
||
4088 | bne ?nxt |
||
4089 | lda #$0A ; dos style text file |
||
4090 | jsr ?put |
||
4091 | bcs ?rst ; error |
||
4092 | bra ?nxt ; next byte |
||
4093 | ?end: clc ; no error |
||
4094 | lda bka ; check if must flush disk buffer |
||
4095 | ora bka+1 |
||
4096 | beq ?cls ; no flush: close file |
||
4097 | jsr ?wr ; flush buffer |
||
4098 | ?cls: php |
||
4099 | bit fsmode ; close file |
||
4100 | bpl ?fcls |
||
4101 | lda #$0E ; close file |
||
4102 | CBMFSCLS |
||
4103 | bra ?go |
||
4104 | ?fcls: nop |
||
4105 | ?go: plp |
||
4106 | ?rst: jsr pp2mv ; restore pointer |
||
4107 | bcs ?end2 |
||
4108 | lda #$80 |
||
4109 | trb bflag ; clear modified flag |
||
4110 | ?end2: rts |
||
4111 | |||
4112 | ?put: INDEX16 ; insert into disk buffer |
||
4113 | ldy bka ; current index |
||
4114 | sta [pb],y ; store byte |
||
4115 | iny ; update index |
||
4116 | sty bka |
||
4117 | cpy #EDDSKBUFSIZ ; check if full |
||
4118 | INDEX08 |
||
4119 | bcc ?rts |
||
4120 | ?wr: bit fsmode ; write buffer to disk |
||
4121 | bpl ?wfat ; fat file |
||
4122 | lda pb+2 ; set buffer pointer |
||
4123 | pha |
||
4124 | pei (pb) |
||
4125 | pei (bka) ; buffer size |
||
4126 | lda #$0E |
||
4127 | pha ; chnl 14 |
||
4128 | CBMFSWR ; write buffer |
||
4129 | bcc ?ok |
||
4130 | jsr cdskerr ; get error string |
||
4131 | lda #$0E ; close file |
||
4132 | CBMFSCLS |
||
4133 | sec ; error |
||
4134 | rts |
||
4135 | ?wfat: clc |
||
4136 | ?ok: stz bka ; clear index |
||
4137 | stz bka+1 |
||
4138 | ?rts: rts |
||
4139 | |||
4140 | fsave: |
||
4141 | clc |
||
4142 | rts |
||
4143 | |||
4144 | ; check current buffer |
||
4145 | ; ZF=1 if clipboard or empty buffer |
||
4146 | chkbuf: |
||
4147 | lda xbuf |
||
4148 | cmp #CLIPBRD |
||
4149 | beq ?end ; is clipboard |
||
4150 | lda pbuf |
||
4151 | sta pb+1 |
||
4152 | lda pbuf+1 |
||
4153 | sta pb+2 |
||
4154 | stz pb |
||
4155 | ldy #BSTART |
||
4156 | lda [pb],y ; ZF=1 if empty |
||
4157 | ?end: rts |
||
4158 | |||
4159 | ; ALT-N |
||
4160 | clrbuf: |
||
4161 | jsr chkbuf |
||
4162 | beq ?end ; clipboard or empty buffer |
||
4163 | ldx #<?sclr |
||
4164 | ldy #>?sclr |
||
4165 | lda #^?sclr |
||
4166 | jsr confirm ; ask confirmation |
||
4167 | bcs ?end ; no, <ESC> |
||
4168 | bne ?end ; no, <N> |
||
4169 | bit bflag ; buffer modified? |
||
4170 | bpl ?go ; no |
||
4171 | jsr save |
||
4172 | ?go: stz cline |
||
4173 | stz cline+1 |
||
4174 | lda xbuf |
||
4175 | jsr freebuf |
||
4176 | lda #$40 |
||
4177 | sta slfg |
||
4178 | jsr updwin |
||
4179 | ?end: rts |
||
4180 | |||
4181 | ?sclr: .DB 'Are you sure to clear current buffer <Y/N>?', 0 |
||
4182 | |||
4183 | ; X,Y,A = string ptr |
||
4184 | ; CF = 1 if <ESC> |
||
4185 | ; CF=0, ZF=0 if <N> |
||
4186 | ; CF=0, ZF=1 if <Y> |
||
4187 | confirm: |
||
4188 | xba |
||
4189 | lda seatt |
||
4190 | xba |
||
4191 | jsr outstr |
||
4192 | ?get: jsr slgkey ; wait key pressed |
||
4193 | bcs ?get ; control key |
||
4194 | xba ; ALT,CTL,SHIFT |
||
4195 | bne ?get ; will be no pressed |
||
4196 | xba |
||
4197 | cmp #KB_ESC |
||
4198 | beq ?end ; exit with CF=1 |
||
4199 | cmp #'a' |
||
4200 | bcc ?nxt |
||
4201 | cmp #'z'+1 |
||
4202 | bcs ?nxt |
||
4203 | and #$DF ; capitalize |
||
4204 | ?nxt: cmp #'Y' |
||
4205 | beq ?ok ; exit with CF=0, ZF=1 |
||
4206 | cmp #'N' |
||
4207 | bne ?get |
||
4208 | inc a ; exit with CF=0, ZF=0 |
||
4209 | ?ok: clc |
||
4210 | ?end: php |
||
4211 | lda #$40 ; force updare status line |
||
4212 | sta slfg |
||
4213 | jsr updsl |
||
4214 | plp |
||
4215 | rts |
||
4216 | |||
4217 | ;ALT-T |
||
4218 | settab: |
||
4219 | lda deftab ; prepare prompt string |
||
4220 | pha |
||
4221 | lda #MAXTABVAL |
||
4222 | pha |
||
4223 | lda #MINTABVAL |
||
4224 | pha |
||
4225 | phk ; bank of format string |
||
4226 | pea #?tstr |
||
4227 | lda #7 |
||
4228 | pha |
||
4229 | BSPRINTF2 ; format in local string |
||
4230 | stx bka ; bank |
||
4231 | tax ; low address |
||
4232 | xba |
||
4233 | tay ; hi address |
||
4234 | lda bka |
||
4235 | jsr inputstr |
||
4236 | bcs ?end |
||
4237 | jsr getnum ; get number in bka |
||
4238 | bcs ?end ; error |
||
4239 | ldx bka |
||
4240 | lda bka+1 |
||
4241 | beq ?ok |
||
4242 | ?err: ldy #MAXTABVAL |
||
4243 | phy |
||
4244 | ldy #MINTABVAL |
||
4245 | phy |
||
4246 | pha ; illegal value |
||
4247 | phx |
||
4248 | pea #EDERRSIZ ; size of dest. string |
||
4249 | lda #^EDDSKERR ; eror dest. string |
||
4250 | pha |
||
4251 | pea #EDDSKERR |
||
4252 | phk ; format string |
||
4253 | pea #?serr |
||
4254 | lda #13 |
||
4255 | pha |
||
4256 | BSPRINTF |
||
4257 | ldx #$FF ; error string in EDDSKERR |
||
4258 | jsr error |
||
4259 | bra ?end |
||
4260 | ?ok: cpx #MINTABVAL |
||
4261 | bcc ?err |
||
4262 | cpx #MAXTABVAL+1 |
||
4263 | bcs ?err |
||
4264 | stx deftab |
||
4265 | ?end: lda #$80 ; clear input mode flag |
||
4266 | trb slfg |
||
4267 | rts |
||
4268 | |||
4269 | ?tstr: .DB 'Set tab value in range %bu..%bu (current value: %bu): ', 0 |
||
4270 | ?serr: .DB 'Illegal tab value: %hu (must be in range %bu..%bu)', 0 |
||
4271 | |||
4272 | ; ALT-G |
||
4273 | gotoln: |
||
4274 | ldx #<?gto |
||
4275 | ldy #>?gto |
||
4276 | lda #^?gto |
||
4277 | jsr inputstr |
||
4278 | bcs ?end |
||
4279 | jsr getnum ; get number in bka |
||
4280 | bcs ?end ; error |
||
4281 | lda bka |
||
4282 | ora bka+1 |
||
4283 | beq ?hom |
||
4284 | cmp #1 |
||
4285 | bne ?nxt |
||
4286 | ?hom: jsr gohome |
||
4287 | bra ?end |
||
4288 | ?nxt: ACC16 |
||
4289 | lda bka |
||
4290 | cmp ncount |
||
4291 | ACC08 |
||
4292 | bcc ?gol |
||
4293 | jsr goend |
||
4294 | bra ?end |
||
4295 | ?gol: ACC16 |
||
4296 | cmp cline |
||
4297 | ACC08 |
||
4298 | beq ?end |
||
4299 | ACC16 |
||
4300 | ldx #0 |
||
4301 | bcs ?gol1 ; > cline |
||
4302 | dex ; < cline |
||
4303 | sec |
||
4304 | lda cline |
||
4305 | sbc bka |
||
4306 | bra ?gol2 |
||
4307 | ?gol1: sbc cline |
||
4308 | ?gol2: sta bkb |
||
4309 | ACC08 |
||
4310 | txy |
||
4311 | bpl ?down ; go down |
||
4312 | JSR pp8mv |
||
4313 | ?01: JSR startln |
||
4314 | ACC16 |
||
4315 | BCS ?05 |
||
4316 | ldx fslct |
||
4317 | BEQ ?03 |
||
4318 | DEC nslctl |
||
4319 | ?03: DEC cline |
||
4320 | ?05: DEC bkb |
||
4321 | ACC08 |
||
4322 | BNE ?01 |
||
4323 | LDA #$06 |
||
4324 | bra ?10 |
||
4325 | ?down: |
||
4326 | ?01a: JSR nextln |
||
4327 | ACC16 |
||
4328 | BCS ?03a |
||
4329 | ldx fslct |
||
4330 | BEQ ?02a |
||
4331 | INC nslctl |
||
4332 | ?02a: INC cline |
||
4333 | ?03a: DEC bkb |
||
4334 | ACC08 |
||
4335 | BNE ?01a |
||
4336 | LDA #$11 |
||
4337 | |||
4338 | ?10: jsr epage |
||
4339 | ?end: lda #$80 ; clear input mode flag |
||
4340 | trb slfg |
||
4341 | rts |
||
4342 | |||
4343 | ?gto: .DB 'Goto line #: ', 0 |
||
4344 | |||
4345 | getnum: |
||
4346 | ldx #0 |
||
4347 | stx bka |
||
4348 | stx bka+1 |
||
4349 | stx bkb+1 |
||
4350 | ?nxt: jsr ?get |
||
4351 | tay |
||
4352 | beq ?ret ; end of string |
||
4353 | bcs ?err |
||
4354 | sbc #'0'-1 |
||
4355 | sta bkb |
||
4356 | ACC16 |
||
4357 | lda bka |
||
4358 | cmp #6554 |
||
4359 | bcs ?end ; overflow |
||
4360 | asl a |
||
4361 | asl a |
||
4362 | adc bka |
||
4363 | asl a |
||
4364 | adc bkb |
||
4365 | sta bka |
||
4366 | ?end: ACC08 |
||
4367 | bcc ?nxt |
||
4368 | ?err: ldx #8 |
||
4369 | jsr error |
||
4370 | lda #$80 |
||
4371 | trb slfg |
||
4372 | sec |
||
4373 | rts |
||
4374 | ?ret: clc |
||
4375 | rts |
||
4376 | |||
4377 | ?get: lda >EDBUFLIN,x |
||
4378 | inx |
||
4379 | cmp #'9'+1 |
||
4380 | bcs ?ex |
||
4381 | sec |
||
4382 | sbc #$30 |
||
4383 | sec |
||
4384 | sbc #$D0 |
||
4385 | ?ex: rts |
||
4386 | |||
4387 | ;--------------------- |
||
4388 | ; save crt buffer & page 01 |
||
4389 | crtsav: |
||
4390 | lda >CREMEOFF ; save current video ram bit |
||
4391 | tay |
||
4392 | sta >CREMEON ; enable video ram |
||
4393 | CPU16 |
||
4394 | ldx #$0FFF ; move 4k |
||
4395 | ?lp: lda >VBBCHARRAM,x |
||
4396 | sta >EDCRTSAV,x |
||
4397 | dex |
||
4398 | bpl ?lp |
||
4399 | CPU08 |
||
4400 | tyx |
||
4401 | sta >CREMEOFF,x ; restore video ram bit |
||
4402 | ldx #ScnLinTmp ; save page 01 |
||
4403 | ?lp2: lda !DP01ADDR,x |
||
4404 | sta >EDSAVE01,x |
||
4405 | inx |
||
4406 | bne ?lp2 |
||
4407 | rts |
||
4408 | |||
4409 | crtrest: |
||
4410 | lda >CREMEOFF ; save current video ram bit |
||
4411 | tay |
||
4412 | sta >CREMEON ; enable video ram |
||
4413 | CPU16 |
||
4414 | ldx #$0FFF ; move 4k |
||
4415 | ?lp: lda >EDCRTSAV,x |
||
4416 | sta >VBBCHARRAM,x |
||
4417 | dex |
||
4418 | bpl ?lp |
||
4419 | CPU08 |
||
4420 | lda #$F0 ; who change this byte???? |
||
4421 | sta >VBBPALRAM |
||
4422 | tyx |
||
4423 | sta >CREMEOFF,x ; restore video ram bit |
||
4424 | ldx #ScnLinTmp ; restore page 01 |
||
4425 | ?lp2: lda >EDSAVE01,x |
||
4426 | sta !DP01ADDR,x |
||
4427 | inx |
||
4428 | bne ?lp2 |
||
4429 | rts |
||
4430 | |||
4431 | ; --- load editor buffer |
||
4432 | ; longp: buffer pointer |
||
4433 | ; dbufsiz: buffer size |
||
4434 | bufld: |
||
4435 | phx |
||
4436 | lda dbufsiz |
||
4437 | ora dbufsiz+1 |
||
4438 | beq ?end ; empty |
||
4439 | ?nxt: lda [longp] ; get byte |
||
4440 | cmp #$0A ; skip line feed |
||
4441 | beq ?inc |
||
4442 | cmp #$0D |
||
4443 | beq ?ins |
||
4444 | cmp #KB_TAB ; discard non printable but TAB & CR |
||
4445 | beq ?tab |
||
4446 | cmp #' ' |
||
4447 | bcc ?inc |
||
4448 | ldx bka |
||
4449 | cpx #MAXTEXTLEN |
||
4450 | bcc ?ins |
||
4451 | sta bka+1 |
||
4452 | lda #$0D |
||
4453 | jsr insert |
||
4454 | ACC16 |
||
4455 | inc ncount |
||
4456 | ACC08 |
||
4457 | jsr incptr2 |
||
4458 | stz bka |
||
4459 | lda bka+1 |
||
4460 | ?ins: jsr insert ; insert byte in editor buffer |
||
4461 | inc bka ; update text lenght |
||
4462 | bcc ?cr ; ok, room available |
||
4463 | bcs ?em ; memory error |
||
4464 | ?tab: jsr ?tkey |
||
4465 | bra ?inc |
||
4466 | ?em: ldy #$FE |
||
4467 | lda #$0D |
||
4468 | sta [pblk],y |
||
4469 | iny |
||
4470 | lda #0 |
||
4471 | sta [pblk],y |
||
4472 | ACC16 |
||
4473 | inc ncount |
||
4474 | ACC08 |
||
4475 | bra ?ret |
||
4476 | ?cr: cmp #$0D ; last byte was a CR? |
||
4477 | bne ?upd ; no |
||
4478 | stz bka |
||
4479 | ACC16CLC |
||
4480 | inc ncount ; update lines count |
||
4481 | bne ?nov |
||
4482 | sec ; lines count overflow |
||
4483 | dec ncount |
||
4484 | ?nov: ACC08 |
||
4485 | bcc ?upd |
||
4486 | jsr incptr2 |
||
4487 | ?ret: plx |
||
4488 | sec ; error |
||
4489 | rts |
||
4490 | ?upd: jsr incptr2 ; update editor buffer pointer |
||
4491 | ?inc: ACC16 |
||
4492 | inc longp ; update buffer pointer |
||
4493 | dec dbufsiz ; update size |
||
4494 | ACC08 |
||
4495 | bne ?nxt |
||
4496 | ?end: plx |
||
4497 | clc |
||
4498 | rts |
||
4499 | |||
4500 | ?tkey: lda #0 ; put blank's instead tab's |
||
4501 | ?tb0: clc |
||
4502 | ?tb1: adc #8 ; assume default tab = 8 |
||
4503 | cmp bka |
||
4504 | beq ?tb0 |
||
4505 | bcc ?tb1 |
||
4506 | sbc bka |
||
4507 | beq ?tbx |
||
4508 | sta ctmp2 |
||
4509 | ?tbl: lda #' ' |
||
4510 | jsr insert |
||
4511 | jsr incptr2 |
||
4512 | inc bka |
||
4513 | dec ctmp2 |
||
4514 | bne ?tbl |
||
4515 | ?tbx: rts |
||
4516 | |||
4517 | ; check command line for open file |
||
4518 | chkcmd: |
||
4519 | lda longp |
||
4520 | ora longp+1 |
||
4521 | ora longp+2 |
||
4522 | beq ?end ; null pointer |
||
4523 | lda [longp] |
||
4524 | beq ?end ; empty command line |
||
4525 | ldy #0 |
||
4526 | tyx |
||
4527 | ?mv: lda [longp],y |
||
4528 | sta >EDDSKERR,x |
||
4529 | iny |
||
4530 | inx |
||
4531 | bne ?mv |
||
4532 | jsr cbmopn |
||
4533 | ?end: rts |
||
4534 | |||
4535 | ;------ CBM FS |
||
4536 | |||
4537 | ; open CBM file |
||
4538 | ; filename in EDDSKERR buffer |
||
4539 | cbmopn: |
||
4540 | lda #^EDBUFFILE ; set pointer to filename |
||
4541 | sta longp+2 |
||
4542 | lda #<EDBUFFILE |
||
4543 | sta longp |
||
4544 | lda #>EDBUFFILE |
||
4545 | sta longp+1 |
||
4546 | ldx #0 |
||
4547 | txy |
||
4548 | lda >EDDSKERR+1 ; check drive |
||
4549 | cmp #':' |
||
4550 | bne ?dr ; store deafult drive '0' |
||
4551 | lda >EDDSKERR |
||
4552 | cmp #'0' ; continue if drive 0 or 1 |
||
4553 | beq ?mv |
||
4554 | cmp #'1' |
||
4555 | beq ?mv |
||
4556 | ?dr: lda #'0' ; put default drive '0' |
||
4557 | sta [longp] |
||
4558 | iny |
||
4559 | lda #':' |
||
4560 | sta [longp],y |
||
4561 | iny |
||
4562 | ?mv: lda >EDDSKERR,x ; set filename |
||
4563 | beq ?nxt |
||
4564 | cmp #'a' ; upper case |
||
4565 | bcc ?st |
||
4566 | cmp #'z'+1 |
||
4567 | bcs ?st |
||
4568 | and #$DF |
||
4569 | ?st: sta [longp],y |
||
4570 | inx |
||
4571 | iny |
||
4572 | bne ?mv |
||
4573 | ?nxt: ldx #3 |
||
4574 | phy ; save index |
||
4575 | ?lp: lda >?rds,x |
||
4576 | sta [longp],y |
||
4577 | iny |
||
4578 | dex |
||
4579 | bpl ?lp |
||
4580 | lda #0 |
||
4581 | sta [longp],y |
||
4582 | jsr cdskopn ; open file |
||
4583 | ply |
||
4584 | bcs ?derr ; error |
||
4585 | lda #0 |
||
4586 | sta [longp],y |
||
4587 | lda longp+2 |
||
4588 | pha |
||
4589 | pei (longp) |
||
4590 | lda #^LOADMSG |
||
4591 | pha |
||
4592 | pea #LOADMSG |
||
4593 | lda #7 |
||
4594 | pha |
||
4595 | BSPRINTF2 ; format in local string |
||
4596 | phx ; bank that hold string |
||
4597 | tax ; low address |
||
4598 | xba |
||
4599 | tay ; hi address |
||
4600 | lda slattr ; attribute |
||
4601 | xba |
||
4602 | pla ; bank |
||
4603 | jsr outstr |
||
4604 | lda #$40 ; force update status line |
||
4605 | sta slfg |
||
4606 | jsr mvpp2 |
||
4607 | stz bka ; used for count text lenght |
||
4608 | ?ld: jsr cdskld ; load buffer |
||
4609 | bcs ?derr |
||
4610 | beq ?end ; end |
||
4611 | jsr bufld |
||
4612 | bcs ?end |
||
4613 | txa ; eof status |
||
4614 | bpl ?ld |
||
4615 | ?end: php |
||
4616 | lda #$0E ; close file |
||
4617 | CBMFSCLS |
||
4618 | plp |
||
4619 | bcs ?err04 |
||
4620 | ldx #$FF ; update buffer filename |
||
4621 | ?fn: inx |
||
4622 | lda >EDBUFFILE,x |
||
4623 | sta >EDCURFILE,x |
||
4624 | bne ?fn |
||
4625 | lda bflag |
||
4626 | and #$7F ; clear modified flag |
||
4627 | ora #$10 ; set valid fname flag |
||
4628 | sta bflag |
||
4629 | jsr decptr2 |
||
4630 | bcs ?err |
||
4631 | jsr getbyte |
||
4632 | cmp #$0D |
||
4633 | beq ?err |
||
4634 | jsr incptr2 |
||
4635 | lda #$0D |
||
4636 | jsr insert |
||
4637 | ?err: jsr pp2mv |
||
4638 | jmp updwin |
||
4639 | |||
4640 | ?derr: ldx #$FF ; disk error |
||
4641 | jsr error |
||
4642 | bra ?err |
||
4643 | ?err02: ldx #2 |
||
4644 | jsr error |
||
4645 | bra ?err |
||
4646 | ?err04: ldx #4 |
||
4647 | jsr error |
||
4648 | bra ?err |
||
4649 | |||
4650 | ?rds: .DB 'R,S,' |
||
4651 | |||
4652 | ; load a block from CBM disk on chnl 14 |
||
4653 | ; CF = 1 if error |
||
4654 | ; ZF = 1 if buffer is empty |
||
4655 | ; X = $80 if eof |
||
4656 | cdskld: |
||
4657 | lda #^EDDSKBUF ; set buffer pointer |
||
4658 | pha |
||
4659 | pea #EDDSKBUF |
||
4660 | pea #EDDSKBUFSIZ ; buffer size |
||
4661 | lda #$0E |
||
4662 | pha ; chnl 14 |
||
4663 | CBMFSRD ; read buffer |
||
4664 | bcc ?ok |
||
4665 | jsr cdskerr ; get error string |
||
4666 | lda #$0E ; close file |
||
4667 | CBMFSCLS |
||
4668 | sec ; error |
||
4669 | rts |
||
4670 | ?ok: ACC16 |
||
4671 | sta dbufsiz ; store size |
||
4672 | pha |
||
4673 | lda #EDDSKBUF |
||
4674 | sta longp ; reset buffer pointer |
||
4675 | ldx #^EDDSKBUF |
||
4676 | stx longp+2 |
||
4677 | ldx #$80 ; eof flag |
||
4678 | pla ; eof |
||
4679 | beq ?end ; ZF = 1 if buffer is empty |
||
4680 | cmp #EDDSKBUFSIZ |
||
4681 | bcc ?end ; eof |
||
4682 | dex ; not eof |
||
4683 | ?end: ACC08 |
||
4684 | clc |
||
4685 | rts |
||
4686 | |||
4687 | ; send command to cbm fs emulator |
||
4688 | ; command string in longp |
||
4689 | cdskcmd: |
||
4690 | lda #15 |
||
4691 | bra cdsksnd |
||
4692 | |||
4693 | ; open file |
||
4694 | cdskopn: |
||
4695 | lda #$0E |
||
4696 | |||
4697 | cdsksnd: |
||
4698 | ldx longp+2 ; bank of cmnd string |
||
4699 | phx |
||
4700 | pei (longp) ; address of cmnd string |
||
4701 | pha ; chnl |
||
4702 | CBMFSCMD ; send command |
||
4703 | bcs cdskerr ; if error |
||
4704 | rts |
||
4705 | |||
4706 | ; get CBM disk error (in: CF = 1 if error pending else CF = 0) |
||
4707 | cdskerr: |
||
4708 | php ; save carry |
||
4709 | lda #^EDDSKERR |
||
4710 | pha ; address of buffer |
||
4711 | pea #EDDSKERR |
||
4712 | pea #EDERRSIZ ; size of buffer |
||
4713 | lda #15 ; channel 15 |
||
4714 | pha |
||
4715 | CBMFSRD ; read |
||
4716 | plp |
||
4717 | bcs ?end ; error pending |
||
4718 | lda >EDDSKERR |
||
4719 | ora >EDDSKERR+1 |
||
4720 | cmp #'0' |
||
4721 | clc |
||
4722 | beq ?end |
||
4723 | sec |
||
4724 | ?end: rts |
||
4725 | |||
4726 | |||
4727 | ; test load |
||
4728 | testl: |
||
4729 | .EXTERN PCERRS |
||
4730 | |||
4731 | ;bra ?110 |
||
4732 | ldx #0 |
||
4733 | ?lp: lda >?100,x |
||
4734 | sta >EDDSKERR,x |
||
4735 | beq ?lp1 |
||
4736 | inx |
||
4737 | bne ?lp |
||
4738 | ?lp1: jmp cbmopn |
||
4739 | |||
4740 | ?100 .DB '1:test10.pas',0 |
||
4741 | |||
4742 | ?110: |
||
4743 | lda #<PCERRS |
||
4744 | sta pb |
||
4745 | lda #>PCERRS |
||
4746 | sta pb+1 |
||
4747 | lda #^PCERRS |
||
4748 | sta pb+2 |
||
4749 | jsr mvpp2 |
||
4750 | ?02: lda [pb] |
||
4751 | beq ?06 |
||
4752 | jsr insert |
||
4753 | bcc ?03 |
||
4754 | ldy #$FE |
||
4755 | lda #$0D |
||
4756 | sta [pblk],y |
||
4757 | iny |
||
4758 | lda #0 |
||
4759 | sta [pblk],y |
||
4760 | ACC16 |
||
4761 | inc ncount |
||
4762 | ACC08 |
||
4763 | bra ?08 |
||
4764 | ?03: cmp #$0D |
||
4765 | bne ?04 |
||
4766 | ACC16 |
||
4767 | inc ncount ; check overflow !!! |
||
4768 | ACC08 |
||
4769 | ?04: jsr incptr2 |
||
4770 | ACC16 |
||
4771 | inc pb |
||
4772 | ACC08 |
||
4773 | bra ?02 |
||
4774 | ?06: jsr decptr2 |
||
4775 | bcs ?08 |
||
4776 | ?07: jsr getbyte |
||
4777 | cmp #$0D |
||
4778 | beq ?08 |
||
4779 | jsr incptr2 |
||
4780 | lda #$0D |
||
4781 | jsr insert |
||
4782 | ?08: jsr pp2mv |
||
4783 | jmp updwin |
||
4784 | |||
4785 | P10TBL: |
||
4786 | .DW 1 |
||
4787 | .DW 10 |
||
4788 | .DW 100 |
||
4789 | .DW 1000 |
||
4790 | .DW 10000 |
||
4791 | |||
4792 | STRTBLL: |
||
4793 | .DB <str00, <str01, <str02, <str03, <str04, <str05, <str06, <str07 |
||
4794 | .DB <str08 |
||
4795 | |||
4796 | MAXSTR .EQU ($ - STRTBLL) |
||
4797 | |||
4798 | STRTBLH: |
||
4799 | .DB >str00, >str01, >str02, >str03, >str04, >str05, >str06, >str07 |
||
4800 | .DB >str08 |
||
4801 | |||
4802 | strent: |
||
4803 | .DB ' - hit <enter>...', 0 |
||
4804 | |||
4805 | str00: |
||
4806 | .DB 'OK, no error', 0 |
||
4807 | |||
4808 | str01: |
||
4809 | .DB 'Out of memory', 0 |
||
4810 | |||
4811 | str02: |
||
4812 | .DB 'Invalid command', 0 |
||
4813 | |||
4814 | str03: |
||
4815 | .DB 'Illegal tab value', 0 |
||
4816 | |||
4817 | str04: |
||
4818 | .DB 'Not enough memory', 0 |
||
4819 | |||
4820 | str05: |
||
4821 | .DB 'Clipboard: illegal command', 0 |
||
4822 | |||
4823 | str06: |
||
4824 | .DB 'Can''t paste text: lines count overflow', 0 |
||
4825 | |||
4826 | str07: |
||
4827 | .DB 'Can''t insert a new line: lines count overflow', 0 |
||
4828 | |||
4829 | str08: |
||
4830 | .DB 'Illegal numeric value', 0 |
||
4831 | |||
4832 | LOADMSG: |
||
4833 | .DB 'Loading "%s"...', 0 |
||
4834 | |||
4835 | stlstr: |
||
4836 | .DB 'buffer:#0 " " M I O SCN N:00000 L:00000 C:000 ' |
||
4837 | stlstr1: |
||
4838 | .DB 'buffer:#0 " " M I O SCN N:00000 L:00000 C:000 ' |
||
4839 | ; 0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef |
||
4840 | stlstr2: |
||
4841 | .DB 'CLIPBOARD M I O SCN N:00000 L:00000 C:000 ' |
||
4842 | |||
4843 | ; control key's table |
||
4844 | KEYTBL: |
||
4845 | .DB KB_CSRLEFT, KB_CSRDOWN, KB_CSRUP, KB_CSRRIGHT |
||
4846 | .DB KB_HOME, KB_END, KB_PGUP, KB_PGDOWN |
||
4847 | .DB KB_BACKSPACE, KB_SHIFTHOME, KB_SHIFTEND, KB_CTLTAB |
||
4848 | .DB KB_SHCR, KB_DELETE, KB_INSERT, KB_CTLESC |
||
4849 | |||
4850 | ; ALT-X : quit | ALT-O: open | ALT-N: new | ALT-T: set tab |
||
4851 | .DB 'x', 'o', 'n', 't' |
||
4852 | ; ALT-G: goto | ALT-S: save |
||
4853 | .DB 'g', 's' |
||
4854 | |||
4855 | KEYTBLLEN .EQU ($ - KEYTBL - 1) |
||
4856 | |||
4857 | ; control key's function table |
||
4858 | KEYPROC: |
||
4859 | .DW csrleft, csrdwn, csrup, csrrght |
||
4860 | .DW gohome, goend, pageup, pagedwn |
||
4861 | .DW backkey, gostartln, goendln, tind |
||
4862 | .DW kshenter, delkey, tins, testl |
||
4863 | |||
4864 | .DW exit, open, clrbuf, settab |
||
4865 | .DW gotoln, save |
||
4866 | |||
4867 | ; key's table |
||
4868 | KEYTBL2: |
||
4869 | .DB KB_CTLC, KB_TAB, KB_CR, KB_CTLV |
||
4870 | .DB KB_CTLX, KB_ESC, KB_CTLS, KB_CTLY |
||
4871 | |||
4872 | KEYTBLLEN2 .EQU ($ - KEYTBL2 - 1) |
||
4873 | |||
4874 | ; no-control key function table |
||
4875 | KEYPROC2: |
||
4876 | .DW copysel, tabkey, kenter, pastesel |
||
4877 | .DW cutsel, cmdline, seltxt, delline |
||
4878 |