Path: news.uiowa.edu!hobbes.physics.uiowa.edu!math.ohio-state.edu!uwm.edu!vixen.cso.uiuc.edu!news.uoregon.edu!cie-2.uoregon.edu!nparker From: nparker@cie-2.uoregon.edu (Neil Parker) Newsgroups: comp.sys.apple2,comp.sys.apple2.programmer Subject: Re: Advanced Applesoft HELP! Date: 19 May 1995 10:14:04 GMT Organization: University of Oregon Campus Information Exchange Lines: 60 Message-ID: <3phr1c$59m@pith.uoregon.edu> References: NNTP-Posting-Host: cie-2.uoregon.edu Xref: news.uiowa.edu comp.sys.apple2:88227 comp.sys.apple2.programmer:4954 In article dalloff@freenet.columbus.oh.us (Dave Althoff) writes: >I have written a machine-language library for an Applesoft program. >Normally, I stick such libraries at $8000 and am done with it at that. >But this is a program which, if I am not careful, could accidentally tromp >a library stored up there. And the library is fairly long; and I really >don't like doing library BLOADs anyway. > >I was careful to write the library using 100% relocatable code. >Therefore, it seems that this would be a good candidate for that age-old >tactic where the library is sandwiched in between the last line of >tokenized Applesoft and the current LOMEM: value. This causes Applesoft >to take care of all the memory management, automatically relocating the >library if the Applesoft gets edited, and causing the library to be saved >on disk as part of the tokenized program. Really a neat trick! And it >works well. I've done it in the past. > >Trouble is, I can't remember how I did it 8-}! And I can't seem to find >any of my old POKE charts 8-(. I have lots of DOS 3.3 data, but next to >nothing on the workings of Applesoft. > >Can anybody at least point me in the right direction? And if you're still >a little fuzzy on what I'm trying to do, the old RENUMBER program from the >DOS 3.3 System Master used this tactic...in fact, RENUMBER remained memory >resident until an FP command was issued. And yes, I'm looking at that one >for a starting point (the CALL PEEK (nnn)+PEEK(nnn+1)*256 is really helpful!). The pointer you need is the Applesoft end-of-program pointer, at locations 175 and 176 ($AF and $B0 in hex). To create your hybrid program: 1. LOAD the Applesoft code. 2. CALL -151 3. Note the end-of-program address, in $AF (low byte) and $B0 (hi byte). 4. Make sure there are at least three zero bytes preceeding the end-of- program address. Those three bytes MUST stay there, or Applesoft won't be able to figure out where the program's last line is. 4. Control-C return 5. BLOAD ML.LIBRARY,A$(the address you noted in step 3) 6. Find the ending address of the machine language library. Add one to this value, and store it in $AF and $B0. 7. SAVE the Applesoft program. Your Applesoft file now contains the hybrid program (Applesoft + machine language). To call your machine language library: 10 LL = (whatever): REM Insert the length of the ML library here 20 EP = PEEK (175) + 256 * PEEK (176): REM End of program 30 ML = EP - LL: REM Find start of ML code 40 CALL ML - Neil Parker -- Neil Parker, nparker@{cie-2,cie}.uoregon.edu, http://cie-2.uoregon.edu/~nparker "Evolution is vastly overrated." -- Ambassador Delenn, _Babylon_5_