Subversion Repositories Kolibri OS

Rev

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

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