Programming for PlayStation 2 - start
Everyone celebrates the new year in different ways.
Someone remembers him, but someone does not.
I stood on the balcony and smoked, watching the fireworks. In general, I was waiting for the disc to burn.
The disc was not a pity for the sake of such an experiment - it was worth it.
This was my first application for PlayStation 2. True, all she could do was display the keyboard and use the joystick to type, but it was already progress!
So, launch! Works!
The very essence
So I begin the series of articles on programming for the PlayStation 2
First, there will be a long theory.
Then practice. Since I am not a professional C ++ (or C - as you like, but I will talk in C ++), then please do not strictly judge the code.
Also, on the PlayStation 2 SDK, it is desirable to use Red Hat 6 or higher, however, I write all this under Windows 7. Although everything works crookedly, it works - okay.
By the beginning of practical experiments, I advise you to have a chip-controlled PlayStation 2 and a network cable. For my experiments, a PlayStation 2 Slim 90006 NTSC-format chip and a blue network cable =) was selected () I did not use iLink mode for debugging, since the drivers in the kit are only for Linux, and I need a hard drive).
Naturally, your games will not be official. I'm even sure that Sony may not forgive such slovenliness. Officially, you can buy support, the SDK and equipment itself, you couldn’t lie for $ 10,000. And they don’t give a license to everyone ...
We are not rich people, so we will go by the way ...
Unofficially, I searched for this SDK for several days, downloaded it for two weeks (or maybe more), figured out a bunch of docks even more. Currently, the SDK is 608 meters, including software, without Visual Studio 6.
So. To begin with, we will have to go through 13 simple chapters (only in some I still have questions that I still understand, for example, a memory card).
I’m going to tell the chapters in the following order:
Controller Library (two chapters are about the joystick and multitap);
CD (DVD) -ROM Library (games can be both on CD and on DVD);
Memory Card Library. (memory card. Two chapters and they are very difficult to understand);
PS2 Memory Card FileSystem (FAT memory card file system);
EE Kernel (the most hemorrhoids topic, but worth knowing);
Graphic Library (it will be a long time, but many will wait for this article - I'm sure);
Sound Library (also a lot);
Movie Library (MPEG and IPU);
Network Library (work with the network and everything related to it);
Hard Disk Library (I do not have a hard disk, so I will only talk about it in theory);
Pentium 3, FIG knows how much RAM, but I think that's enough 500 meters.
At some point, when it will be possible to get out of the theory, I will post the PlayStation 2 SDK (pennies have not been downloaded, but writing, it seems, does not interfere).
Also, at a certain moment, I will begin to study with you, because I have not yet mastered all the information. I suggest, for now, just writing, but how it goes, I will lay out the SDK and it will be possible to combine.
I am using Metrowerks CodeWarrior 22.214.171.1244. Alas, the PS2 SDK got up normally only there. The compiler is GCC or Visual Studio 6.
For information and those who "can do everything"
The PS2 uses Linux. If my guesses are correct, then this “something” reminds me of Red Hat. Naturally, all files and commands are case sensitive.
You can use threads, but there is only one processor - ARM.
As you know, you have to work with bytes. For example, here is what the response to the stream request includes (type - DBGP_EE_THREADLIST_DATA ):
- Id - stream ID
- Priority - its priority
- Status - the status of the stream, which may include the following types:
- THS_RUN = 0x01 // launched
- THS_READY = 0x02 // ready
- THS_WAIT = 0x04 // pending
- THS_SUSPEND = 0x08 // paused
- THS_WAITSUSPEND = 0xc // while waiting for the suspension (for me this is generally a secret secret)
- THS_DORMANT = 0x10 // inactive thread
- Cause - the actual reason for waiting: 0 - none, 1 - sleep, 2 - sema (i.e. semaphore)
- Waited - semaphore ID
- Wakeupcount - the number of wakeup requests
- Count - the number of times the thread entered the RUN state
- Pc - Command Counter
- Sp - Pointer to the top of the $ 29 stack (thanks to Maccimo )
- Func - Execution Point Address
- Ra - Return Point Address $ 31
- reserved  - Reserved infa
- reserved  - Reserved infa.
Oh yes, if the stream is in RUN state, then the current values are in pc, sp and ra.
As you can see, programming on the PS2 is not the easiest task. You can compare it with programming for a PC only in language and calls to standard functions. Naturally, you need to save on memory. Extra need to be unloaded. If you want to read something from the disk - you need to move the head immediately before reading - the information may become irrelevant. This is a very difficult programming, so evaluate your strength really.
In general, until the next article. I’ll try to post it faster ...
PS : I apologize for not being able to post the PS2 SDK now. But I hope everything will be the next article.
Update : Started writing the first article and remembered.
I forgot to indicate that a regular makefile is being used.
It looks something like this (taken from the first example for the joystick): Your program works with the main function. Your code should work in an infinite loop, i.e. an empty project looks like this:
SHELL = /bin/sh
TOP = /usr/local/sce/ee
LIBDIR = $(TOP)/lib
INCDIR = $(TOP)/include
TARGET = main
OBJS = crt0.o \
LCFILE = $(LIBDIR)/app.cmd
LIBS = $(LIBDIR)/libgraph.a \
PREFIX = ee
AS = $(PREFIX)-gcc
CC = $(PREFIX)-gcc
LD = $(PREFIX)-gcc
DVPASM = $(PREFIX)-dvp-as
OBJDUMP = $(PREFIX)-objdump
RUN = dsedb -r run
RM = /bin/rm -f
CFLAGS = -O2 -Wall -Wa,-al -fno-common
CXXFLAGS = -O2 -Wall -Werror -Wa,-al -fno-exceptions -fno-common
ASFLAGS = -c -xassembler-with-cpp -Wa,-al
DVPASMFLAGS = -g
LDFLAGS = -Wl,-Map,$(TARGET).map -mno-crt0 -L$(LIBDIR) -lm
.SUFFIXES: .c .s .cc .dsm
$(TARGET).elf: $(OBJS) $(LIBS)
$(LD) -o $@ -T $(LCFILE) $(OBJS) $(LIBS) $(LDFLAGS)
$(AS) $(ASFLAGS) $(TMPFLAGS) -o $@ $< > $*.lst
$(AS) $(ASFLAGS) $(TMPFLAGS) -I$(INCDIR) -o $@ $< > $*.lst
$(DVPASM) $(DVPASMFLAGS) -I$(INCDIR) -o $@ $< > $*.lst
$(CC) $(CFLAGS) $(TMPFLAGS) -I$(INCDIR) -c $< -o $*.o > $*.lst
$(CC) $(CXXFLAGS) $(TMPFLAGS) -I$(INCDIR) -c $< -o $*.o > $*.lst
$(RM) *.o *.map *.lst core *.dis *.elf
int main (void);
int main (void)