Subversion Repositories Kolibri OS

Rev

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

  1. ;
  2. ;   pipes for menuet {and now kolibri}
  3. ;   v1.2
  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.  
  32.      call draw_window
  33.      call draw_board
  34.  
  35. still:
  36.  
  37.     mov  eax,10                 ; wait here for event
  38.     mcall
  39.  
  40.     cmp  eax,1                  ; redraw request ?
  41.      je  red
  42.     cmp  eax,2                  ; key in buffer ?
  43.      je  key
  44.     cmp  eax,3                  ; button in buffer ?
  45.      je  button
  46.  
  47.     jmp  still
  48.  
  49.   red:                          ; redraw
  50.     call draw_window
  51.     call draw_board
  52.     call draw_message
  53.     jmp  still
  54.  
  55.   key:                          ; key
  56.     mov  eax,2                  ; just read it and ignore
  57.     mcall
  58.     jmp  still
  59.   button:                       ; button
  60.     call get_input
  61.     jmp  still
  62.  
  63.  
  64.  
  65. get_input:
  66. pusha
  67.     mov  eax,17                 ; get id
  68.     mcall
  69.  
  70.     cmp  ah,1                   ; button id=1 ?
  71.     jne  .noclose
  72.  
  73.     mov  eax,-1                 ; close this program
  74.     mcall
  75.   .noclose:
  76.     cmp  ah,4
  77.     jne  .moderate
  78.     mov  [diffic],1
  79.     jmp  .enddiffic
  80.    .moderate:
  81.     cmp  ah,3
  82.     jne  .easy
  83.     mov  [diffic],3
  84.     jmp  .enddiffic
  85.    .easy:
  86.     cmp  ah,2
  87.     jne  .board
  88.     mov  [diffic],5
  89.    .enddiffic:
  90.     mov  [score],0
  91.     mov  [speed],40
  92.     mov  [level],1
  93.     mov  [stat],0
  94.     mov  [time],0
  95.     call draw_window
  96.     call scramble_board
  97.     call draw_board
  98.     call countdown
  99.     call wassermarsch
  100.     jmp  .getno
  101.   .board:
  102.     cmp  [stat],2
  103.     jge  .getno
  104.     shr  eax,8                  ; -> 24bit id
  105.     cmp  eax,10
  106.     jle  .getno
  107.     cmp  eax,150
  108.     jg   .getno
  109.     sub  eax,10
  110.     mov  edi,eax
  111.     add   edi,map
  112.     cmp   [edi], byte 1
  113.     jg    .nogerade
  114.     xor   byte [edi], 1
  115.     call  draw_board
  116.     jmp   .getno
  117.   .nogerade:
  118.     cmp   [edi], byte 6
  119.     jge   .getno
  120.     cmp   [edi], byte 5
  121.     jne   .rota
  122.     sub   byte [edi],4
  123.   .rota:
  124.     inc   byte [edi]
  125.     call  draw_board
  126.   .getno:
  127. popa
  128. ret
  129. ;//// end of event detection
  130. get_direction:              ;Setzt Richtungs-Konstanten
  131. pusha                       ;IN:
  132. mov eax,[esp+28]            ;eax  -  Richtung IN
  133. mov ebx,[esp+16]            ;ebx  -  Teilchen (Map-Wert)
  134. cmp ebx,0                   ;OUT:
  135. jne .no0                    ;eax  -  Richtung OUT
  136.   cmp eax,14
  137.   jne .o0
  138.   jmp .setout
  139.   .o0:
  140.   cmp eax,-14
  141.   jne .col
  142.   jmp .setout
  143. .no0:
  144. cmp ebx,1
  145. jne .no1
  146.   cmp eax,1
  147.   jne .o1
  148.   jmp .setout
  149.   .o1:
  150.   cmp eax,-1
  151.   jne .col
  152.   jmp .setout
  153. .no1:
  154. cmp ebx,2
  155. jne .no2
  156.   cmp eax,14
  157.   jne .o2
  158.   sub eax,13
  159.   jmp .setout
  160.  .o2:
  161.   cmp eax,-1
  162.   jne .col
  163.   sub eax,13
  164.   jmp .setout
  165. .no2:
  166. cmp ebx,3
  167. jne .no3
  168.   cmp eax,-14
  169.   jne .o3
  170.   add eax,15
  171.   jmp .setout
  172.  .o3:
  173.   cmp eax,-1
  174.   jne .col
  175.   add eax,15
  176.   jmp .setout
  177. .no3:
  178. cmp ebx,4
  179. jne .no4
  180.   cmp eax,-14
  181.   jne .o4
  182.   add eax,13
  183.   jmp .setout
  184.  .o4:
  185.   cmp eax,1
  186.   jne .col
  187.   add eax,13
  188.   jmp .setout
  189. .no4:
  190. cmp ebx,5
  191. jne .no5
  192.   cmp eax,14
  193.   jne .o5
  194.   sub eax,15
  195.   jmp .setout
  196.  .o5:
  197.   cmp eax,1
  198.   jne .col
  199.   sub eax,15
  200.   jmp .setout
  201. .no5:
  202. cmp ebx,6
  203. jne .no6
  204.   jmp .setout
  205. .no6:
  206. cmp ebx,7
  207. jne .no7
  208.   mov eax,14
  209.   jmp .setout
  210. .no7:
  211. cmp ebx,8
  212. jne .no8
  213.   cmp eax,14
  214.   jne .col
  215.   mov [stat],1
  216.   jmp .setout
  217. .no8:
  218. cmp ebx,16        ; cross 2x
  219. jne .col
  220.   add [score],10  ; + 10 bonus points
  221.   jmp .setout
  222. .col:
  223. xor eax,eax
  224. .setout:
  225. xor ebx,ebx
  226. mov [esp+28],eax
  227. mov [esp+16],ebx
  228. popa
  229. ret
  230.  
  231. countdown:
  232. pusha
  233. xor  eax,eax
  234. mov  al,[diffic]
  235. imul eax,10
  236. mov  [time],eax
  237. .udown:
  238. call show_score
  239. mov  ecx,10
  240. .down:
  241. mov  eax,5
  242. mov  ebx,10
  243. mcall
  244. mov  eax,11
  245. mcall
  246. cmp  eax,1
  247. jne  .nored
  248. call draw_window
  249. call draw_board
  250. jmp  .nothing
  251. .nored:
  252. cmp  eax,3
  253. jne  .nothing
  254. call get_input
  255. .nothing:
  256. cmp  [stat],0         ;bugfix 210806
  257. jnz  .exitsub         ;bugfix 210806
  258. dec  ecx
  259. jnz  .down
  260. dec  [time]
  261. jnz   .udown
  262. .exitsub:             ;bugfix 210806
  263. popa
  264. ret
  265.  
  266. wassermarsch:
  267. pusha
  268.    .restart:
  269.      mov  esi,map+16          ;start position
  270.      mov  eax, 14             ;start-richtung
  271.    .findway:
  272.      movzx ebx, byte [esi]
  273.      call  get_direction
  274.      test  eax,eax
  275.      jz   .collision
  276.      push  eax
  277.       xor   eax,eax
  278.       mov   al,6
  279.       sub   al,[diffic]
  280.       add   [score],eax          ;points/item = 6 - difficulty
  281.       mov   ecx,dword [speed]
  282.       add   byte [esi],10
  283.       .down:
  284.       mov   eax,5
  285.       mov   ebx,2
  286.       mcall
  287.       mov   eax,11
  288.       mcall
  289.       cmp   eax,1
  290.       jne   .nored
  291.       call  draw_window
  292.       .nored:
  293.       cmp   eax,3
  294.       jne   .noevnt
  295.       call  get_input
  296.       .noevnt:
  297.       dec   ecx
  298.       jnz   .down
  299.      pop   eax
  300.  
  301.      add   esi,eax
  302.      call  draw_board
  303.      call  show_score
  304.      jmp   .findway
  305.    .collision:
  306.     cmp [stat],1
  307.     jne .loose
  308.     call draw_message
  309.     mov   eax,5
  310.     mov   ebx,500
  311.     mcall
  312.     mov [stat],0
  313.     inc [level]
  314.     cmp [speed],6                ;waterflowdelay < 6 ?
  315.     jle .skipsub
  316.     sub [speed],2
  317.    .skipsub:
  318.     call draw_window
  319.     call scramble_board
  320.     call draw_board
  321.     call countdown
  322.     jmp  .restart
  323.    .loose:
  324.     mov  [stat],2
  325.     call draw_message
  326. popa
  327. ret
  328.  
  329. show_score:
  330. pusha
  331. mov  eax,13                      ;clear time and score area
  332. mov  ebx,50 shl 16 +15
  333. mov  ecx,395 shl 16 +15
  334. mov  edx,bgcolor
  335. mcall
  336. add  ebx,60 shl 16 + 20
  337. mcall
  338. add  ebx,80 shl 16
  339. mcall
  340. mov  eax,47
  341. mov  ebx,0x20000
  342. mov  ecx,[time]
  343. mov  edx,50*65536+398
  344. mov  esi,fg2color
  345. mcall
  346. mov  ebx,0x50000
  347. mov  ecx,[score]
  348. add  edx,60 shl 16
  349. mcall
  350. mov  ebx,0x20000
  351. mov  ecx,[level]
  352. add  edx,80 shl 16
  353. mcall
  354.  
  355. popa
  356. ret
  357.  
  358.  
  359.  
  360. scramble_board:
  361. pusha
  362. mov edi,map+16 ;startpunkt
  363. mov eax,7      ;wieder-
  364. stosb          ;herstellen
  365.  
  366. mov ebx, 0x00000007  ;modul         m max-wert
  367. .loop_through:
  368. mov   esi,edi
  369. lodsb
  370. cmp   eax, 9
  371.  je   .skip
  372. inc   eax
  373. xor   edx, edx
  374. div   ebx           ;modulo -> edx
  375. mov   eax, edx
  376. cmp   eax,6
  377. jne   .skip
  378. dec   [half]
  379. movzx eax, byte [half]
  380. jnz   .skip
  381. mov   [half], byte 7
  382. .skip:
  383. stosb
  384. cmp edi,map+125 ;endpunkt erhalten
  385. jge .exit
  386. jmp .loop_through
  387. .exit:
  388. mov  eax,8
  389. stosb
  390. popa
  391. ret
  392.  
  393.  
  394. gen_image:
  395. pusha
  396.     xor   ebx,ebx          ;default: kein wasser
  397.     movzx eax,byte [map]   ;erstes byte der map lesen (position)
  398.     inc   byte [map]       ;position inkrementieren
  399.     add   eax,map          ;zur position die map-adresse addieren
  400.     movzx  esi,byte [eax]
  401.     cmp   esi,10
  402.     jl    .nowater
  403.     sub   esi,10          ;map-werte+10 sind mit wasser gefuellt
  404.     mov   ebx,1
  405.     cmp   esi,16
  406.     jne   .nowater
  407.     sub   esi,10
  408.  .nowater:
  409.    imul  esi,3072         ;mapwert * 32*32*3 = image-adresse
  410.     add  esi,images
  411.     mov  edi,0x10000
  412.     mov  ecx,32*32*3
  413.  .gendd:                  ;RGB-Image im Speicher generieren
  414.     mov   eax,dword [esi] ;byte aus imagemap lesen
  415.     shl   eax,8
  416.     shr   eax,8
  417.     cmp   ebx,0
  418.     jz    .nowcolor
  419.     mov   ebx,eax
  420.     cmp   ebx,0x00B0B5B0
  421.     jne   .nog1
  422.     jmp   .wcolor
  423.  .nog1:
  424.     cmp   ebx,0x00A0A5A0
  425.     jne   .nog2
  426.     jmp   .wcolor
  427.  .nog2:
  428.     cmp   ebx,0x00909590
  429.     jne   .nog3
  430.     jmp   .wcolor
  431.  .nog3:
  432.     cmp   ebx,0x00808580
  433.     jne   .nog4
  434.     jmp   .wcolor
  435.  .nog4:
  436.     cmp   ebx,0x00707570
  437.     jne   .nowcolor
  438.     jmp   .wcolor
  439.  .wcolor:
  440.     add   eax,0x40
  441.  .nowcolor:
  442.     add  esi,3
  443.     stosd
  444.     dec  edi
  445.     loop .gendd
  446. popa
  447. ret
  448.  
  449.  
  450.  
  451. ;   *********************************************
  452. ;   *******  WINDOW DEFINITIONS AND DRAW ********
  453. ;   *********************************************
  454. draw_message:
  455. pusha
  456.     cmp  [stat],0
  457.     je  .nomessage
  458.     cmp  [stat],3
  459.     je  .nomessage
  460.     mov  eax,13
  461.     mov  ebx,146 shl 16 + 200
  462.     mov  ecx,190 shl 16 + 40
  463.     mov  edx,0x0
  464.     mcall
  465.     add  ebx,2 shl 16 - 4
  466.     add  ecx,2 shl 16 - 4
  467.     mov  edx,fgcolor
  468.     mcall
  469.  
  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,0x50000000     ;no button image - no esi need
  523.     mcall
  524.     pop  edx
  525.     push ebx
  526.     push ecx
  527.     mov  eax,7
  528.     mov  ebx,0x10000
  529.     mov  ecx,32 shl 16 +32
  530.     mcall
  531.     pop  ecx
  532.     pop  ebx
  533.     add  edx,33 shl 16
  534.     add  ebx,33 shl 16
  535.     dec  edi
  536.     jnz  .hloop
  537.   sub  edx,14*(33 shl 16)        ;Spielfeldgroesse X
  538.   sub  ebx,14*(33 shl 16)
  539.   add  edx,33
  540.   add  ecx,33 shl 16
  541.   dec  esi
  542.   jnz  .vloop
  543.   mov  [map], byte 1             ;Map-Position zuruecksetzen
  544. popa
  545. ret
  546.  
  547.  
  548. draw_window:
  549. pusha
  550.  
  551.     mov  eax,12                    ; function 12:tell os about windowdraw
  552.     mov  ebx,1                     ; 1, start of draw
  553.     mcall
  554.  
  555.                                    ; DRAW WINDOW
  556.     mov  eax,0                     ; function 0 : define and draw window
  557.     mov  ebx,100*65536+492         ; [x start] *65536 + [x size]
  558.     mov  ecx,100*65536+420         ; [y start] *65536 + [y size]
  559.     mov  edx,bgcolor               ; color of work area RRGGBB,8->color gl
  560.     or   edx,0x13000000
  561.     mov  edi,title
  562.     mcall
  563.  
  564.     mov   eax,8
  565.     mov   ebx,84*65536+72
  566.     mov   ecx,28*65536+15
  567.     mov   edx,2
  568.     mov   esi,btcolor
  569.     mcall
  570.     add   ebx,76 shl 16
  571.     inc   edx
  572.     mcall
  573.     add   ebx,76 shl 16
  574.     inc   edx
  575.     mcall
  576.  
  577.     mov   eax,4
  578.     mov   ebx,26 shl 16 +32
  579.     mov   ecx,fgcolor
  580.     mov   edx,lbl_toolbar+1
  581.     movsx esi, byte [lbl_toolbar]
  582.     mcall
  583.     mov   ebx,18 shl 16 +398
  584.     mov   edx,lbl_score+1
  585.     movsx esi, byte [lbl_score]
  586.     mcall
  587.     mov   ebx,350 shl 16 +405
  588.     mov   ecx,fg3color
  589.     mov   edx,lbl_copy+1
  590.     movsx esi,byte [lbl_copy]
  591.     mcall
  592.  
  593.     mov  eax,12                    ; function 12:tell os about windowdraw
  594.     mov  ebx,2                     ; 2, end of draw
  595.     mcall
  596.  
  597.     popa
  598.     ret
  599.  
  600.  
  601. ; DATA AREA
  602.  
  603.  
  604. title  db   'PIPES',0
  605. lbl_gameover:
  606.      db 19
  607.      db 'G a m e   O v e r !'
  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 23
  620.      db 'v1.2 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.