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

Dennis Ritchie the father of everything

Since Dennis Ritchie passed away, I have been thinking to write something about this guy, not just because to me he is the most important computer scientist since early days of modern computer systems, but just because he was the father of everything we are running today.

The C programming language (Book cover)
The C programming language (Book cover)

Unfortunately the world did not give to him, what is in my opinion, the deserved attention in the moment of his death, because 7 days before another great entrepreneur had passed away, so the world media and market was more affected by his death. I’m talking about Steve Jobs, that is known as a great entrepreneur and business man, but without the work of Dennis Ritchie helping him indirectly, maybe his progression would have been more difficult than it was.

This is because all basic software of Apple, like MacOS X and IOS was written using the C language, created by Dennis Ritchie several years before at Bell Labs, and considering that both operating systems are UNIX-Like, the importance of Dennis Ritchie for Apple’s present day success increases, because he was the creator of UNIX too.

The Bell Labs.

It is impressive the influence of Dennis Ritchie in all modern languages, like, C#, Java, Shell scripting, and a lot of others that have their dialect based on C language, but when he created the C language I think that has was just thinking about reusing his works in new models of computers that were been born in the mid seventies.

In those days computer use was restricted to universities and big companies. Considering the corporate world I can say that this environment was a controlled place and it’s growth was maintained by other big companies like Hewlett Packard and IBM, but in university and the world of research this growth was more open and with no boundaries, I think that was almost chaotic.

At this time a well known research lab was the source of the biggest researches of the sixties and seventies, considering the computer science scene. This lab sponsored the development of a computer digital language whose main goal was to create a generic and abstract language capable to access the low level resources of any machine using a lightweight set of reserved commands, making it easier to learn than machine language.

I’m talking about the Bell Laboratories, a well known research institute at that time, created by another great genius and the father of all modern communication found today, Alexander Graham Bell. I remember in the early nineties I thought Bell Labs to be the most important place of technology since the sixties until those days and I was really fascinated by their creations, since C, UNIX and C++, all related to computer science, but if we consider the big legacy of Bell Laboratories, I must cite the transistor invention and the telephone, this one being the big start-up of Bell labs.

Dennis Ritchie and Ken Thompson at Bell Labs
Dennis Ritchie and Ken Thompson at Bell Labs

Maybe you know Bell Labs as AT&T, a big american telecommunication company from the eighties and nineties, but in fact AT&T is older than we know and the relationship with Bell labs came from the twenties and in my point of view, AT&T was a company behind the Institute Bell Labs, giving it financial support to develop the base of the current digital technology in the world.

Today Bell Labs is part of a French telecommunications company, known as Alcatel-Lucent and the good news about this is that the new company is keeping focus on technologies based on networking, software and other digital technologies. On the other hand other basic technologies like semiconductor research was taken apart.

The creation of the C language

 In the early nineties, I was very interested to learn about computer languages because I had started to study computer science in university and I was living a special moment where my colleagues and teachers were exchanging a lot of information about computer languages, mathematics, physics and other basic concepts.

In this motivating scenario where all seemed to be new, I was presented to the C language by several colleagues and specifically by a teacher, that was a student of the author of the well known best selling book Turbo C – The complete reference, Herbert Schildt.

The new edition of a classic - by Herbert Schildt.
C – The complete reference (Herbert Schildt)

Herbert Schildt was my first gate to the C language and after I started to learn just reading his books I wanted to learn about the creator of C language and why it was created, then the big question is why Dennis Ritchie created the C language ?

There are a lot of theories and tales about the motivation of the creation of the C language but in fact the real reason why Dennis Ritchie created the C language was because he was involved in UNIX development in conjunction with his big friend and colleague Ken Thompson, in the early seventies.

In those days, the UNIX operating system was barely beginning and it was completely written in assembly language for the DEC PDP-7 and it was known that PDP-7 was almost obsolete, then when the new DEC PDP-11 was released, the UNIX system would be dead too fast, because the compatibility between those machines was not so simple and natural as in modern computers.

UNIX (Thompson/Ritchie creation)
UNIX (Thompson/Ritchie creation)

The best choice was to look for a new, powerful and abstract language to use in his port of the UNIX operating system and the first choice of Ken Thompson was the B language, that is a variant of an older language, called BCPL.

Unfortunately B lacks a lot of features to help the programmers make good, abstract and scalable softwares.

Knowing all of these limitations Dennis Ritchie started to create the C language, based on some concepts of B language but without all of the features lacking of the B language.

After this, in the mid seventies the UNIX system was completely rewritten using the C language and until now UNIX and C, both, have been the most important technologies present on several modern computers and for overall learning in computer science too, thanks to Dennis Ritchie and Ken Thompson.

The legacy

Today we are living a great moment in the area of technology, a moment when new and exciting technologies are being born every day. But I think that we must never forget about these grand masters of computer science, that in the past created the strong base that we are using now and Dennis Ritchie is for me the most important of all computer scientists. Just because other great masters like Bjarne Stroustup, the father of C++, James Gosling, the father of Java and many other important guys, based their creations on Dennis Ritchie’s work.

C++ (Created by Bjarne Stroustrup)
C++ (Created by Bjarne Stroustrup)

I believe that Dennis Ritchie is directly and indirectly influencing all generations of new computer scientists and the IT professionals in general, because almost all commercial and open source technologies are based on his work.

Just to cite an example, today we have open technologies like Java and the other hand we have closed technologies like C#, these are two technologies that are now competing for attention from most professionals of the technology information market, but it is known that both share the same syntax and other features, and why not say, the same spirit of C language…….the spirit of Dennis Ritchie.

Ken Thompson and Dennis Ritchie
Ken Thompson and Dennis Ritchie

Enjoy the silence.



Dennis Ritchie (Bell Labs page)

Dennis Ritchie death announcement (NY Times)

Steve Jobs death announcement (TechCrunch)

Apple WebSite

MacOSX (Wikipedia)

IOS (Wikipedia)

The C language (Wikipedia)

Bell Labs (Alcatel website)


C# (Wikipedia)

Java (Wikipedia)

Shell Script (Wikipedia)

Hewlett Packard


Alexander Grahan Bell (Wikipedia)

C++ (Wikipedia)



Turbo C – Complete reference (Amazon)

Herbert Schildt

Ken Thompson’s bio at Bell Labs


DEC PDP-11 (Wikipedia)

B Language (Wikipedia)

BCPL Language (Wikipedia)

Bjarne Stroustrup

James Gosling

Print Friendly, PDF & Email