Reset
Listing index
Sub
Routine:        Space   
Function:       Counts "Space" of mark/space ratio
Called by:      Read
Calls:          None
Entry:          HL point to the location Space will be stored at
Exit:           Space stored at HL
Preserved:      None


SPACE   IN      A,(0)
        LD      E,A
        IN      A,(1)
        LD      D,A
        IN      A,(2)
        LD      C,A
; Read ports 0-2 into E,D,C registers.
        LD      B,24
        XOR     A
SPACE1  BIT     7,C
; Test the leftermost bit and jump if its a '1', otherwise normalise by shifting one bit to the left, and repeating.
        JR      NZ,SPACE2
        SLA     E
        RL      D
        RL      C
        DEC     A
; Reduce the exponent, held in A.
        DJNZ    SPACE1
SPACE2  RES     7,C
Store the result at HL.
        LD      (HL),0
        INC     HL
        LD      (HL),E
        INC     HL
        LD      (HL),D
        INC     HL
        LD      (HL),C
        INC     HL
        LD      (HL),A
        RET
Reset
Listing index
Sub