home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / mskermit / msyap3.asm < prev    next >
Assembly Source File  |  2020-01-01  |  80KB  |  1,752 lines

  1.         NAME msyap3
  2. ; File MSYAP3.ASM;
  3.  
  4. ; NEC APC III system dependent module (taken from msyibm.asm).
  5. ;  Much EGA and other screen support commented out from ibm code.
  6. ; NEC modifications by Robert F. Goeke
  7. ; Last Edit: 14 March 1988
  8. ; edit history:
  9. ; 15 Mar 1988 Incorporate latest IBM mods for NEC
  10.  
  11. ; Following comments from msyibm.asm code:
  12. ; 5 Jan 1988 Restore cursor codes broken by Tek code additions. [jrd]
  13. ; 1 Jan 1988 version 2.30
  14. ; 24 Dec 1987 Restore startup screen attributes at Kermit prompts. [jrd]
  15. ; 21 Dec 1987 Fix memory size sign problem for >640K systems. From Edgar Butt
  16. ; 4 Dec 1987 cleanup mode switching, add more Video 7 material. [jrd]
  17. ; 8 Nov 1987 Add EGA mode switching, from Terry Kennedy.
  18. ; 1 Nov 1987 Add support for Tektronix, based on work by Brian Holley. [jrd]
  19. ; 13 Oct 1987 Revise memory allocation sequence to avoid small holes. [jrd]
  20. ; 2 Oct 1987 Make log file character width match Set Display but 8 bits when
  21. ;  debugging. [jrd]
  22. ; 12 Sept 1987 clarify sequence of translation and 8 bit display. [jrd]
  23. ; 27 Aug 1987 Do Translation before logging. [jrd]
  24. ; 18 Aug 1987 Change ESC to escape for MASM 4.5+ [jrd]
  25. ; 28 July 1987 Fix scron problem in screen save. [jrd]
  26. ; 23 June 1987 Add plain_attribute macro; fix bug in circular buffer
  27. ;  routines which kept attributes from being stored (and replayed)
  28. ; 8 June 1987 Add keypad application mode tests to emit single chars. [jrd]
  29. ; 6 June 1987 Adapt to most recent msyibm file (keyboard translator et al)
  30. ;  [jrd]
  31. ; 10 May 1987 Move input translation into terminal emulator, leave copy
  32. ;  here for terminal type None, use mszibm byte anspflg to sense print
  33. ;  screen is active, print translated characters but don't translate if
  34. ;  debugging is active. [jrd]
  35. ; 28 March 1987 Make low_rgt screen coord word a global parameter.
  36. ;  Add support for variable length screens and cursor size changes with
  37. ;  EGA boards. Tests ok with 25, 35, 43, 50 lines with &/without MS Windows.
  38. ;  EGA Memory locations 40:84H and 40:87H are used in this process.
  39. ;  Use savadr dw as place to save screen: usually screen page 1 if screen
  40. ;  dimensions are non-standard (80x25), else memory buffer scrsav. [jrd]
  41. ; 21 March 1987 Translate arriving Connect mode chars via table rxtable. [jrd]
  42. ;  Add 132 Column support for Tseng Labs EVA board via procedure chgdsp,
  43. ;  add restore scrolled screen before writing to it. From David L. Knoell [dlk]
  44. ; Modify msy and msz to use variable screen length and widths. [dlk] and [jrd]
  45. ; 17 March 1987 Reduce screen roll back buffer to half the memory to do the
  46. ;  same number of screens. [jrd]
  47. ; 12 Jan 1987 Add keyboard translator, remove older code. [jrd]
  48. ; 1 Oct 1986 Version 2.29a
  49.  
  50.         public  term, lclyini                      ; entry points
  51.         public  prtbout, prtnout, csrtype, scrmod, scrseg, scrsync
  52.         public  scroff, scron, atsclr, vtscru, vtscrd, scrloc, trnmod, telmsy
  53.         public  chgdsp, vtroll
  54.                         ; action verb procedures for keyboard translator
  55.         public  uparrw, dnarrw, rtarr, lfarr, pf1, pf2, pf3, pf4
  56.         public  kp0, kp1, kp2, kp3, kp4, kp5, kp6, kp7, kp8, kp9
  57.         public  kpminus, kpcoma, kpenter, kpdot, chrout, cstatus, cquit
  58.         public  cquery, dmpscn, vtans52, vtinit, dnwpg, upwpg, endwnd, homwnd
  59.         public  upone, dnone, trnprs, dumpscr, modlin, modwrt, snull
  60.         public  klogon, klogof, cdos, chang
  61.  
  62.         public  vtemu, crt_mode, scbattr, refresh, low_rgt  ; data
  63.     public  crt_cols, crt_lins, savescr, restscr, getflgs
  64.         include mssdef.h
  65.  
  66. ; some definitions
  67. ; NEC APC III hardware
  68. screen  equ     19h                     ; bios screen call
  69. kb      equ     18h                     ; keyboard interrupt
  70. vram    equ     0A000H                  ; Video Ram
  71. alt_shift equ   8H                      ; alt shift key down
  72. ctl_shift equ   4H                      ; ctl key down
  73. left_shift equ  2H                      ; left shift key down
  74. ; right_shift equ 1H                      ; right shift key down
  75. func_shift equ  1H                      ; an NEC mod                    RFG
  76.  
  77. biostty equ     0eh                     ; Bios screen tty write mode [jrd]
  78.  
  79. modfrm  struc                           ; format of mode (status) line
  80.         db      'Esc-chr: '             ; do not write in last column.
  81. m_echr  db      2 dup (?)
  82.         db      '  help: '
  83. m_hlp   db      2 dup (?)
  84.         db      '?  port:'
  85. m_prt   db      1 dup (?)
  86.         db      ' speed:'
  87. m_baud  db      5 dup (?)
  88.         db      ' parity:'
  89. m_par   db      4 dup (?)
  90.         db      ' echo:'
  91. m_echo  db      3 dup (?)
  92. m_term  db      13 dup (' ')            ; 13 bytes for term type
  93. m_prn   db      3 dup (' ')             ; show PRN when printer is on [jrd]
  94. modfrm  ends
  95.  
  96. ; This macro flips the rev_video bit of attribute in ah.    RFG
  97. ; NB this neither changes any other attribute nor any other register
  98. flip_rev_video  macro
  99.                 local   flip,flop
  100.                 test    ah,att_rev_video
  101.                 jnz     flip
  102.                 or      ah,att_rev_video
  103.                 jmp     flop
  104. flip:           and     ah,not att_rev_video
  105. flop:           nop
  106.                 endm
  107.  
  108. ; This macro makes takes the character attributes in ah and makes them plain
  109. ; Different than IBM case 'cause we don't really have "intensity".       RFG
  110. plain_attribute macro
  111.                 and     ah,not(att_overline+att_blink+att_underline)
  112.                 endm
  113.  
  114. att_overline    equ     01H             ; this is all NEC version stuff RFG
  115. att_blink       equ     02H
  116. att_rev_video   equ     04H
  117. att_underline   equ     08H
  118. att_intensity   equ     04H             ; same as reverse video
  119.  
  120. datas   segment public 'datas'
  121.         extrn flags:byte, mar_top:byte, mar_bot:byte, portval:word
  122.         extrn filtst:byte, dmpname:byte, kbdflg:byte, rxtable:byte
  123.         extrn anspflg:byte, tekflg:byte
  124.  
  125. ; stuff for screen routines
  126. yflags  db      ?                       ; status flags...
  127. flags1  db      0                       ; internal flags (but used in mszibm).
  128. prtscr  equ     1                       ; print screen pressed
  129. inited  equ     08h                     ; been here before...
  130. vtinited db     0                       ; flag for emulator having been inited
  131. cursor  dw      ?
  132. esc_ch  db      ?
  133. parmsk  db      ?                       ; 8/7 bit parity mask, for reception
  134. argadr  dw      ?                       ; address of arg blk
  135.  
  136. savadr  dw      2 dup (?)               ; offset then segment of saved screen
  137. savflg  dw      ?                       ; low_rgt at time of screen save
  138.  
  139.  
  140. vtemu   emulst  <>                      ; emulator flags [jrd]
  141. ansflgs db      0                       ; ANSI flags
  142. trmtyp  db      0                       ; most recent terminal type
  143. mtty    db      '  TTY   '              ; no terminal type (mode line)
  144.  
  145. lincur  dw      ?                       ; cursor type save area
  146. scbattr db      ?                       ; Screen background attribute
  147. oldattr db      ?                       ; screen attributes at init time
  148. curattr db      ?                       ; current attribute
  149. temp    dw      ?                       ; scratch storage
  150. modtemp db      0                       ; temp to hold Kermit modeline status
  151. captrtn dw      ?                       ; routine to call for captured output
  152. dmphand dw      ?                       ; screen dump file handle 
  153. dumpbuf db      132 dup (?), cr, lf     ; 134 byte dump work buffer
  154. dumpsep db      FF,cr,lf                ; screen image separators
  155. dmperr  db      ' Cannot open file to save screen to disk $'
  156. crlf    db      cr,lf,'$'
  157.  
  158. ; some static data for mode line
  159. modbuf  modfrm  <>                      ; mode line buffer
  160. unkbaud db      'unkwn'                 ; must be 5 chars...
  161. baudn   db      ' 45.5',' 50  ',' 75  ',' 110 ','134.5',' 150 ',' 300 ',' 600 '
  162.         db      ' 1200',' 1800',' 2000',' 2400',' 4800',' 9600','19200','38400'
  163.         db      '57.6K','115 K'
  164. baudnsiz  equ   18                      ; # of baud rates known (tbl size / 4)
  165. parnams db      'even','mark','none','odd ','spc '
  166. lclmsg  db      'loc'
  167. remmsg  db      'rem'
  168. portno  db      ?
  169.  
  170. ; storage for multi-window stuff
  171. swidth  equ     80                      ; max screen width
  172. slen    equ     24                      ; and length of text
  173. npages  equ     10                      ; # of pages of scrolling on each side
  174. crt_norm db     ?                       ; video mode for normal screen
  175. crt_mode db     ?                       ; video mode (typ 3, must be text)
  176. crt_cols db     ?                       ; number of screen columns (typ 80)
  177. crt_lins db     24                      ; number of screen rows - 1 (typ 24)
  178. low_rgt dw      ?                       ; lower right corner of text window
  179.                                         ; high = row address (typ 23)
  180.                                         ; low = column address (typ 79)
  181. inipara dw      ?                       ; initial paragraphs of scroll memory
  182. refresh db      0                       ; screen refresh (0=wait for retrace)
  183. vtroll  db      0                       ; auto roll back allowed (0 = no).
  184.  
  185. ; circular buffer for screen roll back.
  186. cbuf    struc
  187. pp      dw      ?                       ; place ptr in buffer
  188. bend    dw      ?                       ; end of buffer
  189. orig    dw      ?                       ; buffer origin
  190. lcnt    dw      0                       ; # of lines in buffer.
  191. lmax    dw      ?                       ; max lines of buffer. [jrd]
  192. cbuf    ends
  193.  
  194. twnd    cbuf    <>                      ; top screen spill-buffer struct
  195. bwnd    cbuf    <>                      ; bottom screen spill buffer struct
  196.  
  197. datas   ends
  198.  
  199. code    segment public 'code'                   ; code segment
  200.         extrn   beep:near, prtchr:near, outchr:near, sbrk:near, pcwait:near
  201.         extrn   isfile:near, strlen:near, strcpy:near   ; in mssfil
  202.         extrn   anstty:near,ansini:near,ansrei:near     ; in mszibm
  203.         extrn   anstat:near,anskbi:near,ansdsl:near     ; in mszibm
  204.         extrn   ans52t:near, vsinit:near                ; in mszibm
  205.         extrn   msuinit:near, keybd:near                ; in msuibm
  206.         extrn   tekini:near,tekcls:near,tekemu:near,tekend:near ;in msgibm
  207.  
  208.         assume  cs:code, ds:datas, es:datas
  209.  
  210. ; do initialization local to this module...
  211. ; Dynamically allocates 4000 bytes for screen save/restore buffer plus
  212. ;  320 to 38400 bytes for screen scroll back buffers. Tries to leave space
  213. ;  for Command.com before enlarging buffers. [jrd]
  214. ; delete screen dump memory allocation; see savescr                     RFG
  215. lclyini proc    near
  216.         call    msuinit                 ; initialize keyboard module msuxxx
  217.         mov     ax,swidth               ; ask for two lines (1 per buffer)
  218.         add     ax,ax
  219.         add     ax,ax                   ; times four (2 lines of char + attrib)
  220.         call    sbrk                    ; allocate mem. Exit Kermit on failure
  221.                                         ;if we get here them we have the lines
  222.         mov     bwnd.orig,ax            ; memory segment, bottom window area
  223.         mov     twnd.orig,ax            ; top. same place for both buffers!
  224.         push    es                      ; save this register.
  225.         mov     es,ax                   ; seg pointer to new memory block
  226.         mov     bx,(swidth*slen*npages+7)/8 ; paragraphs wanted for roll back
  227.         add     bx,24000D/16            ; plus paragraphs to run Command.com
  228.         mov     ah,setblk               ; DOS Setblock. Ask for that space.
  229.         int     dos                     ; bx has # paragraphs available
  230.         sub     bx,24000D/16            ; deduct space for DOS 3.x Command.Com
  231.         cmp     bx,(swidth*4+15)/16     ; any room left for buffers?
  232.         jae     lclyin2                 ; some space is available for buffers
  233.         mov     bx,(swidth*4+15)/16     ; else use our sbrk allocation
  234. lclyin2:mov     ah,setblk               ; ask for that many (bx) paragraphs
  235.         int     dos                     ; Errors here == DOS deceived us.
  236.         pop     es                      ; restore reg.
  237.         mov     ax,bx                   ; bx = # paragraphs allocated by DOS
  238.         mov     inipara,bx              ; save for later resizing of buffers
  239.         mov     cl,3                    ; 2**3 = 8
  240.         shl     ax,cl                   ; paragraphs to words (char + attrib)
  241.         xor     dx,dx                   ; clear extended size
  242.         mov     cx,swidth               ; number of chars per line in buffer
  243.         div     cx                      ; ax = number of lines in buffer
  244.         mov     bwnd.lmax,ax            ; max lines per buffer (quotient)
  245.         mov     twnd.lmax,ax            ; max lines per buffer
  246.         add     cx,cx                   ; count char and attribute per item
  247.         xor     dx,dx                   ; clear extended numerator
  248.         mul     cx                      ; ax = effective # bytes per buffer
  249.         dec     ax                      ; adjust for counting from zero
  250.         mov     bwnd.bend,ax            ; offset of last byte in buffer
  251.         mov     twnd.bend,ax            ; offset of last byte in buffer
  252.         mov     bwnd.pp,0               ; offset of first byte in buffer
  253.         mov     twnd.pp,0               ; offset of first byte in buffer
  254.         mov     bwnd.lcnt,0             ; number of lines occupied in buffer
  255.         mov     twnd.lcnt,0             ; number of lines occupied in buffer
  256.         call    scrseg                  ; test running in an Environment
  257.         call    scrmod                  ; read video state, get crt_mode.
  258.         mov     ah,8                    ; read current attributes
  259.         xor     bh,bh                   ; page 0
  260.         int     screen
  261.         mov     scbattr,ah              ; save video attributes
  262.         mov     oldattr,ah              ; and here too
  263.         call    vsinit                  ; init terminal emulator module MSZ
  264.         ret
  265. lclyini endp
  266.  
  267. scrini  proc    near                    ; init screen stuff
  268.         call    scrmod                  ; get screen mode, low_rgt
  269.         mov     ah,3                    ; get cursor position and char.
  270.         xor     bh,bh                   ; page 0
  271.         int     screen
  272.         mov     lincur,cx               ; save cursor type (scan line #'s)
  273.         mov     dx,cursor               ; assume old cursor
  274.         test    flags1,inited           ; have we been here before?
  275.         jnz     scrin4                  ; nz = yes, use old cursor
  276.         mov     ah,oldattr              ; get init time attributes
  277.         mov     curattr,ah              ; and set nice screen attribute
  278.         mov     scbattr,ah
  279.         mov     ah,3                    ; figure out where cursor is
  280.         xor     bh,bh                   ; page 0
  281.         int     screen                  ; read cursor position, in dx
  282. scrin4: cmp     dh,byte ptr low_rgt+1   ; past logical end of screen?
  283.         jb      scrin2                  ; b = no, keep going
  284.         mov     dh,byte ptr low_rgt+1   ; yes, just use lower right corner
  285. scrin2: cmp     dl,byte ptr low_rgt     ; maybe past right margin
  286.         jb      scrin3                  ; b = no, use the way it is
  287.         mov     dl,byte ptr low_rgt
  288. scrin3: mov     cursor,dx               ; init cursor
  289.         mov     ah,2                    ; set cursor position
  290.         xor     bh,bh                   ; page zero
  291.         int     screen                  ; set cursor in case it moved
  292.         ret
  293. scrini  endp
  294.  
  295. ; Routine to initialize terminal emulator. Call once.
  296.  
  297. vtinit  proc    near
  298.         cmp     flags.vtflg,0           ; doing emulation?
  299.         je      vtinix                  ; e = no
  300.         cmp     tekflg,0                ; Tek mode active?
  301.         jne     vtini2                  ; ne = yes, do it's reinit
  302.         or      vtinited,inited
  303.         call    ansflg                  ; update ansi flags
  304.         mov     al,yflags               ; Pass the flags.
  305.         mov     bx,argadr               ; Get address of argument block
  306.         mov     dl,[bx].baudb           ; Baud rate code in dl
  307.         mov     dh,[bx].parity          ; Parity code in bits
  308.         mov     cl,4                    ; 0-3 of dh
  309.         shl     dh,cl
  310.         test    flags.remflg,d8bit      ; eight bit display?
  311.         jnz     vtini1                  ; nz = yes
  312.         or      dh,07H                  ; Just say 7 data bits.
  313.         call    ansini                  ; call startup routine in mszibm.
  314.         ret
  315. vtini1: or      dh,8                    ; say 8 bits
  316.         call    ansini
  317. vtinix: clc
  318.         ret
  319. vtini2: call    tekcls                  ; clear Tek screen
  320.         clc
  321.         ret
  322. vtinit  endp
  323.  
  324.  
  325. argini  proc    near                    ; read passed arguments
  326.         mov     bx,argadr               ; base of argument block
  327.         mov     al,[bx].flgs            ; get flags
  328.         and     al,capt+emheath+havtt+trnctl+lclecho+modoff+lnwrap
  329.         mov     yflags,al               ; mask for allowable and save
  330.         mov     al,[bx].prt
  331.         mov     portno,al               ; update port number
  332.         mov     al,[bx].rows
  333.         mov     crt_lins,al             ; init # of rows and cols
  334.         mov     ax,[bx].captr
  335.         mov     captrtn,ax              ; buffer capture routine
  336.         mov     al,[bx].escc
  337.         mov     esc_ch,al
  338.         mov     parmsk,0ffh             ; parity mask, assume parity = None
  339.         cmp     [bx].parity,parnon      ; is parity None?
  340.         je      argini1                 ; e = yes, keep all 8 bits
  341.         mov     parmsk,07fh             ; else keep lower 7 bits
  342. argini1:ret                ; that's it
  343.  
  344. argini  endp
  345.  
  346. modlin  proc    near                    ; turn on mode line
  347.         mov     al,esc_ch
  348.         mov     modbuf.m_echr,' '       ; first char is initial space
  349.         mov     modbuf.m_hlp,' '        ; goes here too.
  350.         cmp     al,32                   ; printable?
  351.         jnb     modl1                   ; yes, keep going
  352.         add     al,40h                  ; made printable
  353.         mov     modbuf.m_echr,5eh       ; caret, note control char
  354.         mov     modbuf.m_hlp,5eh
  355. modl1:  mov     modbuf.m_echr+1,al      ; fill in character
  356.         mov     modbuf.m_hlp+1,al
  357.         mov     bx,argadr               ; get argument block
  358.         mov     al,[bx].baudb           ; get baud bits
  359.         mov     si,offset unkbaud       ; assume unknown baud
  360.         cmp     al,baudnsiz             ; too big?
  361.         jnb     modl2                   ; nb = yes, use default
  362.         mov     cl,size m_baud          ; each is 5 bytes long
  363.         mul     cl
  364.         mov     ah,0
  365.         add     ax,offset baudn
  366.         mov     si,ax
  367. modl2:  mov     cx,size m_baud          ; length of baud space
  368.         mov     di,offset modbuf.m_baud
  369.         push    es                      ; save es
  370.         push    ds
  371.         pop     es                      ; set es to datas segment
  372.         cld
  373.         rep     movsb                   ; copy in baud rate
  374.         mov     al,[bx].parity          ; get parity code
  375.         mov     cl,2                    ; each is 4 bytes long...
  376.         shl     al,cl
  377.         mov     ah,0
  378.         add     ax,offset parnams       ; names of parity settings
  379.         mov     si,ax
  380.         mov     cx,4                    ; each is 4 long
  381.         mov     di,offset modbuf.m_par
  382.         rep     movsb
  383.         mov     si,offset remmsg        ; Assume remote echoing.
  384.         test    yflags,lclecho          ; Is remote side echoing?
  385.         jz      modl4                   ; Yes, keep going
  386.         mov     si,offset lclmsg        ; Else it's local echoing.
  387. modl4:  mov     cx,3                    ; size of on/off
  388.         mov     di,offset modbuf.m_echo
  389.         rep     movsb
  390.         mov     al,portno               ; communications port
  391.         cmp     al,' '                  ; binary (non-printable)?
  392.         jae     modl5                   ; ae = no, ascii
  393.         add     al,'0'                  ; convert to ascii
  394. modl5:  mov     modbuf.m_prt,al         ; fill in port number
  395.         mov     cx,8                    ; blank out terminal id field
  396.         mov     si,offset mtty          ; assume no terminal emulation.
  397.         mov     di,offset modbuf.m_term ; destination
  398.         rep     movsb                   ; copy it in.
  399.         mov     modbuf.m_prn,' '        ; assume not printing the screen [jrd]
  400.         mov     modbuf.m_prn+1,' '
  401.         mov     modbuf.m_prn+2,' '
  402.         test    anspflg,prtscr          ; doing a print the screen?
  403.         jz      modl5a                  ; z = no.
  404.         mov     modbuf.m_prn,'P'        ; yes. display PRN at end of line
  405.         mov     modbuf.m_prn+1,'R'
  406.         mov     modbuf.m_prn+2,'N'
  407. modl5a: mov     cx,size modfrm          ; this is size of mode line
  408.         mov     si,offset modbuf        ; mode line image
  409.         pop     es
  410.                         ; alternate entry to write an alternate mode line
  411. modwrt: push    cx
  412.         push    si                      ; save mode line and size
  413.         mov     ah,3                    ; read cursor position
  414.         xor     bx,bx                   ; screen page 0
  415.         int     screen
  416.         mov     cursor,dx               ; save cursor position
  417.         call    trmatt                  ;[IU2] Get terminal attributes
  418.         plain_attribute
  419.         mov     bh,ah                   ; get video attribute
  420.         mov     dx,low_rgt              ; right most column
  421.         inc     dh                      ; refer to status line
  422.         mov     ch,dh                   ; bottom line [dlk]
  423.         mov     cl,0                    ; left col = 0 (first) [dlk]
  424.         mov     ax,600h                 ; scroll to clear the line
  425.         int     screen
  426.         mov     dh,byte ptr low_rgt+1   ; refer to status line
  427.         inc     dh
  428.         xor     dl,dl                   ; left most column
  429.         mov     bh,0
  430.         mov     ah,2                    ; set cursor position
  431.         int     screen
  432.         pop     si
  433.         pop     cx                      ; restore these
  434.         cmp     cl,crt_cols             ; mode line longer than screen?
  435.         jbe     modl6                   ; le = no
  436.         mov     cl,crt_cols             ; else do just one line's worth [jrd]
  437.         dec     cx                      ; don't let screen scroll
  438. modl6:  cld
  439.         lodsb                           ; get a byte
  440.         push    si                      ; RFG
  441.         mov     ah,14                   ; write to terminal
  442.         mov     bh,0                    ; page 0
  443.         int     screen
  444.         pop     si                      ; RFG
  445.         loop    modl6                   ; write out entire mode line
  446.         cmp     flags.vtflg,0           ; emulating?
  447.         je      modl7                   ; e = no
  448.         and     yflags,not modoff       ; update local flags (mode line on)
  449.         mov     al,yflags               ; Yes - update flags also
  450.         call    ansdsl                  ; get extras from emulator
  451. modl7:  mov     dx,cursor
  452.         mov     ah,2
  453.         mov     bh,0
  454.         int     screen                  ; put cursor back where it belongs
  455.         ret                             ; and return
  456. modlin  endp
  457.  
  458. clrmod  proc    near                    ; clear mode line
  459.     cmp    flags.vtflg,tttek    ; NEC -- a precaution only
  460.     je    clrmodx
  461.         call    trmatt                  ; Get terminal screen attributes
  462.         mov     bh,al                   ; Use screen background attribute
  463.         mov     ax,600h                 ; blank window
  464.         mov     dx,low_rgt              ; right most column
  465.         inc     dh                      ; refer to status line
  466.         mov     cx,dx                   ; bottom line [dlk]
  467.         xor     cl,cl                   ; left most column
  468.         int     screen                  ; clear mode line
  469. clrmodx: ret                            ; and return
  470. clrmod  endp
  471.  
  472.  
  473. ; Fetch screen attributes from emulator (if emulating). It exists mainly
  474. ; so that the reverse video will work.   Returns the current mode
  475. ; line background attribute in ah, the current screen background in al,
  476. ; and the current "cursor" (foreground) attribute in bl.  (Note: anstat
  477. ; returns status yflags in bh).
  478.  
  479. trmatt  proc    near                    ; Get attributes
  480.         cmp     flags.vtflg,0           ; emulating? [jrd]
  481.         je      trmat1                  ; No, just do simple stuff.
  482.         mov     al,yflags               ; anstat expects flags byte in al.
  483.         call    anstat                  ; Fetch emulator status/attributes
  484.         ret
  485. trmat1: mov     al,scbattr              ; Background attributes. [jrd]
  486.         mov     bl,curattr              ; And cursor attribute.
  487.         mov     ah,al                   ; where modlin needs them [jrd]
  488.         plain_attribute
  489.         flip_rev_video                  ; reverse the video
  490.         ret
  491. trmatt  endp
  492.  
  493. ; Get byte yflags of terminal emulator passed in AL. Used in mode line
  494. ; handling when 25th line is used by the emulator.
  495. telmsy  proc    near
  496.         mov     yflags,al               ; get the updated flags
  497.         call    ansflg                  ; and any other emulator info
  498.         ret
  499. telmsy  endp
  500.  
  501.  
  502. ;[IU2] This routine updates the ANSI status flags from the emulator,
  503. ; and passes the "yflags" byte to the VT100 emulator also.
  504.  
  505. ansflg  proc    near
  506.         push    ax                      ; Save acs over call
  507.         push    bx
  508.         mov     al,yflags
  509.         call    anstat                  ; Get status and attributes
  510.         mov     ansflgs,bh              ; Save.
  511.         pop     bx
  512.         pop     ax
  513.         ret
  514. ansflg  endp
  515.  
  516. getflgs proc    near                    ; supply yflags for terminal emulators
  517.         mov     al,yflags
  518.         ret
  519. getflgs endp
  520.  
  521. term    proc    near                    ; terminal mode entry point
  522.         mov     argadr,ax               ; save argument ptr
  523.         call    argini                  ; init options from arg address
  524.         call    scrini                  ; init screen stuff
  525.  
  526.         test    flags1,inited           ; have we run yet?
  527.         jz      term1                   ; z = no, so no saved screen yet
  528.         call    restscr                 ; restore screen
  529. term1:  or      flags1,inited           ; remember we've run already.
  530.         cmp     flags.vtflg,0           ; current terminal type = None?
  531.         je      term3a                  ; e = yes, nothing to init.
  532.         mov     al,yflags               ; tell emulator we are back
  533.         cmp     vtinited,inited         ; inited emulator yet?
  534.         je      term3                   ; e = yes
  535.         cmp     tekflg,0                ; Tek mode still active?
  536.         jne     term3a                  ; ne = yes, no re-init here
  537.         call    vtinit                  ; init it now
  538.         jmp     term3a
  539. term3:  call    ansrei                  ; reinit the emulator
  540.         call    ansflg                  ; and get its flags
  541. term3a: cmp     flags.modflg,0          ; is mode line disabled?
  542.         je      term2a                  ; e = yes, disabled
  543.         cmp     flags.vtflg,0           ; emulating a terminal?
  544.         jne     term1a                  ; ne = yes, can have mode line
  545.         cmp     trmtyp,0                ; previous terminal type = none?
  546.         jne     term2                   ; ne = no. need to clear mode line.
  547.         jmp     term2a                  ; yes, let 25th line be intact
  548. term1a: test    yflags,modoff           ; is mode line toggled off?
  549.         jnz     term2                   ; nz = yes, clear the line.
  550.         cmp     flags.vtflg,tttek       ; going to be a Tek terminal?
  551.         je      term2a                  ; e = yes, no mode line
  552.         call    modlin                  ; turn on mode line
  553.         jmp     term2a
  554. term2:  call    clrmod                  ; ensure its off
  555. term2a: mov     al,flags.vtflg          ; current terminal type
  556.         mov     trmtyp,al               ; place to remember it til next time
  557.         cmp     flags.vtflg,tttek       ; Tek mode?
  558.         je      term4                   ; e = yes
  559.         cmp     tekflg,0                ; Tek mode active within DEC stuff?
  560.         je      lp                      ; e = no
  561. term4:  call    tekini                  ; reinit to get graphics screen
  562.  
  563. lp:     call    portchr                 ; char at port?
  564.          jnc    chkinp                  ; nc = no, keep going
  565.          nop
  566.         call    outtty                  ; print on terminal
  567.  
  568. chkinp: call    keybd                   ; call keyboard translator in msu
  569.         jnc     lp                      ; nc = no char or have processed it
  570.                                         ; carry set = quit Connect mode.
  571.  
  572. quit:   call    tekend
  573.     mov     ah,3                    ; get cursor position
  574.         xor     bh,bh                   ; page 0
  575.         int     screen
  576.         mov     cursor,dx               ; save position
  577.         call    savescr                 ; save screen
  578.         cmp     flags.vtflg,0           ; emulating?
  579.         je      quit1                   ; e = no
  580.         call    clrmod                  ; erase mode line
  581. quit1:  mov     ah,oldattr              ; attributes at init time
  582.         mov     scbattr,ah              ; background = original state [jrd]
  583.                                         ; for ega in non-standard # lines
  584.         mov     cx,lincur               ; cursor type at startup
  585.         mov     ah,1
  586.         int     screen                  ; restore cursor type
  587. quit3:
  588.         mov     ah,2                    ; Position cursor
  589.         mov     bh,0                    ; Page 0
  590.         mov     dx,low_rgt              ; bottom line
  591.         inc     dh                      ; status line position
  592.         xor     dl,dl                   ; left most column
  593.         int     screen                  ; Do it.
  594.  
  595.         mov     al,yflags
  596.         mov     bx,argadr
  597.         mov     [bx].flgs,al            ; update flags in arg block
  598.         ret                             ; and return to caller
  599. term    endp
  600.  
  601. ; put the character in al to the screen
  602. outtty  proc    near
  603.         cmp     flags.vtflg,0           ; emulating a terminal?
  604.         jne     outnoc                  ; ne = yes, emulator handles printing
  605.         test    flags.remflg,d8bit      ; keep 8 bits for displays?
  606.         jnz     outnp9                  ; nz = yes, 8 bits if possible
  607.         and     al,7fh                  ; remove high bit
  608. outnp9: cmp     rxtable+256,0           ; translation turned off?
  609.         je      outnp7                  ; e = yes, no translation
  610.         push    bx
  611.         mov     bx,offset rxtable       ; address of translate table
  612.         xlatb                           ; new char is in al
  613.         pop     bx
  614. outnp7: test    anspflg,prtscr          ; should we be printing?
  615.         jz      outnop                  ; no, keep going
  616.         push    ax
  617.         mov     ah,lstout               ; write to system printer device
  618.         mov     dl,al
  619.         int     dos
  620.         pop     ax
  621.         jnc     outnop                  ; nc = successful print
  622.         push    ax
  623.         call    beep                    ; else make a noise and
  624.         call    trnprs                  ;  turn off printing
  625.         pop     ax
  626. outnop: test    yflags,capt             ; capturing output?
  627.         jz      outnoc                  ; no, forget this part
  628.         push    ax                      ; save char
  629.         call    captrtn                 ; give it captured character
  630.         pop     ax                      ; restore character and keep going
  631. outnoc: cmp     tekflg,0                ; Tek mode active?
  632.         jne     outnp6                  ; ne = yes, skip screen rolling
  633.         cmp     vtroll,0                ; auto roll back allowed?
  634.         jz      outnp6                  ; z = no, leave screen as is.
  635.         cmp     bwnd.lcnt,0             ; is screen rolled back? [dlk]
  636.         je      outnp6                  ; e = no
  637.         call    endwnd                  ; restore screen before writing [dlk]
  638. outnp6: cmp     flags.vtflg,0           ; emulating a terminal?
  639.         jnz     outnop1                 ; nz = yup, go do something smart
  640.         test    yflags,trnctl           ; debug? if so use Bios tty mode
  641.         jz      outnp4                  ; z = no
  642.         mov     ah,biostty              ; Bios tty screen write
  643.         cmp     al,7fh                  ; Ascii Del char or greater?
  644.         jb      outnp1                  ; b = no
  645.         je      outnp0                  ; e = Del char
  646.         push    ax                      ; save the char
  647.         mov     al,7eh                  ; output a tilde for 8th bit
  648.         int     screen
  649.         pop     ax                      ; restore char
  650.         and     al,7fh                  ; strip high bit
  651. outnp0: cmp     al,7fh                  ; is char now a DEL?
  652.         jne     outnp1                  ; ne = no
  653.         and     al,3fH                  ; strip next highest bit (Del --> '?')
  654.         jmp     outnp2                  ; send, preceded by caret
  655. outnp1: cmp     al,' '                  ; control char?
  656.         jae     outnp3                  ; ae = no
  657.         add     al,'A'-1                ; make visible
  658. outnp2: push    ax                      ; save char
  659.         mov     al,5eh                  ; caret
  660.         int     screen                  ; display it
  661.         pop     ax                      ; recover the non-printable char
  662. outnp3: int     screen
  663.         ret
  664. outnp4: cmp     al,bell                 ; bell (Control G)? [jrd]
  665.         jne     outnp5                  ; ne = no
  666.         jmp     beep                    ; use short beep, avoid char loss.
  667. outnp5: mov     dl,al                   ; write without intervention.
  668.         mov     ah,conout
  669.         int     dos                     ; else let dos display char
  670.         ret                             ; and return
  671.  
  672. outnop1:cmp     flags.vtflg,tttek       ; doing Tektronix emulation?
  673.         je      outnop2                 ; e = yes, use Tek emulator
  674.         cmp     tekflg,0                ; Tek submode active?
  675.         jne     outnop2                 ; ne = yes, use Tek emulator
  676.         jmp     anstty                  ; call terminal emulator routine & ret
  677. outnop2:jmp     tekemu                  ; use Tek emulator and return
  678.  
  679. outtty  endp
  680.  
  681. ; get shift state into al.  We care about only shift, ctl, and alt keys.
  682. ; right shift is collapsed into left shift.
  683. ; in NEC there is no left/right shift, but the right_shift code is used
  684. ;       to indicate FUNC                                        RFG
  685. gss     proc    near
  686.         mov     ah,2
  687.         int     kb                      ; get current shift state
  688.         mov     bl,al                   ; copy for a moment
  689.         and     al,(func_shift + left_shift + alt_shift + ctl_shift)
  690.         ret
  691. gss     endp
  692.  
  693. ;[IU2] Here to output character to port with no echo (like escape sequences
  694. ; sent by PF keys, responses to requests from the host, etc.   It is
  695. ; wrong thinking to echo these).
  696.  
  697. prtbout proc    near                    ; Global routine now.
  698.         mov     ah,al                   ; This is where outchr expects it
  699.     call    outchr
  700.          nop                            ; Ignore skip return.
  701.          nop
  702.          nop
  703.         ret
  704. prtbout endp
  705.  
  706.  
  707. ;[IU2] Here to output an unsigned 8-bit number (in al) to the port without
  708. ; echoing. Used by terminal emulator escape sequence output.
  709.  
  710. prtnout proc    near
  711.         mov     bl,10                   ; Output in base 10.
  712.         jmp     prtno2                  ; Ensure at least a zero.
  713.  
  714. prtno1: cmp     al,0
  715.         jne     prtno2                  ; Yes - do more digits
  716.         ret                             ; No - return from recursive call.
  717. prtno2: mov     ah,0                    ; Clear previous remainder.
  718.         div     bl                      ; Divide off a digit
  719.         push    ax                      ; Push remainder (in ah) on stack
  720.         call    prtno1                  ; Recur.
  721.         pop     ax                      ; Pop off a digit
  722.         add     ah,'0'                  ; Make it ASCII
  723.         call    outchr                  ; Output to port
  724.      nop
  725.      nop
  726.      nop
  727.         ret
  728. prtnout endp
  729.  
  730. ; send the character in al out to the serial port; handle echoing.
  731. ; Can send an 8 bit char while displaying only 7 bits locally.
  732. outprt  proc    near
  733.         test    yflags,lclecho          ; echoing?
  734.         jz      outpr1                  ; z = no, forget it
  735.         push    ax                      ; save char
  736.         call    outtty                  ; print it
  737.         pop     ax                      ; restore
  738. outpr1: mov     ah,al                   ; this is where outchr expects it
  739.         call    outchr                  ; output to the port
  740.          nop
  741.          nop
  742.          nop                            ; skip returns...
  743.         ret
  744. outprt  endp
  745.  
  746. ; returns with carry on if a character is available
  747.  
  748. portchr proc    near
  749.         call    prtchr                  ; character at port?
  750.          jmp    short portc1            ; yes, go handle
  751.          nop                            ; skip return is stupid...
  752. portc0: clc                             ; no carry -> no character
  753.         ret                             ; and return...
  754. portc1: and     al,parmsk               ; apply 8/7 bit parity mask [jrd]
  755.         stc                             ; have a character
  756.         ret                             ; and return
  757. portchr endp
  758.  
  759. ;;; Action routines (verbs) for keyboard translator KEYBD in msuibm.
  760. ; These are invoked by a jump instruction. Return carry clear for normal
  761. ; processing, return carry set for invoking Quit (kbdflg has transfer char).
  762. uparrw: mov     al,'A'                  ; cursor keys
  763.         jmp     short comarr
  764. dnarrw: mov     al,'B'
  765.         jmp     short comarr
  766. rtarr:  mov     al,'C'
  767.         jmp     short comarr
  768. lfarr:  mov     al,'D'
  769. comarr: push    ax                      ; save final char
  770.         mov     al,escape        ; Output an escape.
  771.     cmp    flags.vtflg,tttek    ; Tek terminal
  772.     je    comar0            ; e = yes, use VT100 codes
  773.         call    outprt                  ; Output, echo permitted
  774.         cmp     flags.vtflg,ttvt100     ; VT100 terminal emulation?
  775.         jne     comar2                  ; No, do VT52/HEATH-19 sequence.
  776. comar0: call    ansflg                  ; Update flags all around.
  777.         mov     al,'['                  ; Maybe this next?
  778.         test    ansflgs,decckm          ; Cursor key mode reset?
  779.         je      comar1                  ; Yes, output the "["
  780.         mov     al,'O'                  ; No, set, use the "O".
  781. comar1: call    outprt                  ; Output it (echo permitted).
  782. comar2: pop     ax                      ; recover final char
  783.         call    outprt                  ; Output to port (echo permitted)
  784.         clc
  785.         ret
  786.  
  787. pf1:    mov     al,'P'                  ; keypad function keys 1-4
  788.         jmp     short compf
  789. pf2:    mov     al,'Q'
  790.         jmp     short compf
  791. pf3:    mov     al,'R'
  792.         jmp     short compf
  793. pf4:    mov     al,'S'
  794. compf:  push    ax                      ; save final char
  795.         mov     al,escape                  ; Output an escape.
  796.         call    prtbout
  797.         call    ansflg                  ; get emulator flags
  798.         test    ansflgs,decanm          ; ansi mode?
  799.         jz      short compf1            ; z = no
  800.         mov     al,'O'                  ; send an "O".
  801.         call    prtbout                 ; Output it.
  802. compf1: pop     ax                      ; Get the saved char back
  803.         call    prtbout                 ; Output to port
  804.         clc
  805.         ret
  806.  
  807. kp0:    mov     al,'p'                  ; keypad numeric keys
  808.         jmp     short comkp
  809. kp1:    mov     al,'q'
  810.         jmp     short comkp
  811. kp2:    mov     al,'r'
  812.         jmp     short comkp
  813. kp3:    mov     al,'s'
  814.         jmp     short comkp
  815. kp4:    mov     al,'t'
  816.         jmp     short comkp
  817. kp5:    mov     al,'u'
  818.         jmp     short comkp
  819. kp6:    mov     al,'v'
  820.         jmp     short comkp
  821. kp7:    mov     al,'w'
  822.         jmp     short comkp
  823. kp8:    mov     al,'x'
  824.         jmp     short comkp
  825. kp9:    mov     al,'y'
  826.         jmp     short comkp
  827. kpminus:mov     al,'m'
  828.         jmp     short comkp
  829. kpcoma: mov     al,'l'
  830.         jmp     short comkp
  831. kpenter:mov     al,'M'
  832.         jmp     short comkp
  833. kpdot:  mov     al,'n'
  834. comkp:  test    ansflgs,deckpam         ; keypad application mode active?
  835.         jnz     comkp3                  ; nz = yes, use escape sequences
  836.         sub     al,40h                  ; deduct offset to numeric symbols
  837.         jmp     comkp0                  ; and send that single char
  838. comkp3: push    ax                      ; save final char
  839.         mov     al,escape                  ; Output an escape.
  840.         call    prtbout
  841.         mov     al,'O'                  ; Output the "O"
  842.         cmp     flags.vtflg,ttvt100     ; VT100 mode?
  843.         je      comkp1                  ; e = yes, use "O" code
  844.     cmp    flags.vtflg,tttek    ; Tek terminal
  845.     je    comkp1            ; e = yes, use VT100 codes
  846.         test    ansflgs,decanm          ; ANSI (alt application keypad) mode?
  847.         jnz     comkp1                  ; nz = yes, use "O"
  848. comkp2: mov     al,'?'                  ; else use "?" instead of "O".
  849. comkp1: call    prtbout
  850.         pop     ax                      ; recover final char
  851. comkp0: call    prtbout                 ; send it
  852.         clc
  853.         ret
  854.  
  855. klogon  proc    near                    ; resume logging (if any)
  856.         test    flags.capflg,logses     ; session logging enabled?
  857.         jz      klogn                   ; z = no, forget it
  858.         or      argadr.flgs,capt        ; turn on capture flag
  859.         or      yflags,capt             ; set local msy flag as well
  860.     call    ansflg
  861. klogn:  clc
  862.         ret
  863. klogon  endp
  864.  
  865. klogof  proc    near                    ; suspend logging (if any)
  866.         and     argadr.flgs,not capt    ; stop capturing
  867.         and     yflags,not capt         ; reset local msy flag as well
  868.     call    ansflg
  869. klogo:  clc
  870.         ret
  871. klogof  endp
  872.  
  873. snull   proc    near                    ; send a null byte
  874.         mov     al,0                    ; the null
  875.         call    prtbout                 ; send without logging and local echo
  876.         clc
  877.         ret
  878. snull   endp
  879.                                         ; general character out for emulator
  880. chrout: cmp     flags.vtflg,0           ; emulating?
  881.         je      chrou5                  ; e = no
  882.         call    anskbi                  ; Yes, say we had keyboard input.
  883.         cmp     al,cr                   ; A CR?
  884.         jne     chrou5                  ; No - just output it and return
  885.         call    ansflg                  ; Yes - update VT100 flags
  886.         test    ansflgs,anslnm          ; ANSI new-line mode set?
  887.         jz      chrou5                  ; No - just send the cr
  888.         call    outprt                  ; Yes - output a carriage-return
  889.         mov     al,lf                   ; Followed by a line feed.
  890. chrou5: call    outprt
  891.         clc
  892.         ret
  893.  
  894.                                         ; these commands invoke Quit
  895.  
  896. cdos:   mov     al,'P'                  ; Push to DOS
  897.         jmp     short cmdcom
  898. cstatus:mov     al,'S'                  ; Status
  899.         jmp     short cmdcom
  900. cquit:  mov     al,'C'                  ; Exit Connect mode
  901.         jmp     short cmdcom
  902. cquery: mov     al,'?'                  ; Help
  903.         jmp     short cmdcom
  904. chang:  mov     al,'H'                  ; Hangup, drop DTR & RTS
  905.         jmp     short cmdcom
  906. cmdcom: mov     kbdflg,al               ; pass char to msster.asm via kbdflg
  907.         stc                             ; signal that Quit is needed
  908.         ret
  909.  
  910. dmpscn  proc    near                    ; dump screen to file
  911.         call    savescr                 ; save screen to buffer
  912.         call    dumpscr                 ; do buffer to file
  913.         clc                             ; do not exit Connect mode
  914.         ret
  915. dmpscn  endp
  916.  
  917.  
  918. ; Routine to toggle VT100/VT52/Heath-19 modes in VT100 emulator.
  919.  
  920. vtans52 proc    near
  921.         cmp     flags.vtflg,0           ; emulating?
  922.         je      vtans5                  ; e = no
  923.         call    ans52t                  ; Call MSZ toggle-it routine.
  924.         call    ansflg                  ; Update flags.
  925.         clc                             ; clear c bit so don't exit Connect.
  926. vtans5: ret
  927. vtans52 endp
  928.                                         ; Toggle Mode Line
  929. trnmod: cmp     flags.modflg,0          ; is mode line enabled?
  930.         je      trnm2                   ; e = no, don't touch it
  931.     cmp    flags.vtflg,tttek    ; Tek mode?
  932.     je    trnm2            ; yes
  933.     cmp    tekflg,0        ; Tek submode?
  934.     jne    trnm2            ; ne = yes, no mode line changes
  935.         test    yflags,modoff           ; mode line already off?
  936.         jnz     trnm1                   ; yes, go turn on
  937.         call    clrmod                  ; no, clear mode line here
  938.         or      yflags,modoff           ; turn on flag
  939.         call    ansflg                  ; Update flags all around.
  940.         clc                             ; clear c bit so don't exit Connect
  941.         ret                             ; and return
  942. trnm1:  and     yflags,not modoff       ; Clear flag first.
  943.         call    modlin                  ; Then turn on mode line.
  944.         call    ansflg                  ; Update flags all around.
  945. trnm2:  clc
  946.     ret
  947.  
  948. trnprs: push    ax                      ; toggle ^ PrtSc screen to printer
  949.         test    anspflg,prtscr          ; are we currently printing?
  950.         jnz     trnpr2                  ; nz = yes, its on and going off
  951.         mov     ah,ioctl
  952.         mov     al,7                    ; get output status of printer
  953.         push    bx
  954.         mov     bx,4                    ; file handle for system printer
  955.         int     dos
  956.         pop     bx
  957.         jc      trnpr1                  ; c = printer not ready
  958.         cmp     al,0ffh                 ; Ready status?
  959.         je      trnpr2                  ; e = Ready
  960. trnpr1: call    beep                    ; Not Ready, complain
  961.         jmp     trnpr3                  ; and ignore request
  962. trnpr2: xor     anspflg,prtscr          ; flip the flag
  963.         test    yflags,modoff           ; mode line off?
  964.         jnz     trnpr3                  ; nz = yes
  965.         call    modlin                  ; else rewrite mode line
  966. trnpr3: pop     ax
  967.         clc                             ; return carry clear (don't quit)
  968.         ret
  969.  
  970. ;;;;; General screen management routines for NEC APC
  971.  
  972. ; computes screen location to ax, given row and col in [dh,dl], resp.
  973. ; trashes dx
  974. scrloc  proc    near
  975.         mov     al,dh                   ; get row
  976.         xor     ah,ah                   ; clear ah
  977.         mul     crt_cols                ; multiply by number of columns
  978.         xor     dh,dh                   ; clear row
  979.         add     ax,dx                   ; this is current position
  980.         shl     ax,1                    ; double for attributes
  981.         ret
  982. scrloc  endp
  983.  
  984. ; Routine to set cursor type.  Pass cursor type in al: 0 = No cursor,
  985. ; 1 = Underline cursor, 2 = Block cursor, 3 = restore cursor,
  986. ; 5 = No blink underline, 6 = No blink block.
  987. ; modified for NEC                                  RFG
  988.  
  989. csrtype proc    near
  990.         push    cx                      ; save the reg
  991.         mov     ah,1                    ; Video fxn for set cursor type
  992.         mov     cx,0707H                ; Set one line.
  993.         cmp     al,1                    ; Underline?
  994.         je      csrty2                  ; Right - then do it
  995.         or      cx,0400H                ; set for no blink
  996.         cmp     al,5                    ; is it this?
  997.         je      csrty2                  ; Right - then do it
  998.         mov     cx,0007H                ; set for block
  999.         cmp     al,2                    ; Block?
  1000.         je      csrty2                  ; Right - then do it
  1001.         or      cx,0400H                ; set for no blink
  1002.         cmp     al,5                    ; no-blink underline?
  1003.         je      csrty2                  ; Right - then do it
  1004.         cmp     al,0                    ; Disable cursor?
  1005.         je      csrty3                  ; Right - then do it
  1006.         jmp     csrty4                  ; last choice is enable
  1007. csrty2: int     screen                  ; Set it.
  1008.         pop     cx
  1009.         ret
  1010. csrty3: push    bx
  1011.         mov     ah,3                    ; BIOS call to read current
  1012.         mov     bh,0                    ;    current cursor status
  1013.         int     screen
  1014.         or      ch,80H                  ; Set disable bit
  1015.         mov     ah,1                    ; And set cursor
  1016.         pop     bx
  1017.         jmp     csrty2
  1018. csrty4: push    bx
  1019.         mov     ah,3
  1020.         mov     bh,0
  1021.         int     screen
  1022.         and     ch,7FH                  ; Clear disable bit
  1023.         mov     ah,1
  1024.         pop     bx
  1025.         jmp     csrty2
  1026. csrtype endp
  1027.  
  1028.  
  1029. ; Save the entire screen in a buffer so we can restore and/or dump it.
  1030. ; Saves regular (80x25) screens to memory buffer scrsav and other sized
  1031. ; screens to video memory page 1. Resultant save place put into savadr
  1032. ; (offset then segment) and current low_rgt size info in savflg. Note,
  1033. ; some Environments (TopView/Windows etc) may not permit use of page 1. [jrd]
  1034. ; modified for the NEC since text/attribute pattern is different.
  1035. ;       put image of Page 0 VRAM into Page 1 VRAM for the save  RFG
  1036. savescr proc    near
  1037.         push    ax
  1038.         push    bx
  1039.         push    cx
  1040.         push    dx
  1041.         push    di
  1042.         push    si
  1043.         push    ds
  1044.         push    es
  1045.         mov     ax,vram                 ; start of VRAM is A000:0000
  1046.         mov     savadr+2,ax             ; save segment in this word
  1047.         call    scrmod                  ; ascertain video mode and screen
  1048.         mov     ax,low_rgt              ; text screen lower right (typ 23,79)
  1049.         mov     savflg,ax               ; save it for screen restore
  1050.         mov     si,0                    ; this is Page 0, to be saved
  1051.         mov     di,1000H                ; this is Page 1, the save buffer
  1052.         mov     savadr,di               ; save offset in this word
  1053.         mov     cx,80*25
  1054.         mov     ax,vram
  1055.         mov     ds,ax
  1056.         mov     es,ax
  1057.         cld
  1058.         rep     movsw                   ; move the text page
  1059.         mov     si,2000H                ; this is Page 0, attributes
  1060.         mov     di,3000H                ; this is Page 1
  1061.         mov     cx,80*25
  1062.         rep     movsw                   ; move the attribute page
  1063.         pop     es
  1064.         pop     ds
  1065.         pop     si
  1066.         pop     di
  1067.         pop     dx
  1068.         pop     cx
  1069.         pop     bx
  1070.         pop     ax
  1071.         ret                             ; and return
  1072. savescr endp
  1073.  
  1074. ; restore screen from scrsav buffer. Restores all 25 lines. [jrd]
  1075. ; like savescr, modified for NEC                                RFG
  1076. restscr proc    near
  1077.         push    ax
  1078.         push    bx
  1079.         push    cx
  1080.         push    dx
  1081.         push    di
  1082.         push    si
  1083.         push    ds
  1084.         push    es
  1085.         mov     ax,vram                 ; start of VRAM is A000:0000
  1086.         mov     ds,ax
  1087.         mov     es,ax
  1088.         mov     si,1000H                ; this is Page 1, to be restored
  1089.         mov     di,0                    ; this is Page 0
  1090.         mov     cx,80*25
  1091.         rep     movsw                   ; move the text page
  1092.         mov     si,3000H                ; this is Page 1, attributes
  1093.         mov     di,2000H                ; this is Page 0
  1094.         mov     cx,80*25
  1095.         rep     movsw                   ; move the attributes
  1096.         pop     es
  1097.         pop     ds
  1098.         pop     si
  1099.         pop     di
  1100.         pop     dx
  1101.         pop     cx
  1102.         pop     bx
  1103.         pop     ax
  1104.         ret                             ; and return
  1105. restscr endp
  1106.  
  1107.  
  1108. ; Save the screen to a buffer and then append buffer to a disk file. [jrd]
  1109. ; Default filename is Kermit.scn; actual file can be a device too. Filename
  1110. ; is determined by mssset and is passed as pointer dmpname.
  1111. ; Dumpscr reads the screen image saved by savescr so call savescr call first.
  1112. ; Mod to use VRAM (see savescr)                                 RFG
  1113.  
  1114. dumpscr proc    near
  1115.         push    ax
  1116.         push    bx
  1117.         push    cx
  1118.         push    dx
  1119.         mov     dmphand,-1              ; preset illegal handle
  1120.         mov     dx,offset dmpname       ; name of disk file, from mssset
  1121.         mov     ax,dx                   ; where isfile wants name ptr
  1122.         call    isfile                  ; what kind of file is this?
  1123.         jc      dmp5                    ; c = no such file, create it
  1124.         test    byte ptr filtst.dta+21,1fh ; file attributes, ok to write?
  1125.         jnz     dmp0                    ; nz = no.
  1126.         mov     al,1                    ; writing
  1127.         mov     ah,open2                ; open existing file
  1128.         int     dos
  1129.         jc      dmp0                    ; c = failure
  1130.         mov     dmphand,ax              ; save file handle
  1131.         mov     bx,ax                   ; need handle here
  1132.         mov     cx,0ffffh               ; setup file pointer
  1133.         mov     dx,-1                   ; and offset
  1134.         mov     al,2                    ; move to eof minus one byte
  1135.         mov     ah,lseek                ; seek the end
  1136.         int     dos
  1137.         jmp     dmp1
  1138.  
  1139. dmp5:   test    filtst.fstat,80h        ; access problem?
  1140.         jnz     dmp0                    ; nz = yes
  1141.         mov     ah,creat2               ; file did not exist
  1142.         mov     cx,20h                  ; attributes, archive bit
  1143.         int     dos
  1144.         mov     dmphand,ax              ; save file handle
  1145.         jnc     dmp1                    ; nc = ok
  1146.  
  1147. dmp0:   mov     ah,3                    ; get cursor position
  1148.         xor     bx,bx                   ; page 0
  1149.         int     screen
  1150.         push    dx                      ; save it
  1151.         mov     dh,byte ptr low_rgt+1   ; go to status line
  1152.         inc     dh
  1153.         xor     dl,dl                   ; left most column
  1154.         mov     ah,2                    ; position cursor
  1155.         int     screen
  1156.         mov     dx,offset dmperr        ; say no can do
  1157.         mov     ah,prstr
  1158.         int     dos
  1159.         pop     dx                      ; get original cursor position
  1160.         mov     ah,2                    ; position cursor
  1161.         xor     bx,bx                   ; page 0
  1162.         int     screen
  1163.         pop     dx
  1164.         pop     cx
  1165.         pop     bx
  1166.         pop     ax
  1167.         clc
  1168.         ret
  1169.  
  1170. dmp1:   mov     ah,ioctl                ; is destination ready for output?
  1171.         mov     al,7                    ; test output status
  1172.         mov     bx,dmphand              ; handle
  1173.         int     dos
  1174.         jc      dmp0                    ; c = error
  1175.         cmp     al,0ffh                 ; ready?
  1176.         jne     dmp0                    ; ne = not ready.
  1177.         push    di                      ; read screen buffer, write lines
  1178.         push    si
  1179.         push    es
  1180.         mov     cl,byte ptr low_rgt+1   ; number of lines - 2
  1181.         add     cl,2                    ; number of line on screen
  1182.         xor     ch,ch
  1183.         mov     si,savadr               ; offset in storage area
  1184. dmp2:   push    cx                      ; save outer loop counter
  1185.         mov     es,savadr+2             ; get storage segment
  1186.         mov     di,offset dumpbuf       ; data segment memory
  1187.         mov     cl,byte ptr savflg      ; number of columns on screen - 1
  1188.         inc     cl                      ; number of columns on screen
  1189.         xor     ch,ch
  1190. dmp3:   mov     ax,word ptr es:[si]     ; read char + trash
  1191.         mov     byte ptr [di],al        ; store just char, don't use es:
  1192.         inc     si                      ; update pointers
  1193.         inc     si
  1194.         inc     di
  1195.         loop    dmp3                    ; do for each column
  1196.         std                             ; set scan backward
  1197.         mov     cl,byte ptr savflg      ; number of columns on screen - 1
  1198.         inc     cl                      ; number of columns on screen
  1199.         xor     ch,ch
  1200.         push    es
  1201.         mov     ax,ds
  1202.         mov     es,ax                   ; set es to data segment for es:di
  1203.         mov     di,offset dumpbuf       ; start of line
  1204.         add     di,cx                   ; plus length of line
  1205.         dec     di                      ; minus 1 equals end of line
  1206.         mov     al,' '                  ; thing to scan over
  1207.         repe    scasb                   ; scan until non-space
  1208.         cld                             ; set direction forward
  1209.         pop     es
  1210.         jz      dmp3a                   ; z = all spaces
  1211.         inc     cx
  1212.         inc     di
  1213. dmp3a:  mov     word ptr [di+1],0A0Dh   ; append cr/lf
  1214.         add     cx,2                    ; line count + cr/lf
  1215.         mov     dx,offset dumpbuf       ; array to be written
  1216.         mov     bx,dmphand              ; need file handle
  1217.         mov     ah,write2               ; write the line
  1218.         int     dos
  1219.         pop     cx                      ; get line counter again
  1220.         jc      dmp3b                   ; c = error
  1221.         loop    dmp2                    ; do next line
  1222.         mov     dx,offset dumpsep       ; put in formfeed/cr/lf
  1223.         mov     cx,3                    ; three bytes overall
  1224.         mov     ah,write2               ; write them
  1225. dmp3b:  mov     bx,dmphand              ; file handle
  1226.         int     dos
  1227.         mov     ah,close2               ; close the file now
  1228.         int     dos
  1229. dmp6:   pop     es
  1230.         pop     si
  1231.         pop     di
  1232.         pop     dx
  1233.         pop     cx
  1234.         pop     bx
  1235.         pop     ax
  1236.         clc
  1237.         ret
  1238. dumpscr endp
  1239.  
  1240.  
  1241. ; Get CRT mode - returns mode in variable crt_mode,
  1242. ; updates crt_cols and low_rgt. [jrd]
  1243. scrmod  proc    near
  1244.         push    ax
  1245.         push    dx
  1246.         mov     ah,15                   ; Get current video state.
  1247.         int     screen
  1248.         mov     crt_mode,al             ; Store CRT mode value.
  1249.         mov     crt_cols,ah             ; store # of cols [jrd]
  1250.         mov     dl,ah                   ; # of cols again
  1251.         mov     dh,crt_lins             ; and # of rows (constant from msster)
  1252.         dec     dl                      ; max text column, count from zero
  1253.         dec     dh                      ; max text row, count from zero
  1254.         mov     low_rgt,dx              ; save away window address
  1255.         pop     dx
  1256.         pop     ax
  1257.         ret                             ; And return.
  1258. scrmod  endp
  1259.  
  1260.  
  1261. ; Get screen segment - returns screen segment in ax, and full address in es:di
  1262.  
  1263. ; modified for NEC; there is only one answer                    RFG
  1264. scrseg  proc    near
  1265.         mov     ax,vram
  1266.         mov     es,ax
  1267.         xor     di,di                   ; start at beginning of screen (0,0)
  1268.         ret
  1269. scrseg  endp
  1270.  
  1271. ; Synchronize a Topview provided virtual screen buffer with the image
  1272. ; seen by the user. Requires cx = number of words written to screen
  1273. ; (char & attribute bytes) and es:di = ENDING address of screen write.
  1274. ; Changes ax and di.
  1275. ; Stripped out on NEC          RFG
  1276. scrsync proc    near
  1277.         ret
  1278. scrsync endp
  1279.  
  1280. ; The following two routines are used to turn off the display while we
  1281. ; are reading or writing the screen in one of the color card modes.
  1282. ; Turn screen off for (known) color card modes only. All regs preserved.
  1283. ; not an NEC required function                                  RFG
  1284.  
  1285. scroff  proc    near
  1286.         ret                             ; And return.
  1287. scroff  endp
  1288.  
  1289.  
  1290. ; Turn screen on for (known) color card modes only
  1291. ; All registers are preserved.
  1292.  
  1293. scron   proc    near
  1294.         ret                             ; And return.
  1295. scron   endp
  1296.  
  1297.  
  1298. ; Screen clearing routine. [IU]
  1299. ;
  1300. ; Call:         ax/     coordinates of first screen location to be cleared.
  1301. ;               bx/     coordinates of last location to be cleared.
  1302. ; Coord: ah = row [0-24], al = column [0-79]. Preserves all registers. [jrd]
  1303. ; redone for the NEC in a non-Topview manner                    RFG
  1304. atsclr: push    ax
  1305.         push    bx
  1306.         push    cx
  1307.         push    dx
  1308.         mov     cx,ax                   ; upper left corner
  1309.         mov     dx,bx                   ; lower right corner
  1310.         mov     bh,scbattr              ; attribute
  1311.         mov     al,0                    ; blank entire window
  1312.         mov     ah,6                    ; scroll the page described above
  1313.         int     screen
  1314.         pop     dx
  1315.         pop     cx
  1316.         pop     bx
  1317.         pop     ax
  1318.         ret
  1319.  
  1320. ; Scrolling routines.  vtscru scrolls up one row, vtscrd scrolls down one
  1321. ; row.  atsprep is called before scrolling up to save the top line in the
  1322. ; circular buffer. All registers are preserved.
  1323.  
  1324. ; Screen-roll down. Move text down one line, for terminal emulator only.
  1325.  
  1326. vtscrd: push    ax                      ; Upgraded by [jrd]
  1327.         push    bx
  1328.         push    cx
  1329.         push    dx
  1330.         mov     ax,701H                 ; scroll down one line
  1331.         mov     ch,mar_top              ; top margin line
  1332.         mov     cl,0                    ; left most column
  1333.         mov     dh,mar_bot              ; bottom margin line
  1334.         mov     dl,byte ptr low_rgt     ; right most column
  1335.         mov     bh,scbattr              ; attributes
  1336.         int     screen                  ; scroll it down
  1337.         pop     dx
  1338.         pop     cx
  1339.         pop     bx
  1340.         pop     ax
  1341.         clc
  1342.         ret
  1343.                                         ; worker routine for vtscru/d
  1344. atsprep:push    es                      ; upgraded from older version  [jrd]
  1345.         call    scrseg                  ; get display address in es:di
  1346.         mov     si,di                   ; si will be source
  1347.         mov     bx,offset twnd          ; this is where it goes
  1348.         call    putcirc                 ; put screen line in circular buffer
  1349.         pop     es                      ; and that
  1350.         ret                             ; and return
  1351.  
  1352.  
  1353. ; Screen scroll up one line (text moves up) for terminal emulator use.
  1354.  
  1355. vtscru: push    ax                      ; Upgraded by  [jrd]
  1356.         push    bx
  1357.         push    cx
  1358.         push    dx
  1359.         push    si
  1360.         push    di
  1361.         cmp     mar_top,0               ; scrolling the top screen line?
  1362.         ja      scru1                   ; a = no. don't save anything
  1363.         call    atsprep                 ; save top line
  1364. scru1:  mov     ax,601H                 ; scroll up one line
  1365.         mov     dh,mar_bot              ; bottom row
  1366.         mov     dl,byte ptr low_rgt     ; right most column
  1367.         mov     ch,mar_top              ; top row of scrolling region
  1368.         mov     cl,0                    ; left most column
  1369.         mov     bh,scbattr              ; background attributes
  1370.         int     screen                  ; scroll up that region
  1371.         pop     di                      ; Restore the rest of the regs.
  1372.         pop     si
  1373.         pop     dx
  1374.         pop     cx
  1375.         pop     bx
  1376.         pop     ax
  1377.         clc
  1378.         ret                             ; And return
  1379.  
  1380. ;screen text roll up, version for manual scrolling only
  1381.  
  1382. mscru:  push    ax                      ; Upgraded by  [jrd]
  1383.         push    bx
  1384.         push    cx
  1385.         push    dx
  1386.         push    si
  1387.         push    di
  1388.         cmp     bwnd.lcnt,0             ; any lines in bottom window?
  1389.         je      mscru2                  ; e = no, so ignore request
  1390.         call    atsprep                 ; save top line
  1391. mscru1: mov     ax,601H                 ; scroll up one line
  1392.         mov     dx,low_rgt              ; lower right corner
  1393.         xor     cx,cx                   ; top row of scrolling region
  1394.         mov     bh,scbattr              ; background attributes
  1395.         int     screen                  ; scroll up that region
  1396.         mov     dx,low_rgt
  1397.         mov     dl,0                    ; location is lower left corner
  1398.         call    scrloc                  ; get count from display start
  1399.         push    es
  1400.         push    ax                      ; save count
  1401.         call    scrseg                  ; get screen's segment into ax, es:di
  1402.         pop     ax                      ; recover count
  1403.         add     di,ax                   ; destination memory address (es:di)
  1404.         mov     bx,offset bwnd          ; source of lines
  1405.         call    getcirc                 ; get line from circ buf to screen
  1406.         pop     es                      ; restore es
  1407. mscru2: pop     di                      ; Restore the rest of the regs.
  1408.         pop     si
  1409.         pop     dx
  1410.         pop     cx
  1411.         pop     bx
  1412.         pop     ax
  1413.         ret
  1414.  
  1415.  
  1416. ; prep for screen scroll down. [jrd]
  1417. ; copies bottom scroll line from screen to bottom window buffer.
  1418. ; destroys ax,cx,dx,si,di.
  1419. getbot proc near                        ; Upgraded from old version [jrd]
  1420.         push    es
  1421.         mov     dx,low_rgt              ; from screen location, row
  1422.         mov     dl,0                    ; starting in col 0
  1423.         call    scrseg                  ; get adaptor's offset into es:di
  1424.         call    scrloc                  ; get offset in display buffer in ax
  1425.         add     di,ax                   ; source addr in display buffer es:di
  1426.         mov     si,di                   ; screen is source (si)
  1427.         mov     bx,offset bwnd          ; buffer to use (bottom window)
  1428.         call    putcirc                 ; copy bottom screen line to circ buf
  1429.         pop     es
  1430.         ret
  1431. getbot endp
  1432.  
  1433. ;screen text scroll down, for manual mode only
  1434. mscrd:  push    ax                      ; Upgraded by [jrd]
  1435.         push    bx
  1436.         push    cx
  1437.         push    dx
  1438.         push    si
  1439.         push    di
  1440.         cmp     twnd.lcnt,0             ; any lines left in top window?
  1441.         je      mscrd1                  ; e = no, ingore request
  1442.         call    getbot                  ; fetch bottom line from screen
  1443.         mov     ax,701H                 ; scroll down one line
  1444.         xor     cx,cx                   ; top left corner
  1445.         mov     dx,low_rgt              ; bottom right corner
  1446.         mov     bh,scbattr              ; attributes
  1447.         int     screen                  ; scroll it down
  1448.         push    es
  1449.         call    scrseg                  ; get segment address of screen
  1450.         mov     bx,offset twnd          ; buffer to use (top window)
  1451.         call    getcirc                 ; copy from circ buf to screen
  1452.         pop     es
  1453. mscrd1: pop     di                      ; Restore the rest of the ACs.
  1454.         pop     si
  1455.         pop     dx
  1456.         pop     cx
  1457.         pop     bx
  1458.         pop     ax
  1459.         ret
  1460.  
  1461. ; move viewing window down as much as possible (text moves up)
  1462. endwnd  proc    near                    ; go to end of scrolling text
  1463.     push    cx
  1464.         mov     cx,bwnd.lcnt            ; all bottom window lines [dlk]
  1465.         jmp     dnwp0                   ; and enter dwnpg
  1466. endwnd  endp
  1467.  
  1468. dnone   proc    near                    ; move text up one line [jrd]
  1469.     push    cx
  1470.         mov     cx,1
  1471.         jmp     dnwp0
  1472. dnone   endp
  1473.  
  1474. ; scroll viewing window down (text moves up) one page (24 lines)
  1475. dnwpg   proc    near
  1476.     push    cx
  1477.         mov     cl,byte ptr low_rgt+1   ; number of rows, excl status
  1478.         inc     cl                      ; count from 1, not 0
  1479.         mov     ch,0
  1480. dnwp0:                                  ; additional entry point
  1481.         cmp     bwnd.lcnt,cx            ; enough lines in bottom line buffer?
  1482.         jge     dnwp1                   ; ge = we have that many lines stored
  1483.         mov     cx,bwnd.lcnt            ; do as many as we have
  1484. dnwp1:  jcxz    dnwp2                   ; z = nothing to do
  1485.     cmp    tekflg,0        ; Tek mode active?
  1486.     jne    dnwp2            ; ne = yes, no scrolling
  1487.         call    mscru                   ; scroll up text one line
  1488.         loop    dnwp1
  1489. dnwp2:  pop    cx
  1490.     clc
  1491.         ret
  1492. dnwpg   endp
  1493.  
  1494. ; home viewing window
  1495. homwnd  proc    near
  1496.     push    cx
  1497.         mov     cx,twnd.lcnt            ; all top window lines [dlk]
  1498.         jmp     upwp0                   ; join upwpg
  1499. homwnd  endp
  1500.  
  1501. upone   proc    near                    ; move text down one line [jrd]
  1502.     push    cx
  1503.         mov     cx,1
  1504.         jmp     upwp0
  1505. upone   endp
  1506.  
  1507. ; scroll viewing window up (text moves down) a page (24 lines)
  1508. upwpg   proc    near
  1509.     push    cx
  1510.         mov     cl,byte ptr low_rgt+1   ; number of rows, excl status line
  1511.         inc     cl                      ; count from 1, not 0
  1512.         mov     ch,0
  1513. upwp0:                                  ; additional entry point
  1514.         cmp     twnd.lcnt,cx            ; enough lines in top line buffer?
  1515.         jae     upwp1                   ; ae = at least as many as requested
  1516.         mov     cx,twnd.lcnt            ; do only as many as are stored.
  1517. upwp1:  jcxz    upwp2                   ; z = no lines to scroll
  1518.     cmp    tekflg,0        ; Tek mode active?
  1519.     jne    upwp2            ; ne = yes, no scrolling
  1520.         call    mscrd                   ; roll down text one line
  1521.         loop    upwp1
  1522. upwp2:  pop    cx
  1523.     clc
  1524.         ret
  1525. upwpg   endp
  1526.  
  1527.  
  1528. ; Put a line into the circular buffer.  Pass the buffer structure in bx.
  1529. ; Source is vram:si which is the current screen address.
  1530. ; Rewritten by [jrd]
  1531. ; Modified for the NEC screen attribute structure -- RFG
  1532. putcirc proc    near
  1533.         push    es
  1534.         mov     cl,crt_cols             ; number of columns
  1535.         xor     ch,ch
  1536.         mov     es,[bx].orig            ; get segment of memory area
  1537.         cmp     bx,offset bwnd          ; bottom buffer?
  1538.         je      putci6                  ; e = yes
  1539.         mov     di,twnd.pp              ; pick up buffer ptr (offset from es)
  1540.         add     di,cx                   ; increment to next available slot
  1541.         add     di,cx                   ; char and attribute
  1542.         cmp     di,twnd.bend            ; would line extend beyond buffer?
  1543.         jb      putci1                  ; b = not beyond end
  1544.         mov     di,0                    ; else start at the beginning
  1545. putci1: mov     twnd.pp,di              ; update ptr
  1546.         cld                             ; set direction to forward
  1547.         push    ds                      ; save regular datas seg reg
  1548.         push    ax
  1549.         mov     ax,vram                 ; video memory segment
  1550.         mov     ds,ax                   ; use screen segment for ds:si
  1551. putci1z:                                ; NEC mod starts here -- RFG
  1552.         movsb                           ; transfer a text byte
  1553.         mov     ax,si                   ; remember 'movsb' incremented di
  1554.         add     ax,1FFFH                ; point at the attribute
  1555.         mov     si,ax
  1556.         movsb                           ; transfer an attribute byte
  1557.         dec     cx                      ; count one full character
  1558.         mov     ax,si
  1559.         sub     ax,1FFFH                ; point at the next text
  1560.         mov     si,ax
  1561.         cmp     cx,0                    ; have we done it all?
  1562.         jne     putci1z                 ; no, keep truckin'
  1563. ;                                       ; end of NEC mod -- RFG
  1564.         pop     ax
  1565.         pop     ds                      ; restore regular datas segment
  1566.         mov     cx,twnd.lmax            ; line capacity of buffer
  1567.         dec     cx                      ; minus one work space line
  1568.         cmp     twnd.lcnt,cx            ; can we increment line count?
  1569.         jae     putci1b                 ; ae = no, keep going
  1570.         inc     twnd.lcnt               ; else count this line
  1571. putci1b:cmp     bwnd.lcnt,0             ; any lines in bottom buffer?
  1572.         je      putci2                  ; e = no
  1573.         mov     cx,bwnd.pp              ; see if we overlap bot buf
  1574.         cmp     cx,twnd.pp              ; is this line in bot buf area?
  1575.         jne     putci2                  ; ne = no
  1576.         add     cl,crt_cols             ; move bottom pointer one slot earlier
  1577.         adc     ch,0
  1578.         add     cl,crt_cols             ; words
  1579.         adc     ch,0
  1580.         cmp     cx,bwnd.bend            ; beyond end of buffer?
  1581.         jb      putci1a                 ; b = no
  1582.         mov     cx,0                    ; yes, start at beginning of buffer
  1583. putci1a:mov     bwnd.pp,cx              ; new bottom pointer
  1584.         dec     bwnd.lcnt               ; one less line in bottom buffer
  1585. putci2: pop     es
  1586.         ret
  1587. putci6:                                 ; bottom buffer
  1588.         add     cx,cx                   ; words worth
  1589.         cmp     bwnd.lcnt,0             ; any lines in the buffer yet?
  1590.         jne     putci7                  ; ne = yes
  1591.         mov     di,twnd.pp              ; get latest used slot of top buff
  1592.         add     di,cx                   ; where first free (?) slot starts
  1593.         cmp     di,bwnd.bend            ; are we now beyond the buffer?
  1594.         jb      putci6a                 ; b = no
  1595.         mov     di,0                    ; yes, start at beginning of buffer
  1596. putci6a:add     di,cx                   ; start of second free (?) slot
  1597.         cmp     di,bwnd.bend            ; are we now beyond the buffer?
  1598.         jb      putci6b                 ; b = no
  1599.         mov     di,0                    ; yes, start at beginning of buffer
  1600. putci6b:mov     cx,twnd.lmax            ; buffer line capacity
  1601.         sub     cx,twnd.lcnt            ; minus number used by top buffer
  1602.         sub     cx,2                    ; minus one work slot and one we need
  1603.         cmp     cx,0                    ; overused some slots?
  1604.         jge     putci8                  ; ge = enough to share
  1605.         add     twnd.lcnt,cx            ; steal these from top window beginning
  1606.         jmp     short putci8
  1607. putci7: mov     es,bwnd.orig            ; get segment of memory area
  1608.         mov     di,bwnd.pp              ; pick up buffer ptr (offset from es)
  1609.         cmp     di,0                    ; would line start before buffer?
  1610.         jne     putci7a                 ; ne = after start of buffer
  1611.         mov     di,bwnd.bend            ; else start at the end minus one slot
  1612.         inc     di
  1613. putci7a:sub     di,cx
  1614. putci8: mov     bwnd.pp,di              ; update ptr (this is latest used slot)
  1615.         mov     cl,crt_cols
  1616.         xor     ch,ch
  1617.         cld                             ; set direction to forward
  1618.         push    ds                      ; save regular datas seg reg
  1619.         push    ax
  1620.         mov     ax,vram                 ; video memory segment
  1621.         mov     ds,ax                   ; use screen segment for ds:si
  1622. putci8z:                                ; NEC mod starts here -- RFG
  1623.         movsb                           ; transfer a text byte
  1624.         mov     ax,si
  1625.         add     ax,1FFFH                ; point at the attribute
  1626.         mov     si,ax
  1627.         movsb                           ; transfer an attribute byte
  1628.         dec     cx                      ; count one full character
  1629.         mov     ax,si
  1630.         sub     ax,1FFFH                ; point at the text
  1631.         mov     si,ax
  1632.         cmp     cx,0                    ; have we done it all?
  1633.         jne     putci8z                 ; no, keep truckin'
  1634. ;                                       ; end of NEC mod -- RFG
  1635.         pop     ax
  1636.         pop     ds                      ; restore regular datas segment
  1637.         mov     cx,bwnd.lmax            ; line capacity of buffer
  1638.         cmp     bwnd.lcnt,cx            ; can we increment line count?
  1639.         jae     putci8b                 ; ae = no, keep going
  1640.         inc     bwnd.lcnt               ; else count this line
  1641. putci8b:cmp     twnd.lcnt,0             ; any lines in top line buf?
  1642.         je      putci9                  ; e = no
  1643.         mov     cx,twnd.pp              ; yes, see if we used last top line
  1644.         cmp     cx,bwnd.pp              ; where we just wrote
  1645.         jne     putci9                  ; not same place, so all is well
  1646.         dec     twnd.lcnt               ; one less line in top window
  1647.         cmp     cx,0                    ; currently at start of buffer?
  1648.         jne     putci8a                 ; ne = no
  1649.         mov     cx,twnd.bend            ; yes
  1650.         inc     cx
  1651. putci8a:sub     cl,crt_cols             ; back up top window
  1652.         sbb     ch,0
  1653.         sub     cl,crt_cols             ; by one line
  1654.         sbb     ch,0
  1655.         mov     twnd.pp,cx              ; next place to read
  1656. putci9: pop     es
  1657.         ret
  1658.  
  1659. putcirc endp
  1660.  
  1661. ; Get a line from the circular buffer, removing it from the buffer.
  1662. ; returns with carry on if the buffer is empty.
  1663. ; Pass the buffer structure in bx.
  1664. ; Destination preset in es:di which is the current screen address.
  1665. ; Rewritten by [jrd]
  1666. getcirc proc    near
  1667.         cmp     [bx].lcnt,0             ; any lines in buffer?
  1668.         jne     getci1                  ; ne = yes, ok to take one out.
  1669.         stc                             ; else set carry
  1670.         ret                             ; and return
  1671. getci1:                                 ; top and bottom window common code
  1672.         mov     cl,crt_cols             ; # of chars to copy
  1673.         xor     ch,ch
  1674.         push    cx                      ; save around calls
  1675.         mov     si,[bx].pp              ; this is source
  1676.         cld                             ; set direction to forward
  1677.         push    ds                      ; save original ds
  1678.         mov     ds,[bx].orig            ; use seg address of buffer for si
  1679. getci1z:                                ; NEC mod starts here -- RFG
  1680.         movsb                           ; transfer a text byte
  1681.         mov     ax,di                   ; remember 'movsb' incremented di
  1682.         add     ax,1FFFH                ; point at the attribute
  1683.         mov     di,ax
  1684.         movsb                           ; transfer the attribute byte
  1685.         dec     cx                      ; count one full character
  1686.         mov     ax,di
  1687.         sub     ax,1FFFH                ; point at the next text byte
  1688.         mov     di,ax
  1689.         cmp     cx,0                    ; have we done it all?
  1690.         jne     getci1z                 ; no, keep truckin'
  1691. ;                                       ; NEC mod ends here -- RFG
  1692.         pop     ds                      ; recover original data segment
  1693.         pop     cx                      ; length for Topview
  1694.         push    cx                      ; save again
  1695.         mov     si,[bx].pp              ; get ptr again
  1696.         pop     cx
  1697.         add     cx,cx                   ; words
  1698.         cmp     bx,offset bwnd          ; bottom window?
  1699.         je      getci6                  ; e = yes
  1700.         sub     si,cx                   ; top window, move back
  1701.         jnc     getcir2                 ; nc = still in buffer, continue
  1702.         mov     si,twnd.bend            ; else use end of buffer
  1703.         sub     si,cx                   ; minus length of a piece
  1704.         inc     si
  1705. getcir2:mov     twnd.pp,si              ; update ptr
  1706.         dec     twnd.lcnt               ; decrement # of lines in buffer
  1707.         clc                             ; make sure no carry
  1708.         ret
  1709. getci6:                                 ; bottom window
  1710.         add     si,cx                   ; words, move back (bot buf = reverse)
  1711.         cmp     si,bwnd.bend            ; still in buffer?
  1712.         jb      getci7                  ; b = yes
  1713.         mov     si,0                    ; else use beginning of buffer
  1714. getci7: mov     bwnd.pp,si              ; update ptr
  1715.         dec     bwnd.lcnt               ; decrement # of lines in buffer
  1716.         clc                             ; make sure no carry
  1717.         ret
  1718. getcirc endp
  1719.  
  1720. ;
  1721. ; CHKDSP - procedure to check for hardware support of 132 cols [dlk]
  1722. ;
  1723. chgdsp  proc    near
  1724.         ret                             ; return to caller
  1725. chgdsp  endp
  1726.  
  1727. ; Jumping to this location is like retskp.  It assumes the instruction
  1728. ;   after the call is a jmp addr.
  1729.  
  1730. RSKP    PROC    NEAR
  1731.         pop    bp
  1732.         add    bp,3
  1733.         push    bp
  1734.         ret
  1735. RSKP    ENDP
  1736.  
  1737. ; Jumping here is the same as a ret.
  1738.  
  1739. R       PROC    NEAR
  1740.         ret
  1741. R       ENDP
  1742.  
  1743. code    ends
  1744.  
  1745. if1
  1746.         %out [End of pass 1]
  1747. else
  1748.         %out [End of assembly]
  1749. endif
  1750.  
  1751.         end
  1752.