Level only displays 2 screens wide

Discussion of hardware and software development for Super NES and Super Famicom. See the SNESdev wiki for more information.

Moderator: Moderators

Forum rules
  • For making cartridges of your Super NES games, see Reproduction.
Post Reply
User avatar
OscarRichard
Posts: 30
Joined: Sun Jul 29, 2012 9:58 am
Location: Mexico
Contact:

Level only displays 2 screens wide

Post by OscarRichard »

I'm using PVSNESLIB to make my first project and I have a png image which represents the first level with 1024x256 pixels ( 4 screens wide ) but when I run my game It only shows the first 2 screens even when I keep scrolling to the right. I have used this page to export the level https://portabledev.com/pvsneslib/tilesetextractor/ with tileset.

Here's part of my code:

Code: Select all

int main(void) {
	gravedad=2;
	num_monedas=0;
    // Initialize SNES 
	consoleInit();
	
	spcBoot();
	// Set give soundbank
	spcSetBank(&SOUNDBANK__);
	
	// allocate around 10K of sound ram (39 256-byte blocks)
	spcAllocateSoundRegion(39);
	// Load music
	spcLoad(MOD_POLLEN8);
	// Play file from the beginning
	spcPlay(0);
	
	// Now Put in 16 color mode 
	setMode(BG_MODE1,0); bgSetDisable(1); bgSetDisable(2);
	
	bgInitTileSet(0, &tileset, &palNivel1scrn, 0, (&tileset_end - &tileset), 16*2, BG_16COLORS, 0x2000);
	bgInitMapSet(0, &mapNivel1scrn, (&mapNivel1scrn_end - &mapNivel1scrn),SC_64x32, 0x1000);
	bgSetMapPtr(0, 0x1000, SC_64x32);

	setMode(BG_MODE1,0); bgSetDisable(1); bgSetDisable(2);

	mapLoad((u8 *) &mapNivel1scrn,(u8 *) &tilesetdef, (u8 *) &tilsetprop);
	mapUpdateCamera(0,0);
	
	oamInitGfxSet(&sprjugador, (&sprjugador_end-&sprjugador), &paljugador, 16*2, 0, 0x4000, OBJ_SIZE16_L32);
	dmaCopyVram(&sprEnemigo, 0x4200, (&sprEnemigo_end-&sprEnemigo));
	dmaCopyVram(&sprMoneda, 0x4400, (&sprMoneda_end-&sprMoneda));
	dmaCopyVram(&sprBala, 0x4600, (&sprBala_end-&sprBala));
	
	iniciarJugador();
	cargarEnemigos();
	cargarMonedas();
	cargarBalas();
	
	consoleInitText(1, 1, &snesfont);
	consoleSetTextCol(RGB5(0,0,0), RGB5(31,31,31));
	
	setScreenOn(); 
	// Infinite loop to keep the program running
	while(1) {
		consoleDrawText(1,1,"MONEDAS: %d",num_monedas);
		// Put your code here
		spcProcess();
		actualizarJugador();
		desplazarPantalla();

		actualizarEnemigos();
		actualizarMonedas();
		actualizarBalas();
		colisionBalasEnemigos();

		mapUpdateCamera(plx,0);
		mapUpdate();
		WaitForVBlank();
		mapVblank();
	}
	return 0;
}
Something missing?
Oziphantom
Posts: 1565
Joined: Tue Feb 07, 2017 2:03 am

Re: Level only displays 2 screens wide

Post by Oziphantom »

are the tiles 16x16. I don't know pvsneslib but I can't see anywhere you are switching to 16x16 mode.
User avatar
OscarRichard
Posts: 30
Joined: Sun Jul 29, 2012 9:58 am
Location: Mexico
Contact:

Re: Level only displays 2 screens wide

Post by OscarRichard »

They were in 16x16. I actually have them in 8x8, but the problem still persists.
Oziphantom
Posts: 1565
Joined: Tue Feb 07, 2017 2:03 am

Re: Level only displays 2 screens wide

Post by Oziphantom »

okay so you have a 64x32 map. Which is as wide as you can get. Now each entry is 8x8. 64*8 = 512 pixels of which the screen is 256 pixels wide and 512/256 = 2 there for 2 screens wide.

To get 4 screens wide you have to use 16x16 tiles as 64*16 = 1024 of which the screen is 256 pixels wide and 1024/256 = 4.
User avatar
dougeff
Posts: 3079
Joined: Fri May 08, 2015 7:17 pm

Re: Level only displays 2 screens wide

Post by dougeff »

PVSNESLIB documents say it can handle maps larger than that. I haven't used it, but it seems to have an automatic scrolling engine (I would assume with automatic tile updates)

The example picture is like... 8-10 screens wide.

The last code example says "WORK IN PROGRESS" for the page that is supposed to show the code that makes it work, so I have no reference for what it's supposed to look like.

FYI, there is a discord server for PVSNESLIB. That might be a better place to ask questions.
nesdoug.com -- blog/tutorial on programming for the NES
tepples
Posts: 22708
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: Level only displays 2 screens wide

Post by tepples »

This post explains the concept, not the details of how to implement it in a program that uses PVSnesLib. It may help you understand any PVSnesLib-specific answer that you might get in another space.

Typically, the S-PPU is configured through register BG0SC to allocate a nametable (or tilemap) that is 2 screens wide by 1 screen high for a scrolling playfield. This is 64 by 32 tiles or 512 by 256 pixels. This is larger than the screen, which is 256 by 224 pixels. The fact that it is larger is important because it lets you update parts of the nametable before they come onto the screen. The usual strategy is to draw columns of the larger map into the nametable just as they are about to enter the screen. The part of the screen being updated at any moment is sometimes called the "seam." The +32 increment setting in register VMAIN makes drawing columns more convenient.

Image
Animation explaining how to perform scrolling across a horizontal playfield longer than 512 pixels. This game places the nametables at addresses $2000 and $2400; the BG0SC value for that is $21.
User avatar
OscarRichard
Posts: 30
Joined: Sun Jul 29, 2012 9:58 am
Location: Mexico
Contact:

Re: Level only displays 2 screens wide

Post by OscarRichard »

I have asked in Discord, first. No answers so far...

There's an example included in PVSNES which has a level with like 10 screens wide and that I was following and ended up with the code written.
vnsbr
Posts: 56
Joined: Sun Feb 17, 2019 5:18 pm
Contact:

Re: Level only displays 2 screens wide

Post by vnsbr »

mapUpdateCamera(plx,0);
mapUpdate()

Seems to be the meat of mapupdate and camera handling code, how are we supposed to help without knowing the inner workings and not being familiar with pvsnes?
Post Reply