On Tue, May 18, 2010 at 01:27:36PM -0700, Michael Hawkins wrote:
> Hi sdcc users,
> 
> First of all, I love sdcc! The idea that I can compile C for Z80 is fantastic.
> 
> Please excuse my newbie quesitons. I've been sdcc for the Z80 for a good few 
> months now. I am running on Windows XP.
> 
> 
> My first real adventure was trying to create my own crt0.o which I finally 
> worked out.
> 
> At this point, I've been compiling the code in a very loose fashion because I 
> have had trouble getting sdcc to link multiple C files. I have only OK-ish 
> knowledge of sdcc (and gcc) and rudimentary knowledge of LINUX too.
> 
> So I have four C files which I compile in one big blob.
> 
> sdcc -mz80 --no-std-crt0 --data-loc 0x8000 --code-loc 0x200 z80clock.c crt0.o
> 
> This works because z80clock.c includes the other source files. But this does 
> atleast work. Now the problem is it simply takes too long to compile and I am 
> not using any IDE for development which makes debugging and error checking 
> very tedious indeed.
<snip>

        Can't help with Eclpise but compiling and linking should be fairly 
easy. As someone else mentioned I use cygwin (www.cygwuin.org) to get a 
command line Linux environment on Windows and then use Make with GCC. This
is for the 8051 but the Z80 should be similar:

Makefile:

# Tools

SDCC = "c:/program files/sdcc"
PACKIHX = "c:/program files/sdcc/bin/packihx"

ASM = $(SDCC)/bin/sdas8051
AFLAGS = -plosgffwz

CC = $(SDCC)/bin/sdcc
CFLAGS = --model-medium --fverbose-asm --i-code-in-asm
#CFLAGS =

TARGET = startkit

# Generic rules

%.rel : %.c
        $(CC) -c $< $(CFLAGS)

%.rel : %.cpp
        $(CC) -c $< $(CFLAGS)

%.rel : %.asm
        $(ASM)  $(AFLAGS) $<
# Default - build everything

all: $(TARGET).hex

# Specific rules

$(TARGET).hex : main.rel wiz.rel wizmemcpy.rel socket.rel\
        lcd.rel sio.rel console.rel delay.rel
        $(CC) $(CFLAGS) $(ASLINKFLAGS) $^
        $(PACKIHX) main.ihx > $(TARGET).hex

# General clean-up

clean :
        -rm *.asm
        -rm *.adb
        -rm *.cdb
        -rm *.hex
        -rm *.ihx
        -rm *.lnk
        -rm *.lst
        -rm *.map
        -rm *.mem
        -rm *.rel
        -rm *.rst
        -rm *.sym


# Additional source dependencies

console.rel : console.h ip_config.h socket.h sio.h led.h lcd.h W7100.h types.h M
akefile

delay.rel : delay.h Makefile

lcd.rel : lcd.h W7100.h types.h delay.h Makefile
... (more of the same) 

        In your case assuming files z80clock.c next1.c next2.c (currently 
included in z80clock.c) and not using make, the compile and link would go 
like this (I expect without having tried it :-)):

compile a program (noting the sddition of the -c flag for compile only):

sdcc -mz80 --no-std-crt0 --data-loc 0x8000 --code-loc 0x200 -c z80clock.c
sdcc -mz80 --no-std-crt0 --data-loc 0x8000 --code-loc 0x200 -c next1.c
sdcc -mz80 --no-std-crt0 --data-loc 0x8000 --code-loc 0x200 -c next2.c

link (after the above generates the necessary .o files)

sdcc -mz80 --no-std-crt0 --data-loc 0x8000 --code-loc 0x200 z80clock.o next1.0 
next2.o next2.o crt0.o

   to recompile a single program you need the compile step followed by the link
step. Assuming I got this wrong this should work (and give you what SDCC wants
to see) as well 

sdcc -V -mz80 --no-std-crt0 --data-loc 0x8000 --code-loc 0x200 z80clock.c crt0.o

as the -V flag will print all the command lines to the console (this as noted
is for 8051):

$ make
"c:/program files/sdcc"/bin/sdcc -c main.c -V
+ C:\PROGRA~1\sdcc\bin\sdcpp.exe -nostdinc -Wall -obj-ext=.rel -DSDCC_MODEL_SMAL
L -DSDCC_FLOAT_REENT -DSDCC=297 -DSDCC_REVISION=5821 -DSDCC_mcs51 -D__mcs51 -isy
stem "C:\program files\sdcc\bin\..\include\mcs51" -isystem "C:\program files\sdc
c\bin\..\include"  "main.c"
+ C:\PROGRA~1\sdcc\bin\sdas8051.exe -plosgffwz "main.rel" "main.asm"
"c:/program files/sdcc"/bin/sdcc -c wiz.c -V
...
c\bin\..\include"  "delay.c"
+ C:\PROGRA~1\sdcc\bin\sdas8051.exe -plosgffwz "delay.rel" "delay.asm"

*** the call to the linker starts here ***

"c:/program files/sdcc"/bin/sdcc -V  main.rel wiz.rel wizmemcpy.rel socket.rel l
cd.rel sio.rel console.rel delay.rel
+ C:\PROGRA~1\sdcc\bin\sdld.exe -nf "main.lnk"

"c:/program files/sdcc/bin/packihx" main.ihx > startkit.hex
packihx: read 1213 lines, wrote 713: OK.

     Which compiles and assembles the source files in turn then on the 2nd to 
last line runs the linker to link them all together.

Peter Van Epp

------------------------------------------------------------------------------

_______________________________________________
Sdcc-user mailing list
Sdcc-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sdcc-user

Reply via email to