/// // Hacking around. J Pitts www.playstation.co.uk/~Sig1LL // 29-9-97 /// // This shows how to install an exception handler before the psx kernel // gets control. You can then grab things like bus errors etc. // You could also trap all system calls, and hopefully some decent timers. // The incentive for doing this is to get a good timer suitable for a // music player that would be constant for both NTSC and PAL. // For descriptions of the CAUSE and SR registers look in r3000.h // // -Jim // // Next weeks lesson. How to install your own drivers into the kernel // event tables. // #include extern void ExceptionHandler(void); extern void ExceptionHandlerEnd(void); extern void OldHandler(void); extern void OldHandlerEnd(void); // This should be called for every exception so don't hang around! // I think most exceptions so far come from the vsync. void CallBack(long a0, long a1){ printf ("CAUSE(%x) SR(%x)\n", a0, a1); } /// /// /// void main(void){ int i; long *dest, *src; // install our new handler dest = (long*)0x80000080; src = (long*)ExceptionHandler; EnterCriticalSection(); while (src <= (long*)ExceptionHandlerEnd){ *dest++ = *src++; } ExitCriticalSection(); // let something happen VSync(30); // restore a reasonable handler // its not actually the orig, but its a opcode shorter. ;-) dest = (long*)0x80000080; src = (long*)OldHandler; EnterCriticalSection(); while (src <= (long*)OldHandlerEnd){ *dest++ = *src++; } ExitCriticalSection(); }