By this page i want to offer my MSX projects to the community. Sorry about my poor english writting. I am spanish :-)
crt0msx_msxdos_advanced.s
)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:
int main(char **argv, int argc)
). It adds a few overhead bytesin
and out
to to make easy the Hitech C code compatibilitymemcpy
and memset
functionsFirst we have to do is to assemble the .s
previous files and to compile the .c
previous files using the sdasz80
assembler and the sdcc
compiler included in SDCC package:
$ sdasz80 -o crt0msx_msxdos.s
"or" $ sdasz80 -o crt0msx_msxdos_advanced.s
$ sdasz80 -o putchar.s
$ sdasz80 -o getchar.s
$ sdasz80 -o dos.s
$ sdasz80 -o dos2.s
$ sdasz80 -o interrupt.s
$ sdasz80 -o ioport.s
$ sdasz80 -o keyboard.s
$ sdasz80 -o vdp.s
$ sdcc -mz80 -c -o conio.rel conio.c
$ sdcc -mz80 -c -o heap.rel heap.c
$ sdcc -mz80 -c -o mem.rel mem.c
We obtain 11 object files with .rel
extension and same name. Let's write a small C sample code for testing ej.c
:
#include "conio.h" #include "dos.h" void main(void) { puts("Hello, world :-)\r\n"); exit(0); }
That we compile this way:
$ sdcc -mz80 --code-loc XXXX --data-loc 0 --no-std-crt0 crt0msx_msxdos.rel putchar.rel getchar.rel dos.rel conio.rel ej.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. XXXX indicates code location: for crt0msx_msxdos.s
XXXX = 0x0107 and for crt0msx_msxdos_advanced.s
XXXX = 0x0178. Global variables will be allocated just after code.
If there are no compile-time errors, among the output files we should have the ej.ihx
IntelHex file. Now we process this file with the hex2bin
tool to obtain a binary code:
$ hex2bin ej.ihx
After this command we should have a ej.bin
in the current folder, that we can rename directly to ej.com
and execute it in our MSX:
$ mv ej.bin ej.com
#include "types.h" #include "mem.h" #include "dos.h" #include "vdp.h" uint8_t scratch[128]; uint8_t ge5_load(char *file_name, uint8_t vramh, uint16_t vraml) { fcb f; uint8_t i; memset((uint8_t *) &f, 0, sizeof(fcb)); f.record_size = 128; f.drive = 0; memcpy(f.name, file_name, 11); if (open(&f) != 0) return 0; vdp_set_write_address(vramh, vraml); for (i = 0; i < 213; i++) { if (block_set_data_ptr(scratch) != 0) return 0; if (block_read(&f) != 0) return 0; if (i == 0) vdp_load_screen(scratch + 7, 121); // to skip GE5 header else vdp_load_screen(scratch, 128); } close(&f); return 1; } int main(void) { vdp_set_screen5(); ge5_load("EXAMPLE GE5", 0, 0x0000); // load at visible VRAM getchar(); vdp_set_text(); exit(0); }
main
function parameters (crt0msx_msxdos_advanced.s
).main
function parameters and for solve global data initialization problem.interrupt.h
updated for recent SDCC versions. Thanks to Jan P. Schümann for the patch.memcpy
, memset
, additional VDP routines and a file read example added.files.h
and files.s
has been patched. Now lseek
function is POSIX compliant.out(address, data)
and in(address)
added.read
and write
file access routines return type changed from "unsigned int" to "int" to allow negative results.main
function parameters support added and global variables initialization problem solved.The main difference between building COM and ROM files for MSX with SDCC is basically the crt0
code. I recommend to read the previous section.
In the Nerlaska's MSX web there are a lot of info about this topic. Both Alberto Orante and I will contribute with additional code for building ROMs using SDCC. Here this is a modification of the MSXDOS interrupt routines by Alberto.
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).
sbiload
package: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.
In this section I will put source code, tools and data related to VDP programming.
á é í ó ú ü Á É Í Ó Ú Ü ñ Ñ ¡ ¿
and some minor symbols. Here is:screen 2
compatible tiles (1 bit per pixel, white = 1, black = 0). This is the result of applying this utility to the previous Latin1 charset table.PSG programming: tools and source code.
psg_sample
. This code uses the logaritmic conversion table listed at http://map.tni.nl/articles/psg_sample.php.Fixed point math related section. For Z80 and/or MSX specific.
This work is licensed under a Creative Commons License.
Page maintained by Avelino Herrera Morales