Listing 3 - Using the same program, we converted from PDL to C. If you compare Listing 2 with this one, you get a good feel for how C contrasts with Forth.
void main(void)
{
int jitter_state = 0; /* local variable on stack */
int sts; /* copy of status word read */
/* start of auto variables - declared on stack for duration of routine */
sysHouseKeep(); /* set ports, clear flags, set defaults */
if (sysReadUploadBits() == 0) /* has user saved previous settings?*/
sysCopyProm(); /* if so, load defaults from EEPROM*/
sysSetConfig(sysReadConfig()); /* set board with former settings*/
do { /* endless loop */
if ((selfTestReadBit() == 0) && (selfTestNumber != 0)) { /* find a user input change */
switch (selfTestNumber) { /* decide which test to perform */
case 1:
test1();
break;
case 2:
test2();
break;
case 3:
test3();
break;
case 4:
test1();
break;
default: /* error condition */
break;
} /* end switch */
} /* end if */
else { /* normal operation */
if ( readIOByte(INTERFACE_FLAG) != 0) {
if (sts = readIOByte(STATUS_BYTE) & FAULT_FLAG) {
sysSoftReset();
}
if (jitter_state != sts & JITTER_FLAG)
jitter_state = JITTER_FLAG ^ jitter_state; /* compliment bit*/
if (sts & CALIBRATION_REQUEST)
Calibration();
if (sts & BIT_0) {
sysSetAmplitude();
}
if (sts & BIT_1) {
sysSetBitRate();
sysSetAmplitude();
}
if (sts & BIT_2) {
sysSetBitRate();
sysSetAmplitude();
}
if (sts & BIT_3) {
sysSetFrequency();
}
if (sysParametersChanged()) {
sysUpdateEEPROM();
sysClearInterface();
}
}
} /* end else */
} while ( FOREVER);
}