[z88dk-dev] sms target change

Bridge to the z88dk-developers mailing list
Post Reply
alvin
Well known member
Posts: 1872
Joined: Mon Jul 16, 2007 7:39 pm

[z88dk-dev] sms target change

Post by alvin »

I've added the sms target to the new c lib and in doing so I've changed -create-app to create up to 512k cartridges.

Banks 00 and 01 are understood to be the 32k fixed memory portion of the executable. 8k ram sits at 0xc000. Other banks are 16k and can be mapped in the 0x8000-0xbffff range. I've named the banks "BANK_02" through "BANK_01F" in hex. If files of the name "foo_BANK_xx.bin" are found in the output directory, these are assumed to be extra 16k banks that should be added to the output binary. Any kind of padding caused by missing banks or banks not filling the full 16k is automatically added.

I've also added pragmas to customize sms header information. A simple example that shows all the customizable header elements follows.

Reference for the header info can be found here:

http://www.smspower.org/Development/ROMHeader
http://www.smspower.org/Development/SDSCHeader

Code: Select all

#pragma output SMS_HDR_PRODUCT_CODE   = 107026
#pragma output SMS_HDR_VERSION        = 1
#pragma output SMS_HDR_REGION         = 0x3
#pragma output SMS_HDR_ROM_SIZE       = 0x1

#pragma output SDSC_HDR_VERSION       = 1046
#pragma output SDSC_HDR_DATE          = 20160131
#pragma redirect SDSC_HDR_AUTHOR      = _author
#pragma redirect SDSC_HDR_NAME        = _name
#pragma redirect SDSC_HDR_DESCRIPTION = _description

#include <stdio.h>

const char author[] = "z88dk";
const char name[] = "Awesome Game";
const char description[] = "A game of awesomeness.";

char buf[100];

void main(void)
{
sprintf(buf, "Hello World\n");
}
The pragmas are shown embedded in the C source file but better practice would be to stick them in a separate pragma-include file. (See end of this section: http://www.z88dk.org/wiki/doku.php?id=l ... figuration )

The SDSC header is a recent addition by the hobbyist scene. If none of the SDSC pragmas are defined, the SDSC header is not inserted. All header elements have default values and the default value for the date is the date of the compile.


The new c lib's sms target is based on the embedded target (info at http://www.z88dk.org/wiki/doku.php?id=l ... t_embedded ), as are all new c lib targets. Sms programs need control of interrupt routines and restarts and the mechanism defined for the embedded target will work for sms programs. I have not defined any defaults in the new c lib because these seem to vary from program to program. The classic c lib is using someone's sms library to define those things for all compiles. I'm using devkitSMS as a contrasting example.


If anyone has example code for the sms written using the classic c lib, could you check that create-app still produces running code for it?



------------------------------------------------------------------------------
alvin
Well known member
Posts: 1872
Joined: Mon Jul 16, 2007 7:39 pm

Post by alvin »

I forgot to add:

Sections BANK_02 through BANK_1F are defined in the new c lib's memory map with default org 0x8000 (this can be changed via pragma -- although the most common sms memory model has banks paged in at 0x8000, banks can be paged in at other 16k slots). If any code or data is assigned to one or more of those sections, output binaries will be produced for those banks by z80asm. These are automatically picked up by create-app.
From assembler, it's easy to add code or data to a specific bank. From C, this is a candidate to be done via overlays.
sdcc provides a partial method for assigning c code and data to banks by allowing bank names to be defined on a per-source file basis. This zcc invocation will generate an object file for later linking that places the C code in BANK_05 and C read-only data in BANK_05:

zcc +sms -vn -SO3 -c -clib=sdcc_iy --max-allocs-per-node200000 test.c --codesegBANK_05 --constsegBANK_05

The codeseg will be assigned compiled C code and string data. The constseg will be assigned const data. Ram variables cannot be placed in this way by sdcc and will go to the usual DATA and BSS sections in the standard 64k memory space. On the sms this maps to address 0xc000 and for the sms, this is the only ram available so it's not missing any tricks by not being able to change ram banks.

After compiling to an object file, the .o can be added to the regular compile line to generate the final binaries.

One of the reasons for adding the sms target is to have a concrete example to test overlays with.



------------------------------------------------------------------------------
alvin
Well known member
Posts: 1872
Joined: Mon Jul 16, 2007 7:39 pm

Post by alvin »

One final detail :P

The memory map set up for the sms keeps all library code in the main 32k binary that is (nominally) always paged in in the bottom 32k. C code that is run out of another bank can still access that library code as well as all ram variables and te stack in the address range 0xc000 and up.



------------------------------------------------------------------------------
Post Reply