ansi vs zx colours

ZX80, ZX 81, ZX Spectrum, TS2068 and other clones
Post Reply
cborn
Member
Posts: 17
Joined: Tue Oct 06, 2020 7:45 pm

ansi vs zx colours

Post by cborn »

Hello,
i had a small quest with colours and found the -clib=ansi remark which works nice

Code: Select all

/* zcc +zx -vn -clib=ansi ansi-table.c -o ansi-table -lndos -create-app  */
#include <stdio.h>
int main(void)
{
  int i, j, n;
  for (i = 0; i < 11; i++) {
    for (j = 0; j < 10; j++) {
      n = 10*i + j;
      if (n > 108) break;
      printf("\033[%dm %3d\033[m", n, n);
    }
    printf("\n");
  }
  return (0);
}
but its all a bit different.
without -clib=ansi it seems to use ansi anyway when i us/x10 and /x11 for ink and paper

Code: Select all


/* zcc +zx -vn zxtansi_004.c -o zxtansi_004 -lndos -create-app */

// bitwise:
// BIN FBPPPIII  = b7=Flash b6=bright b543=paper b210=ink
// characterwise:
// chr$ 16 + chr$ I is INK
// chr$ 17 + chr$ P is PAPER
// chr$ 18 + chr$ F is FLASH
// chr$ 19 + chr$ B is BRIGHT
// notice that Flash and Bright are reversed as bitwise value from characterwise value
// more logic WOULD be to use 18 for bright and 19 for flash, but it AINT 'mind the gab'

#include <stdio.h>

int main(void)
{
  int g, b, f, p, i, n ;
  char  colour[]={' ',' ',  ' ',' ',  ' ',' ',  ' ',' ',  0 };
  colour[0]=16;  //ink command
  colour[1]= 0;  //    value black cq 0
  colour[2]=17;  //paper command
  colour[3]= 7;  //    value withe cq 7
  colour[4]=18;  //flash command
  colour[5]=48;  //     off
  colour[6]=19;  //bright command
  colour[7]=48;  //     off

  char defaultcolour[]={' ',' ',  ' ',' ',  ' ',' ',  ' ',' ',  0 };
  defaultcolour[0]=16;  // INK command
  defaultcolour[1]=48;  // \x30 black
  defaultcolour[2]=17;  // PAPER command
  defaultcolour[3]=55;  // \x37 white
  defaultcolour[4]=18;  // FLASH  command
  defaultcolour[5]=48;  // \x30 off
  defaultcolour[6]=19;  // BRIGTH command
  defaultcolour[7]=48;  // \x37 off

for (g =0 ; g < 248 ; g=g+8 )
   { 
   for (f = 0 ; f <=1 ; f++ )
     {
     for (b = 0 ; b <=1 ; b++ )
       {
       for (p = 0 ; p <=7 ; p++)
         {
         printf("%s    n   i   p   f   b   g  i+g  p+g \n" , defaultcolour ) ;
         for (i = 0 ; i <=7 ; i++)
           {
           n = f*128 + b*64 + p*8 + i ; // BINARY VALUE !!!!!
           colour[1]=i+g;  //ink value
           colour[3]=p+g;  //paper value
           colour[5]=f+48;  //flash value
           colour[7]=b+48;  //bright value

//           if (n > 255) break ;
           printf("%s  %4d  %2d %2d %2d %2d %3d %3d %3d\n",colour, n , i, p, f, b, g , i+g , p+g) ;

           }
         sleep(2) ;
         }
       }
     }
   printf("%s \n",defaultcolour) ;
   }
return (0);
}
How can i use the standard values for colour instead off the ansi coding?
User avatar
dom
Well known member
Posts: 1194
Joined: Sun Jul 15, 2007 10:01 pm

Re: ansi vs zx colours

Post by dom »

Colour mapping is detailed here: https://github.com/z88dk/z88dk/wiki/Cla ... ur-mapping - just add that pragma and you're back to regular ZX colours.
Post Reply