Subversion Repositories Kolibri OS

Rev

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

  1. ;
  2. ;   pipes kolibri
  3. ;   v1.41
  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.       mov   eax,5
  278.       mov   ebx,2
  279.       mcall
  280.       mov   eax,11
  281.       mcall
  282.       cmp   eax,1
  283.       jne   .nored
  284.       call  draw_window
  285.       .nored:
  286.       cmp   eax,3
  287.       jne   .noevnt
  288.       call  get_input
  289.       .noevnt:
  290.       dec   ecx
  291.       jnz   .down
  292.      pop   eax
  293.  
  294.      add   esi,eax
  295.      call  draw_board
  296.      call  show_score
  297.      jmp   .findway
  298.    .collision:
  299.     cmp [stat],1
  300.     jne .loose
  301.     call draw_message
  302.     mov   eax,5
  303.     mov   ebx,500
  304.     mcall
  305.     mov [stat],0
  306.     inc [level]
  307.     cmp [speed],6                ;waterflowdelay < 6 ?
  308.     jle .skipsub
  309.     sub [speed],2
  310.    .skipsub:
  311.     call draw_window
  312.     call scramble_board
  313.     call draw_board
  314.     call countdown
  315.     jmp  .restart
  316.    .loose:
  317.     mov  [stat],2
  318.     call draw_message
  319. popa
  320. ret
  321.  
  322. show_score:
  323. pusha
  324. mov  eax,47
  325. mov  ebx,0x20000
  326. mov  ecx,[time]
  327. mov  edx,60*65536+395
  328. mov  esi,fg2color
  329. mov  edi,bgcolor
  330. or   esi,0x50000000
  331. mcall
  332. mov  ebx,0x50000
  333. mov  ecx,[score]
  334. if lang eq et
  335. add  edx,88 shl 16
  336. else
  337. add  edx,80 shl 16
  338. end if
  339. mcall
  340. mov  ebx,0x20000
  341. mov  ecx,[level]
  342. add  edx,104 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.     mcall 13,<146,200>,<190,40>,0
  449.     add  ebx,2 shl 16 - 4
  450.     add  ecx,2 shl 16 - 4
  451.     mov  edx,fgcolor
  452.     mcall
  453.  
  454.         cmp  [stat],3
  455.         jne .stat1
  456.     mov   eax,4
  457.     mov   ebx,159 shl 16 +202
  458.     mov   edx,lbl_new_game
  459.     mov   ecx,btcolor
  460.     or    ecx,0xB0000000
  461.     mcall
  462.     jmp .nomessage
  463.  
  464.   .stat1:      
  465.     cmp   [stat],1
  466.      je   .winmessage
  467.     mov   eax,4
  468.     mov   ebx,170 shl 16 +196
  469.     mov   edx,lbl_gameover
  470.     mov   ecx,btcolor OR 0xB0000000
  471.     mcall
  472.     add   ebx,8 shl 16 +17
  473.     mov   edx,lbl_yscore
  474.     mcall
  475.     mov   esi,ecx       ;color
  476.     mov   edx,ebx       ;pos
  477.     add   edx,90 shl 16
  478.     mov   ebx,0x50000    ;type
  479.     mov   ecx,[score]    ;inp
  480.     mov   eax,47
  481.     mcall
  482.     jmp   .nomessage
  483.    .winmessage:
  484.     mov   eax,4
  485.     mov   ebx,124 shl 16 +194
  486.     mov   edx,lbl_win
  487.     mov   ecx,btcolor
  488.     or    ecx,0xB0000000
  489.     mcall
  490.     add   ebx,17
  491.     add   edx,lbl_win2-lbl_win
  492.     mcall
  493.    .nomessage:
  494. popa
  495. ret
  496.  
  497. draw_board:
  498. pusha
  499.  mov  ebx,15*65536+32
  500.  mov  ecx,50*65536+32
  501.  mov  edx,15*65536+50            ;Spielfeldposition
  502.  mov  esi,10                     ;Spielfeldgroesse Y
  503.  .vloop:
  504.   mov  edi,14                    ;Spielfeldgroesse X
  505.   .hloop:
  506.     call gen_image
  507.     push edx
  508.     mov  eax,8
  509.     movsx edx, byte [map]
  510.     add  edx,9              ;button-id = map-pos + 10;gen_image inkrements
  511.     add  edx,0x80000000     ;first delete previous button
  512.     mcall
  513.     sub  edx,0x30000000     ;first delete previous button
  514.     mcall
  515.     pop  edx
  516.     push ebx
  517.     push ecx
  518.     mov  eax,7
  519.     mov  ebx,0x10000
  520.     mov  ecx,32 shl 16 +32
  521.     mcall
  522.     pop  ecx
  523.     pop  ebx
  524.     add  edx,33 shl 16
  525.     add  ebx,33 shl 16
  526.     dec  edi
  527.     jnz  .hloop
  528.   sub  edx,14*(33 shl 16)        ;Spielfeldgroesse X
  529.   sub  ebx,14*(33 shl 16)
  530.   add  edx,33
  531.   add  ecx,33 shl 16
  532.   dec  esi
  533.   jnz  .vloop
  534.   mov  [map], byte 1             ;Map-Position zuruecksetzen
  535. popa
  536. ret
  537.  
  538.  
  539. draw_window:
  540. pusha
  541.  
  542.     mcall 12,1
  543.  
  544.     mov  edx,bgcolor
  545.     or   edx,0x14000000
  546.     mcall 0,<100,492>,<100,422>,,,lbl_title
  547.  
  548.     mcall 8,<100,72>,<28,16>,2,btcolor
  549.     add   ebx,80 shl 16
  550.     inc   edx
  551.     mcall
  552.     add   ebx,80 shl 16
  553.     inc   edx
  554.     mcall
  555.  
  556.     mov   eax,4
  557.     mov   ebx,20 shl 16 +29
  558.     mov   ecx,fgcolor
  559.         or    ecx,0xB0000000
  560.     mov   edx,lbl_toolbar
  561.     mcall
  562.         or    ecx,0x00000000
  563.     mov   ebx,18 shl 16 +395
  564.     mov   edx,lbl_score
  565.     mcall
  566.     mov   ebx,340 shl 16 +405
  567.     mov   ecx,fg3color
  568.     mov   edx,lbl_copy
  569.     mcall
  570.  
  571.     mcall 12,2
  572.  
  573.     popa
  574.     ret
  575.  
  576. ;=================================================
  577. ; DATA - LABELS
  578. ;=================================================
  579. if lang eq et
  580. lbl_title    db 'Torud',0
  581. lbl_gameover db 'M ä n g   L ä b i !',0
  582. lbl_new_game db 'Alusta enne uut mängu',0
  583. lbl_win      db '          T u b l i !           ',0
  584. lbl_win2     db '          Lähme edasi!          ',0
  585. lbl_yscore   db 'Sinu tulemus:',0
  586. lbl_toolbar  db 'Uus mäng:  Lihtne    Keskmine   Raske',0
  587. lbl_copy     db 'v1.41 2006,Mario Birkner',0
  588. lbl_score    db ' Aeg:   Tulemus:       Tase:',0
  589. else
  590. lbl_title    db 'Pipes',0
  591. lbl_gameover db 'G a m e   O v e r !',0
  592. lbl_new_game db 'Start a new game first',0
  593. lbl_win      db '          G r e a t !           ',0
  594. lbl_win2     db "       Let's keep going!        ",0
  595. lbl_yscore   db 'Your Score:',0
  596. lbl_toolbar  db 'New Game:    Easy     Normal    Hard',0
  597. lbl_copy     db 'v1.41 2006,Mario Birkner',0
  598. lbl_score    db 'Time:    Score:       Level:',0
  599. end if
  600.  
  601. ;=================================================
  602. ; DATA - VARS
  603. ;=================================================
  604. stat    db 3  ;0=gameplay 1=won 2-lost 3=stopped
  605. speed   db 0
  606. time    dd 0
  607. diffic  db 0  ;1=hard 3=moderate 5=easy 8=dedicated to Wildwest - try it out!
  608. score   dd 0
  609. level   dd 1
  610. half    db 1  ;reduces the random-crosses
  611.  
  612. ;=================================================
  613. ; DATA - RES
  614. ;=================================================
  615. map:       ;14*10 blocks + position
  616.      db 1  ;<- act. position
  617.      db 9,9,9,9,9,9,9,9,9,9,9,9,9,9
  618.      db 9,7,1,3,2,0,1,1,0,3,4,4,3,9
  619.      db 9,5,0,2,2,1,3,0,3,1,1,6,4,9
  620.      db 9,4,0,4,6,0,3,3,2,6,0,1,2,9
  621.      db 9,3,0,1,2,4,6,4,5,1,2,4,1,9
  622.      db 9,5,3,2,6,3,2,1,2,1,2,6,0,9
  623.      db 9,4,0,2,3,0,4,1,2,3,2,3,4,9
  624.      db 9,2,0,4,5,6,3,1,3,0,4,1,0,9
  625.      db 9,1,0,3,5,4,2,2,4,1,6,0,8,9
  626.      db 9,9,9,9,9,9,9,9,9,9,9,9,9,9
  627. images:
  628. file 'pipes.raw'
  629. I_END:
  630.