Page 1 of 1

Some newbie questions

Posted: Wed Sep 11, 2013 3:50 pm
by Arrovs
Hello. Im new at Genesis programming world, but im programmed on C for some while.

I did some trainings on SGDK, but now i want some help and opinions as documentation for this is raw.

First what is best way for memory allocating?
Second if i dont need redraw things every frame then how i can get rid from duplicates at old positions when moving things like text to new place?
Third - can i get dynamic char length or i need make string struct for that?

Thanks already. You here doing really good job.

Posted: Wed Sep 11, 2013 8:15 pm
by Stef
Hello Arrovs,

Glad to see you have some interests in Sega Genesis programming :)
SGDK provide some dynamic memory allocation method (MEM_alloc(..) and MEM_free(..)) but honestly it is rare that you need that on Sega Genesis where you can almost time hardcode every variables (static allocation).
About the screen redraw stuff, i don't understand as by default what you draw to screen stay on screen. You have to understand how the the Genesis graphics sub system work first: 2 background plan and sprites capabilities.
For the string, you have to deal with the basic C string methods, even less are they are not all implemented :-/ So yeah, basic static allocation... again that type of old hardware does not play well with dynamic allocation but still that stay possible if you really want it !

Posted: Thu Sep 12, 2013 10:44 am
by Arrovs
I really just want try Genesis possibilities.
And after then i will try static allocation as im never did that kind of thing.

About drawing things in 3 layers - im readed much about that because thats all about forum members speaks here. But all of them speaks about drawing things and fading things. Ou and of course scrolling planes. But i just want to draw text on screen. And then after pressing some keys move it to another place and clear previous place from text. Or i should move text into sprites layer - if its possible? Because sprite moving seems quite easier.

Edited: And it seems didnt like malloc and MEM_alloc - is there any place i can see some info about it?

Posted: Thu Sep 12, 2013 11:12 pm
by Stef
You can of course write text to screen and clear it, rewrite it elsewhere with these methods :

Code: Select all

/**
 * \brief
 *      Draw text.
 *
 * \param str
 *      String to draw.
 * \param x
 *      X position (in tile).
 * \param y
 *      y position (in tile).
 *
 *  This method uses VDP_PLAN_A to draw the text.<br/>
 *  See VDP_setTextPalette() and VDP_setTextPriority().
 */
void VDP_drawText(const char *str, u16 x, u16 y);

/**
 * \brief
 *      Clear text.
 *
 * \param x
 *      X position (in tile).
 * \param y
 *      y position (in tile).
 * \param w
 *      width to clear (in tile).
 *
 *  This method uses VDP_PLAN_A to draw/clear the text.
 */
void VDP_clearText(u16 x, u16 y, u16 w);

/**
 * \brief
 *      Clear a complete line of text.
 *
 * \param y
 *      y position (in tile).
 *
 *  This method uses VDP_PLAN_A to draw/clear the text.
 */
void VDP_clearTextLine(u16 y);
As you can see the method declaration (in the .h file) also contains the documentation. You can browse it from the "doc" folder of your SGDK installation. It's a doxigen documentation and so a bit raw but at least you can browse the complete lite of methods. Just open the "doc/html/files.html" for instance and you can see all include files and related topic (memory.h for memory stuff).

For the text you can also use sprites of course, it's better if you want to make smooth and fast movements for your text ;) If you just want to write text, use the default VDP_drawText(..) methods is ok :)