-
Notifications
You must be signed in to change notification settings - Fork 4
/
seg4.asm
1992 lines (1940 loc) · 42.6 KB
/
seg4.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 ; 4
; Functions for loading levels
%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 WEP4UTIL.CENTERHWND
EXTERN WEP4UTIL.GRAYDLGPROC
EXPORT PASSWORDMSGPROC PASSWORDMSGPROC 11
; 0
; Returns the onscreen rect containing the tile at x,y
func GetTileRect
%arg x:word, y:word
sub sp,byte +0xa
push di
push si
mov ax,[x]
mov bx,[GameStatePtr]
sub ax,[bx+ViewportX]
sub ax,[bx+UnusedOffsetX]
shl ax,byte TileShift
mov [bp-0xa],ax
mov ax,[y]
sub ax,[bx+ViewportY]
sub ax,[bx+UnusedOffsetY]
shl ax,byte TileShift
mov [bp-0x8],ax
mov ax,[bp-0xa]
add ax,TileWidth
mov [bp-0x6],ax
mov ax,[bp-0x8]
add ax,TileHeight
mov [bp-0x4],ax
; return rect by value, via global temp space
mov ax,TempRect
mov di,ax
lea si,[bp-0xa]
push ds
pop es
movsw
movsw
movsw
movsw
pop si
pop di
endfunc
; 5e
; ResetLevelData
;
; Sets all the tiles to Floor
; and clears the slip, monster, toggle, trap,
; clone, teleport, and initial monster lists
; (doesn't free them, just sets the length to 0).
func ResetLevelData
sub sp,byte +0x2
push si
xor si,si
.loop: ; 6e
mov bx,[GameStatePtr]
mov byte [bx+si+Lower],0x0
mov bx,[GameStatePtr]
add bx,si
mov al,[bx+Lower]
mov [bx+Upper],al
inc si
cmp si,0x400 ; BoardWidth * BoardHeight?
jl .loop ; ↑
mov bx,[GameStatePtr]
mov word [bx+SlipListLen],0x0
mov bx,[GameStatePtr]
mov word [bx+MonsterListLen],0x0
mov bx,[GameStatePtr]
mov word [bx+ToggleListLen],0x0
mov bx,[GameStatePtr]
mov word [bx+TrapListLen],0x0
mov bx,[GameStatePtr]
mov word [bx+CloneListLen],0x0
mov bx,[GameStatePtr]
mov word [bx+TeleportListLen],0x0
mov bx,[GameStatePtr]
mov word [bx+InitialMonsterListLen],0x0
pop si
endfunc
; d8
; ReadLevelDataOrDie
; Tries to read a level. Sets LevelNumber on success.
; If it fails, pops up an error message and exits the game.
func ReadLevelDataOrDie
%arg levelNum:word
sub sp,byte +0x2
push si
mov si,[levelNum]
push ds
push word DataFileName ; "CHIPS.DAT"
push si
call far ReadLevelData ; ee 4:a56
add sp,byte +0x6
or ax,ax
if z
; load failed... show and error message and quit the game
call far ResetLevelData ; fa 4:5e
push byte +0x10
push ds
push word CorruptDataMessage
push word [hwndMain]
call far ShowMessageBox ; 109 2:0
add sp,byte +0x8
push word [hwndMain]
push word 0x111
push byte ID_QUIT
push byte +0x0
push byte +0x0
call far USER.PostMessage ; 11e
endif ; 123
mov bx,[GameStatePtr]
mov [bx+LevelNumber],si
pop si
endfunc
; 134
; Sets the window title to "Chip's Challenge: level title"
; or just "Chip's Challenge" if the level title is blank.
func UpdateWindowTitle
%arg hWnd:word
sub sp,0x8c
mov bx,[GameStatePtr]
add bx,LevelTitle
mov [bp-0x8c],bx
cmp byte [bx],0x0
if nz
mov ax,bx
else ; 158
mov ax,s_98e ; ""
endif ; 15b
mov cx,ax
mov [bp-0x8],ds
push ds
push cx
cmp byte [bx],0x0
if ne
mov ax,sColon ; ": "
else ; 16c
mov ax,sNoColon ; ""
endif ; 16f
mov [bp-0x4],ds
push ds
push ax
push ds
push word MessageBoxCaption
push ds
push word s_sss ; "%s%s%s"
lea ax,[bp-0x8a]
push ss
push ax
call far USER._wsprintf ; 182
add sp,byte +0x14
push word [hWnd]
lea ax,[bp-0x8a]
push ss
push ax
call far USER.SetWindowText ; 193
endfunc
; 1a0
; Enable or disable the previous/next menu items
; as appropriate for the given level number.
func UpdateNextPrevMenuItems
%arg levelNum:word
%local levelNumTmp:word
sub sp,byte +0x4
; Previous
push si
mov si,[levelNum]
push word [hMenu]
push byte ID_PREVIOUS
mov [levelNumTmp],si
cmp si,byte +0x1
if g
xor ax,ax
else ; 1c4
mov ax,0x1
endif ; 1c7
push ax
call far USER.EnableMenuItem ; 1c8
; Next
mov ax,[levelNumTmp]
mov bx,[GameStatePtr]
cmp [bx+NumLevelsInSet],ax
jg .next.disabled ; ↓
cmp word [DebugModeEnabled],byte +0x0
jnz .next.disabled ; ↓
.next.enabled:
mov cx,0x1
jmp short .makeTheCall ; ↓
.next.disabled: ; 1e6
xor cx,cx
.makeTheCall: ; 1e8
push word [hMenu]
push byte ID_NEXT
push cx
call far USER.EnableMenuItem ; 1ef
pop si
endfunc
; 1fc
; Sets the timer and chip counter to the
; level's time limit and chip count.
func ResetTimerAndChipCount
sub sp,byte +0x2
mov bx,[GameStatePtr]
mov ax,[bx+InitialTimeLimit]
mov [TimeRemaining],ax
mov ax,[bx+InitialChipsRemainingCount]
mov [ChipsRemainingCount],ax
push word [hwndCounter2]
push byte +0x2
cmp word [TimeRemaining],byte +0x1
sbb ax,ax
and ax,0x2
push ax
call far USER.SetWindowWord ; 22c
push byte +0x1
call far StartTimer ; 233 2:16fa
endfunc
; 240
; frees the monster list and other lists
func FreeGameLists
sub sp,byte +0xe
mov bx,[GameStatePtr]
mov ax,[bx+SlipListHandle]
mov [bp-0x4],ax
or ax,ax
if nz
push ax
call far KERNEL.GlobalUnlock ; 25d
mov bx,[GameStatePtr]
push word [bx+SlipListHandle]
call far KERNEL.GlobalFree ; 26a
endif ; 26f
mov bx,[GameStatePtr]
mov ax,[bx+MonsterListHandle]
mov [bp-0x6],ax
or ax,ax
if nz
push ax
call far KERNEL.GlobalUnlock ; 27f
mov bx,[GameStatePtr]
push word [bx+MonsterListHandle]
call far KERNEL.GlobalFree ; 28c
endif ; 291
mov bx,[GameStatePtr]
mov ax,[bx+ToggleListHandle]
mov [bp-0x8],ax
or ax,ax
if nz
push ax
call far KERNEL.GlobalUnlock ; 2a1
mov bx,[GameStatePtr]
push word [bx+ToggleListHandle]
call far KERNEL.GlobalFree ; 2ae
endif ; 2b3
mov bx,[GameStatePtr]
mov ax,[bx+TrapListHandle]
mov [bp-0xa],ax
or ax,ax
if nz
push ax
call far KERNEL.GlobalUnlock ; 2c3
mov bx,[GameStatePtr]
push word [bx+TrapListHandle]
call far KERNEL.GlobalFree ; 2d0
endif ; 2d5
mov bx,[GameStatePtr]
mov ax,[bx+CloneListHandle]
mov [bp-0xc],ax
or ax,ax
if nz
push ax
call far KERNEL.GlobalUnlock ; 2e5
mov bx,[GameStatePtr]
push word [bx+CloneListHandle]
call far KERNEL.GlobalFree ; 2f2
endif ; 2f7
mov bx,[GameStatePtr]
mov ax,[bx+TeleportListHandle]
mov [bp-0xe],ax
or ax,ax
if nz
push ax
call far KERNEL.GlobalUnlock ; 307
mov bx,[GameStatePtr]
push word [bx+TeleportListHandle]
call far KERNEL.GlobalFree ; 314
endif ; 319
endfunc
; 320
; ClearGameState(bool flag)
;
; Zeroes the game state
; and maybe frees lists first.
func ClearGameState
%arg flag:word
sub sp,byte +0x4
cmp word [flag],byte +0x0
if z
call far FreeGameLists ; 333 4:240
endif ; 338
; memset(gamestateptr, 0, sizeof *gamestateptr)
mov bx,[GameStatePtr]
lea dx,[bx+GameStateSize]
cmp dx,bx
jna .end ; ↓
.zeroLoop: ; 344
mov word [bx],0x0
add bx,byte +0x2
cmp bx,dx
jb .zeroLoop ; ↑
.end: ; 34f
endfunc
; 356
; LoadAndStartLevel(levelNum, restarting)
func FUN_4_0356
%arg levelNum:word
%arg restarting:word
%local oldMelinda:word
%local wasPaused:word
%local oldCursor:word
sub sp,byte +0xa
push di
push si
mov si,[restarting]
mov bx,[GameStatePtr]
mov ax,[bx+IsLevelPlacardVisible]
mov [wasPaused],ax
push byte +0x0
push byte +0x0
push word IDC_WAIT ; i don't care ...wait
call far USER.LoadCursor ; 37a
mov di,ax
push word [hwndBoard]
call far USER.SetCapture ; 385
push di
call far USER.SetCursor ; 38b
mov [oldCursor],ax
push byte +0x1
call far StopTimer ; 395 2:176e
add sp,byte +0x2
push byte +0x0
call far ResetInventory ; 39f 3:1734
add sp,byte +0x2
; If this is a restart and certain thresholds are met,
; ask the player if they want to skip the level
or si,si ; restarting?
jz .noMelinda ; ↓
mov bx,[GameStatePtr]
cmp word [bx+StepCount],byte MelindaStepRequirement
jng .noMelinda ; ↓
cmp word [levelNum],FakeLastLevel
jz .noMelinda ; ↓
cmp word [levelNum],LastLevel
jz .noMelinda ; ↓
inc word [bx+MelindaCount]
mov bx,[GameStatePtr]
cmp word [bx+MelindaCount],byte MelindaThreshold
jl .noMelinda ; ↓
push byte +0x24
push ds
push word MelindaMessage
push word [hwndMain]
call far ShowMessageBox ; 3dd 2:0
add sp,byte +0x8
cmp ax,ID_YES
if z
; yes: increment levelNum
inc word [levelNum]
xor si,si
else ; 3f2
; no: reset melinda count
mov bx,[GameStatePtr]
mov word [bx+MelindaCount],0x0
endif
.noMelinda: ; 3fc
; save RestartCount and MelindaCount for later if we're restarting
mov di,[bp-0xa] ; uninitialized
or si,si ; restarting
if nz
mov bx,[GameStatePtr]
mov di,[bx+RestartCount]
mov ax,[bx+MelindaCount]
mov [oldMelinda],ax
endif
.clearGameState: ; 412
push byte +0x0 ; don't free lists
call far ClearGameState ; 414 4:320
add sp,byte +0x2
or si,si ; restarting
if nz
lea ax,[di+0x1] ; increment restart count
; preserve RestartCount and MelindaCount across restart
mov bx,[GameStatePtr]
mov [bx+RestartCount],ax
mov ax,[oldMelinda]
mov bx,[GameStatePtr]
mov [bx+MelindaCount],ax
endif ; 436
;
; Read the level and load it into GameState
;
push word [levelNum]
call far ReadLevelDataOrDie ; 439 4:d8
; Start the music
; but not if we're paused or restarting the same level
add sp,byte +0x2
cmp word [GamePaused],byte +0x0
jnz .noMusic ; ↓
or si,si
jnz .noMusic ; ↓
; ok actually start it
mov bx,[GameStatePtr]
push word [bx+LevelNumber]
call far FUN_8_0308 ; 454 8:308
add sp,byte +0x2
.noMusic: ; 45c
; Set up the board and viewport
call far InitBoard ; 45c 3:54c
cmp word [DebugModeEnabled],byte +0x0
if nz
; if debug mode is enabled, show the whole game board
mov bx,[GameStatePtr]
mov word [bx+ViewportY],0x0
mov bx,[GameStatePtr]
mov ax,[bx+ViewportY]
mov [bx+ViewportX],ax
mov bx,[GameStatePtr]
mov word [bx+UnusedOffsetY],0x0
mov bx,[GameStatePtr]
mov ax,[bx+UnusedOffsetY]
mov [bx+UnusedOffsetX],ax
mov bx,[GameStatePtr]
mov word [bx+ViewportWidth],0x20
mov bx,[GameStatePtr]
mov word [bx+ViewportHeight],0x20
jmp .doneWithViewportStuff ; ↓
nop
endif ; 4ac
; normal mode: 9x9 viewport
mov bx,[GameStatePtr]
mov word [bx+ViewportHeight],0x9
mov bx,[GameStatePtr]
mov ax,[bx+ViewportHeight]
mov [bx+ViewportWidth],ax
mov bx,[GameStatePtr]
mov word [bx+UnusedOffsetY],0x10
mov bx,[GameStatePtr]
mov ax,[bx+UnusedOffsetY]
mov [bx+UnusedOffsetX],ax
mov bx,[GameStatePtr]
; set the viewport position
; based on chip's position
; ViewportX = ChipX - (32-ViewportWidth)/2 clamped to [0, 32-ViewportWidth]
mov ax,[bx+ViewportWidth]
mov cx,ax
sub ax,0x20
neg ax
mov dx,ax
mov ax,cx
mov di,dx
cwd
sub ax,dx
sar ax,1
sub ax,[bx+ChipX]
neg ax
; clamp
or ax,ax
if l
xor ax,ax
endif ; 4fe
cmp ax,di
if g
mov ax,di
endif ; 504
mov [bx+ViewportX],ax
; ViewportY = ChipX - (32-ViewportHeight)/2 clamped to [0, 32-ViewportHeight]
mov bx,[GameStatePtr]
mov ax,[bx+ViewportHeight]
mov cx,ax
sub ax,0x20
neg ax
mov dx,ax
mov ax,cx
mov di,dx
cwd
sub ax,dx
sar ax,1
sub ax,[bx+ChipY]
neg ax
; clamp
or ax,ax
if l
xor ax,ax
endif ; 52e
cmp ax,di
if g
mov ax,di
endif ; 534
mov [bx+ViewportY],ax
.doneWithViewportStuff: ; 538
call far ResetTimerAndChipCount ; 538 4:1fc
mov bx,[GameStatePtr]
mov word [bx+IsLevelPlacardVisible],0x1
cmp word [wasPaused],byte +0x0
if e
call far PauseTimer ; 54d 2:17a2
endif ; 552
mov bx,[GameStatePtr]
push word [bx+LevelNumber]
push word [hwndMain]
call far UpdateWindowTitle ; 55e 4:134
add sp,byte +0x4
mov bx,[GameStatePtr]
push word [bx+LevelNumber]
call far UpdateNextPrevMenuItems ; 56e 4:1a0
add sp,byte +0x2
mov bx,[GameStatePtr]
mov word [bx+UnusedOffsetX],0x0
mov bx,[GameStatePtr]
mov word [bx+UnusedOffsetY],0x0
push word [hwndBoard]
push byte +0x0
push byte +0x0
push byte +0x0
call far USER.InvalidateRect ; 594
; refresh time, chips, and inventory windows
push byte 0x3f
call far FUN_2_0cbe ; 59b 2:cbe
add sp,byte +0x2
or si,si
jnz .cleanup ; ↓
; if we haven't played this level yet,
; save its password in the ini file
push si
push si
push si
push word [levelNum]
call far GetLevelProgressFromIni ; 5ad 2:1adc
add sp,byte +0x8
or ax,ax
if z
; save password, no best time, no score
push ax
push ax
push byte -1
push word [levelNum]
call far SaveLevelProgressToIni ; 5c0 2:1c1c
; save the highest level too
add sp,byte +0x8
push word ID_HighestLevel
call far GetIniInt ; 5cb 2:198e
add sp,byte +0x2
cmp ax,[levelNum]
if l
push word [levelNum]
push word ID_HighestLevel
call far StoreIniInt ; 5de 2:19ca
add sp,byte +0x4
endif
endif
.cleanup: ; 5e6
push word [oldCursor]
call far USER.SetCursor ; 5e9
call far USER.ReleaseCapture ; 5ee
pop si
pop di
endfunc
; 5fc
; Expand rle
func ExpandTilesRLE
%arg src:word, _:dword
%arg dest:word, cxDest:word, cyDest:word
sub sp,byte +0x14
push di
push si
; si = cyDest
mov si,[cyDest]
; ax = (32 - cxDest)/2
mov ax,0x20
sub ax,[cxDest]
cwd
sub ax,dx
sar ax,1
mov [bp-0xa],ax
; (32 - cyDest)/2
mov ax,0x20
sub ax,si
cwd
sub ax,dx
sar ax,1
mov di,ax
mov byte [bp-0x4],0x0
mov ax,[src]
mov [bp-0xc],ax
mov ax,di
add ax,si
cmp ax,di
jle .end ; ↓
mov cx,di
shl cx,byte 0x5
mov ax,[bp-0xa]
add ax,[cxDest]
mov [bp-0x14],ax
sub ax,ax
add ax,si
mov [bp-0xe],ax
mov si,[dest]
.loopY: ; 652
mov di,[bp-0xa]
cmp [bp-0x14],di
jng .nextY ; ↓
mov si,[bp-0xc]
mov dx,[dest]
.loopX: ; 660
cmp byte [bp-0x4],0x0
if ne
mov al,[bp-0x5]
mov [bp-0x3],al
dec byte [bp-0x4]
else ; 672
lodsb
mov [bp-0x3],al
cmp al,0xff
if e
lodsb
mov [bp-0x4],al
dec byte [bp-0x4]
lodsb
mov [bp-0x5],al
mov [bp-0x3],al
endif
endif ; 688
mov al,[bp-0x3]
mov bx,cx
add bx,di
add bx,dx
mov [bx],al
inc di
cmp [bp-0x14],di
jg .loopX ; ↑
mov [bp-0xc],si
mov si,[dest]
.nextY: ; 69f
add cx,byte +0x20
dec word [bp-0xe]
jnz .loopY ; ↑
.end: ; 6a7
pop si
pop di
endfunc
; 6b0
func DecodePassword
%arg password:word
sub sp,byte +0x2
push si
mov si,[password]
cmp byte [si],0x0
if ne
.loop: ; 6c6
xor byte [si],0x99
inc si
cmp byte [si],0x0
jnz .loop ; ↑
endif ; 6cf
pop si
endfunc
; 6d8
; Parse the optional fields for a level
; and load them into the GameState
func DecodeLevelFields
%arg data:word, size:word
sub sp,byte +0xc
push di
push si
mov si,[data]
mov ax,[size]
add ax,si
mov [bp-0xc],ax
cmp ax,si
if na
jmp .end ; ↓
endif ; 6f9
.loop.fields:
mov al,[si]
mov [bp-0x3],al
inc si
mov al,[si]
mov [bp-0x9],al
inc si
mov al,[bp-0x3]
sub ah,ah
dec ax
cmp ax,0x9
if a
jmp .nextField ; ↓
endif ; 713
shl ax,1
xchg ax,bx
jmp [cs:bx+.jumpTable]
nop
.jumpTable:
dw .field.timelimit ; 1
dw .field.chips ; 2
dw .field.title ; 3
dw .field.traps ; 4
dw .field.clones ; 5
dw .field.password ; 6
dw .field.hint ; 7
dw .field.plaintextPassword ; 8
dw .nextField ; 9
dw .field.monsters ; 10
.field.timelimit: ; 730
mov ax,[si]
mov bx,[GameStatePtr]
mov [bx+InitialTimeLimit],ax
jmp .nextField
nop
.field.chips: ; 73e
mov ax,[si]
mov bx,[GameStatePtr]
mov [bx+InitialChipsRemainingCount],ax
jmp .nextField ; ↓
nop
.field.title: ; 74c
cmp byte [bp-0x9],MaxTitleLength
if a
mov byte [si+MaxTitleLength-1],0x0
endif ; 756
mov ax,[GameStatePtr]
add ax,LevelTitle
.lstrcpy: ; 75c
push ds
push ax
push ds
push si
call far KERNEL.lstrcpy ; 760
jmp .nextField ; ↓
.field.traps: ; 768
mov [bp-0x6],si
mov al,[bp-0x9]
mov cl,0xa
sub ah,ah
div cl
sub ah,ah
mov bx,[GameStatePtr]
mov [bx+TrapListLen],ax
mov bx,[GameStatePtr]
mov ax,[bx+TrapListCap]
cmp [bx+TrapListLen],ax
if le
jmp .nextField ; ↓
endif ; 78f
push byte +0xa
push word [bx+TrapListLen]
lea ax,[bx+TrapListCap]
push ax
lea ax,[bx+TrapListPtr]
push ax
lea ax,[bx+TrapListHandle]
push ax
call far GrowArray ; 7a4 3:1a4
add sp,byte +0xa
or ax,ax
if nz
mov word [bp-0x8],0x0
mov bx,[GameStatePtr]
cmp word [bx+TrapListLen],byte +0x0
if le
jmp .nextField ; ↓
endif ; 7c3
mov [data],si
mov word [bp-0x4],0x0
.loop.trapList: ; 7cb
les bx,[bx+TrapListPtr]
mov si,[bp-0x4]
mov ax,[bp-0x6]
lea di,[bx+si]
mov si,ax
mov cx,0x5
rep movsw
add word [bp-0x4],byte +0xa
add word [bp-0x6],byte +0xa
inc word [bp-0x8]
mov ax,[bp-0x8]
mov bx,[GameStatePtr]
cmp [bx+TrapListLen],ax
jg .loop.trapList ; ↑
.mov_si_data_and_jmp_nextField: ; 7f6
mov si,[data]
jmp .nextField ; ↓
endif ; 7fc
mov bx,[GameStatePtr]
mov word [bx+TrapListLen],0x0
jmp .nextField ; ↓
nop
.field.clones: ; 80a
mov [bp-0x6],si
mov al,[bp-0x9]
shr al,byte 0x3
sub ah,ah
mov bx,[GameStatePtr]
mov [bx+CloneListLen],ax
mov bx,[GameStatePtr]
mov ax,[bx+CloneListCap]
cmp [bx+CloneListLen],ax
if le
jmp .nextField ; ↓
endif ; 82e
push byte +0x8
push word [bx+CloneListLen]
lea ax,[bx+CloneListCap]
push ax
lea ax,[bx+CloneListPtr]
push ax
lea ax,[bx+CloneListHandle]
push ax
call far GrowArray ; 843 3:1a4
add sp,byte +0xa
or ax,ax
if nz
mov word [bp-0x8],0x0
mov bx,[GameStatePtr]
cmp word [bx+CloneListLen],byte +0x0
if le
jmp .nextField ; ↓
endif ; 862
mov [data],si
mov word [bp-0x4],0x0
.loop.clonelist: ; 86a
les bx,[bx+CloneListPtr]
mov si,[bp-0x4]
mov ax,[bp-0x6]
lea di,[bx+si]
mov si,ax
movsw
movsw
movsw
movsw
add word [bp-0x4],byte +0x8
add word [bp-0x6],byte +0x8
inc word [bp-0x8]
mov ax,[bp-0x8]
mov bx,[GameStatePtr]
cmp [bx+CloneListLen],ax
jg .loop.clonelist ; ↑
jmp .mov_si_data_and_jmp_nextField ; ↑
nop
endif ; 898
mov bx,[GameStatePtr]
mov word [bx+CloneListLen],0x0
jmp .nextField ; ↓
nop
.field.password: ; 8a6
cmp byte [bp-0x9],MaxPasswordLength
if a
mov byte [si+MaxPasswordLength-1],0x0
endif ; 8b0
mov ax,[GameStatePtr]
add ax,LevelPassword
push ds
push ax
push ds
push si
call far KERNEL.lstrcpy ; 8ba
mov ax,[GameStatePtr]
add ax,LevelPassword
push ax
call far DecodePassword ; 8c6 4:6b0
add sp,byte +0x2
jmp short .nextField ; ↓
.field.hint: ; 8d0
cmp byte [bp-0x9],MaxHintLength
if a
mov byte [si+MaxHintLength-1],0x0
endif ; 8da
mov ax,[GameStatePtr]
add ax,LevelHint
jmp .lstrcpy ; ↑
nop
.field.plaintextPassword: ; 8e4
cmp byte [bp-0x9],MaxPasswordLength
if a
mov byte [si+MaxPasswordLength-1],0x0
endif ; 8ee
mov ax,[GameStatePtr]
add ax,LevelPassword
jmp .lstrcpy ; ↑
nop
.field.monsters: ; 8f8
mov di,si
mov al,[bp-0x9]
shr al,1
sub ah,ah
mov bx,[GameStatePtr]
mov [bx+InitialMonsterListLen],ax
xor dx,dx
mov bx,[GameStatePtr]
cmp [bx+InitialMonsterListLen],dx
jng .nextField ; ↓
mov [data],si
xor bx,bx
.loop.monsterList: ; 91a
mov ax,[di]
mov si,[GameStatePtr]
mov [bx+si+InitialMonsterList],ax
add bx,byte +0x2
add di,byte +0x2
inc dx
mov si,[GameStatePtr]
cmp [si+InitialMonsterListLen],dx
jg .loop.monsterList ; ↑
jmp .mov_si_data_and_jmp_nextField ; ↑
.nextField: ; 938
mov al,[bp-0x9]
sub ah,ah
add si,ax
cmp si,[bp-0xc]
jnb .end ; ↓
jmp .loop.fields ; ↑
.end: ; 947
pop si
pop di
endfunc
; 950
; checks the signature of a file
; and returns the next word (number of levels)
func FUN_4_0950
%arg hFile:word
sub sp,byte +0x4
push si
mov si,[hFile]
push si
lea ax,[bp-0x4]
push ss
push ax
push byte +0x2
call far KERNEL._lread ; 969
cmp ax,0x2
if b
.error: ; 973
xor ax,ax
jmp short .end ; ↓
nop
endif ; 978
cmp word [bp-0x4],0xaaac
jnz .error ; ↑
push si
lea ax,[bp-0x4]
push ss
push ax
push byte +0x2
call far KERNEL._lread ; 987
cmp ax,0x2
jb .error ; ↑
cmp word [bp-0x4],byte +0x2
jnz .error ; ↑
push si
lea ax,[bp-0x4]
push ss
push ax
push byte +0x2