Skip to content

Poking at Z88DK

December 31, 2015

I have SDCC working with a few issues. Most notably I have to specify separate code and data locations which is awkward and also, it initializes globals at run time which doubles the storage for them. I think I could work around the first issue but not the second one. I believe that Z88DK may resolve both issues so I want to try it.

Following this post, I downloaded the nightly build and unzipped it into c:\z88dk\. I updated the path and added two environment variables from the windows control panel. Reading down to the bottom of that post it looks like i could maybe move it to my H drive but I’ll try that later.

I see instructions here for re-targeting. but for now i’ll just see what i’ve got.

zcc - Frontend for the z88dk Cross-C Compiler
v3.00 (C) 1998-2004 D.J.Morris

-z80-verb        Make the assembler more verbose
-cleanup         (default) Cleanup temporary files
-no-cleanup      Don't cleanup temporary files
-make-lib        Compile as if to make a library
-preserve        Don't remove zcc_opt.def at start of run
-make-app        (deprecated) Use defer-assembly
-defer-assembly  Defer assembly until link time
-create-app      Run appmake on the resulting binary to create emulator usable file
-usetemp         (default) Use the temporary directory for intermediate files
-notemp          Don't use the temporary directory for intermediate files
-specs           Print out compiler specs
-asm             Set the assembler type from the command line (z80asm, mpm, asxx, vasm, binutils)
-compiler        Set the compiler type from the command line (sccz80, sdcc)
-crt0            Override the crt0 assembler file to use
-pragma-define   Define the option in zcc_opt.def
-pragma-need     NEED the option in zcc_opt.def
-pragma-bytes    Dump a string of bytes zcc_opt.def
-subtype         Set the target subtype
-clib            Set the target clib type
-startup         Set the startup type
-nostdlib        If set ignore INCPATH, STARTUPLIB
-Cp              Add an option to the preprocessor
-Ca              Add an option to the assembler
-Cl              Add an option to the linker
-Cz              Add an option to appmake
-E               Only preprocess files
-R               Generate relocatable code
-D               Define a preprocessor option
-U               Undefine a preprocessor option
-I               Add an include directory for the preprocessor
-L               Add a library search path
-l               Add a library
-O               Set the peephole optimiser setting for copt
-SO              Set the peephole optimiser setting for sdcc-peephole
-h               Display this text
-v               Output all commands that are run (-vn suppresses)
-bn              Set the output file for the linker stage
-vn              Run the compile stages silently
-c               Only compile the .c files to .o files
-a               Only compile the .c files to .asm/.opt files
-S               Only compile the .c files to .asm/.opt files
-m               Generate an output map of the final executable
-g               Generate a global defs file of the final executable
-s               Generate a symbol map of the final executable
-o               Set the output files
-nt              Set notruncate on the appmake options
-M               Define the suffix of the object files (eg -Mo)

C:\Users\Bill\Desktop\olduinoZ\z88dk\helloworld>z80asm -h
Z80 Module Assembler 2.8.2, (c) InterLogic 1993-2009, Paulo Custodio 2011-2015

  z80asm [options] { @<modulefile> | <filename> }

  [] = optional, {} = may be repeated, | = OR clause.

  To assemble 'fred.asm' use 'fred' or 'fred.asm'

  <modulefile> contains list of file names of all modules to be linked, one module per line.

  File types recognized or created by z80asm:
    .asm = source file (default), or alternative -e<ext>
    .obj = object file (default), or alternative -M<ext>
    .lst = list file
    .bin = Z80 binary file
    .sym = symbols file
    .map = map file
    .reloc = reloc file
    .def = global address definition file
    .err = error file

Help Options:
  -h, --help             Show help options
  -v, --verbose          Be verbose
* -nv, --not-verbose     Don't be verbose

Input / Output File Options:
  -e, --asm-ext=EXT      Assembly file extension excluding '.'
  -M, --obj-ext=EXT      Object file extension excluding '.'
  -o, --output=FILE      Output binary file

Code Generation Options:
  --RCMX000              Assemble for RCM2000/RCM3000 series of Z80-like CPU
  --sdcc                 Assemble for Small Device C Compiler
  -plus, --ti83plus      Interpret 'Invoke' as RST 28h
  -IXIY, --swap-ix-iy    Swap IX and IY registers
  -C, --line-mode        Enable LINE directive

  -I, --inc-path=PATH    Add directory to include search path
  -L, --lib-path=PATH    Add directory to library search path
  -D, --define=SYMBOL    Define a static symbol

  -x, --make-lib=[FILE]  Create a library file.lib
  -i, --use-lib=[FILE]   Link library file.lib

Binary Output:
  -b, --make-bin         Assemble and link/relocate to file.bin
* -nb, --no-make-bin     No binary file
  --split-bin            Create one binary file per section
  -d, --date-stamp       Assemble only updated files
* -nd, --no-date-stamp   Assemble all files
  -a, --make-updated-bin Assemble updated files and link/relocate to file.bin
  -r, --origin=ORG_HEX   Relocate binary file to given address
  -R, --relocatable      Create relocatable code

Output File Options:
* -s, --symtable         Create symbol table file.sym
  -ns, --no-symtable     No symbol table file
  -l, --list             Create listing file.lst
* -nl, --no-list         No listing file
* -m, --map              Create address map
  -nm, --no-map          No address map file
  -g, --globaldef        Create global definition file.def
* -ng, --no-globaldef    No global definition file
C:\Users\Bill\Desktop\olduinoZ\z88dk\helloworld>type helloworld.c
   print the string "hello World!"
#include <stdio.h>
#include <cpuz80spd4port40.h>
void main()
        printf("Hello World!\n");

C:\Users\Bill\Desktop\olduinoZ\z88dk\helloworld>zcc -no-cleanup helloworld.c

copy c:\z88dk\Lib\Config\\..\..\\lib\z88_crt0.opt C:\Users\Bill\AppData\Local\Tmp\s7g4_1.opt
        1 file(s) copied.
copy C:\Users\Bill\AppData\Local\Temp\s7g4_1.opt C:\Users\Bill\AppData\Local\Tep\s7g4_1.asm
        1 file(s) copied.
zcpp -I. -DZ80 -DZ88 -D__Z88__  -DSCCZ80 -DSMALL_C -Ic:\z88dk\Lib\Config\\..\../include  helloworld.c C:\Users\Bill\AppData\Local\Temp\s7g4_.i

sccz80  -asm=z80asm  C:\Users\Bill\AppData\Local\Temp\s7g4_.i

copt c:\z88dk\Lib\Config\\..\..\/lib/z80rules.2 < C:\Users\Bill\AppData\Local\Tmp\s7g4_.asm  						> C:\Users\Bill\AppData\Local\Temp\s7g4_.op1

copt c:\z88dk\Lib\Config\\..\..\/lib/z80rules.1 < C:\Users\Bill\AppData\Local\Tmp\s7g4_.op1  						> C:\Users\Bill\AppData\Local\Temp\s7g4_.opt

z80asm  -eopt  -ns -Mo -Ic:\z88dk\Lib\Config\\..\..\/lib C:\Users\Bill\AppData\ocal\Temp\s7g4_.opt

z80asm -a -m -Mo -Lc:\z88dk\Lib\Config\\..\..\/lib/clibs
	-oa.bas -iz88_clib -iz80_crt0

 Directory of C:\Users\Bill\Desktop\olduinoZ\z88dk\helloworld

28/12/2015  02:18 PM               996 a.bas
28/12/2015  02:18 PM               116 a.reloc
28/12/2015  02:15 PM               144 helloworld.c
28/12/2015  02:19 PM             1,698 helloworld.opt
28/12/2015  02:19 PM               246 zcc_opt.def
               5 File(s)          3,200 bytes
               2 Dir(s)  12,943,360,000 bytes free

C:\Users\Bill\Desktop\olduinoZ\z88dk\helloworld>type helloworld.opt
;* * * * *  Small-C/Plus z88dk * * * * *
;  Version: 20140624.1
;       Reconstructed for z80 Module Assembler
;       Module compile time: Mon Dec 28 14:19:00 2015

        ; MODULE        helloworld.c

        INCLUDE "z80_crt0.hdr"

        ld      hl,i_1+0
        push    hl
        ld      a,1
        call    printf
        pop     bc

        defm    "Hello World!"
        defb    13

        defm    ""
        defb    0

; --- Start of Static Variables ---

; --- Start of Scope Defns ---

        EXTERN  rnd_saveblock
        EXTERN  sprintf
        EXTERN  fgetc
        EXTERN  freopen
        EXTERN  fgets
        EXTERN  open_z88
        EXTERN  creat
        EXTERN  close
        EXTERN  fread
        EXTERN  getwd
        EXTERN  fseek
        EXTERN  ltoa_any
        EXTERN  fopen
        EXTERN  ftell
        EXTERN  fprintf
        EXTERN  vsscanf
        EXTERN  __sgoioblk
        EXTERN  fgets_cons
        EXTERN  fputc
        EXTERN  scanf
        EXTERN  fputs
        EXTERN  lseek
        EXTERN  writebyte
        EXTERN  fclose
        EXTERN  rmdir
        EXTERN  fdopen
        EXTERN  fdtell
        EXTERN  freopen_z88
        EXTERN  getarg
        EXTERN  getcwd
        EXTERN  vfprintf_comp
        EXTERN  fscanf
        EXTERN  fdgetpos
        EXTERN  write
        EXTERN  puts_cons
        EXTERN  vfprintf_mini
        EXTERN  feof
        EXTERN  getk
        EXTERN  gets
        EXTERN  vfprintf_fp
        PUBLIC  _main
        EXTERN  read
        EXTERN  open
        EXTERN  fopen_z88
        EXTERN  rnd_erase
        EXTERN  rnd_loadblock
        EXTERN  puts
        EXTERN  fwrite
        EXTERN  rename
        EXTERN  fchkstd
        EXTERN  readbyte
        EXTERN  fgetc_cons
        EXTERN  remove
        EXTERN  vsprintf
        EXTERN  vfscanf
        EXTERN  nropen
        EXTERN  fgetpos
        EXTERN  printf
        EXTERN  sscanf
        EXTERN  printk
        EXTERN  printn
        EXTERN  closeall
        EXTERN  ungetc
        EXTERN  fabandon
        EXTERN  _vfprintf
        EXTERN  fputs_callee
        EXTERN  fputc_callee
        EXTERN  fputc_cons

; --- End of Scope Defns ---

; --- End of Compilation ---

So it looks like the final output is in a.bas although the code doesn’t look right to me but then i don’t know what target i was compiling for!
15-12-31 zcc output


From → Olduino/Z

  1. z88dk has changed quite a lot and you’re heading toward the old side in your post above 🙂

    The current documentation (under construction) is here:

    Installation instructions are here:

    The best results are coming from an sdcc / z88dk combination. To make sdcc compatible there are some install instructions here:

    Since you already have sdcc installed, if you are on windows it’s enough to copy the zsdcc.exe binary mentioned to sdcc’s bin directory. Otherwise you can go through the build process detailed.

    Compiling using sdcc & z88dk is overviewed here:

    If you follow the links below the temporary blurb you will have a fairly good understanding of how things work.

    To get something compiling immediately for your project, I’d use the embedded target and a RAM model (currently other targets are cp/m and zx spectrum):

    zcc +embedded -vn -SO3 -startup=0 -clib=sdcc_iy –max-allocs-per-node200000 test.c -o test [-lm]

    But you’ll need to change the ORG address away from 0 by adding a pragma in the test.c source:

    #pragma output CRT_ORG_CODE = 32768

    With an ORG away from 0, the program will try to return to the monitor after exit. Other pragmas you might need are changing the stack location (REGISTER_SP = ?) and maybe getting rid of automatic malloc (CLIB_MALLOC_HEAP_SIZE = 0). The default has the heap placed in the space between the end of the BSS section and the bottom of the stack.

    There are several things you can do to reduce code size which are documented in the links above.

    The embedded target has no stdin, stdout, stderr but you can still use the sprintf and sscanf families as well as open memstream files to do file i/o in memory (heap is required for this). Maybe to test output you could sprintf to a buffer and output that to the serial port one char at a time.

    To add drivers to stdin, stdout, stderr the library provides terminal (console) base classes which can be derived from or serial character devices which can be derived from. Both will take care of cr/lf conversion and the former will add text editing features. But instructions for creating a new target is probably best asked in the z88dk forum. You should see much smaller and faster output binaries than with sdcc alone.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: