aboutsummaryrefslogtreecommitdiff
path: root/engines/simon/simon.h
blob: 382669506e9e4a2a21e99d6bedd1ef0386ed416a (plain)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
/* ScummVM - Scumm Interpreter
 * Copyright (C) 2001-2006 The ScummVM project
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.

 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 * $URL$
 * $Id$
 *
 */

#ifndef SIMON_H
#define SIMON_H

#include <stdio.h>

#include "base/engine.h"
#include "base/plugins.h"

#include "common/rect.h"
#include "common/util.h"

#include "simon/midi.h"
#include "simon/sound.h"
#include "simon/vga.h"

class GameDetector;

namespace Simon {

/* Various other settings */
//#define DUMP_FILE_NR 8
//#define DUMP_BITMAPS_FILE_NR 8

uint fileReadItemID(Common::File *in);

#define CHECK_BOUNDS(x, y) assert((uint)(x) < ARRAYSIZE(y))
#define NUM_PALETTE_FADEOUT 32

struct Child;
struct SubObject;

struct Item;
struct WindowBlock;
struct Subroutine;
struct SubroutineLine;
struct TimeEvent;

struct TextLocation {
	int16 x, y, width;
	TextLocation() { memset(this, 0, sizeof(*this)); }
};

struct HitArea {
	uint16 x, y;
	uint16 width, height;
	uint16 flags;
	uint16 id;
	WindowBlock *window;
	Item *item_ptr;
	uint16 verb;
	uint16 priority;
	HitArea() { memset(this, 0, sizeof(*this)); }
};

struct VgaPointersEntry {
	byte *vgaFile1;
	byte *vgaFile2;
	byte *sfxFile;
	VgaPointersEntry() { memset(this, 0, sizeof(*this)); }
};

struct VgaSprite {
	uint16 id;
	uint16 image;
	uint16 palette;
	uint16 x, y;									/* actually signed numbers */
	uint16 flags;
	uint16 priority;
	uint16 windowNum, fileId;
	VgaSprite() { memset(this, 0, sizeof(*this)); }
};

struct VgaSleepStruct {
	uint16 ident;
	const byte *code_ptr;
	uint16 sprite_id;
	uint16 cur_vga_file;
	VgaSleepStruct() { memset(this, 0, sizeof(*this)); }
};

struct VgaTimerEntry {
	uint16 delay;
	const byte *script_pointer;
	uint16 sprite_id;
	uint16 cur_vga_file;
	VgaTimerEntry() { memset(this, 0, sizeof(*this)); }
};

enum SIMONGameType {
	GType_FF = 0,
	GType_SIMON1 = 1,
	GType_SIMON2 = 2
};

struct GameFileDescription {
	const char *fileName;
	uint16 fileType;
	const char *md5;
};

struct GameDescription {
	const char *name;
	SIMONGameType gameType;
	GameIds gameId;
	const char *extra;
	int filesCount;
	GameFileDescription *filesDescriptions;
	uint32 features;
	Common::Language language;
	Common::Platform platform;

	DetectedGame toDetectedGame();
};

struct GameSpecificSettings;

class Debugger;

class SimonEngine : public Engine {
	friend class Debugger;

	void errorString(const char *buf_input, char *buf_output);

	typedef void (SimonEngine::*OpcodeProc) (bool &cond, int &ret);
	void setupOpcodes();
	const OpcodeProc *_opcode_table;
	int _numOpcodes;

	typedef void (SimonEngine::*VgaOpcodeProc) ();
	void setupVgaOpcodes();
	const VgaOpcodeProc *_vga_opcode_table;

public:
	GameDescription *_gameDescription;

	bool initGame(void);

	int getGameId() const { return _gameDescription->gameId; }
	int getGameType() const { return _gameDescription->gameType; }
	uint32 getFeatures() const { return _gameDescription->features; }
	Common::Language getLanguage() const { return _gameDescription->language; }
	Common::Platform getPlatform() const { return _gameDescription->platform; }

protected:
	void playSting(uint a);

	const byte *_vcPtr;								/* video code ptr */
	uint16 _vc_get_out_of_code;


	uint32 *_gameOffsetsPtr;

	uint VGA_DELAY_BASE;
	uint TABLE_INDEX_BASE;
	uint TEXT_INDEX_BASE;
	uint NUM_VIDEO_OP_CODES;
	uint VGA_MEM_SIZE;
	uint TABLES_MEM_SIZE;
	uint MUSIC_INDEX_BASE;
	uint SOUND_INDEX_BASE;
	const GameSpecificSettings *gss;

	byte _keyPressed;

	typedef enum {
		FORMAT_NONE,
		FORMAT_MP3,
		FORMAT_WAV,
		FORMAT_VOC
	} SoundFormat;

	Common::File *_gameFile;

	byte *_strippedTxtMem;
	uint _textSize;
	uint _stringTabNum, _stringTabPos, _stringtab_numalloc;
	byte **_stringTabPtr;

	Item **_itemArrayPtr;
	uint _itemArraySize;
	uint _itemArrayInited;

	byte *_itemHeapPtr;
	uint _itemHeapCurPos;
	uint _itemHeapSize;

	byte *_iconFilePtr;

	byte *_tblList;

	const byte *_codePtr;

	byte **_localStringtable;
	uint _stringIdLocalMin, _stringIdLocalMax;

	byte *_tablesHeapPtr, *_tablesHeapPtrOrg, *_tablesheapPtrNew;
	uint _tablesHeapSize, _tablesHeapCurPos, _tablesHeapCurPosOrg;
	uint _tablesHeapCurPosNew;

	Subroutine *_subroutineList, *_subroutineListOrg;
	uint _subroutine;

	uint _dxSurfacePitch;

	uint _recursionDepth;

	uint32 _lastVgaTick;

	uint16 _marks;

	bool _scriptVar2;
	bool _runScriptReturn1;
	bool _skipVgaWait;
	bool _noParentNotify;
	bool _beardLoaded;
	bool _hitarea_unk_3;
	bool _mortalFlag;
	byte _updateScreen;
	bool _usePaletteDelay;
	bool _syncFlag2;
	bool _inCallBack;
	bool _cepeFlag;
	byte _copyPartialMode;
	uint _speed;
	bool _fastMode;
	bool _dxUse3Or4ForLock;

	uint16 _debugMode;
	uint16 _language;
	bool _pause;
	bool _startMainScript;
	bool _continousMainScript;
	bool _startVgaScript;
	bool _continousVgaScript;
	bool _drawImagesDebug;
	bool _dumpImages;
	bool _speech;
	bool _subtitles;
	bool _fade;
	byte _animatePointer;
	byte _mouseCursor;
	byte _mouseAnim;
	byte _mouseAnimMax;
	bool _vgaVar9;
	int16 _scriptUnk1;
	bool _restoreWindow6;
	int _scrollX, _scrollXMax, _scrollHeight;
	int _scrollY, _scrollYMax, _scrollWidth;
	int _scrollCount, _scrollFlag;
	const byte *_scrollImage;
	byte _vgaVar8;

 	uint16 _hyperLink, _newLines;
 	uint16 _oracleMaxScrollY, _noOracleScroll;
 	uint16 _interactY;

	int16 _scriptVerb, _scriptNoun1, _scriptNoun2;
	int16 _scriptAdj1, _scriptAdj2;

	uint16 _curWindow;
	WindowBlock *_textWindow;

	Item *_subjectItem, *_objectItem;
	Item *_item1;

	Item *_hitAreaObjectItem;
	HitArea *_lastHitArea;
	HitArea *_lastNameOn;
	HitArea *_lastHitArea3;
	byte _leftButtonDown;
	byte _rightButtonDown;
	Item *_hitAreaSubjectItem;
	HitArea *_currentVerbBox, *_lastVerbOn;
	uint _needHitAreaRecalc;
	uint _verbHitArea;
	uint16 _defaultVerb;
	uint _mouseHideCount;
	uint _currentBoxNumber;
	uint _iOverflow;

	uint16 _windowNum;

	uint _printCharCurPos, _printCharMaxPos;
	uint _numLettersToPrint;

	uint _lastTime;

	TimeEvent *_firstTimeStruct, *_pendingDeleteTimeEvent;

	uint _base_time;

	int _mouseX, _mouseY;
	int _mouseXOld, _mouseYOld;

	Item *_dummyItem1;
	Item *_dummyItem2;
	Item *_dummyItem3;

	volatile uint16 _lockWord;
	uint16 _scrollUpHitArea;
	uint16 _scrollDownHitArea;

	uint16 _videoVar7;
	volatile uint16 _paletteColorCount;

	int _screenWidth, _screenHeight;

	byte _videoVar4;
	bool _videoVar5;
	bool _fastFadeOutFlag;
	bool _unkPalFlag;
	bool _exitCutscene;
	bool _noRightClick;
	byte _paletteFlag;

	uint _soundFileId;
	int16 _lastMusicPlayed;
	int16 _nextMusicToPlay;

	bool _showPreposition;
	bool _showMessageFlag;

	uint _videoNumPalColors;

	uint _vgaSpriteChanged;

	byte *_vgaBufFreeStart, *_vgaBufEnd, *_vgaBufStart;
	byte *_vgaFileBufOrg, *_vgaFileBufOrg2;

	byte *_curVgaFile1;
	byte *_curVgaFile2;
	byte *_curSfxFile;

	uint16 _syncCount, _timer5, _timer4;

	uint16 _frameRate;

	uint16 _vgaCurFile2;
	uint16 _vgaWaitFor, _vgaCurFileId;
	uint16 _vgaCurSpriteId;
	uint16 _vgaCurSpritePriority;

	int16 _baseY;
	float _scale;
	Common::Rect _feebleRect;
	int _scaleX, _scaleY, _scaleWidth, _scaleHeight;

	VgaTimerEntry *_nextVgaTimerToProcess;

	Item *_vcItemArray[20];
	Item *_itemArray6[20];

	uint16 _stringIdArray2[20];
	uint16 _stringIdArray3[20];
	uint16 _speechIdArray4[20];

	uint16 _bitArray[48];
	int16 _variableArray[256];
	int16 _variableArray2[256];

	WindowBlock *_windowArray[8];

	byte _fcsData1[8];
	bool _fcsData2[8];

	TextLocation _textLocation1, _textLocation2, _textLocation3, _textLocation4;

	int _freeStringSlot;

	byte _stringReturnBuffer[2][180];

	HitArea _hitAreas[90];

	VgaPointersEntry _vgaBufferPointers[450];
	VgaSprite _vgaSprites[180];
	VgaSleepStruct _vgaSleepStructs[30];

	const uint16 *_pathFindArray[100];

	uint8 _pathValues[400];
	uint8 _PVCount;
	uint8 _GPVCount;

	uint8 _pathValues1[400];
	uint8 _PVCount1;
	uint8 _GPVCount1;

	uint8 _paletteBackup[1024];
	uint8 _palette[1024];

	byte _videoBuf1[3000];

	VgaTimerEntry _vgaTimerList[95];

	WindowBlock *_windowList;

	byte _lettersToPrintBuf[80];

	MidiPlayer midi;
	bool _native_mt32;

	int _numScreenUpdates;
	int _vgaTickCounter;

	Sound *_sound;

	bool _effectsPaused;
	bool _ambientPaused;
	bool _musicPaused;

	Debugger *_debugger;

	FILE *_dumpFile;

	int _saveLoadRowCurPos;
	int _numSaveGameRows;
	bool _saveDialogFlag;
	bool _saveOrLoad;
	bool _saveLoadFlag;

	byte _saveLoadType, _saveLoadSlot;
	char _saveLoadName[32];

	int _sdlMouseX, _sdlMouseY;

	byte *_sdl_buf_3;
	byte *_sdl_buf;
	byte *_sdl_buf_attached;
	byte *_sdl_buf_scaled;

	Common::RandomSource _rnd;

	const byte *_vc10BasePtrOld;
	byte _hebrew_char_widths[32];

public:
	SimonEngine(OSystem *syst);
	virtual ~SimonEngine();

protected:
	uint16 to16Wrapper(uint value);
	uint16 readUint16Wrapper(const void *src);

	int allocGamePcVars(Common::File *in);
	void setUserFlag(Item *item, int a, int b);
	void createPlayer();
	void allocateStringTable(int num);
	void setupStringTable(byte *mem, int num);
	void setupLocalStringTable(byte *mem, int num);
	void readGamePcText(Common::File *in);
	void readItemChildren(Common::File *in, Item *item, uint tmp);
	void readItemFromGamePc(Common::File *in, Item *item);
	void loadGamePcFile(const char *filename);
	void loadOffsets(const char *filename, int number, uint32 &file, uint32 &offset, uint32 &compressedSize, uint32 &size);

	void palette_fadeout(uint32 *pal_values, uint num);
	
	byte *allocateItem(uint size);
	byte *allocateTable(uint size);
	void alignTableMem();

	Child *findChildOfType(Item *i, uint child);
	Child *allocateChildBlock(Item *i, uint type, uint size);

	void allocItemHeap();
	void allocTablesHeap();

	Subroutine *createSubroutine(uint a);
	void readSubroutine(Common::File *in, Subroutine *sub);
	SubroutineLine *createSubroutineLine(Subroutine *sub, int a);
	void readSubroutineLine(Common::File *in, SubroutineLine *new_table, Subroutine *sub);
	byte *readSingleOpcode(Common::File *in, byte *ptr);
	void readSubroutineBlock(Common::File *in);

	Subroutine *getSubroutineByID(uint subroutine_id);

	/* used in debugger */
	void dumpSubroutines();
	void dumpSubroutine(Subroutine *sub);
	void dumpSubroutineLine(SubroutineLine *sl, Subroutine *sub);
	const byte *dumpOpcode(const byte *p);

	int startSubroutine(Subroutine *sub);
	int startSubroutineEx(Subroutine *sub);

	bool checkIfToRunSubroutineLine(SubroutineLine *sl, Subroutine *sub);

	int runScript();

	Item *getNextItemPtr();
	uint getNextItemID();
	uint getItem1ID() {return 1;}
	Item *getItem1Ptr();
	Item *getItemPtrB();

	byte getByte();
	int getNextWord();

	uint getNextVarContents();
	uint getVarOrWord();
	uint getVarOrByte();
	uint readVariable(uint variable);
	void writeNextVarContents(uint16 contents);
	void writeVariable(uint variable, uint16 contents);

	void setItemParent(Item *item, Item *parent);

	uint itemPtrToID(Item *id);

	Item *derefItem(uint item);
	void setItemState(Item *item, int value);

	void showMessageFormat(const char *s, ...);
	const byte *getStringPtrByID(uint stringId);
	const byte *getLocalStringByID(uint stringId);
	uint getNextStringID();

	void addTimeEvent(uint timeout, uint subroutine_id);
	void delTimeEvent(TimeEvent *te);

	bool isRoom(Item *item);
	bool isObject(Item *item);

	void itemChildrenChanged(Item *item);
	void unlinkItem(Item *item);
	void linkItem(Item *item, Item *parent);

	bool o_chance(uint a);

	void o_kill_sprite_simon1(uint a);
	void o_kill_sprite_simon2(uint a, uint b);

	void o_vga_reset();
	void changeWindow(uint a);
	void o_unk_103();
	void closeWindow(uint a);
	void clear_hitarea_bit_0x40(uint hitarea);
	void set_hitarea_bit_0x40(uint hitarea);
	void moveBox(uint hitarea, int x, int y);
	bool is_hitarea_0x40_clear(uint hitarea);
	void delete_hitarea(uint hitarea);
	void addNewHitArea(int id, int x, int y, int width, int height, int flags, int unk3, Item *item_ptr);
	HitArea *findEmptyHitArea();
	void resetVerbs();
	void setVerb(HitArea * ha);
	void hitarea_leave(HitArea * ha);
	void leaveHitAreaById(uint hitarea_id);

	void o_waitForSync(uint a);
	void skipSpeech();
	void o_sync(uint a);
	void o_playMusic();
	void o_saveGame();
	void o_loadGame();
	void o_confirmQuit();
	void o_restoreIconArray(uint a);
	void o_freezeBottom();
	void killAllTimers();

	uint getOffsetOfChild2Param(SubObject *child, uint prop);
	void o_setTextColor(uint color);
	void o_playSFX(uint a);
	void o_lockZone();
	void o_unlockZone();
	void o_pathfind(int x, int y, uint var_1, uint var_2);
	void o_mouseOn();
	void o_mouseOff();
	void o_loadBeard();
	void o_unloadBeard();
	void o_unloadZone(uint a);
	void o_unfreezeBottom();
	void o_fadeToBlack();

	TextLocation *getTextLocation(uint a);
	void o_printStr();
	void o_setup_cond_c();
	void setup_cond_c_helper();

	void o_inventory_descriptions();

	void checkLinkBox();
 	void hyperLinkOn(uint16 x);
 	void hyperLinkOff();
	void linksUp();
	void linksDown();
	void listSaveGames(int n);
	void oracleTextUp();
	void oracleTextDown();

	void bltOracleText();
	void oracleLogo();
	void scrollOracle();
	void scrollOracleUp();
	void scrollOracleDown();
	void swapCharacterLogo();

	void mouseOff();
	void mouseOn();

	void drawIconArray(uint i, Item *item_ptr, int line, int classMask);
	void drawIconArray_FF(uint i, Item *item_ptr, int line, int classMask);
	void drawIconArray_Simon(uint i, Item *item_ptr, int line, int classMask);

	void loadTextIntoMem(uint stringId);
	void loadTablesIntoMem(uint subr_id);

	uint loadTextFile(const char *filename, byte *dst);
	Common::File *openTablesFile(const char *filename);
	void closeTablesFile(Common::File *in);

	uint loadTextFile_simon1(const char *filename, byte *dst);
	Common::File *openTablesFile_simon1(const char *filename);

	uint loadTextFile_gme(const char *filename, byte *dst);
	Common::File *openTablesFile_gme(const char *filename);

	void invokeTimeEvent(TimeEvent *te);
	bool kickoffTimeEvents();

	void clearName();
	void endCutscene();
	void runSubroutine101();
	void checkUp(WindowBlock *window);
	void checkDown(WindowBlock *window);
	void inventoryUp(WindowBlock *window);
	void inventoryDown(WindowBlock *window);
	void resetNameWindow();
	void printVerbOf(uint hitarea_id);
	HitArea *findHitAreaByID(uint hitarea_id);

	void showActionString(const byte *string);
	void videoPutchar(WindowBlock *window, byte c, byte b = 0);
	void clearWindow(WindowBlock *window);
	void video_toggle_colors(HitArea * ha, byte a, byte b, byte c, byte d);

	void read_vga_from_datfile_1(uint vga_id);

	uint get_fcs_ptr_3_index(WindowBlock *window);

	void setup_hitarea_from_pos(uint x, uint y, uint mode);
	void displayName(HitArea * ha);
	void displayBoxStars();
	void hitarea_stuff();

	void handleMouseMoved();
	void pollMouseXY();
	void drawMousePointer();

	void removeIconArray(uint num);
	void draw_icon_c(WindowBlock *window, uint icon, uint x, uint y);
	bool has_item_childflag_0x10(Item *item);
	uint itemGetIconNumber(Item *item);
	uint setupIconHitArea(WindowBlock *window, uint num, uint x, uint y, Item *item_ptr);
	void addArrows(WindowBlock *window, uint num);

	void loadIconData();	
	void loadIconFile();
	void processSpecialKeys();
	void hitarea_stuff_helper();

	void permitInput();
	void showmessage_helper_3(uint a, uint b);
	void showmessage_print_char(byte chr);

	void handleVerbClicked(uint verb);

	void o_set_video_mode(uint mode, uint vga_res);
	void set_video_mode_internal(uint mode, uint vga_res_id);

	void o_loadZone(uint vga_res);
	void loadZone(uint vga_res);

	void loadSprite(uint windowNum, uint vga_res, uint vga_sprite_id, uint x, uint y, uint palette);
	void o_defineWindow(uint a, uint b, uint c, uint d, uint e, uint f, uint g, uint h);
	void playSpeech(uint speech_id, uint vga_sprite_id);
	WindowBlock *openWindow(uint x, uint y, uint w, uint h, uint flags, uint fill_color, uint text_color);

	bool printTextOf(uint a, uint x, uint y);
	bool printNameOf(Item *item, uint x, uint y);
	void printInteractText(uint16 num, const char *string);
	void printScreenText(uint vga_sprite_id, uint color, const char *string_ptr, int16 x, int16 y, int16 width);

	void renderStringAmiga(uint vga_sprite_id, uint color, uint width, uint height, const char *txt);
	void renderString(uint vga_sprite_id, uint color, uint width, uint height, const char *txt);

	void setArrowHitAreas(WindowBlock *window, uint num);

	byte *setup_vga_destination(uint32 size);
	void vga_buf_unk_proc3(byte *end);
	void vga_buf_unk_proc1(byte *end);
	void vga_buf_unk_proc2(uint a, byte *end);
	void delete_memptr_range(byte *end);

	void setup_vga_file_buf_pointers();

	void run_vga_script();

public:
	// Simon1/Simon2 video script opcodes
	void vc1_fadeOut();
	void vc2_call();
	void vc3_loadSprite();
	void vc4_fadeIn();
	void vc5_skip_if_neq();
	void vc6_skip_ifn_sib_with_a();
	void vc7_skip_if_sib_with_a();
	void vc8_skip_if_parent_is();
	void vc9_skip_if_unk3_is();
	void vc10_draw();
	void vc11_clearPathFinder();
	void vc12_delay();
	void vc13_addToSpriteX();
	void vc14_addToSpriteY();
	void vc15_wakeup_id();
	void vc16_sleep_on_id();
	void vc17_setPathfinderItem();
	void vc18_jump();
	void vc19_chain_to_script();
	void vc20_setRepeat();
	void vc21_endRepeat();
	void vc22_setSpritePalette();
	void vc23_setSpritePriority();
	void vc24_setSpriteXY();
	void vc25_halt_sprite();
	void vc26_setSubWindow();
	void vc27_resetSprite();
	void vc28_dummy_op();
	void vc29_stopAllSounds();
	void vc30_setFrameRate();
	void vc31_setWindow();
	void vc32_copyVar();
	void vc33_setMouseOn();
	void vc34_setMouseOff();
	void vc35_clearWindow();
	void vc36_setWindowImage();
	void vc37_addToSpriteY();
	void vc38_skipIfVarZero();
	void vc39_setVar();
	void vc40();
	void vc41();
	void vc42_delayIfNotEQ();
	void vc43_skipIfBitClear();
	void vc44_skipIfBitSet();
	void vc45_setSpriteX();
	void vc46_setSpriteY();
	void vc47_addToVar();
	void vc48_setPathFinder();
	void vc49_setBit();
	void vc50_clearBit();
	void vc51_clear_hitarea_bit_0x40();
	void vc52_playSound();
	void vc53_no_op();
	void vc54_no_op();
	void vc55_offset_hit_area();
	void vc56_delay();
	void vc57_no_op();
	void vc58();
	void vc59();
	void vc60_killSprite();
	void vc61_setMaskImage();
	void vc62_fastFadeOut();
	void vc63_fastFadeIn();

	// Simon2 specific Video Script Opcodes
	void vc64_skipIfSpeechEnded();
	void vc65_slowFadeIn();
	void vc66_skipIfNotEqual();
	void vc67_skipIfGE();
	void vc68_skipIfLE();
	void vc69_playTrack();
	void vc70_queueMusic();
	void vc71_checkMusicQueue();
	void vc72_play_track_2();
	void vc73_setMark();
	void vc74_clearMark();

	// Feeble specific Video Script Opcodes
	void vc75_setScale();
	void vc76_setScaleXOffs();
	void vc77_setScaleYOffs();
	void vc78_computeXY();
	void vc79_computePosNum();
	void vc80_setOverlayImage();
	void vc81_setRandom();
	void vc82_getPathValue();
	void vc83_playSoundLoop();
	void vc84_stopSoundLoop();

	// Opcodes, Simon 1 and later
	void o1_at(bool &cond, int &ret);
	void o1_notAt(bool &cond, int &ret);
	void o1_carried(bool &cond, int &ret);
	void o1_notCarried(bool &cond, int &ret);
	void o1_isAt(bool &cond, int &ret);
	void o1_zero(bool &cond, int &ret);
	void o1_notZero(bool &cond, int &ret);
	void o1_eq(bool &cond, int &ret);
	void o1_notEq(bool &cond, int &ret);
	void o1_gt(bool &cond, int &ret);
	void o1_lt(bool &cond, int &ret);
	void o1_eqf(bool &cond, int &ret);
	void o1_notEqf(bool &cond, int &ret);
	void o1_ltf(bool &cond, int &ret);
	void o1_gtf(bool &cond, int &ret);
	void o1_chance(bool &cond, int &ret);
	void o1_isRoom(bool &cond, int &ret);
	void o1_isObject(bool &cond, int &ret);
	void o1_state(bool &cond, int &ret);
	void o1_oflag(bool &cond, int &ret);
	void o1_destroy(bool &cond, int &ret);
	void o1_place(bool &cond, int &ret);
	void o1_copyff(bool &cond, int &ret);
	void o1_clear(bool &cond, int &ret);
	void o1_let(bool &cond, int &ret);
	void o1_add(bool &cond, int &ret);
	void o1_sub(bool &cond, int &ret);
	void o1_addf(bool &cond, int &ret);
	void o1_subf(bool &cond, int &ret);
	void o1_mul(bool &cond, int &ret);
	void o1_div(bool &cond, int &ret);
	void o1_mulf(bool &cond, int &ret);
	void o1_divf(bool &cond, int &ret);
	void o1_mod(bool &cond, int &ret);
	void o1_modf(bool &cond, int &ret);
	void o1_random(bool &cond, int &ret);
	void o1_goto(bool &cond, int &ret);
	void o1_oset(bool &cond, int &ret);
	void o1_oclear(bool &cond, int &ret);
	void o1_putBy(bool &cond, int &ret);
	void o1_inc(bool &cond, int &ret);
	void o1_dec(bool &cond, int &ret);
	void o1_setState(bool &cond, int &ret);
	void o1_print(bool &cond, int &ret);
	void o1_message(bool &cond, int &ret);
	void o1_msg(bool &cond, int &ret);
	void o1_addTextBox(bool &cond, int &ret);
	void o1_setShortText(bool &cond, int &ret);
	void o1_setLongText(bool &cond, int &ret);
	void o1_end(bool &cond, int &ret);
	void o1_done(bool &cond, int &ret);
	void o1_printLongText(bool &cond, int &ret);
	void o1_process(bool &cond, int &ret);
	void o1_when(bool &cond, int &ret);
	void o1_if1(bool &cond, int &ret);
	void o1_if2(bool &cond, int &ret);
	void o1_isCalled(bool &cond, int &ret);
	void o1_is(bool &cond, int &ret);
	void o1_debug(bool &cond, int &ret);
	void o1_rescan(bool &cond, int &ret);
	void o1_comment(bool &cond, int &ret);
	void o1_haltAnimation(bool &cond, int &ret);
	void o1_restartAnimation(bool &cond, int &ret);
	void o1_getParent(bool &cond, int &ret);
	void o1_getNext(bool &cond, int &ret);
	void o1_getChildren(bool &cond, int &ret);
	void o1_picture(bool &cond, int &ret);
	void o1_loadZone(bool &cond, int &ret);
	void o1_animate(bool &cond, int &ret);
	void o1_stopAnimate(bool &cond, int &ret);
	void o1_killAnimate(bool &cond, int &ret);
	void o1_defWindow(bool &cond, int &ret);
	void o1_window(bool &cond, int &ret);
	void o1_cls(bool &cond, int &ret);
	void o1_closeWindow(bool &cond, int &ret);
	void o1_addBox(bool &cond, int &ret);
	void o1_delBox(bool &cond, int &ret);
	void o1_enableBox(bool &cond, int &ret);
	void o1_disableBox(bool &cond, int &ret);
	void o1_moveBox(bool &cond, int &ret);
	void o1_doIcons(bool &cond, int &ret);
	void o1_isClass(bool &cond, int &ret);
	void o1_setClass(bool &cond, int &ret);
	void o1_unsetClass(bool &cond, int &ret);
	void o1_waitSync(bool &cond, int &ret);
	void o1_sync(bool &cond, int &ret);
	void o1_defObj(bool &cond, int &ret);
	void o1_here(bool &cond, int &ret);
	void o1_doClassIcons(bool &cond, int &ret);
	void o1_playTune(bool &cond, int &ret);
	void o1_waitEndTune(bool &cond, int &ret);
	void o1_ifEndTune(bool &cond, int &ret);
	void o1_setAdjNoun(bool &cond, int &ret);
	void o1_saveUserGame(bool &cond, int &ret);
	void o1_loadUserGame(bool &cond, int &ret);
	void o1_stopTune(bool &cond, int &ret);
	void o1_pauseGame(bool &cond, int &ret);
	void o1_copysf(bool &cond, int &ret);
	void o1_restoreIcons(bool &cond, int &ret);
	void o1_freezeZones(bool &cond, int &ret);
	void o1_placeNoIcons(bool &cond, int &ret);
	void o1_clearTimers(bool &cond, int &ret);
	void o1_setDollar(bool &cond, int &ret);
	void o1_isBox(bool &cond, int &ret);
	void o1_doTable(bool &cond, int &ret);
	void o1_storeItem(bool &cond, int &ret);
	void o1_getItem(bool &cond, int &ret);
	void o1_bSet(bool &cond, int &ret);
	void o1_bClear(bool &cond, int &ret);
	void o1_bZero(bool &cond, int &ret);
	void o1_bNotZero(bool &cond, int &ret);
	void o1_getOValue(bool &cond, int &ret);
	void o1_setOValue(bool &cond, int &ret);
	void o1_ink(bool &cond, int &ret);
	void o1_screenTextBox(bool &cond, int &ret);
	void o1_screenTextMsg(bool &cond, int &ret);
	void o1_playEffect(bool &cond, int &ret);
	void o1_getDollar2(bool &cond, int &ret);
	void o1_isAdjNoun(bool &cond, int &ret);
	void o1_b2Set(bool &cond, int &ret);
	void o1_b2Clear(bool &cond, int &ret);
	void o1_b2Zero(bool &cond, int &ret);
	void o1_b2NotZero(bool &cond, int &ret);
	void o1_lockZones(bool &cond, int &ret);
	void o1_unlockZones(bool &cond, int &ret);
	void o1_screenTextPObj(bool &cond, int &ret);
	void o1_getPathPosn(bool &cond, int &ret);
	void o1_scnTxtLongText(bool &cond, int &ret);
	void o1_mouseOn(bool &cond, int &ret);
	void o1_mouseOff(bool &cond, int &ret);
	void o1_loadBeard(bool &cond, int &ret);
	void o1_unloadBeard(bool &cond, int &ret);
	void o1_unloadZone(bool &cond, int &ret);
	void o1_loadStrings(bool &cond, int &ret);
	void o1_unfreezeZones(bool &cond, int &ret);
	void o1_specialFade(bool &cond, int &ret);

	// Opcodes, Simon 2 and later
	void o2_printLongText(bool &cond, int &ret);
	void o2_rescan(bool &cond, int &ret);
	void o2_animate(bool &cond, int &ret);
	void o2_stopAnimate(bool &cond, int &ret);
	void o2_mouseOff(bool &cond, int &ret);
	void o2_isShortText(bool &cond, int &ret);
	void o2_clearMarks(bool &cond, int &ret);
	void o2_waitMark(bool &cond, int &ret);

	// Opcodes, Feeble Files
	void o3_jumpOut(bool &cond, int &ret);
	void o3_printLongText(bool &cond, int &ret);
	void o3_oracleTextDown(bool &cond, int &ret);
	void o3_oracleTextUp(bool &cond, int &ret);
	void o3_ifTime(bool &cond, int &ret);
	void o3_setTime(bool &cond, int &ret);
	void o3_loadUserGame(bool &cond, int &ret);
	void o3_listSaveGames(bool &cond, int &ret);
	void o3_checkCD(bool &cond, int &ret);
	void o3_screenTextBox(bool &cond, int &ret);
	void o3_hyperLinkOn(bool &cond, int &ret);
	void o3_hyperLinkOff(bool &cond, int &ret);
	void o3_checkPaths(bool &cond, int &ret);
	void o3_mouseOff(bool &cond, int &ret);
	void o3_loadSmack(bool &cond, int &ret);
	void o3_playSmack(bool &cond, int &ret);
	void o3_centreScroll(bool &cond, int &ret);
	void o3_resetPVCount(bool &cond, int &ret);
	void o3_setPathValues(bool &cond, int &ret);
	void o3_stopClock(bool &cond, int &ret);
	void o3_restartClock(bool &cond, int &ret);
	void o3_setColour(bool &cond, int &ret);
	void o3_b3Set(bool &cond, int &ret);
	void o3_b3Clear(bool &cond, int &ret);
	void o3_b3Zero(bool &cond, int &ret);
	void o3_b3NotZero(bool &cond, int &ret);

protected:
	void drawImages(VC10_state *state);
	void drawImages_Feeble(VC10_state *state);
	bool drawImages_clip(VC10_state *state);
	void scaleClip(int16 h, int16 w, int16 y, int16 x, int16 scrollY);

	void delete_vga_timer(VgaTimerEntry * vte);
	void vcResumeSprite(const byte *code_ptr, uint16 cur_file, uint16 cur_sprite);
	int vcReadVarOrWord();
	uint vcReadNextWord();
	uint vcReadNextByte();
	uint vcReadVar(uint var);
	void vcWriteVar(uint var, int16 value);
	void vcSkipNextInstruction();

	int getScale(int y, int x);
	void checkScrollX(int x);
	void checkScrollY(int y);

	bool itemIsSiblingOf(uint16 val);
	bool itemIsParentOf(uint16 a, uint16 b);
	bool vc_maybe_skip_proc_1(uint16 a, int16 b);

	void add_vga_timer(uint num, const byte *code_ptr, uint cur_sprite, uint cur_file);
	VgaSprite *findCurSprite();

	bool getBitFlag(uint bit);
	void setBitFlag(uint bit, bool value);

	void expire_vga_timers();

	bool isSpriteLoaded(uint16 id, uint16 fileId);

	void video_copy_if_flag_0x8_c(WindowBlock *window);
	void delete_hitarea_by_index(uint index);

	void removeArrows(WindowBlock *window, uint num);
	void windowPutChar(uint a);

	void restoreWindow(WindowBlock *window);
	void colorWindow(WindowBlock *window);

	void restoreBlock(uint b, uint r, uint y, uint x);

	byte *getFrontBuf();
	byte *getBackBuf();
	byte *getScaleBuf();

	byte *read_vga_from_datfile_2(uint id, uint type);

	void resfile_read(void *dst, uint32 offs, uint32 size);

	int init(GameDetector &detector);
	int go();
	void openGameFile();

	void timer_callback();
	void timer_proc1();

	void timer_vga_sprites();
	void timer_vga_sprites_2();

	void dx_clear_surfaces(uint num_lines);
	void dx_update_screen_and_palette();

	void dump_video_script(const byte *src, bool one_opcode_only);
	void dump_vga_file(const byte *vga);
	void dump_vga_script(const byte *ptr, uint res, uint sprite_id);
	void dump_vga_script_always(const byte *ptr, uint res, uint sprite_id);
	void dump_vga_bitmaps(const byte *vga, byte *vga1, int res);
	void dump_single_bitmap(int file, int image, const byte *offs, int w, int h, byte base);
	void dump_bitmap(const char *filename, const byte *offs, int w, int h, int flags, const byte *palette, byte base);

	void dx_clear_attached_from_top(uint lines);
	void dx_copy_from_attached_to_2(uint x, uint y, uint w, uint h);
	void dx_copy_from_attached_to_3(uint lines);
	void dx_copy_from_2_to_attached(uint x, uint y, uint w, uint h);

	void print_char_helper_1(const byte *src, uint len);
	void print_char_helper_5(WindowBlock *window);

	void quickLoadOrSave();
	void shutdown();

	byte *vc10_uncompressFlip(const byte *src, uint w, uint h);
	byte *vc10_flip(const byte *src, uint w, uint h);

	Item *getNextItemPtrStrange();

	bool saveGame(uint slot, char *caption);
	bool loadGame(uint slot);

	void showmessage_helper_2();
	void print_char_helper_6(uint i);

	void video_putchar_newline(WindowBlock *window);
	void video_putchar_drawchar(WindowBlock *window, uint x, uint y, byte chr);

	void loadMusic(uint music);
	void checkTimerCallback();
	void delay(uint delay);
	void pause();

	void o_waitForMark(uint i);
	void scrollEvent();

	void decodeStripA(byte *dst, const byte *src, int height);
	void scroll_timeout();
	void hitarea_stuff_helper_2();
	void fastFadeIn();
	void slowFadeIn();

	void vc_kill_sprite(uint file, uint sprite);

	void set_dummy_cursor();

	void set_volume(int volume);

	void saveOrLoadDialog(bool load);
	void o_unk_132_helper_3();
	int o_unk_132_helper(bool *b, char *buf);
	void o_clearCharacter(WindowBlock *window, int x, byte b = 0);
	void saveGameDialog(char *buf);
	void o_fileError(WindowBlock *window, bool save_error);

	int countSaveGames();
	int displaySaveGameList(int curpos, bool load, char *dst);

	void show_it(void *buf);

	char *gen_savename(int slot);
};

} // End of namespace Simon

#endif