ARS Action Replay File Server Release 2 for CodeWarrior and GNU C ©1997,1998 by Craig Graham. Summary: High speed file server for development work on the Sony Yaroze Playstation. This program is intended for use with a system comprising all of the the following: IBM PC compatible with Win95. Sony Yaroze Playstation Metrowerks ‘Code Warrior’ development tools (optional). Datel Electronics ‘Action Replay’ card for Playstation Datel Electronics ‘Pro Comms Link’ card for Action Replay. You need all of this - it won’t work without any single component. Disclaimer: I am aware that several Hacker toolsets are available on the net (Caetla from Japan, and EZ-o-Ray from Europe) that provide this functionality, but unlike them, ARS does not: allow any development without a licensed Yaroze toolset require or attempt to re-program the action replay cards flash memory provide any form of assistance for hacking a Playstation. It simply performs as a high speed File Server and console log for the Yaroze. 1. Introduction Ok, why ARS? Well, Action Replay File Server. What about the ‘F’? ARFS isn’t as funny…. Anyway, here’s what ARS does…. ARS provides high speed file loading and diagnostics printing from a Yaroze via a Datel Electronics ‘Action Replay’ card plus their ‘PC-Pro Comms Link’ add-on card. 1.1 What Do You Get? File Loading From The PC Hard Drive. Multiple files can be opened at the same time, with read access only. Quick Load - bload is supported. Speed. Well, the main advantage is the speed - the file loading is about 20 times faster than the MetroWorks Code Warrior file server. Reliability. The CW fileserver has a habit of locking up - this one doesn't. Diagnostics / Debug Printing. Printing to the Action Replay is much much faster than the serial debug print that the Playstation is capable of - this is due to the higher bandwidth link (2Mbit/sec) and also the fact that the Playstation's serial port doesn't work very well. 1.2 New Stuff In This Version Quite radical really: Support for GNU C, I’ve put in some new stuff on retries to prevent the link from locking up. cg_fsinit() is now a function which does some tricky stuff to hook into the Playstation OS kernal jump table to redirect file access and printf’s at a much lower level. Cool, ‘coz it means we now catch all the Playstation OS messages (like “ResetGraph:jtb=…”) on the ARS console instead of them coming up in the slow serial debug window. One new call cg_shutdown() which you should call before your program exits to unhook all the vectors ARS stole. 2. Setting Up ARS The system is in two parts: The PC server software ARS.EXE The Playstation file i/o library (ar_lib.lib for CodeWarrior or libar.a for GNU C). In order to get it all working follow these easy steps: Buy a Yaroze from Sony. Order Code Warrior with it. Buy an Action Replay + Pro Comms Link from Datel. Cost’s about 90pounds (UK). Plug the Action Replay into the Yaroze. And follow Datel’s instructions for setting it up with the PC link - make a note of the IO port the PC link is on. Once that works, go on to step 4. Put ARS.EXE anywhere in your path (put it in with your yaroze tools if you like). 2.1 Setting Up ARS (Code Warrior) Put ar_lib.lib in your Code Warrior libs directory (same directory as libps.lib). Put ar_lib.h in your includes directory. Ok, it’s installed. Easy eh? 2.2 Setting Up ARS (GNU C) Put libar.a in your GNU C libs directory (same directory as libps.a). Put ar_lib.h in your includes directory. Ok, it’s installed. Easy eh? To use ARS from a GNU C program, compile with the following command line: gcc -g -DAR_DEBUG main.c -lar You can leave out the -g if you don’t want a debug build. To remove ARS support, compile with: gcc -g main.c Testing ARS I’ve provided a test program ‘test_ars’ which will just check out the link for you. So, build it (it should build and link fine). Start your Yaroze. Now, run ARS.EXE. >ars You should have made a note of the IO port that the Action Replay card is installed on - mine is on port 0x320, which is what ARS will default to - if your Action replay is on a different port, you have to tell ars what port using the /I command line switch: eg. >ars /I3f0 would set the Action Replay’s IO port as 0x3f0 Now, using the Code Warrior debugger run test_ars. You should see in the ARS window the following: AR FileServer For Playstation | IOPORT=320 | quiet=OFF | online | activity: Action Replay FileServer Version:Dec 30 1997 (C)1997,by Craig Graham ============ Ready... PLAYSTATION CONNECT (Yaroze+CodeWarrior) Testing The ARS FileServer Library testing:0 testing:1 testing:2 testing:3 testing:4 testing:5 testing:6 testing:7 testing:8 testing:9 **ERROR, FILE [\foo_bar.psx] NOT FOUND That’s fine, the error message is caused by the open command failling - good, as the file doesn’t exist. The code for testars is below: #include #include #include #include main() { long file_handle,f; // Connect to ars cg_fsinit(); // Print some diags printf("Testing The ARS FileServer Library\n"); for(f=0; f<10; f++) printf("testing:%d\n",f); // Open a file - we know it doesn't exist, but it's only a test // isn't it? file_handle=open("cdrom:\\foo_bar.psx",O_RDONLY); cg_shutdown(); } 3. The AR_LIB Library The ar_lib library provides the following functions for using ARS. void cg_fsinit(void); This function must be called before you do any file i/o or printf’s. It does two things: Patches the Playstation OS kernal jump table to install redirected file I/O and printf functions. Send’s a message to the ARS program on the PC to tell it the Yaroze is ready to play... ar_rw(‘R’); Call it first at the start of your program (in the same place as you would have called MWRedirectIO() ) to signal that the Playstation wishes to reconnect to the ARS server on the PC. void cg_shutdown(void); This function must be called just before your program exits. It simply un-hooks all the patched kernal jump table vectors so your program will exit cleanly without having to reset the Yaroze every time. long cg_fopen(char *fname, int mode); Open a file on the PC via ARS. 16 files at once is the max. Parameters: fname = Filename to open. Paths are relative to where you run ARS from, or if you use a \\ prefix, they are relative to the root directory of the PC’s hard drive. Mode = file open mode - in fact, this is ignored and O_RDONLY is used all the time… Returns: a file handle, or -1 if the file doesn’t exist. void cg_fclose(int handle); Close a file openned on the PC via ARS. Parameters: handle = a valid file handle returned from cg_fopen. long cg_fread(int handle, char *buf, long num); Read bytes from a file opened on the PC via ARS. Parameters: handle = a valid file handle returned from cg_fopen. buf = pointer to a buffer large enough to hold the data read num = number of bytes to read Returns: number of bytes actually read (this may be less than num if end of file is reached). long cg_bload(char *fname, unsigned char *buf); Read in a whole file at once (bypass the file handles & stuff) Parameters: fname = filename to load buf = pointer to a buffer big enough for the file. Returns: Number of bytes read (ie. Length of the file). void cg_print(char *t); Print text to the ARS console You can embed ANSI colour coding escapes into the string to get coloured printout. Parameters: t = pointer to a C-String (ie. ‘\0’ terminated) int cg_printf(char *fmt,…); Formatted print (just like standard C printf), to the ARS console. Parameters: Just like standard printf, except that the only escapes recognised are: %d decimal %ld long decimal %x hexidecimal %lx long hexidecimal %c character %s string Don’t try to use complex formatting like %.2d, ‘coz it won’t work. asm unsigned char ar_rw(unsigned char v); Low level byte read/write to the Action Replay comms channel This will read from the Action Replay comms channel before writing to it. This is important to remember if you use it to write your own functions into the server. Parameters: v = character to transmit Returns: character received. Doing It The Easy Way…Part 1 To develop stuff that isn’t ARS specific, I’ve provided a simple define (just like the Metrowerks DEBUG_IO define). If you include ar_lib.h everywhere, then define AR_DEBUG in your NY_Debug_Prefix.h file, the standard Playstation file I/O functions are redefined as ARS file i/o functions (in the same way as Metrowerks does). #define AR_DEBUG If AR_DEBUG is defined, here are the functions that get re-defined: #define open(n,f) cg_fopen((n)+6,(f)) #define close(d) cg_fclose((d)) #define lseek(d, o, f) 0 #define read(d, b, n) cg_fread((d),(b),(n)) #define write(d, b, n) 0 #define bload(n, a) cg_bload((n),(a)) #define printf cg_printf NOTE: the define for open includes a +6 to skip past the usual cdrom: prefix that filenames usually have on a PSX. Take out the AR_DEBUG define, and all functions will revert back to standard definitions…. Doing It The Easy Way…Part 2 Release 2 of ARS has support for kernal level redirected IO. Instead of having to include ARLIB.H everywhere, just call cg_fsinit() once at the start of your program and use standard Yaroze file access (without the defines). The Playstation OS file access functions are patched to use the ARS fileserver routines instead. The AR_DEBUG define still switches ARS file loading on and off (if it isn’t defined, the call to cg_fsinit() does nothing). 4. ARS - How to use it Command line switches to ARS are: /I Set ARS to use an Action Replay Pro Comms Link card on io port eg. ars /I3f0 would use IO port 0x3f0 /Q Quiet mode - suppress informative messages when files are opened/closed/read from. This can tidy things up a little, but you won’t know exactly what is going on. /N No activity indicator. The DOS prompt’s character I/O is surprisingly slow - and the regular flashing of the activity indicator slows file access down a bit. If you find it a problem, use this switch to disable the activity light and get slightly faster transfers (much faster on a slow machine) ARS In Use: The ARS has two areas - the status line at the top of the screen, and the console area (filling the rest of the screen). The status line gives the following information: AR FileServer For Playstation | IOPORT=320 | quiet=OFF | online | activity: IOPORT The hex io port that ARS is using to talk to the Action Replay Pro Comms link card online Is displayed if the playstation has connected to ARS. Activity: A letter ‘I’ will flicker next to the word ‘activity’ to show that data is passing between the PC and the Playstation. The main console are prints up messages saying what is happening as follows. Diagnostics messages from cg_print() / cg_printf() are displayed in: White Reconnect/response to cg_fsinit() is shown as white on green: PLAYSTATION CONNECT (Yaroze+CodeWarrior) File Server commands (open/read/close/bload) are show as: **SERV_MESSAGE IN GREEN Error messages are shown in red: **ERROR: Will display in red Keyboard: Once running ARS has only two keys that do anything: ESCAPE Exit the program ‘R’ If you have re-flashed your Ation Rplay with the EZ-O-RAY rom image, then hitting ‘r’ will do a fast reboot of the Yaroze. I don’t advocate using the EZ-O-RAY rom, but if you do, this is a useful function….. The ARS File Server For Yaroze Page PAGE 2