     1                                  ;	SCCSID = @(#)cpmio2.asm 1.1 85/04/11
     2                                  ;TITLE	CPMIO2 - device IO for MSDOS
     3                                  ;NAME	CPMIO2
     4                                  
     5                                  [list -]
     5          ******************       warning: redefining multi-line macro `struc' [-w+pp-macro-redef-multi]
    14                              <4> [list -]
    14                              <3> [list -]
     3                              <2> 
     4                              <2> addsection DOSSTART, align=16 PUBLIC class=DOSSTART
     5                              <2> ; (no prior section) ; DOSSTART		ENDS
     6                              <2> 
     7                              <2> addsection DOSSTARTJUMP, align=1 PUBLIC class=START
     8                              <2> ; (no prior section) ; DOSSTARTJUMP		ENDS
     9                              <2> 
    10                              <2> addsection CONSTANTS, align=2 PUBLIC class=CONST
    11                              <2> ; (no prior section) ; CONSTANTS	ENDS
    12                              <2> 
    13                              <2> addsection DATA, align=2 PUBLIC class=DATA
    14                              <2> ; (no prior section) ; DATA		ENDS
    15                              <2> 
    16                              <2> addsection TABLE, align=2 PUBLIC class=TABLE
    17                              <2> ; (no prior section) ; TABLE		ENDS
    18                              <2> 
    19                              <2> addsection DOSDATATABLE, align=2 PUBLIC class=DOSDATACODE
    20                              <2> ; (no prior section) ; DOSDATATABLE		ENDS
    21                              <2> 
    22                              <2> addsection DOSDATACODE, align=1 PUBLIC class=DOSDATACODE
    23                              <2> ; (no prior section) ; DOSDATACODE		ENDS
    24                              <2> 
    25                              <2> addsection DOSBIODATA, align=2 PUBLIC class=DOSBIODATA
    26                              <2> 
    27                              <2> addsection LAST, align=16 PUBLIC class=LAST
    28                              <2> ; (no prior section) ; LAST		ENDS
    29                              <2> 
    30                              <2> group DOSGROUP DOSSTART DOSSTARTJUMP CONSTANTS DATA TABLE DOSDATATABLE DOSDATACODE DOSBIODATA LAST
     8                              <1> 
     9                              <1> %include "dcodeseg.nas"
     1                              <2> 
     2                              <2> %ifndef DCODESEGNAS
     3                              <2> %assign DCODESEGNAS 1
     4                              <2> 
     5                              <2> section DOSCODETABLE align=2 PUBLIC class=DOSCODE
     6                              <2> ; (no prior section) ; DOSCODETABLE		ENDS
     7                              <2> section DOSCODECODE align=1 PUBLIC class=DOSCODE
     8                              <2> ; (no prior section) ; DOSCODECODE		ENDS
     9                              <2> section DOSBIOCODE align=2 PUBLIC class=DOSCODE
    10                              <2> section BIOCODE	align=2 PUBLIC class=DOSCODE
    11                              <2> 
    12                              <2> %ifnidni DOSENTRYGROUP, DOSCODEGROUP
    13                              <2>  group DOSCODEGROUP DOSCODETABLE DOSCODECODE DOSBIOCODE BIOCODE
    14                              <2> %endif
    15                              <2> 
    16                              <2> %endif
    10                              <1> 
    11                              <1> section LAST
    12                              <1> ; (no prior section) ; LAST		ENDS
     8                                  ;.cref
     9                                  [list +]
    10                                  
    11                                  ;
    12                                  ; Old style CP/M 1-12 system calls to talk to reserved devices
    13                                  ;
    14                                  ;   $Std_Con_Input
    15                                  ;   $Std_Con_Output
    16                                  ;   OUTT
    17                                  ;   TAB
    18                                  ;   BUFOUT
    19                                  ;   $Std_Aux_Input
    20                                  ;   $Std_Aux_Output
    21                                  ;   $Std_Printer_Output
    22                                  ;   $Std_Con_Input_Status
    23                                  ;   $Std_Con_Input_Flush
    24                                  ;
    25                                  ;   Revision History:
    26                                  ;
    27                                  ;	AN000	 version 4.00 - Jan. 1988
    28                                  ;
    29                                  
    30                                  section DOSCODECODE
    31                                  
    32                                  ;.xcref
    33                                  [list -]
    33          ******************       warning: out: ... for DOS Version 4.00 ... [-w+user]
    33          ******************       warning: out: BPB.INC... [-w+user]
    33          ******************       warning: out: ... CLONE version build switch on ... [-w+user]
    33          ******************       warning: out: DEVSYM.INC... [-w+user]
    37                                  ;.cref
    38                                  
    39                                  ; The following routines form the console I/O group (funcs 1,2,6,7,8,9,10,11).
    40                                  ; They assume ES and DS NOTHING, while not strictly correct, this forces data
    41                                  ; references to be SS or CS relative which is desired.
    42                                  
    43                                      i_need  CARPOS,BYTE
    44                                      i_need  CHARCO,BYTE
    45                                      i_need  PFLAG,BYTE
    46                                      i_need  CurrentPDB,WORD			 ;AN000;
    47                                      i_need  InterCon,BYTE			 ;AN000;
    48                                      i_need  SaveCurFlg,BYTE			 ;AN000;
    49                                  
    50                                  
    51                                   assume nocheck, ss:DOSGROUP
    52                                  
    53                                  Break
    54                                  
    55                                  ; Inputs:
    56                                  ;	None
    57                                  ; Function:
    58                                  ;	Input character from console, echo
    59                                  ; Returns:
    60                                  ;	AL = character
    61                                  
    62                                  	procedure   D_STD_CON_INPUT,NEAR   ;System call 1
    62          ******************       warning: proc D_STD_CON_INPUT... [-w+user]
    63                                  ASSUME	DS:NOTHING,ES:NOTHING
    64                                  
    65                                   %IF  DBCS					;AN000;
    66                                  	push	word ptr [InterCon]		;AN000;
    67                                  	mov	byte [InterCon],01H			;AN000;
    68                                  	invoke	INTER_CON_INPUT_NO_ECHO 	;AN000;
    69                                  	pop	word ptr [InterCon]		;AN000;
    70                                  	pushf					;AN000;
    71                                  	push	AX				;AN000;
    72                                  	mov	byte [SaveCurFlg],0			;AN000;
    73                                  	jnz	sj0				;AN000;
    74                                  	mov	byte [SaveCurFlg],1			;AN000;
    75                                  sj0:						;AN000;
    76                                  	invoke	OUTT				;AN000;
    77                                  SaveCurFLg equ SaveCurFlg	; NASM port label
    78                                  	mov	byte [SaveCurFLg],0			;AN000;
    79                                  	pop	AX				;AN000;
    80                                  	popf					;AN000;
    81                                  	jz	D_STD_CON_INPUT			;AN000;
    82                                   %ELSE						;AN000;
    83 00000000 E8(0000)                	invoke	D_STD_CON_INPUT_NO_ECHO
    84 00000003 50                      	PUSH	AX
    85 00000004 E80400                  	invoke	OUTT
    86 00000007 58                      	POP	AX
    87                                   %ENDIF						;AN000;
    88 00000008 C3                      	return
    89                                  EndProc D_STD_CON_INPUT
    90                                  
    91                                  Break
    92                                  
    93                                  ; Inputs:
    94                                  ;	DL = character
    95                                  ; Function:
    96                                  ;	Output character to console
    97                                  ; Returns:
    98                                  ;	None
    99                                  
   100                                  	procedure   D_STD_CON_OUTPUT,NEAR   ;System call 2
   100          ******************       warning: proc D_STD_CON_OUTPUT... [-w+user]
   101                                  	public	OUTCHA			       ;AN000;
   102                                  ASSUME	DS:NOTHING,ES:NOTHING
   103                                  
   104 00000009 88D0                    	MOV	AL,DL
   105                                  
   106                                  	entry	OUTT
   107 0000000B 3C20                    	CMP	AL,20H
   108 0000000D 725F                    	JB	CTRLOUT
   109 0000000F 3C7F                    	CMP	AL,c_DEL
   110 00000011 7405                    	JZ	OUTCH
   111                                  OUTCHA: 				   ;AN000;
   112 00000013 36FE06[0000]            	INC	BYTE PTR [ss:CARPOS]
   113                                  OUTCH:
   114 00000018 1E                      	PUSH	DS
   115 00000019 56                      	PUSH	SI
   116 0000001A 36FE06[0000]            	INC	BYTE PTR [ss:CHARCO]		;invoke  statchk...
   117 0000001F 368026[0000]3F          	AND	BYTE PTR [ss:CHARCO],00111111B	;AN000; every 64th char
   118 00000025 7505                    	JNZ	OUTSKIP
   119 00000027 50                      	PUSH	AX
   120 00000028 E8(0000)                	invoke	STATCHK
   121 0000002B 58                      	POP	AX
   122                                  OUTSKIP:
   123 0000002C E8(0000)                	invoke	RAWOUT				;output the character
   124 0000002F 5E                      	POP	SI
   125 00000030 1F                      	POP	DS
   126                                   assume ds:nothing
   127                                   %IF  DBCS				;AN000;
   128                                  	TEST	byte [SaveCurFlg],01H	;AN000;print but no cursor adv? 2/13/KK
   129                                  	retnz				;AN000;if so then do not send to prt2/13/KK
   130                                   %ENDIF
   131 00000031 36F606[0000]FF          	TEST	BYTE PTR [ss:PFLAG],-1
   132 00000037 74CF                    	retz
   133 00000039 53                      	PUSH	BX
   134 0000003A 1E                      	PUSH	DS
   135 0000003B 56                      	PUSH	SI
   136 0000003C BB0100                  	MOV	BX,1
   137 0000003F E8(0000)                	invoke	GET_IO_SFT
   138 00000042 7224                    	JC	TRIPOPJ
   139 00000044 8B5C05                  	MOV	BX,[SI + sf_flags]
   140 00000047 F7C30080                	TEST	BX,sf_isnet			; output to NET?
   141 0000004B 751B                    	JNZ	TRIPOPJ 			; if so, no echo
   142 0000004D F7C38000                	TEST	BX,devid_device 		; output to file?
   143 00000051 7415                    	JZ	TRIPOPJ 			; if so, no echo
   144 00000053 BB0400                  	MOV	BX,4
   145 00000056 E8(0000)                	invoke	GET_IO_SFT
   146 00000059 720D                    	JC	TRIPOPJ
   147 0000005B F744050008              	TEST	word [SI + sf_flags],sf_net_spool	; StdPrn redirected?
   148 00000060 7409                    	JZ	LISSTRT2J			; No, OK to echo
   149 00000062 36C606[0000]00          	MOV	BYTE PTR [ss:PFLAG],0		; If a spool, NEVER echo
   150                                  TRIPOPJ:
   151 00000068 E98B00                  	JMP	TRIPOP
   152                                  
   153                                  LISSTRT2J:
   154 0000006B E98500                  	JMP	LISSTRT2
   155                                  
   156                                  CTRLOUT:
   157 0000006E 3C0D                    	CMP	AL,c_CR
   158 00000070 7420                    	JZ	ZERPOS
   159 00000072 3C08                    	CMP	AL,c_BS
   160 00000074 7428                    	JZ	BACKPOS
   161 00000076 3C09                    	CMP	AL,c_HT
   162 00000078 759E                    	JNZ	OUTCH
   163 0000007A 36A0[0000]              	MOV	AL,[ss:CARPOS]
   164 0000007E 0CF8                    	OR	AL,0F8H
   165 00000080 F6D8                    	NEG	AL
   166                                  
   167                                  	entry	TAB
   168                                  
   169 00000082 51                      	PUSH	CX
   170 00000083 88C1                    	MOV	CL,AL
   171 00000085 B500                    	MOV	CH,0
   172 00000087 E307                    	JCXZ	POPTAB
   173                                  TABLP:
   174 00000089 B020                    	MOV	AL," "
   175 0000008B E87DFF                  	invoke	OUTT
   176 0000008E E2F9                    	LOOP	TABLP
   177                                  POPTAB:
   178 00000090 59                      	POP	CX
   179 00000091 C3                      	return
   180                                  
   181                                  ZERPOS:
   182 00000092 36C606[0000]00          	MOV	BYTE PTR [ss:CARPOS],0
   183 00000098 E97DFF                  	JMP	OUTCH
   184 0000009B E96DFF                  OUTJ:	JMP	OUTT
   185                                  
   186                                  BACKPOS:
   187 0000009E 36FE0E[0000]            	DEC	BYTE PTR [ss:CARPOS]
   188 000000A3 E972FF                  	JMP	OUTCH
   189                                  
   190                                  	entry	BUFOUT
   191 000000A6 3C20                    	CMP	AL," "
   192 000000A8 73F1                    	JAE	OUTJ		;Normal char
   193 000000AA 3C09                    	CMP	AL,9
   194 000000AC 74ED                    	JZ	OUTJ		;OUT knows how to expand tabs
   195                                  
   196                                  ;DOS 3.3  7/14/86
   197 000000AE 3C15                    	CMP	AL,"U"-"@"      ; turn ^U to section symbol
   198 000000B0 740D                    	JZ	CTRLU
   199 000000B2 3C14                    	CMP	AL,"T"-"@"      ; turn ^T to paragraph symbol
   200 000000B4 7409                    	JZ	CTRLU
   201                                  NOT_CTRLU:
   202                                  ;DOS 3.3  7/14/86
   203                                  
   204 000000B6 50                      	PUSH	AX
   205 000000B7 B05E                    	MOV	AL,"^"
   206 000000B9 E84FFF                  	invoke	OUTT		;Print '^' before control chars
   207 000000BC 58                      	POP	AX
   208 000000BD 0C40                    	OR	AL,40H		;Turn it into Upper case mate
   209                                  CTRLU:
   210 000000BF E849FF                  	invoke	OUTT
   211 000000C2 C3                      	return
   212                                  EndProc D_STD_CON_OUTPUT
   213                                  
   214                                  Break
   215                                  
   216                                  ; Inputs:
   217                                  ;	None
   218                                  ; Function:
   219                                  ;	Returns character from aux input
   220                                  ; Returns:
   221                                  ;	Character in AL
   222                                  
   223                                  	procedure   D_STD_AUX_INPUT,NEAR   ;System call 3
   223          ******************       warning: proc D_STD_AUX_INPUT... [-w+user]
   224                                  ASSUME	DS:NOTHING,ES:NOTHING
   225                                  
   226 000000C3 E8(0000)                	invoke	STATCHK
   227 000000C6 BB0300                  	MOV	BX,3
   228 000000C9 E8(0000)                	invoke	GET_IO_SFT
   229 000000CC 72F4                    	retc
   230 000000CE EB03                    	JMP	SHORT TAISTRT
   231                                  AUXILP:
   232 000000D0 E8(0000)                	invoke	SPOOLINT
   233                                  TAISTRT:
   234 000000D3 B401                    	MOV	AH,1
   235 000000D5 E8(0000)                	invoke	IOFUNC
   236 000000D8 74F6                    	JZ	AUXILP
   237 000000DA 30E4                    	XOR	AH,AH
   238 000000DC E8(0000)                	invoke	IOFUNC
   239 000000DF C3                      	return
   240                                  EndProc D_STD_AUX_INPUT
   241                                  
   242                                  Break
   243                                  
   244                                  ; Inputs:
   245                                  ;	Character in DL
   246                                  ; Function:
   247                                  ;	Output character to aux output
   248                                  ; Returns:
   249                                  ;	Nothing
   250                                  
   251                                  	procedure   D_STD_AUX_OUTPUT,NEAR   ;System call 4
   251          ******************       warning: proc D_STD_AUX_OUTPUT... [-w+user]
   252                                  ASSUME	DS:NOTHING,ES:NOTHING
   253                                  
   254 000000E0 53                      	PUSH	BX
   255 000000E1 BB0300                  	MOV	BX,3
   256 000000E4 EB04                    	JMP	SHORT SENDOUT
   257                                  
   258                                  EndProc D_STD_AUX_OUTPUT
   259                                  
   260                                  Break
   261                                  
   262                                  ; Inputs:
   263                                  ;	DL = Character
   264                                  ; Function:
   265                                  ;	Output the character to the list device
   266                                  ; Returns:
   267                                  ;	None
   268                                  
   269                                  	procedure   D_STD_PRINTER_OUTPUT,NEAR   ;System call 5
   269          ******************       warning: proc D_STD_PRINTER_OUTPUT... [-w+user]
   270                                  ASSUME	DS:NOTHING,ES:NOTHING
   271                                  
   272 000000E6 53                      	PUSH	BX
   273 000000E7 BB0400                  	MOV	BX,4
   274                                  
   275                                  SENDOUT:
   276 000000EA 88D0                    	MOV	AL,DL
   277 000000EC 50                      	PUSH	AX
   278 000000ED E8(0000)                	invoke	STATCHK
   279 000000F0 58                      	POP	AX
   280 000000F1 1E                      	PUSH	DS
   281 000000F2 56                      	PUSH	SI
   282                                  LISSTRT2:
   283 000000F3 E8(0000)                	invoke	RAWOUT2
   284                                  TRIPOP:
   285 000000F6 5E                      	POP	SI
   286 000000F7 1F                      	POP	DS
   287                                   assume ds:nothing
   288 000000F8 5B                      	POP	BX
   289 000000F9 C3                      	return
   290                                  EndProc D_STD_PRINTER_OUTPUT
   291                                  
   292                                  Break
   293                                  
   294                                  ; Inputs:
   295                                  ;	None
   296                                  ; Function:
   297                                  ;	Check console input status
   298                                  ; Returns:
   299                                  ;	AL = -1 character available, = 0 no character
   300                                  
   301                                  	procedure   D_STD_CON_INPUT_STATUS,NEAR	 ;System call 11
   301          ******************       warning: proc D_STD_CON_INPUT_STATUS... [-w+user]
   302                                  ASSUME	DS:NOTHING,ES:NOTHING
   303                                  
   304 000000FA E8(0000)                	invoke	STATCHK
   305 000000FD B000                    	MOV	AL,0			; no xor!!
   306 000000FF 74F8                    	retz
   307 00000101 0CFF                    	OR	AL,-1
   308 00000103 C3                      	return
   309                                  EndProc D_STD_CON_INPUT_STATUS
   310                                  
   311                                  Break
   312                                  
   313                                  ; Inputs:
   314                                  ;	AL = DOS function to be called after flush (1,6,7,8,10)
   315                                  ; Function:
   316                                  ;	Flush console input buffer and perform call in AL
   317                                  ; Returns:
   318                                  ;	Whatever call in AL returns or AL=0 if AL was not 1,6,7,8 or 10
   319                                  
   320                                  	procedure   D_STD_CON_INPUT_FLUSH,NEAR	;System call 12
   320          ******************       warning: proc D_STD_CON_INPUT_FLUSH... [-w+user]
   321                                  ASSUME	DS:NOTHING,ES:NOTHING
   322                                  
   323 00000104 50                      	PUSH	AX
   324 00000105 52                      	PUSH	DX
   325 00000106 31DB                    	XOR	BX,BX
   326 00000108 E8(0000)                	invoke	GET_IO_SFT
   327 0000010B 7205                    	JC	BADJFNCON
   328 0000010D B404                    	MOV	AH,4
   329 0000010F E8(0000)                	invoke	IOFUNC
   330                                  
   331                                  BADJFNCON:
   332 00000112 5A                      	POP	DX
   333 00000113 58                      	POP	AX
   334 00000114 88C4                    	MOV	AH,AL
   335 00000116 3C01                    	CMP	AL,1
   336 00000118 7413                    	JZ	REDISPJ
   337 0000011A 3C06                    	CMP	AL,6
   338 0000011C 740F                    	JZ	REDISPJ
   339 0000011E 3C07                    	CMP	AL,7
   340 00000120 740B                    	JZ	REDISPJ
   341 00000122 3C08                    	CMP	AL,8
   342 00000124 7407                    	JZ	REDISPJ
   343 00000126 3C0A                    	CMP	AL,10
   344 00000128 7403                    	JZ	REDISPJ
   345 0000012A B000                    	MOV	AL,0
   346 0000012C C3                      	return
   347                                  
   348                                  REDISPJ:
   349                                   %IF  DBCS			  ;AN000;
   350                                  	mov	ds,[CurrentPDB]   ;AN000;
   351                                  				  ;AN000; set DS same as one from COMMAND entry
   352                                   %ENDIF
   353 0000012D FA                      	CLI
   354 0000012E E9(0000)                	transfer    REDISP
   355                                  EndProc D_STD_CON_INPUT_FLUSH
   356                                  
   357                                      END
