Gameboy Development Forum

Discussion about software development for the old-school Gameboys, ranging from the "Gray brick" to Gameboy Color
(Launched in 2008)

You are not logged in.

Ads

#1 2016-01-09 17:46:14

Glad
Member
From: France
Registered: 2015-03-04
Posts: 28
Website

Background and window

Hi people !
I'm currently programming a little game in asm and I've got a question about windows. I've been able to place a window on the screen but I need the color $00 to be transparent. Is it possible or did I have to use sprites instead ?
Thanks !

Last edited by Glad (2016-01-09 17:46:49)


Another boring artist.

Current software project --> Walking under the rain (GB)
Current hardware project --> GlitchBoy

Offline

 

#2 2016-01-09 21:44:56

Glad
Member
From: France
Registered: 2015-03-04
Posts: 28
Website

Re: Background and window

I read the PanDocs about windows and I've got my answer... Apparently I can't display a custom sized window since it cover all the background so I will just use sprites. Never use them before, I'm a bit scared.


Another boring artist.

Current software project --> Walking under the rain (GB)
Current hardware project --> GlitchBoy

Offline

 

#3 2016-01-10 04:50:37

Xephyr
Member
From: France
Registered: 2015-02-26
Posts: 59

Re: Background and window

Well it depends on what you want to do with your window. You can always move it to the top / bottom or a side of your screen in order to have a menu. In the screenshot above for example, the window has been moved to the top so that only two line of the screen are used :

http://www.batondejoie.com/wp-content/uploads/2011/06/super_mario_land-first_stage.png

You can also use sprites as you mentioned, but don't forget that they are limited in numbers.

Offline

 

#4 2016-01-10 11:58:12

Glad
Member
From: France
Registered: 2015-03-04
Posts: 28
Website

Re: Background and window

So technically, I can make a custom sized window ?

I mean, if I place my window at the bottom of the screen and make it flash by enable/disable the window on [rLCDC], it will work ?

I want it to work like the picture below (the window is in the red rectangle)

http://img15.hostingpics.net/thumbs/mini_725966test2Recoveredcopy.png

Last edited by Glad (2016-01-10 11:59:34)


Another boring artist.

Current software project --> Walking under the rain (GB)
Current hardware project --> GlitchBoy

Offline

 

#5 2016-01-10 12:16:51

Xephyr
Member
From: France
Registered: 2015-02-26
Posts: 59

Re: Background and window

Yeah, you should be able do that by moving your window (there's some registers for that).

But if you have only that text to animate, sprites should be enough though.

Last edited by Xephyr (2016-01-10 12:17:59)

Offline

 

#6 2016-01-10 12:21:56

Glad
Member
From: France
Registered: 2015-03-04
Posts: 28
Website

Re: Background and window

So I load a 20*18 tiles window and put the upper lft corner at the bottom of my screen and it will work ?


Another boring artist.

Current software project --> Walking under the rain (GB)
Current hardware project --> GlitchBoy

Offline

 

#7 2016-01-10 12:25:25

Tauwasser
Member
Registered: 2010-10-23
Posts: 160

Re: Background and window

Moving it to the right and/or bottom of the screen is easy, because the overhang is just not drawn. Having it at the top or left is hard, because you then need to disable it on the correct line in order for it to be drawn.

cYa,

Tauwasser

Offline

 

#8 2016-01-10 15:13:04

Glad
Member
From: France
Registered: 2015-03-04
Posts: 28
Website

Re: Background and window

So I've been able to move my windows at the bottom like I wanted but there's some glitchs at the top now...

http://img15.hostingpics.net/thumbs/mini_979415Untitled3copy.jpg


Another boring artist.

Current software project --> Walking under the rain (GB)
Current hardware project --> GlitchBoy

Offline

 

#9 2016-01-10 17:44:29

Tauwasser
Member
Registered: 2010-10-23
Posts: 160

Re: Background and window

It looks like you either write to the Bg, or you accidentally switched the tile base from 0x8800 to 0x8000 or something.

cYa,

Tauwasser

Offline

 

#10 2016-01-10 18:54:55

Glad
Member
From: France
Registered: 2015-03-04
Posts: 28
Website

Re: Background and window

For displaying the BG, I put this in [rLCDC] : %11010001

And when I need my window to pop, I write this in [rLCDC] : %1111001

I've read the pandoc and the gameboy programming guide but I can't find out where I'm wrong !
Maybe It's a problem with the bit 4 for the BG and window tile data selection...


Another boring artist.

Current software project --> Walking under the rain (GB)
Current hardware project --> GlitchBoy

Offline

 

#11 2016-01-10 20:05:22

l0k1
Member
Registered: 2014-10-23
Posts: 44

Re: Background and window

Just flipping that bit shouldn't write garbage to the screen. Can you show us some more code?

EDIT: bit, not but.

Last edited by l0k1 (2016-01-11 00:02:56)

Offline

 

#12 2016-01-10 20:25:34

Glad
Member
From: France
Registered: 2015-03-04
Posts: 28
Website

Re: Background and window

here is the two function for displaying the main menu screen and the window :

Main_Menu:

di
call LCD_Off
xor A
ld [rSCX],A
ld [rSCY],A
ld HL, Menu_Tiles
ld DE,$95 * $10            ;Chargement de 146 tiles
call Load_Tiles_Into_VRAM

ld HL,Menu_Map
call Screen_Load_0_20x18

ld A,%11010001             ;BG On -
ld [rLCDC],A
ei
call Fade_In_Black

ret

SECTION "Press_Start_Window",HOME

Press_Start_Window:
di
call LCD_Off
ld A,7
ld [rWX],A
ld A, $6D
ld [rWY],A
ld HL, Press_Start_Tiles
ld DE,$1B * $10            ;Chargement de 27 tiles
call Load_Tiles_Into_VRAM

ld HL,Press_Start_Map
call Screen_Load_1_20x18

ld A,%11110001             ;Window+BG On
ld [rLCDC],A
ei

ret

and here's the sub fonctions for loading the screen and loading the window

Screen_Load_0_20x18:
   ld DE,18                   ;this many y-lines.
   ld BC,_SCRN0-(12)          ;background tile map 0. subtracting 12, as it'll be added in again soon.
.y_line_loop
   push DE                    ;Storing the Y-Line coord for later.
   ld DE,12                   ;first, we need to increase _SCRN0 location by 12*16, and ignore all the tiles off screen
.inc_bgmap_location
   inc BC
   dec DE
   ld A,E
   or D
   jp nz,.inc_bgmap_location
   
   ld DE,20          ;x-length, 20 tiles at 16 bytes each
.x_line_loop
   ld A,[HL+]        ;where the magic happens
   ld [BC],A
   inc BC
   dec DE
   ld A,E
   or D
   jp nz,.x_line_loop

   pop DE            ;after we've got done loading an x-line, we need to check our y-line
   dec DE
   ld A,E
   or D
   jp nz,.y_line_loop
   ret

     SECTION "20x18 Screen Load 1",HOME
   ;Used for loading a map into the BG map area at $9800 that is 20x18 tiles.
   ;HL must be at the start of the tile data.
   ;Assumes rSCX & rSCY are at 0,0.
Screen_Load_1_20x18:
   ld DE,18                   ;this many y-lines.
   ld BC,_SCRN1-(12)          ;background tile map 1. subtracting 12, as it'll be added in again soon.
.y_line_loop_w
   push DE           ;Storing the Y-Line coord for later.
   ld DE,12          ;first, we need to increase _SCRN1 location by 12*16, and ignore all the tiles off screen
.inc_winmap_location
   inc BC
   dec DE
   ld A,E
   or D
   jp nz,.inc_winmap_location
   
   ld DE,20          ;x-length, 20 tiles at 16 bytes each
.x_line_loop_w
   ld A,[HL+]        ;where the magic happens
   ld [BC],A
   inc BC
   dec DE
   ld A,E
   or D
   jp nz,.x_line_loop_w

   pop DE            ;after we've got done loading an x-line, we need to check our y-line
   dec DE
   ld A,E
   or D
   jp nz,.y_line_loop_w
   ret

I use some sample of your SuperHappyFunBubbleTime project for doing this !

Last edited by Glad (2016-01-10 21:51:04)


Another boring artist.

Current software project --> Walking under the rain (GB)
Current hardware project --> GlitchBoy

Offline

 

#13 2016-01-11 00:02:01

l0k1
Member
Registered: 2014-10-23
Posts: 44

Re: Background and window

Glad to see my code is helping someone. =] Use all you need!

First, a thought - the note you have under the section heading for Screen_Load_1_20x18 should read that it's loading data to $9C00, not $9800.

But! That's not important. =]

It looks like the error is coming in with your second use of Load_Tiles_Into_VRAM. When you call that the second time, it's overwriting the tiles you put in on the first Load_Tiles_Into_VRAM call, which is why "garbage" is being shown on the screen.
What I'd do to fix is load all the tiles right away, so you don't have to call it a second time.
Or, use sprites for the "Press Start" text.

Either way, really good looking opening screen. Puts mine to shame!

Offline

 

#14 2016-01-11 09:50:42

Glad
Member
From: France
Registered: 2015-03-04
Posts: 28
Website

Re: Background and window

Thank you very much L0k1 ! I will try to load all the tiles together and see if it's change something. If it don't I will go for the sprites !


Another boring artist.

Current software project --> Walking under the rain (GB)
Current hardware project --> GlitchBoy

Offline

 

#15 2016-01-11 21:34:05

Glad
Member
From: France
Registered: 2015-03-04
Posts: 28
Website

Re: Background and window

Took me 3 hours but I did it ! I've load all my tiles at the same time like you suggest and it worked !
Thank you so much guys !


Another boring artist.

Current software project --> Walking under the rain (GB)
Current hardware project --> GlitchBoy

Offline

 

#16 2016-01-12 03:25:47

l0k1
Member
Registered: 2014-10-23
Posts: 44

Re: Background and window

Awesome! Happy you got it working.

grumpily gets back to working on his own bugs

Last edited by l0k1 (2016-01-12 03:26:31)

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2005 Rickard Andersson