|
| 1 | +#include "s16debug.h" |
| 2 | +#include <stdarg.h> |
| 3 | +#include <stdio.h> |
| 4 | +#include <string.h> |
| 5 | +#include <ctype.h> |
| 6 | + |
| 7 | +#include <tcpip.h> |
| 8 | +#include <tcpipx.h> |
| 9 | + |
| 10 | +#pragma optimize 79 |
| 11 | +#pragma noroot |
| 12 | + |
| 13 | +static char buffer[512]; |
| 14 | + |
| 15 | +static Word CheckSweet16(void) |
| 16 | +{ |
| 17 | + static Word Sweet16 = -1; |
| 18 | + if (Sweet16 == -1) |
| 19 | + { |
| 20 | + /* |
| 21 | + * Apple II tech note 201 |
| 22 | + */ |
| 23 | + word emu_id = 0; |
| 24 | + word emu_version = 0; |
| 25 | + asm { |
| 26 | + // the lda ..,x is to prevent |
| 27 | + // the 2nd lda from being optimized out. |
| 28 | + lda #0 |
| 29 | + ldx #0 |
| 30 | + sep #0x20 |
| 31 | + sta >0x00c04f,x |
| 32 | + lda >0x00c04f,x |
| 33 | + sta <emu_id |
| 34 | + lda >0x00c04f,x |
| 35 | + sta <emu_version |
| 36 | + rep #0x20 |
| 37 | + } |
| 38 | + |
| 39 | + if (emu_id == 0x16 && emu_version >= 0x23) Sweet16 = 1; |
| 40 | + else Sweet16 = 0; |
| 41 | + } |
| 42 | + |
| 43 | + return Sweet16; |
| 44 | +} |
| 45 | + |
| 46 | +void s16_debug_puts(const char *str) |
| 47 | +{ |
| 48 | + if (!CheckSweet16()) return; |
| 49 | + |
| 50 | + asm { |
| 51 | + ldx <str+2 |
| 52 | + ldy <str |
| 53 | + cop 0x84 |
| 54 | + } |
| 55 | +} |
| 56 | + |
| 57 | + |
| 58 | +void s16_debug_dump(const char *bytes, unsigned length) |
| 59 | +{ |
| 60 | + static const char *HexMap = "0123456789abcdef"; |
| 61 | + |
| 62 | + if (!CheckSweet16()) return; |
| 63 | + |
| 64 | + while (length) |
| 65 | + { |
| 66 | + Word i, j, l; |
| 67 | + l = 16; |
| 68 | + if (l > length) l = length; |
| 69 | + |
| 70 | + memset(buffer, ' ', sizeof(buffer)); |
| 71 | + |
| 72 | + for (i = 0, j = 0; i < l; ++i) |
| 73 | + { |
| 74 | + unsigned x = bytes[i]; |
| 75 | + buffer[j++] = HexMap[x >> 4]; |
| 76 | + buffer[j++] = HexMap[x & 0x0f]; |
| 77 | + j++; |
| 78 | + if (i == 7) j++; |
| 79 | + |
| 80 | + buffer[50 + i] = isascii(x) && isprint(x) ? x : '.'; |
| 81 | + } |
| 82 | + |
| 83 | + buffer[50 + 16 + 1] = 0; |
| 84 | + s16_debug_puts(buffer); |
| 85 | + |
| 86 | + length -= l; |
| 87 | + bytes += l; |
| 88 | + } |
| 89 | + |
| 90 | +} |
| 91 | + |
| 92 | +void s16_debug_printf(const char *format, ...) |
| 93 | +{ |
| 94 | + // need to format the data even if sweet-16 is |
| 95 | + // not present in order to clean up the stack. |
| 96 | + |
| 97 | + va_list ap; |
| 98 | + va_start(ap, format); |
| 99 | + vsnprintf(buffer, sizeof(buffer), format, ap); |
| 100 | + va_end(ap); |
| 101 | + |
| 102 | + s16_debug_puts(buffer); |
| 103 | +} |
| 104 | + |
| 105 | +//--- |
| 106 | + |
| 107 | +void s16_debug_srbuff(const srBuff *sb) |
| 108 | +{ |
| 109 | + if (!CheckSweet16()) return; |
| 110 | + |
| 111 | +/* |
| 112 | + s16_debug_printf("%04x %04x %08lx %08lx %08lx %04x %04x %04x", |
| 113 | + sb->srState, |
| 114 | + sb->srNetworkError, |
| 115 | + sb->srSndQueued, |
| 116 | + sb->srRcvQueued, |
| 117 | + sb->srDestIP, |
| 118 | + sb->srDestPort, |
| 119 | + sb->srConnectType, |
| 120 | + sb->srAcceptCount |
| 121 | + ); |
| 122 | +*/ |
| 123 | + |
| 124 | + s16_debug_printf(" srState: $%04x", sb->srState); |
| 125 | + s16_debug_printf(" srNetworkError: $%04x", sb->srNetworkError); |
| 126 | + s16_debug_printf(" srSndQueued: $%08lx", sb->srSndQueued); |
| 127 | + s16_debug_printf(" srRcvQueued: $%08lx", sb->srRcvQueued); |
| 128 | + s16_debug_printf(" srDestIP: $%08lx", sb->srDestIP); |
| 129 | + s16_debug_printf(" srDestPort: $%04x", sb->srDestPort); |
| 130 | + s16_debug_printf(" srConnectType: $%04x", sb->srConnectType); |
| 131 | + s16_debug_printf(" srAcceptCount: $%04x", sb->srAcceptCount); |
| 132 | + |
| 133 | +} |
| 134 | + |
| 135 | + |
| 136 | + |
| 137 | +void s16_debug_tcp(unsigned ipid) |
| 138 | +{ |
| 139 | + userRecordPtr ur; |
| 140 | + userRecordHandle urh; |
| 141 | + |
| 142 | + if (!CheckSweet16()) return; |
| 143 | + |
| 144 | + urh = TCPIPGetUserRecord(ipid); |
| 145 | + |
| 146 | + if (!urh) return; |
| 147 | + |
| 148 | + ur = *urh; |
| 149 | + if (!ur) return; |
| 150 | + if (!ur->uwUserID) return; |
| 151 | + |
| 152 | + // -- auto-generated -- |
| 153 | + |
| 154 | + s16_debug_printf(" uwUserID: $%04x", ur->uwUserID); |
| 155 | + s16_debug_printf(" uwDestIP: $%08lx", ur->uwDestIP); |
| 156 | + s16_debug_printf(" uwDestPort: $%04x", ur->uwDestPort); |
| 157 | + s16_debug_printf(" uwIP_TOS: $%04x", ur->uwIP_TOS); |
| 158 | + s16_debug_printf(" uwIP_TTL: $%04x", ur->uwIP_TTL); |
| 159 | + s16_debug_printf(" uwSourcePort: $%04x", ur->uwSourcePort); |
| 160 | + s16_debug_printf(" uwLogoutPending: $%04x", ur->uwLogoutPending); |
| 161 | + s16_debug_printf(" uwICMPQueue: $%08lx", ur->uwICMPQueue); |
| 162 | + s16_debug_printf(" uwTCPQueue: $%08lx", ur->uwTCPQueue); |
| 163 | + s16_debug_printf(" uwTCPMaxSendSeg: $%04x", ur->uwTCPMaxSendSeg); |
| 164 | + s16_debug_printf(" uwTCPMaxReceiveSeg: $%04x", ur->uwTCPMaxReceiveSeg); |
| 165 | + s16_debug_printf(" uwTCPDataInQ: $%08lx", ur->uwTCPDataInQ); |
| 166 | + s16_debug_printf(" uwTCPDataIn: $%08lx", ur->uwTCPDataIn); |
| 167 | + s16_debug_printf(" uwTCPPushInFlag: $%04x", ur->uwTCPPushInFlag); |
| 168 | + s16_debug_printf(" uwTCPPushInOffset: $%08lx", ur->uwTCPPushInOffset); |
| 169 | + s16_debug_printf(" uwTCPPushOutFlag: $%04x", ur->uwTCPPushOutFlag); |
| 170 | + s16_debug_printf(" uwTCPPushOutSEQ: $%08lx", ur->uwTCPPushOutSEQ); |
| 171 | + s16_debug_printf(" uwTCPDataOut: $%08lx", ur->uwTCPDataOut); |
| 172 | + s16_debug_printf(" uwSND_UNA: $%08lx", ur->uwSND_UNA); |
| 173 | + s16_debug_printf(" uwSND_NXT: $%08lx", ur->uwSND_NXT); |
| 174 | + s16_debug_printf(" uwSND_WND: $%04x", ur->uwSND_WND); |
| 175 | + s16_debug_printf(" uwSND_UP: $%04x", ur->uwSND_UP); |
| 176 | + s16_debug_printf(" uwSND_WL1: $%08lx", ur->uwSND_WL1); |
| 177 | + s16_debug_printf(" uwSND_WL2: $%08lx", ur->uwSND_WL2); |
| 178 | + s16_debug_printf(" uwISS: $%08lx", ur->uwISS); |
| 179 | + s16_debug_printf(" uwRCV_NXT: $%08lx", ur->uwRCV_NXT); |
| 180 | + s16_debug_printf(" uwRCV_WND: $%04x", ur->uwRCV_WND); |
| 181 | + s16_debug_printf(" uwRCV_UP: $%04x", ur->uwRCV_UP); |
| 182 | + s16_debug_printf(" uwIRS: $%08lx", ur->uwIRS); |
| 183 | + s16_debug_printf(" uwTCP_State: $%04x", ur->uwTCP_State); |
| 184 | + s16_debug_printf(" uwTCP_StateTick: $%08lx", ur->uwTCP_StateTick); |
| 185 | + s16_debug_printf(" uwTCP_ErrCode: $%04x", ur->uwTCP_ErrCode); |
| 186 | + s16_debug_printf(" uwTCP_ICMPError: $%04x", ur->uwTCP_ICMPError); |
| 187 | + s16_debug_printf(" uwTCP_Server: $%04x", ur->uwTCP_Server); |
| 188 | + s16_debug_printf(" uwTCP_ChildList: $%08lx", ur->uwTCP_ChildList); |
| 189 | + s16_debug_printf(" uwTCP_ACKPending: $%04x", ur->uwTCP_ACKPending); |
| 190 | + s16_debug_printf(" uwTCP_ForceFIN: $%04x", ur->uwTCP_ForceFIN); |
| 191 | + s16_debug_printf(" uwTCP_FINSEQ: $%08lx", ur->uwTCP_FINSEQ); |
| 192 | + s16_debug_printf(" uwTCP_MyFINACKed: $%04x", ur->uwTCP_MyFINACKed); |
| 193 | + s16_debug_printf(" uwTCP_Timer: $%08lx", ur->uwTCP_Timer); |
| 194 | + s16_debug_printf(" uwTCP_TimerState: $%04x", ur->uwTCP_TimerState); |
| 195 | + s16_debug_printf(" uwTCP_rt_timer: $%04x", ur->uwTCP_rt_timer); |
| 196 | + s16_debug_printf(" uwTCP_2MSL_timer: $%04x", ur->uwTCP_2MSL_timer); |
| 197 | + s16_debug_printf(" uwTCP_SaveTTL: $%04x", ur->uwTCP_SaveTTL); |
| 198 | + s16_debug_printf(" uwTCP_SaveTOS: $%04x", ur->uwTCP_SaveTOS); |
| 199 | + s16_debug_printf(" uwTCP_TotalIN: $%08lx", ur->uwTCP_TotalIN); |
| 200 | + s16_debug_printf(" uwTCP_TotalOUT: $%08lx", ur->uwTCP_TotalOUT); |
| 201 | + s16_debug_printf(" uwUDP_Server: $%04x", ur->uwUDP_Server); |
| 202 | + s16_debug_printf(" uwUDPQueue: $%08lx", ur->uwUDPQueue); |
| 203 | + s16_debug_printf(" uwUDPError: $%04x", ur->uwUDPError); |
| 204 | + s16_debug_printf(" uwUDPErrorTick: $%08lx", ur->uwUDPErrorTick); |
| 205 | + s16_debug_printf(" uwUDPCount: $%08lx", ur->uwUDPCount); |
| 206 | + |
| 207 | +} |
| 208 | + |
0 commit comments