Listing 2 - Compare this to Listing 1. Its the same top level program translated from PDL to Forth.
: MAIN
HOUSE.KEEP \ set ports, clear flags, set defaults
READ.UPLOAD.BIT \ has user saved previous settings?
0= IF COPY.PROM \ load defaults from EEPROM
ENDIF
READ.CONFIG \ get former settings from EEPROM
SET.CONFIG \ set board registers
BEGIN \ start of endless loop
GET.SELF.TEST.BIT 0= \ Test state of hardware bit
SELF-TEST-NUMBER @ NOT AND
IF \ bit=0 & number <>0 then do self test operation
SELF-TEST-NUMBER @
CASE \ select test by number
1 OF TEST1 ENDOF
2 OF TEST2 ENDOF
3 OF TEST3 ENDOF
4 OF TEST4 ENDOF
ENDCASE
ELSE \ normal operation
\ The input interface chip has a single-bit serial output, which changes
\ from zero to one when a fault occurs or when the user enters a
\ front-panel command or new parameter. By serially reading the
\ eight-bit status word and testing its bits, you can see the nature of
\ the change and which other interface words must be read.
\ Thus the operation is: Test port for flag.
\ If flag, read entire status word.
\ Examine word for user requests (e.g. jitter on/off)
\ Set state to match user request.
\ Examine word for parameter changes.
\ Read new parameters and distribute them.
TEST.INTERFACE.FLAG \ Check for faults or user input
IF STATUS-BYTE 8.READ \ Do serial input of status byte
DUP FAULT-FLAG AND \ Mask fault flag bit
IF SOFT.RESET ENDIF \ Fault so do restart
DUP JITTER-FLAG AND \ Mask users jitter request
JITTER-STATE @ = NOT \ Compare with present state
IF TOGGLE.STATE ENDIF \ If different change state
DUP CALIBRATION-REQUEST AND \ Mask users calib request
IF CALIBRATE ENDIF \ Do requested calibration
\ Check four "user parameter change" flags in status byte.
\ As appropriate, read user inputs and change settings.
DUP 0 BIT.MASK IF SET.AMPLITUDE ENDIF
DUP 1 BIT.MASK IF SET.BITRATE SET.AMPLITUDE ENDIF
DUP 2 BIT.MASK IF SET.BITRATE SET.AMPLITUDE ENDIF
3 BIT.MASK IF SET.FREQUENCY ENDIF
\ If any parameters were changed, save new values.
PARAMETERS.CHANGED? IF UPDATE.EEPROM ENDIF
CLEAR.INTERFACE.FLAG \ reset hardware flag
ENDIF
ENDIF
REPEAT
;