How to restore BASIC memory after CLEAR command?

Door The_Engineer

Master (180)

afbeelding van The_Engineer

15-12-2011, 23:14

While working on an issue on old FutureDisk BASIC code, I noticed that usage of the CLEAR command moves the BASIC file work area, the string work space and the stack pointer. BASIC changes the values for HIMEM (#FC4A), MEMSIZ (#F672) and STKTOP (#F674). But BASIC does not store the initial value.

If I want to restore the BASIC work area to initial setting (i.e. after boot at prompt) I cannot find a correct way to do it.

On MSX 1,2,2+ and TurboR started with SHIFT (i.e. diskrom skipped), the CLEAR command to go back to initial would be:
CLEAR 200,&HF380.

This is documented as &HF380 is the bottom of the BIOS work area.

The documentation for the DOS 1 diskrom available shows address #F349 containing the lowest address in use by the disk work area.
However, experimentation shows that probably disk basic adds another 218 bytes to the work area that I cannot find any reference for in any documentation.
Coincidentally the jump entry for the BSAVE command at #F37A contains the initial value of HIMEM after boot at prompt.
As a workaround you could use the address at #F37B as address for the CLEAR command.
But this does not look like the right way.

For DOS2 I have no clue at all how to reconstruct the BASIC work area. The disk work area did not reveal any useful address.

Any ideas from the experts?

Aangemeld of registreer om reacties te plaatsen

Van RetroTechie

Paragon (1563)

afbeelding van RetroTechie

15-12-2011, 23:44

The documentation for the DOS 1 diskrom available shows address #F349 containing the lowest address in use by the disk work area.
However, experimentation shows that probably disk basic adds another 218 bytes to the work area that I cannot find any reference for in any documentation.

That is because there is 0 guarantee how much work area is taken by different disk implementations (and in fact, this does vary from system to system). And then there's other things that may eat space there like RS232, builtin software for superimpose addons, etc, etc. If you pick what you find on your machine, it'll be wrong for other machines. If you assume anything in this regard, your assumption will be wrong (sometime, somewhere, for someone).

Only way I could think of is store current value somewhere that isn't changed during the course of the program, and restore using that.

Coincidentally the jump entry for the BSAVE command at #F37A contains the initial value of HIMEM after boot at prompt.
As a workaround you could use the address at #F37B as address for the CLEAR command.
But this does not look like the right way.

If it isn't documented in official, programmer-targeted docs, it is the wrong way. Use what's officially documented, step outside that & all bets are off.

Van DanySoft

Champion (452)

afbeelding van DanySoft

16-12-2011, 22:19

It can be use the NEW command to return to memory. In this case you encounter an error "Syntax Error".
But we can not investigate the BASIC memory: it is very difficult to control Himes, and SIZMEM SKTOP ....
bye bye