
; 
;    DOMINO:conofacevcc.s                          DATE: 5-86   
;    O'Leary, Stewart, Van de Geijn    University of Maryland
;
;    Programmed by Van de Geijn
;

;                      This is conoface 
;              (awaken, pause, and finis) 
;           for the Z80 processor using the Vandata
;                     vcc cross compiler.
;
;  "awaken (nodep)"  activates  "nodeprog (nodep, initialp)", which
;  returns control either by a "return" (to set status=0), a
;  "pause()" (to set status=1), or a "finis()" (to set status=2).
;

        .data
oldix:
        dw     00H
        .text
_awaken:
        call   c$nent
        ld     l,(ix+04h)
        ld     h,(ix+05h)       ; hl = ndp
        inc    hl
        inc    hl               ; hl = &ndp->status
        ld     a,(hl)
        inc    hl               ; status = 0? (READY)
        or     (hl)
        jp     NZ, restore
; case 1: status = READY
        dec    hl
        ld     (hl),01H         ; status = 1
        ld     de,08H       
        add    hl,de            ; hl = &ndp->program
        ld     c,(hl)
        inc    hl
        ld     b,(hl)           ; bc = ndp->program
        ld     de,05H       
        add    hl,de            ; hl = &ndp->stackbot
        ld     e,(hl)
        inc    hl
        ld     d,(hl)
        ex     de,hl            ; hl = ndp->stackbot and de = &ndp->stackbot+1
        inc    hl
        inc    hl
        ld     sp,hl            ; sp = ndp->stackbot + 2
        ld     hl,_initial
        push   hl               ; load second argument
        ld     (hl),01H         ; initial = 1
        inc    hl
        ld     (hl), 00H
        ld     (oldix), ix     ; save old ix
        ld     l,(ix+04H)
        ld     h,(ix+05H)       ; hl = ndp
        call   c$ibc
ret1:
        ld     l,(ix+04H)
        ld     h,(ix+05H)       ; hl = ndp
        inc    hl
        inc    hl
        xor    a                ; a = 0
        ld     (hl),a           ; status = READY
        inc    hl
        ld     (hl),a
        jp     c$1ret
; case 2: status = ACTIVE
restore:
        xor    a
        ld     (_initial), a 
        ld     (_initial+01H), a   ; initial = 0
        ld     de,0bH
        add    hl,de            ; hl = &ndp->stacktop
        ld     e,(hl)
        inc    hl
        ld     d,(hl)           
        ex     hl,de            ; hl = ndp->stacktop
        ld     sp,hl            ; sp = ndp->stacktop
        pop    ix
        call   c$0ret           ; return as if from pause()
       
_pause:
        call c$0ent
        push ix                 ; save ix for next awaken
        ld   ix,(oldix)        ; get ix of last call to awaken
        ld   l,(ix+04h)
        ld   h,(ix+05h)         ; hl = ndp
        ld   de,0eH
        add  hl,de              ; hl = &ndp->stacktop
        ex   de,hl
        ld   hl,00H
        add  hl,sp              ; hl = sp
        ex   de,hl
        ld   (hl),e
        inc  hl
        ld   (hl),d             ; ndp->stacktop = sp
        call c$1ret             ; return as if from awaken

_finis:
        call c$0ent
        ld   ix,(oldix)        ; get ix of last call to awaken
        ld   l,(ix+04H)
        ld   h,(ix+05H)         ; hl = ndp
        inc  hl
        inc  hl                 ; hl = &ndp->status
        ld   a,02H
        ld   (hl),a             ; status = 2 (= DETACHED)
        call c$1ret             ; return as if from awaken

	.extrn	c$ibc
        .extrn  c$0ret
        .extrn  c$1ret
        .extrn  c$nent
        .extrn  c$0ent
	.globl	_awaken
	.globl	_pause
	.globl  _finis
	.extrn	_initial
        end

