aboutsummaryrefslogtreecommitdiff
path: root/SrcShared/EmPalmStructs.h
blob: b066be46e392b377f36fa7cb605fdfc42367fd7d (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
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
/* -*- mode: C++; tab-width: 4 -*- */
/* ===================================================================== *\
	Copyright (c) 2000-2001 Palm, Inc. or its subsidiaries.
	All rights reserved.

	This file is part of the Palm OS Emulator.

	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.
\* ===================================================================== */

#ifndef EmPalmStructs_h
#define EmPalmStructs_h

#include "EmMemory.h"			// EmMemGet8, EmMemPut8, EmMem_memcpy, etc.
#include "EmPalmStructs.i"
#include "HostControl.h"		// HostControlSelectorType, etc.

#include <stddef.h>				// ptrdiff_t

/*
	The Palm OS Emulator interacts closely with legacy Palm OS data
	structures.  These data structures are laid out by the compilers
	designed for the Palm OS.  However, the Palm OS Emulator -- which needs
	to access these structures at times -- is NOT necessarily compiled with
	a compiler that lays out the structures in a compatible fashion.  Thus,
	if the emulator needs to muck with, say, a variable of EventType, it
	can't merely create one and have at it.  Nor can it get a pointer to
	one, cast it to an EventType*, and have at it.  There's just no guarantee
	that the compiler used to build Poser will put the fields in the same
	places that the Palm OS expects it, or that the architecture will
	support accessing fields in those places.

	To solve this problem, for each Palm OS struct Poser wants to
	manipulate, it creates two parallel "Rep" classes: an "Alias" class and
	a "Proxy" class.  These Rep classes appear and act as much as the
	original struct as possible.  However, behind the scenes C++ magic
	allows Poser to access the data in a manner that is guaranteed to be
	binary-compatible with the Palm OS structs, regardless of what platform
	it's running on and what compiler it was built with.

	Aliases and Proxies are very similar to each other in the way the user
	interacts with them.  The have fields which, when used as an lvalue,
	will store the proferred data in the correct memory location and with
	the correct endianness and, when used as an rvalue, will produce the
	necessary value, fetching the data from the correct memory location and
	byteswapping it if necessary.

	Aliases and Proxies differ in their backing store.  An Alias class is
	initialized with a pointer to some buffer that already exists.  This
	buffer may exist as a Poser variable or as a buffer in the emulated Palm
	OS space.  All data accesses are made against that provided buffer. 
	When an Alias is created from another Alias, they both end up pointing
	to the same space.  If one Alias is used to modify the buffer, the
	second Alias will also reflect that change.

	Proxies, on the other hand, are more stand-alone.  They provide their
	own buffers as a backing store.  Copying one Proxy to another or
	creating one Proxy from another results in a new independent object. 
	After the copy has been made, modifying one object does not affect the
	second.

	Aliases are not only handy for wrapping a chunk of data that was
	generated elsewhere, but they are also essential for providing an "array
	operator" (that is, "operator[]") for both kinds of Rep classes.  That
	operator returns an Alias that points to the right location in memory. 
	If we didn't have Aliases -- for instance, we only had Proxies -- then
	the Proxy returned by operator[] could not be used to modify the backing
	store, since it's independent of the backing store used by the object
	that created it.

	Proxies, on the other hand, are handy when you need to treat an object
	more like a real-live struct.  Proxies can be copied and put into
	STL-like collections without having to worry about the lifetime of the
	object they were created from.

	Let's look at the Alias class for EventType:

		template <class A>
		class EmAliasEventType
		{
			public:
				typedef typename A::ptr_type ptr_type;

				EmAliasEventType (ptr_type);
				EmAliasEventType (const EmAliasEventType&);

				ptr_type GetPtr (void) const;
				static size_t GetSize (void);
				
				EmAliasEventType<A>& operator= (const EmAliasEventType<A>&);
				EmAliasEventType<A> operator[] (int);

			private:
				EmAliasEventType (void);

				EmAliasEventType<A>& operator= (const bool);
				EmAliasEventType<A>& operator= (const char);
				EmAliasEventType<A>& operator= (const unsigned char);
				EmAliasEventType<A>& operator= (const unsigned short);
				EmAliasEventType<A>& operator= (const unsigned int);
				EmAliasEventType<A>& operator= (const unsigned long);
				EmAliasEventType<A>& operator= (const signed char);
				EmAliasEventType<A>& operator= (const signed short);
				EmAliasEventType<A>& operator= (const signed int);
				EmAliasEventType<A>& operator= (const signed long);
				EmAliasEventType<A>& operator= (const void*);
				
				ptr_type fPtr;

			public:
				EmAliasInt16<A> eType;
				EmAliasBoolean<A> penDown;
				EmAliasUInt8<A> tapCount;
				EmAliasInt16<A> screenX;
				EmAliasInt16<A> screenY;
				EmAliasEventTypeData<A> data;
		};

	This is a template class parameterized with a data accessor.  This data
	accessor has static methods for reading and writing 1-, 2-, and 4-byte
	values.  In this module, we define two such accessors.  One, called LAS
	for Local Address Space, accesses Big Endian values in Poser's address
	space.  The second, called PAS for Palm Address Space, accesses Big
	Endian values in the emulated address space.

	There are two constructors.  The first constructor takes a pointer to an
	appropriately-sized buffer that already exists -- all reads and write
	take place against that buffer.  The second constructor is the copy
	constructor.  It copies the pointer used by the original object.  After
	the copy, if the original object modifies the data in the backing store,
	the copy with reflect that change, too.

	GetPtr returns the pointer to the buffer backing the struct.  The return
	type of this function is based on the class the proxy class is
	instantiated with.  It is void* if used with LAS, and emuptr if used
	with PAS.

	GetSize returns the size of the represented struct, in this case
	EventType, which is 24 bytes long.

	An assignment operator is provided to perform a memberwise copy
	operation.

	An array operator is provided to return Alias objects that point to the
	appropriately index location in memory.

	Following these standard methods are the fields.  These fields are also
	Alias classes, initialized with the base pointer passed into the
	EmAliasEventType constructor plus an appropriate offset.

	Now let's take a look at a Proxy class:

		class EmProxyEventType
		{
			public:
				typedef void ptr_type;

				EmProxyEventType (void);
				EmProxyEventType (const EmProxyEventType&);

				ptr_type GetPtr (void) const;
				static size_t GetSize (void);

				EmProxyEventType& operator= (const EmProxyEventType&);
				EmAliasEventType<LAS> operator[] (int);

			private:
				EmProxyEventType& operator= (const bool);
				EmProxyEventType& operator= (const char);
				EmProxyEventType& operator= (const unsigned char);
				EmProxyEventType& operator= (const unsigned short);
				EmProxyEventType& operator= (const unsigned int);
				EmProxyEventType& operator= (const unsigned long);
				EmProxyEventType& operator= (const signed char);
				EmProxyEventType& operator= (const signed short);
				EmProxyEventType& operator= (const signed int);
				EmProxyEventType& operator= (const signed long);
				EmProxyEventType<& operator= (const void*);
				
				char fLocalData[24];

			public:
				EmAliasInt16<LAS> eType;
				EmAliasBoolean<LAS> penDown;
				EmAliasUInt8<LAS> tapCount;
				EmAliasInt16<LAS> screenX;
				EmAliasInt16<LAS> screenY;
				EmAliasEventTypeData<LAS> data;
		};

	As you can see, this Proxy class is almost the same as an Alias class.
	However:

	*	Instead of having an fPtr field to hold the pointer to the data
		buffer, it has an fLocalData field that holds the data itself.

	*	There is no constructor that accepts a pointer.  Instead, there
		is a public default constructor.

	*	It is not a template class.  Since the data is local, it is
		always accessed in a manner consistant with the LAS accessor.

	*	The copy constructor copies the data instead of the pointer.

	There are two sorts of Rep classes: primitive and aggregate.  Primitive
	Rep classes are responsible for the management of simple scalar types. 
	Aggregate Rep classes represent structs, and are composed of other
	primitive and aggregate Alias classes.  The biggest difference between
	primitive and aggregate Rep classes is the set of assignment operators
	clients are allowed to call.  For instance, you can assign integers to
	primitive Rep classes, but not to aggregate Rep classes

	EXAMPLE:

		Say you wanted to call void EvtAddEventToQueue (EventType*).
		You would use EmEventType as follows:

		EmProxyEventType	event;	// Use local buffer

		event.eType		= penDownEvent;
		event.penDown	= true;
		event.screenX	= 100;
		event.screenY	= 100;

		EvtAddEventToQueue((EventType*) event.GetPtr ());

	EFFICIENCY:

		There is some overhead using these classes instead of using structs
		directly.  At the very least, there's an additional level of
		redirection, as the fields accessed contain pointers to the actual
		data as opposed to the actual data itself.  Additionally, on Little
		Endian systems, there is the cost of byteswapping on every access. 
		Finally, there is the cost of calling and executing the proxy class
		constructor.

		In EmPalmStructs.cpp, there are two functions: Test1 and Test2.  The
		first accesses the struct SysPktRPC2Type using the proxy class, the
		second using the struct directly.

		On the Mac, using CW Pro 5.2 with optimizations on, Test1 is 88
		bytes, calls an out-of-line constructor, and each field access takes
		one additional level of indirection.  Test2 is 64 bytes.  The 24-byte
		difference is taken up by an additional 4 bytes for each of the
		assignments, and an additional 12 bytes to call the proxy class's
		constructor.

	LIMITATIONS:

	*	Can't take the adress of an EmFoo.  Will get *its* address
		instead of what you want (the address of the storage).  Instead,
		call GetPtr.

	*	Need explicit casts to extract the value in cases where the
		type is ambigous.  Classic case is "printf("%d", my_EmInt)".  The
		object will be pushed onto the stack, not the wrapped integer.

	*	Can't take the size of the object.  Instead, call GetSize.

	*	Can't call offsetof to get field offsets.  Instead, call
		offsetof_<fieldName>.  Note that this returns the offset of the most
		immediate struct.  That is, struct1.struct2.offsetof_field()
		returns the offset from the beginning of struct2 to field.
		Calling offsetof(StructType1, struct2.field) returns the offset
		from the beginning of struct1 to the field.

	*	Need a way to copy between classes instantiated with different
		address space objects.
*/

int		BadGetter (void);
void	BadSetter (void);

#if PLATFORM_MAC

#define PUT_BE_LONG(p, v)	*(uint32*) p = (v)
#define PUT_BE_SHORT(p, v)	*(uint16*) p = (v)
#define PUT_BE_BYTE(p, v)	*(uint8*) p = (v)

#define GET_BE_LONG(p)		(*(uint32*) p)
#define GET_BE_SHORT(p)		(*(uint16*) p)
#define GET_BE_BYTE(p)		(*(uint8*) p)

#else

#define PUT_BE_LONG(p, v)	 do { \
		((unsigned char*)(p))[0] = (unsigned char)(((unsigned long)(v)) >> 24);	\
		((unsigned char*)(p))[1] = (unsigned char)(((unsigned long)(v)) >> 16);	\
		((unsigned char*)(p))[2] = (unsigned char)(((unsigned long)(v)) >>  8);	\
		((unsigned char*)(p))[3] = (unsigned char)(((unsigned long)(v)) >>  0);	\
		} while(0)

#define PUT_BE_SHORT(p, v)	 do { \
		((unsigned char*)(p))[0] = (unsigned char)(((unsigned short)(v)) >> 8);	\
		((unsigned char*)(p))[1] = (unsigned char)(((unsigned short)(v)) >> 0);	\
		} while(0)

#define PUT_BE_BYTE(p, v)	 do { \
		((unsigned char*)(p))[0] = (unsigned char)(v);	\
		} while(0)

#define GET_BE_LONG(p)	(unsigned long)(\
		(((unsigned long)((unsigned char*)(p))[0]) << 24) |	\
		(((unsigned long)((unsigned char*)(p))[1]) << 16) |	\
		(((unsigned long)((unsigned char*)(p))[2]) <<  8) |	\
		(((unsigned long)((unsigned char*)(p))[3]) <<  0)	\
		)

#define GET_BE_SHORT(p)	(unsigned short)(\
		(((unsigned short)((unsigned char*)(p))[0]) <<  8) |	\
		(((unsigned short)((unsigned char*)(p))[1]) <<  0)	\
		)

#define GET_BE_BYTE(p)	(unsigned char)(\
		(((unsigned char)((unsigned char*)(p))[0]) <<  0)	\
		)

#endif


// Provide methods for getting and setting Big Endian data in Local Address Space

class LAS
{
	public:
		typedef void* ptr_type;

		inline static uint8		GetByte (ptr_type p)					{ return (uint8) GET_BE_BYTE (p); }
		inline static uint16	GetWord (ptr_type p)					{ return (uint16) GET_BE_SHORT (p); }
		inline static uint32	GetLong (ptr_type p)					{ return (uint32) GET_BE_LONG (p); }
		inline static void		PutByte (ptr_type p, const uint8 v)		{ PUT_BE_BYTE (p, v); }
		inline static void		PutWord (ptr_type p, const uint16 v)	{ PUT_BE_SHORT (p, v); }
		inline static void		PutLong (ptr_type p, const uint32 v)	{ PUT_BE_LONG (p, v); }

		inline static void		BlockCopy (ptr_type d, ptr_type s, size_t len)
																		{ memcpy (d, s, len); }

		inline static ptr_type	add (ptr_type p, ptrdiff_t diff)
																		{ return (ptr_type)(((size_t)p) + diff); }
		inline static ptrdiff_t	diff (ptr_type a, ptr_type b)
																		{ return (ptrdiff_t)(((ptrdiff_t)a) - (ptrdiff_t)b); }
};


// Provide methods for getting and setting Big Endian data in Palm Addres Space

class PAS
{
	public:
		typedef emuptr ptr_type;

		inline static uint8		GetByte (ptr_type p)					{ return (uint8) EmMemGet8 (p); }
		inline static uint16	GetWord (ptr_type p)					{ return (uint16) EmMemGet16 (p); }
		inline static uint32	GetLong (ptr_type p)					{ return (uint32) EmMemGet32 (p); }
		inline static void		PutByte (ptr_type p, const uint8 v)		{ EmMemPut8 (p, v); }
		inline static void		PutWord (ptr_type p, const uint16 v)	{ EmMemPut16 (p, v); }
		inline static void		PutLong (ptr_type p, const uint32 v)	{ EmMemPut32 (p, v); }

		inline static void		BlockCopy (ptr_type d, ptr_type s, size_t len)
																		{ EmMem_memcpy (d, s, len); }

		inline static ptr_type	add (ptr_type p, ptrdiff_t diff)
																		{ return (ptr_type)(((size_t)p) + diff); }
		inline static ptrdiff_t diff (ptr_type a, ptr_type b)
																		{ return (ptrdiff_t)(((ptrdiff_t)a) - (ptrdiff_t)b); }
};


// ======================================================================
// Macro for creating the class that wraps up simple types.
// ======================================================================

#define DECLARE_SCALAR_ALIAS(type, asType)											\
																					\
	template <class A>																\
	class EmAlias##type																\
	{																				\
		public:																		\
			typedef typename A::ptr_type ptr_type;									\
																					\
								EmAlias##type (ptr_type);							\
								EmAlias##type (const EmAlias##type<A>&);			\
																					\
			ptr_type			GetPtr	(void) const	{ return fPtr; }			\
			static size_t		GetSize (void)			{ return sizeof (asType); }	\
																					\
			EmAlias##type<A>&	operator= (const bool);								\
			EmAlias##type<A>&	operator= (const char);								\
																					\
			EmAlias##type<A>&	operator= (const unsigned char);					\
			EmAlias##type<A>&	operator= (const unsigned short);					\
			EmAlias##type<A>&	operator= (const unsigned int);						\
			EmAlias##type<A>&	operator= (const unsigned long);					\
																					\
			EmAlias##type<A>&	operator= (const signed char);						\
			EmAlias##type<A>&	operator= (const signed short);						\
			EmAlias##type<A>&	operator= (const signed int);						\
			EmAlias##type<A>&	operator= (const signed long);						\
																					\
			EmAlias##type<A>&	operator= (const void*);							\
			EmAlias##type<A>&	operator= (const EmAlias##type<A>&);				\
																					\
								operator type (void) const;							\
																					\
			EmAlias##type<A>	operator[] (int);									\
			const EmAlias##type<A>	operator[] (int) const;							\
																					\
		private:																	\
								EmAlias##type (void);								\
																					\
			ptr_type			fPtr;												\
	};

#define DECLARE_SCALAR_PROXY(type, asType)											\
																					\
	class EmProxy##type																\
	{																				\
		public:																		\
			typedef void* ptr_type;													\
																					\
								EmProxy##type (void);								\
								EmProxy##type (const EmProxy##type&);				\
																					\
			ptr_type			GetPtr	(void) const	{ return (ptr_type) &fLocalData; }	\
			static size_t		GetSize (void)			{ return sizeof (asType); }	\
																					\
			EmProxy##type&		operator= (const bool);								\
			EmProxy##type&		operator= (const char);								\
																					\
			EmProxy##type&		operator= (const unsigned char);					\
			EmProxy##type&		operator= (const unsigned short);					\
			EmProxy##type&		operator= (const unsigned int);						\
			EmProxy##type&		operator= (const unsigned long);					\
																					\
			EmProxy##type&		operator= (const signed char);						\
			EmProxy##type&		operator= (const signed short);						\
			EmProxy##type&		operator= (const signed int);						\
			EmProxy##type&		operator= (const signed long);						\
																					\
			EmProxy##type&		operator= (const void*);							\
			EmProxy##type&		operator= (const EmProxy##type&);					\
																					\
								operator type (void) const;							\
																					\
			EmAlias##type<LAS>	operator[] (int);									\
			const EmAlias##type<LAS>	operator[] (int) const;						\
																					\
		private:																	\
			struct {																\
				char			_bytes[sizeof (asType)];							\
			} fLocalData;															\
	};

#define DECLARE_SCALAR_CLASSES(type, asType)										\
	DECLARE_SCALAR_ALIAS(type, asType)												\
	DECLARE_SCALAR_PROXY(type, asType)

#define DEFINE_SCALAR_ALIAS(type, asType)											\
																					\
	template <class A>																\
	INLINE_ EmAlias##type<A>::EmAlias##type (void) :								\
		fPtr ((ptr_type) NULL)														\
	{																				\
	}																				\
																					\
	template <class A>																\
	INLINE_ EmAlias##type<A>::EmAlias##type (ptr_type p) :							\
		fPtr (p)																	\
	{																				\
	}																				\
																					\
	template <class A>																\
	INLINE_ EmAlias##type<A>::EmAlias##type (const EmAlias##type<A>& that) :		\
		fPtr (that.GetPtr ())														\
	{																				\
	}																				\
																					\
	MAKE_ONE_SCALAR_ALIAS_ASSIGNMENT_OPERATOR(type, asType, bool)					\
	MAKE_ONE_SCALAR_ALIAS_ASSIGNMENT_OPERATOR(type, asType, char)					\
	MAKE_ONE_SCALAR_ALIAS_ASSIGNMENT_OPERATOR(type, asType, signed char)			\
	MAKE_ONE_SCALAR_ALIAS_ASSIGNMENT_OPERATOR(type, asType, signed short)			\
	MAKE_ONE_SCALAR_ALIAS_ASSIGNMENT_OPERATOR(type, asType, signed int)				\
	MAKE_ONE_SCALAR_ALIAS_ASSIGNMENT_OPERATOR(type, asType, signed long)			\
	MAKE_ONE_SCALAR_ALIAS_ASSIGNMENT_OPERATOR(type, asType, unsigned char)			\
	MAKE_ONE_SCALAR_ALIAS_ASSIGNMENT_OPERATOR(type, asType, unsigned short)			\
	MAKE_ONE_SCALAR_ALIAS_ASSIGNMENT_OPERATOR(type, asType, unsigned int)			\
	MAKE_ONE_SCALAR_ALIAS_ASSIGNMENT_OPERATOR(type, asType, unsigned long)			\
	MAKE_ONE_SCALAR_ALIAS_ASSIGNMENT_OPERATOR(type, asType, const void*)			\
	MAKE_ONE_SCALAR_ALIAS_ASSIGNMENT_OPERATOR(type, asType, const EmAlias##type<A>&)\
																					\
	template <class A>																\
	INLINE_ EmAlias##type<A>::operator type (void) const							\
	{																				\
		if (sizeof (asType) == 1)													\
			return (type) A::GetByte((ptr_type) fPtr);								\
																					\
		if (sizeof (asType) == 2)													\
			return (type) A::GetWord((ptr_type) fPtr);								\
																					\
		if (sizeof (asType) == 4)													\
			return (type) A::GetLong((ptr_type) fPtr);								\
																					\
		return (type) BadGetter ();													\
	}																				\
																					\
	template <class A>																\
	INLINE_ EmAlias##type<A> EmAlias##type<A>::operator [] (int index)				\
	{																				\
		return EmAlias##type<A> ((ptr_type) (((char*) this->GetPtr ()) + index * this->GetSize ()));	\
	}																				\
																					\
	template <class A>																\
	INLINE_ const EmAlias##type<A> EmAlias##type<A>::operator [] (int index) const	\
	{																				\
		return EmAlias##type<A> ((ptr_type) (((char*) this->GetPtr ()) + index * this->GetSize ()));	\
	}

#define DEFINE_SCALAR_PROXY(type, asType)											\
																					\
	INLINE_ EmProxy##type::EmProxy##type (void)										\
	{																				\
	}																				\
																					\
	INLINE_ EmProxy##type::EmProxy##type (const EmProxy##type& that)				\
	{																				\
		*this = (asType) (type) that;												\
	}																				\
																					\
	MAKE_ONE_SCALAR_PROXY_ASSIGNMENT_OPERATOR(type, asType, bool)					\
	MAKE_ONE_SCALAR_PROXY_ASSIGNMENT_OPERATOR(type, asType, char)					\
	MAKE_ONE_SCALAR_PROXY_ASSIGNMENT_OPERATOR(type, asType, signed char)			\
	MAKE_ONE_SCALAR_PROXY_ASSIGNMENT_OPERATOR(type, asType, signed short)			\
	MAKE_ONE_SCALAR_PROXY_ASSIGNMENT_OPERATOR(type, asType, signed int)				\
	MAKE_ONE_SCALAR_PROXY_ASSIGNMENT_OPERATOR(type, asType, signed long)			\
	MAKE_ONE_SCALAR_PROXY_ASSIGNMENT_OPERATOR(type, asType, unsigned char)			\
	MAKE_ONE_SCALAR_PROXY_ASSIGNMENT_OPERATOR(type, asType, unsigned short)			\
	MAKE_ONE_SCALAR_PROXY_ASSIGNMENT_OPERATOR(type, asType, unsigned int)			\
	MAKE_ONE_SCALAR_PROXY_ASSIGNMENT_OPERATOR(type, asType, unsigned long)			\
	MAKE_ONE_SCALAR_PROXY_ASSIGNMENT_OPERATOR(type, asType, const void*)			\
	MAKE_ONE_SCALAR_PROXY_ASSIGNMENT_OPERATOR(type, asType, const EmProxy##type&)	\
																					\
	INLINE_ EmProxy##type::operator type (void) const								\
	{																				\
		if (sizeof (asType) == 1)													\
			return (type) LAS::GetByte((ptr_type) &fLocalData);						\
																					\
		if (sizeof (asType) == 2)													\
			return (type) LAS::GetWord((ptr_type) &fLocalData);						\
																					\
		if (sizeof (asType) == 4)													\
			return (type) LAS::GetLong((ptr_type) &fLocalData);						\
																					\
		return (type) BadGetter ();													\
	}																				\
																					\
	INLINE_ EmAlias##type<LAS> EmProxy##type::operator [] (int index)				\
	{																				\
		return EmAlias##type<LAS> ((ptr_type) (((char*) this->GetPtr ()) + index * this->GetSize ()));	\
	}																				\
																					\
	INLINE_ const EmAlias##type<LAS> EmProxy##type::operator [] (int index) const	\
	{																				\
		return EmAlias##type<LAS> ((ptr_type) (((char*) this->GetPtr ()) + index * this->GetSize ()));	\
	}

#define DEFINE_SCALAR_CLASSES(type, asType)											\
	DEFINE_SCALAR_ALIAS(type, asType)												\
	DEFINE_SCALAR_PROXY(type, asType)

// Macro that creates the implementation for an assignment operator for simple types.

#define MAKE_ONE_SCALAR_ALIAS_ASSIGNMENT_OPERATOR(type, asType, rhs_type)			\
																					\
	template <class A>																\
	INLINE_ EmAlias##type<A>& EmAlias##type<A>::operator= (rhs_type val)			\
	{																				\
		if (sizeof (asType) == 1)		A::PutByte (this->GetPtr (), (unsigned char) (asType) val);		\
		else if (sizeof (asType) == 2)	A::PutWord (this->GetPtr (), (unsigned short) (asType) val);	\
		else if (sizeof (asType) == 4)	A::PutLong (this->GetPtr (), (unsigned long) (asType) val);		\
		else BadSetter ();															\
																					\
		return *this;																\
	}

#define MAKE_ONE_SCALAR_PROXY_ASSIGNMENT_OPERATOR(type, asType, rhs_type)			\
																					\
	INLINE_ EmProxy##type& EmProxy##type::operator= (rhs_type val)					\
	{																				\
		if (sizeof (asType) == 1)		LAS::PutByte (this->GetPtr (), (unsigned char) (asType) val);	\
		else if (sizeof (asType) == 2)	LAS::PutWord (this->GetPtr (), (unsigned short) (asType) val);	\
		else if (sizeof (asType) == 4)	LAS::PutLong (this->GetPtr (), (unsigned long) (asType) val);	\
		else BadSetter ();															\
																					\
		return *this;																\
	}


// ======================================================================
// Macro for creating the class that wraps up aggregate types.
// ======================================================================

#define DECLARE_STRUCT_ALIAS(type, size, FOR_EACH_FIELD)							\
																					\
	template <class A>																\
	class EmAlias##type																\
	{																				\
		public:																		\
			typedef typename A::ptr_type ptr_type;									\
																					\
								EmAlias##type	(ptr_type);							\
								EmAlias##type	(const EmAlias##type&);				\
																					\
			ptr_type			GetPtr	(void) const	{ return fPtr; }			\
			static size_t		GetSize	(void)			{ return size; }			\
																					\
			EmAlias##type<A>&	operator= (const EmAlias##type<A>&);				\
																					\
			EmAlias##type<A>	operator[] (int);									\
			const EmAlias##type<A>	operator[] (int) const;							\
																					\
		private:																	\
								EmAlias##type	(void);								\
																					\
			ptr_type			fPtr;												\
																					\
		public:																		\
			FOR_EACH_FIELD(DECLARE_FIELD_ALIAS)										\
			FOR_EACH_FIELD(DECLARE_FIELD_OFFSET)									\
	};

#define DECLARE_STRUCT_PROXY(type, size, FOR_EACH_FIELD)							\
																					\
	class EmProxy##type																\
	{																				\
		public:																		\
			typedef void* ptr_type;													\
																					\
								EmProxy##type	(void);								\
								EmProxy##type	(const EmProxy##type&);				\
																					\
			ptr_type			GetPtr	(void) const	{ return (ptr_type) &fLocalData; }	\
			static size_t		GetSize	(void)			{ return size; }			\
																					\
			EmProxy##type&		operator= (const EmProxy##type&);					\
																					\
			EmAlias##type<LAS>	operator[] (int);									\
			const EmAlias##type<LAS>	operator[] (int) const;						\
																					\
		private:																	\
			struct {																\
				char			_bytes[size];										\
			} fLocalData;															\
																					\
		public:																		\
			FOR_EACH_FIELD(DECLARE_FIELD_PROXY)										\
			FOR_EACH_FIELD(DECLARE_FIELD_OFFSET)									\
	};

#define DECLARE_STRUCT_CLASSES(type, size, FOR_EACH_FIELD)							\
	DECLARE_STRUCT_ALIAS(type, size, FOR_EACH_FIELD)								\
	DECLARE_STRUCT_PROXY(type, size, FOR_EACH_FIELD)

#define DEFINE_STRUCT_ALIAS(type, size, FOR_EACH_FIELD)								\
																					\
	template <class A>																\
	INLINE_ EmAlias##type<A>::EmAlias##type (void) :								\
		fPtr ((ptr_type) NULL)														\
		FOR_EACH_FIELD(MAKE_MEMBER_INITIALIZER_ALIAS)								\
	{																				\
	}																				\
																					\
	template <class A>																\
	INLINE_ EmAlias##type<A>::EmAlias##type (ptr_type p) :							\
		fPtr (p)																	\
		FOR_EACH_FIELD(MAKE_MEMBER_INITIALIZER_ALIAS)								\
	{																				\
	}																				\
																					\
	template <class A>																\
	INLINE_ EmAlias##type<A>::EmAlias##type (const EmAlias##type<A>& that) :		\
		fPtr (that.fPtr)															\
		FOR_EACH_FIELD(MAKE_MEMBER_INITIALIZER_ALIAS)								\
	{																				\
	}																				\
																					\
	template <class A>																\
	INLINE_ EmAlias##type<A>& EmAlias##type<A>::operator= (const EmAlias##type<A>& val)	\
	{																				\
		if (this != &val)															\
		{																			\
			A::BlockCopy (this->GetPtr (), val.GetPtr (), this->GetSize ());		\
		}																			\
																					\
		return *this;																\
	}																				\
																					\
	template <class A>																\
	INLINE_ EmAlias##type<A> EmAlias##type<A>::operator [] (int index)				\
	{																				\
		return EmAlias##type<A> ((ptr_type) (((char*) this->GetPtr ()) + index * this->GetSize ()));	\
	}																				\
																					\
	template <class A>																\
	INLINE_ const EmAlias##type<A> EmAlias##type<A>::operator [] (int index) const	\
	{																				\
		return EmAlias##type<A> ((ptr_type) (((char*) this->GetPtr ()) + index * this->GetSize ()));	\
	}

#define DEFINE_STRUCT_PROXY(type, size, FOR_EACH_FIELD)								\
																					\
	INLINE_ EmProxy##type::EmProxy##type (void) :									\
		fLocalData ()																\
		FOR_EACH_FIELD(MAKE_MEMBER_INITIALIZER_PROXY)								\
	{																				\
	}																				\
																					\
	INLINE_ EmProxy##type::EmProxy##type (const EmProxy##type& that) :				\
		fLocalData ()																\
		FOR_EACH_FIELD(MAKE_MEMBER_INITIALIZER_PROXY)								\
	{																				\
		*this = that;																\
	}																				\
																					\
	INLINE_ EmProxy##type& EmProxy##type::operator= (const EmProxy##type& val)		\
	{																				\
		if (this != &val)															\
		{																			\
			LAS::BlockCopy (this->GetPtr (), val.GetPtr (), this->GetSize ());		\
		}																			\
																					\
		return *this;																\
	}																				\
																					\
	INLINE_ EmAlias##type<LAS> EmProxy##type::operator [] (int index)				\
	{																				\
		return EmAlias##type<LAS> ((ptr_type) (((char*) this->GetPtr ()) + index * this->GetSize ()));	\
	}																				\
																					\
	INLINE_ const EmAlias##type<LAS> EmProxy##type::operator [] (int index) const	\
	{																				\
		return EmAlias##type<LAS> ((ptr_type) (((char*) this->GetPtr ()) + index * this->GetSize ()));	\
	}

#define DEFINE_STRUCT_CLASSES(type, size, FOR_EACH_FIELD)							\
	DEFINE_STRUCT_ALIAS(type, size, FOR_EACH_FIELD)									\
	DEFINE_STRUCT_PROXY(type, size, FOR_EACH_FIELD)

// Macro for creating the data member that acts as a proxy for the data
// we're wrapping up.

#define DECLARE_FIELD_ALIAS(field_offset, field_type, field_name)					\
																					\
	EmAlias##field_type<A>	field_name;


#define DECLARE_FIELD_PROXY(field_offset, field_type, field_name)					\
																					\
	EmAlias##field_type<LAS>	field_name;


#define DECLARE_FIELD_OFFSET(field_offset, field_type, field_name)					\
																					\
	static size_t	offsetof_##field_name (void) { return field_offset; }


// Macros for creating the data member initializers in the constructors

#define MAKE_MEMBER_INITIALIZER_ALIAS(field_offset, field_type, field_name)			\
																					\
	, field_name((ptr_type) (((char*) fPtr) + field_offset))


#define MAKE_MEMBER_INITIALIZER_PROXY(field_offset, field_type, field_name)			\
																					\
	, field_name((ptr_type) (((char*) this->GetPtr ()) + field_offset))




typedef uint8	UIOptionsType;
typedef uint8	ScrOperation;

#define FOR_EACH_SCALAR_1(DO_TO_SCALAR)				\
	DO_TO_SCALAR (char, char)						\
	DO_TO_SCALAR (Int8, Int8)						\
	DO_TO_SCALAR (UInt8, UInt8)						\
	DO_TO_SCALAR (Int16, Int16)						\
	DO_TO_SCALAR (UInt16, UInt16)					\
	DO_TO_SCALAR (Int32, Int32)						\
	DO_TO_SCALAR (UInt32, UInt32)					\


#define FOR_EACH_SCALAR_2(DO_TO_SCALAR)				\
	DO_TO_SCALAR (Boolean, uint8)					\
	DO_TO_SCALAR (Char, uint8)						\
	DO_TO_SCALAR (ControlStyleType, uint8)			\
	DO_TO_SCALAR (Coord, uint16)					\
	DO_TO_SCALAR (DmResID, uint16)					\
	DO_TO_SCALAR (emuptr, emuptr)					\
	DO_TO_SCALAR (Err, uint16)						\
	DO_TO_SCALAR (FontID, uint8)					\
	DO_TO_SCALAR (FormObjectKind, uint8)			\
	DO_TO_SCALAR (LocalID, uint32)					\


#define FOR_EACH_SCALAR_3(DO_TO_SCALAR)				\
	DO_TO_SCALAR (NetIPAddr, uint32)				\
	DO_TO_SCALAR (PatternType, uint8)				\
	DO_TO_SCALAR (ScrOperation, uint8)				\
	DO_TO_SCALAR (SlkPktHeaderChecksum, uint8)		\
	DO_TO_SCALAR (UnderlineModeType, uint8)			\
	DO_TO_SCALAR (UndoMode, uint8)					\
	DO_TO_SCALAR (UIOptionsType, uint8)				\
	DO_TO_SCALAR (WChar, uint16)					\


#define FOR_EACH_SCALAR_4(DO_TO_SCALAR)				\
	DO_TO_SCALAR (HostControlSelectorType, uint16)	\
	DO_TO_SCALAR (HostBoolType, int32)				\
	DO_TO_SCALAR (HostClockType, int32)				\
	DO_TO_SCALAR (HostErrType, int32)				\
	DO_TO_SCALAR (HostIDType, int32)				\
	DO_TO_SCALAR (HostPlatformType, int32)			\
	DO_TO_SCALAR (HostSignalType, int32)			\
	DO_TO_SCALAR (HostSizeType, int32)				\
	DO_TO_SCALAR (HostTimeType, int32)				\


#define FOR_EACH_STRUCT_1(DO_TO_STRUCT)							\
	FOR_AbsRectType_STRUCT (DO_TO_STRUCT)						\
	FOR_PointType_STRUCT (DO_TO_STRUCT)							\
	FOR_RectangleType_STRUCT (DO_TO_STRUCT)						\
	FOR_RGBColorType_STRUCT (DO_TO_STRUCT)						\


#define FOR_EACH_STRUCT_2(DO_TO_STRUCT)							\
	FOR_BreakpointType_STRUCT (DO_TO_STRUCT)					\
	FOR_M68KRegsType_STRUCT (DO_TO_STRUCT)						\
																\
	FOR_UsbHwrType_STRUCT (DO_TO_STRUCT)						\
	FOR_HwrBatCmdReadType_STRUCT (DO_TO_STRUCT)					\
	FOR_HwrJerryPLDType_STRUCT (DO_TO_STRUCT)					\
	FOR_HwrLAPType_STRUCT (DO_TO_STRUCT)						\
	FOR_HwrMediaQ11xxType_STRUCT (DO_TO_STRUCT)					\
	FOR_HwrPalmI705PLDType_STRUCT (DO_TO_STRUCT)				\
	FOR_HwrSymbolASICType_STRUCT (DO_TO_STRUCT)					\
	FOR_SED1375RegsType_STRUCT (DO_TO_STRUCT)					\
	FOR_SED1376RegsType_STRUCT (DO_TO_STRUCT)					\
																\
	FOR_SysBatteryDataStructV1_STRUCT (DO_TO_STRUCT)			\
	FOR_SysBatteryDataStructV2_STRUCT (DO_TO_STRUCT)			\
	FOR_SysBatteryDataStructV3_STRUCT (DO_TO_STRUCT)			\
																\
	FOR_SysNVParamsType_STRUCT (DO_TO_STRUCT)					\


#define FOR_EACH_STRUCT_3(DO_TO_STRUCT)							\
	FOR_ClipboardItem_STRUCT (DO_TO_STRUCT)						\
	FOR_FieldUndoType_STRUCT (DO_TO_STRUCT)						\
	FOR_GraphicStateTypeV1_STRUCT (DO_TO_STRUCT)				\
	FOR_GraphicStateTypeV2_STRUCT (DO_TO_STRUCT)				\
	FOR_GraphicStateTypeV3_STRUCT (DO_TO_STRUCT)				\
	FOR_UIColorStateType_STRUCT (DO_TO_STRUCT)					\

  
#define FOR_EACH_STRUCT_4(DO_TO_STRUCT)							\
	FOR_UIGlobalsType_STRUCT (DO_TO_STRUCT)						\
	FOR_UIGlobalsTypeCommon_STRUCT (DO_TO_STRUCT)				\
	FOR_UIGlobalsTypeV1_STRUCT (DO_TO_STRUCT)					\
	FOR_UIGlobalsTypeV2_STRUCT (DO_TO_STRUCT)					\
	FOR_UIGlobalsTypeV3_STRUCT (DO_TO_STRUCT)					\
	FOR_UIGlobalsTypeV31_STRUCT (DO_TO_STRUCT)					\
	FOR_UIGlobalsTypeV32_STRUCT (DO_TO_STRUCT)					\
	FOR_UIGlobalsTypeV35_STRUCT (DO_TO_STRUCT)					\


#define FOR_EACH_STRUCT_5(DO_TO_STRUCT)							\
	FOR_M68KExcTableType_STRUCT (DO_TO_STRUCT)					\
	FOR_FixedGlobalsType_STRUCT (DO_TO_STRUCT)					\
	FOR_LowMemHdrType_STRUCT (DO_TO_STRUCT)						\
	FOR_SysAppInfoType_STRUCT (DO_TO_STRUCT)					\
	FOR_SysLibTblEntryType_STRUCT (DO_TO_STRUCT)				\
	FOR_PenBtnInfoType_STRUCT (DO_TO_STRUCT)					\
	FOR_SndCommandType_STRUCT (DO_TO_STRUCT)					\
																\
	FOR_kernel_info_task_STRUCT (DO_TO_STRUCT)					\
	FOR_kernel_info_semaphore_STRUCT (DO_TO_STRUCT)				\
	FOR_kernel_info_timer_STRUCT (DO_TO_STRUCT)					\
	FOR_SysKernelInfoType_STRUCT (DO_TO_STRUCT)					\


#define FOR_EACH_STRUCT_6(DO_TO_STRUCT)							\
	FOR_SlkPktFooterType_STRUCT (DO_TO_STRUCT)					\
	FOR_SlkPktHeaderType_STRUCT (DO_TO_STRUCT)					\
																\
	FOR_SysPktRPCParamType_STRUCT (DO_TO_STRUCT)				\
																\
	FOR_SysPktBodyType_STRUCT (DO_TO_STRUCT)					\
	FOR_SysPktContinueCmdType_STRUCT (DO_TO_STRUCT)				\
	FOR_SysPktDbgBreakToggleCmdType_STRUCT (DO_TO_STRUCT)		\
	FOR_SysPktDbgBreakToggleRspType_STRUCT (DO_TO_STRUCT)		\
	FOR_SysPktFindCmdType_STRUCT (DO_TO_STRUCT)					\
	FOR_SysPktFindRspType_STRUCT (DO_TO_STRUCT)					\
	FOR_SysPktGetBreakpointsCmdType_STRUCT (DO_TO_STRUCT)		\
	FOR_SysPktEmptyRspType_STRUCT (DO_TO_STRUCT)				\
	FOR_SysPktGetBreakpointsRspType_STRUCT (DO_TO_STRUCT)		\


#define FOR_EACH_STRUCT_7(DO_TO_STRUCT)							\
	FOR_SysPktGetTrapBreaksCmdType_STRUCT (DO_TO_STRUCT)		\
	FOR_SysPktGetTrapBreaksRspType_STRUCT (DO_TO_STRUCT)		\
	FOR_SysPktGetTrapConditionsCmdType_STRUCT (DO_TO_STRUCT)	\
	FOR_SysPktGetTrapConditionsRspType_STRUCT (DO_TO_STRUCT)	\
	FOR_SysPktReadMemCmdType_STRUCT (DO_TO_STRUCT)				\
	FOR_SysPktReadMemRspType_STRUCT (DO_TO_STRUCT)				\
	FOR_SysPktReadRegsCmdType_STRUCT (DO_TO_STRUCT)				\
	FOR_SysPktReadRegsRspType_STRUCT (DO_TO_STRUCT)				\
	FOR_SysPktRPC2Type_STRUCT (DO_TO_STRUCT)					\
	FOR_SysPktRPCType_STRUCT (DO_TO_STRUCT)						\
	FOR_SysPktRtnNameCmdType_STRUCT (DO_TO_STRUCT)				\


#define FOR_EACH_STRUCT_8(DO_TO_STRUCT)							\
	FOR_SysPktRtnNameRspType_STRUCT (DO_TO_STRUCT)				\
	FOR_SysPktSetBreakpointsCmdType_STRUCT (DO_TO_STRUCT)		\
	FOR_SysPktSetBreakpointsRspType_STRUCT (DO_TO_STRUCT)		\
	FOR_SysPktSetTrapBreaksCmdType_STRUCT (DO_TO_STRUCT)		\
	FOR_SysPktSetTrapConditionsCmdType_STRUCT (DO_TO_STRUCT)	\
	FOR_SysPktSetTrapConditionsRspType_STRUCT (DO_TO_STRUCT)	\
	FOR_SysPktStateCmdType_STRUCT (DO_TO_STRUCT)				\
	FOR_SysPktStateRspType_STRUCT (DO_TO_STRUCT)				\
	FOR_SysPktWriteMemCmdType_STRUCT (DO_TO_STRUCT)				\
	FOR_SysPktWriteMemRspType_STRUCT (DO_TO_STRUCT)				\
	FOR_SysPktWriteRegsCmdType_STRUCT (DO_TO_STRUCT)			\
	FOR_SysPktWriteRegsRspType_STRUCT (DO_TO_STRUCT)			\


#define FOR_EACH_STRUCT_9(DO_TO_STRUCT)							\
	FOR_RecordEntryType_STRUCT (DO_TO_STRUCT)					\
	FOR_RsrcEntryType_STRUCT (DO_TO_STRUCT)						\
	FOR_RecordListType_STRUCT (DO_TO_STRUCT)					\
	FOR_DatabaseHdrType_STRUCT (DO_TO_STRUCT)					\
	FOR_DatabaseDirEntryType_STRUCT (DO_TO_STRUCT)				\
	FOR_DatabaseDirType_STRUCT (DO_TO_STRUCT)					\
	FOR_DmOpenInfoType_STRUCT(DO_TO_STRUCT)						\
	FOR_DmAccessType_STRUCT(DO_TO_STRUCT)						\
	FOR_DmSearchStateType_STRUCT(DO_TO_STRUCT)					\
																\
	FOR_CardHeaderType_STRUCT(DO_TO_STRUCT)						\
	FOR_CardInfoType_STRUCT(DO_TO_STRUCT)						\
	FOR_StorageHeaderType_STRUCT(DO_TO_STRUCT)					\
																\
	FOR_ExgGoToType_STRUCT (DO_TO_STRUCT)						\
	FOR_ExgSocketType_STRUCT (DO_TO_STRUCT)						\
																\
	FOR_DlkDBCreatorList_STRUCT (DO_TO_STRUCT)					\
	FOR_DlkServerSessionType_STRUCT (DO_TO_STRUCT)				\


#define FOR_EACH_STRUCT_10(DO_TO_STRUCT)						\
	FOR_generic_STRUCT (DO_TO_STRUCT)							\
	FOR_penUp_STRUCT (DO_TO_STRUCT)								\
	FOR_keyDown_STRUCT (DO_TO_STRUCT)							\
	FOR_winEnter_STRUCT (DO_TO_STRUCT)							\
	FOR_winExit_STRUCT (DO_TO_STRUCT)							\
	FOR_tsmConfirm_STRUCT (DO_TO_STRUCT)						\
	FOR_tsmFepButton_STRUCT (DO_TO_STRUCT)						\
	FOR_tsmFepMode_STRUCT (DO_TO_STRUCT)						\
	FOR_ctlEnter_STRUCT (DO_TO_STRUCT)							\
	FOR_ctlSelect_STRUCT (DO_TO_STRUCT)							\
	FOR_ctlRepeat_STRUCT (DO_TO_STRUCT)							\
	FOR_ctlExit_STRUCT (DO_TO_STRUCT)							\
	FOR_fldEnter_STRUCT (DO_TO_STRUCT)							\
	FOR_fldHeightChanged_STRUCT (DO_TO_STRUCT)					\
	FOR_fldChanged_STRUCT (DO_TO_STRUCT)						\
	FOR_fldExit_STRUCT (DO_TO_STRUCT)							\
	FOR_lstEnter_STRUCT (DO_TO_STRUCT)							\
	FOR_lstExit_STRUCT (DO_TO_STRUCT)							\
	FOR_lstSelect_STRUCT (DO_TO_STRUCT)							\
	FOR_tblEnter_STRUCT (DO_TO_STRUCT)							\
	FOR_tblExit_STRUCT (DO_TO_STRUCT)							\
	FOR_tblSelect_STRUCT (DO_TO_STRUCT)							\
	FOR_frmLoad_STRUCT (DO_TO_STRUCT)							\
	FOR_frmOpen_STRUCT (DO_TO_STRUCT)							\
	FOR_frmGoto_STRUCT (DO_TO_STRUCT)							\
	FOR_frmClose_STRUCT (DO_TO_STRUCT)							\
	FOR_frmUpdate_STRUCT (DO_TO_STRUCT)							\
	FOR_frmTitleEnter_STRUCT (DO_TO_STRUCT)						\
	FOR_frmTitleSelect_STRUCT (DO_TO_STRUCT)					\
	FOR_attnIndicatorEnter_STRUCT (DO_TO_STRUCT)				\
	FOR_attnIndicatorSelect_STRUCT (DO_TO_STRUCT)				\
	FOR_daySelect_STRUCT (DO_TO_STRUCT)							\
	FOR_menu_STRUCT (DO_TO_STRUCT)								\
	FOR_popSelect_STRUCT (DO_TO_STRUCT)							\
	FOR_sclEnter_STRUCT (DO_TO_STRUCT)							\
	FOR_sclExit_STRUCT (DO_TO_STRUCT)							\
	FOR_sclRepeat_STRUCT (DO_TO_STRUCT)							\
	FOR_menuCmdBarOpen_STRUCT (DO_TO_STRUCT)					\
	FOR_menuOpen_STRUCT (DO_TO_STRUCT)							\
	FOR_gadgetEnter_STRUCT (DO_TO_STRUCT)						\
	FOR_gadgetMisc_STRUCT (DO_TO_STRUCT)						\
																\
	FOR_EventTypeData_STRUCT (DO_TO_STRUCT)						\
	FOR_EventType_STRUCT (DO_TO_STRUCT)							\


#define FOR_EACH_STRUCT_11(DO_TO_STRUCT)						\
	FOR_ROMDBRecordHeader1Type_STRUCT (DO_TO_STRUCT)			\
	FOR_ROMDBResourceHeader1Type_STRUCT (DO_TO_STRUCT)			\
	FOR_ROMDBHeader1Type_STRUCT (DO_TO_STRUCT)					\
	FOR_ROMCardHeader5Type_STRUCT (DO_TO_STRUCT)				\
	FOR_ROMStoreHeader4Type_STRUCT (DO_TO_STRUCT)				\
	FOR_ROMHeapHeader1Type_STRUCT (DO_TO_STRUCT)				\
	FOR_ROMHeapHeader2Type_STRUCT (DO_TO_STRUCT)				\
	FOR_ROMHeapHeader3Type_STRUCT (DO_TO_STRUCT)				\
	FOR_ROMDBDir1Type_STRUCT (DO_TO_STRUCT)						\
	FOR_ROMHeapChunkHdr2Type_STRUCT (DO_TO_STRUCT)				\
	FOR_ROMHeapChunkHdr1Type_STRUCT (DO_TO_STRUCT)				\
	FOR_ROMFtrFeatureType_STRUCT (DO_TO_STRUCT)					\
	FOR_ROMFtrCreatorType_STRUCT (DO_TO_STRUCT)					\
	FOR_ROMFtrTableType_STRUCT (DO_TO_STRUCT)					\


#define FOR_EACH_STRUCT_12(DO_TO_STRUCT)						\
	FOR_ControlAttrType_STRUCT (DO_TO_STRUCT)					\
	FOR_ControlType_STRUCT (DO_TO_STRUCT)						\
	FOR_GraphicControlType_STRUCT (DO_TO_STRUCT)				\
	FOR_SliderControlType_STRUCT (DO_TO_STRUCT)					\
	FOR_BitmapTypeV2_STRUCT (DO_TO_STRUCT)						\
	FOR_BitmapTypeV3_STRUCT (DO_TO_STRUCT)						\
	FOR_FrameBitsType_STRUCT (DO_TO_STRUCT)						\
	FOR_WindowFlagsType_STRUCT (DO_TO_STRUCT)					\
	FOR_WindowType_STRUCT (DO_TO_STRUCT)						\
	FOR_FormObjListType_STRUCT (DO_TO_STRUCT)					\
	FOR_FormAttrType_STRUCT (DO_TO_STRUCT)						\
	FOR_FormType_STRUCT (DO_TO_STRUCT)							\
																\
	FOR_cjxln_STRUCT (DO_TO_STRUCT)								\
	FOR_cj_xgbh_STRUCT (DO_TO_STRUCT)							\
	FOR_cj_xsmb_STRUCT (DO_TO_STRUCT)							\


#define FOR_EACH_STRUCT_13(DO_TO_STRUCT)						\
	FOR_TimGlobalsType_STRUCT (DO_TO_STRUCT)					\
																\
	FOR_FormObjAttrType_STRUCT (DO_TO_STRUCT)					\
																\
	FOR_FormBitmapType_STRUCT (DO_TO_STRUCT)					\
	FOR_FormLineType_STRUCT (DO_TO_STRUCT)						\
	FOR_FormFrameType_STRUCT (DO_TO_STRUCT)						\
	FOR_FormRectangleType_STRUCT (DO_TO_STRUCT)					\
	FOR_FormTitleType_STRUCT (DO_TO_STRUCT)						\
	FOR_FormPopupType_STRUCT (DO_TO_STRUCT)						\
	FOR_FrmGraffitiStateType_STRUCT (DO_TO_STRUCT)				\
																\
	FOR_ScrollBarAttrType_STRUCT (DO_TO_STRUCT)					\
	FOR_ScrollBarType_STRUCT (DO_TO_STRUCT)						\
																\
	FOR_FormGadgetAttrType_STRUCT (DO_TO_STRUCT)				\
	FOR_FormGadgetType_STRUCT (DO_TO_STRUCT)					\
																\
	FOR_FormLabelType_STRUCT (DO_TO_STRUCT)						\
																\
	FOR_FieldAttrType_STRUCT (DO_TO_STRUCT)						\
	FOR_FieldType_STRUCT (DO_TO_STRUCT)							\
																\
	FOR_ListAttrType_STRUCT (DO_TO_STRUCT)						\
	FOR_ListType_STRUCT (DO_TO_STRUCT)							\
																\
	FOR_TableAttrType_STRUCT (DO_TO_STRUCT)						\
	FOR_TableType_STRUCT (DO_TO_STRUCT)							\


#define FOR_EACH_STRUCT_14(DO_TO_STRUCT)						\
	FOR_HostDirEntType_STRUCT (DO_TO_STRUCT)					\
	FOR_HostGremlinInfoType_STRUCT (DO_TO_STRUCT)				\
	FOR_HostStatType_STRUCT (DO_TO_STRUCT)						\
	FOR_HostTmType_STRUCT (DO_TO_STRUCT)						\
	FOR_HostUTimeType_STRUCT (DO_TO_STRUCT)						\
																\
	FOR_NetHostInfoType_STRUCT (DO_TO_STRUCT)					\
	FOR_NetHostInfoBufType_STRUCT (DO_TO_STRUCT)				\
	FOR_NetIOParamType_STRUCT (DO_TO_STRUCT)					\
	FOR_NetIOVecType_STRUCT (DO_TO_STRUCT)						\
	FOR_NetServInfoType_STRUCT (DO_TO_STRUCT)					\
	FOR_NetServInfoBufType_STRUCT (DO_TO_STRUCT)				\
	FOR_NetSocketAddrINType_STRUCT (DO_TO_STRUCT)				\
	FOR_NetSocketAddrRawType_STRUCT (DO_TO_STRUCT)				\
	FOR_NetSocketAddrType_STRUCT (DO_TO_STRUCT)					\


#if PLATFORM_MAC
	#define INLINE_SCALAR_IMPLEMENTATION	1
#else
	#define INLINE_SCALAR_IMPLEMENTATION	0
#endif

FOR_EACH_SCALAR_1 (DECLARE_SCALAR_CLASSES)
FOR_EACH_SCALAR_2 (DECLARE_SCALAR_CLASSES)
FOR_EACH_SCALAR_3 (DECLARE_SCALAR_CLASSES)
FOR_EACH_SCALAR_4 (DECLARE_SCALAR_CLASSES)

#if INLINE_SCALAR_IMPLEMENTATION

#undef INLINE_
#define INLINE_ inline

FOR_EACH_SCALAR_1 (DEFINE_SCALAR_CLASSES)
FOR_EACH_SCALAR_2 (DEFINE_SCALAR_CLASSES)
FOR_EACH_SCALAR_3 (DEFINE_SCALAR_CLASSES)
FOR_EACH_SCALAR_4 (DEFINE_SCALAR_CLASSES)

#undef INLINE_
#define INLINE_

#endif

FOR_EACH_STRUCT_1 (DECLARE_STRUCT_CLASSES)
FOR_EACH_STRUCT_2 (DECLARE_STRUCT_CLASSES)
FOR_EACH_STRUCT_3 (DECLARE_STRUCT_CLASSES)
FOR_EACH_STRUCT_4 (DECLARE_STRUCT_CLASSES)
FOR_EACH_STRUCT_5 (DECLARE_STRUCT_CLASSES)
FOR_EACH_STRUCT_6 (DECLARE_STRUCT_CLASSES)
FOR_EACH_STRUCT_7 (DECLARE_STRUCT_CLASSES)
FOR_EACH_STRUCT_8 (DECLARE_STRUCT_CLASSES)
FOR_EACH_STRUCT_9 (DECLARE_STRUCT_CLASSES)
FOR_EACH_STRUCT_10 (DECLARE_STRUCT_CLASSES)
FOR_EACH_STRUCT_11 (DECLARE_STRUCT_CLASSES)
FOR_EACH_STRUCT_12 (DECLARE_STRUCT_CLASSES)
FOR_EACH_STRUCT_13 (DECLARE_STRUCT_CLASSES)
FOR_EACH_STRUCT_14 (DECLARE_STRUCT_CLASSES)

#endif	// EmPalmStructs_h