;# SCCSID = @(#)avioxxx.asm	6.3 92/02/13
; ****************************************************************************
; *                                                                          *
; *                       IBM/Microsoft Confidential                         *
; *                                                                          *
; *                 Copyright (c) IBM Corporation  1987, 1990                *
; *                 Copyright (c) Microsoft Corp.  1987, 1990                *
; *                           All Rights Reserved                            *
; *                                                                          *
; ****************************************************************************
        PAGE    58,132
        SUBTTL  AVIOxxx calls
        TITLE   AVIOXXX.ASM
;******************************************************************************
;*******   C H A N G E       H I S T O R Y   **********************************
;******************************************************************************
;%%%= public build entry
;     07-30-87
;P3414= remove additional parms generated by Winthorn DCR24059
;       08-19-88
;@T2  = 04/03/89 TPL, Sizzle work, PTR B700???
;DTBB1= 08/21/89 WKB, Dynamic Trace
;D549 = 11/07/89 WKB, DCR549
;@T52 = 01/15/90 TPL, DCR 704 work
;@T80 = 02/06/92 TPL, Don't use the reserved register FS, B732479

.xlist
include error.inc
include error2.inc
include struc.inc
include infoseg.inc
include vioextrn.inc
include vioequ.inc
include avioequ.inc
include viomac.inc
include vioidata.inc
include viocdata.inc
.list
.386p                                                                   ;D549

extrn   viorout:NEAR            ;internal call external definitions
IFDEF MMIOPH                                                            ;DTBB1
extrn   viopretrace:NEAR        ;
extrn   vioposttrace:NEAR       ;
ENDIF                                                                   ;DTBB1

public VIOASSOCIATE
public VIOASSOCIATE_POSTDT                                              ;DTBB1
public VIOCREATEPS
public VIOCREATEPS_POSTDT                                               ;DTBB1
public VIODELETESETID
public VIODELETESETID_POSTDT                                            ;DTBB1
public VIODESTROYPS
public VIODESTROYPS_POSTDT                                              ;DTBB1
public VIOGETDEVICECELLSIZE
public VIOGETDEVICECELLSIZE_POSTDT                                      ;DTBB1
public VIOGETORG
public VIOGETORG_POSTDT                                                 ;DTBB1
public VIOCREATELOGFONT
public VIOCREATELOGFONT_POSTDT                                          ;DTBB1
public VIOQUERYSETIDS
public VIOQUERYSETIDS_POSTDT                                            ;DTBB1
public VIOQUERYFONTS
public VIOQUERYFONTS_POSTDT                                             ;DTBB1
public VIOSETDEVICECELLSIZE
public VIOSETDEVICECELLSIZE_POSTDT                                      ;DTBB1
public VIOSETORG
public VIOSETORG_POSTDT                                                 ;DTBB1
public VIOSHIELDINIT
public VIOSHIELDINIT_POSTDT                                             ;DTBB1
public VIOSHIELDTERM
public VIOSHIELDTERM_POSTDT                                             ;DTBB1
public VIOSHOWPS
public VIOSHOWPS_POSTDT                                                 ;DTBB1
public VIOGETPSADDRESS
public VIOGETPSADDRESS_POSTDT                                           ;DTBB1
public VIOQUERYCONSOLE
public VIOQUERYCONSOLE_POSTDT                                           ;DTBB1

instance segment byte public 'data' USE16                               ;D549
instance ends

common segment byte public 'far_data' USE16                        ;D549;@T52
common ends

cseg    segment byte public 'code' USE16                                ;D549
        assume  cs:cseg,ds:instance,es:common,ss:nothing
        page

        SUBTTL AVIOXXX - AVIO FUNCTION CALL ENTRY POINTS
        page
;/*********************** START OF SPECIFICATIONS ***********************/
;/* SUBROUTINE NAMES:  VIOxxx                                           */
;/*                                                                     */
;/* DESCRIPTIVE NAMES:  AVIO function call entry points.                */
;/*                                                                     */
;/* FUNCTIONS:  Place the VIO function code on stack and CALL the       */
;/*             common router subroutine viorout.                       */
;/*                                                                     */
;/* NOTES:  These external entry points are used by all video subsystems*/
;/*         The first time a process makes a VIO function               */
;/*         call, vioattach will be called.  vioattach will call        */
;/*         DosGetProcAddr to get ptrs to the Base Video Subsystem      */
;/*         for the calling process.  The viorout VIOxxx entry points   */
;/*         define the number of stack parameters for each VIOxxx       */
;/*         function, but the current video subsystem itself            */
;/*         defines these parameters.                                   */
;/*                                                                     */
;/* ENTRY POINTS:  VIOxxx                                               */
;/*     LINKAGES:  FAR CALL's (external API's)                          */
;/*                                                                     */
;/* INPUT:  Number of stack parms required is defined by the number of  */
;/*         words popped from stack when returning to the caller.  For  */
;/*         the meaning of the stack parms for each VIOxxx function,    */
;/*         see the Base Video Subsystem's corresponding BVSxxx         */
;/*         function input description.                                 */
;/*                                                                     */
;/* EXIT-NORMAL:  AX = 0                                                */
;/*                                                                     */
;/* EXIT-ERROR:  AX = error code set by viorout                         */
;/*                                                                     */
;/* EFFECTS:  None.                                                     */
;/*                                                                     */
;/* INTERNAL REFERENCES:  None.                                         */
;/*            ROUTINES:  viorout - Route the VIO function call to the  */
;/*                             current PID's BVSMAIN entry point as    */
;/*                             recorded in the instance data fields    */
;/*                             bvs_sel and bvs_off.                    */
;/*                                                                     */
;/* EXTERNAL REFERENCES:  None.                                         */
;/*            ROUTINES:  None.                                         */
;/*********************** END OF SPECIFICATIONS *************************/

VIOASSOCIATE proc far
   mov  ax,bit_associate        ;passed to viorout                      ;1.2
   push fc_associate            ;VIO function number
   call viorout
VIOASSOCIATE_POSTDT label far                                           ;DTBB1
   ret  6                       ;return and pop parameters
VIOASSOCIATE endp

VIOCREATEPS proc far
   mov  ax,bit_createps         ;passed to viorout                      ;1.2
   push fc_createps             ;VIO function number
   call viorout                 ;call router
VIOCREATEPS_POSTDT label far                                            ;DTBB1
   ret  14                      ;return and pop parameters
VIOCREATEPS endp

VIODELETESETID  proc far
   mov  ax,bit_deletesetid      ;passed to viorout                      ;1.2
   push fc_deletesetid          ;VIO function number
   call viorout
VIODELETESETID_POSTDT label far                                         ;DTBB1
   ret  6                       ;return and pop parameters
VIODELETESETID endp

VIODESTROYPS proc far
   mov  ax,bit_destroyps        ;passed to viorout                      ;1.2
   push fc_destroyps            ;VIO function number
   call viorout
VIODESTROYPS_POSTDT label far                                           ;DTBB1
   ret  2                       ;return and pop parameters
VIODESTROYPS endp

VIOGETDEVICECELLSIZE proc far
   mov  ax,bit_getdevicecellsize;passed to viorout                      ;1.2
   push fc_getdevicecellsize    ;VIO function number
   call viorout
VIOGETDEVICECELLSIZE_POSTDT label far                                   ;DTBB1
   ret  10                      ;return and pop parameters
VIOGETDEVICECELLSIZE endp

VIOGETORG proc far
   mov  ax,bit_getorg           ;passed to viorout                      ;1.2
   push fc_getorg               ;VIO function number
   call viorout
VIOGETORG_POSTDT label far                                              ;DTBB1
   ret  10                      ;return and pop parameters
VIOGETORG endp

VIOCREATELOGFONT proc far
   mov  ax,bit_createlogfont    ;passed to viorout                      ;1.2
   push fc_createlogfont        ;VIO function number
   call viorout
VIOCREATELOGFONT_POSTDT label far                                       ;DTBB1
   ret  14                      ;return and pop parameters
VIOCREATELOGFONT endp

VIOQUERYSETIDS proc far
   mov  ax,bit_querysetids      ;passed to viorout                      ;1.2
   push fc_querysetids          ;VIO function number
   call viorout
VIOQUERYSETIDS_POSTDT label far                                         ;DTBB1
   ret  18                      ;return and pop parameters
VIOQUERYSETIDS endp

VIOQUERYFONTS proc far
   mov  ax,bit_queryfonts       ;passed to viorout                      ;1.2
   push fc_queryfonts           ;VIO function number
   call viorout
VIOQUERYFONTS_POSTDT label far                                          ;DTBB1
   ret  26                      ;return and pop parameters              ;P3414
VIOQUERYFONTS endp

VIOSETDEVICECELLSIZE proc far
   mov  ax,bit_setdevicecellsize;passed to viorout                      ;1.2
   push fc_setdevicecellsize    ;VIO function number
   call viorout
VIOSETDEVICECELLSIZE_POSTDT label far                                   ;DTBB1
   ret  6                       ;return and pop parameters
VIOSETDEVICECELLSIZE endp

VIOSETORG proc far
   mov  ax,bit_setorg           ;passed to viorout                      ;1.2
   push fc_setorg               ;VIO function number
   call viorout
VIOSETORG_POSTDT label far                                              ;DTBB1
   ret  6                       ;return and pop parameters
VIOSETORG endp

VIOSHOWPS proc far
   mov  ax,bit_showps           ;passed to viorout                      ;1.2
   push fc_showps               ;VIO function number
   call viorout
VIOSHOWPS_POSTDT label far                                              ;DTBB1
   ret  8                       ;return and pop parameters
VIOSHOWPS endp

VIOGETPSADDRESS proc far
   mov  ax,bit_getpsaddress     ;passed to viorout                      ;1.2
   push fc_getpsaddress         ;VIO function number
   call viorout
VIOGETPSADDRESS_POSTDT label far                                        ;DTBB1
   ret  6                       ;return and pop parameters
VIOGETPSADDRESS endp

VIOSHIELDINIT proc far
   xor   ax,ax          ;preset AX = NO_ERROR
   push  fc_shieldinit  ;VIO function code
   push  ax             ;dummy near ret. IP                             ;@T2
   push  ds             ;save DS
   enter 10,0           ;setup BP and allocate 4 words local storage    ;1.2
   push  es             ;save registers
   push  gs             ;save FS                                   ;D549,@T80
   pusha                ;

   mov  ax,instance
   mov  ds,ax
   mov  ax,common
   mov  es,ax

   lgs   bx,ds:SGCB             ;load with SGCB ptr                ;D549,@T80

   mov   cx,bx                  ;CX <-- SGDATA[currSG].shieldRAMsem offset
   add   cx,VIO_shieldRAMsem    ;                                       ;D549

   mov   dx,ds:currPID          ;DX <-- currPID

   .repeat
     push gs                                                       ;D549,@T80
     push cx
     push wait_hi
     push wait_lo
     call DOSSEMREQUEST
   .until <ax ne ERROR_INTERRUPT>

   .if <gs:[bx].VIO_shieldPID eq 0> or  ;if VIOSHIELDINIT never called or ;@T80
   .if <gs:[bx].VIO_shieldPID eq dx>    ;if calling PID is the owner      ;@T80
     mov  gs:[bx].VIO_shieldPID,dx  ;currPID <-- SHIELDINIT and SHIELDTERM owner;@T80

     push gs                                                        ;D549,@T80
     push cx
     call DOSSEMCLEAR

     popa                       ;prepare to call subsystem
     pop   gs                   ;                                   ;D549,@T80
     pop   es                   ;
     xor   ax,ax                ;AX <-- 0:  func NOT replaced
     leave
     pop   ds
     add   sp,2
     mov   ax,bit_shieldinit    ;passed to viorout                      ;1.2
     call  viorout
     push  fc_shieldinit
     push  0
     push  ds
     enter 10,0                                                         ;1.2
     push  es
     push  gs                                                      ;D549,@T80
     pusha
   .else
     mov   [bp].rout_savAX,ERROR_VIO_SHIELD_OWNED
     push  gs                                                      ;D549,@T80
     push  cx
     call  DOSSEMCLEAR

IFDEF MMIOPH                                                            ;DTBB1
     mov   es,ds:gdtinfo                        ;ES <-- global info sel.
     mov   al,es:[SIS_MEC_TABLE].SIS_VIOMEC     ;AL <-- byte w/VIO MEC
     test  al,traceonoffmask                    ;0=OFF, non-0=ON

     .if <nz>                   ;is VIO tracing enabled?                ;@T2
       call  viopretrace
       call  vioposttrace
     .endif
ENDIF                                                                   ;DTBB1

   .endif

   popa
   pop   gs                                                         ;D549,@T80
   pop   es
   leave
   pop   ds             ;restore DS
   add   sp,4           ;remove dummy IP and function code from stack
VIOSHIELDINIT_POSTDT label far                                          ;DTBB1
   ret   4              ;return and pop parameters
VIOSHIELDINIT endp

VIOSHIELDTERM proc far
   xor   ax,ax          ;preset AX = NO_ERROR
   push  fc_shieldterm  ;VIO function code
   push  ax             ;dummy near ret. IP                             ;@T2
   push  ds             ;save DS
   enter 10,0           ;setup BP and allocate 4 words local storage    ;1.2
   push  es             ;save registers
   push  gs             ;save FS                                   ;D549,@T80
   pusha                ;

   mov  ax,instance
   mov  ds,ax
   mov  ax,common
   mov  es,ax

   mov   dx,ds:currPID          ;DX <-- currPID

   lgs   bx,ds:SGCB             ;load with SGCB ptr                ;D549,@T80
   .if <gs:[bx].VIO_shieldPID ne dx>;if VIOSHIELDINIT never called,;D549,@T80
     mov   [bp].rout_savAX,ERROR_VIO_SHIELD_OWNED

IFDEF MMIOPH                                                            ;DTBB1
     mov   es,ds:gdtinfo                        ;ES <-- global info sel.
     mov   al,es:[SIS_MEC_TABLE].SIS_VIOMEC     ;AL <-- byte w/VIO MEC
     test  al,traceonoffmask                    ;0=OFF, non-0=ON

     .if <nz>                   ;is VIO tracing enabled?                ;@T2
       call  viopretrace
       call  vioposttrace
     .endif
ENDIF                                                                   ;DTBB1

   .else
     popa                       ;prepare to call subsystem
     pop   gs                   ;                                  ;D549,@T80
     pop   es                   ;
     xor   ax,ax                ;AX <-- 0:  func NOT replaced
     leave
     pop   ds
     add   sp,2
     mov   ax,bit_shieldterm    ;passed to viorout                      ;1.2
     call  viorout
     push  fc_shieldterm
     push  0
     push  ds
     enter 10,0                                                         ;1.2
     push  es
     push  gs                                                      ;D549,@T80
     pusha
   .endif

   popa
   pop   gs                                                        ;D549,@T80
   pop   es
   leave
   pop   ds             ;restore DS
   add   sp,4           ;remove dummy IP and function code from stack
VIOSHIELDTERM_POSTDT label far                                          ;DTBB1
   ret  2                       ;return and pop parameters
VIOSHIELDTERM endp

VIOQUERYCONSOLE proc far
   mov  ax,bit_queryconsole     ;passed to viorout                      ;1.2
   push fc_queryconsole         ;VIO function number
   call viorout
VIOQUERYCONSOLE_POSTDT label far                                        ;DTBB1
   ret  4                       ;return and pop parameters
VIOQUERYCONSOLE endp

cseg ends
     end
