This file implements the XMODEM 128-byte protocol in both directions. Use with AIDE requires AIDE release 2.500 upwards.
No test code is provided for this file as the system has been tested by comparison of transferred binary files.
1 equ XmodemTx? \ -- n
Non-zero to compile transmit code
1 equ XmodemRx? \ -- n
Non-zero to compile receive code.
$0101 equ blkerror
A block number error has occurred.
$0103 equ noreply
There was no reply within one second.
$0104 equ crcerror
Bad CRC or checksum.
$0105 equ overflow
Too many blocks were sent.
$010 equ maxerrs \ -- n
Maximum number of errors before transfer is aborted.
#128 Buffer: x-buffer \ -- addr
Holds a 128 byte Xmodem data block.
: init-blks \ addr #bytes -- #blks
Given the size of an image, return the number of complete
128 byte blocks, set the variable CUR-ADDRESS to ADDR and
set the variable BLK# to 1.
: (To-Buffer) \ -- ; copy 128 bytes to X-BUFFER
Move 128 bytes from the memory pointed to by CUR-ADDRESS
into X-BUFFER. This is the default action of TO-BUFFER.
The variable CUR-ADDRESS is set by BIN-DOWN and friends.
Defer To-Buffer \ --
Copy the next 128 bytes to transmit to X-BUFFER. They
are then transmitted from X-BUFFER. You can change this
action as required by your application.
The default action is (TO-BUFFER).
: ?Ack \ -- ; wait for char, abort if not ACK
Wait for a character and terminate the transfer and abort
if the character is not an ACK.
: Send-Block \ Blk# -- ; transmit a block
Transmit the 128 byte contents of X-BUFFER to the host.
: Bin-Down \ addr #bytes -- ; transfer memory to host
Download (transmit) the given block of memory to the host
using the XMODEM 128 byte block protocol.
On entry, the variable CUR-ADDRESS is set to ADDR on entry
and #bytes is rounded up to a 128 byte unit.
: ser-flush \ -- ; flush the link input
Flush all input character from the host/target link.
: send-ack \ -- ; send ACK
Transmit an ACK character.
: send-nak \ -- ; Transmit a NAK character
Transmit a NAK character.
: send-can \ -- ; send CAN character
Transmit a CAN character.
: Get-BlockData \ -- cksum ; get block from host
Receive a 128 byte XMODEM data block from the host.
: toomanyerrs? \ -- T|F ; true if too many errors
Return true if too many comms errors have occurred.
: (From-Buffer) \ -- ; copy 128 bytes from X-BUFFER
Move 128 bytes from X-BUFFER into the memory pointed to
by CUR-ADDRESS
Defer From-Buffer \ -- ; copy 128 bytes from X-BUFFER
Move 128 bytes from X-BUFFER into the memory pointed to
by CUR-ADDRESS. CUR-ADDRESS is set up by BIN-UP and friends.
The default action is (FROM-BUFFER). You can modify the
action to suit your own application.
: Get-Block \ -- ;
Receive an XMODEM 128 byte data block from the host, processing
the header and checksum data.
: waitforresponse \ -- ; wait for host to respond
Wait for the host to respond for up to 1 second. If the
host does not respond, a NOREPLY status is set in the
variable RXSTATUS. This word requires the ticker interrupt
to be running.
: Bin-Up \ addr len -- status ; status 0 = GOOD
Upload (receive) a block of data of the given size into memory
using the XMODEM 128 byte block protocol. An error status is
returned, 0 indicating success.
On entry, the variable CUR-ADDRESS is set to ADDR on entry
and len is rounded up to a 128 byte unit.
Note that an error return of $0105 indicates the the file
being sent is larger than the LEN input parameter.
: RecvXmodem \ addr len -- len' status ; status=0=good
Upload (receive) a block of data of the given size into memory
using the XMODEM 128 byte block protocol. The number of bytes
correctly received and an error status are returned, 0
indicating success. See BIN-UP above for more details.