Reading current sprites as VRAM?

Post Reply
thetooth
Posts: 3
Joined: Thu Jan 21, 2010 4:04 am

Reading current sprites as VRAM?

Post by thetooth » Thu Jan 21, 2010 4:11 am

Hi i am building a drawing like app that allows you to draw sprites on screen and apply effects(glichs) to them and after the OAM is exosted have it draw the on screen sprites to the background layer so the user continues to draw over the top.

the problem is i have no idea how to read the sprite data... after quickly scrolling through video.h i assumed SPRITE_GFX_SUB would contain a pixel array like VRAM and simply copy the data a cross like this:

Code: Select all

for(i = 0; i < 256 * 192; i++){
	VRAM_A[i] = SPRITE_GFX_SUB[i];
}
This doesn't seem to work at all and I've tried a few variations but still nothing. any help?

thetooth
Posts: 3
Joined: Thu Jan 21, 2010 4:04 am

Re: Reading current sprites as VRAM?

Post by thetooth » Thu Jan 21, 2010 7:58 am

Heres the code: http://kodo.ameoto.com/k/0296185170
If any one can see whats wrong tell me...

StevenH
Posts: 133
Joined: Sun Feb 22, 2009 7:59 pm

Re: Reading current sprites as VRAM?

Post by StevenH » Thu Jan 21, 2010 8:13 am

OK, a quick and (possibly very) dirty overview of how the sprite video memory is set out.

Sprite video ram, like all video ram, is accessed in u16 sized chunks (you can access it as a u32 or u64 as well but for this post I will stick to u16 which is what the define is)

Depending on how your memory is layed out will affect how you actually access the sprite data.
  • For the 2D mapping modes you have a 256 pixel x 256 pixel grid split into chunks that are 8x8. A 16x16 sprite in this mode will look as it should if drawn on paper. Think of the 2D mode as a sprite sheet put directly into the sprite video memory.
  • For 1D mapping you have a long line of 8x8 pixel boxes. A 16x16 sprite will be stored as consequtive 8x8 chunks - 0,1,2,3. This mode would be likened to a file.
Example spirte design used in the following examples:
0 = Transparent colour
1 = Red colour

Code: Select all

0 0 1 1 1 1 0 0 
0 1 0 0 0 0 1 0 
1 0 1 0 0 1 0 1 
1 0 0 0 0 0 0 1 
1 0 0 0 0 0 0 1 
1 0 1 1 1 1 0 1 
0 1 0 0 0 0 1 0 
0 0 1 1 1 1 0 0 
For 16 colour sprites:
The way the data is stored is in the 4 nibbles of the u16, in reverse order. So if you stored 0x01234 in a memory location you are actually putting on the screen the colours 3 2 1 0.
So taking the example sprite from above you would store the following data into the sprite video memory at the location that your sprite should be placed at.

Code: Select all

0x1100, 0x0011,
0x0010, 0x0100,
0x0101, 0x1010,
0x0001, 0x1000,
0x0001, 0x1000,
0x1101, 0x1011,
0x0010, 0x0100,
0x1100, 0x0011
For 256 colour sprites:
As with the 16 colour sprites the data is stored in reverse, each byte of the u16 is 1 colour but this time a single block takes up 64 bytes of memory. So if you stored 0x01234 in a memory location you are actually putting on the screen the colours 0x23 0x01.
So taking the example sprite from above you would store the following data into the sprite video memory at the location that your sprite should be placed at.

Code: Select all

0x0000, 0x0101, 0x0101, 0x0000, 
0x0100, 0x0000, 0x0000, 0x0001, 
0x0001, 0x0001, 0x0100, 0x0100, 
0x0001, 0x0000, 0x0000, 0x0100, 
0x0001, 0x0000, 0x0000, 0x0100, 
0x0001, 0x0101, 0x0101, 0x0100, 
0x0100, 0x0000, 0x0000, 0x0001, 
0x0000, 0x0101, 0x0101, 0x0000, 
For truecolour sprites, each pixel is stored in the video memory in a direct 1:1 relation. I'm not up to speed with this sprite mode as I've not looked at it fully to understand it, but it does eat up the memory allocation for sprite banks very fast and IMHO should not be used, unless you really need a true colour sprite...

I did say it was a quick and dirty way to how sprites worked :lol:

Oh don't forget that the 16 and 256 colour sprites are broken up into blocks of 8x8, so you will have to convert from screen co-ords to sprite co-ords first. Basically if you know how to convert screen to tile co-ords for a 2D square tile map editor, then you can work out what sprite tile you are working on.

I'm not sure exactly what your attempting to do, but the biggest sprite you can work on at any time is a 64 x 64 sprite, so if you are wanting to draw on the sprites you are going to have to split the screen into blocks of 64x64 and then down into the 8x8 tiles of the sprite before setting the actual colours, using bitmasks for the relivant pixel.

thetooth
Posts: 3
Joined: Thu Jan 21, 2010 4:04 am

Re: Reading current sprites as VRAM?

Post by thetooth » Thu Jan 21, 2010 9:04 am

...lol maybe i should have a walk outside for awhile and think of this. i only started learning C 2months ago an its taken this long to start drawing stuff so its all a matter of time before this makes any sense.

ty for your help, i do get what you mean i know how to do it(relatively) but I've had enough for one day :P

User avatar
vuurrobin
Posts: 219
Joined: Fri Jul 11, 2008 8:49 pm
Location: The Netherlands
Contact:

Re: Reading current sprites as VRAM?

Post by vuurrobin » Thu Jan 21, 2010 12:42 pm

I think using 2 or 3 backgrounds is better for an drawing app than using sprites. less problems with moving the data, aligning the sprites etc.

Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests