Page 1 of 1
pixels are not displayed
Posted: Thu Nov 24, 2016 9:26 pm
by alko
I try display an array of pixels, but the screen is empty.
Code: Select all
void plasma()
{
BMP_init(TRUE, PLAN_A, PAL1, FALSE);
BMP_setBufferCopy(TRUE);
VDP_setVerticalScroll(PLAN_A,0);
VDP_setVerticalScroll(PLAN_B,0);
VDP_setHorizontalScroll(PLAN_A,0);
VDP_setHorizontalScroll(PLAN_B,0);
BMP_clear();
u16 palette[16];
palette[0] = RGB24_TO_VDPCOLOR(0x000000);
palette[1] = RGB24_TO_VDPCOLOR(0x0000FF);
palette[2] = RGB24_TO_VDPCOLOR(0x00FF00);
palette[3] = RGB24_TO_VDPCOLOR(0xFF0000);
palette[4] = RGB24_TO_VDPCOLOR(0x00FFFF);
palette[5] = RGB24_TO_VDPCOLOR(0xFFFF00);
palette[6] = RGB24_TO_VDPCOLOR(0xFF00FF);
palette[7] = RGB24_TO_VDPCOLOR(0xFFFFFF);
palette[8] = RGB24_TO_VDPCOLOR(0x404040);
palette[9] = RGB24_TO_VDPCOLOR(0x000080);
palette[10] = RGB24_TO_VDPCOLOR(0x008000);
palette[11] = RGB24_TO_VDPCOLOR(0x800000);
palette[12] = RGB24_TO_VDPCOLOR(0x008080);
palette[13] = RGB24_TO_VDPCOLOR(0x808000);
palette[14] = RGB24_TO_VDPCOLOR(0x800080);
palette[15] = RGB24_TO_VDPCOLOR(0x808080);
VDP_setPalette(PAL1, palette);
u16 i; u16 j; u8 c;
for(i=0; i<100;i++){
for(j=0; j<100;j++){
BMP_setPixel(i, j,c);
c++;
}
}
BMP_flip(TRUE);
}
Re: pixels are not displayed
Posted: Thu Nov 24, 2016 10:58 pm
by Stef
BMP_flip(...)
You can also use bmp_buffer_write to directly access the bitmap buffer you can write
Faster to write pixels that BMP_setPxel(..)
Edit: Oh sorry i didn't saw you had it on last line...
Let me try your code..
Edit2: Tried your piece of code on both Fusion and Gens Kmod, getting expected result (rectangle of colorized pixels).
You tested on RH only ?
Also be sure to disable interrupts before calling any methods doing VDP stuff (as BMP_init()), it can mess up the code execution... it was working for me as i didn't had any process but maybe that is not your case...
Re: pixels are not displayed
Posted: Fri Nov 25, 2016 6:16 pm
by alko
Stef wrote:
Edit2: Tried your piece of code on both Fusion and Gens Kmod, getting expected result (rectangle of colorized pixels).
You tested on RH only ?
What is RH?
Also be sure to disable interrupts
I tried this.
This is main cycle of programm
Code: Select all
int main()
{
SYS_disableInts();
VDP_setScreenWidth320();
VDP_setScreenHeight240();
// JOY_setEventHandler(joyEvent);
// zastavka();
init_game();
SYS_enableInts();
while(TRUE)
{
// handleInput();
u32 current = getTimer(0, FALSE);
u32 elapsed = current - previous;
previous = current;
lag += elapsed;
while (lag >= 2000)
{
plasma();
lag -= 2000;
}
SPR_update(sprites, 80);
VDP_waitVSync();
}
return 0;
}
Re: pixels are not displayed
Posted: Tue Nov 29, 2016 6:05 pm
by Stef
Where is the BMP_init(..) call ?
Re: pixels are not displayed
Posted: Wed Nov 30, 2016 6:04 pm
by alko
Where is the BMP_init(..) call ?
finally it's work.
I wanted to make effect per-pixel Plasma
https://www.youtube.com/watch?v=FMfGiSZ ... e=youtu.be
but even random color 100*100 filled at a rate 2 fps.
Re: pixels are not displayed
Posted: Wed Nov 30, 2016 7:13 pm
by Stef
If you use the set pixel method you can't expect more
Use the BMP_getWritePointer() then directly write pixel into the buffer, much faster =)
Re: pixels are not displayed
Posted: Fri Dec 02, 2016 6:53 pm
by alko
Stef wrote:
Use the BMP_getWritePointer() then directly write pixel into the buffer, much faster =)
How to use this?
in parameters only point coordinates.
but how to set the color
Re: pixels are not displayed
Posted: Sat Dec 03, 2016 10:31 am
by Stef
This method allows you to receive the bitmap buffer pointer for specified pixel location.
But you can retrieve position for pixel 0,0:
Code: Select all
u8* bmp = BMP_getWritePointer(0,0);
Then you can do:
Code: Select all
bmp[x + (y << BMP_PITCH_SFT)] = color;
Where color is a 8 bits value representing 2 adjacent pixels at once. X resolution is only 128 pixel wide if we consider 8 bits write, if you want real 256 pixel wide resolution then you have to affect high or low nibble independently but then the rendering speed is much slower...
The used palette by Bitmap mode is defined with BMP_init(..) method.
Re: pixels are not displayed
Posted: Wed Dec 07, 2016 10:55 pm
by astrofra
Maybe you are expecting too much from a 7Mhz CPU with a tile-based framebuffer and no real chunky mode
The plasma is a good challenge on the MD. I tried to address it with the line per line scrolling mode, maybe combined with a color cycling ?
Re: pixels are not displayed
Posted: Wed Dec 21, 2016 4:52 pm
by alko
I decided to do per-tiles plasma.
But updated too slow.
Code: Select all
void plasma()
{
if(initplasma==0)
{
ind = TILE_USERINDEX;
VDP_setPalette(PAL0, pix0.palette->data);
ind_pix0= ind;
VDP_loadTileSet(pix0.tileset, ind_pix0, TRUE);
map_pix0 = unpackMap(pix0.map, NULL);
ind += pix0.tileset->numTile;
ind_pix1= ind;
VDP_loadTileSet(pix1.tileset, ind_pix1, TRUE);
map_pix1 = unpackMap(pix1.map, NULL);
ind += pix1.tileset->numTile;
ind_pix2= ind;
VDP_loadTileSet(pix2.tileset, ind_pix2, TRUE);
map_pix2 = unpackMap(pix2.map, NULL);
ind += pix2.tileset->numTile;
ind_pix3= ind;
VDP_loadTileSet(pix0.tileset, ind_pix3, TRUE);
map_pix3 = unpackMap(pix3.map, NULL);
ind += pix3.tileset->numTile;
ind_pix4= ind;
VDP_loadTileSet(pix4.tileset, ind_pix4, TRUE);
map_pix4 = unpackMap(pix4.map, NULL);
ind += pix4.tileset->numTile;
VDP_setVerticalScroll(PLAN_A,0);
VDP_setVerticalScroll(PLAN_B,0);
VDP_setHorizontalScroll(PLAN_A,0);
VDP_setHorizontalScroll(PLAN_B,0);
initplasma=1;
koef=1;
}
int i,j;
koef+=1;
for(i=0;i<40;i++){
for(j=0;j<28;j++){
pixstate=random()%6; //sinFix16(i)*(koef/2);
// if(pixstate>5||pixstate<0)pixstate=0;
if(pixstate==0)VDP_setMap(PLAN_B, map_pix0, TILE_ATTR_FULL(PAL0, FALSE, FALSE, FALSE, ind_pix0), i, j );
else if(pixstate==1)VDP_setMap(PLAN_B, map_pix1, TILE_ATTR_FULL(PAL0, FALSE, FALSE, FALSE, ind_pix1), i, j );
else if(pixstate==2)VDP_setMap(PLAN_B, map_pix2, TILE_ATTR_FULL(PAL0, FALSE, FALSE, FALSE, ind_pix2), i, j );
else if(pixstate==3)VDP_setMap(PLAN_B, map_pix3, TILE_ATTR_FULL(PAL0, FALSE, FALSE, FALSE, ind_pix3), i, j );
else if(pixstate==4)VDP_setMap(PLAN_B, map_pix4, TILE_ATTR_FULL(PAL0, FALSE, FALSE, FALSE, ind_pix4), i, j );
else if(pixstate==5)VDP_setMap(PLAN_B, map_pix5, TILE_ATTR_FULL(PAL0, FALSE, FALSE, FALSE, ind_pix5), i, j );
}
}
}
Is it possible to speed up the process?
Re: pixels are not displayed
Posted: Wed Dec 21, 2016 5:35 pm
by cero
Yeah, instead of 1120 individual calls, create a shadow in RAM and DMA it in.
Re: pixels are not displayed
Posted: Wed Dec 21, 2016 6:37 pm
by alko
cero wrote: create a shadow in RAM and DMA it in.
how to do it?
Re: pixels are not displayed
Posted: Thu Dec 22, 2016 12:06 pm
by cero
u16 shadow[1120];
shadow[j * 40 + i] = TILE_ATTR_FULL(PAL0, FALSE, FALSE, FALSE, ind_pix0);
Then you add 28 DMA calls to the queue, as it can't be transferred in one block without wasting RAM.
Re: pixels are not displayed
Posted: Wed Mar 15, 2017 2:22 pm
by alko
I still do not understand how to implement fast displaying tile's.
could you tell me in details?
Re: pixels are not displayed
Posted: Thu Mar 16, 2017 10:41 am
by Stef
Just use a map cache in RAM like this :
Code: Select all
Map* map = allocateMapEx(40, 28);
u16 *tilemap = map->tilemap;
...
u16 offi = 0;
u16 offj = 0;
u16 time = 1000;
// main loop
while(time--)
{
// generate plasma map
for(u16 i = 0; i < 40; i++)
{
for(u16 j = 0; j < 28; j++)
{
u16 pixstate = ((sinFix16(offi + (i << 6)) + cosFix16(offj + (j << 7))) >> 2) & 15;
*tilemap++ = pixstate;
}
}
// wait VSync
VDP_waitVSync();
// send map to VDP
VDP_setMap(PLAN_B, map, TILE_ATTR_FULL(PAL0, FALSE, FALSE, FALSE, TILE_USER_IND), 0, 0);
// modify base plasma offsets
offi += 10;
offj += 15;
}
..
// release allocated map
MEM_free(map);
I didn't tested the code and it may have some issues, but that is the idea...