Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
1812 yogev_ezra 1
; --------------------------------------------------------------------------
2
; FILE: TArray.Asm
3
; DATE: October 4, 2008
4
; --------------------------------------------------------------------------
5
 
6
; --------------------------------------------------------------------------
7
; LEAVE
8
; --------------------------------------------------------------------------
9
; Input:
10
;   ECX = 1-based index (IESC) of the leaving enemy
11
; --------------------------------------------------------------------------
12
align PROC_ALIGN
13
TArray_Leave:
14
    pushad
15
 
16
    mcLoadGameDataPtr ebx
17
    movzx   edx, [ebx + TREKDATA.NENHERE]
18
    dec     edx
19
    dec     ecx
20
 
21
    mcLoadMemberRef edi, TREKDATA.KX
22
    mov     al, [edi + edx]
23
    mov     [edi + ecx], al
24
 
25
    mcLoadMemberRef edi, TREKDATA.KY
26
    mov     al, [edi + edx]
27
    mov     [edi + ecx], al
28
 
29
    imul    ecx, 10
30
    imul    edx, 10
31
 
32
    mcLoadMemberRef edi, TREKDATA.KPOWER
33
    fld     tbyte [edi + edx]
34
    fstp    tbyte [edi + ecx]
35
 
36
    mcLoadMemberRef edi, TREKDATA.KDIST
37
    fld     tbyte [edi + edx]
38
    fstp    tbyte [edi + ecx]
39
 
40
    dec     [ebx + TREKDATA.KLHERE]
41
    dec     [ebx + TREKDATA.NENHERE]
42
 
43
    cmp     [ebx + TREKDATA.CONDIT], CONDITION_DOCKED
44
    je      .done
45
 
46
    call    TCommon_NewCondition
47
 
48
.done:
49
    popad
50
    ret
51
 
52
; --------------------------------------------------------------------------
53
; Input:
54
;   EDI = array relative offset
55
;   ECX = 1-based index of DOUBLE cell
56
;   ST(0) = value to store
57
; --------------------------------------------------------------------------
58
align PROC_ALIGN
59
TArray_SetDouble:
60
    push    eax ecx
61
    movzx   ecx, cl
62
    dec     ecx
63
    imul    ecx, 10
64
    mcLoadGameDataPtr eax
65
    add     edi, eax
66
    fstp    tbyte [edi + ecx]
67
    pop     ecx eax
68
    ret
69
 
70
; --------------------------------------------------------------------------
71
; Input:
72
;   CL = 1-based index of KPOWER cell
73
; Output:
74
;   EDX = address of that DOUBLE cell
75
; --------------------------------------------------------------------------
76
align PROC_ALIGN
77
TArray_KlingonPowerPtr:
78
    push    ecx
79
    movzx   ecx, cl
80
    mcLoadGameDataPtr edx
81
    add     edx, TREKDATA.KPOWER
82
    dec     ecx
83
    imul    ecx, 10
84
    add     edx, ecx
85
    pop     ecx
86
    ret
87
 
88
; --------------------------------------------------------------------------
89
; Input:
90
;   EDI = array relative offset
91
;   CL = 1-based index of DOUBLE cell
92
; Output:
93
;   ST(0) = loaded value
94
; --------------------------------------------------------------------------
95
align PROC_ALIGN
96
TArray_GetDouble:
97
    push    eax ecx
98
    movzx   ecx, cl
99
    dec     ecx
100
    imul    ecx, 10
101
    mcLoadGameDataPtr eax
102
    add     edi, eax
103
    fld     tbyte [edi + ecx]
104
    pop     ecx eax
105
    ret
106
 
107
; --------------------------------------------------------------------------
108
; Input:
109
;   CL = 1-based index of DAMAGE cell
110
; Output:
111
;   ST(0) = loaded value
112
; --------------------------------------------------------------------------
113
align PROC_ALIGN
114
TArray_GetDblDamage:
115
    push    edi
116
    mcLoad8bitsToReg32 edi, TREKDATA.DAMAGE
117
    call    TArray_GetDouble
118
    pop     edi
119
    ret
120
 
121
; --------------------------------------------------------------------------
122
; Input:
123
;   CL = 1-based index of DEVICE
124
; Output:
125
;   CF=1 if device is damaged
126
; --------------------------------------------------------------------------
127
align PROC_ALIGN
128
TArray_IsDamaged:
129
    call    TArray_GetDblDamage
130
    fldz
131
    mc_CMP_ST0_ST1
132
    jz      .no_damage
133
 
134
    stc
135
    ret
136
 
137
.no_damage:
138
    clc
139
    ret
140
 
141
; --------------------------------------------------------------------------
142
; Input:
143
;   ECX = 1-based index of KPOWER cell
144
; Output:
145
;   ST(0) = loaded value
146
; --------------------------------------------------------------------------
147
align PROC_ALIGN
148
TArray_GetDblKPower:
149
    push    edi
150
    mcLoad8bitsToReg32 edi, TREKDATA.KPOWER
151
    call    TArray_GetDouble
152
    pop     edi
153
    ret
154
 
155
; --------------------------------------------------------------------------
156
; Input:
157
;   ECX = 1-based index of KDIST cell
158
; Output:
159
;   ST(0) = loaded value
160
; --------------------------------------------------------------------------
161
align PROC_ALIGN
162
TArray_GetDblKDist:
163
    push    edi
164
    mcLoad8bitsToReg32 edi, TREKDATA.KDIST
165
    call    TArray_GetDouble
166
    pop     edi
167
    ret
168
 
169
; --------------------------------------------------------------------------
170
; Input:
171
;   ECX = 1-based index of DAMAGE cell
172
;   ST(0) = value to store
173
; --------------------------------------------------------------------------
174
align PROC_ALIGN
175
TArray_SetDblDamage:
176
    push    edi
177
    mcLoad8bitsToReg32 edi, TREKDATA.DAMAGE
178
    call    TArray_SetDouble
179
    pop     edi
180
    ret
181
 
182
; --------------------------------------------------------------------------
183
; Input:
184
;   ECX = 1-based index of KPOWER cell
185
;   ST(0) = value to store
186
; --------------------------------------------------------------------------
187
align PROC_ALIGN
188
TArray_SetDblKPower:
189
    push    edi
190
    mcLoad8bitsToReg32 edi, TREKDATA.KPOWER
191
    call    TArray_SetDouble
192
    pop     edi
193
    ret
194
 
195
; --------------------------------------------------------------------------
196
; Input:
197
;   ECX = 1-based index of KDIST cell
198
;   ST(0) = value to store
199
; --------------------------------------------------------------------------
200
align PROC_ALIGN
201
TArray_SetDblKDist:
202
    push    edi
203
    mcLoad8bitsToReg32 edi, TREKDATA.KDIST
204
    call    TArray_SetDouble
205
    pop     edi
206
    ret
207
 
208
; --------------------------------------------------------------------------
209
; Input:
210
;   AL = X coordinate in range [1..10]
211
;   DL = Y coordinate in range [1..10]
212
; Output:
213
;   EBX = address of QUAD (X,Y)
214
; NOTE:
215
;   Coordinates are preserved during the call
216
; --------------------------------------------------------------------------
217
align PROC_ALIGN
218
TArray_QuadPtr:
219
    push    eax ecx edx
220
    ;
221
    ; I = (X-1)*10 + (Y-1)
222
    ;
223
    dec     al
224
    dec     dl
225
    cbw
226
    imul    ax, 10
227
    add     al, dl
228
    movzx   ecx, al
229
    ;
230
    ; Load address into EBX
231
    ;
232
    mov     ebx, [glb_pGameData]
233
    lea     ebx, [ebx + ecx + TREKDATA.QUAD]
234
 
235
    pop     edx ecx eax
236
    ret
237
 
238
; --------------------------------------------------------------------------
239
; Output:
240
;   CF=TRUE if CHAR_WEB is the only element encountered around
241
;           the quadrant edges.
242
; --------------------------------------------------------------------------
243
align PROC_ALIGN
244
TArray_IsWebComplete:
245
    ;
246
    ; Check the way from sector 1-1 to sector 1-10
247
    ;
248
    mcLoad1 eax
249
    mov     edx, eax
250
    call    TArray_QuadPtr
251
 
252
    mcLoad8bitsToReg32 ecx, 10
253
    mov     al, CHAR_WEB
254
 
255
.check_1:
256
    cmp     [ebx], al
257
    jne     .return_false
258
    inc     ebx
259
    loop    .check_1
260
    ;
261
    ; Check the way from sector 10-1 to sector 10-10
262
    ;
263
    mov     al, 10
264
    mov     dl, 1
265
    call    TArray_QuadPtr
266
 
267
    mcLoad8bitsToReg32 ecx, 10
268
    mov     al, CHAR_WEB
269
 
270
.check_2:
271
    cmp     [ebx], al
272
    jne     .return_false
273
    inc     ebx
274
    loop    .check_2
275
    ;
276
    ; Check the vertical ways:
277
    ;   1. From sector 1-1 to sector 10-1
278
    ;   2. From sector 1-10 to sector 10-10
279
    ;
280
    mov     al, 2
281
    mov     dl, 1
282
    call    TArray_QuadPtr
283
 
284
    mcLoad8bitsToReg32 ecx, 8
285
    mov     al, CHAR_WEB
286
 
287
.check_3:
288
    cmp     [ebx], al
289
    jne     .return_false
290
    cmp     [ebx + 9], al
291
    jne     .return_false
292
 
293
    add     ebx, 10
294
    loop    .check_3
295
    ;
296
    ; All plugged!
297
    ;
298
    stc
299
    ret
300
 
301
.return_false:
302
    clc
303
    ret
304
 
305
; --------------------------------------------------------------------------
306
align PROC_ALIGN
307
TArray_SetShip:
308
    mcLoadGameDataPtr ebx
309
    mcLoadMember al, TREKDATA.SECTX
310
    mcLoadMember dl, TREKDATA.SECTY
311
    push    ebx
312
    call    TArray_QuadPtr
313
    pop     esi
314
 
315
    mov     al, [esi + TREKDATA.SHIP]
316
    mov     [ebx], al
317
    ret
318
 
319
; --------------------------------------------------------------------------
320
; Input:
321
;   AL = X coordinate in range [1..8]
322
;   DL = Y coordinate in range [1..8]
323
; Output:
324
;   ECX = index into array (NOT OFFSET)
325
; NOTE:
326
;   Coordinates are preserved during the call
327
; --------------------------------------------------------------------------
328
align PROC_ALIGN
329
TArray_8x8Index:
330
    ;
331
    ; In STAR TREK cosmos: coordinate X is row and
332
    ; coordinate Y is column in the matrix, so
333
    ; index is calculated as:
334
    ;
335
    ; I = (X-1)*8 + (Y-1)
336
    ;
337
    push    eax edx
338
    dec     al
339
    dec     dl
340
    shl     al, 3
341
    add     al, dl
342
    movzx   ecx, al
343
    pop     edx eax
344
    ret
345
 
346
; --------------------------------------------------------------------------
347
; Input:
348
;   AL = X coordinate in range [1..8]
349
;   DL = Y coordinate in range [1..8]
350
; Output:
351
;   EBX = address of SCANNED (8,8) cell
352
; NOTE:
353
;   All registers are preserved
354
; --------------------------------------------------------------------------
355
align PROC_ALIGN
356
TArray_ScannedQuadPtr:
357
    push    ecx
358
    call    TArray_8x8Index
359
    mov     ebx, [glb_pGameData]
360
    lea     ebx, [ebx + ecx + TREKDATA.SCANNED]
361
    pop     ecx
362
    ret
363
 
364
; --------------------------------------------------------------------------
365
; Input:
366
;   AL = X coordinate in range [1..8]
367
;   DL = Y coordinate in range [1..8]
368
; NOTE:
369
;   All registers are preserved
370
; --------------------------------------------------------------------------
371
align PROC_ALIGN
372
TArray_SetScanned:
373
    push    ebx
374
    call    TArray_ScannedQuadPtr
375
    mov     byte [ebx], 1
376
    pop     ebx
377
    ret
378
 
379
; --------------------------------------------------------------------------
380
; Input:
381
;   AL = X coordinate in range [1..8]
382
;   DL = Y coordinate in range [1..8]
383
; Output:
384
;   CF=TRUE if quadrant was scanned by SRSCAN command
385
; NOTE:
386
;   All registers are preserved
387
; --------------------------------------------------------------------------
388
align PROC_ALIGN
389
TArray_IsScanned:
390
    push    eax
391
    push    ebx
392
    call    TArray_ScannedQuadPtr
393
    mov     al, [ebx]
394
    pop     ebx
395
    shr     al, 1
396
    pop     eax
397
    ret
398
 
399
; --------------------------------------------------------------------------
400
; Input:
401
;   AL = X coordinate in range [1..8]
402
;   DL = Y coordinate in range [1..8]
403
; Output:
404
;   EBX = address of NEWSTUF (8,8) cell
405
; NOTE:
406
;   All registers are preserved
407
; --------------------------------------------------------------------------
408
align PROC_ALIGN
409
TArray_NewStufPtr:
410
    push    ecx
411
    call    TArray_8x8Index
412
    mov     ebx, [glb_pGameData]
413
    lea     ebx, [ebx + ecx + TREKDATA.NEWSTUF]
414
    pop     ecx
415
    ret
416
 
417
; --------------------------------------------------------------------------
418
; Output:
419
;   EBX = address of NEWSTUF (QUADX,QUADY) cell
420
; NOTE:
421
;   All registers are preserved
422
; --------------------------------------------------------------------------
423
align PROC_ALIGN
424
TArray_MyNewStufPtr:
425
    push    eax edx esi
426
    mov     esi, [glb_pGameData]
427
    mov     al, [esi + TREKDATA.QUADX]
428
    mov     dl, [esi + TREKDATA.QUADY]
429
    call    TArray_NewStufPtr
430
    pop     esi edx eax
431
    ret
432
 
433
; --------------------------------------------------------------------------
434
; Input:
435
;   AL = X coordinate in range [1..8]
436
;   DL = Y coordinate in range [1..8]
437
; Output:
438
;   EBX = address of GALAXY (8,8) cell
439
; NOTE:
440
;   All registers are preserved
441
; --------------------------------------------------------------------------
442
align PROC_ALIGN
443
TArray_GalaxyPtr:
444
    push    ecx
445
    call    TArray_8x8Index
446
    mov     ebx, [glb_pGameData]
447
    lea     ebx, [ebx + ecx*4 + TREKDATA.GALAXY]
448
    pop     ecx
449
    ret
450
 
451
; --------------------------------------------------------------------------
452
; Input:
453
;   AL = quadrant X coordinate in range [1..8]
454
;   DL = quadrant Y coordinate in range [1..8]
455
;   ESI = TPlanet address
456
; Output:
457
;   CF=1 if location is matching PLNETS array item
458
; --------------------------------------------------------------------------
459
align PROC_ALIGN
460
TArray_IsPlanetHere:
461
    cmp     [esi + TPlanet.planet_X], al
462
    jne     .ret_false
463
 
464
    cmp     [esi + TPlanet.planet_Y], dl
465
    jne     .ret_false
466
 
467
    stc
468
    ret
469
 
470
.ret_false:
471
    clc
472
    ret
473
 
474
; --------------------------------------------------------------------------
475
; Input:
476
;   AL = quadrant X coordinate in range [1..8]
477
;   DL = quadrant Y coordinate in range [1..8]
478
;   ECX = commander index (1-based)
479
; Output:
480
;   CF=1 if location is matching CX,CY arrays
481
; --------------------------------------------------------------------------
482
align PROC_ALIGN
483
TArray_IsCommanderHere:
484
    push    ebx ecx esi edi
485
    mcLoadGameDataPtr ebx
486
 
487
    mcLoadMemberRef esi, TREKDATA.CX
488
    mcLoadMemberRef edi, TREKDATA.CY
489
    dec     ecx
490
 
491
    cmp     [esi + ecx], al
492
    jne     .ret_false
493
 
494
    cmp     [edi + ecx], dl
495
    jne     .ret_false
496
 
497
    pop     edi esi ecx ebx
498
    stc
499
    ret
500
 
501
.ret_false:
502
    pop     edi esi ecx ebx
503
    clc
504
    ret
505
 
506
; --------------------------------------------------------------------------
507
; Input:
508
;   AL = quadrant X coordinate in range [1..8]
509
;   DL = quadrant Y coordinate in range [1..8]
510
; Output:
511
;   ECX = 1-based index into PLNETS array or zero
512
;   ESI = address of TPlanet structure
513
; --------------------------------------------------------------------------
514
align PROC_ALIGN
515
TArray_FindPlanet:
516
    mcLoadGameDataPtr ebx
517
    mcLoadMemberRef esi, TREKDATA.PLNETS
518
    mcLoad1 ecx
519
 
520
.check_planet:
521
    call    TArray_IsPlanetHere
522
    jc      .done
523
 
524
    inc     ecx
525
    cmp     cl, [ebx + TREKDATA.INPLAN]
526
    ja      .ret_false
527
 
528
    add     esi, TPlanet.size
529
    jmp     .check_planet
530
 
531
.ret_false:
532
    mcZeroBits ecx
533
 
534
.done:
535
    ret
536
 
537
; --------------------------------------------------------------------------
538
; Input:
539
;   AL = quadrant X coordinate in range [1..8]
540
;   DL = quadrant Y coordinate in range [1..8]
541
; Output:
542
;   ECX = 1-based index into CX,CY arrays or zero
543
; --------------------------------------------------------------------------
544
align PROC_ALIGN
545
TArray_FindCommander:
546
    mcLoadGameDataPtr esi
547
    mcLoad1 ecx
548
 
549
.scan:
550
    call    TArray_IsCommanderHere
551
    jc      .found_it
552
 
553
    inc     ecx
554
    cmp     cl, [esi + TREKDATA.REMCOM]
555
    jbe     .scan
556
 
557
    mcZeroBits ecx
558
 
559
.found_it:
560
    ret
561
 
562
; --------------------------------------------------------------------------
563
; Input:
564
;   ECX = planet index (1-based)
565
; Output:
566
;   EDI = address of TPlanet structure
567
; --------------------------------------------------------------------------
568
align PROC_ALIGN
569
TArray_PlanetPtr:
570
    dec     ecx
571
    mcLoadGameDataPtr edi
572
    imul    ecx, TPlanet.size
573
    lea     edi, [edi + ecx + TREKDATA.PLNETS]
574
    ret
575
 
576
; --------------------------------------------------------------------------
577
; Output:
578
;   EBX = address of GALAXY (QUADX,QUADY) cell
579
; NOTE:
580
;   All registers are preserved
581
; --------------------------------------------------------------------------
582
align PROC_ALIGN
583
TArray_MyGalaxyPtr:
584
    push    eax edx esi
585
    mov     esi, [glb_pGameData]
586
    mov     al, [esi + TREKDATA.QUADX]
587
    mov     dl, [esi + TREKDATA.QUADY]
588
    call    TArray_GalaxyPtr
589
    pop     esi edx eax
590
    ret
591
 
592
; --------------------------------------------------------------------------
593
; Input:
594
;   AL = X coordinate in range [1..8]
595
;   DL = Y coordinate in range [1..8]
596
; Output:
597
;   EBX = address of STARCH (8,8) cell
598
; NOTE:
599
;   All registers are preserved
600
; --------------------------------------------------------------------------
601
align PROC_ALIGN
602
TArray_StarChartPtr:
603
    push    ecx
604
    call    TArray_8x8Index
605
    mov     ebx, [glb_pGameData]
606
    lea     ebx, [ebx + ecx*4 + TREKDATA.STARCH]
607
    pop     ecx
608
    ret
609
 
610
; --------------------------------------------------------------------------
611
; Input:
612
;   AL = X coordinate in range [1..8]
613
;   DL = Y coordinate in range [1..8]
614
; Output:
615
;   ECX = value of STARCH (8,8) cell
616
; NOTE:
617
;   All registers are preserved
618
; --------------------------------------------------------------------------
619
align PROC_ALIGN
620
TArray_GetStarChartValue:
621
    push    ebx
622
    call    TArray_StarChartPtr
623
    mov     ecx, [ebx]
624
    pop     ebx
625
    ret
626
 
627
; --------------------------------------------------------------------------
628
; Input:
629
;   AL = X coordinate in range [1..8]
630
;   DL = Y coordinate in range [1..8]
631
; Output:
632
;   ECX = value of GALAXY (8,8) cell
633
; NOTE:
634
;   All registers are preserved
635
; --------------------------------------------------------------------------
636
align PROC_ALIGN
637
TArray_GetGalaxyValue:
638
    push    ebx
639
    call    TArray_GalaxyPtr
640
    mov     ecx, [ebx]
641
    pop     ebx
642
    ret
643
 
644
; --------------------------------------------------------------------------
645
; Input:
646
;   AL = X coordinate in range [1..8]
647
;   DL = Y coordinate in range [1..8]
648
;   ECX = value to set at STARCH (8,8) cell
649
; NOTE:
650
;   All registers are preserved
651
; --------------------------------------------------------------------------
652
align PROC_ALIGN
653
TArray_SetStarChartValue:
654
    push    ebx
655
    call    TArray_StarChartPtr
656
    mov     [ebx], ecx
657
    pop     ebx
658
    ret
659
 
660
; --------------------------------------------------------------------------
661
; Input:
662
;   AL = X coordinate in range [1..8]
663
;   DL = Y coordinate in range [1..8]
664
;   ECX = value to set at GALAXY (8,8) cell
665
; NOTE:
666
;   All registers are preserved
667
; --------------------------------------------------------------------------
668
align PROC_ALIGN
669
TArray_SetGalaxyValue:
670
    push    ebx
671
    call    TArray_GalaxyPtr
672
    mov     [ebx], ecx
673
    pop     ebx
674
    ret
675
 
676
 
677
; --- EOF ---