Subversion Repositories Kolibri OS

Rev

Rev 109 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 109 Rev 132
1
;
1
;
2
;    LIFE.ASM
2
;    LIFE.ASM
3
;
3
;
4
;    This program displays Conways game of life
4
;    This program displays Conways game of life
5
;
5
;
6
;    Compile with FASM v1.49 for DOS;
6
;    Compile with FASM for Menuet;
7
;
7
;
8
;    Version 0.1a   20th May   2004
-
 
9
;                   Ivan Poddubny
-
 
10
;
8
;
11
;    Version 0.1    30th March 2004
9
;    Version 0.1    30th March 2004
12
;                   Mike Hibbett
10
;                   Mike Hibbett
13
;
11
;
-
 
12
;    Version 0.2    23th May 2004
-
 
13
;                   Random generation dots with start
-
 
14
;
-
 
15
;    Convert to ASCL Libary by Pavlushin Evgeni
-
 
16
;
14
;    This is an experiment to see how small a usefull application can get
17
;    This is an experiment to see how small a usefull application can get
15
 
18
;
16
include "lang.inc"
-
 
17
include "macros.inc"
-
 
18
 
19
 
19
  use32
20
use32
20
  org     0x0
21
               org     0x0
21
 
22
 
22
  db     'MENUET01'              ; 8 byte id
23
               db     'MENUET01'              ; 8 byte id
23
  dd     0x01                    ; header version
24
               dd     0x01                    ; header version
24
  dd     START                   ; start of code
25
               dd     START                   ; start of code
25
  dd     I_END                   ; size of image
26
               dd     I_END                   ; size of image
26
  dd     0xc1000                  ; memory for app
27
               dd     0x100000                 ; memory for app
27
  dd     0xc1000                  ; esp
28
               dd     0x100000                ; esp
28
  dd     0x0 , 0x0               ; I_Param , I_Icon
29
               dd     0x0 , 0x0               ; I_Param , I_Icon
-
 
30
include 'ascl.inc'
29
 
-
 
30
;include "DEBUG.INC"
31
 
31
macro setcell x,y  { mov     [esi + 512*(y)*3 + (x)*3], al }
32
macro setcell x,y  { mov     [esi + 512*(y)*3 + (x)*3], al }
32
 
33
 
33
START:
34
START:
34
 
35
 
35
    mov     al, 0xFF
36
    mov     al, 0xFF
36
    mov     esi, I_END
37
    mov     esi, I_END
37
 
38
 
38
    ; This is the seed pattern.
39
    ; This is the seed pattern.
39
 
40
 
40
    ; Life needs a seed pattern, which is 'hardcode' at compile time
41
    ; Life needs a seed pattern, which is 'hardcode' at compile time
41
    ; The grid is 512 wide (x direction) by 512 deep (y direction)
42
    ; The grid is 512 wide (x direction) by 512 deep (y direction)
42
    ; setcell take the arguments setcell x,y
43
    ; setcell take the arguments setcell x,y
43
    ; 0,0 is the top left corner.
44
    ; 0,0 is the top left corner.
44
 
45
 
45
;    setcell 200,120
46
    setcell 200,120
46
;    setcell 201,120
47
    setcell 201,120
47
;    setcell 200,121
48
    setcell 200,121
48
;    setcell 199,121
49
    setcell 199,121
49
;    setcell 200,122
50
    setcell 200,122
50
 
51
 
51
;    setcell 70,120
52
    setcell 70,120
52
;    setcell 71,120
53
    setcell 71,120
53
;    setcell 70,121
54
    setcell 70,121
54
;    setcell 69,121
55
    setcell 69,121
55
;    setcell 70,122
-
 
56
 
-
 
57
    mov     eax, 40
-
 
58
    mov     ebx, 100101b
-
 
59
    int     0x40
56
    setcell 70,122
60
 
57
 
61
    call    draw_window
58
    call    draw_window
62
 
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
63
still:
67
    shl edi,3
64
 
68
;    mov [I_END+edi],al
65
;    mov  eax, 23                 ; wait here for event
69
;    random 50000,edi     ;down pice of screen
-
 
70
;    mov al,0xff
-
 
71
;    shl edi,3
66
;    mov  ebx, 5
72
    add edi,512*460 ;760
-
 
73
    mov [I_END+edi],al
67
;    int  0x40
74
    pop ecx
68
    mov  eax, 11
-
 
69
    int  0x40
-
 
70
 
-
 
71
    test eax, eax
75
    dec ecx
72
    je   nokey
-
 
73
    cmp  eax,1                  ; redraw request ?
-
 
74
    je   red
-
 
75
    cmp  eax,3                  ; button in buffer ?
-
 
-
 
76
    jnz xxx
76
    je   button
77
 
77
    cmp  eax,6
-
 
78
    je   mouse
-
 
79
 
-
 
80
    jmp  still
-
 
81
 
-
 
82
 
-
 
83
  mouse:
-
 
84
    mov  eax, 37
-
 
85
    mov  ebx, 2
-
 
86
    int  0x40
-
 
87
    test eax, eax
-
 
88
    jz   still
-
 
89
 
-
 
90
    mov  eax, 37
-
 
91
    mov  ebx, 1
-
 
92
    int  0x40
-
 
93
    sub  eax, 5*65536+20
-
 
94
    mov  ebx, eax
-
 
95
    shr  eax, 16
-
 
96
    and  ebx, 0xffff
-
 
97
 
-
 
98
; WRITE COORDINATES
-
 
99
;   dpd  eax
-
 
100
;   dps  "  "
-
 
101
;   dpd  ebx
-
 
102
;   dps  <10,13>
-
 
103
 
-
 
104
    cmp  ax, 0
-
 
105
    js   still
-
 
106
    cmp  bx, 0
-
 
107
    js   still
-
 
108
 
-
 
109
    shl  ebx, 9
-
 
110
    add  ebx, eax
-
 
111
    imul ebx, 3
78
still:
112
    add  ebx, I_END
79
 
113
    mov  [ebx], dword 0xFFFFFFFF
80
    timeevent 5,nokey,red,key,button    ;Wait EVENT with 5 fps
114
    jmp  draw
81
    jmp still
115
 
82
 
116
  red:                          ; REDRAW WINDOW
83
red:                          ; REDRAW WINDOW
117
    call draw_window
84
    call draw_window
118
    jmp  still
85
    jmp  still
-
 
86
 
-
 
87
key:                          ; KEY
-
 
88
    mov  eax,2                  ; get it, but ignore
119
 
89
    int  0x40
120
 
-
 
121
nokey:
-
 
122
    ; cycle life state
90
 
123
 
-
 
124
mov eax,5
91
nokey:
125
mov ebx,5
92
 
126
int 0x40
93
    ; cycle life state
127
 
94
 
128
    mov  esi, I_END + 512*3
95
    mov  esi, I_END + 512*3
129
 
96
 
130
    mov     al, 0xFF
97
    mov     al, 0xFF
131
 
98
 
132
lifeloop:
99
lifeloop:
133
    mov     ah, 0
100
    mov     ah, 0
134
    cmp     [esi - 3], al
101
    cmp     [esi - 3], al
135
    jne     t2
102
    jne     t2
136
    inc     ah
103
    inc     ah
137
t2:
104
t2:
138
    cmp     [esi + 3], al
105
    cmp     [esi + 3], al
139
    jne     t3
106
    jne     t3
140
    inc     ah
107
    inc     ah
141
t3:
108
t3:
142
    cmp     [esi - 512*3], al
109
    cmp     [esi - 512*3], al
143
    jne     t4
110
    jne     t4
144
    inc     ah
111
    inc     ah
145
t4:
112
t4:
146
    cmp     [esi + 512*3], al
113
    cmp     [esi + 512*3], al
147
    jne     t5
114
    jne     t5
148
    inc     ah
115
    inc     ah
149
t5:
116
t5:
150
    cmp     [esi - 512*3 - 3], al
117
    cmp     [esi - 512*3 - 3], al
151
    jne     t6
118
    jne     t6
152
    inc     ah
119
    inc     ah
153
t6:
120
t6:
154
    cmp     [esi - 512*3 + 3], al
121
    cmp     [esi - 512*3 + 3], al
155
    jne     t7
122
    jne     t7
156
    inc     ah
123
    inc     ah
157
t7:
124
t7:
158
    cmp     [esi + 512*3 - 3], al
125
    cmp     [esi + 512*3 - 3], al
159
    jne     t8
126
    jne     t8
160
    inc     ah
127
    inc     ah
161
t8:
128
t8:
162
    cmp     [esi + 512*3 + 3], al
129
    cmp     [esi + 512*3 + 3], al
163
    jne     tend
130
    jne     tend
164
    inc     ah
131
    inc     ah
165
 
132
 
166
tend:
133
tend:
167
    ; If cell is empty but has 3 neigbours, birth
134
    ; If cell is empty but has 3 neigbours, birth
168
    ; If cell is occupied and has 2,3 neigbours, live
135
    ; If cell is occupied and has 2,3 neigbours, live
169
    ; else die
136
    ; else die
170
 
137
 
171
    cmp     ah, 3
138
    cmp     ah, 3
172
    jne     btest
139
    jne     btest
173
    mov     [esi+1], al
140
    mov     [esi+1], al
174
    jmp     nextcell
141
    jmp     nextcell
175
 
142
 
176
btest:
143
btest:
177
    cmp     ah, 2
144
    cmp     ah, 2
178
    jne     nextcell
145
    jne     nextcell
179
    cmp     [esi], al
146
    cmp     [esi], al
180
    jne     nextcell
147
    jne     nextcell
181
    mov     [esi+1], al
148
    mov     [esi+1], al
182
 
149
 
183
nextcell:
150
nextcell:
184
    add     esi, 3
151
    add     esi, 3
185
    cmp     esi, I_END + 512*512*3
152
    cmp     esi, I_END + 512*512*3
186
    jne     lifeloop
153
    jne     lifeloop
187
 
154
 
188
    ; copy new generation across
155
    ; copy new generation across
189
 
-
 
190
 
156
 
191
    mov     ecx, 512*512*3
157
    mov     ecx, 512*512*3
192
    mov     esi, I_END+1
158
    mov     esi, I_END+1
193
    mov     edi, I_END
159
    mov     edi, I_END
194
    rep     movsb               ; copy the data across
160
    rep     movsb               ; copy the data across
195
 
161
 
196
    mov     ecx, 512*512
162
    mov     ecx, 512*512
197
    mov     esi, I_END
163
    mov     esi, I_END
198
nc1:
164
nc1:
199
    mov     [esi+2], byte 0
165
    mov     [esi+2], byte 0
200
    add     esi, 3
166
    add     esi, 3
201
    loop    nc1
167
    loop    nc1
202
draw:
168
 
203
    mov     ebx, I_END
169
    mov     ebx, I_END
204
    mov     ecx, 512*65536+512
170
    mov     ecx, 512*65536+512
205
    mov     edx, 5*65536+22
171
    mov     edx, 5*65536+20
206
    mov     eax,7
172
    mov     eax,7
207
    int     0x40
173
    int     0x40
208
 
174
 
209
    jmp  still
175
    jmp  still
210
 
176
 
211
button:                       ; BUTTON - only close supported
177
button:                       ; BUTTON - only close supported
212
    or   eax,-1
-
 
213
    int  0x40
178
    close
214
 
-
 
215
 
-
 
216
 
-
 
217
 
179
 
218
;   *********************************************
180
;   *********************************************
219
;   *******  WINDOW DEFINITIONS AND DRAW ********
181
;   *******  WINDOW DEFINITIONS AND DRAW ********
220
;   *********************************************
182
;   *********************************************
221
 
-
 
222
 
-
 
223
draw_window:
183
draw_window:
224
    mov  eax,12
-
 
225
    mov  ebx,1
-
 
226
    int  0x40
184
    startwd
227
 
-
 
228
    mov  eax,0                     ; open window
-
 
229
    mov  ebx,50*65536+512+9
-
 
230
    mov  ecx,50*65536+512+22+4
185
    window 50,50,512+9,512+23,window_Skinned
231
    mov  edx,0x03000000
-
 
232
    int  0x40
-
 
233
 
-
 
234
    mov  eax,4                     ; WINDOW LABEL
186
    label  8,8,'Life Screen',cl_White+font_Big
235
    mov  ebx,8*65536+8
-
 
236
    mov  ecx,0x10ffffff
-
 
237
    mov  edx,header
-
 
238
    mov  esi,header.size
-
 
239
    int  0x40
187
    endwd
240
 
-
 
241
    mov     eax,12                    ; function 12:tell os about windowdraw
-
 
242
    mov     ebx,2                     ; 2, end of draw
-
 
243
    int     0x40
-
 
244
 
-
 
245
    ret
188
    ret
246
 
-
 
247
 
-
 
248
 
-
 
249
; DATA AREA
-
 
250
 
-
 
251
header          db  'Life'
-
 
252
   .size = $ - header
-
 
253
 
189
 
254
I_END:
190
I_END: