PVSnesLib for Snes 20th birthday :D !

Discussion of hardware and software development for Super NES and Super Famicom.

Moderator: Moderators

Forum rules
  • For making cartridges of your Super NES games, see Reproduction.
alekmaul
Posts: 54
Joined: Tue Apr 24, 2012 12:22 pm
Contact:

PVSnesLib for Snes 20th birthday :D !

Post by alekmaul » Wed Jun 06, 2012 12:54 am

Hello,
I posted it on some others forums but I forgot to do a complete post here ...
I want to share with you this new try to have a generic C lib for Snes (We need homebrew for this really nice console, it's its birthday :D).
It's based on snes-sdk, with help of tools from mic_, shiru , mukunda and others (just see thanks webpage on pvsneslib documentation).
I know c source code from 816-tcc is nto really optimized and result are often slow with it, but it's a try, so why not :D !
There is now everything to do a project, even sound support, thanks of snesmod library (and Kung Fu Furby for help ;-) ).
Here is the wiki entry I made about it, of course **it far to be complete** and it really need more work to have something that be ok with all Snes functionnalities.

http://www.portabledev.com/wiki/doku.php

You can download the last version from wiki here : http://www.portabledev.com/wiki/doku.ph ... version_en

Google code entry : http://code.google.com/p/pvsneslib/

Here is a screen shot from something I ported from Shiru's source code :

(image too huge, just the link) http://www.portabledev.com/media/SNES/P ... upaboy.jpg

I still have problem with speed and optimore (thanks mic_ ;-) ) seems to have problem with the lib (no keypad support when I'm using it, don't know currently why).

pichichi010
Posts: 172
Joined: Thu Dec 29, 2011 5:41 pm

Post by pichichi010 » Fri Jun 08, 2012 12:42 pm

hey Alekmaul!

Nice work!!!

pm me whenever you have a chance! **URGENT**

User avatar
juef
Posts: 67
Joined: Thu Jul 15, 2010 8:20 am
Location: Québec, Canada

Post by juef » Sun Jun 10, 2012 4:56 pm

This does look very nice! I love how clean and structured the wiki looks. Definitely gonna try this next week!

orwannon
Posts: 40
Joined: Fri Feb 20, 2009 10:07 am

Post by orwannon » Wed Jun 13, 2012 7:25 am

Hey, alekmaul,

thanks a lot for this! I had been waiting/hoping for a toolchain like this for a very long time. Thanks to you, I might finally venture deep into the mysterious realm of SNES programming. :lol:

After fiddling around a bit with pvsneslib, I think I've found a bug or two:


KEY_X and KEY_Y refer to the Y button and the X button, respectively. This can be corrected by simply swapping around their BIT numbers in include/snes/pads.h like so:

Code: Select all

  KEY_X      = BIT(6), //!< pad X button.
  KEY_Y      = BIT(14), //!< pad Y button.

Additionally, I couldn't get the following condition to behave correctly:

Code: Select all

if (joypad1 & (KEY_B | KEY_UP)) {
		// blah, blah
     }
Here, "blah, blah" happens when either B or up is pressed, not both at the same time as stated in the wiki.


Haven't tried much more yet, but will definitely do so. :)

Thanks again!

Shiru
Posts: 1161
Joined: Sat Jan 23, 2010 11:41 pm

Post by Shiru » Wed Jun 13, 2012 7:35 am

For both it should be if((joypad1&KEY_B)&&(joypad1&KEY_UP)) { }, or less obvious if(!(~joypad1&(KEY_B|KEY_UP))) { }

alekmaul
Posts: 54
Joined: Tue Apr 24, 2012 12:22 pm
Contact:

Post by alekmaul » Wed Jun 13, 2012 9:01 pm

Thanks a lot for the bug about X & Y buttons, fixed in next release (will be available at the end of this month with , of course, some new features).

orwannon
Posts: 40
Joined: Fri Feb 20, 2009 10:07 am

Post by orwannon » Thu Jun 14, 2012 3:29 am

Shiru wrote:if((joypad1&KEY_B)&&(joypad1&KEY_UP)) { }
That works, thanks! :D

alekmaul, I've spotted another minor issue: The internal ROM name doesn't match whatever you put in the NAME section in hdr.asm, instead the project name (e.g. "hello_world") is used.

Thanks again, and I'm looking forward to the next release! :D

alekmaul
Posts: 54
Joined: Tue Apr 24, 2012 12:22 pm
Contact:

Post by alekmaul » Thu Jun 14, 2012 4:26 am

About internal name, it is certainly because you have the following lines in your makefile (they are in each examples) :

GTITLE := -ht"$(TARGET)"

#---------------------------------------------------------------------------------
all : bitmaps $(OUTPUT).sfc
$(SNTOOLS) -hi! $(GTITLE) $(TARGET).sfc

So, the internal name is changed with the current directory name $(TARGET) , as you can see for variable GTITLE.
Use -ht option to change the name with snestool.

EagleEye
Posts: 5
Joined: Sun Jun 10, 2012 7:29 pm
Location: USA

Post by EagleEye » Tue Jun 19, 2012 10:05 am

Can someone help me? I want this demo to display all the colors in palette 0 (it shows most, but some are black instead(?)), and demonstrate layer 1 over layer 0 (or the reverse? I'm not sure). I can't quite figure out how to make it does these things.

The demo

Thank you.

User avatar
juef
Posts: 67
Joined: Thu Jul 15, 2010 8:20 am
Location: Québec, Canada

Post by juef » Tue Jun 19, 2012 10:25 am

EagleEye, I'm not quite there yet, but when I am I'll make sure to give it a try.

alekmaul, thanks again for this project! I find it is much easier this way than learning about the SNES and assembly at the same time. I'm guessing assembly won't be avoidable in the end though, whether it's for speed or more advanced features. I'd love having a variable width font in my project, but looking at the PVSnesLib source gives me a headache for now, so I guess I'll stick to a constant width font until I'm more comfortable with the SNES as a whole :)

alekmaul
Posts: 54
Joined: Tue Apr 24, 2012 12:22 pm
Contact:

Post by alekmaul » Tue Jun 19, 2012 9:16 pm

Sorry juef, do not have time to take a complete look at the code but I see some things :

Code: Select all

	setMode(BG_MODE1,0); bgSetDisable(2); bgSetDisable(1);
So you will only have BG0 enable, your BG1 will never be display.

Code: Select all

	bgInitMapSet(0, &map[0], 64, SC_32x32, 0x0000);
	bgInitMapSet(1, &map[6],  6, SC_32x32, 0x0000);
	bgInitMapSet(0, &map[0], 64, SC_32x32, 0x0020);
	bgInitMapSet(0, &map[0], 64, SC_32x32, 0x0040);
	bgInitMapSet(0, &map[0], 64, SC_32x32, 0x0060);
...
Why so much InitMapSet and an Init to BG1 (the second one), what do you really want to do ?

You've got a tool named gfx2snes that can easily creates for you some map, tiles and palette, why do you not use it ?

Take a look at snes-examples\graphics\Effects\Transparency project, there is a nice effect about a BG with another one just before it scrolling around the screen.

EagleEye
Posts: 5
Joined: Sun Jun 10, 2012 7:29 pm
Location: USA

Post by EagleEye » Wed Jun 20, 2012 5:20 am

I don't use gfx2snes because I'll need to dynamically load in maps into memory and I'm testing that out. Additionally, I need to generate my own palettes and graphics anyway. The idea is that each frame I'll upload the tilemap to VRAM after I've modified it to reflect the current map correctly. I had BG1 disabled because I couldn't get it to work right and I wanted it to look correct enough when run without modification.

I'll look into Transparency's project. Thank you. :)

Combined Edit: I got layer 2 working using Transparency as an example, and then figured out how to use layer 1 instead. Unfortunately, it seems you can't call bgInitMapSet after you've called setMode. I have no clue how to switch out the tilemaps otherwise, so I guess I'll have to figure out how to turn off something, write to the tilemap, and turn that same something back on. In the meantime, I'm going to work on design, etc. I'll probably figure out what to do after a little break. (Here's my thing's mostly-fixed source, for anyone interested.)

P.S. scrY. pad0, and move are defined in the Transparency example, but never used.

alekmaul
Posts: 54
Joined: Tue Apr 24, 2012 12:22 pm
Contact:

Post by alekmaul » Wed Jun 20, 2012 9:37 am

You need to be near VBL to change tile map.
As you can see in google code of the lib, here is the code of initMapSet:

Code: Select all

void bgInitMapSet(u8 bgNumber, u8 *mapSource, u16 mapSize, u16 sizeMode, u16 address) {
	setBrightness(0);  // Force VBlank Interrupt
		
	dmaCopyVram(mapSource, address,mapSize);
	if (bgNumber != 0xff)
		bgSetMapPtr(bgNumber, address, sizeMode);
}
So, if you only want to change tilemap,just use dmaCopyVram with correct parameters, just after VBL (wait for it with WaitForVBlank() for example)
P.S. scrY. pad0, and move are defined in the Transparency example, but never used.
Yep, will fix that for next release. You're right ;-)

Also, I need help for doing something like pseudo3Dmode but i do not understand how matrix are working for snes, someone has a source code example like the squaresoft mode7 demo ? (http://www.unseen64.net/2010/10/28/squa ... tech-demo/)

EagleEye
Posts: 5
Joined: Sun Jun 10, 2012 7:29 pm
Location: USA

Post by EagleEye » Wed Jun 20, 2012 11:11 am

Thanks. Now I'm pretty much set as far as SNES development. You've made this amazingly easy. :)

User avatar
juef
Posts: 67
Joined: Thu Jul 15, 2010 8:20 am
Location: Québec, Canada

Post by juef » Mon Jul 16, 2012 1:36 pm

I'm having fun with this! :D

So far, I've only completed the tutorials up to the animated sprites one. I managed to "merge" the previous input tutorial with the animated sprite, improved the display of input buttons, added a position display, and introduced acceleration and screen wrapping (is that the right word?) to the sprite.

If anyone wants to see, download it here!

The only thing I'm having trouble with so far is with the top and left side of the screen. There seems to be a "black bar" at the top, and the sprite disappears all at once on the left side of the screen, whereas it gradually hidden by the bottom and right side. I've tried toying with negative integer positions, alas with no success. Can anyone help?

See video of the "game" in action!

Post Reply