MSX Sunrise-like IDE devices programming

Since I wrote my first post about IDE devices (Sunrise-like) on MSX computers, I’ve been thinking to write a new post about this subject.

Well, the MSX community already knows about my last efforts to develop disk tools for MSX computers and how I’m spending some energy to build a framework that will help the development of new software compatible with IDE (Sunrise-Like) devices.

In the last year I finished my first project using MSX IDE standard. The result was the creation of a disk editor known as MSXDUMP.

In conjunction with MSXDUMP, an important part of the framework has been developed. It is responsible to perform the access between the high level software layer and the low level hardware layer.

Of course this piece of my framework was possible thanks to the work done by Sunrise team, long time ago when they wrote the IDE BIOS containing all low level calls available to the software programmer.

Also it is possible to write software for Sunrise-like IDE devices using direct access through I/O ports dedicated to this device, but in this case the work would be very hard and unnecessary because the IDE BIOS routines cover everything needed by the device.

For this reason, this article won’t cover direct access.

A world without standard

In the 80’s the software industry was very primitive and the software developers seemed to be living in a wild jungle with several kinds of hardware to program and control. With different hardware standards those days were very hard for developers, considering the lack of software standardization in this primitive industry.

Everything was focused on hardware for the most part of existing standards found in the 80’s. The MSX was the first attempt, in the 8 bit world, to join the hardware with the software to act like the operating systems do today.

Then the concept of BIOS functions, generally introduced through a cartridge, was born with MSX computers and with it came the almost infinite expansibility of the MSX standard.

The Sunrise IDE BIOS

When I got my first Tecnobytes ATA/IDE interface, that was a Sunrise compatible interface manufactured in Brazil by Tecnobytes Classic Computers, for the first time I could understand the workings and limitations of this device.

Tecnobytes ATA IDE Sunrise-like interface

The big part of the device’s limitation is related to the software’s inherent lack for this device. This was the reason why I started to study Sunrise compatible device internals.

Fortunately the current Brazilian MSX community has been the best since MSX was introduced here in the 80’s and thanks to the internet we can find all the information needed to know most details about this device.

I want to cite and thank Ricardo Oazem of Tecnobytes Classic Computers who provided me all technical details including documents and source code about I/O ports and BIOS functions of Sunrise IDE.

All technical information found in this article is compatible with any Sunrise-like IDE devices, like, Sunrise, Tecnobytes and Carchano IDE.

IDE Sunrise-like interface by Carchano.
IDE Sunrise-like interface by Carchano.

Inside the BIOS

After a long period studying the source code of the Sunrise BIOS and the documents found on the Sunrise website, I finally understood how it works in details.

Functions versioning

Internally the IDE has some addresses dedicated to versioning and a IDE signature, like described below.

      ctDefaultWrkspcPage     = 3;     { Default workspace slot page }
      ctIDENotFound           = 255;   { IDE not found }
      ctBIOSMajorVerAddr      = $7FB6; { BIOS major version address }
      ctBIOSMinorVerAddr      = $7FB7; { BIOS minor version address }
      ctBIOSRevisionAddr      = $7FB8; { BIOS revision version address }
      ctIDESignatureAddr      = $7F80; { IDE signature address }

(* Workspace BIOS Call Routines *)
      ctBIOSGetDriveFieldAddr = $7FBF; { Get drive field address }

The first operation to do is to discover what slot the IDE is connected to. This can be done using the address &H7F80 (IDE signature address) for each slot/sub-slot of MSX, looking for the bytes ‘I’ followed by ‘D’ and ‘#’, until you find it.

After discovering the slot that the IDE is connected to, you can get the BIOS version used by the interface. This is easily found at following addresses.

      ctBIOSMajorVerAddr      = $7FB6; { BIOS major version address }
      ctBIOSMinorVerAddr      = $7FB7; { BIOS minor version address }
      ctBIOSRevisionAddr      = $7FB8; { BIOS revision version address }

Retrieving the BIOS version isn’t a mandatory step but is a good idea to check it. If you’re not sure about the existence of a feature provided by the BIOS of your device so this checking will be useful.

The Drive Field structure.

MSX computers are limited devices with low resources capacity, for this reason the MSX-DOS can handle just 8 simultaneous logical drives. The Sunrise IDE allocates 6 of these 8 logical drives, so the maximum capacity of simultaneous connected IDE devices is 6.

This allocated area for these 6 drives is a structure known as Drive Field. Each drive field contains the following structure below.

 * Drive field definition. The size of drive fields is variable
 * and can change according BIOS version. The current rule is written
 * like below:
 * 8 for BIOS 1.9x and 2.xx;
 * > 8 for BIOS 3.xx and higher;
 * See idesys.txt for details
Type TDriveField = Record
  nDeviceCodeByte     : Byte;
  n24PartitionStart,                        { 24Bit absolute sector number }
  n24PartitionLenght  : TInt24;             { 24Bit sector (count - 1) }
  nAdditionalPartInfo,                      { Addition partition info }
  (* The two bytes below is reserved to BIOS 3.xx or higher *)
  nPartitionStart,                          { Partition start bit 24 to 31 }
  nPartitionLength    : Byte;               { Partition (lenght - 1) 24 to 31 }

As you can see there are two bytes at the end of the structure above and in the “official” documentation of IDE, it says “RESERVED TO BIOS 3.xx OR HIGHER”. I suppose that these two bytes was put there for future use in FAT16 and FAT32 native support in the Sunrise IDE devices.

The WorkSpace

The Sunrise specification defines  an area that contains all the 6 DriveFields structures managed by the interface, plus another structure known as the DeviceInfoBytes, followed by an unused free space of 18 bytes.

This structure formed by 6 DriveFields + DeviceInfoBytes + Free space (18 bytes) is known as the IDE WorkSpace.

The IDE WorkSpace is filled at the machine start up and loads the first 6 partitions available to the IDE connected interface.

 * IDE interface Workspace allocate at boot process.
 * More details check idesys.txt file at this library
 * directory.
Type TIDEWorkspace = Record
  ptrDriveField      : Array[0..ctDriveFieldSize] Of PDriveField;
  ptrDeviceInfoBytes : PDeviceInfoBytes;
  ptrFreeSpace       : PFreeSpace;

NOTE: It is possible to exchange the partition content pointed to a different DriveField just using the IDEPAR command line utility.
In a hypothetical situation where your drive letter B: points to the second partition in the disk, you could point this drive B: to another formatted partition higher than 6 crossing the limits imposed by the Sunrise interface.
This could be done using the IDEPAR utility, but it use is not covered by this article.

The DeviceInfoBytes structure

The DeviceInfoBytes structure is an important and useful area of the IDE WorkSpace because it contains some information about the physical device that is connected in the interface, like the number of heads from device master and slave, maximum of cylinders by sector on both, master and slave connected disks.

The structure is defined as shown below:

 * Device info bytes definition.
 * 6 bytes for BIOS 1.9x and 2.xx.
Type TDeviceInfoBytes = Record
  nNumOfHeadsMaster,             { For ATA Devices }
  nNumOfHeadsSlave,              { For ATA Devices }
  nNumSectorsCylMaster,          { For ATA Devices }
  nNumSectorsCylSlave,           { For ATA Devices }
  nUndefined           : Byte;   { Undefined yet - don`t use them }

Type PDeviceInfoBytes = ^TDeviceInfoBytes;  { TDeviceInfoBytes pointer type }

The new BIOS functions

The Sunrise interface introduces at least 4 new BIOS function calls that can be used by applications compatible with Sunrise devices.


The two first functions are listed below:

(* Sunrise-like IDE BIOS calls *)

Const     ctBIOSSelectATAPIDevice = $7FB9; { Select master or slave device }
          ctBIOSSendATAPIPacket   = $7FBC; { Send ATAPI to selected device }

These two functions are related to control ATA devices, like a CDROM, using the ATAPI command packets. An example is an application that commands the CDROM device to open the tray.

Sector I/O BIOS calls.

It is known that IDE devices can handle a mass storage with higher capacity than the old disk drives. In fact, old disk drives just can manage sectors from 0 (zero) to 65535 (the maximum value accepted by a 16 bit unsigned number).

Fortunately today we have some storage devices supporting megabytes, gigabytes and recently terabytes.

The Sunrise IDE interface brought the possibility of connecting with these higher capacity devices, but unfortunately the MSX-DOS BDOS functions and old softwares cannot handle the full capacity of these new devices.

Fortunately Sunrise already developed alternative I/O sector functions capable of managing devices that can handle a big amount of data.

Two new I/O functions were introduced into the IDE BIOS to do the sector’s handling using 24 bit unsigned numbers (0 to 16.777.215). These functions are listed below:

(* Sunrise-like IDE BIOS calls *)

Const     ctBIOSAbsSectorRead  = $7F89;  { Absolute sector read function  }
          ctBIOSAbsSectorWrite = $7F8C;  { Absolute sector write function }

These two functions should be used by applications that handle sector management instead the MSX-DOS BDOS functions ABSREAD (&H2F) and ABSWRIT (&H30), because the new functions support unsigned 24 bit sector’s handling instead the MSX-DOS old functions that support only 16 bit setor’s handling.

The Big Number library

The MSX computers can perform 16 bit operations directly and to use the new I/O functions provided by the BIOS, the programmers should provide a way for MSX perform 24 bit operations.

Fortunately I created a library (BigNumber) that can handle numbers of any size, since 8 bit, 16 bit, 24 bit, 32 bit to infinite bits.

This library can be found at OldSkoolTech and is fully written and compatible with Turbo Pascal 3 and has been used in my own softwares like the MSXDUMP 0.2, compatibles with Sunrise devices.

Well, I believe that this article could be an useful article to technicians and developers that are interested in creating new softwares to use the full capacity of Sunrise devices, so enjoy it !!



Análise da interface ATA IDE – Tecnobytes

MSXDUMP v0.2 (final) liberado no

Memory-mapped I/O ports

Tecnobytes Classic Computers

Sunrise for MSX home page

MSX-DOS Wikipedia

Carchano MSX IDE interface

ATAPI packets (Wikipedia)

CP/M-BDOS (Wikipedia)

PopolonY2k’s BigNumber library at

OldSkoolTech project (

Turbo Pascal (Wikipedia)

Print Friendly, PDF & Email
%d bloggers like this: