Subversion Repositories Kolibri OS

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1775 yogev_ezra 1
;
2
;    LIFE.ASM
3
;
4
;    This program displays Conways game of life
5
;
6
;    Compile with FASM for Menuet;
7
;
8
;
9
;    Version 0.1    30th March 2004
10
;                   Mike Hibbett
11
;
12
;    Version 0.2    23th May 2004
13
;                   Random generation dots with start
14
;
15
;    Convert to ASCL Libary by Pavlushin Evgeni
16
;
17
;    This is an experiment to see how small a usefull application can get
18
;
19
 
20
use32
21
               org     0x0
22
 
23
               db     'MENUET01'              ; 8 byte id
24
               dd     0x01                    ; header version
25
               dd     START                   ; start of code
26
               dd     I_END                   ; size of image
27
               dd     0x100000                 ; memory for app
28
               dd     0x100000                ; esp
29
               dd     0x0 , 0x0               ; I_Param , I_Icon
30
include 'ascl.inc'
31
 
32
macro setcell x,y  { mov     [esi + 512*(y)*3 + (x)*3], al }
33
 
34
START:
35
 
36
    mov     al, 0xFF
37
    mov     esi, I_END
38
 
39
    ; This is the seed pattern.
40
 
41
    ; Life needs a seed pattern, which is 'hardcode' at compile time
42
    ; The grid is 512 wide (x direction) by 512 deep (y direction)
43
    ; setcell take the arguments setcell x,y
44
    ; 0,0 is the top left corner.
45
 
46
    setcell 200,120
47
    setcell 201,120
48
    setcell 200,121
49
    setcell 199,121
50
    setcell 200,122
51
 
52
    setcell 70,120
53
    setcell 71,120
54
    setcell 70,121
55
    setcell 69,121
56
    setcell 70,122
57
 
58
    call    draw_window
59
 
60
    ;Random generation dots
61
 
62
    mov ecx,20000
63
xxx:
64
    push ecx
65
    random 30000,edi     ;up pice of screen
66
    mov al,0xff
67
    shl edi,3
68
;    mov [I_END+edi],al
69
;    random 50000,edi     ;down pice of screen
70
;    mov al,0xff
71
;    shl edi,3
72
    add edi,512*460 ;760
73
    mov [I_END+edi],al
74
    pop ecx
75
    dec ecx
76
    jnz xxx
77
 
78
still:
79
 
80
    timeevent 5,nokey,red,key,button    ;Wait EVENT with 5 fps
81
    jmp still
82
 
83
red:                          ; REDRAW WINDOW
84
    call draw_window
85
    jmp  still
86
 
87
key:                          ; KEY
88
    mov  eax,2                  ; get it, but ignore
89
    int  0x40
90
 
91
nokey:
92
 
93
    ; cycle life state
94
 
95
    mov  esi, I_END + 512*3
96
 
97
    mov     al, 0xFF
98
 
99
lifeloop:
100
    mov     ah, 0
101
    cmp     [esi - 3], al
102
    jne     t2
103
    inc     ah
104
t2:
105
    cmp     [esi + 3], al
106
    jne     t3
107
    inc     ah
108
t3:
109
    cmp     [esi - 512*3], al
110
    jne     t4
111
    inc     ah
112
t4:
113
    cmp     [esi + 512*3], al
114
    jne     t5
115
    inc     ah
116
t5:
117
    cmp     [esi - 512*3 - 3], al
118
    jne     t6
119
    inc     ah
120
t6:
121
    cmp     [esi - 512*3 + 3], al
122
    jne     t7
123
    inc     ah
124
t7:
125
    cmp     [esi + 512*3 - 3], al
126
    jne     t8
127
    inc     ah
128
t8:
129
    cmp     [esi + 512*3 + 3], al
130
    jne     tend
131
    inc     ah
132
 
133
tend:
134
    ; If cell is empty but has 3 neigbours, birth
135
    ; If cell is occupied and has 2,3 neigbours, live
136
    ; else die
137
 
138
    cmp     ah, 3
139
    jne     btest
140
    mov     [esi+1], al
141
    jmp     nextcell
142
 
143
btest:
144
    cmp     ah, 2
145
    jne     nextcell
146
    cmp     [esi], al
147
    jne     nextcell
148
    mov     [esi+1], al
149
 
150
nextcell:
151
    add     esi, 3
152
    cmp     esi, I_END + 512*512*3
153
    jne     lifeloop
154
 
155
    ; copy new generation across
156
 
157
    mov     ecx, 512*512*3
158
    mov     esi, I_END+1
159
    mov     edi, I_END
160
    rep     movsb               ; copy the data across
161
 
162
    mov     ecx, 512*512
163
    mov     esi, I_END
164
nc1:
165
    mov     [esi+2], byte 0
166
    add     esi, 3
167
    loop    nc1
168
 
169
    mov     ebx, I_END
170
    mov     ecx, 512*65536+512
171
    mov     edx, 5*65536+20
172
    mov     eax,7
173
    int     0x40
174
 
175
    jmp  still
176
 
177
button:                       ; BUTTON - only close supported
178
    close
179
 
180
;   *********************************************
181
;   *******  WINDOW DEFINITIONS AND DRAW ********
182
;   *********************************************
183
draw_window:
184
    startwd
185
    window 50,50,512+9,512+23,window_Skinned
186
    label  8,8,'Life Screen',cl_White+font_Big
187
    endwd
188
    ret
189
 
190
I_END: