Im total newbie in programming. But very want to start learning. Sega Megadrive is a console from my childhood - so, i decded, why not combine those two things.
Already did simple hello world (Conway's Game of Life demo). Now want to understand how to scroll some wide background picture. But got difficulties with it, so, if its possible - i would be glad to get any help!
I have picture consisted of 230 x 28 tiles (8x8) (optmized a little, so used 4024 unique tiles), palette, map. Just want to try to scroll this picture horizontally. For simplifity, just scroll from left side to right side of this picture.
I decided to do it this way:
1) create map buffer equal to screen size+1 tile col (41x28), fill it with map data chunks from real map, aligned by x offset (0 at beginning, because start from left side).
2) fill vram with actual tiles, using indexes from map buffer.
3) set horizontal scroll for plane.
4) when plane scrolled by 8 pixels, so extra tile col became visble, i stop scrolling, and refill map buffer from map with x+1 offset, refill vram with new tiles.
It works. Barely. Very visible tearing/blinking, no smooth. I tried disable display and enable dma, when refilling new tiles - but it just make blinking even more visble. Overall process looks like it scrolled by tiles, not pixels. But if i enable wating for Vsync, i may see that initial scroll (before first 8 pixels limit) is very smooth and scrolled by single pixels. But afterward it start scrolling by tiles, not pixels..No smooth at all.
Here is code. Btw, I understand that its lame, and probably it must be done slightly different way. Would be happy if someone will give me hint on this.
P.S. Thanks to Stef for his great Genesis Devkit!
P.P.S. Yesterday spend all evening watching various demos on this great forum. Guys, its amazing what u do with Sega Genesis!
Code: Select all
for (y = 0; y < 29; y++) {
for (i = 0; i < 42; i++) map1_buff[y*41+i] = map1[y*230+i]; //fill 41x28 map buffer with data from picture map, offset x=0
}
for (i = 0; i < 1148; i++) {
tile_ptr = &tile[map1_buff[i]*8];
VDP_loadTileTo(tile_ptr,i,1,0); //fill vram with tiles
}
VDP_fillTileRectInc(APLAN, TILE_ATTR(0,0,0,0),0,0,41,28);
VDP_setPalette(0,palette0);
for (;;) {
if(BUTTON_RIGHT & joy) VDP_setHorizontalScroll(APLAN, 0, 0-scroll++); //press right, to scroll pic from left to right
if(scroll == 8) { //when pic scrolled by 8px (1 tile col), reload new tiles to vram, offset x++
scroll_tile_shift++;
for (y = 0; y < 29; y++) {
for (i = 0; i < 42; i++) map1_buff[y*41+i] = map1[scroll_tile_shift+y*230+i];
}
//VDP_setReg(0x01,0x14); //just make blinks more visible
for (i = 0; i < 1148; i++) {
tile_ptr = &tile[map1_buff[i]*8];
VDP_loadTileTo(tile_ptr,i,1,1);
}
//VDP_setReg(0x01,0x74);
scroll = 0;
}
//VDP_waitVSync();
//VDP_blit();
}