Routine: Read
Function: Reads mechanism: displacement angle and motor speed.
Called by: Chk1, Chk2, Visc
Calls: Add, Clock, Divide, Mark, Mult, Recip, Regld, Regsv, Space
Entry: DE points to angle, HL to speed
Exit: Angle, speed stored at DE, HL respectively. NC flag set on error
Preserved: None
READ PUSH DE
PUSH HL
READ1 IN A,(6)
LD (TIMERB),A
; Initialise variable Timerb: Read6 is used to see that if no change in mechanism state happens within 2 seconds, the program jumps to Readfl, and returns from this routine with the NC flag set. Normal termination is with the C flag set.
READ2 CALL READ6
JP NC,READFL
IN A,(14)
RL A
; Read in mechanism state, and repeat until it becomes 0.
JR C,READ2
IN A,(6)
LD (TIMERB),A
READ3 CALL READ6
JR NC,READFL
IN A,(14)
RL A
; Read in mechanism state and repeat until it becomes 1.
JR NC,READ3
DJNZ READ1
IN A,(7)
LD HL,NUM1
IN A,(6)
LD (TIMERB),A
READ4 CALL READ6
JR NC,READFL
IN A,(14)
RL A
; Read in mechansim state and repeat until it becomes 0.
JR C,READ4
; Now call subroutine Space, to read in the space period.
CALL SPACE
LD HL,NUM2
IN A,(6)
LD (TIMERB),A
READ5 CALL READ6
JR NC,READFL
IN A,(14)
RL A
; Read in mechanism state and repeat until it becomes 1.
JR NC,READ5
; Now call subroutine Mark, to read in the mark period.
CALL MARK
LD BC,NUM1
LD DE,NUM2
LD HL,NUM3
; Add mark and space periods to get the total rotation period. Next take the reciprocal to get the motor speed.
CALL ADD
LD DE,NUM3
POP HL
CALL RECIP
LD BC,NUM2
LD DE,NUM3
LD HL,NUM4
; Divide Mark by the total period and multiply by 360 degrees, to get the displacement angle.
CALL DIVIDE
LD BC,THRE60
LD DE,NUM4
POP HL
CALL MULT
SCF
RET
READ6 CALL REGSV
; Update clock.
CALL CLOCK
CALL REGLD
LD A,(TIMERB)
LD D,A
IN A,(6)
SUB D
JP P,READ7
NEG
; Check that 2 seconds have not passed.
READ7 CP 100
RET
READFL POP HL
; On error restore stack and return.
POP HL
RET