Ever since I first unpacked my Net Yaroze my head's been full
of questions; some easy, some hard. This is expected seen as I
got involved with the Net Yaroze project to learn about the
design and development of Playstation software. What I didn't
expect was the sheer amount of questions that would need to be
answered, not only on Net Yaroze coding but on more general
computer terminology. When I first started trying to program my
Net Yaroze I came across many things I didn't understand and seen
as the manuals brushed over these subjects nonchalantly I felt as
though I was expected to know these things already. I admit now
that there were questions I was a little embarrassed to ask.
However, the more I struggle, the less reluctant I am to ask all
those stupid questions.
So, here it is, the questions and answers page for the more inept
coder. This web page is intended to help everyone with no shame
or guilt thrust on anybody. Whether it's to ask a question or to
answer one you can feel easy in the fact that I probably know
less than you. If you want to make any additions to this site
then see the details given at the bottom of the page.
As promised, the Questions & Answers page is a bit more user friendly now. As the number of questions grows it gets more tedious to wade through them all so, hopefully, this slightly new design will make things easier for you. Don't mention it. I need more Yaroze novices to add questions to the site, there must be someone with a niggling little problem that needs solving. So, one and all, keep adding to this page. Oh yeah, just a quick thanks to my regular's who take the time to answer the questions that are put here, you know who you are. Thanks.
Q.(1) I'm currently creating a function which requires a number of long and short variables as part of the formulas within, the variables aren't needed outside the function so I just declare them in the function itself. However, it seems that the function will only accept a certain amount of variables, or a certain amount of memory to be used. When I try to declare over a certain amount of variables, I think it's about 4, when I run the program, instead of the game coming up as usual the Yaroze sort of crashes and displays the normal 'brick background' screen about twice the normal size. Are there any Yaroze rules or C code rules in general that limit the number of variables you can declare at the start of a function? Or could it be something to do with where the code is being stored in memory?
Q. What is a macro?
A. For
some people it's the word 'macro' that catches them out and not
the concept, 'some people' being 'me' in this case. A macro is
best shown by example, take the pre-compiler command - #define
math 9*9 - I'm sure you'll probably recognise this format, if you
don't then it's time to dig out that C manual from under your
bed. This tells the compiler that whenever it sees the word
'math' it substitutes it with '9*9'. For example, 'a=math'
actually compiles as 'a=9*9'. In the case of - #define
math(a,b,c) ((a-b)*(a-c)*(b-c)) - variables are used so when the
compiler sees math(a,b,c), where you can input a,b,c as any
value, the compiler will alter the code accordingly. For example,
'a=math(2,4,6)' would be compiled as 'a=((2-4)*(2-6)*(4-6))'. So
a macro is very much like a function call except all the work is
done by the compiler rather than when the program is running.
They are mainly used to save time when typing out large pieces of
code.
Q. I've seen controller related
variables declared as "volatile u_char *bb0, *bb1;",
what does the 'volatile' part mean?
A. 'Volatile' is used in the same
way as something like 'static', it tells the computer how to
treat a particular variable. In this case 'volatile' tells the
computer that the value of the variable may change without you
actually knowing about it. When a button is pressed on the
control pad the value is stored directly into the memory location
so when you check the memory locations the values will have
magically changed depending on which buttons have been pressed.
Although you are declaring them as variables, you accept that
they may change without your doing.
Q. When setting the ordering table
variables such as"GsOT_TAG
OTTags[2][1<<OT_LENGTH]" I don't understand the
bitwise operator '<<' or what it's use is. Is it best to
understand this now or take it for granted until I become more
familiar with the Yaroze system?
A. The bitwise operator '<<'
means 'shift to the left'. If you imagine the value in binary
format then this operator makes all the bits shift to left by
however many places specified. Take 'a<<3' for example, in
this case the value of 'a' is taken in it's binary format and the
bits are all shifted to the left by 3 places. If it was
'a<<2', then the bits would be shifted by 2 places and so
on. If you have any experience with binary numbers then you'll
know that it's essentially like multiplying the number by a power
of two, 'a<<1' multiplies a by 2, 'a<<2' multiplies a
by 4, 'a<<3' multiplies a by 8. The best way to understand
this is to sit down with a piece of paper and play about with the
binary numbers, it's one of those things that seems complicated
until the answer smacks you in the face like a shovel and it all
makes perfect sense. In the above example the binary bits of the
value 1 are shifted to the left 'OT_LENGTH' places, if you read
the user-guide on ordering tables this may help you understand
why the bit shifting occurs, it sets the range of z values in the
ordering table. For example, an ordering table length of '5' -
'1<<5' - gives a range of 32 z values.
Q. In the Net Yaroze Library Reference
book the function 'GetPadBuf' is described like this: Void
GetPadBuf( volatile unsigned char **buf1, volatile
unsigned char **buf2). Can anyone explain what the '**'
part means in both variables?
A. If you had to take to take a
rough guess you'd probably be right. In C code, the asterisk is
usually associated with pointers and the (multiplication)
operator. In this instance it's something to do with pointers,
it's actually a pointer to a pointer. This may be a little
daunting at first. Just remember, one asterisk is a pointer and
two asterisks is a pointer to a pointer. Now to try and explain,
this means that the underlying
routine can alter the actual address that the pointer 'buf1' is
pointing to. (I've just been re-writing this answer over and over
for the last half an hour and I'm still not sure how to explain
it so I'll get back on the case and finish the answer later,
sorry)
Q. I've seen examples of code where this
statement is used, '#ifndef... //// ...#endif'. It usually
contains a list of '#define' statements, can anyone explain what
this is? (#ifndef and #endif, not #define)
A. '#ifndef' means 'if NOT
DEFINED'. This is a pre-compiler directive which is parsed by the
compiler and is used to affect how your program compiles. If a
program is spread over many files it can be used to make sure
that something is defined only once. If '#ifndef CODE' is used
then '#define CODE' will only be executed if CODE hasn't been
defined already. '#endif' is used to end the '#ifndef' block.
'#ifdef' can also be used, this means 'if DEFINED' and is also
ended by '#endif'. '#ifdef CODE' will only execute the block of
'#define' comments if CODE has already been defined. They work in
the same way as standard if/then/else statements only they're
used in conjunction with '#define' commands. For this reason you
can also use '#else' in the same way. Apparently, these
statements can be very useful when debugging sections of code, to
test whether certain things have been defined or not.
Q. Can someone please tell me the
difference between 'logical' and 'physical' memory space?
A. 'Physical' memory is the actual
'chips' of memory inside the Yaroze whilst 'logical' memory is a
made up address which 'maps' to part of the physical memory.
There really isn't any reason to let this bother you with the Net
Yaroze system. When loading things into the Yaroze memory just
refer to page 39 in the 'User Guide', this is an example of
memory mapping. These are kind of like addresses to the memory,
aslong as you don't try to use parts of the memory that are
allocated to the 'System area' or 'System stack area' you'll be
fine. The other addresses are allocated to the 'Application area'
which is for you to use for your programs.
Q. Having known C code for a while now
I've come across the abs() function time and again. However,
after coming across it again in the Library Reference manual I've
decided to ask a question I should have asked a long time ago.
What exactly is the 'absolute value' and what purpose does it
achieve, any takers?
A. The absolute value just creates
a positive number. abs(4) results in (4) and abs(-4) also results
in (4). This can be used for things like finding the distance
between two co-ordinates, eg. abs(x1-x2), this will always give a
positive number.
Q. Can anyone explain to me what
'dither' or 'dithering' is please?
A. 'Dithering' is the method of mixing pixels to achieve
the illusion of different colours. A simple way of explaining
this is if you had a box, half of which was black and the other
half was white. If you were to dither the colours then the
computer/art package, or in this case the Yaroze, would mix the
pixels where the two colours joined. This would give the
impression, to the human eye, that there is the colour grey
present aswell as the black and white. Dithering is a good way of
making low-bit images look like they've got more colours than
they actually have. It can also 'smooth' images taking the
sharpness out of outlines.
Q. Does
anyone know which control character the gnu compiler uses to read
'long' variables in the printf function? Usually, I use '%ld' but
this doesn't work. I've tried some other letters but I can't get
anything to work.
A. Apparently, the Playstation deals with longs and
integers the same. This is due to it being 32-bit.When it uses an
integer it actually 'pads' out the integer turning it into a
long, it does this because long's are 32-bit in length, you see?
Anyway, when using a 'long' in a FntPrint() function just use the
same control character as an integer, which is '%d'. Remember not
to use '%i', the Yaroze won't accept it.
Q. When creating 'makefiles' I keep
getting a '*** missing seperator' error when I actually try to
'make' the files. I've tried many different methods of creating a
makefile including copying other peoples makefiles but I continue
to get this error. The '*** missing seperator' error is always
situated on the lines where the compiling commands are located
such as:
'gcc -c game.c' or '$(CC) $(OBJS) -o $(PROG)'. Both these lines
and others like them cause the error, can anyone explain why?
A. When creating makefiles you have to insert tabs between
different elements otherwise things can get messed up. Makefiles
are very sensitive to things like this. When typing your 'gcc -c
game.c' line or others similar make sure you put a tab in before
the text. This should stop it happening. If the problem persists
then it is probably due to your text editor. DOS edit doesn't
save tabs properly for instance so using 'notepad' or another
text editor will sort the problem.
Q. I'm not sure of certain variable
formats such as "PACKET GpuPacketArea[2][...." or
"GsOT WorldOT[2]", do these formats work the same as
standard C variables such as 'int', 'char' or 'float'?
A. In this case, PACKET is
actually an unsigned char variable and GsOT is a structure with a
few components inside such as length and org.
This doesn't really matter though, just use them in the function
calls like they are basic types and everything should work fine.
What seems to catch people out are things like using the 'GsOT'
structure but never having to state what variables are contained
within. It's probably best to let the playstation deal with these
things, just refer to the manual when using the specific
structure components and you shouldn't have any bother.
Q. Can anyone tell me where to find
quality documentation on displaying 2D graphics (backgrounds,
sprites, etc.) on the Net Yaroze? A thorough guide for beginners
is prefered.
A. Apparently, someone who's been
having a few problems displaying sprites recommends Ira Rainey's
2D tutorial. This can be found on his website. A background
tutorial can be found on Andy Partington's website, look for
Kung-Fu Coders(tm). For the true beginner, check out James Chow's
website, he's got some good tutorials on the very basics. Not too
shabby.
Q. What does 'VRAM' mean?
A. 'VRAM' stands for 'Video RAM'.
RAM is Random Access Memory, it's basically the computers memory
where it stores all it's code, variables, etc. In this case, it's
probably the 'V' part that catches you out, it's 'V' for 'Video'.
The Net Yaroze's VRAM is the frame buffer where it stores various
images, cluts, display/drawing environments, etc. It's like a big
piece of graph paper 1024 squares across and 512 squares down, in
the Yaroze's case the squares represent pixels. Each pixel is
16bit which means, if you do the sums, the Net Yaroze's frame
buffer, or 'VRAM', is 1MB in size. Page 47 of the Net Yaroze User
Guide explains the frame buffer pretty good.
Q. I was recently looking over a 2D
tutorial by Ira Rainey, which is very good by the way. When
initialising the sprite I came across a line like this- 'rect.x =
tim_data.px;' - which takes the frame buffer x co-ordinate and
puts it in the RECT structure, this is fair enough. However, when
using the Timutil it gives you the option of placing it in the
frame buffer. It's hard to explain but what's the point of
allocating it a place in the frame buffer and it keeping this
information in the file itself if you just have to manually
transport the image and the clut to the frame buffer anyway? I
assume I'm overlooking something pretty basic, please help!
A. A tricky one, this. A couple of
people have had a go at answering this but the problem lies in
understanding the question, I can only try to mix all the answers
together. I think the problem arises due to the fact that the TIM
file holds frame buffer co-ordinates but doesn't have the sense
to put itself there, right? I can understand why this could be
misleading. The benefit of the TIM file holding values like this
is that it makes coding a little easier. If you use Timutil then
you can visually see where all your sprites sit in your frame
buffer and these co-ordinates are saved in the TIM files header
part. Now although the Yaroze doesn't take this information and
automatically put the sprites in the frame buffer it is still
very helpful. When dealing with many sprites and transferring
them from memory to the frame buffer it's easier to just refer to
the necessary frame buffer co-ordinates as sprite.px
instead of the actual numerical values. It's just quicker, in
time you'll probably come to appreciate it. I hope this answers
the question.
Q. When creating backgrounds using the
'GsSortFixBg16' the cells are fixed at 16x16 pixels and the
scaling/rotation abilities are disabled. Are there any functions
that utilise variable cell sizes or have the ability to use the
scaling and rotating variables? If not, why are they included in
the GsBG sructure?
A. Unfortunately, as far as the
people who have replied know, the background rotation/scaling
functions can't be used with the Net Yaroze system. I know, what
a ball-ache, eh? The reason that the rotation/scaling functions
are actually used in certain structures is probably for the use
with the professional Playstation development system. Oh yeah,
that applies to the cell sizes aswell. 16x16 pixel cells are the
only size that you can use as standard (I'm still waiting for
conformation on this).
Q. Is it possible to use arguments in
the Yaroze 'FntPrint()' function like the standard 'printf()'
function? When using the line 'FntPrint("sprite x position=
%i",sprite.x);' where sprite.x holds an
integer value the Yaroze doesn't display the variable part in
it's text. It just prints 'sprite x position= ' on screen. (this question has been rewritten for
clarity. It was one of mine anyway, sorry)
A. Easily solved, use %d
instead of %i when declaring an integer variable. If you put
'FntPrint("this is a number %i, this is a letter
%c"number,letter);' then the text after %i will probably be
omitted which could leave you to believe that other arguments
such as %c don't work either. Just use %d for integers and
everything should run smoothly. The Yaroze doesn't accept '%i'.
As they say in America, 'Go figure...'.
Q. When looking over tuto0.c provided in
the quick directory of Sony's Net Yaroze PC files ( the one that
prints 'hello world!' on screen) it load's a font from the frame
buffer area without putting one there beforehand (960,256 in the
frame buffer), is this a default font that is always there and
can you load any different fonts to replace this?
A.The FntLoad() function actually
loads font patterns 'to' the frame buffer and not 'from' the
frame buffer, it loads the font pattern to the co-ordinates
specified in the FntLoad(x,y) arguments. There is a default font
contained in the Yaroze libraries apparently, so that is where it
comes from. As yet, I don't think there are any easy ways to
change the Yaroze fonts although there are some thoughts floating
around about how it can be done. You could write your own font
writing program if you have the patience.
Q. In the GsCELL structure, the unsigned
short flag holds inversion information. After
experimenting with the values held by flag and following
the bit chart in the Library Reference book I still don't see any
change with the cells in my background. Can anyone explain how to
change the values of flag and what affect vertical and
horizontal inversion actually has on the cells?
A. Like the scaling and rotation
arguments, the inversion flags are not supported by the Yaroze
functions. It's best just to forget about them.
Q. I'm
currently working on a project which requires me to check whether
two lines intersect or not and if they do at which point do they
meet. I know how to do this using algebraic formulas but these
won't work when used with a computer. Does anyone know of any
methods that could be used to solve this 'line intersection'
problem?
A. There are many different ways of
achieving this depending on the different situations that call
for it. The trick is making it as fast and accurate as possible.
To save space I'm not going to put any specific formulas on this
page so if anyone needs any help with this subject get in touch
with me and I'll pass on any information that people have sent to
me.
Q. I've recently tried to make the
transition from 2D to 3D, WOW! Can anyone recommend any good 3D
tutorials?
A. If you look about on the
members website you'll probably find some good ones from Sony
itself, I found the Vectors and Matrices Mini Tutorial by James
Russell-SCEE helpful. Check out Middlesex Uni's website, one of
the tutors there has produced a good 3D tutorial.
*****************************************
Again, I hope this web page gains support from the Net Yaroze members and can be looked upon as a way of support for everyone who is having problems. Obviously, this section will only work if people take part so don't let me down. Feel free to contact me for whatever reason, whether it's to ask a question or to answer one I treat all replies with care and attention.