
.program pulser
clock_div:
    PULL NOBLOCK
    MOV X, OSR
    MOV Y, X
l0:
    JMP Y-- l0

    IRQ CLEAR 0 REL
    ; SM 0 + 0 -> IRQ 0 
    ; SM 1 + 0 -> IRQ 1

    JMP clock_div

counter:
    ; SM 2 + 2 -> IRQ 0
    ; SM 3 + 2 -> IRQ 1
    PULL
    MOV X, OSR
    JMP !X l1_end
    JMP X-- l1
l1:
    PULL NOBLOCK
    MOV Y, OSR
    JMP !Y l1_end
    MOV X, OSR

    IRQ WAIT 2 REL
    SET PINS, 1
    IRQ WAIT 2 REL
    SET PINS, 0

    JMP X-- l1

l1_end:
    MOV ISR, X
    PUSH NOBLOCK
    IRQ SET 0 REL
    ; SM 2 + 0 -> IRQ 2
    ; SM 3 + 0 -> IRQ 3
    JMP counter

