Original Post

How do I turn a C file into something to run in a Virtual Boy emulator? I was fiddling around with Notepad making a C file and I downloaded gccvb and VIDE, but I can’t find anything that would do this?

  • This topic was modified 15 years, 3 months ago by VirtualChris.
155 Replies

Success!
a few questions, though:
Suppose I want to have an image of a submarine on a title screen and I have it all mapped out in VIDE (see attachment below.) How would I (first, make it so if you press a key, it goes to the title screen, and then) display the submarine picture? I tried messing around with
if(vbReadPad()&(K_ANY))
but I couldn’t figure out how to use goto statements in C.
sorry if i’m annoying, but I just would like as much help as i can get because i’m new to this whole developing for VB thing.

Attachments:

Instead of using if(vbReadPad()&K_ANY), use while(!(vbReadPad()&K_ANY)). If you just want it to wait, just do: while(!(vbReadPad()&K_ANY));, or if you want it to do something while it waits for a keypress, you can do while(!(vbReadPad()&K_ANY))
{
//do stuff
}

DogP

First, you should realize that any pixels in your sub that are black in VIDE will be transparent on the screen. You should alter your source image to have black for the transparent bits and three other shades of grey (dithering is optional, but don’t let it use black to darken one of the other greys).

Now, to display it, you would export the BGMap to a .H file, the chars to a .H file, load the BGMap data into a BGMap segment (other than the one being used by vbTextOut) and then just change World 31 to use the new BGMap segment by OR’ing (|) the header with the segment number.

Of course, you could use a separate World for the sub if you wanted. You would just have to move the “END” World down to the next lower number.

Also, to get a handle on what goes in a World (like the G and M coordinates and all that stuff), be sure to consult the dev wiki. And stop apologizing for asking questions! That’s why this forum is here! (With many thanks to KR155E ;-))

What if I want it to show an image after a keypress (the title screen), then what am I doing wrong here?
(for the image, see attachment “submarine.h”)

I looked at your VEP file and there’s only a charset. Make sure you load your image with Advanced->Charmap tools->Map constructor.

That way you get a set of tiles and a map that combines them back into an image.

Success again! A title screen!

Attachments:

Nicely done!

However, it might be better (to make it easier to expand later on) to just load the sub image into a second BGMap at the top, where you load the font, and then change the World to point to it, like I described above.

Of course, you’d also have to change the target BGMap in subsequent vbTextOut() calls (but you knew that ;-)).

But, it’s up to you how you code it, isn’t it? 😀

Figured out how to center things, so now everything is more centered than it was before.

Attachments:

I’m having a little trouble with this program. If you press Start while the “read instruction booklet” screen shows up, it bypasses the title screen and goes into the main game. Also, in the main game, I want the sub to keep moving even though a key isn’t being pressed. How would I go about doing that?
(I’ve also uploaded the VB rom so you can see what I’m talking about.)

Attachments:

Very cool! About the start press problem, you can fix that by doing while(vbReadPad()&K_STA); after the while(!(vbReadPad()&K_STA)){}. That will cause it to wait until the button is released.

The other suggestion (doesn’t matter too much in this case, but good programming practice) is to change the while(!(vbReadPad()&K_ANY)){} and K_STA loops to do the vbTextOut and other things outside the loop, then just wait with while(!(vbReadPad()&K_ANY)); . The way you’re doing it now, you’re redrawing the same text over and over, when you just need to draw it once and wait. I see you also have multiple vbDisplayShow()s… that’s unnecessary, and definitely doesn’t need to be done in the loop.

For it to keep moving instead of changing the sub’s position directly with the keypad, increment/decrement it’s position with a variable that you change with the keypad. Something like this:

while(1)
{
	if(vbReadPad()&(K_LD)) vert=1;
	if(vbReadPad()&(K_LU)) vert=-1;
	if(vbReadPad()&(K_LL)) horz=-1;
	if(vbReadPad()&(K_LR)) horz=1;

	xpos+=horz;
	ypos+=vert;

	vbSetWorld(31, WRLD_LON, 0, 0, 0, 0, 0, 0, 0, 0);
	vbSetWorld(30, WRLD_LON, xpos, 0, ypos, 0, 0, 0, 384, 224);
	vbSetWorld(29, WRLD_END, 0, 0, 0, 0, 0, 0, 0, 0);

	vbWaitFrame(1);
}

Of course this will cause it to always move… to make it to press right to start moving right, then left to stop, then left again to start going left, do something like:

	if(vbReadPad()&(K_LD)) vert++;
	if (vert>1) vert=1;
	if(vbReadPad()&(K_LD)) vert--;
	if (vert<-1) vert=-1;

Then you could modify that to have acceleration and deceleration based on how long they hold the button by making it clip at +/- 2 or 3, etc with if (vert>3) vert=3; Of course you'll also need to make sure it doesn't go off the screen, but that can be part of the collision detection that I'm sure you're planning on doing.

Nice work so far... keep it up!

DogP

Thank you!
In case you’re wondering where I’m going with all this, you can visit the original Atari 2600 version of GoSub here. To download it, just click on the little Pac-Man symbol on the right and then play it with either the Stella or Z26 emulators.

Posted is what I have so far with the VB version of the game.

Attachments:

Two new problems.
#1 – In the main game, I want to display both the level # and # of lives. But when I go and type in “LEVEL” and “LIVES”, the text moves along with the submarine! How do I stop this? Also, I put in two new variables, “lives” and “level”. How do I display them after “LEVEL” and “LIVES”, respectively?

I haven’t tried compiling any of this code, but I think this is probably what you want to do. For the first problem, you want to have the text output to a different BGMap. You do that by ORing the BGMap number in the second argument of vbSetWorld(), then change the vbTextOut to output to BGMap 1 like:

vbSetWorld(30, WRLD_ON|1, 0, 0, 0, 0, 0, 0, 384, 224);

vbTextOut(1, 1, 7,"IMPORTANT:");

For the second question, do you have a itoa() function in your libgccvb.h? If so, that’s what you want to use. If not, I’d suggest getting it (should be able to find one in some sample code around here), but realize it’s not perfect. A simple way to do it would also be:

char level_str[3];
char lives_str[3];

//null terminate string
level_str[2]=0;
lives_str[2]=0;

level_str[0]=(level/10)+'0';
level_str[1]=(level%10)+'0';
lives_str[0]=(lives/10)+'0';
lives_str[1]=(lives%10)+'0';

vbTextOut(1, 4, 7,level_str);
vbTextOut(1, 5, 7,lives_str);

Don’t forget all variables need to be declared before any code, so the char lines need to be up by your int vert=…. and the other code can be done in your main loop, but should only need to be done whenever the player loses a life or goes to the next level. This code would assume that the level and lives are never higher than 99 (and always display 2 digits).

Also, any reason you only want to play with the left eye? 😉 You should change the WRLD_LON to WRLD_ON (or WRLD_LON|WRLD_RON). That will make it display to both eyes.

DogP

It worked, but it shows the first character in the character map for the small submarine in a pattern. How do i get rid of that?

Attachments:

Oh… you should clear your BGMap(1)… similar to the copymem((void*)BGMap(0)… that you used for creating your graphics, you need to set the other BGMap to be all blank. You can do that with setmem((void*)BGMap(1), 255, 1024*16); . I put 255 in there assuming that char 255 in your charseg is an all blank character. If not, go into VIDE and find the index of a blank character and put that number in.

DogP

Success!

Attachments:

There’s nothing wrong, but the next thing I’d like to do is add a maze for the sub to navigate through (with an outlined border around the edges of the screen.) What would be the best way to do this? I’d like, at the least, 25 different mazes (which I’d design.) I just would like blocks to put in various places to form the mazes, if at all possible. Would they be solid blocks, or can they have designs on them? I’d like to design them as coral reefs, like in the water levels of SMB1 for the NES. But if they can be solid blocks, I wouldn’t mind. I know this can probably be done, as VUE Snake proves.

EDIT: Here’s a rough mock-up of what I’m imagining.

  • This reply was modified 15 years, 7 months ago by VirtualChris.

A little error that needs to be fixed.
I’m trying to put the treasure map in the game, but it comes out instead of the picture I want, it’s a broken picture of the submarine. How do I make it so it’s the treasure map instead of the broken sub?

Attachments:

I see you’re copying the chars to Charseg 2… when you exported the map, did you select that the chars will be in Charseg 2? You need to make sure you install DanB’s VIDE export plugin that was mentioned earlier in the thread if you haven’t already.

This will make a popup window come up when you click export to .h on the charmap. In that window, you want to select charseg 2. You could also put the treasure graphics in the same image as the rest of your game graphics, and just select it with vbSetWorld(29, WRLD_ON|2, xpos, 0, ypos, X_POS_IN_GFX, 0, Y_POS_IN_GFX, WIDTH, HEIGHT);, which cuts out a chunk WIDTH wide and HEIGHT high starting at X_POS_IN_GFX, Y_POS_IN_GFX in your graphics, and places it at xpos and ypos.

If nobody answers your question about creating the level, I’ll try to answer tomorrow night, but I’m pretty busy tonight and don’t have time for a lengthy post.

DogP

I don’t understand any of this. When I clicked “export to .h” it never asked me what Charseg it wanted it to be in. It just asked what I wanted to name the .h file and where to put it on my hard drive. I have advmap.vpg and INCLUDE.vpg in the same folder where VIDE is located.

 

Write a reply

You must be logged in to reply to this topic.