Subversion Repositories Kolibri OS

Rev

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

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