home *** CD-ROM | disk | FTP | other *** search
- #include "patches.h"
- #include <traps.h>
- #include <lowmem.h>
- #include "MacsBugSerialStuff.h"
-
-
- static asm long* GetOldDebugUtilStorage()
- {
- lea _oldDebugUtilStorage,a0
- rts
- _oldDebugUtilStorage:
- dc.l 0x00000000
- }
-
- static asm long* GetCountStorage()
- {
- lea _countStorage,a0
- rts
- _countStorage:
- dc.l 0x00000000
- }
-
-
- static asm long* GetValueStorage()
- {
- lea _valueStorage,a0
- rts
- _valueStorage:
- dc.l 0x00000000
- }
-
-
- static asm long* GetA5Storage()
- {
- lea _a5Store,a0
- rts
- _a5Store:
- dc.l 0x00000000
- }
-
-
- static Boolean KeyIsDown(
- short theKeyCode)
- {
- KeyMap theKeys;
-
- GetKeys( theKeys); /* Get state of each key */
-
- /* Ordering of bits in a KeyMap is truly bizarre. A KeyMap is a */
- /* 16-byte (128 bits) array where each bit specifies the start */
- /* of a key (0 = up, 1 = down). We isolate the bit for the */
- /* specified key code by first determining the byte position in */
- /* the KeyMap and then the bit position within that byte. */
- /* Key codes 0-7 are in the first byte (offset 0 from the */
- /* start), codes 8-15 are in the second, etc. The BitTst() trap */
- /* counts bits starting from the high-order bit of the byte. */
- /* For example, for key code 58 (the option key), we look at */
- /* the 8th byte (7 offset from the first byte) and the 5th bit */
- /* within that byte. */
-
- return( BitTst( ((char*) &theKeys) + theKeyCode / 8,
- (long) 7 - (theKeyCode % 8) ) );
- }
-
- // 16777216
-
- static void memset(Ptr p,char value,long length)
- {
- long z = 0;
- for(z = 0;z<length;z++){
- p[z] = value;
- }
- }
-
- static Ptr GetScreenBase()
- {
- GDHandle h = LMGetMainDevice();
-
- return h[0]->gdPMap[0]->baseAddr;
- }
-
- static long Poll(short selector)
- {
- long continueQ = true;
- long* theA5 = GetA5Storage();
-
- SetA5(*theA5);
-
- if(selector == 1){ // debugger enter
- SerialDriver_SendBytes((unsigned char*)"Yo Dude!",8);
- }
-
- long* value = GetValueStorage();
-
- if(SerialDriver_BytePresent()){
- UInt8 theByte;
-
-
- if(SerialDriver_ReceiveByte(&theByte,10) == noErr){
- if(theByte == 'a'){
- SerialDriver_SendBytes((unsigned char*)"eat me!",7);
- }
- }
-
-
- }
-
- return continueQ;
- }
-
-
- static asm void newDebugUtil()
- {
- subq.l #4,a7 // reserve space for old trap address
- move.l a0,-(a7) // save a0
- movem.l a1-a5/d0-d7,-(a7) // save everything else
-
- move.w d0,-(a7)
- jsr Poll
- addq.l #2,a7
- tst.w d0
- bne.s _Continue
-
- movem.l (a7)+,a1-a5/d0-d7
- move.l (a7)+,a0
- addq.l #4,a7
- rts
-
- _Continue:
-
-
- movem.l (a7)+,a1-a5/d0-d7 // restore registers
-
- jsr GetOldDebugUtilStorage // get original trap address storage in a0
- move.l (a0),a0 // get original trap address value into a0
- move.l a0,4(a7) // stuff old trap onto stack
- move.l (a7)+,a0 // restore original a0
- rts // rts to jump to old trap.
- }
-
- void main()
- {
-
- long* theA5 = GetA5Storage();
- *theA5 = SetCurrentA5();
-
- long* debugUtilStorage = GetOldDebugUtilStorage();
- *debugUtilStorage = PatchTrap(_DebugUtil,(long)newDebugUtil);
-
-
- SerialDriver_Open();
- SerialDriver_SendBytes((unsigned char*)"Go!",3);
-
- Debugger();
-
- }