Amstrad PCW: gotoxy

Post Reply
bbock
Member
Posts: 22
Joined: Mon Jan 03, 2011 12:35 am

Amstrad PCW: gotoxy

Post by bbock »

The gotoxy command is defined in conio.h, but it doesn't seem to work on the Amstrad PCW. I wrote a drawBox function to draw a character based box using several gotoxy commands:

Code: Select all

// Draws a box at position (x, y) with width w and height h.
void drawBox(int x, int y, int w, int h) {
  int i;

  gotoxy(x, y);
  putchar(150);
  for (i = 1; i < w - 1; i++) {
      putchar(154);
  }
  putchar(156);
  for (i = y + 1; i < y + h - 1; i++) {
    gotoxy(x, i);         putchar(149);
    gotoxy(x + w - 1, i); putchar(149);
  }
  gotoxy(x, y + h - 1);
  putchar(147);
  for (i = 1; i < w - 1; i++) {
      putchar(154);
  }
  putchar(153);
}
Calling drawBox(10, 5, 30, 3); with gotoxy from conio.h produces the following output:

gotoxy_fail.png

It seems as if the gotoxy commands were completely ignored.

Then I wrote my own gotoxy function:

Code: Select all

void gotoxy(unsigned int x, unsigned int y) {
    putchar(27);        // ESC
    putchar('Y');       // cursor to position
    putchar(y + 32);    // row + 32
    putchar(x + 32);    // column + 32
}
Calling the same drawBox command as above leads to the expected output:

gotoxy_success.png

So - what's wrong with the conio.h version of gotoxy?
You do not have the required permissions to view the files attached to this post.
User avatar
dom
Well known member
Posts: 2072
Joined: Sun Jul 15, 2007 10:01 pm

Re: Amstrad PCW: gotoxy

Post by dom »

If the PCW has an ADM-3a console, try adding --generic-console to the command line arguments.
bbock
Member
Posts: 22
Joined: Mon Jan 03, 2011 12:35 am

Re: Amstrad PCW: gotoxy

Post by bbock »

Nope, not working:

gotoxy_fail2.png

I wonder where you got the --generic-console option from. It's not listed on the zcc page https://github.com/z88dk/z88dk/wiki/Tool---zcc
Is there a complete list of zcc options anywhere?
And a list of available libraries maybe? When I got linker errors using the float type, I thought it might be a good idea to link the math library, which can be done by the -lm option. Well, that worked, but I had to guess...
There is room for improvement regarding the documentation, but I don't want to criticize too much, because in my opinion the z88dk project is one of the best retro computing projects ever made. My congratulations to all the people who made this possible. And the fast support here in the forum is awesome, too.
You do not have the required permissions to view the files attached to this post.
User avatar
dom
Well known member
Posts: 2072
Joined: Sun Jul 15, 2007 10:01 pm

Re: Amstrad PCW: gotoxy

Post by dom »

I should have looked more closely - it's actually a VT52 terminal based on that position code. Unfortunately at the moment the conio code only works on: the vt52 and vt100 terminals that talk directly to the hardware and the ADM-3a one that prints via the bdos calls. It'll be fairly easy to add support for conio.h on a VT52 via bdos calls but I've not got anything up my sleeve at the moment.

Regarding your other points, unfortunately documentation has always been lacking, though I think we're in a better state than a few years ago. I know I'm guilty of not documented things that I think are obvious, but in hindsight turn out not to be! Contributions are always welcome: the wiki is editable by all.

There's no "master list" for anything, for example zcc options do vary on a per target basis, if you run zcc +cpm you'll see all of the first class options. But then that can be extended with the list of pragmas: https://github.com/z88dk/z88dk/wiki/Classic--Pragmas which can be supplied as command line options. The target wiki page may also have some extra information about options as well. There's just quite a lot of configurability, but I do try to strive for "it just works" if only to make my life easier.

Which does come onto the maths libraries - this was one of the things that I thought was obvious back at the start - if you're missing any maths functions, just add -lm As to why it's not in the library by default: there's many different implementations: https://github.com/z88dk/z88dk/wiki/Cla ... -Libraries
bbock
Member
Posts: 22
Joined: Mon Jan 03, 2011 12:35 am

Re: Amstrad PCW: gotoxy

Post by bbock »

Thank you very much for the many hints - very useful.
dom wrote: Wed Jan 25, 2023 9:50 pm ... It'll be fairly easy to add support for conio.h on a VT52 via bdos calls but I've not got anything up my sleeve at the moment. ...
If you need documentation about the VT52-like terminal commands, there is a great description in the PCW's user manual. Look here:
https://www.manualslib.com/manual/10028 ... 308#manual
You'll find all necessary information in Appendix III - Terminal characteristics (search for "Terminal characteristics" in the table of contents).

Regarding the math libraries: do you know whether the Amstrad CPC lib ( -lcpcmath ) can be used with the PCW? The two architectures have quite some similarities, although there are a lot of differences as well...
bbock
Member
Posts: 22
Joined: Mon Jan 03, 2011 12:35 am

Amstrad PCW: math libraries

Post by bbock »

Of course the easiest way to find out is to test yourself. So I did, and here are my findings:

I used the following simplistic one-file project:

Code: Select all

#include <stdio.h>

int main(void) {
    float a, r;
    
    r = 2.5;
    a = r * r * 3.141592654;
    
    printf("Circle area\n");
    printf("r = %12.9f\n", r);
    printf("a = %12.9f\n", a);
    
    return 0;
}
Nothing special so far. I tried five different compiles:

Code: Select all

1. zcc +cpm -subtype=pcw80 -compiler=sdcc -lm -create-app %files% -o %mainfile%.com; size of mathtest.com: 7.406 Bytes
2. zcc +cpm -subtype=pcw80 -compiler=sccz80 -lm -create-app %files% -o %mainfile%.com; size of mathtest.com: 9.281 Bytes
3. zcc +cpm -subtype=pcw80 -compiler=sccz80 -lcpcmath -create-app %files% -o %mainfile%.com; error: file open: cpcmath.lib
4. zcc +cpm -subtype=pcw80 -compiler=sccz80 -lmathz88 -fp-mode=z88 -create-app %files% -o %mainfile%.com; error: file open: mathz88.lib
5. zcc +cpm -subtype=pcw80 -compiler=sccz80 --math-mbf32 -fp-mode=z88 -create-app %files% -o %mainfile%.com; size of mathtest.com: 10.074 Bytes
Expected output:

Code: Select all

Circle area
r =  2.500000000
a = 19.634954452
  1. This is the standard math library, but compiled with sdcc, not sccz80. The output was not what I expected: instead of the numbers it displayed just "r = f" and "a = f"...
  2. The standard math library with sccz80, which probably is what most people use.
  3. As the PCW is somewhat similar to the CPC, I was curious if this one worked. Unfortunately the library was missing in my z88dk installation...
  4. It seems that the Cambridge Z88 math library was missing, too...
  5. The Microsoft Basic math lib resulted in the largest com file.
User avatar
dom
Well known member
Posts: 2072
Joined: Sun Jul 15, 2007 10:01 pm

Re: Amstrad PCW: math libraries

Post by dom »

bbock wrote: Sat Jan 28, 2023 8:02 pm

Code: Select all

1. zcc +cpm -subtype=pcw80 -compiler=sdcc -lm -create-app %files% -o %mainfile%.com; size of mathtest.com: 7.406 Bytes
2. zcc +cpm -subtype=pcw80 -compiler=sccz80 -lm -create-app %files% -o %mainfile%.com; size of mathtest.com: 9.281 Bytes
3. zcc +cpm -subtype=pcw80 -compiler=sccz80 -lcpcmath -create-app %files% -o %mainfile%.com; error: file open: cpcmath.lib
4. zcc +cpm -subtype=pcw80 -compiler=sccz80 -lmathz88 -fp-mode=z88 -create-app %files% -o %mainfile%.com; error: file open: mathz88.lib
5. zcc +cpm -subtype=pcw80 -compiler=sccz80 --math-mbf32 -fp-mode=z88 -create-app %files% -o %mainfile%.com; size of mathtest.com: 10.074 Bytes
[1]This is the standard math library, but compiled with sdcc, not sccz80. The output was not what I expected: instead of the numbers it displayed just "r = f" and "a = f"...
See here: https://github.com/z88dk/z88dk/wiki/Cla ... converters - when the converter are added you'll see the size increase.
[3]As the PCW is somewhat similar to the CPC, I was curious if this one worked. Unfortunately the library was missing in my z88dk installation...
There was a typo in the name of the library on the wiki page here: https://github.com/z88dk/z88dk/wiki/Cla ... -libraries However the comment "All of these libraries use the floating point package located in the machine's ROM." had always been there.
[4]It seems that the Cambridge Z88 math library was missing, too...
Ditto.
[5]The Microsoft Basic math lib resulted in the largest com file.
This surprised me, but then I remembered that the entire library is included - so including all the trig etc functions you're not using, the -lm compilation just pulls in what's needed.

----

As a note, the size of these executable is much larger than anyone would expect given what the program is actually doing. This is a result of stdio being used, which pulls in the CP/M fcntl routines. Adding -lndos will almost halve the size.
Post Reply