home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ddkx86v2.zip / DDKX86 / DBCSDD / SRC_DBCS / VDHV / VDHIOPL.ASM < prev    next >
Assembly Source File  |  1995-04-14  |  115KB  |  2,511 lines

  1. ;*DDK*************************************************************************/
  2. ;
  3. ; COPYRIGHT (C) Microsoft Corporation, 1989
  4. ; COPYRIGHT    Copyright (C) 1995 IBM Corporation
  5. ;
  6. ;    The following IBM OS/2 WARP source code is provided to you solely for
  7. ;    the purpose of assisting you in your development of OS/2 WARP device
  8. ;    drivers. You may use this code in accordance with the IBM License
  9. ;    Agreement provided in the IBM Device Driver Source Kit for OS/2. This
  10. ;    Copyright statement may not be removed.;
  11. ;*****************************************************************************/
  12.         PAGE    60,132
  13.         TITLE   VDHIOPL.ASM -- Video Device Handler Ring 2 Routines
  14. ;/*****************************************************************************
  15. ;*
  16. ;* SOURCE FILE NAME = VDHIOPL.asm
  17. ;*
  18. ;* DESCRIPTIVE NAME = Video device handler ring 2 routines
  19. ;*
  20. ;*
  21. ;* VERSION      V2.0
  22. ;*
  23. ;* DATE
  24. ;*
  25. ;* DESCRIPTION  This module contains routines that run at ring 2 in
  26. ;*              order to directly access the hardware ( via IN and OUT
  27. ;*              instructions ).
  28. ;*
  29. ;* FUNCTIONS    ACCESSBLINK
  30. ;*              ACCESSCLUT
  31. ;*              ACCESSCURSORPOS
  32. ;*              ACCESSCURSORTYPE
  33. ;*              ACCESSDISPLAYMASK
  34. ;*              ACCESSHARDWARE
  35. ;*              ACCESSOVERSCAN
  36. ;*              ACCESSREGISTER
  37. ;*              ACCESSUNDERSCORE
  38. ;*              ACCESSVIDEOENABLE
  39. ;*              CHARFONTEND
  40. ;*              GetMonitorID
  41. ;*              QUERY132
  42. ;*              SET132
  43. ;*              SETMAPMASK
  44. ;*              VGAWait
  45. ;*              _CharFontBegin
  46. ;*              _DPRINTF
  47. ;*              _HardwareColor
  48. ;*              _HardwareColumns
  49. ;*              _Query8514A
  50. ;*              _QueryXGA
  51. ;*              inchr
  52. ;*              putchar
  53. ;*
  54. ;* NOTES        NONE
  55. ;*
  56. ;* STRUCTURES   NONE
  57. ;*
  58. ;* EXTERNAL REFERENCES
  59. ;*
  60. ;*              NONE
  61. ;*
  62. ;* EXTERNAL FUNCTIONS
  63. ;*
  64. ;*              NONE
  65. ;*
  66. ;* CHANGE ACTIVIY =
  67. ;*   DATE      FLAG        APAR    CHANGE DESCRIPTION
  68. ;*   --------  ----------  -----   --------------------------------------
  69. ;*   mm/dd/yy  @Vr.mpppxx  xxxxx   xxxxxxx
  70. ;*   03/09/89  @D184       D184    STJ, Identify additional displays for 8514/A
  71. ;*   04/14/89  @S4         B701111 STJ, Remove negative logic,
  72. ;*   05/10/89  @C21        B701513 CJJ, Don't turn Video signal back on and reenable
  73. ;*             @C21                     reading of VideoEnable for VGA,
  74. ;*   06/29/89  @T39        B784056 TPL, Remove hardware dependencies in VDHINIT,
  75. ;*   07/31/89  @B705063    B705063 WKB, Decrease interrupt latency period as per spec
  76. ;*   08/08/89  @B19        B785016 WKB, Included OEM VGA enhancements, B785017 also.
  77. ;*   08/17/89  @S24        B706605 STJ, Restore undocumented 8514/A AI interfaces,
  78. ;*   09/11/89  @T47        B707464 TPL, Save/restore 3xBox (graphics) bit planes,
  79. ;*   09/13/89  @S28        B700010 STJ, Retain external clocking on VGA,
  80. ;*   09/14/89  @T49        B707543 TPL, Workaround for a 486 bug,
  81. ;*   10/25/89  @TL3        B708718 TPL, Setup bit mask register on restore,
  82. ;*   12/18/89  @tb25       AR05401 TLB, Don't do fixvgabug and sequencer enable unless
  83. ;*             @tb25                    in restore,
  84. ;*   04/03/90  @T57        B788756 TPL, Do not clear reserve bit when hidding cursor,
  85. ;*   06/08/90  @S28f       B789810 TPL, Do not preserve External Clock bit,
  86. ;*   06/14/90  @B72        B713826 WKB, Correct underscore problem from VioGetState,
  87. ;*   07/23/90  @T72        D1295   TPL, DCR 1295 - Support recognition of XGA device
  88. ;*   09/13/90  @D1085      D1085   WKB, DCR 1085 - Support 132 columns on appropriate h/w
  89. ;*   09/20/90  @B716255    B716255 TPL, Return XGA present for Kauai-HS
  90. ;*   10/17/90  @B717771    B717771 WKB, Reduce interrupt latency period,
  91. ;*   03/25/92  @DRW                     Skip sequencer 7 'fixups' for Tseng-based adapters
  92. ;*   09/28/93  J-TS0928    JS05992 TSO, Lapped cursor is not drawn correctly.
  93. ;*****************************************************************************/
  94.  
  95. .286p
  96.  
  97. ;
  98. ;+----------------------------------------------------------------------------+
  99. ;|  Include files                                                             |
  100. ;+----------------------------------------------------------------------------+
  101. ;
  102.         include struc.inc               ; Structured assembly macros
  103.         include vdh.inc                 ; Definitions
  104.         include vdhctl.inc
  105.         include vgaemu.inc              ; VGA text emulation video buffer
  106.  
  107. TSENG_ADAPTER   EQU     3               ;                               ;@DRW
  108.         extrn   _SVGAPresent:word       ; SVGA adapter type             ;@DRW
  109.  
  110. INSTSEG SEGMENT PARA PUBLIC 'DATA'
  111.         extrn   CursorOffset : word
  112.         extrn   CursorSel    : word
  113. INSTSEG ENDS
  114.  
  115. _DATA   SEGMENT WORD PUBLIC 'DATA'
  116.         extrn   VideoBuffSel    : word
  117.         extrn   HardwareScroll  : word                                  ;J-TS00
  118.         extrn   PrevLineComp    : word                                  ;J-TS00
  119.         extrn   MaxLineComp     : word                                  ;J-TS00
  120. _DATA   ENDS                                                            ;J-TS00
  121.  
  122. R2SEG   SEGMENT BYTE  PUBLIC  'CODE'
  123.         ASSUME  CS: R2SEG, DS: DGROUP
  124.  
  125.  
  126.         IFDEF   VDHVGA_OR_VDH8514A
  127.  
  128. ;/**********************  START OF SPECIFICATIONS  **********************/
  129. ;/*                                                                     */
  130. ;/*  SUBROUTINE NAME: Query8514A                                        */
  131. ;/*                                                                     */
  132. ;/*  DESCRIPTIVE NAME: Query 8514/A configuration                       */
  133. ;/*                                                                     */
  134. ;/*  FUNCTION: Verify presence of 8514/A adapter, query memory size,    */
  135. ;/*            and query display type.                                  */
  136. ;/*                                                                     */
  137. ;/*  ENTRY POINT: Query8514A                                            */
  138. ;/*    LINKAGE:   CALL FAR                                              */
  139. ;/*                                                                     */
  140. ;/*  INPUT: None                                                        */
  141. ;/*                                                                     */
  142. ;/*  EXIT-NORMAL: AL = display type  ( Color8514, Color8512_8513, etc)  */
  143. ;/*               AH = memory size ( 0 - 512k, 1 - 1MB )                */
  144. ;/*                                                                     */
  145. ;/*  EXIT-ERROR:  AX = VDHERROR_NO_ADAPTER                              */
  146. ;/*                                                                     */
  147. ;/*  INTERNAL REFERENCES:                                               */
  148. ;/*    ROUTINES: NONE                                                   */
  149. ;/*                                                                     */
  150. ;/*  EXTERNAL REFERENCES:                                               */
  151. ;/*    ROUTINES: NONE                                                   */
  152. ;/*                                                                     */
  153. ;/***********************  END OF SPECIFICATIONS  ***********************/
  154.         PUBLIC  _Query8514A
  155. _Query8514A PROC FAR
  156.  
  157.         mov     cx, VDHERROR_NO_ADAPTER ; Initialize cx = 8514/A not found
  158.  
  159.         mov     dx, 9AE9h               ; High byte of status reg ;D184
  160.         in      al, dx                  ; Read 8514 Queue Status Reg ;D184
  161.         test    al, 20h                 ;D184
  162.         .if     < z >                   ; Not busy
  163.             mov     dx, 92E8h
  164.             mov     ax, 5555h
  165.             out     dx, ax
  166.             in      ax, dx
  167.             .if     < ax eq 5555h >     ; 8514 found
  168.                 mov     dx, 42E8h
  169.                 in      al, dx          ; Get display info
  170.  
  171.                 mov     ah, al
  172.                 and     al, 70h
  173.                 .if     < al ne 70h >   ; Display attached to 8514/A
  174.                     .if     < al eq 10h > ;D184
  175.                         mov     cl, Mono8507_8604 ; 8514/A with 8507/8604 ;D184
  176.                     .endif              ;D184
  177.                     .if     < al eq 20h > ;D184
  178.                         mov     cl, Color8514 ; 8514/A with 8514
  179.                     .endif
  180.                     .if     < al eq 30h > ;D184
  181.                         mov     cl, Color8515 ; 8514/A with 8515 ;D184
  182.                     .endif              ;D184
  183.                     .if     < al eq 50h > ;D184
  184.                         mov     cl, Mono8503 ; 8514/A with 8503
  185.                     .endif
  186.                     .if     < al eq 60h >
  187.                         mov     cl, Color8512_8513 ; 8514/A with 8512/3
  188.                     .endif
  189.  
  190.                     test    ah, 80h     ; 512k or 1MB ?
  191.                     .if     < nz >
  192.                         mov     ch, MEM_1MB
  193.                     .endif
  194.                 .endif
  195.             .endif
  196.         .endif
  197.  
  198.         mov     ax, cx
  199.         ret
  200. _Query8514A ENDP
  201.  
  202.         ENDIF                           ; IFDEF VDHVGA_OR_VDH8514A
  203.  
  204.         IFDEF   VDH8514A                ;Start of @S24 changes
  205.  
  206. ;/**********************  START OF SPECIFICATIONS  **********************/
  207. ;/*                                                                     */
  208. ;/*  SUBROUTINE NAME: AccessDisplayMask                                 */
  209. ;/*                                                                     */
  210. ;/*  DESCRIPTIVE NAME: Set or read physical display mask                */
  211. ;/*                                                                     */
  212. ;/*  FUNCTION: AccessDisplayMask is called to query or set the physical */
  213. ;/*            display mask setting.                                    */
  214. ;/*                                                                     */
  215. ;/*  ENTRY POINT: AccessDisplayMask                                     */
  216. ;/*    LINKAGE:   CALL FAR                                              */
  217. ;/*                                                                     */
  218. ;/*  INPUT: (Passed on stack)                                           */
  219. ;/*             WORD  Direction ( GET or SET )                          */
  220. ;/*             DWORD DisplayMask ( far pointer to dword )              */
  221. ;/*                                                                     */
  222. ;/*  EXIT-NORMAL: Display mask is set or returned                       */
  223. ;/*                                                                     */
  224. ;/*  INTERNAL REFERENCES:                                               */
  225. ;/*    ROUTINES: NONE                                                   */
  226. ;/*                                                                     */
  227. ;/*  EXTERNAL REFERENCES:                                               */
  228. ;/*    ROUTINES: NONE                                                   */
  229. ;/*                                                                     */
  230. ;/***********************  END OF SPECIFICATIONS  ***********************/
  231.             PUBLIC  ACCESSDISPLAYMASK
  232. ACCESSDISPLAYMASK PROC FAR
  233.  
  234.             enter   2, 0                ; Allocate 1 word temporary storage
  235.             push    es
  236.             push    di
  237.  
  238.             les     di, ParameterPacket ; es:di = underscore scan line
  239.  
  240.             .if     < Direction eq SET >
  241.  
  242.                 mov     dx,02EAh        ; Set address
  243.                 mov     al,BYTE PTR es:[di].DisplayMask
  244.                 out     dx,al           ;Set the mask
  245.  
  246.             .else
  247.  
  248.                 sub     ax,ax
  249.                 mov     dx,02EAh        ; Set address
  250.                 in      al,dx           ;Get the mask
  251.                 mov     WORD PTR es:[di].DisplayMask,ax
  252.                 sub     ax,ax
  253.                 mov     WORD PTR es:[di].DisplayMask+2,ax
  254.  
  255.             .endif
  256.  
  257.             pop     di
  258.             pop     es
  259.             leave
  260.             ret     6
  261.  
  262. ACCESSDISPLAYMASK ENDP
  263.  
  264. ;/**********************  START OF SPECIFICATIONS  **********************/
  265. ;/*                                                                     */
  266. ;/*  SUBROUTINE NAME: AccessCLUT for 8514/A                             */
  267. ;/*                                                                     */
  268. ;/*  DESCRIPTIVE NAME: Set or read physical color lookup table          */
  269. ;/*                                                                     */
  270. ;/*  FUNCTION: AccessCLUT is called to query or set the physical        */
  271. ;/*            color lookup table.                                      */
  272. ;/*                                                                     */
  273. ;/*  ENTRY POINT: AccessCLUT                                            */
  274. ;/*    LINKAGE:   CALL FAR                                              */
  275. ;/*                                                                     */
  276. ;/*  INPUT: (Passed on stack)                                           */
  277. ;/*             WORD   Direction ( GET or SET )                         */
  278. ;/*             DWORD  ColorLookupTable  ( far pointer to structure )   */
  279. ;/*                      DWORD DataArea ( far pointer to table )        */
  280. ;/*                      WORD  FirstEntry                               */
  281. ;/*                      WORD  NumEntries                               */
  282. ;/*                                                                     */
  283. ;/*  EXIT-NORMAL: Color lookup table is altered or queried              */
  284. ;/*                                                                     */
  285. ;/*  INTERNAL REFERENCES:                                               */
  286. ;/*    ROUTINES: NONE                                                   */
  287. ;/*                                                                     */
  288. ;/*  EXTERNAL REFERENCES:                                               */
  289. ;/*    ROUTINES: NONE                                                   */
  290. ;/*                                                                     */
  291. ;/***********************  END OF SPECIFICATIONS  ***********************/
  292.  
  293. paldata     equ     02EDh               ;Palette data Register ;@S24
  294. paladdr     equ     02ECh               ;Palette Address Register ;@S24
  295. rpaladdr    equ     02EBh               ;Palette Address Register ;@S24
  296.  
  297.             PUBLIC  ACCESSCLUT
  298. ACCESSCLUT  PROC    FAR
  299.  
  300.             push    bp
  301.             mov     bp, sp
  302.             push    es
  303.             push    di
  304.  
  305.             les     di, ParameterPacket ; es:di = palette packet
  306.  
  307.             mov     cx,WORD PTR es:[di].NumEntries ; # of RBGx entries
  308.             mov     ax, WORD PTR es:[di].FirstEntry ; starting reg
  309.             les     di, DWORD PTR es:[di].DataArea
  310.             cld
  311.  
  312.             .if     < Direction eq SET >
  313.                 push    ds
  314.                 push    si
  315.                 mov     si,es
  316.                 mov     ds,si
  317.                 mov     si,di
  318.  
  319.                 .repeat
  320.                     mov     dx,paladdr  ;Palette address reg
  321.                     cli
  322.                     out     dx,al       ;Put out address
  323.                     mov     dx,paldata  ;Point to data reg for RGB triplet
  324.                     inc     ax          ;set next palette address
  325.                     push    ax
  326.                     lodsb
  327.                     shr     al,1
  328.                     shr     al,1        ;Reduce to hardware range
  329.                     out     DX,AL       ;Put out the red
  330.                     lodsb
  331.                     shr     al,1
  332.                     shr     al,1        ;Reduce to hardware range
  333.                     xchg    AH,AL       ;Blue is first in the definition
  334.                     lodsb
  335.                     shr     al,1
  336.                     shr     al,1        ;Reduce to hardware range
  337.                     out     DX,AL       ;Put out the green
  338.                     xchg    AH,AL       ;Get the blue back
  339.                     out     DX,AL       ;Put out the blue
  340.                     sti
  341.                     lodsb               ;Discard extra byte
  342.                     pop     ax
  343.                 .loop                   ;Go back for more
  344.  
  345.                 pop     si
  346.                 pop     ds
  347.             .else                       ;Read the color registers
  348.  
  349.                 .repeat
  350.                     mov     dx,rpaladdr ;Palette read address reg
  351.                     cli
  352.                     out     dx,al       ;Put out address
  353.                     mov     dx,paldata  ;Point to data reg for RGB triplet
  354.                     inc     ax          ;set next palette address
  355.                     push    ax          ;save palette address
  356.                     in      al,dx       ;do triplet - get RED
  357.                     shl     al,1        ;Align Data
  358.                     shl     al,1        ;Align Data
  359.                     stosb               ;save RED
  360.                     in      al,dx       ;- get GREEN
  361.                     shl     al,1        ;Align Data
  362.                     shl     al,1        ;Align Data
  363.                     xchg    ah,al       ;keep GREEN
  364.                     in      al,dx       ;- get BLUE
  365.                     sti
  366.                     shl     al,1        ;Align Data
  367.                     shl     al,1        ;Align Data
  368.                     stosb               ;save BLUE
  369.                     xchg    ah,al       ;restore GREEN
  370.                     stosb               ;save GREEN
  371.                     mov     al,0        ;Setup 4th byte
  372.                     stosb
  373.                     pop     ax          ;restore palette address
  374.                 .loop
  375.  
  376.             .endif
  377.  
  378.             pop     di
  379.             pop     es
  380.             pop     bp
  381.             ret     6
  382.  
  383. ACCESSCLUT  ENDP
  384.  
  385.         ELSE                            ; Not VDH8514A ;End of @S24 changes
  386.  
  387.             IFDEF   VDHVGA              ; Read/write hardware
  388.  
  389. ;/**********************  START OF SPECIFICATIONS  **********************/
  390. ;/*                                                                     */
  391. ;/*  SUBROUTINE NAME: _HardwareColumns                                  */
  392. ;/*                                                                     */
  393. ;/*  DESCRIPTIVE NAME: Get number of text columns in current mode       */
  394. ;/*                                                                     */
  395. ;/*  FUNCTION: _HardwareColumns is called by routines who need to know  */
  396. ;/*            whether the current mode has 40 or 80 character columns. */
  397. ;/*                                                                     */
  398. ;/*  ENTRY POINT: _HardwareColumns                                      */
  399. ;/*    LINKAGE:   CALL FAR                                              */
  400. ;/*                                                                     */
  401. ;/*  INPUT: NONE                                                        */
  402. ;/*                                                                     */
  403. ;/*  EXIT-NORMAL: AX = Number of character columns ( 40 or 80 )         */
  404. ;/*                                                                     */
  405. ;/*  INTERNAL REFERENCES:                                               */
  406. ;/*    ROUTINES: NONE                                                   */
  407. ;/*                                                                     */
  408. ;/*  EXTERNAL REFERENCES:                                               */
  409. ;/*    ROUTINES: NONE                                                   */
  410. ;/*                                                                     */
  411. ;/***********************  END OF SPECIFICATIONS  ***********************/
  412.                 PUBLIC  _HardwareColumns
  413. _HardwareColumns PROC   FAR
  414.  
  415. ;
  416. ;+----------------------------------------------------------------------------+
  417. ;|  Determine number of character columns by reading Sequencer register       |
  418. ;|  Dot Clock bit (b3) of Clocking Mode Register: 0 = 80 col, 1 = 40 col      |
  419. ;+----------------------------------------------------------------------------+
  420. ;
  421.                 mov     dx, SeqAddressPort ; Sequencer address register
  422.                 mov     al, IndClockModeReg ; Clocking Mode index
  423.                 cli
  424.                 out     dx, al
  425.  
  426.                 mov     dx, SeqDataPort ; Sequencer data register
  427.                 in      al, dx
  428.                 test    al, 8           ; Check Dot Clock bit
  429.                 .if     < z >
  430.                     mov     ax, 80      ; 80 column mode
  431.                 .else
  432.                     mov     ax, 40      ; 40 column mode
  433.                 .endif
  434.  
  435.                 sti
  436.                 ret
  437.  
  438. _HardwareColumns ENDP
  439.  
  440. ;/**********************  START OF SPECIFICATIONS  **********************/
  441. ;/*                                                                     */
  442. ;/*  SUBROUTINE NAME: _HardwareColor                                    */
  443. ;/*                                                                     */
  444. ;/*  DESCRIPTIVE NAME: Determine if current mode is color or monochrome */
  445. ;/*                                                                     */
  446. ;/*  FUNCTION: _HardwareColor is called by routines who need to know    */
  447. ;/*            whether the current mode is color or monochrome.         */
  448. ;/*                                                                     */
  449. ;/*  ENTRY POINT: _HardwareColor                                        */
  450. ;/*    LINKAGE:   CALL FAR                                              */
  451. ;/*                                                                     */
  452. ;/*  INPUT: NONE                                                        */
  453. ;/*                                                                     */
  454. ;/*  EXIT-NORMAL: AX = 1 - color, 0 - monochrome                        */
  455. ;/*                                                                     */
  456. ;/*  INTERNAL REFERENCES:                                               */
  457. ;/*    ROUTINES: NONE                                                   */
  458. ;/*                                                                     */
  459. ;/*  EXTERNAL REFERENCES:                                               */
  460. ;/*    ROUTINES: NONE                                                   */
  461. ;/*                                                                     */
  462. ;/***********************  END OF SPECIFICATIONS  ***********************/
  463.                 PUBLIC  _HardwareColor
  464. _HardwareColor  PROC    FAR
  465.  
  466. ;
  467. ;+----------------------------------------------------------------------------+
  468. ;|  Determine whether color or monochrome mode to determine which             |
  469. ;|  ports should be used.  This is done by checking the                       |
  470. ;|  I/O Address Select bit (b0) of the Miscellaneous Output Register:         |
  471. ;|      b0: 0 = Monochrome emulation mode, 1 = Color emulation mode           |
  472. ;+----------------------------------------------------------------------------+
  473. ;
  474.                 mov     dx, MiscOutputRegRead ; Read Miscellaneous Output Register
  475.                 in      al, dx
  476.                 and     ax, 1           ; Return 1 - color, 0 - monochrome
  477.  
  478.                 ret
  479.  
  480. _HardwareColor  ENDP
  481.  
  482.             ENDIF                       ; IFDEF VDHVGA
  483.  
  484.             IFDEF VDHEGA_OR_VDHVGA                                      ;@T72
  485.  
  486. ;/**********************  START OF SPECIFICATIONS  **********************/
  487. ;/*                                                                     */
  488. ;/*  SUBROUTINE NAME: SetMapMask                                        */
  489. ;/*                                                                     */
  490. ;/*  DESCRIPTIVE NAME: Address select a bit plane to read or write      */
  491. ;/*                                                                     */
  492. ;/*  FUNCTION: SetMapMask is called by SaveRestorePVB in order to address*/
  493. ;/*            a specific bit plane in graphics mode during a 3xBox     */
  494. ;/*            display buffer save or restore                           */
  495. ;/*                                                                     */
  496. ;/*  ENTRY POINT: SetMapMask                                            */
  497. ;/*    LINKAGE:   CALL FAR                                              */
  498. ;/*                                                                     */
  499. ;/*  INPUT: (Passed on stack)                                           */
  500. ;/*             WORD ReadMapMask  ( 0 - 3, 4 = write )                  */
  501. ;/*             WORD WriteMapMask ( 1, 2, 4, or 8 )                     */
  502. ;/*                                                                     */
  503. ;/*  EXIT-NORMAL: Bit plane selected for read or write                  */
  504. ;/*                                                                     */
  505. ;/*  INTERNAL REFERENCES:                                               */
  506. ;/*    ROUTINES: NONE                                                   */
  507. ;/*                                                                     */
  508. ;/*  EXTERNAL REFERENCES:                                               */
  509. ;/*    ROUTINES: NONE                                                   */
  510. ;/*                                                                     */
  511. ;/***********************  END OF SPECIFICATIONS  ***********************/
  512.             PUBLIC  SETMAPMASK
  513. SETMAPMASK  PROC    FAR
  514.  
  515. ; ENTRY: SS:SP = offset selector mask
  516.             push    bp
  517.             mov     bp, sp
  518.             push    dx
  519.             push    ax
  520.  
  521.             cli
  522.  
  523.             .if     < ReadMap eq 0 > or
  524.             .if     < MapMask eq 1 >
  525. ;
  526. ;+----------------------------------------------------------------------------+
  527. ;|  Set graphics mode register just for the first bit plane                   |
  528. ;+----------------------------------------------------------------------------+
  529. ;
  530.                 mov     dx, GraphAddressPort
  531.                 mov     ax, 0001h       ; Start from Set/Reset regs.    ;@T47
  532.                 .repeat                 ;                               ;@T47
  533.                     out     dx, al      ; Setup address port            ;@T47
  534.                     inc     dx          ; Index to data port            ;@T47
  535.                     inc     ax          ; Index to next address port    ;@T47
  536.                     xchg    al,ah       ;                               ;@T47
  537.                     out     dx,al       ; Clear Graphics register       ;@T47
  538.                     dec     dx          ; Back to address port          ;@T47
  539.                     xchg    al,ah       ;                               ;@T47
  540.                     cmp     al,6        ;                               ;@T47
  541.                 .until  <z>             ;                               ;@T47
  542.  
  543.                 .if     < MapMask eq 1 >; 1st write request?            ;@TL3
  544.                     mov     al,8        ;                               ;@TL3
  545.                     out     dx,al       ; Index to Bit Mask register    ;@TL3
  546.                     inc     dx          ;                               ;@TL3
  547.                     mov     al,0ffh     ;                               ;@TL3
  548.                     out     dx,al       ; Allow write to all bits       ;@TL3
  549.                 .endif                  ;                               ;@TL3
  550.             .endif                      ;                               ;@T47
  551.  
  552.             .if     < ReadMap ne WriteFunction >
  553. ;
  554. ;+----------------------------------------------------------------------------+
  555. ;|  Reading from display buffer, address select specified bit plane           |
  556. ;+----------------------------------------------------------------------------+
  557. ;
  558.                 mov     dx, SeqAddressPort
  559.                 mov     al, 02h         ; Memory map register in sequencer
  560.                 out     dx, al
  561.                 inc     dx
  562.                 mov     al, 0Fh
  563.                 out     dx, al          ; Memory map = 00001111
  564.  
  565. ;
  566. ;+----------------------------------------------------------------------------+
  567. ;|  Address select specified bit plane to read                                |
  568. ;+----------------------------------------------------------------------------+
  569. ;
  570.                 mov     dx, GraphAddressPort
  571.                 mov     al, 04h         ; Read map select register
  572.                 out     dx, al
  573.                 inc     dx
  574.                 mov     al, ReadMap
  575.                 out     dx, al          ; Read map select  = 0, 1, 2, 3
  576.             .else
  577. ;
  578. ;+----------------------------------------------------------------------------+
  579. ;|  Writing to display buffer, address select specified bit plane             |
  580. ;+----------------------------------------------------------------------------+
  581. ;
  582.                 mov     dx, SeqAddressPort
  583.                 mov     al, 02h         ; Memory map register in sequencer
  584.                 out     dx, al
  585.                 inc     dx
  586.                 mov     al, MapMask
  587.                 out     dx, al          ; Memory map
  588.             .endif
  589.  
  590.             sti
  591.  
  592.             pop     ax
  593.             pop     dx
  594.             pop     bp
  595.             ret     4                   ; Remove 2 words from stack
  596.  
  597. SETMAPMASK  ENDP
  598.  
  599.             ENDIF  ; VDHEGA_OR_VDHVGA                                   ;@T72
  600.  
  601. ;@T39       IFDEF  FONT_SUPPORT         ;@S4
  602.  
  603. ;/**********************  START OF SPECIFICATIONS  **********************/
  604. ;/*                                                                     */
  605. ;/*  SUBROUTINE NAME: _CharFontBegin                                    */
  606. ;/*                                                                     */
  607. ;/*  DESCRIPTIVE NAME: Address the font buffer                          */
  608. ;/*                                                                     */
  609. ;/*  FUNCTION: _CharFontBegin is called by routines in order to address */
  610. ;/*            the font buffer for writing or reading                   */
  611. ;/*                                                                     */
  612. ;/*  ENTRY POINT: _CharFontBegin                                        */
  613. ;/*    LINKAGE:   CALL FAR                                              */
  614. ;/*                                                                     */
  615. ;/*  INPUT: NONE                                                        */
  616. ;/*                                                                     */
  617. ;/*  EXIT-NORMAL: Font buffer is address selected at A0000              */
  618. ;/*                                                                     */
  619. ;/*  INTERNAL REFERENCES:                                               */
  620. ;/*    ROUTINES: NONE                                                   */
  621. ;/*                                                                     */
  622. ;/*  EXTERNAL REFERENCES:                                               */
  623. ;/*    ROUTINES: NONE                                                   */
  624. ;/*                                                                     */
  625. ;/***********************  END OF SPECIFICATIONS  ***********************/
  626.             PUBLIC  _CharFontBegin
  627. _CharFontBegin PROC FAR
  628.  
  629.             push    dx
  630.             mov     dx, GraphAddressPort
  631.             mov     ax, 0204h
  632.  
  633.             cli
  634.             out     dx, ax              ; Read Map Select register
  635.  
  636.             mov     ax, 0005h
  637.             out     dx, ax              ; Graphics Mode register
  638.  
  639.             mov     ax, 0406h
  640.             out     dx, ax              ; Graphics Misc register
  641.  
  642.             mov     dx, SeqAddressPort
  643.             mov     ax, 0402h           ; write font to bp only bit plane 0
  644.             out     dx, ax              ; Write Map Select
  645.  
  646.             mov     ax, 0404h
  647.             out     dx, ax              ; Turn on odd/even
  648.  
  649.             sti
  650.  
  651.             pop     dx
  652.             ret
  653.  
  654. _CharFontBegin ENDP
  655.  
  656. ;/**********************  START OF SPECIFICATIONS  **********************/
  657. ;/*                                                                     */
  658. ;/*  SUBROUTINE NAME:  CharFontEnd                                      */
  659. ;/*                                                                     */
  660. ;/*  DESCRIPTIVE NAME: Deselect font buffer                             */
  661. ;/*                                                                     */
  662. ;/*  FUNCTION:  CharFontEnd and  CharFontEnd2 are called following      */
  663. ;/*            completion of accessing the font buffer.                 */
  664. ;/*                                                                     */
  665. ;/*  ENTRY POINTS:  CharFontEnd,  CharFontEnd2                          */
  666. ;/*    LINKAGE:   CALL FAR                                              */
  667. ;/*                                                                     */
  668. ;/*  INPUT: NONE                                                        */
  669. ;/*                                                                     */
  670. ;/*  EXIT-NORMAL: font buffer address is deselected                     */
  671. ;/*                                                                     */
  672. ;/*  INTERNAL REFERENCES:                                               */
  673. ;/*    ROUTINES: NONE                                                   */
  674. ;/*                                                                     */
  675. ;/*  EXTERNAL REFERENCES:                                               */
  676. ;/*    ROUTINES: NONE                                                   */
  677. ;/*                                                                     */
  678. ;/***********************  END OF SPECIFICATIONS  ***********************/
  679.             PUBLIC  CHARFONTEND
  680. CHARFONTEND PROC    FAR
  681.             push    bp
  682.             mov     bp, sp
  683.             mov     cx, 0A06h           ; Setup mono buffer with chaining
  684.             .if     < ColorMonoMode eq COLOR_MODE >
  685.                 or      cx, 0400h       ; Setup color buffer
  686.             .endif
  687.             pop     bp
  688.  
  689.             PUBLIC  CHARFONTEND2
  690. CHARFONTEND2 LABEL  FAR
  691.  
  692.             push    ax
  693.  
  694.             mov     dx, GraphAddressPort
  695.             mov     ax, 0004h
  696.  
  697.             cli
  698.             out     dx, ax              ; Read Map Select register
  699.  
  700.             mov     ax, 1005h
  701.             out     dx, ax              ;Graphics Mode register
  702.  
  703.             mov     ax, cx
  704.             out     dx, ax              ;Graphics Misc register
  705.  
  706.  
  707.             mov     dx, SeqAddressPort
  708.             mov     ax, 0302h
  709.             out     dx, ax              ;Write Map Select
  710.  
  711.             mov     ax, 0004h
  712.             out     dx, ax              ;Turn off odd/even
  713.  
  714.             sti
  715.             pop     ax
  716.  
  717.             ret     2
  718.  
  719. CHARFONTEND ENDP
  720.  
  721. ;@T39       ENDIF  FONT_SUPPORT
  722.  
  723.  
  724.             IFDEF   BLINK_SUPPORT       ;@S4
  725.  
  726. ;/**********************  START OF SPECIFICATIONS  **********************/
  727. ;/*                                                                     */
  728. ;/*  SUBROUTINE NAME: AccessBlink                                       */
  729. ;/*                                                                     */
  730. ;/*  DESCRIPTIVE NAME: Set or read physical blink vs. BG intensity      */
  731. ;/*                                                                     */
  732. ;/*  FUNCTION: AccessBlink is called to query or set the physical       */
  733. ;/*            blink versus background intensity setting                */
  734. ;/*                                                                     */
  735. ;/*  ENTRY POINT: AccessBlink                                           */
  736. ;/*    LINKAGE:   CALL FAR                                              */
  737. ;/*                                                                     */
  738. ;/*  INPUT: (Passed on stack)                                           */
  739. ;/*             WORD  Direction ( GET or SET )                          */
  740. ;/*             DWORD Blink ( far pointer to word )                     */
  741. ;/*                                                                     */
  742. ;/*  EXIT-NORMAL: Blink vs. BG intensity is set or returned             */
  743. ;/*                                                                     */
  744. ;/*  INTERNAL REFERENCES:                                               */
  745. ;/*    ROUTINES: NONE                                                   */
  746. ;/*                                                                     */
  747. ;/*  EXTERNAL REFERENCES:                                               */
  748. ;/*    ROUTINES: NONE                                                   */
  749. ;/*                                                                     */
  750. ;/***********************  END OF SPECIFICATIONS  ***********************/
  751.                 PUBLIC  ACCESSBLINK
  752. ACCESSBLINK     PROC    FAR
  753.  
  754.                 push    bp
  755.                 mov     bp, sp
  756.                 push    es
  757.                 push    di
  758.  
  759.                 les     di, ParameterPacket ;es:di = Blink setting
  760. ;
  761. ;+----------------------------------------------------------------------------+
  762. ;|  Address Attribute Mode Control Register in Attribute Controller Registers |
  763. ;+----------------------------------------------------------------------------+
  764. ;
  765.                 @SetAttAddressPort      ; Attribute Address Register
  766.                 mov     al, IndAttModeCtl ; Address Attribute Mode Control Register
  767.                 out     dx, al          ; Set up for get mode ctl color
  768. ;
  769. ;+----------------------------------------------------------------------------+
  770. ;|  Set/Read Attribute Mode Control Register                                  |
  771. ;+----------------------------------------------------------------------------+
  772. ;
  773.                 mov     dx, AttDataReadPort ; Read current mode ctl setting
  774.  
  775.                 IFDEF   VDHVGA          ; Read/write hardware
  776.  
  777.                     in      al, dx      ; Read reserved bits
  778.  
  779.                 ELSE
  780.  
  781.                     xor     al, al      ; Zero reserved bits
  782.  
  783.                 ENDIF                   ; IFDEF VDHVGA
  784.  
  785.                 .if     < Direction eq SET >
  786.  
  787.                     and     al, 11110111B ; Select background intensity
  788.                     .if     < <WORD PTR es:[di].Blink> eq 0 >
  789.                         or      al, 00001000B ; Enable blink
  790.                     .endif
  791.  
  792.                     mov     dx, AttDataWritePort ; Set the hardware
  793.                     out     dx, al
  794.  
  795.                     IFDEF   VDHVGA      ; Read/write hardware
  796.  
  797.                     .else
  798.                         test    al, 00001000B ; Check setting
  799.                         .if     < z >
  800.                             mov     WORD PTR es:[di].Blink, 1 ; Report background intensity
  801.                         .else
  802.                             mov     WORD PTR es:[di].Blink, 0 ; Report blink enable
  803.                         .endif
  804.  
  805.                     ENDIF               ; IFDEF VDHVGA
  806.  
  807.                 .endif
  808.  
  809.                 @VideoOn
  810.  
  811.                 sti
  812.  
  813.                 pop     di
  814.                 pop     es
  815.                 pop     bp
  816.                 ret     8
  817.  
  818. ACCESSBLINK     ENDP
  819.  
  820.             ENDIF
  821.  
  822.             IFDEF   OVERSCAN_SUPPORT    ;@S4
  823.  
  824. ;/**********************  START OF SPECIFICATIONS  **********************/
  825. ;/*                                                                     */
  826. ;/*  SUBROUTINE NAME: AccessOverscan                                    */
  827. ;/*                                                                     */
  828. ;/*  DESCRIPTIVE NAME: Set or read physical border color                */
  829. ;/*                                                                     */
  830. ;/*  FUNCTION: AccessOverscan is called to query or set the physical    */
  831. ;/*            overscan color                                           */
  832. ;/*                                                                     */
  833. ;/*  ENTRY POINT: AccessOverscan                                        */
  834. ;/*    LINKAGE:   CALL FAR                                              */
  835. ;/*                                                                     */
  836. ;/*  INPUT: (Passed on stack)                                           */
  837. ;/*             WORD  Direction ( GET or SET )                          */
  838. ;/*             DWORD Overscan ( far pointer to word )                  */
  839. ;/*                                                                     */
  840. ;/*  EXIT-NORMAL: Overscan color is set or returned                     */
  841. ;/*                                                                     */
  842. ;/*  INTERNAL REFERENCES:                                               */
  843. ;/*    ROUTINES: NONE                                                   */
  844. ;/*                                                                     */
  845. ;/*  EXTERNAL REFERENCES:                                               */
  846. ;/*    ROUTINES: NONE                                                   */
  847. ;/*                                                                     */
  848. ;/***********************  END OF SPECIFICATIONS  ***********************/
  849.                 PUBLIC  ACCESSOVERSCAN
  850. ACCESSOVERSCAN  PROC    FAR
  851.  
  852.                 push    bp
  853.                 mov     bp, sp
  854.                 push    es
  855.                 push    di
  856.  
  857.                 les     di, ParameterPacket ; es:di = Overscan color
  858. ;
  859. ;+----------------------------------------------------------------------------+
  860. ;|  Address Overscan Color Register in Attribute Controller Registers         |
  861. ;+----------------------------------------------------------------------------+
  862. ;
  863.                 @SetAttAddressPort      ; Attribute Address Register
  864.                 mov     al, IndOverscanColor ; Address Overscan Color Register
  865.                 out     dx, al          ; Set up for get mode ctl color
  866. ;
  867. ;+----------------------------------------------------------------------------+
  868. ;|  Set/Read Overscan Color Register                                          |
  869. ;+----------------------------------------------------------------------------+
  870. ;
  871.                 .if     < Direction eq SET >
  872.  
  873.                     mov     al, BYTE PTR es:[di].Overscan
  874.  
  875.                     mov     dx, AttDataWritePort ; Set the hardware
  876.                     out     dx, al
  877.  
  878.                     IFDEF   VDHVGA      ; Read/write hardware
  879.  
  880.                     .else
  881.                         mov     dx, AttDataReadPort ; Read current setting
  882.                         in      al, dx
  883.  
  884.                      ;;;mov     BYTE PTR es:[di].Overscan, al           ;@B72
  885.                         xor     ah,ah                                   ;@B72
  886.                         mov     WORD PTR es:[di].Overscan, ax           ;@B72
  887.  
  888.                     ENDIF               ; IFDEF VDHVGA
  889.  
  890.                 .endif
  891.  
  892.                 @VideoOn
  893.  
  894.                 sti
  895.  
  896.                 pop     di
  897.                 pop     es
  898.                 pop     bp
  899.                 ret     8
  900.  
  901. ACCESSOVERSCAN  ENDP
  902.  
  903.             ENDIF
  904.  
  905.             IFDEF   UNDERSCORE_SUPPORT  ;@S4
  906.  
  907. ;/**********************  START OF SPECIFICATIONS  **********************/
  908. ;/*                                                                     */
  909. ;/*  SUBROUTINE NAME: AccessUnderscore                                  */
  910. ;/*                                                                     */
  911. ;/*  DESCRIPTIVE NAME: Set or read physical underscore scan line no.    */
  912. ;/*                                                                     */
  913. ;/*  FUNCTION: AccessUnderscore is called to query or set the physical  */
  914. ;/*            underscore scan line                                     */
  915. ;/*                                                                     */
  916. ;/*  ENTRY POINT: AccessUnderscore                                      */
  917. ;/*    LINKAGE:   CALL FAR                                              */
  918. ;/*                                                                     */
  919. ;/*  INPUT: (Passed on stack)                                           */
  920. ;/*             WORD  Direction ( GET or SET )                          */
  921. ;/*             DWORD Underscore ( far pointer to word )                */
  922. ;/*                                                                     */
  923. ;/*  EXIT-NORMAL: Underscore scan line is set or returned               */
  924. ;/*                                                                     */
  925. ;/*  INTERNAL REFERENCES:                                               */
  926. ;/*    ROUTINES: NONE                                                   */
  927. ;/*                                                                     */
  928. ;/*  EXTERNAL REFERENCES:                                               */
  929. ;/*    ROUTINES: NONE                                                   */
  930. ;/*                                                                     */
  931. ;/***********************  END OF SPECIFICATIONS  ***********************/
  932.                 PUBLIC  ACCESSUNDERSCORE
  933. ACCESSUNDERSCORE PROC   FAR
  934.  
  935.                 enter   2, 0            ; Allocate 1 word of temporary storage
  936.                 push    es
  937.                 push    di
  938.  
  939.                 les     di, ParameterPacket ; es:di = underscore scan line
  940.  
  941.                 .if     < ColorMode eq TRUE > ; Determine port address fixup
  942.                     mov     ColorMonoFixup, ColorAdjustment
  943.                 .else
  944.                     mov     ColorMonoFixup, MonoAdjustment
  945.                 .endif
  946.  
  947. ;
  948. ;+----------------------------------------------------------------------------+
  949. ;|  Address Underline Location Register in CRT Controller Registers           |
  950. ;+----------------------------------------------------------------------------+
  951. ;
  952.                 mov     dx, CRTCtlAddressReg ; CRT Controller Address Register
  953.                 add     dx, ColorMonoFixup ; Port address fixup
  954.                 mov     al, IndUnderlineLoc ; Address Underline Location Register
  955.                 cli
  956.                 out     dx, al
  957.  
  958. ;
  959. ;+----------------------------------------------------------------------------+
  960. ;|  Set/Read Underline Location Register                                      |
  961. ;+----------------------------------------------------------------------------+
  962. ;
  963.                 mov     dx, CRTCtlDataReg ; CRT Controller Data Register
  964.                 add     dx, ColorMonoFixup ; Port address fixup         ;@B72
  965.  
  966.                 IFDEF   VDHVGA          ; Read/write hardware
  967.  
  968.                     in      al, dx      ; Read reserved bits
  969.  
  970.                 ELSE
  971.  
  972.                     xor     al, al      ; Zero reserved bits
  973.  
  974.                 ENDIF                   ; IFDEF VDHVGA
  975.  
  976.                 .if     < Direction eq SET >
  977.  
  978.                     and     al, 11100000B ; Clear bits we will set
  979.  
  980.                     or      al, BYTE PTR es:[di].Underscore ; Set the hardware
  981.                     out     dx, al
  982.  
  983.                     IFDEF   VDHVGA      ; Read/write hardware
  984.  
  985.                     .else
  986.                         and     al, 00011111B ; Isolate underscore scan line
  987.                      ;;;mov     BYTE PTR es:[di].Underscore, al         ;@B72
  988.                         xor     ah,ah                                   ;@B72
  989.                         mov     WORD PTR es:[di].Underscore, ax         ;@B72
  990.  
  991.                     ENDIF               ; IFDEF VDHVGA
  992.  
  993.                 .endif
  994.  
  995.                 sti
  996.  
  997.                 pop     di
  998.                 pop     es
  999.                 leave                   ; Deallocate temporary storage
  1000.                 ret     8
  1001.  
  1002. ACCESSUNDERSCORE ENDP
  1003.  
  1004.             ENDIF
  1005.  
  1006. ;/**********************  START OF SPECIFICATIONS  **********************/
  1007. ;/*                                                                     */
  1008. ;/*  SUBROUTINE NAME: AccessVideoEnable                                 */
  1009. ;/*                                                                     */
  1010. ;/*  DESCRIPTIVE NAME: Set or read physical video enable                */
  1011. ;/*                                                                     */
  1012. ;/*  FUNCTION: AccessVideoEnable is called to query or set the physical */
  1013. ;/*            video enable setting.                                    */
  1014. ;/*                                                                     */
  1015. ;/*  ENTRY POINT: AccessVideoEnable                                     */
  1016. ;/*    LINKAGE:   CALL FAR                                              */
  1017. ;/*                                                                     */
  1018. ;/*  INPUT: (Passed on stack)                                           */
  1019. ;/*             WORD  Direction ( GET or SET )                          */
  1020. ;/*             DWORD VideoEnable ( far pointer to word )               */
  1021. ;/*                                                                     */
  1022. ;/*  EXIT-NORMAL: Video enable is set or returned                       */
  1023. ;/*                                                                     */
  1024. ;/*  INTERNAL REFERENCES:                                               */
  1025. ;/*    ROUTINES: NONE                                                   */
  1026. ;/*                                                                     */
  1027. ;/*  EXTERNAL REFERENCES:                                               */
  1028. ;/*    ROUTINES: NONE                                                   */
  1029. ;/*                                                                     */
  1030. ;/***********************  END OF SPECIFICATIONS  ***********************/
  1031.             PUBLIC  ACCESSVIDEOENABLE
  1032. ACCESSVIDEOENABLE PROC FAR
  1033.  
  1034.             push    bp
  1035.             mov     bp, sp
  1036.             push    es
  1037.             push    di
  1038.  
  1039.             les     di, ParameterPacket ; es:di = underscore scan line
  1040.  
  1041.             cli                         ; clear interrupts
  1042.  
  1043. ;IFDEF   VDHVGA                          ; Read/write hardware
  1044.  
  1045. ;        mov     dx, SeqAddressPort      ; Sequencer Address Register
  1046. ;        mov     al, IndClockModeReg     ; Clocking mode register
  1047. ;        out     dx, al
  1048.  
  1049. ;        mov     dx, SeqDataPort         ; Sequencer Data Register
  1050.  
  1051. ;        in      al, dx                  ; Read reserved bits
  1052.  
  1053. ;        .if     < Direction eq SET >
  1054.  
  1055. ;            and     al, 11011111B       ; Enable video
  1056.  
  1057. ;            .if     < <WORD PTR es:[di].VideoEnable> eq 0 >
  1058. ;                or      al, 00100000B   ; Disable video
  1059. ;            .endif
  1060.  
  1061. ;            out     dx, al              ; Set the hardware
  1062. ;        .else
  1063. ;            mov     WORD PTR es:[di].VideoEnable, 0 ; Preset Report Disable video
  1064. ;            test    al, 00100000B
  1065. ;            .if     < z >
  1066. ;                inc     WORD PTR es:[di].VideoEnable ; Set Report Enable video
  1067. ;            .endif
  1068. ;        .endif
  1069.  
  1070. ;ELSE
  1071.  
  1072.             IFDEF   VDHEGA_OR_VDHVGA
  1073.  
  1074.                 @SetAttAddressPort      ;Set the Attribute Address Port
  1075.  
  1076.                 IFDEF   VDHVGA          ;@C21
  1077.  
  1078.                     .if     < Direction eq GET > ;@C21
  1079.                         mov     dx,AttDataReadPort ;@C21
  1080.                         in      al,dx   ;@C21
  1081.                         mov     WORD PTR es:[di].VideoEnable, 0 ;Disabled  @C21
  1082.                         test    al, 20h ;@C21
  1083.                         .if     < nz >  ;@C21
  1084.                             inc     WORD PTR es:[di].VideoEnable ;Enabled   @C21
  1085.                         .endif          ;@C21
  1086.                     .else               ;@C21
  1087.  
  1088.                     ENDIF               ;@C21
  1089.  
  1090.                     sub     ax,ax       ;Preset Disable video
  1091.                     .if     < <WORD PTR es:[di].VideoEnable> ne ax >
  1092.                         mov     al, 20h ;Set Enable video
  1093.                     .endif
  1094.                     out     dx, al      ;Write to the port
  1095.  
  1096.                     IFDEF   VDHVGA      ;@C21
  1097.                     .endif              ;@C21
  1098.                 ENDIF                   ;@C21
  1099.  
  1100.             ENDIF                       ; IFDEF VDHEGA
  1101.  
  1102. ;ENDIF                                   ; IFDEF VDHVGA
  1103.  
  1104.             sti
  1105.             pop     di
  1106.             pop     es
  1107.             pop     bp
  1108.             ret     8
  1109.  
  1110. ACCESSVIDEOENABLE ENDP
  1111.  
  1112.             IFDEF   VDHVGA
  1113.  
  1114. ;/**********************  START OF SPECIFICATIONS  **********************/
  1115. ;/*                                                                     */
  1116. ;/*  SUBROUTINE NAME: AccessCLUT for VGA                        @S24    */
  1117. ;/*                                                                     */
  1118. ;/*  DESCRIPTIVE NAME: Set or read physical color lookup table          */
  1119. ;/*                                                                     */
  1120. ;/*  FUNCTION: AccessCLUT is called to query or set the physical        */
  1121. ;/*            color lookup table.                                      */
  1122. ;/*                                                                     */
  1123. ;/*  ENTRY POINT: AccessCLUT                                            */
  1124. ;/*    LINKAGE:   CALL FAR                                              */
  1125. ;/*                                                                     */
  1126. ;/*  INPUT: (Passed on stack)                                           */
  1127. ;/*             WORD   Direction ( GET or SET )                         */
  1128. ;/*             DWORD  ColorLookupTable  ( far pointer to structure )   */
  1129. ;/*                      DWORD DataArea ( far pointer to table )        */
  1130. ;/*                      WORD  FirstEntry                               */
  1131. ;/*                      WORD  NumEntries                               */
  1132. ;/*                                                                     */
  1133. ;/*  EXIT-NORMAL: Color lookup table is altered or queried              */
  1134. ;/*                                                                     */
  1135. ;/*  INTERNAL REFERENCES:                                               */
  1136. ;/*    ROUTINES: NONE                                                   */
  1137. ;/*                                                                     */
  1138. ;/*  EXTERNAL REFERENCES:                                               */
  1139. ;/*    ROUTINES: NONE                                                   */
  1140. ;/*                                                                     */
  1141. ;/***********************  END OF SPECIFICATIONS  ***********************/
  1142.  
  1143.                 PUBLIC  ACCESSCLUT
  1144. ACCESSCLUT      PROC    FAR
  1145.  
  1146.                 push    bp
  1147.                 mov     bp, sp
  1148.                 push    es
  1149.                 push    di
  1150.  
  1151.                 les     di, ParameterPacket ; es:di = palette packet
  1152.  
  1153.                 mov     cx,WORD PTR es:[di].NumEntries ; # of triplets  ;B705063
  1154.                 mov     ax, WORD PTR es:[di].FirstEntry ; starting reg  ;B705063
  1155.                 les     di, DWORD PTR es:[di].DataArea
  1156.  
  1157.                 .if     < Direction eq SET > ;B705063
  1158.                     mov     dx, PELAddressWrite ;B705063
  1159.                     cli                 ;B705063
  1160.                     out     dx, al      ;B705063
  1161.                     mov     dx, PELDataRegister ; Get data register ;B705063
  1162.                     .repeat             ;B705063
  1163.                         cli             ;B705063
  1164.                         mov     al, BYTE PTR es:[di] ;B705063
  1165.                         out     dx, al  ; Set register value ;B705063
  1166.                         inc     di      ;B705063
  1167.                         mov     al, BYTE PTR es:[di] ;B705063
  1168.                         out     dx, al  ; Set register value ;B705063
  1169.                         inc     di      ;B705063
  1170.                         mov     al, BYTE PTR es:[di] ;B705063
  1171.                         out     dx, al  ; Set register value ;B705063
  1172.                         sti             ;B705063
  1173.                         inc     di      ;B705063
  1174.                     .loop               ;B705063
  1175.                 .else                   ;B705063
  1176.                     cld                 ;B705063
  1177.                     mov     dx, PELAddressRead ;B705063
  1178.                     cli                 ;B705063
  1179.                     out     dx, al      ;B705063
  1180.                     mov     dx, PELDataRegister ; Get data register ;B705063
  1181.                     .repeat             ;B705063
  1182.                         cli             ;B705063
  1183.                         in      al, dx  ; Set register value ;B705063
  1184.                         and     al, 3Fh ; Isolate color ( 6 bits ) ;B705063
  1185.                         stosb           ;B705063
  1186.                         in      al, dx  ; Set register value ;B705063
  1187.                         and     al, 3Fh ; Isolate color ( 6 bits ) ;B705063
  1188.                         stosb           ;B705063
  1189.                         in      al, dx  ; Set register value ;B705063
  1190.                         sti             ;B705063
  1191.                         and     al, 3Fh ; Isolate color ( 6 bits ) ;B705063
  1192.                         stosb           ;B705063
  1193.                     .loop               ;B705063
  1194.                 .endif
  1195.  
  1196.                 pop     di
  1197.                 pop     es
  1198.                 pop     bp
  1199.                 ret     6
  1200.  
  1201. ACCESSCLUT      ENDP
  1202.  
  1203.             ENDIF
  1204.  
  1205. ;/**********************  START OF SPECIFICATIONS  **********************/
  1206. ;/*                                                                     */
  1207. ;/*  SUBROUTINE NAME: AccessHardware                                    */
  1208. ;/*                                                                     */
  1209. ;/*  DESCRIPTIVE NAME: Set or read physical indexed registers           */
  1210. ;/*                                                                     */
  1211. ;/*  FUNCTION: AccessHardware is called to query or set the physical    */
  1212. ;/*            indexed registers - Sequencers, Attributes, CRTs, or     */
  1213. ;/*            Graphics                                                 */
  1214. ;/*                                                                     */
  1215. ;/*  ENTRY POINT: AccessHardware                                        */
  1216. ;/*    LINKAGE:   CALL FAR                                              */
  1217. ;/*                                                                     */
  1218. ;/*  INPUT: (Passed on stack)                                           */
  1219. ;/*             DWORD  RegAddress ( far pointer to structure )          */
  1220. ;/*                       WORD RegAddressPort                           */
  1221. ;/*                       WORD RegDataPort                              */
  1222. ;/*                       WORD RegColorAdjust                           */
  1223. ;/*                       WORD RegFlags                                 */
  1224. ;/*             WORD   DataType ( BYTES or WORDS )                      */
  1225. ;/*             WORD   Direction ( GET or SET )                         */
  1226. ;/*             DWORD  RegData ( far pointer to structure )             */
  1227. ;/*                       DWORD DataArea  ( far pointer to data table ) */
  1228. ;/*                       WORD  FirstEntry                              */
  1229. ;/*                       WORD  NumEntries                              */
  1230. ;/*                                                                     */
  1231. ;/*  EXIT-NORMAL: Indexed registers are altered or queried              */
  1232. ;/*                                                                     */
  1233. ;/*  INTERNAL REFERENCES:                                               */
  1234. ;/*    ROUTINES: NONE                                                   */
  1235. ;/*                                                                     */
  1236. ;/*  EXTERNAL REFERENCES:                                               */
  1237. ;/*    ROUTINES: NONE                                                   */
  1238. ;/*                                                                     */
  1239. ;/***********************  END OF SPECIFICATIONS  ***********************/
  1240.             PUBLIC  ACCESSHARDWARE
  1241. ACCESSHARDWARE PROC FAR
  1242.  
  1243.             push    bp
  1244.             mov     bp, sp
  1245.             push    es
  1246.             push    di
  1247.             push    ds
  1248.             push    si
  1249.  
  1250.             les     di, ParameterPacket ; es:di = data packet
  1251.             lds     si, AddressPacket   ; ds:di = address packet
  1252.  
  1253.             mov     bx, WORD PTR  es:[di].FirstEntry ; Get starting reg
  1254.             mov     cx, WORD PTR  es:[di].NumEntries ; Get number of regs
  1255.             les     di, DWORD PTR es:[di].DataArea
  1256.  
  1257. ;B717771    cli
  1258.  
  1259.             .if     < ds:[si].RegFlags eq Attributes_CMD >
  1260. ;
  1261. ;+----------------------------------------------------------------------------+
  1262. ;|  To access the attribute address register, an 'in' must be issued to       |
  1263. ;|  the Attribute Controller at address 03BA for mono or 03DA for color.      |
  1264. ;+----------------------------------------------------------------------------+
  1265. ;
  1266.                 mov     dx, AttCtlInitializeReg ; Feature Control Register - init AttCtl flip-flop
  1267.                 .if     < ColorMode eq TRUE >
  1268.                     add     dx, ColorAdjustment
  1269.                 .endif
  1270.             .endif
  1271.  
  1272.             push    dx                  ;@B19
  1273.  
  1274. HARDWARE_REG:
  1275.             cli                         ;B717771
  1276.             .if     < ds:[si].RegFlags eq Attributes_CMD >
  1277.                 pop     dx              ;@B19
  1278.                 in      al, dx          ; Read port to reset flip-flop
  1279.                 push    dx              ;@B19
  1280.             .endif
  1281.  
  1282. ;@B19       push    dx                  ; Save reset flip-flop port
  1283.  
  1284.             mov     dx, ds:[si].RegAddressPort ; Address Register
  1285.             .if     < ColorMode eq TRUE >
  1286.                 add     dx, ds:[si].RegColorAdjust
  1287.             .endif
  1288.             mov     al, bl              ; Address Palette Reg ( 00 - 0F )
  1289.  
  1290. ;MJS P VGA                                                      ;@B19
  1291. IFDEF       VDHVGA                      ;@B19
  1292.                                         ; wait for vertical retrace to avoid glitching VRAM ;@B19
  1293.             .if     <al EQ 10h> AND     ;@B19
  1294.             .if     <dx EQ AttAddressPort> ;@B19
  1295.                 call    VGAWait         ;@B19
  1296.             .endif                      ;@B19
  1297. ENDIF                                   ;@B19
  1298. ;MJS P VGA                                                      ;@B19
  1299.  
  1300.             out     dx, al              ; Set up for get palette reg
  1301.  
  1302.             mov     dx, ds:[si].RegDataPort ; Address Register
  1303.             .if     < ColorMode eq TRUE >
  1304.                 add     dx, ds:[si].RegColorAdjust
  1305.             .endif
  1306.  
  1307.             .if     < Direction eq SET >
  1308.                 mov     al, BYTE PTR es:[di]
  1309.                 out     dx, al
  1310.             .else
  1311.  
  1312.                 IFDEF   VDHVGA          ; Read/write hardware
  1313.  
  1314.                     in      al, dx
  1315.                     .if     < WordByte eq WORDS >
  1316.                         xor     ah, ah
  1317.                         mov     WORD PTR es:[di], ax
  1318.                     .else
  1319.                         mov     BYTE PTR es:[di], al
  1320.                     .endif
  1321.  
  1322.                 ENDIF                   ; IFDEF VDHVGA
  1323.  
  1324.             .endif
  1325.  
  1326.             inc     bx
  1327.             .if     < WordByte eq WORDS >
  1328.                 inc     di              ; Point to next byte
  1329.             .endif
  1330.             inc     di                  ; Point to next byte
  1331.  
  1332. ;@B19       pop     dx                  ; Retrieve reset flip-flop port
  1333.             sti                         ;B717771
  1334.             loop    HARDWARE_REG
  1335.  
  1336.  
  1337.             pop     dx                  ;@B19
  1338.  
  1339.             cli                         ;B717771
  1340.  
  1341.             .if     < ds:[si].RegFlags eq Sequencers_CMD > AND  ; @tb25
  1342.             .if     < Direction eq SET >                        ; @tb25
  1343.  
  1344. ;J-TS00 IF VDHVGA AND (1 - VDHINIT)                                             ;@DRW
  1345.             push    ds                                                  ;@DRW
  1346.             mov     ax, seg _SVGAPresent
  1347.             mov     ds, ax
  1348.             cmp     _SVGAPresent, TSENG_ADAPTER                         ;@DRW
  1349.             pop     ds                                                  ;@DRW
  1350.             je      @F                                                  ;@DRW
  1351.             @FixVGABug
  1352. @@:
  1353. ;J-TS00 ENDIF   ;VDHVGA                                                         ;MS00
  1354.  
  1355.                 mov     dx, SeqAddressPort ; Sequencer address port
  1356.                 mov     al, 0           ; Reset register index
  1357.                 out     dx, al
  1358.                 mov     dx, SeqDataPort ; Sequencer data port
  1359.                 mov     al, 3           ; Enable Sequencers again
  1360.                 out     dx, al
  1361.             .endif
  1362.  
  1363. ;@C21 ******.if     < ds:[si].RegFlags eq Attributes_CMD >
  1364. ;@C21 ******    @VideoOn
  1365. ;@C21 ******.endif
  1366.  
  1367.             sti
  1368.  
  1369.             pop     si
  1370.             pop     ds
  1371.             pop     di
  1372.             pop     es
  1373.             pop     bp
  1374.             ret     14
  1375.  
  1376. ACCESSHARDWARE ENDP
  1377.  
  1378. ; MJS P VGA
  1379. IFDEF       VDHVGA
  1380. ;/**********************  START OF SPECIFICATIONS  **********************/
  1381. ;/*                                                                     */
  1382. ;/*  SUBROUTINE NAME: VGAWait                                           */
  1383. ;/*                                                                     */
  1384. ;/*  DESCRIPTIVE NAME: wait for video retrace before a write to port    */
  1385. ;/*                    3C0h, register 10h                               */
  1386. ;/*                                                                     */
  1387. ;/*  FUNCTION:                                                          */
  1388. ;/*                                                                     */
  1389. ;/*  ENTRY POINT: VGAWait                                               */
  1390. ;/*    LINKAGE:   CALL NEAR                                             */
  1391. ;/*                                                                     */
  1392. ;/*  INPUT: none                                                        */
  1393. ;/*  INTERNAL REFERENCES:                                               */
  1394. ;/*    ROUTINES: NONE                                                   */
  1395. ;/*                                                                     */
  1396. ;/*  EXTERNAL REFERENCES:                                               */
  1397. ;/*    ROUTINES: NONE                                                   */
  1398. ;/*                                                                     */
  1399. ;/***********************  END OF SPECIFICATIONS  ***********************/
  1400.             PUBLIC  VGAWait
  1401. VGAWait     PROC    NEAR                ;@B19
  1402.             sti
  1403.             push    ax
  1404.             push    cx
  1405.             push    dx
  1406.             mov     dx, FeatureControlWrite
  1407.             .if     < ColorMode eq TRUE >
  1408.                 add     dx, 20h         ; use color ports
  1409.             .endif
  1410.             xor     cx,cx               ;time out in case a card never sets this bit
  1411. VGAWait1:
  1412.             in      al,dx
  1413.             test    al,8                ; look for retrace bit
  1414.             loopnz  VGAWait1            ; wait for retrace to end
  1415.             xor     cx,cx               ; time out in case a card never sets this bit
  1416. VGAWait2:
  1417.             sti
  1418.             nop
  1419.             nop                         ;486     work around            ;@T49
  1420.             cli
  1421.             in      al,dx
  1422.             test    al,8                ; look for retrace bit
  1423.             loopz   VGAWait2            ;wait for retrace to begin again
  1424.  
  1425.             pop     dx
  1426.             pop     cx
  1427.             pop     ax
  1428.             ret
  1429. VGAWait     ENDP
  1430. ENDIF
  1431. ; MJS P VGA
  1432.  
  1433.         ENDIF                           ; IFDEF VDH8514A
  1434.  
  1435. ;/**********************  START OF SPECIFICATIONS  **********************/
  1436. ;/*                                                                     */
  1437. ;/*  SUBROUTINE NAME: AccessRegister                                    */
  1438. ;/*                                                                     */
  1439. ;/*  DESCRIPTIVE NAME: Set or read physical non-indexed register        */
  1440. ;/*                                                                     */
  1441. ;/*  FUNCTION: AccessRegister is called to query or set the physical    */
  1442. ;/*            non-indexed register specified                           */
  1443. ;/*                                                                     */
  1444. ;/*  ENTRY POINT: AccessRegister                                        */
  1445. ;/*    LINKAGE:   CALL FAR                                              */
  1446. ;/*                                                                     */
  1447. ;/*  INPUT: (Passed on stack)                                           */
  1448. ;/*             DWORD  RegAddress ( far pointer to structure )          */
  1449. ;/*                       WORD RegAddressPort                           */
  1450. ;/*                       WORD RegDataPort                              */
  1451. ;/*                       WORD RegColorAdjust                           */
  1452. ;/*                       WORD RegFlags                                 */
  1453. ;/*             WORD   Direction ( GET or SET or SETWORD )              */
  1454. ;/*             DWORD  RegData ( far pointer to data )                  */
  1455. ;/*                                                                     */
  1456. ;/*  EXIT-NORMAL: Non-indexed register is altered or queried            */
  1457. ;/*                                                                     */
  1458. ;/*  INTERNAL REFERENCES:                                               */
  1459. ;/*    ROUTINES: NONE                                                   */
  1460. ;/*                                                                     */
  1461. ;/*  EXTERNAL REFERENCES:                                               */
  1462. ;/*    ROUTINES: NONE                                                   */
  1463. ;/*                                                                     */
  1464. ;/***********************  END OF SPECIFICATIONS  ***********************/
  1465.         PUBLIC  ACCESSREGISTER
  1466. ACCESSREGISTER PROC FAR
  1467.  
  1468.         push    bp
  1469.         mov     bp, sp
  1470.         push    es
  1471.         push    di
  1472.         push    ds
  1473.         push    si
  1474.  
  1475.         les     di, ParameterPacket     ; es:di = data packet
  1476.         lds     si, AddressPkt          ; ds:si = address packet
  1477.  
  1478.         mov     dx, ds:[si].RegDataPort ; Register port
  1479.  
  1480.         cli
  1481.  
  1482.         .if     < Direction eq SET >
  1483.  
  1484.             IFNDEF  VDHMPA_OR_VDHCGA
  1485.                 IFNDEF  VDH8514A
  1486.  
  1487.                     .if     < ds:[si].RegDataPort eq MiscOutputRegWrite >
  1488.                         push    dx      ; Save register address
  1489.                         mov     dx, SeqAddressPort ; Sequencer address port
  1490.                         mov     al, 0   ; Reset register index
  1491.                         out     dx, al
  1492.                         mov     dx, SeqDataPort ; Sequencer data port
  1493.                         mov     al, 1   ; Synchronous reset
  1494.                         out     dx, al
  1495.  
  1496. ;@S28f                  IFDEF   VDHVGA  ;@S28
  1497.  
  1498. ;@S28f                      mov     dx,MiscOutputRegRead ;@S28
  1499. ;@S28f                      in      al,dx ;@S28
  1500. ;@S28f                      and     al,08h ;@S28
  1501.  
  1502. ;@S28f                      pop     dx  ; Retrieve register address ;@S28
  1503. ;@S28f                      or      al, BYTE PTR es:[di] ; Set miscoutput reg ;@S28
  1504.  
  1505. ;@S28f                  ELSE            ;not VDHVGA ;@S28
  1506.  
  1507.                             pop     dx  ; Retrieve register address
  1508.                             mov     al, BYTE PTR es:[di] ; Set miscoutput register
  1509.  
  1510. ;@S28f                  ENDIF           ;@S28
  1511.  
  1512.                         out     dx, al
  1513.  
  1514. ;J-TS00 IF VDHVGA AND (1 - VDHINIT)                                             ;@DRW
  1515.                 push    ds                                              ;@DRW
  1516.                 mov     ax, seg _SVGAPresent                            ;@DRW
  1517.                 mov     ds, ax                                          ;@DRW
  1518.                 cmp     _SVGAPresent, TSENG_ADAPTER                     ;@DRW
  1519.                 pop     ds                                              ;@DRW
  1520.                 je      @F                                              ;@DRW
  1521.                 @FixVGABug
  1522. @@:
  1523. ;J-TS00 ENDIF   ;VDHVGA                                                         ;MS00
  1524.  
  1525.                         mov     dx, SeqAddressPort ; Sequencer address port
  1526.                         mov     al, 0   ; Reset register index
  1527.                         out     dx, al
  1528.                         mov     dx, SeqDataPort ; Sequencer data port
  1529.                         mov     al, 3   ; Normal operation
  1530.                         out     dx, al
  1531.                     .else
  1532.  
  1533.                     ENDIF
  1534.                 ENDIF
  1535.  
  1536.                 mov     al, BYTE PTR es:[di]
  1537.                 out     dx, al
  1538.  
  1539.                 IFNDEF  VDHMPA_OR_VDHCGA
  1540.                     IFNDEF  VDH8514A
  1541.  
  1542.                     .endif
  1543.  
  1544.                 ENDIF
  1545.             ENDIF
  1546.  
  1547.         .else
  1548.             .if     < Direction eq SETWORD >
  1549.  
  1550.                 mov     ax, word ptr es:[di]
  1551.                 out     dx,ax
  1552.  
  1553.             .else                       ;< Direction eq GET >
  1554.  
  1555.                 in      al, dx
  1556.                 stosb
  1557.  
  1558.             .endif
  1559.         .endif
  1560.  
  1561.         sti
  1562.  
  1563.         pop     si
  1564.         pop     ds
  1565.         pop     di
  1566.         pop     es
  1567.         pop     bp
  1568.         ret     10
  1569.  
  1570. ACCESSREGISTER ENDP
  1571.  
  1572. LG_SET_RESET            EQU     00H
  1573. LG_ENABLE_SET_RESET     EQU     01H
  1574. LG_COMP                 EQU     02H
  1575. LG_FUNCTION             EQU     03H
  1576. LG_MODE                 EQU     05H
  1577. LG_READ_MAP             EQU     04H
  1578. LG_BIT_MASK             EQU     08H
  1579. LG_COMMAND              EQU     0BH
  1580.  
  1581. LS_CLOCK_MODE           EQU     01H
  1582. LS_MAP_MASK             EQU     02H
  1583.  
  1584. LC_OVERFLOW             EQU     07H
  1585. LC_MAX_SCAN_LINE        EQU     09H
  1586. LC_START_HIGH           EQU     0CH
  1587. LC_START_LOW            EQU     0DH
  1588. LC_LINE_COMP            EQU     18H
  1589.  
  1590.  
  1591. ;/**********************  START OF SPECIFICATIONS  **********************/
  1592. ;/*                                                                     */
  1593. ;/*  SUBROUTINE NAME: SetupAPAWrite                                     */
  1594. ;/*                                                                     */
  1595. ;/*  DESCRIPTIVE NAME: Setup VGA registers to update APA.               */
  1596. ;/*                                                                     */
  1597. ;/*  INPUT: None                                                        */
  1598. ;/*                                                                     */
  1599. ;/*  INTERNAL REFERENCES:                                               */
  1600. ;/*    ROUTINES: None                                                   */
  1601. ;/*                                                                     */
  1602. ;/*  EXTERNAL REFERENCES:                                               */
  1603. ;/*    ROUTINES: None                                                   */
  1604. ;/*                                                                     */
  1605. ;/***********************  END OF SPECIFICATIONS  ***********************/
  1606. SetupAPAWrite   proc    far
  1607.         public  SetupAPAWrite
  1608.  
  1609.         push    ax                      ; save ax, dx
  1610.         push    dx
  1611.  
  1612.         mov     dx, GraphAddressPort    ; set VGA port address
  1613.         mov     al, LG_FUNCTION         ; set rotate 0
  1614.         mov     ah, 0
  1615.         out     dx, ax
  1616.         mov     al, LG_BIT_MASK         ; set bit mask ffh
  1617.         mov     ah, 0ffh
  1618.         out     dx, ax
  1619.  
  1620.         mov     dx, SeqAddressPort      ; set VGA port address
  1621.         mov     al, LS_MAP_MASK         ; set map mask ffh
  1622.         mov     ah, 0ffh
  1623.         out     dx, ax
  1624.  
  1625.         pop     dx                      ; restore ax, dx
  1626.         pop     ax
  1627.         ret
  1628.  
  1629. SetupAPAWrite   endp
  1630.  
  1631. ;/**********************  START OF SPECIFICATIONS  **********************/
  1632. ;/*                                                                     */
  1633. ;/*  SUBROUTINE NAME: SetupAPAMove                                      */
  1634. ;/*                                                                     */
  1635. ;/*  DESCRIPTIVE NAME: Setup VGA registers to move APA.                 */
  1636. ;/*                                                                     */
  1637. ;/*  INPUT: None                                                        */
  1638. ;/*                                                                     */
  1639. ;/*  INTERNAL REFERENCES:                                               */
  1640. ;/*    ROUTINES: None                                                   */
  1641. ;/*                                                                     */
  1642. ;/*  EXTERNAL REFERENCES:                                               */
  1643. ;/*    ROUTINES: None                                                   */
  1644. ;/*                                                                     */
  1645. ;/***********************  END OF SPECIFICATIONS  ***********************/
  1646. SetupAPAMove    proc    far
  1647.         public  SetupAPAMove
  1648.  
  1649.         push    ax                      ; save ax, dx
  1650.         push    dx
  1651.  
  1652.         mov     dx, GraphAddressPort    ; set VGA port address
  1653.         mov     al, LG_MODE             ; set write mode 1
  1654.         mov     ah, 01h
  1655.         out     dx, ax
  1656.  
  1657.         mov     dx, SeqAddressPort      ; set VGA port address
  1658.         mov     al, LS_MAP_MASK         ; set map mask ffh
  1659.         mov     ah, 0ffh
  1660.         out     dx, ax
  1661.  
  1662.         pop     dx                      ; restore ax, dx
  1663.         pop     ax
  1664.         ret
  1665.  
  1666. SetupAPAMove    endp
  1667.  
  1668. ;/**********************  START OF SPECIFICATIONS  **********************/
  1669. ;/*                                                                     */
  1670. ;/*  SUBROUTINE NAME: SetAPAColor                                       */
  1671. ;/*                                                                     */
  1672. ;/*  DESCRIPTIVE NAME: Set APA write colors.                            */
  1673. ;/*                                                                     */
  1674. ;/*  INPUT:                                                             */
  1675. ;/*     AL      = Foreground (0-3 bit) and Background (4-7) Colors      */
  1676. ;/*     ES:DI --> Target APA address
  1677. ;/*                                                                     */
  1678. ;/*  INTERNAL REFERENCES:                                               */
  1679. ;/*    ROUTINES: None                                                   */
  1680. ;/*                                                                     */
  1681. ;/*  EXTERNAL REFERENCES:                                               */
  1682. ;/*    ROUTINES: None                                                   */
  1683. ;/*                                                                     */
  1684. ;/***********************  END OF SPECIFICATIONS  ***********************/
  1685. SetAPAColor proc    far
  1686.         public  SetAPAColor
  1687.  
  1688.         push    bx                      ; save bx, dx
  1689.         push    dx                      ; 
  1690.  
  1691.         mov     dx, GraphAddressPort    ; set VGA port address
  1692.  
  1693.         mov     bl, al                  ; save color
  1694.  
  1695.         mov     al, LG_MODE             ; set write mode 3
  1696.         mov     ah, 03h
  1697.         out     dx, ax
  1698.  
  1699.         mov     al, LG_SET_RESET        ; set background color
  1700.         mov     ah, bl                  ; 
  1701.         shr     ah, 4                   ; get background color
  1702.         out     dx, ax
  1703.  
  1704.         mov     byte ptr es:[di], 0ffh  ; clear APA with background color
  1705.         mov     al, es:[di]             ; set complement register
  1706.  
  1707.         mov     al, LG_SET_RESET        ; set foreground color
  1708.         mov     ah, bl                  ; 
  1709.         and     ah, 0fh                 ; get foreground color
  1710.         out     dx, ax
  1711.  
  1712.         pop     dx                      ; restore bx, dx
  1713.         pop     bx                      ; 
  1714.  
  1715.         ret
  1716.  
  1717. SetAPAColor endp
  1718.  
  1719. ;/**********************  START OF SPECIFICATIONS  **********************/
  1720. ;/*                                                                     */
  1721. ;/*  SUBROUTINE NAME: SetClsColor                                       */
  1722. ;/*                                                                     */
  1723. ;/*  DESCRIPTIVE NAME: Set APA clear colors.                            */
  1724. ;/*                                                                     */
  1725. ;/*  INPUT:                                                             */
  1726. ;/*     AL      = Foreground Color                                      */
  1727. ;/*                                                                     */
  1728. ;/*  INTERNAL REFERENCES:                                               */
  1729. ;/*    ROUTINES: None                                                   */
  1730. ;/*                                                                     */
  1731. ;/*  EXTERNAL REFERENCES:                                               */
  1732. ;/*    ROUTINES: None                                                   */
  1733. ;/*                                                                     */
  1734. ;/***********************  END OF SPECIFICATIONS  ***********************/
  1735. SetClsColor proc    far
  1736.         public  SetClsColor
  1737.  
  1738.         jmp     SetGridColor
  1739.         ret
  1740.  
  1741. SetClsColor endp
  1742.  
  1743. ;/**********************  START OF SPECIFICATIONS  **********************/
  1744. ;/*                                                                     */
  1745. ;/*  SUBROUTINE NAME: SetGridColor                                      */
  1746. ;/*                                                                     */
  1747. ;/*  DESCRIPTIVE NAME: Set APA grid write colors.                       */
  1748. ;/*                                                                     */
  1749. ;/*  INPUT:                                                             */
  1750. ;/*     AL      = Grid Color                                            */
  1751. ;/*                                                                     */
  1752. ;/*  INTERNAL REFERENCES:                                               */
  1753. ;/*    ROUTINES: None                                                   */
  1754. ;/*                                                                     */
  1755. ;/*  EXTERNAL REFERENCES:                                               */
  1756. ;/*    ROUTINES: None                                                   */
  1757. ;/*                                                                     */
  1758. ;/***********************  END OF SPECIFICATIONS  ***********************/
  1759. SetGridColor    proc    far
  1760.         public  SetGridColor
  1761.  
  1762.         push    ax                      ; save ax, dx
  1763.         push    dx
  1764.  
  1765.         push    ax                      ; save grid color
  1766.  
  1767.         mov     dx, GraphAddressPort    ; set VGA port address
  1768.  
  1769.         mov     al, LG_MODE             ; set write mode 3
  1770.         mov     ah, 03h
  1771.         out     dx, ax
  1772.  
  1773.         pop     ax                      ; restore grid color
  1774.         mov     ah, al
  1775.  
  1776.         mov     al, LG_SET_RESET        ; set grid color
  1777.         and     ah, 0fh                 ; get foreground color
  1778.         out     dx, ax
  1779.  
  1780.         pop     dx                      ; restore ax,dx
  1781.         pop     ax
  1782.  
  1783.         ret
  1784.  
  1785. SetGridColor    endp
  1786.  
  1787. ;/**********************  START OF SPECIFICATIONS  **********************/
  1788. ;/*                                                                     */
  1789. ;/*  SUBROUTINE NAME: DrawCursorToAPA                                   */
  1790. ;/*                                                                     */
  1791. ;/*  DESCRIPTIVE NAME: Draw character cursor on APA.                    */
  1792. ;/*                                                                     */
  1793. ;/*  INPUT:                                                             */
  1794. ;/*     AL      = Cursor Color                                          */
  1795. ;/*     AH      = Character Foreground Color (0-3 bit) and              */
  1796. ;/*                         Background Color (4-7 bit)                  */
  1797. ;/*     BX      = one scan line length                                  */
  1798. ;/*     CX      = Cursor Height (scan lines)                            */
  1799. ;/*     SI      = Offset to charactor top                               */ ;J-TS0928
  1800. ;/*     ES:DI --> Cursor Start APA Address                              */
  1801. ;/*                                                                     */
  1802. ;/*  INTERNAL REFERENCES:                                               */
  1803. ;/*    ROUTINES: None                                                   */
  1804. ;/*                                                                     */
  1805. ;/*  EXTERNAL REFERENCES:                                               */
  1806. ;/*    ROUTINES: None                                                   */
  1807. ;/*                                                                     */
  1808. ;/***********************  END OF SPECIFICATIONS  ***********************/
  1809. DrawCursorToAPA proc    near
  1810.         public  DrawCursorToAPA
  1811.  
  1812.         push    bp                      ; save scan line length
  1813.         mov     bp, bx
  1814.  
  1815.         mov     dx, GraphAddressPort    ; set VGA port address
  1816.         mov     bx, ax                  ; save colors
  1817.         mov     al, LG_COMP             ; set color comp
  1818.         out     dx, ax
  1819.         mov     ax, bx                  ; restore colors
  1820.         shr     ah, 4                   ; if char back color = cursor color
  1821.         .if     <ah eq al>              ; cursor color is reversed.
  1822.             xor     al, 0fh
  1823.         .endif
  1824.         mov     ah, al                  ; set set/reset register (cursor color)
  1825.         mov     al, LG_SET_RESET
  1826.         out     dx, ax
  1827.         mov     al, LG_MODE             ; set read mode 1, write mode 3
  1828.         mov     ah, 03h+08h
  1829.         out     dx, ax
  1830.         mov     al, LG_FUNCTION         ; set rotate 0
  1831.         mov     ah, 0
  1832.         out     dx, ax
  1833.         mov     al, LG_BIT_MASK         ; set bit mask ffh
  1834.         mov     ah, 0ffh
  1835.         out     dx, ax
  1836.  
  1837.         mov     bl, bh                  ; if char back color = char fore color
  1838.         shr     bl, 4                   ; foreground color is ignored.
  1839.         and     bh, 0fh
  1840.  
  1841. DrawCursorLap:                                                      ;J-TS0928
  1842.         push    cx                                                  ;J-TS0928
  1843.         xor     ch, ch                                              ;J-TS0928
  1844.  
  1845.         .if     <bh eq bl>              ; back = fore
  1846.  
  1847.             mov     al, 0ffh
  1848. DrawCursorLoop1:
  1849.             mov     es:[di], al         ; draw cursor
  1850.             add     di, bp
  1851.             loop    DrawCursorLoop1
  1852.  
  1853.         .else                           ; back != fore
  1854.  
  1855. DrawCursorLoop2:
  1856.             mov     al, es:[di]         ; get font pattern
  1857.             not     al
  1858.             mov     es:[di], al         ; draw cursor
  1859.             add     di, bp
  1860.             loop    DrawCursorLoop2
  1861.  
  1862.         .endif
  1863.  
  1864.         pop     cx                                                  ;J-TS0928
  1865.         .if     <ch ne 0>                                           ;J-TS0928
  1866.             mov     cl, ch                                          ;J-TS0928
  1867.             xor     ch, ch                                          ;J-TS0928
  1868.             sub     di, si                                          ;J-TS0928
  1869.             jmp     DrawCursorLap                                   ;J-TS0928
  1870.         .endif                                                      ;J-TS0928
  1871.  
  1872.         pop     bp
  1873.  
  1874.         ret
  1875.  
  1876. DrawCursorToAPA endp
  1877.  
  1878. ;/**********************  START OF SPECIFICATIONS  **********************/
  1879. ;/*                                                                     */
  1880. ;/*  SUBROUTINE NAME: XorCursorToAPA                                    */
  1881. ;/*                                                                     */
  1882. ;/*  DESCRIPTIVE NAME: Xor character cursor on APA.                     */
  1883. ;/*                                                                     */
  1884. ;/*  INPUT:                                                             */
  1885. ;/*     BX      = one scan line length                                  */
  1886. ;/*     CX      = Cursor Height (scan lines)                            */
  1887. ;/*     ES:DI --> Cursor Start APA Address                              */
  1888. ;/*                                                                     */
  1889. ;/*  INTERNAL REFERENCES:                                               */
  1890. ;/*    ROUTINES: None                                                   */
  1891. ;/*                                                                     */
  1892. ;/*  EXTERNAL REFERENCES:                                               */
  1893. ;/*    ROUTINES: None                                                   */
  1894. ;/*                                                                     */
  1895. ;/***********************  END OF SPECIFICATIONS  ***********************/
  1896. XorCursorToAPA  proc    near
  1897.         public  XorCursorToAPA
  1898.  
  1899.         push    bp
  1900.         mov     bp, bx
  1901.  
  1902.         mov     dx, GraphAddressPort    ; set VGA port address
  1903.  
  1904.         mov     al, LG_MODE             ; set read mode 0 / write mode 0
  1905.         mov     ah, 00h
  1906.         out     dx, ax
  1907.  
  1908.         mov     al, LG_BIT_MASK         ; set bit mask ffh
  1909.         mov     ah, 0ffh
  1910.         out     dx, ax
  1911.  
  1912.         mov     al, LG_ENABLE_SET_RESET ; set set/reset enable
  1913.         mov     ah, 0
  1914.         out     dx, ax
  1915.  
  1916.         mov     al, LG_FUNCTION         ; set rotate 0
  1917.         mov     ah, 0
  1918.         out     dx, ax
  1919.  
  1920.         mov     bh, 4                   ; plane count
  1921.         mov     bl, 1000b
  1922.  
  1923. XorCsrLoop1:
  1924.         mov     dx, GraphAddressPort    ; set VGA port address
  1925.         mov     al, LG_READ_MAP         ; set read map
  1926.         mov     ah, bh
  1927.         dec     ah
  1928.         out     dx, ax
  1929.  
  1930.         mov     dx, SeqAddressPort      ; set VGA port address
  1931.         mov     al, LS_MAP_MASK         ; select write map
  1932.         mov     ah, bl
  1933.         out     dx, ax
  1934.  
  1935.         push    cx
  1936.         push    di
  1937.  
  1938. XorCsrLoop2:
  1939.         mov     al, es:[di]             ; xor one scan line
  1940.         xor     al, 0ffh
  1941.         mov     es:[di], al
  1942.         add     di, bp
  1943.         loop    XorCsrLoop2
  1944.  
  1945.         pop     di
  1946.         pop     cx
  1947.         shr     bl, 1
  1948.         dec     bh
  1949.         jnz     XorCsrLoop1             ; next plane
  1950.  
  1951.         pop     bp
  1952.  
  1953.         ret
  1954.  
  1955. XorCursorToAPA endp
  1956.  
  1957. ;/**********************  START OF SPECIFICATIONS  **********************/
  1958. ;/*                                                                     */
  1959. ;/*  SUBROUTINE NAME: SaveFont                                          */
  1960. ;/*                                                                     */
  1961. ;/*  DESCRIPTIVE NAME: Save character images from APA to local buffer.  */
  1962. ;/*                                                                     */
  1963. ;/*  INPUT:                                                             */
  1964. ;/*     DS:SI --> local buffer                                          */
  1965. ;/*     ES:DI --> character start APA address                           */
  1966. ;/*     AX    --> one scan line length (bytes)                          */
  1967. ;/*     BL    --> number of APA                                         */
  1968. ;/*                                                                     */
  1969. ;/*  INTERNAL REFERENCES:                                               */
  1970. ;/*    ROUTINES: None                                                   */
  1971. ;/*                                                                     */
  1972. ;/*  EXTERNAL REFERENCES:                                               */
  1973. ;/*    ROUTINES: None                                                   */
  1974. ;/*                                                                     */
  1975. ;/***********************  END OF SPECIFICATIONS  ***********************/
  1976. SaveFont        proc    far
  1977.         public  SaveFont
  1978.         pusha
  1979.  
  1980.         mov     bp, ax                  ; move scan line length
  1981.  
  1982.         mov     dx, SeqAddressPort      ; set VGA port address
  1983.         mov     al, LS_MAP_MASK         ; set map mask ffh
  1984.         mov     ah, 0ffh
  1985.         out     dx, ax
  1986.  
  1987.         mov     dx, GraphAddressPort    ; set VGA port address
  1988.         mov     al, LG_MODE             ; set read mode 0
  1989.         mov     ah, 00h
  1990.         out     dx, ax
  1991.  
  1992. SaveFontLoop1:
  1993.         mov     al, LG_READ_MAP         ; set read map
  1994.         mov     ah, bl
  1995.         dec     ah
  1996.         out     dx, ax
  1997.  
  1998.         mov     cx, FONT_HEIGHT         ; set font height loop counter
  1999.  
  2000. SaveFontLoop2:
  2001.         mov     al, es:[di]             ; get one line
  2002.         mov     ds:[si], al             ; save one line
  2003.         inc     si                      ; inc pointers
  2004.         add     di, bp
  2005.         loop    SaveFontLoop2
  2006.  
  2007.         mov     ax, bp                  ; restore APA pointer
  2008.         mov     ah, FONT_HEIGHT
  2009.         mul     ah
  2010.         sub     di, ax
  2011.         dec     bl
  2012.  
  2013.         jnz     SaveFontLoop1
  2014.  
  2015.         popa
  2016.         ret
  2017.  
  2018. SaveFont        endp
  2019.  
  2020. ;/**********************  START OF SPECIFICATIONS  **********************/
  2021. ;/*                                                                     */
  2022. ;/*  SUBROUTINE NAME: RestoreFont                                       */
  2023. ;/*                                                                     */
  2024. ;/*  DESCRIPTIVE NAME: Restore character images from APA to local buffer*/
  2025. ;/*                                                                     */
  2026. ;/*  INPUT:                                                             */
  2027. ;/*     DS:SI --> Local Buffer                                          */
  2028. ;/*     ES:DI --> Character Start APA Address                           */
  2029. ;/*     AX    --> one scan line length (bytes)                          */
  2030. ;/*     BL    --> number of APA                                         */
  2031. ;/*                                                                     */
  2032. ;/*  INTERNAL REFERENCES:                                               */
  2033. ;/*    ROUTINES: None                                                   */
  2034. ;/*                                                                     */
  2035. ;/*  EXTERNAL REFERENCES:                                               */
  2036. ;/*    ROUTINES: None                                                   */
  2037. ;/*                                                                     */
  2038. ;/***********************  END OF SPECIFICATIONS  ***********************/
  2039. RestoreFont     proc    far
  2040.         public  RestoreFont
  2041.         pusha
  2042.  
  2043.         mov     bp, ax                  ; move scan line length
  2044.  
  2045.         mov     dx, GraphAddressPort    ; set VGA port address
  2046.         mov     al, LG_MODE             ; set write mode 0
  2047.         mov     ah, 00h
  2048.         out     dx, ax
  2049.         mov     al, LG_FUNCTION         ; set rotate 0
  2050.         mov     ah, 0
  2051.         out     dx, ax
  2052.         mov     al, LG_BIT_MASK         ; set bit mask ffh
  2053.         mov     ah, 0ffh
  2054.         out     dx, ax
  2055.         mov     al, LG_ENABLE_SET_RESET ; set set/reset enable
  2056.         mov     ah, 0
  2057.         out     dx, ax
  2058.  
  2059.         mov     dx, SeqAddressPort      ; set VGA port address
  2060.  
  2061. RestoreFontLoop1:
  2062.         mov     al, LS_MAP_MASK         ; select restore map
  2063.         mov     cl, bl
  2064.         mov     ah, 10000000b
  2065.         rol     ah, cl
  2066.         out     dx, ax
  2067.  
  2068.         mov     cx, FONT_HEIGHT
  2069.  
  2070. RestoreFontLoop2:
  2071.         mov     al, ds:[si]
  2072.         mov     es:[di], al
  2073.         inc     si
  2074.         add     di, bp
  2075.         loop    RestoreFontLoop2
  2076.  
  2077.         mov     ax, bp                  ; restore APA pointer
  2078.         mov     ah, FONT_HEIGHT
  2079.         mul     ah
  2080.         sub     di, ax
  2081.         dec     bl
  2082.  
  2083.         jnz     RestoreFontLoop1
  2084.  
  2085.         popa
  2086.         ret
  2087.  
  2088. RestoreFont     endp
  2089.  
  2090. ;********************** START OF SPECIFICATIONS *************************
  2091. ;*                                                                      *
  2092. ;* SUBROUTINE NAME:     DrawCursor                                      *
  2093. ;*                                                                      *
  2094. ;* DESCRIPTIVE NAME:    Draw cursor with no condition                   *
  2095. ;*                                                                      *
  2096. ;* INPUT:       DS:     Video Buffer Selector                           *
  2097. ;*                                                                      *
  2098. ;* OUTPUT:      None                                                    *
  2099. ;*                                                                      *
  2100. ;* INTERNAL REFERENCES: None                                            *
  2101. ;*                                                                      *
  2102. ;* EXTERNAL REFERENCES: SaveFont, DrawCursorToAPA                       *
  2103. ;*                                                                      *
  2104. ;********************** END OF SPECIFICATIONS ***************************
  2105. DrawCursor      proc    far
  2106.         public  DrawCursor
  2107.  
  2108.         cli
  2109.  
  2110.         ; save currently displayed font
  2111.  
  2112.         mov     si, VGA_SaveChar            ; set save area pointer
  2113.  
  2114.         mov     ax, ds:VGA_CsrScrWidth      ; set shadow buffer pointer
  2115.         mul     ds:VGA_CsrRow
  2116.         add     ax, ds:VGA_CsrCol
  2117.         shl     ax, 2
  2118.         mov     bx, ax
  2119.  
  2120.         mov     ax, INSTSEG                 ; set APA pointer
  2121.         mov     es, ax
  2122.         mov     es, es:CursorSel
  2123.         mov     ax, APA_WIDTH*FONT_HEIGHT
  2124.         mul     ds:VGA_CsrRow
  2125.         add     ax, ds:VGA_CsrCol
  2126.         add     ax, ds:VGA_APAStart
  2127.         mov     di, ax
  2128.  
  2129.         push    bx                          ; save shadow buffer pointer
  2130.         push    di                          ; save APA pointer for latter use
  2131.         mov     ax, APA_WIDTH               ; set scan line length
  2132.         mov     bl, 4                       ; set number of planes
  2133.         call    SaveFont                    ; save font image
  2134.  
  2135.         .if     <ds:VGA_CsrWidth eq 2>      ; cursor is DBCS width ?
  2136.             add     si, FONT_HEIGHT*4       ; set save area pointer
  2137.             inc     di                      ; set APA pointer
  2138.  
  2139.             mov     ax, APA_WIDTH           ; set scan line length
  2140.             mov     bl, 4                   ; set number of planes
  2141.             call    SaveFont                ; save font image
  2142.         .endif
  2143.  
  2144.         ; draw cursor
  2145.  
  2146.         pop     di                          ; restore APA pointer
  2147.         pop     bx                          ; restore shadow buffer pointer
  2148.  
  2149.         mov     ax, APA_WIDTH               ; inc ptr to cursor start line
  2150.         mul     ds:VGA_CsrStart
  2151.         add     di, ax
  2152.  
  2153.         mov     cx, ds:VGA_CsrEnd           ; get cursor height
  2154.         .if     <cx ge ds:VGA_CsrStart>                             ;J-TS0928
  2155.             sub     cx, ds:VGA_CsrStart
  2156.             inc     cx
  2157.         .else                                                       ;J-TS0928
  2158.             mov     cx, FONT_HEIGHT                                 ;J-TS0928
  2159.             sub     cx, ds:VGA_CsrStart                             ;J-TS0928
  2160.             inc     cx                                              ;J-TS0928
  2161.             mov     ch, byte ptr ds:VGA_CsrEnd                      ;J-TS0928
  2162.             inc     ch                                              ;J-TS0928
  2163.         .endif                                                      ;J-TS0928
  2164.  
  2165.         push    bx
  2166.         push    cx
  2167.         push    di
  2168.  
  2169.         mov     al, byte ptr ds:VGA_CsrColor ; get cursor color
  2170.         mov     ah, ds:shadow[bx+1]         ; get font color
  2171.         mov     bx, APA_WIDTH               ; set scan line length
  2172.         mov     si, APA_WIDTH*FONT_HEIGHT   ; off to char box top   ;J-TS0928
  2173.         call    DrawCursorToAPA             ; draw cursor to APA
  2174.  
  2175.         pop     di
  2176.         pop     cx
  2177.         pop     bx
  2178.  
  2179.         .if     <ds:VGA_CsrWidth eq 2>      ; cursor is DBCS width ?
  2180.             inc     di                      ; set APA pointer
  2181.             mov     al, byte ptr ds:VGA_CsrColor ; get cursor color
  2182.             mov     ah, ds:shadow[bx+5]     ; get font color
  2183.             mov     bx, APA_WIDTH           ; set scan line length
  2184.             mov     si, APA_WIDTH*FONT_HEIGHT ; off to char box top ;J-TS0928
  2185.             call    DrawCursorToAPA         ; draw cursor to APA
  2186.         .endif
  2187.  
  2188.         mov     ds:VGA_SaveFlag, 1          ; char is saved
  2189.  
  2190.         sti
  2191.  
  2192.         ret
  2193.  
  2194. DrawCursor      endp
  2195.  
  2196. ;********************** START OF SPECIFICATIONS *************************
  2197. ;*                                                                      *
  2198. ;* SUBROUTINE NAME:     EraseCursor                                     *
  2199. ;*                                                                      *
  2200. ;* DESCRIPTIVE NAME:    Erase cursor with no condition                  *
  2201. ;*                                                                      *
  2202. ;* INPUT:       DS:     Video Buffer Selector                           *
  2203. ;*                                                                      *
  2204. ;* OUTPUT:      None                                                    *
  2205. ;*                                                                      *
  2206. ;* INTERNAL REFERENCES: None                                            *
  2207. ;*                                                                      *
  2208. ;* EXTERNAL REFERENCES: RestoreFont                                     *
  2209. ;*                                                                      *
  2210. ;********************** END OF SPECIFICATIONS ***************************
  2211. EraseCursor     proc    far
  2212.         public  EraseCursor
  2213.  
  2214.         cli
  2215.  
  2216.         mov     si, VGA_SaveChar            ; set save area pointer
  2217.  
  2218.         mov     ax, INSTSEG                 ; set APA pointer
  2219.         mov     es, ax
  2220.         mov     es, es:CursorSel
  2221.         mov     ax, APA_WIDTH*FONT_HEIGHT
  2222.         mul     ds:VGA_CsrRow
  2223.         add     ax, ds:VGA_CsrCol
  2224.         add     ax, ds:VGA_APAStart
  2225.         mov     di, ax
  2226.  
  2227.         push    si
  2228.         push    di
  2229.  
  2230.         mov     ax, APA_WIDTH               ; set scan line length
  2231.         mov     bl, 4                       ; set number of planes
  2232.         call    RestoreFont                 ; hide cursor from APA
  2233.         pop     di
  2234.         pop     si
  2235.  
  2236.         .if     <ds:VGA_CsrWidth eq 2>      ; cursor is DBCS width ?
  2237.             add     si, FONT_HEIGHT*4       ; set save area pointer
  2238.             inc     di                      ; set APA pointer
  2239.             mov     ax, APA_WIDTH           ; set scan line length
  2240.             mov     bl, 4                   ; set number of planes
  2241.             call    RestoreFont             ; hide cursor from APA
  2242.         .endif
  2243.  
  2244.         mov     ds:VGA_SaveFlag, 0          ; char is restored
  2245.  
  2246.         sti
  2247.  
  2248.         ret
  2249.  
  2250. EraseCursor     endp
  2251.  
  2252. ;********************** START OF SPECIFICATIONS *************************
  2253. ;*                                                                      *
  2254. ;* SUBROUTINE NAME:     XorCursor                                       *
  2255. ;*                                                                      *
  2256. ;* DESCRIPTIVE NAME:    Xor cursor based on XVIO request                *
  2257. ;*                                                                      *
  2258. ;* INPUT:       DS:     Video Buffer Selector                           *
  2259. ;*                                                                      *
  2260. ;* OUTPUT:      None                                                    *
  2261. ;*                                                                      *
  2262. ;* INTERNAL REFERENCES: None                                            *
  2263. ;*                                                                      *
  2264. ;* EXTERNAL REFERENCES: None                                            *
  2265. ;*                                                                      *
  2266. ;********************** END OF SPECIFICATIONS ***************************
  2267. XorCursor   proc    far
  2268.         public  XorCursor
  2269.  
  2270.         cli
  2271.  
  2272.         mov     ax, INSTSEG                 ; set APA pointer
  2273.         mov     es, ax
  2274.         mov     es, es:CursorSel
  2275.         mov     ax, SCREEN_WIDTH*FONT_HEIGHT
  2276.         mul     ds:VGA_CsrRow
  2277.         add     ax, ds:VGA_CsrCol
  2278.         mov     di, ax
  2279.  
  2280.         mov     ax, SCREEN_WIDTH            ; inc ptr to cursor start line
  2281.         mul     ds:VGA_CsrStart
  2282.         add     di, ax
  2283.         mov     cx, ds:VGA_CsrEnd           ; get cursor height
  2284.         sub     cx, ds:VGA_CsrStart
  2285.         inc     cx
  2286.  
  2287.         mov     bx, SCREEN_WIDTH            ; set scan line length
  2288.  
  2289.         .if     <ds:VGA_CsrColor ne 0>      ; not black
  2290.             call    XorCursorToAPA          ; xor cursor to APA
  2291.         .endif
  2292.  
  2293.         sti
  2294.  
  2295.         ret
  2296.  
  2297. XorCursor   endp
  2298.  
  2299. ;/**********************  START OF SPECIFICATIONS  **********************/
  2300. ;/*                                                                     */
  2301. ;/*  SUBROUTINE NAME: SetAPAStart                                       */
  2302. ;/*                                                                     */
  2303. ;/*  DESCRIPTIVE NAME: Set APA start address register on VGA to support */
  2304. ;/*                    hardware scroll.                                 */
  2305. ;/*                                                                     */
  2306. ;/*  INPUT:                                                             */
  2307. ;/*     AX      = APA Start Address                                     */
  2308. ;/*                                                                     */
  2309. ;/*  INTERNAL REFERENCES:                                               */
  2310. ;/*    ROUTINES: None                                                   */
  2311. ;/*                                                                     */
  2312. ;/*  EXTERNAL REFERENCES:                                               */
  2313. ;/*    ROUTINES: None                                                   */
  2314. ;/*                                                                     */
  2315. ;/***********************  END OF SPECIFICATIONS  ***********************/
  2316. SetAPAStart proc    far
  2317.         public  SetAPAStart
  2318.         pusha
  2319.  
  2320.         push    ds
  2321.         push    _DATA
  2322.         pop     ds
  2323.         mov     si, ds:PrevLineComp         ; get hardware scroll params.
  2324.         mov     di, ds:MaxLineComp
  2325.         mov     bp, ds:HardwareScroll       ; get hardware scroll flag
  2326.         pop     ds
  2327.  
  2328.         push    ax
  2329.                                             ; calc line compare reg
  2330.         not     ax                          ; ax = 10000h - ax
  2331.         inc     ax
  2332.         shr     ax, 7                       ; line count in ax
  2333.         .if     <ax gt FONT_HEIGHT*SCREEN_HEIGHT>
  2334.             mov     ax, FONT_HEIGHT*SCREEN_HEIGHT
  2335.         .endif
  2336.         dec     ax                          ; 
  2337.         mov     cx, ax                      ; line compare reg value in cx
  2338.  
  2339.         mov     dx, MiscOutputRegRead       ; Read Miscellaneous Output Register
  2340.         in      al, dx
  2341.         mov     bx, InputStatusReg1
  2342.         mov     dx, CRTCtlAddressReg
  2343.         .if     <bit ax and 01h>            ; bit 0 = 1 - color, 0 - monochrome
  2344.             add     bx, ColorAdjustment
  2345.             add     dx, ColorAdjustment
  2346.         .else
  2347.             add     bx, MonoAdjustment
  2348.             add     dx, MonoAdjustment
  2349.         .endif
  2350.  
  2351.         pop     ax
  2352.  
  2353.         .if     <bp eq PROTECT_HS_LC>       ; line compare scroll
  2354.             .if     <si b di> and           ; LineComp already enabled
  2355.             .if     <cx b si>               ; scroll up
  2356.                 push    ax
  2357.                 call    SetLineCompGale
  2358.                 pop     ax
  2359.                 call    SetCRTStartGale
  2360.             .else                           ; scroll down
  2361.                 call    SetCRTStartGale
  2362.                 call    SetLineCompGale
  2363.             .endif
  2364.         .else                               ; only start address scroll
  2365.             call    SetCRTStartGale
  2366.         .endif
  2367.  
  2368.         popa
  2369.         ret
  2370. SetAPAStart endp
  2371.  
  2372. ;/**********************  START OF SPECIFICATIONS  **********************/
  2373. ;/*                                                                     */
  2374. ;/*  SUBROUTINE NAME: SetCRTStartGale                                   */
  2375. ;/*                                                                     */
  2376. ;/*  DESCRIPTIVE NAME: Set CRT start address register on VGA to support */
  2377. ;/*                    hardware scroll.                                 */
  2378. ;/*                                                                     */
  2379. ;/*  INPUT:                                                             */
  2380. ;/*     AX      = APA Start Address                                     */
  2381. ;/*     BX      = InputStatusReg1                                       */
  2382. ;/*     CX      = New Line Compare                                      */
  2383. ;/*     DX      = CRTCtlAddressReg                                      */
  2384. ;/*                                                                     */
  2385. ;/*  INTERNAL REFERENCES:                                               */
  2386. ;/*    ROUTINES: None                                                   */
  2387. ;/*                                                                     */
  2388. ;/*  EXTERNAL REFERENCES:                                               */
  2389. ;/*    ROUTINES: None                                                   */
  2390. ;/*                                                                     */
  2391. ;/***********************  END OF SPECIFICATIONS  ***********************/
  2392.  
  2393. SetCRTStartGale proc    near
  2394.  
  2395.         push    ax
  2396.         mov     al, LC_START_HIGH           ; set new start address
  2397.         out     dx, ax
  2398.         pop     ax
  2399.  
  2400.         mov     ah, al
  2401.         mov     al, LC_START_LOW
  2402.         out     dx, ax
  2403.  
  2404.         ret
  2405. SetCRTStartGale endp
  2406.  
  2407. ;/**********************  START OF SPECIFICATIONS  **********************/
  2408. ;/*                                                                     */
  2409. ;/*  SUBROUTINE NAME: SetLineCompGale                                   */
  2410. ;/*                                                                     */
  2411. ;/*  DESCRIPTIVE NAME: Set Line compare register on VGA to support      */
  2412. ;/*                    hardware scroll.                                 */
  2413. ;/*                                                                     */
  2414. ;/*  INPUT:                                                             */
  2415. ;/*     AX      = APA Start Address                                     */
  2416. ;/*     BX      = InputStatusReg1                                       */
  2417. ;/*     CX      = New Line Compare                                      */
  2418. ;/*     DX      = CRTCtlAddressReg                                      */
  2419. ;/*                                                                     */
  2420. ;/*  INTERNAL REFERENCES:                                               */
  2421. ;/*    ROUTINES: None                                                   */
  2422. ;/*                                                                     */
  2423. ;/*  EXTERNAL REFERENCES:                                               */
  2424. ;/*    ROUTINES: None                                                   */
  2425. ;/*                                                                     */
  2426. ;/***********************  END OF SPECIFICATIONS  ***********************/
  2427.  
  2428. SetLineCompGale proc    near
  2429.  
  2430.         xchg    bx, dx
  2431.  
  2432. CRTStartLoop:                               ; wait until entering in vertical retrace
  2433.         sti
  2434.         nop
  2435.         cli
  2436.         in      al, dx
  2437.         test    al, 08h
  2438.         jz      CRTStartLoop
  2439.  
  2440.         xchg    bx, dx
  2441.  
  2442.         mov     al, LC_LINE_COMP            ; set lower 8 bit value
  2443.         mov     ah, cl
  2444.         out     dx, ax
  2445.  
  2446.         mov     al, LC_OVERFLOW             ; set bit 8 value
  2447.         out     dx, al
  2448.         inc     dx
  2449.         in      al, dx
  2450.         dec     dx
  2451.         and     al, 0efh
  2452.         mov     ah, ch
  2453.         and     ah, 01h
  2454.         shl     ah, 4
  2455.         or      ah, al
  2456.         mov     al, LC_OVERFLOW
  2457.         out     dx, ax
  2458.  
  2459.         mov     al, LC_MAX_SCAN_LINE        ; set bit 9 value
  2460.         out     dx, al
  2461.         inc     dx
  2462.         in      al, dx
  2463.         dec     dx
  2464.         and     al, 0bfh
  2465.         mov     ah, ch
  2466.         and     ah, 02h
  2467.         shl     ah, 5
  2468.         or      ah, al
  2469.         mov     al, LC_MAX_SCAN_LINE
  2470.         out     dx, ax
  2471.  
  2472.         push    ds
  2473.         push    _DATA
  2474.         pop     ds
  2475.         mov     PrevLineComp, cx
  2476.         pop     ds
  2477.  
  2478.         ret
  2479. SetLineCompGale endp
  2480.  
  2481.  
  2482. ;/**********************  START OF SPECIFICATIONS  **********************/
  2483. ;/*                                                                     */
  2484. ;/*  SUBROUTINE NAME: Enable/DisableInt                                 */
  2485. ;/*                                                                     */
  2486. ;/*  DESCRIPTIVE NAME: Enable/Disable interrrupt.                       */
  2487. ;/*                                                                     */
  2488. ;/*  INPUT: None                                                        */
  2489. ;/*                                                                     */
  2490. ;/*  INTERNAL REFERENCES:                                               */
  2491. ;/*    ROUTINES: None                                                   */
  2492. ;/*                                                                     */
  2493. ;/*  EXTERNAL REFERENCES:                                               */
  2494. ;/*    ROUTINES: None                                                   */
  2495. ;/*                                                                     */
  2496. ;/***********************  END OF SPECIFICATIONS  ***********************/
  2497. EnableInt   proc    far
  2498.         public  EnableInt
  2499.         sti
  2500.         ret
  2501. EnableInt   endp
  2502.  
  2503. DisableInt  proc    far
  2504.         public  DisableInt
  2505.         cli
  2506.         ret
  2507. DisableInt   endp
  2508.  
  2509. R2SEG   ENDS
  2510. END
  2511.