ZX80 weird formatting issue

ZX80, ZX 81, ZX Spectrum, TS2068 and other clones
Post Reply
ShaunB
Member
Posts: 41
Joined: Mon Jan 02, 2012 6:13 pm

ZX80 weird formatting issue

Post by ShaunB »

Hi ZX gurus,

I'm having a weird formatting issue when printing the £ sign on the ZX80, as the attached screen should demonstrate.

Image

Here is my codes:

Code: Select all

void titleScreen()
{
        printf("       donkeysoft  mmxvii\r\n    and monument  microgames\r\n            presents\r\n          QuIcK FrUiTs");
        printf("\r\nyou start with ?5.00 \r\neach spin costs ?0.25p");
        printf("\r\nWIN TABLE:\n");
        printTab(2, "? ? ? = ?10.00\n");
        printTab(2, "$ $ $ = ?7.50\n");
        prompt("press any key to play", 2);
}
The printTab() function is as follows:

Code: Select all

void printSpc(unsigned char spc, unsigned char txt[31])
{
        for(spc; spc > 0; spc--)
        {
                printf(" ");
        }
        printf("%s", txt);
}

void printTab(unsigned char tab, unsigned char txt[28])
{
        tab = tab * 4;
        printSpc(tab, txt);
}
Is there an issue when converting the £ sign in the compiler? Or is it the ZX80 that is somehow causing the issue, and if so why is it printing the winnings okay etc...?

Many thanks,

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

Post by alvin »

I don't have permission to see the screenshot but I can guess what the problem is. The pound symbol is not an ascii character so you're making a string with a unicode encoded symbol in it. Try using code 0x60 or the ascii back-tick instead. On the spectrum that's where the pound symbol is and the ascii conversion for the zx80 may be using the same ascii character for pound.
ShaunB
Member
Posts: 41
Joined: Mon Jan 02, 2012 6:13 pm

Post by ShaunB »

Thanks Alvin,

That explains the white-spaces.

Here are the Sinclair ZX80 character codes which is non-ASCII compatible and there are some differences between the ZX80 and the ZX81.

This does mean that I'll have to not use the printf() command and use my own print routine instead; not a problem but I wanted to keep things fairly standard with this project.

Thanks,

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

Post by alvin »

For the zx80 (and zx81) printf does an ascii to zx80 character set conversion at runtime. The pound symbol is in there ( https://github.com/z88dk/z88dk/blob/mas ... ab.asm#L41 -- the zx80 shares the zx81's printf ) and it looks to be at ascii code 0xa3.

So you should be able to do something like this to see pound symbols:

Code: Select all

printTab(2, "\xa3 \xa3 \xa3 = " "\xa3" "10.00\n");
I had to be careful to place the last pound symbol in a separate string so that the hex constant wouldn't swallow the "10" after it.
ShaunB
Member
Posts: 41
Joined: Mon Jan 02, 2012 6:13 pm

Post by ShaunB »

Hi Alvin,

I think you have given me a hint on how string concatenation works in z88dk?

Thanks,

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

Post by alvin »

Do you mean something like strcat() or the two quoted strings put together?

In C, two quoted strings next to each other are the same as a single quoted string.

So:

"The quick brown fox jumped over the lazy dogs"

is the same as:

"The quick brown" " fox jumped " "over the lazy dogs"

In the above, I couldn't do this:

printTab(2, "\xa3 \xa3 \xa3 = \xa310.00\n");

because the compiler would take the last hex constant as "\xa310" instead of "\xa3". There has to be a non-hex digit separating the hex constant from the rest of the literal string. One way to do that is to make two quoted strings out of it:

printTab(2, "\xa3 \xa3 \xa3 = \xa3" "10.00\n");
Post Reply