Newsgroups: comp.sys.apple2.programmer Path: news.uiowa.edu!news.physics.uiowa.edu!math.ohio-state.edu!howland.reston.ans.net!newsfeed.internetmci.com!news.msfc.nasa.gov!elroy.jpl.nasa.gov!decwrl!waikato!comp.vuw.ac.nz!actrix.gen.nz!dempson From: dempson@atlantis.actrix.gen.nz (David Empson) Subject: Re: Calling ProDOS with assembly language Message-ID: Sender: news@actrix.gen.nz (News Administrator) Organization: Actrix - Internet Services Date: Sat, 13 Jan 1996 01:19:28 GMT References: <30F5F041.2EB1@postoffice.ptd.net> <30F67E80.5485@post.its.mcw.edu> X-Nntp-Posting-Host: atlantis.actrix.gen.nz Lines: 186 [Note: much of the text of this article is directed at the original poster, Jason A Long, not at Ron Kneusel.] In article <30F67E80.5485@post.its.mcw.edu>, Ron Kneusel wrote: > > Basically, you only get BSAVE and BLOAD in ProDOS when you have the > BASIC.SYSTEM file loaded. They are only available if your machine language code is called from a BASIC program, not directly from the command line. > With out it you need to use the ProDOS MLI (Machine Language > Interface). [snip] > All the commands work the same way: > > JSR MLI (address is $BF00) > HEX $CA (single byte command code, $CA = read from open file) > DW TBL (lo/hi address of a parameter table used by all commands) > BCS ERR (return code in A, carry set if an error occured) > . > . > TBL HEX $03 (1st byte always number of parameters in the table) > HEX $01 (ProDOS file reference number, 1 for first open file (?)) > DW BUFF (lo/hi address of data buffer -- receives the bytes read) > HEX 0000 (# bytes actually read returned here, lo/hi) > > N.B. The above is from memory so I'm not responsible of slight inaccuracies! > The general form is correct. You seem to have a few calls confused there. :-) The reference number is used by all "open file operation" calls (open, close, read, write, get_eof, set_eof, get_mark, set_mark, etc.). The open call returns a reference number, which is used in subsequent calls associated with the same file. You should not assume anything about the number it returns. There are several "closed file operation" calls such as create, destroy, rename, get_file_info, set_file_info, etc. which don't use reference numbers, just an explicit pathname. The buffer passed to the OPEN call is a 1K file buffer for use by ProDOS (to hold the active index and data blocks). It must be page-aligned, and you should never directly access it. The READ and WRITE calls expect the address at which you want to read or write the actual data. They also expect a "request count", and they return a "transfer count" (which you have in your suggested parameter block for OPEN). Also note that the parameter blocks are quite different in structure for most calls. For example, BASIC.SYSTEM has a common set of parameter blocks it uses to make MLI calls, and there are at least nine of them, many of which are shared by similar calls. The actual call mechanism (JSR $BF00 followed by the call number and parameter block pointer) is identical for all calls - you just change the embedded arguments as required for each call. In some cases, you may like to patch a single call to the MLI with the appropriate call number and parameter block pointer, but it is usually easier to just place each call in-line at the point where it is needed. Here is a quick list of all of the ProDOS Machine Language Interface calls: CREATE Create an empty file or directory. DESTROY Delete a file or an empty directory. RENAME Rename a file, directory or volume. SET_FILE_INFO Set directory information for a file or directory: access rights, file type, auxiliary type, modification date/time. GET_FILE_INFO Get directory information for a file, directory or volume: as SET_FILE_INFO, as well as getting the creation date/time, the number of blocks used, and the "storage type" (indicates the physical structure of the file/directory/volume). For a volume, the total number of blocks and number of used blocks are returned. ONLINE Identify the volume in a specific device, or list all on-line volumes. SET_PREFIX Set the ProDOS prefix (for subsequent calls using a partial pathname). GET_PREFIX Get the ProDOS prefix. OPEN Open a file, to allow reading/writing. NEWLINE Set up "new line" mode for read, allowing operations such as reading a text file one line at a time. READ Read data from an open file. WRITE Write data to an open file. CLOSE Close one, many or all open files. FLUSH Ensure that buffers and directories for one or more open files have been written to disk (this is done automatically when you close a file, but this call is useful if you want to keep a file open for a while after writing to it). SET_MARK Change the "file mark" (the read/write position with an open file). GET_MARK Get the file mark. SET_EOF Change the size (end of file) of an open file, either making it larger or smaller. (It is possible to set up "sparse" files using this call, where large portions of the file may not be physically allocated on the disk, and are assumed to be full of zero bytes.) GET_EOF Get the size (end of file) of an open file. SET_BUF Change the I/O buffer address for an open file. (This call is rarely used, unless you have a dynamic buffering scheme, like BASIC.SYSTEM. The I/O buffer address is normally specified when you open the file, and never changed.) GET_BUF Get the I/O buffer address for an open file. ALLOC_INTERRUPT Install an interrupt handler. DEALLOC_INTERRUPT Remove an interrupt handler. READ_BLOCK Perform a direct block read to a volume. WRITE_BLOCK Perform a direct block write to a volume. GET_TIME Update the time on the ProDOS global page. (This is done automatically by every other call, but this call can be useful if you want to know the current time but don't want to do anything else. You need a clock for this call to be useful.) QUIT Terminate a system program and return to the program selector. (If you have AppleTalk support installed, you can also make AppleTalk protocol calls through the ProDOS entry point.) There is only one obvious omission: ProDOS has no built-in facility for formatting disks. This generally requires a utility program which has the appropriate code. The utility program is responsible for physically formatting a 5.25" disk, or for calling the ProDOS block device driver (usually in the slot firmware) to format other types of volumes. It then uses ProDOS WRITE_BLOCK calls to set up the boot blocks, root directory and volume bitmap. The utility must contain its own copy of the ProDOS boot sector (or read it from another formatted volume). To make use of the MLI, you often need documentation on the ProDOS "global page", which is the memory area from $BF00 to $BFFF. It contains several entry points, data tables and variables that are used by ProDOS system programs, and by ProDOS itself. You also need full documentation on the structure of each of the parameter blocks, the error codes that can be returned by each call, and any special considerations for the calls you are using. I would definitely recommend getting a good book on MLI programming (any of the three I mentioned in my previous posting) before trying to do too much with the MLI. Simple operations are possible without access to the full documentation, so let me know what you want to do, and I'll give you the appropriate code fragments. If you are a novice machine code programmer, I'd suggest starting with the BASIC.SYSTEM callback method, which is much easier. -- David Empson dempson@actrix.gen.nz Snail mail: P.O. Box 27-103, Wellington, New Zealand