System variables (again!)

Page 1/4
| 2 | 3 | 4

By Metalion

Paragon (1628)

Metalion's picture

10-05-2022, 21:11

Yes, it's that time of year again when we have (again) that discussion about using the RAM used by system variables ... Cool

My context will be precise: I'm developing a megarom, I do not need floppy disks, and I'm using very little of the BIOS, apart from the ISR, the keyboard and the joysticks. I need more RAM space.

What is the strict minimum I need to keep in the system variables area ?

Login or register to post comments

By aoineko

Paragon (1132)

aoineko's picture

11-05-2022, 09:26

The problem is that if you use even a little bit the BIOS routines and/or its ISR, a large part of the system variables area "can" be used.
So the safe answer would be F380h (minus the size of your call stack).

If you want to go further, you should have an exhaustive list of the used routines (directly or from the ISR), and see if it is possible to deduce which parts of the system variables area are used.
But I guess it could vary from one BIOS to another.

By Micha

Expert (110)

Micha's picture

11-05-2022, 11:20

There may be two options:
1) Bypass the bios by writing your own ISR, joystick and keyboard routines (by copying them from a bios and change all the RAM adresses they use by ones that you pick and control). This is the safest way, but may be a lot of work...
2) Stay below F380 with all your code, data and stack, but pick certain areas above F380 that are safe to use.
Luckily, the use of the work area (above F380) and its variables is part of the MSX standard (in contrast to the BIOS; only the BIOS entry points are part of the standard), so if you pick parts that you know you don't use, then you are good to go. You could think of areas that are used by basic for example. Don't just use empty areas, they might be reserved for future use.

By Metalion

Paragon (1628)

Metalion's picture

11-05-2022, 13:55

I have found that the biggest contiguous zone that can be used is $F3FC-$F921h : 1318 bytes.
(this zone is used only by the BASIC interpreter and math pack)

There's also another zone from $F92A-$FAF5 : 459 bytes.
(also BASIC interpreter)

The 8 bytes between those 2 zones is used by CHGMOD in the BIOS.
So if you do not use that call, you can use the full $F3FC-$FAF4 zone : 1785 bytes

By gdx

Enlighted (6422)

gdx's picture

11-05-2022, 15:45

Using Bios routines saves RAM space. You have to be sure that the variables you overwrite are not used when the hardware changes. I have seen many MSX1 games malfunction on higher generations because reserved areas were used.

Usually BUF (0F55Eh) and KBUF (0F41Fh) must be temporary used only because some routines (the BIOS routines PINLIN, INLIN and QINLIN use them, and even the MBIOS use BUF for exemple).

aoineko wrote:

I guess it could vary from one BIOS to another.

No, all Bios routines use same system variables and areas except those which have been modified from one generation of MSX to another, or also when the region is different but very few.

By ro

Scribe (5056)

ro's picture

11-05-2022, 16:19

In theory, yes you can replace page 3 with fresh RAM. Certainly if you're setting the machine up for RAM for all pages (effectively not using ROM , BASIC and DISKROM stuff). The only thing I'm still confused about are the secundairy slot vars. The SLTTLB (Slot Table) information is (somehow) automatically(*) updated (almost real time) by the machine to reflect the current selected secondary slots for each extended primary slot per page. (0XFCC5/8). Speaking of slot selection, 0xFFFF (-1) is used for sec.slot selection. But, if yer only switching once on initialization.. have a ball!

(*) I’m not sure how the SLTTBL gets updated. It’s not by interrupt, I’ve tested that. Pretty soon after SLTSL (#FFFF) gets updated, the corresponding SLTTBL records gets updates as well. I have no clue of how this happens.

By ericb59

Paragon (1124)

ericb59's picture

12-05-2022, 10:27

I Have a question, perhaps a little out of subject but...
It seems the Work Area (0xF380 to 0xFFFF) also exists when using MSX-DOS.
So I suppose using KBUF area as a temporary ram variable is possible too ?
Right ?

By Bengalack

Paladin (801)

Bengalack's picture

12-05-2022, 18:39

Interesting topic... Lilly's Saga is rom, and only uses a few bios-calls at the very first lines of code at startup (check msx-version and print out error in case of version lower than 2 or vram less than 128kB). Ie. after that there is no further BIOS-usage. And I've had to refactor many times to constantly reduce ram-usage. I'm using ram from 0000-0F380 and setting SP at 0F380 (ignoring HIMEM pointer (at FC4Ah), and that Sony HB-F500 actually does not have 0F380 at HIMEM. Assuming that this will work as the computer is totally overtaken by the non-returnin game/rom at this point). To the best of my knowledge, I could use ram in area F380-FFFE - but I have stayed away from it. Not sure why - I can probably just abuse that area oO AFAIK SMW uses upper ram.

By Micha

Expert (110)

Micha's picture

13-05-2022, 09:17

Bengalack wrote:

To the best of my knowledge, I could use ram in area F380-FFFE - but I have stayed away from it. Not sure why - I can probably just abuse that area oO AFAIK SMW uses upper ram.

Be cautious here... If you don't have your own ISR, then Bios will be used, and parts of the work area will be used as well. At least the keybuffers area (FBDA - FC17) is used, and there will be more small pieces of the work area RAM that are subject to change (such as the JIFFY variable at FC9E, among others)

If you do have your own ISR and you don't use BIOS calls and you have all other interrupts disabled then it should be safe to use F380-FFFE...

By gdx

Enlighted (6422)

gdx's picture

13-05-2022, 10:34

Micha wrote:

If you do have your own ISR and you don't use BIOS calls and you have all other interrupts disabled then it should be safe to use F380-FFFE...

...and if you don't need the info that the variables give, and if MSX3 not use reserved area.

In addition, Supersoniqs cartridge use the FFFEh address to expand the memory mapper size, so it is probably better to avoid using this address as well.

By Micha

Expert (110)

Micha's picture

13-05-2022, 11:41

gdx wrote:
Micha wrote:

If you do have your own ISR and you don't use BIOS calls and you have all other interrupts disabled then it should be safe to use F380-FFFE...

...and if you don't need the info that the variables give, and if MSX3 not use reserved area.

In addition, Supersoniqs cartridge use the FFFEh address to expand the memory mapper size, so it is probably better to avoid using this address as well.

Yeah, you are right... I shouldn't be promoting using the work area (even though if you know what you are doing you can make use of (part of) it safely) and also I shouldn't be suggesting to bypass the BIOS...
I've checked the MSX technical data book from Microsoft again, and it says clearly (in chapter 6 - notes for MSX software developers) :
a) Do not write programs directly to handle the hardware (sound, keyboard, joysticks, etc) but always use the BIOS entry points for that. There is an exception for the VDP, you can directly use the ports, but read at ROM positions 0006 and 0007 which ports you should use. So if you want to comply with the msx standard you simply cannot bypass the BIOS (unless you e.g. would make a demo that only uses the VDP)
b) Do not use RAM above F380 if you don't have detailed documentation on the meaning of these locations. All unused RAM in this area is reserved for future use. (this is basically what i said in my first post)

Page 1/4
| 2 | 3 | 4