home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / ccdos / ccyibm.asm < prev    next >
Assembly Source File  |  2020-01-01  |  121KB  |  2,631 lines

  1.     NAME ccyibm
  2. ; File CCYIBM.ASM
  3. ; Edit History:
  4. ;   Mar.21,1991:
  5. ;    * Add MASM Option /DCGA in serval places. The goal is to make ZUnet-PBX 
  6. ;        can be run in different CCDOS versions(Such as: CCDOS213,LIANXIAN,
  7. ;        STCDOS,CGA17,etc.) on different video adapers( such as CGA,EGA,VGA 
  8. ;        and MDA).
  9. ;      In this program Macro Conditions "IFDEF  CGA ... ENDIF" and "IFNDEF CGA 
  10. ;        ... ENDIF" are used.
  11. ;      Option CGA is used only when you want to build a program used in PC/XT
  12. ;        (CGA or MDA adapter).Maybe it can be used in VGA adapter. [zqf]
  13. ;   1990:
  14. ;    * Program is modified in many places to suit for different CCDOS versions.
  15. ;        You can check them by indexing 'zqf' or 'CCDOS'. [zqf]
  16.  
  17. ;CHINESE
  18. ifdef   MSDOS
  19.         include msyibm.dat
  20. else
  21.         include ccyibm.dat
  22. endif
  23.  
  24. code    segment public 'code'
  25.         extrn   beep:near, prtchr:near, outchr:near, sbrk:near, pcwait:near
  26.         extrn   isfile:near, strlen:near, strcpy:near   ; in mssfil
  27.         extrn   anstty:near,ansini:near,ansrei:near     ; in mszibm
  28.         extrn   anstat:near,anskbi:near,ansdsl:near     ; in mszibm
  29.         extrn   ans52t:near, vsinit:near                ; in mszibm
  30.         extrn   msuinit:near, keybd:near                ; in msuibm
  31.         extrn   tekini:near,tekcls:near,tekemu:near,tekend:near ;in msgibm
  32.         extrn   tekrint:near
  33. ifdef   DEBG
  34. ;        extrn   debgp:near
  35. endif
  36.         assume  cs:code, ds:datas, es:datas
  37.  
  38. ; do initialization local to this module
  39. ; Dynamically allocates 4000 bytes for screen save/restore buffer plus
  40. ;  320 to 38400 bytes for screen scroll back buffers. Tries to leave space
  41. ;  for Command.com before enlarging buffers. [jrd]
  42. lclyini proc    near
  43.         call    msuinit                 ; initialize keyboard module msuxxx
  44.  
  45.         mov     ax,swidth*(slen+1)*2    ; (80 char + 80 attr) * 25 lines
  46.         call    sbrk                    ; memory allocation routine (mssker)
  47.                                         ;if we get here them we have the lines
  48.         mov     scrsav,ax               ; memory segment for save screens
  49.                                         ; screen roll back buffers
  50.         mov     bx,0ffffh               ; ask for all of memory, to get size
  51.         mov     ah,alloc                ; allocate all of memory (must fail)
  52.         int     dos                     ; bx has # free paragraphs
  53.         mov     ax,bx                   ; ax has copy of number free paragraphs
  54.         sub     ax,24000D/16            ; space for Command.com copy #2
  55.         jbe     lclyin1                 ; be = not enough for it. [ebb]
  56.         cmp     ax,(swidth*slen+15)/16  ; minimum roll back space left over?
  57.         jbe     lclyin1                 ; be = not even that much
  58.         cmp     ax,(swidth*slen*npages+7)/8 ; paragraphs wanted for roll back
  59.         jbe     lclyin2                 ; be = enough but not more than needed
  60.         mov     ax,(swidth*slen*npages+7)/8 ; limit to our actual needs
  61.         jmp     short lclyin2           ; ask for all we really want
  62. lclyin1:mov     ax,(4*swidth+15)/16     ; use minimum needed paragraphs
  63. lclyin2:mov     inipara,ax              ; save for later resizing of buffers
  64.         mov     cl,4                    ; convert paragraphs to bytes
  65.         shl     ax,cl                   ;  for sbrk
  66.         call    sbrk                    ; ask for that many bytes
  67.                                         ;if we get here them we have the space
  68.         mov     bwnd.orig,ax            ; memory segment, bottom window area
  69.         mov     twnd.orig,ax            ; top. same place for both buffers!
  70.  
  71.         call    scrseg                  ; test running in an Environment
  72.         call    scrmod                  ; read video state, get crt_mode
  73.         mov     ax,low_rgt              ; lower right corner of screen
  74.         mov     al,crt_mode
  75.         mov     crt_norm,al             ; save as normal mode
  76.         mov     savflg,ax
  77.         mov     ah,conout               ; output a space to set background
  78.         mov     dl,' '                  ; and foreground screen colors
  79.         int     dos
  80.         mov     ah,3                    ; get current cursor position into dx
  81.         mov     bh,0
  82.         int     screen
  83.         dec     dl                      ; backup to the space
  84.         mov     ah,2                    ; set cursor
  85.         int     screen
  86.         mov     ah,8                    ; read current attributes
  87.         xor     bh,bh                   ; page 0
  88.         int     screen
  89.         mov     scbattr,ah              ; save video attributes
  90.         mov     oldattr,ah              ; and here too
  91.         mov     ax,inipara              ; # paragraphs allocated by DOS
  92.         mov     cl,3                    ; 2**3 = 8
  93.         shl     ax,cl                   ; paragraphs to words (char + attrib)
  94.         xor     dx,dx                   ; clear extended size
  95.         mov     ch,0
  96.         mov     cl,byte ptr low_rgt
  97.         inc     cl                      ; number of chars per line in buffer
  98.         div     cx                      ; ax = number of lines in buffer
  99.         mov     bwnd.lmax,ax            ; max lines per buffer (quotient)
  100.         mov     twnd.lmax,ax            ; max lines per buffer
  101.         add     cx,cx                   ; count char and attribute per item
  102.         xor     dx,dx                   ; clear extended numerator
  103.         mul     cx                      ; ax = effective # bytes per buffer
  104.         dec     ax                      ; adjust for counting from zero
  105.         mov     bwnd.bend,ax            ; offset of last byte in buffer
  106.         mov     twnd.bend,ax            ; offset of last byte in buffer
  107.         mov     bwnd.pp,0               ; offset of first byte in buffer
  108.         mov     twnd.pp,0               ; offset of first byte in buffer
  109.         mov     bwnd.lcnt,0             ; number of lines occupied in buffer
  110.         mov     twnd.lcnt,0             ; number of lines occupied in buffer
  111.         call    vsinit                  ; init terminal emulator module MSZ
  112.         mov     ega_mode,0              ; assume no EGA
  113.         mov     ax,1200H                ; EGA: Bios alternate select
  114.         mov     bl,10H                  ; Ask for EGA info
  115.         mov     bh,0ffH                 ; Bad info, for testing
  116.         mov     cl,0fH                  ; Reserved switch settings
  117.         int     screen                  ; EGA, are you there?
  118.         cmp     cl,0cH                  ; Test reserved switch settings
  119.         jge     lclyin3                 ; ge = no EGA in use
  120.         push    es
  121.         mov     ax,40h                  ; check Bios 40:87h for ega being
  122.         mov     es,ax                   ;  the active display adapter
  123.         test    byte ptr es:[87h],8     ; is ega active?
  124.         pop     es
  125.         jnz     lclyin3                 ; nz = no
  126.         mov     ega_mode,1              ; yes, set flag to say so
  127.         mov     crt_norm,3              ; assume color monitor is attached
  128.         cmp     bh,0                    ; is color mode in effect?
  129.         je      lclyin3                 ; e = yes
  130.         mov     crt_norm,7              ; else use mode 7 for mono
  131. lclyin3:ret
  132. lclyini endp
  133.  
  134. scrini  proc    near                    ; init screen stuff
  135.         call    scrseg                  ; update screen segment tv_seg(s/o)
  136.         call    scrmod                  ; get screen mode, low_rgt
  137.         mov     ah,3                    ; get cursor position and type
  138.         xor     bh,bh                   ; page 0
  139.         int     screen
  140.         mov     lincur,cx               ; save cursor type (scan line #'s)
  141.         mov     ax,low_rgt              ; present screen text size
  142.         cmp     ax,savflg               ;  vs size of saved screen
  143.         jne     scrin1                  ; ne = different, initialize
  144.         jmp     scrin3                  ; same, skip initialization
  145.                                         ; Re-initialize screen buffers
  146. scrin1: mov     ax,inipara              ; paragraphs allotted to roll back
  147.         mov     cl,3                    ; 2**3 = 8
  148.         shl     ax,cl                   ; paragraphs to words (char + attrib)
  149.         xor     dx,dx                   ; clear extended size
  150.         mov     cl,byte ptr low_rgt     ; number of chars per line in buffer
  151.         inc     cl                      ; chars per line
  152.         xor     ch,ch                   ; clear high byte
  153.         div     cx                      ; ax = number of lines in buffer
  154.         mov     bwnd.lmax,ax            ; max lines per buffer (quotient)
  155.         mov     twnd.lmax,ax            ; max lines per buffer
  156.         add     cx,cx                   ; count char and attribute per item
  157.         xor     dx,dx                   ; clear extended numerator
  158.         mul     cx                      ; ax = effective # bytes per buffer
  159.         dec     ax                      ; adjust for counting from zero
  160.         mov     bwnd.bend,ax            ; offset of last byte in buffer
  161.         mov     twnd.bend,ax            ; offset of last byte in buffer
  162.         mov     bwnd.pp,0               ; offset of first byte in buffer
  163.         mov     twnd.pp,0               ; offset of first byte in buffer
  164.         mov     bwnd.lcnt,0             ; number of lines occupied in buffer
  165.         mov     twnd.lcnt,0             ; number of lines occupied in buffer
  166.  
  167.         mov     ega_mode,0              ; assume no EGA
  168.         mov     ax,1200H                ; EGA: Bios alternate select
  169.         mov     bl,10H                  ; Ask for EGA info
  170.         mov     bh,0ffH                 ; Bad info, for testing
  171.         mov     cl,0fH                  ; Reserved switch settings
  172.         int     screen                  ; EGA, are you there?
  173.         cmp     cl,0cH                  ; Test reserved switch settings
  174.         jge     scrin2                  ; ge = no EGA in use
  175.         push    es
  176.         mov     ax,40h                  ; check Bios 40:87h for ega being
  177.         mov     es,ax                   ;  the active display adapter
  178.         test    byte ptr es:[87h],8     ; is ega active?
  179.         pop     es
  180.         jnz     scrin2                  ; nz = no
  181.         mov     ega_mode,1              ; yes, set flag to say so
  182.         mov     crt_norm,3              ; assume color monitor is attached
  183.         cmp     bh,0                    ; is color mode in effect?
  184.         je      scrin2                  ; e = yes
  185.         mov     crt_norm,7              ; else use mode 7 for mono
  186. scrin2: mov     ah,oldattr              ; get init time attributes
  187.         mov     curattr,ah              ; and set nice screen attribute
  188.         mov     scbattr,ah
  189.         mov     cursor,0                ; cursor to upper left corner
  190.         cmp     flags.vtflg,0           ; terminal type of None?
  191.         ja      scrin3                  ; a = no, emulating
  192.         mov     dh,byte ptr low_rgt+1
  193.         inc     dh                      ; bottom
  194.         mov     dl,0                    ;  left corner
  195.         jmp     short scrin5
  196.                                         ; Common finish code
  197. scrin3: mov     dx,cursor               ; use old cursor, if any
  198.         cmp     flags.vtflg,0           ; emulating?
  199.         je      scrin4                  ; e = no
  200.         cmp     dh,byte ptr low_rgt+1   ; past logical end of screen?
  201.         jbe     scrin4                  ; be = no, keep going
  202.         mov     dh,byte ptr low_rgt+1   ; yes, just use lower right corner
  203. scrin4: cmp     dl,byte ptr low_rgt     ; maybe past right margin
  204.         jbe     scrin5                  ; be = no, use the way it is
  205.         mov     dl,byte ptr low_rgt
  206. scrin5: mov     cursor,dx               ; init cursor
  207.         mov     ah,2                    ; set cursor position
  208.         xor     bh,bh                   ; page zero
  209. ; ---------don't set cursor in CCDOS. Dec.12,1990 [zqf]
  210. IFDEF   CGA         ; Add Option CGA to servered screen.Mar.21,1991 [zqf]
  211.         cmp     isccdos,1               ; is in CCDOS ?
  212.         je      scrin6                  ; e = yes, skip 
  213. ENDIF
  214.         int     screen                  ; set cursor in case it moved
  215. scrin6:
  216. ; -----------
  217.         test    flags1,inited           ; have we run yet?
  218.         jz      scrin7                  ; z = no, so no saved screen yet
  219.         call    restscr                 ; restore screen[zqf]Dec.13,1990
  220. scrin7: or      flags1,inited           ; remember we've run already
  221.         cmp     flags.modflg,1          ; is mode line on and locally owned?
  222.         ja      scrin10                 ; a = host owned, leave intact
  223.         cmp     flags.vtflg,0           ; emulating a terminal?
  224.         jne     scrin8                  ; ne = yes, can have mode line
  225.         or      yflags,modoff           ; for no emulation say toggled off
  226.         cmp     trmtyp,0                ; previous terminal type = none?
  227.         jne     scrin9                  ; ne = no. need to clear mode line
  228.         jmp     scrin10                 ; yes, let 25th line be intact
  229. scrin8: cmp     flags.modflg,0          ; is mode line disabled?
  230.         je      scrin9                  ; e = yes, clear it
  231.         test    yflags,modoff           ; is mode line toggled off?
  232.         jnz     scrin9                  ; nz = yes, clear the line
  233.         call    modlin                  ; turn on mode line
  234.         jmp     short scrin10
  235. scrin9: call    clrmod                  ; ensure its off
  236. scrin10:cmp     flags.vtflg,0           ; current terminal type = None?
  237.         je      scrin12                 ; e = yes, nothing to init
  238.         mov     al,yflags               ; tell emulator we are back
  239.         cmp     vtclear,0               ; screen need clearing?
  240.         jne     scrin10a                ; yes, do emulator reinit now
  241.         cmp     vtinited,inited         ; inited emulator yet?
  242.         je      scrin11                 ; e = yes
  243.         cmp     tekflg,0                ; Tek mode still active?
  244.         jne     scrin12                 ; ne = yes, no re-init here
  245. scrin10a:call   vtinit                  ; init it now
  246.         mov     vtclear,0               ; say screen is clear
  247.         jmp     short scrin12
  248. scrin11:call    ansrei                  ; reinit the emulator
  249.         call    ansflg                  ; and get its flags
  250. scrin12:mov     al,flags.vtflg          ; current terminal type
  251.         mov     trmtyp,al               ; place to remember it til next time
  252.         cmp     flags.vtflg,tttek       ; Tek mode?
  253.         je      scrin13                 ; e = yes
  254.         cmp     tekflg,0                ; Tek mode active within DEC stuff?
  255.         je      scrin14                 ; e = no
  256. scrin13:call    tekini                  ; reinit to get graphics screen
  257. scrin14:ret
  258. scrini  endp
  259.  
  260. ; Routine to initialize VT102/52/Heath-19 terminal emulator.
  261.  
  262. vtinit  proc    near
  263.         mov     holdscr,0               ; clear holdscreen
  264.         cmp     flags.vtflg,0           ; doing emulation?
  265.         je      vtinix                  ; e = no
  266.         cmp     tekflg,0                ; Tek mode active?
  267.         jne     vtini2                  ; ne = yes, do it's reinit
  268.         or      vtinited,inited
  269.         call    ansflg                  ; update ansi flags
  270.         mov     bx,argadr               ; Get address of argument block
  271.         mov     dl,[bx].flgs
  272.         and     dl,lclecho
  273.         and     yflags,not lclecho
  274.         or      yflags,dl
  275.         mov     al,yflags               ; Pass the flags
  276.         mov     dl,[bx].baudb           ; Baud rate code in dl
  277.         mov     dh,[bx].parity          ; Parity code in bits
  278.         mov     cl,4                    ; 0-3 of dh
  279.         shl     dh,cl
  280.         or      dh,07H                  ; Just say 7 data bits
  281.         test    flags.remflg,d8bit      ; eight bit display?
  282.         jz      vtini1                  ; z = no
  283.         inc     dh                      ; set low four bits to value 8
  284. vtini1: call    ansini                  ; call startup routine in mszibm
  285. vtinix: clc
  286.         ret
  287. vtini2: call    tekrint                 ; reinitialize Tek emulator
  288.         clc
  289.         ret
  290. vtinit  endp
  291.  
  292.  
  293. argini  proc    near                    ; read passed arguments
  294.         mov     bx,argadr               ; base of argument block
  295.         mov     al,[bx].flgs            ; get flags
  296.         and     al,capt+emheath+havtt+trnctl+lclecho+modoff+lnwrap
  297.         mov     yflags,al               ; mask for allowable and save
  298.         mov     al,[bx].prt
  299.         mov     portno,al               ; update port number
  300.         mov     al,[bx].rows
  301.         mov     crt_lins,al             ; init # of rows and cols
  302.         mov     ax,[bx].captr
  303.         mov     captrtn,ax              ; buffer capture routine
  304.         mov     al,[bx].escc
  305.         mov     esc_ch,al
  306.         mov     parmsk,0ffh             ; parity mask, assume parity = None
  307.         cmp     [bx].parity,parnon      ; is parity None?
  308.         je      argini1                 ; e = yes, keep all 8 bits
  309.         mov     parmsk,07fh             ; else keep lower 7 bits
  310. argini1:ret                             ; that's it
  311. argini  endp
  312.  
  313. modlin  proc    near                    ; turn on mode line
  314.   ; ************************** Change Connect Mode Line, Oct.8,1990 [zqf].
  315.         cmp     isccdos, 0              ; if in MS-DOS or CC-DOS ?
  316.         je      modl0                   ; e = in MS-DOS
  317.         jmp     cmodl0                  ; in CC-DOS
  318.   ; ***
  319.   ; ******** in MS-DOS below
  320. modl0:  mov     al,esc_ch
  321.         mov     modbuf.m_echr,' '       ; first char is initial space
  322.         mov     modbuf.m_hlp,' '        ; goes here too
  323.         cmp     al,32                   ; printable?
  324.         jnb     modl1                   ; yes, keep going
  325.         add     al,40h                  ; made printable
  326.         mov     modbuf.m_echr,5eh       ; caret, note control char
  327.         mov     modbuf.m_hlp,5eh
  328. modl1:  mov     modbuf.m_echr+1,al      ; fill in character
  329.         mov     modbuf.m_hlp+1,al
  330.         mov     bx,argadr               ; get argument block
  331.         mov     al,[bx].baudb           ; get baud bits
  332.         mov     si,offset unkbaud       ; assume unknown baud
  333.         cmp     al,baudnsiz             ; too big?
  334.         jnb     modl2                   ; nb = yes, use default
  335.         mov     cl,size m_baud          ; each is 5 bytes long
  336.         mul     cl
  337.         mov     ah,0
  338.         add     ax,offset baudn
  339.         mov     si,ax
  340. modl2:  mov     cx,size m_baud          ; length of baud space
  341.         mov     di,offset modbuf.m_baud
  342.         push    es                      ; save es
  343.         push    ds
  344.         pop     es                      ; set es to datas segment
  345.         cld
  346.         rep     movsb                   ; copy in baud rate
  347.         mov     al,[bx].parity          ; get parity code
  348.         shl     al,1                    ; each is 4 bytes long
  349.         shl     al,1
  350.         mov     ah,0
  351.         add     ax,offset parnams       ; names of parity settings
  352.         mov     si,ax
  353.         mov     cx,4                    ; each is 4 long
  354.         mov     di,offset modbuf.m_par
  355.         rep     movsb
  356.         mov     si,offset remmsg        ; Assume remote echoing
  357.         test    yflags,lclecho          ; Is remote side echoing?
  358.         jz      modl4                   ; Yes, keep going
  359.         mov     si,offset lclmsg        ; Else it's local echoing.
  360. modl4:  mov     cx,3                    ; size of on/off
  361.         mov     di,offset modbuf.m_echo
  362.         rep     movsb
  363.         mov     al,portno               ; communications port
  364.         cmp     al,' '                  ; binary (non-printable)?
  365.         jae     modl5                   ; ae = no, ascii
  366.         add     al,'0'                  ; convert to ascii
  367. modl5:  mov     modbuf.m_prt,al         ; fill in port number
  368.         mov     cx,8                    ; blank out terminal id field
  369.         mov     si,offset mtty          ; assume no terminal emulation
  370.         mov     di,offset modbuf.m_term ; destination
  371.         rep     movsb                   ; copy it in
  372.         mov     modbuf.m_prn,' '        ; assume not printing the screen
  373.         mov     modbuf.m_prn+1,' '
  374.         mov     modbuf.m_prn+2,' '
  375.         test    anspflg,prtscr          ; doing a print the screen?
  376.         jz      modl5a                  ; z = no
  377.         mov     modbuf.m_prn,'P'        ; yes. display PRN at end of line
  378.         mov     modbuf.m_prn+1,'R'
  379.         mov     modbuf.m_prn+2,'N'
  380. modl5a: mov     cx,size modfrm          ; this is size of mode line
  381.         mov     si,offset modbuf        ; mode line image
  382.         pop     es
  383.   ; **** 
  384.         jmp     modwrt
  385.   ; ******** in CC-DOS below
  386. cmodl0:  mov     al,esc_ch
  387.         mov     cmodbuf.cm_echr,' '       ; first char is initial space
  388.         mov     cmodbuf.cm_hlp,' '        ; goes here too
  389.         cmp     al,32                   ; printable?
  390.         jnb     cmodl1                   ; yes, keep going
  391.         add     al,40h                  ; made printable
  392.         mov     cmodbuf.cm_echr,5eh       ; caret, note control char
  393.         mov     cmodbuf.cm_hlp,5eh
  394. cmodl1:  mov     cmodbuf.cm_echr+1,al      ; fill in character
  395.         mov     cmodbuf.cm_hlp+1,al
  396.         mov     bx,argadr               ; get argument block
  397.         mov     al,[bx].baudb           ; get baud bits
  398.         mov     si,offset cunkbaud       ; assume unknown baud
  399.         cmp     al,baudnsiz             ; too big?
  400.         jnb     cmodl2                   ; nb = yes, use default
  401.         mov     cl,size cm_baud          ; each is 5 bytes long
  402.         mul     cl
  403.         mov     ah,0
  404.         add     ax,offset baudn
  405.         mov     si,ax
  406. cmodl2:  mov     cx,size cm_baud          ; length of baud space
  407.         mov     di,offset cmodbuf.cm_baud
  408.         push    es                      ; save es
  409.         push    ds
  410.         pop     es                      ; set es to datas segment
  411.         cld
  412.         rep     movsb                   ; copy in baud rate
  413.         mov     al,[bx].parity          ; get parity code
  414.         shl     al,1                    ; each is 4 bytes long
  415.         shl     al,1
  416.         mov     ah,0
  417.         add     ax,offset cparnams       ; names of parity settings
  418.         mov     si,ax
  419.         mov     cx,4                    ; each is 4 long
  420.         mov     di,offset cmodbuf.cm_par
  421.         rep     movsb
  422.         mov     si,offset cremmsg        ; Assume remote echoing
  423.         test    yflags,lclecho          ; Is remote side echoing?
  424.         jz      cmodl4                   ; Yes, keep going
  425.         mov     si,offset clclmsg        ; Else it's local echoing.
  426. cmodl4:  mov     cx,4                    ; size of on/off
  427.         mov     di,offset cmodbuf.cm_echo
  428.         rep     movsb
  429.         mov     al,portno               ; communications port
  430.         cmp     al,' '                  ; binary (non-printable)?
  431.         jae     cmodl5                   ; ae = no, ascii
  432.         add     al,'0'                  ; convert to ascii
  433. cmodl5:  mov     cmodbuf.cm_prt,al         ; fill in port number
  434.         mov     cx,8                    ; blank out terminal id field
  435.         mov     si,offset mtty          ; assume no terminal emulation
  436.         mov     di,offset cmodbuf.cm_term ; destination
  437.         rep     movsb                   ; copy it in
  438.         mov     cmodbuf.cm_prn,' '        ; assume not printing the screen
  439.         mov     cmodbuf.cm_prn+1,' '
  440.         mov     cmodbuf.cm_prn+2,' '
  441.         test    anspflg,prtscr          ; doing a print the screen?
  442.         jz      cmodl5a                  ; z = no
  443.         mov     cmodbuf.cm_prn,'P'        ; yes. display PRN at end of line
  444.         mov     cmodbuf.cm_prn+1,'R'
  445.         mov     cmodbuf.cm_prn+2,'N'
  446. cmodl5a: mov     cx,size cmodfrm          ; this is size of mode line
  447.         mov     si,offset cmodbuf        ; mode line image
  448.         pop     es
  449.   ; **************************  Oct.8,1990 [zqf].
  450.                         ; alternate entry to write an alternate mode line
  451. modwrt: push    cx
  452.         push    si                      ; save mode line and size
  453.         mov     ah,3                    ; read cursor position
  454.         xor     bx,bx                   ; screen page 0
  455.         int     screen
  456.         mov     cursor,dx               ; save cursor position
  457.         call    trmatt                  ; Get terminal attributes
  458.         and     ah,77h                  ; omit blinking/bold attributes
  459.         mov     bh,ah                   ; get video attribute
  460.         mov     dx,low_rgt              ; right most column
  461.         inc     dh                      ; refer to status line
  462.         mov     ch,dh                   ; bottom line [dlk]
  463.         mov     cl,0                    ; left col = 0 (first) [dlk]
  464.         mov     ax,600h                 ; scroll to clear the line
  465. ;**** Modify to suit CCDOS. Sept 5,1990 [zqf]
  466.         cmp     isccdos,1               ; if in CCDOS ?
  467.         jne     modl5b                  ; ne = No, in MS-DOS
  468.         mov     ax,cx                   ; in CCDOS
  469.         mov     bx,dx
  470.         call    atsclr                  ; clear mode line in CC-DOS
  471.         jmp     modl5c 
  472. modl5b: int     screen                  ; clear mode line in MS-DOS
  473. modl5c:
  474. ;****
  475.         mov     dh,byte ptr low_rgt+1   ; refer to status line
  476.         inc     dh
  477.         xor     dl,dl                   ; left most column
  478.         mov     bh,0
  479.         mov     ah,2                    ; set cursor position
  480.         int     screen
  481.         pop     si
  482.         pop     cx                      ; restore these
  483.         cmp     cl,crt_cols             ; mode line longer than screen?
  484.         jbe     modl6                   ; le = no
  485.         mov     cl,crt_cols             ; else do just one line's worth
  486.         dec     cx                      ; don't let screen scroll
  487. modl6:  cld
  488.         lodsb                           ; get a byte
  489.         mov     ah,14                   ; write to terminal
  490.         mov     bh,0                    ; page 0
  491.         int     screen
  492.         loop    modl6                   ; write out entire mode line
  493.         cmp     flags.vtflg,0           ; emulating?
  494.         je      modl7                   ; e = no
  495.         and     yflags,not modoff       ; update local flags (mode line on)
  496.         mov     al,yflags               ; Yes - update flags also
  497.         call    ansdsl                  ; get extras from emulator
  498. modl7:  mov     dx,cursor
  499.         mov     ah,2
  500.         mov     bh,0
  501.         int     screen                  ; put cursor back where it belongs
  502.         ret
  503. modlin  endp
  504.  
  505. clrmod  proc    near                    ; clear mode line
  506.         call    trmatt                  ; Get terminal screen attributes
  507.         mov     bh,al                   ; Use screen background attribute
  508.         mov     ax,600h                 ; blank window
  509.         mov     dx,low_rgt              ; right most column
  510.         inc     dh                      ; refer to status line
  511.         mov     cx,dx                   ; bottom line [dlk]
  512.         xor     cl,cl                   ; left most column
  513. ;**** Modify to suit CCDOS. June 25,1990 [zqf]
  514.         mov     ax,cx
  515.         mov     bx,dx
  516.         call    atsclr
  517. ;       int     screen                  ; clear mode line
  518. ;****
  519.         or      yflags,modoff           ; turn on flag
  520.         ret
  521. clrmod  endp
  522.  
  523.  
  524. ; Fetch screen attributes from emulator (if emulating). It exists mainly
  525. ; so that the reverse video will work.   Returns the current mode
  526. ; line background attribute in ah, the current screen background in al,
  527. ; and the current "cursor" (foreground) attribute in bl.  (Note: anstat
  528. ; returns status yflags in bh).
  529.  
  530. trmatt  proc    near                    ; Get attributes
  531.         cmp     flags.vtflg,0           ; emulating?
  532.         je      trmat1                  ; No, just do simple stuff
  533.         mov     al,yflags               ; anstat expects flags byte in al
  534.         call    anstat                  ; Fetch emulator status/attributes
  535.         ret
  536. trmat1: mov     al,scbattr              ; Background attributes
  537.         mov     bl,curattr              ; And cursor attribute
  538.         mov     ah,al                   ; where modlin needs them
  539.         and     ah,77h                  ; get colors part, no blink/bold
  540.         rol     ah,1                    ; reverse them
  541.         rol     ah,1
  542.         rol     ah,1
  543.         rol     ah,1
  544.         ret
  545. trmatt  endp
  546.  
  547. ; Get byte yflags of terminal emulator passed in AL. Used in mode line
  548. ; handling when 25th line is used by the emulator. [jrd]
  549. telmsy  proc    near
  550.         mov     yflags,al               ; get the updated flags
  551.         call    ansflg                  ; and any other emulator info
  552.         ret
  553. telmsy  endp
  554.  
  555.  
  556. ;[IU2] This routine updates the ANSI status flags from the emulator,
  557. ; and passes the "yflags" byte to the VT100 emulator also.
  558.  
  559. ansflg  proc    near
  560.         push    ax                      ; save regs
  561.         push    bx
  562.         mov     al,yflags
  563.         call    anstat                  ; Get status and attributes
  564.         mov     ansflgs,bh              ; Save
  565.         test    ansflgs,dececho         ; does host want us to do local echo?
  566.         jz      ansflg1                 ; z = no, use working default
  567.         or      yflags,lclecho          ; turn on local echoing
  568. ansflg1:pop     bx
  569.         pop     ax
  570.         ret
  571. ansflg  endp
  572.  
  573. getflgs proc    near                    ; supply yflags for terminal emulators
  574.         mov     al,yflags
  575.         ret
  576. getflgs endp
  577.  
  578. term    proc    near                    ; terminal mode entry point
  579.         mov     argadr,ax               ; save argument ptr
  580.         call    argini                  ; init options from arg address
  581.         call    scrini                  ; init screen stuff
  582.         mov     bx,portval              ; port data structure address
  583.         mov     bx,[bx].flowc           ; get flow control chars (bl=xoff)
  584.         mov     flowon,bh
  585.         mov     flowoff,bl              ; save for later
  586.         mov     oldsp,sp                ; remember stack for i/o failure,
  587.                                         ;  used by procedure  endcon
  588. lp:     call    prtchr                  ; char at port?
  589.          jmp    short lpinp             ; yes, go handle
  590.          nop                            ; else look at kbd
  591. lpkbd:  mov     fairness,0              ; say kbd was examined
  592.         call    keybd                   ; call keyboard translator in msu
  593.         jnc     lp                      ; nc = no char or have processed it
  594.         jmp     short quit              ; carry set = quit connect mode
  595. lpinp:  and     al,parmsk               ; apply 8/7 bit parity mask
  596.         call    outtty                  ; print on terminal
  597.         inc     fairness                ; say read port but not kbd, again
  598.         cmp     fairness,100            ; this many port reads before kbd?
  599.         jb      lp                      ; b = no, read port again
  600.         jmp     short lpkbd             ; yes, let user have a chance too
  601.  
  602. quit:   
  603.         call    pntflsh                 ; flush printer buffer
  604.         call    tekend                  ; cleanup Tektronix mode [bjh]
  605.         mov     ah,3                    ; get cursor position into dx
  606.         xor     bh,bh                   ; page 0
  607.         int     screen
  608.         mov     cursor,dx               ; save position
  609.         cmp     flags.vtflg,0           ; terminal type of none?
  610.         ja      quit1                   ; a = yes
  611.         test    yflags,modoff           ; is modeline still toggled off?
  612.         jnz     quit1                   ; nz = yes
  613.         call    clrmod                  ; clear it before storing screen
  614. quit1:  nop
  615. ;****************** 
  616.         call    savescr                 ; save screen in MS-DOS
  617. ;*******************
  618.         mov     ax,0600h                ; clear mode line with old attributes
  619.         mov     bh,oldattr              ; attributes
  620.         mov     dx,low_rgt              ; right most column
  621.         inc     dh                      ; refer to status line
  622.         mov     cx,dx                   ; bottom line [dlk]
  623.         xor     cl,cl                   ; left most column
  624. ;**** Modify to suit CCDOS. June 25,1990 [zqf]
  625.         mov     ax,cx
  626.         mov     bx,dx
  627.         call    atsclr
  628. ;       int     screen                  ; clear mode line
  629. ;****
  630.         mov     ah,oldattr              ; attributes at init time
  631.         mov     scbattr,ah              ; background = original state
  632.                                         ; for ega in non-standard # lines
  633.         cmp     ega_mode,0              ; ega board active?
  634.         je      quit2                   ; e = no
  635.         cmp     byte ptr low_rgt+1,23   ; is screen standard length?
  636.         je      quit2                   ; e = yes, so regular cursor set is ok
  637.         push    es                      ; turn off ega cursor emulation
  638.         mov     ax,40h                  ; byte 40:87H is ega Info byte
  639.         mov     es,ax
  640.         push    es:[87h]                ; save info byte around call
  641.         or      byte ptr es:[87h],1     ; set emulation off (low bit = 1)
  642.         mov     cx,lincur               ; cursor shape to set
  643.         mov     ah,1                    ; set the shape
  644.         int     screen                  ;   back to starting value
  645.         pop     es:[87h]                ; recover original Info byte
  646.         pop     es                      ; and our work reg
  647.         jmp     short quit3             ; skip regular mode cursor setting
  648. quit2:                                  ; for regular sized screen
  649.         mov     cx,lincur               ; cursor type at startup
  650.         mov     ah,1
  651.         int     screen                  ; restore cursor type
  652. quit3:  mov     ah,2                    ; Position cursor
  653.         mov     bh,0                    ; Page 0
  654.         mov     dx,low_rgt              ; bottom line
  655.         inc     dh                      ; status line position
  656.         xor     dl,dl                   ; left most column
  657. ; ---------don't set cursor in CCDOS. Dec.12,1990 [zqf]
  658. IFDEF   CGA         ; Add Option CGA to servered screen.Mar.21,1991 [zqf]
  659.         cmp     isccdos,1               ; is in CCDOS ?
  660.         je      quit4                  ; e = yes, skip 
  661. ENDIF
  662.         int     screen                  ; Do it
  663. quit4:
  664. ; -----------
  665.         mov     al,yflags
  666.         and     al,not lclecho          ; don't copy host's echo flag
  667.         mov     bx,argadr
  668.         mov     ah,[bx].flgs            ; get user's flag settings
  669.         and     ah,lclecho              ; clear all but local echo bit
  670.         or      [bx].flgs,al            ; update flags in arg block
  671.         ret
  672. term    endp
  673.  
  674. ; put the character in al to the screen
  675. outtty  proc    near
  676.         cmp     flags.vtflg,0           ; emulating a terminal?
  677.         jne     outnoc                  ; ne = yes, emulator handles printing
  678.         test    flags.remflg,d8bit      ; keep 8 bits for displays?
  679.         jnz     outnp9                  ; nz = yes, 8 bits if possible
  680.         and     al,7fh                  ; remove high bit
  681. outnp9: cmp     rxtable+256,0           ; translation turned off?
  682.         je      outnp7                  ; e = yes, no translation
  683.         push    bx
  684.         mov     bx,offset rxtable       ; address of translate table
  685.         xlatb                           ; new char is in al
  686.         pop     bx
  687. outnp7: test    anspflg,prtscr          ; should we be printing?
  688.         jz      outnop                  ; no, keep going
  689.         call    pntchr                  ; queue char for printer
  690.         jnc     outnop                  ; nc = successful print
  691.         push    ax
  692.         call    beep                    ; else make a noise and
  693.         call    trnprs                  ;  turn off printing
  694.         pop     ax
  695. outnop: test    yflags,capt             ; capturing output?
  696.         jz      outnoc                  ; no, forget this part
  697.         push    ax                      ; save char
  698.         call    captrtn                 ; give it captured character
  699.         pop     ax                      ; restore character and keep going
  700. outnoc: cmp     vtroll,0                ; auto roll back allowed?
  701.         jz      outnp6                  ; z = no, leave screen as is
  702.         cmp     tekflg,0                ; Tek mode active?
  703.         jne     outnp6                  ; ne = yes, skip screen rolling
  704.         cmp     bwnd.lcnt,0             ; is screen rolled back? [dlk]
  705.         je      outnp6                  ; e = no
  706. ; ---------don't set cursor in CCDOS. Dec.12,1990 [zqf]
  707. IFDEF   CGA         ; Add Option CGA to servered screen.Mar.21,1991 [zqf]
  708.         cmp     isccdos,1               ; is in CCDOS ?
  709.         je      outnpa                  ; e = yes, skip 
  710. ENDIF
  711.         call    endwnd                  ; restore screen before writing [dlk]
  712. outnpa:
  713. ; -----------
  714. outnp6: cmp     flags.vtflg,0           ; emulating a terminal?
  715.         jne     outnop1                 ; ne = yup, go do something smart
  716.         test    yflags,trnctl           ; debug? if so use Bios tty mode
  717.         jz      outnp4                  ; z = no
  718.         mov     ah,biostty              ; Bios tty screen write
  719.         cmp     al,7fh                  ; Ascii Del char or greater?
  720.         jb      outnp1                  ; b = no
  721.         je      outnp0                  ; e = Del char
  722.         push    ax                      ; save the char
  723.         mov     al,7eh                  ; output a tilde for 8th bit
  724.         int     screen
  725.         pop     ax                      ; restore char
  726.         and     al,7fh                  ; strip high bit
  727. outnp0: cmp     al,7fh                  ; is char now a DEL?
  728.         jne     outnp1                  ; ne = no
  729.         and     al,3fH                  ; strip next highest bit (Del --> '?')
  730.         jmp     outnp2                  ; send, preceded by caret
  731. outnp1: cmp     al,' '                  ; control char?
  732.         jae     outnp3                  ; ae = no
  733.         add     al,'A'-1                ; make visible
  734. outnp2: push    ax                      ; save char
  735.         mov     al,5eh                  ; caret
  736.         int     screen                  ; display it
  737.         pop     ax                      ; recover the non-printable char
  738. outnp3: push    ax
  739.         int     screen
  740.         pop     ax
  741.         ret
  742. outnp4: cmp     al,bell                 ; bell (Control G)?
  743.         jne     outnp5                  ; ne = no
  744.         jmp     beep                    ; use short beep, avoid char loss
  745. outnp5: mov     dl,al                   ; write without intervention
  746.         mov     ah,conout
  747.         int     dos                     ; else let dos display char
  748.         ret
  749.  
  750. outnop1:cmp     flags.vtflg,tttek       ; doing Tektronix emulation?
  751.         je      outnop2                 ; e = yes, use Tek emulator
  752.         cmp     tekflg,0                ; Tek submode active?
  753.         jne     outnop2                 ; ne = yes, use Tek emulator
  754.         jmp     anstty                  ; call terminal emulator routine & ret
  755. outnop2:jmp     tekemu                  ; use Tek emulator and return
  756.  
  757. outtty  endp
  758.  
  759. ;[IU2] Here to output character to port with no echo (like escape sequences
  760. ; sent by PF keys, responses to requests from the host, etc.   It is
  761. ; wrong thinking to echo these).
  762.  
  763. prtbout proc    near                    ; Global routine now
  764.         mov     ah,al                   ; This is where outchr expects it
  765.         call    outchr
  766.          jmp    endcon                  ; failure, end connection
  767.          nop
  768.         clc                             ; carry clear for success
  769.         ret
  770. prtbout endp
  771.  
  772.  
  773. ;[IU2] Here to output an unsigned 8-bit number (in al) to the port without
  774. ; echoing. Used by terminal emulator escape sequence output.
  775.  
  776. prtnout proc    near
  777.         mov     bl,10                   ; Output in base 10
  778.         jmp     prtno2                  ; Ensure at least a zero
  779.  
  780. prtno1: cmp     al,0
  781.         jne     prtno2                  ; Yes - do more digits
  782.         ret                             ; No - return from recursive call
  783. prtno2: mov     ah,0                    ; Clear previous remainder
  784.         div     bl                      ; Divide off a digit
  785.         push    ax                      ; Push remainder (in ah) on stack
  786.         call    prtno1                  ; Recur
  787.         pop     ax                      ; Pop off a digit
  788.         add     ah,'0'                  ; Make it ASCII
  789.         call    outchr                  ; send to port
  790.          jmp    endcon                  ; failure, end connection
  791.          nop
  792.         clc                             ; carry clear for success
  793.         ret
  794. prtnout endp
  795.  
  796. ; send the character in al out to the serial port; handle echoing.
  797. ; Can send an 8 bit char while displaying only 7 bits locally.
  798. outprt  proc    near
  799.         test    yflags,lclecho          ; echoing?
  800.         jz      outpr1                  ; z = no, forget it
  801.         push    ax                      ; save char
  802.         call    outtty                  ; print it
  803.         pop     ax                      ; restore
  804. outpr1: mov     ah,al                   ; this is where outchr expects it
  805.         call    outchr                  ; output to the port
  806.          jmp    endcon                  ; failure, end connection
  807.          nop
  808.         clc                             ; carry clear for success
  809.         ret
  810. outprt  endp
  811.  
  812. ; Jump here to exit Connect mode and execute macros 'TERMINALR' (vtrmac) or
  813. ; 'TERMINALS' (vtsmac). Does nothing if macro does not exist.
  814. ; Preserves registers except ax. Returns to TELNET caller with 'C' in kbdflg.
  815. vtrmac  proc    near                    ; RESET macro
  816.         mov     ax,offset vtrname       ; select macro name
  817.         mov     vtmacname,ax
  818.         mov     vtmaclen,vtrlen         ; and its length
  819.         jmp     short vtmacro           ; finish in common code
  820. vtrmac  endp
  821.  
  822. vtsmac  proc    near                    ; SET macro
  823.         mov     ax,offset vtsname
  824.         mov     vtmacname,ax
  825.         mov     vtmaclen,vtslen
  826.         jmp     short vtmacro
  827. vtsmac  endp
  828.  
  829. ;
  830. ; Reference     Macro structure for     db      number of entries (mac names)
  831. ;  is file       table mcctab      |->  db      length of macroname, excl '$'
  832. ;  mssset.asm           each entry |->  db      'macroname','$'
  833. ;  where these                     |->  dw      offset of definition string
  834. ;  are stored.
  835. ;               Definition string in    db      length of <string with null>
  836. ;                buffer macbuf          db      'string with trailing null'
  837. ;
  838. vtmacro proc    near                    ; common code for macros vtsmac,vtrmac
  839.         push    bx
  840.         push    cx
  841.         push    si
  842.         mov     bx,offset mcctab        ; table of macro names
  843.         mov     cl,[bx]                 ; number of names in table
  844.         xor     ch,ch
  845.         jcxz    vtmacx                  ; z = empty table, do nothing
  846.         inc     bx                      ; point to length of first name
  847. vtmac2: mov     al,[bx]                 ; length of this name
  848.         xor     ah,ah
  849.         cmp     al,vtmaclen             ; length same as desired keyword?
  850.         jne     vtmac3                  ; ne = no, search again
  851.         mov     si,bx
  852.         inc     si                      ; point at first char of name
  853.         push    cx                      ; save name counter
  854.         push    di                      ; save reg
  855.         mov     cl,vtmaclen             ; length of name, excluding '$'
  856.         xor     ch,ch
  857.         mov     di,vtmacname            ; point at desired macro name
  858.         push    es                      ; save reg
  859.         push    ds
  860.         pop     es                      ; make es use datas segment
  861.         cld
  862.         repe    cmpsb                   ; match strings
  863.         pop     es                      ; need current si below
  864.         pop     cx
  865.         pop     di                      ; recover saved regs
  866.         je      vtmac4                  ; e = matched
  867. vtmac3: add     bx,ax                   ; step to next name, add name length
  868.         add     bx,4                    ; + count, dollar sign, def word ptr
  869.         loop    vtmac2                  ; try next name
  870. vtmacx: pop     si                      ; no macro, return to Connect mode
  871.         pop     cx
  872.         pop     bx
  873.         ret
  874.  
  875. vtmac4: cmp     taklev,maxtak           ; room in Take level?
  876.         jge     vtmacx                  ; ge = no, exit with no action
  877.         inc     taklev                  ; increment take level
  878.         add     takadr,size takinfo     ; make a new Take entry/macro
  879.         mov     bx,takadr               ; point to current macro structure
  880.         inc     si                      ; skip dollar sign after name
  881.         mov     si,[si]                 ; get definition address
  882.         mov     [bx].takbuf,si          ; address of definition string struc
  883.         mov     cl,[si]                 ; length byte of definition
  884.         xor     ch,ch
  885.         mov     [bx].takcnt,cx          ; number of chars in definition
  886.         inc     si                      ; address of definition text proper
  887.         mov     [bx].takptr,si          ; where to read next command char
  888.         mov     [bx].taktyp,0ffh        ; flag as a macro
  889.         pop     si
  890.         pop     cx
  891.         pop     bx
  892.         jmp     endcon                  ; exit Connect mode
  893. vtmacro endp
  894.  
  895. ; Error recovery routine used when outchr reports unable to send character
  896. ;  or when vtmacro requests exiting Connect mode.
  897. ; Exit Connect mode cleanly, despite layers of intermediate calls.
  898. endcon  proc    near
  899.         mov     kbdflg,'C'              ; report 'C' to TERM's caller
  900.         mov     sp,oldsp                ; recover startup stack pointer
  901.                                         ; TERM caller's return address is now
  902.                                         ; on the top of stack. A longjmp.
  903.         jmp     quit                    ; exit Connect mode cleanly
  904. endcon  endp
  905.  
  906. ;;; Action routines (verbs) for keyboard translator KEYBD in msuibm.
  907. ; These are invoked by a jump instruction. Return carry clear for normal
  908. ; processing, return carry set for invoking Quit (kbdflg has transfer char).
  909. uparrw: mov     al,'A'                  ; cursor keys
  910.         jmp     short comarr
  911. dnarrw: mov     al,'B'
  912.         jmp     short comarr
  913. rtarr:  mov     al,'C'
  914.         test    vtemu.vtflgop,vswdir    ; writing left to right?
  915.         jz      comarr                  ; z = yes
  916.         mov     al,'D'                  ; reverse sense of keys
  917.         jmp     short comarr
  918. lfarr:  mov     al,'D'
  919.         test    vtemu.vtflgop,vswdir    ; writing left to right?
  920.         jz      comarr                  ; z = yes
  921.         mov     al,'C'                  ; reverse sense of keys
  922. comarr: push    ax                      ; save final char
  923.         mov     ttyact,0                ; network, group chars for packet
  924.         mov     al,escape               ; Output an escape
  925.         call    outprt                  ; Output, echo permitted
  926.         cmp     flags.vtflg,tttek       ; Tek terminal?
  927.         je      comar0                  ; e = yes, use VT100 codes
  928.         cmp     flags.vtflg,ttvt100     ; VT100 terminal emulation?
  929.         jne     comar2                  ; No, do VT52/HEATH-19 sequence
  930. comar0: call    ansflg                  ; Update flags all around
  931.         mov     al,'['                  ; Maybe this next?
  932.         test    ansflgs,decckm          ; Cursor key mode reset?
  933.         je      comar1                  ; Yes, output the "["
  934.         mov     al,'O'                  ; No, set, use the "O"
  935. comar1: call    outprt                  ; Output it (echo permitted)
  936. comar2: pop     ax                      ; recover final char
  937.         mov     ttyact,1                ; network, restore tty active flag
  938.         call    outprt                  ; Output to port (echo permitted)
  939.         ret
  940.  
  941. pf1:    mov     al,'P'                  ; keypad function keys 1-4
  942.         jmp     short compf
  943. pf2:    mov     al,'Q'
  944.         jmp     short compf
  945. pf3:    mov     al,'R'
  946.         jmp     short compf
  947. pf4:    mov     al,'S'
  948. compf:  push    ax                      ; save final char
  949.         mov     ttyact,0                ; network, group chars for packet
  950.         mov     al,escape               ; Output an escape
  951.         call    prtbout
  952.         call    ansflg                  ; get emulator flags
  953.         test    ansflgs,decanm          ; ansi mode?
  954.         jz      short compf1            ; z = no
  955.         mov     al,'O'                  ; send an "O"
  956.         call    prtbout                 ; Output it
  957. compf1: pop     ax                      ; Get the saved char back
  958.         mov     ttyact,1                ; network, restore tty active flag
  959.         call    prtbout                 ; Output to port
  960.         ret
  961.  
  962. kp0:    mov     al,'p'                  ; keypad numeric keys
  963.         jmp     short comkp
  964. kp1:    mov     al,'q'
  965.         jmp     short comkp
  966. kp2:    mov     al,'r'
  967.         jmp     short comkp
  968. kp3:    mov     al,'s'
  969.         jmp     short comkp
  970. kp4:    mov     al,'t'
  971.         jmp     short comkp
  972. kp5:    mov     al,'u'
  973.         jmp     short comkp
  974. kp6:    mov     al,'v'
  975.         jmp     short comkp
  976. kp7:    mov     al,'w'
  977.         jmp     short comkp
  978. kp8:    mov     al,'x'
  979.         jmp     short comkp
  980. kp9:    mov     al,'y'
  981.         jmp     short comkp
  982. kpminus:mov     al,'m'
  983.         jmp     short comkp
  984. kpcoma: mov     al,'l'
  985.         jmp     short comkp
  986. kpenter:mov     al,'M'
  987.         jmp     short comkp
  988. kpdot:  mov     al,'n'
  989. comkp:  test    ansflgs,deckpam         ; keypad application mode active?
  990.         jnz     comkp3                  ; nz = yes, use escape sequences
  991.         sub     al,40h                  ; deduct offset to numeric symbols
  992.         jmp     comkp0                  ; and send that single char
  993. comkp3: push    ax                      ; save final char
  994.         mov     ttyact,0                ; network, group chars for packet
  995.         mov     al,escape               ; Output an escape
  996.         call    prtbout
  997.         mov     al,'O'                  ; Output the "O"
  998.         cmp     flags.vtflg,ttvt100     ; VT100 mode?
  999.         je      comkp1                  ; e = yes, use "O" code
  1000.         cmp     flags.vtflg,tttek       ; Tek terminal
  1001.         je      comkp1                  ; e = yes, use VT100 codes
  1002.         test    ansflgs,decanm          ; ANSI (alt application keypad) mode?
  1003.         jnz     comkp1                  ; nz = yes, use "O"
  1004. comkp2: mov     al,'?'                  ; else use "?" instead of "O"
  1005. comkp1: call    prtbout
  1006.         pop     ax                      ; recover final char
  1007. comkp0: mov     ttyact,1                ; network, restore tty active flag
  1008.         call    prtbout                 ; send it
  1009.         ret
  1010.  
  1011. klogon  proc    near                    ; resume logging (if any)
  1012.         test    flags.capflg,logses     ; session logging enabled?
  1013.         jz      klogn                   ; z = no, forget it
  1014.         or      argadr.flgs,capt        ; turn on capture flag
  1015.         or      yflags,capt             ; set local msy flag as well
  1016.         call    ansflg                  ; tell emulator
  1017. klogn:  clc
  1018.         ret
  1019. klogon  endp
  1020.  
  1021. klogof  proc    near                    ; suspend logging (if any)
  1022.         and     argadr.flgs,not capt    ; stop capturing
  1023.         and     yflags,not capt         ; reset local msy flag as well
  1024.         call    ansflg                  ; tell emulator
  1025. klogo:  clc
  1026.         ret
  1027. klogof  endp
  1028.  
  1029. snull   proc    near                    ; send a null byte
  1030.         mov     al,0                    ; the null
  1031.         jmp     prtbout                 ; send without logging and local echo
  1032. snull   endp
  1033.  
  1034. khold:  xor     holdscr,1               ; toggle Hold screen byte for msx
  1035.         clc
  1036.         ret
  1037.                                         ; general character out for emulator
  1038. chrout: cmp     flags.vtflg,0           ; emulating?
  1039.         je      chrou5                  ; e = no
  1040.         call    anskbi                  ; Yes, say we had keyboard input
  1041.         cmp     al,cr                   ; A CR?
  1042.         jne     chrou5                  ; No - just output it and return
  1043.         call    ansflg                  ; Yes - update VT100 flags
  1044.         test    ansflgs,anslnm          ; ANSI new-line mode set?
  1045.         jz      chrou5                  ; No - just send the cr
  1046.         call    outprt                  ; Yes - output a carriage-return
  1047.         mov     al,lf                   ; Followed by a line feed
  1048. chrou5: call    outprt
  1049.         ret
  1050.  
  1051.                                         ; these commands invoke Quit
  1052. cdos:   mov     al,'P'                  ; Push to DOS
  1053.         jmp     short cmdcom
  1054. cstatus:mov     al,'S'                  ; Status
  1055.         jmp     short cmdcom
  1056. cquit:  mov     al,'C'                  ; Exit Connect mode
  1057.         jmp     short cmdcom
  1058. cquery: mov     al,'?'                  ; Help
  1059.         jmp     short cmdcom
  1060. chang:  mov     al,'H'                  ; Hangup, drop DTR & RTS
  1061.         jmp     short cmdcom
  1062. cmdcom: mov     kbdflg,al               ; pass char to msster.asm via kbdflg
  1063.         stc                             ; signal that Quit is needed
  1064.         ret
  1065.  
  1066. dmpscn  proc    near                    ; dump screen to file
  1067.         call    savescr                 ; save screen to buffer
  1068.         call    dumpscr                 ; do buffer to file
  1069.         clc                             ; do not exit Connect mode
  1070.         ret
  1071. dmpscn  endp
  1072.  
  1073.  
  1074. ;[IU2] Routine to toggle VT100/VT52/Heath-19 modes in VT100 emulator.
  1075.  
  1076. vtans52 proc    near
  1077.         cmp     flags.vtflg,0           ; emulating?
  1078.         je      vtans5                  ; e = no
  1079.         call    ans52t                  ; Call MSZ toggle-it routine
  1080.         call    ansflg                  ; Update flags
  1081.         clc                             ; clear c bit so don't exit Connect
  1082. vtans5: ret
  1083. vtans52 endp
  1084.                                         ; Toggle Mode Line
  1085. trnmod: cmp     flags.modflg,1          ; mode line enabled and owned by us?
  1086.         jne     trnm2                   ; ne = no, don't touch it
  1087.         cmp     flags.vtflg,tttek       ; Tek mode?
  1088.         je      trnm2                   ; yes
  1089.         cmp     tekflg,0                ; Tek submode?
  1090.         jne     trnm2                   ; ne = yes, no mode line changes
  1091.         test    yflags,modoff           ; mode line already off?
  1092.         jnz     trnm1                   ; yes, go turn on
  1093.         call    clrmod                  ; no, clear mode line here
  1094.         or      yflags,modoff           ; turn on flag
  1095.         call    ansflg                  ; Update flags all around
  1096.         clc                             ; clear c bit so don't exit Connect
  1097.         ret
  1098. trnm1:  and     yflags,not modoff       ; Clear flag first
  1099.         cmp     flags.vtflg,0           ; terminal type of none?
  1100.         ja      trnm3
  1101.         push    dx                      ; scroll screen to save bottom line
  1102.         mov     ah,prstr                ; for terminal type none
  1103.         mov     dx,offset crlf
  1104.         int     dos
  1105.         pop     dx
  1106. trnm3:  call    modlin                  ; Then turn on mode line
  1107.         call    ansflg                  ; Update flags all around
  1108. trnm2:  clc
  1109.         ret
  1110.  
  1111. trnprs: push    ax                      ; toggle ^ PrtSc screen to printer
  1112.         test    anspflg,prtscr          ; are we currently printing?
  1113.         jnz     trnpr2                  ; nz = yes, its on and going off
  1114.         mov     ah,ioctl
  1115.         mov     al,7                    ; get output status of printer
  1116.         push    bx
  1117.         mov     bx,4                    ; file handle for system printer
  1118.         int     dos
  1119.         pop     bx
  1120.         jc      trnpr1                  ; c = printer not ready
  1121.         cmp     al,0ffh                 ; Ready status?
  1122.         je      trnpr2                  ; e = Ready
  1123. trnpr1: call    beep                    ; Not Ready, complain
  1124.         jmp     trnpr3                  ; and ignore request
  1125. trnpr2: xor     anspflg,prtscr          ; flip the flag
  1126.         test    yflags,modoff           ; mode line off?
  1127.         jnz     trnpr3                  ; nz = yes
  1128.         call    modlin                  ; else rewrite mode line
  1129. trnpr3: pop     ax
  1130.         clc                             ; return carry clear (don't quit)
  1131.         ret
  1132.  
  1133. ; Print on PRN the char in register al. On success return with C bit clear.
  1134. ; On failure do procedure pntchk and return its C bit (typically C set).
  1135. ; Uses buffer dumpbuf (screen dump).
  1136. pntchr  proc    near
  1137.         push    bx                      ; buffer the character
  1138.         mov     bx,pntptr               ; offset of next free byte in buffer
  1139.         mov     [bx],al                 ; store the character
  1140.         inc     bx                      ; update pointer
  1141.         mov     pntptr,bx               ; save pointer
  1142.         cmp     bx,offset dumpbuf+dumplen ; buffer full yet?
  1143.         pop     bx
  1144.         jb      pntchrx                 ; b = no, just return
  1145.         jmp     pntflsh                 ; go flush the buffer
  1146. pntchrx:clc                             ; clear carry bit
  1147.         ret
  1148. pntchr  endp
  1149.  
  1150. ; Flush printer buffer. Return carry clear if success.
  1151. ; On failure do procedure pntchk and return its C bit (typically C set).
  1152. ; Uses buffer dumpbuf (screen dump).
  1153. pntflsh proc    near
  1154.         cmp     pntptr,offset dumpbuf   ; any text in buffer?
  1155.         jne     pntfls1                 ; ne = yes
  1156.         ret                             ; else nothing to do
  1157. pntfls1:push    ax
  1158.         push    bx
  1159.         push    cx
  1160.         push    dx
  1161.         mov     bx,portval
  1162.         mov     bx,[bx].flowc           ; get flow control chars (bl=xoff)
  1163.         mov     flowon,bh
  1164.         mov     flowoff,bl              ; save for later
  1165.         mov     al,bl                   ; get flow control char
  1166.         cmp     al,0                    ; flow control active?
  1167.         je      pntfls2                 ; e = no, not using xoff
  1168.         call    prtbout                 ; output xoff (al), no echo
  1169. pntfls2:mov     ah,write2
  1170.         mov     bx,4                    ; file handle for DOS printer PRN
  1171.         mov     cx,pntptr               ; next free byte in buffer
  1172.         mov     dx,offset dumpbuf       ; start of buffer
  1173.         mov     pntptr,dx               ; reset buffer pointer
  1174.         sub     cx,dx                   ; cx = current byte count
  1175.         jcxz    pntfls3                 ; z = empty, do nothing
  1176.         int     dos                     ; write buffer to printer
  1177. pntfls3:pushf                           ; save carry status bit
  1178.         mov     al,flowon
  1179.         cmp     al,0                    ; flow control active?
  1180.         je      pntfls4                 ; e = no, not using xon
  1181.         call    prtbout                 ; output xon (al), no echo
  1182. pntfls4:popf
  1183.         pop     dx
  1184.         pop     cx
  1185.         pop     bx
  1186.         pop     ax
  1187.         jnc     pntflsx                 ; nc = success
  1188.         call    pntchk                  ; c = error (printer not ready)
  1189. pntflsx:ret
  1190. pntflsh endp
  1191.  
  1192. ; Check for PRN (DOS's printer) being ready. If ready, return with C clear
  1193. ; Otherwise, write Not Ready msg on mode line and return with C bit set.
  1194. ; N.B. DOS Critical Error will occur here if PRN is not ready.  [jrd]
  1195. pntchk  proc    near
  1196.         push    dx
  1197.         push    cx
  1198.         push    ax
  1199.         mov     cx,10                   ; ten retries before declaring error
  1200. pntchk0:mov     ah,ioctl                ; get printer status, via DOS
  1201.         mov     al,7                    ; status for output
  1202.         push    bx
  1203.         mov     bx,4                    ; std handle for DOS system printer
  1204.         int     dos
  1205.         pop     bx
  1206.         jc      pntchk1                 ; c = call failed
  1207.         cmp     al,0ffh                 ; code for Ready?
  1208.         je      pntchk3                 ; e = yes, assume printer is ready
  1209. pntchk1:push    cx                      ; save counter, just in case
  1210.         mov     ax,100                  ; wait 100 millisec
  1211.         call    pcwait
  1212.         pop     cx
  1213.         loop    pntchk0                 ; and try a few more times
  1214.                                         ; get here when printer is not ready
  1215.         test    yflags,modoff           ; is mode line off?
  1216.         jnz     pntchk2                 ; nz = off, skip msg
  1217.         push    bx
  1218.         push    si
  1219. ;        mov     si,offset pntmsg        ; say printer not ready
  1220.         mcmsgsi pntmsg, cpntmsg
  1221.         mov     cx,pntmsgl              ; length
  1222.         cmp     isccdos,0
  1223.         je      pntchk11
  1224.         mov     cx,cpntmsgl
  1225. pntchk11:
  1226.         call    modwrt                  ; write alternate mode line
  1227.         pop     si
  1228.         pop     bx
  1229. pntchk2:pop     ax
  1230.         pop     cx
  1231.         pop     dx
  1232.         stc                             ; say printer not ready
  1233.         ret
  1234. pntchk3:pop     ax
  1235.         pop     cx
  1236.         pop     dx
  1237.         clc                             ; say printer is ready
  1238.         ret
  1239. pntchk  endp
  1240.  
  1241. ;;;;; General screen management routines for IBM PC
  1242.  
  1243. ; computes screen location to ax, given row and col in [dh,dl], resp.
  1244.  
  1245. scrloc  proc    near
  1246.         mov     al,dh                   ; get row
  1247.         mul     crt_cols                ; multiply by number of columns
  1248.         add     al,dl                   ; plus current column number
  1249.         adc     ah,0                    ; ripple carry
  1250.         shl     ax,1                    ; double for attributes
  1251.         ret
  1252. scrloc  endp
  1253.  
  1254. ; Routine to set cursor type.  Pass cursor type in al: 0 = No cursor,
  1255. ; 1 = Underline cursor, 2 = Block cursor.   All cursors blink due to hardware.
  1256. ; Routine frags any ac that video ints frag.
  1257. ; For EGA boards running in non-25 line mode the cursor emulation is turned
  1258. ; off during cursor shape changing and restored afterward. It's another
  1259. ; ega Feature. [jrd]
  1260. ; Sense crt_mode 18h as Tseng Labs UltraPAK mono board in 132 column mode.
  1261. csrtype proc    near
  1262.         push    cx                      ; save the reg
  1263.         mov     ah,1                    ; Video fxn for set cursor type
  1264.         mov     cx,0F00H                ; Assume no cursor
  1265.         cmp     al,0                    ; No cursor?
  1266.         je      csrty2                  ; Right - set it and be done with it
  1267.         cmp     crt_mode,7              ; B&W card?
  1268.         je      csrty3                  ; Yes - different sizes
  1269.         cmp     crt_mode,18h            ; Tseng UltraPAK mono board?
  1270.         je      csrty3                  ; e = yes, use mono cursor
  1271.         mov     cx,0607H                ; No, use CGA underline cursor
  1272.         cmp     al,2                    ; Block?
  1273.         jne     csrty2                  ; No - set it now
  1274. csrty1: xor     ch,ch                   ; Yes - make it a block
  1275. csrty2: cmp     ega_mode,0              ; ega board active?
  1276.         je      csrty4                  ; e = no
  1277.         cmp     byte ptr low_rgt+1,23   ; standard screen length?
  1278.         je      csrty4                  ; e = yes, use regular cursor setting
  1279.         push    es                      ; EGA. turn off cursor emulation
  1280.         mov     ax,40h                  ; 40:87h is ega Info byte
  1281.         mov     es,ax
  1282.         push    es:[87h]                ; save Info byte around call
  1283.         or      byte ptr es:[87h],1     ; set emulation off (low bit = 1)
  1284.         mov     ah,1                    ; Video fxn for set cursor type
  1285.         int     screen
  1286.         pop     es:[87h]                ; restore Info byte
  1287.         pop     es                      ;  and our work register
  1288.         pop     cx
  1289.         ret
  1290. csrty4: int     screen                  ; regular cursor shape setting
  1291.         pop     cx
  1292.         ret
  1293. csrty3: mov     cx,0B0CH                ; Assume B&W underline cursor
  1294.         cmp     al,2                    ; Block?
  1295.         jne     csrty2                  ; No - set it now
  1296.         jmp     csrty1                  ; Yes - make it a block
  1297. csrtype endp
  1298.  
  1299.  
  1300. ; Save the entire screen in a buffer so we can restore and/or dump it.
  1301. ; Saves regular (80x25) screens to memory buffer scrsav and other sized
  1302. ; screens to video memory page 1. Resultant save place put into savadr
  1303. ; (offset then segment) and current low_rgt size info in savflg. Note,
  1304. ; some Environments (TopView/Windows etc) may not permit use of page 1. [jrd]
  1305. savescr proc    near
  1306.         push    es
  1307.         push    ds
  1308.         push    ax
  1309.         push    cx
  1310.         push    si
  1311.         push    di
  1312. ; ****************** if in CC-DOS mode? Nov.1990 [zqf]
  1313.         cmp     isccdos,1               ; if CC-DOS ?
  1314.         jne     savsc0                  ; ne = No.
  1315. IFNDEF   CGA         ; Add Option CGA to servered screen.Mar.21,1991 [zqf]
  1316.         call    savccscr                ; yes, call CCDOS screen save proc
  1317. ENDIF
  1318.         jmp     savsc4                  ; return
  1319. savsc0:
  1320. ; **********************
  1321.         call    scrseg                  ; get screen segment in ax and es:di
  1322.         push    ax                      ; save screen segment
  1323.         mov     si,0
  1324.         mov     di,scrsav               ; place to put screen (memory buff)
  1325.         mov     savadr+2,di             ; working seg address for restore
  1326.         mov     savadr,0                ; and no offset for memory buffer
  1327.  
  1328.         call    scrmod                  ; ascertain video mode and screen
  1329.         mov     ax,low_rgt              ; text screen lower right (typ 23,79)
  1330.         mov     savflg,ax               ; save it for screen restore
  1331.         inc     al                      ; number of columns
  1332.         add     ah,2                    ;  plus status line = number of rows
  1333.         cmp     al,swidth               ; same as preset screen space (80)?
  1334.         ja      savsc1                  ; a = no, use screen video page 1
  1335.         cmp     ah,slen+1               ; same as preset screen length (24)?
  1336.         je      savsc3                  ; e = yes, use our memory buffer
  1337. savsc1: mul     ah                      ; times rows = characters on screen
  1338.         shl     ax,1                    ; times two for attributes = page 1
  1339.         mov     cx,ax                   ; cx = working copy of screen size
  1340.         and     cx,000fh                ; get lower four bits for offset part
  1341.         mov     savadr,cx               ; save offset in this word
  1342.         mov     cl,4
  1343.         shr     ax,cl                   ; compute number of paragraphs
  1344.         pop     di                      ; source screen address
  1345.         push    di                      ; restore again
  1346.         add     di,ax                   ; add paragraphs, point di to page 1
  1347.         mov     savadr+2,di             ; and save segment in this word
  1348. savsc3:
  1349.         mov     es,savadr+2             ; segment of storage area
  1350.         mov     di,savadr               ;  offset of same
  1351.         mov     ax,low_rgt              ; lower right of text screen
  1352.         inc     al                      ; number of columns on screen
  1353.         add     ah,2                    ; number of rows on screen
  1354.         mul     ah                      ; number of characters on the screen
  1355.         mov     cx,ax                   ; save this in counter cx
  1356.         call    scroff                  ; turn off screen [dt]
  1357.         pop     ds                      ; address screen
  1358.         cld
  1359.         rep     movsw                   ; save the screen
  1360. savsc4:
  1361.         pop     di
  1362.         pop     si
  1363.         pop     cx
  1364.         pop     ax
  1365.         pop     ds                      ; restore this
  1366.         call    scron                   ; turn on screen [dt]
  1367.         pop     es
  1368.         ret
  1369. savescr endp
  1370.  
  1371. ; restore screen from buffer (offset and seg in savadr, text coord in savflg).
  1372. ; Restores all screen lines. [jrd]
  1373. restscr proc    near
  1374. ; ****************** if in CC-DOS mode? Nov.1990 [zqf]
  1375.         cmp     isccdos,1               ; if CC-DOS ?
  1376.         jne     rstscr0                 ; ne = No.
  1377. IFNDEF   CGA         ; Add Option CGA to servered screen.Mar.21,1991 [zqf]
  1378.         call    rstccscr                ; yes, call CCDOS screen restore proc
  1379. ENDIF
  1380.         ret                             ; return
  1381. rstscr0:
  1382. ; **********************
  1383.         push    es
  1384.         mov     ax,savflg               ; saved low_rgt text screen coord
  1385.         add     ah,2                    ; number of screen lines
  1386.         inc     al                      ; number of screen columns
  1387.         mul     ah                      ; columns time lines = # characters
  1388.         mov     cx,ax                   ; save this in counter cx
  1389.         push    cx                      ; save count
  1390.         call    scrseg                  ; get address of screen in es:di
  1391.         call    scroff                  ; turn off screen [dt]
  1392.         push    ds                      ; save original data segment
  1393.         mov     si,savadr               ; offset of storage area
  1394.         push    savadr+2                ; segment of same
  1395.         pop     ds                      ; put storage segment into ds
  1396.         cld
  1397.         rep     movsw                   ; restore data to screen
  1398.         pop     ds                      ; recover original data segment
  1399.         call    scron                   ; turn on screen [dt]
  1400.         pop     cx                      ; recover count
  1401.         call    scrsync                 ; synch Topview with new screen
  1402.         pop     es
  1403.         ret
  1404. restscr endp
  1405.  
  1406. ;**************************** used in CC-DOS Nov.28,1990 [zqf]
  1407. ; SAVCCSCR ---- called by <savescr> of module "ccyibm.asm".
  1408. ;               which save screen char & attr in buffer pointed
  1409. ;               by scrsav in CC-DOS. Nov 28,1990 [zqf]
  1410. ; All registers are reserved.
  1411. ;********************************
  1412.  
  1413. SAVCCSCR proc    near
  1414.         push    ax
  1415.         push    bx
  1416.         push    cx
  1417.         push    dx
  1418.         push    di
  1419.         push    es
  1420.         
  1421.         mov     ax,scrsav       ; buffer segment address, offset is zero
  1422.         mov     es,ax
  1423.         mov     di,0
  1424.         mov     savadr+2,es
  1425.         mov     savadr,di
  1426. ; read current cursor
  1427.         mov     bh,0
  1428.         mov     ah,3
  1429.         int     10h             ; read current cursor pos. & type.
  1430.         mov     curpos,dx      ; saved in <curattr>
  1431.         mov     curtyp,cx      ;
  1432. ; save screen
  1433.         mov     bh,0
  1434.         mov     dx,0
  1435. savccscr1:  mov     ah,2
  1436.         int     10h             ; set cursor position <DH,DL>---<row,col>
  1437.         mov     ah,8
  1438.         int     10h             ; read char & attr in current cursor pos.
  1439.         mov     es:[di],ax      ; save in scrbuf
  1440.         inc     dl
  1441.         cmp     dl,crt_cols     ; crt_cols:number of screen cols (typ 80)
  1442.         jl      savccscr2
  1443.         mov     dl,0
  1444.         inc     dh
  1445.         cmp     dh,crt_lins     ; crt_lins:number of rows-1 (typ 24)
  1446.         jg      savccscr3
  1447. savccscr2:
  1448.         inc     di
  1449.         inc     di
  1450.         jmp     savccscr1
  1451. savccscr3:  
  1452.         pop     es
  1453.         pop     di
  1454.         pop     dx
  1455.         pop     cx
  1456.         pop     bx
  1457.         pop     ax
  1458.         ret
  1459. SAVCCSCR endp
  1460. ;*******************************
  1461.  
  1462. ;**************************** used in CC-DOS Nov.28,1990 [zqf]
  1463. ; RSTCCSCR ---- called by <restscr> of module "ccyibm.asm".
  1464. ;               which restore screen char & attr in buffer pointed
  1465. ;               by savadr in CC-DOS. Nov 28,1990 [zqf]
  1466. ; All registers are reserved.
  1467. ;********************************
  1468. RSTCCSCR  proc
  1469.         push    ax
  1470.         push    bx
  1471.         push    cx
  1472.         push    dx
  1473.         push    di
  1474.         push    es
  1475.         mov     ax,savadr+2             ; segment address of buffer
  1476.         mov     es,ax
  1477.         mov     di,savadr               ; offset address of buffer
  1478. ; restore screen
  1479.         mov     bh,0
  1480.         mov     dx,0
  1481. rstccscr1:mov     ah,2
  1482.         int     10h             ; set cursor position <DH,DL>---<row,col>
  1483.         mov     ax,es:[di]      ; restore from scrbuf
  1484.         mov     bl,ah
  1485.         mov     cx,1
  1486.         mov     ah,9
  1487.         int     10h             ; write char & attr in current cursor pos.
  1488.         inc     dl
  1489.         cmp     dl,crt_cols     ; crt_cols:number of screen cols (typ 80)
  1490.         jl      rstccscr2
  1491.         mov     dl,0
  1492.         inc     dh
  1493.         cmp     dh,crt_lins     ; crt_lins:number of rows-1 (typ 24)
  1494.         jg      rstccscr3
  1495. rstccscr2:  
  1496.         inc     di
  1497.         inc     di              ; adjust pointer
  1498.         jmp     rstccscr1
  1499. rstccscr3:  
  1500. ; set original cursor pos &type
  1501.         mov     bh,0
  1502.         mov     cx,curtyp
  1503.         mov     ah,1 
  1504.         int     10h             ; build cursor type
  1505.         mov     bh,0
  1506.         mov     dx,curpos
  1507.         mov     ah,2
  1508.         int     10h             ; set original cursor pos.
  1509.         pop     es
  1510.         pop     di
  1511.         pop     dx
  1512.         pop     cx
  1513.         pop     bx
  1514.         pop     ax
  1515.         ret
  1516. RSTCCSCR  endp       
  1517. ;********************************
  1518.           
  1519.  
  1520.  
  1521. ; Save the screen to a buffer and then append buffer to a disk file. [jrd]
  1522. ; Default filename is Kermit.scn; actual file can be a device too. Filename
  1523. ; is determined by mssset and is passed as pointer dmpname.
  1524. ; Dumpscr reads the screen image saved by savescr so call savescr call first.
  1525.  
  1526. dumpscr proc    near
  1527.         push    ax
  1528.         push    bx
  1529.         push    cx
  1530.         push    dx
  1531.         mov     dmphand,-1              ; preset illegal handle
  1532.         mov     dx,offset dmpname       ; name of disk file, from mssset
  1533.         mov     ax,dx                   ; where isfile wants name ptr
  1534.         call    isfile                  ; what kind of file is this?
  1535.         jc      dmp5                    ; c = no such file, create it
  1536.         test    byte ptr filtst.dta+21,1fh ; file attributes, ok to write?
  1537.         jnz     dmp0                    ; nz = no.
  1538.         mov     al,1                    ; writing
  1539.         mov     ah,open2                ; open existing file
  1540.         int     dos
  1541.         jc      dmp0                    ; c = failure
  1542.         mov     dmphand,ax              ; save file handle
  1543.         mov     bx,ax                   ; need handle here
  1544.         mov     cx,0ffffh               ; setup file pointer
  1545.         mov     dx,-1                   ; and offset
  1546.         mov     al,2                    ; move to eof minus one byte
  1547.         mov     ah,lseek                ; seek the end
  1548.         int     dos
  1549.         jmp     dmp1
  1550.  
  1551. dmp5:   test    filtst.fstat,80h        ; access problem?
  1552.         jnz     dmp0                    ; nz = yes
  1553.         mov     ah,creat2               ; file did not exist
  1554.         mov     cx,20h                  ; attributes, archive bit
  1555.         int     dos
  1556.         mov     dmphand,ax              ; save file handle
  1557.         jnc     dmp1                    ; nc = ok
  1558.  
  1559. dmp0:   mov     ah,3                    ; get cursor position
  1560.         xor     bx,bx                   ; page 0
  1561.         int     screen
  1562.         push    dx                      ; save it
  1563.         mov     dh,byte ptr low_rgt+1   ; go to status line
  1564.         inc     dh
  1565.         xor     dl,dl                   ; left most column
  1566.         mov     ah,2                    ; position cursor
  1567.         int     screen
  1568. ;        mov     dx,offset dmperr        ; say no can do
  1569.         mcmsg   dmperr, cdmperr
  1570.  
  1571.         mov     ah,prstr
  1572.         int     dos
  1573.         pop     dx                      ; get original cursor position
  1574.         mov     ah,2                    ; position cursor
  1575.         xor     bx,bx                   ; page 0
  1576.         int     screen
  1577.         pop     dx
  1578.         pop     cx
  1579.         pop     bx
  1580.         pop     ax
  1581.         clc
  1582.         ret
  1583.  
  1584. dmp1:   mov     ah,ioctl                ; is destination ready for output?
  1585.         mov     al,7                    ; test output status
  1586.         mov     bx,dmphand              ; handle
  1587.         int     dos
  1588.         jc      dmp0                    ; c = error
  1589.         cmp     al,0ffh                 ; ready?
  1590.         jne     dmp0                    ; ne = not ready
  1591.         push    di                      ; read screen buffer, write lines
  1592.         push    si
  1593.         push    es
  1594.         mov     cl,byte ptr low_rgt+1   ; number of lines - 2
  1595.         add     cl,2                    ; number of line on screen
  1596.         xor     ch,ch
  1597.         mov     si,savadr               ; offset in storage area
  1598. dmp2:   push    cx                      ; save outer loop counter
  1599.         mov     es,savadr+2             ; get storage segment
  1600.         mov     di,offset dumpbuf       ; data segment memory
  1601.         mov     cl,byte ptr savflg      ; number of columns on screen - 1
  1602.         inc     cl                      ; number of columns on screen
  1603.         xor     ch,ch
  1604. dmp3:   mov     ax,word ptr es:[si]     ; read char + attribute
  1605.         mov     byte ptr [di],al        ; store just char, don't use es:
  1606.         inc     si                      ; update pointers
  1607.         inc     si
  1608.         inc     di
  1609.         loop    dmp3                    ; do for each column
  1610.         std                             ; set scan backward
  1611.         mov     cl,byte ptr savflg      ; number of columns on screen - 1
  1612.         inc     cl                      ; number of columns on screen
  1613.         xor     ch,ch
  1614.         push    es
  1615.         mov     ax,ds
  1616.         mov     es,ax                   ; set es to data segment for es:di
  1617.         mov     di,offset dumpbuf       ; start of line
  1618.         add     di,cx                   ; plus length of line
  1619.         dec     di                      ; minus 1 equals end of line
  1620.         mov     al,' '                  ; thing to scan over
  1621.         repe    scasb                   ; scan until non-space
  1622.         cld                             ; set direction forward
  1623.         pop     es
  1624.         jz      dmp3a                   ; z = all spaces
  1625.         inc     cx
  1626.         inc     di
  1627. dmp3a:  mov     word ptr [di+1],0A0Dh   ; append cr/lf
  1628.         add     cx,2                    ; line count + cr/lf
  1629.         mov     dx,offset dumpbuf       ; array to be written
  1630.         mov     bx,dmphand              ; need file handle
  1631.         mov     ah,write2               ; write the line
  1632.         int     dos
  1633.         pop     cx                      ; get line counter again
  1634.         jc      dmp3b                   ; c = error
  1635.         loop    dmp2                    ; do next line
  1636.         mov     dx,offset dumpsep       ; put in formfeed/cr/lf
  1637.         mov     cx,3                    ; three bytes overall
  1638.         mov     ah,write2               ; write them
  1639. dmp3b:  mov     bx,dmphand              ; file handle
  1640.         int     dos
  1641.         mov     ah,close2               ; close the file now
  1642.         int     dos
  1643. dmp6:   pop     es
  1644.         pop     si
  1645.         pop     di
  1646.         pop     dx
  1647.         pop     cx
  1648.         pop     bx
  1649.         pop     ax
  1650.         clc
  1651.         ret
  1652. dumpscr endp
  1653.  
  1654.  
  1655. ; Get CRT mode - returns mode in variable crt_mode,
  1656. ; updates crt_cols and low_rgt.
  1657. ; For EGA active it looks in Bios work memory 40:84H for number of rows. [jrd]
  1658. scrmod  proc    near
  1659.         push    ax
  1660.         push    dx
  1661.         mov     ah,15                   ; Get current video state
  1662.         int     screen
  1663.         mov     crt_mode,al             ; Store CRT mode value
  1664.         mov     crt_cols,ah             ; store # of cols
  1665.         mov     dl,ah                   ; # of cols again
  1666.         mov     dh,crt_lins             ; and # of rows (constant from msster)
  1667.         cmp     ega_mode,0              ; ega active?
  1668.         je      scrmod4                 ; e = no
  1669.         push    es                      ; yes, permit different lengths
  1670.         mov     ax,40h                  ; refer to 40:84h for # ega rows
  1671.         mov     es,ax
  1672.         mov     ah,es:[84h]             ; get number of rows - 1 (typ 24)
  1673.         cmp     ah,20                   ; less than 20 rows?
  1674.         jb      scrmod3                 ; b = yes, ignore this length
  1675.         cmp     ah,80                   ; more than 80 rows?
  1676.         ja      scrmod3                 ; a = yes, ignore this length
  1677.         mov     dh,ah                   ; use this length
  1678.         mov     crt_lins,dh             ; update our working constant
  1679. scrmod3:pop     es
  1680. scrmod4:dec     dl                      ; max text column, count from zero
  1681.         dec     dh                      ; max text row, count from zero
  1682.         mov     low_rgt,dx              ; save away window address
  1683.         pop     dx
  1684.         pop     ax
  1685.         ret
  1686. scrmod  endp
  1687.  
  1688.  
  1689. ; Get screen segment - returns screen segment in ax, and full address in es:di
  1690.  
  1691. scrseg  proc    near
  1692.         xor     di,di                   ; start at beginning of screen (0,0)
  1693.         mov     ax,0B000H               ; Assume B&W card
  1694.         cmp     crt_mode,7              ; Is it?
  1695.         je      scrse1                  ; e = yes
  1696.         cmp     crt_mode,18h            ; Tseng UltraPAK mono in 132 col?
  1697.         je      scrse1                  ; e = yes, use seg B000H
  1698.         mov     ax,0B800H               ; No - video memory is here on color
  1699.         cmp     crt_mode,12             ; graphics set?
  1700.         jb      scrse1                  ; b = no
  1701.         cmp     crt_mode,18             ; end of ordinary 640x480 graphics
  1702.         ja      scrse1                  ; a = no, assume CGA segment
  1703.         mov     ax,0A000H               ; graphics
  1704. scrse1: mov     es,ax           ; tell Topview our hardware address needs
  1705.         mov     tv_segs,es              ; save our hardware screen address
  1706.         mov     tv_sego,di              ; segment and offset form
  1707.         mov     tv_mode,1               ; assume we're running under Topview
  1708.         mov     ah,tvhere               ; query Topview for its presence
  1709.         int     screen
  1710.         mov     ax,es                   ; get its new segment for screen work
  1711.         cmp     ax,tv_segs              ; same as hardware?
  1712.         jne     scrse2                  ; ne = no, we are being mapped
  1713.         cmp     di,tv_sego              ; check this too
  1714.         jne     scrse2          ; ne = no too. Use TV's work buf as screen
  1715.         mov     tv_mode,0               ; else no Topview or no mapping
  1716. scrse2: mov     tv_segs,es              ; save segment
  1717.         mov     tv_sego,di              ; and offset
  1718.         ret
  1719. scrseg  endp
  1720.  
  1721. ; Synchronize a Topview provided virtual screen buffer with the image
  1722. ; seen by the user. Requires cx = number of words written to screen
  1723. ; (char & attribute bytes) and es:di = ENDING address of screen write.
  1724. ; Changes ax and di.
  1725. scrsync proc    near
  1726.         cmp     tv_mode,0               ; Topview mode active?
  1727.         je      scrsyn1                 ; e = no, skip DOS call below
  1728.         sub     di,cx                   ; backup to start byte (cx = words)
  1729.         sub     di,cx                   ;  after storing words to screen
  1730.         mov     ah,tvsynch              ; tell Topview we have changed screen
  1731.         int     screen                  ;  so user sees updated screen
  1732. scrsyn1:ret
  1733. scrsync endp
  1734.  
  1735. ; The following two routines are used to turn off the display while we
  1736. ; are reading or writing the screen in one of the color card modes.
  1737. ; Turn screen off for (known) color card modes only. All regs preserved.
  1738. ; Includes code for old procedure scrwait. 16 June 1987 [jrd]
  1739. scroff  proc    near
  1740.         cmp     refresh,0               ; slow refresh?
  1741.         jne     scrofx                  ; ne = no wait
  1742.         cmp     ega_mode,0              ; Extended Graphics Adapter in use?
  1743.         jne     scrofx                  ; ne = yes, no waiting
  1744.         cmp     tv_mode,0               ; Topview mode?
  1745.         jne     scrofx                  ; ne = yes, no waiting
  1746.         cmp     crt_mode,7              ; B&W card?
  1747.         jnb     scrofx                  ; Yes - just return
  1748.         push    ax                      ; Save ax and dx
  1749.         push    dx
  1750.         mov     dx,crt_status           ; CGA: Wait for vertical retrace
  1751. scrof1: in      al,dx
  1752.         test    al,disp_enb             ; display enabled?
  1753.         jnz     scrof1                  ; yes, keep waiting
  1754. scrof2: in      al,dx
  1755.         test    al,disp_enb             ; now wait for it to go off
  1756.         jz      scrof2                  ; so can have whole cycle
  1757.         mov     dx,crtmset              ; Output to CRT mode set port
  1758.         mov     al,25H                  ; This shuts down the display
  1759.         out     dx,al                   ; Dumb, but card is too
  1760.         pop     dx                      ; restore regs
  1761.         pop     ax
  1762. scrofx: ret
  1763. scroff  endp
  1764.  
  1765.  
  1766. ; Turn screen on for (known) color card modes only
  1767. ; All registers are preserved.
  1768.  
  1769. scron   proc    near
  1770.         cmp     refresh,0               ; slow refresh?
  1771.         jne     scronx                  ; ne = no wait
  1772.         cmp     ega_mode,0              ; Extended Graphics Adapter in use?
  1773.         jne     scronx                  ; ne = yes, no waiting
  1774.         cmp     tv_mode,0               ; Topview mode?
  1775.         jne     scronx                  ; ne = yes, no waiting
  1776.         cmp     crt_mode,7              ; B&W card?
  1777.         jnb     scronx                  ; Yes - just return
  1778.         push    ax                      ; Save ax, dx, and si
  1779.         push    dx
  1780.         push    si
  1781.         mov     al,crt_mode             ; Convert crt_mode to a word
  1782.         xor     ah,ah
  1783.         mov     si,ax                   ; Get it in a usable register
  1784.         mov     al,msets[si]            ; Fetch the modeset byte
  1785.         mov     dx,crtmset              ; This port
  1786.         out     dx,al                   ; Flash it back on
  1787.         pop     si                      ; restore regs
  1788.         pop     dx
  1789.         pop     ax
  1790. scronx: ret
  1791. scron   endp
  1792.  
  1793.  
  1794. ; Screen clearing routine. [IU]
  1795. ;
  1796. ; Call:         ax/     coordinates of first screen location to be cleared.
  1797. ;               bx/     coordinates of last location to be cleared.
  1798. ; Coord: ah = row [0-24], al = column [0-79]. Preserves all registers. [jrd]
  1799.  
  1800. atsclr: push    ax                      ; save regs
  1801.         push    cx
  1802.         push    dx
  1803.  
  1804.         CALL    PATSCLR             ; CALL PROC TO CLEAR LINE
  1805.  
  1806.         mov     dx,bx                   ; Compute last screen offset in ax
  1807.         push    ax
  1808.         call    scrmod                  ; update column length
  1809.         pop     ax                      ; scrmod zaps ax
  1810.         push    ax
  1811.         call    scrloc                  ; get screen start address in ax
  1812.         mov     cx,ax                   ; Save it in cx for a minute
  1813.         pop     dx                      ; Compute first screen offset in ax
  1814.         call    scrloc
  1815.         sub     cx,ax                   ; Compute number of locs to clear
  1816.         add     cx,2
  1817.         sar     cx,1                    ; Make byte count a word count
  1818.         jle     atscl2                  ; If nothing to clear, then vamos
  1819.         push    di                      ; save regs
  1820.         push    es                      ; save es
  1821.         push    ax                      ; save around call
  1822.         call    scrseg                  ; Get address of screen in ax, es:di
  1823.         pop     ax                      ; recover displacement
  1824.         add     di,ax                   ; displacement memory address
  1825.         mov     ah,scbattr              ; Use current screen background attr
  1826.         mov     al,' '                  ; Use space for fill
  1827.         mov     dl,byte ptr low_rgt     ; line length - 1
  1828.         inc     dl                      ; line length
  1829.         xor     dh,dh
  1830. ;;;;;   cmp     cx,dx                   ; Blanking a line or less??
  1831. ;;;;;   jg      atscl1                  ; No - make scroff disable display
  1832. atscl1:
  1833. ; call    scroff                  ; Turn screen off if color card
  1834.         push    cx                      ; save word count for Topview
  1835.         cld
  1836. ;        rep     stosw                   ; Blit... (excuse PDP-10ese please)
  1837.         pop     cx                      ; recover word count
  1838. ;        call    scrsync                 ; synch Topview
  1839. ;        call    scron                   ; Turn screen back on if color card
  1840.         pop     es                      ; Restore segment register
  1841.         pop     di                      ; And destination index
  1842. atscl2: pop     dx                      ; restore regs
  1843.         pop     cx
  1844.         pop     ax
  1845.         ret
  1846.  
  1847. ; Screen clearing routine.Ver 2.00 Dec. 15,1989 [ZU]
  1848. ; (Screen clearing by scroll whole bolck between <ah,al> and <bh,bl>
  1849. ; Call      ax/     corrdinates of upon left location to be cleared.
  1850. ;           <ah,al>--<row,col>
  1851. ;       bx/     corrdinates of down right location to be cleared.
  1852. ;           <bh,bl>--<row,col>
  1853. ; Cord: ah=row [0-24], al = col [0-79]. Preserves all registers. [zqf]
  1854.  
  1855. patsclr proc    near
  1856.     push    ax
  1857.     push    bx
  1858.     push    cx
  1859.     push    dx
  1860.     push    si
  1861.     push    di
  1862. ; check if clear block or a line ?
  1863.     cmp bh,ah
  1864.     jg patsclr_b     ; le= clear a block more than one line
  1865.     
  1866. ; clear a block in one line
  1867. ; read screen mode
  1868. patsclr_l:
  1869.     push    ax
  1870.     push    bx
  1871.     mov ah,15   ;state
  1872.     int video
  1873.     mov activepage,bh
  1874. ;    mov cols,ah
  1875.     pop bx
  1876.     pop ax
  1877. ; save current cursor
  1878.     push    ax
  1879.     push    bx
  1880.     mov bh,activepage
  1881.     mov ah,readcur
  1882.     int video
  1883.     mov currow,dh
  1884.     mov curcol,dl
  1885.     mov curtype,cx
  1886.     pop bx
  1887.     pop ax
  1888. ; compute number of chars to clear in cx
  1889.     push    ax
  1890.     xor cx,cx
  1891.     mov dx,0
  1892. patscl1:    cmp bh,ah
  1893.     jle patscl2
  1894.     mov dl,80       ;cols
  1895.     sub dl,al
  1896.     add cx,dx
  1897.     xor al,al
  1898.     inc ah
  1899.     jmp patscl1
  1900. patscl2:    cmp bl,al
  1901.     jl  patscl3
  1902.     sub bl,al
  1903.     mov bh,0
  1904.     add cx,bx
  1905.     inc cx
  1906. patscl3:    pop ax
  1907.     cmp cx,0
  1908.     jle patscl10
  1909. ; set cursor at start location of clearing area
  1910.     mov dx,ax
  1911.     mov bh,activepage
  1912.     mov ah,setcur
  1913.     int video
  1914. ; clear screen < CX__number of chars >
  1915.     mov al,' '      ;space
  1916.     mov bh,activepage
  1917.     mov bl,scbattr
  1918. ;    mov ah,writech  ; ????? different with 'writeach'
  1919.     mov ah,writeach
  1920.     int video
  1921.  
  1922. ; restore current cursor
  1923.     mov dh,currow
  1924.     mov dl,curcol
  1925.     mov bh,activepage
  1926.     mov ah,setcur
  1927.     int video
  1928.  
  1929. patscl10:
  1930.     pop di
  1931.     pop si
  1932.     pop dx
  1933.     pop cx
  1934.     pop bx
  1935.     pop ax
  1936.     ret
  1937.  
  1938. ; scroll window at location <ah,al> to <bh,bl>
  1939. patsclr_b:
  1940.     mov cx,ax
  1941.     mov dx,bx
  1942.     mov bh,scbattr
  1943.     mov al,0
  1944.     mov ah,06h
  1945.     int video
  1946.     jmp patscl10
  1947. patsclr endp
  1948.  
  1949. ; Scrolling routines.  vtscru scrolls up, vtscrd scrolls down 'scroll'
  1950. ; rows. The top line is saved in the circular buffer before scrolling up.
  1951. ; When running under an Environment control number of line positions moved
  1952. ; to be less than scrolling region. [jrd]
  1953. ; All registers are preserved.
  1954.  
  1955. ; Screen-roll down. Move text down one line, for terminal emulator only.
  1956.  
  1957. vtscrd: push    ax                      ; Upgraded by [jrd]
  1958.         push    bx
  1959.         push    cx
  1960.         push    dx
  1961.         mov     ah,7                    ; scroll down
  1962.         mov     ch,mar_top              ; top margin line
  1963.         mov     cl,0                    ; left most column
  1964.         mov     dh,mar_bot              ; bottom margin line
  1965.         mov     dl,byte ptr low_rgt     ; right most column
  1966.         mov     bh,scbattr              ; attributes
  1967.         mov     bl,dh
  1968.         sub     bl,ch                   ; region size - 1 line
  1969.         mov     al,scroll               ; number of lines to scroll, from msz
  1970. vscrd1: cmp     al,bl                   ; want to scroll more that than?
  1971.         jbe     vscrd2                  ; be = no
  1972.         push    ax
  1973.         mov     al,bl                   ; limit to region-1 for Windows
  1974.         int     screen                  ;  and do in parts
  1975.         pop     ax
  1976.         sub     al,bl                   ; get remainder
  1977.         jmp     short vscrd1            ; do next part
  1978. vscrd2: int     screen                  ; scroll it down
  1979.         pop     dx
  1980.         pop     cx
  1981.         pop     bx
  1982.         pop     ax
  1983.         ret
  1984.  
  1985. ; Screen scroll up one line (text moves up) for terminal emulator use.
  1986. ; When running under an Environment control number of line positions moved
  1987. ; to be less than scrolling region. [jrd]
  1988.  
  1989. vtscru: push    ax                      ; Upgraded by  [jrd]
  1990.         push    bx
  1991.         push    cx
  1992.         push    dx
  1993.         mov     cl,scroll               ; number of lines to scroll
  1994.         mov     ch,0
  1995.         cmp     cx,0
  1996.         jnz     vscru0
  1997.         jmp     vscru3                  ; z = nothing to do
  1998. vscru0:
  1999.         cmp     mar_top,0               ; scrolling the top screen line?
  2000.         ja      vscru2                  ; a = no. don't save anything
  2001.         push    si
  2002.         push    di
  2003. ;******** test for CCDOS. Dec.12,1990 [zqf]
  2004. IFDEF   CGA         ; Add Option CGA to servered screen.Mar.21,1991 [zqf]
  2005.     cmp     isccdos,1               ; if CCDOS ?
  2006.     je      vscru1a                 ; e = yes, in CCDOS, skip
  2007. ENDIF
  2008.         call    scroff                  ; turn off color screen
  2009.         mov     si,tv_sego              ; screen offset for es:si
  2010.         mov     bx,offset twnd          ; put lines in top window buffer
  2011. vscru1: push    cx                      ; save count
  2012.         call    putcirc                 ; put screen line in circular buffer
  2013.         pop     cx
  2014.         loop    vscru1                  ; save 'scroll' number of lines
  2015.         call    scron                   ; turn on screen again
  2016. IFDEF   CGA         ; Add Option CGA to servered screen.Mar.21,1991 [zqf]
  2017. vscru1a:
  2018. ENDIF
  2019. ;********
  2020.         pop     di
  2021.         pop     si                      ; now scroll the visible screen
  2022. vscru2: mov     ah,6                    ; scroll up
  2023.         mov     dh,mar_bot              ; bottom row
  2024.         mov     dl,byte ptr low_rgt     ; right most column
  2025.         mov     ch,mar_top              ; top row of scrolling region
  2026.         mov     cl,0                    ; left most column
  2027.         mov     bh,scbattr              ; attributes
  2028.         mov     bl,dh
  2029.         sub     bl,ch                   ; region size - 1 line
  2030.         mov     al,scroll               ; number of lines to scroll, from msz
  2031. vscru2a:cmp     al,bl                   ; want to scroll more that than?
  2032.         jbe     vscru2b                 ; be = no
  2033.         push    ax
  2034.         mov     al,bl                   ; limit to region - 1 for Windows
  2035. ;******** test for CCDOS. Dec.12,1990 [zqf]
  2036. IFDEF   CGA         ; Add Option CGA to servered screen.Mar.21,1991 [zqf]
  2037.         cmp     isccdos,1               ; if CCDOS ?
  2038.         je      vscru2c                 ; e = yes, in CCDOS, skip
  2039. ENDIF
  2040.         int     screen                  ;  and do in parts
  2041. IFDEF   CGA         ; Add Option CGA to servered screen.Mar.21,1991 [zqf]
  2042.         jmp     vscru2d                 ; in MSDOS
  2043. vscru2c:
  2044.         push    dx
  2045.         mov     dl,0dh
  2046.         mov     ah,2
  2047.         int     21h
  2048.         mov     dl,0ah
  2049.         mov     ah,2
  2050.         int     21h
  2051.         pop     dx
  2052. vscru2d:
  2053. ENDIF
  2054. ;********
  2055.         pop     ax
  2056.         sub     al,bl
  2057.         jmp     short vscru2a           ; do next part
  2058. vscru2b:
  2059. ;******** test for CCDOS. Dec.12,1990 [zqf]
  2060. IFDEF   CGA         ; Add Option CGA to servered screen.Mar.21,1991 [zqf]
  2061.         cmp     isccdos,1               ; if CCDOS ?
  2062.         je      vscru2e                 ; e = yes, in CCDOS, skip
  2063. ENDIF
  2064.         int     screen                  ;  and do in parts
  2065. IFDEF   CGA         ; Add Option CGA to servered screen.Mar.21,1991 [zqf]
  2066.         jmp     vscru2f                 ; in MSDOS
  2067. vscru2e:
  2068.         push    dx
  2069.         mov     dl,0dh
  2070.         mov     ah,2
  2071.         int     21h
  2072.         mov     dl,0ah
  2073.         mov     ah,2
  2074.         int     21h
  2075.         pop     dx
  2076. vscru2f:
  2077. ENDIF
  2078. ;********
  2079. vscru3: pop     dx                      ; Restore the rest of the regs
  2080.         pop     cx
  2081.         pop     bx
  2082.         pop     ax
  2083.         ret
  2084.  
  2085. ;screen text roll up, version for manual scrolling only
  2086.  
  2087. mscru:  push    ax                      ; Upgraded by  [jrd]
  2088.         push    bx
  2089.         push    cx
  2090.         push    dx
  2091.         push    si
  2092.         push    di
  2093.         cmp     bwnd.lcnt,0             ; any lines in bottom window?
  2094.         je      mscru2                  ; e = no, so ignore request
  2095.         call    scroff                  ; turn off color screen
  2096.         mov     bx,offset twnd          ; this is where it goes
  2097.         mov     si,tv_sego              ; screen offset for es:si
  2098.         call    putcirc                 ; put screen line in circular buffer
  2099.         mov     ax,601H                 ; scroll up one line
  2100.         mov     dx,low_rgt              ; lower right corner
  2101.         xor     cx,cx                   ; top row of scrolling region
  2102.         mov     bh,scbattr              ; background attributes
  2103.         int     screen                  ; scroll up that region
  2104.         mov     dx,low_rgt
  2105.         mov     dl,0                    ; location is lower left corner
  2106.         call    scrloc                  ; get count from display start
  2107.         mov     di,ax
  2108.         push    es
  2109.         mov     bx,tv_segs              ; get screen's segment into, es:di
  2110.         mov     es,bx                   ; segment
  2111.         add     di,tv_sego              ; destination memory address (es:di)
  2112.         mov     bx,offset bwnd          ; source of lines
  2113.         call    getcirc                 ; get line from circ buf to screen
  2114.         pop     es                      ; restore es
  2115.         call    scron                   ; turn on the screen
  2116. mscru2: pop     di                      ; Restore the rest of the regs
  2117.         pop     si
  2118.         pop     dx
  2119.         pop     cx
  2120.         pop     bx
  2121.         pop     ax
  2122.         ret
  2123.  
  2124.  
  2125. ;screen text scroll down, for manual mode only
  2126. mscrd:  push    ax                      ; Upgraded by [jrd]
  2127.         push    bx
  2128.         push    cx
  2129.         push    dx
  2130.         push    si
  2131.         push    di
  2132.         cmp     twnd.lcnt,0             ; any lines left in top window?
  2133.         je      mscrd1                  ; e = no, ingore request
  2134.         call    scroff                  ; turn off screen
  2135.         mov     dx,low_rgt              ; from screen location, row
  2136.         mov     dl,0                    ; starting in col 0
  2137.         call    scrloc                  ; get offset in display buffer in ax
  2138.         mov     si,tv_sego              ; screen offset for es:di
  2139.         add     si,ax                   ; source addr in display buffer es:si
  2140.         mov     bx,offset bwnd          ; buffer to use (bottom window)
  2141.         call    putcirc                 ; copy bottom screen line to circ buf
  2142.         mov     ax,701H                 ; scroll down one line
  2143.         xor     cx,cx                   ; top left corner
  2144.         mov     dx,low_rgt              ; bottom right corner
  2145.         mov     bh,scbattr              ; attributes
  2146.         int     screen                  ; scroll it down
  2147.         push    es
  2148.         mov     di,tv_segs              ; screen segment
  2149.         mov     es,di
  2150.         mov     di,tv_sego              ; screen offset, for es:di
  2151.         mov     bx,offset twnd          ; buffer to use (top window)
  2152.         call    getcirc                 ; copy from circ buf to screen
  2153.         pop     es
  2154.         call    scron                   ; turn on display again
  2155. mscrd1: pop     di                      ; Restore the rest of the regs
  2156.         pop     si
  2157.         pop     dx
  2158.         pop     cx
  2159.         pop     bx
  2160.         pop     ax
  2161.         ret
  2162.  
  2163. ; move viewing window down as much as possible (text moves up)
  2164. endwnd  proc    near                    ; go to end of scrolling text
  2165.         push    cx
  2166.         mov     cx,bwnd.lcnt            ; all bottom window lines [dlk]
  2167.         jmp     dnwp0                   ; and enter dwnpg
  2168. endwnd  endp
  2169.  
  2170. dnone   proc    near                    ; move text up one line [jrd]
  2171.         push    cx
  2172.         mov     cx,1
  2173.         jmp     dnwp0
  2174. dnone   endp
  2175.  
  2176. ; scroll viewing window down (text moves up) one page (24 lines)
  2177. dnwpg   proc    near
  2178.         push    cx
  2179.         mov     cl,byte ptr low_rgt+1   ; number of rows, excl status
  2180.         inc     cl                      ; count from 1, not 0
  2181.         mov     ch,0
  2182. dnwp0:                                  ; additional entry point
  2183.         cmp     bwnd.lcnt,cx            ; enough lines in bottom line buffer?
  2184.         jge     dnwp1                   ; ge = we have that many lines stored
  2185.         mov     cx,bwnd.lcnt            ; do as many as we have
  2186. dnwp1:  jcxz    dnwp2                   ; z = nothing to do
  2187.         cmp     tekflg,0                ; Tek mode active?
  2188.         jne     dnwp2                   ; ne = yes, no scrolling
  2189.         call    mscru                   ; scroll up text one line
  2190.         loop    dnwp1
  2191. dnwp2:  pop     cx
  2192.         clc
  2193.         ret
  2194. dnwpg   endp
  2195.  
  2196. ; home viewing window
  2197. homwnd  proc    near
  2198.         push    cx
  2199.         mov     cx,twnd.lcnt            ; all top window lines [dlk]
  2200.         jmp     upwp0                   ; join upwpg
  2201. homwnd  endp
  2202.  
  2203. upone   proc    near                    ; move text down one line [jrd]
  2204.         push    cx
  2205.         mov     cx,1
  2206.         jmp     upwp0
  2207. upone   endp
  2208.  
  2209. ; scroll viewing window up (text moves down) a page (24 lines)
  2210. upwpg   proc    near
  2211.         push    cx
  2212.         mov     cl,byte ptr low_rgt+1   ; number of rows, excl status line
  2213.         inc     cl                      ; count from 1, not 0
  2214.         mov     ch,0
  2215. upwp0:                                  ; additional entry point
  2216.         cmp     twnd.lcnt,cx            ; enough lines in top line buffer?
  2217.         jae     upwp1                   ; ae = at least as many as requested
  2218.         mov     cx,twnd.lcnt            ; do only as many as are stored
  2219. upwp1:  jcxz    upwp2                   ; z = no lines to scroll
  2220.         cmp     tekflg,0                ; Tek mode active?
  2221.         jne     upwp2                   ; ne = yes, no scrolling
  2222.         call    mscrd                   ; roll down text one line
  2223.         loop    upwp1
  2224. upwp2:  pop     cx
  2225.         clc
  2226.         ret
  2227. upwpg   endp
  2228.  
  2229.  
  2230. ; Put a line into the circular buffer.  Pass the buffer structure in bx.
  2231. ; Source is tv_segs:si which is the current screen address.
  2232. ; Rewritten by [jrd]
  2233. putcirc proc    near
  2234.         push    es
  2235.         mov     cl,crt_cols             ; number of columns
  2236.         xor     ch,ch
  2237.         mov     es,[bx].orig            ; get segment of memory area
  2238.         cmp     bx,offset bwnd          ; bottom buffer?
  2239.         je      putci6                  ; e = yes
  2240.         mov     di,twnd.pp              ; pick up buffer ptr (offset from es)
  2241.         add     di,cx                   ; increment to next available slot
  2242.         add     di,cx                   ; char and attribute
  2243.         cmp     di,twnd.bend            ; would line extend beyond buffer?
  2244.         jb      putci1                  ; b = not beyond end
  2245.         mov     di,0                    ; else start at the beginning
  2246. putci1: mov     twnd.pp,di              ; update ptr
  2247.         cld                             ; set direction to forward
  2248.         push    ds                      ; save regular datas seg reg
  2249.         mov     ds,tv_segs              ; use screen segment for ds:si
  2250.         rep     movsw                   ; copy into buffer
  2251.         pop     ds                      ; restore regular datas segment
  2252.         mov     cx,twnd.lmax            ; line capacity of buffer
  2253.         dec     cx                      ; minus one work space line
  2254.         cmp     twnd.lcnt,cx            ; can we increment line count?
  2255.         jae     putci1b                 ; ae = no, keep going
  2256.         inc     twnd.lcnt               ; else count this line
  2257. putci1b:cmp     bwnd.lcnt,0             ; any lines in bottom buffer?
  2258.         je      putci2                  ; e = no
  2259.         mov     cx,bwnd.pp              ; see if we overlap bot buf
  2260.         cmp     cx,twnd.pp              ; is this line in bot buf area?
  2261.         jne     putci2                  ; ne = no
  2262.         add     cl,crt_cols             ; move bottom pointer one slot earlier
  2263.         adc     ch,0
  2264.         add     cl,crt_cols             ; words
  2265.         adc     ch,0
  2266.         cmp     cx,bwnd.bend            ; beyond end of buffer?
  2267.         jb      putci1a                 ; b = no
  2268.         mov     cx,0                    ; yes, start at beginning of buffer
  2269. putci1a:mov     bwnd.pp,cx              ; new bottom pointer
  2270.         dec     bwnd.lcnt               ; one less line in bottom buffer
  2271. putci2: pop     es
  2272.         ret
  2273. putci6:                                 ; bottom buffer
  2274.         add     cx,cx                   ; words worth
  2275.         cmp     bwnd.lcnt,0             ; any lines in the buffer yet?
  2276.         jne     putci7                  ; ne = yes
  2277.         mov     di,twnd.pp              ; get latest used slot of top buff
  2278.         add     di,cx                   ; where first free (?) slot starts
  2279.         cmp     di,bwnd.bend            ; are we now beyond the buffer?
  2280.         jb      putci6a                 ; b = no
  2281.         mov     di,0                    ; yes, start at beginning of buffer
  2282. putci6a:add     di,cx                   ; start of second free (?) slot
  2283.         cmp     di,bwnd.bend            ; are we now beyond the buffer?
  2284.         jb      putci6b                 ; b = no
  2285.         mov     di,0                    ; yes, start at beginning of buffer
  2286. putci6b:mov     cx,twnd.lmax            ; buffer line capacity
  2287.         sub     cx,twnd.lcnt            ; minus number used by top buffer
  2288.         sub     cx,2                    ; minus one work slot and one we need
  2289.         cmp     cx,0                    ; overused some slots?
  2290.         jge     putci8                  ; ge = enough to share
  2291.         add     twnd.lcnt,cx            ; steal these from top window beginning
  2292.         jmp     short putci8
  2293.  
  2294. putci7: mov     es,bwnd.orig            ; get segment of memory area
  2295.         mov     di,bwnd.pp              ; pick up buffer ptr (offset from es)
  2296.         cmp     di,0                    ; would line start before buffer?
  2297.         jne     putci7a                 ; ne = after start of buffer
  2298.         mov     di,bwnd.bend            ; else start at the end minus one slot
  2299.         inc     di
  2300. putci7a:sub     di,cx
  2301. putci8: mov     bwnd.pp,di              ; update ptr (this is latest used slot)
  2302.         mov     cl,crt_cols
  2303.         xor     ch,ch
  2304.         cld                             ; set direction to forward
  2305.         push    ds                      ; save regular datas seg reg
  2306.         mov     ds,tv_segs              ; use screen segment for ds:si
  2307.         rep     movsw                   ; copy into buffer
  2308.         pop     ds                      ; restore regular datas segment
  2309.         mov     cx,bwnd.lmax            ; line capacity of buffer
  2310.         cmp     bwnd.lcnt,cx            ; can we increment line count?
  2311.         jae     putci8b                 ; ae = no, keep going
  2312.         inc     bwnd.lcnt               ; else count this line
  2313. putci8b:cmp     twnd.lcnt,0             ; any lines in top line buf?
  2314.         je      putci9                  ; e = no
  2315.         mov     cx,twnd.pp              ; yes, see if we used last top line
  2316.         cmp     cx,bwnd.pp              ; where we just wrote
  2317.         jne     putci9                  ; not same place, so all is well
  2318.         dec     twnd.lcnt               ; one less line in top window
  2319.         cmp     cx,0                    ; currently at start of buffer?
  2320.         jne     putci8a                 ; ne = no
  2321.         mov     cx,twnd.bend            ; yes
  2322.         inc     cx
  2323. putci8a:sub     cl,crt_cols             ; back up top window
  2324.         sbb     ch,0
  2325.         sub     cl,crt_cols             ; by one line
  2326.         sbb     ch,0
  2327.         mov     twnd.pp,cx              ; next place to read
  2328. putci9: pop     es
  2329.         ret
  2330. putcirc endp
  2331.  
  2332. ; Get a line from the circular buffer, removing it from the buffer.
  2333. ; returns with carry on if the buffer is empty.
  2334. ; Pass the buffer structure in bx.
  2335. ; Destination preset in es:di which is the current screen address.
  2336. ; Rewritten by [jrd]
  2337. getcirc proc    near
  2338.         cmp     [bx].lcnt,0             ; any lines in buffer?
  2339.         jne     getci1                  ; ne = yes, ok to take one out
  2340.         stc                             ; else set carry
  2341.         ret
  2342. getci1:                                 ; top and bottom window common code
  2343.         mov     cl,crt_cols             ; # of chars to copy
  2344.         xor     ch,ch
  2345.         mov     si,[bx].pp              ; this is source
  2346.         push    si                      ; save around calls
  2347.         push    cx                      ; save around calls
  2348.         cld                             ; set direction to forward
  2349.         push    ds                      ; save original ds
  2350.         mov     ax,[bx].orig            ; use seg address of buffer for si
  2351.         mov     ds,ax
  2352.         rep     movsw                   ; destination = screen at es:di
  2353.         pop     ds                      ; recover original data segment
  2354.         pop     cx                      ; recover word count
  2355.         call    scrsync                 ; synch Topview
  2356.         pop     si                      ; get ptr again
  2357.         add     cx,cx                   ; words
  2358.         cmp     bx,offset bwnd          ; bottom window?
  2359.         je      getci7                  ; e = yes
  2360.         sub     si,cx                   ; top window, move back
  2361.         jnc     getci6                  ; nc = still in buffer, continue
  2362.         mov     si,twnd.bend            ; else use end of buffer
  2363.         sub     si,cx                   ; minus length of a piece
  2364.         inc     si
  2365. getci6: mov     twnd.pp,si              ; update ptr
  2366.         dec     twnd.lcnt               ; decrement # of lines in buffer
  2367.         clc                             ; make sure no carry
  2368.         ret
  2369. getci7:                                 ; bottom window
  2370.         add     si,cx                   ; words, move back (bot buf = reverse)
  2371.         cmp     si,bwnd.bend            ; still in buffer?
  2372.         jb      getci8                  ; b = yes
  2373.         mov     si,0                    ; else use beginning of buffer
  2374. getci8: mov     bwnd.pp,si              ; update ptr
  2375.         dec     bwnd.lcnt               ; decrement # of lines in buffer
  2376.         clc                             ; make sure no carry
  2377.         ret
  2378. getcirc endp
  2379.  
  2380. ;
  2381. ; CHKDSP - procedure to check for hardware support of 132 cols [dlk]
  2382. ;
  2383. ;  Supported hardware: EVA board from Tseng Labs w/132-col kit installed
  2384. ;               Tseng Labs UltraPAK mono/Herc board w/132 column modes.
  2385. ;               Video 7 Vega Deluxe w/ 132X25.COM driver installed [tmk]
  2386. ;               and VGA board, ATI EGA Wonder, Everex ev-659 and fvga-673.
  2387. ;  The routine checks for the presence of a 132-column-capable adapter. If
  2388. ;  one is found, its handler returns the proper video mode in [CX]. The main-
  2389. ;  line code then moves this to [AX] and issues the video interrupt.
  2390. ;
  2391. chgdsp  proc    near
  2392.         push    es                      ; save all we use
  2393.         push    ax
  2394.         push    bx
  2395.         push    cx
  2396.         push    dx
  2397.         push    si
  2398.         push    di
  2399.         mov     temp,ax                 ; save set/reset flag from msz
  2400.         mov     ah,flowoff              ; get xoff
  2401.         cmp     ah,0                    ; flow control?
  2402.         je      chgds0                  ; e = none
  2403.         call    outchr                  ; send it
  2404.          nop                            ; avoid serial port interrupts while
  2405.          nop                            ; doing many rep scasb's below
  2406.          nop
  2407.         call    savescr                 ; save current screen
  2408.         mov     ax,40                   ; wait 40 millisec before video tests
  2409.         call    pcwait                  ; so don't mix screen and port intrpts
  2410.  
  2411. chgds0: call    ckteva                  ; try Tseng Labs EVA
  2412.         jnc     chgds1                  ; nc = found
  2413.         call    ckv7vd                  ; try Video 7 EGA Deluxe and VGA
  2414.         jnc     chgds1                  ; nc = found
  2415.         call    ckatiw                  ; try ATI EGA Wonder
  2416.         jnc     chgds1                  ; nc = found
  2417.         call    ckevrx                  ; try Everex Micro Enhancer Deluxe
  2418.         jnc     chgds1                  ; nc = found
  2419.         call    ckevga                  ; try Everex EVGA-673
  2420.         jnc     chgds1                  ; nc = found
  2421.         jmp     chgdsx                  ; if not, exit
  2422.                                         ; Perform mode change
  2423. chgds1: mov     ax,cx                   ; get returned value in proper reg
  2424.         int     screen                  ; call the bios
  2425.         cmp     flags.modflg,1          ; is mode line enabled?
  2426.         jbe     chgds2                  ; be = yes, and off or locally owned
  2427.         mov     flags.modflg,1          ; remove foreign ownership
  2428. chgds2: call    scrini                  ; reset parameters
  2429. chgdsx: mov     ah,flowon               ; get flowon byte
  2430.         cmp     ah,0                    ; using flow control?
  2431.         je      chgdsx1                 ; e = no
  2432.         call    outchr                  ; send it
  2433.          nop
  2434.          nop
  2435.          nop
  2436. chgdsx1:pop     di                      ; restore what we saved
  2437.         pop     si
  2438.         pop     dx
  2439.         pop     cx
  2440.         pop     bx
  2441.         pop     ax
  2442.         pop     es
  2443.         ret                             ; return to caller
  2444. chgdsp  endp
  2445.  
  2446. ; Individual tests for various 132-column boards
  2447.                                         ;
  2448.                                         ; Tseng LABS EVA and UltraPAK
  2449. ckteva: mov     ax,0c000h               ; seg addr for EVA
  2450.         mov     es,ax                   ; set into es register
  2451.         mov     di,76h                  ; offset of board's string
  2452.         lea     si,tsngid               ; validation string
  2453.         mov     cx,tsnglen              ; length of validiation string
  2454.         cld
  2455.         repe    cmpsb                   ; compare strings
  2456.         je      ckteva2                 ; e = strings match
  2457.         mov     ax,4d00h                ; check for UltraPAK mono driver
  2458.         int     screen
  2459.         cmp     ax,5aa5h                ; driver signature?
  2460.         jne     chnoad                  ; ne = no
  2461.         mov     cx,7                    ; default to mono (7) for this board
  2462.         cmp     byte ptr temp,0         ; setting 132 columns?
  2463.         je      ckteva1                 ; e = resetting to normal
  2464.         mov     cx,18h                  ; set to 132 cols (Set Mode 18H)
  2465. ckteva1:clc                             ; carry clear means found
  2466.         ret
  2467.  
  2468. ckteva2:                                ; an EVA board - check for 132 col kit
  2469.         cmp     byte ptr es:099h,0      ; check 132 col kit installed
  2470.         je      chnoad                  ; e=0=not installed
  2471.         jmp     catfnd                  ; do the mode change
  2472.  
  2473. chnoad: stc                             ; indicate adapter not present
  2474.         ret                             ; and exit
  2475.                                         ;
  2476.                                         ; ATI EGA Wonder
  2477. ckatiw: mov     ax,0c000h               ; seg addr for EGA Wonder
  2478.         mov     es,ax                   ; set into es register
  2479.         mov     di,012fh                ; offset of message in ROM
  2480.         lea     si,atiwid               ; offset of message here
  2481.         mov     cx,atilen               ; length of validation string
  2482.         cld
  2483.         repe    cmpsb                   ; compare strings
  2484.         jne     chnoad                  ; ne = strings differ
  2485.                                         ;
  2486. catfnd: mov     cx,0003h                ; prepare to reset video mode
  2487.         cmp     byte ptr temp,0         ; are we setting or resetting?
  2488.         je      ckexit                  ; e is reset, exit
  2489.         mov     cx,0023h                ; set to 132 cols (Set Mode 23H)
  2490. ckexit: clc                             ; carry clear means found
  2491.         ret
  2492.                                         ;
  2493.                                         ; Video 7 Vega Deluxe
  2494. ckv7vd: mov     ax,0c000h               ; seg addr for Vega rom bios
  2495.         mov     es,ax                   ; set into es register
  2496.         mov     di,002ah                ; offset of message in ROM
  2497.         lea     si,vid7id               ; offset of message here
  2498.         mov     cx,vid7len
  2499.         cld
  2500.         repe    cmpsb                   ; compare strings
  2501.         je      cnv7fn0                 ; e = same
  2502.         mov     di,002ah                ; offset of ident string
  2503.         mov     si,offset vid7id2       ; Video 7 VGA board
  2504.         mov     cx,vid7len2
  2505.         repe    cmpsb
  2506.         je      cnv7fn2                 ; e = found
  2507. cnv7fx: jmp     chnoad                  ; ne = strings are different
  2508.                                         ;
  2509. cnv7fn0:test    byte ptr es:[03ffeh],1  ; is this a 'Deluxe' Vega?
  2510.         jz      chnoad                  ; z = nope, can't do it
  2511.         mov     ah,35h                  ; DOS Get Vector
  2512.         mov     al,10h                  ; Bios video interrupt
  2513.         int     dos                     ; get it into es:bx
  2514.         mov     di,bx                   ; es:bx is returned int 10h entry pnt
  2515.         sub     di,5ah                  ; back offset to msg in 132X25.COM
  2516.         lea     si,vid7id               ; offset of validation message
  2517.         mov     cx,vid7len              ; length of validation string
  2518.         cld
  2519. cnv7fn1:repe    cmpsb                   ; Look for repeat of msg by 132X25.COM
  2520.         jne     cnv7fn2                 ; if different
  2521.         mov     cl,crt_mode             ; prepare to reset video mode
  2522.         mov     ch,0
  2523.         cmp     byte ptr temp,0         ; are we setting or resetting?
  2524.         je      ckexit                  ; e is reset, exit
  2525.         mov     cx,0000h                ; set to 132 cols (old 40x25)
  2526.         jmp     short ckexit            ; and exit
  2527.  
  2528. cnv7fn2:mov     ax,6f00h                ; check for VegaBios driver
  2529.         int     screen
  2530.         cmp     bx,'V7'                 ; Video 7 Bios presence response
  2531.         jne     cnv7fx                  ; ne = not there
  2532.         mov     ax,6f01h                ; al gets monitor type (mono,color,ega)
  2533.         int     screen
  2534.         mov     bx,51h                  ; presume mono 132x25, page 0
  2535.         cmp     crt_lins,42             ; 43 lines active?
  2536.         jb      cnv7fn2a                ; b = no
  2537.         inc     bx                      ; use bx = 52h for 132x43
  2538. cnv7fn2a:
  2539.         cmp     al,10h                  ; analogue fixed freq (IBM 85xx)?
  2540.         je      cnv7fx                  ; e = yes, no 132 columns
  2541.         cmp     al,2                    ; 1 = mono, 2 = color, above = ega
  2542.         jb      cnv7fn3                 ; b = mono or unknown
  2543.         mov     bx,4fh                  ; presume med res color 132x25
  2544.         je      cnv7fn3                 ; e = med res color, al = 2
  2545.         mov     bx,41h                  ; ega high res 132x25, enhanced mons
  2546.         cmp     crt_lins,42             ; 43 lines active?
  2547.         jb      cnv7fn3                 ; b = no
  2548.         inc     bx                      ; use bx = 42h for 132x43
  2549. cnv7fn3:mov     ax,6f05h                ; set special mode found in bl
  2550.         cmp     byte ptr temp,0         ; resetting to 80 column mode?
  2551.         jne     cnv7fn4                 ; ne = no, setting 132x25
  2552.         mov     al,crt_norm             ; get normal mode
  2553.         mov     ah,0                    ; set mode
  2554.         cmp     crt_lins,42             ; 43 lines active?
  2555.         jb      cnv7fn4                 ; b = no
  2556.         mov     bl,40h                  ; use Video 7 mode 40h 80x43 for color
  2557.         mov     ax,6f05h                ; and do special mode set
  2558. cnv7fn4:int     screen                  ; special mode is in bl
  2559.         mov     cx,0f00h                ; a nop screen bios command
  2560.         clc
  2561.         ret
  2562.  
  2563. ckevrx: mov     ax,0c000h               ; seg addr for Everex EV-659
  2564.         mov     es,ax                   ; set into es register
  2565.         mov     di,0047h                ; offset of message in ROM
  2566.         lea     si,evrxid               ; offset of message here
  2567.         mov     cx,evrxlen              ; length of validation string
  2568.         cld
  2569.         repe    cmpsb                   ; compare strings
  2570.         jne     ckfnr2                  ; ne = strings differ
  2571.         mov     ah,crt_lins             ; we recognize either 44 or 25 rows
  2572.         cmp     ah,43                   ; equal to 44-1 rows?
  2573.         jne     ckfnr1                  ; ne = no
  2574.         mov     cx,0070h                ; Everex extended mode ident
  2575.         mov     bl,09h                  ; prepare to reset video mode to 80x44
  2576.         cmp     byte ptr temp,0         ; are we setting or resetting?
  2577.         je      ckfnr4                  ; e is reset, exit
  2578.         mov     bl,0bh                  ; 132x44
  2579.         jmp     ckexit
  2580. ckfnr1: cmp     ah,24                   ; equal to 25-1 rows?
  2581.         je      ckfnr3                  ; e = yes
  2582. ckfnr2: jmp     chnoad                  ; ne = no
  2583. ckfnr3: mov     cx,0003h                ; prepare to reset video mode
  2584.         cmp     byte ptr temp,0         ; are we setting or resetting?
  2585.         je      ckfnr4                  ; e is reset, exit
  2586.         mov     cx,0070h                ; Everex extended mode ident
  2587.         mov     bl,0ah                  ; 132x25
  2588. ckfnr4: jmp     ckexit
  2589. ckevga: mov     ax,0c000h               ; Everex FVGA-673, rom segment
  2590.         mov     es,ax
  2591.         mov     di,76h                  ; offset in rom for board's id string
  2592.         lea     si,evgid                ; id string
  2593.         mov     cx,evglen               ; length of id string
  2594.         cld
  2595.         repe    cmpsb                   ; do they match?
  2596.         jne     ckevg2                  ; ne = no
  2597.         mov     cx,3                    ; prepare to reset video mode
  2598.         cmp     byte ptr temp,0         ; setting or resetting mode?
  2599.         je      ckevg1                  ; e = resetting, exit
  2600.         mov     cx,0070h                ; mode for 132x25
  2601.         mov     bl,0ah                  ; Everex mode 0ah
  2602. ckevg1: clc
  2603.         ret
  2604. ckevg2: stc                             ; say board not found
  2605.         ret
  2606. ; Jumping to this location is like retskp.  It assumes the instruction
  2607. ;   after the call is a jmp addr.
  2608.  
  2609. RSKP    PROC    NEAR
  2610.         pop     bp
  2611.         add     bp,3
  2612.         push    bp
  2613.         ret
  2614. RSKP    ENDP
  2615.  
  2616. ; Jumping here is the same as a ret
  2617.  
  2618. R       PROC    NEAR
  2619.         ret
  2620. R       ENDP
  2621.  
  2622. code    ends
  2623.  
  2624. if1
  2625.         %out [End of pass 1]
  2626. else
  2627.         %out [End of assembly]
  2628. endif
  2629.  
  2630.         end
  2631.