For C Experts...
Displaying 1-7 of 7 total.
1
Please enter a numerical value for the importance of this sticky.
Enter 0 to unsticky.
Nabucodonosor

Sorry for asking questions about C, but I'm trying to convert a code to Verge. But what in the hell are:

byte *z
byte *p=buffer-line[0]
*(p+offset)=c
offset = j-319-(p)%320+(p)*320

What is this '*' before z and p? And the '-' is for what? I have problems with the '%' character in the code too... Thanks for any help.



Posted on 2001-01-09 20:00:04

Nabucodonosor

When I wrote 'byte *p=buffer-line[0]'
it's not '-' between buffer and line, but a character that I can't write because the board cut it. It's the character after the letter M in your keyboard. So I want to know what '-' + CHR(062) means...


()
...just testing



Posted on 2001-01-09 20:05:27

Lunarbeam

Okies, first of all the * symbol means that you're declaring a pointer. A pointer is a special type of variable that, instead of holding an actual value, holds the address of a place in memory where a value is stored. Performing mathematical operations on pointers (subtraction, addition) causes them to move to the respective place in memory. For instance, a pointer that is at 2 in the memory that has 3 added to it will now 'point' to 5 in memory. This is especially useful for reading information that you know is going to be sequentially placed in memory, i.e. arrays.

The % operator is called the modulo (modulus?). It returns the 'remainder' after division. For instance, the modulo of 7 and 3 is 1, since 1 is the remainder of the division operation.

Im not so sure about the last one (<) coupled with -but the < symbol alone is called a comparison operator; it returns 0 if the number on the right is larger or 1 if the number on the left is larger or vice versa depending on which one you use. Other comparison operators are == and !=.



-- Lunarbeam @

Posted on 2001-01-09 20:53:28

andy

byte *z
byte *p=buffer->line[0]
*(p+offset)=c
offset = j-319-(p)%320+(p)*320

I'm guessing that buffer-line[0] is supposed to be buffer->line[0], since < doesn't have any special meaning there.

z and p are pointers to bytes, not bytes. Think of them as a finger that points to a spot in memory.

Given the context, buffer is also a pointer, but a pointer to a struct. That's why the -> isn't a period.

*(p+offset)=c; basicly says "take the spot that p points to, skip past it offset bytes, and store c there".
That last line is pretty funky stuff, but it looks like it's for a pixel plotting function of some description. % is modulus. If x%y=z, then z is the remainder when x is divided by y. 9%3=0 10%3=1 15%7=1 etc...



'Never confuse a single defeat with a final defeat.' -F. Scott Fitzgerald

Posted on 2001-01-09 21:11:36

Nabucodonosor

Thanks for the help, it was exactly what I wanted to know. Now I want to know if there is a way to use them in Verge. The '%' I know I can use directly, but the others... Thanks anyway...



Posted on 2001-01-09 23:40:59

Lunarbeam

I've been using C++ so long that I completely forgot about structs!



-- Lunarbeam @

Posted on 2001-01-10 01:29:08

Feyr

It's not possible to give you the exact VC code without seeing the struct definition for buffer. What you would need to do goes something like this:

1. Decide on a format for the buffer struct. In order to handle a dynamically created struct in Verge, you'd need to use malloc to allocate a chunk of memory, and pretend that chunk is actually a structure...for example, you could decide that bytes 0 through 319 represent line[0] array, bytes 320 through 639 represent line[1], etc, plus byte positions for whatever other members of the struct exist.

2. Malloc a chunk of memory for a given buffer, like this:
local int buffer;
buffer = malloc(SIZE_OF_BUFFER_STRUCT);

3. Stick this code wherever it's supposed to go:
local int z, p, offset;
p = byte[buffer+LINE0_OFFSET];
byte[p+offset] = c
offset = j-319-(byte[p] % 320)+(byte[p]*320);

4. Fill in whatever supporting code it needs (like the declarations and uses of the c and z)

There's a fair chance that you didn't understand that, since you apparently don't know how to use pointers in C...if that's the case, I'd suggest getting a good programming book or online tutorial and reading up on them =) When you understand pointers, come back and read about the byte, word and quad quasifunctions in Verge, and see if you can make the transition from there. Good luck.

--Feyr



Posted on 2001-01-11 21:46:52


Displaying 1-7 of 7 total.
1
 
Newest messages

Ben McGraw's lovingly crafted this website from scratch for years.
It's a lot prettier this go around because of Jon Wofford.
Verge-rpg.com is a member of the lunarnet irc network, and would like to take this opportunity to remind you that regardless how babies taste, it is wrong to eat them.