Subversion Repositories Kolibri OS

Rev

Rev 5480 | 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.         stdcall akode.set_movement_speed, MOVEMENT_SPEED, 90
  83.  
  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 (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. ; ============================================================================ ;
  753. ; < eax = key scancode / 0 - no keys                                           ;
  754. ; ============================================================================ ;
  755. proc get_key
  756.         mcall   2                               ; get key scancode
  757.  
  758.         test    al, al
  759.         jz      @f
  760.         xor     eax, eax
  761.         jmp     .exit
  762.  
  763. @@:
  764.         shr     eax, 8
  765.  
  766.         cmp     eax, 0E1h
  767.         jne     @f
  768.  
  769.         wait_for_scancode
  770.         wait_for_scancode
  771.  
  772.         xor     eax, eax
  773.         jmp     .exit
  774.  
  775. @@:
  776.         xor     ebx, ebx
  777.         mov     ecx, eax
  778.  
  779.         cmp     eax, 0E0h
  780.         jne     @f
  781.  
  782.         wait_for_scancode
  783.  
  784.         mov     ecx, eax
  785.         or      eax, 0E000h
  786.         mov     ebx, 128
  787.  
  788. @@:
  789.         test    ecx, 80h
  790.         jnz     .key_up
  791.  
  792.         ; key down
  793.         add     ebx, ecx
  794.         lea     ebx, [PressedKeys + ebx * 4]
  795.  
  796.         mov     edx, [ebx]
  797.         test    edx, edx
  798.         jz      @f
  799.  
  800.         xor     eax, eax
  801.         jmp     .exit
  802.  
  803. @@:
  804.         inc     edx
  805.         mov     [ebx], edx
  806.         jmp     .exit
  807.  
  808. .key_up:
  809.         and     ecx, 7Fh
  810.         add     ebx, ecx
  811.         xor     edx, edx
  812.         mov     [PressedKeys + ebx * 4], edx
  813.  
  814. .exit:
  815.         ;DEBUGF  DEBUG_FINE, 'get_key: %x\n', eax:4
  816.         ret
  817. endp
  818. ; ============================================================================ ;
  819.  
  820. ; ============================================================================ ;
  821. ; < eax = 1 - key pressed / 0 - not pressed                                    ;
  822. ; ============================================================================ ;
  823. proc check_key scancode
  824.         mov     eax, [scancode]
  825.         mov     ecx, eax
  826.         shr     eax, 8
  827.         and     ecx, 7Fh
  828.         xor     ebx, ebx
  829.  
  830.         cmp     eax, 0E0h
  831.         jne     @f
  832.         mov     ebx, 128
  833.  
  834. @@:
  835.         add     ebx, ecx
  836.         mov     eax, [PressedKeys + ebx * 4]
  837.  
  838.         ret
  839. endp
  840. ; ============================================================================ ;
  841.  
  842. ; ============================================================================ ;
  843. proc level_load_callback uses eax ebx ecx, load_action, action_result
  844.         mov     eax, [load_action]
  845.         mov     ebx, [action_result]
  846.         xor     ecx, ecx
  847.  
  848.         cmp     eax, AKODE_LEVEL_LOAD.START
  849.         jne     @f
  850.         stdcall draw_image, [LevelLoadingImagePtr], ecx, ecx, [MainWindowWidth], [MainWindowHeight]
  851.  
  852.         cmp     ebx, -1
  853.         je      .level_load_failed
  854.  
  855.         mov     [GameMessage], ebx
  856.         inc     ecx
  857.         mov     [HudPanelNeedsRedraw], ecx
  858.         jmp     .exit
  859.  
  860. @@:     cmp     eax, AKODE_LEVEL_LOAD.END
  861.         jne     @f
  862.         DEBUGF  DEBUG_INFO, 'Level load result: %u\n', ebx
  863.  
  864.         test    ebx, ebx
  865.         jnz     .exit
  866.  
  867. .level_load_failed:
  868.         DEBUGF  DEBUG_ERR, 'Failed to load level\n'
  869.         mov     [GameStatus], GAME_STATUS.LEVEL_LOAD_FAILED
  870.         ;jmp     .exit
  871.  
  872. @@:
  873.  
  874. .exit:
  875.         ret
  876. endp
  877. ; ============================================================================ ;
  878.  
  879. ; ============================================================================ ;
  880. proc action_callback action, cell_x, cell_y, action_result
  881.         m2m     [GameMessage], [action_result]
  882.         mov     [HudPanelNeedsRedraw], 1
  883.         ret
  884. endp
  885. ; ============================================================================ ;
  886.  
  887. ; ============================================================================ ;
  888. proc add_object_to_inventory uses eax ecx edi, object_id, object_image_ptr
  889.         mov     edi, Inventory
  890.         mov     ecx, INVENTORY_SIZE
  891.  
  892. .inventory_loop:
  893.         mov     eax, [edi]
  894.         test    eax, eax
  895.         jnz     @f
  896.  
  897.         mov     eax, [object_id]
  898.         mov     [edi], eax
  899.         mov     eax, [object_image_ptr]
  900.         mov     [edi + 4], eax
  901.         mov     [HudPanelNeedsRedraw], ecx
  902.         jmp     .exit
  903.  
  904. @@:
  905.         add     edi, 8
  906.  
  907.         sub     ecx, 1
  908.         jnz     .inventory_loop
  909.  
  910. .exit:
  911.         ret
  912. endp
  913. ; ============================================================================ ;
  914.  
  915. ; ============================================================================ ;
  916. proc remove_object_from_inventory uses eax ecx esi, object_id
  917.         mov     eax, [object_id]
  918.         mov     esi, Inventory
  919.         mov     ecx, INVENTORY_SIZE
  920.  
  921. .inventory_loop:
  922.         cmp     [esi], eax
  923.         jne     @f
  924.  
  925.         xor     eax, eax
  926.         mov     [esi], eax
  927.         mov     [esi + 4], eax
  928.         mov     [HudPanelNeedsRedraw], ecx
  929.         jmp     .exit
  930.  
  931. @@:
  932.         add     esi, 8
  933.  
  934.         sub     ecx, 1
  935.         jnz     .inventory_loop
  936.  
  937. .exit:
  938.         ret
  939. endp
  940. ; ============================================================================ ;
  941.  
  942. ; ============================================================================ ;
  943. ; < eax = pointer to image data / 0 - fail                                     ;
  944. ; ============================================================================ ;
  945. proc load_object_image image_path_ptr
  946.         stdcall akode.load_and_scale_image, [image_path_ptr], OBJECT_IMAGE_WIDTH, OBJECT_IMAGE_HEIGHT, 0
  947.  
  948.         ret
  949. endp
  950. ; ============================================================================ ;
  951.  
  952. ; ============================================================================ ;
  953. proc free_object_image uses eax ebx ecx, image_ptr
  954.         mov     ecx, [image_ptr]
  955.         test    ecx, ecx
  956.         jz      .exit
  957.  
  958.         mcall   68, 13
  959.  
  960. .exit:
  961.         ret
  962. endp
  963. ; ============================================================================ ;
  964.  
  965. ; ============================================================================ ;
  966. proc player_death
  967.         mov     [GameStatus], GAME_STATUS.DEAD
  968.         ret
  969. endp
  970. ; ============================================================================ ;
  971.  
  972. ; ============================================================================ ;
  973. proc game_over
  974.         mov     [GameStatus], GAME_STATUS.END
  975.         ret
  976. endp
  977. ; ============================================================================ ;
  978.  
  979. ; ============================ Initialized data ============================== ;
  980. DATA
  981.         include 'data.inc'
  982.  
  983.         ; for debug-fdo
  984.         include_debug_strings
  985.  
  986.         align 4
  987.         @IMPORT:
  988.         include 'import.inc'
  989.  
  990. ; =========================== Uninitialized data ============================= ;
  991. UDATA
  992.         include 'udata.inc'
  993.  
  994. ; ================================= The End ================================== ;
  995. MEOS_APP_END