You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

3657 lines
131KB

  1. ;===========================================================================
  2. ; SPEEDSCRIPT 3.1 for the Commodore 64 -- by Charles Brannon
  3. ; (originally published as a type-in by COMPUTE!'s Gazette)
  4. ;
  5. ; Commented disassembly of speedscript.prg (load address $0801, 6156 bytes)
  6. ;
  7. ; This file re-assembles to a byte-identical copy of the original PRG:
  8. ; ca65 speedscript.asm -o speedscript.o
  9. ; ld65 -t none -o speedscript.prg speedscript.o
  10. ; (with "-t none" ld65 writes the code exactly as placed by .org)
  11. ;
  12. ; Labels are descriptive names chosen while reverse-engineering (many follow
  13. ; the names used in Brannon's published source where they are known).
  14. ; Labels of the form Lxxxx are minor branch targets inside a routine.
  15. ;===========================================================================
  16. ;
  17. ; HOW IT STARTS
  18. ; -------------
  19. ; A one-line BASIC program "10 SYS 2061" sits at $0801. SYS 2061 ($080D)
  20. ; enters the machine code, which initialises everything and drops into the
  21. ; main editing loop (MAIN). The program never returns to BASIC unless you
  22. ; press RUN/STOP+RESTORE and answer Y to "EXIT SpeedScript".
  23. ;
  24. ; MEMORY MAP
  25. ; ----------
  26. ; $0400-$07E7 Screen. Row 0 is the "command/message line"; rows 1-24
  27. ; show 24 lines of the document.
  28. ; $0801-$200C This program (BASIC stub, code, tables, message strings)
  29. ; $2008-$200C TEXSTART/TEXEND/TEXBUF low bytes live at the tail of the
  30. ; file; they are (re)initialised by INIT at start-up.
  31. ; $200D-$2471 Variables, input buffers, the printer line buffer, the
  32. ; header/footer buffers, hunt/replace strings, etc.
  33. ; (uninitialised RAM - not part of the file)
  34. ; $2500-$CEFF TEXT AREA: the document being edited (TEXSTART..TEXEND).
  35. ; $D000-$FEFF CUT/PASTE BUFFER (TEXBUF..BUFEND). This is the RAM hiding
  36. ; underneath the I/O chips and the KERNAL ROM, so the
  37. ; program flips the 6510 port ($01) to $34 (all RAM) while
  38. ; copying into or out of it, with the raster IRQ disabled.
  39. ; BASIC ROM is switched out permanently ($01=$36) so $A000-$BFFF is plain
  40. ; RAM for text; it is banked back in briefly ($01=$37) whenever the
  41. ; program wants BASIC's "print a 16-bit number" routine (LINPRT $BDCD).
  42. ;
  43. ; HOW TEXT IS STORED
  44. ; ------------------
  45. ; The document is stored as SCREEN CODES, not PETSCII, so the screen
  46. ; refresh can copy bytes straight into screen memory. Conversions:
  47. ; ASTOIN PETSCII -> screen code INTOAS screen code -> PETSCII
  48. ; Special values inside the text:
  49. ; $1F "return mark" (end of paragraph; shows as a left-arrow)
  50. ; bit 7 set reverse-video character = embedded FORMAT COMMAND for
  51. ; the printer (entered with CTRL-pound)
  52. ; The cursor is drawn by flipping bit 7 of the character under it.
  53. ; Lines are not stored: REFRESH word-wraps the text into 40 column rows
  54. ; every time the screen is redrawn.
  55. ;
  56. ; KEYBOARD COMMANDS (see CTRLTBL / CTRLVEC)
  57. ; -----------------------------------------
  58. ; CRSR right/left move one character CRSR up/down sentence back/fwd
  59. ; F1 / F2 word forward/back F3 / F4 sentence fwd/back
  60. ; F5 / F6 paragraph fwd/back F7 / F8 Load / Save
  61. ; HOME top of screen (twice = top of text)
  62. ; CTRL-Z end of text CLR (SHIFT-HOME) erase all text
  63. ; DEL delete char to left INST insert a space
  64. ; CTRL-F delete char under cursor (SHIFT-CTRL-F: delete the
  65. ; run of spaces from the cursor forward)
  66. ; CTRL-D Delete back: S)entence W)ord P)aragraph (to buffer)
  67. ; CTRL-E Erase forward: S/W/P, repeatable, RETURN exits
  68. ; (SHIFT-CTRL-E appends to the buffer instead of clearing)
  69. ; CTRL-R Retrieve (paste) the buffer at the cursor
  70. ; CTRL-K Kill (clear) the buffer
  71. ; CTRL-I toggle insert mode (command line turns light blue)
  72. ; CTRL-X transpose two characters CTRL-A change case
  73. ; CTRL-B / CTRL-L cycle background / text colour
  74. ; CTRL-H Hunt again (SHIFT-CTRL-H: set the hunt string)
  75. ; CTRL-J Replace found text (SHIFT-CTRL-J: set replacement)
  76. ; CTRL-G Global search & replace
  77. ; CTRL-P Print to printer (SHIFT-CTRL-P: Screen/Disk/Printer)
  78. ; CTRL-V Verify a saved file CTRL-4 disk directory
  79. ; CTRL-pound insert a format command (reverse character)
  80. ; CTRL-up-arrow send a DOS command / read the error channel
  81. ; CTRL-= show free memory
  82. ; RUN/STOP insert 5 spaces SHIFT-RUN/STOP 255 spaces
  83. ; SHIFT-RETURN new paragraph (2 return marks + 5-space indent)
  84. ; left-arrow key back up and blank the character
  85. ; RUN/STOP+RESTORE exit to BASIC (after a Y/N prompt)
  86. ; (Several CTRL-digit colour codes share a PETSCII value with the CTRL
  87. ; letters above, e.g. CTRL-2 = CTRL-E, CTRL-3 = CTRL-pound.)
  88. ;
  89. ; PRINTER FORMAT COMMANDS (reverse characters in the text, see FMTTAB)
  90. ; --------------------------------------------------------------------
  91. ; l n left margin r n right margin t n top margin
  92. ; b n bottom margin p n page length s n line spacing
  93. ; x n page width (for centring) @ n first page number
  94. ; ? n start printing at page n n force next page
  95. ; h.. header line f.. footer line i.. ignore (comment) line
  96. ; m next line has no left margin w wait between pages
  97. ; a true-ASCII translation j add linefeed after CR
  98. ; g d:name / g t:name chain (link) to the next file and keep printing
  99. ; c centre line e flush right u underline on/off
  100. ; # print page number k=n define printer key k to send code n,
  101. ; then a reverse k in the text sends code n.
  102. ;===========================================================================
  103. .setcpu "6502"
  104. ; ---------------------------------------------------------------------------
  105. ; External / RAM equates (zero page, program variables above the code,
  106. ; I/O registers and KERNAL entry points)
  107. ; ---------------------------------------------------------------------------
  108. R6510 = $01 ; 6510 I/O port: memory configuration ($36 = BASIC out, $34 = all RAM, $37 = normal)
  109. UNDERCURS = $02 ; the real character under the (blinking) cursor
  110. WINDCOLR = $0C ; background colour of the command line (row 0); read by IRQ_HANDLER
  111. COLRPTR = $14 ; pointer into colour RAM used by REFRESH
  112. FROML = $26 ; block-move source pointer (low/high)
  113. FROMH = $27
  114. CURR = $39 ; CURSOR POSITION: address of the character under the cursor
  115. TEMP = $3B ; scratch byte / scratch pointer
  116. STATUS = $90 ; KERNAL I/O status byte (ST)
  117. STKEY = $91 ; KERNAL STOP-key flag ($7F = STOP pressed)
  118. KMSGFLG = $9D ; KERNAL message mode ($80 = show "PRESS PLAY..." etc.)
  119. DESTL = $9E ; block-move destination pointer (low/high)
  120. DESTH = $9F
  121. JIFFYLO = $A2 ; jiffy clock, lowest byte (60 Hz)
  122. LLEN = $B4 ; block-move length, low byte
  123. HLEN = $B5 ; block-move length, high byte (pages)
  124. SCRPTR = $C3 ; pointer into screen RAM used by REFRESH
  125. NDX = $C6 ; number of keys in keyboard buffer
  126. PNTR = $D3 ; KERNAL cursor column
  127. QTSW = $D4 ; KERNAL quote-mode flag
  128. INSRT = $D8 ; KERNAL pending-insert count
  129. TEX = $FB ; general text pointer
  130. FPTR = $FD ; pointer to the line being printed (OUTLINE)
  131. RPTFLG = $028A ; key repeat ($80 = all keys repeat)
  132. SHFLAG = $028D ; SHIFT/C=/CTRL flags: 1=SHIFT 2=C= 4=CTRL
  133. CINV = $0314 ; IRQ vector
  134. NMINV = $0318 ; NMI vector (RESTORE key)
  135. SCREEN = $0400 ; screen RAM
  136. BUFEND = $200E ; end of the cut/paste buffer ($FF00)
  137. LENTABLE = $2010 ; length of the top screen line (used to scroll one row)
  138. TOPLIN = $2011 ; address of the first character shown on screen row 1
  139. MSGFLG = $2013 ; non-zero = a message is on the command line (clear it on next key)
  140. INSMODE = $2014 ; insert mode: 0 = overstrike, $0E = insert (also the command line colour)
  141. ENDPOS = $2015 ; end index for UMOVE inner loop / length of the line being printed
  142. FINPOS = $2016 ; scratch: index where a printed line ends
  143. LASTLINE = $2017 ; END OF DOCUMENT: address just past the last character
  144. LIMIT = $2019 ; max length allowed in INPUT
  145. INLEN = $201A ; length of the string typed in INPUT
  146. BOTSCR = $201B ; address just past the last character on screen
  147. LBUFF = $201D ; 40-byte buffer used to build one screen row
  148. INBUFF = $2045 ; 40-byte keyboard input buffer (INPUT)
  149. FILENAME = $206D ; file name buffer (with "0:" prefix)
  150. FNLEN = $2085 ; file name length
  151. SAVCURR = $2086 ; saved cursor (ERAS)
  152. BCD = $2088 ; ASCHEX: number packed as BCD
  153. HEX = $208A ; ASCHEX: binary result
  154. TPTR = $208C ; cut/paste buffer: next free byte
  155. BUFLEN = $208E ; number of bytes in the buffer
  156. GOBLEN = $2090 ; number of bytes being deleted
  157. FROMSAV = $2092 ; saved FROM pointer (DEL2)
  158. DESTSAV = $2094 ; saved DEST pointer (DEL2)
  159. HDLEN = $2096 ; header length (0 = no header)
  160. FTLEN = $2097 ; footer length (0 = no footer)
  161. LMARGIN = $2098 ; PRINT SETTINGS - 12 bytes set from DEFTAB: left margin
  162. RMARGIN = $2099 ; right margin
  163. PAGELENGTH = $209A ; page length (lines)
  164. TOPMARGIN = $209B ; top margin
  165. BOTMARGIN = $209C ; bottom margin (last line printed)
  166. SPACING = $209D ; line spacing
  167. CONTINUOUS = $209E ; 0 = wait for paper between pages
  168. PAGENUM = $209F ; current page number
  169. STARTNUM = $20A1 ; first page to actually print
  170. PAGEWIDTH = $20A3 ; page width (for centring)
  171. NOMARG = $20A4 ; 0 = suppress left margin on next line
  172. POS = $20A5 ; current print column
  173. LINE = $20A6 ; current print line on page
  174. YSAVE = $20A7 ; saved Y register
  175. SAVCHAR = $20A8 ; saved character
  176. INSLEN = $20A9 ; number of bytes to insert (lo; hi = DEVNO)
  177. DEVNO = $20AA ; print device number / INSLEN+1
  178. NEEDASC = $20AB ; 1 = translate to true ASCII
  179. UNDERLINE = $20AC ; 1 = underline on
  180. FPOS = $20AD ; address where hunt string was last found ($FFxx = none)
  181. PCHR = $20AF ; saved character in PCHAR
  182. HUNTLEN = $20B0 ; hunt string length
  183. HUNTBUFF = $20B1 ; hunt string (30 bytes)
  184. REPLEN = $20CF ; replace string length
  185. REPBUFF = $20D0 ; replace string (30 bytes)
  186. CODEBUFFER = $20EE ; printer key codes: 128 bytes indexed by screen code
  187. PRBUFF = $216E ; one formatted print line
  188. HDBUFF = $226E ; header text
  189. FIRSTRUN = $236E ; $CB once SpeedScript has run (text kept on re-entry)
  190. FTBUFF = $236F ; footer text
  191. SAVCOL = $246F ; saved screen colour during printing
  192. LINEFEED = $2470 ; 10 = send LF after every CR
  193. BLINKFLAG = $2471 ; cursor blink phase (1 = cursor currently shown reversed)
  194. LINPRT = $BDCD ; BASIC ROM: print unsigned 16-bit number A=hi X=lo
  195. VIC_CR1 = $D011 ; VIC control reg 1
  196. RASTER = $D012 ; VIC raster compare
  197. VIC_IRR = $D019 ; VIC interrupt latch
  198. VIC_IMR = $D01A ; VIC interrupt enable
  199. EXTCOL = $D020 ; border colour
  200. BGCOL0 = $D021 ; background colour
  201. CIA1_CRA = $DC0E ; CIA1 timer A control (the normal 60 Hz IRQ source)
  202. CIA2_ICR = $DD0D ; CIA2 interrupt control (NMI source)
  203. IRQ_NORMAL = $EA31 ; KERNAL standard IRQ (keyboard scan, clock)
  204. WARMSTART = $FE66 ; KERNAL warm start (as after RUN/STOP+RESTORE)
  205. NMI_RS232 = $FE72 ; KERNAL NMI handler for RS-232
  206. IRQ_EXIT = $FEBC ; KERNAL: pull Y,X,A and RTI
  207. IOINIT = $FF84 ; KERNAL: init I/O devices
  208. SCNKEY = $FF9F ; KERNAL: scan keyboard
  209. SETLFS = $FFBA ; KERNAL: set logical file, device, secondary addr
  210. SETNAM = $FFBD ; KERNAL: set file name (A=len, X/Y=addr)
  211. OPEN = $FFC0 ; KERNAL: open file
  212. CLOSE = $FFC3 ; KERNAL: close file
  213. CHKIN = $FFC6 ; KERNAL: set input channel
  214. CHKOUT = $FFC9 ; KERNAL: set output channel
  215. CLRCHN = $FFCC ; KERNAL: restore default channels
  216. CHRIN = $FFCF ; KERNAL: input a byte
  217. CHROUT = $FFD2 ; KERNAL: output a byte
  218. LOAD_K = $FFD5 ; KERNAL: LOAD/VERIFY
  219. SAVE_K = $FFD8 ; KERNAL: SAVE
  220. STOP = $FFE1 ; KERNAL: test STOP key (Z=1 if pressed)
  221. GETIN = $FFE4 ; KERNAL: get a key / byte (0 if none)
  222. CLALL = $FFE7 ; KERNAL: close all files
  223. UMOVE_SRC = UMOVE_LOOP+1 ; UMOVE source address (patched at run time)
  224. UMOVE_SRC_HI = UMOVE_LOOP+2 ;
  225. UMOVE_DST = UMOVE_STA+1 ; UMOVE destination address (patched)
  226. UMOVE_DST_HI = UMOVE_STA+2 ;
  227. DMOVE_SRC = DMOVE_LOOP+1 ; DMOVE source address (patched)
  228. DMOVE_SRC_HI = DMOVE_LOOP+2 ;
  229. DMOVE_DST = DMOVE_STA+1 ; DMOVE destination address (patched)
  230. DMOVE_DST_HI = DMOVE_STA+2 ;
  231. .org $07FF
  232. .word $0801 ; PRG load address header (2 bytes, not loaded into memory)
  233. CTRLVEC_HI = CTRLVEC+1 ; high bytes of the CTRLVEC words
  234. FMTVEC_HI = FMTVEC+1 ; high bytes of the FMTVEC words
  235. ; ===========================================================================
  236. ; BASIC STUB: 10 SYS 2061
  237. ; link pointer ($080B), line number 10, the SYS token ($9E), the text
  238. ; "2061", a 0 ending the line, and a $0000 link marking end of program.
  239. ; ===========================================================================
  240. BASIC_STUB:
  241. .byte $0B,$08,$0A,$00,$9E,$32,$30,$36,$31,$00,$00,$00 ; link to next line ($080B), line number 10, SYS token ($9E), "2061", 0, end-of-program link $0000
  242. ; ===========================================================================
  243. ; START - entry point (SYS 2061)
  244. ; INIT sets up memory pointers. FIRSTRUN holds $CB after the first run; if
  245. ; it is anything else the text area is filled with spaces. This means that
  246. ; if you exit to BASIC and SYS 2061 again, your document is still there.
  247. ; ===========================================================================
  248. START: jsr INIT ; set up pointers, I/O, colours
  249. lda #$CB ; "already ran" signature value
  250. cmp FIRSTRUN ; Z=1 if we have run before ...
  251. sta FIRSTRUN ; ... (mark that we have run now; STA leaves flags alone)
  252. beq START2 ; second run: keep the old text
  253. jsr ERASE ; first run: blank the whole text area
  254. START2: jsr INIT2 ; clear buffer, install IRQ/NMI, show title
  255. jmp MAIN ; enter the editor main loop (never returns)
  256. ; ===========================================================================
  257. ; UMOVE - copy a block of memory UPWARD (ascending addresses)
  258. ; In: FROML/FROMH = source, DESTL/DESTH = destination,
  259. ; LLEN/HLEN = number of bytes
  260. ; Copies the lowest byte first, so it is safe when DEST < FROM (closing a
  261. ; gap / deleting text). For speed it pokes the source and destination
  262. ; addresses straight into the operands of the LDA/STA in the inner loop
  263. ; (self-modifying code), then copies whole 256-byte pages followed by the
  264. ; remaining LLEN bytes.
  265. ; ===========================================================================
  266. UMOVE: lda FROML ; patch source address into LDA abs,Y
  267. sta UMOVE_SRC
  268. lda FROMH
  269. sta UMOVE_SRC_HI
  270. lda DESTL ; patch destination address into STA abs,Y
  271. sta UMOVE_DST
  272. lda DESTH
  273. sta UMOVE_DST_HI
  274. ldx HLEN ; X = number of whole pages
  275. beq UMOVE_PART ; no whole pages -> just do the partial page
  276. UMOVE_PAGE:
  277. lda #$00 ; ENDPOS=0: inner loop runs until Y wraps (256 bytes)
  278. UMOVE_SETEND:
  279. sta ENDPOS ; ENDPOS = where the inner loop stops
  280. ldy #$00
  281. UMOVE_LOOP:
  282. lda a:$0000,y ; LDA source,Y (operand patched above)
  283. UMOVE_STA:
  284. sta a:$0000,y ; STA dest,Y (operand patched above)
  285. iny
  286. cpy ENDPOS ; reached end index?
  287. bne UMOVE_LOOP
  288. inc UMOVE_SRC_HI ; next page of source
  289. inc UMOVE_DST_HI ; next page of destination
  290. cpx #$00 ; X=0 means the partial page was just done
  291. beq UMOVE_DONE
  292. dex ; one fewer whole page
  293. bne UMOVE_PAGE ; more whole pages to copy
  294. UMOVE_PART:
  295. lda LLEN ; then the leftover LLEN bytes (if any)
  296. bne UMOVE_SETEND
  297. UMOVE_DONE:
  298. rts
  299. ; ===========================================================================
  300. ; DMOVE - copy a block of memory DOWNWARD (descending addresses)
  301. ; Same parameters as UMOVE. Copies the highest byte first, so it is safe
  302. ; when DEST > FROM (opening a gap / inserting text). The operands are
  303. ; patched to point at the LAST page of the block, then it walks backward.
  304. ; (When LLEN<>0 the first partial pass copies offsets LLEN..0, i.e. one
  305. ; byte more than strictly needed - harmless.)
  306. ; ===========================================================================
  307. DMOVE: lda HLEN ; X = HLEN (whole pages)
  308. tax
  309. ora LLEN ; nothing to move at all?
  310. bne DMOVE_GO
  311. rts ; length 0 -> done
  312. DMOVE_GO:
  313. clc
  314. txa ; source high byte = FROMH + HLEN (last page)
  315. adc FROMH
  316. sta DMOVE_SRC_HI
  317. lda FROML ; source low byte
  318. sta DMOVE_SRC
  319. clc
  320. txa ; dest high byte = DESTH + HLEN
  321. adc DESTH
  322. sta DMOVE_DST_HI
  323. lda DESTL ; dest low byte
  324. sta DMOVE_DST
  325. inx ; X = HLEN+1 passes (partial page + whole pages)
  326. ldy LLEN ; start with the partial (top) page, index LLEN
  327. bne DMOVE_LOOP
  328. beq DMOVE_NEXTPG ; LLEN = 0: skip straight to the whole pages
  329. DMOVE_PAGE:
  330. ldy #$FF ; whole page: index $FF down to 0
  331. DMOVE_LOOP:
  332. lda $2452,y ; LDA source,Y (patched)
  333. DMOVE_STA:
  334. sta $2457,y ; STA dest,Y (patched)
  335. dey
  336. cpy #$FF ; until Y wraps below 0
  337. bne DMOVE_LOOP
  338. DMOVE_NEXTPG:
  339. dec DMOVE_SRC_HI ; step source and dest back one page
  340. dec DMOVE_DST_HI
  341. dex ; more pages?
  342. bne DMOVE_PAGE
  343. rts
  344. ; ===========================================================================
  345. ; REFRESH - redraw the text window (screen rows 1-24) from TOPLIN
  346. ; For each of the 24 rows it copies up to 40 characters into LBUFF, stopping
  347. ; early at a return mark. If the row is full it backs up to the last space
  348. ; so words are not split (word wrap); a word longer than 40 characters is
  349. ; simply cut at column 40. The row is copied to screen RAM, its colour RAM
  350. ; is set to TEXCOLR, and the rest of the row is padded with spaces.
  351. ; Side effects: LENTABLE = length of row 1 (lets CHECK scroll one row),
  352. ; BOTSCR = address just past the last visible character,
  353. ; WINDCOLR = INSMODE (command line colour shows insert mode),
  354. ; border = SCRCOL.
  355. ; ===========================================================================
  356. REFRESH:
  357. lda #$28 ; row 1 of the screen is $0428 ...
  358. sta SCRPTR
  359. sta COLRPTR ; ... and its colour RAM is $D828
  360. lda #$04
  361. sta SCRPTR+1
  362. lda #$D8
  363. sta COLRPTR+1
  364. lda TOPLIN ; TEX = first character to show
  365. sta TEX
  366. lda TOPLIN+1
  367. sta TEX+1
  368. ldx #$01 ; X = screen row counter (1..24)
  369. lda INSMODE ; command line colour = 0 (black) or $0E (insert mode)
  370. sta WINDCOLR
  371. lda SCRCOL ; border = current screen colour
  372. sta EXTCOL
  373. REF_ROW:
  374. ldy #$00
  375. REF_COPY:
  376. lda TEXCOLR ; set colour RAM for this column to text colour
  377. sta (COLRPTR),y
  378. lda (TEX),y ; fetch a text character
  379. sta LBUFF,y ; ... and build the row in LBUFF
  380. iny
  381. and #$7F ; (ignore reverse bit)
  382. cmp #$1F ; return mark ends the row
  383. beq REF_LINEEND
  384. cpy #$28 ; filled all 40 columns?
  385. bne REF_COPY
  386. dey ; row is full: look back for a space to break at
  387. REF_WRAP:
  388. lda (TEX),y
  389. and #$7F
  390. cmp #$20
  391. beq REF_BRKSPACE
  392. dey ; not a space, keep looking
  393. bne REF_WRAP
  394. ldy #$27 ; no space anywhere: hard break at 40 chars
  395. REF_BRKSPACE:
  396. iny ; Y = number of characters on this row
  397. REF_LINEEND:
  398. sty TEMP ; save row length
  399. dey
  400. REF_TOSCREEN:
  401. lda LBUFF,y ; copy LBUFF to the screen, right to left
  402. sta (SCRPTR),y
  403. dey
  404. bpl REF_TOSCREEN
  405. ldy TEMP ; advance TEX past this row
  406. clc
  407. tya
  408. adc TEX
  409. sta TEX
  410. lda TEX+1
  411. adc #$00
  412. sta TEX+1
  413. cpx #$01 ; first row?
  414. bne REF_PAD
  415. sty LENTABLE ; remember its length for one-line scrolling
  416. REF_PAD:
  417. cpy #$28 ; pad the rest of the row with spaces
  418. beq REF_NEXTROW
  419. lda #$20
  420. sta (SCRPTR),y
  421. iny
  422. jmp REF_PAD
  423. REF_NEXTROW:
  424. clc ; next screen row: +40 on screen and colour pointers
  425. lda SCRPTR
  426. adc #$28
  427. sta SCRPTR
  428. sta COLRPTR
  429. bcc REF_ROWINC
  430. inc SCRPTR+1
  431. inc COLRPTR+1
  432. REF_ROWINC:
  433. inx
  434. cpx #$19 ; done 24 rows?
  435. beq REF_DONE
  436. jmp REF_ROW
  437. REF_DONE:
  438. lda TEX ; BOTSCR = first character NOT on the screen
  439. sta BOTSCR
  440. lda TEX+1
  441. sta BOTSCR+1
  442. rts
  443. ; ===========================================================================
  444. ; ERASE - wipe the whole document
  445. ; Resets TOPLIN, LASTLINE and CURR to TEXSTART and fills every page from
  446. ; TEXSTART-1 up to TEXEND with spaces.
  447. ; ===========================================================================
  448. ERASE: lda TEXSTART ; TEX = TOPLIN = LASTLINE = CURR = TEXSTART
  449. sta TEX
  450. sta TOPLIN
  451. sta LASTLINE
  452. sta CURR
  453. lda TEXSTART+1
  454. sta TEX+1
  455. sta TOPLIN+1
  456. sta LASTLINE+1
  457. sta CURR+1
  458. sec ; X = number of pages in the text area
  459. lda TEXEND+1
  460. sbc TEXSTART+1
  461. tax
  462. lda #$20 ; fill byte: space (screen code $20)
  463. ldy #$FF ; Y=$FF with TEX-256 -> address TEXSTART-1
  464. dec TEX+1
  465. sta (TEX),y ; blank the byte just before the text, too
  466. iny ; Y=0
  467. inc TEX+1
  468. ERASE_LOOP:
  469. sta (TEX),y ; fill a page with spaces
  470. iny
  471. bne ERASE_LOOP
  472. inc TEX+1 ; next page
  473. dex
  474. bne ERASE_LOOP
  475. sta (TEX),y ; and one byte at the very end
  476. rts
  477. ; ===========================================================================
  478. ; PRMSG - print a zero-terminated string. In: A = low, Y = high address.
  479. ; (Strings are PETSCII and may contain control codes. Max 255 chars.)
  480. ; ===========================================================================
  481. PRMSG: sta TEMP
  482. sty TEMP+1
  483. ldy #$00
  484. PRMSG_LOOP:
  485. lda (TEMP),y
  486. beq PRMSG_DONE ; 0 terminates the string
  487. jsr CHROUT
  488. iny
  489. bne PRMSG_LOOP
  490. PRMSG_DONE:
  491. rts
  492. ; ===========================================================================
  493. ; GETAKEY - wait until a key is pressed, return it in A
  494. ; ===========================================================================
  495. GETAKEY:
  496. jsr GETIN
  497. beq GETAKEY
  498. rts
  499. ; ===========================================================================
  500. ; INIT - one-time machine set-up
  501. ; Clear the screen, switch BASIC ROM out (RAM at $A000-$BFFF), and set the
  502. ; memory layout: TEXSTART=$2500 TEXEND=$CF00 TEXBUF=$D000 BUFEND=$FF00.
  503. ; Also clears insert mode and the hunt/replace strings.
  504. ; ===========================================================================
  505. INIT: lda #$93 ; PETSCII CLR: clear screen
  506. jsr CHROUT
  507. lda #$36 ; $36: BASIC ROM off, KERNAL + I/O on
  508. sta R6510
  509. lda #$00 ; zero:
  510. sta INSMODE ; overstrike mode
  511. sta TEXSTART ; all four pointers start on a page boundary
  512. sta TEXEND
  513. sta TEXBUF
  514. sta BUFEND
  515. sta HUNTLEN ; no hunt string
  516. sta REPLEN ; no replace string
  517. lda #$24 ; TEXSTART high = $24+1 = $25 (text starts at $2500)
  518. clc
  519. adc #$01
  520. sta TEXSTART+1
  521. lda #$CF ; TEXEND = $CF00 (just below the I/O area)
  522. sta TEXEND+1
  523. lda #$D0 ; TEXBUF = $D000 (buffer lives under I/O + KERNAL)
  524. sta TEXBUF+1
  525. lda #$FF ; BUFEND = $FF00
  526. sta BUFEND+1
  527. sta FPOS+1 ; FPOS high = $FF: nothing found yet
  528. jmp IOINIT ; initialise CIAs etc. and return
  529. ; ===========================================================================
  530. ; INIT2 / INIT3 - (re)start the editor
  531. ; INIT2 also empties the cut/paste buffer. INIT3 is used after "erase
  532. ; all text". Sets key repeat for all keys, KERNAL messages on, installs the
  533. ; split-screen raster IRQ and the RESTORE-key NMI handler, puts the cursor
  534. ; at the top of the text, and shows the title + by-line.
  535. ; ===========================================================================
  536. INIT2: jsr KILLBUFF ; empty the cut/paste buffer
  537. INIT3: lda #$80 ; $80 =
  538. sta RPTFLG ; all keys auto-repeat
  539. sta KMSGFLG ; KERNAL control messages on ("PRESS PLAY ON TAPE")
  540. jsr IRQ_ON ; start the two-colour raster interrupt
  541. lda #<NMI_HANDLER ; NMI vector -> our RESTORE handler
  542. sta NMINV
  543. lda #>NMI_HANDLER
  544. sta NMINV+1
  545. lda TEXSTART ; cursor = start of text
  546. sta CURR
  547. lda TEXSTART+1
  548. sta CURR+1
  549. jsr SYSMSG ; show "SpeedScript 3.1" on the command line
  550. lda #<MSG_BYLINE ; followed by " by Charles Brannon"
  551. ldy #>MSG_BYLINE
  552. jsr PRMSG
  553. inc MSGFLG ; MSGFLG <> 0: the message is erased by the next key
  554. rts
  555. DEADBYTES:
  556. .byte $B1,$0B ; never executed (stray bytes: LDA ($0B),Y)
  557. ; ===========================================================================
  558. ; SYSMSG - clear the command line and show the title; MSGFLG = 0
  559. ; ===========================================================================
  560. SYSMSG: jsr TOPCLR
  561. lda #<MSG_TITLE
  562. ldy #>MSG_TITLE
  563. jsr PRMSG
  564. lda #$00
  565. sta MSGFLG
  566. rts
  567. ; ===========================================================================
  568. ; NMI_HANDLER - RUN/STOP + RESTORE
  569. ; If the NMI came from CIA2 (RS-232) pass it to the KERNAL. Otherwise put
  570. ; the real character back under the cursor and ask "EXIT SpeedScript: Are
  571. ; you sure?". Y = restore the normal IRQ and warm-start BASIC (the text
  572. ; stays in memory). Anything else = reset the stack and restart the editor.
  573. ; ===========================================================================
  574. NMI_HANDLER:
  575. pha ; save A, X, Y
  576. txa
  577. pha
  578. tya
  579. pha
  580. lda #$7F ; disable all CIA2 interrupts
  581. sta CIA2_ICR
  582. ldy CIA2_ICR ; read (and clear) CIA2 interrupt flags
  583. bpl NMI_RESTORE ; bit 7 clear = not a CIA2 interrupt = RESTORE key
  584. jmp NMI_RS232 ; CIA2 (RS-232) NMI: let the KERNAL handle it
  585. NMI_RESTORE:
  586. lda BLINKFLAG ; is the cursor currently drawn reversed?
  587. beq NMI_ASK
  588. lda UNDERCURS ; yes: put the real character back
  589. ldy #$00
  590. sta (CURR),y
  591. NMI_ASK:
  592. lda #$02 ; command line red
  593. sta WINDCOLR
  594. jsr CLRCHN ; make sure I/O goes to screen/keyboard
  595. jsr TOPCLR
  596. lda #<MSG_EXIT ; "EXIT SpeedScript"
  597. ldy #>MSG_EXIT
  598. jsr PRMSG
  599. jsr YORN ; ": Are you sure? (Y/N):"
  600. bne NMI_STAY ; not Y: stay in SpeedScript
  601. jsr IRQ_OFF ; back to the normal 60 Hz IRQ
  602. sei
  603. lda #$7F ; A=$7F as the KERNAL NMI code expects
  604. jmp WARMSTART ; jump into KERNAL warm start -> BASIC READY.
  605. NMI_STAY:
  606. jsr IRQ_OFF ; restore normal IRQ (INIT2 re-installs ours)
  607. ldx #$FA ; reset the stack (we were deep inside an NMI)
  608. txs
  609. jsr INIT2 ; restart editor (also clears the buffer)
  610. jmp MAIN
  611. ; ===========================================================================
  612. ; TOPCLR - blank the command line (screen row 0) and HOME the cursor so
  613. ; the next CHROUT prints at the top-left
  614. ; ===========================================================================
  615. TOPCLR: ldx #$27
  616. lda #$20
  617. TOPCLR_LOOP:
  618. sta SCREEN,x
  619. dex
  620. bpl TOPCLR_LOOP
  621. lda #$13 ; PETSCII HOME
  622. jmp CHROUT
  623. ; ===========================================================================
  624. ; ASTOIN - convert a PETSCII character to a screen code
  625. ; screen = (A AND $3F) OR ((A AND $80) >> 1)
  626. ; e.g. "a" $41 -> $01, "A" $C1 -> $41, "0" $30 -> $30, $5F -> $1F
  627. ; ===========================================================================
  628. ASTOIN: pha
  629. and #$80 ; keep bit 7 ...
  630. lsr a ; ... and move it to bit 6
  631. sta TEMP
  632. pla
  633. and #$3F ; low 6 bits
  634. ora TEMP ; combine
  635. rts
  636. ; ===========================================================================
  637. ; MAIN - THE EDITOR MAIN LOOP
  638. ; 1. Remember the character under the cursor.
  639. ; 2. Toggle its reverse bit (blink), redraw the screen.
  640. ; 3. Wait for a key; every 16 jiffies with no key go back to 2 (blink).
  641. ; 4. Put the real character back.
  642. ; 5. Dispatch: left-arrow -> move left, blank char
  643. ; RETURN -> becomes $5F (stored as return mark $1F)
  644. ; printable char -> store at cursor (insert if INSMODE or if
  645. ; we are on a return mark), advance cursor
  646. ; control char -> look up in CTRLTBL and call the routine
  647. ; Every command routine "returns" to MAIN because the dispatcher pushes
  648. ; MAIN-1 as a fake return address.
  649. ; ===========================================================================
  650. MAIN: ldy #$00
  651. sty BLINKFLAG ; cursor not currently reversed
  652. lda (CURR),y ; save the real character under the cursor
  653. sta UNDERCURS
  654. CURSOR_FLASH:
  655. ldy #$00
  656. lda (CURR),y ; flip reverse bit of the cursor character
  657. eor #$80
  658. sta (CURR),y
  659. lda BLINKFLAG ; remember the blink phase
  660. eor #$01
  661. sta BLINKFLAG
  662. jsr REFRESH ; redraw so the change shows
  663. WAITKEY:
  664. jsr GETIN ; key pressed?
  665. bne GOTKEY
  666. lda JIFFYLO ; no key: has bit 4 of the jiffy clock come on?
  667. and #$10
  668. beq WAITKEY
  669. lda #$00 ; yes: restart the 16-jiffy timer ...
  670. sta JIFFYLO
  671. jmp CURSOR_FLASH ; ... and blink
  672. GOTKEY: tax ; X = key
  673. ldy #$00
  674. lda UNDERCURS ; restore the true character under the cursor
  675. sta (CURR),y
  676. sty BLINKFLAG ; BLINKFLAG = 0
  677. cpx #$5F ; left-arrow key?
  678. bne CHKMSG
  679. jsr LEFT ; yes: move left ...
  680. lda #$20 ; ... and overwrite with a space
  681. ldy #$00
  682. sta (CURR),y
  683. jmp MAIN
  684. CHKMSG: lda MSGFLG ; is a message showing on the command line?
  685. beq NOMSG
  686. txa
  687. pha
  688. jsr SYSMSG ; yes: replace it with the title (keep the key)
  689. pla
  690. tax
  691. NOMSG: txa
  692. cmp #$0D ; RETURN?
  693. bne NOTCR
  694. ldx #$5F ; yes: use $5F, which ASTOIN turns into return mark $1F
  695. NOTCR: txa
  696. and #$7F ; ignore SHIFT bit ...
  697. cmp #$20 ; ... codes $00-$1F / $80-$9F are control keys
  698. bcc CONTROL
  699. cpx #$A0 ; SHIFT-SPACE ($A0)?
  700. bne TYPECHAR
  701. ldx #$20 ; treat as plain space
  702. TYPECHAR:
  703. txa
  704. pha
  705. ldy #$00 ; is the cursor on a return mark?
  706. lda (CURR),y
  707. cmp #$1F
  708. beq MAKEROOM
  709. lda INSMODE ; or is insert mode on?
  710. beq STORECHAR
  711. MAKEROOM:
  712. jsr INSCHAR ; either way: open a one-character gap first
  713. STORECHAR:
  714. pla
  715. jsr ASTOIN ; PETSCII -> screen code
  716. PUTCHR: ldy #$00 ; PUTCHR: store character at the cursor
  717. sta (CURR),y
  718. jsr REFRESH
  719. sec ; is cursor >= LASTLINE (typing at the very end)?
  720. lda CURR
  721. sbc LASTLINE
  722. sta TEMP
  723. lda CURR+1
  724. sbc LASTLINE+1
  725. ora TEMP
  726. bcc ADVANCE ; no: document length unchanged
  727. lda CURR ; yes: LASTLINE = CURR+1 (carry is set here)
  728. adc #$00
  729. sta LASTLINE
  730. lda CURR+1
  731. adc #$00
  732. sta LASTLINE+1
  733. ADVANCE:
  734. inc CURR ; advance the cursor
  735. bne TYPED_DONE
  736. inc CURR+1
  737. TYPED_DONE:
  738. jsr CHECK ; keep cursor in range and on screen
  739. jmp MAIN
  740. ; CONTROL - look a control key up in CTRLTBL and jump to its routine.
  741. ; The routine address-1 is pushed and RTS jumps to it; MAIN-1 is pushed
  742. ; underneath so the routine's own RTS returns to MAIN.
  743. CONTROL:
  744. txa
  745. ldx CTRLTBL ; X = number of entries (39)
  746. CTRL_SEARCH:
  747. cmp CTRLTBL,x ; search the table from the end
  748. beq CTRL_FOUND
  749. dex
  750. bne CTRL_SEARCH
  751. jmp MAIN ; unknown key: ignore it
  752. CTRL_FOUND:
  753. dex ; X = (index-1)*2 = offset into CTRLVEC
  754. txa
  755. asl a
  756. tax
  757. lda #>(MAIN-1) ; push MAIN-1 (return address for the command)
  758. pha
  759. lda #<(MAIN-1)
  760. pha
  761. lda CTRLVEC_HI,x ; push command address-1, high byte first
  762. pha
  763. lda CTRLVEC,x
  764. pha
  765. rts ; "return" into the command routine
  766. ; CTRLTBL - first byte = entry count, then the 39 key codes.
  767. ; CTRLVEC - matching routine addresses (minus 1, for the RTS trick).
  768. CTRLTBL:
  769. .byte $27 ; count = 39
  770. .byte $1D,$9D,$89,$85,$02,$0C,$8A,$86 ; CRSR-R CRSR-L F2 F1 CTRL-B CTRL-L F4 F3
  771. .byte $14,$94,$04,$13,$09,$93,$87,$8B ; DEL INST CTRL-D HOME CTRL-I CLR F5 F6
  772. .byte $05,$88,$8C,$16,$91,$11,$9F,$12 ; CTRL-E F7 F8 CTRL-V CRSR-U CRSR-D CTRL-4 CTRL-R
  773. .byte $18,$1A,$10,$1C,$1E,$06,$01,$0B ; CTRL-X CTRL-Z CTRL-P CTRL-pound CTRL-up CTRL-F CTRL-A CTRL-K
  774. .byte $08,$1F,$03,$83,$0A,$8D,$07 ; CTRL-H CTRL-= STOP SH-STOP CTRL-J SH-RET CTRL-G
  775. CTRLVEC:
  776. .word RIGHT-1 ; CRSR right: one character right
  777. .word LEFT-1 ; CRSR left: one character left
  778. .word WLEFT-1 ; F2: word left
  779. .word WRIGHT-1 ; F1: word right
  780. .word BORDER-1 ; CTRL-B: next border/background colour
  781. .word LETTERS-1 ; CTRL-L: next text colour
  782. .word SLEFT-1 ; F4: sentence left
  783. .word SRIGHT-1 ; F3: sentence right
  784. .word BACKSPACE-1 ; DEL: delete character to the left
  785. .word INSCHAR-1 ; INST: insert a space
  786. .word DELETE-1 ; CTRL-D: delete backward (S/W/P)
  787. .word HOME-1 ; HOME: top of screen / top of text
  788. .word INSTGL-1 ; CTRL-I: toggle insert mode
  789. .word CLEARALL-1 ; CLR: erase all text
  790. .word PARRIGHT-1 ; F5: paragraph right
  791. .word PARLEFT-1 ; F6: paragraph left
  792. .word ERAS-1 ; CTRL-E: erase forward (S/W/P)
  793. .word LOAD-1 ; F7: load
  794. .word SAVE-1 ; F8: save
  795. .word VERIFY-1 ; CTRL-V: verify
  796. .word SLEFT-1 ; CRSR up: sentence left
  797. .word SRIGHT-1 ; CRSR down: sentence right
  798. .word CATALOG-1 ; CTRL-4: disk directory
  799. .word RETRIEVE-1 ; CTRL-R: retrieve (paste) buffer
  800. .word TRANSPOSE-1 ; CTRL-X: transpose characters
  801. .word GOEND-1 ; CTRL-Z: end of text
  802. .word PRINT-1 ; CTRL-P: print
  803. .word FORMAT-1 ; CTRL-pound: insert format command
  804. .word DISKCMD-1 ; CTRL-up arrow: DOS command
  805. .word DELFWD-1 ; CTRL-F: delete forward
  806. .word CASECHG-1 ; CTRL-A: change case
  807. .word KILLBUFF-1 ; CTRL-K: kill buffer
  808. .word HUNT-1 ; CTRL-H: hunt
  809. .word FREEMEM-1 ; CTRL-=: free memory
  810. .word TAB5-1 ; RUN/STOP: insert 5 spaces
  811. .word INS255-1 ; SHIFT-RUN/STOP: insert 255 spaces
  812. .word REPSTART-1 ; CTRL-J: replace
  813. .word NEWPARA-1 ; SHIFT-RETURN: new paragraph
  814. .word GLOBAL-1 ; CTRL-G: global search & replace
  815. ; ===========================================================================
  816. ; CHECK - keep the cursor legal and visible
  817. ; First CHECK2 clamps CURR into TEXSTART..LASTLINE. Then:
  818. ; * cursor above the screen -> make the cursor's address the new TOPLIN
  819. ; * cursor below the screen -> scroll down one row at a time (TOPLIN +=
  820. ; LENTABLE, REFRESH) until it is visible again.
  821. ; ===========================================================================
  822. CHECK: jsr CHECK2
  823. sec ; CURR < TOPLIN ?
  824. lda CURR
  825. sbc TOPLIN
  826. lda CURR+1
  827. sbc TOPLIN+1
  828. bcs CHKBOTTOM ; no: check the bottom
  829. sec ; already at the top of the text? then nothing to do
  830. lda TOPLIN
  831. sbc TEXSTART
  832. sta TEMP
  833. lda TOPLIN+1
  834. sbc TEXSTART+1
  835. ora TEMP
  836. beq CHKBOTTOM
  837. lda CURR ; scroll up: screen now starts at the cursor
  838. sta TOPLIN
  839. lda CURR+1
  840. sta TOPLIN+1
  841. jsr REFRESH
  842. CHKBOTTOM:
  843. sec ; BOTSCR - CURR ...
  844. lda BOTSCR
  845. sbc CURR
  846. sta TEX
  847. lda BOTSCR+1
  848. sbc CURR+1
  849. sta TEX+1
  850. ora TEX
  851. beq SCROLLDN ; zero: cursor just off the bottom -> scroll
  852. bcs CHECK_DONE ; positive: cursor is on screen, done
  853. SCROLLDN:
  854. clc ; scroll down one row: TOPLIN += length of row 1
  855. lda TOPLIN
  856. adc LENTABLE
  857. sta TOPLIN
  858. lda TOPLIN+1
  859. adc #$00
  860. sta TOPLIN+1
  861. jsr REFRESH ; redraw (recomputes LENTABLE and BOTSCR)
  862. jmp CHKBOTTOM ; and test again
  863. CHECK_DONE:
  864. rts
  865. ; CHECK2 - clamp pointers: LASTLINE <= TEXEND, TEXSTART <= CURR <= LASTLINE
  866. CHECK2: sec ; LASTLINE >= TEXEND ?
  867. lda LASTLINE
  868. sbc TEXEND
  869. sta TEMP
  870. lda LASTLINE+1
  871. sbc TEXEND+1
  872. ora TEMP
  873. bcc CHK_LOW
  874. lda TEXEND ; yes: LASTLINE = TEXEND
  875. sta LASTLINE
  876. lda TEXEND+1
  877. sta LASTLINE+1
  878. CHK_LOW:
  879. sec ; CURR < TEXSTART ?
  880. lda CURR
  881. sbc TEXSTART
  882. sta TEMP
  883. lda CURR+1
  884. sbc TEXSTART+1
  885. ora TEMP
  886. bcs CHK_HIGH
  887. lda TEXSTART ; yes: CURR = TEXSTART
  888. sta CURR
  889. lda TEXSTART+1
  890. sta CURR+1
  891. rts
  892. CHK_HIGH:
  893. sec ; CURR >= LASTLINE ?
  894. lda CURR
  895. sbc LASTLINE
  896. sta TEMP
  897. lda CURR+1
  898. sbc LASTLINE+1
  899. ora TEMP
  900. bcs CLAMP_END
  901. rts
  902. CLAMP_END:
  903. lda LASTLINE ; yes: CURR = LASTLINE
  904. sta CURR
  905. lda LASTLINE+1
  906. sta CURR+1
  907. rts
  908. ; RIGHT / LEFT - move the cursor one character (CRSR keys)
  909. RIGHT: inc CURR
  910. bne RIGHT_DONE
  911. inc CURR+1
  912. RIGHT_DONE:
  913. jmp CHECK
  914. LEFT: lda CURR
  915. bne LEFT_LO
  916. dec CURR+1
  917. LEFT_LO:
  918. dec CURR
  919. jmp CHECK
  920. ; ===========================================================================
  921. ; WLEFT - move to the start of the previous word (F2)
  922. ; TEX = CURR-256 and Y=$FF so (TEX),Y is the byte before the cursor.
  923. ; Skip back over spaces/return marks, then over the word itself, then
  924. ; place the cursor just after the space found. (Looks back at most 255
  925. ; characters.)
  926. ; ===========================================================================
  927. WLEFT: lda CURR
  928. sta TEX
  929. lda CURR+1
  930. sta TEX+1
  931. dec TEX+1
  932. ldy #$FF
  933. WL_SKIPSP:
  934. lda (TEX),y ; skip spaces ...
  935. cmp #$20
  936. beq WL_NEXT
  937. cmp #$1F ; ... and return marks
  938. bne WL_SKIPWORD
  939. WL_NEXT:
  940. dey
  941. bne WL_SKIPSP
  942. WL_SKIPWORD:
  943. lda (TEX),y ; now skip the word: stop at a space ...
  944. cmp #$20
  945. beq SETCURR
  946. cmp #$1F ; ... or a return mark
  947. beq SETCURR
  948. dey
  949. bne WL_SKIPWORD
  950. rts ; ran out of range: leave the cursor alone
  951. SETCURR:
  952. sec ; SETCURR: CURR = TEX+Y+1 (character after the break)
  953. tya
  954. adc TEX
  955. sta CURR
  956. lda TEX+1
  957. adc #$00
  958. sta CURR+1
  959. jmp CHECK
  960. ; ===========================================================================
  961. ; WRIGHT - move to the start of the next word (F1)
  962. ; Skip forward over the current word, then over spaces/return marks.
  963. ; If we run past LASTLINE, go to the end of the text.
  964. ; ===========================================================================
  965. WRIGHT: ldy #$00
  966. WR_SKIPWORD:
  967. lda (CURR),y ; skip the rest of this word
  968. cmp #$20
  969. beq WR_SKIPSP
  970. cmp #$1F
  971. beq WR_SKIPSP
  972. iny
  973. bne WR_SKIPWORD
  974. rts
  975. WR_SKIPSP:
  976. iny ; skip spaces/returns, crossing page boundaries
  977. bne WR_TEST
  978. inc CURR+1
  979. lda CURR+1
  980. cmp LASTLINE+1 ; past the end of the text?
  981. bcc WR_TEST
  982. bne ENDTEX ; yes: go to the end
  983. WR_TEST:
  984. lda (CURR),y
  985. cmp #$20
  986. beq WR_SKIPSP
  987. cmp #$1F
  988. beq WR_SKIPSP
  989. ADDYCURR:
  990. clc ; ADDYCURR: CURR += Y, then CHECK
  991. tya
  992. adc CURR
  993. sta CURR
  994. lda CURR+1
  995. adc #$00
  996. sta CURR+1
  997. jmp CHECK
  998. ENDTEX: lda LASTLINE ; ENDTEX: cursor = LASTLINE (end of text)
  999. sta CURR
  1000. lda LASTLINE+1
  1001. sta CURR+1
  1002. jmp CHECK
  1003. ; GOEND - CTRL-Z: jump to the end of the document. The screen is
  1004. ; positioned to start about 4 pages (1K) before the end, then CHECK
  1005. ; scrolls the cursor into view.
  1006. GOEND: lda #$00
  1007. sta TOPLIN ; TOPLIN low = 0
  1008. lda LASTLINE+1 ; TOPLIN high = LASTLINE high - 4 ...
  1009. sec
  1010. sbc #$04
  1011. cmp TEXSTART+1 ; ... but not before the start of text
  1012. bcs GOEND_SET
  1013. lda TEXSTART+1
  1014. GOEND_SET:
  1015. sta TOPLIN+1
  1016. jsr REFRESH
  1017. jmp ENDTEX
  1018. ; BORDER - CTRL-B: next screen colour (0-15) for border and text window.
  1019. ; LETTERS - CTRL-L: next text (character) colour. SCRCOL and TEXCOLR are
  1020. ; single data bytes embedded in the code.
  1021. BORDER: inc SCRCOL
  1022. lda SCRCOL
  1023. and #$0F
  1024. sta SCRCOL
  1025. rts
  1026. SCRCOL: .byte $0C ; SCRCOL: border/background colour (12 = medium grey)
  1027. LETTERS:
  1028. inc TEXCOLR
  1029. lda TEXCOLR
  1030. and #$0F
  1031. sta TEXCOLR
  1032. jmp REFRESH
  1033. TEXCOLR:
  1034. .byte $0B ; TEXCOLR: text colour (11 = dark grey)
  1035. ; ===========================================================================
  1036. ; SLEFT - move to the start of the previous sentence (F4 / CRSR up)
  1037. ; A sentence ends with ".", "!", "?" or a return mark. Skip back over the
  1038. ; punctuation the cursor is sitting just after, find the previous one,
  1039. ; then skip spaces forward to the first letter of the sentence. Goes to
  1040. ; TEXSTART if no earlier sentence end is found.
  1041. ; ===========================================================================
  1042. SLEFT: lda CURR
  1043. sta TEX
  1044. lda CURR+1
  1045. sta TEX+1
  1046. dec TEX+1
  1047. ldy #$FF
  1048. SL_SKIPPUNC:
  1049. lda (TEX),y ; skip trailing punctuation / return marks
  1050. cmp #$2E
  1051. beq SL_NEXT
  1052. cmp #$21
  1053. beq SL_NEXT
  1054. cmp #$3F
  1055. beq SL_NEXT
  1056. cmp #$1F
  1057. bne SL_FINDPUNC
  1058. SL_NEXT:
  1059. dey
  1060. bne SL_SKIPPUNC
  1061. rts
  1062. SL_FINDPUNC:
  1063. lda (TEX),y ; search back for . ! ? or return mark
  1064. cmp #$2E
  1065. beq SL_FOUND
  1066. cmp #$21
  1067. beq SL_FOUND
  1068. cmp #$3F
  1069. beq SL_FOUND
  1070. cmp #$1F
  1071. beq SL_FOUND
  1072. dey
  1073. bne SL_FINDPUNC
  1074. dec TEX+1 ; crossed into the previous page
  1075. lda TEX+1
  1076. cmp TEXSTART ; before the start of text?
  1077. bcs SL_FINDPUNC
  1078. jmp TOPTEXT ; yes: go to the top of the text
  1079. SL_FOUND:
  1080. sty TEMP ; found the end of the previous sentence
  1081. dec TEMP
  1082. SL_SKIPSP:
  1083. iny ; skip spaces forward to the first word
  1084. beq SL_PAGEWRAP
  1085. lda (TEX),y
  1086. cmp #$20
  1087. beq SL_SKIPSP
  1088. dey ; back up one: SETCURR adds 1
  1089. jmp SETCURR
  1090. SL_PAGEWRAP:
  1091. ldy TEMP ; Y wrapped to 0 while skipping: keep searching back
  1092. jmp SL_FINDPUNC
  1093. TOPTEXT:
  1094. lda TEXSTART ; TOPTEXT: cursor = TEXSTART
  1095. sta CURR
  1096. lda TEXSTART+1
  1097. sta CURR+1
  1098. jmp CHECK
  1099. ; ===========================================================================
  1100. ; SRIGHT - move to the start of the next sentence (F3 / CRSR down)
  1101. ; Search forward for ".", "!", "?" or a return mark, then skip any run of
  1102. ; spaces/punctuation; stop at the first other character.
  1103. ; ===========================================================================
  1104. SRIGHT: ldy #$00
  1105. SR_FINDPUNC:
  1106. lda (CURR),y
  1107. cmp #$2E
  1108. beq SR_SKIP
  1109. cmp #$21
  1110. beq SR_SKIP
  1111. cmp #$3F
  1112. beq SR_SKIP
  1113. cmp #$1F
  1114. beq SR_SKIP
  1115. iny
  1116. bne SR_FINDPUNC
  1117. inc CURR+1 ; next page; stop at the end of the text
  1118. lda CURR+1
  1119. cmp LASTLINE+1
  1120. beq SR_FINDPUNC
  1121. bcc SR_FINDPUNC
  1122. jmp ENDTEX
  1123. SR_SKIP:
  1124. iny ; skip spaces and punctuation after the sentence end
  1125. bne SR_TEST
  1126. inc CURR+1
  1127. lda CURR+1
  1128. cmp LASTLINE+1
  1129. bcc SR_TEST
  1130. beq SR_TEST
  1131. jmp ENDTEX
  1132. SR_TEST:
  1133. lda (CURR),y
  1134. cmp #$20
  1135. beq SR_SKIP
  1136. cmp #$2E
  1137. beq SR_SKIP
  1138. cmp #$21
  1139. beq SR_SKIP
  1140. cmp #$3F
  1141. beq SR_SKIP
  1142. cmp #$1F
  1143. beq SR_SKIP
  1144. jmp ADDYCURR ; CURR += Y
  1145. ; ===========================================================================
  1146. ; KILLBUFF - CTRL-K: empty the cut/paste buffer (TPTR = TEXBUF) and
  1147. ; show "Buffer Cleared"
  1148. ; ===========================================================================
  1149. KILLBUFF:
  1150. lda TEXBUF
  1151. sta TPTR
  1152. lda TEXBUF+1
  1153. sta TPTR+1
  1154. jsr TOPCLR
  1155. lda #<MSG_BUFCLR
  1156. ldy #>MSG_BUFCLR
  1157. jsr PRMSG
  1158. lda #$01
  1159. sta MSGFLG
  1160. rts
  1161. ; ===========================================================================
  1162. ; DELETION ENGINE
  1163. ; DELSETUP: if the cursor is at TEXSTART there is nothing to delete
  1164. ; behind it, so it pops its caller's return address and returns
  1165. ; straight to MAIN. Otherwise FROM = CURR (end of the doomed text).
  1166. ; The caller then moves CURR back (one char / word / sentence / paragraph)
  1167. ; and calls DEL1.
  1168. ;
  1169. ; DEL1: DEST = CURR (start), GOBLEN = FROM - DEST (bytes to remove).
  1170. ; DEL2: If the deleted text fits, append it to the cut/paste buffer at
  1171. ; TPTR (with all-RAM banking since the buffer is under I/O), then
  1172. ; close the gap by UMOVEing everything after it down, and reduce
  1173. ; LASTLINE. If the buffer would overflow: "Buffer Full", nothing
  1174. ; is deleted and the keyboard buffer is flushed.
  1175. ; ===========================================================================
  1176. DELSETUP:
  1177. sec ; CURR = TEXSTART ?
  1178. lda CURR
  1179. sbc TEXSTART
  1180. sta TEMP
  1181. lda CURR+1
  1182. sbc TEXSTART+1
  1183. ora TEMP
  1184. bne DELSETUP2
  1185. pla ; yes: discard return address -> back to MAIN
  1186. pla
  1187. rts
  1188. DELSETUP2:
  1189. lda CURR ; FROM = CURR
  1190. sta FROML
  1191. lda CURR+1
  1192. sta FROMH
  1193. rts
  1194. DEL1: sec ; DEST = CURR; GOBLEN = FROM - CURR
  1195. lda CURR
  1196. sta DESTL
  1197. eor #$FF ; (EOR #$FF + ADC with carry set = subtract)
  1198. adc FROML
  1199. sta GOBLEN
  1200. lda CURR+1
  1201. sta DESTH
  1202. eor #$FF
  1203. adc FROMH
  1204. sta GOBLEN+1
  1205. DEL2: lda FROML ; save FROM and DEST
  1206. sta FROMSAV
  1207. lda FROMH
  1208. sta FROMSAV+1
  1209. lda DESTL
  1210. sta DESTSAV
  1211. sta FROML ; FROM = DEST: start of the text to copy to the buffer
  1212. lda DESTH
  1213. sta DESTSAV+1
  1214. sta FROMH
  1215. sec ; will TPTR + GOBLEN pass BUFEND?
  1216. lda GOBLEN+1
  1217. adc TPTR+1
  1218. cmp BUFEND+1
  1219. bcc DEL3
  1220. jsr TOPCLR ; yes: "Buffer Full"
  1221. lda #<MSG_BUFFULL
  1222. ldy #>MSG_BUFFULL
  1223. jsr PRMSG
  1224. lda #$01
  1225. sta MSGFLG
  1226. lda #$00 ; flush the keyboard buffer
  1227. sta NDX
  1228. rts
  1229. DEL3: lda TPTR ; DEST = TPTR (end of what is in the buffer)
  1230. sta DESTL
  1231. lda TPTR+1
  1232. sta DESTH
  1233. lda GOBLEN ; length = GOBLEN, and TPTR += GOBLEN
  1234. sta LLEN
  1235. clc
  1236. adc TPTR
  1237. sta TPTR
  1238. lda GOBLEN+1
  1239. sta HLEN
  1240. adc TPTR+1
  1241. sta TPTR+1
  1242. lda #$00 ; stop raster IRQs while I/O is banked out
  1243. sta VIC_IMR
  1244. lda #$34 ; $34: all RAM (buffer is under I/O/KERNAL)
  1245. sta R6510
  1246. jsr UMOVE ; copy deleted text into the buffer
  1247. lda #$36 ; back to normal banking
  1248. sta R6510
  1249. lda #$01 ; raster IRQ on again
  1250. sta VIC_IMR
  1251. lda FROMSAV ; FROM = old CURR (end), DEST = new CURR (start)
  1252. sta FROML
  1253. lda FROMSAV+1
  1254. sta FROMH
  1255. lda DESTSAV
  1256. sta DESTL
  1257. lda DESTSAV+1
  1258. sta DESTH
  1259. sec ; length = LASTLINE - DEST
  1260. lda LASTLINE
  1261. sbc DESTL
  1262. sta LLEN
  1263. lda LASTLINE+1
  1264. sbc DESTH
  1265. sta HLEN
  1266. jsr UMOVE ; close the gap
  1267. sec ; LASTLINE -= GOBLEN
  1268. lda LASTLINE
  1269. sbc GOBLEN
  1270. sta LASTLINE
  1271. lda LASTLINE+1
  1272. sbc GOBLEN+1
  1273. sta LASTLINE+1
  1274. rts
  1275. ; BACKSPACE - DEL key: delete the character left of the cursor. It goes
  1276. ; through the buffer machinery, but TPTR is then backed up one byte so
  1277. ; single deleted characters do not accumulate in the buffer.
  1278. BACKSPACE:
  1279. jsr DELSETUP
  1280. jsr LEFT
  1281. jsr DEL1
  1282. TPTRDEC:
  1283. sec ; TPTRDEC: forget the last byte put in the buffer
  1284. lda TPTR
  1285. sbc #$01
  1286. sta TPTR
  1287. lda TPTR+1
  1288. sbc #$00
  1289. sta TPTR+1
  1290. rts
  1291. ; DELFWD - CTRL-F: delete the character under the cursor (move right, then
  1292. ; delete left). SHIFT+CTRL-F instead deletes the run of spaces at the
  1293. ; cursor (DELSPACES).
  1294. DELFWD: lda SHFLAG ; SHIFT and CTRL both held (1+4)?
  1295. cmp #$05
  1296. bne DELFWD1
  1297. jmp DELSPACES
  1298. DELFWD1:
  1299. jsr RIGHT
  1300. jsr DELSETUP
  1301. jsr LEFT
  1302. jsr DEL1
  1303. jmp TPTRDEC
  1304. ; ===========================================================================
  1305. ; DELETE - CTRL-D: "Delete (S,W,P)" - delete the previous Sentence, Word
  1306. ; or Paragraph into the (first emptied) buffer
  1307. ; ===========================================================================
  1308. DELETE: jsr KILLBUFF ; start with an empty buffer
  1309. lda #$02 ; command line red
  1310. sta WINDCOLR
  1311. jsr TOPCLR
  1312. lda #<MSG_DELETE
  1313. ldy #>MSG_DELETE
  1314. jsr PRMSG
  1315. jsr GETAKEY
  1316. pha
  1317. jsr SYSMSG
  1318. pla
  1319. and #$BF ; clear bit 6: S/W/P -> $13/$17/$10
  1320. cmp #$17 ; W: word
  1321. bne DEL_NOTW
  1322. jsr DELSETUP
  1323. jsr WLEFT
  1324. jmp DEL1
  1325. DEL_NOTW:
  1326. cmp #$13 ; S: sentence
  1327. bne DEL_NOTS
  1328. jsr DELSETUP
  1329. jsr SLEFT
  1330. jmp DEL1
  1331. DEL_NOTS:
  1332. cmp #$10 ; P: paragraph
  1333. bne DEL_EXIT
  1334. jsr DELSETUP
  1335. jsr PARLEFT
  1336. jmp DEL1
  1337. DEL_EXIT:
  1338. rts
  1339. ; HOME - first press: cursor to the top of the screen; if it is already
  1340. ; there, go to the top of the text.
  1341. HOME: sec
  1342. lda CURR
  1343. sbc TOPLIN
  1344. sta TEMP
  1345. lda CURR+1
  1346. sbc TOPLIN+1
  1347. ora TEMP
  1348. beq HOME_TOP
  1349. lda TOPLIN
  1350. sta CURR
  1351. lda TOPLIN+1
  1352. sta CURR+1
  1353. rts
  1354. HOME_TOP:
  1355. lda TEXSTART
  1356. sta CURR
  1357. lda TEXSTART+1
  1358. sta CURR+1
  1359. jmp CHECK
  1360. ; DELSPACES - SHIFT-CTRL-F: remove all spaces from the cursor forward up to
  1361. ; the next non-space (not copied to the buffer).
  1362. DELSPACES:
  1363. lda CURR
  1364. sta TEX
  1365. sta DESTL
  1366. lda CURR+1
  1367. sta TEX+1
  1368. sta DESTH
  1369. ldy #$00
  1370. DS_SCAN:
  1371. lda (TEX),y ; scan forward while spaces
  1372. cmp #$20
  1373. bne DS_FOUND
  1374. iny
  1375. bne DS_SCAN
  1376. lda TEX+1 ; next page, unless past the end of the text
  1377. cmp LASTLINE+1
  1378. bcc DS_NEXTPG
  1379. lda LASTLINE
  1380. sta TEX
  1381. lda LASTLINE+1
  1382. sta TEX+1
  1383. ldy #$00
  1384. jmp DS_FOUND
  1385. DS_NEXTPG:
  1386. inc TEX+1
  1387. jmp DS_SCAN
  1388. DS_FOUND:
  1389. clc ; FROM = first non-space
  1390. tya
  1391. adc TEX
  1392. sta FROML
  1393. lda #$00
  1394. adc TEX+1
  1395. sta FROMH
  1396. sec ; length = LASTLINE - CURR
  1397. lda LASTLINE
  1398. sbc DESTL
  1399. sta LLEN
  1400. lda LASTLINE+1
  1401. sbc DESTH
  1402. sta HLEN
  1403. sec ; GOBLEN = number of spaces removed
  1404. lda FROML
  1405. sbc DESTL
  1406. sta GOBLEN
  1407. lda FROMH
  1408. sbc DESTH
  1409. sta GOBLEN+1
  1410. jsr UMOVE ; slide the text down over the spaces
  1411. sec ; LASTLINE -= GOBLEN
  1412. lda LASTLINE
  1413. sbc GOBLEN
  1414. sta LASTLINE
  1415. lda LASTLINE+1
  1416. sbc GOBLEN+1
  1417. sta LASTLINE+1
  1418. rts
  1419. ; INS255 - SHIFT-RUN/STOP: insert 255 spaces.
  1420. ; TAB5 - RUN/STOP: insert 5 spaces and move past them.
  1421. ; INSSPACES - open a gap of INSLEN bytes at the cursor, fill with spaces.
  1422. INS255: lda #$FF
  1423. sta INSLEN
  1424. jmp INSSPACES
  1425. TAB5: lda #$05
  1426. sta INSLEN
  1427. jsr INSSPACES
  1428. lda (CURR),y
  1429. cmp #$20
  1430. bne TAB_DONE
  1431. iny
  1432. TAB_DONE:
  1433. jmp ADDYCURR
  1434. INSSPACES:
  1435. lda #$00
  1436. sta INSLEN+1 ; INSLEN high byte = 0
  1437. jsr INSBLOCK ; open the gap
  1438. lda #$20
  1439. ldx INSLEN
  1440. ldy #$00
  1441. INSS_FILL:
  1442. sta (CURR),y
  1443. iny
  1444. dex
  1445. bne INSS_FILL
  1446. rts
  1447. ; NEWPARA - SHIFT-RETURN: insert two return marks (a blank line) followed
  1448. ; by a 5-space paragraph indent.
  1449. NEWPARA:
  1450. jsr INSCHAR
  1451. jsr INSCHAR
  1452. lda #$1F ; two return marks
  1453. ldy #$00
  1454. sta (CURR),y
  1455. iny
  1456. sta (CURR),y
  1457. jsr REFRESH
  1458. jsr RIGHT
  1459. jsr RIGHT
  1460. jmp TAB5
  1461. ; ===========================================================================
  1462. ; INSCHAR - insert one space at the cursor (INST key, insert mode)
  1463. ; INSBLOCK - open a gap of INSLEN (16-bit) bytes at the cursor by DMOVEing
  1464. ; CURR..LASTLINE up. If the text would pass TEXEND it silently
  1465. ; aborts AND drops the caller's return address (back to MAIN).
  1466. ; ===========================================================================
  1467. INSCHAR:
  1468. lda #$01
  1469. sta INSLEN
  1470. lda #$00
  1471. sta DEVNO
  1472. jsr INSBLOCK
  1473. lda #$20
  1474. ldy #$00
  1475. sta (CURR),y
  1476. jmp CHECK
  1477. INSBLOCK:
  1478. clc ; LASTLINE + INSLEN (high byte) ...
  1479. lda LASTLINE
  1480. adc INSLEN
  1481. lda LASTLINE+1
  1482. adc DEVNO
  1483. cmp TEXEND+1 ; ... reaches TEXEND?
  1484. bcc INSB_OK
  1485. pla ; yes: out of memory - abandon the caller
  1486. pla
  1487. jmp INSB_EXIT
  1488. INSB_OK:
  1489. clc ; FROM = CURR, DEST = CURR + INSLEN
  1490. lda CURR
  1491. sta FROML
  1492. adc INSLEN
  1493. sta DESTL
  1494. lda CURR+1
  1495. sta FROMH
  1496. adc INSLEN+1
  1497. sta DESTH
  1498. sec ; length = LASTLINE - CURR
  1499. lda LASTLINE
  1500. sbc FROML
  1501. sta LLEN
  1502. lda LASTLINE+1
  1503. sbc FROMH
  1504. sta HLEN
  1505. jsr DMOVE ; move the text up (high end first)
  1506. clc ; LASTLINE += INSLEN
  1507. lda LASTLINE
  1508. adc INSLEN
  1509. sta LASTLINE
  1510. lda LASTLINE+1
  1511. adc INSLEN+1
  1512. sta LASTLINE+1
  1513. INSB_EXIT:
  1514. rts
  1515. ; INSTGL - CTRL-I: toggle insert mode (0 <-> $0E; the command line turns
  1516. ; light blue in insert mode)
  1517. INSTGL: lda INSMODE
  1518. eor #$0E
  1519. sta INSMODE
  1520. rts
  1521. ; YORN - print "Are you sure? (Y/N)" and wait for a key. It calls SCNKEY
  1522. ; itself because this is also used from the NMI handler, when the IRQ that
  1523. ; normally scans the keyboard may not be running. Returns Z=1 for "Y".
  1524. YORN: lda #<MSG_SURE
  1525. ldy #>MSG_SURE
  1526. jsr PRMSG
  1527. YORN_WAIT:
  1528. jsr SCNKEY
  1529. jsr GETIN
  1530. beq YORN_WAIT
  1531. cmp #$93 ; ignore CLR (still in the buffer from SHIFT-HOME)
  1532. beq YORN_WAIT
  1533. and #$7F ; remove SHIFT bit
  1534. cmp #$59 ; Z = 1 if "y"/"Y"
  1535. rts
  1536. ; CLEARALL - SHIFT-CLR/HOME: "ERASE ALL TEXT" - after Y, wipe the document
  1537. ; and restart the editor.
  1538. CLEARALL:
  1539. lda #$02
  1540. sta WINDCOLR
  1541. jsr TOPCLR
  1542. lda #<MSG_ERASEALL
  1543. ldy #>MSG_ERASEALL
  1544. jsr PRMSG
  1545. jsr YORN
  1546. beq CLEARALL_YES
  1547. jmp SYSMSG
  1548. CLEARALL_YES:
  1549. ldx #$FA ; reset the stack, erase, re-init, main loop
  1550. txs
  1551. jsr ERASE
  1552. jsr INIT3
  1553. jmp MAIN
  1554. ; PARRIGHT - F5: move to just after the next return mark.
  1555. PARRIGHT:
  1556. ldy #$00
  1557. PR_SCAN:
  1558. lda (CURR),y
  1559. cmp #$1F
  1560. beq PR_FOUND
  1561. iny
  1562. bne PR_SCAN
  1563. inc CURR+1
  1564. lda CURR+1
  1565. cmp LASTLINE+1
  1566. bcc PR_SCAN
  1567. beq PR_SCAN
  1568. jmp ENDTEX
  1569. PR_FOUND:
  1570. iny
  1571. bne PR_SET
  1572. inc CURR+1
  1573. PR_SET: jmp ADDYCURR
  1574. ; PARLEFT - F6: move to the start of the paragraph (just after the previous
  1575. ; return mark). If the cursor is already right after one, keep looking
  1576. ; further back.
  1577. PARLEFT:
  1578. lda CURR
  1579. sta TEX
  1580. lda CURR+1
  1581. sta TEX+1
  1582. dec TEX+1
  1583. ldy #$FF
  1584. PL_SCAN:
  1585. lda (TEX),y
  1586. cmp #$1F
  1587. beq PL_FOUND
  1588. PL_NEXT:
  1589. dey
  1590. cpy #$FF
  1591. bne PL_SCAN
  1592. dec TEX+1
  1593. lda TEX+1
  1594. cmp TEXSTART+1
  1595. bcs PL_SCAN
  1596. jmp TOPTEXT
  1597. PL_FOUND:
  1598. sec
  1599. tya
  1600. adc TEX
  1601. sta TEX
  1602. lda #$00
  1603. adc TEX+1
  1604. sta TEX+1
  1605. sec ; did we land where we started?
  1606. lda TEX
  1607. sbc CURR
  1608. sta TEMP
  1609. lda TEX+1
  1610. sbc CURR+1
  1611. ora TEMP
  1612. bne PL_SET
  1613. sty TEMP ; yes: step back past that return mark and keep looking
  1614. clc
  1615. lda TEX
  1616. sbc TEMP
  1617. sta TEX
  1618. lda TEX+1
  1619. sbc #$00
  1620. sta TEX+1
  1621. jmp PL_NEXT
  1622. PL_SET: lda TEX
  1623. sta CURR
  1624. lda TEX+1
  1625. sta CURR+1
  1626. jmp CHECK
  1627. ; ===========================================================================
  1628. ; IRQ_ON - install the split-screen raster interrupt
  1629. ; Stops the CIA1 timer IRQ and uses a VIC raster interrupt instead, so the
  1630. ; command line (row 0) can have a different background colour from the
  1631. ; text area. The keyboard is still scanned once per frame.
  1632. ; ===========================================================================
  1633. IRQ_ON: sei
  1634. lda #$00 ; stop CIA1 timer A (no 60 Hz timer IRQ)
  1635. sta CIA1_CRA
  1636. lda #$1B ; screen on, 25 rows, raster bit 8 = 0
  1637. sta VIC_CR1
  1638. lda #<IRQ_HANDLER ; IRQ vector -> IRQ_HANDLER
  1639. sta CINV
  1640. lda #>IRQ_HANDLER
  1641. sta CINV+1
  1642. lda #$01 ; enable raster interrupts ...
  1643. sta VIC_IMR
  1644. sta RASTER ; ... first at raster line 1
  1645. cli
  1646. rts
  1647. ; IRQ_HANDLER - runs twice per frame:
  1648. ; raster 1 : background = WINDCOLR (colour of the command line, row 0);
  1649. ; schedule the next IRQ for line 58; exit quickly.
  1650. ; raster 58 : (the bottom of text row 0) background = SCRCOL for the text
  1651. ; area; schedule line 1; then run the normal KERNAL IRQ
  1652. ; (keyboard scan, jiffy clock) - so that still happens once
  1653. ; per frame, replacing the CIA timer IRQ that was stopped.
  1654. IRQ_HANDLER:
  1655. lda #$3A ; line 58 = bottom of the command line
  1656. ldy WINDCOLR ; assume: colour for the command line
  1657. cmp RASTER ; which interrupt is this?
  1658. bne IRQ_SETBG
  1659. lda #$01 ; line 58: next interrupt at line 1 ...
  1660. ldy SCRCOL ; ... and switch to the text-area colour
  1661. IRQ_SETBG:
  1662. sty BGCOL0 ; set the background colour
  1663. sta RASTER ; schedule the next interrupt
  1664. cmp #$01 ; A=1 means this was the line-58 interrupt
  1665. beq IRQ_FULL
  1666. lda #$01 ; acknowledge VIC interrupt
  1667. sta VIC_IRR
  1668. jmp IRQ_EXIT ; line-1 interrupt: quick exit (pull regs, RTI)
  1669. IRQ_FULL:
  1670. lda #$01 ; acknowledge VIC interrupt
  1671. sta VIC_IRR
  1672. jmp IRQ_NORMAL ; line-58 interrupt: full KERNAL IRQ (scan keys, clock)
  1673. ; ===========================================================================
  1674. ; ERAS - CTRL-E: "Erase (S,W,P): RETURN to exit"
  1675. ; Repeatedly erases the next Sentence, Word or Paragraph FORWARD from the
  1676. ; cursor, copying it to the buffer. CTRL-E clears the buffer first;
  1677. ; SHIFT-CTRL-E keeps it and appends. Any other key exits.
  1678. ; ===========================================================================
  1679. ERAS: lda SHFLAG ; SHIFT held?
  1680. and #$01
  1681. bne ERAS_PROMPT ; yes: keep (append to) the buffer
  1682. jsr KILLBUFF
  1683. ERAS_PROMPT:
  1684. jsr TOPCLR
  1685. lda #<MSG_ERASE
  1686. ldy #>MSG_ERASE
  1687. jsr PRMSG
  1688. ERAS_LOOP:
  1689. ldy #$00 ; show the cursor (reverse) while we wait
  1690. lda (CURR),y
  1691. eor #$80
  1692. sta (CURR),y
  1693. jsr REFRESH
  1694. ldy #$00 ; then un-reverse it in memory
  1695. lda (CURR),y
  1696. eor #$80
  1697. sta (CURR),y
  1698. lda #$02
  1699. sta WINDCOLR
  1700. jsr GETAKEY
  1701. ora #$40 ; fold to upper/lower-insensitive: w/s/p
  1702. cmp #$57 ; W: word
  1703. bne ERAS_NOTW
  1704. jsr ERAS_MARK
  1705. jsr WRIGHT
  1706. jmp ERAS_DO
  1707. ERAS_NOTW:
  1708. cmp #$53 ; S: sentence
  1709. bne ERAS_NOTS
  1710. jsr ERAS_MARK
  1711. jsr SRIGHT
  1712. jmp ERAS_DO
  1713. ERAS_NOTS:
  1714. cmp #$50 ; P: paragraph
  1715. bne ERAS_EXIT
  1716. jsr ERAS_MARK
  1717. jsr PARRIGHT
  1718. jmp ERAS_DO
  1719. ERAS_EXIT:
  1720. jsr CHECK ; other key: exit
  1721. jmp SYSMSG
  1722. ERAS_MARK:
  1723. lda CURR ; ERAS_MARK: remember the start (SAVCURR and DEST)
  1724. sta DESTL
  1725. sta SAVCURR
  1726. lda CURR+1
  1727. sta DESTH
  1728. sta SAVCURR+1
  1729. rts
  1730. ERAS_DO:
  1731. sec ; ERAS_DO: FROM = new CURR (end); GOBLEN = CURR - SAVCURR
  1732. lda CURR
  1733. sta FROML
  1734. sbc SAVCURR
  1735. sta GOBLEN
  1736. lda CURR+1
  1737. sta FROMH
  1738. sbc SAVCURR+1
  1739. sta GOBLEN+1
  1740. jsr DEL2 ; copy to buffer and close the gap
  1741. lda SAVCURR ; cursor back to where the erase started
  1742. sta CURR
  1743. lda SAVCURR+1
  1744. sta CURR+1
  1745. jsr REFRESH
  1746. jmp ERAS_LOOP
  1747. ; ===========================================================================
  1748. ; INPUT - read a line from the keyboard on the command line
  1749. ; Draws its own reverse-space cursor in light green, accepts DEL, ignores
  1750. ; other control keys, stops at LIMIT (to the end of the 40-column line).
  1751. ; The text goes to INBUFF (0-terminated), its length to INLEN and A
  1752. ; (Z=1 if nothing was typed).
  1753. ; Note: GETAKEY uses GETIN, so if a CHKIN is active this reads from that
  1754. ; file instead of the keyboard - READERR uses that to read the disk
  1755. ; error channel.
  1756. ; ===========================================================================
  1757. INPUT: lda #$27 ; LIMIT = 39 - cursor column (carry assumed set)
  1758. sbc PNTR
  1759. sta LIMIT
  1760. ldy #$00
  1761. INP_LOOP:
  1762. lda #$99 ; light green, RVS ON, space, CRSR left: draw cursor
  1763. jsr CHROUT
  1764. lda #$12
  1765. jsr CHROUT
  1766. lda #$20
  1767. jsr CHROUT
  1768. lda #$9D
  1769. jsr CHROUT
  1770. sty INLEN ; save Y (GETIN clobbers it)
  1771. jsr GETAKEY
  1772. ldy INLEN
  1773. sta TEMP
  1774. lda #$92 ; RVS OFF, space, CRSR left: erase cursor
  1775. jsr CHROUT
  1776. lda #$20
  1777. jsr CHROUT
  1778. lda #$9D
  1779. jsr CHROUT
  1780. lda #$9B ; back to light grey
  1781. jsr CHROUT
  1782. lda TEMP
  1783. cmp #$0D ; RETURN ends input
  1784. beq INP_DONE
  1785. cmp #$14 ; DEL?
  1786. bne INP_CHAR
  1787. dey ; back up one character, if there is one
  1788. bpl INP_BACK
  1789. iny
  1790. jmp INP_LOOP
  1791. INP_BACK:
  1792. lda #$9D
  1793. jsr CHROUT
  1794. jmp INP_LOOP
  1795. INP_CHAR:
  1796. lda TEMP
  1797. and #$7F ; ignore other control characters
  1798. cmp #$20
  1799. bcc INP_LOOP
  1800. cpy LIMIT ; line full?
  1801. beq INP_LOOP
  1802. lda TEMP ; store and echo the character
  1803. sta INBUFF,y
  1804. jsr CHROUT
  1805. lda #$00 ; cancel quote mode and pending inserts so
  1806. sta QTSW
  1807. sta INSRT ; further control keys are not printed literally
  1808. iny
  1809. jmp INP_LOOP
  1810. INP_DONE:
  1811. jsr CHROUT ; print the RETURN
  1812. lda #$00
  1813. sta INBUFF,y ; terminate the string
  1814. tya ; A = length
  1815. rts
  1816. ; ===========================================================================
  1817. ; SAVE - F8: "Save:" filename, Tape or Disk, then save TEXSTART..LASTLINE
  1818. ; ===========================================================================
  1819. SAVE: jsr TOPCLR
  1820. lda #<MSG_SAVE
  1821. ldy #>MSG_SAVE
  1822. jsr PRMSG
  1823. jsr TOPEN ; get filename + device; returns to MAIN if cancelled
  1824. bcs IOERROR
  1825. lda TEXSTART ; TEX = start address
  1826. sta TEX
  1827. lda TEXSTART+1
  1828. sta TEX+1
  1829. ldx LASTLINE ; X/Y = end address
  1830. ldy LASTLINE+1
  1831. lda #<TEX ; A = zero-page address of the start pointer
  1832. jsr SAVE_K
  1833. bcs IOERROR
  1834. lda STATUS ; ST, ignoring EOI
  1835. and #$BF
  1836. bne IOERROR
  1837. jmp NOERRS
  1838. ; IOERROR - LOAD/SAVE/VERIFY failed. A=0 means STOP was pressed. For disk
  1839. ; (device >= 8) read and show the drive's error channel.
  1840. ; NOTE: for tape (IODEV = 1) the code at TAPEERR_HANG loops forever - it
  1841. ; looks like a bug; the "Tape ERROR" message after it can never be reached.
  1842. IOERROR:
  1843. beq STOPPED ; A=0: stopped by the user
  1844. lda IODEV ; disk?
  1845. cmp #$08
  1846. bcc TAPEERR_HANG
  1847. jsr READERR ; show the disk drive error message
  1848. jmp ENDIO
  1849. TAPEERR_HANG:
  1850. lda IODEV ; tape: IODEV is 1, so this spins forever (!)
  1851. cmp #$01
  1852. beq TAPEERR_HANG
  1853. jsr TOPCLR
  1854. lda #<MSG_TAPEERR
  1855. ldy #>MSG_TAPEERR
  1856. jsr PRMSG
  1857. ENDIO: jsr IRQ_ON ; ENDIO: back to the raster IRQ, leave the message showing
  1858. lda #$01
  1859. sta MSGFLG
  1860. rts
  1861. STOPPED:
  1862. jsr TOPCLR
  1863. lda #<MSG_STOPPED
  1864. ldy #>MSG_STOPPED
  1865. jsr PRMSG
  1866. jmp ENDIO
  1867. IODEV: .byte $00 ; IODEV: device for load/save/verify (1 = tape, 8 = disk)
  1868. ; ===========================================================================
  1869. ; TOPEN - get a filename and "Tape or Disk?", then SETLFS / SETNAM
  1870. ; If nothing is entered or the answer is neither T nor D, it drops the
  1871. ; caller's return address and returns to MAIN. For disk, unless the name
  1872. ; already has a drive prefix ("0:name" / "s0:name"), "0:" is prepended.
  1873. ; Finishes by restoring the normal IRQ (tape and serial bus timing need
  1874. ; the CIA timer, and the raster IRQ must not run during I/O).
  1875. ; ===========================================================================
  1876. TOPEN: jsr INPUT ; read the filename
  1877. beq TOPEN_ABORT ; empty: cancel
  1878. lda #<MSG_TAPEDISK ; "Tape or Disk?"
  1879. ldy #>MSG_TAPEDISK
  1880. jsr PRMSG
  1881. jsr GETAKEY
  1882. ldx #$08 ; D -> device 8
  1883. cmp #$44
  1884. beq TOPEN_DEV
  1885. ldx #$01 ; T -> device 1
  1886. cmp #$54
  1887. beq TOPEN_DEV
  1888. TOPEN_ABORT:
  1889. jsr SYSMSG ; anything else: restore title and
  1890. pla ; return to MAIN (skip the caller)
  1891. pla
  1892. rts
  1893. TOPEN_DEV:
  1894. stx IODEV
  1895. lda #$01 ; logical file 1, secondary address 0
  1896. ldy #$00
  1897. jsr SETLFS
  1898. ldy #$00
  1899. cpx #$01 ; tape: use the name as typed
  1900. beq TOPEN_COPY
  1901. lda INBUFF,y ; leftover of a test for "@" (save-with-replace);
  1902. cmp #$40
  1903. nop ; the branch has been NOPed out
  1904. nop
  1905. lda INBUFF+1,y ; drive prefix already given ("x:" or "xx:")?
  1906. cmp #$3A
  1907. beq TOPEN_COPY
  1908. lda INBUFF+2,y
  1909. cmp #$3A
  1910. beq TOPEN_COPY
  1911. lda #$30 ; no: build "0:" + name
  1912. sta FILENAME
  1913. lda #$3A
  1914. sta FILENAME+1
  1915. TOPEN_ADD0:
  1916. lda INBUFF,y ; copy name after the "0:"
  1917. sta FILENAME+2,y
  1918. iny
  1919. cpy INLEN
  1920. bcc TOPEN_ADD0
  1921. beq TOPEN_ADD0
  1922. iny
  1923. jmp TOPEN_NAME
  1924. TOPEN_COPY:
  1925. lda INBUFF,y ; copy the name unchanged
  1926. sta FILENAME,y
  1927. iny
  1928. cpy INLEN
  1929. bne TOPEN_COPY
  1930. TOPEN_NAME:
  1931. sty FNLEN ; FNLEN = length
  1932. jsr TOPCLR
  1933. lda #<INBUFF ; show the filename on the command line
  1934. ldy #>INBUFF
  1935. jsr PRMSG
  1936. lda FNLEN ; SETNAM(FNLEN, FILENAME)
  1937. ldx #<FILENAME
  1938. ldy #>FILENAME
  1939. jsr SETNAM
  1940. lda #$0D
  1941. jsr CHROUT
  1942. jmp IRQ_OFF ; normal IRQ for the I/O to come
  1943. ; FORMAT - CTRL-pound: "Press format key:" - the next key is stored in the
  1944. ; text as a REVERSE character, which the print routine treats as a
  1945. ; formatting command.
  1946. FORMAT: jsr TOPCLR
  1947. lda #<MSG_FORMAT
  1948. ldy #>MSG_FORMAT
  1949. jsr PRMSG
  1950. jsr GETAKEY
  1951. jsr ASTOIN ; to screen code
  1952. ora #$80 ; set reverse bit = format command
  1953. pha
  1954. lda INSMODE
  1955. beq FORMAT_PUT
  1956. jsr INSCHAR
  1957. FORMAT_PUT:
  1958. jsr SYSMSG
  1959. pla
  1960. jmp PUTCHR
  1961. ; ===========================================================================
  1962. ; LOAD - F7: "Load:" filename, Tape or Disk
  1963. ; If the cursor is at the start of the text, the old text is erased and
  1964. ; the file loaded at TEXSTART. If the cursor is anywhere else, the
  1965. ; command line turns green and the file is loaded AT THE CURSOR,
  1966. ; replacing what follows (a merge/append).
  1967. ; ===========================================================================
  1968. LOAD: sec ; cursor at TEXSTART?
  1969. lda CURR
  1970. sbc TEXSTART
  1971. sta TEMP
  1972. lda CURR+1
  1973. sbc TEXSTART+1
  1974. ora TEMP
  1975. beq LOAD_ASK
  1976. lda #$05 ; no: green command line = load at cursor
  1977. sta WINDCOLR
  1978. LOAD_ASK:
  1979. jsr TOPCLR
  1980. lda #<MSG_LOAD
  1981. ldy #>MSG_LOAD
  1982. jsr PRMSG
  1983. jsr TOPEN
  1984. lda WINDCOLR ; normal load (not green)?
  1985. cmp #$05
  1986. beq LOAD_GO
  1987. jsr ERASE ; yes: erase old text (CURR = TEXSTART)
  1988. LOAD_GO:
  1989. lda #$00 ; A=0: LOAD, to address X/Y (secondary address 0)
  1990. ldx CURR
  1991. ldy CURR+1
  1992. jsr LOAD_K
  1993. bcc LOAD_OK
  1994. jmp IOERROR
  1995. LOAD_OK:
  1996. stx LASTLINE ; LASTLINE = end address of the loaded data
  1997. sty LASTLINE+1
  1998. NOERRS: jsr CLALL ; NOERRS: close files, "No errors"
  1999. jsr TOPCLR
  2000. lda #<MSG_NOERR
  2001. ldy #>MSG_NOERR
  2002. jsr PRMSG
  2003. jmp ENDIO
  2004. ; VERIFY - CTRL-V: compare a file with the text in memory.
  2005. VERIFY: jsr TOPCLR
  2006. lda #<MSG_VERIFY
  2007. ldy #>MSG_VERIFY
  2008. jsr PRMSG
  2009. jsr TOPEN
  2010. lda #$01 ; A=1: VERIFY at TEXSTART
  2011. ldx TEXSTART
  2012. ldy TEXSTART+1
  2013. jsr LOAD_K
  2014. lda STATUS
  2015. and #$BF
  2016. beq NOERRS
  2017. jsr TOPCLR
  2018. lda #<MSG_VERERR
  2019. ldy #>MSG_VERERR
  2020. jsr PRMSG
  2021. jmp ENDIO
  2022. ; IRQ_OFF - restore the standard KERNAL IRQ (CIA timer), black border and
  2023. ; background, raster interrupts off.
  2024. IRQ_OFF:
  2025. sei
  2026. lda #$00
  2027. sta VIC_IMR
  2028. sta EXTCOL
  2029. sta BGCOL0
  2030. lda #<IRQ_NORMAL
  2031. sta CINV
  2032. lda #>IRQ_NORMAL
  2033. sta CINV+1
  2034. lda #$01
  2035. sta CIA1_CRA
  2036. cli
  2037. rts
  2038. ; ===========================================================================
  2039. ; CATALOG - CTRL-4: show the disk directory, then "Press RETURN"
  2040. ; ===========================================================================
  2041. CATALOG:
  2042. lda #$93
  2043. jsr CHROUT
  2044. lda #$0D
  2045. jsr CHROUT
  2046. jsr IRQ_OFF
  2047. jsr DIRECTORY
  2048. lda #$0D
  2049. jsr CHROUT
  2050. lda #<MSG_RETURN
  2051. ldy #>MSG_RETURN
  2052. jsr PRMSG
  2053. CAT_WAIT:
  2054. jsr GETIN ; wait for RETURN
  2055. cmp #$0D
  2056. bne CAT_WAIT
  2057. jsr IRQ_ON
  2058. jmp SYSMSG
  2059. ; DCLOSE - restore channels and close file 1.
  2060. DCLOSE: jsr CLRCHN
  2061. lda #$01
  2062. jsr CLOSE
  2063. rts
  2064. ; DIRECTORY - read "$" from drive 8 as a BASIC program and list it:
  2065. ; skip the 2-byte load address; for each "line" read the 2-byte link
  2066. ; (0 = end), the 2-byte block count (printed with LINPRT), then the text
  2067. ; up to the 0 terminator. Holding SPACE pauses the listing.
  2068. DIRECTORY:
  2069. jsr CLALL
  2070. lda #$01
  2071. ldx #$08
  2072. ldy #$00
  2073. jsr SETLFS
  2074. lda #$01 ; filename "$" (first byte of the "$No Room" string)
  2075. ldx #<DIRNAME
  2076. ldy #>DIRNAME
  2077. jsr SETNAM
  2078. jsr OPEN
  2079. bcs DCLOSE
  2080. ldx #$01
  2081. jsr CHKIN
  2082. jsr DCHRIN ; skip load address
  2083. jsr DCHRIN
  2084. DIR_LINE:
  2085. jsr DCHRIN ; link address: high byte 0 = end of listing
  2086. jsr DCHRIN
  2087. beq DCLOSE
  2088. jsr CLRCHN
  2089. jsr GETIN ; SPACE pressed? then wait for another key
  2090. cmp #$20
  2091. bne DIR_BLOCKS
  2092. jsr GETAKEY
  2093. DIR_BLOCKS:
  2094. ldx #$01
  2095. jsr CHKIN
  2096. jsr DCHRIN ; block count low/high
  2097. pha
  2098. jsr DCHRIN
  2099. tay
  2100. pla
  2101. tax
  2102. tya
  2103. ldy #$37 ; bank BASIC ROM in to call LINPRT
  2104. sty R6510
  2105. jsr LINPRT
  2106. ldy #$36
  2107. sty R6510
  2108. lda #$20
  2109. jsr CHROUT
  2110. DIR_NAME:
  2111. jsr DCHRIN ; print the rest of the line
  2112. beq DIR_EOL
  2113. jsr CHROUT
  2114. jmp DIR_NAME
  2115. DIR_EOL:
  2116. lda #$0D
  2117. jsr CHROUT
  2118. jmp DIR_LINE
  2119. ; DCHRIN - CHRIN with error check: on any status (other than EOI) it throws
  2120. ; away its own return address and its caller's, closes the file and so
  2121. ; returns from DIRECTORY entirely.
  2122. DCHRIN: jsr CHRIN
  2123. pha
  2124. lda STATUS
  2125. and #$BF
  2126. beq DCHRIN_OK
  2127. pla
  2128. pla
  2129. pla
  2130. jmp DCLOSE
  2131. DCHRIN_OK:
  2132. pla
  2133. rts
  2134. ; ===========================================================================
  2135. ; ASCHEX - convert a decimal number in the text at (TEX),Y to binary
  2136. ; Step 1: pack the digits as BCD into BCD/BCD+1 (shift left 4, OR digit).
  2137. ; Step 2: in DECIMAL mode count BCD down to zero while counting HEX up in
  2138. ; binary - a tiny but slow BCD->binary conversion.
  2139. ; Returns the low byte in A, the full 16-bit result in HEX/HEX+1, and Y
  2140. ; pointing past the digits.
  2141. ; ===========================================================================
  2142. ASCHEX: ldx #$00
  2143. stx BCD
  2144. stx BCD+1
  2145. stx HEX
  2146. stx HEX+1
  2147. AH_DIGIT:
  2148. sec
  2149. lda (TEX),y ; digit?
  2150. sbc #$30
  2151. bcc AH_TOBIN
  2152. cmp #$0A
  2153. bcs AH_TOBIN
  2154. asl BCD ; BCD <<= 4
  2155. rol BCD+1
  2156. asl BCD
  2157. rol BCD+1
  2158. asl BCD
  2159. rol BCD+1
  2160. asl BCD
  2161. rol BCD+1
  2162. ora BCD ; add the new digit
  2163. sta BCD
  2164. iny
  2165. bne AH_DIGIT
  2166. inc TEX+1
  2167. jmp AH_DIGIT
  2168. AH_TOBIN:
  2169. sed ; decimal mode for the countdown
  2170. AH_COUNT:
  2171. lda BCD
  2172. ora BCD+1
  2173. beq AH_DONE
  2174. sec ; BCD -= 1 (in decimal)
  2175. lda BCD
  2176. sbc #$01
  2177. sta BCD
  2178. lda BCD+1
  2179. sbc #$00
  2180. sta BCD+1
  2181. inc HEX ; HEX += 1 (INC is binary even in decimal mode)
  2182. bne AH_NEXT
  2183. inc HEX+1
  2184. AH_NEXT:
  2185. jmp AH_COUNT
  2186. AH_DONE:
  2187. lda HEX
  2188. cld
  2189. rts
  2190. ; ===========================================================================
  2191. ; RETRIEVE - CTRL-R: insert the whole cut/paste buffer at the cursor
  2192. ; ===========================================================================
  2193. RETRIEVE:
  2194. sec ; BUFLEN = TPTR - TEXBUF
  2195. lda TPTR
  2196. sbc TEXBUF
  2197. sta BUFLEN
  2198. lda TPTR+1
  2199. sbc TEXBUF+1
  2200. sta BUFLEN+1
  2201. ora BUFLEN
  2202. bne RET_MAKEROOM
  2203. jsr TOPCLR ; empty: "No text in buffer."
  2204. lda #<MSG_NOTEXT
  2205. ldy #>MSG_NOTEXT
  2206. jsr PRMSG
  2207. lda #$01
  2208. sta MSGFLG
  2209. rts
  2210. RET_MAKEROOM:
  2211. clc ; FROM = CURR, DEST = CURR + BUFLEN
  2212. lda CURR
  2213. sta FROML
  2214. adc BUFLEN
  2215. sta DESTL
  2216. lda CURR+1
  2217. sta FROMH
  2218. adc BUFLEN+1
  2219. sta DESTH
  2220. sec ; length = LASTLINE - CURR
  2221. lda LASTLINE
  2222. sbc FROML
  2223. sta LLEN
  2224. lda LASTLINE+1
  2225. sbc FROMH
  2226. sta HLEN
  2227. clc ; would the end pass TEXEND?
  2228. adc DESTH
  2229. cmp TEXEND+1
  2230. bcc RET_COPY
  2231. jsr TOPCLR ; yes: "No Room" (skips the "$" of the string)
  2232. lda #<MSG_NOROOM
  2233. ldy #>MSG_NOROOM
  2234. jsr PRMSG
  2235. lda #$01
  2236. sta MSGFLG
  2237. rts
  2238. RET_COPY:
  2239. jsr DMOVE ; open the gap
  2240. clc ; LASTLINE += BUFLEN; length = BUFLEN
  2241. lda BUFLEN
  2242. sta LLEN
  2243. adc LASTLINE
  2244. sta LASTLINE
  2245. lda BUFLEN+1
  2246. sta HLEN
  2247. adc LASTLINE+1
  2248. sta LASTLINE+1
  2249. lda CURR ; DEST = CURR, FROM = TEXBUF
  2250. sta DESTL
  2251. lda CURR+1
  2252. sta DESTH
  2253. lda TEXBUF
  2254. sta FROML
  2255. lda TEXBUF+1
  2256. sta FROMH
  2257. lda #$00 ; all-RAM banking and copy the buffer in
  2258. sta VIC_IMR
  2259. lda #$34
  2260. sta R6510
  2261. jsr UMOVE
  2262. lda #$36
  2263. sta R6510
  2264. lda #$01
  2265. sta VIC_IMR
  2266. jmp CHECK
  2267. ; TRANSPOSE - CTRL-X: swap the character under the cursor with the next one.
  2268. ; CASECHG - CTRL-A: flip upper/lower case of a letter, move right.
  2269. TRANSPOSE:
  2270. ldy #$00
  2271. lda (CURR),y
  2272. tax
  2273. iny
  2274. lda (CURR),y
  2275. dey
  2276. sta (CURR),y
  2277. iny
  2278. txa
  2279. sta (CURR),y
  2280. rts
  2281. CASECHG:
  2282. ldy #$00
  2283. lda (CURR),y
  2284. and #$3F ; letter? (screen codes 1-26 in either case)
  2285. beq CASE_DONE
  2286. cmp #$1B
  2287. bcs CASE_DONE
  2288. lda (CURR),y
  2289. eor #$40 ; bit 6 is the case bit in screen codes
  2290. sta (CURR),y
  2291. CASE_DONE:
  2292. jmp RIGHT
  2293. ; INTOAS - convert a screen code to PETSCII (inverse of ASTOIN).
  2294. ; bit 6 of the screen code -> bit 7; bit 5 = 0 (letters/@[]) -> set bit 6.
  2295. ; Result also left in TEMP.
  2296. INTOAS: sta TEMP
  2297. and #$3F
  2298. asl TEMP ; N = old bit 6, V = old bit 5
  2299. bit TEMP
  2300. bpl INTOAS_B5 ; old bit 6 set: shifted/upper-case -> add $80
  2301. ora #$80
  2302. INTOAS_B5:
  2303. bvs INTOAS_DONE ; old bit 5 clear: $00-$1F/$40-$5F range -> add $40
  2304. ora #$40
  2305. INTOAS_DONE:
  2306. sta TEMP
  2307. rts
  2308. ; DEFTAB - default print settings copied to LMARGIN..PAGEWIDTH by PRINIT,
  2309. ; DEFCODES - default printer key definitions for reverse 1,2,3,4.
  2310. DEFTAB: .byte $05 ; left margin 5
  2311. .byte $4B ; right margin 75
  2312. .byte $42 ; page length 66 lines (11 inches at 6 lpi)
  2313. .byte $05 ; top margin 5
  2314. .byte $3A ; bottom margin 58
  2315. .byte $01 ; single spacing
  2316. .byte $01 ; continuous paper (no wait)
  2317. .byte $01 ; page number 1 (lo)
  2318. .byte $00 ; (hi)
  2319. .byte $01 ; start printing at page 1 (lo)
  2320. .byte $00 ; (hi)
  2321. DEF_PAGEWIDTH:
  2322. .byte $50 ; page width 80
  2323. DEFCODES:
  2324. .byte $1B ; key "1" = 27 (ESC)
  2325. .byte $0E ; key "2" = 14
  2326. .byte $0F ; key "3" = 15
  2327. .byte $12 ; key "4" = 18
  2328. ; ===========================================================================
  2329. ; PCHAR - send one character to the print device
  2330. ; Characters are only output once PAGENUM >= STARTNUM (the "?" command).
  2331. ; Holding SHIFT pauses output (the border shows the shift state).
  2332. ; Pressing STOP aborts the whole print job.
  2333. ; ===========================================================================
  2334. PCHAR: sta PCHR
  2335. txa
  2336. pha
  2337. tya
  2338. pha
  2339. sec ; PAGENUM < STARTNUM ? then swallow the character
  2340. lda PAGENUM
  2341. sbc STARTNUM
  2342. lda PAGENUM+1
  2343. sbc STARTNUM+1
  2344. bcc PCHAR_EXIT
  2345. lda PCHR
  2346. jsr CHROUT
  2347. SHIFTPAUSE:
  2348. lda SHFLAG ; while SHIFT is held: pause (border turns white)
  2349. and #$01
  2350. sta EXTCOL
  2351. bne SHIFTPAUSE
  2352. lda STKEY ; STOP key?
  2353. cmp #$7F
  2354. bne PCHAR_EXIT
  2355. inc EXTCOL ; aborting: change border, end line, finish up
  2356. jsr CR
  2357. jmp PREND
  2358. PCHAR_EXIT:
  2359. pla
  2360. tay
  2361. pla
  2362. tax
  2363. lda PCHR
  2364. rts
  2365. ; PRINTINGMSG - clear the screen line and show "Printing...".
  2366. PRINTINGMSG:
  2367. jsr TOPCLR
  2368. lda #<MSG_PRINTING
  2369. ldy #>MSG_PRINTING
  2370. jmp PRMSG
  2371. ; PEXIT - abandon printing.
  2372. PEXIT: jmp PREND
  2373. ; ===========================================================================
  2374. ; PRINT - CTRL-P: print the document
  2375. ; CTRL-P alone prints to device 4, secondary address 7 (lower case on
  2376. ; Commodore printers). SHIFT-CTRL-P asks "Print to: Screen, Disk,
  2377. ; Printer?": S = device 3, D = asks for a filename and writes a ",W"
  2378. ; file on device 8, P = asks for the device number (4-9) and, for a
  2379. ; printer (4-7), a secondary address.
  2380. ; ===========================================================================
  2381. PRINT: lda SCRCOL ; remember the screen colour, go black while printing
  2382. sta SAVCOL
  2383. lda #$00
  2384. sta WINDCOLR
  2385. sta EXTCOL
  2386. sta SCRCOL
  2387. jsr SETNAM ; no filename (A=0)
  2388. lda #$04 ; default: device 4 ...
  2389. sta DEVNO
  2390. ldy #$07 ; ... secondary address 7
  2391. lda SHFLAG ; SHIFT held?
  2392. and #$01
  2393. bne PRMENU
  2394. jmp PROPEN
  2395. PRMENU: jsr TOPCLR
  2396. lda #<MSG_PRINTTO
  2397. ldy #>MSG_PRINTTO
  2398. jsr PRMSG
  2399. jsr GETAKEY
  2400. and #$7F
  2401. ldx #$03 ; S: screen = device 3
  2402. stx DEVNO
  2403. cmp #$53
  2404. beq PRSECADDR
  2405. ldx #$08 ; D: disk = device 8
  2406. stx DEVNO
  2407. cmp #$44
  2408. beq PRDISK
  2409. cmp #$50 ; P: printer, ask the device number
  2410. bne PEXIT
  2411. jsr TOPCLR
  2412. lda #<MSG_DEVNUM
  2413. ldy #>MSG_DEVNUM
  2414. jsr PRMSG
  2415. jsr GETAKEY
  2416. sec ; digit -> number
  2417. sbc #$30
  2418. cmp #$04
  2419. bcc PEXIT
  2420. cmp #$50
  2421. bcs PEXIT
  2422. sta DEVNO
  2423. jmp PRSECADDR
  2424. PRDISK: jsr TOPCLR ; disk: ask for a filename
  2425. lda #<MSG_PRFILE
  2426. ldy #>MSG_PRFILE
  2427. jsr PRMSG
  2428. jsr INPUT
  2429. beq PEXIT
  2430. ldy INLEN ; append ",W" (open a SEQ file for writing)
  2431. lda #$2C
  2432. sta INBUFF,y
  2433. iny
  2434. lda #$57
  2435. sta INBUFF,y
  2436. iny
  2437. sty INLEN
  2438. lda INLEN
  2439. ldx #<INBUFF
  2440. ldy #>INBUFF
  2441. jsr SETNAM
  2442. PRSECADDR:
  2443. lda DEVNO ; Y = device; printers 4-7 also need a sec. address
  2444. tay
  2445. cmp #$04
  2446. bcc PROPEN
  2447. cmp #$08
  2448. bcs PROPEN
  2449. jsr TOPCLR
  2450. lda #<MSG_SECADDR
  2451. ldy #>MSG_SECADDR
  2452. jsr PRMSG
  2453. jsr GETAKEY
  2454. sec ; digit -> secondary address
  2455. sbc #$30
  2456. tay
  2457. bpl PROPEN
  2458. jmp PEXIT
  2459. PROPEN: lda #$01 ; SETLFS(1, device, secondary address)
  2460. ldx DEVNO
  2461. jsr SETLFS
  2462. jsr PRINTINGMSG
  2463. lda #$01 ; close file 1 in case it was left open
  2464. jsr CLOSE
  2465. jsr OPEN
  2466. ldx #$01 ; all output to file 1
  2467. jsr CHKOUT
  2468. bcc PRINIT
  2469. jmp PREND
  2470. ; PRINIT - reset all print settings to DEFTAB/DEFCODES, no header/footer,
  2471. ; LINE = $FF (= "top of the first page not printed yet").
  2472. PRINIT: ldx #$00
  2473. stx FTLEN
  2474. stx HDLEN
  2475. stx NEEDASC
  2476. stx UNDERLINE
  2477. stx LINEFEED
  2478. PRINIT_DEF:
  2479. lda DEFTAB,x ; copy the 12 defaults
  2480. sta LMARGIN,x
  2481. inx
  2482. cpx #$0C
  2483. bne PRINIT_DEF
  2484. lda #$FF ; LINE = $FF: need a top-of-page
  2485. sta LINE
  2486. sta NOMARG
  2487. ldx #$04 ; copy printer codes for keys 1-4
  2488. PRINIT_CODES:
  2489. lda DEFCODES-1,x
  2490. sta CODEBUFFER+$30,x
  2491. dex
  2492. bne PRINIT_CODES
  2493. PRSTART:
  2494. lda TEXSTART ; PRSTART: begin at the top of the text
  2495. sta TEX
  2496. lda TEXSTART+1
  2497. sta TEX+1
  2498. ; ===========================================================================
  2499. ; PLOOP - format and print one line
  2500. ; Copies characters from (TEX) into PRBUFF until the right margin (or a
  2501. ; return mark). Reverse characters are format commands (FMTCMD). If the
  2502. ; margin is reached, backs up to the last space (word wrap). Then:
  2503. ; top-of-page if needed, left margin, the line itself (OUTLINE), line
  2504. ; spacing, end-of-page check, end-of-text check.
  2505. ; ===========================================================================
  2506. PLOOP: ldy #$00 ; POS = 0 ...
  2507. sty POS
  2508. cpy NOMARG ; ... or the left margin unless suppressed
  2509. beq PL_GETCH
  2510. lda LMARGIN
  2511. sta POS
  2512. PL_GETCH:
  2513. lda (TEX),y ; reverse character = format command
  2514. bpl PL_NOTCMD
  2515. jmp FMTCMD
  2516. PL_NOTCMD:
  2517. cmp #$1F ; return mark = end of line
  2518. beq PL_ENDLINE
  2519. PL_STORE:
  2520. sta PRBUFF,y ; store into the print line
  2521. iny
  2522. inc POS
  2523. lda POS ; reached the right margin?
  2524. cmp RMARGIN
  2525. bcc PL_GETCH
  2526. sty FINPOS ; line full: back up to a space
  2527. PL_BACKUP:
  2528. lda (TEX),y
  2529. cmp #$20
  2530. beq PL_ENDLINE
  2531. dec POS
  2532. dey
  2533. bne PL_BACKUP
  2534. ldy FINPOS ; no space at all: break at the margin
  2535. jmp PL_ADVANCE
  2536. DEADCODE:
  2537. iny ; unreachable code (left over from an earlier version)
  2538. lda (TEX),y
  2539. cmp #$20
  2540. beq PL_ENDLINE
  2541. dey
  2542. PL_ENDLINE:
  2543. sty FINPOS ; FINPOS = end of line
  2544. PL_ADVANCE:
  2545. tya ; TEX += Y+1 (skip the space / return mark too)
  2546. sec
  2547. adc TEX
  2548. sta TEX
  2549. lda TEX+1
  2550. adc #$00
  2551. sta TEX+1
  2552. ldy #$00
  2553. lda LINE ; first line of a page?
  2554. cmp #$FF
  2555. bne PL_LMARG
  2556. jsr TOP ; yes: header and top margin
  2557. PL_LMARG:
  2558. lda NOMARG ; left margin, unless the "m" command suppressed it
  2559. beq PL_OUTPUT
  2560. jsr LMARG
  2561. PL_OUTPUT:
  2562. sec ; NOMARG back to "margin on"
  2563. rol NOMARG
  2564. lda FINPOS ; line length for OUTLINE
  2565. sta ENDPOS
  2566. lda #<PRBUFF ; print from PRBUFF
  2567. sta FPTR
  2568. lda #>PRBUFF
  2569. sta FPTR+1
  2570. jsr OUTLINE
  2571. jsr CRSPACING ; CR(s) for line spacing
  2572. lda LINE ; reached the bottom margin?
  2573. cmp BOTMARGIN
  2574. bcc PL_CHKEND
  2575. jsr PAGE ; yes: finish the page
  2576. PL_CHKEND:
  2577. sec ; past the end of the text?
  2578. lda TEX
  2579. sbc LASTLINE
  2580. sta TEMP
  2581. lda TEX+1
  2582. sbc LASTLINE+1
  2583. ora TEMP
  2584. beq PL_AGAIN
  2585. bcc PL_AGAIN
  2586. lda FTLEN ; if there is a footer, run to the bottom of the page
  2587. beq PL_FINISHED
  2588. lda #$00 ; (no header / top margin for a new page)
  2589. sta HDLEN
  2590. sta TOPMARGIN
  2591. jsr PAGE
  2592. PL_FINISHED:
  2593. lda DEVNO ; printing to screen: wait for a key to see it
  2594. cmp #$03
  2595. bne PREND
  2596. jsr GETAKEY
  2597. PREND: jsr STOP ; PREND: wait until STOP is released
  2598. beq PREND
  2599. lda #$01 ; close the print file
  2600. jsr CLOSE
  2601. jsr CLALL
  2602. lda SAVCOL ; restore the screen colour
  2603. sta SCRCOL
  2604. ldx #$FA ; reset the stack and go back to editing
  2605. txs
  2606. jsr SYSMSG
  2607. jmp MAIN
  2608. PL_AGAIN:
  2609. jmp PLOOP
  2610. ; ===========================================================================
  2611. ; PAGE - finish the current page and start a new one
  2612. ; Line-feeds down to the footer position, prints the footer (with left
  2613. ; margin), ejects with three CRs, bumps PAGENUM, and - unless printing
  2614. ; continuously, to screen or to disk - asks for the next sheet. Then
  2615. ; falls into TOP.
  2616. ; ===========================================================================
  2617. PAGE: sec ; lines left to the footer = PAGELENGTH - LINE - 2
  2618. lda PAGELENGTH
  2619. sbc LINE
  2620. tay
  2621. dey
  2622. dey
  2623. beq PAGE_FOOTER
  2624. bmi PAGE_FOOTER
  2625. PAGE_FILL:
  2626. jsr CR
  2627. dey
  2628. bne PAGE_FILL
  2629. PAGE_FOOTER:
  2630. lda FTLEN ; footer?
  2631. beq PAGE_EJECT
  2632. sta ENDPOS
  2633. lda #<FTBUFF
  2634. sta FPTR
  2635. lda #>FTBUFF
  2636. sta FPTR+1
  2637. jsr LMARG
  2638. jsr OUTLINE
  2639. PAGE_EJECT:
  2640. jsr CR ; end of the page
  2641. jsr CR
  2642. jsr CR
  2643. inc PAGENUM ; PAGENUM += 1
  2644. bne PAGE_WAIT
  2645. inc PAGENUM+1
  2646. PAGE_WAIT:
  2647. lda CONTINUOUS ; continuous paper?
  2648. bne TOP
  2649. lda DEVNO ; screen?
  2650. cmp #$03
  2651. beq TOP
  2652. cmp #$08 ; disk file?
  2653. beq TOP
  2654. sec ; still skipping pages before STARTNUM?
  2655. lda PAGENUM
  2656. sbc STARTNUM
  2657. lda PAGENUM+1
  2658. sbc STARTNUM+1
  2659. bcc TOP
  2660. jsr CLRCHN ; ask for a new sheet
  2661. jsr TOPCLR
  2662. lda #<MSG_NEXTSHEET
  2663. ldy #>MSG_NEXTSHEET
  2664. jsr PRMSG
  2665. jsr GETAKEY
  2666. jsr PRINTINGMSG
  2667. ldx #$01 ; output back to the printer
  2668. jsr CHKOUT
  2669. ; TOP - start of page: print the header (with left margin) if there is
  2670. ; one, then the top margin as blank lines; LINE = TOPMARGIN.
  2671. TOP: lda HDLEN
  2672. beq TOP_MARGIN
  2673. sta ENDPOS
  2674. lda #<HDBUFF
  2675. sta FPTR
  2676. lda #>HDBUFF
  2677. sta FPTR+1
  2678. jsr LMARG
  2679. jsr OUTLINE
  2680. TOP_MARGIN:
  2681. ldy TOPMARGIN
  2682. sty LINE
  2683. dey
  2684. beq TOP_DONE
  2685. bmi TOP_DONE
  2686. TOP_CRS:
  2687. jsr CR
  2688. dey
  2689. bne TOP_CRS
  2690. TOP_DONE:
  2691. rts
  2692. ; LMARG - print LMARGIN spaces; POS = LMARGIN.
  2693. LMARG: lda #$20
  2694. ldy LMARGIN
  2695. sty POS
  2696. beq LMARG_DONE
  2697. LMARG_LOOP:
  2698. jsr PCHAR
  2699. dey
  2700. bne LMARG_LOOP
  2701. LMARG_DONE:
  2702. rts
  2703. ; CRSPACING - print SPACING carriage returns; LINE += SPACING.
  2704. CRSPACING:
  2705. ldy SPACING
  2706. clc
  2707. tya
  2708. adc LINE
  2709. sta LINE
  2710. CRSP_LOOP:
  2711. jsr CR
  2712. dey
  2713. bne CRSP_LOOP
  2714. rts
  2715. ; CR - print one carriage return, plus a linefeed if the "j" command was used.
  2716. CR: lda #$0D
  2717. jsr PCHAR
  2718. lda LINEFEED
  2719. beq CR_DONE
  2720. jsr PCHAR
  2721. CR_DONE:
  2722. rts
  2723. ; ===========================================================================
  2724. ; FMTCMD - a reverse character was met while formatting a line
  2725. ; Convert it to PETSCII and look it up in FMTTAB. Found: call the handler
  2726. ; with FMT_RESUME-1 pushed as the return address. Handlers parse their
  2727. ; argument, leave YSAVE pointing at what follows, and FMT_RESUME skips
  2728. ; TEX past the command and restarts the line.
  2729. ; Not in the table: if followed by "=" it defines a printer key code
  2730. ; (e.g. reverse 1 =27); otherwise it is a printer key / in-line command
  2731. ; (c, e, u, # ...) and is copied into the print line for OUTLINE.
  2732. ; ===========================================================================
  2733. FMTCMD: sta SAVCHAR ; keep the original (reverse) character
  2734. and #$7F
  2735. jsr INTOAS ; to PETSCII
  2736. ldx FMTTAB
  2737. FMT_SEARCH:
  2738. cmp FMTTAB,x
  2739. beq FMT_DISPATCH
  2740. dex
  2741. bne FMT_SEARCH
  2742. dec POS ; not a format command: takes no column
  2743. jmp PRKEY
  2744. FMT_DISPATCH:
  2745. dex
  2746. txa
  2747. asl a
  2748. tax
  2749. sty YSAVE ; YSAVE = position of the command
  2750. lda #>(FMT_RESUME-1) ; push FMT_RESUME-1
  2751. pha
  2752. lda #<(FMT_RESUME-1)
  2753. pha
  2754. lda FMTVEC_HI,x ; push handler address-1 and RTS to it
  2755. pha
  2756. lda FMTVEC,x
  2757. pha
  2758. rts
  2759. FMT_RESUME:
  2760. sec ; FMT_RESUME: TEX += YSAVE+1
  2761. lda YSAVE
  2762. adc TEX
  2763. sta TEX
  2764. lda TEX+1
  2765. adc #$00
  2766. sta TEX+1
  2767. jmp PLOOP ; restart the line
  2768. SKIPPARM:
  2769. lda (TEX),y ; SKIPPARM: if we stopped on a return mark, skip it
  2770. cmp #$1F
  2771. beq SKIPPARM2
  2772. dey ; otherwise do not skip the stopping character
  2773. SKIPPARM2:
  2774. sty YSAVE
  2775. rts
  2776. ; FMTTAB - first byte = count (18), then the command letters (PETSCII).
  2777. ; FMTVEC - handler addresses minus 1.
  2778. FMTTAB: .byte $12 ; count = 18
  2779. .byte $57 ; "w"
  2780. .byte $41 ; "a"
  2781. .byte $4C ; "l"
  2782. .byte $52 ; "r"
  2783. .byte $54 ; "t"
  2784. .byte $42 ; "b"
  2785. .byte $53 ; "s"
  2786. .byte $4E ; "n"
  2787. .byte $48 ; "h"
  2788. .byte $46 ; "f"
  2789. .byte $40 ; "@"
  2790. .byte $50 ; "p"
  2791. .byte $3F ; "?"
  2792. .byte $58 ; "x"
  2793. .byte $4D ; "m"
  2794. .byte $49 ; "i"
  2795. .byte $47 ; "g"
  2796. .byte $4A ; "j"
  2797. FMTVEC: .word F_WAIT-1 ; w: wait between pages
  2798. .word F_ASCII-1 ; a: true ASCII
  2799. .word F_LMARGIN-1 ; l: left margin
  2800. .word F_RMARGIN-1 ; r: right margin
  2801. .word F_TOPMARGIN-1 ; t: top margin
  2802. .word F_BOTMARGIN-1 ; b: bottom margin
  2803. .word F_SPACING-1 ; s: line spacing
  2804. .word F_NEXTPAGE-1 ; n: next page
  2805. .word F_HEADER-1 ; h: header
  2806. .word F_FOOTER-1 ; f: footer
  2807. .word F_PAGENUM-1 ; @: page number
  2808. .word F_PAGELEN-1 ; p: page length
  2809. .word F_STARTPAGE-1 ; ?: start printing at page
  2810. .word F_PAGEWIDTH-1 ; x: page width
  2811. .word F_NOMARGIN-1 ; m: no left margin
  2812. .word F_IGNORE-1 ; i: ignore line
  2813. .word F_LINK-1 ; g: link to next file
  2814. .word F_LINEFEED-1 ; j: linefeeds
  2815. ; The format-command handlers. On entry Y indexes the command character.
  2816. ; Numeric arguments are read with ASCHEX.
  2817. F_NOMARGIN:
  2818. iny ; m: next line printed without the left margin
  2819. lda #$00
  2820. sta NOMARG
  2821. jmp SKIPPARM
  2822. F_PAGEWIDTH:
  2823. iny ; x n: page width
  2824. jsr ASCHEX
  2825. sta PAGEWIDTH
  2826. jmp SKIPPARM
  2827. F_STARTPAGE:
  2828. iny ; ? n: first page to print (16-bit)
  2829. jsr ASCHEX
  2830. sta STARTNUM
  2831. lda HEX+1
  2832. sta STARTNUM+1
  2833. jmp SKIPPARM
  2834. F_PAGENUM:
  2835. iny ; @ n: page number (16-bit)
  2836. jsr ASCHEX
  2837. sta PAGENUM
  2838. lda HEX+1
  2839. sta PAGENUM+1
  2840. jmp SKIPPARM
  2841. F_PAGELEN:
  2842. iny ; p n: page length
  2843. jsr ASCHEX
  2844. sta PAGELENGTH
  2845. jmp SKIPPARM
  2846. F_WAIT: lda #$00 ; w: wait for a new sheet after each page
  2847. sta CONTINUOUS
  2848. iny
  2849. jmp SKIPPARM
  2850. F_LINEFEED:
  2851. lda #$0A ; j: send LF ($0A) after every CR
  2852. sta LINEFEED
  2853. iny
  2854. jmp SKIPPARM
  2855. F_ASCII:
  2856. iny ; a: translate to true ASCII
  2857. lda #$01
  2858. sta NEEDASC
  2859. jmp SKIPPARM
  2860. F_LMARGIN:
  2861. iny ; l n: left margin
  2862. jsr ASCHEX
  2863. sta LMARGIN
  2864. jmp SKIPPARM
  2865. F_RMARGIN:
  2866. iny ; r n: right margin
  2867. jsr ASCHEX
  2868. sta RMARGIN
  2869. jmp SKIPPARM
  2870. F_TOPMARGIN:
  2871. iny ; t n: top margin
  2872. jsr ASCHEX
  2873. sta TOPMARGIN
  2874. jmp SKIPPARM
  2875. F_BOTMARGIN:
  2876. iny ; b n: bottom margin
  2877. jsr ASCHEX
  2878. sta BOTMARGIN
  2879. jmp SKIPPARM
  2880. F_SPACING:
  2881. iny ; s n: line spacing
  2882. jsr ASCHEX
  2883. sta SPACING
  2884. jmp SKIPPARM
  2885. F_NEXTPAGE:
  2886. ldy YSAVE ; n: force a new page now
  2887. iny
  2888. tya
  2889. pha
  2890. jsr PAGE
  2891. pla
  2892. tay
  2893. sty YSAVE
  2894. rts
  2895. F_HEADER:
  2896. jsr FINDRET ; h text: header = rest of the line
  2897. dey
  2898. sty HDLEN
  2899. ldy #$01
  2900. HDR_COPY:
  2901. lda (TEX),y ; copy it into HDBUFF
  2902. sta HDBUFF-1,y
  2903. iny
  2904. cpy HDLEN
  2905. bcc HDR_COPY
  2906. beq HDR_COPY
  2907. iny
  2908. jmp SKIPPARM
  2909. FINDRET:
  2910. iny ; FINDRET: advance Y to the next return mark
  2911. lda (TEX),y
  2912. cmp #$1F
  2913. bne FINDRET
  2914. rts
  2915. F_FOOTER:
  2916. jsr FINDRET ; f text: footer = rest of the line
  2917. dey
  2918. sty FTLEN
  2919. ldy #$01
  2920. FTR_COPY:
  2921. lda (TEX),y
  2922. sta FIRSTRUN,y
  2923. iny
  2924. cpy FTLEN
  2925. bcc FTR_COPY
  2926. beq FTR_COPY
  2927. jmp SKIPPARM
  2928. F_IGNORE:
  2929. jsr FINDRET ; i: ignore everything to the end of the line
  2930. jmp SKIPPARM
  2931. PRKEY: iny ; PRKEY: is the next character "=" ?
  2932. lda (TEX),y
  2933. cmp #$3D
  2934. beq PRKEY_DEFINE
  2935. dey ; no: copy the reverse char into the print line
  2936. lda SAVCHAR
  2937. jmp PL_STORE
  2938. PRKEY_DEFINE:
  2939. iny ; yes: CODEBUFFER[key] = number
  2940. jsr ASCHEX
  2941. pha
  2942. lda SAVCHAR
  2943. and #$7F
  2944. tax
  2945. pla
  2946. sta CODEBUFFER,x
  2947. jsr SKIPPARM
  2948. jmp FMT_RESUME
  2949. F_LINK: iny ; g d:name / g t:name - chain to the next file
  2950. ldx #$08
  2951. lda (TEX),y
  2952. and #$3F ; "d" (screen code 4) -> disk, device 8
  2953. cmp #$04
  2954. beq LINK_COLON
  2955. ldx #$01 ; "t" (screen code 20) -> tape, device 1
  2956. cmp #$14
  2957. beq LINK_COLON
  2958. jmp PEXIT
  2959. LINK_COLON:
  2960. stx IODEV
  2961. iny
  2962. lda (TEX),y ; must be followed by ":"
  2963. cmp #$3A
  2964. beq LINK_NAME
  2965. jmp PEXIT
  2966. LINK_NAME:
  2967. iny ; copy the filename (assumes the command starts the line)
  2968. lda (TEX),y
  2969. cmp #$1F
  2970. beq LINK_LOAD
  2971. jsr INTOAS
  2972. sta FILENAME-3,y
  2973. jmp LINK_NAME
  2974. LINK_LOAD:
  2975. tya ; length = Y - 3
  2976. sec
  2977. sbc #$03
  2978. ldx #<FILENAME
  2979. ldy #>FILENAME
  2980. jsr SETNAM
  2981. jsr CLRCHN ; output back to the screen, close file 2
  2982. lda #$02
  2983. jsr CLOSE
  2984. lda #$02 ; SETLFS(2, device, 0)
  2985. ldx IODEV
  2986. ldy #$00
  2987. jsr SETLFS
  2988. jsr ERASE ; erase the current text and load the next file
  2989. lda #$00
  2990. ldx CURR
  2991. ldy CURR+1
  2992. jsr LOAD_K
  2993. bcc LINK_OK
  2994. jmp PEXIT
  2995. LINK_OK:
  2996. stx LASTLINE ; new end of text
  2997. sty LASTLINE+1
  2998. pla ; drop the return to FMT_RESUME
  2999. pla
  3000. ldx #$01 ; output back to the printer
  3001. jsr CHKOUT
  3002. jmp PRSTART ; and print the new text from the top
  3003. ; ===========================================================================
  3004. ; DISKCMD - CTRL-up arrow: "Disk command:" - send the typed text to the
  3005. ; drive's command channel (15). Just RETURN reads and shows the drive
  3006. ; status instead. READERR is also used after a failed disk load/save.
  3007. ; ===========================================================================
  3008. DISKCMD:
  3009. jsr CLALL
  3010. lda #$00
  3011. jsr SETNAM
  3012. lda #$0F ; open 15,8,15
  3013. ldx #$08
  3014. ldy #$0F
  3015. jsr SETLFS
  3016. jsr OPEN
  3017. bcc DCMD_ASK
  3018. DCMD_CLOSE:
  3019. lda #$0F ; DCMD_CLOSE: close 15 and give up
  3020. jsr CLOSE
  3021. jsr CLALL
  3022. jmp SYSMSG
  3023. DCMD_ASK:
  3024. jsr TOPCLR
  3025. lda #<MSG_DISKCMD
  3026. ldy #>MSG_DISKCMD
  3027. jsr PRMSG
  3028. jsr INPUT
  3029. beq READERR ; nothing typed: just read the error channel
  3030. ldx #$0F
  3031. jsr CHKOUT
  3032. bcs DCMD_CLOSE
  3033. lda #<INBUFF ; send the command
  3034. ldy #>INBUFF
  3035. jsr PRMSG
  3036. lda #$0D
  3037. jsr CHROUT
  3038. jsr CLRCHN
  3039. READERR:
  3040. jsr CLALL ; READERR: reopen 15,8,15
  3041. lda #$00
  3042. jsr SETNAM
  3043. lda #$0F
  3044. ldx #$08
  3045. ldy #$0F
  3046. jsr SETLFS
  3047. jsr OPEN
  3048. bcs DCMD_CLOSE
  3049. jsr TOPCLR
  3050. ldx #$0F ; input from the error channel ...
  3051. jsr CHKIN
  3052. jsr INPUT ; ... INPUT now reads (and echoes) the status line
  3053. jsr CLRCHN
  3054. lda #$0F
  3055. jsr CLOSE
  3056. jsr CLALL
  3057. lda #$01
  3058. sta MSGFLG
  3059. rts
  3060. ; GLOBAL - CTRL-G: ask hunt and replace strings, then replace every
  3061. ; occurrence from the cursor to the end of the text.
  3062. GLOBAL: jsr ASKHUNT
  3063. lda HUNTLEN
  3064. beq GLOBAL_DONE
  3065. jsr ASKREP
  3066. GLOBAL_LOOP:
  3067. jsr CONTSRCH
  3068. lda FPOS+1
  3069. cmp #$FF
  3070. beq GLOBAL_DONE
  3071. jsr REPLACE
  3072. jsr REFRESH
  3073. jmp GLOBAL_LOOP
  3074. GLOBAL_DONE:
  3075. jmp SYSMSG
  3076. ; HUNT - CTRL-H: find the next occurrence of the hunt string.
  3077. ; SHIFT-CTRL-H: ask for a new hunt string ("Hunt for:").
  3078. HUNT: lda SHFLAG
  3079. cmp #$05
  3080. bne CONTSRCH
  3081. ASKHUNT:
  3082. jsr TOPCLR
  3083. lda #<MSG_HUNT
  3084. ldy #>MSG_HUNT
  3085. jsr PRMSG
  3086. jsr INPUT
  3087. sta HUNTLEN ; HUNTLEN = length
  3088. bne ASKHUNT_COPY
  3089. jmp SYSMSG
  3090. ASKHUNT_COPY:
  3091. ldy #$00
  3092. AH_COPYLOOP:
  3093. lda INBUFF,y ; copy INBUFF -> HUNTBUFF
  3094. sta HUNTBUFF,y
  3095. iny
  3096. cpy INLEN
  3097. bne AH_COPYLOOP
  3098. jmp SYSMSG
  3099. ; ===========================================================================
  3100. ; CONTSRCH - search forward from CURR+1 for HUNTBUFF (case-sensitive, in
  3101. ; screen codes). Found: cursor and FPOS = start of the match. Else "Not
  3102. ; Found" and FPOS high = $FF.
  3103. ; The matcher is simple: on a mismatch it restarts comparing at the next
  3104. ; text position without backing up, so some overlapping matches can be
  3105. ; missed (e.g. "aab" inside "aaab").
  3106. ; ===========================================================================
  3107. CONTSRCH:
  3108. lda CURR
  3109. sta TEX
  3110. lda CURR+1
  3111. sta TEX+1
  3112. lda #$FF ; FPOS = "not found"
  3113. sta FPOS+1
  3114. ldy #$01 ; start one past the cursor
  3115. ldx #$00
  3116. lda HUNTLEN
  3117. beq NOTFOUND
  3118. SRCH_CMP:
  3119. lda HUNTBUFF,x ; compare hunt character (as screen code)
  3120. jsr ASTOIN
  3121. cmp (TEX),y
  3122. beq SRCH_NEXT
  3123. ldx #$FF ; mismatch: X=$FF so INX restarts the match
  3124. SRCH_NEXT:
  3125. iny
  3126. bne SRCH_COUNT
  3127. inc TEX+1
  3128. lda TEX+1 ; past the end of the text?
  3129. cmp LASTLINE+1
  3130. beq SRCH_COUNT
  3131. bcs NOTFOUND
  3132. SRCH_COUNT:
  3133. inx
  3134. cpx HUNTLEN ; matched all HUNTLEN characters?
  3135. bne SRCH_CMP
  3136. clc ; TEMP = address just after the match
  3137. tya
  3138. adc TEX
  3139. sta TEMP
  3140. lda TEX+1
  3141. adc #$00
  3142. sta TEMP+1
  3143. lda LASTLINE ; beyond LASTLINE? then not found
  3144. cmp TEMP
  3145. lda LASTLINE+1
  3146. sbc TEMP+1
  3147. bcc NOTFOUND
  3148. sec ; CURR = FPOS = TEMP - HUNTLEN
  3149. lda TEMP
  3150. sbc HUNTLEN
  3151. sta CURR
  3152. sta FPOS
  3153. lda TEMP+1
  3154. sbc #$00
  3155. sta CURR+1
  3156. sta FPOS+1
  3157. jsr CHECK
  3158. rts
  3159. NOTFOUND:
  3160. jsr TOPCLR
  3161. lda #<MSG_NOTFOUND
  3162. ldy #>MSG_NOTFOUND
  3163. jsr PRMSG
  3164. lda #$01
  3165. sta MSGFLG
  3166. rts
  3167. ; REPSTART - CTRL-J: replace the text just found.
  3168. ; SHIFT-CTRL-J: ask for the replacement ("Replace with:").
  3169. REPSTART:
  3170. lda SHFLAG
  3171. cmp #$05
  3172. bne REPLACE
  3173. ASKREP: jsr TOPCLR
  3174. lda #<MSG_REPLACE
  3175. ldy #>MSG_REPLACE
  3176. jsr PRMSG
  3177. jsr INPUT
  3178. sta REPLEN
  3179. beq ASKREP_DONE
  3180. ldy #$00
  3181. ASKREP_COPY:
  3182. lda INBUFF,y
  3183. sta REPBUFF,y
  3184. iny
  3185. cpy INLEN
  3186. bne ASKREP_COPY
  3187. ASKREP_DONE:
  3188. jmp SYSMSG
  3189. ; REPLACE - only if the cursor is still at FPOS (where the hunt string was
  3190. ; found): delete HUNTLEN characters, insert REPBUFF, and move the cursor
  3191. ; past the replacement.
  3192. REPLACE:
  3193. sec
  3194. lda CURR
  3195. sta DESTL
  3196. sbc FPOS
  3197. sta TEMP
  3198. lda CURR+1
  3199. sta DESTH
  3200. sbc FPOS+1
  3201. ora TEMP
  3202. bne REP_DONE ; cursor moved since the hunt: do nothing
  3203. lda #$FF ; can only replace once per find
  3204. sta FPOS+1
  3205. clc ; FROM = CURR + HUNTLEN
  3206. lda HUNTLEN
  3207. adc CURR
  3208. sta FROML
  3209. lda #$00
  3210. adc CURR+1
  3211. sta FROMH
  3212. sec ; length = LASTLINE - CURR
  3213. lda LASTLINE
  3214. sbc DESTL
  3215. sta LLEN
  3216. lda LASTLINE+1
  3217. sbc DESTH
  3218. sta HLEN
  3219. jsr UMOVE ; remove the found text
  3220. sec ; LASTLINE -= HUNTLEN
  3221. lda LASTLINE
  3222. sbc HUNTLEN
  3223. sta LASTLINE
  3224. lda LASTLINE+1
  3225. sbc #$00
  3226. sta LASTLINE+1
  3227. lda REPLEN ; replacement string empty? done
  3228. beq REP_DONE
  3229. sta INSLEN ; make room for REPLEN characters
  3230. lda #$00
  3231. sta INSLEN+1
  3232. jsr INSBLOCK
  3233. ldy #$00
  3234. REP_COPY:
  3235. lda REPBUFF,y ; copy the replacement (as screen codes)
  3236. jsr ASTOIN
  3237. sta (CURR),y
  3238. iny
  3239. cpy REPLEN
  3240. bne REP_COPY
  3241. clc ; cursor after the replacement
  3242. lda CURR
  3243. adc REPLEN
  3244. sta CURR
  3245. lda CURR+1
  3246. adc #$00
  3247. sta CURR+1
  3248. REP_DONE:
  3249. jmp CHECK
  3250. ; ===========================================================================
  3251. ; OUTLINE - send ENDPOS characters from (FPTR) to the printer
  3252. ; Normal characters: screen code -> PETSCII (-> true ASCII if "a") and out;
  3253. ; with underline on, each is followed by BACKSPACE + "_".
  3254. ; Reverse characters are in-line commands:
  3255. ; c centre the line (pad (PAGEWIDTH-length)/2 - LMARGIN spaces)
  3256. ; e flush right (pad RMARGIN - length - LMARGIN spaces)
  3257. ; u toggle underline (then also sends its CODEBUFFER entry)
  3258. ; # print the page number
  3259. ; anything else: send the byte defined for it with "key=n"
  3260. ; ===========================================================================
  3261. OUTLINE:
  3262. ldy #$00
  3263. OUT_LOOP:
  3264. cpy ENDPOS
  3265. beq OUT_DONE
  3266. lda (FPTR),y ; reverse: in-line command
  3267. bmi SPECIAL
  3268. jsr INTOAS ; screen code -> PETSCII
  3269. jsr CONVASC ; optional ASCII translation
  3270. jsr PCHAR
  3271. lda UNDERLINE ; underlining?
  3272. beq OUT_NEXT
  3273. lda #$08 ; backspace and underscore
  3274. jsr PCHAR
  3275. lda #$5F
  3276. jsr PCHAR
  3277. OUT_NEXT:
  3278. iny
  3279. jmp OUT_LOOP
  3280. OUT_DONE:
  3281. rts
  3282. SPECIAL:
  3283. sty YSAVE
  3284. and #$7F
  3285. sta SAVCHAR
  3286. jsr INTOAS
  3287. cmp #$43 ; "c": centre
  3288. bne SPC_NOTC
  3289. sec
  3290. lda PAGEWIDTH
  3291. sbc ENDPOS
  3292. lsr a
  3293. sec
  3294. sbc LMARGIN
  3295. tay
  3296. lda #$20
  3297. SPC_SPACES:
  3298. jsr PCHAR
  3299. dey
  3300. bne SPC_SPACES
  3301. ldy YSAVE
  3302. jmp OUT_NEXT
  3303. SPC_NOTC:
  3304. cmp #$45 ; "e": flush right (edge)
  3305. bne SPC_NOTE
  3306. sec
  3307. lda RMARGIN
  3308. sbc ENDPOS
  3309. sec
  3310. sbc LMARGIN
  3311. tay
  3312. lda #$20
  3313. jmp SPC_SPACES
  3314. SPC_NOTE:
  3315. cmp #$55 ; "u": underline toggle
  3316. bne SPC_NOTU
  3317. lda UNDERLINE
  3318. eor #$01
  3319. sta UNDERLINE
  3320. SPC_NOTU:
  3321. cmp #$23 ; "#": page number
  3322. bne SENDCODE
  3323. sty YSAVE
  3324. ldx PAGENUM ; A/X = page number; print with BASIC's LINPRT
  3325. lda PAGENUM+1
  3326. ldy #$37
  3327. sty R6510
  3328. jsr LINPRT
  3329. ldy #$36
  3330. sty R6510
  3331. ldy YSAVE
  3332. jmp OUT_NEXT
  3333. SENDCODE:
  3334. ldx SAVCHAR ; SENDCODE: send the user-defined printer code
  3335. lda CODEBUFFER,x
  3336. jsr PCHAR
  3337. jmp OUT_NEXT
  3338. ; CONVASC - if "a" (NEEDASC) is on, swap the case of letters so a true
  3339. ; ASCII printer gets lower case $61-$7A and upper case $41-$5A.
  3340. CONVASC:
  3341. ldx NEEDASC
  3342. beq CONVASC_DONE
  3343. sta TEMP
  3344. and #$7F
  3345. cmp #$41
  3346. bcc CONVASC_DONE
  3347. cmp #$5B
  3348. bcs CONVASC_DONE
  3349. tax
  3350. lda TEMP ; $20 if it was lower case, 0 if upper
  3351. and #$80
  3352. eor #$80
  3353. lsr a
  3354. lsr a
  3355. sta TEMP
  3356. txa
  3357. ora TEMP
  3358. CONVASC_DONE:
  3359. rts
  3360. ; ===========================================================================
  3361. ; FREEMEM - CTRL-=: show TEXEND - LASTLINE (free bytes) on the command line
  3362. ; ===========================================================================
  3363. FREEMEM:
  3364. jsr TOPCLR
  3365. sec
  3366. lda TEXEND
  3367. sbc LASTLINE
  3368. tax
  3369. lda TEXEND+1
  3370. sbc LASTLINE+1
  3371. ldy #$37
  3372. sty R6510
  3373. jsr LINPRT
  3374. ldy #$36
  3375. sty R6510
  3376. lda #$01
  3377. sta MSGFLG
  3378. rts
  3379. ; ===========================================================================
  3380. ; MESSAGES (PETSCII, 0-terminated). The editor runs in the lower/upper
  3381. ; case character set, so $41-$5A print as lower case and $C1-$DA as
  3382. ; capitals. {xx} = control code: $08 disable C=/SHIFT case switch,
  3383. ; $0E lower case set, $9B light grey, $92 RVS off, $12 RVS on, $93 CLR.
  3384. ; ===========================================================================
  3385. MSG_TITLE:
  3386. .byte $08,$0E,$9B,$92,$D3,$50,$45,$45,$44,$D3,$43,$52,$49,$50,$54,$20,$33,$2E,$31,$00 ; "{08}{0E}{9B}{92}SpeedScript 3.1" + 0
  3387. MSG_BYLINE:
  3388. .byte $20,$42,$59,$20,$C3,$48,$41,$52,$4C,$45,$53,$20,$C2,$52,$41,$4E,$4E,$4F,$4E,$00 ; " by Charles Brannon" + 0
  3389. MSG_BUFCLR:
  3390. .byte $C2,$55,$46,$46,$45,$52,$20,$C3,$4C,$45,$41,$52,$45,$44,$00 ; "Buffer Cleared" + 0
  3391. MSG_BUFFULL:
  3392. .byte $C2,$55,$46,$46,$45,$52,$20,$C6,$55,$4C,$4C,$00 ; "Buffer Full" + 0
  3393. MSG_DELETE:
  3394. .byte $C4,$45,$4C,$45,$54,$45,$20,$28,$D3,$2C,$D7,$2C,$D0,$29,$00 ; "Delete (S,W,P)" + 0
  3395. MSG_SURE:
  3396. .byte $3A,$20,$C1,$52,$45,$20,$59,$4F,$55,$20,$53,$55,$52,$45,$3F,$20,$28,$D9,$2F,$CE,$29,$3A,$00 ; ": Are you sure? (Y/N):" + 0
  3397. MSG_ERASEALL:
  3398. .byte $C5,$D2,$C1,$D3,$C5,$20,$C1,$CC,$CC,$20,$D4,$C5,$D8,$D4,$00 ; "ERASE ALL TEXT" + 0
  3399. MSG_ERASE:
  3400. .byte $C5,$52,$41,$53,$45,$20,$28,$D3,$2C,$D7,$2C,$D0,$29,$3A,$20,$12,$D2,$C5,$D4,$D5,$D2,$CE,$92,$20,$54,$4F,$20,$45,$58,$49,$54,$00 ; "Erase (S,W,P): {12}RETURN{92} to exit" + 0
  3401. MSG_FORMAT:
  3402. .byte $D0,$52,$45,$53,$53,$20,$46,$4F,$52,$4D,$41,$54,$20,$4B,$45,$59,$3A,$00 ; "Press format key:" + 0
  3403. MSG_SAVE:
  3404. .byte $D3,$41,$56,$45,$3A,$00 ; "Save:" + 0
  3405. MSG_TAPEERR:
  3406. .byte $D4,$41,$50,$45,$20,$C5,$D2,$D2,$CF,$D2,$00 ; "Tape ERROR" + 0
  3407. MSG_STOPPED:
  3408. .byte $D3,$54,$4F,$50,$50,$45,$44,$00 ; "Stopped" + 0
  3409. MSG_VERERR:
  3410. .byte $D6,$45,$52,$49,$46,$59,$20,$C5,$52,$52,$4F,$52,$00 ; "Verify Error" + 0
  3411. MSG_NOERR:
  3412. .byte $CE,$4F,$20,$45,$52,$52,$4F,$52,$53,$00 ; "No errors" + 0
  3413. MSG_TAPEDISK:
  3414. .byte $93,$20,$12,$D4,$92,$41,$50,$45,$20,$4F,$52,$20,$12,$C4,$92,$49,$53,$4B,$3F,$00 ; "{93} {12}T{92}ape or {12}D{92}isk?" + 0
  3415. MSG_LOAD:
  3416. .byte $CC,$4F,$41,$44,$3A,$00 ; "Load:" + 0
  3417. MSG_VERIFY:
  3418. .byte $D6,$45,$52,$49,$46,$59,$3A,$00 ; "Verify:" + 0
  3419. MSG_RETURN:
  3420. .byte $D0,$52,$45,$53,$53,$20,$12,$D2,$C5,$D4,$D5,$D2,$CE,$92,$00 ; "Press {12}RETURN{92}" + 0
  3421. MSG_DISKCMD:
  3422. .byte $C4,$49,$53,$4B,$20,$43,$4F,$4D,$4D,$41,$4E,$44,$3A,$00 ; "Disk command:" + 0
  3423. DIRNAME:
  3424. .byte $24 ; "$"
  3425. MSG_NOROOM:
  3426. .byte $CE,$4F,$20,$D2,$4F,$4F,$4D,$00 ; "No Room" + 0
  3427. MSG_NOTEXT:
  3428. .byte $CE,$4F,$20,$54,$45,$58,$54,$20,$49,$4E,$20,$42,$55,$46,$46,$45,$52,$2E,$00 ; "No text in buffer." + 0
  3429. MSG_PRINTTO:
  3430. .byte $93,$D0,$52,$49,$4E,$54,$20,$54,$4F,$3A,$20,$12,$D3,$92,$43,$52,$45,$45,$4E,$2C,$12,$C4,$92,$49,$53,$4B,$2C,$12,$D0,$92,$52,$49,$4E,$54,$45,$52,$3F,$00 ; "{93}Print to: {12}S{92}creen,{12}D{92}isk,{12}P{92}rinter?" + 0
  3431. MSG_DEVNUM:
  3432. .byte $C4,$45,$56,$49,$43,$45,$20,$4E,$55,$4D,$42,$45,$52,$3F,$00 ; "Device number?" + 0
  3433. MSG_SECADDR:
  3434. .byte $D3,$45,$43,$4F,$4E,$44,$41,$52,$59,$20,$C1,$44,$44,$52,$45,$53,$53,$20,$23,$3F,$00 ; "Secondary Address #?" + 0
  3435. MSG_PRFILE:
  3436. .byte $D0,$52,$49,$4E,$54,$20,$54,$4F,$20,$46,$49,$4C,$45,$4E,$41,$4D,$45,$3A,$00 ; "Print to filename:" + 0
  3437. MSG_PRINTING:
  3438. .byte $93,$D0,$52,$49,$4E,$54,$49,$4E,$47,$2E,$2E,$2E,$0D,$0D,$00 ; "{93}Printing...<CR><CR>" + 0
  3439. MSG_NEXTSHEET:
  3440. .byte $C9,$4E,$53,$45,$52,$54,$20,$4E,$45,$58,$54,$20,$53,$48,$45,$45,$54,$2C,$20,$50,$52,$45,$53,$53,$20,$12,$D2,$C5,$D4,$D5,$D2,$CE,$92,$00 ; "Insert next sheet, press {12}RETURN{92}" + 0
  3441. MSG_HUNT:
  3442. .byte $C8,$55,$4E,$54,$20,$46,$4F,$52,$3A,$00 ; "Hunt for:" + 0
  3443. MSG_NOTFOUND:
  3444. .byte $CE,$4F,$54,$20,$C6,$4F,$55,$4E,$44,$00 ; "Not Found" + 0
  3445. MSG_REPLACE:
  3446. .byte $D2,$45,$50,$4C,$41,$43,$45,$20,$57,$49,$54,$48,$3A,$00 ; "Replace with:" + 0
  3447. MSG_EXIT:
  3448. .byte $C5,$D8,$C9,$D4,$20,$D3,$50,$45,$45,$44,$D3,$43,$52,$49,$50,$54,$00 ; "EXIT SpeedScript" + 0
  3449. ; Pointer low bytes that happen to sit at the end of the file (set by INIT).
  3450. ; TEXSTART ($2008/$2009) start of text, TEXEND ($200A/$200B) end of the
  3451. ; text area, TEXBUF ($200C/$200D) start of the cut/paste buffer.
  3452. TEXSTART:
  3453. .byte $0D
  3454. .byte $0D
  3455. TEXEND: .byte $0D
  3456. .byte $0D
  3457. TEXBUF: .byte $0D

Powered by TurnKey Linux.