Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.sys.apple2.programmer > #697

Re: KFest 2008 (code/demo)

From "Bill Buckels" <bbuckels@mts.net>
Newsgroups comp.sys.apple2.programmer
Subject Re: KFest 2008 (code/demo)
Date 2013-04-03 21:39 -0500
Organization Aioe.org NNTP Server
Message-ID <kjip4s$11q$1@speranza.aioe.org> (permalink)
References <8e03f7f9-a0b4-44c9-a0bf-552a3c0c6265@googlegroups.com> <79a95566-8526-492e-8510-13ca899dcee9@googlegroups.com>

Show all headers | View raw


"BLuRry" <brendan.robert@gmail.com> wrote:

> *scratches head*

You need to rotate the auxiliary colors, that's all. Here's two translation 
tables and a c program that explains. Unfortunately I am not finished 
writing my book about this yet, a little later in the week perhaps, when  I 
do you can read the novel...

code snippets and some explanation follows... I am assuming that you know 
how packed pixels work between the even and odd scanlines that sort of 
thing. If not *YOU* can send me PM and ask for more:)

Color Indices for Auxiliary Memory - Rotating the Bits of the Nibbles

The "packed pixel" colors for DLGR main memory (bank 0) use the same color 
indices (color numbers) as normal Lo-Res. In a manner of speaking, auxiliary 
memory uses the same numbers too, but they are stored in memory differently; 
when writing a Lo-Res color index number to bank1 (auxiliary memory), a 
right rotate no carry (right circular shift) of the 4-bit color number is 
needed, and when reading a Lo-Res color number from bank 1, a left rotate no 
carry (left circular shift) is needed.

In English, a circular shift is the operation of rearranging the entries in 
a "tuple", (in the case of moving a pixel between main and auxiliary memory, 
the four-tuple of bits in the Lo-Res color or color nibble), either by 
moving the final entry to the first position, while shifting all other 
entries to the next position, or by performing the inverse operation.

/* the following is used to remap double lo res 4 bit colors
from bank 0 to bank 1 */
unsigned char dloauxcolor[16] = {
0,8,1,9,2,10,3,11,4,12,5,13,6,14,7,15};

/* the following is used to remap double lo res 4 bit colors
from bank 1 back to bank 0 */
unsigned char dlomaincolor[16] = {
0,2,4,6,8,10,12,14,1,3,5,7,9,11,13,15};


Program Listing - DLGR Conversion Table Generator

int main()
{
    int color;
    unsigned char nib,big,bit;

    /* produce conversion tables for DLGR color indices */
    puts("/* the following is used to remap\n"
         "double lo res 4 bit colors\n"
         "from bank 0 to bank 1 */\n"
         "unsigned char dloauxcolor[16] = {");

    for (color=0; color< 16; color++) {
        /* right circular shift */
          nib = (unsigned char )color;
        big = (nib >> 1);
        bit = (nib &1) << 3;
        nib = (big | bit);

        if (color) putchar(',');
          printf("%d",(int)nib);
    }
    puts("};");

    puts("/* the following is used to remap\n"
         "double lo res 4 bit colors\n"
         "from bank 1 back to bank 0 */\n"
         "unsigned char dlomaincolor[16] = {");

    for (color=0; color< 16; color++) {
        /* left circular shift */
          nib = (unsigned char )color;
          big = (nib << 1) &0xF;
          bit = (nib >> 3) &1;
          nib = (big | bit);

        if (color) putchar(',');
          printf("%d",(int)nib);

      }
      puts("};");

    return 0;
}

The working code above produced the DLGR color conversion tables listed 
earlier. The programming example that follows demonstrates how the 
conversion table is used on the Apple II. These tables are also used for 
color conversion in AWINDLO and BMP2LO.

Programming Example - Plotting a DLGR Pixel using Apple II Rom Routines

/* bank 0 color remapping to bank 1 color */
unsigned char dloauxcolor[16] = {
      0,8,1,9,2,10,3,11,4,12,5,13,6,14,7,15};
#define XREG  0
#define YREG  1
#define COLOREG 0
#asm
instxt <zpage.h>
XVAL equ  REGS
YVAL equ  REGS+1
COLOR equ REGS
#endasm
unsigned char *dlobyteregptr = (unsigned char *)0x80;
dloplot(x, y, color)
{
  int w, z = x;
/* Double Lo-Res works the same way 80-column text does:
   columns 0, 2, 4, ...78 are stored in AuxRAM,
   and columns 1, 3, 5, ...79 are stored in MainRAM. */
   x = z / 2;
   w = x * 2;
   if (z==w)  dlobyteregptr[COLOREG] = dloauxcolor[color];
   else dlobyteregptr[COLOREG] = (unsigned char)color;
#asm
  LDA COLOR ; Sets the plotting color to N, 0 <= N <= 15
  JSR $F864
#endasm
   if (z!=w)
  {
#asm
      sta  $c054
#endasm
  }
  else {
#asm
      sta  $c055
#endasm
  }
  /* load parameters into user regs */
  dlobyteregptr[XREG] = x;
  dlobyteregptr[YREG] = y;
  /* make ml call */
#asm
  LDY XVAL  ; Lo-Res Plot X (Horizontal) Coordinate (0-39)
  LDA YVAL  ; Lo-Res Plot Y (Vertical) Coordinate (0-39)
  JSR $F800
#endasm
}

The above routine is written in Aztec C65 for Apple IIe ProDOS. It is a 
working code excerpt from the AppleX MS-DOS/Windows cross-compiler 
distribution. 

Back to comp.sys.apple2.programmer | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

KFest 2008 (code/demo) Dagen Brock <DagenBrock@gmail.com> - 2013-04-02 13:09 -0700
  Re: KFest 2008 (code/demo) BLuRry <brendan.robert@gmail.com> - 2013-04-02 21:14 -0700
    Re: KFest 2008 (code/demo) "Bill Buckels" <bbuckels@mts.net> - 2013-04-03 21:39 -0500
      Re: KFest 2008 (code/demo) BLuRry <brendan.robert@gmail.com> - 2013-04-03 19:48 -0700

csiph-web