;       SCCSID = @(#)cpmio2.asm 6.3 91/08/11
;       SCCSID = @(#)cpmio2.asm 6.3 91/08/11
TITLE   CPMIO2 - device IO for MSDOS
NAME    CPMIO2

;
; Old style CP/M 1-12 system calls to talk to reserved devices
;
;   $Std_Con_Input
;   $Std_Con_Output
;   OUTT
;   TAB
;   BUFOUT
;   $Std_Aux_Input
;   $Std_Aux_Output
;   $Std_Printer_Output
;   $Std_Con_Input_Status
;   $Std_Con_Input_Flush
;
;   Revision History:
;
;       AN000    version 4.00 - Jan. 1988
; 75149 Change Team 10/28/93 Added printer output flag to STD_PRINTER_OUTPUT

.xlist
include v86seg.inc
.xcref
include basemaca.inc
include osmaca.inc
include oldmaca.inc
include demmac.inc
include dossymc.inc
include devsym.inc
include demdbcs.inc
include mvdmexp.inc
include mi.inc
include demsvc.inc
include dos3dev.inc
include vector.inc
.cref
.list
        CpuMode 386


V86CODE    SEGMENT
        ASSUME  CS:V86GROUP

        EXTRN   Raw_Con_In:NEAR
        EXTRN   RawOut:NEAR
        EXTRN   Get_IO_SFT:NEAR
        EXTRN   IOFunc:NEAR
        extrn   VMcheck_handle:NEAR          ;mdr
        extrn   fl_printer_output:BYTE                                   ;75149

; The following routines form the console I/O group (funcs 1,2,6,7,8,9,10,11).
; They assume ES and DS NOTHING, while not strictly correct, this forces data
; references to be SS or CS relative which is desired.



Break

; Inputs:
;       None
; Function:
;       Input character from console, echo
; Returns:
;       AL = character

        procedure   $STD_CON_INPUT,NEAR   ;System call 1
ASSUME  DS:NOTHING,ES:NOTHING

        mov     bx,0                   ; mdr
        call    VMcheck_handle         ; mdr return if stdin is DOS handle

        call    Get_IO_SFT              ; mdr setup dev pointer
        invoke  RAW_CON_IN
        mov     bx,1
        push    ax
        invoke  RAWOUT
        pop     ax
        return
EndProc $STD_CON_INPUT

Break

; Inputs:
;       DL = character
; Function:
;       Output character to console
; Returns:
;       None

        procedure   $STD_CON_OUTPUT,NEAR   ;System call 2
ASSUME  DS:NOTHING,ES:NOTHING

        mov     al,dl
        mov     bx,1
        invoke  RAWOUT                          ;output the character
        return

EndProc $STD_CON_OUTPUT

Break

; Inputs:
;       None
; Function:
;       Returns character from aux input
; Returns:
;       Character in AL

        procedure   $STD_AUX_INPUT,NEAR   ;System call 3
ASSUME  DS:NOTHING,ES:NOTHING

        mov     bx,3                   ; mdr
        call    VMcheck_handle         ; mdr return if stdaux is DOS handle

        call    Get_IO_SFT              ; mdr setup dev pointer
        jmp     AUXTRY

AUXILP:
        invoke  SPOOLINT
AUXTRY:
        MOV     AH,1
        invoke  IOFUNC
        jz      AUXILP
        XOR     AH,AH
        invoke  IOFUNC
        return

EndProc $STD_AUX_INPUT

Break

; Inputs:
;       Character in DL
; Function:
;       Output character to aux output
; Returns:
;       Nothing

        procedure   $STD_AUX_OUTPUT,NEAR   ;System call 4
ASSUME  DS:NOTHING,ES:NOTHING

        mov     al,dl
        mov     bx,3                   ; mdr check stdaux
        invoke  RAWOUT
        ret

EndProc $STD_AUX_OUTPUT

Break

; Inputs:
;       DL = Character
; Function:
;       Output the character to the list device
; Returns:
;       None

        procedure   $STD_PRINTER_OUTPUT,NEAR   ;System call 5
ASSUME  DS:NOTHING,ES:NOTHING
        mov     al,dl
        mov     bx,4                   ; mdr check stdprn
        mov     fl_printer_output,1    ; set printer output flag          75149
        invoke  RAWOUT
        return

EndProc $STD_PRINTER_OUTPUT

Break

; Inputs:
;       None
; Function:
;       Check console input status
;       AL = -1 character available, = 0 no character

        procedure   $STD_CON_INPUT_STATUS,NEAR   ;System call 11
ASSUME  DS:NOTHING,ES:NOTHING

        mov     bx,0                   ; mdr
        call    VMcheck_handle         ; mdr return if stdin is DOS handle

        call    GET_IO_SFT              ; mdr setup dev pointer
        MOV     AH,1                    ; mdr see if char available
        invoke  IOFUNC
        xor     al,al                   ; mdr zero out AL
        jz      no_char_avail           ; mdr if no char avail then return
        OR      AL,-1                   ; mdr else set AL to -1
no_char_avail:
        return

EndProc $STD_CON_INPUT_STATUS

Break

; Inputs:
;       AL = DOS function to be called after flush (1,6,7,8,10)
; Function:
;       Flush console input buffer and perform call in AL
; Returns:
;       Whatever call in AL returns or AL=0 if AL was not 1,6,7,8 or 10

        procedure   $STD_CON_INPUT_FLUSH,NEAR   ;System call 12
ASSUME  DS:NOTHING,ES:NOTHING

        mov     bx,0                   ; mdr
        call    VMcheck_handle         ; mdr return if stdin is DOS handle

        PUSH    AX
        PUSH    DX
        invoke  GET_IO_SFT
        MOV     AH,4
        invoke  IOFUNC

        POP     DX
        POP     AX
        MOV     AH,AL
        CMP     AL,1
        JZ      REDISPJ
        CMP     AL,6
        JZ      REDISPJ
        CMP     AL,7
        JZ      REDISPJ
        CMP     AL,8
        JZ      REDISPJ
        CMP     AL,10
        JZ      REDISPJ
        MOV     AL,0
        return

REDISPJ:
        CLI
        transfer    REDISP
EndProc $STD_CON_INPUT_FLUSH


;
; SpoolInt - signal processes that the DOS is truly idle.  We are allowed to
; do this ONLY if we are working on a 1-12 system call AND if we are not in
; the middle of an INT 24.
;
procedure   SPOOLINT,NEAR

        PUSHF
        INT     int_spooler
        POPF
        return
EndProc SPOOLINT


V86CODE    ENDS
    END
