File: Bank_SED1375.cpp

package info (click to toggle)
pose 3.0a3-3
  • links: PTS
  • area: contrib
  • in suites: potato
  • size: 15,500 kB
  • ctags: 20,548
  • sloc: ansic: 72,579; cpp: 50,198; perl: 1,336; python: 1,242; sh: 363; makefile: 290
file content (1154 lines) | stat: -rw-r--r-- 32,526 bytes parent folder | download
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
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
/* -*- mode: C++; tab-width: 4 -*- */
/* ================================================================================== */
/* Copyright (c) 1998-1999 3Com Corporation or its subsidiaries. All rights reserved. */
/* ================================================================================== */

#include "EmulatorCommon.h"
#include "Bank_SED1375.h"

#include "Bank_ROM.h"			// ROMBank::IsPCInRAM
#include "Byteswapping.h"		// ByteswapWords
#include "CPU_REG.h"			// Software::BusError, Screen::Palette
#include "DebugMgr.h"			// Debug::CheckStepSpy
#include "RAM_ROM.h"			// gMemoryAccess
#include "SessionFile.h"		// WriteSED1375RegsType, ReadSED1375RegsType, etc.


typedef uae_u32 	(*ReadFunction)(uaecptr address, int size);
typedef void		(*WriteFunction)(uaecptr address, int size, uae_u32 value);

// Macro to return the Dragonball address of the specified register

#define addressof(x)	(kMemoryStart + sed1375RegisterOffset + offsetof(SED1375RegsType, x))


// Macros for reading/writing Dragonball registers.

#define READ_REGISTER(reg)	\
	((sizeof(g1375Regs.reg) == 1) ? do_get_mem_byte(&g1375Regs.reg) :	\
	 (sizeof(g1375Regs.reg) == 2) ? do_get_mem_word(&g1375Regs.reg) :	\
								  do_get_mem_long(&g1375Regs.reg))

#define WRITE_REGISTER(reg, value)	\
	(sizeof(g1375Regs.reg) == 1) ? do_put_mem_byte(&g1375Regs.reg, value) : \
	(sizeof(g1375Regs.reg) == 2) ? do_put_mem_word(&g1375Regs.reg, value) : \
								 do_put_mem_long(&g1375Regs.reg, value)

class SED1375Reg
{
	public:
		static void 		SetHandler			(ReadFunction, WriteFunction, uae_u32 start, int count);

		static uae_u32		UnsupportedRead 	(uaecptr address, int size);
		static void 		UnsupportedWrite	(uaecptr address, int size, uae_u32 value);

		static uae_u32		StdRead 			(uaecptr address, int size);
		static void 		StdWrite			(uaecptr address, int size, uae_u32 value);
		static void 		NullWrite			(uaecptr address, int size, uae_u32 value); // For read-only registers

		static uae_u32		GetVertNonDisplay	(uaecptr address, int size);
		static uae_u32		GetCLUTEntry		(uaecptr address, int size);
		static void 		SetCLUTEntry		(uaecptr address, int size, uae_u32 value);

		static void 		SetCLUTAddr 		(uaecptr address, int size, uae_u32 value);
};


const SED1375RegsType kInitialSED1375RegisterValues =
{
	0x24,		// Byte productRevisionCode;		// 0x00

	0x00,		// Byte mode0;						// 0x01
	0x00,		// Byte mode1;						// 0x02
	0x00,		// Byte mode2;						// 0x03

	0x00,		// Byte horizontalPanelSize;		// 0x04

	0x00,		// Byte verticalPanelSizeLSB;		// 0x05
	0x00,		// Byte verticalPanelSizeMSB;		// 0x06

	0x00,		// Byte FPLineStartPosition;		// 0x07
	0x00,		// Byte horizontalNonDisplayPeriod; // 0x08
	0x00,		// Byte FPFRAMEStartPosition;		// 0x09
	0x00,		// Byte verticalNonDisplayPeriod;	// 0x0A
	0x00,		// Byte MODRate;					// 0x0B

	0x00,		// Byte screen1StartAddressLSB; 	// 0x0C
	0x00,		// Byte screen1StartAddressMSB; 	// 0x0D
	0x00,		// Byte screen1StartAddressMSBit;	// 0x0E

	0x00,		// Byte screen2StartAddressLSB; 	// 0x0F
	0x00,		// Byte screen2StartAddressMSB; 	// 0x10
	0x00,		// Byte screen2StartAddressMSBit;	// 0x11

	0x00,		// Byte memoryAddressOffset;		// 0x12

	0x00,		// Byte screen1VerticalSizeLSB; 	// 0x13
	0x00,		// Byte screen1VerticalSizeMSB; 	// 0x14

	0x00,		// Byte lookUpTableAddress; 		// 0x15
	0x00,		// Byte unused1;					// 0x16
	0x00,		// Byte lookUpTableData;			// 0x17

	0x00,		// Byte GPIOConfigurationControl;	// 0x18
	0x00,		// Byte GPIOStatusControl;			// 0x19

	0x00,		// Byte scratchPad; 				// 0x1A
	0x00,		// Byte portraitMode;				// 0x1B
	0x00,		// Byte lineByteCountRegister;		// 0x1C, for portrait mode only
	0x00,		// Byte unused2;					// 0x01D not used
	0x00,		// Byte unusual;					// 0x1E
	0x00		// Byte testMode;					// 0x1F
};


static AddressBank	gAddressBank =
{
	SED1375Bank::GetLong,
	SED1375Bank::GetWord,
	SED1375Bank::GetByte,
	SED1375Bank::SetLong,
	SED1375Bank::SetWord,
	SED1375Bank::SetByte,
	SED1375Bank::GetRealAddress,
	SED1375Bank::ValidAddress,
	SED1375Bank::GetMetaAddress,
	NULL
};

static const uae_u32	kMemoryStart = sed1375BaseAddress;

static SED1375RegsType	g1375Regs;
static void*			gVideoMem;
static void*			gMetaMem;
static uae_u16			gClutData[256];
static Bool 			gClutDirty;

// These functions provide fetch and store access to the
// emulator's register memory.

static ReadFunction 	gReadFunctions[sizeof(SED1375RegsType)];
static WriteFunction	gWriteFunctions[sizeof(SED1375RegsType)];

#define kCLUTColorIndexMask 	0xf000
#define kCLUTColorsMask 		0x0fff

#define kCLUTRedMask			0x0f00
#define kCLUTGreenMask			0x00f0
#define kCLUTBlueMask			0x000f

#define kCLUTIndexRed			0x4000
#define kCLUTIndexGreen 		0x2000
#define kCLUTIndexBlue			0x1000



#pragma mark -


/***********************************************************************
 *
 * FUNCTION:	SED1375Bank::Initialize
 *
 * DESCRIPTION: Standard initialization function.  Responsible for
 *				initializing this sub-system when a new session is
 *				created.  May also be called from the Load function
 *				to share common functionality.
 *
 * PARAMETERS:	None.
 *
 * RETURNED:	Nothing.
 *
 ***********************************************************************/

void SED1375Bank::Initialize (void)
{
	// Memory banks starting at kMemoryStart are managed by the functions in SED1375Bank.

	long	numBanks = (sed1375RegisterOffset + sizeof (SED1375RegsType) + 0x0FFFF) / 0x10000;
	Memory::InitializeBanks (gAddressBank, bankindex (kMemoryStart), numBanks);

	// Allocate a chunk of memory for the VRAM space.

	if (!gVideoMem)
	{
		gVideoMem = Platform::AllocateMemoryClear (sed1375VideoMemSize);
		gMetaMem = Platform::AllocateMemoryClear (sed1375VideoMemSize);
	}

	// Install the handlers for each register.

	SED1375Bank::InstallHandlers ();
}


/***********************************************************************
 *
 * FUNCTION:	SED1375Bank::Reset
 *
 * DESCRIPTION: Standard reset function.  Sets the sub-system to a
 *				default state.	This occurs not only on a Reset (as
 *				from the menu item), but also when the sub-system
 *				is first initialized (Reset is called after Initialize)
 *				as well as when the system is re-loaded from an
 *				insufficient session file.
 *
 * PARAMETERS:	None.
 *
 * RETURNED:	Nothing.
 *
 ***********************************************************************/

void SED1375Bank::Reset (void)
{
	g1375Regs = kInitialSED1375RegisterValues;

	Canonical (g1375Regs);
	ByteswapWords (&g1375Regs, sizeof(g1375Regs));

	gClutDirty = true;			// Just make sure the clut gets refreshed after reset.
}


/***********************************************************************
 *
 * FUNCTION:	SED1375Bank::Save
 *
 * DESCRIPTION: Standard save function.  Saves any sub-system state to
 *				the given session file.
 *
 * PARAMETERS:	None.
 *
 * RETURNED:	Nothing.
 *
 ***********************************************************************/

void SED1375Bank::Save (SessionFile& f)
{
	StWordSwapper					swapper1 (&g1375Regs, sizeof(g1375Regs));
//	StCanonical<SED1375RegsType>	swapper2 (g1375Regs);
	f.WriteSED1375RegsType (g1375Regs);
	f.FixBug (SessionFile::kBugByteswappedStructs);

	StWordSwapper	swapper3 (gVideoMem, sed1375VideoMemSize);
	f.WriteSED1375Image (gVideoMem, sed1375VideoMemSize);

	StWordSwapper	swapper4 (gMetaMem, sed1375VideoMemSize);
	f.WriteSED1375MetaImage (gMetaMem, sed1375VideoMemSize);

	StWordSwapper	swapper5 (gClutData, sizeof(gClutData));
	f.WriteSED1375Palette (gClutData);
}


/***********************************************************************
 *
 * FUNCTION:	SED1375Bank::Load
 *
 * DESCRIPTION: Standard load function.  Loads any sub-system state
 *				from the given session file.
 *
 * PARAMETERS:	None.
 *
 * RETURNED:	Nothing.
 *
 ***********************************************************************/

void SED1375Bank::Load (SessionFile& f)
{
	assert (gVideoMem != NULL);
	assert (gMetaMem != NULL);

	// Read in the SED registers, and then byteswap them.

	if (f.ReadSED1375RegsType (g1375Regs))
	{
		// The Windows version of Poser 2.1d29 and earlier did not write
		// out structs in the correct format.  The fields of the struct
		// were written out in Little-Endian format, not Big-Endian.  To
		// address this problem, the bug has been fixed, and a new field
		// is added to the file format indicating that the bug has been
		// fixed.  With the new field (the "bug bit"), Poser can identify
		// old files from new files and read them in accordingly.
		// 
		// With the bug fixed, the .psf files should now be interchangeable
		// across platforms (modulo other bugs...).

		if (!f.IncludesBugFix (SessionFile::kBugByteswappedStructs))
		{
			Canonical (g1375Regs);
		}
		ByteswapWords (&g1375Regs, sizeof(g1375Regs));
	}
	else
	{
		f.SetCanReload (false);
	}

	// Read in the LCD image, and then byteswap it.

	if (f.ReadSED1375Image (gVideoMem))
	{
		ByteswapWords (gVideoMem, sed1375VideoMemSize);
	}
	else
	{
		f.SetCanReload (false);
	}

	// Read in the LCD meta image, and then byteswap it.

	if (f.ReadSED1375MetaImage (gMetaMem))
	{
		ByteswapWords (gMetaMem, sed1375VideoMemSize);
	}
	else
	{
		f.SetCanReload (false);
	}

	// Read in the LCD palette, and then byteswap it.

	if (f.ReadSED1375Palette (gClutData))
	{
		ByteswapWords (gClutData, sizeof (gClutData));
	}
	else
	{
		f.SetCanReload (false);
	}

	gClutDirty = true;	// This variable comments on the state of gClutData.
						// By forcing it to "true", we don't have to save
						// and later reload gClutData.
}


/***********************************************************************
 *
 * FUNCTION:	SED1375Bank::Dispose
 *
 * DESCRIPTION: Standard dispose function.	Completely release any
 *				resources acquired or allocated in Initialize and/or
 *				Load.
 *
 * PARAMETERS:	None.
 *
 * RETURNED:	Nothing.
 *
 ***********************************************************************/

void SED1375Bank::Dispose (void)
{
	Platform::DisposeMemory (gVideoMem);
	Platform::DisposeMemory (gMetaMem);
}


// ---------------------------------------------------------------------------
//		 SED1375Bank::InstallHandlers
// ---------------------------------------------------------------------------

void SED1375Bank::InstallHandlers (void)
{
	SED1375Reg::SetHandler (SED1375Reg::UnsupportedRead, SED1375Reg::UnsupportedWrite,
						kMemoryStart + sed1375RegisterOffset, sizeof (SED1375RegsType));

	// Now add standard/specialized handers for the defined registers.

#define INSTALL_HANDLER(read, write, reg) \
	SED1375Reg::SetHandler (SED1375Reg::read, SED1375Reg::write, \
							addressof (reg), sizeof (g1375Regs.reg))


	INSTALL_HANDLER (StdRead,			StdWrite,				productRevisionCode);
	INSTALL_HANDLER (StdRead,			StdWrite,				mode0);
	INSTALL_HANDLER (StdRead,			StdWrite,				mode1);
	INSTALL_HANDLER (StdRead,			StdWrite,				mode2);
	INSTALL_HANDLER (StdRead,			StdWrite,				horizontalPanelSize);
	INSTALL_HANDLER (StdRead,			StdWrite,				verticalPanelSizeLSB);
	INSTALL_HANDLER (StdRead,			StdWrite,				verticalPanelSizeMSB);
	INSTALL_HANDLER (StdRead,			StdWrite,				FPLineStartPosition);
	INSTALL_HANDLER (StdRead,			StdWrite,				horizontalNonDisplayPeriod);
	INSTALL_HANDLER (StdRead,			StdWrite,				FPFRAMEStartPosition);
	INSTALL_HANDLER (GetVertNonDisplay, StdWrite,				verticalNonDisplayPeriod);
	INSTALL_HANDLER (StdRead,			StdWrite,				MODRate);
	INSTALL_HANDLER (StdRead,			StdWrite,				screen1StartAddressLSB);
	INSTALL_HANDLER (StdRead,			StdWrite,				screen1StartAddressMSB);
	INSTALL_HANDLER (StdRead,			StdWrite,				screen1StartAddressMSBit);
	INSTALL_HANDLER (StdRead,			StdWrite,				screen2StartAddressLSB);
	INSTALL_HANDLER (StdRead,			StdWrite,				screen2StartAddressMSB);
	INSTALL_HANDLER (StdRead,			StdWrite,				screen2StartAddressMSBit);
	INSTALL_HANDLER (StdRead,			StdWrite,				memoryAddressOffset);
	INSTALL_HANDLER (StdRead,			StdWrite,				screen1VerticalSizeLSB);
	INSTALL_HANDLER (StdRead,			StdWrite,				screen1VerticalSizeMSB);
	INSTALL_HANDLER (StdRead,			SetCLUTAddr,			lookUpTableAddress);
	INSTALL_HANDLER (GetCLUTEntry,		SetCLUTEntry,			lookUpTableData);
	INSTALL_HANDLER (StdRead,			StdWrite,				GPIOConfigurationControl);
	INSTALL_HANDLER (StdRead,			StdWrite,				GPIOStatusControl);
	INSTALL_HANDLER (StdRead,			StdWrite,				scratchPad);
	INSTALL_HANDLER (StdRead,			StdWrite,				portraitMode);
	INSTALL_HANDLER (StdRead,			StdWrite,				lineByteCountRegister);
	INSTALL_HANDLER (StdRead,			StdWrite,				unusual);
	INSTALL_HANDLER (StdRead,			StdWrite,				testMode);
}


// ---------------------------------------------------------------------------
//		 SED1375Bank::GetLong
// ---------------------------------------------------------------------------

uae_u32 SED1375Bank::GetLong (uaecptr iAddress)
{
#if PROFILE_MEMORY
	gMemoryAccess[kSED1375LongRead]++;
	if (iAddress & 2)
		gMemoryAccess[kSED1375LongRead2]++;
#endif

#if (CHECK_FOR_ADDRESS_ERROR)
	if ((iAddress & 1) != 0)
	{
		Software::AddressError ();
	}
#endif

#if (PREVENT_USER_REGISTER_GET)
	if (gMemAccessFlags.fProtect_RegisterGet && ROMBank::IsPCInRAM ())
	{
		PreventedAccess (iAddress, 4, true);
	}
#endif

#if (VALIDATE_REGISTER_GET)
	if (gMemAccessFlags.fValidate_RegisterGet && !ValidAddress (iAddress, 4))
	{
		InvalidAccess (iAddress, 4, true);
	}
#endif

#if HAS_PROFILING
	CYCLE_GETLONG (WAITSTATES_SED1375);
#endif

	uae_u32 		offset = iAddress - kMemoryStart;
	ReadFunction	fn = SED1375Reg::UnsupportedRead;

	if (offset < sed1375VideoMemSize)			// Memory access is in VRAM area?
	{
		return do_get_mem_long (((char*) gVideoMem) + offset);
	}

	if (offset >= sed1375RegisterOffset)
	{
		fn = gReadFunctions[offset - sed1375RegisterOffset];
	}

	assert (fn);
	return fn (iAddress, 4);
}


// ---------------------------------------------------------------------------
//		 SED1375Bank::GetWord
// ---------------------------------------------------------------------------

uae_u32 SED1375Bank::GetWord (uaecptr iAddress)
{
#if PROFILE_MEMORY
	gMemoryAccess[kSED1375WordRead]++;
#endif

#if (CHECK_FOR_ADDRESS_ERROR)
	if ((iAddress & 1) != 0)
	{
		Software::AddressError ();
	}
#endif

#if (PREVENT_USER_REGISTER_GET)
	if (gMemAccessFlags.fProtect_RegisterGet && ROMBank::IsPCInRAM ())
	{
		PreventedAccess (iAddress, 2, true);
	}
#endif

#if (VALIDATE_REGISTER_GET)
	if (gMemAccessFlags.fValidate_RegisterGet && !ValidAddress (iAddress, 2))
	{
		InvalidAccess (iAddress, 2, true);
	}
#endif

#if HAS_PROFILING
	CYCLE_GETWORD (WAITSTATES_SED1375);
#endif

	uae_u32 		offset = iAddress - kMemoryStart;
	ReadFunction	fn = SED1375Reg::UnsupportedRead;

	if (offset < sed1375VideoMemSize)			// Memory access is in VRAM area?
	{
		return do_get_mem_word(((char*) gVideoMem) + offset);
	}

	if (offset >= sed1375RegisterOffset)
	{
		fn = gReadFunctions[offset - sed1375RegisterOffset];
	}

	assert (fn);
	return fn (iAddress, 2);
}


// ---------------------------------------------------------------------------
//		 SED1375Bank::GetByte
// ---------------------------------------------------------------------------

uae_u32 SED1375Bank::GetByte (uaecptr iAddress)
{
#if PROFILE_MEMORY
	gMemoryAccess[kSED1375ByteRead]++;
#endif

#if (PREVENT_USER_REGISTER_GET)
	if (gMemAccessFlags.fProtect_RegisterGet && ROMBank::IsPCInRAM ())
	{
		PreventedAccess (iAddress, 1, true);
	}
#endif

#if (VALIDATE_REGISTER_GET)
	if (gMemAccessFlags.fValidate_RegisterGet && !ValidAddress (iAddress, 1))
	{
		InvalidAccess (iAddress, 1, true);
	}
#endif

#if HAS_PROFILING
	CYCLE_GETBYTE (WAITSTATES_SED1375);
#endif

	uae_u32 		offset = iAddress - kMemoryStart;
	ReadFunction	fn = SED1375Reg::UnsupportedRead;

	if (offset < sed1375VideoMemSize)			// Memory access is in VRAM area?
	{
		return do_get_mem_byte(((char*) gVideoMem) + offset);
	}

	if (offset >= sed1375RegisterOffset)
	{
		fn = gReadFunctions[offset - sed1375RegisterOffset];
	}

	assert (fn);
	return fn (iAddress, 1);
}


// ---------------------------------------------------------------------------
//		 SED1375Bank::SetLong
// ---------------------------------------------------------------------------

void SED1375Bank::SetLong (uaecptr iAddress, uae_u32 iLongValue)
{
#if PROFILE_MEMORY
	gMemoryAccess[kSED1375LongWrite]++;
	if (iAddress & 2)
		gMemoryAccess[kSED1375LongWrite2]++;
#endif

#if (CHECK_FOR_ADDRESS_ERROR)
	if ((iAddress & 1) != 0)
	{
		Software::AddressError ();
	}
#endif

#if (PREVENT_USER_REGISTER_SET)
	if (gMemAccessFlags.fProtect_RegisterSet && ROMBank::IsPCInRAM ())
	{
		PreventedAccess (iAddress, 4, false);
	}
#endif

#if (VALIDATE_REGISTER_SET)
	if (gMemAccessFlags.fValidate_RegisterSet && !ValidAddress (iAddress, 4))
	{
		InvalidAccess (iAddress, 4, false);
	}
#endif

#if HAS_PROFILING
	CYCLE_PUTLONG (WAITSTATES_SED1375);
#endif

	uae_u32 		offset = iAddress - kMemoryStart;
	WriteFunction	fn = SED1375Reg::UnsupportedWrite;

	if (offset < sed1375VideoMemSize)		// Memory access is in VRAM area?
	{
		do_put_mem_long(((char*) gVideoMem) + offset, iLongValue);

		Screen::MarkDirty (iAddress, sizeof (long));
	}
	else if (offset >= sed1375RegisterOffset)
	{
		fn = gWriteFunctions[offset - sed1375RegisterOffset];

		assert (fn);
		fn (iAddress, 4, iLongValue);
	}

	// See if any interesting memory locations have changed.  If so,
	// CheckStepSpy will change gBreakReason, which we'll check later.

	Debug::CheckStepSpy (iAddress, 4);
}


// ---------------------------------------------------------------------------
//		 SED1375Bank::SetWord
// ---------------------------------------------------------------------------

void SED1375Bank::SetWord (uaecptr iAddress, uae_u32 iWordValue)
{
#if PROFILE_MEMORY
	gMemoryAccess[kSED1375WordWrite]++;
#endif

#if (CHECK_FOR_ADDRESS_ERROR)
	if ((iAddress & 1) != 0)
	{
		Software::AddressError ();
	}
#endif

#if (PREVENT_USER_REGISTER_SET)
	if (gMemAccessFlags.fProtect_RegisterSet && ROMBank::IsPCInRAM ())
	{
		PreventedAccess (iAddress, 2, false);
	}
#endif

#if (VALIDATE_REGISTER_SET)
	if (gMemAccessFlags.fValidate_RegisterSet && !ValidAddress (iAddress, 2))
	{
		InvalidAccess (iAddress, 2, false);
	}
#endif

#if HAS_PROFILING
	CYCLE_PUTWORD (WAITSTATES_SED1375);
#endif

	uae_u32 		offset = iAddress - kMemoryStart;
	WriteFunction	fn = SED1375Reg::UnsupportedWrite;

	if (offset < sed1375VideoMemSize)			// Memory access is in VRAM area?
	{
		do_put_mem_word(((char*) gVideoMem) + offset, iWordValue);

		Screen::MarkDirty (iAddress, sizeof (short));
	}
	else if (offset >= sed1375RegisterOffset)
	{
		fn = gWriteFunctions[offset - sed1375RegisterOffset];

		assert (fn);
		fn (iAddress, 2, iWordValue);
	}

	// See if any interesting memory locations have changed.  If so,
	// CheckStepSpy will change gBreakReason, which we'll check later.

	Debug::CheckStepSpy (iAddress, 2);
}


// ---------------------------------------------------------------------------
//		 SED1375Bank::SetByte
// ---------------------------------------------------------------------------

void SED1375Bank::SetByte (uaecptr iAddress, uae_u32 iByteValue)
{
#if PROFILE_MEMORY
	gMemoryAccess[kSED1375ByteWrite]++;
#endif

#if (PREVENT_USER_REGISTER_SET)
	if (gMemAccessFlags.fProtect_RegisterSet && ROMBank::IsPCInRAM ())
	{
		PreventedAccess (iAddress, 1, false);
	}
#endif

#if (VALIDATE_REGISTER_SET)
	if (gMemAccessFlags.fValidate_RegisterSet && !ValidAddress (iAddress, 1))
	{
		InvalidAccess (iAddress, 1, false);
	}
#endif

#if HAS_PROFILING
	CYCLE_PUTBYTE (WAITSTATES_SED1375);
#endif

	uae_u32 		offset = iAddress - kMemoryStart;
	WriteFunction	fn = SED1375Reg::UnsupportedWrite;

	if (offset < sed1375VideoMemSize)		// Memory access is in VRAM area?
	{
		do_put_mem_byte(((char*) gVideoMem) + offset, iByteValue);

		Screen::MarkDirty (iAddress, sizeof (char));
	}
	else if (offset >= sed1375RegisterOffset)
	{
		fn = gWriteFunctions[offset - sed1375RegisterOffset];

		assert (fn);
		fn (iAddress, 1, iByteValue);
	}

	// See if any interesting memory locations have changed.  If so,
	// CheckStepSpy will change gBreakReason, which we'll check later.

	Debug::CheckStepSpy (iAddress, 1);
}


// ---------------------------------------------------------------------------
//		 SED1375Bank::ValidAddress
// ---------------------------------------------------------------------------

int SED1375Bank::ValidAddress (uaecptr iAddress, uae_u32 iSize)
{
	UNUSED_PARAM(iSize)

	uae_u32 		offset = iAddress - kMemoryStart;
	WriteFunction	fn = SED1375Reg::UnsupportedWrite;

	if (offset < sed1375VideoMemSize)			// Memory access is in VRAM area?
		fn = SED1375Reg::StdWrite;
	else if (offset >= sed1375RegisterOffset)
		fn = gWriteFunctions[offset - sed1375RegisterOffset];

	int result = (fn != SED1375Reg::UnsupportedWrite);

	assert (result);

	return result;
}


// ---------------------------------------------------------------------------
//		 SED1375Bank::GetRealAddress
// ---------------------------------------------------------------------------

uae_u8* SED1375Bank::GetRealAddress (uaecptr iAddress)
{
	uae_u32 offset = iAddress - kMemoryStart;

	if (offset < sed1375RegisterOffset)
		return (uae_u8*) ((uae_u32) gVideoMem + offset);

	return ((uae_u8*) &g1375Regs) + (offset - sed1375RegisterOffset);
}


// ---------------------------------------------------------------------------
//		 SED1375Bank::GetMetaAddress
// ---------------------------------------------------------------------------

uae_u8* SED1375Bank::GetMetaAddress (uaecptr iAddress)
{
	uae_u32 offset = iAddress - kMemoryStart;

	if (offset < sed1375RegisterOffset)
		return (uae_u8*) ((uae_u32) gMetaMem + offset);

	return ((uae_u8*) &g1375Regs) + (offset - sed1375RegisterOffset);
}


// ---------------------------------------------------------------------------
//		 SED1375Bank::InvalidAccess
// ---------------------------------------------------------------------------

void SED1375Bank::InvalidAccess (uaecptr iAddress, long size, Bool forRead)
{
	UNUSED_PARAM(iAddress)
	UNUSED_PARAM(size)
	UNUSED_PARAM(forRead)

	Software::BusError ();
}


// ---------------------------------------------------------------------------
//		 SED1375Bank::PreventedAccess
// ---------------------------------------------------------------------------

void SED1375Bank::PreventedAccess (uaecptr iAddress, long size, Bool forRead)
{
	Memory::PreventedAccess (iAddress, size, forRead, Errors::kRegisterAccess);
}


// ---------------------------------------------------------------------------
//		 SED1375Bank::GetLCDDepth
// ---------------------------------------------------------------------------

int SED1375Bank::GetLCDDepth (void)
{
	Byte depth = (READ_REGISTER (mode1) & sed1375BPP256Colors);

	switch (depth)
	{
		case sed1375BPP256Colors:
			return 8;

		case sed1375BPP16Colors:
			return 4;

		case sed1375BPP4Colors:
			return 2;

		default:
			return 1;
	}
}


// ---------------------------------------------------------------------------
//		 SED1375Bank::GetLCDRowBytes
// ---------------------------------------------------------------------------

int SED1375Bank::GetLCDRowBytes (void)
{
	int 	depth = GetLCDDepth ();
	Byte	hSize = GetLCDWidth ();

	return (int) (hSize / (8 / depth));
}


// ---------------------------------------------------------------------------
//		 SED1375Bank::GetLCDWidth
// ---------------------------------------------------------------------------

int SED1375Bank::GetLCDWidth (void)
{
	return (int) ((READ_REGISTER(horizontalPanelSize) + 1) * 8);
}


// ---------------------------------------------------------------------------
//		 SED1375Bank::GetLCDHeight
// ---------------------------------------------------------------------------

int SED1375Bank::GetLCDHeight (void)
{
	return (int) ((READ_REGISTER(verticalPanelSizeMSB) << 8) |
						READ_REGISTER(verticalPanelSizeLSB)) + 1;
}


// ---------------------------------------------------------------------------
//		 SED1375Bank::GetLCDStartAddr
// ---------------------------------------------------------------------------

uaecptr SED1375Bank::GetLCDStartAddr (void)
{
	// The screen address is word-offset based. We must convert to a physical address.

	uae_u32 byteOffset =	(READ_REGISTER(screen1StartAddressMSBit) << 16) |
							(READ_REGISTER(screen1StartAddressMSB) << 8) |
							 READ_REGISTER(screen1StartAddressLSB);

	return kMemoryStart + (byteOffset * 2);
}


// ---------------------------------------------------------------------------
//		 SED1375Bank::GetLCDStartAddr
// ---------------------------------------------------------------------------

int SED1375Bank::GetLCDPalette (RGBType* scrPalette)
{
	int 	depth = SED1375Bank::GetLCDDepth ();
	int 	totalEntries = (1 << depth);

	if (gClutDirty)
	{
		for (int ii = 0; ii < totalEntries; ++ii)
		{
			uae_u16 curEntry = gClutData[ii];
			uae_u8	color;

			color = (uae_u8) ((curEntry & kCLUTRedMask) >> 4);
			scrPalette[ii].fRed = color + (color >> 4);

			color = (uae_u8) ((curEntry & kCLUTGreenMask) >> 0);
			scrPalette[ii].fGreen = color + (color >> 4);

			color = (uae_u8) ((curEntry & kCLUTBlueMask) << 4);
			scrPalette[ii].fBlue = color + (color >> 4);
		}

		gClutDirty = false;
	}

	return totalEntries;
}


// ---------------------------------------------------------------------------
//		 SED1375Bank::GetLCDOffset
// ---------------------------------------------------------------------------

int SED1375Bank::GetLCDOffset (void)
{
	return 0;
}


// ---------------------------------------------------------------------------
//		 SED1375Bank::LCDIsOn
// ---------------------------------------------------------------------------

Bool SED1375Bank::LCDIsOn (void)
{
	return (READ_REGISTER (mode1) & sed1375DisplayBlank) == 0;
}


// ---------------------------------------------------------------------------
//		 SED1375Bank::BacklightIsOn
// ---------------------------------------------------------------------------

Bool SED1375Bank::BacklightIsOn (void)
{
	return true;			// The Backlight is always on for Austin units.
}


#pragma mark -

// ===========================================================================
//		 Register Accessors
// ===========================================================================

// ---------------------------------------------------------------------------
//		 SED1375Reg::SetHandler
// ---------------------------------------------------------------------------

void SED1375Reg::SetHandler (ReadFunction read, WriteFunction write,
							uae_u32 start, int count)
{
	int index = start - (kMemoryStart + sed1375RegisterOffset);
	for (int ii = 0; ii < count; ++ii, ++index)
	{
		gReadFunctions[index] = read;
		gWriteFunctions[index] = write;
	}
}


// ---------------------------------------------------------------------------
//		 SED1375Reg::UnsupportedRead
// ---------------------------------------------------------------------------

uae_u32 SED1375Reg::UnsupportedRead (uaecptr address, int size)
{
	if (!CEnableFullAccess::AccessOK ())
	{
		SED1375Bank::InvalidAccess (address, size, true);
	}

	return ~0;
}


// ---------------------------------------------------------------------------
//		 SED1375Reg::UnsupportedWrite
// ---------------------------------------------------------------------------

void SED1375Reg::UnsupportedWrite (uaecptr address, int size, uae_u32 value)
{
	UNUSED_PARAM(value)

	if (!CEnableFullAccess::AccessOK ())
	{
		SED1375Bank::InvalidAccess (address, size, false);
	}
}


// ---------------------------------------------------------------------------
//		 SED1375Reg::StdRead
// ---------------------------------------------------------------------------

uae_u32 SED1375Reg::StdRead (uaecptr address, int size)
{
	if (size == 1)
		return do_get_mem_byte (SED1375Bank::GetRealAddress (address));

	if (size == 2)
		return do_get_mem_word (SED1375Bank::GetRealAddress (address));

	return do_get_mem_long (SED1375Bank::GetRealAddress (address));
}


// ---------------------------------------------------------------------------
//		 SED1375Reg::StdWrite
// ---------------------------------------------------------------------------

void SED1375Reg::StdWrite (uaecptr address, int size, uae_u32 value)
{
	if (size == 1)
		do_put_mem_byte (SED1375Bank::GetRealAddress (address), value);

	else if (size == 2)
		do_put_mem_word (SED1375Bank::GetRealAddress (address), value);

	else
		do_put_mem_long (SED1375Bank::GetRealAddress (address), value);
}


// ---------------------------------------------------------------------------
//		 SED1375Reg::NullWrite
// ---------------------------------------------------------------------------

void SED1375Reg::NullWrite (uaecptr address, int size, uae_u32 value)
{
	UNUSED_PARAM(address)
	UNUSED_PARAM(size)
	UNUSED_PARAM(value)

	// Do nothing (for read-only registers).
}


// ---------------------------------------------------------------------------
//		 SED1375Reg::GetVertNonDisplay
// ---------------------------------------------------------------------------

uae_u32 SED1375Reg::GetVertNonDisplay (uaecptr address, int size)
{
	UNUSED_PARAM(address)
	UNUSED_PARAM(size)

	// Always set the vertical non-display status high since in the real
	// hardware, the ROM will check this flag in order to write the CLUT
	// regsiters.

	return READ_REGISTER (verticalNonDisplayPeriod) | sed1375VerticalNonDisplayStatus;
}


// ---------------------------------------------------------------------------
//		 SED1375Reg::SetCLUTAddr
// ---------------------------------------------------------------------------

void SED1375Reg::SetCLUTAddr (uaecptr address, int size, uae_u32 value)
{
	SED1375Reg::StdWrite (address, size, value);

	value &= 0x0FF;

	gClutData[value] &= kCLUTColorsMask;				// Update the rgb index
	gClutData[value] |= kCLUTIndexRed;
}


// ---------------------------------------------------------------------------
//		 SED1375Reg::GetCLUTEntry
// ---------------------------------------------------------------------------

uae_u32 SED1375Reg::GetCLUTEntry (uaecptr address, int size)
{
	assert (size == 1);

	if (size != 1)
		return 0;			// Error case.

	uae_u8	clutIndex = READ_REGISTER (lookUpTableAddress); 	// Get the LUT Addr.
	uae_u16	clutEntry = gClutData[clutIndex];					// Get the entry.
	uae_u8	colorData;

	if ((clutEntry & kCLUTIndexRed) != 0)
	{
		colorData = (uae_u8) ((clutEntry & kCLUTRedMask) >> 4); 	// Get the 4 bits of red.

		gClutData[clutIndex] =										// Update the next rgb index
			(gClutData[clutIndex] & kCLUTColorsMask) | kCLUTIndexGreen;
	}
	else if ((clutEntry & kCLUTIndexGreen) != 0)
	{
		colorData = (uae_u8) (clutEntry & kCLUTGreenMask);			// Get the 4 bits of green

		gClutData[clutIndex] =										// Update the next rgb index
			(gClutData[clutIndex] & kCLUTColorsMask) | kCLUTIndexBlue;
	}
	else
	{
		colorData = (uae_u8) ((clutEntry & kCLUTBlueMask) << 4);	// Get the 4 bits of blue.

		address = (uaecptr) (sed1375RegsAddr + offsetof (SED1375RegsType, lookUpTableAddress));
		SED1375Reg::SetCLUTAddr (address, 1, (clutIndex + 1) & 0xFF);
	}

	return colorData;
}


// ---------------------------------------------------------------------------
//		 SED1375Reg::SetCLUTEntry
// ---------------------------------------------------------------------------

void SED1375Reg::SetCLUTEntry (uaecptr address, int size, uae_u32 value)
{
	assert (size == 1);

	if (size != 1)
		return; 		// Error case.

	uae_u8	clutIndex = READ_REGISTER (lookUpTableAddress); 	// Get the LUT Addr.
	uae_u16	clutEntry = gClutData[clutIndex];					// Get the entry.

	uae_u8	newColor = (uae_u8) (value & 0x00F0);

	if (clutEntry & kCLUTIndexRed)
	{
		gClutData[clutIndex] &= ~kCLUTRedMask;			// Clear out old red bits.
		gClutData[clutIndex] |= newColor << 4;			// Save in new red bits.

		gClutData[clutIndex] =							// Update the rgb index
			(gClutData[clutIndex] & kCLUTColorsMask) | kCLUTIndexGreen;
	}
	else if (clutEntry & kCLUTIndexGreen)
	{
		gClutData[clutIndex] &= ~kCLUTGreenMask;		// Clear out old red bits.
		gClutData[clutIndex] |= newColor;				// Save in new green bits.

		gClutData[clutIndex] =							// Update the rgb index
			(gClutData[clutIndex] & kCLUTColorsMask) | kCLUTIndexBlue;
	}
	else
	{
		gClutData[clutIndex] &= ~kCLUTBlueMask; 		// Clear out old red bits.
		gClutData[clutIndex] |= newColor >> 4;			// Save in new blue bits.

		address = (uaecptr) (sed1375RegsAddr + offsetof (SED1375RegsType, lookUpTableAddress));
		SED1375Reg::SetCLUTAddr (address, 1, (clutIndex + 1) & 0xFF);
	}

	gClutDirty = true;
	Screen::InvalidateAll();
}