| 1 |
Kevin Kofler's doc. Thanks from roms ! |
| 2 |
|
| 3 |
Preliminary doc: |
| 4 |
|
| 5 |
unsigned char DetectLinkInterface(void); (0x8d2572/0x8d2c92/0x949c72) |
| 6 |
Detects if the USB link is usable. Returns 1 (USB preferred) if it is and 2 |
| 7 |
(legacy DBus IO preferred) if it isn't. This routine uses DetectUSB first, |
| 8 |
and then runs a complex test transfer to double-check. This test transfer |
| 9 |
needs to be handled on the receiving side as well, so it is usually easier |
| 10 |
to just use DetectUSB. |
| 11 |
|
| 12 |
short DetectUSB(void); (0x94a174/0x950fdc/0x8864de) |
| 13 |
Quickly detects if the USB link is usable. Returns 0 if USB is available, |
| 14 |
or a non-zero error code if it isn't. |
| 15 |
|
| 16 |
unsigned char DetectReceiveInterface(short allowLIO); (0x8d25a4/0x8d2cc4/0x949ca4) |
| 17 |
Waits for a calculator to connect on either the USB or the LIO interface. |
| 18 |
Returns: |
| 19 |
* 0 if something is detected on the USB link. |
| 20 |
* 2 if allowLIO is non-zero, nothing is detected on the USB link and |
| 21 |
something is detected on the LIO link. |
| 22 |
* 3 if interrupted by the user ([ON] key). |
| 23 |
If you want to wait for something to be received on the USB link, |
| 24 |
DetectReceiveInterface(FALSE) is the function to use, but there's a catch: |
| 25 |
only one calculator can use DetectReceiveInterface for each transfer. (USB is |
| 26 |
a host/client protocol.) You absolutely MUST call USBReset on both calculators |
| 27 |
before using DetectReceiveInterface on the other calculator. This is very much |
| 28 |
unlike the LIO interface, which is peer-to-peer. Also, the other calculator |
| 29 |
MUST call DetectUSB to synchronize with a DetectReceiveInterface call. To sum |
| 30 |
up, for a transfer which is synchronized by the sender (such as a move in a |
| 31 |
turn-based game), the sending calculator should call: USBLinkClose(); |
| 32 |
USBLinkReset(); DetectUSB(); USB_SendData(src,size,2000);, the receiving |
| 33 |
calculator should call: USBLinkClose(); USBLinkReset(); |
| 34 |
DetectReceiveInterface(FALSE); USB_RecvData(src,size,2000);. |
| 35 |
|
| 36 |
short USB_SendData(const void *buffer, size_t size, long timeout); (0x949b86/0x94a36e/0x9433d2) |
| 37 |
Sends size bytes from buffer over the USB link. For "timeout", try 2000. (I |
| 38 |
am not sure this is actually a timeout. AMS always uses 2000, so you should |
| 39 |
do the same.) Returns 0 if successful, some non-0 error code otherwise. |
| 40 |
|
| 41 |
short USB_RecvData(void *buffer, size_t size, long timeout); (0x949c7e/0x94a466/0x9434ca) |
| 42 |
Receives size bytes into buffer from the USB link. For "timeout", try 2000. (I |
| 43 |
am not sure this is actually a timeout. AMS always uses 2000, so you should |
| 44 |
do the same.) Returns 0 if successful, some non-0 error code otherwise. |
| 45 |
|
| 46 |
short USBLinkClose(void); (0x949c6a/0x94a452/0x9434b6) |
| 47 |
This function is used by AMS to finalize a file transfer. |
| 48 |
Returns 0 if successful, some non-0 error code otherwise. |
| 49 |
|
| 50 |
void USBLinkReset(void); (0x94a284/0x950ffe/0x886500) |
| 51 |
This function closes and resets the USB link. It is used by AMS when done with |
| 52 |
an USB transfer, and sometimes also before initiating one. You should always |
| 53 |
call this function when done with a transfer. |
| 54 |
|
| 55 |
void USBCheckReceived(void); (0x9480d4/0x9488bc/0x9416f6) |
| 56 |
Subroutine of DetectReceiveInterface. Checks whether something is received on |
| 57 |
the USB link. See USBCheckStatus. |
| 58 |
Important: The "catch" described for DetectReceiveInterface also applies to |
| 59 |
this subroutine. |
| 60 |
|
| 61 |
short USBCheckStatus(void); (0x949d74/0x94a55c/0x9435c0) |
| 62 |
Subroutine of DetectReceiveInterface. Checks whether USBCheckReceived was |
| 63 |
successful, i.e. something was received on the USB link. USBCheckReceived (or |
| 64 |
possibly some other status checking routine, but that's the one I know about) |
| 65 |
must have been called first for this routine to return meaningful results. |
| 66 |
Returns 1 on success, 0 on failure. |
| 67 |
|
| 68 |
Hacks (AMS 3.00/3.01): |
| 69 |
IsSupportedAMS300: long long at XR_stringPtr-116 is 76021003261f4e75 |
| 70 |
DetectLinkInterface = XR_stringPtr-158 |
| 71 |
DetectReceiveInterface = XR_stringPtr-108 |
| 72 |
|
| 73 |
Hacks (AMS 3.10): |
| 74 |
IsSupportedAMS300: long long at push_offset_array-1112 is 76021003261f4e75 |
| 75 |
DetectLinkInterface = push_offset_array-1154 |
| 76 |
DetectReceiveInterface = push_offset_array-1104 |
| 77 |
|
| 78 |
Hacks (all AMS): |
| 79 |
DetectUSB: address is at DetectLinkInterface+4. |
| 80 |
USBCheckReceived: address is at DetectReceiveInterface+16 |
| 81 |
USBCheckStatus: address is at DetectReceiveInterface+22 |
| 82 |
USB_SendData = USBCheckStatus-494 |
| 83 |
USB_RecvData = USBCheckStatus-246 |
| 84 |
USBLinkClose = USBCheckStatus-266 |
| 85 |
USBLinkReset: address is at DetectLinkInterface+36. |
| 86 |
|
| 87 |
// USB link routines |
| 88 |
#define XR_stringPtr_addr (_rom_call_addr(293)) |
| 89 |
#define push_offset_array_addr (_rom_call_addr(3c4)) |
| 90 |
#define IsSupportedAMS300 IsSupportedUSBAMS /* deprecated */ |
| 91 |
#define IsSupportedUSBAMS() (IsSupportedUSBAMS30x()||IsSupportedUSBAMS31x()) |
| 92 |
#define IsSupportedUSBAMS30x() (*(long long*)(XR_stringPtr_addr-116)==0x76021003261f4e75ll) |
| 93 |
#define IsSupportedUSBAMS31x() (*(long long*)(push_offset_array_addr-1112)==0x76021003261f4e75ll) |
| 94 |
#define DetectLinkInterface30x ((unsigned char(*)(void))(XR_stringPtr_addr-158)) |
| 95 |
#define DetectReceiveInterface30x ((unsigned char(*)(short))(XR_stringPtr_addr-108)) |
| 96 |
#define DetectLinkInterface31x ((unsigned char(*)(void))(push_offset_array_addr-1154)) |
| 97 |
#define DetectReceiveInterface31x ((unsigned char(*)(short))(push_offset_array_addr-1104)) |
| 98 |
#define DetectLinkInterface (IsSupportedUSBAMS31x()?DetectLinkInterface31x:DetectLinkInterface30x) |
| 99 |
#define DetectReceiveInterface (IsSupportedUSBAMS31x()?DetectReceiveInterface31x:DetectReceiveInterface30x) |
| 100 |
#define DetectUSB (*(short(**)(void))(DetectLinkInterface+4)) |
| 101 |
#define USBCheckReceived (*(void(**)(void))(DetectReceiveInterface+16)) |
| 102 |
#define USBCheckStatus (*(short(**)(void))(DetectReceiveInterface+22)) |
| 103 |
#define USB_SendData ((short (*)(const void *, size_t, long))(USBCheckStatus-494)) |
| 104 |
#define USB_RecvData ((short (*)(void *, size_t, long))(USBCheckStatus-246)) |
| 105 |
#define USBLinkClose ((short(*)(void))(USBCheckStatus-266)) |
| 106 |
#define USBLinkReset (*(void(**)(void))(DetectLinkInterface+36)) |
| 107 |
|
| 108 |
Possible hacks: |
| 109 |
DetectLinkInterface: search for 76021003261f4e75, subtract 42. (Backwards |
| 110 |
search from XR_stringPtr=0x2d2610? XR_stringPtr-158?) |
| 111 |
DetectReceiveInterface: search for 76021003261f4e75, add 8. (Backwards |
| 112 |
search from XR_stringPtr=0x2d2610? XR_stringPtr-108?) |
| 113 |
USB_SendData = USBLinkClose-228 |
| 114 |
USB_RecvData = USBLinkClose+20 |
| 115 |
|
| 116 |
Signatures: |
| 117 |
USB_SendData, USB_RecvData: 4e56ffe848ee1c18ffec4a79 |
| 118 |
USB_LinkClose: 3f3900008xxx4ebafdc8548f (xxx=55C for 3.00, 560 for 3.01, a84 for 3.10) |