Advertisement
orda_burda

Ассемблер Игра

Dec 22nd, 2023 (edited)
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. .include "m8535def.inc"
  2. .def Acc0 = r20
  3. .def ind_out1 = r21
  4. .def Acc1 = r22
  5. .def cursor = r23
  6. .def Acc2 = r24
  7. .def enemy = r25
  8. .def enemy_pos = r26
  9. .def Acc3 = r27
  10. .def step = r28
  11. .def level_start = r19
  12. .def level_numb = r18
  13.  
  14.  
  15. .org 0x00
  16.     rjmp Reset
  17.  
  18. .org 0x006
  19.     rjmp Timer1Ovf
  20.  
  21. .org 0x15
  22. Reset:
  23.  
  24.     ldi Acc0, high(RAMEND)
  25.     out SPH, Acc0
  26.     ldi Acc0, low(RAMEND)
  27.     out SPL, Acc0
  28.  
  29.     ldi Acc0, 1
  30.     com Acc0
  31.        
  32.     sbi DDRC, 0
  33.     sbi DDRC, 1
  34.  
  35.     sbi DDRB, 4
  36.     sbi DDRB, 5
  37.     sbi DDRB, 6
  38.     sbi DDRB, 7
  39.  
  40.     cbi DDRD, 5
  41.     cbi DDRD, 6
  42.     cbi DDRD, 7
  43.  
  44.     ldi Acc0, 0b00000000
  45.     out TCCR1A, Acc0
  46.     ldi Acc0, 0b00001000
  47.     out TCCR1B, Acc0
  48.  
  49.     ldi Acc0, 200
  50.     out OCR1AH, Acc0
  51.     ldi Acc0, 255
  52.     out OCR1AL, Acc0
  53.  
  54.     ldi Acc0, 0b00010000
  55.     out TIMSK, Acc0
  56.  
  57.     ldi step, 3
  58.     ldi level_start, 0
  59.  
  60.     ldi cursor, 0b10000000
  61.  
  62.     ldi level_numb, 1
  63.     rcall LevelLabel
  64.    
  65.     sei
  66.  
  67. Loop:
  68.     sbi portB, 4
  69.     cbi portB, 5
  70.     sbi portB, 6
  71.     sbi portB, 7
  72.     nop
  73.     nop
  74.     nop
  75.     sbis PIND, 5
  76.     rjmp left
  77.  
  78.     sbi portB, 4
  79.     cbi portB, 5
  80.     sbi portB, 6
  81.     sbi portB, 7
  82.     nop
  83.     nop
  84.     nop
  85.     sbis PIND, 6
  86.     rjmp shoot
  87.  
  88.     sbi portB, 4
  89.     cbi portB, 5
  90.     sbi portB, 6
  91.     sbi portB, 7
  92.     nop
  93.     nop
  94.     nop
  95.     sbis PIND, 7
  96.     rjmp right
  97.  
  98.     rjmp end
  99.  
  100. left:
  101.     ldi Acc0, 1
  102.     rcall Game
  103.     rcall Wait1
  104.     rcall indicator_out4
  105.     rjmp end
  106.  
  107. shoot:
  108.     ldi Acc0, 2
  109.     rcall Game
  110.     rcall Wait2
  111.     rcall indicator_out4
  112.     rjmp end
  113.  
  114.  
  115. right:
  116.     ldi Acc0, 3
  117.     rcall Game
  118.     rcall Wait3
  119.     rcall indicator_out4
  120.     rjmp end
  121.  
  122.  
  123.  
  124. end:
  125.  
  126. rjmp Loop
  127.  
  128. Game:
  129.     ;если уровень = 0 начать отсчёт и =1
  130.    
  131.        
  132.     cpi level_start, 0
  133.     brne shoott
  134.     ldi level_start, 1
  135.     ldi Acc0, 0b00001100
  136.     out TCCR1B, Acc0
  137.     ldi step, 1
  138.     rjmp end_game
  139.  
  140. shoott:
  141.     cpi Acc0, 2
  142.     brne move_right
  143.     or enemy, cursor
  144.     sub enemy, cursor
  145.     rjmp end_game
  146.    
  147. move_right:
  148.     cpi Acc0, 3
  149.     brne move_left
  150.     cpi cursor, 16
  151.     breq end_game
  152.     lsr cursor
  153.  
  154. move_left:
  155.     cpi Acc0, 1
  156.     brne end_game
  157.     cpi cursor, 128
  158.     breq end_game
  159.     lsl cursor
  160.  
  161.  
  162. end_game:
  163. ;   cpi enemy, 0
  164. ;   brne end_game_1
  165. ;   inc level_numb
  166. ;end_game_1:
  167. ret
  168.  
  169. LevelLabel:
  170.     ldi ind_out1, 0b11000111
  171.     rcall indicator_out1
  172.     ldi ind_out1, 0b11000001
  173.     rcall indicator_out1
  174.     ldi ind_out1, 0b11000111
  175.     rcall indicator_out1
  176. lvl1:
  177.     cpi level_numb, 1
  178.     ldi enemy, 0b10000000
  179.     brne lvl2
  180.     ldi ind_out1, 0b11111001
  181.     rcall indicator_out1
  182.     rjmp endLabel
  183. lvl2:
  184.     cpi level_numb, 2
  185.     ldi enemy, 0b11000000
  186.     brne lvl3
  187.     ldi ind_out1, 0b10100100
  188.     rcall indicator_out1
  189.     rjmp endLabel
  190. lvl3:
  191.     cpi level_numb, 3
  192.     ldi enemy, 0b11010000
  193.     brne lvl4
  194.     ldi ind_out1, 0b10110000
  195.     rcall indicator_out1
  196.     rjmp endLabel
  197. lvl4:
  198.     cpi level_numb, 4
  199.     ldi enemy, 0b11110000
  200.     brne lvl5
  201.     ldi ind_out1, 0b10011001
  202.     rcall indicator_out1
  203.     rjmp endLabel
  204.  
  205. lvl5:
  206.     ldi level_numb, 1
  207.     ldi ind_out1, 0b11111001
  208.     rcall indicator_out1
  209.     rjmp endLabel
  210.  
  211. endLabel:
  212. ret
  213.  
  214.  
  215. indicator_out4:
  216.     cpi step, 1
  217.     brne step2
  218.     ldi enemy_pos, 0b00000001
  219.     rjmp output_start
  220. step2:
  221.     cpi step, 2
  222.     brne step3
  223.     ldi enemy_pos, 0b01000000
  224.     rjmp output_start
  225. step3:
  226.     cpi enemy, 0
  227.     brne loose
  228.     inc level_numb
  229.     rjmp label
  230. loose:
  231.     ldi level_numb, 1
  232. label:
  233.     rcall LevelLabel
  234.  
  235.     ldi step, 0
  236.     ldi Acc0, 0b00001000
  237.     out TCCR1B, Acc0
  238.     ldi Acc0, 0b00000000
  239.     out TCNT1H, Acc0
  240.     out TCNT1L, Acc0
  241.     ldi level_start, 0
  242.     rjmp end_ind4_1
  243.  
  244.  
  245. output_start:
  246.     clr ind_out1
  247.     mov Acc0, cursor
  248.     mov Acc3, enemy
  249.     clr Acc2
  250.     ind_loop4:
  251.         inc Acc2
  252.         lsl Acc0
  253.         brcc non
  254.     cusorr:
  255.         ldi ind_out1, 0b00001000
  256.         rjmp enemy_ind
  257.     non:
  258.         ldi ind_out1, 0b00000000
  259.  
  260.     enemy_ind:
  261.         lsl Acc3
  262.         brcc end_ind4
  263.         add ind_out1, enemy_pos
  264.        
  265.     end_ind4:
  266.         com ind_out1
  267.         rcall indicator_out1
  268.         cpi Acc2, 4
  269.         brne ind_loop4
  270.  
  271. end_ind4_1:
  272.  
  273. ret
  274.        
  275.  
  276. indicator_out1:
  277.     clr Acc1
  278.     ind_loop1:
  279.         inc Acc1
  280.         lsl ind_out1
  281.         brcc SetZero
  282.     SetOne:
  283.         sbi PortC, 1
  284.         rjmp Clock
  285.     SetZero:
  286.         cbi PortC, 1
  287.     Clock:
  288.         sbi PortC, 0
  289.         nop
  290.         nop
  291.         cbi PortC, 0
  292.         cpi Acc1, 8
  293.         brne ind_loop1
  294. ret
  295.  
  296. Wait1:
  297. Wait1_Loop:
  298.     rcall delay
  299.     sbis PIND, 5
  300.     rjmp Wait1_Loop
  301.     ret
  302.  
  303. Wait2:
  304. Wait2_Loop:
  305.     rcall delay
  306.     sbis PIND, 6
  307.     rjmp Wait2_Loop
  308.     ret
  309.  
  310. Wait3:
  311. Wait3_Loop:
  312.     rcall delay
  313.     sbis PIND, 7
  314.     rjmp Wait3_Loop
  315.     ret
  316.  
  317. delay:
  318.     clr Acc0
  319. delay0:
  320.     clr Acc1
  321. delay1:
  322.     inc Acc1
  323.     cpi Acc1, 45
  324.     brne delay1
  325.     inc Acc0
  326.     cpi Acc0, 40
  327.     brne delay0
  328.     ret
  329.  
  330. Timer1Ovf:
  331.     inc step
  332.     rcall indicator_out4
  333. reti
  334.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement