;redcode
;name DoubleTroubleV4
;author SkybuckFlying
;strategy alternates programs to detect dead programs and revives the dead
programs.
;version 4
;date 21 december 2007
; Let's alternate between programs, this assures that programs are
functioning and gives insight into if the program is intact or dead.
; Works splendedly, program1 keeps reviving program2, while program2 is
d.e.a.d
; Now only thing to do is to incorporate a fixer and the program will be on
their way again ! =D
;
; Ok programs are now alternating, while still using 2 threads. ofcourse if
the running thread dies, the other one will never run
; maybe use wait loops instead...
; also it keeps trying to respawn dead programs... I had some trouble
getting it to work but finally figured it out.. the wait has to be cancelled
; maybe a future version will give up trying to respawn the second
program... and just run itself instead. I could do that.
; for now I am gonna keep things simple. But I am gonna develop the idea as
well incase I need it to see if it could work

yeah probably.
spl Program1Begin
spl Program2Begin
dat #0, #0
; program 1 will use A
; program 2 will use B
Program1Begin
jmz.a 0, ProgramRun
nop 1
nop 2
nop 3
nop 4
nop 5
nop 6
; we are done running signal the other program to run
; switch
mov.x ProgramRun, ProgramRun
; if he is in a wait state then cancel the wait to force him to immediatly
continue
mov.ab #1, Program2Wait
Program1WaitAgain
; reset wait time
mov.ab #10, Program1Wait
; wait for the other program to complete
Program1Wait djn 0, #0
; check if it completed, if it did ok simply run us.
jmz.b Program1Begin, ProgramRun
; else revive program 2
spl Program2Begin
; try waiting again, or alternative run ourselfs after wait is over
jmp Program1WaitAgain
jmp Program1Begin
Program1End
ProgramRun dat #1, #0
Program2Begin
jmz.b 0, ProgramRun
nop 1
nop 2
nop 3
; dat 3 ; pretend program 2 died.
nop 4
nop 5
nop 6
; we are done running signal the other program to run
; if both switch then this will always make program 1 run.. hmmm
; no this one wont be running it's ok hehe.
mov.x ProgramRun, ProgramRun
; if he is in a wait state then cancel the wait to force him to immediatly
continue
mov.ab #1, Program1Wait
Program2WaitAgain
; reset wait time
mov.ab #10, Program2Wait
; wait for the other program to complete
Program2Wait djn 0, #0
; check if it completed, if it did ok simply run us.
jmz.a Program2Begin, ProgramRun
; else revive program 1
spl Program1Begin
; program 1 might be dead so run ourselfs
; try waiting again, or alternative run ourselfs after wait is over
jmp Program2WaitAgain
jmp Program2Begin
Program2End