home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 5 / ctrom5b.zip / ctrom5b / PROGRAM / ASM / ALIB30B / SYS1.ASM < prev    next >
Assembly Source File  |  1994-11-28  |  19KB  |  787 lines

  1.     page    66,132
  2. ;******************************** SYS1.ASM   *********************************
  3.  
  4. LIBSEG           segment byte public "LIB"
  5.         assume cs:LIBSEG , ds:nothing
  6.  
  7. ;----------------------------------------------------------------------------
  8. .xlist
  9.     include  mac.inc
  10.     include  common.inc
  11. .list
  12. ;----------------------------------------------------------------------------
  13.     extrn    SETUP_MOUSE:far
  14.     extrn    HIDE_CURSOR:far
  15.     extrn    SHOW_CURSOR:far
  16.     extrn    BLINK_OFF:far
  17.     extrn    BLINK_ON:far
  18.     extrn    get_ansi_color:far
  19.     extrn    clear_screen:far
  20.     extrn    mem_open:far
  21.     extrn    mem_close:far
  22.     extrn    float_open:near
  23.     extrn    float_close:near
  24.     extrn    lib_info:byte
  25.     extrn    is_stdout_console:far
  26. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  27. ; LIBRARY_SETUP returns a pointer to the following structure.
  28. ;
  29. ;info    struc
  30. ; cpu_type    db    ?    ;0=88 1=186 2=286 3=386 4=486
  31. ; math_chip    db    ?    ;0=none 1=8087 2=287 3=387 4=487
  32. ; mouse_present    db    ?    ;0=no n=yes
  33. ; crt_type    db    ?    ;
  34. ; crt_mode    db    ?
  35. ; mono_flag    db    ?
  36. ; ansi_present    db    ?    ;0=no 1=yes
  37. ; users_color    db    ?
  38. ; crt_seg    dw    ?    ;segment of crt buffer
  39. ; crt_rows    db    ?    ;
  40. ; crt_columns    db    ?    ;
  41. ; key_type    db    ?    ;keyboard type 0=old style 1=enhanced
  42. ; psp_seg    dw    ?    ;psp segment
  43. ;info    ends
  44.  
  45. comment 
  46. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -( SYSTEM  )
  47. LIBRARY_SETUP - setup library for use
  48. ;
  49. ;  inputs:  ax = psp segment
  50. ;           bx = number of floating variables needed
  51. ;           
  52. ;  output:  es:si = pointer to library info structure
  53. ;         carry = error, library unusable
  54. ;
  55. ;      info    struc
  56. ;       cpu_type    db    ?    ;0=88 1=186 2=286 3=386 4=486
  57. ;       math_chip    db    ?    ;0=none 1=8087 2=287 3=387 4=487
  58. ;       mouse_present    db    ?    ;0=no n=yes
  59. ;       crt_type    db    ?    ;
  60. ;       crt_mode    db    ?
  61. ;       mono_flag    db    ?
  62. ;       ansi_present    db    ?    ;0=no 1=yes
  63. ;       users_color    db    ?
  64. ;       crt_seg    dw    ?    ;segment of crt buffer
  65. ;       crt_rows    db    ?    ;
  66. ;       crt_columns    db    ?    ;
  67. ;       key_type    db    ?    ;0=old style 1=enhanced
  68. ;       psp_seg    dw    ?
  69. ;      info    ends
  70. ;         
  71. ;* * * * * * * * * * * * * *
  72. 
  73. fvar_count    dw    0        ;number of floating variables needed
  74.  
  75.     public    LIBRARY_SETUP
  76. LIBRARY_SETUP    PROC    FAR
  77.     mov    lib_info.psp_seg,ax
  78.     mov    cs:fvar_count,bx
  79.         
  80.     call    FIND_CPU_TYPE
  81.     mov    lib_info.cpu_type,al
  82.  
  83.     call    MATH_HARDWARE
  84.     mov    lib_info.math_chip,al
  85.  
  86.     call    SETUP_MOUSE
  87.     jc    ls_disp
  88.     mov    lib_info.mouse_present,1
  89. ls_disp:
  90.     call    display_info
  91.     mov    lib_info.crt_type,al
  92.     mov    lib_info.crt_rows,bl
  93.     mov    lib_info.crt_columns,cl
  94.  
  95.     call    find_display_segment
  96.  
  97.     call    set_display_flags
  98.     mov    lib_info.mono_flag,al
  99.  
  100.     call    CHECK_ANSI
  101.     mov    lib_info.ansi_present,0
  102.     jc    ansi_end
  103.     mov    lib_info.ansi_present,1
  104. ansi_end:
  105. ;;      call      HIDE_CURSOR
  106.     call    BLINK_OFF
  107.     
  108.     cmp    lib_info.ansi_present,0
  109.     je    get_bios_color
  110.     call    get_ansi_color
  111.     mov    lib_info.users_color,ah
  112.     jmp    color_end
  113. get_bios_color:
  114.     mov    ah,08h
  115.     mov    bh,0            ;page 0
  116.     int    10h            ;read display
  117.     mov    lib_info.users_color,ah
  118. color_end:
  119.  
  120.     mov    ax,0500h        ;force display
  121.     int    10h            ;  page 0
  122.     
  123.     call    keyboard_setup        ;determine keyboard type
  124.     mov    lib_info.key_type,al    ;0=old style  1=enhanced
  125.     
  126.     call    mem_open        ;setup memory
  127. ;
  128. ; if mem_open returns an error or warning the carry is set and is returned
  129. ;
  130.     jc    ls_skip1        ;jmp if memory setup error
  131.     mov    bx,cs:fvar_count
  132.     call    float_open        ;sets carry if error
  133. ls_skip1:    
  134.     push    cs
  135.     pop    es
  136.     mov    si,offset lib_info
  137. ls_error:
  138.     cld                ;force direction flag
  139.     retf
  140.  
  141. LIBRARY_SETUP    ENDP
  142.  
  143. comment 
  144. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -( SYSTEM  )
  145. LIBRARY_TERMINATE - close out library for program exit
  146. ;
  147. ;  inputs:  ax = 0 clear screen at exit
  148. ;           ax = 1 do not clear screen
  149. ;           
  150. ;  output:  none
  151. ;* * * * * * * * * * * * * *
  152. 
  153.     public    library_terminate
  154. library_terminate    proc    far
  155.     cmp    ax,0
  156.     jne    lt_skip            ;skip clear screen if ax=n
  157.     mov    ax,0720h        ;clear_screen info
  158.     call    clear_screen
  159.     mov    dx,0            ;cursor position
  160.     jmp    lt_end
  161. lt_skip:mov    dx,1800h
  162.  
  163. lt_end:    call    SHOW_CURSOR        ;dx=cursor position to set
  164.     call    BLINK_ON
  165.     call    float_close
  166.     call    mem_close
  167.     retf
  168. library_terminate    endp
  169. ;
  170. comment 
  171. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -( SYSTEM  )
  172. FIND_CPU_TYPE - detects cpu type
  173. ;
  174. ; inputs:  none
  175. ; output:    AX = 0 if 8086/8088
  176. ;            AX = 1 if 80186/80188
  177. ;            AX = 2 if 80286
  178. ;            AX = 3 if 386 (SX or DX)
  179. ;            AX = 4 if 486 (SX or DX)
  180. ;* * * * * * * * * * * * * *
  181. 
  182.     public    FIND_CPU_TYPE
  183. FIND_CPU_TYPE    PROC    FAR
  184.      XOR     AX,AX
  185.      PUSH    AX
  186.      POPF
  187.      PUSHF
  188.      POP     AX
  189.      AND     AX,0F000h
  190.      CMP     AX,0F000h
  191.      JNZ     getcpu_2            ;jmp if not 8088,80188,8086,80186
  192.      PUSH    CX
  193.      MOV     AX,0FFFFh
  194.      MOV     CL,21h                ;286+ mask -cl- with 1fh
  195.      SHL     AX,CL
  196.      POP     CX
  197.      JNZ     getcpu_1            ;jmp if 80188 or 80186
  198. ;
  199. ; we have found an 8088 or 8086
  200. ;     
  201.      XOR     AX,AX
  202.      JMP     getcpu_exit
  203. ;
  204. ; we have found an 80188 or 80186
  205. ;     
  206. getcpu_1:
  207.      MOV     AX,0001
  208.      JMP     getcpu_exit
  209. ;
  210. ; we have a 286+ cpu, determine if this is 286
  211. ;     
  212. getcpu_2:
  213.      MOV     AX,7000h
  214.      PUSH    AX
  215.      POPF
  216.      PUSHF
  217.      POP     AX
  218.      AND     AX,7000h
  219.      JNZ     getcpu_3            ;jmp if not 80286
  220. ;
  221. ; we have found an 80286
  222. ;     
  223.      MOV     AX,0002
  224.      JMP     getcpu_exit
  225. ;
  226. ; we have found a 80386+ cpu, determine if 80386
  227. ;     
  228. getcpu_3:
  229.      PUSH    DX
  230.      MOV     DX,0003            ;preload code for 80386
  231.      DB        66H,50H            ;PUSH    EAX
  232.      DB        66H,53H            ;PUSH    EBX
  233.      DB        66H,51H            ;PUSH    ECX
  234.      DB        66H,8BH,0DCH        ;MOV     EBX,ESP
  235.      DB        66H,83H,0E4H,8CH    ;AND     ESP,-04
  236.      DB        66H,9CH            ;PUSHFD
  237.      DB        66H,58H            ;POP     EAX
  238.      DB        66H,8BH,0C8H        ;MOV     ECX,EAX
  239.      DB        66H,35H,00,00,04,00    ;XOR     EAX,00040000h
  240.      DB        66H,50H            ;PUSH    EAX
  241.      DB        66H,9DH            ;POPFD
  242.      DB        66H,9CH            ;PUSHFD
  243.      DB        66H,58H            ;POP     EAX
  244.      DB        66H,25H,00,00,04,00    ;AND     EAX,00040000h
  245.      DB        66H,81H,0E1H,0,0,04,00    ;AND     ECX,00040000h
  246.      DB        66H,3BH,0C1H        ;CMP     EAX,ECX
  247.      JZ      getcpu_4            ;jmp if 80386
  248. ;
  249. ; we have found an 80486
  250. ;     
  251.      MOV     DX,0004            ;preload 80486 code
  252. getcpu_4:
  253.      DB        66H,51H            ;PUSH    ECX
  254.      DB        66H,9DH            ;POPFD
  255.      DB        66H,8BH,0E3H        ;MOV     ESP,EBX
  256.      DB        66H,59H            ;POP     ECX
  257.      DB        66H,5BH            ;POP     EBX
  258.      DB        66H,58H            ;POP     EAX
  259.      MOV     AX,DX
  260.      POP     DX
  261. getcpu_exit:
  262.      RETF
  263. FIND_CPU_TYPE    ENDP
  264. comment 
  265. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -( SYSTEM  )
  266. MATH_HARDWARE - determines if 80x87 math coprocessor is installed
  267. ;
  268. ; inputs:    none
  269. ; output:    AX = code for 80x87 model
  270. ;            0 = not installed
  271. ;            1 = 8087
  272. ;            2 = 287
  273. ;            3 = 387 (DX or SX)
  274. ;            4 = 487 (486DX or 487SX)
  275. ;            If the coprocessor is present, it is initilaized by MATH_HARDWARE.
  276. ;            
  277. ;* * * * * * * * * * * * * *
  278. 
  279.     public    MATH_HARDWARE
  280. MATH_HARDWARE    PROC    FAR
  281.      XOR     AX,AX
  282.      PUSH    AX
  283.      POPF
  284.      PUSHF
  285.      POP     AX
  286.      AND     AX,0F000h
  287.      CMP     AX,0F000h
  288.      JZ      math_2
  289.      INT     11h
  290.      AND     AX,0002
  291.      JZ      math_exit1            ;jmp if no math chip
  292.      PUSH    BP
  293.      MOV     BP,SP
  294.      SUB     SP,+04
  295.      MOV     WORD PTR [BP-04],0000
  296.      MOV     WORD PTR [BP-02],7F80h
  297.      FLD     DWORD PTR [BP-04]
  298.      FLD     ST(0)
  299.      FCHS
  300.      FCOMPP
  301.      FSTSW   [BP-02]
  302.      MOV     AX,[BP-02]
  303.      MOV     SP,BP
  304.      POP     BP
  305.      SAHF
  306.      MOV     AX,0002            ;load code for 287
  307.      JZ      math_exit1            ;jmp if 287
  308.      CALL    FIND_CPU_TYPE
  309. math_exit1:
  310.      RETF
  311. math_2:
  312.      PUSH    BP
  313.      MOV     BP,SP
  314.      SUB     SP,+02
  315.      XOR     DX,DX
  316.      MOV     [BP-02],DX
  317.      FINIT
  318.      FSTCW   [BP-02]
  319.      PUSH    CX
  320. math_3:
  321.      MOV     CX,0003
  322.      LOOP    math_3
  323.      POP     CX
  324.      MOV     AX,[BP-02]
  325.      AND     AX,0300h
  326.      CMP     AX,0300h
  327.      JNZ     math_exit2        ;jmp if no math chip
  328.      INC     DX            ;set dx=1 (8087)
  329. math_exit2:
  330.      MOV     AX,DX
  331.      MOV     SP,BP
  332.      POP     BP
  333.      RETF
  334. MATH_HARDWARE    ENDP
  335. comment 
  336. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -( SYSTEM  )
  337. keyboard_setup - determine type of keyboard attached
  338. ;
  339. ; inputs: none
  340. ; output: al = 0(old style bios)  1(enhanced bios)
  341. ;* * * * * * * * * * * * * *
  342. 
  343.     public    keyboard_setup
  344. keyboard_setup    proc    far
  345.     push    es
  346.     mov    ax,0
  347.     mov    es,ax
  348.  
  349.     mov    ah,12h
  350.     int    16h            ;get extended bios shift status
  351.     cmp    al,byte ptr es:[417h]    ;check if memory copy correct
  352.     jne    ks_old            ;jmp if old style keyboard
  353.  
  354.     xor    byte ptr es:[417h],80h    ;toggle insert mode
  355.     mov    ah,12h
  356.     int    16h            ;get extended bios shift status
  357.     cmp    al,byte ptr es:[417h]    ;double check incase first check wrong
  358.     jne    ks_old            ;jmp if old style keyboard
  359.     mov    al,1
  360.     jmp    ks_exit            ;exit, extended keyboard status
  361. ks_old:    mov    al,0
  362. ks_exit:pop    es
  363.     retf    
  364. keyboard_setup    endp
  365. comment 
  366. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -( SYSTEM  )
  367. FIND_MOUSE - determines if a mouse is installed
  368. ;
  369. ; inputs:    none
  370. ; output:    AX = number of mouse buttons
  371. ;            AX = 0 if no mouse or mouse driver installed
  372. ;* * * * * * * * * * * * * *
  373. 
  374.     public    FIND_MOUSE
  375. FIND_MOUSE    PROC    FAR
  376.      push    bx
  377.      xor     ax,ax
  378.      or      al,cs:lib_info.mouse_present
  379.      JNZ     ism_exit
  380.      INT     33h
  381.      AND     AX,BX
  382.      MOV     cs:lib_info.mouse_present,al
  383. ism_exit:
  384.      POP     BX
  385.      RETF
  386. FIND_MOUSE    ENDP
  387. comment 
  388. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -( SYSTEM  )
  389. CHECK_ANSI - check if ANSI active
  390. ;
  391. ; inputs:    none
  392. ; output:    CF = 1 if no ANSI driver active
  393. ;            CF = 0 if ANSI active
  394. ;* * * * * * * * * * * * * *
  395. 
  396.     public    CHECK_ANSI
  397. CHECK_ANSI        PROC    FAR
  398.      APUSH   AX,DX,DS
  399.      call    is_stdout_console
  400.      test    al,al
  401.      jz      no_ansi1        ;jmp if output redirected (force no ansi)
  402.      MOV     AX,CS
  403.      MOV     DS,AX
  404.      CALL    console_input
  405.      CALL    CHECK_ANSI_cont1
  406.  
  407.      DB         1BH,'[6n$'
  408. ;
  409. CHECK_ANSI_cont1:
  410.      POP     DX
  411.      CALL    console_output
  412.      MOV     AH,0Bh        ;check STDIN status, al=ff if input
  413.      INT     21h
  414.      CMP     AL,0FFh
  415.      JZ      IA_1        ;jmp if char. is ready from ansi call
  416.      CALL    isansi_cont2
  417.  
  418.      db         0dH,'    ',0dH,'$'
  419.  
  420. isansi_cont2:
  421.      POP    DX
  422.      CALL    console_output
  423. no_ansi1:
  424.      STC
  425.      JMP     IA_2
  426. IA_1:
  427.      CALL    console_input
  428.      CLC
  429. IA_2:
  430.      APOP    DS,DX,AX
  431.      JB      NO_ANSI
  432.      CLC
  433.      RETF
  434. NO_ANSI:
  435.      STC
  436.      RETF
  437. CHECK_ANSI    ENDP
  438. ;------------------------------
  439. console_output:
  440.      MOV     AH,09
  441.      INT     21h
  442.      RET
  443.  
  444. console_input:
  445.      MOV     AH,06
  446.      MOV     DL,0FFh
  447.      INT     21h
  448.      JNZ     console_input
  449.      RET
  450.  
  451. comment 
  452. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -( SYSTEM  )
  453. DISPLAY_INFO - determine display information
  454. ;
  455. ; inputs:    none
  456. ;            
  457. ; output:    AL = screen rows
  458. ;            CH = screen columns
  459. ;            BX:[SI] = video buffer address
  460. ;            register DX is modified
  461. ;* * * * * * * * * * * * * *
  462. 
  463.     public    display_info
  464. display_info:
  465.     push    es
  466.     call    detectvid            ;get video type
  467.     cmp    ax,0
  468.     je    display_info_exit        ;exit if no display
  469. ;
  470. ; check for special case, dual display and alternate monochrome active
  471. ;
  472.     mov    bx,0
  473.     mov    es,bx
  474.     cmp    al,3                ;check if color display
  475.     jb    mono_port            ;jmp if mono
  476.     cmp    word ptr es:[463h],3d4h        ;verify color port active
  477.     je    port_ck_end            ;jmp if port ok
  478.     mov    ax,2                ;force monochrome display
  479.     jmp    port_ck_end
  480. mono_port:
  481.     cmp    word ptr es:[463h],3b4h        ;verify mono port active
  482.     je    port_ck_end
  483.     mov    ax,5                ;force cga color
  484. port_ck_end:
  485.     
  486.     push    ax
  487.     mov    ax,0500h
  488.     int    10h                ;force page 0
  489.  
  490.     mov    ax,0
  491.     mov    es,ax
  492.     mov    bh,es:[449h]            ;get display mode
  493.     pop    ax
  494.  
  495.     cmp    al,6
  496.     jbe    get_rows            ;jmp if mono or cga
  497.     cmp    al,9
  498.     je    get_rows            ;jmp if cga compatable
  499.  
  500.     push    ax
  501.     push    bx
  502.     mov    ax,1130h
  503.     mov    bh,0
  504.     push    es
  505.     int    10h
  506.     pop    es
  507.     pop    bx
  508.     pop    ax
  509.     mov    bl,dl                ;move rows to -bl-
  510.     jmp    rows_ok      
  511.  
  512. get_rows:
  513.     mov    bl,es:[484h]            ;get rows
  514.     cmp    bl,0
  515.     je    fix_rows            ;jmp if row info bad
  516.     cmp    bl,80
  517.     jb    rows_ok                ;jmp if row info found
  518. fix_rows:
  519.     mov    bl,24                ;force 25 lines on screen
  520. rows_ok:
  521.     inc    bl
  522. get_columns:
  523.     mov    cx,word ptr es:[44ah]        ;get columns on display
  524. display_info_exit:
  525.     pop    es
  526.     ret    
  527. comment 
  528. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -( SYSTEM  )
  529. DETECTVID -  determine display type
  530. ;
  531. ;  inputs: none
  532. ;  
  533. ;  outputs:  ax = 0  no display
  534. ;                 1  monochrome
  535. ;                 2  hercules 
  536. ;                 3  cga digital (mono)
  537. ;                 4  cga analog  (mono)
  538. ;                 5  cga analog (color)
  539. ;                 6  ega mono
  540. ;                 7  ega color 64k
  541. ;                 8  ega color 64k+
  542. ;                 9  cga compatable
  543. ;                10  vga mono
  544. ;                11  vga color 
  545. ;* * * * * * * * * * * * * *
  546. 
  547. vga_mono    equ    10
  548. vga_color    equ    11
  549. monochrome    equ    1
  550. hercules    equ    2
  551.  
  552.     public    detectvid
  553. detectvid:
  554.     mov ax,1a00h          ;used by mcga and vga
  555.     int 10h
  556.     cmp al,1ah            ;if al = 1ah then mcga or vga is present
  557.     jnz dt1
  558.     cmp bl,7              ;if active monitor is monochrome vga
  559.     jnz do1
  560.     mov ax,vga_mono       ;mono vga found
  561.     ret
  562. do1:
  563.     cmp bl,8              ;if active monitor is color vga
  564.     jnz do2
  565.     mov ax,vga_color      ;color vga found
  566.     ret
  567. do2:
  568.     cmp bl,0ah            ;if digital mcga
  569.     jnz do3
  570.     mov ax,3              ;digital mcga found
  571.     ret
  572. do3:
  573.     cmp bl,0bh            ;if monochrome mcga
  574.     jnz do4
  575.     mov ax,4              ;analog monochrome mcga found
  576.     ret
  577. do4:
  578.     cmp bl,0ch            ;if color mcga
  579.     jnz dt1
  580.     mov ax,5              ;analog color mcga found
  581.     ret
  582. dt1:
  583.     mov ah,12h            ;used by ega
  584.     mov bl,10h
  585.     int 10h
  586.     cmp bl,10h            ;if bl is not 10h then ega is present
  587.     jz dt2
  588.     cmp bh,1              ;if monochrome ega
  589.     jnz do5
  590.     mov ax,6              ;monochrome ega
  591.     ret
  592. do5:
  593.     or bl,bl              ;or 64k ega board
  594.     jnz do6
  595.     mov ax,7              ;color ega with 64k memory
  596.     ret
  597. do6:
  598.     mov ax,8              ;color ega with > 64k memory
  599.     ret
  600. dt2:
  601.     mov dx,3d4h           ;address for cga crtc
  602.     call find6845         ;look for controller
  603.     jnc dt3               ;if clear then cga present
  604.     mov dx,3b4h           ;address for hercules or mda
  605.     call find6845         ;look for controller
  606.     jnc dt4               ;jump if hercules or mda present
  607.     mov ax,0              ;unable to detect card
  608.     ret
  609. dt3:
  610.     mov ax,9              ;cga compatible present
  611.     ret
  612. dt4:
  613.     mov dl,0bah           ;read this port
  614.     in al,dx
  615.     and al,80h            ;get value in ah
  616.     mov ah,al
  617.     mov cx,8000h          ;loop this many times
  618. dt5:
  619.     in al,dx              ;read port
  620.     and al,80h
  621.     cmp ah,al             ;has value changed
  622.     loopz dt5
  623.     jcxz dt6              ;if cx = 0 then mda is present
  624.     mov ax,hercules       ;hercules card
  625.     ret
  626. dt6:
  627.     mov ax,monochrome     ;mda card
  628.     ret
  629. ;-------------------------------------------------------------------------
  630.     public    find6845
  631. find6845 proc near        ;find out if crtc is present
  632.     mov al,0fh            ;select reg ( cursor low )
  633.     out dx,al
  634.     inc dx
  635.     in al,dx              ;al = cursor low position
  636.     mov ah,al             ;save value in ah
  637.     mov al,66h            ;arbitrary value
  638.     out dx,al             ;write to crtc
  639.     mov cx,100h
  640. f61:
  641.     loop f61              ;wait for response
  642.     in al,dx
  643.     xchg ah,al            ;ah = returned value
  644.     out dx,al             ;reset port
  645.     cmp ah,66h            ;was value unchanged
  646.     je f62
  647.     stc                   ;if no response
  648. f62:
  649.     ret
  650. find6845 endp
  651.  
  652. comment 
  653. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -( SYSTEM  )
  654. FIND_DISPLAY_SEGMENT  -  scan for current display buffer segment
  655. ;
  656. ;  inputs:   display mode 3 or 7 must be set and display page must = 0
  657. ;  
  658. ;  output:   display_segment is set
  659. ;
  660. ;* * * * * * * * * * * * * *
  661. 
  662.     public    find_display_segment
  663. find_display_segment:
  664.     push    ax
  665.     push    bx
  666.     push    es
  667.     cli
  668.     mov    ax,0b000h        ;display seg?
  669.     mov    es,ax
  670.     mov    bx,es:[0]        ;save current data
  671.     mov    word ptr es:[0],0101h    ;store code 0101 at b000
  672.     mov    ax,0b800h        ;move to b800
  673.     mov    es,ax
  674.     mov    cx,es:[0]        ;save current data
  675.     mov    word ptr es:[0],0303h    ;store code 0303 at b800
  676.  
  677.     push    bx
  678.     push    cx
  679.  
  680.     mov    ah,3
  681.     mov    bh,0
  682.     int    10h            ;read cursor position -> dx
  683.     mov    cx,dx            ;save cursor posn
  684.  
  685.     mov    ah,2            ;move
  686.     mov    bh,0            ; cursor
  687.     mov    dx,0            ;   to page 0
  688.     int    10h            ;     top left
  689.  
  690.     mov    ah,8            ;read
  691.     mov    bh,0            ;  data
  692.     int    10h            ;    at cursor
  693. ;
  694. ; restore cursor position
  695. ;
  696.     push    ax            ;save data read
  697.     mov    dx,cx
  698.     mov    ah,2
  699.     int    10h
  700.     pop    ax            ;restore data read 
  701. ;
  702. ; restore origional display buffer data
  703. ;
  704.     pop    cx            ;  origional
  705.     pop    bx            ;   display contents
  706.     push    ax            ;save data read
  707.     mov    ax,0b000h
  708.     mov    es,ax
  709.     mov    word ptr es:[0],bx
  710.     mov    ax,0b800h
  711.     mov    es,ax
  712.     mov    word ptr es:[0],cx
  713. ;
  714. ; recover data read from display to determine segment location
  715. ;    
  716.     pop    ax
  717.     cmp    ax,0101h
  718.     je    use_b000
  719. use_b800:
  720.     mov    ax,0b800h
  721.     jmp    set_seg_cont
  722. use_b000:
  723.     mov    ax,0b000h
  724. set_seg_cont:
  725.     mov    lib_info.crt_seg,ax
  726.     sti
  727.     pop    es
  728.     pop    bx
  729.     pop    ax
  730.     ret
  731.  
  732. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  733. ; set_display_flags - determine cga snow flag and mono flag default settings
  734. ;  inputs: crt_info data stored in data base
  735. ;  output: al = mono flag (1=mono)
  736. ;          dx = snow flag (cga port if cga)
  737. ;
  738. set_display_flags:
  739.     sub    ax,ax
  740.     mov    es,ax
  741. ;
  742. ; get display mode
  743. ;
  744.     mov    al,byte ptr es:[449h]    ;get display mode
  745.     mov    lib_info.crt_mode,al    
  746. ;
  747. ; force display page zero
  748. ;
  749.     mov    ah,5
  750.     mov    al,0            ;page 0
  751.     int    10h    
  752. ;
  753. ; set cga flag
  754. ;
  755.     mov    al,lib_info.crt_type
  756.     cmp    al,3
  757.     jb    mono_display
  758.     cmp    al,5
  759.     jbe    cga_display
  760.     cmp    al,9
  761.     je    cga_display
  762. ;
  763. ; we must have a color display, it is not a cga or mono
  764. ;
  765.     mov    al,0
  766.     mov    dx,0
  767.     jmp    sdf_exit    
  768. ;
  769. mono_display:
  770.     mov    al,1
  771.     mov    dx,0
  772.     jmp    sdf_exit
  773.     
  774. cga_display:
  775.     mov    al,0
  776.     mov    dx,3dah
  777. sdf_exit:
  778.     ret
  779.  
  780. LIBSEG    ENDS
  781.     end
  782.