-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathCSBCode.cpp
More file actions
11428 lines (10903 loc) · 288 KB
/
CSBCode.cpp
File metadata and controls
11428 lines (10903 loc) · 288 KB
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
#include "stdafx.h"
#include <stdio.h>
#ifdef _MSVC_CE2002ARM
ui32 time(void *);
#else
#include <time.h>
#endif
#include "UI.h"
//#include "Objects.h"
#include "Dispatch.h"
#include "CSB.h"
#include "Data.h"
extern i32 VBLperTimer;
extern bool overlayActive;
i32 timerTypeModifier[3]; // set/clear/toggle
void info(const char *msg, unsigned int n);
void CleanupGraphics();
void CloseTraceFile();
void CustomBackgrounds(i32 x, i32 y, i32 facing, i32 roomNum);
void ClearOverlayPalette();
bool IsTextScrollArea(int, int);
i32 TextWidth();
void TraceTimer(TIMER *pTimer, i32 index, const char *msg);
void RecordfileOpen(bool open);
void RecordFile_Close();
void RecordFile_Record(MouseQueueEnt *MQ);
void RecordFile_Record(const char *line);
bool IsPlayFileOpen();
pnt GetExternalPortraitAddress(i32 index);
void QueueDSASwitchAction(
i32 delay, //
i32 tmrAct, //Action set/clear/toggle
i32 level, //
i32 targetX,i32 targetY,
i32 targetPos,
char MorD);
//i32 D0,D1,D2,D3,D4,D5,D6,D7;
//pnt A0,A1,A2,A3,A4,A5,A6,A7;
extern bool PlaybackCommandOption;
extern bool DMRulesDesignOption;
extern bool invisibleMonsters;
extern bool drawAsSize4Monsters;
extern bool GameIsComplete;
extern bool RepeatGame;
extern bool fullscreenRequested;
extern bool virtualFullscreen;
extern bool overlappingText;
extern i32 VBLMultiplier;
extern char *helpMessage;
extern unsigned char *encipheredDataFile;
extern bool simpleEncipher;
extern i32 trace;
extern ui8 reincarnateAttributePenalty, reincarnateStatPenalty, randomPoints;
extern i32 numGlobalVariables;
extern ui32 *globalVariables;
#ifdef GraphicsDebug
FILE *GrphDbg = NULL;
#endif
pnt firstMemoryBlock=NULL; // Debug list of allocated blocks
DBank d;
void _MessageBox(const char *msg)
{
UI_MessageBox(msg,NULL,MESSAGE_OK);
}
void Terminate()
{
die(0);
};
void die(i32 errorNum, const char *msg) // TAG000efc
{
char message[300];
// {
// FILE *f;
// f = fopen("debug", "a");
// fprintf(f, "die(%d)\n", errorNum);
// fclose(f);
// };
if ((msg==NULL)||(strlen(msg)==0))
{
switch(errorNum)
{
case 41: msg="Cannot open GRAPHICS.DAT"; break;
case 141: msg="Too many files open"; break;
default: msg="SystemError";
};
};
sprintf(message,"System Error 0x%08x\n%s",errorNum,msg);
UI_MessageBox(message,NULL,MESSAGE_OK);
if (errorNum == 41)
{
UI_MessageBox(helpMessage,"Help",MESSAGE_OK);
};
CloseTraceFile();
RecordFile_Close();
UI_Die(errorNum);
}
void _Assert(bool value, char *program, i32 line, const char *text)
{
i32 n;
if (value==0)
{
char msg[1000];
if (text == NULL) text = "";
sprintf(msg,
"Assertion failure at time = %d\n"
"Line %d\n"
"Program %s\n"
"%s\n"
"Should we quit?", d.Time, line, program, text);
n = UI_MessageBox(msg,NULL,MESSAGE_YESNO);
if (n == MESSAGE_IDYES)
{
if (TimerTraceActive)
{
CLOSE(TraceFile);
die (0,NULL);
};
};
};
}
struct PRINTENTRY
{
PRINTENTRY *m_next;
i32 m_color;
i32 m_type;
char m_text[1];
};
class PRINTQUEUE
{
private:
PRINTENTRY *m_firstEnt;
public:
PRINTQUEUE() {m_firstEnt = NULL;};
~PRINTQUEUE()
{
while (m_firstEnt != NULL)
{
PRINTENTRY *temp = m_firstEnt;
m_firstEnt = temp->m_next;
UI_free (temp);
};
};
void Queue(i32 color, i16 type, const char *text);
PRINTENTRY *GetEntry();
};
void PRINTQUEUE::Queue(i32 color, i16 type, const char *text)
{
i32 len;
PRINTENTRY *temp, *next;
len = strlen(text);
len += sizeof (PRINTENTRY) + 10;// Just to feel safe.
temp = (PRINTENTRY *)UI_malloc (len, MALLOC007);
if (temp == NULL)
{
die(0x7dea3,"Cannot allocate Printline Memory");
};
temp->m_next = NULL;
temp->m_color = color;
temp->m_type = type;
strcpy(temp->m_text,text);
if (m_firstEnt ==NULL) m_firstEnt = temp;
else
{
next = m_firstEnt;
while (next->m_next != NULL) next = next->m_next;
next->m_next = temp; // Add new entry at end of queue.
};
}
PRINTENTRY *PRINTQUEUE::GetEntry()
{
PRINTENTRY *temp;
if (m_firstEnt == NULL) return NULL;
temp = m_firstEnt;
m_firstEnt = temp->m_next;
return temp;
}
PRINTQUEUE printQueue;
bool verifyRectPos(RectPos *r)
{
ui32 x1, x2, y1, y2;
if (d.UseByteCoordinates)
{
x1=r->b.x1;
x2=r->b.x2;
y1=r->b.y1;
y2=r->b.y2;
}
else
{
x1=r->w.x1;
x2=r->w.x2;
y1=r->w.y1;
y2=r->w.y2;
};
if (x1>x2) return false;
if (y1>y2) return false;
if (x2>319) return false;
if (y2>199) return false;
return true;
}
#ifdef _littleEndian
i32 LE32(i32 lng)
{
return ((lng >> 24)&0xff)
| ((lng >> 8)&0xff00)
| ((lng << 8)&0xff0000)
| ((lng <<24)&0xff000000);
}
#endif
#ifdef _bigEndian
i32 BE32(i32 lng)
{
return ((lng >> 24)&0xff)
| ((lng >> 8)&0xff00)
| ((lng << 8)&0xff0000)
| ((lng <<24)&0xff000000);
}
#endif
RN& RNGear(pnt p)
{
return *((RN *)(p));
}
#ifdef _DEBUG
i32& longGear(ui8 *p)
{
ASSERT(((int)p & 3) == 0,"p");
return *((i32 *)(p));
}
#endif
pnt& pntGear(pnt p)
{
ASSERT(((int)p & 3) == 0,"p");
return *((pnt *)(p));
}
upnt& upntGear(pnt p)
{
return *((upnt *)(p));
}
void SwapWordsInButtonList(btn *pButton)
{
for (;pButton->word0 != 0; pButton++)
{
pButton->word0 = LE16(pButton->word0);
pButton->xMin = LE16(pButton->xMin);
pButton->xMax = LE16(pButton->xMax);
pButton->yMin = LE16(pButton->yMin);
pButton->yMax = LE16(pButton->yMax);
pButton->button = LE16(pButton->button);
};
}
i32 programDescriptor[] = {
0, // Program Header Address
0, // Last Allocated address +1
0, // Start of program I-Bank
0, // Length of program I-Bank
0, // Start of initialized data
0x05ec, // Length of initialized data
0, // Start of uninitialized data
0x5b70 // Length of uninitialized data
};
ui8 LScreenBase[320][210]; // Extra room at end for ???
void SetButtonPointers()
{
d.pButn18970[0][0] = d.Buttons18624;
d.pButn18970[0][1] = d.Buttons18660;
d.pButn18970[0][2] = d.Buttons18708;
d.pButn18970[0][3] = d.Buttons18768;
d.pButn18970[1][0] = d.Buttons18792;
d.pButn18970[1][1] = d.Buttons18828;
d.pButn18970[1][2] = d.Buttons18876;
d.pButn18970[1][3] = d.Buttons18936;
}
DBank::DBank()
{
}
void DBank::Initialize() // TAG00332a
{
//d.Word1834=512;
Word1844=512;
Word1870 = 1;
Pointer2066[0] = &Byte1982;
//Pointer2066[1] = (pnt)&Word1838;
Pointer2066[2] = (pnt)&Word1870;
Pointer2066[3] = (pnt)&Word1844;
Pointer2526[0] = Word2050;
Pointer2526[1] = Word2210;
Pointer2526[2] = Word2318;
GraphicHandle = -1;
CurrentFloorAndCeilingGraphic = -1;
CurrentWallGraphic = -1;
Word7254 = 1;
LoadedLevel = -1;
Word11684 = 1;
Word11694 = 0;
Time = 0;
clockTick = 1;
newPartyLevel = -1;
LogicalScreenBase=&LScreenBase[0][0];
srand((unsigned int)UI_GetSystemTime());
RandomNumber=rand();
TextScanlineScrollCount = -1;
LastMonsterAttackTime = -200;
Pointer12988[0] = &Byte23114;
Pointer12988[1] = &Byte11850;
Pointer12988[2] = &Byte22676;
Pointer12988[3] = &Byte16550;
Pointer12988[4] = &Byte13118;
Pointer12988[5] = &Byte16702;
ITEM16QueLen = 0;
DelayedActuatorAction = -1; //Word13148
HandChar = -1; // owner of cursor
Pointer16596[0] = "FIGHTER";
Pointer16596[1] = "NINJA";
Pointer16596[2] = "PRIEST";
Pointer16596[3] = "WIZARD";
Long16600 = -505;
DisplayResurrectChestOrScroll = 0;
objOpenChest = RNnul;
Pointer16770[2] = "NEOPHYTE";
Pointer16770[3] = "NOVICE";
Pointer16770[4] = "APPRENTICE";
Pointer16770[5] = "JOURNEYMAN";
Pointer16770[6] = "CRAFTSMAN";
Pointer16770[7] = "ARTISAN";
Pointer16770[8] = "ADEPT";
Pointer16770[9] = "EXPERT";
Pointer16770[10] = "` MASTER";
Pointer16770[11] = "a MASTER";
Pointer16770[12] = "b MASTER";
Pointer16770[13] = "c MASTER";
Pointer16770[14] = "d MASTER";
Pointer16770[15] = "e MASTER";
Pointer16770[16] = "ARCHMASTER";
Pointer16778 = &Byte10638;
//pwPointer16774 = &Word918;
Pointer16770[0] = (char *)&Long16600;
//Pointer16770[1] = (pnt)&Word1834;
DirectionNames[0] = "NORTH";
DirectionNames[1] = "EAST";
DirectionNames[2] = "SOUTH";
DirectionNames[3] = "WEST";
Pointer16822[0] = "L";
Pointer16822[1] = "STRENGTH";
Pointer16822[2] = "DEXTERITY";
Pointer16822[3] = "WISDOM";
Pointer16822[4] = "VITALITY";
Pointer16822[5] = "ANTI-MAGIC";
Pointer16822[6] = "ANTI-FIRE";
MouseQEnd = MOUSEQLEN-1;
MouseInterlock = 1;
SetButtonPointers();
MagicCaster = -1;
Pointer22812 = "GAME LOADED, READY TO PLAY.";
Pointer22816 = "CAN'T MODIFY CHAOS STRIKES BACK DISK!";
Pointer22820 = "THAT'S NOT THE MASTER DISK!";
Pointer22824 = "CAN'T FIND SAVED GAME!";
Pointer22828 = "UNABLE TO SAVE GAME!";
Pointer22832 = "UNABLE TO FORMAT DISK!";
Pointer22836 = "THAT'S THE CHAOS STRIKES BACK DISK!";
Pointer22840 = "THAT'S A GAME SAVE DISK!";
Pointer22844 = "THAT DISK IS WRITE-PROTECTED!";
Pointer22848 = "THAT DISK IS UNREADABLE";
Pointer22852 = "THAT'S NOT THE SAME GAME";
Pointer22856 = "SAVED GAME DAMAGED!";
Pointer22860 = "PUT THE GAME SAVE DISK IN ~";
Pointer22864 = "PUT THE CHAOS STRIKES BACK DISK IN ~";
Pointer22868 = "PUT A BLANK DISK IN ~";
Pointer22872 = "SAVING GAME . . .";
Pointer22876 = "LOADING GAME . . .";
Pointer22880 = "FORMATTING DISK . . .";
Pointer22884 = "FORMAT DISK ANYWAY?";
Pointer22888 = "THERE IS NO DISK IN ~!";
Pointer22892 = "LOAD SAVED GAME";
Pointer22896 = "SAVE AND PLAY";
Pointer22900 = "SAVE AND QUIT";
Pointer22904 = "FORMAT FLOPPY";
Pointer22908 = "OK";
Pointer22912 = "CANCEL";
strcpy(Byte23008,"A:\\csbgame.dat");
strcpy(Byte23024,"A:\\csbgame.bak");
strcpy(Byte23030,"A:\\F");
UseByteCoordinates = 0;
Pointer23040 = (pnt)0x484;
CurrentSound = -1;
Word23046 = 0;
Word23118 = 0;
STHideCursor(HC50);
NewCursorShape = 1;
Word23150 = 0;
Byte23202[0] = 2;
Byte23202[1] = 17;
Byte23202[2] = 2;
Byte23202[3] = 17;
Byte23206[0] = 0;
Byte23206[1] = 15;
Byte23206[2] = 0;
Byte23206[3] = 15;
wRectPos23214.w.x1 = 2;
wRectPos23214.w.x2 = 20;
wRectPos23214.w.y1 = 2;
wRectPos23214.w.y2 = 15;
wRectPos23222.w.x1 = 0;
wRectPos23222.w.x2 = 18;
wRectPos23222.w.y1 = 0;
wRectPos23222.w.y2 = 13;
OnMouseSwitchActionLock = 0; //(23224)
Word23226 = 0;
// Word23228 = 0;
ClusterInCache = -1; //(23276)
Word23366 = 4096;
RightZeroMask[0] = -1;
RightZeroMask[1] = -2;
RightZeroMask[2] = -4;
RightZeroMask[3] = -8;
RightZeroMask[4] = -16;
RightZeroMask[5] = -32;
RightZeroMask[6] = -64;
RightZeroMask[7] = -128;
RightZeroMask[8] = 0;
RightOneMask[0] = 0;
RightOneMask[1] = 1;
RightOneMask[2] = 3;
RightOneMask[3] = 7;
RightOneMask[4] = 15;
RightOneMask[5] = 31;
RightOneMask[6] = 63;
RightOneMask[7] = 127;
RightOneMask[8] = -1;
LZWBitNumber = 0;
Word23406 = 0;
ClearOverlayPalette();
}
ui16 DBank::GetDerivedGraphicSize(i32 graphicNum)
{
return pwDerivedGraphicSizes[graphicNum];
}
void DBank::SetDerivedGraphicSize(i32 graphicNum, i32 size)
{
if ( (pwDerivedGraphicSizes[graphicNum] != 0)
&&(pDerivedGraphicCacheIndex[graphicNum] != -1) )
{
char msg[100];
sprintf(msg,"Doubly defined graphic size\nGraphic=0x%x, oldSize=0x%x, newSize=0x%x",
graphicNum, pwDerivedGraphicSizes[graphicNum], size);
UI_MessageBox(msg, "Warning", MESSAGE_OK);
if (size > pwDerivedGraphicSizes[graphicNum]) pwDerivedGraphicSizes[graphicNum] = (i16)size;
return;
};
pwDerivedGraphicSizes[graphicNum] = (i16)size;
}
void DBank::AllocateDerivedGraphicsSizesBuffer()
{
pwDerivedGraphicSizes = (i16 *)allocateMemory(730*sizeof(i16), 1);
memset(pwDerivedGraphicSizes, 0, 730*sizeof(i16));
}
void DBank::AllocateDerivedGraphicCacheIndex()
{
pDerivedGraphicCacheIndex = (i16 *)allocateMemory(730*sizeof(i16), 1);
memset(pDerivedGraphicCacheIndex, 0xff, 730*sizeof(i16));
}
i16 DBank::GetDerivedGraphicCacheIndex(i32 graphicNum)
{
return pDerivedGraphicCacheIndex[graphicNum];
}
void DBank::SetDerivedGraphicCacheIndex(i32 graphicNum, i32 index)
{
if ((index != -1) && (pDerivedGraphicCacheIndex[graphicNum] != -1))
{
char msg[100];
sprintf(msg,"Doubly defined graphic Index\nGraphic=0x%x", graphicNum);
UI_MessageBox(msg, "Warning", MESSAGE_OK);
};
pDerivedGraphicCacheIndex[graphicNum] = (i16)index;
//The sizes of the first four graphics are wired into the code.
//We must not forget their sizes even when the graphic is deleted.
if ((index == -1) && (graphicNum > 3)) pwDerivedGraphicSizes[graphicNum] = 0;
}
void SetSupervisorMode() {}
void ClearSupervisorMode() {}
void HangIfZero(i16 P1)
{
if (P1 == 0)
die(0,"HangIfZero");
}
void DisableCursor() {}
i32 GetAvailMemory()
{
return 2000000 - 400000;// 550000;//510000;//1000000;
// We no longer need the 843144 bytes that used to be
// used for graphics. We now use malloc() to allocate
// graphic buffers permanently rather than use the
// complicated graphics heap logic that was designed
// for the memory-starved Atari 512ST.
}
void jdisint(i16)
{ // Disable some interrupts.
HopefullyNotNeeded(0xa671);
}
ui32 GraphicRandom(ui32 n)
{
static ui32 r = 12345;
//;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
r = r * ui32(0xbb40e62d) + 11;
return (r>>7) % n;
}
#ifdef _DEBUG
void DebugMain(char *msg)
{
if (TimerTraceActive)
{
fprintf(GETFILE(TraceFile),"%s\n",msg);
};
}
#endif
//#define DEBUGMAIN(a) DebugMain(a);
#define DEBUGMAIN(a)
// TAG00068e
RESTARTABLE _MainLoop(const CSB_UI_MESSAGE * /*msg*/)
{//()
static dReg D0, D1;
static PRINTENTRY *pPrintEntry;
RESTARTMAP
RESTART(1)
RESTART(2)
RESTART(4)
// RESTART(6)
RESTART(7)
RESTART(8)
RESTART(9)
//RESTART(10)
END_RESTARTMAP
// We discard any message information. At least for now.
tag000698: //We get here for each tick of the clock.
DEBUGMAIN("tag000698")
if (videoMode != VM_ADVENTURE)
{
if ( (videoMode!=VM_INVENTORY) && (d.PartySleeping==0))
{
videoMode = VM_ADVENTURE;
ForceScreenDraw();
UI_Invalidate(true);
};
};
if (d.PartySleeping == 0)
{
scrollingText.SetNewSpeed(d.Speed, speedTable[gameSpeed].vblPerTick);
d.Speed = sw(speedTable[gameSpeed].vblPerTick); // Delay vblOccurred for 10 VBLs
};
d.vblCount = 0;
if (d.newPartyLevel == -1) goto tag0006d0;
tag0006a4:
DEBUGMAIN("tag0006a4")
LoadPartyLevel(d.newPartyLevel); // Load graphics for level
MoveObject(RN(RNnul), -1, 0, d.partyX, d.partyY, NULL, NULL);
d.newPartyLevel = -1;
DiscardAllInput();
tag0006d0:
DEBUGMAIN("tag0006d0")
if (ProcessTimers())
{
// Gamme has been won.
VBLDelay(_1_,300); //about 5 seconds
ShowCredits(_2_,1); // We won the game with 4 corbums in FulYa pit.
// Show Credits will never return
};
if (GameIsComplete) RETURN;
if (d.newPartyLevel != -1) goto tag0006a4;
if (d.SelectedCharacterOrdinal != 0) goto tag000730;
if (d.PartySleeping != 0) goto tag000730;
DrawViewport(d.partyFacing, d.partyX, d.partyY);
if (d.ShowCursor16572 != 0)
{
d.ShowCursor16572=0;
STHideCursor(HC19); //TAG002fd2
CreateObjectCursor(d.Pointer16572);
STShowCursor(HC19); //TAG003026
};
if (d.ShowCursor1 != 0)
{
d.ShowCursor1=0;
d.NewCursorShape=1;
STHideCursor(HC20); //TAG002fd2
STShowCursor(HC20); //TAG003026
};
tag000730:
DEBUGMAIN("tag000730")
WaitForButtonFlash(); // If any are active.
StartQueuedSound(); //counted
DisplayCharacterDamage(); //counted
if (d.GameIsLost == 0)
{
d.Time++;
if (TimerTraceActive)
{
i64 stime;
static i64 prevstime;
stime = UI_GetSystemTime();
#ifdef _LINUX
//fprintf(GETFILE(TraceFile),"%lld %lld Increment virtual game Time\n", stime, stime-prevstime);
fprintf(GETFILE(TraceFile), "Increment virtual game Time to %08x\n", d.Time);
#else
//fprintf(GETFILE(TraceFile),"%I64d %I64d Increment virtual game Time\n", stime, stime-prevstime);
fprintf(GETFILE(TraceFile), "Increment virtual game Timeto %08x\n", d.Time);
#endif
prevstime = stime;
};
if ((currentOverlay.m_p3 != 0) && (currentOverlay.m_p3 < d.Time)) overlayActive = false;
parameterMessageSequence = 0;
scrollingText.ClockTick();
SmartDiscard(false);
GameTime = d.Time;
if ((d.Time&511)==0) // about every 85 seconds
{
NinetySecondUpdate(); //TAG018124
};
if (d.freezeLifeTimer != 0) d.freezeLifeTimer--;
TAG01b29a(_4_);
D0L = d.Time;
D0L &= d.PartySleeping ? 15 : 63;
if (D0L==0) TenSecondUpdate();
D0L=d.partyMoveDisableTimer;
if (D0L!=0)
{
d.partyMoveDisableTimer--;
};
D0L=d.Word11712;
if (D0L != 0) d.Word11712--;
//RemoveTimedOutText(_10_); // Remove text when its time is up.
//RemoveTimedOutText(); // Remove text when its time is up.
D0UL=d.WatchdogTime;
D1UL=d.Time;
if (D0UL < D1UL)
{
die(60, "Watchdog Timer failure"); //die (error number)
};
d.clockTick=0;
tag0007b4:
DEBUGMAIN("tag0007b4")
goto tag0007c8;
tag0007b6: // A UIM_KEYDOWN message was received.
DEBUGMAIN("tag0007b6")
D0L=UI_DIRECT_CONIN(); // Wait for key
//D0L = msg->p1;
ASSERT(D0L != -1,"D0L");
TAG0196da(D0L);
tag0007c8:
DEBUGMAIN("tag0007c8")
pPrintEntry = printQueue.GetEntry();
if (pPrintEntry != NULL)
{
PrintLines(pPrintEntry->m_color,pPrintEntry->m_text);
UI_free (pPrintEntry);
};
WAITFORMESSAGE(_8_);//Any message!;//pumper();
{
//SYSTEMTIME systime;
//GetSystemTime(&systime);
};
D0W=(i16)UI_CONSTAT();
if (D0W != 0) goto tag0007b6;
/*
if (d.QuitPressingEye != 0)
{
d.PressingEye=0;
d.QuitPressingEye=0;
QuitPressingEye(); //Remove object from eye????
}
else
{
if (d.QuitPressingMouth != 0)
{
d.PressingMouth=0;
d.QuitPressingMouth=0;
QuitPressingMouth();
};
};
*/
do
{
HandleMouseEvents(_7_,1); //TAG01a7b2
if (d.QuitPressingEye != 0)
{
d.PressingEye=0;
d.QuitPressingEye=0;
QuitPressingEye(); //Remove object from eye????
}
if (d.QuitPressingMouth != 0)
{
d.PressingMouth=0;
d.QuitPressingMouth=0;
QuitPressingMouth();
};
} while (intResult & 1);
if (DiskMenuNeeded) DisplayDiskMenu(_9_);
if (d.clockTick == 0) WaitForButtonFlash(); // If any active
if (d.clockTick == 0) goto tag0007b4; // Usually 0
if (d.ClockRunning == 0) goto tag0007b4; // Usually 1
if ((d.Time&63) == 0) // about every 10 seconds
{
D0W = (i16)(d.Word11722); //d.Word11724 always zero. & (d.Word11724 ^ 0xffff));
if (D0W != 0)
{
TAG02076e();
TAG0207cc();
};
};
goto tag000698;
};
DEBUGMAIN("RETURN")
RETURN;
}
// *********************************************************
//
// *********************************************************
// TAG000850
void LoadPartyLevel(const i32 level)
{//()
dReg D0;
//i32 LOCAL_1;
//i8 LOCAL_2[6];
TIMER LOCALa;
//RESTARTMAP
//RESTART(1)
//RESTART(2)
//END_RESTARTMAP
TAG00bd40(); //Remove item16 entries for monsters from level.
SetPartyLevel(level);
ReadGraphicsForLevel();
if (d.Time > d.Long16600+500)
{
d.Long16600=d.Time+1;
LOCALa.Function(TT_22);
D0L=d.Long16600+2;
//D1L=level;
//D1L >>= 24;
//D0L |= D1L;
//LOCALa.timerTime = D0L;
// Notice that D1L was shifted right!!!! 20130115 PRS
LOCALa.Time(D0L);
LOCALa.Level((ui8)level);
//Not needed, I think. PRS 17 Feb 2004....SetTimer(&LOCALa);
InsertDisk(0,0);
HopefullyNotNeeded(0xcdb7);
//d.Word19218 = 12777; // Seems in middle of graphic data
//d.Word918 = 136;
//d.Word1834 = 555;
};
ProcessMonstersOnLevel(); //add item16 entries for monsters on level.
SelectPaletteForLightLevel();
return;
}
void MemMove(ui8 *src, ui8 *dest, i32 byteCount) // TAG0009dc
{
memmove(dest, src, byteCount);
}
void ClearMemory(ui8 *dest,i32 numByte) // TAG000a84
{
memset(dest,0,numByte);
}
void fillWithByte(ui8 *addr,i16 num,i8 value,i16 spacing) //TAG000ac0
{
do
{
*addr = value;
addr+=spacing;
} while (--num!=0);
}
void fillMemory(i16 *pwAddress, i32 num, i16 value, i16 spacing) //TAG000af6
{ // num words, spacing apart
spacing /= 2; // Must be word spacing
do
{
*pwAddress = value;
pwAddress += spacing;
} while ((--num) != 0);
}
void TAG000bb0(dReg& D0, dReg& D4, dReg& D5) // called by VBL handler
{ // Expects something in D0, D5, D4
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
// Always zero. I removed it. if (d.Word23228 < 0)
{
// Word11720 always zero. I removed it. d.Word11722 |= d.Word11720;
// Always zero. I removed it. d.Word11720 = 0;
// d.Word23228 = 0;
};
if (d.Word23136 == 0) return;
if (D0W != 0)goto tag000c32;
if (d.TextScanlineScrollCount < 0) goto tag000bde;
if ((ui16)D5W >= 151) goto tag000c32;
tag000bde:
if (d.ViewportUpdated == 0) goto tag000c24;
if (D5W >= 169) goto tag000c24;
if (D4W >= 224) goto tag000c0c;
if (d.Word23146 == 0) goto tag000c04;
if (d.Word23150 == 0) goto tag000c04;
if (D5W <= 23) goto tag000c24;
goto tag000c32;
tag000c04:
if (D5W < 16) goto tag000c24;
goto tag000c32;
tag000c0c:
if (d.Word23146 == 0) goto tag000c24;
if (D5W > 28) goto tag000c24;
if (D5W <= 23) goto tag000c24;
if (D4W < 232) goto tag000c32;
tag000c24:
if (d.FlashButnActive == 0) goto tag000c30;
if (D4W >= 192) goto tag000c32;
tag000c30:
return;
tag000c32:
D0L = 1;
RemoveCursor(); //TAG00289a();
}
ui32 VBLCount = 0;
ui32 VBLInterruptCount = 0;
void vblInterrupt() // TAG000c3a
{
// Vertical Blank Handler
dReg D0, D1, D2, D3, D4, D5;
//aReg A0;
static i32 Count=0;
VBLInterruptCount++;
//SaveRegs(0xfc8c);
//i32 *A4,*A5;
//VBLCount++; // Counted by function that calls us.
// A4 = data000b2c; // both start at zero
// A5 = data000b30;
if (d.ViewportUpdated)
{
d.DynamicPaletteSwitching = d.Word11740;
}
//if (d.DynamicPaletteSwitching != 0)
//{
// d.Word11988 = 0;
// A0 = (pnt)0xfffffa00;
//};
if (d.VBLInterruptActive != 0)
{
return;
};
d.VBLInterruptActive++;
// Loop: ; From below.
//loop:
Instrumentation(icntVBLLoop);
if (d.Word23138 == 0)
{
D0L = 0;
D3H1 = d.NewMouseY;//Word23124;
D3W = d.NewMouseX;//Word23122;
if (!IsPlayFileOpen())
{
d.CurMouseY = D3H1;//Word23128 = D3U;
d.CurMouseX = D3W;//Word23126 = D3W;
};
D2L = D3L;
SWAP(D2);
D4W = d.CurCursorX;
D5W = d.CurCursorY;
if (d.Word23144 != 0)
{
if ((D3W < 274) || (D2W > 28))
{
//SaveRegs(0xf0c0);
TAG002818();
//RestoreRegs(0x030f);
};
};
D0W = d.Word23132;
d.Word23132 = 0;
if ( (d.Word23130 != 0)
&& (d.NewCursorShape == 0)
&& (D3W == D4W)
&& (D2W == D5W) )
{
D0L = 1;
d.Word23130 = 0;
};
TAG000bb0(D0, D4, D5); // Expects something in D0, D5, D4//counted
// May set D0 to 1;
if ((d.Word1870 == 0) && (d.Word11750 == 0))
{
//SaveRegs(0xf0c0);
TAG00456c();
//RestoreRegs(0x030f);
d.Word11750+=5;
};
if ((D0W != 0) && ((ui16)D2W <= 15))
{
DrawCursor();
D0L = 0;
};
if (d.TextScanlineScrollCount >= 0)
{
//SaveRegs(0xf0c0);
D1W = (i16)(27 - d.TextScanlineScrollCount);
D1L = (ui16)D1W * (ui16)160;
MemMove(d.LogicalScreenBase+172*160+160, // Up one line
d.LogicalScreenBase+172*160,
D1W);
// Should not need this. Unconditional Invalidate follows. Invalidate();
//RestoreRegs(0x030f);
}
else
{
if (d.PushTextUp == 0) goto tag000dbe;
d.PushTextUp = 0;
};
D1L = 7;
if (d.TextScanlineScrollCount >= 0)
{
d.TextScanlineScrollCount++;
D1W = d.TextScanlineScrollCount;
if (D1W == 7) d.TextScanlineScrollCount = -1;
};
//SaveRegs(0xf0c0);
D2W = D1W;
D1L = (ui16)D1W * (ui16)160;
D2W = (i16)-D2W;
D2W += 200;
D2L = (ui16)D2W * (ui16)160;
MemMove((ui8 *)d.newTextLine, // Bitmap of new text line.
d.LogicalScreenBase + D2L,
D1W);
Invalidate();
//RestoreRegs(0x030f);
tag000dbe:
if (d.ViewportUpdated != 0)
{
int i;
pnt A0,A1;