Subversion Repositories Kolibri OS

Rev

Rev 5480 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5480 Rev 5492
1
;    Copyright (C) 2014 Anton_K
1
;    Copyright (C) 2014 Anton_K
2
;
2
;
3
;    This program is free software: you can redistribute it and/or modify
3
;    This program is free software: you can redistribute it and/or modify
4
;    it under the terms of the GNU General Public License as published by
4
;    it under the terms of the GNU General Public License as published by
5
;    the Free Software Foundation, either version 2 of the License, or
5
;    the Free Software Foundation, either version 2 of the License, or
6
;    (at your option) any later version.
6
;    (at your option) any later version.
7
;
7
;
8
;    This program is distributed in the hope that it will be useful,
8
;    This program is distributed in the hope that it will be useful,
9
;    but WITHOUT ANY WARRANTY; without even the implied warranty of
9
;    but WITHOUT ANY WARRANTY; without even the implied warranty of
10
;    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
;    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
;    GNU General Public License for more details.
11
;    GNU General Public License for more details.
12
;
12
;
13
;    You should have received a copy of the GNU General Public License
13
;    You should have received a copy of the GNU General Public License
14
;    along with this program. If not, see .
14
;    along with this program. If not, see .
15
 
15
 
16
format binary as 'kex'
16
format binary as 'kex'
17
 
17
 
18
__DEBUG__       = 1             ; 0 - disable debug output / 1 - enable debug output
18
__DEBUG__       = 1             ; 0 - disable debug output / 1 - enable debug output
19
__DEBUG_LEVEL__ = DEBUG_FINE    ; DEBUG_FINE - all debug messages / DEBUG_INFO - info and errors / DEBUG_ERR - only errors
19
__DEBUG_LEVEL__ = DEBUG_FINE    ; DEBUG_FINE - all debug messages / DEBUG_INFO - info and errors / DEBUG_ERR - only errors
20
 
20
 
21
DEBUG_FINE      = 0
21
DEBUG_FINE      = 0
22
DEBUG_INFO      = 1
22
DEBUG_INFO      = 1
23
DEBUG_ERR       = 2
23
DEBUG_ERR       = 2
24
 
24
 
25
include '../../macros.inc'
25
include '../../macros.inc'
26
purge   mov, add, sub
26
purge   mov, add, sub
27
 
27
 
28
; ================================= Header =================================== ;
28
; ================================= Header =================================== ;
29
MEOS_APP_START
29
MEOS_APP_START
30
store dword StartupPath at $ - 4
30
store dword StartupPath at $ - 4
31
 
31
 
32
; ================================ Includes ================================== ;
32
; ================================ Includes ================================== ;
33
include '../../debug-fdo.inc'
33
include '../../debug-fdo.inc'
34
include '../../proc32.inc'
34
include '../../proc32.inc'
35
include '../../dll.inc'
35
include '../../dll.inc'
36
 
36
 
37
include 'AKODE/AKODE.inc'
37
include 'AKODE/AKODE.inc'
38
include 'datadef.inc'
38
include 'datadef.inc'
39
 
39
 
40
; =============================== Entry point ================================ ;
40
; =============================== Entry point ================================ ;
41
CODE
41
CODE
42
        DEBUGF  DEBUG_INFO, 'Started\n'
42
        DEBUGF  DEBUG_INFO, 'Started\n'
43
 
43
 
44
        mcall   68, 11                          ; initialize heap
44
        mcall   68, 11                          ; initialize heap
45
        test    eax, eax
45
        test    eax, eax
46
        jz      .exit_fail_heap_init
46
        jz      .exit_fail_heap_init
47
 
47
 
48
        stdcall dll.Load, @IMPORT               ; load libraries
48
        stdcall dll.Load, @IMPORT               ; load libraries
49
        test    eax, eax
49
        test    eax, eax
50
        jnz     .exit_fail_load_libs
50
        jnz     .exit_fail_load_libs
51
 
51
 
52
        mcall   40, MAIN_EVENT_MASK             ; used events
52
        mcall   40, MAIN_EVENT_MASK             ; used events
53
        mcall   66, 1, 1                        ; use scancodes
53
        mcall   66, 1, 1                        ; use scancodes
54
 
54
 
55
        stdcall draw_window
55
        stdcall draw_window
56
 
56
 
57
        mcall   9, ThreadInfoBuffer, -1         ; get real window size
57
        mcall   9, ThreadInfoBuffer, -1         ; get real window size
58
        mov     eax, [ebx + process_information.client_box.width]
58
        mov     eax, [ebx + process_information.client_box.width]
59
        inc     eax
59
        inc     eax
60
        mov     [MainWindowWidth], eax
60
        mov     [MainWindowWidth], eax
61
        mov     edx, [ebx + process_information.client_box.height]
61
        mov     edx, [ebx + process_information.client_box.height]
62
        inc     edx
62
        inc     edx
63
        mov     [MainWindowHeight], edx
63
        mov     [MainWindowHeight], edx
64
        DEBUGF  DEBUG_FINE, 'Window width: %u\nWindow height: %u\n', eax, edx
64
        DEBUGF  DEBUG_FINE, 'Window width: %u\nWindow height: %u\n', eax, edx
65
 
65
 
66
        mov     ecx, eax
66
        mov     ecx, eax
67
        shl     ecx, 2
67
        shl     ecx, 2
68
        imul    ecx, edx                        ; ecx = width * 4 * height
68
        imul    ecx, edx                        ; ecx = width * 4 * height
69
 
69
 
70
        sub     edx, HUD_PANEL_HEIGHT
70
        sub     edx, HUD_PANEL_HEIGHT
71
        mov     [WorldViewHeight], edx
71
        mov     [WorldViewHeight], edx
72
 
72
 
73
if FSAA
73
if FSAA
74
        shl     eax, FSAA
74
        shl     eax, FSAA
75
        shl     edx, FSAA
75
        shl     edx, FSAA
76
end if
76
end if
77
 
77
 
78
        stdcall akode.init, eax, edx, FIELD_OF_VIEW, BLOCK_BASE_SIZE, BLOCK_HEIGHT
78
        stdcall akode.init, eax, edx, FIELD_OF_VIEW, BLOCK_BASE_SIZE, BLOCK_HEIGHT
79
        test    eax, eax
79
        test    eax, eax
80
        jz      .exit_fail_akode_init
80
        jz      .exit_fail_akode_init
81
 
81
 
82
        stdcall akode.set_movement_speed, MOVEMENT_SPEED, 90
82
        stdcall akode.set_movement_speed, MOVEMENT_SPEED, 90
83
 
83
 
84
        mcall   68, 12                          ; alloc ecx bytes for image buffer
84
        mcall   68, 12                          ; alloc ecx bytes for image buffer
85
        test    eax, eax
85
        test    eax, eax
86
        jz      .exit_fail_alloc
86
        jz      .exit_fail_alloc
87
 
87
 
88
        mov     [ImageBufferPtr], eax
88
        mov     [ImageBufferPtr], eax
89
        push    eax
89
        push    eax
90
 
90
 
91
        stdcall set_startup_path
91
        stdcall set_startup_path
92
 
92
 
93
        stdcall load_hud_images
93
        stdcall load_hud_images
94
        test    eax, eax
94
        test    eax, eax
95
        jnz     @f
95
        jnz     @f
96
        DEBUGF  DEBUG_ERR, 'Failed to load HUD images\n'
96
        DEBUGF  DEBUG_ERR, 'Failed to load HUD images\n'
97
        jmp     .exit_fail_load_hud
97
        jmp     .exit_fail_load_hud
98
 
98
 
99
@@:
99
@@:
100
        cld
100
        cld
101
        xor     eax, eax
101
        xor     eax, eax
102
        mov     edi, PressedKeys
102
        mov     edi, PressedKeys
103
        mov     ecx, 128 * 2
103
        mov     ecx, 128 * 2
104
        rep     stosd
104
        rep     stosd
105
 
105
 
106
        mov     edi, Inventory
106
        mov     edi, Inventory
107
        mov     ecx, INVENTORY_SIZE * 2
107
        mov     ecx, INVENTORY_SIZE * 2
108
        rep     stosd
108
        rep     stosd
109
 
109
 
110
        stdcall akode.set_callbacks, level_load_callback, action_callback
110
        stdcall akode.set_callbacks, level_load_callback, action_callback
111
 
111
 
112
        stdcall akode.load_level, levels.level1
112
        stdcall akode.load_level, levels.level1
113
 
113
 
114
if FULLSCREEN
114
if FULLSCREEN
115
        stdcall hide_cursor
115
        stdcall hide_cursor
116
        push    eax
116
        push    eax
117
end if
117
end if
118
 
118
 
119
        stdcall main_loop
119
        stdcall main_loop
120
 
120
 
121
if FULLSCREEN
121
if FULLSCREEN
122
        pop     ecx
122
        pop     ecx
123
        test    ecx, ecx
123
        test    ecx, ecx
124
        jz      @f
124
        jz      @f
125
        mcall   37, 6                           ; delete cursor
125
        mcall   37, 6                           ; delete cursor
126
@@:
126
@@:
127
end if
127
end if
128
 
128
 
129
.exit_fail_load_hud:
129
.exit_fail_load_hud:
130
        stdcall free_hud_images
130
        stdcall free_hud_images
131
 
131
 
132
        pop     ecx
132
        pop     ecx
133
        mcall   68, 13                          ; free image buffer
133
        mcall   68, 13                          ; free image buffer
134
 
134
 
135
        jmp     .exit
135
        jmp     .exit
136
 
136
 
137
.exit_fail_heap_init:
137
.exit_fail_heap_init:
138
        DEBUGF  DEBUG_ERR, 'Heap initialization failed\n'
138
        DEBUGF  DEBUG_ERR, 'Heap initialization failed\n'
139
        jmp     .exit
139
        jmp     .exit
140
 
140
 
141
.exit_fail_load_libs:
141
.exit_fail_load_libs:
142
        DEBUGF  DEBUG_ERR, 'Failed to load libraries\n'
142
        DEBUGF  DEBUG_ERR, 'Failed to load libraries\n'
143
        jmp     .exit
143
        jmp     .exit
144
 
144
 
145
.exit_fail_akode_init:
145
.exit_fail_akode_init:
146
        DEBUGF  DEBUG_ERR, 'AKODE initialization failed\n'
146
        DEBUGF  DEBUG_ERR, 'AKODE initialization failed\n'
147
        jmp     .exit
147
        jmp     .exit
148
 
148
 
149
.exit_fail_alloc:
149
.exit_fail_alloc:
150
        DEBUGF  DEBUG_ERR, 'Memory allocation for image buffer failed\n'
150
        DEBUGF  DEBUG_ERR, 'Memory allocation for image buffer failed\n'
151
        ;jmp     .exit
151
        ;jmp     .exit
152
 
152
 
153
.exit:
153
.exit:
154
        stdcall akode.cleanup
154
        stdcall akode.cleanup
155
        DEBUGF  DEBUG_INFO, 'Exiting\n'
155
        DEBUGF  DEBUG_INFO, 'Exiting\n'
156
 
156
 
157
        xor     eax, eax
157
        xor     eax, eax
158
        dec     eax
158
        dec     eax
159
        mcall                                   ; kill this thread
159
        mcall                                   ; kill this thread
160
 
160
 
161
; ============================================================================ ;
161
; ============================================================================ ;
162
proc set_startup_path
162
proc set_startup_path
163
        cld
163
        cld
164
        mov     esi, StartupPath
164
        mov     esi, StartupPath
165
        mov     ecx, esi
165
        mov     ecx, esi
166
 
166
 
167
@@:
167
@@:
168
        lodsb
168
        lodsb
169
        test    al, al
169
        test    al, al
170
        jnz     @b
170
        jnz     @b
171
 
171
 
172
        sub     esi, 2
172
        sub     esi, 2
173
        std
173
        std
174
 
174
 
175
@@:
175
@@:
176
        lodsb
176
        lodsb
177
        cmp     al, '/'
177
        cmp     al, '/'
178
        jne     @b
178
        jne     @b
179
 
179
 
180
        mov     [esi + 1], byte 0
180
        mov     [esi + 1], byte 0
181
 
181
 
182
        mcall   30, 1                           ; set current directory
182
        mcall   30, 1                           ; set current directory
183
 
183
 
184
        ret
184
        ret
185
endp
185
endp
186
; ============================================================================ ;
186
; ============================================================================ ;
187
 
187
 
188
; ============================================================================ ;
188
; ============================================================================ ;
189
; < eax = 0 - fail                                                             ;
189
; < eax = 0 - fail                                                             ;
190
; ============================================================================ ;
190
; ============================================================================ ;
191
proc load_hud_images
191
proc load_hud_images
192
        mov     ebx, [MainWindowWidth]
192
        mov     ebx, [MainWindowWidth]
193
        mov     ecx, [MainWindowHeight]
193
        mov     ecx, [MainWindowHeight]
194
        xor     edx, edx
194
        xor     edx, edx
195
 
195
 
196
        stdcall akode.load_and_scale_image, LevelLoadingImageFile, ebx, ecx, edx
196
        stdcall akode.load_and_scale_image, LevelLoadingImageFile, ebx, ecx, edx
197
        test    eax, eax
197
        test    eax, eax
198
        jz      .exit
198
        jz      .exit
199
 
199
 
200
        mov     [LevelLoadingImagePtr], eax
200
        mov     [LevelLoadingImagePtr], eax
201
 
201
 
202
        stdcall akode.load_and_scale_image, DeathImageFile, ebx, ecx, edx
202
        stdcall akode.load_and_scale_image, DeathImageFile, ebx, ecx, edx
203
        test    eax, eax
203
        test    eax, eax
204
        jz      .exit
204
        jz      .exit
205
 
205
 
206
        mov     [DeathImagePtr], eax
206
        mov     [DeathImagePtr], eax
207
 
207
 
208
        stdcall akode.load_and_scale_image, EndImageFile, ebx, ecx, edx
208
        stdcall akode.load_and_scale_image, EndImageFile, ebx, ecx, edx
209
        test    eax, eax
209
        test    eax, eax
210
        jz      .exit
210
        jz      .exit
211
 
211
 
212
        mov     [EndImagePtr], eax
212
        mov     [EndImagePtr], eax
213
 
213
 
214
        stdcall akode.load_and_scale_image, HudPanelImageFile, ebx, HUD_PANEL_HEIGHT, edx
214
        stdcall akode.load_and_scale_image, HudPanelImageFile, ebx, HUD_PANEL_HEIGHT, edx
215
        test    eax, eax
215
        test    eax, eax
216
        jz      .exit
216
        jz      .exit
217
 
217
 
218
        mov     [HudPanelImagePtr], eax
218
        mov     [HudPanelImagePtr], eax
219
 
219
 
220
.exit:
220
.exit:
221
        ret
221
        ret
222
endp
222
endp
223
; ============================================================================ ;
223
; ============================================================================ ;
224
 
224
 
225
; ============================================================================ ;
225
; ============================================================================ ;
226
proc free_hud_images
226
proc free_hud_images
227
        xor     edx, edx
227
        xor     edx, edx
228
        mov     ebx, 13
228
        mov     ebx, 13
229
 
229
 
230
        mov     ecx, [LevelLoadingImagePtr]
230
        mov     ecx, [LevelLoadingImagePtr]
231
        test    ecx, ecx
231
        test    ecx, ecx
232
        jz      @f
232
        jz      @f
233
        mcall   68                              ; free
233
        mcall   68                              ; free
234
        mov     [LevelLoadingImagePtr], edx
234
        mov     [LevelLoadingImagePtr], edx
235
@@:
235
@@:
236
        mov     ecx, [HudPanelImagePtr]
236
        mov     ecx, [HudPanelImagePtr]
237
        test    ecx, ecx
237
        test    ecx, ecx
238
        jz      @f
238
        jz      @f
239
        mcall   68
239
        mcall   68
240
        mov     [HudPanelImagePtr], edx
240
        mov     [HudPanelImagePtr], edx
241
@@:
241
@@:
242
        mov     ecx, [DeathImagePtr]
242
        mov     ecx, [DeathImagePtr]
243
        test    ecx, ecx
243
        test    ecx, ecx
244
        jz      @f
244
        jz      @f
245
        mcall   68
245
        mcall   68
246
        mov     [DeathImagePtr], edx
246
        mov     [DeathImagePtr], edx
247
@@:
247
@@:
248
        mov     ecx, [EndImagePtr]
248
        mov     ecx, [EndImagePtr]
249
        test    ecx, ecx
249
        test    ecx, ecx
250
        jz      @f
250
        jz      @f
251
        mcall   68
251
        mcall   68
252
        mov     [EndImagePtr], edx
252
        mov     [EndImagePtr], edx
253
@@:
253
@@:
254
 
254
 
255
        ret
255
        ret
256
endp
256
endp
257
; ============================================================================ ;
257
; ============================================================================ ;
258
 
258
 
259
; ============================================================================ ;
259
; ============================================================================ ;
260
; < eax = cursor handle / 0 - fail                                             ;
260
; < eax = cursor handle / 0 - fail                                             ;
261
; ============================================================================ ;
261
; ============================================================================ ;
262
proc hide_cursor
262
proc hide_cursor
263
        mcall   68, 12, 32 * 32 * 4
263
        mcall   68, 12, 32 * 32 * 4
264
        test    eax, eax
264
        test    eax, eax
265
        jz      .exit
265
        jz      .exit
266
 
266
 
267
        mov     edi, eax
267
        mov     edi, eax
268
        xor     ebx, ebx
268
        xor     ebx, ebx
269
        shr     ecx, 2
269
        shr     ecx, 2
270
@@:     mov     [eax], ebx
270
@@:     mov     [eax], ebx
271
        add     eax, 4
271
        add     eax, 4
272
        loop    @b
272
        loop    @b
273
 
273
 
274
        mcall   37, 4, edi, 2                   ; load cursor
274
        mcall   37, 4, edi, 2                   ; load cursor
275
        mov     ecx, eax
275
        mov     ecx, eax
276
        inc     ebx
276
        inc     ebx
277
        mcall   37                              ; set cursor
277
        mcall   37                              ; set cursor
278
 
278
 
279
        xchg    edi, ecx
279
        xchg    edi, ecx
280
 
280
 
281
        mcall   68, 13
281
        mcall   68, 13
282
 
282
 
283
        mov     eax, edi
283
        mov     eax, edi
284
 
284
 
285
.exit:
285
.exit:
286
        ret
286
        ret
287
endp
287
endp
288
; ============================================================================ ;
288
; ============================================================================ ;
289
 
289
 
290
; ============================================================================ ;
290
; ============================================================================ ;
291
proc draw_image uses eax ebx ecx edx esi edi, image_ptr, x, y, width, height
291
proc draw_image uses eax ebx ecx edx esi edi, image_ptr, x, y, width, height
292
        mov     ebx, [image_ptr]
292
        mov     ebx, [image_ptr]
293
        mpack   ecx, [width], [height]
293
        mpack   ecx, [width], [height]
294
        mpack   edx, [x], [y]
294
        mpack   edx, [x], [y]
295
        mov     esi, 32
295
        mov     esi, 32
296
        xor     edi, edi
296
        xor     edi, edi
297
        xchg    edi, ebp
297
        xchg    edi, ebp
298
        mcall   65
298
        mcall   65
299
        mov     ebp, edi
299
        mov     ebp, edi
300
 
300
 
301
        ret
301
        ret
302
endp
302
endp
303
; ============================================================================ ;
303
; ============================================================================ ;
304
 
304
 
305
; ============================================================================ ;
305
; ============================================================================ ;
306
proc draw_image_to_buffer uses eax ebx ecx edx esi edi, image_ptr, x, y, width, height
306
proc draw_image_to_buffer uses eax ebx ecx edx esi edi, image_ptr, x, y, width, height
307
        cld
307
        cld
308
        mov     esi, [image_ptr]
308
        mov     esi, [image_ptr]
309
        mov     edi, [ImageBufferPtr]
309
        mov     edi, [ImageBufferPtr]
310
        mov     ebx, [MainWindowWidth]
310
        mov     ebx, [MainWindowWidth]
311
        mov     eax, [y]
311
        mov     eax, [y]
312
        mul     ebx
312
        mul     ebx
313
        add     eax, [x]
313
        add     eax, [x]
314
        lea     edi, [edi + eax * 4]
314
        lea     edi, [edi + eax * 4]
315
 
315
 
316
        sub     ebx, [width]
316
        sub     ebx, [width]
317
        shl     ebx, 2
317
        shl     ebx, 2
318
        mov     edx, [height]
318
        mov     edx, [height]
319
 
319
 
320
@@:
320
@@:
321
        mov     ecx, [width]
321
        mov     ecx, [width]
322
        rep     movsd
322
        rep     movsd
323
        add     edi, ebx
323
        add     edi, ebx
324
 
324
 
325
        sub     edx, 1
325
        sub     edx, 1
326
        jnz     @b
326
        jnz     @b
327
 
327
 
328
        ret
328
        ret
329
endp
329
endp
330
; ============================================================================ ;
330
; ============================================================================ ;
331
 
331
 
332
; ============================================================================ ;
332
; ============================================================================ ;
333
proc draw_image_with_transparency_to_buffer uses eax ebx ecx edx esi edi, image_ptr, x, y, width, height
333
proc draw_image_with_transparency_to_buffer uses eax ebx ecx edx esi edi, image_ptr, x, y, width, height
334
        mov     esi, [image_ptr]
334
        mov     esi, [image_ptr]
335
        mov     edi, [ImageBufferPtr]
335
        mov     edi, [ImageBufferPtr]
336
        mov     ebx, [MainWindowWidth]
336
        mov     ebx, [MainWindowWidth]
337
        mov     eax, [y]
337
        mov     eax, [y]
338
        mul     ebx
338
        mul     ebx
339
        add     eax, [x]
339
        add     eax, [x]
340
        lea     edi, [edi + eax * 4]
340
        lea     edi, [edi + eax * 4]
341
 
341
 
342
        sub     ebx, [width]
342
        sub     ebx, [width]
343
        shl     ebx, 2
343
        shl     ebx, 2
344
        mov     edx, [height]
344
        mov     edx, [height]
345
 
345
 
346
.y_draw_loop:
346
.y_draw_loop:
347
        mov     ecx, [width]
347
        mov     ecx, [width]
348
 
348
 
349
.x_draw_loop:
349
.x_draw_loop:
350
        mov     eax, [esi]
350
        mov     eax, [esi]
351
        cmp     eax, 0FF00FFh
351
        cmp     eax, 0FF00FFh
352
        je      @f
352
        je      @f
353
        mov     [edi], eax
353
        mov     [edi], eax
354
@@:
354
@@:
355
        add     esi, 4
355
        add     esi, 4
356
        add     edi, 4
356
        add     edi, 4
357
 
357
 
358
        sub     ecx, 1
358
        sub     ecx, 1
359
        jnz     .x_draw_loop
359
        jnz     .x_draw_loop
360
 
360
 
361
        add     edi, ebx
361
        add     edi, ebx
362
 
362
 
363
        sub     edx, 1
363
        sub     edx, 1
364
        jnz     .y_draw_loop
364
        jnz     .y_draw_loop
365
 
365
 
366
        ret
366
        ret
367
endp
367
endp
368
; ============================================================================ ;
368
; ============================================================================ ;
369
 
369
 
370
; ============================================================================ ;
370
; ============================================================================ ;
371
proc draw_window
371
proc draw_window
372
        mcall   12, 1                           ; start drawing
372
        mcall   12, 1                           ; start drawing
373
 
373
 
374
if FULLSCREEN
374
if FULLSCREEN
375
        mov     ebx, 0FFFFh
375
        mov     ebx, 0FFFFh
376
        mov     ecx, 0FFFFh
376
        mov     ecx, 0FFFFh
377
else
377
else
378
        mcall   48, 4                           ; eax - skin height
378
        mcall   48, 4                           ; eax - skin height
379
 
379
 
380
        mpack   ebx, MAIN_WINDOW_X, MAIN_WINDOW_WIDTH + 9
380
        mpack   ebx, MAIN_WINDOW_X, MAIN_WINDOW_WIDTH + 9
381
        mpack   ecx, MAIN_WINDOW_Y, MAIN_WINDOW_HEIGHT + 4
381
        mpack   ecx, MAIN_WINDOW_Y, MAIN_WINDOW_HEIGHT + 4
382
        add     ecx, eax
382
        add     ecx, eax
383
end if
383
end if
384
        mov     edx, MAIN_WINDOW_STYLE
384
        mov     edx, MAIN_WINDOW_STYLE
385
        mov     esi, MAIN_WINDOW_STYLE2
385
        mov     esi, MAIN_WINDOW_STYLE2
386
        mov     edi, MAIN_WINDOW_TITLE
386
        mov     edi, MAIN_WINDOW_TITLE
387
        xor     eax, eax
387
        xor     eax, eax
388
        mcall                                   ; draw window
388
        mcall                                   ; draw window
389
 
389
 
390
        mcall   12, 2                           ; end drawing
390
        mcall   12, 2                           ; end drawing
391
 
391
 
392
        ret
392
        ret
393
endp
393
endp
394
; ============================================================================ ;
394
; ============================================================================ ;
395
 
395
 
396
; ============================================================================ ;
396
; ============================================================================ ;
397
proc draw_world
397
proc draw_world
398
        mov     ebx, [ImageBufferPtr]
398
        mov     ebx, [ImageBufferPtr]
399
        ;test    ebx, ebx
399
        ;test    ebx, ebx
400
        ;jz      @f
400
        ;jz      @f
401
 
401
 
402
        stdcall akode.render
402
        stdcall akode.render
403
        stdcall akode.get_image, ebx, FSAA
403
        stdcall akode.get_image, ebx, FSAA
404
 
404
 
405
        mpack   ecx, [MainWindowWidth], [WorldViewHeight]
405
        mpack   ecx, [MainWindowWidth], [WorldViewHeight]
406
        xor     edx, edx
406
        xor     edx, edx
407
        mov     esi, 32
407
        mov     esi, 32
408
        xor     edi, edi
408
        xor     edi, edi
409
        xchg    edi, ebp
409
        xchg    edi, ebp
410
        mcall   65
410
        mcall   65
411
        mov     ebp, edi
411
        mov     ebp, edi
412
 
412
 
413
;@@:
413
;@@:
414
        ret
414
        ret
415
endp
415
endp
416
; ============================================================================ ;
416
; ============================================================================ ;
417
 
417
 
418
; ============================================================================ ;
418
; ============================================================================ ;
419
proc draw_hud
419
proc draw_hud
420
        mov     eax, [HudPanelNeedsRedraw]
420
        mov     eax, [HudPanelNeedsRedraw]
421
        test    eax, eax
421
        test    eax, eax
422
        jz      .exit
422
        jz      .exit
423
 
423
 
424
        xor     eax, eax
424
        xor     eax, eax
425
        mov     [HudPanelNeedsRedraw], eax
425
        mov     [HudPanelNeedsRedraw], eax
426
 
426
 
427
        stdcall draw_image_to_buffer, [HudPanelImagePtr], eax, [WorldViewHeight], [MainWindowWidth], HUD_PANEL_HEIGHT
427
        stdcall draw_image_to_buffer, [HudPanelImagePtr], eax, [WorldViewHeight], [MainWindowWidth], HUD_PANEL_HEIGHT
428
 
428
 
429
        mov     esi, Inventory + 4
429
        mov     esi, Inventory + 4
430
        mov     ebx, INVENTORY_Y
430
        mov     ebx, INVENTORY_Y
431
        add     ebx, [WorldViewHeight]
431
        add     ebx, [WorldViewHeight]
432
        mov     edx, 2
432
        mov     edx, 2
433
 
433
 
434
.y_inventory_loop:
434
.y_inventory_loop:
435
        mov     eax, INVENTORY_X
435
        mov     eax, INVENTORY_X
436
        mov     ecx, INVENTORY_SIZE / 2
436
        mov     ecx, INVENTORY_SIZE / 2
437
 
437
 
438
.x_inventory_loop:
438
.x_inventory_loop:
439
        mov     edi, [esi]
439
        mov     edi, [esi]
440
        add     esi, 8
440
        add     esi, 8
441
        test    edi, edi
441
        test    edi, edi
442
        jz      @f
442
        jz      @f
443
        stdcall draw_image_with_transparency_to_buffer, edi, eax, ebx, OBJECT_IMAGE_WIDTH, OBJECT_IMAGE_HEIGHT
443
        stdcall draw_image_with_transparency_to_buffer, edi, eax, ebx, OBJECT_IMAGE_WIDTH, OBJECT_IMAGE_HEIGHT
444
 
444
 
445
@@:
445
@@:
446
        add     eax, OBJECT_IMAGE_WIDTH + INVENTORY_PADDING_X
446
        add     eax, OBJECT_IMAGE_WIDTH + INVENTORY_PADDING_X
447
 
447
 
448
        sub     ecx, 1
448
        sub     ecx, 1
449
        jnz     .x_inventory_loop
449
        jnz     .x_inventory_loop
450
 
450
 
451
        add     ebx, OBJECT_IMAGE_HEIGHT + INVENTORY_PADDING_Y
451
        add     ebx, OBJECT_IMAGE_HEIGHT + INVENTORY_PADDING_Y
452
 
452
 
453
        sub     edx, 1
453
        sub     edx, 1
454
        jnz     .y_inventory_loop
454
        jnz     .y_inventory_loop
455
 
455
 
456
        mpack   ecx, [MainWindowWidth], HUD_PANEL_HEIGHT
456
        mpack   ecx, [MainWindowWidth], HUD_PANEL_HEIGHT
457
        mov     edx, [WorldViewHeight]
457
        mov     edx, [WorldViewHeight]
458
        mov     ebx, [ImageBufferPtr]
458
        mov     ebx, [ImageBufferPtr]
459
        mov     eax, [MainWindowWidth]
459
        mov     eax, [MainWindowWidth]
460
        imul    eax, edx
460
        imul    eax, edx
461
        lea     ebx, [ebx + eax * 4]
461
        lea     ebx, [ebx + eax * 4]
462
        mov     esi, 32
462
        mov     esi, 32
463
        xor     edi, edi
463
        xor     edi, edi
464
        xchg    edi, ebp
464
        xchg    edi, ebp
465
        mcall   65
465
        mcall   65
466
        mov     ebp, edi
466
        mov     ebp, edi
467
 
467
 
468
        jmp     draw_game_message
468
        jmp     draw_game_message
469
 
469
 
470
.exit:
470
.exit:
471
        ret
471
        ret
472
endp
472
endp
473
; ============================================================================ ;
473
; ============================================================================ ;
474
 
474
 
475
; ============================================================================ ;
475
; ============================================================================ ;
476
proc draw_game_message
476
proc draw_game_message
477
        mov     esi, [GameMessage]
477
        mov     esi, [GameMessage]
478
        test    esi, esi
478
        test    esi, esi
479
        jz      .exit
479
        jz      .exit
480
 
480
 
481
        mpack   ebx, GAME_MESSAGE_X, GAME_MESSAGE_Y
481
        mpack   ebx, GAME_MESSAGE_X, GAME_MESSAGE_Y
482
        add     ebx, [WorldViewHeight]
482
        add     ebx, [WorldViewHeight]
483
        mov     ecx, GAME_MESSAGE_COLOR or (80h shl 24)
483
        mov     ecx, GAME_MESSAGE_COLOR or (80h shl 24)
484
 
484
 
485
.draw_strings_loop:
485
.draw_strings_loop:
486
        mov     edx, esi
486
        mov     edx, esi
487
 
487
 
488
@@:
488
@@:
489
        mov     al, [esi]
489
        mov     al, [esi]
490
        add     esi, 1
490
        add     esi, 1
491
 
491
 
492
        test    al, al
492
        test    al, al
493
        jz      .draw_last_string
493
        jz      .draw_last_string
494
        cmp     al, 0Ah
494
        cmp     al, 0Ah
495
        jne     @b
495
        jne     @b
496
 
496
 
497
        mov     [esi - 1], byte 0
497
        mov     [esi - 1], byte 0
498
 
498
 
499
        mcall   4
499
        mcall   4
500
 
500
 
501
        mov     [esi - 1], byte 0Ah
501
        mov     [esi - 1], byte 0Ah
502
        add     ebx, 10
502
        add     ebx, 10
503
        jmp     .draw_strings_loop
503
        jmp     .draw_strings_loop
504
 
504
 
505
.draw_last_string:
505
.draw_last_string:
506
        mcall   4
506
        mcall   4
507
 
507
 
508
.exit:
508
.exit:
509
        ret
509
        ret
510
endp
510
endp
511
; ============================================================================ ;
511
; ============================================================================ ;
512
 
512
 
513
; ============================================================================ ;
513
; ============================================================================ ;
514
proc main_loop
514
proc main_loop
515
        locals
515
        locals
516
                frame_count     dd 0
516
                frame_count     dd 0
517
                last_timestamp  dd 0
517
                last_timestamp  dd 0
518
        endl
518
        endl
519
 
519
 
520
.main_loop:
520
.main_loop:
521
        mcall   26, 9                           ; get timestamp
521
        mcall   26, 9                           ; get timestamp
522
        mov     ebx, eax
522
        mov     ebx, eax
523
        sub     ebx, [last_timestamp]
523
        sub     ebx, [last_timestamp]
524
        cmp     ebx, 100
524
        cmp     ebx, 100
525
        jb      @f
525
        jb      @f
526
 
526
 
527
        mov     [last_timestamp], eax
527
        mov     [last_timestamp], eax
528
        imul    eax, [frame_count], 100
528
        imul    eax, [frame_count], 100
529
        xor     edx, edx
529
        xor     edx, edx
530
        mov     [frame_count], edx
530
        mov     [frame_count], edx
531
        div     ebx                             ; eax - fps
531
        div     ebx                             ; eax - fps
532
 
532
 
533
        DEBUGF  DEBUG_FINE, 'FPS: %u\n', eax
533
        DEBUGF  DEBUG_FINE, 'FPS: %u\n', eax
534
 
534
 
535
@@:
535
@@:
536
        mcall   11                              ; check events
536
        mcall   11                              ; check events
537
 
537
 
538
        test    eax, eax
538
        test    eax, eax
539
        jz      .idle
539
        jz      .idle
540
 
540
 
541
        dec     eax
541
        dec     eax
542
        jz      .redraw
542
        jz      .redraw
543
 
543
 
544
        dec     eax
544
        dec     eax
545
        jz      .key
545
        jz      .key
546
 
546
 
547
        dec     eax
547
        dec     eax
548
        jz      .button
548
        jz      .button
549
 
549
 
550
        sub     eax, 3
550
        sub     eax, 3
551
        jz      .mouse
551
        jz      .mouse
552
 
552
 
553
        jmp     .idle
553
        jmp     .idle
554
 
554
 
555
.redraw:
555
.redraw:
556
        stdcall draw_window
556
        stdcall draw_window
557
        mov     [HudPanelNeedsRedraw], 1
557
        mov     [HudPanelNeedsRedraw], 1
558
 
558
 
559
.idle:
559
.idle:
560
        mov     eax, [GameStatus]
560
        mov     eax, [GameStatus]
561
        test    eax, eax
561
        test    eax, eax
562
        jnz     @f
562
        jnz     @f
563
 
563
 
564
        stdcall akode.process
564
        stdcall akode.process
565
 
565
 
566
        mov     eax, [GameStatus]
566
        mov     eax, [GameStatus]
567
        test    eax, eax
567
        test    eax, eax
568
        jnz     @f
568
        jnz     @f
569
 
569
 
570
        stdcall draw_hud
570
        stdcall draw_hud
571
        stdcall draw_world
571
        stdcall draw_world
572
 
572
 
573
        add     [frame_count], 1
573
        add     [frame_count], 1
574
        jmp     .main_loop
574
        jmp     .main_loop
575
 
575
 
576
@@:     cmp     eax, GAME_STATUS.LEVEL_LOAD_FAILED
576
@@:     cmp     eax, GAME_STATUS.LEVEL_LOAD_FAILED
577
        jne     @f
577
        jne     @f
578
        jmp     .exit
578
        jmp     .exit
579
 
579
 
580
@@:     cmp     eax, GAME_STATUS.DEAD
580
@@:     cmp     eax, GAME_STATUS.DEAD
581
        jne     @f
581
        jne     @f
582
        stdcall draw_image, [DeathImagePtr], 0, 0, [MainWindowWidth], [MainWindowHeight]
582
        stdcall draw_image, [DeathImagePtr], 0, 0, [MainWindowWidth], [MainWindowHeight]
583
        jmp     .main_loop
583
        jmp     .main_loop
584
 
584
 
585
@@:     cmp     eax, GAME_STATUS.END
585
@@:     cmp     eax, GAME_STATUS.END
586
        jne     @f
586
        jne     @f
587
        stdcall draw_image, [EndImagePtr], 0, 0, [MainWindowWidth], [MainWindowHeight]
587
        stdcall draw_image, [EndImagePtr], 0, 0, [MainWindowWidth], [MainWindowHeight]
588
@@:
588
@@:
589
        jmp     .main_loop
589
        jmp     .main_loop
590
 
590
 
591
.key:
591
.key:
592
        stdcall get_key
592
        stdcall get_key
593
        test    eax, eax
593
        test    eax, eax
594
        jz      .idle
594
        jz      .idle
595
 
595
 
596
        cmp     eax, 001h                       ; Esc
596
        cmp     eax, 001h                       ; Esc
597
        je      .exit
597
        je      .exit
598
 
598
 
599
        cmp     eax, 039h                       ; Space
599
        cmp     eax, 039h                       ; Space
600
        je      .space_pressed
600
        je      .space_pressed
601
        cmp     eax, 002h                       ; 1
601
        cmp     eax, 002h                       ; 1
602
        jb      @f
602
        jb      @f
603
        cmp     eax, 00Bh                       ; 0
603
        cmp     eax, 00Bh                       ; 0
604
        ja      @f
604
        ja      @f
605
 
605
 
606
        ; 0..9 pressed
606
        ; 0..9 pressed
607
        sub     eax, 002h
607
        sub     eax, 002h
608
        mov     eax, dword [Inventory + eax * 8]
608
        mov     eax, dword [Inventory + eax * 8]
609
        test    eax, eax
609
        test    eax, eax
610
        jz      @f
610
        jz      @f
611
        shl     eax, 16
611
        shl     eax, 16
612
        push    eax
612
        push    eax
613
 
613
 
614
        stdcall check_key, 02Ah                 ; left Shift
614
        stdcall check_key, 02Ah                 ; left Shift
615
        test    eax, eax
615
        test    eax, eax
616
        jnz     .shift_pressed
616
        jnz     .shift_pressed
617
 
617
 
618
        stdcall check_key, 036h                 ; right Shift
618
        stdcall check_key, 036h                 ; right Shift
619
        test    eax, eax
619
        test    eax, eax
620
        jnz     .shift_pressed
620
        jnz     .shift_pressed
621
 
621
 
622
        pop     eax
622
        pop     eax
623
        or      eax, ACTION.USE_OBJECT
623
        or      eax, ACTION.USE_OBJECT
624
        stdcall akode.action, eax
624
        stdcall akode.action, eax
625
        jmp     @f
625
        jmp     @f
626
 
626
 
627
.shift_pressed:
627
.shift_pressed:
628
        pop     eax
628
        pop     eax
629
        or      eax, ACTION.LOOK_AT_OBJECT
629
        or      eax, ACTION.LOOK_AT_OBJECT
630
        stdcall akode.action, eax
630
        stdcall akode.action, eax
631
        jmp     @f
631
        jmp     @f
632
 
632
 
633
.space_pressed:
633
.space_pressed:
634
        stdcall check_key, 02Ah                 ; left Shift
634
        stdcall check_key, 02Ah                 ; left Shift
635
        test    eax, eax
635
        test    eax, eax
636
        jnz     .shift_pressed2
636
        jnz     .shift_pressed2
637
 
637
 
638
        stdcall check_key, 036h                 ; right Shift
638
        stdcall check_key, 036h                 ; right Shift
639
        test    eax, eax
639
        test    eax, eax
640
        jnz     .shift_pressed2
640
        jnz     .shift_pressed2
641
 
641
 
642
        stdcall akode.action, ACTION.DO_SOMETHING
642
        stdcall akode.action, ACTION.DO_SOMETHING
643
        jmp     @f
643
        jmp     @f
644
 
644
 
645
.shift_pressed2:
645
.shift_pressed2:
646
        stdcall akode.action, ACTION.LOOK_AROUND
646
        stdcall akode.action, ACTION.LOOK_AROUND
647
 
647
 
648
@@:
648
@@:
649
        xor     esi, esi
649
        xor     esi, esi
650
        dec     esi
650
        dec     esi
651
 
651
 
652
        stdcall check_key, 0E048h               ; ^
652
        stdcall check_key, 0E048h               ; ^
653
        test    eax, eax
653
        test    eax, eax
654
        jz      @f
654
        jz      @f
655
        mov     esi, AKODE_DIRECTION.NORTH
655
        mov     esi, AKODE_DIRECTION.NORTH
656
        jmp     .set_moving_direction
656
        jmp     .set_moving_direction
657
 
657
 
658
@@:     stdcall check_key, 0E050h               ; v
658
@@:     stdcall check_key, 0E050h               ; v
659
        test    eax, eax
659
        test    eax, eax
660
        jz      @f
660
        jz      @f
661
        mov     esi, AKODE_DIRECTION.SOUTH
661
        mov     esi, AKODE_DIRECTION.SOUTH
662
        jmp     .set_moving_direction
662
        jmp     .set_moving_direction
663
 
663
 
664
@@:     stdcall check_key, 011h                 ; W
664
@@:     stdcall check_key, 011h                 ; W
665
        test    eax, eax
665
        test    eax, eax
666
        jz      @f
666
        jz      @f
667
        mov     esi, AKODE_DIRECTION.NORTH
667
        mov     esi, AKODE_DIRECTION.NORTH
668
        jmp     .set_moving_direction
668
        jmp     .set_moving_direction
669
 
669
 
670
@@:     stdcall check_key, 01Fh                 ; S
670
@@:     stdcall check_key, 01Fh                 ; S
671
        test    eax, eax
671
        test    eax, eax
672
        jz      @f
672
        jz      @f
673
        mov     esi, AKODE_DIRECTION.SOUTH
673
        mov     esi, AKODE_DIRECTION.SOUTH
674
        ;jmp     .set_moving_direction
674
        ;jmp     .set_moving_direction
675
 
675
 
676
@@:
676
@@:
677
 
677
 
678
.set_moving_direction:
678
.set_moving_direction:
679
        test    esi, esi
679
        test    esi, esi
680
        js      @f
680
        js      @f
681
        stdcall akode.start_moving, esi
681
        stdcall akode.start_moving, esi
682
        jmp     .turn
682
        jmp     .turn
683
 
683
 
684
@@:
684
@@:
685
        stdcall akode.stop_moving
685
        stdcall akode.stop_moving
686
 
686
 
687
.turn:
687
.turn:
688
        xor     esi, esi
688
        xor     esi, esi
689
        dec     esi
689
        dec     esi
690
 
690
 
691
        stdcall check_key, 0E04Bh               ; <-
691
        stdcall check_key, 0E04Bh               ; <-
692
        test    eax, eax
692
        test    eax, eax
693
        jz      @f
693
        jz      @f
694
        mov     esi, AKODE_DIRECTION.WEST
694
        mov     esi, AKODE_DIRECTION.WEST
695
        jmp     .set_turning_direction
695
        jmp     .set_turning_direction
696
 
696
 
697
@@:     stdcall check_key, 0E04Dh               ; ->
697
@@:     stdcall check_key, 0E04Dh               ; ->
698
        test    eax, eax
698
        test    eax, eax
699
        jz      @f
699
        jz      @f
700
        mov     esi, AKODE_DIRECTION.EAST
700
        mov     esi, AKODE_DIRECTION.EAST
701
        jmp     .set_turning_direction
701
        jmp     .set_turning_direction
702
 
702
 
703
@@:     stdcall check_key, 01Eh                 ; A
703
@@:     stdcall check_key, 01Eh                 ; A
704
        test    eax, eax
704
        test    eax, eax
705
        jz      @f
705
        jz      @f
706
        mov     esi, AKODE_DIRECTION.WEST
706
        mov     esi, AKODE_DIRECTION.WEST
707
        jmp     .set_turning_direction
707
        jmp     .set_turning_direction
708
 
708
 
709
@@:     stdcall check_key, 020h                 ; D
709
@@:     stdcall check_key, 020h                 ; D
710
        test    eax, eax
710
        test    eax, eax
711
        jz      @f
711
        jz      @f
712
        mov     esi, AKODE_DIRECTION.EAST
712
        mov     esi, AKODE_DIRECTION.EAST
713
        ;jmp     .set_turning_direction
713
        ;jmp     .set_turning_direction
714
 
714
 
715
@@:
715
@@:
716
 
716
 
717
.set_turning_direction:
717
.set_turning_direction:
718
        test    esi, esi
718
        test    esi, esi
719
        js      @f
719
        js      @f
720
        stdcall akode.start_turning, esi
720
        stdcall akode.start_turning, esi
721
        jmp     .key
721
        jmp     .key
722
 
722
 
723
@@:
723
@@:
724
        stdcall akode.stop_turning
724
        stdcall akode.stop_turning
725
        jmp     .key
725
        jmp     .key
726
 
726
 
727
.mouse:
727
.mouse:
728
 
728
 
729
        jmp     .idle
729
        jmp     .idle
730
 
730
 
731
.button:
731
.button:
732
.exit:
732
.exit:
733
        ret
733
        ret
734
endp
734
endp
735
; ============================================================================ ;
735
; ============================================================================ ;
736
 
736
 
737
; ============================================================================ ;
737
; ============================================================================ ;
-
 
738
; < eax = key scancode (1 byte)                                                ;
-
 
739
; ============================================================================ ;
-
 
740
macro wait_for_scancode
-
 
741
{
-
 
742
        local   .wait
-
 
743
 
-
 
744
.wait:
-
 
745
        mcall   2
-
 
746
        test    al, al
-
 
747
        jnz     .wait
-
 
748
 
-
 
749
        shr     eax, 8
-
 
750
}
-
 
751
 
-
 
752
; ============================================================================ ;
738
; < eax = key scancode / 0 - no keys                                           ;
753
; < eax = key scancode / 0 - no keys                                           ;
739
; ============================================================================ ;
754
; ============================================================================ ;
740
proc get_key
755
proc get_key
741
        mcall   2                               ; get key scancode
756
        mcall   2                               ; get key scancode
742
 
757
 
743
        test    al, al
758
        test    al, al
744
        jz      @f
759
        jz      @f
745
        xor     eax, eax
760
        xor     eax, eax
746
        jmp     .exit
761
        jmp     .exit
747
 
762
 
748
@@:
763
@@:
749
        shr     eax, 8
764
        shr     eax, 8
750
 
765
 
751
        cmp     eax, 0E1h
766
        cmp     eax, 0E1h
752
        jne     @f
767
        jne     @f
-
 
768
 
753
        mcall   2
769
        wait_for_scancode
754
        mcall   2
770
        wait_for_scancode
-
 
771
 
755
        xor     eax, eax
772
        xor     eax, eax
756
        jmp     .exit
773
        jmp     .exit
757
 
774
 
758
@@:
775
@@:
759
        xor     ebx, ebx
776
        xor     ebx, ebx
760
        mov     ecx, eax
777
        mov     ecx, eax
761
 
778
 
762
        cmp     eax, 0E0h
779
        cmp     eax, 0E0h
763
        jne     @f
780
        jne     @f
764
        mcall   2
-
 
-
 
781
 
765
        shr     eax, 8
782
        wait_for_scancode
-
 
783
 
766
        mov     ecx, eax
784
        mov     ecx, eax
767
        or      eax, 0E000h
785
        or      eax, 0E000h
768
        mov     ebx, 128
786
        mov     ebx, 128
769
 
787
 
770
@@:
788
@@:
771
        test    ecx, 80h
789
        test    ecx, 80h
772
        jnz     .key_up
790
        jnz     .key_up
773
 
791
 
774
        ; key down
792
        ; key down
775
        add     ebx, ecx
793
        add     ebx, ecx
776
        lea     ebx, [PressedKeys + ebx * 4]
794
        lea     ebx, [PressedKeys + ebx * 4]
777
 
795
 
778
        mov     edx, [ebx]
796
        mov     edx, [ebx]
779
        test    edx, edx
797
        test    edx, edx
780
        jz      @f
798
        jz      @f
781
 
799
 
782
        xor     eax, eax
800
        xor     eax, eax
783
        jmp     .exit
801
        jmp     .exit
784
 
802
 
785
@@:
803
@@:
786
        inc     edx
804
        inc     edx
787
        mov     [ebx], edx
805
        mov     [ebx], edx
788
        jmp     .exit
806
        jmp     .exit
789
 
807
 
790
.key_up:
808
.key_up:
791
        and     ecx, 7Fh
809
        and     ecx, 7Fh
792
        add     ebx, ecx
810
        add     ebx, ecx
793
        xor     edx, edx
811
        xor     edx, edx
794
        mov     [PressedKeys + ebx * 4], edx
812
        mov     [PressedKeys + ebx * 4], edx
795
 
813
 
796
.exit:
814
.exit:
-
 
815
        ;DEBUGF  DEBUG_FINE, 'get_key: %x\n', eax:4
797
        ret
816
        ret
798
endp
817
endp
799
; ============================================================================ ;
818
; ============================================================================ ;
800
 
819
 
801
; ============================================================================ ;
820
; ============================================================================ ;
802
; < eax = 1 - key pressed / 0 - not pressed                                    ;
821
; < eax = 1 - key pressed / 0 - not pressed                                    ;
803
; ============================================================================ ;
822
; ============================================================================ ;
804
proc check_key scancode
823
proc check_key scancode
805
        mov     eax, [scancode]
824
        mov     eax, [scancode]
806
        mov     ecx, eax
825
        mov     ecx, eax
807
        shr     eax, 8
826
        shr     eax, 8
808
        and     ecx, 7Fh
827
        and     ecx, 7Fh
809
        xor     ebx, ebx
828
        xor     ebx, ebx
810
 
829
 
811
        cmp     eax, 0E0h
830
        cmp     eax, 0E0h
812
        jne     @f
831
        jne     @f
813
        mov     ebx, 128
832
        mov     ebx, 128
814
 
833
 
815
@@:
834
@@:
816
        add     ebx, ecx
835
        add     ebx, ecx
817
        mov     eax, [PressedKeys + ebx * 4]
836
        mov     eax, [PressedKeys + ebx * 4]
818
 
837
 
819
        ret
838
        ret
820
endp
839
endp
821
; ============================================================================ ;
840
; ============================================================================ ;
822
 
841
 
823
; ============================================================================ ;
842
; ============================================================================ ;
824
proc level_load_callback uses eax ebx ecx, load_action, action_result
843
proc level_load_callback uses eax ebx ecx, load_action, action_result
825
        mov     eax, [load_action]
844
        mov     eax, [load_action]
826
        mov     ebx, [action_result]
845
        mov     ebx, [action_result]
827
        xor     ecx, ecx
846
        xor     ecx, ecx
828
 
847
 
829
        cmp     eax, AKODE_LEVEL_LOAD.START
848
        cmp     eax, AKODE_LEVEL_LOAD.START
830
        jne     @f
849
        jne     @f
831
        stdcall draw_image, [LevelLoadingImagePtr], ecx, ecx, [MainWindowWidth], [MainWindowHeight]
850
        stdcall draw_image, [LevelLoadingImagePtr], ecx, ecx, [MainWindowWidth], [MainWindowHeight]
832
 
851
 
833
        cmp     ebx, -1
852
        cmp     ebx, -1
834
        je      .level_load_failed
853
        je      .level_load_failed
835
 
854
 
836
        mov     [GameMessage], ebx
855
        mov     [GameMessage], ebx
837
        inc     ecx
856
        inc     ecx
838
        mov     [HudPanelNeedsRedraw], ecx
857
        mov     [HudPanelNeedsRedraw], ecx
839
        jmp     .exit
858
        jmp     .exit
840
 
859
 
841
@@:     cmp     eax, AKODE_LEVEL_LOAD.END
860
@@:     cmp     eax, AKODE_LEVEL_LOAD.END
842
        jne     @f
861
        jne     @f
843
        DEBUGF  DEBUG_INFO, 'Level load result: %u\n', ebx
862
        DEBUGF  DEBUG_INFO, 'Level load result: %u\n', ebx
844
 
863
 
845
        test    ebx, ebx
864
        test    ebx, ebx
846
        jnz     .exit
865
        jnz     .exit
847
 
866
 
848
.level_load_failed:
867
.level_load_failed:
849
        DEBUGF  DEBUG_ERR, 'Failed to load level\n'
868
        DEBUGF  DEBUG_ERR, 'Failed to load level\n'
850
        mov     [GameStatus], GAME_STATUS.LEVEL_LOAD_FAILED
869
        mov     [GameStatus], GAME_STATUS.LEVEL_LOAD_FAILED
851
        ;jmp     .exit
870
        ;jmp     .exit
852
 
871
 
853
@@:
872
@@:
854
 
873
 
855
.exit:
874
.exit:
856
        ret
875
        ret
857
endp
876
endp
858
; ============================================================================ ;
877
; ============================================================================ ;
859
 
878
 
860
; ============================================================================ ;
879
; ============================================================================ ;
861
proc action_callback action, cell_x, cell_y, action_result
880
proc action_callback action, cell_x, cell_y, action_result
862
        m2m     [GameMessage], [action_result]
881
        m2m     [GameMessage], [action_result]
863
        mov     [HudPanelNeedsRedraw], 1
882
        mov     [HudPanelNeedsRedraw], 1
864
        ret
883
        ret
865
endp
884
endp
866
; ============================================================================ ;
885
; ============================================================================ ;
867
 
886
 
868
; ============================================================================ ;
887
; ============================================================================ ;
869
proc add_object_to_inventory uses eax ecx edi, object_id, object_image_ptr
888
proc add_object_to_inventory uses eax ecx edi, object_id, object_image_ptr
870
        mov     edi, Inventory
889
        mov     edi, Inventory
871
        mov     ecx, INVENTORY_SIZE
890
        mov     ecx, INVENTORY_SIZE
872
 
891
 
873
.inventory_loop:
892
.inventory_loop:
874
        mov     eax, [edi]
893
        mov     eax, [edi]
875
        test    eax, eax
894
        test    eax, eax
876
        jnz     @f
895
        jnz     @f
877
 
896
 
878
        mov     eax, [object_id]
897
        mov     eax, [object_id]
879
        mov     [edi], eax
898
        mov     [edi], eax
880
        mov     eax, [object_image_ptr]
899
        mov     eax, [object_image_ptr]
881
        mov     [edi + 4], eax
900
        mov     [edi + 4], eax
882
        mov     [HudPanelNeedsRedraw], ecx
901
        mov     [HudPanelNeedsRedraw], ecx
883
        jmp     .exit
902
        jmp     .exit
884
 
903
 
885
@@:
904
@@:
886
        add     edi, 8
905
        add     edi, 8
887
 
906
 
888
        sub     ecx, 1
907
        sub     ecx, 1
889
        jnz     .inventory_loop
908
        jnz     .inventory_loop
890
 
909
 
891
.exit:
910
.exit:
892
        ret
911
        ret
893
endp
912
endp
894
; ============================================================================ ;
913
; ============================================================================ ;
895
 
914
 
896
; ============================================================================ ;
915
; ============================================================================ ;
897
proc remove_object_from_inventory uses eax ecx esi, object_id
916
proc remove_object_from_inventory uses eax ecx esi, object_id
898
        mov     eax, [object_id]
917
        mov     eax, [object_id]
899
        mov     esi, Inventory
918
        mov     esi, Inventory
900
        mov     ecx, INVENTORY_SIZE
919
        mov     ecx, INVENTORY_SIZE
901
 
920
 
902
.inventory_loop:
921
.inventory_loop:
903
        cmp     [esi], eax
922
        cmp     [esi], eax
904
        jne     @f
923
        jne     @f
905
 
924
 
906
        xor     eax, eax
925
        xor     eax, eax
907
        mov     [esi], eax
926
        mov     [esi], eax
908
        mov     [esi + 4], eax
927
        mov     [esi + 4], eax
909
        mov     [HudPanelNeedsRedraw], ecx
928
        mov     [HudPanelNeedsRedraw], ecx
910
        jmp     .exit
929
        jmp     .exit
911
 
930
 
912
@@:
931
@@:
913
        add     esi, 8
932
        add     esi, 8
914
 
933
 
915
        sub     ecx, 1
934
        sub     ecx, 1
916
        jnz     .inventory_loop
935
        jnz     .inventory_loop
917
 
936
 
918
.exit:
937
.exit:
919
        ret
938
        ret
920
endp
939
endp
921
; ============================================================================ ;
940
; ============================================================================ ;
922
 
941
 
923
; ============================================================================ ;
942
; ============================================================================ ;
924
; < eax = pointer to image data / 0 - fail                                     ;
943
; < eax = pointer to image data / 0 - fail                                     ;
925
; ============================================================================ ;
944
; ============================================================================ ;
926
proc load_object_image image_path_ptr
945
proc load_object_image image_path_ptr
927
        stdcall akode.load_and_scale_image, [image_path_ptr], OBJECT_IMAGE_WIDTH, OBJECT_IMAGE_HEIGHT, 0
946
        stdcall akode.load_and_scale_image, [image_path_ptr], OBJECT_IMAGE_WIDTH, OBJECT_IMAGE_HEIGHT, 0
928
 
947
 
929
        ret
948
        ret
930
endp
949
endp
931
; ============================================================================ ;
950
; ============================================================================ ;
932
 
951
 
933
; ============================================================================ ;
952
; ============================================================================ ;
934
proc free_object_image uses eax ebx ecx, image_ptr
953
proc free_object_image uses eax ebx ecx, image_ptr
935
        mov     ecx, [image_ptr]
954
        mov     ecx, [image_ptr]
936
        test    ecx, ecx
955
        test    ecx, ecx
937
        jz      .exit
956
        jz      .exit
938
 
957
 
939
        mcall   68, 13
958
        mcall   68, 13
940
 
959
 
941
.exit:
960
.exit:
942
        ret
961
        ret
943
endp
962
endp
944
; ============================================================================ ;
963
; ============================================================================ ;
945
 
964
 
946
; ============================================================================ ;
965
; ============================================================================ ;
947
proc player_death
966
proc player_death
948
        mov     [GameStatus], GAME_STATUS.DEAD
967
        mov     [GameStatus], GAME_STATUS.DEAD
949
        ret
968
        ret
950
endp
969
endp
951
; ============================================================================ ;
970
; ============================================================================ ;
952
 
971
 
953
; ============================================================================ ;
972
; ============================================================================ ;
954
proc game_over
973
proc game_over
955
        mov     [GameStatus], GAME_STATUS.END
974
        mov     [GameStatus], GAME_STATUS.END
956
        ret
975
        ret
957
endp
976
endp
958
; ============================================================================ ;
977
; ============================================================================ ;
959
 
978
 
960
; ============================ Initialized data ============================== ;
979
; ============================ Initialized data ============================== ;
961
DATA
980
DATA
962
        include 'data.inc'
981
        include 'data.inc'
963
 
982
 
964
        ; for debug-fdo
983
        ; for debug-fdo
965
        include_debug_strings
984
        include_debug_strings
966
 
985
 
967
        align 4
986
        align 4
968
        @IMPORT:
987
        @IMPORT:
969
        include 'import.inc'
988
        include 'import.inc'
970
 
989
 
971
; =========================== Uninitialized data ============================= ;
990
; =========================== Uninitialized data ============================= ;
972
UDATA
991
UDATA
973
        include 'udata.inc'
992
        include 'udata.inc'
974
 
993
 
975
; ================================= The End ================================== ;
994
; ================================= The End ================================== ;
976
MEOS_APP_END
995
MEOS_APP_END
977
>
996
>