MSX Page

Avelino Herrera Morales


Español

blog





By this page i want to offer my MSX projects to the community. Sorry about my poor english writting. I am spanish :-)




SDCC backend for MSXDOS

The SDCC is a cross-compiler for small devices that runs in Windows and in Unix/Linux platforms, that allows you to generate code for a large variety of 8-bit and 16-bit platforms. Among these plataforms we have the Z80 and the Z80 with GameBoy extensions (GBZ80).

The Z80 code that SDCC generates by default is not MSX targeted and the final output is always an IntelHex file with the code. With this backend modification for MSXDOS we will be able to easily convert these IntelHex output files into .COM files. The system requirements for cross-compiling are (for both Windows/Unix/Linux platforms):

Both packages can be installed from binaries or sources. The basic files needed to generate .COM MSXDOS executables are:

The startup code is indispensable, since it allows SDCC compiled programs to be runable in MSXDOS. putchar.s and getchar.s are only needed if you want to use stdio.h library for standard console input and output (printf, gets, et cétera) (NOTICE: scanf function aren't implemented in SDCC 2.4.0). files.s contains open, close, read, write, et cétera file handling functions for MSXDOS2. interrupt.s contains the interrupt handling functions install_isr and uninstall_isr. The ioport.h header allows programs to access I/O ports by the standard out(address, data) and in(address) way instead of ussing the "sfr at" reserved word in SDCC compiler.

First we have to do is assemble the .s previous files using the as-z80 assembler included in SDCC package:

We obtain 6 object files with .o extension and same name. Let's write a small C sample code for testing ejfile.c (we used data2.txt example data file):

#include <stdio.h>
#include <stdlib.h>
#include "files.h"
                                                                                                                                           
#define  TO_READ  50
                                                                                                                                           
char data[TO_READ + 1];
char fd;
unsigned int size;
                                                                                                                                           
void main(void) {
    fd = open("DATA2.TXT", O_RDONLY);
    if (fd < 0) {
        printf("Could not open DATA2.TXT\n");
        return;
    }
    size = read(fd, data, TO_READ);
    printf("Attempting to read %d bytes. %d readed.\n\r", TO_READ, size);
    data[size] = 0;
    printf("Buffer = '%s'\n", data);
    close(fd);
    return;
    }
	

That we compile this way:

$ sdcc -mz80 --code-loc XXX --data-loc YYY --no-std-crt0 ./crt0msx_msxdos.o ./putchar.o ./getchar.o ./files.o ejfile.c

One notice the --no-std-crt0 parameter, that indicates the compiler that should not use the default startup code for Z80, but we provide by command line. --code-loc allows to place code in a specific location: If we use crt0msx_msxdos.s we shall use XXX = 0x106, but if we use crt0msx_msxdos_advanced.s we shall use XXX = 0x170. YYY indicates location for global variables, if we use YYY = 0 global variables will be allocated just after code.

If there are no compile-time errors, among the output files we should have the ejfile.ihx IntelHex file. Now we process this file with the hex2bin tool to obtain a binary code:

$ hex2bin ejfile.ihx

After this command we should have a ejfile.bin in the current folder, that we can rename directly to ejfile.com and execute it in our MSX:

$ mv ejfile.bin ejfile.com

The ejint.c source is an example interrupt handling code that uses interrupt.o and includes interrupt.h. In this case, to compile we must add the interrupt.o file to the SDCC command line.

$ sdcc -mz80 --no-std-crt0 ./crt0msx_msxdos.o ./putchar.o ./getchar.o ./interrupt.o ejint.c

Notice that we have removed the files.o reference because linker does not need it (in this case).

Additional files
Greetings
History
Known bugs
To do
Additional info and related sites



Moonsound programming

In this section I will publish all the Moonsound related C code builded or adapted by me. All the current published codes are related to two articles appeared in the Call MSX spanish magazine about the MSX scene (numbers 3 and 4). These two articles are about Moonsound programming and all the source codes are spanish commented (sorry for the inconvenience).




Huffman compression

In this section I will put all my work related to Huffman compression implementation for MSX.

huffman.tar.gz contains an ANSI-C implementation of the Huffman compression/uncompression algorithms. This archive also contains an specific MSX implementation of the uncompress algorithm for the SDCC compiler. This MSX targeted version requires:

Read the README at huffman/msx subfolder for further details.




Graphics

In this section I will put source code, tools and data related to VDP programming.




PSG

PSG programming: tools and source code.




Fixed point

Fixed point math related section. For Z80 and/or MSX specific.




Documents



Creative Commons License

This work is licensed under a Creative Commons License.



Page maintained by Avelino Herrera Morales