Forums

Topic: Petit Computer

Posts 921 to 940 of 9,620

ramstrong

Discostew wrote:

I don't know if anyone has had this problem yet, but when I began hitting the processing limit (in that my frame rate slowed down), all button input that wasn't based off of BUTTON(0) began to have problems and not function (including button states based off of instantly pressed and instantly released). I had to make my own versions of those two button types, so I wrapped them into a single function.

@VSYNCBUTTON

VSYNC 1
BOLD=BT
BT=BUTTON(0)
BTIP=BT AND (NOT BOLD)
BTIR=(BT XOR BOLD) AND (NOT BT)
RETURN

BT is the regular button press one would get from BUTTON(0), but BTIP and BTIR are the other two states from BUTTON(2) and BUTTON(3).

Yes. For some reason, BUTTON 1-3 all take place in 1/60 of a second, so any longer than that, and the input goes missing. I have been relying on BUTTON(0) ever since. I'd do it like this, though:

BTO=BTN
BTN=BUTTON(0)
BTX=BTO XOR BTN
BTP=BTX AND BTN
BTR=BTX AND BTO

Does that make sense?

If you're looking for Petit Asteroid source code: It's out on Petit Computer Journal #11. Still raw, though. I'm too busy prepping for Nanowrimo. Will not be updating it unless I'm ahead of schedule.

@Rambler
Hex2Dec? Something like this?

H$="B"
? INSTR("0123456789ABCDEF",H$)

Edited on by ramstrong

Petit Computer Journal
Old site http://ramstrong.blogspot.com

Let's just call a spade, a spade.

3DS Friend Code: 1091-7596-4855

Eel

Wait, INSTR("0123456789ABCDEF",H$) can be used to convert Hex (a single digit) to Dec?
Oh I love you so much right now.

I had no idea INSTR even existed

Edited on by Eel

Bloop.

<My slightly less dead youtube channel>

SMM2 Maker ID: 69R-F81-NLG

My Nintendo: Abgarok | Nintendo Network ID: Abgarok

steriaca

Sorry. I made a mistake in the address it is http://petitcomputer.wikia.com/wiki/Zombie_Horde . Please note, it is still unfinished (and will be finished sometime Wensday, just in time for Haloween Night, All Saints Day, All Souls Day, and Day of the Dead).

My Friend Code is 3368-1310-0690.

tiger667

better way to transfer a hex to "normal" number is VAL("&HB") will return 11, just change the B to whatever the hex number is.

edit: just tried and you don't need the VAL() command at all, just use the hex number anywhere a normal number would be used but with &H in front of it.
ex: A=&HB:?A prints 11

as a plus, this can be used for more than one digit hex. ?&HFF will print 255 (and so on)

Edited on by tiger667

tiger667

Discostew

tiger667 wrote:

better way to transfer a hex to "normal" number is VAL("&HB") will return 11, just change the B to whatever the hex number is.

edit: just tried and you don't need the VAL() command at all, just use the hex number anywhere a normal number would be used but with &H in front of it.
ex: A=&HB:?A prints 11

as a plus, this can be used for more than one digit hex. ?&HFF will print 255 (and so on)

I think what was required was to have a hex string be converted to a number. The VAL method works, but the latter doesn't, as the hex number isn't an actual string. With the VAL method, one could simply append "&H" in front of a literal hex string to make the conversion work.

H$="B12"
A=VAL("&H"+H$)
PRINT A

It also works with negative numbers, though the hex string would require being 5 characters long (ex - "FFFFF"=-1 because there are only 19 bits dedicated to the integer portion of the value. The remaining goes towards the rest, 12 bits for the decimal, and 1 to the sign).

edit
Also works with binary if you have a binary string of 0s and 1s and replace "&H" with "&B"

Edited on by Discostew

Discostew

3DS Friend Code: 4425-1477-0127 | Nintendo Network ID: Discostew

81Rambler

Thanks Ramstrong and Discostew, these methods are exactly what I was looking for

To take things a step further, I would also like to know if it's possible to break down an exsisting number into Binary and break that down into further segments (ie; Turning 55 into 00110111 and then 3 (0011) and 7 (0111) respectively or into even smaller segments ( 00, 11, 01, 00 or 0,3,1,0).

I'm looking to use these to create a much more compact graphical writer for use with a smaller color pallete, but without the need of using whole integers (Perhaps even using ASC to pull 8 bits out of a single character), I think programs that use a smaller color pallete (typically those that intentionally try to emulate the look of classic games) would benefit the most from this.

81Rambler

petiSnail

81Rambler wrote:

Thanks Ramstrong and Discostew, these methods are exactly what I was looking for

To take things a step further, I would also like to know if it's possible to break down an exsisting number into Binary and break that down into further segments (ie; Turning 55 into 00110111 and then 3 (0011) and 7 (0111) respectively or into even smaller segments ( 00, 11, 01, 00 or 0,3,1,0).

I'm looking to use these to create a much more compact graphical writer for use with a smaller color pallete, but without the need of using whole integers (Perhaps even using ASC to pull 8 bits out of a single character), I think programs that use a smaller color pallete (typically those that intentionally try to emulate the look of classic games) would benefit the most from this.

Yea, its not too hard to break an int into its smaller components:

To break down 55 (00110111):
N1=( &B00110111 AND &B11000000 ) / POW(2,6)
answer: 00
N2=( &B00110111 AND &B00110000 ) / POW(2,4)
answer: 11
N3=( &B00110111 AND &B00001100 ) / POW(2,2)
answer: 01
N4=( &B00110111 AND &B00000011 ) / POW(2,0)
answer: 11

The 11's in the numbers on the right line up with the two digits on the left number that you want to find. The operator 'AND' will separate those digits lined up with the 11's. You also have to shrink the resulting number though as the extra 0s on the right will still remain. You do this by dividing (called bit-shifting) by 2 to the power of the number of zeros to the right of the 11's in the second number.
example: POW ( 2 , number of 0s on the right to get rid of )

Edited on by petiSnail

petiSnail

steriaca

steriaca wrote:

I put up half the source code up for my 'haloween project' Zombie Horde up on http://petitcomputer.com/Zombie_Horde . I'll try to finish it by Wensday. Meanwhile, get a head start on putting the code in.

Well, I did it! It is done, at least in source code formate. Good luck typeing it in. Err...wrong adress. Try this one. http://petitcomputer.wikia.com/wiki/Zombie_Horde

Edited on by steriaca

My Friend Code is 3368-1310-0690.

portealmario

can somebody explain the conceps of hexidecimal numbers to me?

meng 😐
3ds friend code:1762-2769-7142

Wheels2050

portealmario wrote:

can somebody explain the conceps of hexidecimal numbers to me?

Hexadecimal is simply a different way of representing numbers. It's useful because computers 'think' in binary - i.e. think in factors of two. While we are used to using decimal numbers in everyday life, it's not a natural numbering system for computers.

First, let's review the decimal system. It has digits 0,1,2,3,.....,9. Now, the way we write a number in any base (be that decimal, binary, hexadecimal etc.) is in the form:

xyzw

If we are in base ten (decimal), we would write the number "one thousand, four hundred and sixty seven" as:

1467 (I know you know this, but I'm trying to keep things flowing well).

Now, what 1467 means is that we have:

1x1000 + 4x100 + 6x10 + 7x1.

1, 10, 100, 1000 etc. are all powers of ten. So we can write the above line as:

1x10^3 + 4x10^2 + 6x10^1 + 7x10^0

so as we read from right to left, each digit indicates the number of tens to the appropriate power that the number contains (so the rightmost is 7 lots of ten to the zero, 6 lots of 10 to the one etc.) Thus, we can write any integer number in this format. Note that the number:

0000000000000001467

is exactly the same number, but for convenience we just discard the left-most zeros.

You may be familiar with binary, which is a similar idea - we just replace the powers of ten with powers of two.

so:

1011011

would be:

1x2^6 + 0x2^5 + 1x2^4 + 1x2^3 + 0x2^2 + 1x2^1 + 1x2^0

which, if we work out the exponents of 2:

2^0 = 1
2^1 = 2
2^2 = 4
2^3 = 8
2^4 = 16
2^5 = 32
2^6 = 64

So, sticking those back into our expanded formula above, we have:

1x64 + 0x32 + 1x16 + 1x8 + 0x4 + 1x2 + 1x1 = 91 (If I've done my maths correctly)

It's just like the decimal you're used to, just with powers of two.

Now, we can use those same ideas with hexadecimal - now our base is 16. So the right-most digit is the number of sixteen-to-the-zeros, the one to the left the number of sixteen-to-the-ones, etc.

If you look at our decimal numbering system, you'll quickly notice that we only have 10 digits. However, that poses a problem - how do you write the number "14" in hexadecimal?

14 is less than 16^1 (=16), so we need to write it as 14x16^0. However, how do we do that with a single digit? (which is the idea - a number should only have one 'digit' for each power of your base). Thus, it was decided to use the beginning of the alphabet. 0-9 are as normal, but we then start with "A" and go on. Thus, when reading hexadecimal, we find:

0-9 = as normal
A = 10
B = 11
C = 12
D = 13
E = 14
F = 15

Thus, to write the number '14' in hexadecimal, we simply write Ex16^0 (or, as it is usually seen, just E). When reading hex, people automatically convert that to mean 14.

So, if we have the number: A48, what does that mean? Just like before, we have:

Ax16^2 + 4x16^1 + 8x16^0, which (remembering A=10) gives us: 10x256 + 4x16 + 8x1 = 2632 in decimal.

Hexadecimal is useful, because to write 2632 in binary, we would require: 101001001000, which is obviously much more unwieldy than A48. Thus, hex is seen a lot in computing.

One final thing is that it's not always obvious what base someone is using. If I write the number:

10011110

how do you interpret that? Is it decimal, is it binary, is it hex, or is it something else entirely? Often contextual clues will tell you, but to be sure there are a variety of schemes. Sometimes you'll see a subscript at the right-hand side of the number (so if the above was binary, it would have a little '2' in subscript on the right-hand side). A common way of denoting hex (such as in the C and C++ programming languages) is to precede it with "0x". Thus, if I wrote:

0x847,

you'd know that it's in hex and not the number "eight hundred and forty-seven".

I hope that helps!

EDIT: Bonus points for telling me what 0x847 is in decimal!

Edited on by Wheels2050

I used to have a blog link here. I'll put it back up when the blog has something to read.

Eel

In case of TL:DR:

Hexadecimal numbers use 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E and F as digits (with A being the equivalent to 10 in decimal and so on).
As you may notice, you can use Hexadecimals to write large numbers with fewer digits.

Edited on by Eel

Bloop.

<My slightly less dead youtube channel>

SMM2 Maker ID: 69R-F81-NLG

My Nintendo: Abgarok | Nintendo Network ID: Abgarok

pHUNTERq

I'm having trouble with my level editor reading graphics files for data. What I'm trying to do is read 400 pixels from a grp file, going to the next line when it gets to the edge, or 255. The thing is that, I have a fairly large grp file, and I want to read 400 pixels from somewhere in the middle, just reading the specific data I need, and I'm having trouble with figuring out an equation where it will give me the starting location of where to read when I give it a number. So lets say I want to load data for the screen at X=2, Y=3, then, 2 x 3 = 6, so I put that number in and load the appropriate screen.

I've been busting my brain on this for a while, and I can't come up with something that works, so if someone could kindly push me in the right direction, I would be grateful

3DS Friend Code: 2105-8964-7467

Discostew

pHUNTERq wrote:

I'm having trouble with my level editor reading graphics files for data. What I'm trying to do is read 400 pixels from a grp file, going to the next line when it gets to the edge, or 255. The thing is that, I have a fairly large grp file, and I want to read 400 pixels from somewhere in the middle, just reading the specific data I need, and I'm having trouble with figuring out an equation where it will give me the starting location of where to read when I give it a number. So lets say I want to load data for the screen at X=2, Y=3, then, 2 x 3 = 6, so I put that number in and load the appropriate screen.

I've been busting my brain on this for a while, and I can't come up with something that works, so if someone could kindly push me in the right direction, I would be grateful

Are you trying to access the GRP section like an array (with a range from 0 to 49151), indexing it with a single value? Try the following line...

VALUE=GSPOIT(IDX AND 255,IDX / 256)

Where IDX is the value that ranges from 0 to 49151. Increment IDX to get the very next byte, whether that is the next pixel on the line, or the first pixel on the next line.

About your method earlier. 2x3 may equal 6, but with a GRP file, acting like an image, getting data at (2,3) would actually use the formula ((y * 256)+x), making it ((3*256)+2)=770. So, with the line I displayed earlier, you can set IDX to 770, and increment IDX after you read each byte, and it'll increment sequentially, because 770 AND 255 = 2, and 770 / 256 = 3.0078 (but the GSPOIT function only accepts integers, so it floors it automatically to 3).

Edited on by Discostew

Discostew

3DS Friend Code: 4425-1477-0127 | Nintendo Network ID: Discostew

ramstrong

@petiSnail
Great explanation! Are you going to post it on Petit Tutorial thread?

I wrote a simple program for the algorithm:
CLS
?"FOR BITS:"
?"DEC:1=10;2=100;3=1000"
?"BIN:1=2;2=4;3=8;4=16"
INPUT "NUMBER,BITS";N,B
@LOOP
?N%B
N=FLOOR(N/B)
IF N!=0 GOTO @LOOP
?"DONE!"

SAMPLE OUTPUT
55,16
7
3

55,4
3
1
3

123456,100
56
34
12

Petit Computer Journal
Old site http://ramstrong.blogspot.com

Let's just call a spade, a spade.

3DS Friend Code: 1091-7596-4855

Hairmanban19

hey swordx my 3DS friend code is 3136-7615-5907 please register me i have already registered you

...

3DS Friend Code: 3136-7615-5907

portealmario

Wheels2050 wrote:

portealmario wrote:

can somebody explain the conceps of hexidecimal numbers to me?

Hexadecimal is simply a different way of representing numbers. It's useful because computers 'think' in binary - i.e. think in factors of two. While we are used to using decimal numbers in everyday life, it's not a natural numbering system for computers.

First, let's review the decimal system. It has digits 0,1,2,3,.....,9. Now, the way we write a number in any base (be that decimal, binary, hexadecimal etc.) is in the form:

xyzw

If we are in base ten (decimal), we would write the number "one thousand, four hundred and sixty seven" as:

1467 (I know you know this, but I'm trying to keep things flowing well).

Now, what 1467 means is that we have:

1x1000 + 4x100 + 6x10 + 7x1.

1, 10, 100, 1000 etc. are all powers of ten. So we can write the above line as:

1x10^3 + 4x10^2 + 6x10^1 + 7x10^0

so as we read from right to left, each digit indicates the number of tens to the appropriate power that the number contains (so the rightmost is 7 lots of ten to the zero, 6 lots of 10 to the one etc.) Thus, we can write any integer number in this format. Note that the number:

0000000000000001467

is exactly the same number, but for convenience we just discard the left-most zeros.

You may be familiar with binary, which is a similar idea - we just replace the powers of ten with powers of two.

so:

1011011

would be:

1x2^6 + 0x2^5 + 1x2^4 + 1x2^3 + 0x2^2 + 1x2^1 + 1x2^0

which, if we work out the exponents of 2:

2^0 = 1
2^1 = 2
2^2 = 4
2^3 = 8
2^4 = 16
2^5 = 32
2^6 = 64

So, sticking those back into our expanded formula above, we have:

1x64 + 0x32 + 1x16 + 1x8 + 0x4 + 1x2 + 1x1 = 91 (If I've done my maths correctly)

It's just like the decimal you're used to, just with powers of two.

Now, we can use those same ideas with hexadecimal - now our base is 16. So the right-most digit is the number of sixteen-to-the-zeros, the one to the left the number of sixteen-to-the-ones, etc.

If you look at our decimal numbering system, you'll quickly notice that we only have 10 digits. However, that poses a problem - how do you write the number "14" in hexadecimal?

14 is less than 16^1 (=16), so we need to write it as 14x16^0. However, how do we do that with a single digit? (which is the idea - a number should only have one 'digit' for each power of your base). Thus, it was decided to use the beginning of the alphabet. 0-9 are as normal, but we then start with "A" and go on. Thus, when reading hexadecimal, we find:

0-9 = as normal
A = 10
B = 11
C = 12
D = 13
E = 14
F = 15

Thus, to write the number '14' in hexadecimal, we simply write Ex16^0 (or, as it is usually seen, just E). When reading hex, people automatically convert that to mean 14.

So, if we have the number: A48, what does that mean? Just like before, we have:

Ax16^2 + 4x16^1 + 8x16^0, which (remembering A=10) gives us: 10x256 + 4x16 + 8x1 = 2632 in decimal.

Hexadecimal is useful, because to write 2632 in binary, we would require: 101001001000, which is obviously much more unwieldy than A48. Thus, hex is seen a lot in computing.

One final thing is that it's not always obvious what base someone is using. If I write the number:

10011110

how do you interpret that? Is it decimal, is it binary, is it hex, or is it something else entirely? Often contextual clues will tell you, but to be sure there are a variety of schemes. Sometimes you'll see a subscript at the right-hand side of the number (so if the above was binary, it would have a little '2' in subscript on the right-hand side). A common way of denoting hex (such as in the C and C++ programming languages) is to precede it with "0x". Thus, if I wrote:

0x847,

you'd know that it's in hex and not the number "eight hundred and forty-seven".

I hope that helps!

EDIT: Bonus points for telling me what 0x847 is in decimal!

thanks alot! that really helped !
is it 2071?

meng 😐
3ds friend code:1762-2769-7142

Discostew

portealmario wrote:

is it 2071?

Almost. It's 2119.

(8 * 16^2)+(4 * 16^1)+(7 * 16^0)=2048+64+7=2119

Discostew

3DS Friend Code: 4425-1477-0127 | Nintendo Network ID: Discostew

81Rambler

Man, I'm suprised this tread is still going as strong as it is. I'm glad interest in this game is still going on after all this time

I had a question though regarding random dungeon generation. It's basically an area I have little to no idea of how to handle and I was hoping to get a nudge in the right direction.

If anyone's played the Windows 3.1 game Castle of the Winds, I'd like to make my own version of it (with a rule set closer to that of DnD, but I'm still tossing around my own elements) but what I really liked was the style of room generation there in. Would anyone be able to guide me to an algorithm similar to what was used there? (I think the Mysterious Dungeon series used a similar method, typically larger rooms seperated by extended coridors, although I may shorten distances between each)

81Rambler

KiwiFruit

Hi, I'm almost ready to post my game. I have to organize the QR codes since there's 29 of them. There's 12 for the program, 5 for the sprite, 5 for BG tilesheet 1, 6 for BG tilesheet2, and 1 for color. I'll have the QR posted this weekend.

KiwiFruit

Please login or sign up to reply to this topic