Sign in Join
Wiki copytemporary

MSX-DOS: what changed

Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
11MSX-DOS is a CP/M-DOS-like operating system developed by Microsoft for the Z80 based MSX computer.
22
33Starting with revision r45600 Free Pascal has initial support for generating code for MSX-DOS.
44
55## Overview
66
77The compiler generates flat COM files which reside in the Transient Program Area (TPA) of the memory that reaches from \$100 to the address of the DOS (which might start at something like \$DEF0 or so). The top of the TPA is the place of the stack (at program start the top of the stack points below the start of the DOS) and FPC reserves an area for the heap inside the TPA as well. Thus the size for the program code and data is currently restricted to the remaining size. Mechanisms for (transparently) utilizing the slot mechanisms of the MSX need yet to be researched. Due to this restriction extreme care needs to be taken when linking in code as the limit can be reached quickly and quietly.
88
99At least MSX-DOS 2.0 or newer is required.
1010
1111In addition FPC produces rather verbose code compared to e.g. Turbo Pascal 3.0. It needs to be seen whether this can be improved in the future.
1212
1313As of revision r45600 the *System* unit is supported, but neither the *DOS* nor the *SysUtils* unit are. The *ObjPas* and *ISO7185* units are compiled though not yet tested. Console as well as File I/O are implemented, though only the former is tested due to apparent bugs in the code generator.
1414
1515## Building the compiler
1616
1717First of you need the *ihxutil* utility. For this simply do a build of FPC for your host target which will build the utility as well and the resulting binary will then reside in *utils/ihxutil/bin/\<HOSTCPU\>-\<HOSTOS\>*.
1818
1919Currently a *make all* in the top level directory of the FPC sources does not fully succeed, but it works enough that the resulting compiler and RTL can be used, so use the following:
2020
21-`make all OS_TARGET=msxdos CPU_TARGET=z80 OPT=-CX`
21+```text
22+make all OS_TARGET=msxdos CPU_TARGET=z80 OPT=-CX
23+```
2224
2325## Building a program
2426
2527Once you've build the compiler and RTL you can then build programs using the following command:
2628
27-`./compiler/ppcrossz80 -n -Tmsxdos -Furtl/units/z80-msxdos -viwn -FE<OUTPUTDIR> -FDutils/ihxutil/bin/<HOSTCPU>-<HOSTOS> -CX -XX file.pp`
29+```text
30+./compiler/ppcrossz80 -n -Tmsxdos -Furtl/units/z80-msxdos -viwn -FE<OUTPUTDIR> -FDutils/ihxutil/bin/<HOSTCPU>-<HOSTOS> -CX -XX file.pp
31+```
2832
2933The options *-CX -XX* are very important to enable smartlinking to have even remotely a chance to fit the program into the available space.
3034
3135If you place the *ihxutil* utility into a directory reachable by the PATH environment variable you can leave out the *-FD...* parameter.
3236
3337## Setting heap and stack size
3438
3539The default heap size is 256 Byte and the default stack size is 1024. This can be changed using the *\$MEMORY* directive as documented [here](https://www.freepascal.org/docs-html/current/prog/progsu102.html#x110-1110001.3.19). The format of the directive is
3640
37-`{$MEMORY StackSize,HeapSize}`
41+```text
42+{$MEMORY StackSize,HeapSize}
43+```
3844
3945## Known problems
4046
4147This is a list of currently known problems:
4248
4349- Parameters are not correctly initialized (code generator problem?)
4450- [[Assign]]() does not correctly set the filename (code generator problem?)
4551- HexStr() does not result in correct hex strings (code generator problem?)
4652- MkDir(), ChDir(), RmDir() are not implemented (MSX-DOS does not seem to support these?)
4753
4854## Differences to Turbo Pascal 3.0
4955
5056A common Pascal compiler for MSX is Turbo Pascal 3.0. There are a few significant differences between FPC and that version of Turbo Pascal (even if mode *TP* is used). In general a look at the [Language Reference Guide](https://www.freepascal.org/docs-html/current/ref/ref.html) and maybe also the [Programmer's Guide](https://www.freepascal.org/docs-html/current/prog/prog.html) of FPC is suggested.
5157
5258### Support for units
5359
5460Turbo Pascal 3.0 did not yet support the concept of units that premiered in newer versions of Turbo Pascal. FPC however does support them, so you can put your code into separate units. Though you can still use include files if you want to, but units like *System* will be used automatically.
5561
5662See also [here](https://www.freepascal.org/docs-html/current/ref/refse106.html#x216-23800016.2)
5763
5864### Inline assembly
5965
6066FPC does not support Turbo Pascal's *Inline()* intrinsic to provide inline assembly. Instead FPC provides a mnemonic based inline assembly that is started with **asm** and ended with **end**. Whole functions can be declared such if they're marked with the **assembler** directive (plus probably **nostackframe** to avoid the compiler setting up a stackframe).
6167
6268See also [here](https://www.freepascal.org/docs-html/current/ref/refch18.html#x232-25400018)
6369
6470### Inlining
6571
6672FPC can inline functions declared with the **inline** directive (there are some restrictions though, e.g. no assembly blocks allowed, no open array parameters and a few others), meaning that a call is avoided at the expense of potentially bloating the binary size, though it might lead to better optimized code (especially if constant parameters are used).
6773
6874See also [here](https://www.freepascal.org/docs-html/current/ref/refsu73.html#x191-21300014.10.4)
6975
7076---
7177*From the Free Pascal wiki, page "MSX-DOS", as it stood on 2022-09-07 after a change by Alextp, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*

Back to history