Homebrew Petit Computer Thread

BenRK

Well-Known Member
Member
Joined
Apr 21, 2010
Messages
728
Trophies
0
XP
552
Country
United States
Ok, yeah, i have no clue what i'm doing with this. I'm used to a JAVA/C++ syntax, not Basic. The way i see it, if i can store some variables, move some sprites around, supposedly simple stuff, i can make whatever. Would it be possible to get a little crash course for this? The help file isnt as useful as one would hope, more so as it lacks any form of searching.
 

Snailface

My frothing demand for 3ds homebrew is increasing
Member
Joined
Sep 20, 2010
Messages
4,324
Trophies
2
Age
40
Location
Engine Room with Cyan, watching him learn.
XP
2,256
Ok, yeah, i have no clue what i'm doing with this. I'm used to a JAVA/C++ syntax, not Basic. The way i see it, if i can store some variables, move some sprites around, supposedly simple stuff, i can make whatever. Would it be possible to get a little crash course for this? The help file isnt as useful as one would hope, more so as it lacks any form of searching.
Don't laugh, but gamefaqs has a ton of useful threads on Petit Computer and they're still active.
http://www.gamefaqs.com/boards/663843-petit-computer (there's a beginner's sticky at the very top)
Search for what you need to know within that site and you're bound to find what you need.

Also, I find it helpful to Ctrl + F through the app's demos to see how a particular function works. I've made a single source code file (all-in one) just for this purpose:
http://www.mediafire.com/?44xj3boxttsuqs1
 

BenRK

Well-Known Member
Member
Joined
Apr 21, 2010
Messages
728
Trophies
0
XP
552
Country
United States
Thanks. That beginners tutorial got me started. Now all i need to do is get the tile set i wish to use and get some wizards and sch movimg about a town!

On that note, are there arrays i can use?

And this is a bit further down the line, but what about save files? I would imagine that Petit would lose most if not all usefulness if we couldnt save even high scores.
 

BenRK

Well-Known Member
Member
Joined
Apr 21, 2010
Messages
728
Trophies
0
XP
552
Country
United States
Things are off to a good start. However, I don't understand how to use arrays. At least not fully. I'm used to defining the contents of an array on the go.

For (I=0;I
 

BenRK

Well-Known Member
Member
Joined
Apr 21, 2010
Messages
728
Trophies
0
XP
552
Country
United States
Ok, but what about a 2D array? Would it be the same thing? Like...

Code:
DIM array(19,19)

for xx = 0 to 19
for yy = 0 to 19
array(xx,yy) = VALUE
next yy
next xx

Say I want to use this for a (common) map?
 

Snailface

My frothing demand for 3ds homebrew is increasing
Member
Joined
Sep 20, 2010
Messages
4,324
Trophies
2
Age
40
Location
Engine Room with Cyan, watching him learn.
XP
2,256
Ok, but what about a 2D array? Would it be the same thing? Like...

Code:
DIM array(19,19)

for xx = 0 to 19
for yy = 0 to 19
array(xx,yy) = VALUE
next yy
next xx

Say I want to use this for a (common) map?
That looks fine except the top needs to be DIM ARRAY(20,20).

20 is the total number of elements which is subscripted 0-19, just like C. What's different is For xx=0 to 19 is always inclusive unlike C where you can have (xx=0;xx
 

BenRK

Well-Known Member
Member
Joined
Apr 21, 2010
Messages
728
Trophies
0
XP
552
Country
United States
Alright. That was just a flub, no actual code was in there.

SO! Now to find a way to make a 2D map for my game... Any way we can load/save simple data files?
 

DiscostewSM

Well-Known Member
Member
Joined
Feb 10, 2009
Messages
5,484
Trophies
2
Location
Sacramento, California
Website
lazerlight.x10.mx
XP
5,509
Country
United States
And another question, is it possible to change the font? Using an appropriately sized tile set instead? That way I can just use locate and print and such for this. If not, I ask again, how should I go about moving a tile set into petit? I can't imagine moving it in by hand pixel by pixel will be very productive...

On a side note, can I mess with the brightness of a sprite or tile? I was thinking of how to go about a basic lighting system. Like how Minecraft used to do it. It would make everything very simple if I could just make everything increasingly darker the further from a light source it is. This is just for atmosphere, not particularly necessary.

I hadn't dealt with the font before, so I did a little digging. You can change the font of the console if you want. CHRED allows you to load/save fonts. Within your program, you can load a font by using the LOAD command. If the font was called TESTFONT, you'd do...
Code:
LOAD "BGF:TESTFONT"
...or you can use string concatenation (with the "+"), and have it load it based on the string you give it. Understand that just like loading assets, it will affect the run-time and edit modes, so if you want your program to reset it, just use the CHRINIT command as so...
Code:
CHRINIT "BGF"
I'm not sure if you can use a different font for both the upper and lower screen, but I assume you can as long as you designate which screen is actively being worked on with BGPAGE (parameter of 0 is upper screen, and 1 is lower screen).

About lighting.....from what I can gather, the only way you can get such an effect will involve messing with the color palette of the backgrounds and sprites. Each are limited to 256 colors, but they are split into 16 sections of 16 colors (with the first being the transparent color that does not get drawn). You can access the color palettes via COLREAD and COLSET. Here is an example of taking an existing color at index 30 of the sprite palette on the upper screen, and increasing the red, green, and blue components by 1.

Code:
SPPAGE 0
COLREAD("SP",30),R,G,B
R=R+1:G=G+1:B=B+1
COL$=HEX$(R,2)+HEX$(G,2)+HEX$(B,2)
COLSET "SP",30,COL$

Off the top of my head, if you were to have one 16 color palette that all your background tiles used, you could then have 16 shades of that palette, and then assign each individual tile on the background to refer to one of the 16 shades. If you wanted 2 unique palette sets of 16 colors, that would limit you to 8 different shades. 4 unique sets? 4 different shades. See the pattern? Anyways, how you want to implement your lighting system is up to you.

Alright. That was just a flub, no actual code was in there.

SO! Now to find a way to make a 2D map for my game... Any way we can load/save simple data files?

There are two approaches to having a map. The first is the easy yet limited way. Simply LOAD a SCR file in (which you can make with SCRED) to the one of 2 backgrounds for the designated screen. The limit is that the map itself is at most 64x64 tiles (being that each tile is 8x8 pixels). If you wanted a larger map, you will then have to go the harder route, and implement your own map engine that uses the 64x64 map backgrounds in a way that makes it look like it has more by updating sections of the map that are off the screen.

If you being general in loading/saving data, well......this is where we are out of luck. The only type of resources that can be loaded/saved are of background tilesets, sprite tilesets, background screens, color palettes, and memory files. The closest thing to "data files" that we think of is the memory files,but they are limited to a single string, and strings are limited to 256 characters if I'm not mistaken. The only way to have a large amount of data to be used by the program is having that data literally placed within the program itself as DATA commands. What you can do is place all this DATA at the end of your program, and for each section that you want access to, you set a label just before it, and within your program, call the command RESTORE , with being the label that is just before that set of data. You then READ in that data, either as numbers or strings. FOR loops can help if you want to load that data into an array. Having multiple labels at the beginning of different sections of the DATA allows specifying which area to use RESTORE at, but be aware that all data is read sequentially, and can't be randomly accessed. If you wanted to get to data in the middle of a section without a label pointing to it, it would require RESTOREing fro ma label before it, and then reading in the data one by one until you get to it.
 

BenRK

Well-Known Member
Member
Joined
Apr 21, 2010
Messages
728
Trophies
0
XP
552
Country
United States
So we have access to limited mem files. 256 characters on a single line. That wouldn't work for map files, but simple stuff like high scores and less simple stuff like character saving. That may be all I need for this project. As long as long as the player doesn't have to reset their progress every time they play, then any save format is good enough for me.
 

BenRK

Well-Known Member
Member
Joined
Apr 21, 2010
Messages
728
Trophies
0
XP
552
Country
United States
Sorry for yet again double posting (I'm just really excited about this), but loading the modified font worked perfectly! Well, it brought up the loading stuff it usually does when loading the program, but I assume I can turn that off. I'm not looking forward to bringing over the tile set by hand, but I'll make due.
 

DiscostewSM

Well-Known Member
Member
Joined
Feb 10, 2009
Messages
5,484
Trophies
2
Location
Sacramento, California
Website
lazerlight.x10.mx
XP
5,509
Country
United States
So we have access to limited mem files. 256 characters on a single line. That wouldn't work for map files, but simple stuff like high scores and less simple stuff like character saving. That may be all I need for this project. As long as long as the player doesn't have to reset their progress every time they play, then any save format is good enough for me.

Yeah, mem files are basically your average save file. Do at least have the option to use multiple mem files in case one isn't enough, but anything beyond saves is likely illogical.


Sorry for yet again double posting (I'm just really excited about this), but loading the modified font worked perfectly! Well, it brought up the loading stuff it usually does when loading the program, but I assume I can turn that off. I'm not looking forward to bringing over the tile set by hand, but I'll make due.

You can disable the confirmation window when loading by attaching an additional parameter to your LOAD command like so.

Code:
LOAD "somefile", FALSE

That only works for loading. When saving, you don't have that option from what I can tell. Along with the loading if you haven't figured it out already, you can disable the sound that is made by changing the SYSBEEP value

Code:
SYSBEEP=FALSE

I haven't checked if it disables everything on the spot (including music via MML), or just prevents new sounds from playing. Hopefully it is the latter. Be sure to re-enable it with TRUE once you are done with loading.
 

BenRK

Well-Known Member
Member
Joined
Apr 21, 2010
Messages
728
Trophies
0
XP
552
Country
United States
Yeah, a little experimenting and searching through the help file for the load functioned pointed me in the right direction. Took a little bit of fiddling to get the syntax right, but I got it!

I think I've got everything I need to get started. Thank you very much!
 

DiscostewSM

Well-Known Member
Member
Joined
Feb 10, 2009
Messages
5,484
Trophies
2
Location
Sacramento, California
Website
lazerlight.x10.mx
XP
5,509
Country
United States
I'm afraid to say this, but it looks like my Megaman 2 project with Petit computer isn't going to go anywhere due to one simple thing. Petit Computer is not capable of executing enough lines of code in a single frame to be able to handle what is required. How bad is it?

Code:
LOOPME=100
VTEST=MAINCNTL
@MAIN
PRINT MAINCNTL-VTEST
VTEST=MAINCNTL

FOR I=0 TO 4999
NEXT I

LOOPME=LOOPME-1
IF LOOPME>0 GOTO @MAIN

END

What this code does is it does a loop of 5000 iterations 100 times, and prints out how many frames have elapsed after doing each set. So, how many frames does it take to do a 5000 iteration loop? Literally 5 frames. So, approximately 1 frame to do a 1000 iteration loop, or about 2000 lines of code in this manner (the FOR and the NEXT). In all honest, how can we possibly be able to make games under this limitation? I mean, I was trying to mimic an NES game, and what you saw in the YT video was just under the limit before it began to show signs of slowdown.
 

BassAceGold

Testicles
Member
Joined
Aug 14, 2006
Messages
496
Trophies
1
XP
441
Country
Canada
I'm afraid to say this, but it looks like my Megaman 2 project with Petit computer isn't going to go anywhere due to one simple thing. Petit Computer is not capable of executing enough lines of code in a single frame to be able to handle what is required. How bad is it?

Code:
LOOPME=100
VTEST=MAINCNTL
@MAIN
PRINT MAINCNTL-VTEST
VTEST=MAINCNTL

FOR I=0 TO 4999
NEXT I

LOOPME=LOOPME-1
IF LOOPME>0 GOTO @MAIN

END

What this code does is it does a loop of 5000 iterations 100 times, and prints out how many frames have elapsed after doing each set. So, how many frames does it take to do a 5000 iteration loop? Literally 5 frames. So, approximately 1 frame to do a 1000 iteration loop, or about 2000 lines of code in this manner (the FOR and the NEXT). In all honest, how can we possibly be able to make games under this limitation? I mean, I was trying to mimic an NES game, and what you saw in the YT video was just under the limit before it began to show signs of slowdown.
It seems pretty decent for the hardware its running on. I have created a similar test to yours in my BAGASM interpreter (the DS version, not DS2), however it only does one loop of 5000 because there are no functions for measuring frame times in program yet. The interpreter does measure the time it takes to execute an entire program though, and does not limit the program what-so-ever in the processor department.

So this code here:
Code:
;$R1 - I
;$R2 - temp I
_start:
CLR $R1
I_LOOPS INCR $R1
SET $R2,$R1
SUB $R2,#5000
JMPN I_LOOPS
HALT
Runs in about 0.053968 seconds on no$gba (hardware is a tiny bit faster). Which is around ~3 frames to complete the loop of 5000. Now in DSi mode, this time would be cut in half, so maybe ~1.5 frames in total. Now, my scripting language is not quite as complex as BASIC is which would account for a large majority of the difference in performance, among the many other variations; So really, relative to each other,1 frame to do 1000 iterations doesn't seem all that unreasonable, especially when you consider how decently high level BASIC is for an interpreted language on a portable platform.
 

Snailface

My frothing demand for 3ds homebrew is increasing
Member
Joined
Sep 20, 2010
Messages
4,324
Trophies
2
Age
40
Location
Engine Room with Cyan, watching him learn.
XP
2,256
Code:
LOOPME=100
VTEST=MAINCNTL
@MAIN
PRINT MAINCNTL-VTEST
VTEST=MAINCNTL

FOR I=0TO 4999NEXT

LOOPME=LOOPME-1
IF LOOPME>0 GOTO @MAIN

END
About a 30% increase in speed. Just simplified the FOR loop. :D

Petit C is really slow at math and parsing (linebreaks and comments even slow it down!) but when it gets to library functions it is pretty reasonable in speed. So the key to success, I suppose, is to make big loops and keep the source code compact and lean and free of math as humanly possible. :lol:

Anyway, I hope you don't give up on the Mega Man project -- it's super cool. I hope you can complete it.
 

BenRK

Well-Known Member
Member
Joined
Apr 21, 2010
Messages
728
Trophies
0
XP
552
Country
United States
I am curious why you would need to loop nothing 5000 times, but hey, I'm just working on a simple text based dungeon crawler which doesn't need complicated stuff beyond simple scrolling of the map.

So yeah, don't give up!
 

DiscostewSM

Well-Known Member
Member
Joined
Feb 10, 2009
Messages
5,484
Trophies
2
Location
Sacramento, California
Website
lazerlight.x10.mx
XP
5,509
Country
United States
Code:
LOOPME=100
VTEST=MAINCNTL
@MAIN
PRINT MAINCNTL-VTEST
VTEST=MAINCNTL

FOR I=0TO 4999NEXT

LOOPME=LOOPME-1
IF LOOPME>0 GOTO @MAIN

END
About a 30% increase in speed. Just simplified the FOR loop. :D

Petit C is really slow at math and parsing (linebreaks and comments even slow it down!) but when it gets to library functions it is pretty reasonable in speed. So the key to success, I suppose, is to make big loops and keep the source code compact and lean and free of math as humanly possible. :lol:

Anyway, I hope you don't give up on the Mega Man project -- it's super cool. I hope you can complete it.
Looking at your FORNEXT statement, if spaces really do affect performance, then I've got a lot of formatting to do. I'm in the mindset of having my code spaced (or tabbed in a sense) when within subroutines and loops, much like the array example BenRK posted earlier. If removing those spaces increases performance, then I'm sure to reduce my processing time as I have a lot of embedded code in that fashion.

Anyways, I laid awake last night, thinking about ways of improving my code and I think I have some. Already implemented one, and it put me back into 60fps mode for the moment, but I've got a few more to work with. I would be happy if my results showed the "NES slowdown effect" when too much stuff actually happened than to see it when nothing happened at all.
 

DiscostewSM

Well-Known Member
Member
Joined
Feb 10, 2009
Messages
5,484
Trophies
2
Location
Sacramento, California
Website
lazerlight.x10.mx
XP
5,509
Country
United States
Seems I'm going to have sort of a hiatus on programming for a bit, as I am sending in my 3DS for repairs for the 3rd time (with this time being the Start and Power buttons are hard to press). Not a complete hiatus because I can still continue using the PC tools available. I just won't be able to test it until I get my 3DS back.
 

DiscostewSM

Well-Known Member
Member
Joined
Feb 10, 2009
Messages
5,484
Trophies
2
Location
Sacramento, California
Website
lazerlight.x10.mx
XP
5,509
Country
United States
I currently can't test this right now (because my 3DS was sent in for repairs), but could someone test something for me?

I was reading up on BASIC optimizations (which may not necessarily apply here), but one thing that stuck out was "Don't use multi-dimensional arrays". Much of my stuff uses 2-dim arrays, and if this statement is correct even with Petit Computer, then some swapping to 1-dim arrays will be beneficial. So, get your styluses ready! Which of these two programs runs faster (or which one will print the smaller number)?

2-dimensional array
Code:
CLS
MAXX=100
MAXY=100
DIM MYARRAY(MAXX,MAXY)
VLOOP=100
VALUE=0
VTEST=MAINCNTL
@MAIN
FOR Y=0TO MAXY-1
FOR X=0TO MAXX-1
VALUE=MYARRAY(X,Y)
NEXT
NEXT
VLOOP=VLOOP-1
IF VLOOP GOTO @MAIN
VTEST=MAINCNTL-VTEST
PRINT VTEST
WAIT 240
END

1-dimensional array (sized and accessed as if 2-dimensional)
Code:
CLS
MAXX=100
MAXY=100
DIM MYARRAY(MAXX*MAXY)
VLOOP=100
VALUE=0
VTEST=MAINCNTL
@MAIN
FOR Y=0TO MAXY-1
FOR X=0TO MAXX-1
VALUE=MYARRAY(X+(Y*MAXX))
NEXT
NEXT
VLOOP=VLOOP-1
IF VLOOP GOTO @MAIN
VTEST=MAINCNTL-VTEST
PRINT VTEST
WAIT 240
END
 

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
  • No one is chatting at the moment.
    denpafan @ denpafan: swag