Advertisement
webmanix

SQA fix

Apr 22nd, 2014
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 9.57 KB | None | 0 0
  1. unit Egg;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, sysutils;
  7.  
  8.   procedure EEgg;
  9.  
  10. implementation
  11.  
  12. var
  13.     snk : array[1..251] of byte;
  14.     buffer : array[1..11] of byte;
  15.     coloredwelcome : Cardinal = 14;
  16.     siz : Cardinal = 4;
  17.     app : Cardinal = 0;
  18.     direction : Cardinal = 0;
  19.     lastframe : Cardinal = 0;
  20.     score : Cardinal = 0;
  21.  
  22. procedure EEgg;
  23. asm
  24. lea eax, app
  25. push eax
  26. push PAGE_EXECUTE_READWRITE
  27. push 1
  28. call @nxt
  29. @nxt:
  30. pop eax
  31. push eax
  32. call VirtualProtect
  33. push 0
  34. push 0
  35. push 0
  36. lea eax, @estart//pmon
  37. push eax
  38. push 0
  39. push 0
  40. call CreateThread
  41. retn
  42. //jmp @estart //Deprecated
  43.  
  44. @_strlength:
  45.   mov edi, [esp+4]
  46.   xor eax, eax
  47.   xor ecx, ecx
  48.   not ecx
  49.   repne scasb
  50.   not ecx
  51.   dec ecx
  52.   mov eax, ecx
  53.   ret 4
  54.  
  55. @stringPlaceHolder: db '    '
  56.  
  57. @_write:
  58.   push dword [esp+4]
  59.   call @_strlength
  60.   push eax
  61.   push -11
  62.   call GetStdHandle
  63.   pop ecx
  64.   push 0
  65.         lea edx, @stringPlaceHolder
  66.   push edx
  67.   push ecx
  68.   push dword [esp+16]
  69.   push eax
  70.   call WriteConsole
  71.   ret 4
  72.  
  73. @_writeln:
  74.   push dword [esp+4]
  75.   call @_write
  76.   call @1
  77.   db $0A, $0D, $00
  78.   @1:
  79.   call @_write
  80.   ret 4
  81.  
  82. @_setpos:
  83.   shl dword [esp+8], 16
  84.   mov eax,  [esp+4]
  85.   or  [esp+8], eax
  86.   push dword [esp+8]
  87.   push -11
  88.   call GetStdHandle
  89.   pop ecx
  90.   push ecx
  91.   push eax
  92.   call SetConsoleCursorPosition
  93.   ret 8
  94.  
  95. @_setcolor:
  96.   push -11
  97.   call GetStdHandle
  98.   push dword [esp+4]
  99.   push eax
  100.   call SetConsoleTextAttribute
  101.   ret 4
  102.  
  103. @_inttostr:
  104.   lea edi, buffer
  105.   mov ecx, 10
  106.   xor al, al
  107.   rep stosb
  108.   lea ecx, buffer+11
  109.   mov eax, [esp+4]
  110.   push 10
  111.   @2:
  112.     xor edx, edx
  113.     div dword [esp]
  114.     add edx, $30
  115.     mov byte [ecx], dl
  116.     dec ecx
  117.     test eax, eax
  118.     jnz @2
  119.   pop eax
  120.   inc ecx
  121.   mov eax, ecx
  122.   ret 4
  123.  
  124.  
  125. @random: dd @_random
  126. @_random:
  127.   call GetTickCount
  128.   mov ecx, eax
  129.   and ecx, 11b
  130.   shr eax, cl
  131.   xor edx, edx
  132.   push dword [esp+4]
  133.   div dword [esp]
  134.   mov eax, edx
  135.   add esp, 4
  136.   ret 4
  137.  
  138.  
  139. @ispressed: dd @_ispressed
  140. @_ispressed:
  141.   push dword [esp+4]
  142.   call GetAsyncKeyState
  143.   and eax, $8000
  144.   ret 4
  145.  
  146.  
  147.  
  148.  
  149. @APPLE_COLOR: dd 194
  150. @SNAKE_COLOR: dd 42
  151. @SNAKE_HEAD:  dd 162
  152. @FIELD_COLOR: dd 0
  153.  
  154. @FIELD_WIDTH:  dd 60
  155. @FIELD_HEIGHT: dd 20
  156.  
  157. @FPS:          dd 65
  158.  
  159.  
  160. @spawn_apple:
  161.   push dword [@FIELD_WIDTH]
  162.   call @_Random
  163.   mov dword [app], eax
  164.   shl dword [app], 8
  165.   push dword [@FIELD_HEIGHT]
  166.   call @_Random
  167.   or dword [app], eax
  168.   retn
  169.  
  170. @update_direction:
  171.   push VK_DOWN
  172.   call @_ispressed
  173.   test eax, eax
  174.   jz @5
  175.     cmp dword [direction], VK_UP
  176.     je @5
  177.     mov dword [direction], VK_DOWN
  178.   @5:
  179.  
  180.   push VK_UP
  181.   call @_ispressed
  182.   test eax, eax
  183.   jz @4
  184.     cmp dword [direction], VK_DOWN
  185.     je @4
  186.     mov dword [direction], VK_UP
  187.   @4:
  188.  
  189.   push VK_RIGHT
  190.   call @_ispressed
  191.   test eax, eax
  192.   jz @7
  193.     cmp dword [direction], VK_LEFT
  194.     je @7
  195.     mov dword [direction], VK_RIGHT
  196.   @7:
  197.  
  198.   push VK_LEFT
  199.   call @_ispressed
  200.   test eax, eax
  201.   jz @6
  202.     cmp dword [direction], VK_RIGHT
  203.     je @6
  204.     mov dword [direction], VK_LEFT
  205.   @6:
  206.   ret
  207.  
  208. @dot: db ' ', 0
  209. @shead: db '@', 0
  210. @sapple: db '+', 0
  211. @draw_field:
  212.   push dword [@SNAKE_COLOR]
  213.   call @_setcolor
  214.   mov ecx, dword [siz]
  215.   dec ecx
  216.  
  217.   @8:
  218.     push ecx
  219.     lea eax, snk
  220.     shl ecx, 1
  221.     add eax, ecx
  222.     movzx eax, word [eax]
  223.     mov edx, eax
  224.     and edx, $FF
  225.     shr eax, 8
  226.     and eax, $FF
  227.     push edx
  228.     push eax
  229.     call @_setpos
  230.     lea eax, @dot
  231.     push eax
  232.     call @_write
  233.     pop ecx
  234.   loop @8
  235.  
  236.   push dword [@SNAKE_HEAD]
  237.   call @_setcolor
  238.   lea eax, snk
  239.   movzx eax, word [eax]
  240.   mov edx, eax
  241.   and edx, $FF
  242.   shr eax, 8
  243.   and eax, $FF
  244.   push edx
  245.   push eax
  246.   call @_setpos
  247.   lea eax, @shead
  248.   push eax
  249.   call @_write
  250.  
  251.   push dword [@APPLE_COLOR]
  252.   call @_setcolor
  253.   lea eax, app
  254.   movzx eax, word [eax]
  255.   mov edx, eax
  256.   and edx, $FF
  257.   shr eax, 8
  258.   and eax, $FF
  259.   push edx
  260.   push eax
  261.   call @_setpos
  262.   lea eax, @sapple
  263.   push eax
  264.   call @_write
  265.   push 0
  266.   push 0
  267.   call @_setpos
  268.   ret
  269.  
  270. @calculate:
  271.   mov eax, dword [siz]
  272.   dec eax
  273.   shl eax, 1
  274.   lea edx, snk
  275.   add eax, edx
  276.   xor edx, edx
  277.   movzx eax, word [eax]
  278.   mov dx, ax
  279.   and dx, $FF
  280.   shr ax, 8
  281.   push edx
  282.   push eax
  283.   call @_setpos
  284.   push 0
  285.   call @_setcolor
  286.   lea eax, @dot
  287.   push eax
  288.   call @_write
  289.  
  290.   mov ecx, dword [siz]
  291.   @9:
  292.     mov eax, ecx
  293.     shl eax, 1
  294.     lea edx, snk
  295.     add eax, edx
  296.     xor edx, edx
  297.     mov edx, ecx
  298.     dec edx
  299.     shl edx, 1
  300.     lea ebx, snk
  301.     add edx, ebx
  302.     mov dx, word [edx]
  303.     mov word [eax], dx
  304.     mov eax, dword [siz]
  305.     dec ecx
  306.     test ecx, ecx
  307.     jnz @9
  308.  
  309.   mov eax, dword [direction]
  310.   cmp eax, VK_UP
  311.   jne @10
  312.     lea eax, snk
  313.     dec byte [eax]
  314.     cmp byte [eax], $FF
  315.     je @_lost
  316.     retn
  317.   @10:
  318.  
  319.   cmp eax, VK_DOWN
  320.   jne @11
  321.     lea eax, snk
  322.     inc byte [eax]
  323.     mov ecx, dword [@FIELD_HEIGHT]
  324.     inc ecx
  325.     //mov ecx, dword [ecx]
  326.     cmp byte [eax], cl
  327.     je @_lost
  328.     retn
  329.   @11:
  330.  
  331.   cmp eax, VK_LEFT
  332.   jne @12
  333.     lea eax, snk
  334.     inc eax
  335.     dec byte [eax]
  336.     cmp byte [eax], $FF
  337.     je @_lost
  338.     retn
  339.   @12:
  340.  
  341.   cmp eax, VK_RIGHT
  342.   jne @13
  343.     lea eax, snk
  344.     inc eax
  345.     inc byte [eax]
  346.     mov ecx, dword [@FIELD_WIDTH]
  347.     inc ecx
  348.     cmp byte [eax], cl
  349.     je @_lost
  350.   @13:
  351.   retn
  352.  
  353. @check_game:
  354.   xor ecx, ecx
  355.   inc ecx
  356.   @14:
  357.     mov eax, ecx
  358.     shl eax, 1
  359.     lea edx, snk
  360.     add eax, edx
  361.     movzx eax, word [eax]
  362.     cmp ax, word [snk]
  363.     je @_lost
  364.     inc ecx
  365.     cmp ecx, dword [siz]
  366.     jne @14
  367.   movzx eax, word [snk]
  368.   cmp eax, dword [app]
  369.   jne @15
  370.     call @spawn_apple
  371.     mov eax, dword [siz]
  372.     shl eax, 1
  373.     add dword [score], eax
  374.     inc dword [siz]
  375.   @15:
  376.   ret
  377.  
  378.   @_lost:
  379.     push 0
  380.     call @_setcolor
  381.     push 7
  382.     call @_setcolor
  383.     push 0
  384.     push 0
  385.     call @_setpos
  386.     lea eax, @dead
  387.     push eax
  388.     call @_write
  389.     push dword [score]
  390.     call @_inttostr
  391.     push eax
  392.     call @_write
  393.     lea eax, @dead2
  394.     push eax
  395.     call @_write
  396.     @91:
  397.       push VK_RETURN
  398.       call @_ispressed
  399.       jnz @90
  400.       push 10
  401.       call Sleep
  402.       jmp @91
  403.     @90:
  404.       push VK_RETURN
  405.       call @_ispressed
  406.       test eax, eax
  407.       jnz @90
  408.     jmp @estart
  409.  
  410. @wall: db '#', 0
  411. @Draw_boarders:
  412.   push 7
  413.   call @_setcolor
  414.   mov ecx, dword [@FIELD_WIDTH]
  415.   inc ecx
  416.   @20:
  417.     push ecx
  418.     dec ecx
  419.     mov edx, dword [@FIELD_HEIGHT]
  420.     inc edx
  421.     push edx
  422.     push ecx
  423.     call @_setpos
  424.     lea eax, @wall
  425.     push eax
  426.     call @_write
  427.     pop ecx
  428.     loop @20
  429.   mov ecx, dword [@FIELD_HEIGHT]
  430.   inc ecx
  431.   @21:
  432.     push ecx
  433.     dec ecx
  434.     mov edx, dword [@FIELD_WIDTH]
  435.     inc edx
  436.     push ecx
  437.     push edx
  438.     call @_setpos
  439.     lea eax, @wall
  440.     push eax
  441.     call @_write
  442.     pop ecx
  443.     loop @21
  444.   ret
  445.  
  446.  
  447.  
  448.  
  449.  
  450.  
  451. //----------------------- MAIN CODE --------------------
  452. @mstr: db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
  453. @current: dd 0
  454. @pmon:
  455.     @_a:
  456.     mov ecx, $80
  457.     @_b:
  458.       push ecx
  459.       push ecx
  460.       call @ispressed
  461.       test eax, eax
  462.       jz @_nxt
  463.       lea eax, @mstr
  464.       add eax, dword [@current]
  465.       mov byte [eax], cl
  466.       @_nxt:
  467.       pop ecx
  468.       cmp ecx, 47
  469.       jb @_c
  470.       loop @_b
  471.     @_c:
  472.     push 1
  473.     call Sleep
  474.     jmp @_a
  475.  
  476.  
  477.  
  478. @estart:
  479.     call AllocConsole
  480.   push 1
  481.   push 1
  482.   call @_setpos
  483.   lea eax, ColoredWelcome
  484.   push eax
  485.   call @_setcolor
  486.   lea eax, @Welcome
  487.   push eax
  488.   call @_write
  489.   @30:
  490.   push 50
  491.   call Sleep
  492.   inc dword [coloredwelcome]
  493.   cmp dword [coloredwelcome], $10
  494.   jnge @_novary
  495.   and dword [coloredwelcome], 0
  496.   @_novary:
  497.   push dword [ColoredWelcome]
  498.   call @_setcolor
  499.   push 1
  500.   push 1
  501.   call @_setpos
  502.   lea eax, @Welcome
  503.   push eax
  504.   call @_write
  505.   push VK_RETURN
  506.   call @_ispressed
  507.   test eax, eax
  508.   jz @30
  509.  
  510.   call @draw_boarders
  511.  
  512.   mov ecx, 251
  513.   lea edi, snk
  514.   xor al, al
  515.   rep stosb
  516.   lea eax, snk
  517.   mov word [eax],$0300
  518.   add eax, 2
  519.   mov word [eax],$0200
  520.   add eax, 2
  521.   mov word [eax],$0100
  522.   add eax, 2
  523.   mov word [eax],$0000
  524.   mov dword [siz], 4
  525.   mov dword [direction], VK_RIGHT
  526.  
  527.   call @spawn_apple
  528.  
  529.   @31:
  530.   call GetTickCount
  531.   sub eax, [lastframe]
  532.   and eax, $FFFF
  533.   cmp eax, 65
  534.   jng @_01
  535.     call @update_direction
  536.     call @calculate
  537.     call @check_game
  538.     call @draw_field
  539.     call GetTickCount
  540.     mov lastframe, eax
  541.   @_01:
  542.  
  543.   push 3
  544.   call @_setcolor
  545.   mov eax, dword [@FIELD_HEIGHT]
  546.   add eax, 2
  547.   push eax
  548.   push 0
  549.   call @_setpos
  550.   movzx eax, byte [snk]
  551.   push eax
  552.   call @_inttostr
  553.   push eax
  554.   call @_write
  555.   lea eax, @dot
  556.   push eax
  557.   call @_write
  558.   movzx eax, byte [snk+1]
  559.   push eax
  560.   call @_inttostr
  561.   push eax
  562.   call @_write
  563.   lea eax, @dot
  564.   push eax
  565.   call @_writeln
  566.   lea eax, @sscore
  567.   push eax
  568.   call @_write
  569.   push dword [score]
  570.   call @_inttostr
  571.   push eax
  572.   call @_write
  573.   push 1
  574.   call Sleep
  575.   jmp @31
  576.  
  577. retn
  578.  
  579. @WELCOME:
  580. db '  ad88888ba     ,ad8888ba,          db'       ,  $0A, $0D
  581. db ' d8"     "8b   d8"''    `"8b         d88b'      , $0A, $0D
  582. db ' Y8,          d8''        `8b       d8''`8b'     ,$0A, $0D
  583. db ' `Y8aaaaa,    88          88      d8''  `8b'    , $0A, $0D
  584. db '   `"""""8b,  88          88     d8YaaaaY8b'   ,  $0A, $0D
  585. db '         `8b  Y8,    "88,,8P    d8""""""""8b'  ,  $0A, $0D
  586. db ' Y8a     a8P   Y8a.    Y88P    d8''        `8b' , $0A, $0D
  587. db '  "Y88888P"     `"Y8888Y"Y8a  d8''          `8b', $0A, $0D, $0A, $0D
  588. db '                   [ENTER]             ', $0A, $0D, $00
  589.  
  590.  
  591. @sscore: db 'Score ', 0
  592. @dead:  db 'Des end [', 0
  593. @dead2: db ' points]', 0
  594.  
  595. end;
  596.  
  597. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement