Microsoft (R) Macro Assembler Version 5.10                  5/16/24 23:40:13
CP/DOS  DosOpen  mapper                                     Page     1-1


				page 80,132
				;0
				title CP/DOS  DosOpen  mapper
				
				
 0000				FileAttributeSegment   segment word public 'fat'
				
						       public	FileAttributeTable
				
 0000  0064[			FileAttributeTable     dw     100  dup(0)
	   0000			
			 ]	
				
				
 00C8				FileAttributeSegment	ends
				
				
 0000				dosxxx	segment byte public 'dos'
					assume	cs:dosxxx,ds:nothing,es:nothing,ss:nothing
				;
				; ************************************************************************* *
				; *
				; *	 MODULE: DosOpen
				; *
				; *	 FILE NAME: DosOpen.ASM
				; *
				; *	 FUNCTION: This module creates the specified file (if necessary),
				; *		   and opens it.  If the file name is a device then the
				; *		   handle returned will be a device handle.  The high order
				; *		   byte of the open flag is ignored because PC/DOS does not
				; *		   support a word long open mode.  Invalid parameters are
				; *		   reported as general failures because there are no error
				; *		   codes defined at this time.
				; *
				; *	 CALLING SEQUENCE:
				; *
				; *		   PUSH@ ASCIIZ  FileName	   ;  File path name
				; *		   PUSH@ WORD	 FileHandle	   ;  New file's handle
				; *		   PUSH@ WORD	 ActionTaken	   ;  Action taken
				; *		   PUSH  DWORD	 FileSize	   ;  File primary allocation
				; *		   PUSH  WORD	 FileAttribute	   ;  File attribute
				; *		   PUSH  WORD	 OpenFlag	   ;  Open function type
				; *		   PUSH  WORD	 OpenMode	   ;  Open mode of the file
				; *		   PUSH@ DWORD	 0		   ;  Reserved (must be zero)
				; *		   CALL DosOpen
				; *
				; *	 RETURN SEQUENCE:
				; *
				; *		   IF ERROR (AX not = 0)
				; *
				; *		      AX = Error Code:
				; *
				; *		      o   Invalid parameter(s)
				; *
				; *		      o   Insufficient disk space available
				; *
				; *		      o   Insufficient resources (i.e., file handles)
				; *
				; *
				; *	 MODULES CALLED:  DOS int 21H function 3DH
				; *			  DOS int 21H function 3EH
				; *			  DOS int 21H function 40H
				; *			  DOS int 21H function 42H
				; *			  DOS int 21H function 43H
				; *
				; *************************************************************************
				;
					public	DosOpen
					.sall
					.list
				
 = 0001				ACT_FileExisted 	equ	1
 = 0002				ACT_FileCreated 	equ	2
				
				
				str	struc
Microsoft (R) Macro Assembler Version 5.10                  5/16/24 23:40:13
CP/DOS  DosOpen  mapper                                     Page     1-2


 0000  0000			old_bp		dw     ?
 0002  00000000			return		dd     ?
 0006  00000000			resrv34 	dd     ?     ; reserved
 000A  0000			OpenMode	dw     ?     ; open mode
 000C  0000			OpenFlag	dw     ?     ; open function type (1=Open only if already exist)
 000E  0000			OpenFileAttr	dw     ?     ; file attribute
 0010  00000000			FileSize	dd     ?     ; file allocation size
 0014  00000000			acttak34	dd     ?     ; action taken
 0018  00000000			FileHandlePtr	dd     ?     ; New file handler
 001C  00000000			FileNamePtr	dd     ?     ; file name pointer
 0020				str	ends
				
				;
 0000				DosOpen  proc	far
					Enter	DosOpen 	       ; save registers
 000C  83 EC 02				sub	sp,2		       ; allocate space on the stack
 =-0002				SaveArea	equ	-2
				
				; Check to see if we are trying to open a DASD device.	If so, we must do
				; something unique as PC-DOS does not support this behavior.
				; Return a dummy DASD file handle.  This used by IOCTL category 8 option.
				
 000F  F7 46 0A 8000			test	[bp].OpenMode,08000h   ; DASD open ?
 0014  74 2B				jz	FileOpenRequest        ; branch if file open
				
 0016  C5 76 1C				lds	si,[bp].FileNamePtr    ; convert device name to upper case
 0019  8A 04				mov	al,ds:[si]
 001B  3C 61				cmp	al,'a'
 001D  72 06				jc	NoFold
 001F  3C 7B				cmp	al,'z'+1
 0021  73 02				jnc	NoFold
				
 0023  04 E0				add	al,'A' - 'a'
				
 0025				NoFold:
 0025  2C 41				sub	al,'A'
 0027  72 12				jc	BadDASDName	       ; jump if bad DASD name
				
 0029  3C 1B				cmp	al,27
 002B  73 0E				jnc	BadDASDName
				
 002D  32 E4				xor	ah,ah		       ; drive number from 0 to 25
 002F  40				inc	ax		       ;		   1 to 26
 0030  40				inc	ax		       ;		   2 to 27
 0031  F7 D8				neg	ax		       ;		   -2 to -27
				
 0033  C5 76 18				lds	si,[bp].FileHandlePtr
 0036  89 04				mov	ds:[si],ax	       ; save dasd dummy device handle
 0038  E9 0106 R			jmp	GoodExit	       ; in return data area and return
				
 003B				BadDASDName:
 003B  B8 0003				mov	ax,3		       ; set error code
 003E  E9 0108 R			jmp	ErrorExit	       ; return
				
				
				;  Query the file attribute to determine if file exists
				
				
 0041				FileOpenRequest:
 0041  C5 56 1C				lds	dx,dword ptr [bp].FileNamePtr ; load asciiz string address
 0044  B8 4300				mov	ax,04300h	      ; query file mode
 0047  CD 21				int	21h		      ; get file mode
 0049  73 08				jnc	SaveAttribute	      ; file does exist
				
 004B  3D 0002				cmp	ax,00002h	      ; check if file does not exist error
 004E  74 43				je	dne34		      ; go here if does not exist
				
 0050  E9 0108 R			jmp	erret34 	      ; error return
				
 0053				SaveAttribute:
 0053  89 4E FE				mov	[bp].SaveArea,cx
				
				;  File exists - determine what to do
				
 0056  C5 76 14				lds	si,dword ptr [bp].acttak34 ; Load action taken pointer
 0059  C7 04 0001			mov	word ptr[si],ACT_FileExisted   ; Indicate that file existed
Microsoft (R) Macro Assembler Version 5.10                  5/16/24 23:40:13
CP/DOS  DosOpen  mapper                                     Page     1-3


 005D  8B 46 0C				mov	ax,[bp].OpenFlag   ; load open flag
 0060  25 0003				and	ax,00003h	   ; mask off the replace and open flags
 0063  3D 0003				cmp	ax,00003h	   ; check if both are requested
 0066  74 0A				je	nxt134		   ; error - invalid parm
				
 0068  3D 0001				cmp	ax,00001h	   ; check if file is to be opened
 006B  74 0B				je	opn34		   ; file should be opened
				
 006D  3D 0002				cmp	ax,00002h	   ; check if file should be replaced
 0070  74 32				je	creat34 	   ; file should be replaced
				
 0072				nxt134:;
 0072  B8 000C				mov	ax,0000ch	   ; report general
 0075  E9 0108 R			jmp	erret34 	   ;   failure
				
				;
 0078				opn34:;
				
				;  set the file attribute ( *** commented to fix mapper problem Pylee 6/10
				;
				;	lds	dx,dword ptr [bp].FileNamePtr ; load asciiz string address
				;	mov	cx,[bp].OpenFileAttr	; load the file attribute
				;	mov	ax,04301h	   ; change file mode
				;	int	21h		   ; get file mode
				;	jnc	nxto34		   ; continue good return
				;	jmp	erret34 	   ; error retrun
				
 0078				nxto34:;
				
				;  open the file
				
 0078  C5 76 14				lds	si,dword ptr [bp].acttak34 ; load action taken pointer
 007B  C7 04 0000			mov	word ptr [si],00h     ; clear action reported flag
 007F  C5 56 1C				lds	dx,dword ptr [bp].FileNamePtr ; load asciiz string address
 0082  8B 46 0A				mov	ax,[bp].OpenMode   ; load the  file mode
				
 0085  B4 3D				mov	ah,03dh 	   ; load opcode
 0087  CD 21				int	21h		   ; open file
 0089  72 7D				jc	ErrorExit	   ; error return
				
 008B				FileWasThere:
 008B  C5 76 18				lds	si,dword ptr [bp].FileHandlePtr ; load file handle address
 008E  89 04				mov	[si],ax 	   ; save file handle
 0090  EB 64 90				jmp	PutAwayAttribute   ; normal return
				
 0093				dne34:;
				
				;  File does not exist - determine what to do
				
 0093  8B 46 0C				mov	ax,[bp].OpenFlag   ; load open flag
 0096  25 0010				and	ax,00010h	   ; check create
 0099  3D 0010				cmp	ax,00010h	   ;		 and open file flag
 009C  74 06				je	creat34 	   ; go create the file
				
 009E  B8 000C				mov	ax,0000ch	   ; report general failure
 00A1  EB 65 90				jmp	erret34 	   ;		     if create not requested
				
 00A4				creat34:;
				
				;  file did not exist so it was created or replacement was requested
				
 00A4  C5 76 14				lds	si,dword ptr [bp].acttak34 ; load action taken pointer
 00A7  C7 04 0002			mov	word ptr [si],ACT_FileCreated  ; file created -  action reported
 00AB  C5 56 1C				lds	dx,dword ptr [bp].FileNamePtr ; load asciiz string address
 00AE  8B 4E 0E				mov	cx,[bp].OpenFileAttr	; set file attribute
				
 00B1  B4 3C				mov	ah,03ch
 00B3  CD 21				int	21h		   ; create the file
 00B5  72 51				jc	erret34 	   ; error return
				
 00B7  C5 76 18				lds	si,dword ptr [bp].FileHandlePtr ; load file handle address
 00BA  89 04				mov	[si],ax 		   ; save file handle
				;
				; set file length
				;
 00BC  C4 56 10				les	dx,[bp].FileSize
Microsoft (R) Macro Assembler Version 5.10                  5/16/24 23:40:13
CP/DOS  DosOpen  mapper                                     Page     1-4


 00BF  8C C1				mov	cx,es
 00C1  8B D8				mov	bx,ax		   ; load file handle
				
 00C3  B8 4202				mov	ax,04202h	   ; load opcode
 00C6  CD 21				int	21h		   ; move file pointer
 00C8  72 3E				jc	erret34 	   ; error return
				
 00CA				len134:;
 00CA  C5 76 18				lds	si,dword ptr [bp].FileHandlePtr ; load file handle address
 00CD  8B 1C				mov	bx,[si] 	   ; load file handle
 00CF  C5 56 14				lds	dx,dword ptr [bp].acttak34
 00D2  2B C9				sub	cx,cx
				
 00D4  B4 40				mov	ah,040h
 00D6  CD 21				int	21h		   ; write 0 length record
 00D8  72 2E				jc	erret34 	   ; error return
				
				;
 00DA				len234:;
				;
				;  close and reopen the file to make the length permanent
				;
 00DA  C5 76 18				lds	si,dword ptr [bp].FileHandlePtr ; load file handle address
 00DD  8B 1C				mov	bx,[si] 		   ; load file handle
 00DF  B4 3E				mov	ah,03eh
 00E1  CD 21				int	21h
 00E3  72 23				jc	erret34 	   ; error return
				
 00E5  C5 56 1C				lds	dx,dword ptr [bp].FileNamePtr ; load asciiz string address
 00E8  8B 46 0A				mov	ax,[bp].OpenMode   ; load the  file mode
 00EB  B4 3D				mov	ah,03dh 	   ;
 00ED  CD 21				int	21h		   ; open the file
 00EF  72 17				jc	erret34 	   ; error return
				
 00F1  C5 76 18				lds	si,dword ptr [bp].FileHandlePtr ; load file handle address
 00F4  89 04				mov	[si],ax 	   ; save file handle
				
 00F6				PutAwayAttribute:		   ; save file attribute for other mapper
 00F6  8B D8				mov	bx,ax		   ; calls
 00F8  03 DB				add	bx,bx
				
 00FA  B8 ---- R			mov	ax,seg FileAttributeSegment
 00FD  8E D8				mov	ds,ax
					assume	ds:FileAttributeSegment
				
 00FF  8B 46 FE				mov	ax,[bp].SaveArea
 0102  89 87 0000 R			mov	FileAttributeTable[bx],ax	; save file attribute
				
 0106				GoodExit:
 0106  2B C0				sub	ax,ax		   ; set good return code
				
 0108				erret34:;
 0108				ErrorExit:
 0108  83 C4 02				add	sp,2		   ; deallocate space
					mexit			   ; restore registers
 0117  CA 001A				ret	size str - 6	   ; return
				
 011A				DosOpen  endp
				
 011A				dosxxx	ends
				
					end

Microsoft (R) Macro Assembler Version 5.10                  5/16/24 23:40:13
CP/DOS  DosOpen  mapper                                     Symbols-1


Macros:

		N a m e			Lines

ENTER  . . . . . . . . . . . . .  	   3
MEXIT  . . . . . . . . . . . . .  	   3
POPAL  . . . . . . . . . . . . .  	   9
PUSHAL . . . . . . . . . . . . .  	   9

Structures and Records:

                N a m e                 Width   # fields
                                        Shift   Width   Mask    Initial

STR  . . . . . . . . . . . . . .  	0020	000A
  OLD_BP . . . . . . . . . . . .  	0000
  RETURN . . . . . . . . . . . .  	0002
  RESRV34  . . . . . . . . . . .  	0006
  OPENMODE . . . . . . . . . . .  	000A
  OPENFLAG . . . . . . . . . . .  	000C
  OPENFILEATTR . . . . . . . . .  	000E
  FILESIZE . . . . . . . . . . .  	0010
  ACTTAK34 . . . . . . . . . . .  	0014
  FILEHANDLEPTR  . . . . . . . .  	0018
  FILENAMEPTR  . . . . . . . . .  	001C

Segments and Groups:

                N a m e         	Length	 Align	Combine Class

DOSXXX . . . . . . . . . . . . .  	011A	BYTE	PUBLIC	'DOS'
FILEATTRIBUTESEGMENT . . . . . .  	00C8	WORD	PUBLIC	'FAT'

Symbols:            

                N a m e         	Type	 Value	 Attr

ACT_FILECREATED  . . . . . . . .  	NUMBER	0002	
ACT_FILEEXISTED  . . . . . . . .  	NUMBER	0001	

BADDASDNAME  . . . . . . . . . .  	L NEAR	003B	DOSXXX

CREAT34  . . . . . . . . . . . .  	L NEAR	00A4	DOSXXX

DNE34  . . . . . . . . . . . . .  	L NEAR	0093	DOSXXX
DosOpen  . . . . . . . . . . . .  	F PROC	0000	DOSXXX	Global	Length = 011A

ERRET34  . . . . . . . . . . . .  	L NEAR	0108	DOSXXX
ERROREXIT  . . . . . . . . . . .  	L NEAR	0108	DOSXXX

FileAttributeTable . . . . . . .  	L WORD	0000	FILEATTRIBUTESEGMENT	Global	Length = 0064
FILEOPENREQUEST  . . . . . . . .  	L NEAR	0041	DOSXXX
FILEWASTHERE . . . . . . . . . .  	L NEAR	008B	DOSXXX

GOODEXIT . . . . . . . . . . . .  	L NEAR	0106	DOSXXX

LEN134 . . . . . . . . . . . . .  	L NEAR	00CA	DOSXXX
LEN234 . . . . . . . . . . . . .  	L NEAR	00DA	DOSXXX

NOFOLD . . . . . . . . . . . . .  	L NEAR	0025	DOSXXX
NXT134 . . . . . . . . . . . . .  	L NEAR	0072	DOSXXX
NXTO34 . . . . . . . . . . . . .  	L NEAR	0078	DOSXXX

OPN34  . . . . . . . . . . . . .  	L NEAR	0078	DOSXXX

PUTAWAYATTRIBUTE . . . . . . . .  	L NEAR	00F6	DOSXXX

SAVEAREA . . . . . . . . . . . .  	NUMBER	-0002	
SAVEATTRIBUTE  . . . . . . . . .  	L NEAR	0053	DOSXXX

@CPU . . . . . . . . . . . . . .  	TEXT  0101h		
@FILENAME  . . . . . . . . . . .  	TEXT  open		
@VERSION . . . . . . . . . . . .  	TEXT  510		

Microsoft (R) Macro Assembler Version 5.10                  5/16/24 23:40:13

CP/DOS  DosOpen  mapper                                     Symbols-2






    335 Source  Lines
    359 Total   Lines
     45 Symbols

  47448 + 300645 Bytes symbol space free

      0 Warning Errors
      0 Severe  Errors
