How to reallocate MSXDOS2.sys without going to basic or using basic
This page was last modified 08:43, 3 November 2018 by Gdx. Based on work by Msd and Jorito.

Reallocating MSXDOS2.sys without going to basic or using basic

First read the following lines from the MSX technical data book

  • Procedure for invoking MSX-DOS

7. The environment for MSX-DOS is prepared and C01EH is called with a CY flag set. MSXDOS.SYS is loaded from 100H, and the execution jumps to 100H. After this, MSX-DOS transfers itself to a high order address. If MSXDOS.SYS does not exist, DISK-BASIC is invoked.

8. MSXDOS.SYS loads COMMAND.COM from 100H and jumps to its start address.

COMMAND.COM also transfers itself to a high order address and then begins to execute. If COMMAND.COM does not exist, the message "INSERT A DISKETTE" appears and the execution waits for the correct diskette to be inserted in the drive.

It reads that MSXDOS.SYS(and also MSXDOS2.SYS) is loaded on address 100H and executed. It reallocates itself to the highest possible address rounded at 256 bytes. The address used for this is stored at 0F34Bh. When you rename MSXDOS2.SYS to for example test.com you will see it can be executed and you will enter dos again. MSXDOS2.SYS only uses the value at address 0F34Bh but a copy is maintained at 0F349h. When the basic environment is entered 0F34Bh is lowered. 0F349h is copied over 0F34Bh when you go back to MSX-DOS2.

To allocate some free space above MSX-DOS2.SYS subtract the desired number of bytes from the value in 0F349h.

         LD   HL,(0F349h)
         LD   (OLD_VALUE),HL
         LD   DE,-100 ; Number of bytes to allocate
         ADD  HL,DE
         LD   (0F349h),HL
         LD   (0F34Bh),HL

Now reload MSXDOS2.SYS on address 100h. Before starting MSX-DOS2, by jumping to address 100h, two things need to be done.

  • The command line needs to be cleared to prevent command2.com executing it.
  • Joining parent process to clear any opened handles ,clear the process ID and to make sure set shell is on command2.com