DOS-2 and mapper weird behaviour

By mohai

Paladin (762)

mohai's picture

25-01-2019, 20:23

Hello !
I am experiencing some problems with a file loader I wrote in assembler.
The program loads several files from disk (using FCB), after setting mapper page for page 2 (address 8000h), in order to load 1 file per mapper page.
My program is working in BASIC environment (DOS not active), with enabled BIOS (it is a BLOAD file).

If I run the program from a diskette (DOS 1), it works flawlessly. Mapper page switching works fine and every file is loaded correctly.

BUT, working from hard drive using DOS-2 diskrom (exactly same program, FCBs), after opening the file, DOS2 restores mapper pages to the boot-up state (FCh=3, FD=2, FE=1, FF=0), so some files are not correctly loaded. Question

Is it a normal behavior of DOS-2?
Can it be avoided or I will need to change my loading routines in order to avoid this "bug"?

I made a simple test from BASIC: after altering mapper registers, (i.e. OUT &HFE,4) and issue a FILES command, all registers are restored.

I tried in a 128K RAM MSX and a 256K MSX and both work the same.

Login or register to post comments

By Grauw

Enlighted (7967)

Grauw's picture

25-01-2019, 20:58

In DOS2 environment, you can not OUT to mapper registers directly. Always use the mapper support routines. Otherwise your program can not cooperate with other software which uses the mapper, such as DOS2 itself, causing segment restore issues such as these and worst case overwriting code or data causing crashes.


A program can request a 16k RAM segment at any time by calling the "ALL_SEG" routine. This either returns an error if there are no free segments, or the segment number of a new segment which the program can use. A program must not use any segment which it has not explicitly allocated, except for the four segments which make up the basic 64k of RAM.


Routines are provided to explicitly page a segment in, or to find out which segment is in a particular page. There are routines in which the page (0...3) is specified by the top two bits of an address in HL ("PUT_PH" and "GET_PH"). And there are also specific routines for accessing each page ("GET_Pn" and "PUT_Pn"). These routines are very fast so a program should not suffer in performance by using them.

Here is some example code. After determining the mapper support routines base address, it copies the jump table to a static location in the program code, so that I can call it easily.

For DOS1 support you could pre-populate the jump table with very simple implementations of those functions, so that if DOS2 is not found it will use those instead. Or you can ask users to run MU.COM before executing your program, this provides mapper support routines for DOS1.

By gdx

Prophet (2660)

gdx's picture

26-01-2019, 01:57

This is extended Bios that provides these mapper support routines. Extended Bios is installed by Disk-ROM 2.xx (but can be installed too by another device). Extended bios routines are also available in Basic environement when Disk-Basic 2.xx in installed.
MU.COM is avalaible Here.

By mohai

Paladin (762)

mohai's picture

27-01-2019, 14:37

Thank you everybody.
It seems that what started being a simple file loader would end up in a quite complicated program. LOL!
I will study the DOS2 mapper support routines and see if they suit my routines ...


Enlighted (5252)

NYYRIKKI's picture

27-01-2019, 15:10

As a work around there is MAP2-utility, but it does not work on all computers... If you plan to release your work as DOS2 compatible, I suggest you go with already mentioned standard solutions.

By ToriHino

Champion (298)

ToriHino's picture

27-01-2019, 19:00

mohai wrote:

Thank you everybody.
It seems that what started being a simple file loader would end up in a quite complicated program. LOL!
I will study the DOS2 mapper support routines and see if they suit my routines ...

Using the DOS2 mapper routines as indicated by Grauw is not that complicated. In fact, it even provides good support to multiple mappers as well in various (sub)slots, without worrying about where they are located.

By DarkSchneider

Paladin (788)

DarkSchneider's picture

14-02-2019, 10:09

If you want to use extended memory in BASIC, I would recommend you to use NESTOR BASIC. No need to reinvent the wheel. It also includes Moonblaster re-player and more things.

By mohai

Paladin (762)

mohai's picture

24-02-2019, 23:30

Thanks for the info.
I am starting to work with extended BIOS routines and getting positive results.

My MSX profile