gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Beginners > Looking for a "viewing window" solution (maps)

#7021 - Wildginger - Fri Jun 06, 2003 11:26 am

Hi,

I have a 512x512 map where my character can happily walk around. At present, the screen is full with the current part of the map that is viewable.

What I would like to do is put a window/map over the top of the scrolling background, so that the user can only see 144x144 of the screen ( pixel 0 - 143, x and y ). The rest of the map would be covered at all times by the covering map, and I would present data in these areas.

Im sure this can be done somehow, but does anyone know how? Ive heard about map layers, but could a map have a "transparent" area in it, like a sprite can? So I could have the second map over the background map, with the top left 144x144 transparent?

Or am I barking up the wrong tree in the wrong forest?

Thanks for any ideas / pointers,

Jim
_________________
---
Wildginger (aka JimTownsend)

#7024 - Sweex - Fri Jun 06, 2003 11:58 am

Taken from the Cowbite hardware specification document:

Quote:
Windowing is a method of dividing the screen into subsections known as (surprise) windows. The windows serve as boundary areas to determine where various layers of the GBA will be shown and where they will be clipped. There are two primary windows, win0 and win1, which can be enabled in REG_DISPCNT. There is also the "obj" window, which can be thought of as another window which is defined by the visible regions of the objs on screen. Finally there is the "outside" or "out" window - the area of the screen not already occupied by any other winodw. The position and size of WIN0 and WIN1 are determined by REG_WIN0H, REG_WIN1H, REG_WIN0V, and REG_WIN1V (I/O offsets 0x40, 0x42, 0x44, 0x46). Exactly which characters and backgrounds appear within or without win0, win1, and the obj window is determined by REG_WININ and REG_WINOUT (0x48 and 0x4A).

Here are some things to keep in mind when using windows :

- WIN0 and WIN1 are drawn from the left and top boundary up to but not including the right and bottom boundaries.
- Everything in WIN0 appears "above" WIN1 (i.e. it has higher priority), and everything in windows 0 & 1 appears above the WINOUT and obj windows.
- If a bg or the obj's are turned off in dispcnt, they're off in all windows regardless of the settings in win_in and win_out.
- If only one window is on, WINOUT affects everything outside of it (if both windows are on, WINOUT affects everything outside both of them. IE, it affects (!WIN0)&&(!WIN1) ).
- If a window is on, but the effective display bits are all clear, the backdrop is displayed.
- If the window left coordinate is greater than the window right coordinate, the window will be drawn outside of this region (i.e. to the left and to the right) rather than in the area inbetween.
- Likewise, if the window top coordinate is greater than the window bottom coordinate, the window will be drawn to the top and the bottom.
- A completely inverted window is drawn in the area outside of the "+" shaped region defined by its boundaries.

Windows can be used in console games for a variety of different effects. Though the window registers define a square region, differently shaped windows can be achieved by using hdma or hblank interrupts to change the parameters each scanline. Lantern lighting (when the hero has a lantern or flashlight that illuminates a certain region of a cave) and x-ray vision (use of the window to cut away layers that are in front) are two common effects created with windows. More are certainly possible.

Thanks again to gbcft for most of these notes and for his extensive testing on the nature of windowing.


I am pretty sure you can use the window registers to achieve what you want!

#7031 - niltsair - Fri Jun 06, 2003 1:38 pm

Like sweex said, there's a register to use a viewable window just like you said. Never tried it.

Another less efficient solution, would be to use another layer like you said. Just use color 0 of your palette to tell the layer that this color is transparent.

#7033 - Wildginger - Fri Jun 06, 2003 2:34 pm

Thanks both of you for the replies.

Ive looked up the window register info, and while it looks like it would be exactly what I need, I might not quite be ready for that yet, but very handy to know it exists.

As for the layered maps, Im quite happy to be "not as efficient" while Im learning, and the layers sound fairly straight forward.

So if I make a map with a rectangle of black, and put it onto of the existing map, I will be able to see the bottom map through that rectangle?

Hope so as this would be ideal at this stage . .

Jim.

P.S. What is the priority order of the backgrounds? Is BG0 always on top? Or is BG3 always on top?
_________________
---
Wildginger (aka JimTownsend)

#7039 - niltsair - Fri Jun 06, 2003 5:10 pm

Yeah, i perfectly understand about first trying it out with layers. Beside, if you have a spare layer to spare, then that's not problem and mroe flexible (can have any see through shape . (Can be done with windows by using interupt, but harder and can't have multiple , windows)

No, not the RGB color 0, the index 0 in your palette (whatever that color is).

You can set individual priority to each layer. By default Layer 0 is the topmost or bottommost (can't remember which's which) just try it out and see.

#7052 - sgeos - Fri Jun 06, 2003 11:35 pm

niltsair wrote:
if you have a spare layer to spare, then that's not problem and mroe flexible (can have any see through shape .


I should think the window regs would be easier to use if all you want is a square window.

-Brendan