XMODEM for the TRS-80 Model 100 Version of 5/7/84 (c) Rick Perry, CIS-75665,1045 This version performs auto-dial-redial, auto-logon, terminal emulation, and text file transfers (.DO) using the Christensen checksum protocol. Communication parameters are 8N1D for file transfer and 7I1E for terminal emulation. The program will operate using the 300 baud internal modem or a 1200 baud external modem (Novation Smart-Cat or equivalent). Files may be Up/Down loaded directly from/to RAM, disk or cassette. AUTO-DIAL/LOGON: The program starts with a "Find:" prompt and will attempt to retrieve a phone number and auto-logon sequence from the ADRS.DO file and logon to a host computer. When using the internal modem, if no carrier is detected within 20 seconds after dialing, or if you press any key, the program will hang up the phone. After waiting 20 seconds more, it will retry the number unless you press any key. If the carrier is detected, it will BEEP and proceed through the auto-logon sequence as specified in the ADRS line, then jump to the terminal emulation mode of the program. At the "Find:" prompt, enter a string to search for in the ADRS file or press F8 (or enter "Menu") to return to the Menu. When the string is found press "M" to begin auto-dial using the internal modem, or press "S" to dial through an external 1200 baud Novation Smart-Cat modem, or press ESC to return to the "Find:" prompt, or press any other key to continue searching. If you wish to manually dial a telephone number, enter "Dial" at the "Find:" prompt. After dialing and hearing the carrier tone, press "M" or "S" to allow the program to Connect, or press any other key to return to the "Find:" prompt. The control sequences used with the Novation modem appear around the last twelve lines of the program. This code may be modified to work properly with other smart modems. When dialing through an external modem, code around the last eight lines of the program allow you to directly enter commands to the modem and optionally press CTRL/R to restart the program or CTRL/E to exit to the Menu. TERMINAL EMULATION: The program is not transparent to CTRL/C, i.e. BREAK will halt the program but leave you connected to the host. Function key F5 (Brk) is used to send CTRL/C to the host. Additionally, F1 (Paus) will alternately send CTRL/S & CTRL/Q (XOFF/XON) each time it is pressed. If you accidently press CTRL/C or BREAK, enter CONT to return to the program. If you press CTRL/S, just press it again to continue. F4 (Term) is used to jump directly to TELCOM's Term mode while remaining connected to the host. Once in TELCOM you cannot return to the program without logging off and disconnecting from the host unless you are connected through an external modem. From TELCOM you can UPload and DOWNload text files with the regular ASCII XON/XOFF protocol. F6 (Free) provides a display of how many bytes of RAM are currently available. F7 (Dir) lists the RAM file directory in the same way as the BASIC FILES command. F8 (Bye) is used to exit the program and return to the Model 100's Main Menu. F2 (Down) will initiate a file download transfer and F3 (Up) will initiate uploading. DOWNLOADING: The program will prompt for a valid file name and proceed through the XMODEM protocol with the host. The host should be ready to send the file before entering this mode. While downloading, the received file is not displayed on the screen. When a NAK (negative acknowledge) is sent, the program prints an "X". When ACK (acknowledge) is sent, the program prints ".". You can abort the download at any time by pressing F8 (Abrt). The program itself will automatically abort the download only if one of the following circumstances occur: - The host sends a CANcel. - The received block number is neither the current block number nor the previous block number. - An error trap occurs in the program (this could be caused by an "Out of Memory" condition on the Model 100). UPLOADING: The program will prompt for a valid file name and proceed through the XMODEM protocol with the host. The host should be ready to receive the file before entering this mode. While uploading, the transmitted file is not displayed on the screen. When a NAK is received, the program prints an "X". When ACK is received, the program prints ".". If nothing is received after waiting 10 seconds, or if anything other than NAK, ACK or CAN is received, the program prints a "?". You can abort the upload at any time by pressing F8 (Abrt). The program itself will automatically abort the upload only if the host sends a CANcel or if an error trap occurs (e.g. due to an IO Error when uploading from cassette). PROGRAM NOTES: The program itself does not count the number of NAK's sent or received per block and will not automatically abort if an excessive number of NAK's occur. It is up to you to use F8 (Abrt) to cancel the file transfer if you feel that too many NAK's are occuring. When aborting a file transfer the program sends a single CANcel character (CTRL/X) to the host and returns to its terminal emulation mode. If you then notice that the host has not responded to the CANcel, you may send additional CAN's by pressing CTRL/X. MAXFILES is set to 3 at the beginning and reset to 2 upon normal exit to the Menu. Function key definitions are restored to their previous user-defined values upon exit from the program to the Menu. The following ROM calls are used: 6118 - set serial interface parameters and activate modem. 16969 - turn cursor on. 17061 - set and display temporary function key strings. 21172 - keep phone off hook. 21179 - hang up phone. 21264 - 2 second delay. 21274 - 1/2 second delay. 21293 - dial a phone number. 21392 - execute auto-logon sequence. 21608 - jump to TELCOM's Term mode. The integer array M(0)..M(58) is used to hold five position independent machine language subroutines. Entry points are at M(0), M(3), M(16), M(21) & M(24). The assembly source listing follows: ; ENTRY M(0) - check MDM: for carrier detect. ; calling sequence: CALL VARPTR(M(0)),0,VARPTR(X) ; where X is an integer variable. M(0) call 6EEF ; check for carrier detect mov m,a ; X=0 if carrier detected, ret ; FF if no carrier nop ; ENTRY M(3) - convert string to uppercase. ; calling sequence: CALL VARPTR(M(3)),0,VARPTR(A$) ; where A$ is a string variable. M(3) mov a,m ; check length of string ora a ; if zero rz ; then return mov c,a ; save length in counter C inx h ; get string address mov a,m ; that's the low byte inx h mov h,m ; that's the high byte mov l,a ; HL --> string lxi d,2 ; here comes the tricky part call 31E9 ; in ROM there is XTHL, PCHL $PC1 dad d ; now HL = loop pop d ; and DE --> string loop ldax d ; A = char from string call 0FE9 ; let ROM convert to uppercase stax d ; restore converted char inx d ; point to next char dcr c ; decrement counter rz ; done when counter = 0 pchl ; otherwise jump to loop ; ENTRY M(16) - check MDM: or COM: queue for received chars. ; calling sequence: CALL VARPTR(M(16)),0,VARPTR(X(0)) ; where X(0)..X(1) is an integer array. M(16) mvi m,0 ; set flag, X(0)=0, for no char call 6D6D ; check queue for chars rz ; return if no chars available inr m ; set flag, X(0)=1, for char received inx h inx h ; HL --> received char buffer, X(1) nop ; ENTRY M(21) - retrieve char from MDM: or COM: queue. ; if entry was made at M(16) and the queue contained a char ; then the code will fall through to this point and the ; received char will be placed in X(1). ; M(21) may also be called independently of M(16) to receive ; a char if it's already known that one is there (due to an ; ON MDM GOSUB.. interrupt for example). ; calling sequence: CALL VARPTR(M(21)),0,VARPTR(X) ; where X is an integer variable. M(21) call 6D7E ; get char from queue mov m,a ; store it ret nop ; ENTRY M(24) - timed read of 131 chars from MDM: or COM: queue. ; calling sequence: CALL VARPTR(M(24)),0,VARPTR(Z(0)) ; where Z(0)..Z(131) is an integer array. ; Z(0) is used as a flag. ; Upon return, if Z(0)=0 then a timeout occurred. ; Z(0)=1 implies successful return and in this case ; Z(1)..Z(131) will contain the 131 received characters. x1 equ 39. ; get_ch - $PC2 x2 equ 7. ; ck_que - $PC2 x3 equ 4. ; init - $PC2 M(24) mvi m,0 ; set flag for failure mov d,h mov e,l ; DE = HL --> flag call 31E9 ; xthl, pchl $PC2 mvi b,131. ; char counter push b push h ; stack now contains: ; ; address of flag ; char counter ; sp --> $PC2 init lxi h,7282. ; HL = 1 second timeout counter ck_que call 6D6D ; check queue pop b push b push b ; extra $PC2 on stack xthl ; counter on stack, HL = $PC2 lxi b,x1 ; offset to get_ch dad b xthl rnz ; jnz get_ch pop b ; clear stack dcx h ; decrement timeout counter mov a,h ora l pop b push b push b ; extra $PC2 on stack xthl ; counter on stack, HL = $PC2 lxi b,x2 ; offset to ck_que dad b xthl rnz ; jnz ck_que pop b pop b pop b pop b ret ; timeout exit get_ch call 6D7E ; get char from queue inx d inx d stax d ; store it in buffer pop h pop b dcr b ; decrement char counter push b push h ; HL = $PC2 lxi b,x3 ; offset to init dad b push h rnz ; jnz init pop h pop h pop h pop h inr m ; set flag for success ! ret