Amstrad CPC

Quick start

zcc +cpc -lcpcfs -lmz -create-app -o program adv_a.c

-or-

zcc +cpcansi -lcpcfs -lmz -create-app -o program adv_a.c

Misc notes on the CPC target

Loading Addresses

The code is compiled by default to address $6000 (24576), to run the code on a CPC you should do the following:


memory &5fff
load "[filename]",&6000
call &6000

If you produce code under $1200 and needs to get loaded then run from BASIC, the “memory” command is required; in example, to compile and run a program located at $400:

zcc +cpc -lcpcfs -lmz -zorg=1024 -create-app -o program adv_a.c

openout"d"
memory &3ff
closeout
load"mybin",&400
call &400

Floating Point Support

The CPC target supports a native maths library, this is selected using the -lmz switch when compiling.

The library that is linked in by default supports 3 models of CPC - CPC464, CPC664 and CPC6128.

Should memory be in short supply and you wish to compile for a specific CPC then you can do the following:


zcc +cpc [...] -lmz -l6128_math

or -l464_math or -l664_math which will save about 600 bytes of memory.

The generic floating point functions are still available via the “-lm” flag.

Additional functions

The additional functions introduced with the developement of the native CPC library, are now available in all the implementations; these are:

void deg();

Switch the FP engine into degrees mode
void rad();

Switch the FP engine into radians mode
double pi();

Return the value of pi.
double pow10(int x);

Returns 10^x

File IO Library (fcntl driver)

Support for file IO on the CPC has been added. This uses the CAS_ interface and as such as the limitation that only 2 files may be open at a time - one for reading and one for writing. In addition due to the firmware implementation of these routines, a 2k buffer is required for both input and output. This buffer is statically built into the program.

The following routines are not supported by the CPC fcntl library:

ftell()
fgetpos()
fsetpos()
rewind()
fseek()
creat()
lseek()
mkdir()
getcwd()
rmdir()
getwd()

Additionally, open() only supports the O_RDONLY and O_WRONLY flags.

To link in the library supply the -lcpcfs flag to the compiler. If you do not require file IO in your program then supply the -lndos flag which links in a dummy stub library that simply returns errors.

Application Creation

The appmake has been updated to support the CPC as a target. When compiling if you supply the -create-app flag then a file with the suffix .cpc is generated. This file contains a CPC disc file header which can then be easily transferred onto a CPC disc using cpcfs or a similar tool.

Putting your code into a disk image

This is an example on how you to integrate your favourite emulator tools with the z88dk features. In this case we chose the XTI (Disk Image XTender) utility, which should be available at the following address: ftp://ftp.lip6.fr/pub/amstrad/emu-uti/pcxti14.zip

  • Compile your program with the “-create-app” flag set
  zcc +cpc -lndos -create-app adv_a.c

It will create both a raw block (a.bin) and a special binary file called “a.cpc”

  • Create a blank disk image with the xti tool
  xti -newS tst.dsk
  • Insert the “special file” in the newly created disk image
  xti -incl tst.dsk
    C:\cpcemu>xti -incl tst.dsk
    Disk Image Extender v1.4 (c) 1998 Pierre Guerrier,
    DOS port by Ulrich Doewich
    Image is System, with 169 K free, 0 files over 0 entries.
    Include ? a.cpc
    Including file as A       CPC
    Include ? .
    
    C:\cpcemu>
  • Load and run the new program from within your favourite emulator, after having properly configured the virtual disk drives
  memory &5fff
  load "a.cpc",&6000
  call &6000

Putting your code into a RAM snapshot

This note is still valid, but please note that the “-create-app” flag makes life easier.

	Compile the program (optionally you can set another address for ORG)
		zcc +cpc program.c
	Prepare an empty snapshot with your preferred Amstrad emulator 
	(the snapshot format may be a bit different, but normally the locations are the same)
		memory &1fff  (BASIC command)
	Save the snapshot and exit from the emulator
	Insert the compiled code into the snapshot:
		sna_mng i a.bin loader.sna 24576 30000
	Re-run the emulator, load the modified snapshot and type:
		call &6000

Tricks using the WinAPE emulator

When using the WinAPE Amstrad CPC emulator, if runned code is 0xED, 0xFF then it activates a Breakpoint and show the debugger.

‘norecess’ suggests the following:

#define crASSERT( expression ) \
    if ( !( expression ) ) \
    { \
        asm( "defb $ed, $ff" ); \
    }

#define crBREAK( ) \
    asm( "defb $ed, $ff" );
 
platform/amstradcpc.txt · Last modified: 2008/06/03 20:56 by stefano
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki