Page 1 of 1

SGDK usage, need help understanding some parts

Posted: Sat May 25, 2013 9:20 pm
by Helghast
Hi guys,

I've been starting into development for Megadrive lately, and have been reading loads of documents and articles to get to grips with how this beast works.
I am getting at a point, where I have questions, but nowhere to ask, so I figured people here might be able to point me into the right directions.

I am having issues trying to understand how palette data and VRAM data combine and work together.

I have 2 images which I want to display, which I both am loading into VRAM using VDP_loadTileData (I have converted my images using GenRes), and am loading the palette data into different pallete's each.

I think I'm right by saying all image data (tiles) get loaded into 1 big "image" on VRAM.

Now when I display these images, how can I define the alpha channel for each image (or tell one not to use alpha at all), or is alpha only reserved for Sprites?

I tried to load tile data and sprites together before (I had no issue displaying them separately), but they seem to get corrupted when I attempt this. How do I load a certain Tile from VRAM?
I see some examples (for instance the sonic animation) do spritename>>8, now my programming skills don't go far enough to know what that exactly does, I believe it's bitshifting, but can someone explain easily what this does behind the scenes?


I am sorry for all the amount of questions in 1 post, I'm just trying to learn and experiment with this, no doubt I'll be posting more stuff later (probably even to get it to run on actual hardware, and yes, I'm aware of the elements required for that).

I hope someone here will take some time to help me, I am also available on twitter and Skype (tw: @rawrDennis, sk: kak-hoofd)

kind regards,
Dennis

Posted: Sun May 26, 2013 3:34 am
by TmEE co.(TM)
The VDP takes tile data from VRAM according to the tilemap and sprite list. SPrite list and tilemap both contain 2 bits that determine which of the 4 palettes this tile will use. Each tile is 8x8 block that can have 16 values per pixel. Value of zero is always transparency.
Image is generated on the fly, line by line, there is never a full composited image stored anywhere.

Posted: Mon May 27, 2013 1:41 am
by r57shell
Use this DOC:
https://code.google.com/p/genplus-gx/so ... p.txt?r=31
This is MORE than enough, as I think.

Transparent color = index 0 in each palette of CRAM.
You can imagine process like this:
1) Fill background with backdrop color.
2) Draw Plane A over it
3) Draw Plane B over it
4) Draw sprites
(not taking into account the priority flags)
Plane draws according to Plane Map. Plane Map is array (table) of word in VRAM. word in Plane map = tile_index + flags. Flags like: priority, horizontal flip, vertical flip, palette. Location of array selected by specific register in VDP. VRAM = just RAM in VDP, so there can be word values.

Tile size 32 byte. Tiles aligned by 32 byte. Tiles displayed by indexes. So it's normal to bitshift by 5.
Palette id location: 13,14 bits in Plane Map word. So it's normal to bitshift palette id by 13. Or bitshift by 5 and write high byte.

Code: Select all

C++ | M68k| description 
>>  | asr | arithmetic shift right
<<  | asl | arithmetic shift left
|   | or  | bitwise or
&   | and | bitwise and
^   | eor | bitwise xor
~   | not | bitwise not
You can see VDP Ram in some emulators, such as my modification of gens rerecording 11b (for Windows):
http://elektropage.ru/load/0-0-0-1-20
Tools -> VDP Ram
You can see boxes of sprites, if you turn on: Graphics->Layers->Sprites->Sprites Boxing
Emulation quality less than in MESS or RetroArch... But, I have good (for me) Debug! :)

Posted: Mon May 27, 2013 9:24 am
by Nemesis
If your system is up to the task, you can also use my emulator "Exodus" for debugging. It'll give you realtime views into the VRAM and CRAM so you can see what's going on, and it has a bunch of other debug features such as sprite boxing, display regions, layer removal, sprite debugging, etc.

Posted: Tue May 28, 2013 4:39 pm
by Helghast
Hey guys, I think I am grasping all this so far!
Having difficulties getting to load multiple images now though.
Trying to load 2 background images (as BITMAP), but this seems to go horribly wrong.

cant figure out how the index Works. I load one image tiles into memory, and displaying is all fine. Loading the second one seems to graphically explode, is there a flag which calculates how many tiles have been loaded, and appends after that?
or is there a magic way I need to do that myself?

Also, what tools do you use to create a palette? Paint always outputs the same pallette It seems :/

Regards, D.

Posted: Tue May 28, 2013 4:41 pm
by Helghast
Nemesis wrote:If your system is up to the task, you can also use my emulator "Exodus" for debugging. It'll give you realtime views into the VRAM and CRAM so you can see what's going on, and it has a bunch of other debug features such as sprite boxing, display regions, layer removal, sprite debugging, etc.
was using Gens Kmod, with which I managed to do all that too (helped me understand very well!)

Thanks!