Re: [cc65] Re: TGI colors revisited

From: Oliver Schmidt <ol.sc1web.de>
Date: 2011-05-03 23:16:53
Hi Greg,

> The Lynx library _will_ have conio support (20 columns by 12 lines)!

Cool !

>> Just to make sure there's no misunderstanding which might result in
>> potentially unnecessary work on your side:
>>
>> - The default palette needs to contain the values 0, 1, ..., 14, 15,
>> in that order.
>>
>> - The TGI functions tgi_setpalette/tgi_getpalette/tgi_getdefpalette
>> need to operate on palettes being 16 bytes large.
>> So, there needs to be some mapping between the "TGI palette"
>> and the "12-bit palette".
>>
>> - If you feel that this doesn't give a fine-grained enough
>> control over the colors used, you might consider to provide some
>> tgi_ioctl function to manipulate the 12-bit palette directly.
>
> My reason for not replying sooner is that the implications are too
> complex to be digested quickly.  But, I see that I must speak up before
> the misunderstandings go too far.

I see. Thanks for your involvement.

> First things first:  Those new rules mean that tgi_getdefpalette() has
> become pointless!  It always will return the exact same thing -- on all
> platforms.  A program can generate an ascending array if it's needed.
> When it isn't needed, that function just wastes space in the driver.

If I understand you correctly then you don't disagree (at least right
now) to the usefullness of those rules. So you agree that the result
of those rules is a default palette constructed from ascending values.

That given I absolutely see your point regarding tgi_getdefpalette().
However consider the following:

1. We, the TGI insiders, know how a default palette looks like. But
that doesn't necessarily mean that every TGI application programmer
should be required to know it. Thinking very carefully about the ways
he can use the TGI_COLOR_... macros he could potentially reason it but
he shouldn't be required to know. But one can say: "The TGI
application programmer can just call tgi_getpalette() and save it
before potential calls to tgi_setpalette() to get the default
palette."

2.  If you look at the source of tgi_init() in the TGI kernel you'll
see that the TGI kernel basically does a
tgi_setpalette(tgi_getdefpalette()). The idea behind this is most
likely that the TGI driver can omit certain initializations (palette,
view page, draw page, drawing color, text style) because they are done
by the TGI kernel via the driver entry points. But there's no reason
why the TGI kernel shouldn't know about the way default palettes look
like so it could create the ascending values. However tgi_setpalette()
requires a pointer to the array so the TGI kernel would need to
actually build that array im memory - all this is certainly larger
than the array of values in the driver.

So the result is: If you don't want to redesign the roles of the TGI
kernel and driver on tgi_init() then tgi_getdefpalette() comes for
free.

> The Lynx's graphics engine uses two palettes: the hardware palette is
> the 12-bit one that Karri described, the software palette actually is a
> mapping table.  The number that we give to tgi_setcolor() is used as an
> index into the pen (or paint-brush) table; the value from that table is
> used as an index into the hardware-palette table.  That second
> (hardware) index is stored on the screen.

I must admit I haven't fully understood...

> In order to allow the palette manipulation that you have described
> earlier, we must use the brush table as the TGI palette.  But, after the
> palette is changed, there might not be a one-to-one match between the
> values that were given to tgi_setcolor() and the values that are
> returned when tgi_getpixel() is used on "old" pixels (ones that were
> drawn before the palette was changed)!

If I understand you right than this approach wouldn't fit the
semantics of a palette. A palette means - at least from my perspective
- that setting a (different) palette immediately causes re-coloring of
all already displayed pixels.

The usual approach would rather be to translate the values in the TGI
palette into values for the 12-bit palette on calls to
tgi_setpalette(). A call to tgi_getpalette() could either return a
shadow copy of the last TGI palette given to tgi_setpalette() or
alternatively translate values in the 12-bit palette back into values
in the TGI palette. Or do I miss the point why this generally doesn't
work on the Lynx?

Regards,
Oliver
----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo@musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.
Received on Tue May 3 23:17:08 2011

This archive was generated by hypermail 2.1.8 : 2011-05-03 23:17:10 CEST