;---------------------------------------------------------------------------; ; RS-232 Data Switch Firmware ; ; ; ; File: COMMANDS.ASM ; ; ; ; This file contains the code for most of the commands supported by the ; ; switch firmware. ; ;---------------------------------------------------------------------------; commands segment code unit rseg commands $nolist $include(globals.asm) $list extrn code(skipspc) extrn code(prtstr) extrn code(getport) extrn code(prompt) extrn code(matchtoken) extrn code(getnum) extrn code(printnum) extrn code(tab) extrn code(putchar) extrn code(crlf) extrn code(setbaud) extrn code(fixtbl) extrn code(toupper) extrn code(daysthismonth) extrn code(checkmaint) extrn code(maskaddr) extrn code(printhex2) extrn code(gethex) extrn code(download) public dcd_cmd public dtr_cmd public break_cmd public list_cmd public baud_cmd public name_cmd public date_cmd public mode_cmd public mask_cmd public auto_cmd public help_cmd public run_cmd public dl_cmd public inc_str ;--------------------------------------------------------------------------- ; Function: dcd_cmd ; ; Description: ; This function provides the processing for the "dcd" command. It sets ; the value of the DCD/DTR output on a given port to one of the following: ; - Forced to true ; - Following the corresponding input on the port connected to. ; It also sets the default value (value output when the port is not ; connected to anything and DTR/DCD is not forced true. ; ; Command syntax: DCD SOURCE [] ; DCD FORCE [] ; DCD DEFAULT 0|1 [] ; ; Inputs: Taken from the command line ; Outputs: None ; ; Command may only be used in maintenance mode. dcd_cmd: lcall checkmaint jz dcd_ok ljmp prompt ; Get the keyword ("SOURCE", "FORCE", or "DEFAULT"). dcd_ok: lcall skipspc jz dcd_incomplete mov dptr,#dcdcmdtbl lcall matchtoken jz dcd_syntax cjne a,#3,dcd_notdef ; Process "DCD DEFAULT" ; Get the default value and ensure it is 0 or 1. lcall skipspc jz dcd_incomplete mov r2,#' ' lcall getnum jb badflag,dcd_exit mov a,r1 clr c subb a,#2 jnc dcd_syntax mov r5,1 ; Get the port number. If not given, assume the current ; command port. lcall skipspc jz dcd_myport2 lcall getport jz dcd_exit sjmp dcd_gotport2 dcd_myport2: mov a,myport ; Make sure the port is one of the 4 for which DCD/DTR can ; be controlled. dcd_gotport2: mov r0,a clr c subb a,#5 jnc dcd_toohigh ; Compute the address of the entry in the DCD/DTR default table. mov a,r0 dec a add a,#dtrdeftbl-256*(dtrdeftbl/256) mov dpl,a clr a addc a,#dtrdeftbl/256 mov dph,a ; Store the default in the table and exit. mov a,r5 movx @dptr,a ljmp prompt ; Process "DCD SOURCE/FORCE" ; Get a port number and assume own port if none given. dcd_notdef: mov r3,a lcall skipspc jz dcd_myport lcall getport jz dcd_exit sjmp dcd_gotport dcd_myport: mov a,myport dcd_gotport: mov r0,a ; Check that the port is one of the 4 for which the DTR/DCD ; output can be controlled. clr c subb a,#5 jnc dcd_toohigh cjne r3,#1,notsource ; "DCD SOURCE ..." - set the port's bit in the DTR/DCD mask. mov a,#8 dcd_loop1: rl a djnz r0,dcd_loop1 orl a,dtr_mask_and sjmp dcd_storemask ; "DCD FORCE ..." - reset the bit. notsource: mov a,#0f7h dcd_loop2: rl a djnz r0,dcd_loop2 anl a,dtr_mask_and ; Store the updated mask. dcd_storemask: mov dtr_mask_and,a ljmp prompt ; Error exits (shared with the "DTR" command, next). dcd_incomplete: mov dptr,#inc_str sjmp dcd_printit dcd_toohigh: mov dptr,#dcderrmsg sjmp dcd_printit dcd_syntax: mov dptr,#syntax_str dcd_printit: lcall prtstr dcd_exit: ljmp prompt dcdcmdtbl: db 'SOURCE',0,'FORCE',0,'DEFAULT',0 dcderrmsg: db 'DCD not controllable for this port.',13,10,0 ;--------------------------------------------------------------------------- ; Function: dtr_cmd ; ; Description: ; This function provides the processing for the "dtr" command. It sets ; the timeout for which the DTR/DCD input of a port can be deasserted before ; the port's connections are cleared. Alternatively, it can set DTR/DCD to ; be completely ignored for a given port. ; ; Command syntax: DTR TIMEOUT [] ; DTR IGNORE [] ; ; Inputs: Taken from the command line ; Outputs: None ; ; The DTR command may only be used from maintenance mode. dtr_cmd: lcall checkmaint jnz dcd_exit ; Get the "TIMEOUT" or "IGNORE" keyword. lcall skipspc jz dcd_incomplete mov dptr,#dtrcmdtbl lcall matchtoken jz dcd_syntax ; Assume a timeout of 0 seconds (meaning, ignore DTR/DCD). mov r4,#0 cjne a,#2,dtr_ignore ; Command was "DTR TIMEOUT ..." ; Get the timeout value and exit if illegal. lcall skipspc jz dcd_incomplete mov r2,#' ' lcall getnum jb badflag,dcd_exit mov a,r1 jz toolow mov r4,a ; Continue here for both versions of the command. Get the ; port number and assume own port if not given. dtr_ignore: lcall skipspc jz dtr_myport lcall getport jz dcd_exit sjmp dtr_gotport dtr_myport: mov a,myport ; Store the timeout value in the DTR timeout table. dtr_gotport: dec a add a,#dtrtimtbl-256*(dtrtimtbl/256) mov dpl,a clr a addc a,#dtrtimtbl/256 mov dph,a mov a,r4 movx @dptr,a ljmp prompt dtrcmdtbl: db 'IGNORE',0,'TIMEOUT',0,0 ;--------------------------------------------------------------------------- ; Function: break_cmd ; ; Description: ; This function provides the processing for the "break" command. It sets ; the minimum length an RS-232 "break" has to be before being recognized. ; Alternatively, it can set breaks to be ignored on a given port. ; ; Command syntax: BREAK TIMEOUT