Path: news1.icaen!news.uiowa.edu!feeder.chicago.cic.net!su-news-hub1.bbnplanet.com!cpk-news-hub1.bbnplanet.com!news.bbnplanet.com!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: Prodos Calls Date: 8 Jun 1997 23:13:37 GMT Organization: University of Oregon Campus Information Exchange Lines: 160 Message-ID: <5nfeb1$l4b@pith.uoregon.edu> References: <01bc736d$402928c0$3a067fce@blah.texas.net> NNTP-Posting-Host: cie-2.uoregon.edu NNTP-Posting-User: nparker In article <01bc736d$402928c0$3a067fce@blah.texas.net> "Bryan Parkoff" writes: > I have two different programs that can execute a file. > >Applesoft BASIC >10 HOME >20 PRINT CHR$(4);"-PROGRAM.SYSTEM" >30 END > >Machine Language >JSR $BF00 > $C8,$CA, $CC > $2000 > > Can you please give me sample how to write assemble program that can >execute "PROGRAM.SYSTEM" without using Applesoft BASIC. Unless you booted GS/OS on an Apple IIGS, there's no automatic launch-the- next-program call. Instead, you have to open the file, read it into memory, close it, and call the starting address yourself. Since .SYSTEM programs always load at $2000, your launcher code must reside below $2000. ORG $800 ; ; Useful equates ; OPEN EQU $C8 ;OPEN call number READ EQU $CA ;READ call number CLOSE EQU $CC ;CLOSE call number VPATH2 EQU $280 ;Filename of new prog goes here SOFTEV EQU $3F2 ;Reset vector PWREDUP EQU $3F4 ;Complement of reset vector FILEBUF EQU $1C00 ;Open file buffer MLI EQU $BF00 ;ProDOS entry point BITMAP EQU $BF58 ;ProDOS bit map INIT EQU $FB2F ;Initialize 40-column text screen HOME EQU $FC58 ;Clear the screen PRBYTE EQU $FDDA ;Print hex byte in A COUT EQU $FDED ;Print character in A SETNORM EQU $FE84 ;Normal text mode SETKBD EQU $FE89 ;IN#0 SETVID EQU $FE93 ;PR#0 ; ; First get machine into sane state ; LDA #$15 ;Ctrl-U: force 80-col card off JSR COUT JSR SETNORM ;NORMAL JSR INIT ;TEXT JSR SETVID ;PR#0 JSR SETKBD ;IN#0 JSR HOME ;HOME LDA SOFTEV+1 ;Force reboot on reset STA PWREDUP LDX #$16 ;Mark all pages free in bitmap LDA #0 L1 STA BITMAP,X DEX BNE L1 LDA #$CF ;Pages 0,1,4,5,6,7 not free STA BITMAP LDA #1 ;Page $BF not free STA BITMAP+$17 ; ; Other cleanup stuff may need to happen here, depending on what the ; quitting program did ; ; Now get the file into memory ; JSR MLI ;Try to open file DB OPEN DW OPARMS BCS ERROR LDA OPARMS+5 ;Get the reference number STA RPARMS+1 ;Save it for READ... STA CPARMS+1 ;...and CLOSE JSR MLI ;Read from the file DB READ DW RPARMS BCS ERROR2 JSR MLI ;Close the file DB CLOSE DW CPARMS ; ; Set up $280 pathname, so new prog can figure out its own identity ; LDX PROGNAM L2 LDA PROGNAM,X STA VPATH2,X DEX BPL L2 ; ; Start the new prog ; TXS ;Clear the stack (X already contains $FF here) JMP $2000 ;Start the program ; ; Handle loading errors ; (You'll probably want to write something more friendly) ; ERROR2 PHA ;Save error code JSR MLI ;Came here from read err, so close file DB CLOSE DW CPARMS PLA ERROR PHA ;Save error code LDX #0 ;Print a message L4 LDA MSG,X BEQ L3 JSR COUT INX BNE L4 ;(branch always taken) L3 PLA ;Get error code JSR PRBYTE ;Print it HANG JMP HANG ;Hang the system ; MSB ON MSG ASC "MLI ERROR #" DB 0 ; ; MLI parameter lists ; OPARMS DB 3 ;OPEN needs 3 parms DW PATHNAM ;Ptr to filename DW FILEBUF ;Ptr to open file buffer DB 0 ;ProDOS returns ref num here ; RPARMS DB 4 ;READ needs 4 parms DB 0 ;Ref num goes here DW $2000 ;Ptr to memory to receive data DW $9F00 ;Number of bytes to read DW 0 ;ProDOS returns # of bytes actually read here ; CPARMS DB 1 ;CLOSE needs 1 parm DB 0 ;Ref num goes here ; MSB OFF PATHNAM DB $E ;Length of filename ASC 'PROGRAM.SYSTEM' The actual steps you take to clean up the quitting program depend on what the quitting program does. The above code shows some reasonable things to do, assuming the quitting program didn't leave the machine in a *really* weird state. You'll also need to take care of such issues as closing any files that you had open, shutting down any interrupting devices that you may have started up (and removing their interrupt drivers), etc. Basically, you have to make sure that you don't leave the new program stuck with things it might not be prepared to deal with. Note the step that copies the filename to $280. Programs except to be able to find their own filenames by concatenating the filename at $280 to the current prefix (if any), so you have to provide it for them. - 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 |