Subversion Repositories Kolibri OS

Rev

Rev 485 | Go to most recent revision | Details | Last modification | View Log | RSS feed

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