Jump to content
IGNORED

Memory clear routine for Basic


NuY

Recommended Posts

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!

Link to comment
Share on other sites

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.

  • Like 1
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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:

  1. Boot the attached ATR with Basic enabled
     
  2. Press Space to go to the second list of programs
     
  3. Press B to load the program Speedello
     
  4. 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 by NuY
Link to comment
Share on other sites

  • 4 weeks later...

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?]

 

post-19705-0-50789900-1365985686_thumb.png

problem is with P(S) P is an array....

post-19705-0-03806100-1365986349_thumb.png

p.s. I added the "then goto" just to test ;)

file is speedelo.bas

Link to comment
Share on other sites

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?]

 

post-19705-0-50789900-1365985686_thumb.png

problem is with P(S) P is an array....

post-19705-0-03806100-1365986349_thumb.png

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 by 1NG
  • Like 1
Link to comment
Share on other sites

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 :party: [only tested on altirra]

 

 

Were there any other programs you were having trouble with?

 

:)

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...