home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / t / tel2305s.zip / ENGINE / NCSAIO.ASM < prev    next >
Assembly Source File  |  1992-03-28  |  59KB  |  2,496 lines

  1. ;
  2. ;  ncsaio.asm
  3. ;  Support for BIOS calls in NCSA Telnet
  4. ;****************************************************************************
  5. ;*                                                                            *
  6. ;*                                                                            *
  7. ;*      part of NCSA Telnet                                                    *
  8. ;*      by Tim Krauskopf, VT100 by Gaige Paulsen, Tek by Aaron Contorer        *
  9. ;*                                                                            *
  10. ;*      National Center for Supercomputing Applications                        *
  11. ;*      152 Computing Applications Building                                    *
  12. ;*      605 E. Springfield Ave.                                                *
  13. ;*      Champaign, IL  61820                                                    *
  14. ;*                                                                            *
  15. ;*                                                                            *
  16. ;****************************************************************************
  17.  
  18.     TITLE    NCSAIO    -- LOW-LEVEL I/O FOR SANE HARDWARE HANDLING
  19. ;Microsoft EQU 1
  20. ;Lattice EQU 1
  21. ifndef Microsoft
  22.     ifndef Lattice
  23.         if2
  24.             %out
  25.             %out ERROR: You have to specify "/DMicrosoft" OR "/DLattice" on the
  26.             %out        MASM command line to determine the type of assembly.
  27.             %out
  28.         endif
  29.         end
  30.     endif
  31. endif
  32.  
  33. ;
  34. ;   From original code by Tim Krauskopf    1984-1985
  35. ;
  36. ;   Modified and ported to Lattice C, Sept. 1986
  37. ;   ifdefs for Microsoft C, June 1987
  38. ;   Tim Krauskopf
  39. ;
  40. ;   Modified for version 2.3 release May 1990 by Heeren Pathak
  41. ;
  42. ;   National Center for Supercomputing Applications
  43. ;
  44.     NAME    NIO
  45.  
  46. ;
  47. ;  Macros for reading and writing I/O ports
  48. ;
  49. MOUT    MACRO    REG,STUFF       ; one byte to the given I/O register
  50.     MOV        DX,REG
  51.     MOV        AL,STUFF
  52.     OUT        DX,AL
  53.     ENDM
  54. ;
  55. MIN    MACRO    REG                 ; get one byte to al
  56.     MOV        DX,REG
  57.     IN        AL,DX
  58.     ENDM
  59. ;
  60. ;  Internal data 
  61. ;
  62. X   EQU 6                       ;  for the large model programs
  63. MONO_SEG   EQU     0b000h       ; Standard display segments
  64. COLOR_SEG  EQU     0b800h
  65.  
  66. ifdef Microsoft
  67. ;DGROUP  group   _DATA
  68. ;_DATA   segment public 'DATA'
  69. ;    assume  DS:DGROUP
  70. .MODEL  LARGE
  71. .DATA
  72.  
  73. ifndef NET14
  74.     PUBLIC _DTAPTR                ; pointer to dta location
  75.     PUBLIC _KEYBOARD_TYPE       ; Keyboard type installed
  76. _DTAPTR     DW    0000H            ; DTA address for me
  77. _DTADS        DW    0000H            ; DS for DTA
  78. endif
  79. _KEYBOARD_TYPE    DB    ?            ; KEYBOARD TYPE (0) - is standard
  80.                                 ; (0x10) is enhanced
  81. else
  82.     INCLUDE    DOS.MAC
  83.     DSEG
  84. ifndef NET14
  85.     PUBLIC    DTAPTR                ; pointer to dta location
  86.     PUBLIC  KEYBOARD_TYPE       ; Keyboard type installed
  87. DTAPTR      DW  0000H           ; dta ADDRESS FOR ME
  88. DTADS        DW    0000H            ; ds FOR dta
  89. endif
  90. KEYBOARD_TYPE    DB    ?            ; KEYBOARD TYPE (0) - is standard
  91.                                 ; (0x10) is enhanced
  92. endif
  93.  
  94. ATT            DB    7                ; CURRENT DEFAULT ATTRIBUTE
  95. TOPL        DB    00                ; TOP LINE OF CURRENT WINDOW
  96. BOTL        DB    24                ; BOTTOM LINE OF CURRENT WINDOW
  97. LEFTC        DB    00                ; LEFT SIDE OF CURRENT WINDOW
  98. RIGHTC        DB    79                ; RIGHT SIDE OF CURRENT WINDOW
  99. ROW            DB    00                ; CURSOR POSITION ROW
  100. COL            DB    00                ; CURSOR POSITION COL
  101. WRAP        DB    00                ; WRAP AT END OR NOT
  102. CURSOR      DW  0607H            ; DEFAULT CURSOR SHAPE
  103. CURSOR_SAVE    DW    ?                ; PLACE TO SAVE THE USER'S CURSOR IN
  104. BREAK_STATE    DB    ?                ; WHETHER THE BREAK IS SET TO ON OR OFF
  105. EGAMODE     DB  ?                ; DEFAULT EGA MODE
  106.  
  107. video_segment   DW  COLOR_SEG   ; Display memory segment address
  108. video_type      DB  0ffh        ; Display combination code
  109. video_iscolor   DB  01h         ; 1=color, 0=monochrome
  110. video_mode      DB  03h         ; Video display mode
  111. video_page      DB  00h         ; Video Display Page
  112. video_rows      DB  25          ; Number of Text rows
  113. video_cols      DB  80          ; Number of Text columns
  114. video_cursor    DW  ?           ; Cursor shape
  115. video_font      DW  ?           ; Current font function
  116.  
  117. ifdef Microsoft
  118. ;_DATA   ends
  119. else
  120.     ENDDS
  121. endif
  122.  
  123. ;
  124. ;   The subroutines to call from C
  125. ;
  126. ifdef Microsoft
  127. ;_TEXT   segment public  'CODE'
  128. ;    assume CS:_TEXT
  129. .CODE
  130. ifndef NET14
  131.     PUBLIC  _n_color
  132. endif
  133. ifdef FTPBIN
  134.     PUBLIC  _n_wrap
  135. endif
  136. ;    PUBLIC  _n_erase
  137. ifndef NET14
  138.     PUBLIC  _n_getchar,_n_cur,_n_row,_n_col,_n_clear,_n_window
  139. endif
  140.     PUBLIC  _n_putchar
  141. ifndef NET14
  142.     PUBLIC  _n_chkchar
  143. endif
  144. ;   PUBLIC  _n_savewin,_n_restwin
  145.     PUBLIC  _n_puts,_n_sound
  146. ifndef NET14
  147.     PUBLIC  _n_findfirst,_n_findnext,_n_draw,_n_scrup,_n_scrdn,_n_cheat
  148. endif
  149.     PUBLIC  _n_clicks
  150. ifndef NET14
  151.     PUBLIC  _n_biosattr
  152. endif
  153. ;   PUBLIC  _getdsk, _chgdsk
  154. ifndef NET14
  155.     PUBLIC  _ega43,_n_flags,_set_cur,_ega24,_vga50
  156.     PUBLIC  _n_scrlck,_save_break,_restore_break,_n_gmode,_save_cursor
  157.     PUBLIC  _restore_cursor,_install_cursor,_n_attr
  158.     PUBLIC  _install_keyboard,_fix_vid,_get_mode,_set_mode,_get_size
  159.     PUBLIC  _set_page,_initvideo,_getvconfig,_getvstate,_setvstate
  160. endif
  161. else            ; Lattice C
  162.     PSEG
  163. ifndef NET14
  164.     PUBLIC  n_color
  165. endif
  166. ifdef FTPBIN
  167.     PUBLIC  n_wrap
  168. endif
  169. ;    PUBLIC  n_erase
  170. ifndef NET14
  171.     PUBLIC  n_getchar,n_cur,n_row,n_col,n_clear,n_window
  172. endif
  173.     PUBLIC  n_putchar
  174. ifndef NET14
  175.     PUBLIC  n_chkchar
  176. endif
  177. ;   PUBLIC  n_savewin,n_restwin
  178.     PUBLIC  n_puts,n_sound
  179. ifndef NET14
  180.     PUBLIC  n_findfirst,n_findnext,n_draw,n_scrup,n_scrdn,n_cheat
  181. endif
  182.     PUBLIC  n_clicks
  183. ifndef NET14
  184.     PUBLIC  n_biosattr
  185. endif
  186.     PUBLIC  n_srclck
  187. ifndef NET14
  188.     PUBLIC  ega43,n_flags,set_cur,ega24,vga50
  189.     PUBLIC  n_scrlck,save_break,restore_break,n_gmode,save_cursor
  190.     PUBLIC  restore_cursor,install_cursor,n_attr
  191.     PUBLIC  install_keyboard,fix_vid,get_mode,set_mode,get_size
  192.     PUBLIC  set_page,initvideo,getvconfig,getvstate,setvstate
  193. endif
  194. endif
  195.  
  196.  
  197. ifndef NET14
  198. ;****************************************************************
  199. ; install_keyboard
  200. ;
  201. ; check for enhanced keyboard, and set keyboard type variable
  202. ;
  203. ;
  204. ifdef Microsoft
  205. _install_keyboard    proc     far
  206. else
  207. install_keyboard    proc    far
  208. endif
  209.     PUSH    DS
  210.     PUSH    SI
  211.     MOV        AX,040H                ; load the address of the keyboard flag
  212.     MOV        DS,AX
  213.     MOV        SI,096H
  214.     LODSB                        ; get the keyboard flag
  215.     POP        SI
  216.     POP        DS
  217.     AND        AL,10H                ; mask off all bits except the enhanced flag
  218. ifdef Microsoft
  219.     MOV        _KEYBOARD_TYPE,AL    ; store the keyboard type
  220. else
  221.     MOV        KEYBOARD_TYPE,AL    ; store the keyboard type
  222. endif
  223.     RET
  224. ifdef Microsoft
  225. _install_keyboard    endp
  226. else
  227. install_keyboard    endp
  228. endif
  229.  
  230. ;****************************************************************
  231. ; install cursor
  232. ;
  233. ; put in user defined cursor settings
  234. ;
  235. ;
  236. ifdef Microsoft
  237. _install_cursor    proc     far
  238. else
  239. install_cursor    proc    far
  240. endif
  241.     push    bp      ; save the base pointer
  242.     mov bp,sp       ; point to the stack
  243.  
  244.     mov AX,[bp+x]   ; read our first parameter
  245.     mov CURSOR,AX   ; save into the cursor variable
  246.  
  247.     pop bp          ; get the old base
  248.     ret
  249. ifdef Microsoft
  250. _install_cursor    endp
  251. else
  252. install_cursor    endp
  253. endif
  254.  
  255. ;/***************************************************************/
  256. ; scrlck
  257. ;   returns whether scroll lock is on or not
  258. ;
  259. ifdef Microsoft
  260. _n_scrlck    proc    far
  261. else
  262. n_scrlck    proc    far
  263. endif
  264.  
  265.         mov        ax,0200h        ; get shift states
  266.         int        16h                ; keyboard int
  267.         and        al,010h            ; scroll lock state bit
  268.         xor        ah,ah
  269.  
  270.         ret    
  271. ifdef Microsoft
  272. _n_scrlck    endp
  273. else
  274. n_scrlck    endp
  275. endif
  276.  
  277. ;*********************************************************************
  278. ;*      save_break
  279. ;*      record the state of the DOS BREAK status, and turn BREAK ON
  280. ;*
  281. ifdef Microsoft
  282. _save_break    proc    far
  283. else
  284. save_break    proc     far
  285. endif
  286.  
  287.     MOV        AX,3300H            ; request current break state
  288.     INT        21H                    ;
  289.     MOV        BREAK_STATE,DL        ; preserve the break state
  290.  
  291.     MOV        AX,3301H            ; set break state
  292.     MOV        DL,1                ; turn break on
  293.     INT        21H                    ;
  294.  
  295.     RET
  296. ifdef Microsoft
  297. _save_break     endp
  298. else
  299. save_break    endp
  300. endif    
  301.  
  302. ;*********************************************************************
  303. ;*      restore_break
  304. ;*      restore the previous state of the DOS BREAK state
  305. ;*
  306. ifdef Microsoft
  307. _restore_break    proc    far
  308. else
  309. restore_break    proc     far
  310. endif
  311.  
  312.     MOV        AX,3301H            ; set break state
  313.     MOV        DL,BREAK_STATE        ; return break state to previous value
  314.     INT        21H                    ;
  315.  
  316.     RET
  317. ifdef Microsoft
  318. _restore_break     endp
  319. else
  320. restore_break    endp
  321. endif    
  322.  
  323. ;*********************************************************************
  324. ;*      save_cursor
  325. ;*      record the state of the DOS keyboard cursor for page 0
  326. ;*
  327. ifdef Microsoft
  328. _save_cursor    proc    far
  329. else
  330. save_cursor    proc     far
  331. endif
  332.  
  333.     MOV        AX,0300h            ; GET THE CURRENT CURSOR TYPE
  334.     MOV        BX,0000h            ; INFO FOR PAGE 0
  335.     INT    10h
  336.     MOV        CURSOR_SAVE,CX
  337.  
  338.     RET
  339. ifdef Microsoft
  340. _save_cursor     endp
  341. else
  342. save_cursor    endp
  343. endif
  344.  
  345. ;*********************************************************************
  346. ;*      restore_cursor
  347. ;*      restore the previous state of the DOS keyboard cursor
  348. ;*
  349. ifdef Microsoft
  350. _restore_cursor    proc    far
  351. else
  352. restore_cursor    proc     far
  353. endif
  354.  
  355.     MOV        AH,01H            ; set the keyboard cursor
  356.     MOV        CX,CURSOR_SAVE    ; get the user's keyboard cursor
  357.     INT        10H                ; set the cursor
  358.  
  359.     RET
  360. ifdef Microsoft
  361. _restore_cursor     endp
  362. else
  363. restore_cursor    endp
  364. endif    
  365.  
  366. ;*********************************************************************
  367. ;*      n_gmode
  368. ;*      change the type of video display being used
  369. ;*
  370. ifdef Microsoft
  371. _n_gmode    PROC    FAR
  372. else
  373. n_gmode        PROC    FAR
  374. endif
  375.     PUSH    BP
  376.     MOV        BP,SP
  377.     
  378.     MOV        AX,[BP+X]        ;GET SCREEN MODE TO SWITCH TO
  379.     XOR        AH,AH            ;ENTER VIDEO_IO ROUTINE (SET MODE=0)
  380.     INT        10H                ;VIDEO INTERUPT
  381.  
  382.     POP    BP
  383.     RET
  384. ifdef Microsoft    
  385. _n_gmode    ENDP
  386. else
  387. n_gmode    ENDP
  388. endif
  389.  
  390. ;*********************************************************************
  391. ;*      ega24
  392. ;*      set char set for 24 line mode
  393. ;*
  394.  
  395. ifdef Microsoft
  396. _ega24    proc    far
  397. else
  398. ega24    proc     far
  399. endif
  400.  
  401.     MOV     BL,30H          ;Select scan lines for alphanumeric modes.
  402.     MOV     AX,1202H        ;Set 400 scan lines.
  403.     INT     10H
  404.  
  405.     MOV     AX,3                ; reset egamode
  406.     INT     10H
  407.  
  408.     MOV        AX,0100H            ; SET CURSOR
  409.     MOV        CX,CURSOR            ; TURN ON
  410.     INT     10H
  411.  
  412.     RET
  413. ifdef Microsoft
  414. _ega24     endp
  415. else
  416. ega24    endp
  417. endif    
  418.  
  419. ;****************************************************************
  420. ;*   set_cur
  421. ;*   sets cursor on or off
  422. ;*
  423. ifdef Microsoft
  424. _set_cur     proc    far
  425. else
  426. set_cur        proc    far
  427. endif
  428.     PUSH     BP
  429.     MOV        BP,SP
  430.  
  431.     MOV        AL,[BP+X]            ;get var
  432.     OR        AL,AL
  433.     JNZ        CUR                    ; MAKE CURSOR
  434.     MOV        AX,0100H            ; TURN OFF
  435.     MOV        CX,2000H            ; BEGIN END OF CURSOR
  436.     INT     10h
  437.     JMP     SHORT EXIT                ; we are done
  438. CUR:    
  439.     MOV     CX,CURSOR           ; get cursor type
  440.     MOV     AX,0100h            ; reset cursor
  441.     INT     10h
  442. EXIT:
  443.     POP     BP
  444.     RET
  445. ifdef Microsoft
  446. _set_cur endp
  447. else
  448. set_cur endp
  449. endif
  450.  
  451. ;****************************************************************
  452. ;*   n_flags
  453. ;*     returns the keyboard status flags
  454. ;*
  455. ifdef Microsoft
  456. _n_flags    proc    far
  457. else
  458. n_flags     proc    far
  459. endif
  460.  
  461.     MOV        AX,0200h            ; get shift states
  462.     INT        16h                    ; keyboard INT
  463.     XOR        AH,AH
  464.  
  465.     RET    
  466. ifdef Microsoft
  467. _n_flags    endp
  468. else
  469. n_flags    endp
  470. endif
  471.  
  472. ;****************************************************************
  473. ;*   ega43
  474. ;*   code for 43 line ega mode
  475. ;*     
  476. ifdef Microsoft
  477. _ega43 proc far
  478. else
  479. ega43 proc far
  480. endif
  481.  
  482. ifdef OLD_WAY
  483.     MOV        AH,00H                ; SET TO 80X25 CHAR MODE
  484.     MOV        AL,03H
  485.     INT        10H
  486.  
  487.     MOV        AX,1112H            ; CHAR. GENERATOR BIOS ROUTINUE
  488.     MOV        BL,00H                ; LOAD 8 BY 8 DOUBLE DOT CHARACTER FONT
  489.     INT     10H                    ; VIDEO CALL
  490.  
  491.     MOV        AX,1200H            ; ALTERNATE SCREEN ROUTINE
  492.     MOV     BL,20H              ; SELECT ALTERNATE PRINT SCREEN ROUTINE
  493.     INT     10H                    ; VIDEO CALL
  494. else
  495.     MOV     BL,30H              ; Select scan lines for alphanumeric modes
  496.     MOV     AX,1201H            ; Set 350 scan lines
  497.     INT     10H
  498.  
  499.     MOV     AX,3                ; 80x25 color text
  500.     INT     10H
  501.  
  502.     MOV     AX,1112H            ; Char. generator BIOS routine
  503.     MOV     BL,00H              ; Load 8x8 double dot character font
  504.     INT     10H                 ;
  505.  
  506. endif
  507.  
  508.     MOV        AX,0007H    
  509.     MOV     CURSOR,AX           ; full cursor
  510.  
  511.     RET    
  512. ifdef Microsoft
  513. _ega43     endp
  514. else
  515. ega43    endp
  516. endif
  517.  
  518. ;****************************************************************
  519. ;*   vga50
  520. ;*   code for 50 line vga mode
  521. ;*     
  522. ifdef Microsoft
  523. _vga50 proc far
  524. else
  525. vga50 proc far
  526. endif
  527.  
  528.     MOV     BL,30H              ; Select scan lines for alphanumeric modes
  529.     MOV     AX,1202H            ; Set 400 scan lines
  530.     INT     10H
  531.  
  532.     MOV     AX,3                ; 80x25 color text
  533.     INT     10H
  534.  
  535.     MOV     AX,1112H            ; Char. generator BIOS routine
  536.     MOV     BL,00H              ; Load 8x8 double dot character font
  537.     INT     10H                 ;
  538.  
  539.     MOV        AX,0007H    
  540.     MOV     CURSOR,AX           ; full cursor
  541.  
  542.     RET    
  543. ifdef Microsoft
  544. _vga50  endp
  545. else
  546. vga50   endp
  547. endif
  548. endif       ; NET14
  549.  
  550. ifdef NOT_USED
  551. ;*****************************************************************
  552. ;*   getDSk
  553. ;*   gets the active drive
  554. ;*     
  555. ifdef Microsoft
  556. _getdsk proc    far
  557.  
  558.     MOV        AH,19H
  559.     INT        21h
  560.  
  561.     RET
  562. _getdsk     endp    
  563. endif         
  564.  
  565. ;*****************************************************************
  566. ;*     chgdsk
  567. ;*   changes current drive
  568. ;*
  569.  
  570. ifdef Microsoft
  571. _chgdsk    proc    far
  572.     PUSH    BP
  573.     MOV     BP,SP
  574.  
  575.     MOV        AH,0Eh
  576.     MOV        DL,[BP+X]
  577.     INT        21H
  578.  
  579.     POP        BP
  580.     RET
  581. _chgdsk    endp
  582. endif
  583. endif
  584.  
  585. ifndef NET14
  586. ;*****************************************************************
  587. ;*  n_attr
  588. ;*  replaces char. attribute
  589. ;*
  590. ifdef Microsoft
  591. _n_attr    proc    far
  592. else 
  593. n_attr    proc    far
  594. endif
  595.     PUSH    BP
  596.     MOV        BP,SP
  597.     PUSH     ES
  598.     PUSH    DI
  599. ;
  600. ;  for now, assume that the cursor location has ALready been set
  601. ;  (cursor is there)
  602. ;
  603.     MOV     AX,video_segment
  604.     MOV     ES,AX               ; set up for segment where screen is
  605.  
  606.     MOV        AL,ROW                ; row where chars go
  607.     XOR        AH,AH
  608.     MOV        BL,160
  609.     MUL        BL                    ; AX now equALs start of row
  610.     XOR        BH,BH
  611.  
  612.     MOV        BL,COL
  613.     SHL        BL,1                ; COL*2
  614.     ADD        AX,BX                ; add in column offset
  615.     INC        AX
  616.     MOV     DI,AX
  617.     MOV        AL,[BP+X]            ; ATTRIBUTE For CHARS
  618.     STOSB                        ; STorE aTTR
  619.  
  620.     POP        DI
  621.     POP        ES
  622.     POP        BP
  623.     RET
  624. ifdef Microsoft
  625. _n_attr     endp
  626. else
  627. n_attr      endp
  628. endif
  629.         
  630. ;*****************************************************************
  631. ;*  n_biosattr
  632. ;*  replaces char. attribute
  633. ;*  uses bios instead of directly screen write
  634. ;*
  635.  
  636. ifdef Microsoft
  637. _n_biosattr    proc    far
  638. else 
  639. n_biosattr    proc    far
  640. endif
  641.     PUSH     BP
  642.     MOV     BP,SP
  643.  
  644.     MOV         AH,8h                ; we want to read
  645.     MOV         BH,0H                ; GET FROM PAGE ZERO
  646.     INT     10H
  647.     MOV        BL,[BP+X]            ; GET CHANGED ATTRIBUTE
  648.     MOV        AH,9H                 ; WE WANT TO WRITE
  649.     MOV        CX,1H                ; ONLY ONCE
  650.     INT     10H
  651.  
  652.     POP     BP
  653.     RET
  654. ifdef Microsoft
  655. _n_biosattr     endp
  656. else
  657. n_biosattr      endp
  658. endif
  659.  
  660. ;/***************************************************************/
  661. ;
  662. ;   Change the vALue of my current color
  663. ;
  664. ifdef Microsoft
  665. _n_color    proc    far
  666. else
  667. n_color    proc    far
  668. endif
  669.     PUSH    BP
  670.     MOV        BP,SP
  671.  
  672.     XOR        AX,AX
  673.     MOV        DL,[BP+X]            ; PARAMETER, ONE BYTE
  674.     MOV        AL,ATT                ; RETURN OLD COLor
  675.     MOV        ATT,DL
  676.  
  677.     POP        BP
  678.     RET
  679. ifdef Microsoft
  680. _n_color    endp
  681. else
  682. n_color    endp
  683. endif
  684. endif           ; NET14
  685.  
  686. ;/*****************************************************************/
  687. ;   Determine the current type of DISPlay
  688. ;
  689. ;   ask the BIOS which screen is currently active
  690. ;
  691. ifdef Microsoft
  692. _n_which    proc    far
  693. else
  694. n_which    proc    far
  695. endif
  696.  
  697.     MOV     AX,0300h            ; GET THE CURRENT CURSOR
  698.     MOV        BX,0000h            ; INFO FOR PAGE 0
  699.     INT    10h
  700.     MOV        CURSOR,CX
  701.  
  702.     RET
  703. ifdef Microsoft
  704. _n_which    endp
  705. else
  706. n_which    endp
  707. endif
  708.  
  709. ifdef FTPBIN
  710. ;
  711. ;/***************************************************************/
  712. ;
  713. ;   Set whether word wrap will be on or not
  714. ;   usage:  n_wrap(flag);
  715. ;
  716. ifdef Microsoft
  717. _n_wrap    proc    far
  718. else
  719. n_wrap    proc    far
  720. endif
  721.     PUSH    BP
  722.     MOV        BP,SP
  723.  
  724.     MOV        DL,[BP+X]            ; PARAMETER, ONE BYTE FLAG
  725.     MOV        AL,WRAP                ; RETURN OLD COLor
  726.     MOV        WRAP,DL
  727.  
  728.     POP        BP
  729.     RET
  730. ifdef Microsoft
  731. _n_wrap    endp
  732. else
  733. n_wrap    endp
  734. endif
  735. endif
  736.  
  737. ifndef NET14
  738. ;/***************************************************************/
  739. ;
  740. ;   Move the cursor somewhere
  741. ;
  742. ifdef Microsoft
  743. _n_cur    proc    far
  744. else
  745. n_cur    proc    far
  746. endif
  747.     PUSH    BP
  748.     MOV        BP,SP
  749.  
  750.     MOV     DH,[BP+X]       ; row poSItion
  751.     MOV     DL,[BP+X+2]     ; column poSItion
  752.     MOV     ROW,DH          ; save a copy for me
  753.     MOV     COL,DL          ; save column too
  754.     MOV     AX,0200h        ; ah=2 FUNCTION CalL
  755.     XOR     BX,BX           ; video page 0
  756.     INT     10H             ; set cursor poSItion
  757.  
  758.     POP        BP
  759.     RET
  760. ifdef Microsoft
  761. _n_cur    endp
  762. else
  763. n_cur    endp
  764. endif
  765.  
  766. ;/***************************************************************/
  767. ;
  768. ;  set the window boundaries
  769. ;
  770. ;  usage:  n_window(ulrow,ulcol,lrrow,lrcol);
  771. ;    sets window SIze for future operations.
  772. ;
  773. ;
  774. ifdef Microsoft
  775. _n_window    proc    far
  776. else
  777. n_window    proc    far
  778. endif
  779.     PUSH        BP
  780.     MOV            BP,SP
  781.  
  782.     MOV            AL,[BP+X]        ; UPPER LEFT Y
  783.     MOV            TOPL,AL
  784.     MOV            AL,[BP+X+2]        ; COLUMN POsiTION
  785.     MOV         LEFTC,AL        ; save a copy for me
  786.     MOV            AL,[BP+X+4]
  787.     MOV            BOTL,AL            ; bottom row
  788.     MOV            AL,[BP+X+6]
  789.     MOV            RIGHTC,AL        ; keep this one too
  790. ifdef Microsoft
  791.     CALL        _N_WHICH        ; what kind of screen?
  792. else
  793.     CALL        N_WHICH            ; WHAT KIND OF SCREEN?
  794. endif
  795.  
  796.     POP            BP
  797.     RET
  798. ifdef Microsoft
  799. _n_window    endp
  800. else
  801. n_window    endp
  802. endif
  803. endif       ; NET14
  804.  
  805. ifdef NOT_USED
  806. ;/***************************************************************/
  807. ;
  808. ;  erase portion of the screen
  809. ;
  810. ;  usage:  n_erase(ulrow,ulcol,lrrow,lrcol);
  811. ;
  812. ;
  813. ifdef Microsoft
  814. _n_erase    proc    far
  815. else
  816. n_erase    proc    far
  817. endif
  818.     PUSH    BP
  819.     MOV        BP,SP
  820.  
  821.     MOV        CH,[BP+X]            ; UPPER LEFT X
  822.     MOV        CL,[BP+X+2]            ; COLUMN POsiTION
  823.     MOV        DH,[BP+X+4]
  824.     MOV        DL,[BP+X+6]
  825.     XOR        AX,AX                ; clear area
  826.     MOV        AH,6                ; scroll up function
  827.     MOV        BH,ATT                ; ATTRIBUTE For ERAsiNG IS SAME AS PRint
  828.     INT        10H                    ; CalL bios
  829.  
  830.     POP        BP
  831.     RET
  832. ifdef Microsoft
  833. _n_erase    endp
  834. else
  835. n_erase    endp
  836. endif
  837. endif
  838.  
  839. ifndef NET14
  840. ;/***************************************************************/
  841. ;  scroll up and down
  842. ;  given the number of lines to scroll and the DImenSIons of the
  843. ;  box to scroll.
  844. ;  
  845. ifdef Microsoft
  846. _n_scrup    proc    far
  847. else
  848. n_scrup    proc    far
  849. endif
  850.     PUSH    BP
  851.     MOV        BP,SP
  852.  
  853.     MOV     AL,[BP+X]           ; NUMBER OF LINES TO SCROLL
  854.     MOV     CH,[BP+X+2]         ; UPPER LEFT X
  855.     MOV        CL,[BP+X+4]            ; COLUMN POsiTION
  856.     MOV        DH,[BP+X+6]
  857.     MOV        DL,[BP+X+8]
  858.     MOV        AH,6                ; scroll up function
  859.     MOV        BH,ATT                ; ATTRIBUTE For BLANK LINE IS SAME AS PRint
  860.     INT        10H                    ; CalL bios
  861.  
  862.     POP        BP
  863.     RET
  864. ifdef Microsoft
  865. _n_scrup    endp
  866. else
  867. n_scrup    endp
  868. endif
  869.  
  870. ifdef Microsoft
  871. _n_scrdn    proc    far
  872. else
  873. n_scrdn    proc    far
  874. endif
  875.     PUSH    BP
  876.     MOV        BP,SP
  877.  
  878.     MOV     AL,[BP+X]           ; number of lines to scroll
  879.     MOV     CH,[BP+X+2]         ; upper left x
  880.     MOV        CL,[BP+X+4]            ; column poSItion
  881.     MOV        DH,[BP+X+6]
  882.     MOV        DL,[BP+X+8]
  883.     MOV        AH,7                ; scroll down function
  884.     MOV     BH,ATT              ; attribute for blank line is same as prINT
  885.     INT        10H                    ; CalL bios
  886.  
  887.     POP        BP
  888.     RET
  889. ifdef Microsoft
  890. _n_scrdn    endp
  891. else
  892. n_scrdn    endp
  893. endif
  894.  
  895. ;/***************************************************************/
  896. ;  Find the cursor poSItion, return the row vALue
  897. ;  
  898. ifdef Microsoft
  899. _n_row    proc    far
  900. else
  901. n_row    proc    far
  902. endif
  903.  
  904.     MOV     AX,0300H            ;video find cursor function
  905.     XOR     BX,BX
  906.     INT     10H                 ; find cursor
  907.     MOV        ROW,DH
  908.     MOV     COL,DL              ; save col for next routine
  909.     XOR        AX,AX
  910.     MOV        AL,DH                ; return row location
  911.  
  912.     RET
  913. ifdef Microsoft
  914. _n_row    endp
  915. else
  916. n_row    endp
  917. endif
  918. endif       ; NET14
  919.  
  920. ;/****************************************************************************/
  921.   ;-----------------------------------------------------------
  922.   ;  This routine was submitted by David T. Burhans, Jr.
  923.   ;  It was obtained from an RBBS-PC electronic bulleton board 
  924.   ;  deDIcated to the "C" language [(703) 321-7003].
  925.   ;-----------------------------------------------------------
  926.   ;
  927.   ; SOUND - This routine produces a tone of a SPecified frequency 
  928.   ; and duration on the SPeaker.
  929.   ; The frequency in Hertz is moved INTo DI (21 to 65535 Hertz) 
  930.   ; and the duration in hundredths of a second, is moved INTo BX 
  931.   ; (0 to 65535).
  932.   ; The routine is cALled with the following sequence:
  933.   ;
  934.   ;        UnSIgned        frequency, duration;
  935.   ;
  936.   ;       n_sound(frequency, duration);
  937.   ;
  938. ifdef Microsoft
  939. _n_sound    proc    far
  940. else
  941. n_sound    proc    far
  942. endif
  943.     PUSH    BP
  944.     MOV        BP,SP
  945.     PUSH    DI
  946.  
  947.     MOV     DI,[BP+X]       ; Frequency
  948.     MOV     BX,[BP+X+2]     ; Duration
  949.     CMP     DI, 21H         ; See if freq. is below minimum
  950.     JB      DONE            ; iF LESS THAN LIMIT, THEN
  951.                             ; clean up and return
  952.     MOV     AL,0B6H         ; Write timer mode register
  953.     OUT     43H, AL
  954.     MOV     DX, 14H         ; Timer DIvisor =
  955.     MOV     AX, 4F38H       ; 1331000/Frequency
  956.     DIV     DI
  957.     OUT     42H,AL          ; Write timer 2 count low byte
  958.     MOV     AL,AH
  959.     OUT     42H,AL          ; Write timer 2 count high byte
  960.     IN      AL,61H          ; Get current Port B setting
  961.     MOV     AH,AL           ; and save it in AH
  962.     OR      AL,3            ; Turn SPeaker on
  963.     OUT     61H,AL
  964. HOLD:
  965.     MOV     CX, 2801
  966. SPKR_ON: 
  967.     LOOP    SPKR_ON
  968.     DEC     BX              ; Speaker-on count expired?
  969.     JNZ     HOLD            ; iF NOT, KEEP spEAKER ON
  970.     MOV     AL,AH           ; Otherwise, recover vALue of port
  971.     OUT     61H,AL
  972. DONE:
  973.     POP        DI
  974.     POP     BP              ; Restore cALler's BP
  975.     RET                        ; rETURN TO CalLER
  976. ifdef Microsoft
  977. _n_sound    endp
  978. else
  979. n_sound    endp
  980. endif
  981.  
  982. ifndef NET14
  983. ;/***************************************************************/
  984. ;
  985. ;  Find the column poSItion of the cursor.
  986. ;  Must be preceded by a n_row cALl!!!!
  987. ;  Will work when these routines ALready know the cursor poSItion
  988. ;
  989. ifdef Microsoft
  990. _n_col    proc    far
  991. else
  992. n_col    proc    far
  993. endif
  994.     XOR        AH,AH
  995.     MOV        AL,COL                ; RETURN COL LOCATION
  996.  
  997.     RET
  998. ifdef Microsoft
  999. _n_col    endp
  1000. else
  1001. n_col    endp
  1002. endif
  1003.  
  1004. ;/***************************************************************/
  1005. ;  n_clear
  1006. ;  Clear what we think is the current window
  1007. ;
  1008. ifdef Microsoft
  1009. _n_clear    proc    far
  1010. else
  1011. n_clear    proc    far
  1012. endif
  1013.  
  1014.     MOV        AL,0            ; clear window
  1015.     MOV        AH,6            ; scroll up function
  1016.     MOV        CH,TOPL            ; TOP ROW TO CLEAR
  1017.     MOV        CL,LEFTC        ; LEFT COLUMN
  1018.     MOV        DH,BOTL            ; BOTTOM ROW TO CLEAR
  1019.     MOV        DL,RIGHTC        ; RIGHT siDE TO CLEAR
  1020.     MOV        BH,ATT            ; ATTRIBUTE TO USE For BLANKS
  1021.     INT        10H                ; CalL bios
  1022.  
  1023.     RET
  1024. ifdef Microsoft
  1025. _n_clear    endp
  1026. else
  1027. n_clear    endp
  1028. endif
  1029. endif       ; NET14
  1030.  
  1031. ;/***************************************************************/
  1032. ;  n_upscroll
  1033. ;  Scroll up what we think is the current window, n lines
  1034. ;
  1035. ifdef Microsoft
  1036. _n_upscroll    proc    far
  1037. else
  1038. n_upscroll    proc    far
  1039. endif
  1040.     PUSH    BP
  1041.     MOV        BP,SP
  1042.  
  1043.     MOV        AL,[BP+X]            ; number of lines to scroll
  1044.     MOV        AH,6                ; scroll up function
  1045.     MOV        CH,TOPL                ; top row to clear
  1046.     MOV        CL,LEFTC            ; left column
  1047.     MOV        DH,BOTL                ; bottom row to clear
  1048.     MOV        DL,RIGHTC            ; RIGHT siDE TO CLEAR
  1049.     MOV        BH,ATT                ; attribute to use
  1050.     INT        10H                    ; cALl BIOS
  1051.  
  1052.     POP        BP
  1053.     RET
  1054. ifdef Microsoft
  1055. _n_upscroll    endp
  1056. else
  1057. n_upscroll    endp
  1058. endif
  1059.  
  1060. ;/***************************************************************/
  1061. ;  n_dnscroll
  1062. ;  Scroll up what we think is the current window, n lines
  1063. ;
  1064. ifdef Microsoft
  1065. _n_dnscroll    proc    far
  1066. else
  1067. n_dnscroll    proc    far
  1068. endif
  1069.     PUSH    BP
  1070.     MOV        BP,SP
  1071.  
  1072.     MOV        AL,[BP+X]            ; number of lines to scroll
  1073.     MOV        AH,7                ; scroll down function
  1074.     MOV        CH,TOPL                ; top row to clear
  1075.     MOV        CL,LEFTC            ; left column
  1076.     MOV        DH,BOTL                ; bottom row to clear
  1077.     MOV        DL,RIGHTC            ; right SIde to clear
  1078.     MOV     BH,ATT              ; attribute to use for blank lines
  1079.     INT        10h                    ; CalL bios
  1080.  
  1081.     POP        BP
  1082.     RET
  1083. ifdef Microsoft
  1084. _n_dnscroll    endp
  1085. else
  1086. n_dnscroll    endp
  1087. endif
  1088.  
  1089. ;/***************************************************************/
  1090. ;  n_putchar(letter)
  1091. ;     puts onto screen at current cursor location
  1092. ;
  1093. ifdef Microsoft
  1094. _n_putchar    proc    far
  1095. else
  1096. n_putchar    proc    far
  1097. endif
  1098.     PUSH     BP
  1099.     MOV        BP,SP
  1100.  
  1101.     MOV     AL,[BP+X]       ; char to write
  1102.     XOR     BX,BX           ;  set page number for ALl cursor addresses
  1103.     CMP      AL,10               ; line feed
  1104.     JNZ     NXT
  1105.     MOV     AL,ROW          ; get current cursor row poSItion
  1106.     CMP        AL,BOTL    
  1107.     JL      NOSCR           ; within window area
  1108.     MOV     AX,1            ; scroll up one line
  1109.     PUSH    AX
  1110. ifdef Microsoft
  1111.     CALL    _N_UPSCROLL     ; scrolls it up one
  1112. else
  1113.     CALL    N_UPSCROLL      ; scrolls it up one
  1114. endif
  1115.     POP     AX              ; take parameter off of stack
  1116. ;   MOV     AL,LEFTC        ; get left SIde vALue
  1117. ;   MOV     COL,AL          ; set cursor to left
  1118.     JMP        PUTCUR
  1119. NOSCR:
  1120. ;   MOV     AL,LEFTC        ; return cursor to left SIde
  1121. ;    MOV        COL,AL
  1122.     INC        ROW
  1123.     JMP     PUTCUR          ; set new cursor poSItion, return
  1124. NXT:
  1125.     CMP     AL,7            ; ctrl-G, bell
  1126.     JNZ      NXT2
  1127. ;
  1128. ;  handle bell with a cALl to a SPeciAL routine
  1129. ;
  1130.     MOV     AX,12           ; duration of tone
  1131.     PUSH    AX
  1132.     MOV        AX,1000              ; frequency of tone
  1133.     PUSH     AX
  1134. ifdef Microsoft
  1135.     CALL _N_SOUND
  1136. else
  1137.     CALL N_SOUND
  1138. endif
  1139.     ADD     SP,4            ; remove params from stack
  1140. HERE2:
  1141.     POP        BP
  1142.     RET
  1143. NXT2:
  1144.     CMP     AL,13           ; cr,  home the cursor
  1145.     JNZ        TRYTAB
  1146.     MOV     AL,LEFTC        ; new cursor poSItion
  1147.     MOV        COL,AL
  1148.     JMP        PUTCUR
  1149. TRYTAB:
  1150.     CMP     AL,9            ; tab character
  1151.     JNZ     NOTCRLF         ; ready for regular character
  1152. ;  expand tabs
  1153.     MOV     DL,COL          ; get cursor poSItion
  1154.     MOV        CL,3
  1155.     SHR     DL,CL           ; DIvide cursor poSItion by 8
  1156.     INC     DL              ; increment cursor poSItion
  1157.     SHL     DL,CL           ; multiply back by 8
  1158.     MOV        COL,DL
  1159.                             ; check to see if past right SIde
  1160.     MOV     DL,COL          ; get where the cursor has moved to
  1161.     CMP     DL,RIGHTC       ; over the SIde yet?
  1162.     JA      TABOVER         ; set the new poSItion
  1163.     JMP        PUTCUR
  1164. TABOVER:
  1165.     MOV        DL,LEFTC
  1166.     MOV        COL,DL
  1167.     INC     ROW             ; TO NEXT ROW
  1168.     MOV     DL,ROW          ; WHAT ROW?
  1169.     CMP        DL,BOTL
  1170.     JG      TABNOS          ; we are okay
  1171.     JMP     SHORT PUTCUR
  1172. TABNOS:
  1173.     DEC     ROW             ; need to scroll
  1174.     MOV        AX,1
  1175.     PUSH    AX
  1176. ifdef Microsoft
  1177.     CALL    _N_UPSCROLL     ; scroll window up one line
  1178. else
  1179.     CALL    N_UPSCROLL      ; scroll window up one line
  1180. endif
  1181.     POP        AX
  1182.     MOV     AL,LEFTC        ; reset cursor poSItion to left
  1183.     MOV        COL,AL
  1184.     JMP     SHORT PUTCUR
  1185. NOTCRLF:
  1186.     CMP     AL,8            ; backSPace
  1187.     JNZ     REGCHAR
  1188.     MOV     AL,COL          ; where is cursor?
  1189.     CMP     AL,LEFTC        ; is at left of screen?
  1190.     JZ        HERE2
  1191.     DEC     COL             ; decrement cursor poSItion
  1192.     JMP     SHORT PUTCUR    ; okay, move cursor where it belongs
  1193. REGCHAR:
  1194.     MOV     CX,1H           ; number of repetitions = 1
  1195.     MOV     BL,ATT          ; attribute of char
  1196.     MOV     BH,0            ; write to page zero
  1197.     MOV     AH,9            ; write char
  1198.     INT      10H
  1199.  
  1200.     INC     COL             ; move cursor over one.
  1201.     MOV     DL,COL          ; get current poSItion
  1202.     CMP     DL,RIGHTC       ; is at right SIde of screen?
  1203.     JLE     PUTCUR          ; no, char can just be put out, cursor moved.
  1204. ;
  1205. ;  check wORd-wrap because we are at edge of window
  1206. ;
  1207.     MOV        DL,WRAP
  1208.     OR      DL,DL           ; 0 = NO WRAP, 1 = WRAP
  1209.     JZ        NOWRAP
  1210.     MOV     DL,LEFTC        ; cursor will wrap around
  1211.     MOV     COL,DL          ; save the new column poSItion
  1212.     INC     ROW             ; to next row
  1213.     MOV        DL,BOTL
  1214.     CMP     ROW,DL          ; do we need to scroll?
  1215.     JNG     PUTCUR          ; no, okay for next row, normAL wrap
  1216. ; scroll screen up one 
  1217.     MOV        AX,1
  1218.     PUSH    AX
  1219. ifdef Microsoft
  1220.     CALL    _N_UPSCROLL     ; scroll window up one line
  1221. else
  1222.     CALL    N_UPSCROLL      ; scroll window up one line
  1223. endif
  1224.     POP        AX
  1225.     DEC     ROW             ; scrolled up one
  1226.     JMP     SHORT PUTCUR    ; don't wrap
  1227. NOWRAP:
  1228.     DEC        COL
  1229. PUTCUR:
  1230.     MOV        DH,ROW
  1231.     MOV        DL,COL
  1232.        MOV         AH,2h
  1233.        XOR     BX,BX
  1234.     INT     10H             ; set cursor poSItion
  1235.  
  1236. ESCAPEHERE:
  1237.     POP     BP
  1238.     RET
  1239. ifdef not_used
  1240. TELE:
  1241.     MOV     BL,3            ; SEND WHATEVER CHAR
  1242.     MOV        AH,14
  1243.     INT     10H
  1244.  
  1245.     POP        BP
  1246.     RET
  1247. endif
  1248. ifdef Microsoft
  1249. _n_putchar    endp
  1250. else
  1251. n_putchar    endp
  1252. endif
  1253.  
  1254. ifndef NET14
  1255. ;/**********************************************************************/
  1256. ;  draw
  1257. ;  place characters on the screen-- checking for bounDS, etc.  ALl done
  1258. ;  at a higher level.
  1259. ;
  1260. ;  n_draw(s,len)
  1261. ;    char*s ; INT len;
  1262. ;
  1263. ifdef Microsoft
  1264. _n_draw proc far
  1265. else
  1266. n_draw proc far
  1267. endif
  1268.     PUSH     BP
  1269.     MOV        BP,SP
  1270.     PUSH     ES
  1271.     PUSH    SI
  1272.     PUSH    DI
  1273. ;
  1274. ;  for now, assume that the cursor location has ALready been set
  1275. ;  (cursor is there)
  1276. ;
  1277.     LES        SI,[BP+X]            ; get the segment and offset of the string
  1278.     MOV        DI,[BP+X+4]            ; # OF CHARACTERS
  1279. ;    OR        DI,DI                ; check for no characters to draw
  1280. ;    JZ        ENDDRAW                ; exit if no characters to draw
  1281.     MOV     DH,ROW              ; row where cursor is
  1282. LOOPDRAW:
  1283.     MOV        AL,ES:[SI]            ; get character to write from es:SI
  1284.     INC        SI
  1285.     MOV         CX,1H                  ; number of repetitions = 1
  1286.     XOR      BH,BH                ; dispLAY PAGE 0
  1287.        MOV         BL,ATT                 ; attribute of char
  1288.     MOV         AH,9                   ; write char
  1289.        INT      10h
  1290.     INC        COL                    ; MOVE THE CURSor OVER
  1291.     MOV        DL,COL
  1292.        MOV         AH,2H
  1293.     XOR        BX,BX
  1294.     INT      10H                     ; SET CURSor POsiTION
  1295.     DEC     DI                    ; check counter
  1296.     JNZ     LOOPDRAW            ; GO THROUGH TO REQUIRED COUNT
  1297.  
  1298. ENDDRAW:
  1299.     POP        DI
  1300.     POP        SI
  1301.     POP     ES
  1302.     POP        BP
  1303.     RET
  1304. ifdef Microsoft
  1305. _n_draw endp
  1306. else
  1307. n_draw endp
  1308. endif
  1309.  
  1310. ;/**********************************************************************/
  1311. ;  cheat
  1312. ;  put characters on the screen as per n_draw, but write directly
  1313. ;  to display memory.  Don't even check for retrace
  1314. ;
  1315. ifdef Microsoft
  1316. _n_cheat proc    far
  1317. else
  1318. n_cheat proc    far
  1319. endif
  1320.     PUSH     BP
  1321.     MOV        BP,SP
  1322.     PUSH     ES
  1323.     PUSH     DS
  1324.     PUSH    SI
  1325.     PUSH    DI
  1326. ;
  1327. ;  for now, assume that the cursor location has already been set
  1328. ;  (cursor is there)
  1329. ;
  1330.     MOV     AX,video_segment
  1331.     MOV     ES,AX               ; set up for segment where screen is
  1332.  
  1333.     MOV        AL,ROW                ; row where chars go
  1334.     XOR        AH,AH
  1335.     MOV        BL,160
  1336.     MUL     BL                  ; ax now equals start of row
  1337.  
  1338.     XOR        BH,BH
  1339.     MOV        BL,COL
  1340.     SHL        BL,1                ; COL*2
  1341.     ADD        AX,BX                ; add in column offset
  1342.     MOV     DI,AX               ; store in di (es:di)
  1343.  
  1344.     MOV        CX,[BP+X+4]            ; # of characters
  1345. ;    OR        CX,CX                ; check whether we really have ANY characters
  1346. ;    JZ        ENDCHEAT            ; exit if we have no characters
  1347.     ADD     COL,CL              ; COLUMN POSITION OF CURSOR
  1348.     MOV     AH,ATT              ; ATTRIBUTE FOR CHARS
  1349.     LDS        SI,[BP+X]            ; get the segment and offset of the string
  1350. ;
  1351. ;  do the move
  1352. ;
  1353.     CLD
  1354. LPCHEAT:
  1355.     LODSB                        ; GET NEXT BYTE
  1356.     STOSW                        ; STorE BYTE AND ATTRIBUTE
  1357.     LOOP     LPCHEAT
  1358.  
  1359. ENDCHEAT:
  1360.     POP        DI
  1361.     POP        SI
  1362.     POP        DS
  1363.     POP        ES
  1364.     POP        BP
  1365.     RET
  1366. ifdef Microsoft
  1367. _n_cheat    endp
  1368. else
  1369. n_cheat    endp
  1370. endif
  1371. endif       ; NET14
  1372.  
  1373. ;/**********************************************************************/
  1374. ;
  1375. ;  New keyboard handling
  1376.  
  1377. ;    the interrupt and codes for the keyboard interface.
  1378.  
  1379. KEYBOARD    EQU    16H            ; interrupt 16 to deal with keyboard
  1380. GETC          EQU    0            ; code for reading a character
  1381. CHECKC        EQU    1            ; code for keyboard status
  1382. SHIFTSTAT    EQU    2            ; code for shift key status
  1383. SCAN        EQU    00100H        ; scan code
  1384. SHIFT        EQU    00200H        ; left or right shift key pressed
  1385. CONTROL        EQU    00400H        ; control key pressed
  1386. ALT            EQU    00800H        ; alt key pressed
  1387. ENHANCE        EQU    01000H        ; enhanced keyboard special key
  1388.  
  1389. ifndef NET14
  1390. ;**********************************************************************
  1391. ;
  1392. ;  Get a translated character from the keyboard.
  1393. ;
  1394. ;    Return the next character pressed with the new translation method for
  1395. ;        kermit compatibility.
  1396. ;    Quincey Koziol
  1397. ;
  1398. ;    Usage:
  1399. ;       unsigned int n_getchar(void);
  1400. ;
  1401. ifdef Microsoft
  1402. _n_getchar    proc    far
  1403. else
  1404. n_getchar    proc    far
  1405. endif
  1406.     PUSH      BP
  1407.  
  1408. ifdef Microsoft
  1409.     MOV     AH,_KEYBOARD_TYPE   ; ask for a keyboard character
  1410. else
  1411.     MOV     AH,KEYBOARD_TYPE   ; ask for a keyboard character
  1412. endif
  1413.     INT        KEYBOARD
  1414.     MOV        BX,AX                ; store the scan code character
  1415.     MOV        AH,SHIFTSTAT        ; get the shift keys' status
  1416.     INT        KEYBOARD            ; shift status returned in AX
  1417.     XOR        AH,AH                ; clear the top part of the shift status
  1418.     XOR        DX,DX                ; set local variables to zero
  1419.     XOR        CX,CX                ; 
  1420.     CMP        BH,0                ; check for enhanced key
  1421.     JE        NOT_ENHANCED1        ; jump around first enchanced key checks
  1422.     CMP        BH,0E0H                ; check for other part of enhanced key
  1423.     JNE        NOT_ENHANCED2
  1424.     XCHG    BH,BL                ; shift key from bios left 8 bits
  1425.     XOR        BL,BL                ; 
  1426.     OR        DX,ENHANCE            ; set the enhanced bit
  1427. NOT_ENHANCED2:
  1428.     CMP        BL,0E0H                ; check for second part of enhanced key
  1429.     JNE        NOT_ENHANCED1
  1430.     XOR        BL,BL                ; clear the character code from the bios key
  1431.     OR        DX,ENHANCE            ; set the enhanced bit
  1432. NOT_ENHANCED1:
  1433.     CMP        BL,0                ; check for not scan code only being zero
  1434.     JE        NOT_ALIAS            ; not one of the alias'ed keys from BIOS
  1435.     CMP        BX,(14*SCAN)+8        ; check for Backspace
  1436.     JE        ALIAS_KEY
  1437.     CMP        BX,(55*SCAN)+'*'    ; check for '*'
  1438.     JE        ALIAS_KEY
  1439.     CMP        BX,(74*SCAN)+'-'    ; check for '-'
  1440.     JE        ALIAS_KEY
  1441.     CMP        BX,(78*SCAN)+'+'    ; check for '+'
  1442.     JE        ALIAS_KEY
  1443.     CMP        BX,(71*SCAN)+'7'    ; check for '7'
  1444.     JE        ALIAS_KEY
  1445.     CMP        BX,(72*SCAN)+'8'    ; check for '8'
  1446.     JE        ALIAS_KEY
  1447.     CMP        BX,(73*SCAN)+'9'    ; check for '9'
  1448.     JE        ALIAS_KEY
  1449.     CMP        BX,(75*SCAN)+'4'    ; check for '4'
  1450.     JE        ALIAS_KEY
  1451.     CMP        BX,(76*SCAN)+'5'    ; check for '5'
  1452.     JE        ALIAS_KEY
  1453.     CMP        BX,(77*SCAN)+'6'    ; check for '6'
  1454.     JE        ALIAS_KEY
  1455.     CMP        BX,(79*SCAN)+'1'    ; check for '1'
  1456.     JE        ALIAS_KEY
  1457.     CMP        BX,(80*SCAN)+'2'    ; check for '2'
  1458.     JE        ALIAS_KEY
  1459.     CMP        BX,(81*SCAN)+'3'    ; check for '3'
  1460.     JE        ALIAS_KEY
  1461.     CMP        BX,(82*SCAN)+'0'    ; check for '0'
  1462.     JE        ALIAS_KEY
  1463.     CMP        BX,(83*SCAN)+'.'    ; check for '.'
  1464.     JE        ALIAS_KEY
  1465.     CMP        BX,(83*SCAN)+','    ; check for ','
  1466.     JE        ALIAS_KEY
  1467.     CMP        BX,(15*SCAN)+9        ; check for Tab
  1468.     JE        ALIAS_KEY
  1469.     JMP     SHORT NOT_ALIAS           ; key didn't match one of the alias'ed keys
  1470. ALIAS_KEY:
  1471.     XOR        BL,BL                ; clear ascii code for alias'ed keys
  1472. NOT_ALIAS:
  1473.     CMP        BL,0                ; no ascii value, get a kermit scan code
  1474.     JNE        REGULAR_KEY
  1475.     MOV        DL,BH                ; get the scancode
  1476.     OR        DX,SCAN                ; set the SCAN flag
  1477.     TEST    AX,3                ; check for shift key down
  1478.     JE        NOT_SHIFT            ; shift key not down
  1479.     OR        CX,SHIFT            ; set the SHIFT help flag
  1480. NOT_SHIFT:
  1481.     TEST    AL,20h                ; check for NumLock set
  1482.     JE        NOT_NUMLOCK            ; NumLock not down
  1483.     CMP        DX,71+SCAN            ; on numeric keypad?
  1484.     JB        NOT_NUMLOCK
  1485.     CMP        DX,83+SCAN
  1486.     JA        NOT_NUMLOCK
  1487.     CMP        DX,74+SCAN            ; not the grey - key
  1488.     JE        NOT_NUMLOCK
  1489.     CMP        DX,78+SCAN            ; not the grey + key
  1490.     JE        NOT_NUMLOCK
  1491.     XOR        CX,SHIFT            ; all true, xor the shift help
  1492. NOT_NUMLOCK:
  1493.     OR        DX,CX                ; set the correct shift status
  1494.     TEST    AL,4                ; check for the CONTROL key down
  1495.     JE        NOT_CONTROL
  1496.     OR        DX,CONTROL            ; set the control flag
  1497. NOT_CONTROL:
  1498.     TEST    AX,8                ; check for the ALT key down
  1499.     JE        NOT_ALT
  1500.     OR        DX,ALT                ; set the alt flag
  1501. NOT_ALT:
  1502.     MOV        AX,DX                ; set the return value
  1503.     JMP     SHORT END_NEWGETCHAR
  1504.     
  1505. REGULAR_KEY:                    ; we have an ascii value, return that
  1506.     XOR        BH,BH                ;
  1507.     MOV        AX,BX                ; return the key id
  1508.  
  1509. END_NEWGETCHAR:
  1510.     POP    BP
  1511.     RET
  1512. ifdef Microsoft
  1513. _n_getchar    endp
  1514. else
  1515. n_getchar    endp
  1516. endif
  1517.  
  1518. ;**********************************************************************
  1519. ;  Check for character present at the keyboard
  1520. ;  If there is one available, return it, if not, return -1
  1521. ;
  1522. ;  translate any extended characters
  1523. ;
  1524. ifdef Microsoft
  1525. _n_chkchar    proc    far
  1526. else
  1527. n_chkchar    proc    far
  1528. endif
  1529. ifdef Microsoft
  1530.     MOV        AH,_KEYBOARD_TYPE    ; get the correct BIOS setting for the keyboard
  1531. else
  1532.     MOV        AH,KEYBOARD_TYPE    ; get the correct BIOS setting for the keyboard
  1533. endif
  1534.     INC        AH                    ; increment for the setting to check the keyboard
  1535.     INT         KEYBOARD
  1536.     MOV        AX,-1
  1537.     JZ        NEW_NOKEY
  1538. ifdef Microsoft
  1539.     CALL    _N_GETCHAR            ;get the coded character
  1540. else
  1541.     CALL    N_GETCHAR            ;get the coded character
  1542. endif
  1543. NEW_NOKEY:
  1544.     RET
  1545. ifdef Microsoft
  1546. _n_chkchar    endp
  1547. else
  1548. n_chkchar    endp
  1549. endif
  1550. endif       ; NET14
  1551.  
  1552. ifdef NOT_USED
  1553. ;/***************************************************************/
  1554. ;  savewin
  1555. ;    copy the current window INTo a buffer
  1556. ;
  1557. ;   usage:  n_savewindow(buffer);
  1558. ;
  1559. ifdef Microsoft
  1560. _n_savewin    proc    far
  1561. else
  1562. n_savewin    proc    far
  1563. endif
  1564.     PUSH    BP
  1565.     MOV        BP,SP
  1566.     PUSH    ES
  1567.     PUSH    DS
  1568.     PUSH    SI
  1569.     PUSH    DI
  1570.  
  1571.     LES     DI,[BP+X]           ; pointer to buffer
  1572.     CLD
  1573. ;
  1574. ;  store parameters in first, for recall later
  1575. ;
  1576.     MOV     AL,ROW              ; cursor position: row,col
  1577.     STOSB
  1578.     MOV        AL,COL
  1579.     STOSB
  1580.     MOV        AL,TOPL                ; window boundaries
  1581.     STOSB
  1582.     MOV        AL,LEFTC
  1583.     STOSB
  1584.     MOV        AL,BOTL
  1585.     STOSB
  1586.     MOV        AL,RIGHTC
  1587.     STOSB                       ; STORE IN BUFFER TOO
  1588. ;
  1589. ;  calculate amount to move
  1590. ;
  1591. ;
  1592. ;  calculate number of lines to move
  1593. ;
  1594.     MOV     AL,TOPL         ; X1
  1595.     MOV     BL,BOTL         ; X2
  1596.     SUB     BL,AL           ; x2 = x2-x1
  1597.     INC     BL              ; ADD 1 LINE
  1598.     MOV     [BP+X],BL       ; KEEP IT SOMEWHERE SAFE
  1599. ;
  1600. ;  calculate screen offset  = 160*x1+2*y1;
  1601. ;
  1602. ;   al has topl in it
  1603.     XOR      AH,AH
  1604.     MOV         BL,160
  1605.     MUL     BL              ; how many chars in x1 lines, in AX
  1606.     XOR      CH,CH
  1607.     MOV     CL,LEFTC        ; chars to left SIde
  1608.     SHL     CL,1            ; *2 counts attributes
  1609.     ADD     AX,CX           ; add them
  1610.     MOV     SI,AX           ; place into source index
  1611. ;
  1612. ;  find number of characters to move each time
  1613. ;
  1614.     MOV         CL,RIGHTC
  1615.     SUB      CL,LEFTC               ; Y2 = Y2-Y1
  1616.     INC      CL                     ;  ADD 1
  1617.     MOV         [BP+X+1],CL            ; SAFE PLACE AGAIN
  1618. ;
  1619. ;  find number to add to wrap around for each line
  1620. ;
  1621.     MOV         BL,CL                  ; # OF CHARS MOVED EACH TIME
  1622.     SHL      BL,1                   ; CHARS*2
  1623.     MOV         AL,160
  1624.     SUB      AL,BL                  ; 160-chars*2
  1625.     MOV         [BP+X+2],AL            ; safe place to keep it
  1626. ;
  1627. ;
  1628.     MOV     AX,video_segment    ; where source segment is (screen)
  1629.     MOV         DS,AX
  1630.  
  1631.     MOV     DX,03dAH            ; color card status port
  1632.     XOR      BH,BH
  1633.     MOV         BL,[BP+X]           ; howmany lines to move
  1634.     CMP      AX,0B000H           ; CHECK For MONO CARD
  1635.     JNZ     GETLINE
  1636.     MOV     DX,03BAH            ; change status port vALue
  1637. GETLINE:
  1638.     MOV         CL,[BP+X+1]         ; # OF CHARS TO MOVE
  1639. GETCHAR:
  1640. ;   IN       AL,DX               ; GET STATUS BYTE
  1641.     TEST    AL,1                ; horizontal retrace
  1642. ;   JNZ      GETCHAR             ; not there yet
  1643. ;ISON:
  1644.     IN       AL,DX
  1645. ;   TEST     AL,1
  1646. ;   JZ       ISON                ; STILL ON, TRY AGAIN
  1647.     MOVSW                       ; NOW IS TIME, MOVE THE WORD
  1648.     LOOP     GETCHAR             ; DO ANOTHER UNTIL THIS LINE IS DONE
  1649. ;
  1650.     DEC     BX
  1651.     JZ      ENDKEEP             ; DONE, WE ARE OUT OF HERE
  1652.     MOV        AL,[BP+X+2]
  1653.     XOR        AH,AH
  1654.     ADD     SI,AX               
  1655. ; go to next line, skip 160-n*2 bytes
  1656.     JMP     GETLINE
  1657.  
  1658. ENDKEEP:
  1659.     POP        DI
  1660.     POP        SI
  1661.     POP      DS
  1662.     POP      ES
  1663.     POP      BP
  1664.     RET
  1665. ifdef Microsoft
  1666. _n_savewin    endp
  1667. else
  1668. n_savewin    endp
  1669. endif
  1670.  
  1671. ;/***************************************************************/
  1672. ;  restwindow
  1673. ;   restore the contents of the window to the screen
  1674. ;
  1675. ifdef Microsoft
  1676. _n_restwin    proc    far
  1677. else
  1678. n_restwin    proc    far
  1679. endif
  1680.     PUSH    BP
  1681.     MOV        BP,SP
  1682.     PUSH    ES
  1683.     PUSH    DS
  1684.     PUSH    SI
  1685.     PUSH    DI
  1686.  
  1687.     LES     SI,[BP+X]           ; POINTER TO BUFFER
  1688.     PUSH    ES                  ; Will pop to ds later
  1689.     CLD
  1690. ;
  1691. ;  get back stored variables
  1692. ;
  1693.     MOV     AL,ES:[SI]          ; get cursor row
  1694.     MOV        ROW,AL
  1695.     INC        SI
  1696.     MOV        AL,ES:[SI]
  1697.     MOV        COL,AL
  1698.     INC        SI
  1699.     MOV        AL,ES:[SI]            ; window boundaries
  1700.     MOV        TOPL,AL
  1701.     INC        SI
  1702.     MOV        AL,ES:[SI]
  1703.     MOV        LEFTC,AL
  1704.     INC        SI
  1705.     MOV        AL,ES:[SI]
  1706.     MOV        BOTL,AL
  1707.     INC        SI
  1708.     MOV        AL,ES:[SI]
  1709.     MOV        RIGHTC,AL
  1710.     INC     SI                  ; now we are ready for data
  1711. ;
  1712. ;  calculate amount to move
  1713. ;
  1714. ;
  1715. ;  calculate number of lines to move
  1716. ;
  1717.     MOV     AL,TOPL         ; X1
  1718.     MOV     BL,BOTL         ; X2
  1719.     SUB     BL,AL           ; x2 = x2-x1
  1720.     INC     BL              ; ADD 1 LINE
  1721.     MOV     [BP+X],BL       ; KEEP IT SOMEWHERE SAFE
  1722. ;
  1723. ;  calculate screen offset  = 160*x1+2*y1;
  1724. ;
  1725. ;   AL has topl in it
  1726.     XOR     AH,AH
  1727.     MOV        BL,160
  1728.     MUL     BL              ; HOW MANY CHARS IN X1 LINES, IN AX
  1729.     XOR     CH,CH
  1730.     MOV     CL,LEFTC        ; CHARS TO LEFT SIDE
  1731.     SHL     CL,1            ; *2 COUNTS ATTRIBUTES
  1732.     ADD     AX,CX           ; add them
  1733.     MOV     DI,AX           ; place into source index
  1734. ;
  1735. ;  find number of characters to move each time
  1736. ;
  1737.     MOV         CL,RIGHTC
  1738.     SUB     CL,LEFTC        ; Y2 = Y2-Y1
  1739.     INC      CL                  ;  add 1
  1740.     MOV     [BP+X+1],CL     ; safe place again
  1741. ;
  1742. ;  find number to add to wrap around for each line
  1743. ;
  1744.     MOV     BL,CL               ; # of chars moved each time
  1745.     SHL     BL,1            ; chars*2
  1746.     MOV     AL,160
  1747.     SUB     AL,BL               ; 160-chars*2
  1748.     MOV     [BP+X+2],AL         ; safe place to keep it
  1749. ;
  1750. ;
  1751. ifdef CHECK_FOR_REFRESH
  1752.     MOV     AX,video_segment; screen will receive this data
  1753.     MOV         ES,AX
  1754.     POP     DS              ; set ds to where data is coming from
  1755.     MOV     DX,03DAH        ; COLOR CARD STATUS PorT
  1756.     XOR      BH,BH
  1757.     MOV     BL,[BP+X]       ; howmany lines to move
  1758.     CMP     AX,0B000H       ; check for mono card
  1759.     JNZ     RGETLINE
  1760.     MOV     DX,03BAH        ; change status port vALue
  1761. RGETLINE:
  1762.     MOV     CL,[BP+X+1]     ; # of chars to move
  1763. RGETCHAR:
  1764.     IN      AL,DX           ; GET STATUS BYTE
  1765.     TEST    AL,1            ; horizontal retrace
  1766.     JNZ     RGETCHAR        ; NOT THERE YET
  1767. RISON:
  1768.     IN       AL,DX
  1769.     TEST     AL,1
  1770.     JZ      RISON           ; STILL ON, TRY AGAIN
  1771.     MOVSW                   ; NOW IS TIME, MOVE THE WORD
  1772.     LOOP    RGETCHAR        ; DO ANOTHER UNTIL THIS LINE IS DONE
  1773. else
  1774.     MOV     AX,video_segment; screen will receive this data
  1775.     MOV         ES,AX
  1776.     POP     DS              ; set ds to where data is coming from
  1777. ;   MOV     DX,03DAH        ; COLOR CARD STATUS PORT
  1778.     XOR      BH,BH
  1779.     MOV     BL,[BP+X]       ; howmany lines to move
  1780. ;   CMP     AX,0B000H       ; check for mono card
  1781. ;    JNZ     RGETLINE
  1782. ;   MOV     DX,03BAH        ; change status port vALue
  1783. RGETLINE:
  1784.     XOR        CH,CH
  1785.     MOV     CL,[BP+X+1]     ; # of chars to move
  1786. RGETCHAR:
  1787. ;   IN      AL,DX           ; GET STATUS BYTE
  1788. ;   TEST    AL,1            ; horizontal retrace
  1789. ;   JNZ     RGETCHAR        ; NOT THERE YET
  1790. ;RISON:
  1791. ;    IN       AL,DX
  1792. ;   TEST     AL,1
  1793. ;   JZ      RISON           ; STILL ON, TRY AGAIN
  1794. ;   MOVSW                   ; NOW IS TIME, MOVE THE WORD
  1795. ;   LOOP    RGETCHAR        ; DO ANOTHER UNTIL THIS LINE IS DONE
  1796.     REP     MOVSW           ; move all the words
  1797. endif
  1798. ;
  1799.     DEC     BX
  1800.     JZ      RENDKEEP        ; DONE, WE ARE OUT OF HERE
  1801.     MOV        AL,[BP+X+2]
  1802.     XOR        AH,AH
  1803.     ADD     DI,AX           ; go to next line, skip 160-n*2 bytes
  1804.     JMP     RGETLINE
  1805.  
  1806. RENDKEEP:
  1807.     POP        DI
  1808.     POP        SI
  1809.     POP      DS
  1810.     MOV     DH,ROW          ; LOAD STORED CURSOR POSITION
  1811.     MOV        DL,COL
  1812.        MOV         AH,2H
  1813.        XOR     BX,BX
  1814.     INT     10H             ; SET CURSOR POSITION TO SAVED VALUE
  1815.     POP     ES
  1816.     POP      BP
  1817.     RET
  1818. ifdef Microsoft
  1819. _n_restwin    endp
  1820. else
  1821. n_restwin    endp
  1822. endif
  1823. endif       ; NOT_USED
  1824.  
  1825. ;************************************************************************
  1826. ;  n_puts
  1827. ;  Window-compatible puts, uses n_putchar and ALso translates
  1828. ;  \n to CRLF
  1829. ;
  1830. ;    usage:  identical to puts()
  1831. ;
  1832. ifdef Microsoft
  1833. _n_puts    proc    far
  1834. else
  1835. n_puts    proc    far
  1836. endif
  1837.     PUSH    BP
  1838.     MOV        BP,SP
  1839.     PUSH    ES
  1840.     PUSH    DI
  1841.  
  1842. ;   MOV     DX,[BP+X+2]         ; ds OF STRING
  1843. ;   MOV     ES,DX
  1844. ;   MOV     BX,[BP+X]           ; PTR TO STRING
  1845.     LES     DI,[BP+X]           ; PTR TO STRING
  1846. NEXTC:
  1847. ;   MOV     AL,[BX]             ; GET CHARACTER
  1848.     MOV     AL,ES:[DI]          ; GET CHARACTER
  1849.     XOR     AH,AH               ; clear ah
  1850.  
  1851.     OR        AL,AL                ; is it end of string?
  1852.     JZ        DONEST
  1853. ;   INC     WORD PTR [BP+X]     ; INCREMENT POINTER FOR NEXT ONE
  1854.     INC     DI                  ; INCREMENT POINTER FOR NEXT ONE
  1855.     CMP        AL,10                ; newline?
  1856.     JNZ        DOCHAR
  1857.     MOV        AL,13
  1858.     PUSH    AX
  1859. ifdef Microsoft
  1860.     CALL    _N_PUTCHAR
  1861. else
  1862.     CALL    N_PUTCHAR
  1863. endif
  1864.     POP        AX
  1865.     MOV        AX,10
  1866. DOCHAR:
  1867.     PUSH    AX
  1868. ifdef Microsoft
  1869.     CALL    _N_PUTCHAR
  1870. else
  1871.     CALL    N_PUTCHAR
  1872. endif
  1873.     POP        AX                    ; take off of the stack
  1874.     JMP        NEXTC
  1875.  
  1876. DONEST:
  1877.     MOV        AX,13                ; CR
  1878.     PUSH    AX
  1879. ifdef Microsoft
  1880.     CALL    _N_PUTCHAR
  1881. else
  1882.     CALL    N_PUTCHAR
  1883. endif
  1884.     POP        AX
  1885.  
  1886.     MOV        AX,10                ; LF
  1887.     PUSH    AX
  1888. ifdef Microsoft
  1889.     CALL    _N_PUTCHAR
  1890. else
  1891.     CALL    N_PUTCHAR
  1892. endif
  1893.     POP        AX
  1894.  
  1895.     POP     DI
  1896.     POP     ES
  1897.     POP        BP
  1898.     RET
  1899. ifdef Microsoft
  1900. _n_puts    endp
  1901. else
  1902. n_puts    endp
  1903. endif
  1904.  
  1905. ifndef NET14
  1906. ;**********************************************************************
  1907. ;
  1908. ;  find first
  1909. ;   make dos find file names accorDIng to wildcards
  1910. ;  n_findfirst(filename,attr)
  1911. ;    char *filename; INT attr;
  1912. ;
  1913. ifdef Microsoft
  1914. _n_findfirst    proc    far
  1915. else
  1916. n_findfirst        proc    far
  1917. endif
  1918.     PUSH    BP
  1919.     MOV        BP,SP
  1920.     PUSH    ES
  1921.     PUSH    DS
  1922.  
  1923.     MOV     AH,02FH             ; DOS FUNCTION GET dta
  1924.     INT        21H
  1925. ifdef Microsoft
  1926.     MOV     _DTAPTR,BX          ; SQUIRREL A COPY FOR ME
  1927.     MOV        AX,ES
  1928.     MOV     _DTADS,AX
  1929. else
  1930.     MOV     DTAPTR,BX           ; SQUIRREL A COPY FOR ME
  1931.     MOV        AX,ES
  1932.     MOV        DTADS,AX
  1933. endif
  1934.     MOV     AX,[BP+X+2]         ; DS OF FILENAME PTR
  1935.     MOV        DS,AX
  1936.     MOV        DX,[BP+X]            ; PTR PART OF FILENAME
  1937.     MOV     CX,[BP+X+4]         ; ATTRIBUTE TO SEARCH FOR
  1938.     MOV     AH,04EH             ; FIND MATCHING FILE DOS CALL
  1939.     INT        21H
  1940.     JC      BADRET              ; AX ALREADY CONTAINS ERROR CODE
  1941.     XOR        AX,AX
  1942.  
  1943. BADRET:
  1944.     POP        DS
  1945.     POP        ES
  1946.     POP        BP
  1947.     RET
  1948. ifdef Microsoft
  1949. _n_findfirst    endp
  1950. else
  1951. n_findfirst    endp
  1952. endif
  1953. ;
  1954. ;  n_findnext()
  1955. ;  will find entries that follow findfirst
  1956. ;  no need to respecify file name
  1957. ;
  1958. ifdef Microsoft
  1959. _n_findnext    proc    far
  1960. else
  1961. n_findnext    proc    far
  1962. endif
  1963.  
  1964.     MOV     AH,04FH             ; FIND NEXT DOS CALL
  1965.     INT        21H
  1966.     JC        NBADRET
  1967.     XOR        AX,AX
  1968. NBADRET:
  1969.     RET
  1970. ifdef Microsoft
  1971. _n_findnext    endp
  1972. else
  1973. n_findnext    endp
  1974. endif
  1975. endif       ; NET14
  1976.  
  1977. ;
  1978. ;  get the number of timer clicks from BIOS
  1979. ;
  1980. ifdef Microsoft
  1981. _n_clicks  proc    far             ; must be declared long n_clicks()
  1982. else
  1983. n_clicks  proc    far             ; must be declared long n_clicks()
  1984. endif
  1985.     MOV        AH,0
  1986.     INT        1AH
  1987. ifdef Microsoft
  1988.     MOV     AX,DX               ; msc USES AX-LO, DX-HI
  1989.     MOV     DX,CX               ; return values from INTerrupt 1A
  1990. else
  1991.     MOV     AX,CX               ; Lattice uses AX-HI, BX-LO
  1992.     MOV        BX,DX                ; Lattice returns in BX, MSC in DX and switched
  1993. endif
  1994.  
  1995.     RET
  1996. ifdef Microsoft
  1997. _n_clicks endp
  1998. else
  1999. n_clicks endp
  2000. endif
  2001.  
  2002. ifndef NET14
  2003. ;
  2004. ;    void fix_vid(void)
  2005. ;
  2006. ifdef Microsoft
  2007. _fix_vid proc far
  2008. else
  2009. fix_vid proc far
  2010. endif
  2011.     push es
  2012.  
  2013.     mov ax,40h
  2014.     mov es,ax
  2015.     mov bx,10h
  2016.     mov al,es:[bx]        ; get equipment flags
  2017.     and al,0ch
  2018.     cmp al,0ch
  2019.     je done_vid_fix     ; if mono, we don't do anything
  2020.  
  2021.     mov bx,89h
  2022.     mov al,es:[bx]        ; get VDD flag byte
  2023.     and al,0fdh            ; Make sure bit 1 (gray scale summing enable)
  2024.                         ;   is UNSET
  2025.     mov es:[bx],al      ; put new flag byte in VDD
  2026.  
  2027.     mov ah,0fh
  2028.     int 10h             ; get current mode
  2029.     xor ah,ah
  2030.     int 10h             ; reset current mode (new flags take affect)
  2031.  
  2032. done_vid_fix:
  2033.     pop es
  2034.     ret
  2035. ifdef Microsoft
  2036. _fix_vid endp
  2037. else
  2038. fix_vid endp
  2039. endif
  2040.  
  2041. ifdef Microsoft
  2042. _get_mode proc far
  2043. else
  2044. get_mode proc far
  2045. endif
  2046.     push bp
  2047.     mov bp,sp
  2048.     push es
  2049.  
  2050.     les bx,dword ptr [bp+6]
  2051.  
  2052.     mov cx,7
  2053.     mov ax,1c01h
  2054.     int 10h
  2055.     mov ax,1c02h            ; immediately restore the state
  2056.     int 10h
  2057.  
  2058.     pop es
  2059.     pop bp
  2060.     ret
  2061.  
  2062. ifdef Microsoft
  2063. _get_mode endp
  2064. else
  2065. get_mode endp
  2066. endif
  2067.  
  2068.  
  2069. ifdef Microsoft
  2070. _set_mode proc far
  2071. else
  2072. set_mode proc far
  2073. endif
  2074.  
  2075.     push bp
  2076.     mov bp,sp
  2077.     push es
  2078.  
  2079.     les bx,dword ptr [bp+6]
  2080.  
  2081.     mov cx,7
  2082.     mov ax,1c02h
  2083.     int 10h
  2084.  
  2085.     pop es
  2086.     pop bp
  2087.     ret
  2088.  
  2089. ifdef Microsoft
  2090. _set_mode endp
  2091. else
  2092. set_mode endp
  2093. endif
  2094.  
  2095. ifdef Microsoft
  2096. _get_size proc far
  2097. else
  2098. get_size proc far
  2099. endif
  2100.  
  2101.     mov ax,1c00h
  2102.     mov cx,7
  2103.     int 10h
  2104.     mov ax,bx
  2105.  
  2106.     ret
  2107. ifdef Microsoft
  2108. _get_size endp
  2109. else
  2110. get_size endp
  2111. endif
  2112.  
  2113. ;************************************************************************
  2114. ;  set_page
  2115. ;
  2116. ;  Sets the video page
  2117. ;
  2118. ifdef Microsoft
  2119. _set_page proc far
  2120. else
  2121. set_page proc far
  2122. endif
  2123.     PUSH    BP
  2124.     MOV     BP,SP
  2125.  
  2126.     MOV     AL,[BP+X]           ; Get the page to switch to
  2127.     MOV     AH,05h
  2128.     INT     10h
  2129.  
  2130.     POP     BP
  2131.     RET
  2132. ifdef Microsoft
  2133. _set_page endp
  2134. else
  2135. set_page endp
  2136. endif
  2137.  
  2138. ;************************************************************************
  2139. ;  initvideo
  2140. ;
  2141. ;  Determines the active display adapter and various display parameters
  2142. ;
  2143. ifdef Microsoft
  2144. _initvideo  proc    far
  2145. else
  2146. initvideo   proc    far
  2147. endif
  2148.     PUSH    BP
  2149.     MOV        BP, SP
  2150.     PUSH    DS
  2151.     PUSH    ES
  2152.     PUSH     SI
  2153.     PUSH     DI
  2154.  
  2155.     MOV     AH,0FH          ; Read Video information
  2156.     INT     10H
  2157.     MOV     video_mode,AL   ; Video Display Mode
  2158.     MOV     video_page,BH   ; Video Display Page
  2159.     MOV     video_cols,AH   ; Number of Text Columns
  2160.     MOV     video_segment,MONO_SEG  ; Assume monochrome for now
  2161.     MOV     video_iscolor,0 ;
  2162.  
  2163.     INT     11H             ; Read Equipment list
  2164.     AND     AL,00110000b    ; Isolate Video bits
  2165.     CMP     AL,00110000b    ; Was it mono?
  2166.     JE      find_adapter    ; Yes
  2167.     MOV     video_segment,COLOR_SEG ; Else, set color display
  2168.     MOV     video_iscolor,1 ;
  2169. find_adapter:
  2170.     CALL    ps2_state       ; Read PS/2 video state
  2171.     JNZ     adapter_set     ; Done, if supported
  2172.     CALL    ega_state       ; Read EGA video state
  2173.     JNZ     adapter_set     ; Done, is supported
  2174.     CALL    cga_state       ; Determine CGA or mono
  2175. adapter_set:
  2176.     SUB     AX,AX           ; Adjust dsplay segment for current vide page
  2177.     MOV     ES,AX           ;
  2178.     MOV     AX,ES:[044EH]   ;
  2179.     MOV     CL,4
  2180.     SHR     AX,CL
  2181.     ADD     video_segment,AX
  2182.  
  2183.     MOV     AH,03H          ; get cursor pos'n & shape
  2184.     INT     10H             ;   ..
  2185.     MOV     video_cursor,CX ; save shape for later restore
  2186.  
  2187.     MOV     AX,1130H        ; get font information
  2188.     XOR     BH,BH           ; for current font
  2189.     INT     10H             ;   ..
  2190.     MOV     AX,1112H        ; assume we're using small font
  2191.     CMP     CX,8            ; using 8 * 8 font?
  2192.     JE      setfont         ; if yes, good
  2193.     MOV     AX,1114H        ; no. try for the 8 * 16 font
  2194.     CMP     CX,16           ;   ..
  2195.     JE      setfont         ;   ..
  2196.     MOV     AX,1111H        ; no. must be the 8 * 14 font
  2197. setfont:
  2198.     MOV     video_font,AX   ; save function code to restore this font
  2199.  
  2200.     POP     DI
  2201.     POP     SI
  2202.     POP     ES
  2203.     POP     DS
  2204.     POP     BP
  2205.     ret
  2206. ifdef Microsoft
  2207. _initvideo endp
  2208. else
  2209. initvideo endp
  2210. endif
  2211.  
  2212. ;************************************************************************
  2213. ;   ps2_state
  2214. ;
  2215. ;   This procedure attempts to access ps/2 compatible ROM BIOS video
  2216. ;   services.  The zero flag is set if they aren't supported
  2217. ;
  2218. ps2_state   proc    near
  2219.     MOV     AX,1A00H            ; Read PS/2 video state
  2220.     INT     10H
  2221.     CMP     AL,1AH              ; Was function supported?
  2222.     LAHF                        ; Toggle zero flag (zf=1 if al is not equal to 1ah)
  2223.     XOR     AH,01000000b        ;
  2224.     SAHF
  2225.     JZ      no_ps2              ; PS/2 BIOS not present
  2226.     MOV     video_type,BL       ; Save active display code
  2227.     MOV     AX,1130h            ; Read Font Code
  2228.     SUB     BH,BH               ; Font Code (not used)
  2229.     INT     10h                 ;
  2230.     INC     DL                  ; Adjust row count (clear zf)
  2231.     MOV     video_rows,DL       ;   and save
  2232. no_ps2:
  2233.     RET
  2234. ps2_state endp
  2235.  
  2236. ;************************************************************************
  2237. ;   ega_state
  2238. ;
  2239. ;   If PS/2 compatible ROM BIOS is not present, this procedure attempts
  2240. ;   to access the EGA ROM BIOS video services
  2241. ;
  2242. ega_state proc near
  2243.     MOV     AH,12H              ; Read EGA video state
  2244.     MOV     BL,10H
  2245.     INT     10H
  2246.     CMP     BL,10H              ; Was Function supported?
  2247.     JE      no_ega              ; No, EGA BIOS not present
  2248.     CMP     video_iscolor,BH    ; Is EGA the active display?
  2249.     JE      no_ega              ; No, find active display
  2250.     ADD     BH,4                ; Else, calculate display code
  2251.     MOV     video_type,BH       ;   and save
  2252.     MOV     AX,1130H            ; Read Font code
  2253.     SUB     BH,BH               ; Font Code (not used)
  2254.     INT     10H
  2255.     INC     DL                  ; Adjust row count (clear zf)
  2256.     MOV     video_rows,DL       ;   and save
  2257. no_ega:
  2258.     RET
  2259. ega_state endp
  2260.  
  2261. ;************************************************************************
  2262. ;   cga_state
  2263. ;
  2264. ;   If neither PS/2 compatible ROM BIOS nor EGA ROM BIOS is present,
  2265. ;   this procedure is called.  It simply assumes 25 text rows and sets
  2266. ;   video_type to MDA or CGA depending on the value of  video_iscolor
  2267. ;
  2268. cga_state proc near
  2269.     MOV     video_rows,25       ; If we get here, must be 25 rows
  2270.     MOV     video_type,01H      ; Assume MDA adapter for now
  2271.     CMP     video_iscolor,0     ; Is it mono?
  2272.     JE      no_cga              ; Yes
  2273.     MOV     video_type,02H      ; Else set CGA display adapter
  2274. no_cga:
  2275.     RET
  2276. cga_state endp
  2277.  
  2278. ;************************************************************************
  2279. ;   getvconfig
  2280. ;
  2281. ;   This routine fills a buffer with the current video parameter values.
  2282. ;   Note: initvideo() must be called first in order for this procedure
  2283. ;   to return meaningful values.
  2284. ;
  2285. ;   Usage:      void getvconfig(struct vidinfo *)
  2286. ;
  2287. ;   Where:  struct vidinfo {
  2288. ;               unsigned int segment;
  2289. ;               int type;
  2290. ;               int iscolor;
  2291. ;               int mode;
  2292. ;               unsigned int page;
  2293. ;               unsigned int rows;
  2294. ;               unsigned int columns;
  2295. ;               unsigned int cursor;
  2296. ;               unsigned int font_func;
  2297. ;           };
  2298. ;
  2299. ifdef Microsoft
  2300. _getvconfig proc    far
  2301. else
  2302. getvconfig  proc    far
  2303. endif
  2304.     PUSH    BP
  2305.     MOV     BP,SP
  2306.     PUSH    ES
  2307.     PUSH    DI
  2308.     PUSH    SI
  2309.  
  2310.     CLD                 ; All moves forward
  2311. IF @DataSize
  2312.     LES     DI,[BP+X]   ; Get the Pointer to the buffer
  2313. ELSE
  2314.     MOV     DI,[BP+X]   ; Get the Pointer to the buffer
  2315.     PUSH    DS
  2316.     POP     ES
  2317. ENDIF
  2318.  
  2319.     MOV     SI,OFFSET video_segment ; Get the offset of the start of the videio information
  2320.     MOVSW                   ; Copy the video segment
  2321.  
  2322.     MOV     CX,6            ; Copy six more word values
  2323.     XOR     AH,AH           ; Clear the top part of the transfer register
  2324. Copy_Loop:
  2325.     LODSB                   ; Move each byte from the video parameters
  2326.     STOSW                   ; Into a word in the structure
  2327.     LOOP    Copy_Loop
  2328.  
  2329.     MOVSW                   ; Copy the cursor
  2330.     MOVSW                   ; Copy the font function
  2331.  
  2332.     POP     SI
  2333.     POP     DI
  2334.     POP     ES
  2335.     POP     BP
  2336.     RET
  2337. ifdef Microsoft
  2338. _getvconfig endp
  2339. else
  2340. getvconfig  endp
  2341. endif
  2342.  
  2343. ;************************************************************************
  2344. ;   getvstate
  2345. ;
  2346. ;   This routine fills a buffer with the current video parameter values.
  2347. ;   This routine does not depend on initvideo() for anything.
  2348. ;
  2349. ;   Usage:      void getvstate(struct vidstate *)
  2350. ;
  2351. ;   Where:  struct vidstate {
  2352. ;               char mode;
  2353. ;               unsigned char page;
  2354. ;               unsigned int cursor;
  2355. ;               unsigned int curpos;
  2356. ;               unsigned int font_func;
  2357. ;           };
  2358. ;
  2359. ifdef Microsoft
  2360. _getvstate proc    far
  2361. else
  2362. getvstate  proc    far
  2363. endif
  2364.     PUSH    BP
  2365.     MOV     BP,SP
  2366.     PUSH    ES
  2367.     PUSH    DI
  2368.     PUSH    SI
  2369.  
  2370.     CLD                 ; All moves forward
  2371. IF @DataSize
  2372.     LES     DI,[BP+X]   ; Get the Pointer to the buffer
  2373. ELSE
  2374.     MOV     DI,[BP+X]   ; Get the Pointer to the buffer
  2375.     PUSH    DS
  2376.     POP     ES
  2377. ENDIF
  2378.  
  2379.     MOV   AH,0FH            ; get video mode
  2380.     INT   10H               ;   ..
  2381.     MOV   BYTE PTR ES:[DI],AL      ; save original mode
  2382.     MOV   BYTE PTR ES:[DI+1],BH    ; save original display page
  2383.     MOV   AH,03H            ; get cursor pos'n & shape
  2384.     INT   10H               ;   ..
  2385.     MOV   WORD PTR ES:[DI+2],CX     ; save shape for later restore
  2386.     MOV   WORD PTR ES:[DI+4],DX     ; save position for later restore
  2387.  
  2388.     MOV   AX,1130h          ; get font information
  2389.     XOR   BH,BH             ; for current font
  2390.     PUSH  ES                ; Preserve the ES from being blown away
  2391.     INT   10h               ;   ..
  2392.     POP   ES                ; Get the ES back
  2393.     MOV   AX,1112h          ; assume we're using small font
  2394.     CMP   CX,8              ; using 8 * 8 font?
  2395.     JE    setvfont           ; if yes, good
  2396.  
  2397.     MOV   AX,1114h          ; no. try for the 8 * 16 font
  2398.     CMP   CX,16             ;   ..
  2399.     JE    setvfont           ;   ..
  2400.  
  2401.     MOV   AX,1111h          ; no. must be the 8 * 14 font
  2402. setvfont:
  2403.     MOV   WORD PTR ES:[DI+6],AX ; save function code to restore this font
  2404.  
  2405.     POP     SI
  2406.     POP     DI
  2407.     POP     ES
  2408.     POP     BP
  2409.     RET
  2410. ifdef Microsoft
  2411. _getvstate endp
  2412. else
  2413. getvstate  endp
  2414. endif
  2415.  
  2416. ;************************************************************************
  2417. ;   setvstate
  2418. ;
  2419. ;   This routine takes variables from a video state structure and
  2420. ;       sets that video state
  2421. ;   This routine does not depend on initvideo() for anything.
  2422. ;
  2423. ;   Usage:      void setvstate(struct vidstate *)
  2424. ;
  2425. ;   Where:  struct vidstate {
  2426. ;               char mode;
  2427. ;               unsigned char page;
  2428. ;               unsigned int cursor;
  2429. ;               unsigned int font_func;
  2430. ;           };
  2431. ;
  2432. ifdef Microsoft
  2433. _setvstate proc    far
  2434. else
  2435. setvstate  proc    far
  2436. endif
  2437.     PUSH    BP
  2438.     MOV     BP,SP
  2439.     PUSH    ES
  2440.     PUSH    DI
  2441.  
  2442.     CLD                 ; All moves forward
  2443. IF @DataSize
  2444.     LES     DI,[BP+X]   ; Get the Pointer to the buffer
  2445. ELSE
  2446.     MOV     DI,[BP+X]   ; Get the Pointer to the buffer
  2447.     PUSH    DS
  2448.     POP     ES
  2449. ENDIF
  2450.  
  2451.     MOV     AL,BYTE PTR ES:[DI] ; set video mode
  2452.     XOR     AH,AH
  2453.     INT     10H                 ;  ..
  2454.  
  2455.     MOV     AX,0500h            ; Force display page 0
  2456.     INT     10h
  2457.  
  2458.     MOV     AX,WORD PTR ES:[DI+6]   ; Restore original font
  2459.     XOR     BL,BL               ; character block 0
  2460.     INT     10h
  2461.  
  2462.     MOV     AL,BYTE PTR ES:[DI+1]   ; Restore original display page
  2463.     MOV     AH,5
  2464.     INT     10h
  2465.  
  2466.     MOV     CX,WORD PTR ES:[DI+2]   ; Restore cursor shape
  2467.     MOV     AH,01h
  2468.     INT     10h
  2469.  
  2470.     MOV     AH,02                   ; Restore cursor position for the page
  2471.     MOV     BH,BYTE PTR ES:[DI+1]
  2472.     MOV     DX,WORD PTR ES:[DI+4]
  2473.     INT     10h
  2474.  
  2475.     POP     DI
  2476.     POP     ES
  2477.     POP     BP
  2478.     RET
  2479. ifdef Microsoft
  2480. _setvstate endp
  2481. else
  2482. setvstate  endp
  2483. endif
  2484.  
  2485. endif       ; NET14
  2486.  
  2487. ;-----------------------------------------------------------------
  2488.  
  2489. ifdef Microsoft
  2490. ;_TEXT   ENDS
  2491. else
  2492.     endps
  2493. endif
  2494.     end
  2495.