Path: news1.icaen!news.uiowa.edu!chi-news.cic.net!newsrelay.netins.net!newsfeed.dacom.co.kr!news.pbi.net!news.mathworks.com!howland.erols.net!ais.net!newsfeed.direct.ca!news.uoregon.edu!cie-2.uoregon.edu!nparker From: nparker@cie-2.uoregon.edu (Neil Parker) Newsgroups: comp.sys.apple2.programmer Subject: Re: Apple //gs MLI BSAVE Date: 12 May 1997 06:43:31 GMT Organization: University of Oregon Campus Information Exchange Lines: 147 Message-ID: <5l6e6j$2vh@pith.uoregon.edu> References: <336EA026.B0A@ix.netcom.com> <3370E107.2753@no.no> <3370F1B1.2FD6@ix.netcom.com> NNTP-Posting-Host: cie-2.uoregon.edu NNTP-Posting-User: nparker In article <3370F1B1.2FD6@ix.netcom.com> Larry writes: >[...] >I have tried to do what you suggest...even calling the routine from >within a running Applesoft program. It still refuses to recognize the >command. The BSAVE statement is simply printed to the screen. While >Applesoft hasn't changed, ProDos has. I noticed in one book that ctrl-D >is not listed as a recognized control character as of version 1.5. I >think that means my previous plan for using BSAVE is hopeless. As for >the Aux memory issue, I understand the Applesoft limitation and that's >why I want to use the Aux memory switches allow the MLI to store the raw >data from my A/D in the large block of memory 01/4000-01/BFFF. I have >already gotten the code working to : (1) execute my program from >Applesoft (2) initialize the PIA & A/D converter (3) Collect the data >and store in Aux memory (4) and return to main memory and Applesoft. >Since Applesoft can't get to the Aux memory directly, I want the MLI to >save the data to disk before returning. Unfortunately, this is proving >much harder to do that I anticipated. > >Question: Given that my "BSAVE" method doesn't work, how do I access >ProDos 8 to make it do the same thing? This shouldn't be that hard, but >I'm stuck. Unfortunately, I'm unable to find many people who understand >ProDos/MLI interfacing and many of the good technical books are hard to >come by (and even them I'm not sure I'd be able to figure out a true >ProDos 8 call without help). > >I hope I'm making this harder than it needs to be and someone out there >will step in to straighten me out. Unfortunately, some of the steps of what you want to do aren't quite as straightforward as they appear at first. But first, let's back up a little... BASIC.SYSTEM *can* do a BSAVE from machine language. But sending control-D and a command through COUT doesn't work in ProDOS. Instead, you need to put the entire BSAVE command (in uppercase, with the high bits of each character turned on, and with a $8D at the end) at $200, and JSR $BE03. If an error occurs, the carry flag wil be set, and the ONERR GOTO code is at $BE0F. This method only works for machine-language routines that were CALLed from BASIC. Remember to CLC before you RTS back to BASIC. If BASIC.SYSTEM isn't available, or if you can't count on being CALLed from BASIC, you'll want to use the ProDOS machine language interface (MLI) instead. I'll come back to this in a moment. The main problem is that you want to save information that's stored in the auxiliary bank instead of the main bank. There's no way to do this directly, since if auxiliary memory is switched in, ProDOS (which resides in the main memory) is switched out and unavailable. So you need to copy your information from auxiliary memory to main memory, and save it from there. Given the amount of information you have to save, it may be best to do this in chunks (i.e. read part of the data from aux memory, save it, repeat until done). I suspect MLI calls are the way to go here. You'll need four MLI calls--CREATE, OPEN, WRITE, and CLOSE. An MLI call consists of a JSR to the MLI entry point at $BF00, followed by a one-byte command number, and a two-byte pointer to a parameter list. When the call is finished, ProDOS returns control to the byte immediately following the parameter list pointer. Thus a ProDOS call looks like this: JSR $BF00 DB COMMAND DW PARM_LIST Your code continues here CREATE creates a new file. If the file you want to write to doesn't exist yet, you need to CREATE it before you can do anything else with it. JSR $BF00 ;MLI entry point DB $C0 ;CREATE command number DW CREATE_PARMS ;Ptr to parameter list BCS ERROR ;Carry set if error CREATE_PARMS DB 7 ;Number of parms (*not* number of bytes) DW PATHNAME ;Ptr to name of file to create DB $E3 ;Access bits ($E3=all access allowed) DB 6 ;File type (6=BIN) DW 0 ;Aux type DB 1 ;Storage type (1 for reg file, $D for directory) DW 0 ;Creation date (0=get date from system clock) DW 0 ;Creation time (0=get time from system clock) PATHNAME DB 7 ;Length of filename DB 'NEWFILE' ;Name for new file If there was a problem, the carry flag will be set, and the accumulator will contain an error code. The most important one for your purposes is probably $47, which indicates that the file already exists. OPEN opens an existing file for reading and writing. It requires a 1024-byte page-aligned open-file buffer, which your program should provide, and should not touch between the time the file is OPENed and the time it is CLOSEd. If you're running under BASIC.SYSTEM, you can borrow the general-purpose buffer at HIMEM (there's a pointer to it at $73 and $74), as long as you're through with before you RTS back to BASIC. If you open more than one file at the same time, you need a separate buffer for each file. JSR $BF00 DB $C8 ;OPEN command number DW OPEN_PARMS BCS ERROR OPEN_PARMS DB 3 ;Number of parms DW PATHNAME ;Ptr to filename to be opened DW BUFFER ;Ptr to open-file buffer DB 0 ;ProDOS returns a file number here WRITE writes data to a file. It needs the file number returned by ProDOS in the OPEN parameter list. JSR $BF00 DB $CB ;WRITE command number DW WRITE_PARMS BCS ERROR WRITE_PARMS DB 4 ;Number of parms DB 0 ;Put the file number from OPEN here DW DATA ;Ptr to data to be written DW SIZE ;How many bytes to write DW 0 ;ProDOS returns no. of bytes actually written here CLOSE closes the file after you're done writing to it, flushing any unwritten data to the disk, and releasing the buffer that you gave to the OPEN command. You should *always* close every file that you open. CLOSE needs the file number that was returned in the OPEN parameter list. JSR $BF00 DB $CC ;CLOSE command number DW CLOSE_PARMS BCS ERROR CLOSE_PARMS DB 1 ;Number of parms DB 0 ;Put the file number from OPEN here The above is *far* from everything there is to know about calling ProDOS from machine language, but it should be enough to get you started. - Neil Parker -- Neil Parker | Unsolicited commercial e-mail to my nparker@cie-2.uoregon.edu | address is not welcome, and will be nparker@cie.uoregon.edu | discarded unread. http://cie-2.uoregon.edu/~nparker |