Subversion Repositories Kolibri OS

Rev

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

  1. ;
  2. ;   pipes kolibri
  3. ;   v1.21
  4. ;   2006 by Mario Birkner
  5. ;
  6. ;   l.mod. 27.08.06/15:11
  7. ;
  8. ;   Compile with FASM
  9. ;
  10. bgcolor  equ  0x0074744A      ;thx
  11. fgcolor  equ  0x00E7C750      ;to
  12. fg2color equ  0x00E0B0A0      ;colorref
  13. fg3color equ  0x007F7F55
  14. btcolor  equ  0x005B6200
  15.  
  16. include '..\..\macros.inc'
  17.  
  18. use32
  19.  
  20.                org    0x0
  21.  
  22.                db     'MENUET01'              ; 8 byte id
  23.                dd     0x01                    ; header version
  24.                dd     START                   ; start of code
  25.                dd     I_END                   ; size of image
  26.                dd     0x100000                ; memory for app
  27.                dd     0x7fff0                 ; esp
  28.                dd     0x0 , 0x0               ; I_Param , I_Icon
  29.  
  30. START:                          ; start of execution
  31.      jmp red
  32.  
  33. still:
  34.     mcall 10            ; wait here for event
  35.     cmp  eax,1                  ; redraw request ?
  36.      je  red
  37.     cmp  eax,2                  ; key in buffer ?
  38.      je  key
  39.     cmp  eax,3                  ; button in buffer ?
  40.      je  button
  41.     jmp  still
  42.  
  43.   red:                          ; redraw
  44.     call draw_window
  45.     call draw_board
  46.     call draw_message
  47.     jmp  still
  48.  
  49.   key:                          ; key
  50.     mcall 2                     ; just read it and ignore
  51.     jmp  still
  52.   button:                       ; button
  53.     call get_input
  54.     jmp  still
  55.  
  56.  
  57.  
  58. get_input:
  59. pusha
  60.     mcall 17                    ; get id
  61.  
  62.     cmp  ah,1                   ; button id=1 ?
  63.     jne  .noclose
  64.     mcall -1                    ; close this program
  65.   .noclose:
  66.     cmp  ah,4
  67.     jne  .moderate
  68.     mov  [diffic],1
  69.     jmp  .enddiffic
  70.    .moderate:
  71.     cmp  ah,3
  72.     jne  .easy
  73.     mov  [diffic],3
  74.     jmp  .enddiffic
  75.    .easy:
  76.     cmp  ah,2
  77.     jne  .board
  78.     mov  [diffic],5
  79.    .enddiffic:
  80.     mov  [score],0
  81.     mov  [speed],40
  82.     mov  [level],1
  83.     mov  [stat],0
  84.     mov  [time],0
  85.     call draw_window
  86.     call scramble_board
  87.     call draw_board
  88.     call countdown
  89.     call wassermarsch
  90.     jmp  .getno
  91.   .board:
  92.     cmp  [stat],2
  93.     jge  .getno
  94.     shr  eax,8                  ; -> 24bit id
  95.     cmp  eax,10
  96.     jle  .getno
  97.     cmp  eax,150
  98.     jg   .getno
  99.     sub  eax,10
  100.     mov  edi,eax
  101.     add   edi,map
  102.     cmp   [edi], byte 1
  103.     jg    .nogerade
  104.     xor   byte [edi], 1
  105.     call  draw_board
  106.     jmp   .getno
  107.   .nogerade:
  108.     cmp   [edi], byte 6
  109.     jge   .getno
  110.     cmp   [edi], byte 5
  111.     jne   .rota
  112.     sub   byte [edi],4
  113.   .rota:
  114.     inc   byte [edi]
  115.     call  draw_board
  116.   .getno:
  117. popa
  118. ret
  119. ;//// end of event detection
  120. get_direction:              ;Setzt Richtungs-Konstanten
  121. pusha                       ;IN:
  122. mov eax,[esp+28]            ;eax  -  Richtung IN
  123. mov ebx,[esp+16]            ;ebx  -  Teilchen (Map-Wert)
  124. cmp ebx,0                   ;OUT:
  125. jne .no0                    ;eax  -  Richtung OUT
  126.   cmp eax,14
  127.   jne .o0
  128.   jmp .setout
  129.   .o0:
  130.   cmp eax,-14
  131.   jne .col
  132.   jmp .setout
  133. .no0:
  134. cmp ebx,1
  135. jne .no1
  136.   cmp eax,1
  137.   jne .o1
  138.   jmp .setout
  139.   .o1:
  140.   cmp eax,-1
  141.   jne .col
  142.   jmp .setout
  143. .no1:
  144. cmp ebx,2
  145. jne .no2
  146.   cmp eax,14
  147.   jne .o2
  148.   sub eax,13
  149.   jmp .setout
  150.  .o2:
  151.   cmp eax,-1
  152.   jne .col
  153.   sub eax,13
  154.   jmp .setout
  155. .no2:
  156. cmp ebx,3
  157. jne .no3
  158.   cmp eax,-14
  159.   jne .o3
  160.   add eax,15
  161.   jmp .setout
  162.  .o3:
  163.   cmp eax,-1
  164.   jne .col
  165.   add eax,15
  166.   jmp .setout
  167. .no3:
  168. cmp ebx,4
  169. jne .no4
  170.   cmp eax,-14
  171.   jne .o4
  172.   add eax,13
  173.   jmp .setout
  174.  .o4:
  175.   cmp eax,1
  176.   jne .col
  177.   add eax,13
  178.   jmp .setout
  179. .no4:
  180. cmp ebx,5
  181. jne .no5
  182.   cmp eax,14
  183.   jne .o5
  184.   sub eax,15
  185.   jmp .setout
  186.  .o5:
  187.   cmp eax,1
  188.   jne .col
  189.   sub eax,15
  190.   jmp .setout
  191. .no5:
  192. cmp ebx,6
  193. jne .no6
  194.   jmp .setout
  195. .no6:
  196. cmp ebx,7
  197. jne .no7
  198.   mov eax,14
  199.   jmp .setout
  200. .no7:
  201. cmp ebx,8
  202. jne .no8
  203.   cmp eax,14
  204.   jne .col
  205.   mov [stat],1
  206.   jmp .setout
  207. .no8:
  208. cmp ebx,16        ; cross 2x
  209. jne .col
  210.   add [score],10  ; + 10 bonus points
  211.   jmp .setout
  212. .col:
  213. xor eax,eax
  214. .setout:
  215. xor ebx,ebx
  216. mov [esp+28],eax
  217. mov [esp+16],ebx
  218. popa
  219. ret
  220.  
  221. countdown:
  222. pusha
  223. xor  eax,eax
  224. mov  al,[diffic]
  225. imul eax,10
  226. mov  [time],eax
  227. .udown:
  228. call show_score
  229. mov  ecx,10
  230. .down:
  231. mov  eax,5
  232. mov  ebx,10
  233. mcall
  234. mov  eax,11
  235. mcall
  236. cmp  eax,1
  237. jne  .nored
  238. call draw_window
  239. call draw_board
  240. jmp  .nothing
  241. .nored:
  242. cmp  eax,3
  243. jne  .nothing
  244. call get_input
  245. .nothing:
  246. cmp  [stat],0         ;bugfix 210806
  247. jnz  .exitsub         ;bugfix 210806
  248. dec  ecx
  249. jnz  .down
  250. dec  [time]
  251. jnz   .udown
  252. .exitsub:             ;bugfix 210806
  253. popa
  254. ret
  255.  
  256. wassermarsch:
  257. pusha
  258.    .restart:
  259.      mov  esi,map+16          ;start position
  260.      mov  eax, 14             ;start-richtung
  261.    .findway:
  262.      movzx ebx, byte [esi]
  263.      call  get_direction
  264.      test  eax,eax
  265.      jz   .collision
  266.      push  eax
  267.       xor   eax,eax
  268.       mov   al,6
  269.       sub   al,[diffic]
  270.       add   [score],eax          ;points/item = 6 - difficulty
  271.       mov   ecx,dword [speed]
  272.       add   byte [esi],10
  273.       .down:
  274.       mov   eax,5
  275.       mov   ebx,2
  276.       mcall
  277.       mov   eax,11
  278.       mcall
  279.       cmp   eax,1
  280.       jne   .nored
  281.       call  draw_window
  282.       .nored:
  283.       cmp   eax,3
  284.       jne   .noevnt
  285.       call  get_input
  286.       .noevnt:
  287.       dec   ecx
  288.       jnz   .down
  289.      pop   eax
  290.  
  291.      add   esi,eax
  292.      call  draw_board
  293.      call  show_score
  294.      jmp   .findway
  295.    .collision:
  296.     cmp [stat],1
  297.     jne .loose
  298.     call draw_message
  299.     mov   eax,5
  300.     mov   ebx,500
  301.     mcall
  302.     mov [stat],0
  303.     inc [level]
  304.     cmp [speed],6                ;waterflowdelay < 6 ?
  305.     jle .skipsub
  306.     sub [speed],2
  307.    .skipsub:
  308.     call draw_window
  309.     call scramble_board
  310.     call draw_board
  311.     call countdown
  312.     jmp  .restart
  313.    .loose:
  314.     mov  [stat],2
  315.     call draw_message
  316. popa
  317. ret
  318.  
  319. show_score:
  320. pusha
  321. mov  eax,13                      ;clear time and score area
  322. mov  ebx,50 shl 16 +15
  323. mov  ecx,395 shl 16 +15
  324. mov  edx,bgcolor
  325. mcall
  326. add  ebx,60 shl 16 + 20
  327. mcall
  328. add  ebx,80 shl 16
  329. mcall
  330. mov  eax,47
  331. mov  ebx,0x20000
  332. mov  ecx,[time]
  333. mov  edx,50*65536+398
  334. mov  esi,fg2color
  335. mcall
  336. mov  ebx,0x50000
  337. mov  ecx,[score]
  338. add  edx,60 shl 16
  339. mcall
  340. mov  ebx,0x20000
  341. mov  ecx,[level]
  342. add  edx,80 shl 16
  343. mcall
  344.  
  345. popa
  346. ret
  347.  
  348.  
  349.  
  350. scramble_board:
  351. pusha
  352. mov edi,map+16 ;startpunkt
  353. mov eax,7      ;wieder-
  354. stosb          ;herstellen
  355.  
  356. mov ebx, 0x00000007  ;modul         m max-wert
  357. .loop_through:
  358. mov   esi,edi
  359. lodsb
  360. cmp   eax, 9
  361.  je   .skip
  362. inc   eax
  363. xor   edx, edx
  364. div   ebx           ;modulo -> edx
  365. mov   eax, edx
  366. cmp   eax,6
  367. jne   .skip
  368. dec   [half]
  369. movzx eax, byte [half]
  370. jnz   .skip
  371. mov   [half], byte 7
  372. .skip:
  373. stosb
  374. cmp edi,map+125 ;endpunkt erhalten
  375. jge .exit
  376. jmp .loop_through
  377. .exit:
  378. mov  eax,8
  379. stosb
  380. popa
  381. ret
  382.  
  383.  
  384. gen_image:
  385. pusha
  386.     xor   ebx,ebx          ;default: kein wasser
  387.     movzx eax,byte [map]   ;erstes byte der map lesen (position)
  388.     inc   byte [map]       ;position inkrementieren
  389.     add   eax,map          ;zur position die map-adresse addieren
  390.     movzx  esi,byte [eax]
  391.     cmp   esi,10
  392.     jl    .nowater
  393.     sub   esi,10          ;map-werte+10 sind mit wasser gefuellt
  394.     mov   ebx,1
  395.     cmp   esi,16
  396.     jne   .nowater
  397.     sub   esi,10
  398.  .nowater:
  399.    imul  esi,3072         ;mapwert * 32*32*3 = image-adresse
  400.     add  esi,images
  401.     mov  edi,0x10000
  402.     mov  ecx,32*32*3
  403.  .gendd:                  ;RGB-Image im Speicher generieren
  404.     mov   eax,dword [esi] ;byte aus imagemap lesen
  405.     shl   eax,8
  406.     shr   eax,8
  407.     cmp   ebx,0
  408.     jz    .nowcolor
  409.     mov   ebx,eax
  410.     cmp   ebx,0x00B0B5B0
  411.     jne   .nog1
  412.     jmp   .wcolor
  413.  .nog1:
  414.     cmp   ebx,0x00A0A5A0
  415.     jne   .nog2
  416.     jmp   .wcolor
  417.  .nog2:
  418.     cmp   ebx,0x00909590
  419.     jne   .nog3
  420.     jmp   .wcolor
  421.  .nog3:
  422.     cmp   ebx,0x00808580
  423.     jne   .nog4
  424.     jmp   .wcolor
  425.  .nog4:
  426.     cmp   ebx,0x00707570
  427.     jne   .nowcolor
  428.     jmp   .wcolor
  429.  .wcolor:
  430.     add   eax,0x40
  431.  .nowcolor:
  432.     add  esi,3
  433.     stosd
  434.     dec  edi
  435.     loop .gendd
  436. popa
  437. ret
  438.  
  439.  
  440.  
  441. ;   *********************************************
  442. ;   *******  WINDOW DEFINITIONS AND DRAW ********
  443. ;   *********************************************
  444. draw_message:
  445. pusha
  446.     cmp  [stat],0
  447.         je .nomessage
  448.     mov  eax,13
  449.     mov  ebx,146 shl 16 + 200
  450.     mov  ecx,190 shl 16 + 40
  451.     mov  edx,0x0
  452.     mcall
  453.     add  ebx,2 shl 16 - 4
  454.     add  ecx,2 shl 16 - 4
  455.     mov  edx,fgcolor
  456.     mcall
  457.  
  458.         cmp  [stat],3
  459.         jne .stat1
  460.     mov   eax,4
  461.     mov   ebx,174 shl 16 +206
  462.     mov   edx,lbl_start_a_new_game+1
  463.     movzx esi,byte [lbl_start_a_new_game]
  464.     mov   ecx,btcolor
  465.     add   ecx,0x10000000
  466.     mcall
  467.     jmp .nomessage
  468.  
  469.   .stat1:      
  470.     cmp   [stat],1
  471.      je   .winmessage
  472.     mov   eax,4
  473.     mov   ebx,186 shl 16 +200
  474.     mov   edx,lbl_gameover+1
  475.     movzx esi,byte [lbl_gameover]
  476.     mov   ecx,btcolor
  477.     add   ecx,0x10000000
  478.     mcall
  479.     add   ebx,8 shl 16 +17
  480.     mov   edx,lbl_yscore+1
  481.     movzx esi,byte [lbl_yscore]
  482.     mov   ecx,btcolor
  483.     mcall
  484.     mov   esi,ecx       ;color
  485.     mov   edx,ebx       ;pos
  486.     add   edx,80 shl 16
  487.     mov   ebx,0x50000    ;type
  488.     mov   ecx,[score]    ;inp
  489.     mov   eax,47
  490.     mcall
  491.     jmp   .nomessage
  492.    .winmessage:
  493.     mov   eax,4
  494.     mov   ebx,152 shl 16 +200
  495.     mov   edx,lbl_win+1
  496.     movzx esi,byte [lbl_win]
  497.     mov   ecx,btcolor
  498.     add   ecx,0x10000000
  499.     mcall
  500.     mov   ebx,152 shl 16 +217
  501.     add   edx,esi
  502.     mov   ecx,btcolor
  503.     mcall
  504.    .nomessage:
  505. popa
  506. ret
  507.  
  508. draw_board:
  509. pusha
  510.  mov  ebx,15*65536+32
  511.  mov  ecx,50*65536+32
  512.  mov  edx,15*65536+50            ;Spielfeldposition
  513.  mov  esi,10                      ;Spielfeldgroesse Y
  514.  .vloop:
  515.   mov  edi,14                    ;Spielfeldgroesse X
  516.   .hloop:
  517.     call gen_image
  518.     push edx
  519.     mov  eax,8
  520.     movsx edx, byte [map]
  521.     add  edx,9              ;button-id = map-pos + 10;gen_image inkrements
  522.     add  edx,0x80000000     ;first delete previous button
  523.         mcall
  524.     sub  edx,0x30000000     ;first delete previous button
  525.     mcall
  526.     pop  edx
  527.     push ebx
  528.     push ecx
  529.     mov  eax,7
  530.     mov  ebx,0x10000
  531.     mov  ecx,32 shl 16 +32
  532.     mcall
  533.     pop  ecx
  534.     pop  ebx
  535.     add  edx,33 shl 16
  536.     add  ebx,33 shl 16
  537.     dec  edi
  538.     jnz  .hloop
  539.   sub  edx,14*(33 shl 16)        ;Spielfeldgroesse X
  540.   sub  ebx,14*(33 shl 16)
  541.   add  edx,33
  542.   add  ecx,33 shl 16
  543.   dec  esi
  544.   jnz  .vloop
  545.   mov  [map], byte 1             ;Map-Position zuruecksetzen
  546. popa
  547. ret
  548.  
  549.  
  550. draw_window:
  551. pusha
  552.  
  553.     mcall 12,1
  554.        
  555.     mov  eax,0                     ; function 0 : define and draw window
  556.     mov  ebx,100*65536+492         ; [x start] *65536 + [x size]
  557.     mov  ecx,100*65536+420         ; [y start] *65536 + [y size]
  558.     mov  edx,bgcolor               ; color of work area RRGGBB,8->color gl
  559.     or   edx,0x14000000
  560.     mov  edi,title
  561.     mcall
  562.  
  563.     mov   eax,8
  564.     mov   ebx,84*65536+72
  565.     mov   ecx,28*65536+15
  566.     mov   edx,2
  567.     mov   esi,btcolor
  568.     mcall
  569.     add   ebx,76 shl 16
  570.     inc   edx
  571.     mcall
  572.     add   ebx,76 shl 16
  573.     inc   edx
  574.     mcall
  575.  
  576.     mov   eax,4
  577.     mov   ebx,26 shl 16 +32
  578.     mov   ecx,fgcolor
  579.     mov   edx,lbl_toolbar+1
  580.     movsx esi, byte [lbl_toolbar]
  581.     mcall
  582.     mov   ebx,18 shl 16 +398
  583.     mov   edx,lbl_score+1
  584.     movsx esi, byte [lbl_score]
  585.     mcall
  586.     mov   ebx,340 shl 16 +405
  587.     mov   ecx,fg3color
  588.     mov   edx,lbl_copy+1
  589.     movsx esi,byte [lbl_copy]
  590.     mcall
  591.  
  592.     mcall 12,2
  593.  
  594.     popa
  595.     ret
  596.  
  597.  
  598. ; DATA AREA
  599.  
  600.  
  601. title  db   'Pipes',0
  602. lbl_gameover:
  603.      db 19
  604.      db 'G a m e   O v e r !'
  605. lbl_start_a_new_game:
  606.      db 22
  607.      db 'Start a new game first'
  608. lbl_win:
  609.      db 32
  610.      db '          G r e a t !           '
  611.      db "        Let's goin'on!          "
  612. lbl_yscore:
  613.      db 11
  614.      db 'Your Score:'
  615. lbl_toolbar:
  616.      db 43
  617.      db 'New Game:     Easy       Moderate      Hard'
  618. lbl_copy:
  619.      db 24
  620.      db 'v1.21 2006,Mario Birkner'
  621. lbl_score:
  622.      db 28
  623.      db   'Time:    Score:       Level:'
  624. stat    db 3  ;0=gameplay 1=won 2-lost 3=stopped
  625. speed   db 0
  626. time    dd 0
  627. diffic  db 0  ;1=hard 3=moderate 5=easy 8=dedicated to Wildwest - try it out!
  628. score   dd 0
  629. level   dd 1
  630. half    db 1  ;reduces the random-crosses
  631.  
  632. map:       ;14*10 blocks + position
  633.      db 1  ;<- act. position
  634.      db 9,9,9,9,9,9,9,9,9,9,9,9,9,9
  635.      db 9,7,1,3,2,0,1,1,0,3,4,4,3,9
  636.      db 9,5,0,2,2,1,3,0,3,1,1,6,4,9
  637.      db 9,4,0,4,6,0,3,3,2,6,0,1,2,9
  638.      db 9,3,0,1,2,4,6,4,5,1,2,4,1,9
  639.      db 9,5,3,2,6,3,2,1,2,1,2,6,0,9
  640.      db 9,4,0,2,3,0,4,1,2,3,2,3,4,9
  641.      db 9,2,0,4,5,6,3,1,3,0,4,1,0,9
  642.      db 9,1,0,3,5,4,2,2,4,1,6,0,8,9
  643.      db 9,9,9,9,9,9,9,9,9,9,9,9,9,9
  644. images:
  645. file 'pipes.raw'
  646. I_END:
  647.  
  648.  
  649.  
  650.  
  651.