' ----------------------------------------------------------------------- ' DumpA.bas - Ben Ryves 2007 ' ----------------------------------------------------------------------- ' When run, downloads real variable 'A' off a connected TI-83 Plus, and ' transmits it (formatted as ASCII text) on the serial out pin. ' Due to space limitations (ha!) the formatting is quite crude and won't ' work at extreme levels; -99999999999999..+99999999999999 is the maximum ' range. Leading noughts are, however, handled. ' Reqires a PICAXE-08M for its 256B EEPROM. ' Many thanks to Tim Singer and Romain Liévin's TI Link Protocol Guide. ' Pinout configuration: Symbol Data0 = 1 Symbol Data1 = 2 Symbol Data0Pin = Pin1 Symbol Data1Pin = Pin2 ' Variable allocation: Symbol BitCounter = B13 Symbol ByteToXfer = B12 Symbol CheckBit = B11 Symbol Exponent = B10 Symbol RangeStart = B9 Symbol RangeEnd = B8 ' Entry point: Main: ' Set CPU clock to 8MHz: SetFreq M8 ' Request variable 'A': RangeStart = 0 : RangeEnd = 18 GoSub SendByteRange ' Response from calculator is 23 bytes long; For B0 = 0 To 22 GoSub GetByte Next ' Acknowledge header and CTS: RangeStart = 19 : RangeEnd = 26 GoSub SendByteRange ' Skip first 8 bytes of response: For B0 = 0 To 7 GoSub GetByte Next ' Now we need to decode the data! ' Real number format: ' 1 Flags (if MSB set, it's negative). ' 1 Exponent (+$80) ' 7 Mantissa (Packed BCD). ' Check flag byte for negative: GoSub GetByte If ByteToXfer < $80 Then IsPositive SerTxd ("-") IsPositive: ' Grab exponent into B3: GoSub GetByte Exponent = ByteToXfer - $7F If Exponent < $80 Then PositiveExponent SerTxd (".") For B0 = Exponent To $FF SerTxd ("0") Next PositiveExponent: ' Now, let's read the mantissa and unpack: For B0 = 0 To 6 GoSub GetByte BitCounter = ByteToXfer / $10 GoSub OutPackedDigit BitCounter = ByteToXfer & $0F GoSub OutPackedDigit Next End OutPackedDigit: If Exponent != 0 Then NoExponent SerTxd (".") NoExponent: Exponent = Exponent - 1 SerTxd (#BitCounter) Return ' Data Data (%11001110, %01000101, %10110000, %00000000) Data (%10010000, %00000000, %00000000, %10000010) Data (%00000000, %00000000, %00000000, %00000000) Data (%00000000, %00000000, %00000000, %00000000) Data (%00000000, %01010010, %00000000) Data (%11001110, %01101010, %00000000, %00000000) Data (%11001110, %10010000, %00000000, %00000000) ' GetByte ' Receives a byte from the connected TI calculator. ' Inputs: None. ' Outputs: ByteToXfer (received byte). ' Destroys: BitCounter. GetByte: ByteToXfer = 0 For BitCounter = 0 To 7 ByteToXfer = ByteToXfer / 2 WaitGet: If Data0Pin = Off Then GotBit0 If Data1Pin = Off Then GotBit1 GoTo WaitGet GotBit0: Low Data1 If Data0Pin = Off Then GotBit0 Input Data1 GoTo GotAndUsedBit GotBit1: Low Data0 ByteToXfer = ByteToXfer + $80 If Data1Pin = Off Then GotBit1 Input Data0 GotAndUsedBit: Next Return ' SendByteRange ' Sends a byte range to the connected TI calculator. ' Inputs: RangeStart..RangeEnd (memory range to output). ' Outputs: None. ' Destroys: BitCounter, CheckBit. ' Remarks: Data must be stored backwards; ie, %01100001 would be stored %10000110. SendByteRange: For CheckBit = RangeStart To RangeEnd Read CheckBit, ByteToXfer For BitCounter = 0 To 7 If ByteToXfer >= $80 Then SendBit1 SendBit0: Low Data0 WaitD1L: If Data1Pin = On Then WaitD1L High Data0 WaitD1H: If Data1Pin = Off Then WaitD1H GoTo SentBit SendBit1: Low Data1 WaitD0L: If Data0Pin = On Then WaitD0L High Data1 WaitD0H: if Data0Pin = Off Then WaitD0H SentBit: ByteToXfer = ByteToXfer * 2 Input Data0 Input Data1 Next Next Return