Get Tile Index of background specific position (X, Y)
Moderator: Stef
-
- Very interested
- Posts: 118
- Joined: Mon Feb 19, 2018 7:31 pm
Get Tile Index of background specific position (X, Y)
Hi!
Can someone help me?
I need to know tile index in specific position of background.
Thank you!
Can someone help me?
I need to know tile index in specific position of background.
Thank you!
-
- Interested
- Posts: 17
- Joined: Sat Oct 13, 2018 10:08 pm
Re: Get Tile Index of background specific position (X, Y)
I just ran into the same problem.
SGDK does have a VDP_setTileMapXY() function in SGDK/src/vdp_tile.c. You can modify the code so that it reads from VRAM, something like:
Then you get the index by masking out the attributes:
SGDK does have a VDP_setTileMapXY() function in SGDK/src/vdp_tile.c. You can modify the code so that it reads from VRAM, something like:
Code: Select all
u16 VDP_getTileMapXY(VDPPlane plane, u16 x, u16 y)
{
vu32* const plctrl = (u32*)GFX_CTRL_PORT;
vu16* const pwdata = (u16*)GFX_DATA_PORT;
const u16 addr = VDP_getPlaneAddress(plane, x, y);
*plctrl = GFX_READ_VRAM_ADDR((u32)addr);
return *pwdata;
}
Code: Select all
u16 tile = VDP_getTileMapXY(...);
u16 tileIndex = tile & ~TILE_ATTR_MASK;
-
- Very interested
- Posts: 118
- Joined: Mon Feb 19, 2018 7:31 pm
Re: Get Tile Index of background specific position (X, Y)
Very Nice.
Thank you!
Thank you!
-
- Very interested
- Posts: 3131
- Joined: Thu Nov 30, 2006 9:46 pm
- Location: France - Sevres
- Contact:
Re: Get Tile Index of background specific position (X, Y)
Indeed there is no VDP_getTileMapXY(..) function ins SGDK.
The reason of that is that it's somehow slow to retrieve tile index reading VRAM, usually you should have it in RAM or ROM as you initially set it yourself But i admit that in some situation it can be handy to directly get it from VRAM (as long we don't do it too much)
The reason of that is that it's somehow slow to retrieve tile index reading VRAM, usually you should have it in RAM or ROM as you initially set it yourself But i admit that in some situation it can be handy to directly get it from VRAM (as long we don't do it too much)
Re: Get Tile Index of background specific position (X, Y)
At the risk of saying something stupid,
If you are using a MAP resource on the A or B plane, there is a function," u16 MAP_getTile(Map*map, u16 x, u16 y) " in file " Map.c " maybe do a comparison with the return value and the tile index which you can find with dump VRAM with K-mod
If you are using a MAP resource on the A or B plane, there is a function," u16 MAP_getTile(Map*map, u16 x, u16 y) " in file " Map.c " maybe do a comparison with the return value and the tile index which you can find with dump VRAM with K-mod
-
- Very interested
- Posts: 3131
- Joined: Thu Nov 30, 2006 9:46 pm
- Location: France - Sevres
- Contact:
Re: Get Tile Index of background specific position (X, Y)
Indeed, but you need to use the MAP resource for that
It's also why i said "usually you should have it in RAM or ROM as you initially set it yourself", normally you almost never need to directly read the VRAM to retrieve tilemap data value.
It's also why i said "usually you should have it in RAM or ROM as you initially set it yourself", normally you almost never need to directly read the VRAM to retrieve tilemap data value.
-
- Very interested
- Posts: 118
- Joined: Mon Feb 19, 2018 7:31 pm