Subversion Repositories Kolibri OS

Rev

Rev 7581 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

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