Author Topic: cpc-dev-tool-chain: a portable toolchain for C/ASM development targetting CPC.  (Read 6433 times)

0 Members and 1 Guest are viewing this topic.

Offline cpcitor

  • The user previously known as FindYWay
  • CPC6128
  • ****
  • Posts: 235
  • Country: fr
  • My heart still runs on traditional CPC.
    • My code for the CPC.
  • Liked: 111
Following Benefits of high profile programming: C coding for CPC with decoupling in mindI started this thread dedicated to a subtopic.

I've created a set of scripts to ease the installation and use of C/ASM compilation tools targetting the CPC.

You can read a description on cpcitor/cpc-dev-tool-chain · GitHub
There you have a "download zip" link.

Excerpt from there

What is this ?

This is a portable toolchain for C/ASM development targetting the Amstrad CPC platform.

What does it do ?

  • It takes C and/or assembly source code and use your modern computer to automatically produces a ready-to-run disk image for an Amstrad CPC or emulator.
  • You can edit source and get another image, at will.
  • Eventually it will allow you to edit your graphics/music/whatever in your preferred editor, save, get another image, run.

Why would I want to use that ?
  • If you know to program in C and want to try that for the CPC without first learning all details of all tools.
  • Or if you're an advanced hacker who like an open starting point to build upon (in that case you'll feel at home with the Makefile-based internals).

Why would I not want to use that ?

  • If you don't want to know that virtually all Integrated Development Environments are indeed graphical front-ends for a toolchain.
  • If anything looking like a command line or an open-source style environment makes you sick. In that case, it might be interesting for you to read Wikipedia's article about Hacker (programmer subculture)and ponder whether some kind of structure or common tools helps every member of a community.

EDIT: better markup and update following cpcitor/cpc-dev-tool-chain · GitHub
« Last Edit: 23:34, 14 October 13 by cpcitor »
Had a CPC since 1985, currently software dev professional, including embedded systems.

I made the first CPC cross-dev environment that auto-installs C compiler and tools: cpc-dev-tool-chain: a portable toolchain for C/ASM development targetting CPC.

Offline cpcitor

  • The user previously known as FindYWay
  • CPC6128
  • ****
  • Posts: 235
  • Country: fr
  • My heart still runs on traditional CPC.
    • My code for the CPC.
  • Liked: 111
Updated "hello world" example.

The "hello world" example is much more sophisticated now. It shows how to:
* have a project with several C files
* implement C functions in assembly
* access firmware routines like km_wait_key and txt_output
* use the latter to set mode, paper, pen, border color, show normal and control characters

Screenshots

Everybody loves screenshots.

For these screenshots I've used an experimental build of Kevin's arnoldemu, where the screen handling is broken.


* dump_2013y10m08d_19h16m12s_667456280.png
(3.11 kB, 1024x624 - viewed 243 times)

* dump_2013y10m08d_19h16m17s_746343075.png
(2.64 kB, 1024x624 - viewed 243 times)

* dump_2013y10m08d_19h16m30s_061331603.png
(4.21 kB, 1024x624 - viewed 255 times)

* dump_2013y10m08d_19h16m37s_630931764.png
(2.35 kB, 1024x624 - viewed 233 times)

* dump_2013y10m08d_19h16m39s_979410907.png
(1.34 kB, 1024x624 - viewed 269 times)

* dump_2013y10m08d_19h16m40s_177840760.png
(1.83 kB, 1024x624 - viewed 205 times)
[attach=7
« Last Edit: 22:07, 08 October 13 by cpcitor »
Had a CPC since 1985, currently software dev professional, including embedded systems.

I made the first CPC cross-dev environment that auto-installs C compiler and tools: cpc-dev-tool-chain: a portable toolchain for C/ASM development targetting CPC.

Offline andycadley

  • Supporter
  • 6128 Plus
  • *
  • Posts: 788
  • Liked: 345
I think you missed my point in the last thread, try and imagine how likely you'd be to change your dev environment if the spec started off with:

"You'll need a Windows-like environment (Linux users will want to install Wine)"

I mean, it's not even as if you've evaluated all the options and gone for the best tools, you've just plumped immediately for the GNU toolchain because it just happens to be convenient for you. It's very hard to argue the GNU make is easier to work with than the XML based MSBuild for example, it's certainly much harder to build any kind of IDE or automated process on top of.

And I'll re-iterate, installing Cygwin on Windows is a very, very bad idea. I've seen it hose or utterly compromise the security of far too many systems due to it's utterly broken attempts to use non-canonical ACLs to fudge Unix's limited permissions model over Windows ACLs. You absolutely should not ever recommend anyone installs it at all.

Offline Sykobee (Briggsy)

  • 6128 Plus
  • ******
  • Posts: 662
  • Country: gb
  • Liked: 218

Short of writing a CPC development environment plugin for Eclipse, I think we'll have to cope with two development routes - Unix/Linux and Windows.


Just because it doesn't work for your personal Windows environment, doesn't mean that it isn't useful to make a start somewhere.


Possibly a different build tool can be implemented in the future to remove dependencies on particular platforms. MSBuild sounds horrendously platform specific, so that's out of the question. Maybe with a little work Ant or Maven could be used.

Offline jsa

  • CPC464
  • **
  • Posts: 14
  • Country: fi
  • Hmmmm?
  • Liked: 1
What about scons or waf ? :)




Offline andycadley

  • Supporter
  • 6128 Plus
  • *
  • Posts: 788
  • Liked: 345
Possibly a different build tool can be implemented in the future to remove dependencies on particular platforms. MSBuild sounds horrendously platform specific, so that's out of the question. Maybe with a little work Ant or Maven could be used.
There's a mono port of msbuild (xbuild IIRC) so it's not platform specific, but the point wasn't "You should use X not Y" but rather that trying to start something like this by dictating "You must use X because that happens to be super convenient for me" is a complete non-starter.

Offline cpcitor

  • The user previously known as FindYWay
  • CPC6128
  • ****
  • Posts: 235
  • Country: fr
  • My heart still runs on traditional CPC.
    • My code for the CPC.
  • Liked: 111
Thanks everyone for your feedback.

While we talk about build systems, there's a nifty tool that helps a lot in practice when supporting multiple platforms. It's called CMake and runs on Unix, Windows and Mac OS X.

From the very same portable CMake project files, it can generate buildable projects for many build environments, including msbuild mentioned by @andycadley through its frontend Visual Studio, but also eclipse, kdevelop, code::blocks, makefile (for Unix, minGW, MSYS, NMake, Borland, Watcom), Ninja, XCode and Sublime Text 2. For details about generators see CMake Generator Specific Information - KitwarePublic and CMake - Cross Platform Make

The net result is that, in theory, users of all these environment should be covered relatively easily. A few coworkers and I actually used CMake for a cross-platform project this year. After a fair bit of tuning, Windows and Linux users have worked on projects based on the same set of rule files.

For even more interest, CMake even has some documented setup for SDCC : CmakeSdcc - KitwarePublic .
I have CMake 2.8 on my machine and a Generic-SDCC-C.cmake is indeed installed. Notice that it doesn't cover installation of sdcc, only use.

With the information available so far, would you consider it a good deal to add CMake as a dependency for a CPC development toolchain as a lever to support many IDEs ?
Had a CPC since 1985, currently software dev professional, including embedded systems.

I made the first CPC cross-dev environment that auto-installs C compiler and tools: cpc-dev-tool-chain: a portable toolchain for C/ASM development targetting CPC.

Offline jrodriguezv

  • CPC664
  • ***
  • Posts: 53
  • Country: es
  • Liked: 15
Hi!
 
First of all, thanks for your good job  :)
 
Im testing this project in my laptop with Ubuntu 13.4. You need to add libboost-graph-dev as dependency in order to compile SDCC.
 
Can you consider add support to cpcrslib (cpcrslib - CPC libraries for z88dk and SDCC - Google Project Hosting) in your project.
 
Thanks

Offline cpcitor

  • The user previously known as FindYWay
  • CPC6128
  • ****
  • Posts: 235
  • Country: fr
  • My heart still runs on traditional CPC.
    • My code for the CPC.
  • Liked: 111
Hi!

First of all, thanks for your good job  :)

Hi @jrodriguezv ! Thanks for the support.  :)

Im testing this project in my laptop with Ubuntu 13.4. You need to add libboost-graph-dev as dependency in order to compile SDCC.
 

Interesting. It's definitely not needed in 12.10. If you remember what was the symptom it may be interesting for me to understand.

Can you consider add support to cpcrslib (cpcrslib - CPC libraries for z88dk and SDCC - Google Project Hosting) in your project.

Good idea! Lots of features. Even when not using specialized ones like sprites, out-of-the-box features of general use like UnExo or music player are nice.

I see a tutorial on How to use cpcrslib in SDCC and a release on cpcrslib SDCC 11.03.2012.rar - Google Project Hosting. It seems clear enough and appropriate.

Cannot do this very soon, but here's how I'd do it:
  • create a directory in tool
  • copy and take as example a makefile in tool, most appropriate is iDSK/Makefile
  • adjust targets and commands for cpcrslib : extract (watch out, rar archive has no subdirectory), build (create several make targets that implement instructions from tutorial to build individual file, then a target to build cpcrslib.lib)

Summary : previous steps would automatically fetch and build cpcrslib from source like it does already for sdcc, z88dk, idsk and hex2bin.

Bonus/sanity check (not needed) a make target (or even a patch) that copies some Makefiles into cpcrslib example directories to build them.

Provide a simple example using it. For a start, modifying hello_world_using_sdcc to follow the tutorial would be enough. A "top" solution would adjust main make target that grep sources to check if there's a #include <cpcrslib.h> and auto-build and link cpcrslib only in this case !

Net result : to enable cpcrslib in any project, just write a C file with #include <cpcrslib.h> and use it, it would just work!

Cheers,
Had a CPC since 1985, currently software dev professional, including embedded systems.

I made the first CPC cross-dev environment that auto-installs C compiler and tools: cpc-dev-tool-chain: a portable toolchain for C/ASM development targetting CPC.

Offline cpcitor

  • The user previously known as FindYWay
  • CPC6128
  • ****
  • Posts: 235
  • Country: fr
  • My heart still runs on traditional CPC.
    • My code for the CPC.
  • Liked: 111
Hello all,

Following jrodriguezv's suggestion, I started to work on support for cpcrslib and pushed to cpcitor/cpc-dev-tool-chain · GitHub an updated version.
It now also fetches cpcrslib from google code and compiles it.
cpcrslib is distributed in rar format which makes one more dependency.

Next I'm planning for multi-project. That is, you'll be able to designate any directory as being, for example, a "sdcc project" and it will be, in the sense that the cpc-dev-tool-chain will be able to compile your project without hassle. The first projects to benefit will be the cpcrslib examples themselves. Building cpcsrlib will build them and make a sample dsk, that will make a compile-time sanity check.

Cheers,
Had a CPC since 1985, currently software dev professional, including embedded systems.

I made the first CPC cross-dev environment that auto-installs C compiler and tools: cpc-dev-tool-chain: a portable toolchain for C/ASM development targetting CPC.

Offline jrodriguezv

  • CPC664
  • ***
  • Posts: 53
  • Country: es
  • Liked: 15
Thanks!! You have done it very soon  ;)

I will test it as soon as possible.

Thanks again

Offline cpcitor

  • The user previously known as FindYWay
  • CPC6128
  • ****
  • Posts: 235
  • Country: fr
  • My heart still runs on traditional CPC.
    • My code for the CPC.
  • Liked: 111
Hello,

I updated it again.

Now when you get the project and type "make" it offers a new target : cpcrslib.

Code: [Select]
make

Choose target:
make displayhelp
make hello_world_using_z88dk
make hello_world_using_sdcc
make cpcrslib

This target fetches and builds cpcrslib and tells you that you can enter any example directory. Type "make" there and you get a target.dsk ready to run.

It succeeds in creating an actually runnable disk of cpcrslib example 1 :  "001 - 8x8 Chars & Small Scroll"

Here's a screenshot under arnold :

[attachimg=1]

Other examples do compile but don't work on my emulator.

Maybe the emulator is buggy (this already happened recently).

Any feedback (good or bad results) are interesting.

Visit cpcitor/cpc-dev-tool-chain · GitHub for updated dependencies, verified on Debian 7, Ubuntu 12.10, 13.04
and 13.10 (mainly unrar is new, need "universe" repository enabled).

Regards.
« Last Edit: 00:41, 16 October 13 by cpcitor »
Had a CPC since 1985, currently software dev professional, including embedded systems.

I made the first CPC cross-dev environment that auto-installs C compiler and tools: cpc-dev-tool-chain: a portable toolchain for C/ASM development targetting CPC.

Offline cpcitor

  • The user previously known as FindYWay
  • CPC6128
  • ****
  • Posts: 235
  • Country: fr
  • My heart still runs on traditional CPC.
    • My code for the CPC.
  • Liked: 111
Hello,

I updated it again, fixing some missing dependency declaration like "building cpcrslib needs sdcc".

So far example 001 works out-of-the-box.

The others require crt0_cpc and I only had e.g. 006 unexo work by adjusting "load" and "run" addresses by hand at idsk step.

It looks like when asking the compiler to link at e.g. 0x6038 and add crt0_cpc as first argument, the file actually starts at 6000. That's not written in the toolchain yet.

Regards,
Had a CPC since 1985, currently software dev professional, including embedded systems.

I made the first CPC cross-dev environment that auto-installs C compiler and tools: cpc-dev-tool-chain: a portable toolchain for C/ASM development targetting CPC.

Offline Bruce Abbott

  • CPC664
  • ***
  • Posts: 53
  • Country: nz
  • Liked: 84
I installed cpc-dev into cygwin on my Windows XP PC. This is my first experience with command-line linux development, and I had a few false starts trying to get all the components installed. The main problem was that sdcc wouldn't build, and I couldn't figure out why the makefile was insisting that the tools directories didn't exist. So I removed cpc-dev and downloaded the latest version, and then it all just worked!   

Your "Hello World" compiled fine with sdcc and ran successfully on WinAPE. Of the cpcrslib demos, "004 - Music, SFX & Keyboard" wouldn't compile, while "007 - Uncrunch" compiled but just reset the emulator. The other examples compiled and ran fine.

Offline cpcitor

  • The user previously known as FindYWay
  • CPC6128
  • ****
  • Posts: 235
  • Country: fr
  • My heart still runs on traditional CPC.
    • My code for the CPC.
  • Liked: 111
I installed cpc-dev into cygwin on my Windows XP PC.

Thanks for trying and reporting !

This is my first experience with command-line linux development, and I had a few false starts trying to get all the components installed. The main problem was that sdcc wouldn't build, and I couldn't figure out why the makefile was insisting that the tools directories didn't exist.

You probably fetched a version before my latest commits. I tried to keep the thing independent of the directory it's in, but did not succeed at first try. It seems okay now.  :)

So I removed cpc-dev and downloaded the latest version, and then it all just worked!   

Great ! That's how it's intended to work. 8)

Your "Hello World" compiled fine with sdcc and ran successfully on WinAPE. Of the cpcrslib demos, "004 - Music, SFX & Keyboard" wouldn't compile, while "007 - Uncrunch" compiled but just reset the emulator. The other examples compiled and ran fine.

Regarding music example, the makefile checks if C source includes cpcrslib.h but not cpcwyzlib.h . It's a matter of including that in the top-level sdcc-project.Makefile. It can be done even without understanding the whole thing. The strange fact is : it worked better for you than for me.

What puzzles me is that other samples worked for you not for me. Can you go again to a sample directory, e.g. 003 and type:

Code: [Select]
make >make003.log 2>&1

Then check if the generated DSK still works, and whatever the result PM the file make003.log to me. Comparing that output with what I get will probably be useful to figure out how to have the thing work smoothly.

Same for sample 007 would be great for more comparisons.

I'll be on holiday with family for the next few weeks so may not answer quickly.  ::) I will finally answer anyway.  :)
Had a CPC since 1985, currently software dev professional, including embedded systems.

I made the first CPC cross-dev environment that auto-installs C compiler and tools: cpc-dev-tool-chain: a portable toolchain for C/ASM development targetting CPC.

Offline cpcitor

  • The user previously known as FindYWay
  • CPC6128
  • ****
  • Posts: 235
  • Country: fr
  • My heart still runs on traditional CPC.
    • My code for the CPC.
  • Liked: 111
Screenshots

Thanks to screenshot 10 I see you run the examples with load at explicit address and call.
That may explain.
I Intended to run them just with
Code: [Select]
run"filename.bin"So, if the load and/or run addresses are wrong for whatever reason (and I think they are when using a crt0 at the moment) it will crash.

Thanks again for the informative feedback !

Difficulties like this can hit any newcomer. When they are written for good in a tool, the tool takes care so that the user doesn't have to.
Had a CPC since 1985, currently software dev professional, including embedded systems.

I made the first CPC cross-dev environment that auto-installs C compiler and tools: cpc-dev-tool-chain: a portable toolchain for C/ASM development targetting CPC.

Offline cpcitor

  • The user previously known as FindYWay
  • CPC6128
  • ****
  • Posts: 235
  • Country: fr
  • My heart still runs on traditional CPC.
    • My code for the CPC.
  • Liked: 111
Thank you Bruce. Your logs confirm that there's no difference in what happens on Windows and Linux. You succeeded one more samples because you had manually overridden the wrong address calculated by my code.  ::)

Current scripts assume that load address and run address are the same as the code-loc argument given to sdcc, which is not true in general and especially with a crt0.

First, load address should be taken from hex2bin output. It should be the correct value in virtually all cases.

Regarding run address, I'm not sure it can be figured out automatically always.

Regards,
Had a CPC since 1985, currently software dev professional, including embedded systems.

I made the first CPC cross-dev environment that auto-installs C compiler and tools: cpc-dev-tool-chain: a portable toolchain for C/ASM development targetting CPC.

Offline cpcitor

  • The user previously known as FindYWay
  • CPC6128
  • ****
  • Posts: 235
  • Country: fr
  • My heart still runs on traditional CPC.
    • My code for the CPC.
  • Liked: 111
SDCC-compiled hello world : success on a real CPC.
« Reply #17 on: 23:59, 20 October 13 »
I've experimented 2cdt and playtzx today (from ralferoo's github, thanks ralferoo ! ), using them to transfer the sdcc hello to tape then to a real CPC 464. And it worked !
I should post a photograph.  :)

Ideally I would integrate 2cdt and playtzx as done for the others tools.
Had a CPC since 1985, currently software dev professional, including embedded systems.

I made the first CPC cross-dev environment that auto-installs C compiler and tools: cpc-dev-tool-chain: a portable toolchain for C/ASM development targetting CPC.

Offline cpcitor

  • The user previously known as FindYWay
  • CPC6128
  • ****
  • Posts: 235
  • Country: fr
  • My heart still runs on traditional CPC.
    • My code for the CPC.
  • Liked: 111
Here's the screenshot. Please pardon the mess around the machine. It's straight from the attic. The monitor is the very one I got for my birthday at the time, but I don't remember where that CPC464 comes from (it bears sign of bad use) or where my CPC464 is. But the program is tested and that's what counts.  :D

 [ Invalid Attachment ]

Had a CPC since 1985, currently software dev professional, including embedded systems.

I made the first CPC cross-dev environment that auto-installs C compiler and tools: cpc-dev-tool-chain: a portable toolchain for C/ASM development targetting CPC.

Offline arnoldemu

  • Supporter
  • 6128 Plus
  • *
  • Posts: 5.329
  • Country: gb
    • Unofficial Amstrad WWW Resource
  • Liked: 2220
First, load address should be taken from hex2bin output. It should be the correct value in virtually all cases.

Regarding run address, I'm not sure it can be figured out automatically always.
try this tool:

http://www.cpctech.org.uk/download/fileattr.zip
My games. My Games
My website with coding examples: Unofficial Amstrad WWW Resource

Offline cpcitor

  • The user previously known as FindYWay
  • CPC6128
  • ****
  • Posts: 235
  • Country: fr
  • My heart still runs on traditional CPC.
    • My code for the CPC.
  • Liked: 111
Hello,
Glad that you liked the photograph of the real CPC running SDCC-compiled stuff.

try this tool:

http://www.cpctech.org.uk/download/fileattr.zip

Thanks. Let's try that. I see a tool that takes a file as input. If the file has a valid AMSDOS header, the tool can extract start, length, end or execution address and display that as "defw &address". If the file has no header, answer is "defw &0000".

Currently I don't handle files with amsdos headers as I have no tool to create one and no real need.

Instead, I use the options of iDsk and 2cdt to create the correct header on the fly.

Also, the header for disk and for tape are different. fileattr is for disk header only, right ?
Had a CPC since 1985, currently software dev professional, including embedded systems.

I made the first CPC cross-dev environment that auto-installs C compiler and tools: cpc-dev-tool-chain: a portable toolchain for C/ASM development targetting CPC.

Offline arnoldemu

  • Supporter
  • 6128 Plus
  • *
  • Posts: 5.329
  • Country: gb
    • Unofficial Amstrad WWW Resource
  • Liked: 2220
Also, the header for disk and for tape are different. fileattr is for disk header only, right ?
Correct. I always use amsdos header. Many tools I use add one.

e.g.

pasmo --amsdos file.asm file.bin

For sdcc, I use "addhead" tool here.

http://www.cpctech.org.uk/download/addhead.zip

All my tools work with it. The header stores start, length and execution address.
The tool makes "defw" because I often do this:

fileattr -x > game_x.asm

then in my loader i put:

Code: [Select]
defb &c3
include "game_x.asm"

2cdt can also use a file with amsdos header and create the correct file.

So I think it's the best.

I think tape headers are not normally important.
My games. My Games
My website with coding examples: Unofficial Amstrad WWW Resource

Offline arnoldemu

  • Supporter
  • 6128 Plus
  • *
  • Posts: 5.329
  • Country: gb
    • Unofficial Amstrad WWW Resource
  • Liked: 2220
Glad that you liked the photograph of the real CPC running SDCC-compiled stuff.
Yes I liked the poor CPC464 still working hard although it has some problems :)
My games. My Games
My website with coding examples: Unofficial Amstrad WWW Resource

Offline arnoldemu

  • Supporter
  • 6128 Plus
  • *
  • Posts: 5.329
  • Country: gb
    • Unofficial Amstrad WWW Resource
  • Liked: 2220
A file i use on windows:

Code: [Select]
set PATH=%PATH%;c:\tools
cd lib\mylib
call make.bat
cd ..\..
cd lib\arkostrackerlib
call make.bat
cd ..\..
REM cd gfx
REM call process-gfx.bat
REM cd ..
sdasz80 -plosgff mygame_crt0.s

sdcc -c --verbose -V --nostdlib --opt-code-speed --nostdinc --no-std-crt0 -mz80 -DDISC=1 -I lib/mylib -l lib/mylib/mylib.lib -I lib/arkostrackerlib -l lib/arkostrackerlib/arkostrackerlib.lib mygame.c
if %ERRORLEVEL% NEQ 0 goto :error
sdldz80 -f custom.lk
hex2bin mygame.ihx

REM zorg only works if you use zcc to build and link
del temp\game_x.asm
del temp\game_l.asm
del temp\game_s.asm

addhead -s 0x08100 -x 0x08100 mygame.bin mygame.bin

fileattr -x mygame.bin >mygame_x.asm
fileattr -l mygame.bin  >mygame_l.asm
fileattr -s mygame.bin  >mygame_s.asm


addhead -r mygame.bin mygame.bin

pasmo --amsdos reloc.asm bin\reloc.bin

fileattr -x bin\reloc.bin >temp\game_x.asm
fileattr -l bin\reloc.bin  >temp\game_l.asm
fileattr -s bin\reloc.bin  >temp\game_s.asm

pasmo --amsdos discload_alt_new.asm bin\discload_alt_new.bin
if %ERRORLEVEL% NEQ 0 goto :error
REM disc version
addhead -r gfx\bin\loadscr.bin gfx\bin\loadscr.bin
addhead -a -t "binary" -s 49152 gfx\bin\loadscr.bin gfx\bin\loadscr.bin

cpcxfs -f -nD virus.dsk
cpcxfs virus.dsk -f -b -p bin\discload_alt_new.bin virus.bin
cpcxfs virus.dsk -f -b -p gfx\bin\loadscr.bin virus.bi1
cpcxfs virus.dsk -f -b -p bin\reloc.bin virus.bi2

pasmo --amsdos tapeload_alt.asm bin\tapeload_alt.bin
if %ERRORLEVEL% NEQ 0 goto :error

addhead -r gfx\bin\loadscr.bin gfx\bin\loadscr.bin
addhead -r mygame.bin mygame.bin

REM 2cdt -n bin\tapeload.bin -r BANGEL69 bin\cdt\bangel69_A.cdt
2cdt -n bin\tapeload_alt.bin -r "! VIRUS !" virus.cdt
2cdt -m 2 gfx\bin\loadscr.bin virus.cdt
2cdt -m 2 bin\reloc.bin virus.cdt

:error

This may help you?

On linux I often use makefiles or shell scripts.
My games. My Games
My website with coding examples: Unofficial Amstrad WWW Resource

Offline cpcitor

  • The user previously known as FindYWay
  • CPC6128
  • ****
  • Posts: 235
  • Country: fr
  • My heart still runs on traditional CPC.
    • My code for the CPC.
  • Liked: 111
Request for comments from C developers' hints.
« Reply #24 on: 02:02, 24 October 13 »
I have figured out why some samples failed, based on looking at the generated binary and symbol map.

Sample 001 works without crt0 because there's no global variable. Things are simple. Data segment has zero size. Thus main symbol happens to be at beginning of generated binary, which fits code-loc argument given to SDCC.

Other samples, e.g. 003 do have global variables.
It can still work without a crt0 by figuring out load address from output of hex2bin and run address from address of main symbol.
The Makefile can do that. I'll do it for the load address anyway.

Regarding the run address it's more complicated to do things right...

Since a crt0 introduces a fixed address in memory, it violates the DRY principle ( see http://en.wikipedia.org/wiki/Don%27t_repeat_yourself ) because when user wants code in a different memory address, (s)he will have to change it in two places : SDCC argument --code-loc and crt0.

There are probably many ways to try to have things "just work" for projects using the toolchain.
* dry: compute --code-loc argument from (possibly user-provided) crt0
* dry: generated standard crt0 from (possibly user-provided) code address in project conf
* full lazy, not dry: just leave a mess and force the user to choose a memory layout and addresses
* full luxury, more dry that dry (when you say nothing you can't repeat yourself at all) : after compilation proper (but not linking) automatically compute locations to leave room below (for a possible basic loader) and above (for possible extension ROM data) with overridable defaults, generate crt0. (Can it be done without recompiling ?)
* in case of upper 16k ROM output, use a dedicated parameter set...
* Any other cases ? Cassette or Disk doesn't change the deal.

Anyone has hints ? Feedback welcome.
Had a CPC since 1985, currently software dev professional, including embedded systems.

I made the first CPC cross-dev environment that auto-installs C compiler and tools: cpc-dev-tool-chain: a portable toolchain for C/ASM development targetting CPC.