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 14 years, 4 months ago by VirtualChris.
155 Replies

I believe those plugins have to be in the plugins directory inside the VIDE directory, not just in the root of the VIDE directory (make it if it doesn’t already exist). This is what you should see when you get it correctly: http://home.comcast.net/~virtual.boy/VB/export.jpg . This only pops up when you export the charmap, not the charset.


OK, I got it to work. Up next: the walls.


Question: Is there a limit to the number of files you can include? If so, the number seems to be 8, as I tried putting the official GoSub logo picture in and everything went blank. If so, is there any way to get around this? If not, why won’t the following .C file work? (I selected space 1 when it asked me to when I made it into an .h file using VIDE.)

I just checked the file size of this new GoSub ROM and it’s 79k instead of 64k. Do I need to do something special to make a ROM larger than 64k, and if so, what?

Change the part in the BAT file that refers to padding the ROM. It should have a number at the end of a command line. Either increment the number or try leaving it off altogether.

You mean the “15” at the end of this:
:: —– Pad ROM/add header —–
copy /b %1%2.VB /b + %1%2.hdr %1%2.VB /b /y > NUL
padromvb.exe %1%2.VB 15 > NUL
if exist %1%2.O del %1%2.O > NUL
if exist %1%2.hdr del %1%2.hdr > NUL

I tried doing everything to that number and my ROM still came out 79 KB and didn’t work.

What I didn’t try was simply changing it to 16. I thought it would need to be a number like 31 or something. OK, I got it to work now.

Here’s the latest ROM, incorporating the game’s logo in the title screen. I still need help with wall making, though.


Good to see you’re getting the hang of it. For walls, the easiest way I can think of is to check the BGMap at the position of the sub to determine which character is there, and if it’s your wall character (coral or whatever you want it to be), then crash.

Couple comments:
1) The wall character should be 8×8.
2) The wall character should be on 8 pixel boundaries (so it uses the same character rather than two new character for the top half and bottom half).
3) If you understand BGMaps, you can just create the wall character and create the BGMap by hand (pretty easy), which will take care of alignment for you, since BGMaps are created by an 8×8 character on 8 pixel boundaries. Otherwise you can make it in paint and use VIDE to convert it… just make sure in the charset that there’s only one copy of the wall character.
4) If you want your walls to be at different offsets, it’s doable, you’ll just need to check for multiple characters, but since only part of the character would actually be the wall, you’d have to check for partial collision as well, because people would get really annoyed if they die because they came within 7 pixels of a wall.

Now… how to do it. Like I said, create the BGMap as usual. Then figure out which offset in the charseg that the wall character is at (you can just count the chars in VIDE, and remember the first char is offset 0, not 1). Then do something like:

HWORD getBGMapChar(int bgmap, int x, int y)
	return (BGMM[(0x1000 * bgmap) + (y * 64) + x]&0x7FF);

if ((getBGMapChar(bgmap, x, y)==40) || (getBGMapChar(bgmap, (x+1), y)==40) || (getBGMapChar(bgmap, x, (y+1))==40) || (getBGMapChar(bgmap, (x+1), (y+1))==40))

For the example, I’m assuming the wall char is at location 40 in charseg0. If it was in charseg1, it’d be at 512+40, and so on. I’m also assuming that your sub is 16×16, which is why it’s checking x, y, x+1, and y+1. I would suggest that you make your sub a multiple of 8 if it isn’t already, to make this easy. Note that it doesn’t need to be a rectangle… it could be rectangle plus periscope at the top by doing something like only checking the 8×8 squares that are used like: x, (y+1); x, (y+2); (x+1), y; (x+1), (y+1); (x+1), (y+2); (x+2), (y+1); (x+2), (y+2);. Notice that it’s a rectangle with a periscope at x+1, y.

I’d also try to make the graphics as close to filling the chars as possible to keep people from being annoyed that they crashed because of the rectangular collision detection. Of course you could also add more specific checking around the sub, but once again, that’s more complexity.

Note that x,y is referring to coordinates in 8×8 chars, so 1,1 would actually be pixels 8,8. And you’ll need to divide your movement x,y by 8 to determine the char.

I see you referred to VUE Snake… one thing you should notice is that it moves in large steps, which makes collision detection easy, since it always either completely occupies a block or not at all… but I’m assuming you’re wanting your sub to move in the small smooth steps like you’ve shown so far.

I haven’t tested this code, and I just threw it together from the concept that I use for collision detection on Mario Kart, but it should work. I’d expect that it’ll need some tweaking, or that I left something somewhat important out. Hopefully it’ll get you started though.


The wall char’s location is 0 in BGMap1, so would I write 512+0? Also, in the first line of your code, you didn’t set bgmap, x, and y to anything (i’m assuming because you wrote an int without an =) , and so it doesn’t like that. What should I set the bgmap, x and y variables to? I did, however, get the walls code up, but I can’t seem to get a handle on the collision code.


I assume you mean CharSeg1, not BGMap 1? You take the Chars from Char Memory (CharSeg0 – CharSeg3), not from BGMap Memory. In your demo, the tile for walls is in CharSeg1, position 0, so you access it with 512+0 (or just 512), that’s correct.

Here’s a tip: Red Dragon has very nice debug functions, and one of them allows you to view the content of the Char Memory, BGMap Memory etc. So open your demo in Red Dragon, pause with ESC, and select Debug > View > Chars to view Char Memory for example.

DogP’s code shows a function, int bgmap, int x and int y are the arguments taken by the function, as demonstrated in the last line of his code. They don’t need to be initialized (aka set to anything).

I think you’re now at the first really difficult point to overcome, you’ll need some more C (or general) programming knowledge to proceed, so I’d suggest you take your time to read through some beginner’s tutorials. If you can get the collision detection set up mostly on your own, then nothing else will be able to stop you from finishing the game. 🙂

One more note: You can move vbDisplayShow(); (line 95 of your code) out of the loop to the beginning of your main loop (but after the initialization of the variables of course). All it does is setting the brightness registers so it only needs to be called once. And since you are setting the brightness registers manually in lines 51 to 53, you don’t need vbDisplayShow() at all.

Oh, and here’s an advanced tip you might want to use later: Instead of painting a level BGMap in VIDE, and have a seperate array for collision detection, you can also generate the BGMap on the fly from the collision detection array. This would work by going through the array in a loop and writing directly to the BGMap Memory where there is a “1” (ir whatever value you want to be a wall). Here’s the code you need for that:
BGMM[(0x1000 * BGMap) + Offset] = Value;
Where “BGMap” is the BGMap to write to (0 – 13), Offset is the Char in the BGMap (0 – 512? not sure right now), and Value is the address of the Char in Char Memory (512 for your wall).
But as I said, don’t bother with this until you fully understand how Chars, BGMaps etc work.

Then how does it know what bgmap, x, and y are worth unless you don’t tell it what they’re worth? When I type that code into the computer and compile it, it comes back with error messages that say all three variables are undecleared.

oh right. those are used in the function call, too. well… x and y are your ships coordinates, and bgmap is the number of the bgmap your level maze is in.

I already have variables for my sub’s x and y positions (xpos and ypos). So if I change it to this:

	HWORD getBGMapChar(bgmap, xpos, ypos) 
  	return (BGMM[(0x1000 * bgmap) + (ypos * 64) + xpos]&0x7FF); 

	if ((getBGMapChar(bgmap, xpos, ypos)==40) || (getBGMapChar(bgmap, (xpos+1), ypos)==40) || 

(getBGMapChar(bgmap, xpos, (ypos+1))==40) || (getBGMapChar(bgmap, (xpos+1), (ypos+1))==40)) xpos=10; 

and set the bgmap variable to 1 in the beginning, it says there’s a parse error before getBGMapChar.

(note: I’m not worried about changing the numbers to the correct ones until I get this code compiling.)

Did you insert the getBGMapChar function inside your main function?

Which line has the mentioned error, the function declaration or the if statement?

Also, you don’t need to rename the arguments used in the function to match your main program.

I inserted it in the main function, and it doesn’t like the function declaration.

There’s your problem, then. Don’t declare functions inside others.

You’re doing great, so far, but maybe it’s time for a C primer; just to get the basics.

Yeah, you need the function declared above the main function… like this:

HWORD getBGMapChar(int bgmap, int x, int y)
    return (BGMM[(0x1000 * bgmap) + (y * 64) + x]&0x7FF);

int main()
...existing code...
    if ((getBGMapChar(bgmap, x, y)==40) || (getBGMapChar(bgmap, (x+1), y)==40) || (getBGMapChar(bgmap, x, (y+1))==40) || (getBGMapChar(bgmap, (x+1), (y+1))==40))
...rest of code...

The argument names in the first line are different than what I used in the main program below… the ones for the main program are just placeholders that you should change… in your program it should actually be getBGMapChar(1, (xpos/8)+1, (ypos/8)+1)==512. The first function (getBGMapChar) shouldn’t be changed.


What about the variable “crash”?

That’s just a placeholder for whatever you want to do when they crash into a wall.



Write a reply

You must be logged in to reply to this topic.