Add to git.
[dlife.git] / god.dla
1 ;; GOD CELL
2 ;; BY RICHARD W.M. JONES
3
4 00001:                                  ; Marks beginning of the cell.
5
6         JMPF ~00011                     ; Jump to start of the cell code
7                                         ; proper.
8
9 00010:                                  ; Marks start of local variables.
10         DW 4                            ; Local variable storage.
11
12         ; This is the main cell program.
13
14 00011:                                  ; Marks the start of the cell code.
15
16         ; When debugging, use this canard to detect stack underflows.
17         ;MOVE 65535,A
18         ;PUSH A
19
20         FINDB ~00010                    ; Find beginning of local variables.
21         MOVE I,A                        ; Add length of label.
22         ADD 5,A
23         MOVE A,B                        ; Initialize base register.
24         FINDB ~00001                    ; Find beginning address of cell.
25         MOVE I,A
26         STORE A,0                       ; Save it for later.
27         FINDF ~01111                    ; Find end address of cell.
28         MOVE I,A
29         ADD 5,A                         ; Add length of final label.
30         STORE A,1                       ; Save it for later.
31
32         CALLF ~00100                    ; Call subroutine to subtract
33                                         ; var 0 from var 1 and store in var 2.
34
35         LOAD 2,A                        ; Load the computed length.
36         MALLOC                          ; Allocate memory for the daughter.
37         MOVE I,A
38         JMPZB ~00011                    ; If allocation failed, start again.
39         STORE A,3                       ; Store the daughter's address in 3.
40
41         CALLF ~00110                    ; Call subroutine to do the copy.
42
43         DIVIDE                          ; Break off the daughter cell.
44
45         JMPB ~00011                     ; Repeat forever!
46
47         ; This subroutine subtracts var 0 from var 1 and stores the
48         ; resulting value in var 2.
49
50 00100:
51         LOAD 1,A                        ; Copy var 1 into var 2
52         STORE A,2
53         LOAD 0,A                        ; A <- amount to subtract
54 00101:  JMPZF ~01001                    ; Loop until A == 0
55         PUSH A
56         LOAD 2,A                        ; Subtract 1 from var 2.
57         DEC A
58         STORE A,2
59         POP A
60         DEC A
61         JMPB ~00101
62 01001:  RET 5
63
64         ; This subroutine copies var 2 bytes from [var 0] to [var 3] (ie.
65         ; from the mother to the daughter).
66
67 00110:
68         LOAD 2,A                        ; Number of bytes to copy.
69 00111:  JMPZF ~01000                    ; Leave loop when A == 0.
70         PUSH A
71         LOAD 0,A                        ; Get source address.
72         MOVE A,I
73         MOVE [I],A                      ; Get item to copy from source.
74         PUSH A
75         LOAD 3,A                        ; Get destination address.
76         MOVE A,I
77         POP A
78         MOVE A,[I]                      ; Store item at destination addr.
79         LOAD 0,A                        ; Increment source address.
80         INC A
81         STORE A,0
82         LOAD 3,A                        ; Increment destination address.
83         INC A
84         STORE A,3
85         POP A
86         DEC A
87         JMPB ~00111
88 01000:  RET 5
89
90 01111:                                  ; Marks end of the cell.