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 2022-05-22 08:23:52

Azenris
Member
Registered: 2022-03-30
Posts: 12

Section Fragments

I have a few questions about fragments and alignment  etc.

Basically i have https://pastebin.com/fVytPQ2z

1) Would title_screen_tile_data_vram0 be 16 bytes aligned or is it simply shoved to the end of the first section, and then the whole combined section is 16 byte.
a) title_screen_tile_data_vram0 16 bytes aligned
b) title_screen_data 16 bytes aligned
c) both get 16 byte aligned
d) something completely different

What I want:
> What I want to do is 16 byte align title_screen_tile_data_vram0 & title_screen_tilemap & title_screen_tilemap_attr
> title_screen_palette & title_screen_data I don't care about alignment
> BUT i want all this data in a single bank
> AND i want a floating bank, eg not manually specified.

Is this achievable ?
Which of the a, b, c, d answers is right?
Is the only way to waste space doing some padding like I did before title_screen_tilemap_attr?

Offline

 

#2 2022-05-22 10:18:35

nitro2k01
Administrator
Registered: 2008-02-22
Posts: 242

Re: Section Fragments

a) is correct. title_screen_tile_data_vram0, or more generally the start of the section, is the only thing that's being aligned by the align argument to a section. Yes, currently, the only way to achieve this together with your other requirements (floating bank etc) is to use padding.

To make your life easier, you can use the assert keyword to check the alignment at link time. It will then abort the assembly process if the pieces go out of alignment.

Code:

SECTION FRAGMENT "TITLE_SCREEN ROMX", ROMX, ALIGN[ 4 ] ; 16 byte aligned
 
title_screen_tile_data_vram0::
INCBIN "test_output/title_screen_data.bin", 760, 2528
.end

ASSERT ASSERT ((@) % 16)==0

title_screen_tilemap::
INCBIN "test_output/title_screen_data.bin", 40, 360
.end
 
db 0, 0, 0, 0, 0, 0, 0, 0

ASSERT ASSERT ((@) % 16)==0
 
title_screen_tilemap_attr::
INCBIN "test_output/title_screen_data.bin", 400, 360
.end

Starting in newer versions of RGBDS (v0.5.0+) there's an align keyword that you can use anywhere in a section. It doesn't insert padding though. Instead, it tries to align the whole section around the place of the align statement. But you can use still use it in this case for a similar effect to the assert above. If the data is misaligned, the assembly fails.

Code:

SECTION FRAGMENT "TITLE_SCREEN ROMX", ROMX, ALIGN[ 4 ] ; 16 byte aligned
 
title_screen_tile_data_vram0::
INCBIN "test_output/title_screen_data.bin", 760, 2528
.end

ALIGN 4

title_screen_tilemap::
INCBIN "test_output/title_screen_data.bin", 40, 360
.end
 
db 0, 0, 0, 0, 0, 0, 0, 0

ALIGN 4
 
title_screen_tilemap_attr::
INCBIN "test_output/title_screen_data.bin", 400, 360
.end

However, I have to question the need for alignment for title_screen_tilemap and title_screen_tilemap_attr. I presume those are used to fill up one screen with 20x18 tilemap entries. Where does the 16 byte alignment come from in this case? I can't think of a way that (efficient) code would both use 16 byte alignment and copy 20 bytes at a time.

This makes sense for the tile data, but then you can simply put all your tiles in one place and they will be naturally aligned because each tile is 16 bytes big. (And you can use an assert as above to confirm that you didn't enter the size incorrectly.

Furthermore, even if you're doing bit math that requires alignment, it would be recommended to base the math on the destination address and/or length counter if possible. This way you can use ld A,[HL+] for the read which reduces the need for alignment of the source data.


Blog: Gameboy Genius
"A journey of a thousand miles begins with one small step"
Old Chinese Proverb

Offline

 

#3 2022-05-22 11:21:28

Azenris
Member
Registered: 2022-03-30
Posts: 12

Re: Section Fragments

Thankyou for the information nitro2k01 !

Yea... I seem to have miss-thought about the screen tilemap stuff. There is no reason for me to align that, only the tiledata.
However it is interesting to see the assert stuff used for the addressing ty!
Ty for clarification of the aligning for section fragments.

Ty, ty ! :]

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2005 Rickard Andersson