home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / ENTERPRS / CPM / UTILS / S / VDE267SC.LBR / VDX1.AZM / VDX1.ASM
Assembly Source File  |  2000-06-30  |  46KB  |  2,510 lines

  1. ;*** VDE.ASM -  Video Display Editor
  2. ;*** Universal Version - (c)1988 Eric Meyer
  3. ;*** Module 1: patch areas, core code
  4. ;    -------------------
  5. ; VDE,VDE-2 - 9-12/84 - Enhanced VDO, added functions 
  6. ; VDE-OS,OX - 7/85-1/86 - Small additions and fixes
  7. ; VDE-PX    - 7-9/85 - Epson Geneva terminal version
  8. ; VDE 1.2-3 - 9/85-1/86 - Generic terminal version
  9. ; VDE/M 2.0 - 4/86 - Generic memory map version; CP/M+ support; additions
  10. ;       2.1 - 6/86 - New Keys 0-9; window; undo; directory; new pagination,
  11. ;                   compression, block marker, scroll; etc.
  12. ;       2.2 - 8/86 - WS-like commands; left mrgn, hyphenation; macros
  13. ;       2.3 - 9/86 - VINSTALL; Print options; word fns; real ^QA; RstDrv
  14. ;       2.4 - 1/87 - vidRAM/window redone; "W" mode; ^OZ,^QP; block print
  15. ;       2.5 - 3/87 - User#s; "N" mode; ^OS, ^OV/+/-; new block fns; hard-CRs
  16. ;       2.6 - 7/87 - Allow blank filename; ^U abort; new toggles; ruler;
  17. ;                   ^O<u>; AltBit fixes; works w/o curpos; key buffer; faster
  18. ;                   scrolling; case insensitive searches; no fake "VIDRAM"
  19. ;      2.61 - 8/87 - Bug fixes (incl FastFi), improved hyphenation
  20. ;      2.62 - 11/87 - ^JKL synonyms; ^W prefix; ^OH; several small fixes
  21. ;      2.63 - 1/88 - ^KV; WS style ^W/^Z; chgs to ^OP, ^OI/N, word fns
  22. ;      2.64 - 3/88 - ^OQ,^QT,^QI; ^KD; ^QA fixes; dbl spc; top margin;
  23. ;                         backward find; ShoRCu
  24. ;      2.65 - 4/88 - ^OI/N args; Esc-TAB; ^OA; menu removal; minor fixes
  25. ;      2.66 - 6/24/88 - Printer margins; Minor fixes.  LAST RELEASE!
  26. ;      2.67b - 10/14/88 - Minor fixes
  27. ;    -------------------
  28. ;
  29.     ORG    0100H
  30.     JP    Start        ;Entry and exit vectors
  31. Boot:    JP    0
  32. ;
  33. ;Following VINSTALL data MUST be at 0106-0112H
  34. ;
  35.     DB    02H+(X AND VDM),66H    ;Version compatibility
  36.     DW    UsrPat
  37.     DB    UPatL
  38.     DW    MnuSt
  39.     DW    KMnuSt
  40.     DW    OMnuSt
  41.     DW    QMnuSt
  42. ;
  43. VersID:        ;0113H: version message (28 chars, used in menu)
  44.   IF    VDM
  45. ;        [----5----10---15---20---25--]
  46.     DB    ' VDE-M 2.67b(c)1988 E.Meyer ',0
  47.   ELSE
  48.     DB    ' VDE 2.67b (c)1988 E.Meyer  ',0
  49.   ENDIF
  50. ;
  51. ;
  52. ;USER PATCHABLE VALUES
  53. ;
  54.     ORG    0130H
  55. BAKFlg:    DB    0    ;0130H - create BAK files (y/n)
  56. DFMode:    DB    'A'    ;default file mode W/A/N
  57. FDflt1:    DB    'ASMN'    ;1st default override
  58. FDflt2:    DB    'C  N'    ;2nd
  59. InsFlg:    DB    0    ;default insert on (y/n)
  60. RulFlg:    DB    0    ;default ruler on (y/n)
  61. HCDflt:    DB    0FFh    ;default HCR disp on (y/n)
  62. HypFlg:    DB    0FFH    ;enable hyphenation (y/n)
  63. DfltLM:    DB    1    ;left margin column (1=OFF)
  64. DfltRM:    DB    78    ;right margin column (1=OFF)
  65. Ovlap:    DB    2    ;scroll overlap (0=none)
  66. DirSys:    DB    0    ;include SYS files (y/n)
  67. FixDsk:    DB    'P@'    ;fixed drives
  68. Ring:    DB    0    ;errors ring bell (y/n)
  69. Help:    DB    0    ;use help menus (y/n)
  70. AltHdr:    DB    0FFH    ;use alt video in header (y/n)
  71. NoHdrF:    DB    0    ;suppress header (y/n)
  72.   IF    VDM
  73. MHz:    DB    80H    ;clock speed (40h=4MHz)
  74. Timer:    DB    01H    ;horiz scroll delay (01...FF)
  75.   ELSE
  76. MHz:    DB    50H
  77. Timer:    DB    40H
  78.   ENDIF
  79. TabCnt:    DB    8-1    ;hard tab cols -1 (1/3/7/15)
  80. VTList:    DB    6,15,35,55,0,0,0,0    ;variable tab columns (8)
  81. VTNum    EQU    $-VTList
  82. WildCd:    DB    '_'    ;wildcard character
  83. BlkChr:    DB    00H    ;block character (^@)
  84. TogTbl:    DB    02h,14h,13h,19h        ;toggles ^B,^T[^D],^S,^Y
  85. NTgTbl:    DB    11h,17h,05h,12h        ;switches ^Q,^W,^E,^R (last 015C)
  86. ;
  87. ;INSTALLATION
  88. ;
  89.   IF    VDM        ;Memory Mapped installation
  90.     ORG    0160H
  91.     DB    'Osborne Exec    '    ;ID
  92.     ORG    0170H
  93. View:    DB    80            ;viewable columns (max 128)
  94. Extra:    DB    48            ;empty cols in logical line
  95. Lines:    DB    24            ;viewable lines (min 8)
  96. UsrKys:    DB    0FFh            ;DEL key
  97.     DB    0BH,0AH,0CH,0FFH    ;arrows up,down,right,left
  98.     ORG    0180H
  99. TInit:    DB    1, 1AH,0,0,0,0,0,0    ;terminal init, 7 bytes
  100. TUInit:    DB    1, 1AH,0,0,0,0,0,0    ;terminal uninit
  101.     ORG    0190H
  102. CuOff:    DB    3, ESC,'.0',0,0,0    ;cursor hide, 6 bytes
  103. CuOn:    DB    3, ESC,'.2',0,0,0    ;cursor unhide
  104. VidRAM:    DW    0C000H        ;Video RAM address
  105. VidIN:    PUSH    AF        ;Switch Video IN, 16 bytes
  106.     LD    A,41H
  107.     OUT    0,A
  108.     POP    AF
  109.     RET
  110.     ORG    01B0H
  111. VidOUT:    PUSH    AF        ;Switch Video OUT
  112.     LD    A,01H
  113.     OUT    0,A
  114.     POP    AF
  115.     RET
  116.   ELSE            ;Generic Installation
  117.     ORG    0160H
  118.     DB    'Unidos Osb4 Emul'    ;ID
  119.     ORG    0170H
  120. View:    DB    80            ;viewable columns (max 128)
  121. AuWrap:    DB    0FFh            ;does autowrap occur
  122. Lines:    DB    24            ;lines
  123. UsrKys:    DB    0FFh            ;DEL key
  124.     DB    0BH,0AH,0CH,0FFH    ;arrows up,down,right,left
  125.     ORG    0179H
  126. ClL:    DB    2, ESC,'T',0,0,0,0    ;clear to end of line, 6 bytes
  127. TInit:    DB    1, 1AH,0,0,0,0,0,0    ;terminal init, 7 bytes
  128. TUInit:    DB    1, 1AH,0,0,0,0,0,0    ;terminal uninit
  129. AltOn:    DB    2, ESC,'j',0,0,0,0    ;alt video on, 6 bytes
  130. AltOff:    DB    2, ESC,'k',0,0,0,0    ;alt video off
  131. AltBit:    DB    0            ;high bit gives alt video?
  132. Filter:    DB    7FH            ;highest ASCII to send to screen
  133. PosMod:    DB    'S'            ;curpos mode (Std/Rev/ANSI/None)
  134. PCu:    DB    ESC,'=',20h,20h        ;position cursor to (0,0)
  135. PosDly:    DB    0            ;delay after curpos (00-FF)
  136. InsL:    DB    2, ESC,'E',0,0,0,0    ;insert line [1], 6 bytes
  137. DelL:    DB    2, ESC,'R',0,0,0,0    ;delete line [1], 6 bytes
  138. OddDel:    DB    0            ;ins/del line specific?
  139.   ENDIF
  140. ;
  141.     ORG    01C0H            ;Printer codes
  142.     DB    'Alps ALQ 200    '    ;ID
  143.     ORG    01D0H
  144. UseLF:    DB    0FFh            ;use LF after CR in print?
  145. FormL:    DB    56            ;form length (0=no pag)
  146. PTMarg:    DB    0            ;top margin skip
  147. DotPO:    DB    0            ;left margin skip
  148. PInit:    DB    19, 18H,ESC,'!',1    ;printer init, 19 bytes
  149.     DB        ESC,'x0',ESC,'r0',ESC,'%0',ESC,'l',8,ESC,'Q`'
  150.     ORG    01E8H            ;printer uninit, 7 bytes
  151. PUInit:    DB    6,  ESC,'x0',ESC,'!',01H
  152.     ORG    01F0H
  153. PCodes:    DB    2, ESC,'E',0,0,0,0,0    ;^B toggle on
  154.     DB    2, ESC,'F',0,0,0,0,0    ;...and off
  155.     DB    3, ESC,'S0',0,0,0,0    ;^T [^D] toggle on
  156.     DB    2, ESC,'T',0,0,0,0,0    ;...and off
  157.     DB    3, ESC,'-1',0,0,0,0    ;^S toggle on
  158.     DB    3, ESC,'-0',0,0,0,0    ;...and off
  159.     DB    2, ESC,'4',0,0,0,0,0    ;^Y toggle on
  160.     DB    2, ESC,'5',0,0,0,0,0     ;...and off
  161. UCodes:    DB    1, 0FH,0,0,0,0,0,0    ;sw 1 (^Q)
  162.     DB    3, ESC,'w1',0,0,0,0    ;sw 2 (^W)
  163.     DB    3, ESC,'W1',0,0,0,0       ;sw 3 (^E)
  164.     DB    6, ESC,'w0',ESC,'!',1,0    ;sw 4 (^R)
  165. ;
  166.     ORG    0250H
  167. UsrPat:                ;0250-027FH - User Patch Area
  168. ;(Can extend back into UCodes section if fewer switches used)
  169. ;
  170.     ORG    0280H        ;0280-047FH - Macro keys
  171. UPatL    EQU    $-UsrPat
  172. Keys:    DS    2        ;free count (VDE does this)
  173. K0:    DB    K1-K0-1, 8EH,90H,13H,0FH,06H        ;key 0: horiz. bar
  174.     DB        05H,16H,10H,13H,16H,CR
  175. K1:    DB    K2-K1-1, 8EH,90H,02H,'Eric Meyer'    ;1: personal address
  176.     DB        10H,02H,0FH,03H,ESC,'+9'
  177. K2:    DB    K3-K2-1, 8EH,90H,02H,'APTERYX SOFTWARE'    ;2: business
  178.     DB        10H,02H,0FH,03H,ESC,'+9'
  179. K3:    DB    K4-K3-1, 90H,9AH,ESC,'1',11H,13H,18H    ;3: soften para
  180.     DB          ESC,'= 2',ESC,'=',CR,'2',13H
  181.     DB        16H,' ',16H,04H,ESC,'!1'
  182.     DB        ESC,'2',11H,10H,7FH
  183. K4:    DB    K5-K4-1, 8FH,8CH,'7',CR,0FH,12H,'70',CR    ;4: quote margins
  184. K5:    DB    K6-K5-1, 8FH,8CH,'1',CR,0FH,12H,'78',CR    ;5: text margins
  185. K6:    DB    0    ;null keys 6-7
  186. K7:    DB    0
  187. K8:    DB    K9-K8-1, 8EH,X+'C','ompuServe [74415,1305]' ;8: phone/CIS
  188.     DB        0FH,06H,05H,'Phone (405)329-5777',CR
  189. K9:    DB    KT-K9-1, 8EH,X+'4','01 12th Ave SE, #139'   ;9: address/phone
  190.     DB        0FH,03H,0EH,'Norman, OK  73071',0FH,03H
  191.     DB        ESC,'+0'
  192. KT:
  193. ;
  194. ;
  195. ;----- EXECUTION BEGINS HERE -------
  196. ;
  197.     ORG    0480H
  198. ;
  199. Start:    SUB    A        ;check for Z80
  200.     RET    PE
  201.     LD    SP,Stack
  202.     LD    HL,Data        ;zero out data area
  203.     LD    DE,Data+1
  204.     LD    BC,DataLn-1
  205.     LD    (HL),0
  206.     LDIR
  207.     LD    C,CPMV
  208.     CALL    BDOSep
  209.     LD    (CPM3+1),A    ;CP/M version
  210.     CALL    CPM3
  211.     LD    C,ERRM        ;Error mode to Return?
  212.     LD    E,0FFh
  213.     CALL    NC,BDOSep
  214.     LD    C,GDRV        ;save logged drive
  215.     CALL    BDOSep
  216.     LD    (CurDsk),A
  217.     INC    A
  218.     LD    (FCB),A
  219.     LD    C,USRN        ;and user
  220.     LD    E,0FFH
  221.     CALL    BDOSep
  222.     LD    (CurUsr),A
  223.     LD    (FCBU),A
  224.   IF    VDM
  225.     LD    D,0        ;video RAM anatomy:
  226.     LD    HL,View        ;variable Width,Empty
  227.     LD    E,(HL)
  228.     LD    (Width),DE    ;Width=View
  229.     INC    HL
  230.     LD    E,(HL)
  231.     LD    (Empty),DE    ;Empty=Extra
  232.   ENDIF
  233. ;LD    DE,Lines    ;initialize variables
  234. ;LD    A,(DE)
  235. ;LD    (OrigLn),A
  236. ;LD    HL,RulFlg
  237. ;ADD    (HL)        ;(flag is -1 if on)
  238. ;LD    (DE),A
  239.     LD    A,(Lines)
  240.     LD    (PhysLn),A
  241.     CALL    AdjLns
  242.     LD    A,(FormL)
  243.     LD    (PgLen),A
  244.     LD    HL,(DfltLM)
  245.     LD    (LfMarg),HL
  246.     LD    A,(BlkChr)
  247.     LD    (BadTbl),A
  248.     LD    A,(UseLF)
  249.     CPL
  250.     OR    LF
  251.     LD    (LFChr),A
  252.     LD    HL,MacStr
  253.     DEC    (HL)        ;makes a FF terminator
  254. ;
  255.     LD    HL,DMA
  256.     LD    A,(HL)
  257.     INC    HL
  258.     CALL    Parse        ;parse command line
  259. ;
  260.     CALL    VerKey        ;verify keys
  261.     LD    HL,TInit
  262.     CALL    CtlStr        ;Clear and home cursor
  263.   IF    VDM
  264.     LD    HL,CuOff
  265.     CALL    CtlStr        ;remove real cursor
  266.   ENDIF
  267.     JR    Edit        ;start editing.
  268. ;
  269. ;Clear it all out and start over.
  270. ;
  271. Restrt:    LD    HL,LoadQ
  272.     CALL    NewNam
  273.     LD    A,(EdErr)    ;bad name?
  274.     OR    A
  275.     JR    NZ,BadLd
  276. ;
  277. ;Start editing a File
  278. ;
  279. Edit:    CALL    IniRAM        ;initialize memory
  280.     CALL    DfltM        ;adjust defaults
  281.     CALL    DoHdr        ;show header
  282.     CALL    Top        ;Start at TOF
  283.     CALL    Error0        ;No errors
  284.     LD    A,(FCB+1)
  285.     CP    ' '        ;Filename blank?
  286.     JR    Z,Edit1
  287.     CALL    SavNam        ;save it for LoadIt kludge
  288.     CALL    LoadIt        ;Get input file
  289.     LD    A,(EdErr)
  290.     CP    1        ;is it too big?
  291.     JR    NZ,Edit1
  292. BadLd:    CALL    DoErr        ;Too big, or bad name
  293.     CALL    BlkFCB        ;(Other error means new file)
  294.     JR    Edit
  295. Edit1:    LD    A,(MSIFlg)    ;set up BAKflag
  296.     LD    HL,BAKFlg
  297.     AND    (HL)
  298.     LD    (FilFlg),A
  299.     XOR    A
  300.     LD    (Modify),A
  301. ;
  302. Reset:    LD    SP,Stack    ;recover from ^U prompt abort
  303.     CALL    ShoLn1
  304. ;
  305. ;
  306. ;MAIN LOOP: SHOW TEXT, GET KEY
  307. ;
  308. Ready:    CALL    Orient        ;Get bearings
  309.     CALL    ShoTx        ;  then show text as needed
  310.     CALL    Cursr        ;position cursor
  311.     CALL    TRptKy        ;Get input
  312.     PUSH    AF
  313.   IF    VDM
  314.     CALL    CursrX        ;remove cursor
  315.   ENDIF
  316.     CALL    Error0        ;Clear error indicator
  317.     CALL    SetNo        ;default NO redisp
  318.     POP    AF
  319.     CALL    AdjKey        ;translate arrows/DEL
  320. ;
  321. DoKey:    CALL    Case        ;try to match control code?
  322.     DB    MnuLn/3
  323.     DW    IChar        ;Default : Insert character
  324. MnuSt    EQU    $
  325.     DB    0    ;(internal use: null key)
  326.     DW    CKCan
  327.     DB    80H    ;DEL
  328.     DW    Delete
  329.     DB    81H    ;Up arrow
  330.     DW    Up
  331.     DB    82H    ;Down
  332.     DW    Down
  333.     DB    83H    ;Right
  334.     DW    Right
  335.     DB    84H    ;Left
  336.     DW    Left
  337.     DB    ESC
  338.     DW    Escape
  339.     DB    '^'-40H
  340.     DW    UpLow
  341.     DB    '\'-40H
  342.     DW    Repeat    ;Synonym for ^L
  343.     DB    'A'-40H
  344.     DW    WordLf
  345.     DB    'B'-40H
  346.     DW    Reform
  347.     DB    'C'-40H
  348.     DW    PageF
  349.     DB    'F'-40H
  350.     DW    WordRt
  351.     DB    'G'-40H
  352.     DW    EChar
  353.     DB    'I'-40H
  354.     DW    TabKey
  355.     DB    'J'-40H
  356.     DW    DoMnu
  357.     DB    'K'-40H
  358.     DW    CKKey
  359.     DB    'L'-40H
  360.     DW    Repeat
  361.     DB    'M'-40H
  362.     DW    ICR
  363.     DB    'N'-40H
  364.     DW    ICRA
  365.     DB    'O'-40H
  366.     DW    Onscrn
  367.     DB    'P'-40H
  368.     DW    CtlP
  369.     DB    'Q'-40H
  370.     DW    Quick
  371.     DB    'R'-40H
  372.     DW    PageB
  373.     DB    'T'-40H
  374.     DW    WordDl
  375.     DB    'U'-40H
  376.     DW    Undel
  377.     DB    'V'-40H
  378.     DW    IToggl
  379.     DB    'W'-40H
  380.     DW    Scr1LU
  381.     DB    'Y'-40H
  382.     DW    Eline
  383.     DB    'Z'-40H
  384.     DW    Scr1LD
  385. MnuLn    EQU    $-MnuSt
  386. ;
  387. Sk1Ed:    LD    A,(EdErr)    ;Check for error, repeat main loop
  388.     OR    A
  389.     CALL    NZ,DoErr
  390.     JP    Ready
  391. ;
  392. ;Block commands: ^K toggle is on
  393. ;
  394. CKKey:    LD    HL,CKTog
  395.     CALL    Prefix
  396. CKSyn:    CALL    XCase        ;Entry for ESC synonyms
  397.     CALL    Case
  398.     DB    KMnuLn/3
  399.     DW    Error2        ;complain if unknown
  400. KMnuSt    EQU    $
  401.     DB    'B'-40h
  402.     DW    Block
  403.     DB    'C'-40h
  404.     DW    Copy
  405.     DB    'D'-40h
  406.     DW    Done
  407.     DB    'E'-40h
  408.     DW    Era
  409.     DB    'F'-40h
  410.     DW    Dir
  411.     DB    'H'-40h
  412.     DW    DoMnu
  413.     DB    'I'-40h
  414.     DW    Info
  415.     DB    'K'-40h
  416.     DW    Termin
  417.     DB    'L'-40h
  418.     DW    Load
  419.     DB    'N'-40h
  420.     DW    ChgNam
  421.     DB    'P'-40h
  422.     DW    Print
  423.     DB    'Q'-40h
  424.     DW    Quit
  425.     DB    'R'-40h
  426.     DW    Read
  427.     DB    'S'-40h
  428.     DW    Save
  429.     DB    'U'-40h
  430.     DW    Unmark
  431.     DB    'V'-40h
  432.     DW    MovBlk
  433.     DB    'W'-40h
  434.     DW    Write
  435.     DB    'X'-40h
  436.     DW    Exit
  437.     DB    'Y'-40h
  438.     DW    EBlock
  439.     DB    ESC
  440.     DW    CKCan
  441.     DB    ' '
  442.     DW    CKCan
  443. KMnuLn    EQU    $-KMnuSt
  444. CKCan:    RET
  445. ;
  446. ;ESC commands: ESC toggle is on.
  447. ;
  448. Escape:    LD    HL,ESCTog
  449.     CALL    Prefix
  450.     CALL    AdjKey
  451.     CALL    UCase
  452.     CP    '0'
  453.     JR    C,Esc01        ;macro Keys: special case
  454.     CP    '9'+1
  455.     JP    C,UseKey
  456. Esc01:    CALL    Case
  457.     DB    EMnuLn/3
  458.     DW    CKSyn        ;default: ^K synonym
  459. EMnuSt    EQU    $
  460.     DB    81H    ;Up arrow
  461.     DW    ShftU
  462.     DB    82H    ;Down
  463.     DW    ShftD
  464.     DB    83H    ;Right
  465.     DW    ShftR
  466.     DB    84H    ;Left
  467.     DW    ShftL
  468.     DB    '['        ;ANSI cursor sequences
  469.     DW    ANSIcu
  470.     DB    TAB
  471.     DW    TaBack
  472.     DB    'M'
  473.     DW    DoMac
  474.     DB    '#'
  475.     DW    MacKey
  476.     DB    '!'        ;macro prog stmts
  477.     DW    MacJmp
  478.     DB    '='
  479.     DW    MacTst
  480.     DB    '~'
  481.     DW    MacTsX
  482.     DB    '+'
  483.     DW    ChainK
  484.     DB    ';'
  485.     DW    Wait
  486. EMnuLn    EQU    $-EMnuSt
  487.     RET
  488. ;
  489. ;Onscreen commands.  ^O toggle is on.
  490. ;
  491. Onscrn:    LD    HL,COTog
  492.     CALL    Prefix
  493.     CALL    XCase        ;force to ctl
  494.     CALL    AdjKUp        ;adjust UP ARROW ONLY
  495.     CALL    Case        ;What function?
  496.     DB    OMnuLn/3
  497.     DW    Error2        ;complain if unknown
  498. OMnuSt    EQU    $
  499.     DB    81H    ;up
  500.     DW    MakTop
  501.     DB    'A'-40h
  502.     DW    AITog
  503.     DB    'C'-40h
  504.     DW    Center
  505.     DB    'D'-40h
  506.     DW    HCRTog
  507.     DB    'F'-40h
  508.     DW    Center    ;same fn as 'C'
  509.     DB    'H'-40h
  510.     DW    HypTog
  511.     DB    'I'-40h
  512.     DW    VTSet
  513.     DB    'L'-40h
  514.     DW    SetLM
  515.     DB    'N'-40h
  516.     DW    VTClr
  517.     DB    'P'-40h
  518.     DW    PgSet
  519.     DB    'Q'-40h
  520.     DW    NoHdr
  521.     DB    'R'-40h
  522.     DW    SetRM
  523.     DB    'S'-40h
  524.     DW    DblTog
  525.     DB    'T'-40h
  526.     DW    Ruler
  527.     DB    'V'-40h
  528.     DW    VTTog
  529.     DB    'W'-40h
  530.     DW    Window
  531.     DB    'X'-40h
  532.     DW    RelM
  533.     DB    'Z'-40h
  534.     DW    Blank
  535.     DB    ESC
  536.     DW    COCan
  537.     DB    ' '
  538.     DW    COCan
  539. OMnuLn    EQU    $-OMnuSt
  540. COCan:    RET
  541. ;
  542. ;Quick commands.  ^Q toggle is on.
  543. ;
  544. Quick:    LD    HL,CQTog
  545.     CALL    Prefix
  546.     CALL    XCase
  547.     CALL    AdjKey        ;translate arrow/DEL
  548.     CALL    Case        ;What function?
  549.     DB    QMnuLn/3
  550.     DW    Error2        ;complain if unknown
  551. QMnuSt    EQU    $
  552.     DB    80H    ;DEL
  553.     DW    EBLine
  554.     DB    81H    ;Up arrow
  555.     DW    QuikUp
  556.     DB    82H    ;Down
  557.     DW    QuikDn
  558.     DB    83H    ;Right
  559.     DW    QuikRt
  560.     DB    84H    ;Left
  561.     DW    QuikLf
  562.     DB    'A'-40h
  563.     DW    Rplace
  564.     DB    'B'-40h
  565.     DW    QikBlk
  566.     DB    'C'-40h
  567.     DW    Bottom
  568.     DB    'F'-40h
  569.     DW    Find
  570.     DB    'I'-40h
  571.     DW    ZipTo
  572.     DB    'P'-40h
  573.     DW    QuikMk
  574.     DB    'R'-40h
  575.     DW    Top
  576.     DB    'T'-40h
  577.     DW    E2Char
  578.     DB    'U'-40h
  579.     DW    UndlLn
  580.     DB    'Y'-40h
  581.     DW    EOLine
  582.     DB    ESC
  583.     DW    CQCan
  584.     DB    ' '
  585.     DW    CQCan
  586. QMnuLn    EQU    $-QMnuSt
  587. CQCan:    RET
  588. ;
  589. ;
  590. ;
  591. Prefix:    PUSH    HL        ;show prefix, get suffix
  592.     LD    DE,DspEsc
  593.     CALL    GoTo
  594.     CALL    MakAlt
  595.     POP    HL
  596.     LD    B,3
  597.     CALL    BHLMsg
  598. ;LD    B,9
  599.     LD    B,1
  600.     CALL    BBlank
  601.     LD    DE,DspEsQ    ;position cursor
  602.     CALL    GoTo
  603.   IF    VDM
  604.     CALL    SCursr
  605.   ENDIF
  606.     CALL    RptKey        ;get suffix
  607.     PUSH    AF
  608.     LD    A,(NoHdrF)
  609.     OR    A
  610.     JR    NZ,PrefNH
  611.     LD    DE,DspEsc
  612.     CALL    GoTo
  613.     LD    B,4        ;clean up
  614.     CALL    BBlank
  615.     CALL    UnAlt
  616.     POP    AF
  617.     RET
  618. PrefNH:    CALL    UnAlt        ;(if no header)
  619.     CALL    ShoLn1
  620.     LD    A,(RulFlg)
  621.     OR    A
  622.     CALL    NZ,RulFix
  623.     POP    AF
  624.     RET
  625. ;
  626. ;
  627. ;Return to CP/M ... With or without saving
  628. ;
  629. Exit:    CALL    Save        ;Save the file
  630.     LD    A,(EdErr)    ;Was it ok?
  631.     OR    A
  632.     RET    NZ        ;No, do not quit
  633.     JR    QuitY
  634. ;
  635. Done:    CALL    Save        ;Save, and load new
  636.     LD    A,(EdErr)
  637.     OR    A
  638.     RET    NZ
  639.     JP    Restrt
  640. ;
  641. Quit:    LD    A,(Modify)    ;Quit to CP/M
  642.     OR    A
  643.     JR    Z,QuitY
  644.     LD    HL,QuitQ
  645.     CALL    Prompt
  646.     CALL    Confrm        ;warn if file changed...
  647.     JP    NZ,ShoLn1
  648. QuitY:    LD    HL,TUInit    ;Clear screen
  649.     CALL    CtlStr
  650.   IF    VDM
  651.     LD    HL,CuOn        ;Cursor back on
  652.     CALL    CtlStr
  653.   ENDIF
  654.     LD    A,(CurDsk)    ;restore logged disk
  655.     LD    E,A
  656.     LD    C,SELD
  657.     CALL    BDOS
  658.     LD    A,(CurUsr)    ;and user
  659.     LD    E,A
  660.     LD    C,USRN
  661.     CALL    BDOSep
  662.     JP    Boot        ;restart
  663. ;
  664. ;Error handler
  665. ;
  666. DoErr:    CALL    Loud        ;Show error message, wait for ESC
  667.     CALL    SetNo
  668.     XOR    A        ;kill any running macro
  669.     LD    (MacFlg),A
  670.     LD    A,(EdErr)
  671.     CP    10
  672.     JP    NC,SetAl    ;error 10 does NOT show
  673.     LD    A,(Ring)
  674.     OR    A
  675.     LD    E,Bel
  676.     CALL    NZ,CONOut
  677.     CALL    MakAlt
  678.     CALL    UpLft
  679.     CALL    Dspl
  680.     DB    X,31,'[[','['+X,0
  681.     LD    A,(EdErr)
  682.     ADD    A        ;Double the code
  683.     LD    L,A
  684.     LD    H,0
  685.     LD    DE,ErrTab
  686.     ADD    HL,DE
  687.     LD    E,(HL)        ;Get msg addr from table
  688.     INC    HL
  689.     LD    D,(HL)
  690.     EX    DE,HL
  691.     CALL    DspLp        ;show it
  692.     CALL    DsplC
  693.     DB    ' ]]]',CR,0
  694.     CALL    UnAlt
  695.     CALL    EscLp
  696.     LD    A,(EdErr)
  697.     CP    1
  698.     JR    Z,DoErr2
  699.     CP    9
  700.     JP    C,ShoLn1    ;(errors 2-8 need no redisp)
  701. DoErr2:    JP    SetAl
  702. EscLp:    CALL    RptKey        ;await ESC from console
  703.     CP    ESC
  704.     RET    Z
  705.     CP    ' '
  706.     JR    NZ,EscLp
  707.     RET
  708. ;
  709. Error0:    LD    A,0        ;clear error (don't change flags)
  710.     JR    ErrSet
  711. Error1:    LD    A,1        ;error set fns
  712.     JR    ErrSet
  713. Error2:    LD    A,2
  714.     JR    ErrSet
  715. Error3:    LD    A,3
  716.     JR    ErrSet
  717. Error4:    LD    A,4        ;5,6 currently not used
  718.     JR    ErrSet
  719. Error7:    LD    A,7
  720.     JR    ErrSet
  721. Error8:    LD    A,8
  722.     JR    ErrSet
  723. Error9:    LD    A,9
  724.     JR    ErrSet
  725. Eror10:    LD    A,10
  726. ErrSet:    LD    (EdErr),A
  727.     RET
  728. ;
  729. ;
  730. ;INPUT ROUTINES
  731. ;
  732. KeyIn:    LD    HL,(Timer)    ;Get key, regardless
  733.     LD    H,0
  734.     ADD    HL,HL
  735.     ADD    HL,HL
  736.     ADD    HL,HL
  737.     ADD    HL,HL
  738. KyIn1:    PUSH    HL
  739.     CALL    KyStat
  740.     POP    HL
  741.     DEC    HL
  742.     JR    NZ,Keybd    ;read key if got one
  743.     LD    A,(HorFlg)
  744.     LD    E,A
  745.     LD    A,(KeyFlg)
  746.     OR    E
  747.     OR    H
  748.     OR    L        ;allow redisp for horizontal scroll?
  749.     JR    NZ,KyIn1
  750.     CPL
  751.     LD    (HorFlg),A    ;yep (just once)
  752.   IF    VDM
  753.     CALL    CursrX
  754.   ENDIF
  755.     CALL    ShoAll
  756.     CALL    Cursr
  757.     JR    KyIn1
  758. ;
  759. Keybd:    CALL    KyStat        ;Get key, or 0 if none
  760.     RET    Z
  761.     LD    HL,ConBuf
  762.     DEC    (HL)        ;uncount it
  763.     INC    HL
  764.     LD    A,(HL)        ;here it is
  765.     LD    D,H
  766.     LD    E,L
  767.     INC    HL
  768.     LD    BC,ConBufL-1
  769.     LDIR            ;remove it
  770.     AND    7FH        ;strip parity
  771.     RET
  772. ;
  773. KyStat:    CALL    CONSt        ;Console status with buffering
  774.     JR    Z,ConChk    ;all quiet
  775.     LD    C,A        ;got key
  776.     LD    HL,ConBuf
  777.     INC    (HL)        ;ok, count it
  778.     LD    E,(HL)
  779.     LD    D,0
  780.     ADD    HL,DE        ;point there
  781.     LD    (HL),C        ;put it in
  782.     LD    A,E
  783.     CP    ConBufL        ;buffer full?
  784.     JR    C,ConChk
  785. ConBsy:    LD    A,0C9H        ;(RET)
  786.     LD    (Plug),A    ;plug up the console until buffer empty
  787. ConChk:    LD    A,(ConBuf)    ;check buffer (FAST)
  788.     OR    A
  789.     RET    NZ
  790.     XOR    A        ;buffer empty, unplug console
  791.     LD    (Plug),A
  792.     RET
  793. ;
  794. CONSt:    XOR    A
  795. Plug:    NOP            ;<--- RET plugs up console
  796.     LD    E,0FFH        ;console status/input
  797.     LD    C,UCON
  798.     CALL    BDOSep
  799.     OR    A        ;test for null
  800.     RET
  801. ;
  802. ;
  803. Confrm:    CALL    RptKey        ;get a Y/N answer
  804.     CALL    UCase
  805.     CP    'Y'        ;return Z if confirmed
  806.     RET    Z
  807.     CP    'N'
  808.     JR    Z,CnfNo
  809.     CP    ESC        ;allow this too
  810.     JR    NZ,Confrm
  811. CnfNo:    OR    A
  812.     RET
  813. ;
  814. ;Translate four arrow keys and BS,DEL
  815. ;
  816. AdjKey:    CP    'H'-40h        ;First handle ^H (special case)
  817.     JR    NZ,AdjK0
  818.     LD    C,80h
  819.     LD    HL,UsrKys
  820.     CP    (HL)        ;Is it installed as DEL?
  821.     JR    Z,AKret
  822.     LD    C,84h        ;no, then it's Left arrow
  823.     CP    A
  824.     JR    AKret
  825. AdjK0:    LD    B,5        ;Not ^H, try the rest
  826.     JR    AdjK1
  827. AdjKUp:    LD    B,2        ;only do (DEL and) UP arrow
  828. AdjK1:    LD    HL,UsrKys
  829.     LD    DE,WSKys
  830.     LD    C,7FH        ;encode 80h=DEL, 81h=up, etc.
  831. AKlp:    INC    C
  832.     CP    (HL)
  833.     JR    Z,AKret
  834.     EX    DE,HL
  835.     INC    DE
  836.     CP    (HL)
  837.     JR    Z,AKret
  838.     INC    HL
  839.     DJNZ    AKlp
  840.     CP    C
  841.     LD    C,A        ;NO match: return NZ, char in A and C
  842. AKret:    LD    B,A        ;MATCH: return Z, code in A, char in C
  843.     LD    A,C
  844.     LD    C,B
  845.     RET
  846. WSKys:    DB    DEL,'E'-40H,'X'-40H,'D'-40H,'S'-40H
  847. ;
  848. ;
  849. ANSIcu:    CALL    RptKey        ;Handle ANSI cursor keys ESC-[...
  850.     SUB    'A'
  851.     JP    Z,Up
  852.     DEC    A
  853.     JP    Z,Down
  854.     DEC    A
  855.     JP    Z,Right
  856.     DEC    A
  857.     JP    Z,Left
  858.     JP    Error2
  859. ;
  860. ;Get string input
  861. ;
  862. GetStr:    LD    A,LinLen+1    ;string length +1
  863. GSEnt:    LD    (GSlen+1),A    ;(entry for GetNum and NewNam)
  864.     LD    HL,DMA        ;*** MUST be 0080h ***
  865. Lp1GS:    LD    A,L
  866.     SUB    80H        ;length
  867. GSlen:    CP    0        ;<---- max length pastes in here
  868.     JR    NC,GSBS        ;full?
  869.     PUSH    HL
  870.   IF    VDM
  871.     CALL    SCursr        ;make a cursor
  872.   ENDIF
  873.     CALL    RptKey        ;Get next input
  874.   IF    VDM
  875.     PUSH    AF
  876.     CALL    SCursr        ;remove cursor
  877.     POP    AF
  878.   ENDIF
  879.     CALL    AdjKey        ;translate key
  880.     POP    HL
  881.     CP    80H        ;corrections? DEL,
  882.     JR    Z,GSBS
  883.     CP    84H        ;left
  884.     JR    Z,GSBS
  885.     CP    CR        ;CR ends
  886.     JR    Z,GSCR
  887.     CP    'U'-40H        ;^U aborts operation
  888.     JP    Z,Reset
  889.     CP    'P'-40H        ;^P for ctlcode
  890.     JR    Z,GSctl
  891.     LD    A,C        ;restore orig char
  892.     CP    'X'-40H        ;wipeout
  893.     JR    Z,GSwipe
  894. ;
  895. Sk1GS:    LD    (HL),A        ;Store byte
  896.     INC    HL        ;Move along
  897.     CP    20H
  898.     PUSH    HL
  899.     JR    NC,Sk2GS
  900.     ADD    40H        ;ctls are hili letters
  901.     PUSH    AF
  902.     CALL    AltY
  903.     POP    AF
  904.     CALL    PutChA
  905.     CALL    UnAltY
  906.     JR    Sk3GS
  907. Sk2GS:    CALL    PutChA        ;show byte
  908. Sk3GS:    POP    HL
  909.     JR    Lp1GS
  910. ;
  911. GSBS:    CALL    GSBSsb
  912.     JR    Lp1GS
  913. GSwipe:    CALL    GSBSsb
  914.     JR    NZ,GSwipe
  915.     JR    Lp1GS
  916. GSBSsb:    LD    A,080h        ;Are we at start
  917.     CP    L
  918.     RET    Z        ;return Z if so
  919.     DEC    HL        ;back up pointer
  920.     LD    E,BS        ;wipe out char
  921.     CALL    PutCh
  922.     LD    E,' '
  923.     CALL    PutCh
  924.     LD    E,BS
  925.     CALL    PutCh
  926.     OR    1        ;clear flags
  927.     RET
  928. ;
  929. GSCR:    LD    (HL),0        ;terminator
  930.     LD    A,L
  931.     SUB    080H        ;Compute input length (Z=zero)
  932.     RET            ;HL points past end of string
  933. ;
  934. GSctl:    PUSH    HL
  935.     CALL    RptKey
  936.     CALL    XCase
  937.     POP    HL
  938.     JP    Sk1GS
  939. ;
  940. ;Get numeric input (0-65535 decimal), return C if bad
  941. ;
  942. GetNbr:    PUSH    BC        ;BC = default if no input
  943.     LD    A,5+1
  944.     CALL    GSEnt        ;get up to 3 digits
  945.     POP    DE
  946.     JR    NZ,GNyes
  947.     LD    B,D
  948.     LD    C,E
  949.     LD    A,B        ;no entry, use default
  950.     OR    C
  951.     RET
  952. GNyes:    LD    DE,DMA        ;fall thru to GetNNN
  953. ;
  954. GetNNN:    PUSH    HL        ;gets decimal # pointed by DE
  955.     LD    H,D
  956.     LD    L,E
  957.     LD    B,0
  958. GNL:    LD    A,(HL)
  959.     CP    '0'
  960.     JR    C,GotN        ;terminated by any nondigit.
  961.     CP    '9'+1
  962.     JR    NC,GotN
  963.     INC    HL
  964.     INC    B
  965.     LD    A,B
  966.     CP    5+1
  967.     JR    NC,GNErr    ;5 digits max.
  968.     JR    GNL
  969. GotN:    LD    A,B        ;okay, do them
  970.     LD    BC,0
  971.     OR    A        ;digits?
  972.     JR    Z,GNErr
  973.     CP    2
  974.     JR    Z,Got2
  975.     JR    C,Got1
  976.     CP    4
  977.     JR    Z,Got4
  978.     JR    C,Got3
  979.     CP    5
  980.     JR    NZ,GNErr
  981. Got5:    LD    HL,10000
  982.     CALL    GNNdig
  983.     JR    C,GNErr
  984. Got4:    LD    HL,1000
  985.     CALL    GNNdig
  986.     JR    C,GNErr
  987. Got3:    LD    HL,100
  988.     CALL    GNNdig
  989.     JR    C,GNErr
  990. Got2:    LD    HL,10
  991.     CALL    GNNdig
  992.     JR    C,GNErr
  993. Got1:    LD    HL,1
  994.     CALL    GNNdig
  995.     JR    C,GNErr
  996.     POP    HL
  997.     LD    A,B
  998.     OR    C
  999.     RET
  1000. GNErr:    POP    HL
  1001.     SCF            ;error
  1002.     RET
  1003. ;
  1004. GNNdig:    LD    A,(DE)        ;do a digit: HL=power of 10
  1005.     INC    DE
  1006. GNNLp:    CP    '0'
  1007.     RET    Z
  1008.     DEC    A
  1009.     PUSH    HL
  1010.     ADD    HL,BC
  1011.     LD    B,H
  1012.     LD    C,L
  1013.     POP    HL
  1014.     RET    C        ;overflow
  1015.     JR    GNNLp
  1016. ;
  1017. ;Versions of above for 0...255 only: GetNum, GetNN take # in A
  1018. ;
  1019. GetNum:    LD    C,A
  1020.     LD    B,0
  1021.     CALL    GetNbr
  1022.     JR    GetNN1
  1023. GetNN:    CALL    GetNNN
  1024. GetNN1:    RET    C
  1025.     XOR    A
  1026.     OR    B
  1027.     JR    NZ,GetNNX
  1028.     OR    C        ;result in A, OK
  1029.     RET
  1030. GetNNX:    SCF            ;oops, too big
  1031.     RET
  1032. ;
  1033. ;
  1034. ;Convert 16-bit number in HL to a one to five
  1035. ;digit decimal number in the area pointed to by DE
  1036. ;
  1037. BCDCon:    LD    IX,P10Tab    ;Point at table
  1038.     PUSH    DE        ;Save output pointer
  1039. BCDlp1:    LD    B,(IX+1)
  1040.     LD    C,(IX)
  1041.     LD    A,C        ;low byte
  1042.     CP    1        ;Clear carry flag
  1043.     JR    Z,BCDend
  1044.     SBC    HL,BC        ;Subtract from input
  1045.     JR    NC,BCDok    ;Got one in range
  1046.     ADD    HL,BC        ;Restore it
  1047.     INC    IX
  1048.     INC    IX
  1049.     JR    BCDlp1        ;Try next one
  1050. ;
  1051. BCDok:    LD    A,'1'
  1052.     LD    (DE),A        ;Set initial digit
  1053. BCDlp2:    SBC    HL,BC        ;Subtract again
  1054.     JR    C,BCDsk1    ;Went negative
  1055.     EX    DE,HL
  1056.     INC    (HL)        ;Increment digit
  1057.     EX    DE,HL
  1058.     JR    BCDlp2
  1059. ;
  1060. BCDsk1:    ADD    HL,BC        ;Restore it
  1061.     INC    DE        ;Bump output
  1062.     INC    IX
  1063.     INC    IX
  1064.     LD    C,(IX)
  1065.     LD    B,(IX+1)
  1066.     LD    A,C
  1067.     CP    1        ;Is this last entry
  1068.     JR    Z,BCDend
  1069.     LD    A,'0'
  1070.     LD    (DE),A
  1071.     JR    BCDlp2
  1072. ;
  1073. BCDend:    LD    A,L
  1074.     OR    '0'
  1075.     LD    (DE),A
  1076.     INC    DE
  1077.     EX    DE,HL
  1078.     POP    BC
  1079.     SBC    HL,BC        ;Number filled
  1080.     LD    A,5        ; needed
  1081.     SUB    L        ; to do
  1082.     RET    Z
  1083.     ADD    HL,BC        ;Restore pointer
  1084. BCDlp3:    LD    (HL),' '    ;Clear field
  1085.     INC    HL
  1086.     DEC    A
  1087.     JR    NZ,BCDlp3
  1088.     RET
  1089. ;
  1090. P10Tab:    DW    10000,1000,100,10,1
  1091. ;
  1092. ;
  1093. ;
  1094. ;PRINT text from memory
  1095. ;
  1096. Print:    LD    HL,PgLen    ;set defaults
  1097.     XOR    A
  1098.     CP    (HL)
  1099.     JR    NZ,Pr00
  1100.     INC    A        ;bit 0 set if no pagn
  1101. Pr00:    LD    (POByt),A
  1102.     XOR    A
  1103.     LD    (HdrLen),A
  1104.     LD    (POff),A
  1105.     CPL
  1106.     LD    (PNum),A
  1107.     LD    A,1
  1108.     LD    (Copies),A
  1109.     LD    (PBeg),A
  1110.     LD    A,(DotPO)
  1111.     LD    (PrLMrg),A
  1112.     LD    A,(PTMarg)
  1113.     LD    (PrTMrg),A
  1114.     LD    HL,PrtQ        ;options?
  1115.     CALL    Prompt
  1116.     CALL    GetStr        ;get string into 80
  1117.     LD    DE,DMA        ;point to option string
  1118. PrOlp:    LD    A,(DE)
  1119.     INC    DE
  1120.     LD    HL,POByt    ;set up bit flags
  1121.     LD    BC,PrOlp
  1122.     PUSH    BC        ;(return)
  1123.     CALL    UCase
  1124.     CP    ' '        ;eat spaces
  1125.     RET    Z
  1126.     CP    'B'
  1127.     JR    Z,POBlk
  1128.     CP    'D'
  1129.     JR    Z,PODblS
  1130.     CP    'P'
  1131.     JR    Z,POPau
  1132.     CP    'L'
  1133.     JR    Z,POLMrg
  1134.     CP    'T'
  1135.     JR    Z,POTMrg
  1136.     CP    '*'
  1137.     JR    Z,POCpy
  1138.     CP    '^'
  1139.     JR    Z,POCtl
  1140.     CP    '@'
  1141.     JR    Z,POBeg
  1142.     CP    '#'
  1143.     JR    Z,PONum
  1144.     CP    '='
  1145.     JR    Z,POPgS
  1146.     CP    '"'
  1147.     JP    Z,POHdrT
  1148.     POP    BC        ;kill return
  1149.     OR    A
  1150.     JP    Z,PORdy        ;quit at null
  1151.     JP    Error7        ;unexpected character
  1152. ;
  1153. POCpy:    CALL    GetNN        ;"*" sets copy count
  1154.     JP    C,POBad
  1155.     LD    (Copies),A
  1156.     RET
  1157. POLMrg:    CALL    GetNN        ;"Lnn" sets left margin
  1158.     JP    C,POBad
  1159.     LD    (PrLMrg),A
  1160.     RET
  1161. POTMrg:    CALL    GetNN        ;"Tnn" sets top margin
  1162.     JR    C,POBad
  1163.     LD    (PrTMrg),A
  1164.     RET
  1165. POPau:    SET    4,(HL)        ;bit 4 is for "P"
  1166.     RET
  1167. PODblS:    SET    3,(HL)        ;bit 3 is for "D"
  1168.     RET
  1169. POCtl:    SET    2,(HL)        ;bit 2 is for "^"
  1170.     RET
  1171. POBlk:    LD    A,(HL)
  1172.     AND    0C2H        ;bits 1,6,7 must be clear
  1173.     JR    NZ,POBad
  1174.     LD    A,(HL)
  1175.     AND    04H        ;preserve bit 2
  1176.     OR    21H        ;set 5 (BLOCK), 0; clear 1,6,7
  1177.     LD    (HL),A
  1178.     RET
  1179. POBeg:    BIT    0,(HL)        ;must be paginating
  1180.     JR    NZ,POBad
  1181.     CALL    GetNN        ;"@" page beginning
  1182.     JR    C,POBad
  1183.     OR    A
  1184.     JR    Z,POBad
  1185.     LD    (PBeg),A
  1186.     SET    6,(HL)        ;bit 6 is for "@" (suppresses output)
  1187.     SET    7,(HL)        ;so is bit 7 (multicopy)
  1188.     INC    A
  1189.     NEG            ;255-@ is most # can be
  1190.     LD    B,A
  1191.     LD    A,(PNum)
  1192.     CP    B
  1193.     RET    C        ;okay, less
  1194.     LD    A,B
  1195.     LD    (PNum),A
  1196.     RET
  1197. PONum:    BIT    0,(HL)        ;must be paginating
  1198.     JR    NZ,POBad
  1199.     CALL    GetNN        ;"#" page count
  1200.     JR    C,POBad
  1201.     OR    A
  1202.     JR    Z,POBad
  1203.     LD    B,A
  1204.     LD    A,(PBeg)
  1205.     ADD    B        ;@ + # cannot exceed 255
  1206.     JR    C,POBad
  1207.     LD    A,B
  1208.     LD    (PNum),A
  1209.     RET
  1210. POPgS:    BIT    0,(HL)        ;must be paginating
  1211.     JR    NZ,POBad
  1212.     CALL    GetNN        ;"=" starting pagination
  1213.     JR    C,POBad
  1214.     OR    A
  1215.     JR    Z,POBad
  1216.     LD    (POff),A    ;offset beginning page
  1217.     RET
  1218. POHdrT:    BIT    0,(HL)        ;must be paginating
  1219.     JR    NZ,POBad
  1220.     SET    1,(HL)        ;bit 1 requests header
  1221.     LD    (HdrPtr),DE    ;point to header text
  1222.     LD    B,50        ;and figure its length
  1223. POHlp:    LD    A,(DE)
  1224.     INC    DE
  1225.     CP    '"'
  1226.     JR    Z,POHlpF
  1227.     DJNZ    POHlp
  1228.     JR    POBad        ;too long
  1229. POHlpF:    LD    A,50
  1230.     SUB    B        ;length
  1231.     LD    (HdrLen),A
  1232.     RET
  1233. POBad:    POP    HL        ;eat return
  1234.     JP    Error7
  1235. ;
  1236. PORdy:    CALL    IOon        ;say Wait
  1237.     LD    HL,PInit    ;init string?
  1238.     LD    B,(HL)
  1239.     INC    HL
  1240.     CALL    LSTStr
  1241.     LD    HL,(AftCu)
  1242.     LD    (LastCu),HL    ;save position
  1243.     LD    HL,(BegTx)
  1244.     CALL    MoveL        ;move to top of file
  1245.     LD    A,(POff)
  1246.     OR    A
  1247.     JR    NZ,PORdy0
  1248.     LD    A,(PBeg)
  1249. PORdy0:    LD    HL,PBeg
  1250.     SUB    (HL)        ;adjust starting page offset
  1251.     LD    (POff),A
  1252.     LD    HL,POByt
  1253.     BIT    5,(HL)
  1254.     JR    Z,PORdy1
  1255.     CALL    IsBlk        ;block print requested
  1256.     BIT    1,A        ; must be marked
  1257.     JP    Z,PrOops
  1258.     INC    DE
  1259.     PUSH    HL
  1260.     SBC    HL,DE
  1261.     POP    HL
  1262.     RET    Z        ;block empty
  1263.     DEC    HL
  1264.     EX    DE,HL
  1265.     JR    PORdy2
  1266. PORdy1:    CALL    NdCnt        ;print whole file
  1267.     JP    C,PrDone    ;file empty
  1268.     LD    HL,(AftCu)
  1269.     LD    DE,(EndTx)
  1270. PORdy2:    LD    (StPrt),HL
  1271.     LD    (EndPr),DE
  1272. ;
  1273. RePrt:    LD    HL,POByt    ;[reprint reentry]
  1274.     BIT    7,(HL)
  1275.     JR    Z,PRP0
  1276.     SET    6,(HL)        ;remember if "@" was used
  1277. PRP0:    XOR    A
  1278.     LD    (PageN),A
  1279.     INC    A
  1280.     LD    (IgnFlg),A    ;TOF is start of line (DotChk)
  1281.     LD    A,(PgLen)    ;start first page
  1282.     LD    B,A
  1283.     OR    A
  1284.     CALL    NZ,PgBrk
  1285.     JR    C,Sk4Pr
  1286.     LD    HL,(StPrt)    ;Point at first one
  1287.     LD    C,0        ;Initialize GetNx
  1288. Lp1Pr:    CALL    GetNx        ;Get a character
  1289.     CALL    DotChk        ;(maybe ignore dot command lines)
  1290.     CP    CR
  1291.     JR    NZ,Sk2Pr
  1292.     CALL    PrOut        ;It's a CR
  1293.     PUSH    BC
  1294.     PUSH    HL
  1295.     CALL    Keybd
  1296.     CP    ESC        ;Abort request?
  1297.     POP    HL
  1298.     POP    BC
  1299.     JR    Z,Sk1Pr
  1300.     LD    A,(POByt)
  1301.     BIT    3,A        ;doublespacing? do extra CR(LFCR)LF
  1302.     JR    Z,Sk0Pr
  1303.     CALL    PLF
  1304.     LD    A,CR
  1305.     CALL    PrOut
  1306.     LD    A,B        ;count it (if paginating)
  1307.     OR    A
  1308.     JR    Z,Sk0Pr
  1309.     DEC    B
  1310.     JR    Z,Sk01Pr
  1311. Sk0Pr:    LD    A,B
  1312.     OR    A        ;Not paginating? B is and stays 0
  1313.     LD    A,(LFChr)    ;Add usual line feed
  1314.     JR    Z,Sk2Pr
  1315.     DJNZ    Sk2Pr
  1316. Sk01Pr:    CALL    PgBrk        ;time for NEW PAGE
  1317.     JR    C,Sk4Pr        ;done?
  1318.     JR    Sk2aPr
  1319. Sk1Pr:    LD    A,1        ;abort
  1320.     LD    (Copies),A
  1321.     JR    Sk3Pr
  1322. Sk2Pr:    CALL    ChekC        ;Check for masking
  1323.     CALL    PrOut        ;Output char
  1324.     XOR    A
  1325.     CP    C        ;Hidden space waiting?
  1326.     JR    NZ,Lp1Pr
  1327. Sk2aPr:    LD    DE,(EndPr)    ;At end?
  1328.     LD    A,E
  1329.     SUB    L
  1330.     LD    A,D
  1331.     SBC    H
  1332.     JR    NC,Lp1Pr    ;Loop if more to go
  1333. Sk3Pr:    LD    A,CR
  1334.     CALL    PrOut        ;last CRLF for some matrix printers
  1335.     LD    A,(LFChr)
  1336.     LD    C,A
  1337.     LD    A,(PgLen)
  1338.     OR    A        ;Finish page?
  1339.     JR    Z,Sk3aPr
  1340.     LD    C,FF
  1341. Sk3aPr:    LD    A,C
  1342.     CALL    PrOut
  1343. Sk4Pr:    LD    HL,PCodes    ;undo toggles if on
  1344.     LD    DE,16
  1345.     LD    B,4
  1346. Lp2Pr:    BIT    7,(HL)
  1347.     JR    Z,Lp2PrF
  1348.     RES    7,(HL)
  1349.     PUSH    BC
  1350.     PUSH    DE
  1351.     PUSH    HL
  1352.     LD    DE,8
  1353.     ADD    HL,DE
  1354.     LD    B,(HL)
  1355.     INC    HL
  1356.     CALL    LSTStr
  1357.     POP    HL
  1358.     POP    DE
  1359.     POP    BC
  1360. Lp2PrF:    ADD    HL,DE
  1361.     DJNZ    Lp2Pr
  1362.     LD    HL,Copies    ;more copies?
  1363.     DEC    (HL)
  1364.     JP    NZ,RePrt
  1365.     LD    HL,PUInit    ;uninit string?
  1366.     LD    B,(HL)
  1367.     INC    HL
  1368.     CALL    LSTStr
  1369.     JR    PrDone
  1370. PrOops:    CALL    Error7
  1371. PrDone:    LD    HL,(LastCu)    ;all finished
  1372.     DEC    HL
  1373.     CALL    MoveR        ;go back to position
  1374.     CALL    IOoff
  1375.     JP    ShoLn1
  1376. ;
  1377. PgBrk:    PUSH    BC        ;call this for new page (returns C for EOP)
  1378.     PUSH    HL
  1379.     LD    A,(PageN)
  1380.     OR    A
  1381.     LD    A,FF        ;start new sheet IF not 1
  1382.     CALL    NZ,PrOut
  1383.     LD    A,(POByt)
  1384.     BIT    4,A        ;pause requested?
  1385.     JR    Z,NP00
  1386.     CALL    IOoff        ;do it
  1387.     LD    HL,RdyQ
  1388.     CALL    Prefix
  1389.     CP    ESC
  1390.     JP    Z,NPquit
  1391.     CALL    IOon
  1392. NP00:    LD    HL,PageN
  1393.     INC    (HL)
  1394.     JP    Z,NPquit    ;255 page limit.
  1395.     LD    C,(HL)        ;check "#" limit?
  1396.     LD    A,(PBeg)
  1397.     LD    E,A
  1398.     LD    A,(PNum)    ;Pnum+Pbeg-1 = Lastpage#
  1399.     DEC    A
  1400.     ADD    E
  1401.     JP    C,NPquit    ;255 page limit
  1402.     CP    C
  1403.     JP    C,NPquit    ;"#" pages printed... quit.
  1404.     LD    A,(PBeg)
  1405.     LD    C,A
  1406.     LD    A,(PageN)
  1407.     CP    C
  1408.     LD    HL,POByt
  1409.     JR    C,NP10        ;are we "@" yet?
  1410.     RES    6,(HL)        ;yes (start) printing
  1411.     CALL    DoPOf        ;begin with margin offset
  1412. NP10:    LD    A,(PrTMrg)
  1413.     OR    A
  1414.     JR    Z,NP20
  1415.     LD    B,A
  1416. NP11Lp:    CALL    PCRLF        ;top margin?
  1417.     DJNZ    NP11Lp
  1418. NP20:    LD    HL,POByt
  1419.     BIT    1,(HL)
  1420.     JR    Z,NPnoh        ;want header?
  1421.     LD    A,(HdrLen)
  1422.     ADD    6
  1423.     LD    B,A
  1424.     LD    A,(RtMarg)    ;column for page no.
  1425.     SUB    B
  1426.     JR    NC,NPlp
  1427.     LD    A,70        ;default if margin unusable
  1428.     SUB    B
  1429. NPlp:    PUSH    AF        ;space over to right justify header
  1430.     LD    A,' '
  1431.     CALL    PrOut
  1432.     POP    AF
  1433.     DEC    A
  1434.     JR    NZ,NPlp
  1435.     LD    HL,(HdrPtr)    ;put out header
  1436.     LD    A,(HdrLen)
  1437.     LD    B,A
  1438.     CALL    POStr
  1439.     LD    A,' '
  1440.     CALL    PrOut
  1441.     LD    A,(PageN)    ;put out page
  1442.     LD    HL,POff
  1443.     ADD    (HL)        ;adjust for "=" option
  1444.     LD    L,A
  1445.     LD    H,0
  1446.     LD    DE,PNBuf
  1447.     CALL    BCDCon
  1448.     LD    HL,PNBuf
  1449.     LD    B,5
  1450.     CALL    POStr
  1451.     CALL    PCRLF
  1452.     CALL    PCRLF        ;two blank lines
  1453.     CALL    PCRLF
  1454. NPnoh:    POP    HL
  1455.     POP    BC
  1456.     LD    A,(PgLen)    ;reset TOP
  1457.     LD    B,A
  1458.     OR    A
  1459.     RET
  1460. NPquit:    POP    HL
  1461.     POP    BC
  1462.     SCF
  1463.     RET
  1464. PNBuf:    DB    'nnnnn',0    ;(also used elsewhere)
  1465. ;
  1466. DotChk:    CP    A,CR        ;may ignore dot commands
  1467.     JR    Z,DotCCR
  1468.     CP    A,'.'
  1469.     JR    Z,DotCDt
  1470. DtC01:    EX    AF,AF'        ;ordinary char
  1471.     LD    A,(IgnFlg)
  1472.     CP    0FFh        ;ignoring chars?
  1473.     RET    Z        ;(returns 0FFh, nonprinting)
  1474.     XOR    A
  1475.     LD    (IgnFlg),A    ;nope, clear dot search
  1476. DtCRet:    EX    AF,AF'        ;no action, accept char
  1477.     RET            ;leave it 0FFh (ignore)
  1478. DotCCR:    CALL    DtC01
  1479.     EX    AF,AF'
  1480.     LD    A,1        ;1 = ready to ignore if next char dot
  1481.     LD    (IgnFlg),A
  1482.     EX    AF,AF'
  1483.     RET
  1484. DotCDt:    EX    AF,AF'
  1485.     LD    A,(FMode)    ;Only ignore dotcmds in "W" mode
  1486.     CP    'W'
  1487.     JR    NZ,DtCRet
  1488.     LD    A,(IgnFlg)
  1489.     OR    A
  1490.     JR    Z,DtCRet
  1491.     LD    A,0FFh        ;FF = dot seen, ignore
  1492.     LD    (IgnFlg),A
  1493.     RET
  1494. ;
  1495. ChekC:    CP    ' '        ;may mask ctl chars
  1496.     RET    NC
  1497.     CP    CR        ;exceptions: CR,LF,BadTbl
  1498.     RET    Z
  1499.     CP    LF
  1500.     RET    Z
  1501.     PUSH    HL
  1502.     PUSH    BC
  1503.     LD    HL,BadTbl
  1504.     LD    BC,BadLen
  1505.     CPIR
  1506.     POP    BC
  1507.     POP    HL
  1508.     RET    Z
  1509.     PUSH    AF
  1510.     LD    A,(POByt)
  1511.     BIT    2,A
  1512.     JR    NZ,CMask
  1513.     POP    AF
  1514.     RET
  1515. CMask:    LD    A,'^'        ;mask: print "^",
  1516.     CALL    PrOut
  1517.     POP    AF
  1518.     OR    40H        ;turn ^A into A, etc.
  1519.     RET
  1520. ;
  1521. PrOut:    CP    0FFH        ;(FF=dummy code, ignore)
  1522.     RET    Z
  1523.     PUSH    BC        ;Print byte
  1524.     PUSH    DE
  1525.     PUSH    HL
  1526.     LD    HL,POByt    ;printing yet?
  1527.     BIT    6,(HL)
  1528.     JR    NZ,Sk2PO
  1529.     CP    ' '
  1530.     JR    NC,Sk1PO    ;non-ctl
  1531.     LD    HL,BadTbl
  1532.     LD    BC,BadLen
  1533.     CPIR
  1534.     JR    Z,Sk2PO        ;ILLEGAL
  1535.     LD    HL,TogTbl
  1536.     LD    BC,4
  1537.     CPIR            ;toggle?
  1538.     JR    Z,Sk3PO
  1539.     LD    BC,4
  1540.     CPIR            ;switch?
  1541.     JR    NZ,Sk1PO    ;arbitrary ctl-code
  1542.     LD    A,4-1
  1543.     SUB    C        ;nontog# (0..n)
  1544.     ADD    A
  1545.     ADD    A
  1546.     ADD    A        ;*8
  1547.     LD    E,A
  1548.     LD    D,0
  1549.     LD    HL,UCodes
  1550.     ADD    HL,DE
  1551. Sk00PO:    LD    B,(HL)
  1552.     INC    HL        ;string to send
  1553. Sk0PO:    CALL    LSTStr
  1554.     JR    Sk2PO
  1555. Sk3PO:    LD    A,4-1
  1556.     SUB    C        ;tog# (0..n)
  1557.     ADD    A
  1558.     ADD    A
  1559.     ADD    A
  1560.     ADD    A        ;*16
  1561.     LD    E,A
  1562.     LD    D,0
  1563.     LD    HL,PCodes
  1564.     ADD    HL,DE
  1565.     BIT    7,(HL)        ;toggle status?
  1566.     JR    NZ,Sk3aPO
  1567.     LD    B,(HL)        ;off, turn on
  1568.     SET    7,(HL)
  1569.     INC    HL
  1570.     JR    Sk0PO
  1571. Sk3aPO:    RES    7,(HL)        ;on, turn off
  1572.     LD    DE,8
  1573.     ADD    HL,DE
  1574.     JR    Sk00PO
  1575. Sk1PO:    LD    E,A        ;byte to send
  1576.     PUSH    AF
  1577.     CALL    LSTOut
  1578.     POP    AF
  1579.     CP    LF
  1580.     CALL    Z,DoPOf        ;LF? need margin skip
  1581. Sk2PO:    POP    HL
  1582.     POP    DE
  1583.     POP    BC
  1584.     RET
  1585. ;
  1586. DoPOf:    LD    A,(PrLMrg)    ;do printer margin offset
  1587.     OR    A
  1588.     RET    Z
  1589.     LD    B,A
  1590. DoPOfL:    LD    A,' '
  1591.     CALL    PrOut
  1592.     DJNZ    DoPOfL
  1593.     RET
  1594. ;
  1595. PCRLF:    LD    A,CR        ;do CR(LF?)
  1596.     CALL    PrOut
  1597. PLF:    LD    A,(LFChr)
  1598.     JP    PrOut
  1599. ;
  1600. POStr:    LD    A,B        ;send B chars at (HL) to PrOut
  1601.     OR    A
  1602.     RET    Z
  1603.     LD    A,(HL)
  1604.     CALL    PrOut
  1605.     INC    HL
  1606.     DJNZ    POStr
  1607.     RET
  1608. ;
  1609. LSTStr:    LD    A,B        ;send B chars at (HL) to LST directly
  1610.     OR    A
  1611.     RET    Z
  1612.     LD    E,(HL)
  1613.     PUSH    BC
  1614.     PUSH     HL
  1615.     CALL    LSTOut
  1616.     POP    HL
  1617.     POP    BC
  1618.     INC    HL
  1619.     DJNZ    LSTStr
  1620.     RET
  1621. ;
  1622. LSTOut:    LD    C,LSTO        ;print char in E
  1623.     JP    BDOSep
  1624. ;
  1625. ;
  1626. ;
  1627. ; ASSORTED SUPPORT ROUTINES
  1628. ;
  1629. ;RAM initialization functions
  1630. ;
  1631. IniRAM:    LD    HL,MnuEnd    ;Figure what used to be TxtOrg
  1632.     LD    A,(Help)    ;help menus disabled?
  1633.     OR    A
  1634.     JR    NZ,IniR02
  1635.     LD    HL,VDEend    ;yes, use that memory for editing
  1636. IniR02:    LD    (BegTx),HL
  1637.     LD    HL,(BDOSep+1)    ;BDOS origin (xx06)
  1638.     LD    L,-4        ;a few bytes room
  1639.     DEC    H        ;back a page
  1640.     LD    (EndTx),HL
  1641.     XOR    A        ;initialize screen
  1642.     LD    (NSkip),A
  1643.     INC    A
  1644.     LD    (Horiz),A
  1645.     LD    (Vert),A
  1646.     LD    (CurCol),A
  1647.     LD    HL,1
  1648.     LD    (CurPg),HL
  1649.     LD    (CurPgL),HL
  1650.     LD    (CurLin),HL
  1651.     LD    HL,(BegTx)    ;set up cursor gap, mark CRs at ends
  1652.     DEC    HL
  1653.     LD    (BefCu),HL
  1654.     LD    (HL),CR
  1655.     LD    HL,(EndTx)
  1656.     INC    HL
  1657.     LD    (AftCu),HL
  1658.     LD    (HL),CR
  1659.     RET
  1660. ;
  1661. ;Case selection subroutine
  1662. ;    CALL Case
  1663. ;    DB   # of entries in list
  1664. ;    DW   Default subroutine if no match
  1665. ;    DB   value1
  1666. ;    DW   subroutine1....
  1667. ;    <return point>
  1668. ;
  1669. Case:    POP    HL
  1670.     LD    B,(HL)        ;entries
  1671.     INC    HL
  1672.     LD    E,(HL)        ;DE=default sbr
  1673.     INC    HL
  1674.     LD    D,(HL)
  1675.     INC    HL
  1676. Lp1Ca:    CP    (HL)        ;Value matches?
  1677.     INC    HL
  1678.     JR    NZ,Sk2Ca
  1679.     LD    E,(HL)        ;yes, get address
  1680.     INC    HL
  1681.     LD    D,(HL)
  1682.     JR    Sk3Ca        ;finish up
  1683. ;
  1684. Sk2Ca:    INC    HL        ;No match, skip ahead
  1685. Sk3Ca:    INC    HL
  1686.     DJNZ    Lp1Ca        ;Try again
  1687.     EX    DE,HL        ;Swap sbr and return
  1688.     PUSH    DE        ;Store return (end of list)
  1689.     JP    (HL)        ;Go do sbr (LAST match)
  1690. ;
  1691. ;
  1692. XCase:    CALL    UCase        ;force A to ctl-codes
  1693.     CP    '@'
  1694.     RET    C
  1695.     CP    '_'+1
  1696.     RET    NC
  1697.     AND    1FH
  1698.     RET
  1699. UXCase:    CP    ESC        ;uppercase A if letter OR ctl-code
  1700.     JR    NC,UCase
  1701.     ADD    40H
  1702.     RET
  1703. UCase:    CP    'a'
  1704.     RET    C        ;uppercase A if letter
  1705.     CP    'z'+1
  1706.     RET    NC
  1707.     AND    5FH
  1708.     RET
  1709. ;
  1710. ;
  1711. Wait:    LD    A,(MacFlg)    ;Macro Pause function
  1712.     OR    A
  1713.     JP    Z,Error2
  1714.     LD    A,3        ;Wait about 3/2 sec
  1715.     JR    Dly0
  1716. ;
  1717. Delay:    LD    B,A        ;Delay about A/2 sec
  1718.     LD    A,(MacFlg)    ;but NOT if Macro going
  1719.     OR    A
  1720.     RET    NZ
  1721.     LD    A,B
  1722. Dly0:    ADD    A
  1723.     ADD    A
  1724. Dly1:    PUSH    AF
  1725.     CALL    BDly
  1726.     POP    AF
  1727.     DEC    A
  1728.     JR    NZ,Dly1
  1729.     RET
  1730. BDly:    LD    A,(MHz)
  1731.     LD    B,A
  1732.     LD    C,0
  1733. BDlyLp:    DEC    BC
  1734.     LD    A,B
  1735.     OR    C
  1736.     JR    NZ,BDlyLp
  1737.     RET
  1738. ;
  1739. ;
  1740. ; UR-ROUTINES
  1741. ;
  1742. Fill:    LD    (DE),A        ;fill B bytes at DE with A
  1743.     INC    DE
  1744.     DJNZ    Fill
  1745.     RET
  1746. ;
  1747. SubDP:    PUSH    HL        ;Double precision subtract
  1748.     OR    A        ;BC = HL - BC + 1
  1749.     SBC    HL,BC
  1750.     LD    B,H
  1751.     LD    C,L
  1752.     INC    BC
  1753.     POP    HL
  1754.     RET
  1755. ;
  1756. BgCnt:    LD    HL,(BegTx)    ;Count bytes before cursor
  1757. LCnt:    LD    B,H
  1758.     LD    C,L
  1759.     PUSH    HL
  1760.     LD    HL,(BefCu)
  1761.     CALL    SubDP
  1762.     POP    HL
  1763.     RET
  1764. NdCnt:    LD    HL,(EndTx)    ;Count bytes after cursor
  1765. RCnt:    LD    BC,(AftCu)
  1766.     JR    SubDP
  1767. ;
  1768. GpCnt:    LD    BC,(BefCu)    ;Count cursor gap size
  1769.     LD    HL,(AftCU)
  1770.     DEC    HL
  1771.     DEC    HL
  1772.     JR    SubDP
  1773. ;
  1774. ;Move bytes across cursor gap so the gap moves left.
  1775. ;HL points to what will become BefCu.
  1776. ;
  1777. MoveL:    CALL    LCnt        ;bytes to move
  1778.     RET    C
  1779.     LD    HL,(AftCu)
  1780.     DEC    HL
  1781.     EX    DE,HL
  1782.     LD    HL,(BefCu)
  1783.     LDDR
  1784.     LD    (BefCu),HL
  1785.     EX    DE,HL
  1786.     INC    HL
  1787.     LD    (AftCu),HL
  1788.     RET
  1789. ;
  1790. ;MoveR  - Moves gap right.  HL will become BefCu.
  1791. ;
  1792. MoveR:    CALL    RCnt
  1793.     RET    C
  1794.     LD    HL,(BefCu)
  1795.     INC    HL
  1796.     EX    DE,HL
  1797.     LD    HL,(AftCu)
  1798.     LDIR
  1799.     LD    (AftCu),HL
  1800.     EX    DE,HL
  1801.     DEC    HL
  1802.     LD    (BefCu),HL
  1803.     RET
  1804. ;
  1805. ;CrLft - Find CRs to left of cursor (up to E)
  1806. ;
  1807. CrLft:    CALL    BgCnt
  1808.     JR    NC,Sk1Lf
  1809.     XOR    A        ;no bytes, return with C and no Z
  1810.     SUB    1
  1811.     RET
  1812. Sk1Lf:    CALL    FetchB
  1813.     CP    CR        ;Is cursor on a CR
  1814.     JR    NZ,Sk2Lf
  1815.     LD    A,1
  1816.     CP    E
  1817.     JR    NZ,Sk2Lf
  1818.     SCF            ;Asked for 1, and already there: ret C and Z
  1819.     RET
  1820. Sk2Lf:    LD    A,CR
  1821. Lp3Lf:    CPDR            ;find a CR
  1822.     JP    PO,Sk4Lf    ;count exhausted?
  1823.     DEC    E
  1824.     JR    NZ,Lp3Lf    ;Do more?
  1825.     INC    HL        ;Back up to before CR
  1826.     INC    HL
  1827.     XOR    A        ;Found AOK, ret Z and no C
  1828.     RET
  1829. Sk4Lf:    INC    HL        ;Back to first byte
  1830.     SCF
  1831.     CCF            ;Clear C
  1832.     JR    Z,Sk5Lf        ;Was first byte CR
  1833.     DEC    E        ;No, reduce count
  1834.     RET
  1835. Sk5Lf:    INC    HL        ;Back after CR
  1836.     DEC    E        ;the one we wanted?
  1837.     RET    Z
  1838.     DEC    HL        ;No, back in front of it
  1839.     DEC    E
  1840.     RET
  1841. ;
  1842. ;CrRit - same, to right.
  1843. ;
  1844. CrRit:    CALL    NdCnt
  1845.     JR    NC,Sk1Ri
  1846.     XOR    A
  1847.     SUB    1        ;no bytes, return C and no Z
  1848.     RET
  1849. Sk1Ri:    LD    D,E
  1850.     LD    A,CR
  1851.     LD    HL,(AftCu)
  1852. Lp2Ri:    CPIR
  1853.     JP    PO,Sk3Ri
  1854.     DEC    E
  1855.     JR    NZ,Lp2Ri
  1856.     SCF
  1857.     CCF            ;found AOK, ret Z and no C
  1858.     RET
  1859. Sk3Ri:    LD    A,D
  1860.     CP    E
  1861.     JR    NZ,Sk4Ri
  1862.     SCF            ;none found, return C and Z
  1863.     RET
  1864. Sk4Ri:    LD    HL,(EndTx)
  1865.     DEC    HL
  1866.     LD    A,CR
  1867.     LD    BC,0FFFFh
  1868.     CPDR
  1869.     INC    HL
  1870.     INC    HL
  1871.     OR    1        ;some but not enough, ret no C and no Z
  1872.     RET
  1873. ;
  1874. ;cursor positioning subroutines
  1875. ;
  1876. TopV:    LD    A,1
  1877.     JR    LoadV
  1878. MidV:    LD    A,(TxtLns)
  1879.     SRL    A
  1880.     JR    LoadV
  1881. DecV:    PUSH    HL
  1882.     LD    HL,(CurLin)
  1883.     DEC    HL
  1884.     LD    (CurLin),HL
  1885.     POP    HL
  1886. DecVO:    LD    A,(Vert)    ;returns Z if cannot Dec
  1887.     CP    1
  1888.     JR    Z,LoadV
  1889.     DEC    A
  1890.     JR    LoadV
  1891. IncV:    PUSH    HL
  1892.     LD    HL,(CurLin)
  1893.     INC    HL
  1894.     LD    (CurLin),HL
  1895.     POP    HL
  1896. IncVO:    LD    A,(Vert)    ;returns Z if cannot Inc
  1897.     PUSH    HL
  1898.     LD    HL,TxtLns
  1899.     CP    (HL)
  1900.     POP    HL
  1901.     JR    Z,LoadV
  1902.     INC    A
  1903.     JR    LoadV
  1904. BotV:    LD    A,(TxtLns)
  1905. LoadV:    LD    (Vert),A
  1906.     RET
  1907. LftH:    LD    A,1
  1908.     JR    LoadH
  1909. LTabH:    LD    A,(Horiz)
  1910.     DEC    A
  1911.     JR    Z,RitH
  1912.     CALL    WhatC        ;ouch, got to calculate
  1913.     LD    HL,NSkip    ;Horiz = CurCol-NSkip
  1914.     SUB    (HL)
  1915.     JR    C,RitH
  1916.     JR    LoadH
  1917. DecH:    LD    A,(Horiz)
  1918.     DEC    A
  1919.     RET    Z
  1920.     JR    LoadH
  1921. TabH:    LD    A,(Horiz)
  1922.     DEC    A
  1923.     PUSH    HL
  1924.     LD    HL,TabCnt
  1925.     OR    (HL)
  1926.     POP    HL
  1927.     INC    A
  1928.     JR    IncT
  1929. IncH:    LD    A,(Horiz)
  1930. IncT:    PUSH    HL
  1931.     LD    HL,View
  1932.     CP    (HL)
  1933.     POP    HL
  1934.     RET    NC
  1935.     INC    A
  1936.     JR    LoadH
  1937. RitH:    LD    A,(View)
  1938. LoadH:    LD    (Horiz),A
  1939.     RET
  1940. ;
  1941. ;
  1942. ;Get next text character from memory
  1943. ;(HL and C keep track across repeated calls)
  1944. ;
  1945. GetNx:    XOR    A
  1946.     CP    C        ;Have we a hidden space?
  1947.     JR    NZ,Sk1Gt
  1948.     LD    A,(HL)        ;No, get next byte
  1949.     INC    HL
  1950.     BIT    7,A        ;Does it have hidden space?
  1951.     JR    Z,Sk2Gt
  1952.     AND    07Fh        ;Yes, note and remove
  1953.     INC    C
  1954.     JR    Sk2Gt
  1955. Sk1Gt:    DEC    C        ;Fetch hidden space
  1956.     LD    A,' '
  1957. Sk2Gt:    CP    CR        ;Set Z flag if CR
  1958.     RET
  1959. ;
  1960. ;Hide any hideable spaces. (NEW ALGORITHM)
  1961. ;
  1962. Cmprs:    CALL    BgCnt        ;bytes to left
  1963.     JR    C,Sk2Cm        ;none?
  1964.     LD    D,H
  1965.     LD    E,L
  1966.     DEC    DE
  1967. Lp1Cm:    LD    A,(HL)        ;Get a byte
  1968.     CP    ' '        ;Nonspace? fine
  1969.     JR    NZ,Sk1Cm
  1970.     LD    A,(DE)        ;Last byte CTL? fine
  1971.     CP    20H
  1972.     LD    A,' '
  1973.     JR    C,Sk1Cm
  1974.     LD    A,(DE)        ;Hidden space already? fine
  1975.     BIT    7,A
  1976.     LD    A,' '
  1977.     JR    NZ,Sk1Cm
  1978.     LD    A,(DE)
  1979.     OR    80h        ;Got to hide the space.
  1980.     DEC    DE
  1981. Sk1Cm:    INC    DE        ;Store byte
  1982.     LD    (DE),A
  1983.     INC    HL        ;Bump input
  1984.     DEC    BC
  1985.     LD    A,B
  1986.     OR    C        ;more to do?
  1987.     JR    NZ,Lp1Cm
  1988.     LD    (BefCu),DE    ;This is now BefCu
  1989. ;
  1990. Sk2Cm:    CALL    NdCnt        ;How many after cursor?
  1991.     RET    C
  1992.     LD    HL,(EndTx)    ;work back from end
  1993.     LD    D,H
  1994.     LD    E,L
  1995.     INC    DE
  1996. Lp3Cm:    LD    A,(DE)
  1997.     CP    ' '        ;Last byte space?
  1998.     JR    NZ,Sk3Cm
  1999.     LD    A,1FH        ;This byte CTL?
  2000.     CP    (HL)
  2001.     JR    NC,Sk3Cm
  2002.     BIT    7,(HL)        ;This byte already hiding?
  2003.     JR    NZ,Sk3Cm
  2004.     SET    7,(HL)        ;Got to hide that space
  2005.     INC    DE
  2006. Sk3Cm:    DEC    DE
  2007.     LD    A,(HL)        ;Store byte
  2008.     LD    (DE),A
  2009.     DEC    HL        ;Bump input
  2010.     DEC    BC
  2011.     LD    A,B
  2012.     OR    C        ;more to do?
  2013.     JR    NZ,Lp3Cm
  2014.     LD    (AftCu),DE    ;This is now AftCu
  2015.     RET
  2016. ;
  2017. ;Set BC to gap size (make room if needed, or set EdErr)
  2018. ;
  2019. Space:    LD    L,A        ;Save A
  2020.     PUSH    HL
  2021.     CALL    GpCnt        ;Count gap size
  2022.     CALL    C,Cmprs        ;No room? Hide spaces
  2023.     CALL    GpCnt        ;Room now?
  2024.     CALL    C,Error1
  2025.     POP    HL
  2026.     LD    A,L
  2027.     RET
  2028. ;
  2029. ;Put ordinary byte in A into text at cursor.
  2030. ;
  2031. Insrt:    CALL    Space        ;Insert Before cursor
  2032.     RET    C
  2033.     LD    HL,Modify
  2034.     LD    (HL),0FFh
  2035. Insrt1:    LD    HL,(BefCu)    ;Bump pointer
  2036.     INC    HL
  2037.     LD    (HL),A        ;Store byte
  2038.     LD    (BefCu),HL
  2039.     OR    A        ;Clear flags
  2040.     RET
  2041. InsrtA:    CALL    Space        ;same, but After cursor
  2042.     RET    C
  2043.     LD    HL,Modify
  2044.     LD    (HL),0FFh
  2045. InsrA1:    LD    HL,(AftCu)
  2046.     DEC    HL
  2047.     LD    (HL),A
  2048.     LD    (AftCu),HL
  2049.     OR    A
  2050.     RET
  2051. ;
  2052. ;Compute absolute line number
  2053. ;
  2054. CountS:    LD    HL,1        ;Hard way: from start
  2055.     LD    (CurLin),HL
  2056.     CALL    BgCnt
  2057.     JR    Sk0CL
  2058. CountL:    LD    HL,(LastCu)    ;same but faster, using LastCu
  2059.     INC    HL
  2060.     CALL    LCnt
  2061. Sk0CL:    RET    C            ;(At start, or have not moved)
  2062.     LD    DE,0
  2063.     LD    A,CR
  2064.     LD    HL,(BefCu)
  2065. Lp1CL:    CPDR
  2066.     JR    NZ,Sk1CL
  2067.     INC    DE
  2068.     JP    PE,Lp1CL
  2069. Sk1CL:    LD    HL,(CurLin)
  2070.     ADD    HL,DE
  2071.     LD    (CurLin),HL
  2072.     RET
  2073. CountR:    LD    HL,(LastCu)    ;same, but for backward move
  2074.     DEC    HL
  2075.     CALL    RCnt
  2076.     RET    C        ;(have not moved)
  2077.     LD    DE,0
  2078.     LD    A,CR
  2079.     LD    HL,(AftCu)
  2080. Lp1CR:    CPIR
  2081.     JR    NZ,Sk1CR    ;(have not moved)
  2082.     INC    DE
  2083.     JP    PE,Lp1CR
  2084. Sk1CR:    LD    HL,(CurLin)
  2085.     OR    A
  2086.     SBC    HL,DE
  2087.     LD    (CurLin),HL
  2088.     RET
  2089. ;
  2090. ;
  2091. ;MACRO functions
  2092. ;
  2093. MacKey:    LD    HL,KeyQ
  2094.     CALL    Prompt
  2095.     CALL    RptKey        ;which key?
  2096.     CALL    UCase
  2097.     LD    (MKsav),A
  2098.     CP    'N'        ;no-rpt request?
  2099.     JR    Z,MK0
  2100.     CP    'Q'        ;no-rpt & macro request?
  2101.     JR    NZ,MK00
  2102. MK0:    CALL    Echo        ;show N or Q, get next
  2103.     CALL    RptKey
  2104. MK00:    SUB    '0'
  2105.     JP    C,Error7
  2106.     CP    10
  2107.     JP    NC,Error7
  2108.     LD    D,A        ;save key
  2109.     LD    A,0FFH
  2110.     LD    HL,MacStr
  2111.     LD    BC,StrSiz+1    ;find end
  2112.     CPIR
  2113.     LD    A,StrSiz
  2114.     SUB    C        ;figure length
  2115.     LD    E,A        ;save it
  2116.     LD    HL,Keys+2
  2117.     LD    A,D
  2118.     OR    A
  2119.     JR    Z,MKlp1F
  2120. MKlp1:    LD    C,(HL)
  2121.     LD    B,0        ;find key in list
  2122.     ADD    HL,BC
  2123.     INC    HL
  2124.     DEC    A
  2125.     JR    NZ,MKlp1
  2126. MKlp1F:    LD    A,(HL)        ;old length
  2127.     OR    A
  2128.     JR    Z,MK1
  2129.     PUSH    DE
  2130.     PUSH    HL        ;delete old one
  2131.     LD    E,(HL)
  2132.     LD    D,0
  2133.     LD    (HL),0
  2134.     INC    HL
  2135.     EX    DE,HL
  2136.     ADD    HL,DE
  2137.     LD    B,H
  2138.     LD    C,L
  2139.     PUSH    HL
  2140.     LD    HL,Keys+200H
  2141.     OR    A
  2142.     SBC    HL,BC        ;bytes to move
  2143.     LD    B,H
  2144.     LD    C,L
  2145.     POP    HL
  2146.     LDIR
  2147.     CALL    VerKey
  2148.     POP    HL
  2149.     POP    DE
  2150. MK1:    LD    A,E        ;anything to add?
  2151.     OR    A
  2152.     JR    Z,MKDone
  2153.     LD    A,(Keys+1)    ;will it fit
  2154.     OR    A
  2155.     JR    NZ,MK1a
  2156.     LD    A,(Keys)
  2157.     SUB    E
  2158.     JP    C,Error1
  2159. MK1a:    LD    (HL),E        ;yes
  2160.     INC    HL
  2161.     LD    C,E
  2162.     LD    B,0
  2163.     PUSH    HL
  2164.     LD    HL,Keys+200H-1
  2165.     LD    D,H
  2166.     LD    E,L
  2167.     OR    A
  2168.     SBC    HL,BC        ;from here
  2169.     POP    BC
  2170.     PUSH    HL
  2171.     SBC    HL,BC        ;bytes to move
  2172.     LD    B,H
  2173.     LD    C,L
  2174.     INC    BC        ;inclusive
  2175.     POP    HL
  2176.     LDDR             ;make room
  2177.     LD    C,(HL)
  2178.     LD    B,0
  2179.     INC    HL
  2180.     EX    DE,HL
  2181.     LD    HL,MacStr
  2182.     PUSH    DE
  2183.     LDIR            ;insert new one
  2184.     POP    HL
  2185.     LD    A,(MKsav)
  2186.     CP    'N'        ;take care of N/Q request
  2187.     JR    Z,MK2
  2188.     CP    'Q'
  2189.     JR    NZ,MKDone
  2190.     DEC    HL
  2191.     LD    A,(HL)        ;Q only works if length >1
  2192.     CP    2
  2193.     INC    HL
  2194.     JR    C,MK2
  2195.     INC    HL
  2196.     SET    7,(HL)        ;indicate quiet
  2197.     DEC    HL
  2198. MK2:    SET    7,(HL)        ;indicate no-rpt
  2199. MKDone:    CALL    VerKey
  2200.     JP    ShoLn1
  2201. ;
  2202. ;
  2203. VerKey:    LD    B,10        ;verify key area
  2204.     LD    HL,200H-12
  2205.     LD    D,0
  2206.     LD    IX,Keys+2
  2207. VKlp:    LD    A,StrSiz    ;check size
  2208.     CP    (IX)
  2209.     JR    C,VKwipe
  2210.     LD    E,(IX)
  2211.     SBC    HL,DE        ;decrement
  2212.     JR    C,VKwipe
  2213.     ADD    IX,DE        ;move to next
  2214.     INC    IX
  2215.     DJNZ    VKlp
  2216.     LD    (Keys),HL    ;free bytes
  2217.     LD    A,H
  2218.     OR    L
  2219.     RET    Z        ;full?
  2220. VKlp2:    LD    (IX),0
  2221.     INC    IX        ;zero fill
  2222.     DEC    HL
  2223.     LD    A,H
  2224.     OR    L
  2225.     JR    NZ,VKlp2
  2226.     RET
  2227. VKwipe:    LD    HL,200H-12    ;oops, bad
  2228.     LD    (Keys),HL
  2229.     LD    IX,Keys+2
  2230.     LD    HL,200H-2
  2231.     JR    VKlp2
  2232. ;
  2233. ChainK:    LD    HL,MacFlg    ;chain to new macro
  2234.     BIT    0,(HL)        ;(used only if macro going)
  2235.     RET    Z
  2236.     CALL    RptKey        ;get key#
  2237.     CP    '0'
  2238.     JP    C,Error8
  2239.     CP    '9'+1
  2240.     JP    NC,Error8
  2241.     PUSH    AF
  2242.     CALL    Loud
  2243.     XOR    A
  2244.     LD    (MacFlg),A
  2245.     POP    AF
  2246.     JR    UK0
  2247. ;
  2248. UseKey:    LD    HL,MacFlg    ;macro going already?
  2249.     BIT    0,(HL)
  2250.     RET    NZ        ;YES, this is just a label
  2251. UK0:    SUB    '0'        ;NO, retrieve key 0-9
  2252.     LD    B,A
  2253.     LD    HL,Keys+2
  2254.     JR    Z,UKlp1F
  2255. UKlp1:    LD    E,(HL)
  2256.     LD    D,0        ;find it
  2257.     ADD    HL,DE
  2258.     INC    HL
  2259.     DJNZ    UKlp1
  2260. UKlp1F:    LD    A,(HL)        ;length
  2261.     INC    HL
  2262.     OR    A
  2263.     JP    Z,Error7    ;none?
  2264.     LD    C,A
  2265.     LD    B,0
  2266.     PUSH    BC        ;on stack for Mac00 entry
  2267.     LD    DE,DMA
  2268.     PUSH    DE
  2269.     LDIR            ;fetch it in
  2270.     POP    HL        ;point to it
  2271.     BIT    7,(HL)
  2272.     RES    7,(HL)
  2273.     JR    Z,Mac00        ;not no-rpt? go ask, etc.
  2274.     INC    HL
  2275.     BIT    7,(HL)
  2276.     RES    7,(HL)
  2277.     CALL    NZ,Quiet    ;quiet?
  2278.     LD    A,'1'
  2279.     JR    Mac0        ;go do just once
  2280. ;
  2281. DoMac:    LD    HL,MacroQ    ;get Macro defn
  2282.     CALL    Prompt
  2283.     CALL    GetStr
  2284.     OR    A
  2285.     JR    Z,MacDel    ;none? delete
  2286.     LD    C,A        ;save count
  2287.     LD    B,0
  2288.     PUSH    BC
  2289. Mac00:    LD    HL,RptcQ    ;(entry for normal Key)
  2290.     CALL    Prompt
  2291.     CALL    RptKey
  2292.     CALL    UCase
  2293.     CP    'Q'
  2294.     JR    NZ,Mac0
  2295.     CALL    Echo
  2296.     CALL    Quiet        ;Q? do quiet, get rpt cnt
  2297.     CALL    RptKey
  2298. Mac0:    POP    BC        ;string cnt  (entry for no-rpt Key)
  2299.     PUSH    AF        ;save rpt cnt
  2300.     LD    A,C
  2301.     OR    A        ;null string?
  2302.     JR    Z,Mac1
  2303.     LD    HL,DMA        ;move in string
  2304.     LD    DE,MacStr
  2305.     LDIR
  2306.     EX    DE,HL
  2307.     LD    (HL),0FFh    ;terminator
  2308. Mac1:    CALL    ShoLn1
  2309.     POP    AF
  2310.     LD    B,255
  2311.     CP    '*'        ;figure rpt cnt
  2312.     JR    Z,Mac2        ;(* is maximal)
  2313.     LD    B,0        ;(0 is default)
  2314.     SUB    '0'
  2315.     JR    C,Mac2
  2316.     CP    9+1
  2317.     JR    NC,Mac2
  2318.     LD    B,A
  2319. Mac2:    LD    A,B        ;set rpt cnt
  2320.     LD    (RptCnt),A
  2321.     OR    A
  2322.     JP    Z,Loud        ;oops, rpt=0
  2323. Mac3:    LD    HL,MacStr    ;Point to it
  2324.     LD    (CmdPtr),HL
  2325.     LD    A,0FFH        ;Okay, here goes
  2326.     LD    (MacFlg),A
  2327.     LD    HL,InsFlg    ;save INSERT toggle
  2328.     LD    A,(HL)
  2329.     LD    (SavIns),A    ;turn INSERT off if on
  2330.     BIT    7,(HL)
  2331.     CALL    NZ,IToggl
  2332.     RET
  2333. MacDel:    LD    A,0FFH
  2334.     LD    (MacStr),A
  2335.     JP    ShoLn1
  2336. ;
  2337. ;"Macro Programming Language"
  2338. ;
  2339. MacJmp:    LD    A,(MacFlg)    ;jump to a label
  2340.     OR    A
  2341.     JP    Z,Error8    ;macro must be going
  2342.     LD    (JmpFlg),A    ;say Jump in progress
  2343.     CALL    RptKey
  2344.     LD    HL,JmpFlg
  2345.     LD    (HL),0
  2346.     CP    '['        ;TOF/EOF?
  2347.     JR    Z,MJtop
  2348.     CP    ']'
  2349.     JR    Z,MJend
  2350.     CP    '>'        ;move/loops?
  2351.     JR    Z,MJRt
  2352.     CP    '<'
  2353.     JR    Z,MJLf
  2354.     LD    E,A        ;key to find
  2355.     LD    HL,MacStr
  2356.     LD    B,StrSiz
  2357. MJlp:    LD    A,(HL)        ;search along
  2358.     INC    HL
  2359.     CP    0FFH
  2360.     JP    Z,Error8
  2361.     CP    ESC
  2362.     JR    Z,MJlp01
  2363.     DJNZ    MJlp
  2364.     JP    Error8
  2365. MJlp01:    LD    A,E        ;found ESC... right one?
  2366.     CP    (HL)
  2367.     JR    NZ,MJlp
  2368.     INC    HL        ;yep
  2369.     LD    (CmdPtr),HL
  2370.     RET
  2371. ;
  2372. MJtop:    LD    HL,MacStr    ;redo it from the top
  2373.     LD    (CmdPtr),HL
  2374.     RET
  2375. MJend:    XOR    A        ;quit
  2376.     LD    (MacFlg),A
  2377.     LD    E,A
  2378.     CALL    RstIns
  2379.     JP    Loud
  2380. MJRt:    CALL    NdCnt        ;right/left jump loops
  2381.     JP    C,Error7    ;stop at EOF
  2382.     CALL    Right
  2383.     JR    MJredo
  2384. MJLf:    CALL    BgCnt
  2385.     JP    C,Error7
  2386.     CALL    Left
  2387. MJredo:    LD    HL,(CmdPtr)
  2388.     DEC    HL        ;back up to the ESC to repeat
  2389.     DEC    HL
  2390.     DEC    HL
  2391.     DEC    HL
  2392.     LD    (CmdPtr),HL
  2393.     RET
  2394. ;
  2395. MacTst:    LD    A,0CAH        ;(JP Z)
  2396.     JR    MacT1
  2397. MacTsX:    LD    A,0C2H        ;(JP NZ)
  2398. MacT1:    LD    (MacT),A
  2399.     LD    A,(MacFlg)
  2400.     OR    A        ;macro must be going
  2401.     JP    Z,Error8
  2402.     CALL    RptKey        ;get char to match
  2403.     LD    E,A
  2404.     CALL    Fetch        ;char at cursor
  2405.     CP    E
  2406. MacT:    JP    Z,MacJmp    ;yes? jump    <--- can be JP NZ too
  2407.     JP    RptKey        ;no, just eat label
  2408. ;
  2409. ;Get the next key stroke (check Macro first.)
  2410. ;
  2411. TRptKy:    XOR    A        ;enable redisp Timer
  2412.     JR    RK0
  2413. RptKey:    LD    A,0FFH
  2414. RK0:    LD    (KeyFlg),A
  2415.     LD    A,(MacFlg)
  2416.     OR    A        ;macro waiting?
  2417.     JP    Z,KeyIn        ;no.
  2418. MacIn:    CALL    Keybd        ;YES, check keyboard for abort
  2419.     CP    ESC
  2420.     JR    NZ,MacIn1
  2421.     LD    HL,(CmdPtr)    ;abort, make this last char
  2422.     LD    E,(HL)
  2423.     JR    MacIn3
  2424. MacIn1:    LD    HL,(CmdPtr)    ;OK, take waiting char
  2425.     LD    E,(HL)
  2426.     INC    HL        ;bump pointer
  2427.     LD    (CmdPtr),HL
  2428.     LD    A,(HL)        ;end of macro now? (FF)
  2429.     INC    A
  2430.     JR    NZ,MacIn2    ;NO, return char
  2431.     LD    A,(JmpFlg)    ;jump in progress?
  2432.     OR    A
  2433.     JR    NZ,MacIn2
  2434.     LD    HL,RptCnt    ;need to repeat?
  2435.     LD    A,(HL)
  2436.     INC    A
  2437.     JR    Z,McIn1a
  2438.     DEC    (HL)
  2439.     JR    Z,MacIn3
  2440. McIn1a:    LD    HL,MacStr    ;repeat: reset pointer
  2441.     LD    (CmdPtr),HL
  2442. MacIn2:    LD    A,E
  2443.     AND    7FH        ;strip parity, return char
  2444.     RET
  2445. MacIn3:    PUSH    DE        ;NO, stop macro execution
  2446.     XOR    A
  2447.     LD    (MacFlg),A
  2448.     CALL    RstIns        ;note E=last char (may be ^V!)
  2449.     CALL    Loud
  2450.     POP    DE
  2451.     JR    MacIn2
  2452. ;
  2453. ;Unconditional Q/L for Macros
  2454. ;
  2455.   IF    VDM
  2456. ShutUp    EQU    PutCh    ;where to RET out
  2457.   ELSE
  2458. ShutUp    EQU    CONOut
  2459.   ENDIF
  2460. ;
  2461. Quiet:    LD    HL,ShutUp
  2462.     LD    (HL),0C9H    ;(RET)
  2463.     RET
  2464. Loud:    LD    HL,ShutUp
  2465.     XOR    A        ;(NOP)
  2466.     CP    (HL)
  2467.     RET    Z
  2468.     LD    (HL),A
  2469.     JP    HoldSc        ;gotta see...
  2470. ;
  2471. RstIns:    LD    A,E        ;restore INSERT status after Macro
  2472.     CP    'V'-40h
  2473.     LD    A,(InsFlg)
  2474.     JR    NZ,RstI1
  2475.     CPL            ;kludge for last char ^V
  2476. RstI1:    LD    HL,SavIns
  2477.     CP    (HL)
  2478.     CALL    NZ,IToggl    ;if it has changed
  2479.     RET
  2480. ;
  2481. ;Conditional Q/L for formatting etc.
  2482. ;
  2483. ;
  2484. XQuiet:    LD    HL,ShutUp
  2485.     LD    A,(HL)
  2486.     LD    (HL),0C9H    ;(RET)
  2487.     LD    (SavQ),A
  2488.     RET
  2489. XLoud:    LD    A,(SavQ)
  2490.     OR    A        ;(NOP)
  2491.     RET    NZ
  2492.     LD    (ShutUp),A
  2493.     RET            ;do NOT need redisp here
  2494. ;
  2495. ;Force loud for header display
  2496. ;
  2497. Force:    LD    HL,ShutUp
  2498.     LD    A,(HL)
  2499.     LD    (HL),00H    ;(NOP)
  2500.     LD    (SavQ2),A
  2501.     RET
  2502. UForce:    LD    A,(SavQ2)
  2503.     CP    0C9H        ;(RET)
  2504.     RET    NZ
  2505.     LD    (ShutUp),A
  2506.     RET
  2507. ;
  2508. ;
  2509. ;END of Module 1
  2510.