News:

Printed Amstrad Addict magazine announced, check it out here!

Main Menu
avatar_Ynot.zer0

Programming in C on the CPC

Started by Ynot.zer0, 18:20, 06 February 12

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Ynot.zer0

Can the enlightened ones shed some light on where to start and what to start with?
I wish to program C code on my Amstrad CPC 464 and 6128.  Initially I'll use the WinApe emulator on my laptop, but would like to use the real machine as much as possible.


My questions are:
What software do I you think I need? DSK / ROM images
Are there any libraries that exist for doing certain things? file i/o, graphics, etc...?
Would it be better to code on a PC and copy the output to a CPC?
Are there any examples that people have done that they can share? (simple stuff, doesn't have to be rocket-science)


Initially I just want to do 'hello world', but I hope that I'll progress onto being able to move a 'sprite'(? an image/car ?) around the screen using the cursors keys.


Any advice greatly appreciated!!!


(I've got a history of coding in C, but mostly from a PC background, but some Palm/windows CE also, but that was a few years ago now, so am a little rusty, but I'm sure it'll come back to me quite quickly).

Ygdrazil


arnoldemu

Quote from: ynot.zer0 on 18:20, 06 February 12
Can the enlightened ones shed some light on where to start and what to start with?
I wish to program C code on my Amstrad CPC 464 and 6128.  Initially I'll use the WinApe emulator on my laptop, but would like to use the real machine as much as possible.


My questions are:
What software do I you think I need? DSK / ROM images
Are there any libraries that exist for doing certain things? file i/o, graphics, etc...?
Would it be better to code on a PC and copy the output to a CPC?
Are there any examples that people have done that they can share? (simple stuff, doesn't have to be rocket-science)


Initially I just want to do 'hello world', but I hope that I'll progress onto being able to move a 'sprite'(? an image/car ?) around the screen using the cursors keys.


Any advice greatly appreciated!!!


(I've got a history of coding in C, but mostly from a PC background, but some Palm/windows CE also, but that was a few years ago now, so am a little rusty, but I'm sure it'll come back to me quite quickly).

I wrote Blue Angel 69 in C. I used z88dk and cpcrslib.
The source is on my website:
cpcfreak.cpc-live.com

I coded the C source using a text editor and ran my batch file which invoked z88dk from the command-line to build the exe.

(other libraries and other c development environments exist).

My games. My Games
My website with coding examples: Unofficial Amstrad WWW Resource

Bryce

You can download norecesses PhrozenC ROM for your MegaFlash here: http://www.cpcwiki.eu/index.php/ROM_Table

Bryce.

MacDeath

Yeah, I wish to start learning C too.

and the complete noob just don't know where to start.


Perhaps a few questions then.

From what i understood, there are 2 "good" CPCfriendly compilers.

Z88dk and SDCC.
Both seem to have some CPC oriented and Z80 oriented libraries, hence the CPC friendly aspect.

This said, this is far from being a Noob-user-friendly kind of environment.

first of all, it seem that you need to install some source code and compile it to run on your PC/working machine...

d'uh !

I hoped for an environment perhaps more like Eclipse... with a great GUI, everything pre-integrated into a but app.
And all I have is a compiler which I have to compile myself...
;D


Anyway i'm a noob, I'm jsut starting, this will get simpler when I have read my big books (and understood them).



So, one aspect that annoy me a bit.

I've seen a "lot" of CPC libs... but I couldn't find any mention about a PLUS libs.

Do they even exist ?


Ynot.zer0

I hear ya' MacDeath.  I have gone through the suggestions.


PhrozenC - seemed good, I liked the idea of being able to write it on the CPC (well, WinApe), compile it and run it.  Then I fell into the not being able to enter the '{' symbol, which is kinda essential when coding in C.  That stumped me and I got no joy, so I thought I'd move on.


I went to norecess.net and read through his articles.  They seemed clear enough.  I then downloaded SDCC and the pasmo software.  Whilst I was doing this the movie 'Escape from New York' was on TV, it was very in keeping with the retro vibe  8)


I was able to create my C file, use the commands to make that into an .ASM file and then use pasmo to make it into a .BIN file.  I then used CPCDiskXP to make myself a new .DSK and add the .BIN file into it.  yay! loaded it into WinApe... entered > run"TEST1.BIN
and it just reboots the CPC rather than outputting the alphabet.  hmmm... I then checked the articles and the contents of what I was doing, I was doing the same thing and getting very similar output, I mean similar as there were just a couple of values that were different in the .ASM file that got created.  I wondered if the versions of SDCC mattered?  I just grabbed the latest versions available.  anyway, after repeating this 3-4 times, the movie had finished and it was 1am... so I stopped there.


I did notice that norecess has made Phactory, which seems to be a nice attempt to consolidate an IDE - eclipse style, but specific to the CPC.  I'll hopefully be able to take a look at it shortly....


I was then going to investigate z88dk and cpcrslib.... but work got the better of me and somehow it is now Thursday PM and I'm  too brain dead to investigate further - maybe next week when I'm staying in hotels all week I'll get some CPC-time  ;D

MacDeath

This "Phactory" looks promising...

A proper GUI environment...

Just hope it is usable at the moment.

Will see that this week end.


Mochilote


Optimus

Oh hi,


I thought I coppied the right address yesterday but I guess I pressed Ctrl+C the second time instead of Windows+C in this mac mini box (I am always confused with those changes)


Those are great tutorials btw, not only shows how to compile something simple like Hello World but has actual examples writting some simple graphics on the CPC videoram. I was thinking of writting such tutorials before I saw yours but now I don't have to do it. Or maybe I could release my CPC framework among with a similar tutorial oneday.

Mochilote

#10

I'm glad you like the tutorials. I will continue to do more, I have another almost ready.


Sounds interesting, a CPC framework,certainly if you do the tutorials many people will read and used it.

Mochilote

#11

Mochilote

#12

Mochilote

#13

MacDeath

Would be cool to have some tuto or even some library concerning the Amstrad PLUS features to be used in C.

I mean, it's not like there are so many PLUS features, but being Hardwired, those could really be used to have faster things when dealing with a PLUS.


arnoldemu

Quote from: MacDeath on 13:19, 13 June 12
Would be cool to have some tuto or even some library concerning the Amstrad PLUS features to be used in C.

I mean, it's not like there are so many PLUS features, but being Hardwired, those could really be used to have faster things when dealing with a PLUS.
Norecess wrote some c code for some of the plus stuff.
My games. My Games
My website with coding examples: Unofficial Amstrad WWW Resource

Mochilote


One new tutorial:


-Sprites II: Sprite animation (C & ASM with SDCC)
-Updated the tutorial SDCC vs z88dk: Comparing size and speed of the binaries generated for Amstrad CPC including in the last test the results with the new version of sdcc 3.2.0.


AMSDOS

Quote from: Ynot.zer0 on 20:12, 09 February 12PhrozenC - seemed good, I liked the idea of being able to write it on the CPC (well, WinApe), compile it and run it.  Then I fell into the not being able to enter the '{' symbol, which is kinda essential when coding in C.  That stumped me and I got no joy, so I thought I'd move on.


In Winape if you select 'Settings' & 'Input' it will display the Amstrad Keyboard and if you click on the "[" & "{" it should tell you where "{" has been mapped to. On my keyboard it's mapped to the "Right Alt" key, but I think I might of put it there cause I was looking for a place to put it. On my PC Keyboard the "[" & "{" has been mapped to "@" & "|" for the Amstrad and the "]" / "}" is the same for both, but on my PCs there's "\" & "|" which is above the "Return" key which Winape doesn't seem to be using at all, pressing it in Winape makes the Amstrad Beep, so perhaps that can be used for that if you've got it on your keyboard.
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3


Xifos

It's interesting.

But how do you manage to have a 16k Background pointer ?
That's a lot of memory for a 48 ko cpc (16k taken for screen, no use of extra 64 ko of 6128).
How does malloc() work on cpc by the way ?


arnoldemu

Quote from: Xifos on 16:02, 01 October 12
It's interesting.

But how do you manage to have a 16k Background pointer ?
That's a lot of memory for a 48 ko cpc (16k taken for screen, no use of extra 64 ko of 6128).
How does malloc() work on cpc by the way ?
malloc on a cpc!!!!  :o
never used it when I coded C on a cpc.

The screen is normally located at 0x0c000.
So you could do this:

unsigned char *pScreen = 0x0c000;

or you could let the library functions do all the work for you with managing the screen?
My games. My Games
My website with coding examples: Unofficial Amstrad WWW Resource

Xifos

I was talking about double buffering with a 16 ko entire screen to restore background.
Too much ram for a game i think.
I never used malloc on cpc, only on pc 80X86 (and with 64 ko segments) !  ;)
I don't know if memory management with gate array could be done with malloc by the compiler, in order to use more than 64 ko...

Anyway, i appreciate Mochilote tutorials a lot !

arnoldemu

#22
Quote from: Xifos on 20:45, 01 October 12
I was talking about double buffering with a 16 ko entire screen to restore background.
Too much ram for a game i think.
I never used malloc on cpc, only on pc 80X86 (and with 64 ko segments) !  ;)
I don't know if memory management with gate array could be done with malloc by the compiler, in order to use more than 64 ko...

Anyway, i appreciate Mochilote tutorials a lot !
For Balloonacy, I had double buffering 16k screens. :)
My games:
My Games

I had 32k free for levels, gfx and sound.
Yes it was simple game, but there was enough ;)

Many games back in the day did exactly this, mostly with spectrum sized screens to bring the double buffer to use 24k compared to 32k.


The most common way to double buffer, is that one screen is drawn to (and it is invisible), the other is seen. Then using hardware you switch them when all drawing is done (invisible is now visible, the visible is now invisible). Then you go back and redraw the tiles where the sprites were to erase them. Next you draw them in the new position. This repeats. Examples of this are batman the movie by ocean.

Some games, did not use double buffering, but had a background stored in ram. This was never written to.
The background was copied into a sprite buffer, as in Mochilote example, sprite is drawn to the buffer, and then to the screen. Barbarian is one example of this. I think it is done this way because the screen could not be made of tiles.

EDIT: with 64k you can use multi-load. 128k is good too. 64k is still ok for smaller games. People think. Only 32k!! That is never enough.
Clever coding and thinking mean this often is.

When I write a 128k game, I'll tell you how I did the management of the ram pages. :)

My games. My Games
My website with coding examples: Unofficial Amstrad WWW Resource

arnoldemu

Quote from: Mochilote on 15:04, 30 September 12
One new tutorial:


-Sprites III: Transparency (C & ASM with SDCC)
Are the links to these tutorials also on the wiki?
It would be good to also have a list that others can look at.
My games. My Games
My website with coding examples: Unofficial Amstrad WWW Resource

Xifos

Thanks for your answers arnoldemu :)

I used to : save background (in a buffer of same size as sprites), print sprite, restore background.
Did that on 16 bit (a long time ago on pc 386), maybe it's too slow on cpc if there are too much sprites...

Can we go back in time and ask zilog to do a z86 with registers for segments of 16ko ?
(and convince amstrad to use it for cpc)
;)

Powered by SMFPacks Menu Editor Mod