Unable to compile working program to Amstrad

Amstrad CPC and NC systems
User avatar
dom
Well known member
Posts: 2072
Joined: Sun Jul 15, 2007 10:01 pm

Post by dom »

Take a look at the lib/config/*.cfg files - macros are defined to indicate the platform:

CPC: -DCPC -D__CPC__
MSX: -DMSX -D__MSX__
Spectrum: -DSPECTRUM -D__SPECTRUM__

etc
baltasarq
Member
Posts: 35
Joined: Wed May 11, 2016 7:53 pm

Post by baltasarq »

Again, many thanks.
If I download the z88dk code tonight, will the fixes you told me be applied?
User avatar
dom
Well known member
Posts: 2072
Joined: Sun Jul 15, 2007 10:01 pm

Post by dom »

You'll still need to do the #define __MSX_H__ workaround - I've not got round to sorting that one out yet. But everything else is in I think.
baltasarq
Member
Posts: 35
Joined: Wed May 11, 2016 7:53 pm

Post by baltasarq »

I downloaded the nightly build, and now certainly the program compiles and runs.
But it is a mess. The conio.h library does not offer abstraction, for example, it does not change the number of columns by default to 70 as it does in the Speccy.
So I put a lot of #ifdef __CPC__, trying to get basic colors, such as blue background and white foreground. But there was no luck, no luck at all. Maybe the game is working, but I simply could not tell.

Maybe you can take a look and see what am I doing wrong:
https://github.com/Baltasarq/Bares

I don't know, maybe the platform is not mature enough and I should give up...

-- baltasar
alvin
Well known member
Posts: 1872
Joined: Mon Jul 16, 2007 7:39 pm

Post by alvin »

The cpc target does not have special code to draw characters on screen so the program is stuck with whatever the cpc firmware supplies.

On the cpc you have three display modes: mode 0 is 20x25 with 16 colours, mode 1 40x25 with 4 colours and mode 2 80x25 with 2 colours. By default the firmware puts the cpc in mode 1 with blue background as you've seen. There's no way to get more than 40 columns in that mode. If you want 80 columns you can switch to mode 2 but then you only have one text colour.

I'll have a look at this in the next day or two.
baltasarq
Member
Posts: 35
Joined: Wed May 11, 2016 7:53 pm

Post by baltasarq »

I would not really care to have only 40 columns and a couple of colors, provided i could make it work, or visible, or whatever.
User avatar
dom
Well known member
Posts: 2072
Joined: Sun Jul 15, 2007 10:01 pm

Post by dom »

I've not tried it but it looks like conip is generating ansi sequences. There's an ansi library for the cpc -clib=ansi that may well make things work as expected.
baltasarq
Member
Posts: 35
Joined: Wed May 11, 2016 7:53 pm

Post by baltasarq »

Yes, but I'm already compiling with the -clib=ansi switch, and using conio.h. That does not seem to be the problem.
The compiling I'm doing is:

zcc +cpc -O3 -SO3 -create-app -clib=ansi -lm -lndos bares.c cmds.c objs.c locs.c player.c -o bares
alvin
Well known member
Posts: 1872
Joined: Mon Jul 16, 2007 7:39 pm

Post by alvin »

Yes the problem will be in how the cpc's version of conio / ansi changes foreground and background colours, which will be different from other targets.

In mode 1 you have four "inks" and each ink's colour is assigned from a pallette of 16 real colours. Of those four inks, one is the background. You can't just change text background colour for a bit of text like you can on other targets because changing the background colour changes the background colour of the entire screen. So if you allowed that you would see some psychedellic flashing. Since we're using the firmware on the cpc to draw text, there is no way to draw the background of text characters in an ink other than the background colour (at least this is my understanding before I do some more reading up). For changing the foreground colour, there should be a way to choose / set three colours from the 4 inks available. How that's done from the set text foreground colour I am not sure. But you do not want to use the same ink for all text printing and then change the value of that ink's colour when a text foreground colour command is met -- that will change the ink colour of all text appearing on screen and not just the next text string printed.

Anyway, baltasarq, I had no trouble seeing the text after changing one of the ink colours from BLUE to RED. I think it was this:

void set_default_colors()
{
textbackground( WHITE );
textcolor( RED );
}

in bares.c. Of course this is not a real solution to the problem but it does allow you to at least see the text.
baltasarq
Member
Posts: 35
Joined: Wed May 11, 2016 7:53 pm

Post by baltasarq »

Okay, I've been able to see the text and even play the game. The good news is that it works.
The bad news are that:

- The "help" command needs more space than the 50 columns the Amstrad offers. That's of course can be deal with in both platforms.
- The only colours that work are RED and YELLOW for foreground. Period. The background seems to be always BLUE, no matter what you do.
- This is a big setback: you cannot delete characters when you type your command. Strange chars appear and you have to press ENTER and start again. This does not make the game impossible to use, but it simply does not offer enough quality.

So, maybe a) the conio.h library can be made it to work for amstrad CPC (not probable), or b) I can put some instructions in that put the background in white and the text in black, for example. I would not need not much apart from this. Well, and delete should work.
User avatar
dom
Well known member
Posts: 2072
Joined: Sun Jul 15, 2007 10:01 pm

Post by dom »

Delete should work in tonights nightly - the CPC firmware returns 127 as the delete key code, but fgets(stdin) expects to have 12 or 8 as the delete key.

To get more columns on the CPC we'd need to write a driver for the CPC that writes directly to the display buffer or switch to a different mode (but then you lose the few colours you've got) - z88dk doesn't change the mode, so switch to mode 2 and see what it looks like in that mode.
baltasarq
Member
Posts: 35
Joined: Wed May 11, 2016 7:53 pm

Post by baltasarq »

Sorry, Dom, I don't know haw to switch amstrad to mode 2... ?could you post the code? Many thanks.
alvin
Well known member
Posts: 1872
Joined: Mon Jul 16, 2007 7:39 pm

Post by alvin »

baltasarq wrote:Sorry, Dom, I don't know haw to switch amstrad to mode 2... ?could you post the code? Many thanks.
I thought there might have been a function in cpc.h to do this but I don't see it.

You should be able to change to mode 2 by inlining this asm first thing in main:

Code: Select all

#asm
EXTERN firmware

ld a,2
call firmware
defw 0xbc0e
#endasm
User avatar
dom
Well known member
Posts: 2072
Joined: Sun Jul 15, 2007 10:01 pm

Post by dom »

Or just entering mode 2 from basic before calling the program.
baltasarq
Member
Posts: 35
Joined: Wed May 11, 2016 7:53 pm

Post by baltasarq »

I sincerely don't want to include asm code that way, because I suspect it could change anytime.
Can you include a function to change to mode 2 (or maybe also to any other mode) in one of these next nightly builds?

Many thanks for your interest, and your efforts.
User avatar
dom
Well known member
Posts: 2072
Joined: Sun Jul 15, 2007 10:01 pm

Post by dom »

I've added cpc_setmode(int) to cpc.h - should be ready for you tomorrow!
baltasarq
Member
Posts: 35
Joined: Wed May 11, 2016 7:53 pm

Post by baltasarq »

Many thanks!
So I only need to add cpc.h and call cpc_setmode( 2 )... is that it?

Kudos!
baltasarq
Member
Posts: 35
Joined: Wed May 11, 2016 7:53 pm

Post by baltasarq »

This is fantastic. It just works. You have about 70 columns (nothing to modify in the code), and backspace works.
The only defect is this one:
void set_default_colors()
{
#ifdef __CPC__
textbackground( BLACK );
textcolor( WHITE );
#else
textbackground( WHITE );
textcolor( BLUE );
#endif
}

The only actual colors that work are BLUE and YELLOW. If I put YELLOW as foreground and BLUE as background, then it is seen as the default color set in the Amstrad. If you put the background color as YELLOW, and BLUE as foreground, then the background is still blue, and text is displayed in YELLOW background and BLUE foreground.

I see two possibilities from here: a) leave it as it is, so the adventure will have the default colors the CPC boots with. b) make WHITE and BLACK work, so I can put BLACK background with WHITE foreground, a more orthodox color combination.
alvin
Well known member
Posts: 1872
Joined: Mon Jul 16, 2007 7:39 pm

Post by alvin »

I'm still waffling about what to do with this. I think what will happen is we will enumerate the 16 colours in conio.h so that similar colours are close to each other in some sense. Then, eg, for mode 1 on the cpc since there are four colours, we'll divide those 16 colours in conio.h into four regions so that if you choose a colour in the same region, the colour won't actually change. Then there will be platform specific functions to assign colours to the four regions. The cpc has a separate pallette so that those four colours can be assigned from a choice of 16.
baltasarq
Member
Posts: 35
Joined: Wed May 11, 2016 7:53 pm

Post by baltasarq »

Okay, keep me posted around here, so I can test that advances in colors. Thanks for your efforts!!
baltasarq
Member
Posts: 35
Joined: Wed May 11, 2016 7:53 pm

Post by baltasarq »

Any news about colors?
alvin
Well known member
Posts: 1872
Joined: Mon Jul 16, 2007 7:39 pm

Post by alvin »

I will try to find time to finish it up soon.
Post Reply