public inbox for linux-m68k@lists.linux-m68k.org
 help / color / mirror / Atom feed
From: Michael Schmitz <schmitzmic@gmail.com>
To: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Petr Stehlik <pstehlik@sophics.cz>,
	linux-m68k <linux-m68k@lists.linux-m68k.org>
Subject: Re: Wrong colors on ARAnyM
Date: Tue, 15 Feb 2022 09:50:04 +1300	[thread overview]
Message-ID: <4b3a0bc8-24a1-2a33-19bb-fbae954c614c@gmail.com> (raw)
In-Reply-To: <CAMuHMdVUX0zJtRAtjCBAa7iEk7MwCjcmSsJdCrSrPcY=6ti=cQ@mail.gmail.com>

Hi Geert,

On 14/02/22 20:41, Geert Uytterhoeven wrote:
> Hi Michael,
>
> (replying in plain text mode ;-)
Sorry about that - hopefully fixed now.
>
> On Sun, Feb 13, 2022 at 9:29 PM Michael Schmitz <schmitzmic@gmail.com> wrote:
>>
>>   2. Change the color depth a few times:
>>
>>      $ fbset -depth 1
>>      $ fbset -depth 2
>>
>> Depth 2 forces STe palette mode (in decode_var; activated in the Videl in the vbl switcher).
>>
>> [...]
>> It _looks_ as though changes to f_shift and st_shift are not pushed to hardware in the VBL interrupt. Does ARAnyM run the VBL interrupt regularly?
> Yes it does.
>
>> But maybe the kernel and ARAnyM disagree because useStPalette() has this:
>>
>> int hreg = handleReadW(HW + 0x82); // Too lame!
>> // Better way how to make out ST LOW mode wanted
>> if (hreg == 0x10 || hreg == 0x17 || hreg == 0x3e) {
>> useStPal = true;
>>
>> }
>>
>> for st_shift == 0
> Linux' falcon_setcolreg() writes to both the Falcon palette registers
> and shifter_tt.color_reg[], so shouldn't the STE color palette contain
> the correct colors, too?


I don't think it will:

The STe palette is set like this:

                 shifter_tt.color_reg[regno] =
                         (((red & 0xe) >> 1) | ((red & 1) << 3) << 8) |
                         (((green & 0xe) >> 1) | ((green & 1) << 3) << 4) |
                         ((blue & 0xe) >> 1) | ((blue & 1) << 3);

with all colours downshifted by 12 bits already. Rewriting that in the 
same form as is used in falcon_setcolreg(), i.e. without the downshift:

                 shifter_tt.color_reg[regno] =
                         (((red & 0xe000) >> 13) | ((red & 1000) >> 9) 
<< 8) |
                         (((green & 0xe000) >> 13) | ((green & 1000) >> 
9) << 4) |
                         ((blue & 0xe000) >> 13) | ((blue & 1000) >> 9);


Now look at falcon_setcolreg:

                 shifter_tt.color_reg[regno] =
                         (((red & 0xe000) >> 13) | ((red & 0x1000) >> 
12) << 8) |
                         (((green & 0xe000) >> 13) | ((green & 0x1000) 
 >> 12) << 4) |
                         ((blue & 0xe000) >> 13) | ((blue & 0x1000) >> 12);


My guess would be the two ought to be identical, assuming the STe 
palette registers provide backwards hardware compatibility.

Either way, I think we've got operator precedence wrong here. Shift 
takes precedence over bitwise and / or? With that precedence, what we 
have in summary is

                 shifter_tt.color_reg[regno] =
                         (((red & 0xe000) >> 13) | ((red & 0x1000) >> 4)) |
                         (((green & 0xe000) >> 13) | ((green & 0x1000) 
 >> 8)) |
                         ((blue & 0xe000) >> 13) | ((blue & 0x1000) >> 12);

Only the blue bits ever entirely seem to end up where they ought to. 
Testing this hypothesis on ARAnyM (without getting it to boot all the 
way, for some odd reason likely to do with my current .config) shows 
that the current code results in the shifter_tt.color_reg entries either 
5 or 0x17, 0x113 or 0x117. Adding the missing parentheses results in 
what I'd expect to see.

This bug has been present since at least 2.4.30. I do recall seeing this 
odd blue console before on the Falcon, so it's been a real bug for ages. 
Did the operator precedence change sometime since?

>
>> As the problem is not 100% reproducible, it looks like a race condition
>> in ARAnyM, or a wrong initialization order in atafb.
>>
>> I'd have to test this on hardware but haven't got fbset on the Falcon. I'll try to locate a binary.
> Sorry, you do not need fbset to reproduce this:
>
>      echo N > /sys/class/graphics/fb0/bits_per_pixel

Thanks, that's easy enough to try.

Playing around with that command a bit, it does appear that the second 
switch after selecting depth 2 turns the console blue (regardless of 
what depth is set in that step). And the second switch after that (even 
if setting depth 2) restores normal colours. No race that I can see 
there, it's quite reproducible.

Now what would cause us to miss every other palette update or depth change?

I'll verify that the bug is gone once I've rebuilt with a sane .config. 
But I think we've got enough to fix at least the annoying STe palette 
bug. Unless you want to keep that alive until we've found out what 
causes us to miss odd updates...

Cheers,

     Michael


>
> Gr{oetje,eeting}s,
>
>                          Geert
>
> --
> Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
>
> In personal conversations with technical people, I call myself a hacker. But
> when I'm talking to journalists I just say "programmer" or something like that.
>                                  -- Linus Torvalds

  reply	other threads:[~2022-02-14 20:51 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <cd0eadc8-2255-c905-d466-6514a3e1d6bd@physik.fu-berlin.de>
2022-02-12 14:59 ` Wrong colors on ARAnyM Geert Uytterhoeven
     [not found]   ` <b03160b6-7f3b-7765-49ee-c49b7dd2c4e0@gmail.com>
2022-02-14  7:41     ` Geert Uytterhoeven
2022-02-14 20:50       ` Michael Schmitz [this message]
2022-02-14 21:36         ` Michael Schmitz
2022-02-15  8:11         ` Geert Uytterhoeven
2022-02-15  9:16           ` Petr Stehlík
2022-02-21  1:54             ` Michael Schmitz
2022-02-15 20:49           ` Michael Schmitz
2022-02-16  8:24             ` Geert Uytterhoeven
2022-02-16 18:05               ` Michael Schmitz
2022-02-16  7:32           ` Michael Schmitz
     [not found]   ` <3dfea92e-baa1-6374-cdd-7aa8bd8c8ff@tarent.de>
2022-03-09 18:55     ` Wrong colours " Thorsten Glaser

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4b3a0bc8-24a1-2a33-19bb-fbae954c614c@gmail.com \
    --to=schmitzmic@gmail.com \
    --cc=geert@linux-m68k.org \
    --cc=linux-m68k@lists.linux-m68k.org \
    --cc=pstehlik@sophics.cz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox