How do I get z88dk to work on a completely new target system?

Discussion about other targets
Post Reply
Stupid20CharLimit
New member
Posts: 4
Joined: Mon Feb 27, 2023 8:52 pm

How do I get z88dk to work on a completely new target system?

Post by Stupid20CharLimit »

I have a homebrew z80 computer that I would like to compile c programs for. I'm a z88dk noob and I've been trying to figure out how to use this thing on and off for quite some time now.

My kernel loads programs off of a compact flash card and has a built-in command line. A picture is worth a thousand words so here is a video of me showcasing mouse functionality on my system just so you guys can gauge sort of what kind of system this is and understand my needs a little better.

My kernel runs in assembly and has a compact flash card with a filesystem on it. I can load programs from the filesystem into ram and run them from ram. My system loads the programs into ram starting at address 3000h and does a call to that address. When the program runs its last ret instruction, it goes back to running the command line. Programs are able to use however much ram they want up to like 9000h iirc. In reality, non of my programs are ever larger than 4kb but they can be up to I think 16kb before running into problems.

My kernel has a lot of useful system subroutines starting at location b000h, each 4 bytes apart. A program can easily use these subroutines by doing a call instruction to that address. There's all kinds of subroutines but most importantly there's driver and math stuff. I would like to set up z88dk in such a way that I can access these from a c program.

Now that I have explained my system architecture in a way that my needs can hopefully be better understood, let's talk about actually getting z88dk to do stuff.

I'm pretty stumped here. If I could just set up the simplest thing that works, I could probably take it from there but I have been unsuccessful even doing that. For starters, these are the steps I've taken:
- I copied the file "z88dk/lib/config/z80.cfg" and named it "custom_z80.cfg"
- I replaced the line

Code: Select all

CRT0		 DESTDIR/lib/target/z80/classic/crt0.asm
with

Code: Select all

CRT0		 DESTDIR/lib/target/custom_z80/classic/crt0.asm
- based on random bits and pieces from other files and various projects on the internet, edited my crt0_z80.asm to look like this:

Code: Select all

    MODULE  customz80_crt0

    .globl _main
    .globl _exit
    .globl l__DATA
    .globl s__DATA
    .globl l__BSS
    .globl s__BSS
    .globl l__INITIALIZER
    .globl s__INITIALIZER
    .globl s__INITIALIZED

    .area _HEADER


    defc    crt0 = 1
    ;INCLUDE "zcc_opt.def"


    EXTERN  _main           ; main() is always external to crt0 code



    defc    CRT_ORG_CODE = 0x3000
    defc    CRT_ORG_BSS = 0x37FF
    CRT_MODEL   = 0 (RAM), 1 = (ROM, code copied), 2 = (ROM, code compressed)

    ;defc    CONSOLE_ROWS = 24
    ;defc    CONSOLE_COLUMNS = 40

    defc    CRT_KEY_DEL = 12
    defc    __CPU_CLOCK = 4000000 

    org     CRT_ORG_CODE
    jp      start

start:
    ;call    crt0_init_bss


    call    _main           ; Call user program
cleanup:
    ;push    hl              ; return code
    ;call    crt0_exit



    ;INCLUDE "crt/classic/crt_runtime_selection.asm"
    ;INCLUDE "crt/classic/crt_section.asm"

_init_end:
; The following section contains the data to copy to the _INITIALIZED section.
    .area _INITIALIZER


    ; =========== START OF CODE =========== ;
    .area _HOME

    ; SYSTEM section contains the system library code that acts as a glue between C and OS assembly.
    .area _SYSTEM

    ; TEXT section contains the actual user's code. We MUST use this section to store the code
    ; intead of the default _CODE one because the SDCC assembler/linker will always put _CODE
    ; as the first section. We don't want this behavior, we cannot override it, so let's work
    ; around it.
    .area _TEXT

    ; ============ END OF CODE ============ ;


    ; =========== START OF DATA =========== ;
    ; The following sections contain data, group them.
    .area _INITIALIZED
    .area _BSEG
    .area _BSS
    .area _DATA
    .area _HEAP
    ; ============ END OF DATA ============ ;
It was my intention for the executable code to be in a 2kb block and the bss and whatever else to go behind that in 1kb blocks or something.

When I compile a test program such as for example this:

Code: Select all

int main()
{
	int i = 4;
	int y = 5;
	char ree = '1';
	if (y < 7)
	{
		//ree = '9';
	}
	ree = '5';

	return i;
}

void test()
{
	int i = 7;
}
I get the following files:
- a test.bin file 0 bytes in size
- a test_BSS.bin file 134 bytes in size
- a test_CODE.bin file 371 bytes in size
- a test_DATA.bin file 9 bytes in size

The sizes of these files don't change regardless of what I put in "test.c".

How can I get started? I want the simplest thing I can get to work without having to rewrite my entire kernel in some weird different way. If that means no standard libraries, fine. I bet I could figure it out myself if I could get it working well enough to run a hello world on the target system but for now, I'm completely stumped.

What can I do to get something as simple as the above source code to compile both a) at all and b) run on my system?
User avatar
dom
Well known member
Posts: 2076
Joined: Sun Jul 15, 2007 10:01 pm

Re: How do I get z88dk to work on a completely new target system?

Post by dom »

Let's take this in stages. First of all, let's get something compiling to the right address and creating a single binary blob.

First of all, lets write a crt0. This one is pretty simple (though not the shortest), save it as crt0.asm in the directory along side the file you want to compile:

Code: Select all

    MODULE  crt0


    defc    crt0 = 1
    INCLUDE "zcc_opt.def"

    EXTERN    _main             ;main() is always external to crt0

    PUBLIC    cleanup           ;jp'd to by exit()
    PUBLIC    l_dcal            ;jp(hl)


IF      !DEFINED_CRT_ORG_CODE
    defc    CRT_ORG_CODE  = $9000
ENDIF

    defc    TAR__clib_exit_stack_size = 8
    defc    TAR__register_sp = -1
    defc    __CPU_CLOCK = 4000000
    INCLUDE "crt/classic/crt_rules.inc"

    org     CRT_ORG_CODE

start:
    ld      (__restore_sp_onexit+1),sp  ;Save entry stack
    INCLUDE "crt/classic/crt_init_sp.asm"
    INCLUDE "crt/classic/crt_init_atexit.asm"
    call    crt0_init_bss
    ld      (exitsp),sp
IF DEFINED_USING_amalloc
    INCLUDE "crt/classic/crt_init_amalloc.asm"
ENDIF


; Push pointers to argv[n] onto the stack now
; We must start from the end
    call    _main               ;Call user code

cleanup:
    call    crt0_exit
__restore_sp_onexit:
    ld      sp,0                ;Pick up entry sp
    ret

l_dcal:
    jp  (hl)            ;Used for call by function ptr

    INCLUDE "crt/classic/crt_runtime_selection.asm"

    INCLUDE "crt/classic/crt_section.asm"
And now let's create a binary. I'm going to hijack the sos target (because it's one of the simplest) and I'm assuming that program.c and crt0.asm are in the same directory:

Code: Select all

zcc +sos -crt0=crt0.asm program.c
After running that, you should have a file "a.bin" that is a complete binary. Obviously it doesn't integrate to anything in your OS yet, but it should run.

Once proven you can start to add it properly, there's a page here: https://github.com/z88dk/z88dk/wiki/Cla ... targetting which describes how to do It - I recommend starting off with console input/output and going from there - you'll have to write small stubs than call into your OS.
Stupid20CharLimit
New member
Posts: 4
Joined: Mon Feb 27, 2023 8:52 pm

Re: How do I get z88dk to work on a completely new target system?

Post by Stupid20CharLimit »

Ok thanks, I was able to make a program that ran correctly and made changes to a byte in memory.

Next steps are to try to get it to print a "hello world".

I've made a custom_z80 folder in z88dk/lib/target/custom_z80. In z88dk/lib/target/custom_z80/classic/cz80_crt0.asm, I have a file with mostly the contents of what you provided (I changed CRT_ORG_CODE to $3000).

I made a file called custom_z80.cfg at z88dk/lib/config. There contents are as follows:

Code: Select all

#
# Target configuration file for z88dk
#

# Asm file which contains the startup code (without suffix)
CRT0		 DESTDIR/lib/target/custom_z80/classic/cz80_crt0

# Any default options you want - these are options to zcc which are fed
# through to compiler, assembler etc as necessary
OPTIONS		 -O2 -SO2 -iquote. -lsos_clib -DZ80 -DSOS -D__SOS__ -M -Cc-standard-escape-chars -subtype=default -lndos -LDESTDIR/lib/clibs/z80

SUBTYPE     none 
SUBTYPE		default -Cz+sos
SUBTYPE		mz -Cz+mz

INCLUDE alias.inc
At this point, I can compile the same program and it will run correctly and modify the correct byte. Now I'm stuck again though. I followed exactly the instructions on the classic retargeting page. I am trying to make it so that I can call fputc_cons_native(char c) in a c program and it will call my kernel's printChar subroutine. I just need to load a value into the a register and then call an address.

So, I made the folder "z88dk/libsrc/target/custom_z80". I made a file called "custom_z80.lst" with these contents:

Code: Select all

target/custom_z80/stdio/fputc_cons_native.asm
@stdio/stdio.lst
I then made a folder called stdio and inside it made a file called "fputc_cons_native.asm". Inside this file, the contents are:

Code: Select all

.global __fputc_cons_native
_fputc_cons_native:
	
	;load whatever's in the a register?
	call $B000

	call $B008
ret
I'm pretty sure that's not correct but I'm not really sure what else to change it to other than adding or removing underscores to maybe trigger an assembler directive or something. Moving on.

Anyway next, I made my makefile by copying one from somewhere (I forgot where) and filled it out to what I thought made sense. Here are the contents:

Code: Select all

include ../../Make.config

TARGET ?= custom_z80

SUBDIRS = stdio

CLEANDIRS = $(SUBDIRS:%=%-clean)

ASMFILES = $(wildcard *.asm)
OBJECTS = $(ASMFILES:.asm=.o)

all: dirs subdirs-all $(addprefix obj/$(TARGET)/,$(OBJECTS))


subdirs-all: $(SUBDIRS)

subdirs-clean: $(SUBDIRS_CLEAN)


clean: subdirs-clean
	$(RM) -r obj
	$(RM) zcc_opt.def *.err *.o
	$(RM) */*.o */*/*.o

subdirs-clean: $(CLEANDIRS)

obj/$(TARGET)/%.o: %.asm
	$(Q)$(ASSEMBLER) -DFOR$(TARGET) -I../.. -I../../../lib/  $^
	@mv $(^:.asm=.o) $@

dirs:
	@mkdir -p obj/$(TARGET)

.PHONY:	subdirs-all $(SUBDIRS) $(SUBDIRS_CLEAN)

$(SUBDIRS):
	$(MAKE) -C $@ all TARGET=$(TARGET)

$(CLEANDIRS):
	$(MAKE) -C $(@:%-clean=%) clean
	$(RM) */*.o

Running this makefile only gives me:

Code: Select all

make[1]: *** No rule to make target 'all'.  Stop.
make: *** [Makefile:37: stdio] Error 2
Next, I edited the makefile at z88dk/libsrc/Makefile. I added the following 2 blocks of text where the wiki said to put them:

Code: Select all

TOCREATE += $(call check_target,custom_z80, custom_z80_clib.lib)

Code: Select all

custom_z80_clib.lib:
	@echo ''
	@echo '--- building custom z80 library ---'
	@echo ''
	$(call buildgeneric,custom_z80)
        TARGET=custom_z80 TYPE=z80 $(LIBLINKER) -DSTANDARDESCAPECHARS -DFORcustom_z80 -x$(OUTPUT_DIRECTORY)/custom_z80_clib @$(TARGET_DIRECTORY)/custom_z80/custom_z80.lst
When I run that makefile, I get this output:

Code: Select all

make[2]: Nothing to be done for 'all'.
make[2]: Nothing to be done for 'all'.
make[2]: Nothing to be done for 'all'.

--- building custom z80 library ---


--- SP1 Software Sprite Engine ---
# newlib and sccz80 + classic libraries
z88dk-z80asm -d -I/home/scott/Documents/git/z88dk/lib/config/../ -x/home/scott/Documents/git/z88dk/libsrc//sp1-ts2068 @ts2068hr.lst
z88dk-z80asm -d -I/home/scott/Documents/git/z88dk/lib/config/../ -x/home/scott/Documents/git/z88dk/libsrc//sp1-zx81hr -IXIY @zx81hr.lst
# sdcc + classic library
make -C zx all
cp zx/sp1-zx.lib /home/scott/Documents/git/z88dk/libsrc/
Now, when I compile using ./zcc +custom_z80 test.c, the output is
test.c:2:32: fatal error: Cannot initialise function '_fputc_cons_native' to a constant
Compilation aborted
I've already tried adding or removing underscores from the function names in various combinations so that's not the way to fix it. I'm not really sure what to do now. Any ideas?
User avatar
dom
Well known member
Posts: 2076
Joined: Sun Jul 15, 2007 10:01 pm

Re: How do I get z88dk to work on a completely new target system?

Post by dom »

This works for me:

Code: Select all

Subject: [PATCH] (customz80) Skeleton

---
 lib/config/customz80.cfg                      | 15 ++++++
 .../customz80/classic/customz80_crt0.asm      | 51 +++++++++++++++++++
 libsrc/Makefile                               |  8 +++
 libsrc/target/customz80/customz80.lst         |  3 ++
 .../customz80/stdio/fputc_cons_native.asm     | 18 +++++++
 5 files changed, 95 insertions(+)
 create mode 100755 lib/config/customz80.cfg
 create mode 100644 lib/target/customz80/classic/customz80_crt0.asm
 create mode 100644 libsrc/target/customz80/customz80.lst
 create mode 100644 libsrc/target/customz80/stdio/fputc_cons_native.asm

diff --git a/lib/config/customz80.cfg b/lib/config/customz80.cfg
new file mode 100755
index 0000000000..bef4031abc
--- /dev/null
+++ b/lib/config/customz80.cfg
@@ -0,0 +1,15 @@
+#
+# Target configuration file for z88dk
+#
+
+# Asm file which contains the startup code (without suffix)
+CRT0		 DESTDIR/lib/target/customz80/classic/customz80_crt0
+
+# Any default options you want - these are options to zcc which are fed
+# through to compiler, assembler etc as necessary
+OPTIONS		 -O2 -SO2 -iquote. -lcustomz80_clib  -DZ80 -DCUSTOMZ80 -D__CUSTOMZ80__ -M -Cc-standard-escape-chars -lndos -LDESTDIR/lib/clibs/z80
+
+
+
+
+INCLUDE alias.inc
diff --git a/lib/target/customz80/classic/customz80_crt0.asm b/lib/target/customz80/classic/customz80_crt0.asm
new file mode 100644
index 0000000000..7a8b140401
--- /dev/null
+++ b/lib/target/customz80/classic/customz80_crt0.asm
@@ -0,0 +1,51 @@
+    MODULE  crt0
+
+
+    defc    crt0 = 1
+    INCLUDE "zcc_opt.def"
+
+    EXTERN    _main             ;main() is always external to crt0
+
+    PUBLIC    cleanup           ;jp'd to by exit()
+    PUBLIC    l_dcal            ;jp(hl)
+
+
+IF      !DEFINED_CRT_ORG_CODE
+    defc    CRT_ORG_CODE  = $9000
+ENDIF
+
+    defc    TAR__clib_exit_stack_size = 8
+    defc    TAR__register_sp = -1
+    defc    __CPU_CLOCK = 4000000
+    INCLUDE "crt/classic/crt_rules.inc"
+
+    org     CRT_ORG_CODE
+
+start:
+    ld      (__restore_sp_onexit+1),sp  ;Save entry stack
+    INCLUDE "crt/classic/crt_init_sp.asm"
+    INCLUDE "crt/classic/crt_init_atexit.asm"
+    call    crt0_init_bss
+    ld      (exitsp),sp
+IF DEFINED_USING_amalloc
+    INCLUDE "crt/classic/crt_init_amalloc.asm"
+ENDIF
+
+
+; Push pointers to argv[n] onto the stack now
+; We must start from the end
+    call    _main               ;Call user code
+
+cleanup:
+    call    crt0_exit
+__restore_sp_onexit:
+    ld      sp,0                ;Pick up entry sp
+    ret
+
+l_dcal:
+    jp  (hl)            ;Used for call by function ptr
+
+    INCLUDE "crt/classic/crt_runtime_selection.asm"
+
+    INCLUDE "crt/classic/crt_section.asm"
+
diff --git a/libsrc/Makefile b/libsrc/Makefile
index 85b752b28d..f6a55d6eca 100644
--- a/libsrc/Makefile
+++ b/libsrc/Makefile
@@ -40,6 +40,7 @@ TOCREATE += $(call check_target,c7420,c7420_clib.lib)
 TOCREATE += $(call check_target,coleco,coleco_clib.lib)
 TOCREATE += $(call check_target,cpc,cpc_clib.lib cpcfs.lib cpc_math.lib)
 TOCREATE += $(call check_target,cpm,$(CPMLIBS))
+TOCREATE += $(call check_target,customz80,customz80_clib.lib)
 TOCREATE += $(call check_target,dai,dai_clib.lib)
 TOCREATE += $(call check_target,einstein,einstein.lib $(CPMLIBS))
 TOCREATE += $(call check_target,embedded,embedded_clib.lib)
@@ -1812,6 +1813,13 @@ dai_clib.lib:
 	$(call buildgeneric,dai,portable)
 	TARGET=dai TYPE=8080 $(LIBLINKER) -m8080 -DFORdai -DSTANDARDESCAPECHARS -x$(OUTPUT_DIRECTORY)/dai_clib @$(TARGET_DIRECTORY)/dai/dai.lst
 
+customz80_clib.lib:
+	@echo ''
+	@echo '--- Building Custom Z80 Library ---'
+	@echo ''
+	$(call buildgeneric,customz80,portable)
+	TARGET=customz80 TYPE=z80 $(LIBLINKER) -m8080 -DFORcustomz80 -DSTANDARDESCAPECHARS -x$(OUTPUT_DIRECTORY)/customz80_clib @$(TARGET_DIRECTORY)/customz80/customz80.lst
+
 ondra_clib.lib:
 	@echo ''
 	@echo '--- Building Ondra Library ---'
diff --git a/libsrc/target/customz80/customz80.lst b/libsrc/target/customz80/customz80.lst
new file mode 100644
index 0000000000..3f8828fef3
--- /dev/null
+++ b/libsrc/target/customz80/customz80.lst
@@ -0,0 +1,3 @@
+target/customz80/stdio/fputc_cons_native
+@stdio/stdio.lst
+
diff --git a/libsrc/target/customz80/stdio/fputc_cons_native.asm b/libsrc/target/customz80/stdio/fputc_cons_native.asm
new file mode 100644
index 0000000000..f88493602e
--- /dev/null
+++ b/libsrc/target/customz80/stdio/fputc_cons_native.asm
@@ -0,0 +1,18 @@
+;
+; Print character to screen using firmware
+;
+
+	SECTION	code_clib
+        PUBLIC  fputc_cons_native
+
+	INCLUDE	"target/dai/def/dai.def"
+
+;
+; Entry:        hl = points to char
+;
+.fputc_cons_native
+	ld      hl,2
+	add     hl,sp
+	ld	a,(hl)
+        call    $8008		;Print routine in rom
+	ret
-- 
2.30.1 (Apple Git-130)
Which I think you've got most of the parts of.

Code: Select all

% cd libsrc
% make customz80_clib.lib
% cp customz80_clib.lib ../lib/clibs
% cd ../examples/console
% zcc +customz80 world.c
WORP3
Member
Posts: 26
Joined: Thu Dec 29, 2022 12:51 pm

Re: How do I get z88dk to work on a completely new target system?

Post by WORP3 »

dom wrote: Mon Feb 27, 2023 10:20 pm Let's take this in stages. First of all, let's get something compiling to the right address and creating a single binary blob.

First of all, lets write a crt0. This one is pretty simple (though not the shortest), save it as crt0.asm in the directory along side the file you want to compile:

Code: Select all

    MODULE  crt0


    defc    crt0 = 1
    INCLUDE "zcc_opt.def"

    EXTERN    _main             ;main() is always external to crt0

    PUBLIC    cleanup           ;jp'd to by exit()
    PUBLIC    l_dcal            ;jp(hl)


IF      !DEFINED_CRT_ORG_CODE
    defc    CRT_ORG_CODE  = $9000
ENDIF

    defc    TAR__clib_exit_stack_size = 8
    defc    TAR__register_sp = -1
    defc    __CPU_CLOCK = 4000000
    INCLUDE "crt/classic/crt_rules.inc"

    org     CRT_ORG_CODE

start:
    ld      (__restore_sp_onexit+1),sp  ;Save entry stack
    INCLUDE "crt/classic/crt_init_sp.asm"
    INCLUDE "crt/classic/crt_init_atexit.asm"
    call    crt0_init_bss
    ld      (exitsp),sp
IF DEFINED_USING_amalloc
    INCLUDE "crt/classic/crt_init_amalloc.asm"
ENDIF


; Push pointers to argv[n] onto the stack now
; We must start from the end
    call    _main               ;Call user code

cleanup:
    call    crt0_exit
__restore_sp_onexit:
    ld      sp,0                ;Pick up entry sp
    ret

l_dcal:
    jp  (hl)            ;Used for call by function ptr

    INCLUDE "crt/classic/crt_runtime_selection.asm"

    INCLUDE "crt/classic/crt_section.asm"
And now let's create a binary. I'm going to hijack the sos target (because it's one of the simplest) and I'm assuming that program.c and crt0.asm are in the same directory:

Code: Select all

zcc +sos -crt0=crt0.asm program.c
After running that, you should have a file "a.bin" that is a complete binary. Obviously it doesn't integrate to anything in your OS yet, but it should run.

Once proven you can start to add it properly, there's a page here: https://github.com/z88dk/z88dk/wiki/Cla ... targetting which describes how to do It - I recommend starting off with console input/output and going from there - you'll have to write small stubs than call into your OS.
I always thought that the

Code: Select all

zcc +z80
would give the most simple target, can you tell me what the difference is between the +z80 and sos? I'm just looking for a simple target without input/output or display etc.
Stupid20CharLimit
New member
Posts: 4
Joined: Mon Feb 27, 2023 8:52 pm

Re: How do I get z88dk to work on a completely new target system?

Post by Stupid20CharLimit »

dom wrote: Tue Feb 28, 2023 12:15 pm This works for me:

Code: Select all

% cd libsrc
% make customz80_clib.lib
% cp customz80_clib.lib ../lib/clibs
% cd ../examples/console
% zcc +customz80 world.c
Ok I had to run make customz80_clib.lib instead of just make.

What do I need to make it look like in my c file for it to work? I've tried "int .fputc_cons_native(char c);", "int _fputc_cons_native(char c);", "int __fputc_cons_native(char c);" and a bunch of other guesses but haven't got it to compile like that.

I also haven't been able to make it respond to any changes I make in z88dk/libsrc/target/custom_z80/stdio/fputc_cons_native.asm. I can add its content to the crt0 file of course but I still haven't figured out what exact formatting I have to do it in to make it compile. I at least can get different error codes. Nothing I do in fputc_cons_native.asm makes the compiler spit out different errors though.

I can run the Makefile in z88dk/libsrc/Makefile but the one at z88dk/libsrc/target/custom_z80/Makefile won't work. Should I be working to solve that problem or does it not matter?
Stupid20CharLimit
New member
Posts: 4
Joined: Mon Feb 27, 2023 8:52 pm

Re: How do I get z88dk to work on a completely new target system?

Post by Stupid20CharLimit »

I'm not sure if I'm getting any further with this but the thing that spits out the least amount of errors is this:

1. put the fputc_cons_native subroutine in crt0 file because putting it in z88dk/libsrc/target/custom_z80/stdio/fputc_cons_native.asm is broken and doesn't work. Just for the purpose of providing as much information as possible, this is what I have it at right now:

Code: Select all

fputc_cons_native:
	
	ld a, (hl)
	call $B000

	call $B008
ret
2. put "int fputc_cons_native(char c);" in my text.c file. At this point, as long as I don't call the function anywhere in my code, it will compile. This means it will compile when my code looks like this:

Code: Select all

int fputc_cons_native(char c);

int main()
{
	
	char test[] = "test 123";
	printString(test);
	//fputc_cons_native('F');
        
	return 0;
}
When I uncomment the line "//fputc_cons_native('F');" and try to compile with ./zcc +custom_z80 test.c, I get this:
test.c::fputc_cons_native::0::0:7: error: undefined symbol: fputc_cons_native
^---- fputc_cons_native
There are other combinations of things that give me different errors, but I feel this is the closest thing to "the right way" as I can get on my own. However, a hack I came up with is that I can add the following code into my c file:

Code: Select all

int fputc_cons_native(char c)
{
	__asm__("call $B000");
}
Since the 4.3.3 of the sdcc compiler user guide shows which registers get used for differently sized variables, I can actually do stuff with variables. I'm not sure what implications there are of doing it this way (I imagine I won't be able to make certain libraries work) but at least this is something I can work with if I just can't find any other way to make it work.
User avatar
dom
Well known member
Posts: 2076
Joined: Sun Jul 15, 2007 10:01 pm

Re: How do I get z88dk to work on a completely new target system?

Post by dom »

I think you've stumbled across some missing documentation.

The library supports multiple implementations for console output:

Code: Select all

fputc_cons_generic -> ANSI VT52 engine
fputc_cons_ansi    -> ANSI VT100 engine
fputc_cons_fzx     -> +zx only (FZX font driver)
fputc_cons_native  -> Generally output using the targets firmware
The CRT sets up an alias for fputc_cons() to one of these functions as configured by pragmas. The default is to alias to fputc_cons_native(). Thus, the intention is that fputc_cons_native() is never called directly, just call fputc_cons(). All the stdio routines call fputc_cons() so they work against all output drivers.

For the makefile question. I suspect that you're not going to write to any C functions to interface to your firmware, so just follow the structure of my patch and you won't need any additional makefile.

It should be noted, that I've not been able to figure out a sensible and maintainable way to do dependency tracking in libsrc so in order to rebuild a library you need to do the following:

Code: Select all

rm customz80_clib.lib
make customz80_clib.lib
cp customz80_clib.lib ../lib/clibs/
Post Reply