Difference between revisions of "Create a plain ROM"
From MSX Game Library
(→Page specific data and code) |
|||
Line 26: | Line 26: | ||
== Page specific data and code == | == Page specific data and code == | ||
− | The | + | The [[Build tool]] allows you to add data and code to a given page of a plain ROM. |
To do this, you just need to add at the root of your project, a file with a postfix <tt>_px</tt> where <tt>x</tt> is the number of the page where to place this code (0 to 3). | To do this, you just need to add at the root of your project, a file with a postfix <tt>_px</tt> where <tt>x</tt> is the number of the page where to place this code (0 to 3). | ||
And that's all. :) | And that's all. :) |
Revision as of 22:32, 2 May 2023
A plain ROM is a format of binary application to be write into a ROM. The most common use case is the creation of game cartridges. The build tool will generate a .ROM file that can be written to an EPROM (like with a Mega Flash ROM cartridge).
Principles
A plain ROM, unlike a mapped ROM, is constructed from a single block whose parts will always be seen by the Z80 at the same address. Therefore, they cannot be more than 64 KB in size (the maximum size visible to the Z80). A program in ROM is detected by the MSX system thanks to a header located at addresses 4000h or 8000h but can in theory use any space between 0000h and FFFFh. Generally, a ROM uses one or more 16 KB pages (numbered from 0 to 3). Pages 1 and 2 can be used freely, but the system expects to have special content in pages 0 and 3:
- Page 0:
- The MSX BIOS with all standard functions.
- The interrupt handling code (ISR) at address 0038h.
- Page 3:
- RAM with call stack and BIOS variables area.
- Secondary slot register at address FFFFh.
MSXgl was designed to easily override the limitations of page 0 by providing BIOS-independent functionality and by providing ISR code that can install automatically in 0038h. On the other hand, it is not easy to use page 3, especially because the call stack is located there. However, it is possible to write code that will copy the contents of page 3 to VRAM (or to RAM in another page for MSX2 or above).
Targets
To create an plain ROM you just have to choice one of the following targets format:
Target | Description |
---|---|
ROM_8K | 8 KB ROM in page 1 (4000h ~ 5FFFh) |
ROM_8K_P2 | 8 KB ROM in page 2 (8000h ~ 9FFFh) |
ROM_16K | 16 KB ROM in page 1 (4000h ~ 7FFFh) |
ROM_16K_P2 | 16 KB ROM in page 2 (8000h ~ BFFFh) |
ROM_32K | 32 KB ROM in page 1&2 (4000h ~ BFFFh) |
ROM_48K | 48 KB ROM in page 0-2 (0000h ~ BFFFh) |
ROM_48K_ISR | 48 KB ROM in page 0-2 (0000h ~ BFFFh) with ISR replacement |
ROM_64K | 64 KB ROM in page 0-3 (0000h ~ FFFFh) |
ROM_64K_ISR | 64 KB ROM in page 0-3 (0000h ~ FFFFh) with ISR replacement |
ROM | Alias for ROM_32K |
For more detail, see Target article.
Page specific data and code
The Build tool allows you to add data and code to a given page of a plain ROM. To do this, you just need to add at the root of your project, a file with a postfix _px where x is the number of the page where to place this code (0 to 3). And that's all. :)
The page file can be either in C (.c) or in assembler (.asm). Data and code are accumulated from the following addresses:
- Page 0:
- 0000h (for targets without ISR)
- 0100h (for targets with ISR)
- Page 1: 4000h
- Page 2: 8000h
- Page 3: C000h
Exemple
Let's say you have a project named Monkey with the ROM_32K target format but for which you have almost no space left. You can then switch to ROM_48K_ISR format in your project configuration (project_config.js) to have 16 KB more! You don't have to change anything in your program (it still starts at 4000h), but you can now add data or code to page 0 by including it in a monkey_p0.c file (you can also move there data or code from the main program).
Since you are using the ROM_48K_ISR format, the build tool will automatically add the necessary interrupt handling code for the system at address 0038h. As a result, all data and code contained in file monkey_p0.c will be added from address 0100h (to avoid overwriting the ISR code). This way, page 0 of your cartridge will always remain selected by the system and you won't have to juggle with slots or do inter-slot reading: The content of page 0 is directly accessible between addresses 0100h and 3FFFh.
All data labels or functions declared in monkey_p0.c can be used in your main program, but of course you have to provide their definitions (defined as extern).