Image Map Image Map
Page 3 of 4 FirstFirst 1234 LastLast
Results 21 to 30 of 31

Thread: DOS Disk file access help.

  1. #21
    Join Date
    Jan 2007
    Location
    Pacific Northwest, USA
    Posts
    32,004
    Blog Entries
    18

    Default

    That's nice, but if you stick text into [ code ] brackets, I can snip it and trace through it myself, rather than enter each line manually, assemble and determine what's going on.

  2. #22

    Default

    I just pasted it so it should be possible just to cut and paste the text, I'm not sure where the code [ ] are to display code the way you have been doing it.


    ; program to load a 61440 byte file from a disk to 3000:0000
    ; program called GETFL
    ; usage: GETFL FILENAME.EXT (xxxxxxxx.xxx)



    cr equ 0dh
    lf equ 0ah
    len equ 61440
    mem equ 3000h


    prog segment

    assume csrog

    org 80h ; Command Tail
    nam_len db ? ; length
    fil_nam db 20h dup (?) ; contents

    org 100h

    start: jmp begin

    fil_han dw ? ; place for file handle


    o_err db cr, lf, 'CANNOT OPEN FILE.', cr, lf, '$'
    r_err db cr, lf, 'CANNOT READ THE FILE', cr, lf, '$'


    display macro string
    mov dx,offset string
    mov ah,09H
    int 21h
    endm


    begin: xor bx,bx
    mov bl,nam_len ; load bl with path name length
    mov fil_nam[bx],0 ; make the ASCIZ string


    lea dx,fil_nam + 1 ; point to path name

    mov ah,3dh ; open file
    mov al,02h ; for read only
    int 21h
    jc o_error
    mov fil_han,ax ; store the file handle

    mov bx,fil_han

    read: mov cx,len ; 61440 bytes to read
    push ds ; save data segment reg
    mov dx,mem
    mov ds,dx ; segment at 3000.
    xor dx,dx ; with zero offset

    mov ah,3fh ; read 61440 bytes
    int 21h
    pop ds
    jc r_error
    jmp close

    o_error:display o_err
    jmp close

    r_error:display r_err
    jmp close

    close: mov bx,fil_han ; again in case bx got altered
    mov ah,3eh ; somehow
    int 21h

    exit: mov ah,4ch
    xor al,al
    int 21H

    prog ends
    end start

  3. #23
    Join Date
    Jan 2007
    Location
    Pacific Northwest, USA
    Posts
    32,004
    Blog Entries
    18

    Default

    Okay, I think I can fix it. Normally, to post verbatim text, you place it between [code] and [/code] markers. Simple!
    Last edited by Chuck(G); August 25th, 2019 at 03:05 PM.

  4. #24
    Join Date
    Jan 2007
    Location
    Pacific Northwest, USA
    Posts
    32,004
    Blog Entries
    18

    Default

    Okay, I assembled it using MASM 6.14 and it appears to work okay. Note that you need to assemble it in "tiny" model.

    My command line was "ml /AT testa.asm"

    Here's the assembly listing:

    Code:
    Microsoft (R) Macro Assembler Version 6.14.8444		    08/25/19 16:51:44
    testa.asm						     Page 1 - 1
    
    
    				; program to load a 61440 byte file from a disk to 3000:0000
    				; program called GETFL
    				; usage: GETFL FILENAME.EXT (xxxxxxxx.xxx)
    				
     = 000D				cr 	equ 	0dh
     = 000A				lf 	equ 	0ah
     = F000				len 	equ 	61440
     = 3000				mem 	equ 	3000h
    				
     0000				prog segment
    				
    					assume cs:prog
    				
    					org 	80h 	; Command Tail
     0080 00			nam_len db 	? 	; length
     0081  0020 [			fil_nam db 	20h dup (?) ; contents
            00
           ]
    				
    					org 100h
    				
     0100				start: 
     0100  EB 31				jmp begin
    				
     0102 0000			fil_han dw 	? ; place for file handle
    				
    				
     0104 0D 0A 43 41 4E 4E		o_err 	db 	cr, lf, 'CANNOT OPEN FILE.', cr, lf, '$'
           4F 54 20 4F 50 45
           4E 20 46 49 4C 45
           2E 0D 0A 24
     011A 0D 0A 43 41 4E 4E		r_err 	db 	cr, lf, 'CANNOT READ THE FILE', cr, lf, '$'
           4F 54 20 52 45 41
           44 20 54 48 45 20
           46 49 4C 45 0D 0A
           24
    				
    				
    				display macro 	string
    					mov 	dx,offset string
    					mov 	ah,09H
    	int 	21h
    	endm
    				
    				
    				begin: 
    					xor 	bx,bx
     0133					mov 	bl,nam_len 	; load bl with path name length
     0133  33 DB				mov 	fil_nam[bx],0 	; make the ASCIZ string
     0135  2E: 8A 1E 0080 R		
     013A  2E: C6 87 0081 R			lea 	dx,fil_nam + 1 	; point to path name
           00
    				
     0140  8D 16 0082 R			mov 	ah,3dh 		; open file
    					mov 	al,02h 		; for read only
     0144  B4 3D				int 	21h
     0146  B0 02				jc 	o_error
     0148  CD 21				mov 	fil_han,ax 	; store the file handle
     014A  72 1D			
     014C  2E: A3 0102 R			mov 	bx,fil_han
    				read: 
     0150  2E: 8B 1E 0102 R			mov cx,len 		; 61440 bytes to read
     0155					push 	ds 		; save data segment reg
     0155  B9 F000				mov 	dx,mem
     0158  1E				mov 	ds,dx 		; segment at 3000.
     0159  BA 3000				xor 	dx,dx 		; with zero offset
     015C  8E DA			
     015E  33 D2				mov 	ah,3fh 		; read 61440 bytes
    					int 	21h
     0160  B4 3F				pop 	ds
     0162  CD 21				jc 	r_error
     0164  1F				jmp 	close
     0165  72 0B			
     0167  EB 12			o_error:
    					display	o_err
     0169					jmp 	close
    				
     0169  BA 0104 R	     1		mov 	dx,offset o_err
     016C  B4 09		     1		mov 	ah,09H
     016E  CD 21		     1		int 	21h
     0170  EB 09			r_error:
    					display r_err
     0172					jmp 	close
    				
     0172  BA 011A R	     1		mov 	dx,offset r_err
     0175  B4 09		     1		mov 	ah,09H
     0177  CD 21		     1		int 	21h
     0179  EB 00			close: 
    					mov 	bx,fil_han 	; again in case bx got altered
     017B					mov 	ah,3eh 		; somehow
     017B  2E: 8B 1E 0102 R			int 	21h
     0180  B4 3E			
     0182  CD 21			exit: 
    					mov 	ah,4ch
     0184					xor 	al,al
     0184  B4 4C				int 	21H
     0186  32 C0			
     0188  CD 21			prog 	ends
    					end 	start 
     018A
    Microsoft (R) Macro Assembler Version 6.14.8444		    08/25/19 16:51:44
    testa.asm						     Symbols 2 - 1
    
    
    
    
    Macros:
    
                    N a m e                 Type
    
    display  . . . . . . . . . . . .	Proc
    
    
    Segments and Groups:
    
                    N a m e                 Size     Length   Align   Combine Class
    
    prog . . . . . . . . . . . . . .	16 Bit	 018A	  Para	  Private 
    
    
    Symbols:
    
                    N a m e                 Type     Value    Attr
    
    begin  . . . . . . . . . . . . .	L Near	 0133	  prog	
    close  . . . . . . . . . . . . .	L Near	 017B	  prog	
    cr . . . . . . . . . . . . . . .	Number	 000Dh	 
    exit . . . . . . . . . . . . . .	L Near	 0184	  prog	
    fil_han  . . . . . . . . . . . .	Word	 0102	  prog	
    fil_nam  . . . . . . . . . . . .	Byte	 0081	  prog	
    len  . . . . . . . . . . . . . .	Number	 F000h	 
    lf . . . . . . . . . . . . . . .	Number	 000Ah	 
    mem  . . . . . . . . . . . . . .	Number	 3000h	 
    nam_len  . . . . . . . . . . . .	Byte	 0080	  prog	
    o_error  . . . . . . . . . . . .	L Near	 0169	  prog	
    o_err  . . . . . . . . . . . . .	Byte	 0104	  prog	
    r_error  . . . . . . . . . . . .	L Near	 0172	  prog	
    r_err  . . . . . . . . . . . . .	Byte	 011A	  prog	
    read . . . . . . . . . . . . . .	L Near	 0155	  prog	
    start  . . . . . . . . . . . . .	L Near	 0100	  prog	
    
    	   0 Warnings
    	   0 Errors

  5. #25

    Default

    Quote Originally Posted by Chuck(G) View Post
    Okay, I assembled it using MASM 6.14 and it appears to work okay.
    ,

    I have an early version of MASM on my 5155 (I will have to check which one). As I say it assembles fine, but it doesn't actually load the disk file to memory and it reports the cannot open error.

    Is the Tiny model command part of all versions of MASM ? It is not mentioned in the book which describes this method to get the file's effective address.

  6. #26
    Join Date
    Jan 2007
    Location
    Pacific Northwest, USA
    Posts
    32,004
    Blog Entries
    18

    Default

    On early versions of MASM, creating a .COM file involves invoking EXE2BIN to convert the relocatable EXE to an absolute COM file. Perhaps that's what's going on with yours.

    A bit on EXE2BIN

    Later versions of MASM and other compilers can produce .COM files directly.

  7. #27

    Default

    Quote Originally Posted by Chuck(G) View Post
    On early versions of MASM, creating a .COM file involves invoking EXE2BIN to convert the relocatable EXE to an absolute COM file. Perhaps that's what's going on with yours.

    A bit on EXE2BIN

    Later versions of MASM and other compilers can produce .COM files directly.
    I have EXE2BIN already.

    Nearly all of the programs I have written (but none have used disk access before- except using Debug to help) on the 5155, I have just left them as .EXE's and they all worked fine, so I didn't go the extra step to convert them to a .COM before using them. So I will convert this to a .COM and try again. Maybe that is the problem, why none of the programs I have attempted with disk access have worked.

  8. #28

    Default

    Converted to a .COM and it works ! That was an interesting lesson to learn.

  9. #29
    Join Date
    Aug 2006
    Location
    Chicagoland, Illinois, USA
    Posts
    6,000
    Blog Entries
    1

    Default

    I think your .exe didn't work because you may have been making assumptions in the code about what the default segment registers were set to. In a .COM, CS=DS=ES=SS, so missing something is much more likely to work by accident.
    Offering a bounty for:
    - The software "Overhead Express" (doesn't have to be original, can be a copy)
    - A working Sanyo MBC-775, Olivetti M24, or Logabax 1600
    - Music Construction Set, IBM Music Feature edition (has red sticker on front stating IBM Music Feature)

  10. #30
    Join Date
    Jan 2007
    Location
    Pacific Northwest, USA
    Posts
    32,004
    Blog Entries
    18

    Default

    In the .EXE version, you have DS=SS=ES = PSP segment, but CS will be 10h beyond that (100h locations), so the command tail isn't accessible through CS. If you're still thinking about single-segment execution as an EXE, then you need to move the file name from the PSP into your own local working storage. Other than CS and SP (if a stack segment is declared), you're expected to load your segment registers appropriately.

    e.g.
    Code:
        mov     ax,seg Data       ; my data segment
        mov     ds,ax
    The usual practice for a "small" .EXE program is to declare a separate segment for data and put all of your working storage there. Eliminates all of those nasty segment override prefixes. In fact, there are .COM programs that do this as well. Very useful when you're coding something that involves more that 64KiB of code or data.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •