It sounds like you've been having some fun
Is there a community around these devices?
You're targetting a rom cartridge then - do you have access to the full 64k space and how much ram do you have (or maybe you can decide that on cartridge)?
Can anyone recommend me how to cleanly add the new V-Tech platform using the new lib? Which files are the bare minimum, where should I put them etc. I would like to start with the bare minimum console in/out and add sound, serial, printer etc. later on. I have the sources, I just need to known where they should go.
The first step should be a bare initial target so you know all the mechanics are in place.
For the newlib, the source tree is completely contained in:
z88dk/libsrc/_DEVELOPMENT ( https://github.com/z88dk/z88dk/tree/mas ... EVELOPMENT
The headers are defined in:
z88dk/include/_DEVELOPMENT/proto ( https://github.com/z88dk/z88dk/tree/mas ... MENT/proto
These headers are written in an m4 form so that they can be expanded for each of the supported c compilers in the ../sccz80, ../sdcc, ../clang subdirectories, which you can look at for a more normal header. The compilers will use their version of the headers.
In the source tree, everything to do with a specific target is in:
z88dk/libsrc/_DEVELOPMENT/target ( https://github.com/z88dk/z88dk/tree/mas ... ENT/target
For your target, you will create a new directory using the same acronym passed to zcc when compiling. Eg, "zcc +zx ..." is used to compile zx spectrum programs so the zx spectrum gets a "zx" subdirectory.
Inside the target's subdirectory, you will be specifying what functions are part of the library (in library/ - paths are relative to z88dk/libsrc/_DEVELOPMENT), what crt code is available (in startup/ - this is the small bit of code that runs before main to perform initialization and it would also include the restarts if the org address is zero), any drivers (in driver/ - these are mainly for devices that attach to stdio), and configuration information (in config/). The configuration files are normally per "logical unit", eg c library / sound device / etc, and they are collected together by the file "config.m4" in the main target directory.
Outside of the target directory in z88dk/libsrc/_DEVELOPMENT, there are some places for target-specific code. The arch/ subdirectory is set aside for target specific code and it has corresponding header files in z88dk/include/_DEVELOPMENT/proto/arch ( https://github.com/z88dk/z88dk/tree/mas ... proto/arch
Some of the code is also intended to be a common cross-platform interface. For example, the input library is intended to be a cross-platform means to read keyboard, joysticks and mice. So z88dk/libsrc/_DEVELOPMENT/input contains code for different targets that implement a common interface to these devices. This is something that can be optionally added later.
Once these files are in place, you inform z88dk of the target's existence by creating a .cfg file in z88dk/lib/config ( https://github.com/z88dk/z88dk/tree/master/lib/config
). Each target's acronym gets a file as in "zx.cfg" for the zx spectrum (zcc +zx ...). This cfg file contains default settings that will be loaded by zcc when it starts.
And you add the target to the list of z80 libraries to build by editing z88dk/libsrc/_DEVELOPMENT/Winmake.bat (for windows) and z88dk/libsrc/_DEVELOPMENT/Makefile (for everything else). Build the library on your own with "Winmake targetname" or "make TARGET=targetname" (eg "Winmake zx" or "make TARGET=zx") from the z88dk/libsrc/_DEVELOPMENT directory.
After these things are done, the target is live and you can specialize it further.
I know that's a lot so maybe the best course is to just enumerate the steps for adding a target in a step by step manner as you're finishing them.
The first goal will be to have a bare minimum target functioning.
1. Pick an acronym that is used in compile lines as in "zcc +vt2k .." (I don't know what the best one would be - here I'm trying on vtech2000). The acronym should be short and descriptive somehow and needs to be unique in z88dk/lib/config ( https://github.com/z88dk/z88dk/tree/master/lib/config
) because it will be getting a cfg file there.
2. Create a target directory in z88dk/libsrc/_DEVELOPMENT/target ( https://github.com/z88dk/z88dk/tree/mas ... ENT/target
). You can see there are directories for cpm,zx,etc. Add another like "vt2k".
3. Copy the contents of z88dk/libsrc/_DEVELOPMENT/target/z80 to z88dk/libsrc/_DEVELOPMENT/target/vt2k. The z80 target is the minimum newlib target. So copying that will get you to the minimum state quickly.
4. Inside the new z88dk/libsrc/_DEVELOPMENT/target/vt2k, delete "config_z80.h", "config_z80_private.inc", "config_z80_public.inc". These files are automatically generated when the library is built.
Modify each of the new files for the vt2k target.
5. In z88dk/libsrc/_DEVELOPMENT/target/vt2k/config:
"config_clib.m4" does some configuration of the library. You can make any changes you like up to line 512 ( https://github.com/z88dk/z88dk/blob/mas ... ib.m4#L512
) where the end of the user configuration is - the rest of the lines are just generating output from the config. You probably won't want to make any changes.
"config_clib.m4.bak" should be a copy of "config_clib.m4". This is intended to allow someone to make changes to the main file and then quickly change them back by restoring from the backup.
"config_clib_const.m4" contains clib constant definitions, of which there are none for now. Things like ioctl messages will go here when the stdio drivers are written.
"config_clib_const.m4.bak" is a copy of "config_clib_const.m4"
"config_cpu.m4" contains information on the z80. You'll want to set the correct clock "define(`__CPU_CLOCK', 4000000)". If you have an nmos z80 or you don't know, always keep options on nmos z80. There is a bug concerning the "ld a,i" instruction in nmos z80s for which the library can provide a workaround that will work on both nmos and cmos z80s.
"config_cpu.m4.bak" is a copy of "config_cpu.m4"
"config_target.m4" contains defines pertaining to the machine itself. This file is also defining a label that will be used to identify the target while compiling and assembling. You'll want to do a search and replace of "__EMBEDDED_Z80" with something like "__VT2K" over the entire file. You may also be giving names to io ports here - see some of the other targets for examples. We always have two leading underscores for names in config files so that they remain in the "system's namespace". The idea is c headers will selectively expose these names by eliminating the two leading underscores.
"config_target.m4.bak" is a copy of "config_target.m4"
6. In z88dk/libsrc/_DEVELOPMENT/target/vt2k/library:
The three files here determine what functions go into the target's library. Initially you want all the generic stuff and none of the target-specific things. The list files copied from the z80 target do exactly that so you shouldn't have to make any changes. But you can see what is in the library by following the list files yourself. The root directory for the list files is z88dk/libsrc/_DEVELOPMENT.
There are three list files here for three different versions of the library: one version is for sccz80, one for sdcc_ix and one for sdcc_iy (sdcc operated with --reserve-regs-iy flag).
7. In z88dk/libsrc/_DEVELOPMENT/target/vt2k/startup
This directory contains all the crts - ie the startup code. Some targets have many, you'll be starting with one. The mechanism that z88dk uses to select a specific crt is via a startup value either provided on the compile line (-startup=10) or selected in the target's cfg file. So the crts are typically numbered by startup value and here the crt is number 0.
Rename the crt from "z80_crt_0.asm.m4" to "vt2k_crt_0.asm.m4"
Editing "vt2k_crt_0.asm.m4" ( https://github.com/z88dk/z88dk/blob/mas ... t_0.asm.m4
lines 1-9 you'll want to change the comments to reference the vtech pre-computer 2000 and update the path listed.
line 15, change to include "config_vt2k_public.inc". This will be a file containing all the defined constants from the config directory. When the library is built, the file will be generated.
line 24, change to include(`vt2k_rules.inc'). This file will process target-specific pragmas, of which you will initially have none.
The compile time options are a collection of defaults overruled by compile-time pragmas:
https://www.z88dk.org/wiki/doku.php?id= ... figuration
The rules files are determining the final value of those compile time options, which the crt will implement (or not, but the ones provided by z88dk do).
line 30 sets the memory map. No change here.
lines 32-49 is driver instantiation. This is where devices are attached to stdin, stdout, stderr. For now, leave as is. There will be no stdin,stdout,stderr defined. This section is the primary difference between crts for a target.
lines 61-70 no change. The user can choose to insert code that is executed first with appropriate pragma.
lines 72-80 no change. If the org is 0, the page zero code will be supplied ( https://github.com/z88dk/z88dk/blob/mas ... ro_z80.inc
Inside the crt the root dir for includes is z88dk/libsrc/_DEVELOPMENT/target/vt2k . If you need different page zero code, you would include it here and save it in target/vt2k as include "crt_page_zero_vt2k.inc" or similar.
line 86 is where the main part of the crt starts. It's going to optionally disable interrupts, optionally set the stack location, optionally set a command line for argc/argv (this code will do none or empty), initialize data and bss sections. Most likely no changes.
line 124. section code_crt_init allows programs to insert initialization code just before main is called.
Then interrupts are optionally enabled and main is called.
After that there's the exit stack to run and returning (or not) appropriately to the caller.
None of these things you are likely to have to change - you will instead be setting compile time defaults that will govern default behaviour below.
8. In z88dk/libsrc/_DEVELOPMENT/target/vt2k/config.m4
lines 39-43 change the paths from "target/z80/..." to "target/vt2k/..."
This file gathers all the config files from the config directory.
9. In z88dk/libsrc/_DEVELOPMENT/target/vt2k/crt_config.inc ( https://github.com/z88dk/z88dk/blob/mas ... config.inc
This is where you will define the default compile time behaviour such as where in memory things go and how the program exits.
Have this page open ( https://www.z88dk.org/wiki/doku.php?id= ... figuration
) to understand the settings.
You're targetting a rom cartridge so it will only make sense to do rom and compressed-rom compiles. So you may want to get rid of the CRTCFG=0 case in lines 16-61.
Instead of "embedded rom model" you can put "vt2k rom model".
"crt_config.inc.bak" should be a copy of "crt_config.inc"
10. In z88dk/libsrc/_DEVELOPMENT/target/vt2k/crt_memory_map.inc
No change. This sets the memory map for the compile and the library supplied one is adequate for 64k systems.
11. In z88dk/libsrc/_DEVELOPMENT/target/vt2k/z80_rules.inc
Rename to vt2k_rules.inc. This is an empty file as you don't have any target specific pragmas yet.
12. In z88dk/libsrc/_DEVELOPMENT/target/vt2k/z80_crt.asm.m4
Rename to vt2k_crt.asm.m4. This is the master crt that selectes the actual crt used from the startup directory depending on the startup value.
lines 24-39. The user is supplying a crt, you supply defaults for CRTCFG and MMAP. The values were defined in crt_config.inc and crt_memory_map.inc.
lines 41-111. You define cases for different startup values. The startup values are going to indicate quick default configurations. I would keep startup=1 and 2 as they define rom and compressed rom compiles as defined for the z80 target. You may want to change the startup values when you add console io.
line 8. Choose a default compile by selecting a default startup value.
Add the vt2k target to the library build list.
13. In z88dk/libsrc/_DEVELOPMENT/Winmake.bat
line 8 add vt2k in alphabetical order.
14. In z88dk/libsrc/_DEVELOPMENT/Makefile
line 5 add vt2k in alphabetical order.
You should now be able to build the vt2k library without errors.
From a console in z88dk/libsrc/_DEVELOPMENT
run "Winmake vt2k" (windows) to build the vt2k libraries
run "make TARGET=vt2k" (other) to build the vt2k libraries
The library files will be deposited in the subdirectories of z88dk/libsrc/_DEVELOPMENT/lib
Make z88dk aware of the new target.
Create file z88dk/lib/config/vt2k.cfg :
Code: Select all
# Target configuration file for z88dk
# Asm file which contains the startup code (without suffix)
# Not supported in classic library
# Any default options you want - these are options to zcc which are fed
# through to compiler, assembler etc as necessary
OPTIONS -v -O2 -SO2 -iquote. -D__Z88DK -D__VT2K -D__Z80 -clib=sdcc_iy -subtype=default
CLIB default -lvt2k_clib -lndos -Cc-standard-escape-chars
CLIB new -Cc-standard-escape-chars -D__SCCZ80 -Ca-D__SCCZ80 -Cl-D__SCCZ80 -nostdlib -isystemDESTDIR/include/_DEVELOPMENT/sccz80 -Ca-IDESTDIR/libsrc/_DEVELOPMENT/target/vt2k -lvt2k -LDESTDIR/libsrc/_DEVELOPMENT/lib/sccz80 -Cl-IDESTDIR/libsrc/_DEVELOPMENT/target/vt2k -crt0=DESTDIR/libsrc/_DEVELOPMENT/target/vt2k/vt2k_crt.asm.m4
CLIB sdcc_ix -compiler=sdcc -D__SDCC -D__SDCC_IX -Ca-D__SDCC -Ca-D__SDCC_IX -Cl-D__SDCC -Cl-D__SDCC_IX -nostdlib -isystemDESTDIR/include/_DEVELOPMENT/sdcc -Ca-IDESTDIR/libsrc/_DEVELOPMENT/target/vt2k -lvt2k -LDESTDIR/libsrc/_DEVELOPMENT/lib/sdcc_ix -Cl-IDESTDIR/libsrc/_DEVELOPMENT/target/vt2k -crt0=DESTDIR/libsrc/_DEVELOPMENT/target/vt2k/vt2k_crt.asm.m4
CLIB sdcc_iy -compiler=sdcc --reserve-regs-iy -D__SDCC -D__SDCC_IY -Ca-D__SDCC -Ca-D__SDCC_IY -Cl-D__SDCC -Cl-D__SDCC_IY -nostdlib -isystemDESTDIR/include/_DEVELOPMENT/sdcc -Ca-IDESTDIR/libsrc/_DEVELOPMENT/target/vt2k -lvt2k -LDESTDIR/libsrc/_DEVELOPMENT/lib/sdcc_iy -Cl-IDESTDIR/libsrc/_DEVELOPMENT/target/vt2k -crt0=DESTDIR/libsrc/_DEVELOPMENT/target/vt2k/vt2k_crt.asm.m4
CLIB clang_ix -compiler=clang -D__SDCC -D__SDCC_IX -Ca-D__SDCC -Ca-D__SDCC_IX -Cl-D__SDCC -Cl-D__SDCC_IX -nostdlib -isystemDESTDIR/include/_DEVELOPMENT/sdcc -Ca-IDESTDIR/libsrc/_DEVELOPMENT/target/vt2k -lvt2k -LDESTDIR/libsrc/_DEVELOPMENT/lib/sdcc_ix -Cl-IDESTDIR/libsrc/_DEVELOPMENT/target/vt2k -crt0=DESTDIR/libsrc/_DEVELOPMENT/target/vt2k/vt2k_crt.asm.m4
CLIB clang_iy -compiler=clang --reserve-regs-iy -D__SDCC -D__SDCC_IY -Ca-D__SDCC -Ca-D__SDCC_IY -Cl-D__SDCC -Cl-D__SDCC_IY -nostdlib -isystemDESTDIR/include/_DEVELOPMENT/sdcc -Ca-IDESTDIR/libsrc/_DEVELOPMENT/target/vt2k -lvt2k -LDESTDIR/libsrc/_DEVELOPMENT/lib/sdcc_iy -Cl-IDESTDIR/libsrc/_DEVELOPMENT/target/vt2k -crt0=DESTDIR/libsrc/_DEVELOPMENT/target/vt2k/vt2k_crt.asm.m4
SUBTYPE default -Cz+rom
"CRT0" and "CLIB default" specify things for the classic library so have nothing to do with newlib. (Your target will not work with classic until another crt and library for it is added).
"OPTIONS" defines "__VT2K" - this should be the same symbol as defined in the config file way back.
"SUBTYPE default" is causing "appmake +rom" to be used when -create-app appears on the compile line. It will make a rom as output. If you want an intel hex file too, you can add the relevant option.
Add a case in arch.h:
https://github.com/z88dk/z88dk/blob/mas ... oto/arch.h
Code: Select all
This will allow the defines from your config files to be made available with #include <arch.h>.
Rebuid the headers by running "Winmake" (windows) or "make" (other) from:
At this point you should have a functioning minimal target.
Code: Select all
unsigned char buffer;
sprintf(buffer, "Hello World\n");
(sdcc as compiler)
zcc +vt2k -vn -clib=sdcc_iy -SO3 --max-allocs-per-node200000 hello.c -o hello -create-app
(sccz80 as compiler)
zcc +vt2k -vn -clib=new hello.c -o hello -create-app
Maybe check that the binary generated is ok by disassembling using z88dk-dis or other.
If you got this far the next step would be console io.