NuY Posted March 13, 2013 Share Posted March 13, 2013 Bit of a favour to ask... I have a Basic menu program that I use to run automatically from a disk to load other Basic programs, but I'm getting the occasional one that refuses to work. I've identified the issue as crap Basic code, but I'd rather not alter the original games, and have something in my loader that can fix the issue. The problem I've come across is that when issuing a NEW command using forced Return key mode, it doesn't actually clear out RAM and (presumably) just re-initialises the pointers. A couple of programs DIM some arrays but don't then initialise the arrays, instead assuming that they contain 0, whereas because of the previous program having been in memory, they contain garbge values that aren't even numbers when referenced. The solution I came up with was essentially doing a better NEW command and zeroing out all memory locations in the Basic workspace area. However - my ASM skills are severly lacking. Would anyone be able to knock up a quick and dirty routine to be able to do this? It would need to be runnable from Basic (standard rather than Turbo) and zero memory from (presumably) MEMLO up to the top of RAM in graphics mode 0, but skipping over screen RAM (as I'm using forced Return key mode and need text to stay on screen!). Slotted into page 6 would do very nicely. Ta muchly! Quote Link to comment Share on other sites More sharing options...
+JAC! Posted March 13, 2013 Share Posted March 13, 2013 There is a simple way to do it in BASIC by DIM and String assignment. I'll try to find and EMU.... Quote Link to comment Share on other sites More sharing options...
NuY Posted March 13, 2013 Author Share Posted March 13, 2013 There is a simple way to do it in BASIC by DIM and String assignment. I'll try to find and EMU.... Ah yes, the old DIM A$(FRE(0)):A$=CHR$(0):A$(FRE(0)-1)=CHR$(0):A$(2)=A$ technique (or similar). Completely forgot about that! Thanks. 1 Quote Link to comment Share on other sites More sharing options...
Roydea6 Posted March 13, 2013 Share Posted March 13, 2013 Wouldn't an A$="" be needed to release memory for other basic stuff. Quote Link to comment Share on other sites More sharing options...
Rybags Posted March 13, 2013 Share Posted March 13, 2013 NuY is pretty close, although I suspect it'd not work due to the free Ram amount changing drastically once the string is DIMed. What I'd do: 1000 F=FRE(0)-20 : DIM Z$(F) : Z$=CHR$(0) : Z$(F)=" " : Z$(2)=Z$ 1010 CLR Do that as the first thing in the program since it clears all variables. The "-20" you might be able to do without. Probably advisable to DIM any numeric arrays you need straight after to ensure they all contain zeros. Quote Link to comment Share on other sites More sharing options...
NuY Posted March 13, 2013 Author Share Posted March 13, 2013 NuY is pretty close, although I suspect it'd not work due to the free Ram amount changing drastically once the string is DIMed. What I'd do: 1000 F=FRE(0)-20 : DIM Z$(F) : Z$=CHR$(0) : Z$(F)=" " : Z$(2)=Z$ 1010 CLR Do that as the first thing in the program since it clears all variables. The "-20" you might be able to do without. Probably advisable to DIM any numeric arrays you need straight after to ensure they all contain zeros. I gave it a quick try under Altirra and it looks like the largest size you can DIM a string to is 32767 bytes - any more and you get an error 9. I'm doing this from direct mode via forced Return method for various boring reasons that I won't go into. What I came up with seems to work okay, but I wanted it to work under as many DOS/memory configurations as possible: A=(32767*(FRE(0)>33000))+((FRE(0)-127)*(FRE(0)<32767)):DIM A$(A):A$=CHR$(0):A$(A)=CHR$(0):A$(2)=A$:CLR On a machine with >32K available, this leaves about 5-6K at the top of memory uncleared, but my menu prog only occupies around 6-7K anyway, and as far as I know the variable table and program all sit at the bottom of memory anyway. Not tried it in practice with the menu prog yet, but it should be okay. The reason for leaving a little free space (around 200 bytes in the example above) is because I was getting Error 2 messages if I tried to DIM to all available RAM. Quote Link to comment Share on other sites More sharing options...
kenfused Posted March 14, 2013 Share Posted March 14, 2013 DIM and clear another string before that one big enough that the second one will not exceed 32767. Or just DIM and clear a second string with what is left. Quote Link to comment Share on other sites More sharing options...
idavis Posted March 14, 2013 Share Posted March 14, 2013 So are you looking for something to zero out from MEMLO to MEMTOP? Quote Link to comment Share on other sites More sharing options...
NuY Posted March 20, 2013 Author Share Posted March 20, 2013 (edited) So I finally got around to testing this out, and unfortunately it hasn't worked. I'm stumped. Tested under real hardware and emulation and the same thing happens each time. Would someone be able to check it out and offer some guidance? To replicate the issue, perform the following steps: Boot the attached ATR with Basic enabled Press Space to go to the second list of programs Press B to load the program Speedello Watch the computer try to seek out a move, and it will crash with Error 11 in line 420 (if the game starts expecting a user move, use the joystick to place the cursor and press fire to confirm a square. Standard Othello/Reversi rules apply) The menu program is MENU.BAS and the lines to load the program selected are: 3135 GRAPHICS 0:POKE 559,0 3140 ? "{clrscreen}NEW" "{down}{down}A=FRE(0):A=(32767*(A>32867))+((A-100)*(A<32767)):DIMA$(A):IFA=32767THENB=FRE(0)-100:DIMB$(B)" 3145 ? "{down}{down}A$=";CHR$(34);"{ctrl-,}";CHR$(34);":A$(A)=";CHR$(34);"{ctrl-,}";CHR$(34);":A$(2)=A$"; 3146 ? ":IFB>0THENB$=";CHR$(34);"{ctrl-,}";CHR$(34);":B$(B)=";CHR$(34);"{ctrl-,}";CHR$(34);":B$(2)=B$" 3147 ? "{down}{down}NEW" "{down}{down}CLR:LOAD";CHR$(34);FILE$ "{down}{down}POKE842,12:GR.0:RUN" 3150 POSITION 0,0:POKE 842,13:END ...and the filename of the game affected is SPEEDELO.BAS. Disk is in SpartaDOS format and is booting RealDOS. I've tried and replicated the problem under multiple DOSes and machine configurations. Help! Edit: I should add, booting DOS and loading the game straight from Basic works fine. As posted previously, I know why it's not working, as the program doesn't set the array values to 0. However, for preservation's sake, I don't want to alter the original source; I want the loader to replicate as close as possible a fresh boot environment. Ta! Softside Games 1.zip Edited March 20, 2013 by NuY Quote Link to comment Share on other sites More sharing options...
NuY Posted March 20, 2013 Author Share Posted March 20, 2013 So are you looking for something to zero out from MEMLO to MEMTOP? I believe this would work, yes, but with the caveat of leaving screen RAM alone... Quote Link to comment Share on other sites More sharing options...
+therealbountybob Posted April 15, 2013 Share Posted April 15, 2013 had a very quick look at Speedello; 130XE manual has error 11 as a floating point overflow /underflow - divide by 0, or # too large or small - screenshot might help someone resolve this - perhaps this code has been typed in incorrectly - might be another copy somewhere ? [or does menu affect floating point ops/RAM area perhaps?] problem is with P(S) P is an array.... p.s. I added the "then goto" just to test file is speedelo.bas Quote Link to comment Share on other sites More sharing options...
1NG Posted April 15, 2013 Share Posted April 15, 2013 (edited) had a very quick look at Speedello; 130XE manual has error 11 as a floating point overflow /underflow - divide by 0, or # too large or small - screenshot might help someone resolve this - perhaps this code has been typed in incorrectly - might be another copy somewhere ? [or does menu affect floating point ops/RAM area perhaps?] problem is with P(S) P is an array.... p.s. I added the "then goto" just to test file is speedelo.bas As I had some experience at the 10 Lines Code Competition at the NOMAM a few days ago I have a very short solution to clear memory at the top end of the memory (e.g. for PM in graphics 5): 9GR.8 The game is in graphics 5 and if a graphics 8 is set before that, it cleares the memory of 8KB. The GR.5 after that uses less memory and leaves enough KB with zeroes for e.g. PM. Only in this special case 5 characters are enough for a memory clear! This doesn´t work for highres games of course ... Edited April 15, 2013 by 1NG 1 Quote Link to comment Share on other sites More sharing options...
+therealbountybob Posted April 16, 2013 Share Posted April 16, 2013 Here is a new ATR with a fixed version of Speedelo.bas ! Softside Games 1.atr I figured the array was getting corrupted with invalid entries - too complex to work out why so added a line (#21) to wipe it before it was populated and it seems to work with the menu now [only tested on altirra] Were there any other programs you were having trouble with? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.