Why two windows?

Discussion of hardware and software development for Super NES and Super Famicom. See the SNESdev wiki for more information.

Moderator: Moderators

Forum rules
  • For making cartridges of your Super NES games, see Reproduction.
iNCEPTIONAL

Re: Why two windows?

Post by iNCEPTIONAL »

tokumaru wrote: Fri Apr 05, 2019 3:55 pm 1 for each player? I don't know...
Definitely used as such in Contra III for the likes of smart bombs and shields.
User avatar
jeffythedragonslayer
Posts: 344
Joined: Thu Dec 09, 2021 12:29 pm

Re: Why two windows?

Post by jeffythedragonslayer »

I think the reason there are only two windows is because the logic for combining them together gets too complicated when you add more than that. Each window contributes one binary input (whether the pixel is "inside" or "outside" that window) to a truth table tensor that tells you whether or not the pixel is "inside" or "outside" all of the windows.

How many truth tables can you build with two binary inputs?

Code: Select all

2^(2^2) =16
^  ^ ^
|  | because 2 of them
|  because binary input
because binary output
The window logic can be AND, OR, XOR or NOR (2 bits can keep track of that choice), you can disable one window or the other (another two bits) and you can invert both windows (another two bits). Wait, that's 6 bits! 2^6.. that’s 64! What did I do wrong? Well, I think there are some symmetries because of De Morgan's laws.

How many with three binary inputs?

Code: Select all

2^(2^3)=256
^  ^ ^
|  | because 3 of them
|  because binary input
because binary output
Four?

Code: Select all

2^(2^4)=65,536
^  ^ ^
|  | because 4 of them
|  because binary input
because binary output
iNCEPTIONAL

Re: Why two windows?

Post by iNCEPTIONAL »

jeffythedragonslayer wrote: Fri Jul 01, 2022 12:46 am I think the reason there are only two windows is because the logic for combining them together gets too complicated when you add more than that. Each window contributes one binary input (whether the pixel is "inside" or "outside" that window) to a truth table tensor that tells you whether or not the pixel is "inside" or "outside" all of the windows.

How many truth tables can you build with two binary inputs?

Code: Select all

2^(2^2) =16
^  ^ ^
|  | because 2 of them
|  because binary input
because binary output
The window logic can be AND, OR, XOR or NOR (2 bits can keep track of that choice), you can disable one window or the other (another two bits) and you can invert both windows (another two bits). Wait, that's 6 bits! 2^6.. that’s 64! What did I do wrong? Well, I think there are some symmetries because of De Morgan's laws.

How many with three binary inputs?

Code: Select all

2^(2^3)=256
^  ^ ^
|  | because 3 of them
|  because binary input
because binary output
Four?

Code: Select all

2^(2^4)=65,536
^  ^ ^
|  | because 4 of them
|  because binary input
because binary output
Question: Do you think I would be able to have the shadow shape on my planet*, which is done using one of the windows (plus some colour math), rotate across the planet as the sun moves across the screen without it basically causing slowdown?

Think of it in terms of what's already there plus a few enemies additionally flying around and some weapons fire and such, but with that stuff coded in such as way as to not already cause the game to slowdown or be near the point of slowing down most of the time.

Just trying to gauge how costly that window-based shadow rotation effect might be roughly, since the shape would be changing every frame basically, and if it would be genuinely plausible to use in-game while the other typical shmup stuff is going on (assuming the rest of the game is well programmed and optimized).

*https://youtu.be/IyrOCNQc_rs?t=48
Last edited by iNCEPTIONAL on Fri Jul 01, 2022 5:08 am, edited 1 time in total.
creaothceann
Posts: 611
Joined: Mon Jan 23, 2006 7:47 am
Location: Germany
Contact:

Re: Why two windows?

Post by creaothceann »

jeffythedragonslayer wrote: Fri Jul 01, 2022 12:46 am I think the reason there are only two windows is because the logic for combining them together gets too complicated when you add more than that. Each window contributes one binary input (whether the pixel is "inside" or "outside" that window) to a truth table tensor that tells you whether or not the pixel is "inside" or "outside" all of the windows.
The window attributes and the current position are most likely processed with simple logic gates, like this:

Code: Select all

var
        x, y : i16;  // current position


        // SNES PPU registers

        W1_left, W1_right                          : u8;  // 2126 WH0, 2127 WH1
        W2_left, W2_right                          : u8;  // 2128 WH2, 2129 WH3

        W1_inverted_for_BG1, W1_enabled_for_BG1    : u1;  // 2123 W12SEL
        W2_inverted_for_BG1, W2_enabled_for_BG1    : u1;
        W1_inverted_for_BG2, W1_enabled_for_BG2    : u1;
        W2_inverted_for_BG2, W2_enabled_for_BG2    : u1;

        W1_inverted_for_BG3, W1_enabled_for_BG3    : u1;  // 2124 W34SEL
        W2_inverted_for_BG3, W2_enabled_for_BG3    : u1;
        W1_inverted_for_BG4, W1_enabled_for_BG4    : u1;
        W2_inverted_for_BG4, W2_enabled_for_BG4    : u1;
        
        W1_inverted_for_OBJ, W1_enabled_for_OBJ    : u1;  // 2125 WOBJSEL
        W2_inverted_for_OBJ, W2_enabled_for_OBJ    : u1;
        W1_inverted_for_COL, W1_enabled_for_COL    : u1;
        W2_inverted_for_COL, W2_enabled_for_COL    : u1;

        Window_logic_for_BG1, Window_logic_for_BG2 : u2;  // 212A WBGLOG  (0..3 = OR/AND/XOR/XNOR)
        Window_logic_for_BG3, Window_logic_for_BG4 : u2;

        Window_logic_for_OBJ, Window_logic_for_COL : u2;  // 212B WOBJLOG (0..3 = OR/AND/XOR/XNOR)

        Mask_BG1_on_Main, Mask_BG1_on_Sub          : u1;  // 212E, 212F bit 0
        Mask_BG2_on_Main, Mask_BG2_on_Sub          : u1;  // 212E, 212F bit 1
        Mask_BG3_on_Main, Mask_BG3_on_Sub          : u1;  // 212E, 212F bit 2
        Mask_BG4_on_Main, Mask_BG4_on_Sub          : u1;  // 212E, 212F bit 3
        Mask_OBJ_on_Main, Mask_OBJ_on_Sub          : u1;  // 212E, 212F bit 4

begin
        in_W1 := NOT (most_significant_bit(x - W1_left) OR most_significant_bit(W1_right - x));  // same for window 2
        in_W1_for_BG1 := (in_W1 XOR W1_inverted_for_BG1) AND W1_enabled_for_BG1;                 //
        in_W1_for_BG2 := (in_W1 XOR W1_inverted_for_BG2) AND W1_enabled_for_BG2;                 //
        in_W1_for_BG3 := (in_W1 XOR W1_inverted_for_BG3) AND W1_enabled_for_BG3;                 //
        in_W1_for_BG4 := (in_W1 XOR W1_inverted_for_BG4) AND W1_enabled_for_BG4;                 //
        in_W1_for_OBJ := (in_W1 XOR W1_inverted_for_OBJ) AND W1_enabled_for_OBJ;                 //
        in_W1_for_COL := (in_W1 XOR W1_inverted_for_COL) AND W1_enabled_for_COL;                 //

        if (in_W1_for_BG1 and in_W2_for_BG1) then  case Window_logic_for_BG1 of  // same for BG2/BG3/BG4/OBJ/COL
                0:   masked_BG1 :=     (in_W1_for_BG1  OR in_W2_for_BG1);        //
                1:   masked_BG1 :=     (in_W1_for_BG1 AND in_W2_for_BG1);        //
                2:   masked_BG1 :=     (in_W1_for_BG1 XOR in_W2_for_BG1);        //
                else masked_BG1 := NOT (in_W1_for_BG1 XOR in_W2_for_BG1);        //
        end else begin                                                           //
                masked_BG1 := in_W1_for_BG1 OR in_W2_for_BG1;                    //
        end;                                                                     //

        if (cur_Screen = Mainscreen)                                // same for BG2/BG3/BG4/OBJ/COL
                then masked_BG1 := masked_BG1 AND Mask_BG1_on_Main  //
                else masked_BG1 := masked_BG1 AND Mask_BG1_on_Sub;  //
end;
(Free Pascal pseudocode)

Adding more windows would mean increasing the chip die size (many of these operations can be done at the same time) and/or increasing the number of cycles required to render a pixel.
My current setup:
Super Famicom ("2/1/3" SNS-CPU-GPM-02) → SCART → OSSC → StarTech USB3HDCAP → AmaRecTV 3.10
User avatar
jeffythedragonslayer
Posts: 344
Joined: Thu Dec 09, 2021 12:29 pm

Re: Why two windows?

Post by jeffythedragonslayer »

iNCEPTIONAL wrote: Fri Jul 01, 2022 1:12 am Question: Do you think I would be able to have the shadow shape on my planet*, which is done using one of the windows (plus some colour math), rotate across the planet as the sun moves across the screen without it basically causing slowdown?
Yes, make the HDMA table a 2d array. Along one axis you lookup the angle formed by the vectors pointing out of the planet into the camera and sun. The other axis is the scanline, and the value you lookup is the X position of the first pixel that is in shadow.
iNCEPTIONAL

Re: Why two windows?

Post by iNCEPTIONAL »

jeffythedragonslayer wrote: Fri Jul 01, 2022 6:41 am
iNCEPTIONAL wrote: Fri Jul 01, 2022 1:12 am Question: Do you think I would be able to have the shadow shape on my planet*, which is done using one of the windows (plus some colour math), rotate across the planet as the sun moves across the screen without it basically causing slowdown?
Yes, make the HDMA table a 2d array. Along one axis you lookup the angle formed by the vectors pointing out of the planet into the camera and sun. The other axis is the scanline, and the value you lookup is the X position of the first pixel that is in shadow.
See, this stuff is good to know because that properly moving shadow across the Earth is really going to sell the visual effect that everything is rotating around the Earth centre point, especially when the higher speed rotation kicks in.
tepples
Posts: 22708
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: Why two windows?

Post by tepples »

cornedgreens wrote: Thu Jun 30, 2022 8:11 pm
tepples wrote: Sat Apr 06, 2019 6:58 am Perhaps the Super NES window doesn't need top and bottom variables because its HDMA is more versatile than that of the GBA.
Is this so? Please explain. Did it not have the DMA controller built into the CPU like the SNES did?
The Super NES has eight DMA channels. The Game Boy Advance has only four, and two are often occupied with PCM audio.
Post Reply