Path: utzoo!utgpu!news-server.csri.toronto.edu!helios.physics.utoronto.ca!physics.utoronto.ca!neufeld Newsgroups: comp.sys.apple2 From: neufeld@physics.utoronto.ca (Christopher Neufeld) Subject: Re: Protectin Portions of Memory in BASIC. . . Message-ID: <1991Jan10.152830.29077@helios.physics.utoronto.ca> Organization: University of Toronto Physics/Astronomy/CITA References: Date: 10 Jan 91 20:28:30 GMT In article nagendra@bucsf.bu.edu (nagendra mishr) writes: >try this >lomem 16384 >himem 8192 >that should block off hires page one for variable storage. > That's not legal, at least not in Applesoft BASIC running under DOS3.3. You get an OUT OF MEMORY error if you try it. You can poke the values directly into zero page to force this condition, but then the computer will crash. The way to protect memory from numeric and string variable overwrites is to put the routines which you don't want clobbered outside of the memory range {LOMEM...HIMEM}. If your machine language fragment is at $4000 (16384) and uses 4kB, setting LOMEM:21000 will avoid hitting it, and will provide you with room if your machine language segment grows a bit in future. Applesoft programs, unless they use large arrays, rarely run into memory limitation problems. If your BASIC program is so long that it is threatening to hit your machine language fragment, well you should have written the fragment in relocateable code or you'll have to reassemble it from your assembly listings. You can get around this, the simplest way is to write the machine language fragment to run at $800, then make the following the first few lines of your program: 10 REM PROGRAM MAIN 20 REM THIS PROGRAM LOADS IN AT $1000, LEAVING 2KB ROOM FOR THE 30 REM MACHINE LANGUAGE FRAGMENT LOADED AT $0800 40 IF PEEK(104) = 8 THEN POKE 104,16: POKE 4096,0: PRINT CHR$(4)"RUN MAIN" 50 PRINT CHR$(4)"BLOAD FRAGMENT,A$800" ..... With this setup the program automatically reconfigures zero page space and reloads itself from disk into the right place, then loads FRAGMENT into the safe space below itself, which can never be intruded on by variables without conscious effort by the programmer (there are POKEs to move variable storage here if you're that kind of person). Now you don't have to play LOMEM, HIMEM games, and the Applesoft program can grow as much as it likes without threatening your code fragment. Note that this technique is particularly useful when you have a long Applesoft program which uses high resolution graphics. You move the load address to above the graphics page. The '104' in the code above comes from the start of program pointer at $67,$68 in LO-HI format. The program loads at the pointer+1, and the memory address referred to by the pointer must be set to zero (hence the POKE 4096,0). If you have a particularly long program, and you don't want to reload it as this fragment does, write a four line launcher program like this: 10 REM PROGRAM LAUNCHER 20 IF PEEK(104) = 8 THEN POKE 104,16: POKE 4096,0 30 PRINT CHR$(4)"RUN MAIN" 40 END to run your program "MAIN", run "LAUNCHER" instead, and it will set up memory and run the program. >nagendra@bucsf.bu.edu -- Christopher Neufeld....Just a graduate student | "Shtarker! Zis is KAOS! neufeld@helios.physics.utoronto.ca Ad astra! | Vee do not 'yippee yo cneufeld@{pnet91,pro-micol}.cts.com | kye aye' here!" "Don't edit reality for the sake of simplicity" | Siegfried of KAOS