Subversion Repositories Kolibri OS

Rev

Rev 5314 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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