-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathlogic.asm
4990 lines (4752 loc) · 102 KB
/
logic.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
SEGMENT CODE ; 3
; Game logic
%include "base.inc"
%include "constants.asm"
%include "structs.asm"
%include "variables.asm"
%include "func.mac"
%include "if.mac"
%include "extern.inc"
%include "windows.inc"
EXTERN atoi
EXTERN atol
EXTERN rand
; 0
; FindMonster returns the index of the monster at (x, y),
; or -1.
func FindMonster
sub sp,byte +0x2
push di
push si
%arg x:word, y:word
xor cx,cx
mov bx,[GameStatePtr]
cmp [bx+MonsterListLen],cx
jng .notfound
; Initialize es:bx to point to the first monster
; on the monster list
mov si,bx
mov ax,[si+MonsterListPtr+FarPtr.Off]
mov dx,[si+MonsterListPtr+FarPtr.Seg]
inc ax
mov bx,ax
mov es,dx
mov di,[x]
.loop:
; if monster.x == x and monster.y == y
; goto found
cmp [es:bx+Monster.x-1],di
jnz .next
mov ax,[y]
cmp [es:bx+Monster.y-1],ax
jz .found
.next:
add bx,byte Monster_size
inc cx
cmp [si+MonsterListLen],cx
jg .loop
jmp short .notfound
nop
.found:
mov ax,cx
jmp short .end
.notfound:
mov ax,-1
.end:
pop si
pop di
endfunc
; 58
; Same as above, but searches the slip list
func FindSlipper
sub sp,byte +0x2
push di
push si
%arg x:word, y:word
xor cx,cx
mov bx,[GameStatePtr]
cmp [bx+SlipListLen],cx
jng .notfound
mov si,bx
mov ax,[si+SlipListPtr+FarPtr.Off]
mov dx,[si+SlipListPtr+FarPtr.Seg]
inc ax
mov bx,ax
mov es,dx
mov di,[x]
.loop:
cmp [es:bx+Slipper.x-1],di
jnz .next
mov ax,[y]
cmp [es:bx+Slipper.y-1],ax
jz .found
.next:
add bx,byte Slipper_size
inc cx
cmp [si+SlipListLen],cx
jg .loop
jmp short .notfound
nop
.found:
mov ax,cx
jmp short .end
.notfound:
mov ax,-1
.end:
pop si
pop di
endfunc
; b0
func TurnLeft
sub sp,byte +0x2
; x y -> x y
; W -1 0 -> 0 1 S
; N 0 -1 -> -1 0 W
; S 0 1 -> 1 0 E
; E 1 0 -> 0 -1 N
%arg x:word, y:word, xOut:word, yOut:word
; ax = x<<1 + y
mov ax,[x]
shl ax,1
add ax,[y]
inc ax
inc ax
jz .west ; -2
dec ax
jz .north ; -1
dec ax
dec ax
jz .south ; +1
dec ax
jz .east ; +2
jmp short .end
nop
.west:
mov bx,[xOut]
mov word [bx],0
mov bx,[yOut]
mov word [bx],1
jmp short .end
.north:
mov bx,[xOut]
mov word [bx],-1
.setYOutToZero:
mov bx,[yOut]
mov word [bx],0
jmp short .end
.south:
mov bx,[xOut]
mov word [bx],1
jmp short .setYOutToZero
nop
.east:
mov bx,[xOut]
mov word [bx],0
mov bx,[yOut]
mov word [bx],-1
.end:
endfunc
; 116
func TurnRight
sub sp,byte +0x2
; x y -> x y
; W -1 0 -> 0 -1 N
; N 0 -1 -> 1 0 E
; S 0 1 -> -1 0 W
; E 1 0 -> 0 1 S
%arg x:word, y:word, xOut:word, yOut:word
mov ax,[x]
shl ax,1
add ax,[y]
inc ax
inc ax
jz .west
dec ax
jz .north
dec ax
dec ax
jz .south
dec ax
jz .east
jmp short .end
nop
.west:
mov bx,[xOut]
mov word [bx],0
mov bx,[yOut]
mov word [bx],-1
jmp short .end
.north:
mov bx,[xOut]
mov word [bx],1
.setYOutToZero:
mov bx,[yOut]
mov word [bx],0
jmp short .end
.south:
mov bx,[xOut]
mov word [bx],-1
jmp short .setYOutToZero
nop
.east:
mov bx,[xOut]
mov word [bx],0
mov bx,[yOut]
mov word [bx],1
.end:
endfunc
; 17c
func TurnAround
sub sp,byte +0x2
; x y -> x y
; W -1 0 -> 1 0 E
; N 0 -1 -> 0 1 S
; S 0 1 -> 0 -1 N
; E 1 0 -> -1 0 W
%arg x:word, y:word, xOut:word, yOut:word
; *xOut = -x
mov ax,[x]
neg ax
mov bx,[xOut]
mov [bx],ax
; *yOut = -y
mov ax,[y]
neg ax
mov bx,[yOut]
mov [bx],ax
endfunc
; 1a4
func GrowArray
sub sp,byte +0x2
push si
%arg hMem:word, ptr:word, lenPtr:word, numToAlloc:word, size:word
; ptr is a NEAR*FAR*
mov bx,[hMem]
cmp word [bx],byte +0x0
jz .globalAlloc
push word [bx]
call far KERNEL.GlobalUnlock ; 1bc
mov bx,[hMem]
push word [bx]
; Compute (*len + numToAlloc) * size
mov bx,[lenPtr]
mov ax,[bx]
add ax,[numToAlloc]
imul word [size]
cwd
push dx ; dwBytes
push ax
push byte +0x2 ; GMEM_MOVABLE
call far KERNEL.GlobalReAlloc ; 1d6
jmp short .lock
nop
.globalAlloc: ; 1de
push byte +0x42 ; GHND
; size * numToAlloc
mov ax,[size]
imul word [numToAlloc]
cwd
push dx ; dwBytes
push ax
call far KERNEL.GlobalAlloc ; 1e9
.lock: ; 1ee
; update hMem
; and call GlobalLock to get a pointer
; to the allocated memory
mov si,ax
or si,si
if nz
mov bx,[hMem]
mov [bx],si
endif ; 1f9
mov bx,[hMem]
push word [bx]
call far KERNEL.GlobalLock ; 1fe
mov bx,[ptr]
mov [bx],ax
mov [bx+0x2],dx
or si,si
jnz .success
; GlobalAlloc/ReAlloc failed, return 0
xor ax,ax
jmp short .end
nop
.success: ; 214
; lenPtr += numToAlloc
; return 1
mov ax,[numToAlloc]
mov bx,[lenPtr]
add [bx],ax
mov ax,1
.end: ; 21f
pop si
endfunc
; 228
func NewMonster
%arg tile:byte
%arg x:word, y:word
%arg xdir:word, ydir:word
%arg cloning:word
%define pos (bp-6)
%define lowerTile (bp-3)
sub sp,byte +0x6
push si
; Grow monster list if necessary.
mov bx,[GameStatePtr]
mov ax,[bx+MonsterListCap]
cmp [bx+MonsterListLen],ax
jl .addMonsterToList
push byte Monster_size
push byte +0x10
mov ax,bx
add ax,MonsterListCap
push ax
mov ax,bx
add ax,MonsterListPtr
push ax
mov ax,bx
add ax,MonsterListHandle
push ax
call far GrowArray ; 25a 3:1a4
add sp,byte +0xa
or ax,ax
if z
jmp word .end
endif
.addMonsterToList: ; 269
; pos = y*32 + x
mov si,[y]
shl si,byte 0x5
add si,[x]
mov [pos],si
; Get tile under the monster
mov bx,[GameStatePtr]
mov al,[bx+si+Lower]
mov [lowerTile],al
; Return if not cloning and the lower tile is a clone machine
;
; In other words: during initialization,
; don't add monsters on clone machines
; to the monster list.
cmp word [cloning],byte +0x0
jnz .notOnACloneMachine
cmp al,CloneMachine
jnz .notOnACloneMachine
jmp word .end
.notOnACloneMachine: ; 28d
; monster.tile = lowerTile
mov al,[tile]
les si,[bx+MonsterListPtr]
mov bx,[bx+MonsterListLen]
mov cx,bx
shl bx,byte 0x2
add bx,cx
shl bx,1
add bx,cx
mov [es:bx+si+Monster.tile],al
; monster.x = x
mov cx,[x]
mov bx,[GameStatePtr]
mov si,[bx+MonsterListLen]
mov dx,si
shl si,byte 0x2
add si,dx
shl si,1
add si,dx
les bx,[bx+MonsterListPtr]
mov [es:bx+si+Monster.x],cx
; monster.y = y
mov cx,[y]
mov bx,[GameStatePtr]
mov si,[bx+MonsterListLen]
mov dx,si
shl si,byte 0x2
add si,dx
shl si,1
add si,dx
les bx,[bx+MonsterListPtr]
mov [es:bx+si+Monster.y],cx
; monster.xdir = xdir
mov cx,[xdir]
mov bx,[GameStatePtr]
mov si,[bx+MonsterListLen]
mov dx,si
shl si,byte 0x2
add si,dx
shl si,1
add si,dx
les bx,[bx+MonsterListPtr]
mov [es:bx+si+Monster.xdir],cx
; monster.ydir = ydir
mov cx,[ydir]
mov bx,[GameStatePtr]
mov si,[bx+MonsterListLen]
mov dx,si
shl si,byte 0x2
add si,dx
shl si,1
add si,dx
les bx,[bx+MonsterListPtr]
mov [es:bx+si+Monster.ydir],cx
; monster.slipping = 0
mov bx,[GameStatePtr]
mov si,[bx+MonsterListLen]
mov cx,si
shl si,byte 0x2
add si,cx
shl si,1
add si,cx
les bx,[bx+MonsterListPtr]
mov word [es:bx+si+Monster.slipping],0x0
; If tile is not the upper tile at pos...
mov bx,[pos]
mov si,[GameStatePtr]
cmp [bx+si+Upper],al
if ne
; ...push the upper tile down
mov al,[bx+si+Upper]
add bx,si
mov [bx+Lower],al
mov bx,[pos]
add bx,[GameStatePtr]
mov al,[bx+Lower]
mov [lowerTile],al
endif ; 35c
; Set the top tile to tile
mov al,[tile]
mov bx,[pos]
mov si,[GameStatePtr]
mov [bx+si+Upper],al
; If the monster is on a trap...
mov bx,[GameStatePtr]
inc word [bx+MonsterListLen]
cmp byte [lowerTile],Trap
if e
; ... call EnterTrap and return
push byte -0x1
push byte -0x1
push word [y]
push word [x]
call far EnterTrap ; 380 3:21aa
add sp,byte +0x8
jmp short .end
endif ; 38a
cmp byte [lowerTile],ChipN
jb .notChip
cmp byte [lowerTile],ChipE
jna .deathByMonster
.notChip: ; 396
cmp byte [lowerTile],SwimN
jb .end
cmp byte [lowerTile],SwimE
ja .end
.deathByMonster: ; 3a2
; Monster landed on Chip (or Swimming Chip)
; Set cause of death
mov bx,[GameStatePtr]
mov word [bx+Autopsy],Eaten
.end: ; 3ac
pop si
endfunc
; 3b4
func DeleteMonster
sub sp,byte +0x8
push di
push si
%arg idx:word
%local offset:word
; Get a pointer to the requested monster
mov si,[idx]
mov ax,si
shl ax,byte 0x2
add ax,si
shl ax,1
add ax,si
mov bx,[GameStatePtr]
les bx,[bx+MonsterListPtr]
add bx,ax
mov [bp-0x8],bx ; unused
mov [bp-0x6],es ; unused
; If monster is slipping, delete from slip list
cmp word [es:bx+Monster.slipping],byte +0x0
if nz
push byte +0x2 ; unused
push word [es:bx+Monster.y]
push word [es:bx+Monster.x]
mov al,[es:bx+Monster.tile]
push ax ; unused
call far DeleteSlipperAt ; 3f6 3:12be
add sp,byte +0x8
endif ; 3fe
; If we're already at the end of the list, skip the loop.
lea ax,[si+0x1]
mov bx,[GameStatePtr]
cmp [bx+MonsterListLen],ax
jng .end
; offset = idx*11
mov ax,si
shl ax,byte 0x2
add ax,si
shl ax,1
add ax,si
mov [offset],ax
.loop: ; 419
; Move next monster to current index.
mov ax,[bx+MonsterListPtr+FarPtr.Off]
mov dx,[bx+MonsterListPtr+FarPtr.Seg]
add ax,[offset]
mov cx,ax
mov bx,dx
add ax,0xb
push ds
mov di,cx
mov si,ax
mov es,bx
mov ds,dx
mov cx,0x5
rep movsw
movsb
pop ds
; Rinse and repeat.
add word [offset],byte +0xb
mov ax,[idx]
inc ax
mov [idx],ax
inc ax
mov bx,[GameStatePtr]
cmp ax,[bx+MonsterListLen]
jl .loop
.end: ; 451
; Decrement MonsterListLen
dec word [bx+MonsterListLen]
pop si
pop di
endfunc
; 45e
func DeleteMonsterAt
sub sp,byte +0x2
%arg dunno:word x:word, y:word
push word [y]
push word [x]
call far FindMonster ; 471 3:471
add sp,byte +0x4
push ax
call far DeleteMonster ; 47a 3:47a
endfunc
; 486
func SetTileDir
sub sp,byte +0x4
%arg origTile:byte, xdir:word, ydir:word
%define tile (bp-3)
mov al,[origTile]
and al,0xfc
mov [tile],al
mov ax,[xdir]
shl ax,1
add ax,[ydir]
inc ax
inc ax
jz .west
dec ax
jz .north
dec ax
dec ax
jz .south
dec ax
jz .east
mov al,[origTile]
jmp short .end
.west: ; 4b6
mov al,[tile]
inc al
jmp short .end
nop
.north: ; 4be
mov al,[tile]
jmp short .end
nop
.south: ; 4c4
mov al,[tile]
add al,0x2
jmp short .end
nop
.east: ; 4cc
mov al,[tile]
add al,0x3
.end: ; 4d1
endfunc
; 4d8
func GetMonsterDir
sub sp,byte +0x2
%arg tile:byte, xOut:word, yOut:word
cmp byte [tile],FirstMonster
jb .notAMonster
cmp byte [tile],LastMonster
ja .notAMonster
mov al,[tile]
and ax,0x3
jz .north
dec ax
jz .west
dec ax
jz .south
dec ax
jz .east
jmp short .ok
.north: ; 504
mov bx,[xOut]
mov word [bx],0
mov bx,[yOut]
mov word [bx],-1
jmp short .ok
.west: ; 514
mov bx,[xOut]
mov word [bx],-1
jmp short .setYToZero
nop
.south: ; 51e
mov bx,[xOut]
mov word [bx],0
mov bx,[yOut]
mov word [bx],1
jmp short .ok
.east: ; 52e
mov bx,[xOut]
mov word [bx],1
.setYToZero: ; 535
mov bx,[yOut]
mov word [bx],0
.ok: ; 53c
; Return 1
mov ax,0x1
jmp short .end
nop
.notAMonster: ; 542
; Return 0
xor ax,ax
.end: ; 544
endfunc
; 54c
; Initialize monster list, toggle walls, teleports, and chip's position.
func InitBoard
sub sp,byte +0xc
push di
push si
%define tile (bp-3)
%local local_4:byte ; -4
%local coords:word ; -6
%define xoff (bp-0x6)
%local yoff:word ; -8
%local y:word ; -a
; Loop over initial monster list
; and add entries to actual monster list
xor di,di
mov bx,[GameStatePtr]
cmp [bx+InitialMonsterListLen],di
jng .noMonsters
xor si,si
.loop: ; 569
; Get x, y coords of i'th monster.
mov ax,[bx+si+InitialMonsterList]
mov [coords],ax
mov al,[coords+1] ; y
sub ah,ah
mov [y],ax
shl ax,byte 0x5
mov cl,[coords] ; x
sub ch,ch
add ax,cx
add bx,ax
; Get upper tile
mov al,[bx+Upper]
mov [tile],al
; If not a monster, continue
cmp al,FirstMonster
jb .next
cmp al,LastMonster
ja .next
; Switch on monster direction
and ax,0x3
jz .north
dec ax
jz .west
dec ax
jz .south
dec ax
jz .east
jmp short .next
nop
; Call NewMonster with appropriate arguments
.north: ; 5a2
push byte 0
push byte -1
jmp short .pushZero
.west: ; 5a8
push byte 0
push byte 0
push byte -1
jmp short .callNewMonster
.south: ; 5b0
push byte 0
push byte 1
.pushZero: ; 5b4
push byte 0
jmp short .callNewMonster
.east: ; 5b8
push byte 0
push byte 0
push byte 1
.callNewMonster: ; 5be
push word [y]
push cx ; x
mov al,[tile]
push ax
call far NewMonster ; 5c6 3:228
add sp,byte +0xc
.next: ; 5ce
add si,byte +0x2
inc di
mov bx,[GameStatePtr]
cmp [bx+InitialMonsterListLen],di
jg .loop
.noMonsters: ; 5dc
; Loop over the game board
xor di,di
mov [yoff],di
.loopY: ; 5e1
xor si,si
mov [xoff],di ; unused
.loopX: ; 5e6
; Get tile at x,y
mov bx,[GameStatePtr]
add bx,[yoff]
mov al,[bx+si+Upper]
mov [tile],al
; If tile is a monster, get lower tile
cmp al,FirstMonster
jb .notAMonster
cmp al,LastMonster
ja .notAMonster
mov bx,[GameStatePtr]
add bx,[yoff]
add bx,si ; x
mov al,[bx+Lower]
mov [tile],al
; Check if the tile is a toggle wall or floor, a teleport,
; or the protagonist.
.notAMonster: ; 60a
mov al,[tile]
sub ah,ah
sub ax,ToggleWall
if l
jmp word .nextX
endif ; 617
; Bail if the subtraction overflowed,
; which is impossible.
if o
jmp word .nextX
endif ; 61c
dec ax
jng .toggleWallOrFloor
sub ax,0x3
if z
jmp word .teleport
endif ; 627
sub ax,0x43
if l
jmp word .nextX
endif ; 62f
sub ax,0x3
if le
jmp word .chip
endif ; 637
jmp word .nextX
.toggleWallOrFloor: ; 63a
; Add toggle wall or floor to toggle list.
; No idea why this isn't its own function like all the other lists.
mov bx,[GameStatePtr]
mov ax,[bx+ToggleListCap]
cmp [bx+ToggleListLen],ax
if nl
push byte Point_size
push byte +0x20
mov ax,bx
add ax,ToggleListCap
push ax
mov ax,bx
add ax,ToggleListPtr
push ax
mov ax,bx
add ax,ToggleListHandle
push ax
call far GrowArray ; 65e 3:1a4
add sp,byte +0xa
or ax,ax
jz .nextX
endif ; 66a
mov bx,[GameStatePtr]
mov bx,[bx+ToggleListLen]
mov ax,bx
mov bx,[GameStatePtr]
mov cx,[bx+ToggleListPtr+FarPtr.Off]
mov dx,[bx+ToggleListPtr+FarPtr.Seg]
mov bx,ax
shl bx,byte 0x2
mov es,dx
add bx,cx
mov [es:bx+Point.x],si ; = x
mov bx,[GameStatePtr]
mov bx,[bx+ToggleListLen]
mov ax,bx
mov bx,[GameStatePtr]
mov cx,[bx+ToggleListPtr+FarPtr.Off]
mov dx,[bx+ToggleListPtr+FarPtr.Seg]
mov bx,ax
shl bx,byte 0x2
mov es,dx
add bx,cx
mov [es:bx+Point.y],di ; = y
mov bx,[GameStatePtr]
inc word [bx+ToggleListLen]
jmp short .nextX
nop
.teleport: ; 6ba
; Add teleport to teleport list.
push di ; y
push si ; x
call far AddTeleport ; 6bc 3:295e
add sp,byte +0x4
jmp short .nextX
.chip: ; 6c6
; Set chip's position
mov bx,[GameStatePtr]
mov [bx+ChipX],si
mov bx,[GameStatePtr]
mov [bx+ChipY],di
.nextX: ; 6d6
inc si
cmp si,byte +0x20
jnl .nextY
jmp word .loopX
.nextY: ; 6df
inc di
add word [yoff],byte +0x20
cmp word [yoff],Lower
jnl .break
jmp word .loopY
.break:
.checkChipCoords: ; 6ee
; If either of chip's coordinates is -1,
; put chip on the map at (1,1).
; Can't ever happen because chip starts at (0,0).
mov bx,[GameStatePtr]
cmp word [bx+ChipX],byte -0x1
jz .addChipToMap
cmp word [bx+ChipY],byte -0x1
jnz .end
.addChipToMap: ; 700
mov word [bx+ChipX],0x1
mov bx,[GameStatePtr]
mov word [bx+ChipY],0x1
mov bx,[GameStatePtr]
mov al,[bx+Lower+(1*32)+1]
mov [bx+Upper+(1*32)+1],al
mov bx,[GameStatePtr]
mov byte [bx+Lower+(1*32)+1],0x0
.end: ; 724
pop si
pop di
endfunc
; 72e
; Returns a random integer between 0 and n-1.
func RandInt
sub sp,byte +0x2
call far rand ; 73b 1:dc
sub dx,dx
div word [bp+0x6]
mov ax,dx
endfunc
; 74e
; Big freaking monster loop
; Loop through the monster list and move each monster.
func MonsterLoop
sub sp,byte +0x20
push di
push si
%arg hDC:word ; +6
%arg isEvenTurn:word ; +8
; Look at all these locals!
%define tile (bp-3)
%local local_4:byte ; -4
%local xdir:word ; -6
%local ydir:word ; -8
%local deadflag:word ; -a
%local i:word ; -c
%local ynewdir:word ; -e
%local xnewdir:word ; -10
%local x:word ; -12
%local y:word ; -14
%local len:word ; -16
%local xdistance:word ; -18
%local ydistance:word ; -1a
%local p:dword ; -1e
%local offset:word ; -20
mov bx,[GameStatePtr]
mov ax,[bx+MonsterListLen]
mov [len],ax
mov word [i],0x0
or ax,ax
jg .loop
jmp word .end
; Top of loop
.loop: ; 774
; Compute offset of monster[i]
mov ax,[i]
mov cx,ax
shl ax,byte 0x2
add ax,cx
shl ax,1
add ax,cx
mov [offset],ax
; Pointer to monster[i]
mov bx,[GameStatePtr]
les bx,[bx+MonsterListPtr]
add bx,ax
mov [p+FarPtr.Off],bx
mov [p+FarPtr.Seg],es
; If monster is slipping, skip it.
cmp word [es:bx+Monster.slipping],byte +0x0
if nz
jmp word .next ; slipping
endif ; 79f
; Get attributes
mov ax,[es:bx+Monster.x]
mov [x],ax
mov bx,[GameStatePtr]