Opening a file in DOS

Page 1/3
| 2 | 3

By Daemos

Prophet (2170)

Daemos's picture

02-02-2011, 19:53

Sorry to bother again about this subject but I still am unable to load files from disk under MSXDOS Eek!
I have done the prerequisite research on how the calls work etc. I have also studied some sample code and basicly what I don't understand are two things:

1.) How do I tell DOS the name of the file.
2.) Where in the RAM is the file being stored for further processing

So here is some code to show you what part I understand and what part not:


org &h0100

openf: equ &h0f

ld C,openf
ld DE,(the FCB adress, huh??)
call 5 ; do the call

ret

I have looked up about this FCB adress thingy and the sample code also keeps it unclear. The FCB adress tells DOS about the file location on the disk and in case of a successfull execution of this very small routine the file should then be located somewhere in the RAM?

Login or register to post comments

By Manuel

Ascended (19691)

Manuel's picture

02-02-2011, 20:34

Daemos: what would happen with a file larger than RAM size?

By commodorejohn

Expert (92)

commodorejohn's picture

02-02-2011, 20:45

The file isn't loaded into RAM when you open it. You have to do that yourself by setting the transfer address and then manually reading a number of records into memory. ("Records" here being CP/M's native 128-byte sector size.) MSX Assembly Page has a couple references for MSX-DOS function calls.

By WORP3

Paladin (864)

WORP3's picture

02-02-2011, 20:46

See: http://www.msx.org/forumtopic11229.html for a good example !

In short you have to fill in a FCB including the filename, record size,etc.
open the file with call 5 reg C=0x0F and de pointing to your fcb.
Do some read from file with call 5 c=0x27 de= des address hl= size
close file with call 5 c=0x10

By msd

Paragon (1532)

msd's picture

02-02-2011, 21:33

DOS2 functions are easier to use. If you have it use those instead..

map.grauw.nl/resources/dos2_functioncalls.php Here you can find all dos1 and dos2 function calls

By Daemos

Prophet (2170)

Daemos's picture

02-02-2011, 23:05

Thank you all for the great info. your links to the proper documentation will get me going for a while. I will post the results as soon as there will be some.

map.grauw.nl must be made by a hero. That site has so much info that I sometimes miss the important parts.


Daemos: what would happen with a file larger than RAM size?

I have no clue at all but I think that depending on the adress you write to you will overwrite data in the higher parts of the memory if you do not limit the filesize correctly. Otherwise if that doesn't happen most propably the file doesn't get fully loaded into the RAM. Therefore I can only come to the conclusion that there must be a possibility to only do partial loading of the file or better said do small transfers of the required data.

By j4mk3

Resident (33)

j4mk3's picture

03-02-2011, 11:23

Great Info.
About this theme...but a bit different...
Any link or text about how to access disk file (read/write) but from a .ROM whitout load MSXDOS ?

By commodorejohn

Expert (92)

commodorejohn's picture

03-02-2011, 14:13

Any link or text about how to access disk file (read/write) but from a .ROM whitout load MSXDOS ?
I could be wrong, but IIRC the MSX-DOS 1 function calls are built into the disk ROM, so you should be able to use them as long as a disk drive is present.

By Daemos

Prophet (2170)

Daemos's picture

03-02-2011, 16:34

Ok. Here is what I understand from the info so far.

If I set the FCB at adress &h5c I basicly point to an adress where MSXDOS has put the filename into the memory which was parsed at the command line. However I want the program to hold the file names within.

The FCB is 33 bytes in size where the first byte selects the drive to read from. The next 8 bytes hold the file name. Then there are 3 bytes for the file extension and a lot more bytes that remain unclear to me.

So if I make an routine that looks like this:

org &h0100

ld c,&hf
ld de,FCB
call 5

ret

FCB: db 0 ;drive A
        db "filename"
        db "ext"
        ds 22 ;remaining bytes filled with zero's

end

the file filename.ext will be opened right? If the file is found the routine simply returns a 0 into the acumulator. From there I will have to take the required steps of loading the bits I want into the ram so I guess it would look like this:


FILESIZE: equ 16384 ;can't find my hex calculator and I am to lazy to walk to the MSX right now ;)

PUTRAM:

ld c,27
ld DE,&hc000 ;I picked a random adress here way high
ld HL,FILESIZE ;Lets asume that this file is always 16KB for simplicity
call 5

ret

end

So now, if all went well (yes I need to still close the file but that is a later concern) there is 16KB of file into the RAM starting at adress &hc000. Lets hope that I am a little bit right.

offtopic inbetween:

My feeling tells me that when I boot MSXDOS the msxdos.sys is loaded into the first 3KB of slot 1. The basic rom and bios remain in page 0 and 1 of slot 0 right? So you have the entire 64KB of RAM available in slot 1 and that is where my mcode loads into. right?

By WORP3

Paladin (864)

WORP3's picture

03-02-2011, 16:41

You are forgetting to set the record size inside your FCB !
Also you should reset the FCB to a defined state.

By Daemos

Prophet (2170)

Daemos's picture

03-02-2011, 16:55

The record size should be 128 bytes? How do I set this? in byte 0F and 0E right?

Page 1/3
| 2 | 3