Page 1 of 1

New in SGDK

Posted: Fri Apr 11, 2014 11:16 pm
by Mills
Hi everybody, I hope this thread is usefull and you can help me :).

Some days ago i started to make little roms with SGDK, (genesis/MD looks like a powerfull device, a lot of maths power).

1- Making waves with bkg

I tried to achieve a wave effect but i don't know how to do it, or control it...

This code moves a plane using a sine function:

Code: Select all

  while(1){

   if (X > 1024) X = 0;

   VDP_setHorizontalScroll(BPLAN,sinFix16(X));
			
   X+=4;
			
  }
Now i want to reset the X value every time the screen goes to VBLANK. i need some function to do something like:

"if (screen is in vblank) X = 0;"

I'd also like to know if there is a "scan line counter" and how to use it. and maybe there is a better way to make waves with the planes.

2- Noob C question

I've got a bunch of planes loaded in a rom, they are called "plane1, plane2..."

Now i want to draw them to make a "video", this code does not work, but it will explain what i want to do:

Code: Select all

//imagine i loaded 9 planes (plane1, plane2...)

    while(1){

	    if (i == 10) i = 1;

            VDP_drawImageEx(BPLAN, &plane(i), TILE_ATTR_FULL(PAL0,0,0,0,ind),0,0,0,1);
            ind += plane(i).tileset->numTile;
			
	    i++;

	    VDP_waitVSync();
   }
How do i have to write the "plane(i)" part, so that it loads plane1 if i = 1?.

3- Drawing 3D objects over a image

I also got a 3d object rotating and everything :). Is it possible to draw the objects in plane A over an image loaded in plane B?


4- 22050 Khz sound

I used Deflemask to create some music, then realized i could insert 22050 Khz samples for the drums, created a vgm, compiled a rom with it...
The rom worked well and played the samples in an emulator.. Can the real hardware play that samples at 22050 Khz?


Thanks a lot!


I attach some pictutes of what i got to work :).

Out of control waves:

Image

3D icosahedron:

Image

512x512 seamless images:

Image

Re: New in SGDK

Posted: Sat Apr 12, 2014 10:08 am
by Stef
Hi Mills,

Welcome on board :)
You started by saying that genesis has lot of maths power... actually it has some for a 25 yo system but still quite limited ;)
I will try to answer some of your SGDK related questions.
1- Making waves with bkg

...

Now i want to reset the X value every time the screen goes to VBLANK. i need some function to do something like:

"if (screen is in vblank) X = 0;"

I'd also like to know if there is a "scan line counter" and how to use it. and maybe there is a better way to make waves with the planes.
The simplest way of doing it is to use the hardware horizontal line scrolling. First you need to set the VDP in this mode :

Code: Select all

VDP_setScrollingMode(HSCROLL_LINE, VSCROLL_PLANE);
then you need to set the scroll values for each line :

Code: Select all

while(TRUE)
{
  for(i = 0; i < VDP_getScreenHeight(); i++)
    hscroll[i] = sinFix16((offset + (i << 2)) & 1023);

  // wait for vblank
  VDP_waitVSync();

  // set horizontal scroll
  VDP_setHorizontalScrollLine(PLAN_B, 0, hscroll, VDP_getScreenHeight(), FALSE);

  // move offset in sinus table
  offset += 8;
}
and that should work.
2- Noob C question

I've got a bunch of planes loaded in a rom, they are called "plane1, plane2..."

//imagine i loaded 9 planes (plane1, plane2...)

...

How do i have to write the "plane(i)" part, so that it loads plane1 if i = 1?.
Oh it was almost correct : &place instead of &plane(i)
You should take care about the ind value also as it will go outside vram at some point. You can just do :

Code: Select all

  numTile = plane[i].tileset->numTile;
  if ((ind + numTile) > TILE_USERMAXINDEX)
    ind = TILE_USERINDEX;
  VDP_drawImageEx(BPLAN, &plane[i], TILE_ATTR_FULL(PAL0,0,0,0,ind),0,0,0,1); 
  ind += numTile;
3- Drawing 3D objects over a image

I also got a 3d object rotating and everything :). Is it possible to draw the objects in plane A over an image loaded in plane B?
Definitely possible if you don't use the double buffering in VRAM (eat too much space). For that just use FALSE (or 0) a first parameter on the BMP_init(..) method.
4- 22050 Khz sound

I used Deflemask to create some music, then realized i could insert 22050 Khz samples for the drums, created a vgm, compiled a rom with it...
The rom worked well and played the samples in an emulator.. Can the real hardware play that samples at 22050 Khz?
Nope, the included VGM driver only play 8000 Hz sample so you have to convert it first. Also you have to take care about not doing too much DMA or locking the main 68000 bus if you want to keep goos sampling quality (the Z80 need to access the main 68000 bus to play it, it you lock it with DMA or 68000 VDP access in active period, the sample playback is degraded).

Your pictures show that you already got some nice stuff to work, as the sinus wave ??

Re: New in SGDK

Posted: Sat Apr 12, 2014 12:05 pm
by Mills
Stef wrote:Hi Mills,

Welcome on board :)
You started by saying that genesis has lot of maths power... actually it has some for a 25 yo system but still quite limited ;)
I will try to answer some of your SGDK questions !
Thanks!.

Drwaing the 3d object and the bkg image worked, with wrong palettes and tiles.. but worked, i'll play with the clean options and palettes.

The plane code did not work, it says: "plane" undeclared.

The VDP_setHorizontalScrollLine function .. i don't really understand it LOL . It always complains about parameters.

The good thing is i got it working this way it did not throw any error:

Code: Select all

        for(i = 0; i < VDP_getScreenHeight(); i++) 
        hscroll[i] = sinFix16((offset + (i << 2)) & 1023); 
        // wait for vblank 
        VDP_waitVSync(); 
        // set horizontal scroll 
        VDP_setHorizontalScrollLine(VDP_PLAN_B, 0, hscroll,VDP_getScreenHeight(), 0); 
        // move offset in sinus table 
        offset += 8;
but it only moves half the lines, making a cool transparency effect. How do i move all the lines? Maybe c code is too slow to move line by line?

Re: New in SGDK

Posted: Sun Apr 20, 2014 1:15 pm
by Stef
Mills wrote: The plane code did not work, it says: "plane" undeclared.


Oh i though you already have them ! Actually i guess you have severals images, so you can do as specified in this topic :

viewtopic.php?t=1669&postdays=0&postorder=asc&start=75

You can use a table to references your different images then load them in a loop.


The VDP_setHorizontalScrollLine function .. i don't really understand it LOL . It always complains about parameters.

The good thing is i got it working this way it did not throw any error:

Code: Select all

        for(i = 0; i < VDP_getScreenHeight(); i++) 
        hscroll[i] = sinFix16((offset + (i << 2)) & 1023); 
        // wait for vblank 
        VDP_waitVSync(); 
        // set horizontal scroll 
        VDP_setHorizontalScrollLine(VDP_PLAN_B, 0, hscroll,VDP_getScreenHeight(), 0); 
        // move offset in sinus table 
        offset += 8;
Oh yeah sorry i made a copy / paste mistake in my original code, your is the correct one !
but it only moves half the lines, making a cool transparency effect. How do i move all the lines? Maybe c code is too slow to move line by line?
You mean it moves only every other lines ??
Well it should not, except if your plan are somehow interlaced.
What it does if you add the following :

Code: Select all

VDP_setHorizontalScrollLine(VDP_PLAN_A, 0, hscroll,VDP_getScreenHeight(), 0); 

Re: New in SGDK

Posted: Sun Apr 20, 2014 7:33 pm
by Mills
Stef wrote:
Mills wrote: The plane code did not work, it says: "plane" undeclared.


Oh i though you already have them ! Actually i guess you have severals images, so you can do as specified in this topic :

viewtopic.php?t=1669&postdays=0&postorder=asc&start=75

You can use a table to references your different images then load them in a loop.


The VDP_setHorizontalScrollLine function .. i don't really understand it LOL . It always complains about parameters.

The good thing is i got it working this way it did not throw any error:

Code: Select all

        for(i = 0; i < VDP_getScreenHeight(); i++) 
        hscroll[i] = sinFix16((offset + (i << 2)) & 1023); 
        // wait for vblank 
        VDP_waitVSync(); 
        // set horizontal scroll 
        VDP_setHorizontalScrollLine(VDP_PLAN_B, 0, hscroll,VDP_getScreenHeight(), 0); 
        // move offset in sinus table 
        offset += 8;
Oh yeah sorry i made a copy / paste mistake in my original code, your is the correct one !
but it only moves half the lines, making a cool transparency effect. How do i move all the lines? Maybe c code is too slow to move line by line?
You mean it moves only every other lines ??
Well it should not, except if your plan are somehow interlaced.
What it does if you add the following :

Code: Select all

VDP_setHorizontalScrollLine(VDP_PLAN_A, 0, hscroll,VDP_getScreenHeight(), 0); 
Thanks, the scroll problem was solved, I set the hcroll variable as u16, :).

I have more questions about SGDK, i'll ask them in SGDK subforum.