dcdoncount=&80 dcdoffcount=&81 MC=&4000 ACIAVAL=&95 ulaval_a=&82 ulaval_b=&83 delayamount=&84 FOR C%=0 TO 3 STEP 3 P%=MC [ OPT C% LDA #0 STA dcdoncount STA dcdoffcount \ interrupts off SEI \ set up ULA and ACIA, start motor LDA ulaval_a STA &FE10 JSR aciareset \ wait for DCD pulse JSR awaitdcdon JSR aciareset \ now, write to serial ULA to see if we get another DCD pulse LDA ulaval_b \ motor off STA &FE10 JSR delayby \ wait for a bit so that the "no carrier" condition takes effect in the ULA LDA ulaval_a \ motor on again STA &FE10 JSR awaitdcdon \ wait for a second DCD pulse \ stop motor and clean up LDA #&40 ; RS423 STA &FE10 LDA #3 STA &FE08 LDA #&56 STA &FE08 CLI RTS .awaitdcdon \ poll for pulse to show up LDY #0 .awaitdcd2 JSR delay LDA &FE08 \ check ACIA bit 2 for DCD pulse AND #4 BEQ nodcd2 \ if still zero then continue \ got it INC dcdoncount \ clear the dcd latch condition LDA &FE08 LDA &FE09 JSR awaitdcdoff \ now wait for DCD off (or failure) RTS .nodcd2 DEY BNE awaitdcd2 RTS .awaitdcdoff \ poll for pulse to end LDY #0 .Lawaitdcdoff JSR delay LDA &FE08 \ check ACIA bit 2 for DCD pulse AND #4 BNE nodcdoff \ if still high then go again \ got it INC dcdoffcount RTS .nodcdoff DEY BNE Lawaitdcdoff RTS .delayby TXA PHA LDX delayamount .lpdelayby DEX BNE lpdelayby PLA TAX RTS .delay TXA PHA LDX #0 .lpdelay NOP:NOP:NOP:NOP:NOP:NOP:NOP:NOP NOP:NOP:NOP:NOP:NOP:NOP:NOP:NOP DEX BNE lpdelay PLA TAX RTS .aciareset LDA #3 STA &FE08 LDA #ACIAVAL STA &FE08 RTS ] NEXT C% : ?delayamount=100 REM try 1: motor off 1, motor off (write same value), motor off 1 REM (register value unchanged) REM expect no DCD pulse REM incident leader is ignored, as motor is off ?ulaval_a=&05 ?ulaval_b=&05 CALL MC PROCresults("off 1, off 1, off 1") : REM try 2: motor off, motor off (write new value), motor off 1 REM (register value changed) REM expect no DCD pulse REM incident leader is ignored, as motor is off ?ulaval_a=&05 ?ulaval_b=&06 CALL MC PROCresults("off 1, off 2, off 1") : REM try 3: motor on, motor off (10 ticks), motor on ?delayamount=10 ?ulaval_a=&85 ?ulaval_b=&05 CALL MC PROCresults("on, off (10 ticks), on") : REM try 4: motor on, motor off (15 ticks), motor on ?delayamount=15 ?ulaval_a=&85 ?ulaval_b=&05 CALL MC PROCresults("on, off (15 ticks), on") : REM try 5: motor on, motor on (write same value), motor on ?delayamount=100 ?ulaval_a=&85 ?ulaval_b=&85 CALL MC PROCresults("on 1, on 1, on 1") : REM try 6: motor on, motor on (write new value), motor on REM expect ? ?ulaval_a=&85 ?ulaval_b=&86 CALL MC PROCresults("on 1, on 2, on 1") : END : DEF PROCresults(A$) P.'A$ P." DCD on: ";?dcdoncount P." DCD off: ";?dcdoffcount ENDPROC