Raster Effect with Gendev ( SGDK)

SGDK only sub forum

Moderator: Stef

bastien
Very interested
Posts: 208
Joined: Mon Jun 25, 2007 7:19 pm
Location: Besançon,France
Contact:

Raster Effect with Gendev ( SGDK)

Post by bastien » Sat Sep 03, 2011 7:01 am

Hi all,
i have made some cool demo with Gendev ( PCM , Sprite , joypad , etc.. ).
But i'm looking a way to apply a Raster effect in picture with this SDK.
maybe someone have a source exemple ?

Thanks a lot :)
Last edited by bastien on Sun Sep 04, 2011 7:21 am, edited 1 time in total.

andlabs
Very interested
Posts: 62
Joined: Sat Aug 08, 2009 4:44 pm

Post by andlabs » Sat Sep 03, 2011 5:37 pm

What kind of raster effect(s) are you looking to do?

bastien
Very interested
Posts: 208
Joined: Mon Jun 25, 2007 7:19 pm
Location: Besançon,France
Contact:

Post by bastien » Sat Sep 03, 2011 6:15 pm

maybe the same thing as Jurassick Park 2 The Lost World Title screen.
thanks for reply :wink:

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Post by Stef » Sat Sep 03, 2011 8:27 pm

You can also nice effect without even using raster effect :

http://www.youtube.com/watch?v=FcmSxIUbVLE

This video show a nice use of both line horizontal scroll and 2 cells vertical scroll :) You can simulate a rotation effect (with a limited angle amplitude though). You can even improve the 2 cells vertical resolution by combining 2 plans and so get cell based vertical scroll.

bastien
Very interested
Posts: 208
Joined: Mon Jun 25, 2007 7:19 pm
Location: Besançon,France
Contact:

Post by bastien » Sun Sep 04, 2011 7:20 am

yeah it's also a good idea stef,
but i look if someone give an open code with a part of Raster Effect with gendev ( SGDK).

LocalH
Very interested
Posts: 152
Joined: Tue Dec 19, 2006 5:04 pm

Post by LocalH » Mon Sep 05, 2011 1:06 am

You can also "stretch" vertically (or indeed theoretically display any scanline of the image although I haven't tested it) by setting full screen vscroll and stuffing values into the single VSRAM address used for full scroll on every scanline. My First Time Out demo uses full screen scroll in a simpler version of this to do the logo bouncing, text bouncing, and solid scroller, and breaks on crappy emulators :)

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Post by Stef » Mon Sep 05, 2011 9:35 am

Not Sure you'll find any existing examples with SGDK ;)
As LocalH mentionned, one of the most common raster effect is to change the VScroll value during H blank so you can somewhat deform the image vertically. You use the H blank callback in SGDK and do your test :)

Code: Select all

u32 vscroll;
...

void myHBlankFunction()
{
   // modify V scroll value
   VDP_setVerticalScroll(APLAN, 0, vscroll >> 8);
   vscroll += 0x30;
}
...

void main() {
   ...
  // define method to call on HInt / HBlank
  setHBlankCallback(myHBlankFunction);
  // want H Int on each scanline
  VDP_setHIntCounter(1);
  // enable H Int
  VDP_setHInterrupt(1);

  vscroll = 0;
  ...

  while(1);
}
Last edited by Stef on Tue Sep 06, 2011 12:00 pm, edited 1 time in total.

bastien
Very interested
Posts: 208
Joined: Mon Jun 25, 2007 7:19 pm
Location: Besançon,France
Contact:

Post by bastien » Mon Sep 05, 2011 4:42 pm

Thanks for this code, but i have tested it with a simple code exemple and it's do nothing...
maybe i have missed something ?

Code: Select all

#include "genesis.h"
#include "prelude.h"

extern u16 title_pal[];
extern u32 title_tiles[];
u32 vscroll;


void intro()
{
    VDP_resetScreen();
    VDP_setPalette(0, (u16 *) title_pal);
    VDP_doVRamDMA( (u32) title_tiles, 32, 21760);
    VDP_fillTileMapRectInc(BPLAN, TILE_ATTR(0, 0, 0, 0) + (32/32),0,0,320/8,136/8);

    startPlay_4PCM(prelude, sizeof(prelude), AUDIO_PCM_CH1, 1);//
}


void myHBlankFunction()
{

    // modify V scroll value
    VDP_setVerticalScroll(APLAN, 0, vscroll >> 8);
    vscroll += 0x30;
}


int main()
{

    intro();

    // define method to call on HInt / HBlank
    setHBlankCallback(myHBlankFunction);
    // want H Int on each scanline
    VDP_setHIntCounter(1);
    // enable H Int
    VDP_setHInterrupt(1);

    vscroll = 0;


    while(1)
    {
        VDP_waitVSync();
    }
    return 0;

}
i have removed the void before "setHBlankCallback(myHBlankFunction);" for deleted a warning in compliation message.

sega16
Very interested
Posts: 251
Joined: Sat Jan 29, 2011 3:16 pm
Location: U.S.A.

Post by sega16 » Mon Sep 05, 2011 10:05 pm

I always wanted to have a line double to get a 320x122 instead of 320x224 so I came up with this code:

Code: Select all

    vu16 *pw;
    vu32 *pl;
    u16 addr;
    for (counter = 0; counter < 224; counter+=2)
    {
        pw = (u16 *) GFX_DATA_PORT;
        pl = (u32 *) GFX_CTRL_PORT;
        addr=counter+1;//lets say counter is zero this will tell it to pick line 1 to become line zero in the end
    *pl = GFX_WRITE_VSRAM_ADDR(addr);
    *pw = counter;
    }
But for some reason it just makes the screen blank instead of double the lines.
Note:It is NOT called on the hblank
Also I just edited VDP_setVerticalScroll

LocalH
Very interested
Posts: 152
Joined: Tue Dec 19, 2006 5:04 pm

Post by LocalH » Tue Sep 06, 2011 4:11 am

Increasing scroll values scrolls UP and RIGHT. Decreasing them scrolls DOWN and LEFT. If your values are getting written to VSRAM properly, then you're scrolling lines up instead of down. Each scanline's value needs to basically be the offset between the actual scanline, and the scanline to be displayed, subtracted from $0800 (since you have 11 bits of vertical scroll). So, for example, let's go from the basis that a scroll of $0000 will display every scanline where it should be displayed. Let's say that you want lines 0 and 1 of the addressable screen to show line 0, and lines 2 and 3 should display line 1. Line 0's scroll value should be $0000 as expected. Line 1 would normally display line 1, since you want to display line 0 there you need to scroll line 1 down by one line, and since you scroll down by decreasing the value, you would need a scroll value of $07FF for line 1. For line 2 to display line 1, you again need a scroll value of $07FF. To display line 1 on line 3, you'll need to scroll it down another line, requiring you to use $07FE. Perhaps sometime I should figure out a way to explain this better. =P

sega16
Very interested
Posts: 251
Joined: Sat Jan 29, 2011 3:16 pm
Location: U.S.A.

Post by sega16 » Wed Sep 07, 2011 1:01 am

Ok localH I read your post re-read it and re-read it again and still don't seem to get it from what I understand
Line0=0
line1=7FF
line2=7FF
line3=7FE
line4=7FE
line5=7FD
line6=7FD
and so following that I did this:
But it did not work right.What is the problem?

Code: Select all

const u32 vscroll_data[] =
{
//line 0
0,
//line 1
2047,
//line 1 realy 2
2047,
//line 3
2046,
//line 3
2046,
//line 5
2045,
//line 5
2045,
//line 7
2044,
//line 7
2044,
//line 9
2043,
//line 9
2043,
//line 11
2042,
//line 11
2042,
//line 13
2041,
//line 13
2041,
//line 15
2040,
//line 15
2040,
//line 17
2039,
//line 17
2039,
//line 19
2038,
//line 19
2038,
//line 21
2037,
//line 21
2037,
//line 23
2036,
//line 23
2036,
//line 25
2035,
//line 25
2035,
//line 27
2034,
//line 27
2034,
//line 29
2033,
//line 29
2033,
//line 31
2032,
//line 31
2032,
//line 33
2031,
//line 33
2031,
//line 35
2030,
//line 35
2030,
//line 37
2029,
//line 37
2029,
//line 39
2028,
//line 39
2028,
//line 41
2027,
//line 41
2027,
//line 43
2026,
//line 43
2026,
//line 45
2025,
//line 45
2025,
//line 47
2024,
//line 47
2024,
//line 49
2023,
//line 49
2023,
//line 51
2022,
//line 51
2022,
//line 53
2021,
//line 53
2021,
//line 55
2020,
//line 55
2020,
//line 57
2019,
//line 57
2019,
//line 59
2018,
//line 59
2018,
//line 61
2017,
//line 61
2017,
//line 63
2016,
//line 63
2016,
//line 65
2015,
//line 65
2015,
//line 67
2014,
//line 67
2014,
//line 69
2013,
//line 69
2013,
//line 71
2012,
//line 71
2012,
//line 73
2011,
//line 73
2011,
//line 75
2010,
//line 75
2010,
//line 77
2009,
//line 77
2009,
//line 79
2008,
//line 79
2008,
//line 81
2007,
//line 81
2007,
//line 83
2006,
//line 83
2006,
//line 85
2005,
//line 85
2005,
//line 87
2004,
//line 87
2004,
//line 89
2003,
//line 89
2003,
//line 91
2002,
//line 91
2002,
//line 93
2001,
//line 93
2001,
//line 95
2000,
//line 95
2000,
//line 97
1999,
//line 97
1999,
//line 99
1998,
//line 99
1998,
//line 101
1997,
//line 101
1997,
//line 103
1996,
//line 103
1996,
//line 105
1995,
//line 105
1995,
//line 107
1994,
//line 107
1994,
//line 109
1993,
//line 109
1993,
//line 111
1992,
//line 111
1992
};
    for (counter = 1; counter <= 112; counter++)
    {
    pw = (u16 *) GFX_DATA_PORT;
    pl = (u32 *) GFX_CTRL_PORT;
    addr=counter;
    *pl = GFX_WRITE_VSRAM_ADDR(addr);
    *pw = vscroll_data[counter];
    }

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Post by Stef » Wed Sep 07, 2011 9:10 am

I think you're mixing up scroll stuff with VScroll.
The VScroll table contains data for Vertical Scroll which can be defined to work on the entire plan (then only the first entry of the table is used) or 2 tiles column based (so each entry correspond to a column tile pair). But you have to understand we speak about columns and not scanlines as you're trying to do. To do the effect you are describing you have to change the vscroll value at each scanline (and so use the H Int callback), exactly as the code i given to Bastien.
Unfortunately the code doesn't seem to work right, but it's probably a stupid mistake i made somewhere...

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Post by Stef » Wed Sep 07, 2011 9:18 am

bastien wrote:Thanks for this code, but i have tested it with a simple code exemple and it's do nothing...
maybe i have missed something ?

Code: Select all

#include "genesis.h"
#include "prelude.h"

....
i have removed the void before "setHBlankCallback(myHBlankFunction);" for deleted a warning in compliation message.
Yep, the void what i stupid typo i left when i copied the function name from the header file :p
Right now, i don't see what's wrong in your code, i've to test it myself...

Edit : Got it ! In your code you're filling your image data in BPLAN then modifying vertical scroll value of APLAN ;)

bastien
Very interested
Posts: 208
Joined: Mon Jun 25, 2007 7:19 pm
Location: Besançon,France
Contact:

Post by bastien » Wed Sep 07, 2011 3:48 pm

Thanks you very much Stef it's works perfectly now :twisted:

sega16
Very interested
Posts: 251
Joined: Sat Jan 29, 2011 3:16 pm
Location: U.S.A.

Post by sega16 » Thu Sep 08, 2011 12:04 am

Using this code it will double SOME lines but not all.I believe the reason for this is because the code is not fast enough but what could I do to make it better?

Code: Select all

void myHBlankFunction()
{
    if (line == 224)
    {
        line=0;
        vscroll=0x800;
        the_scroll=0;
    }
    if (the_scroll == 1)
    {
        the_scroll=0;
        vscroll--;
    }
    else
    {
        the_scroll=1;
    }
   //VDP_setVerticalScroll(APLAN, 0, 0x07A0);
    vu16 *pw;
    vu32 *pl;
    //u16 addr;

    /* Point to vdp port */
    pw = (u16 *) GFX_DATA_PORT;
    pl = (u32 *) GFX_CTRL_PORT;

    //addr = (cell & 0x1F) * 4;
    //if (plan == BPLAN) addr += 2;

    *pl = GFX_WRITE_VSRAM_ADDR(/*addr*/0);
    //*pw = vscroll;
    *pw = vscroll;
    line++;
}

Post Reply