aboutsummaryrefslogtreecommitdiff
path: root/SrcShared/Hardware/EmRegsSED1376.cpp
blob: 223c24aa46735f7e6b5b55ba52e99b2539f1cac2 (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
/* -*- 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.
\* ===================================================================== */

#include "EmCommon.h"
#include "EmRegsSED1376.h"

#include "EmMemory.h"			// EmMem_memcpy
#include "EmScreen.h"			// EmScreen::InvalidateAll
#include "EmPixMap.h"			// EmPixMap::GetLCDScanlines
#include "SessionFile.h"		// WriteSED1376RegsType


// Given a register (specified by its field name), return its address
// in emulated space.

#define addressof(reg)				\
	(this->GetAddressStart () + fRegs.offsetof_##reg ())


// Macro to help the installation of handlers for a register.

#define INSTALL_HANDLER(read, write, reg)			\
	this->SetHandler (	(ReadFunction) &EmRegsSED1376::read,		\
						(WriteFunction) &EmRegsSED1376::write,		\
						addressof (reg),			\
						fRegs.reg.GetSize ())

// Panel type register [10h]
#define sed1376MonoMask				0x40

// Display mode register [70h]
#define sed1376DisplayBlankMask		0x80
#define sed1376BPPMask				0x07
#define sed1376BPPShift				0x00

// REG[0x70] displayMode register
// (Same as previous set, but with Handspring names for their contributed code)
#define	sed1376DisplayModeBlank					0x80
#define	sed1376DisplayModeDitherOff				0x40
#define	sed1376DisplayModeHwInvert				0x20
#define	sed1376DisplayModeSwInvert				0x10
#define	sed1376DisplayModeDepthMask				0x07
#define	sed1376DisplayModeDepth16				0x04
#define	sed1376DisplayModeDepth8				0x03
#define	sed1376DisplayModeDepth4				0x02
#define	sed1376DisplayModeDepth2				0x01
#define	sed1376DisplayModeDepth1				0x00

// Special effects register [71h]
#define sed1376WordSwapMask			0x80
#define sed1376ByteSwapMask			0x40
#define sed1376SubWindowEnableMask	0x10

#define hwrDisplayGPIOPCI			0x08			// in GPIOStatusControl0
#define hwrDisplayGPIOEL_ON			0x10			// in GPIOStatusControl0
#define hwrDisplayGPIOLCD_ON		0x20			// in GPIOStatusControl0
#define hwrDisplayGPIOMOD			0x40			// in GPIOStatusControl0

// The current SED1376 driver code is completely whacked.  It's initialized to use
// the main display for drawing (see HwrDisplayInit in HwrDisplayBootSED1376.c), but
// if you change the base address, it (a) always returns the base of the embedded
// SRAM buffer as the old base address, and (b) stores the new base address in
// ovlyStartAddress (see PrvDisplayBaseAddr in HwrDisplaySED1376.c).  Also, the
// splash screen appears to be drawn relative to ovlyStartAddress.  Finally,
// there appears to be code to draw a border in the main screen around the
// overlay screen (see PrvDisplayBorder in HwrDisplayBootSED1376.c), however,
// the mainStartAddress registers are never changed to point to this border.
// On top of that, the border is only programmed on the left and right of the
// of the overlay screen, not on the top and bottom.

#define OVERLAY_IS_MAIN			1


// ---------------------------------------------------------------------------
//		¥ EmRegsSED1376::EmRegsSED1376
// ---------------------------------------------------------------------------

EmRegsSED1376::EmRegsSED1376 (emuptr baseRegsAddr, emuptr baseVideoAddr) :
	fBaseRegsAddr (baseRegsAddr),
	fBaseVideoAddr (baseVideoAddr),
	fRegs ()
{
}


// ---------------------------------------------------------------------------
//		¥ EmRegsSED1376::~EmRegsSED1376
// ---------------------------------------------------------------------------

EmRegsSED1376::~EmRegsSED1376 (void)
{
}


// ---------------------------------------------------------------------------
//		¥ EmRegsSED1376::Initialize
// ---------------------------------------------------------------------------

void EmRegsSED1376::Initialize (void)
{
	EmRegs::Initialize ();
}


// ---------------------------------------------------------------------------
//		¥ EmRegsSED1376::Reset
// ---------------------------------------------------------------------------

void EmRegsSED1376::Reset (Bool hardwareReset)
{
	EmRegs::Reset (hardwareReset);

	if (hardwareReset)
	{
		memset (fRegs.GetPtr (), 0, fRegs.GetSize ());

//		EmAssert ((sed1376ProductCodeExpected | sed1376RevisionCodeExpected) == 0x28);
		fRegs.productRevisionCode	= 0x28;
		fRegs.displayBufferSize		= 20;	// 80K / 4K
		fRegs.configurationReadback	= 0;
	}
}


// ---------------------------------------------------------------------------
//		¥ EmRegsSED1376::Save
// ---------------------------------------------------------------------------

void EmRegsSED1376::Save (SessionFile& f)
{
	EmRegs::Save (f);

	f.WriteSED1376RegsType (*(SED1376RegsType*) fRegs.GetPtr ());
	f.WriteSED1376Palette (fClutData);
}


// ---------------------------------------------------------------------------
//		¥ EmRegsSED1376::Load
// ---------------------------------------------------------------------------

void EmRegsSED1376::Load (SessionFile& f)
{
	EmRegs::Load (f);

	// Read in the SED registers.

	if (!f.ReadSED1376RegsType (*(SED1376RegsType*) fRegs.GetPtr ()))
	{
		f.SetCanReload (false);
	}

	// Read in the LCD palette.

	if (!f.ReadSED1376Palette (fClutData))
	{
		f.SetCanReload (false);
	}
}


// ---------------------------------------------------------------------------
//		¥ EmRegsSED1376::Dispose
// ---------------------------------------------------------------------------

void EmRegsSED1376::Dispose (void)
{
	EmRegs::Dispose ();
}


// ---------------------------------------------------------------------------
//		¥ EmRegsSED1376::SetSubBankHandlers
// ---------------------------------------------------------------------------

void EmRegsSED1376::SetSubBankHandlers (void)
{
	// Install base handlers.

	EmRegs::SetSubBankHandlers ();

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

	INSTALL_HANDLER (StdReadBE,			NullWrite,				productRevisionCode);
	INSTALL_HANDLER (StdReadBE,			NullWrite,				displayBufferSize);
	INSTALL_HANDLER (StdReadBE,			NullWrite,				configurationReadback);
	INSTALL_HANDLER (StdReadBE,			StdWriteBE,				memoryClockConfiguration);
	INSTALL_HANDLER (StdReadBE,			StdWriteBE,				pixelClockConfiguration);
	INSTALL_HANDLER (StdReadBE,			StdWriteBE,				lutWriteBlue);
	INSTALL_HANDLER (StdReadBE,			StdWriteBE,				lutWriteGreen);
	INSTALL_HANDLER (StdReadBE,			StdWriteBE,				lutWriteRed);
	INSTALL_HANDLER (ZeroRead,			lutWriteAddressWrite,	lutWriteAddress);
	INSTALL_HANDLER (StdReadBE,			NullWrite,				lutReadBlue);
	INSTALL_HANDLER (StdReadBE,			NullWrite,				lutReadGreen);
	INSTALL_HANDLER (StdReadBE,			NullWrite,				lutReadRed);
	INSTALL_HANDLER (ZeroRead,			lutReadAddressWrite,	lutReadAddress);
	INSTALL_HANDLER (StdReadBE,			StdWriteBE,				panelType);
	INSTALL_HANDLER (StdReadBE,			StdWriteBE,				MODRate);
	INSTALL_HANDLER (StdReadBE,			StdWriteBE,				horizontalTotal);
	INSTALL_HANDLER (StdReadBE,			invalidateWrite,		horizontalPeriod);
	INSTALL_HANDLER (StdReadBE,			StdWriteBE,				horizontalPeriodStart0);
	INSTALL_HANDLER (StdReadBE,			StdWriteBE,				horizontalPeriodStart1);
	INSTALL_HANDLER (StdReadBE,			StdWriteBE,				verticalTotal0);
	INSTALL_HANDLER (StdReadBE,			StdWriteBE,				verticalTotal1);
	INSTALL_HANDLER (StdReadBE,			invalidateWrite,		verticalPeriod0);
	INSTALL_HANDLER (StdReadBE,			invalidateWrite,		verticalPeriod1);
	INSTALL_HANDLER (StdReadBE,			StdWriteBE,				verticalPeriodStart0);
	INSTALL_HANDLER (StdReadBE,			StdWriteBE,				verticalPeriodStart1);
	INSTALL_HANDLER (StdReadBE,			StdWriteBE,				FPLINEPulseWidth);
	INSTALL_HANDLER (StdReadBE,			StdWriteBE,				FPLINEPulseStart0);
	INSTALL_HANDLER (StdReadBE,			StdWriteBE,				FPLINEPulseStart1);
	INSTALL_HANDLER (StdReadBE,			StdWriteBE,				FPFRAMEPulseWidth);
	INSTALL_HANDLER (StdReadBE,			StdWriteBE,				FPFRAMEPulseStart0);
	INSTALL_HANDLER (StdReadBE,			StdWriteBE,				FPFRAMEPulseStart1);
	INSTALL_HANDLER (StdReadBE,			StdWriteBE,				DTFD_GCPIndex);
	INSTALL_HANDLER (StdReadBE,			StdWriteBE,				DTFD_GCPData);
	INSTALL_HANDLER (StdReadBE,			invalidateWrite,		displayMode);
	INSTALL_HANDLER (StdReadBE,			invalidateWrite,		specialEffects);
	INSTALL_HANDLER (StdReadBE,			invalidateWrite,		mainStartAddress0);
	INSTALL_HANDLER (StdReadBE,			invalidateWrite,		mainStartAddress1);
	INSTALL_HANDLER (StdReadBE,			invalidateWrite,		mainStartAddress2);
	INSTALL_HANDLER (StdReadBE,			invalidateWrite,		mainLineAddressOffset0);
	INSTALL_HANDLER (StdReadBE,			invalidateWrite,		mainLineAddressOffset1);
	INSTALL_HANDLER (StdReadBE,			invalidateWrite,		ovlyStartAddress0);
	INSTALL_HANDLER (StdReadBE,			invalidateWrite,		ovlyStartAddress1);
	INSTALL_HANDLER (StdReadBE,			invalidateWrite,		ovlyStartAddress2);
	INSTALL_HANDLER (StdReadBE,			invalidateWrite,		ovlyLineAddressOffset0);
	INSTALL_HANDLER (StdReadBE,			invalidateWrite,		ovlyLineAddressOffset1);
	INSTALL_HANDLER (StdReadBE,			invalidateWrite,		ovlyStartXPosition0);
	INSTALL_HANDLER (StdReadBE,			invalidateWrite,		ovlyStartXPosition1);
	INSTALL_HANDLER (StdReadBE,			invalidateWrite,		ovlyStartYPosition0);
	INSTALL_HANDLER (StdReadBE,			invalidateWrite,		ovlyStartYPosition1);
	INSTALL_HANDLER (StdReadBE,			invalidateWrite,		ovlyEndXPosition0);
	INSTALL_HANDLER (StdReadBE,			invalidateWrite,		ovlyEndXPosition1);
	INSTALL_HANDLER (StdReadBE,			invalidateWrite,		ovlyEndYPosition0);
	INSTALL_HANDLER (StdReadBE,			invalidateWrite,		ovlyEndYPosition1);
	INSTALL_HANDLER (powerSaveConfigurationRead,	StdWriteBE,	powerSaveConfiguration);
	INSTALL_HANDLER (StdReadBE,			StdWriteBE,				SoftwareReset);
	INSTALL_HANDLER (StdReadBE,			StdWriteBE,				scratchPad0);
	INSTALL_HANDLER (StdReadBE,			StdWriteBE,				scratchPad1);
	INSTALL_HANDLER (StdReadBE,			StdWriteBE,				GPIOConfiguration0);
	INSTALL_HANDLER (StdReadBE,			StdWriteBE,				GPIOConfiguration1);
	INSTALL_HANDLER (StdReadBE,			StdWriteBE,				GPIOStatusControl0);
	INSTALL_HANDLER (StdReadBE,			StdWriteBE,				GPIOStatusControl1);
	INSTALL_HANDLER (StdReadBE,			StdWriteBE,				PWMClockCVPulseControl);
	INSTALL_HANDLER (StdReadBE,			StdWriteBE,				PWMClockCVPulseConfig);
	INSTALL_HANDLER (StdReadBE,			StdWriteBE,				CVPulseBurstLength);
	INSTALL_HANDLER (StdReadBE,			StdWriteBE,				PWMOutDutyCycle);
}


// ---------------------------------------------------------------------------
//		¥ EmRegsSED1376::GetRealAddress
// ---------------------------------------------------------------------------

uint8* EmRegsSED1376::GetRealAddress (emuptr address)
{
	return (uint8*) fRegs.GetPtr () + address - this->GetAddressStart ();
}


// ---------------------------------------------------------------------------
//		¥ EmRegsSED1376::GetAddressStart
// ---------------------------------------------------------------------------

emuptr EmRegsSED1376::GetAddressStart (void)
{
	return fBaseRegsAddr;
}


// ---------------------------------------------------------------------------
//		¥ EmRegsSED1376::GetAddressRange
// ---------------------------------------------------------------------------

uint32 EmRegsSED1376::GetAddressRange (void)
{
	return fRegs.GetSize ();
}


// ---------------------------------------------------------------------------
//		¥ EmRegsSED1376::GetLCDScreenOn
// ---------------------------------------------------------------------------

Bool EmRegsSED1376::GetLCDScreenOn (void)
{
//	return ((fRegs.displayMode) & sed1376DisplayBlankMask) == 0;
	return ((fRegs.GPIOStatusControl0) & hwrDisplayGPIOLCD_ON) != 0;
}


// ---------------------------------------------------------------------------
//		¥ EmRegsSED1376::GetLCDBacklightOn
// ---------------------------------------------------------------------------

Bool EmRegsSED1376::GetLCDBacklightOn (void)
{
	return ((fRegs.GPIOStatusControl0) & hwrDisplayGPIOEL_ON) != 0;
}


// ---------------------------------------------------------------------------
//		¥ EmRegsSED1376::GetLCDHasFrame
// ---------------------------------------------------------------------------

Bool EmRegsSED1376::GetLCDHasFrame (void)
{
	return true;
}


// ---------------------------------------------------------------------------
//		¥ EmRegsSED1376::invalidateWrite
// ---------------------------------------------------------------------------

void EmRegsSED1376::invalidateWrite (emuptr address, int size, uint32 value)
{
	this->StdWriteBE (address, size, value);
	EmScreen::InvalidateAll ();
}


// ---------------------------------------------------------------------------
//		¥ EmRegsSED1376::powerSaveConfigurationRead
// ---------------------------------------------------------------------------

uint32 EmRegsSED1376::powerSaveConfigurationRead (emuptr 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
	// registers.

	return (fRegs.powerSaveConfiguration) | 0x80;
}


// ---------------------------------------------------------------------------
//		¥ EmRegsSED1376::lutWriteAddressWrite
// ---------------------------------------------------------------------------

void EmRegsSED1376::lutWriteAddressWrite (emuptr address, int size, uint32 value)
{
	UNUSED_PARAM(address)
	UNUSED_PARAM(size)

	value &= 0x0FF;

	uint8	red		= fRegs.lutWriteRed;
	uint8	green	= fRegs.lutWriteGreen;
	uint8	blue	= fRegs.lutWriteBlue;

	fClutData[value] = RGBType ((red & 0xFC) | (red >> 6),
								(green & 0xFC) | (green >> 6),
								(blue & 0xFC) | (blue >> 6));

	EmScreen::InvalidateAll ();
}


// ---------------------------------------------------------------------------
//		¥ EmRegsSED1376::lutReadAddressWrite
// ---------------------------------------------------------------------------

void EmRegsSED1376::lutReadAddressWrite (emuptr address, int size, uint32 value)
{
	UNUSED_PARAM(address)
	UNUSED_PARAM(size)

	value &= 0x0FF;

	RGBType	rgb = fClutData[value];

	fRegs.lutReadRed	= rgb.fRed & 0xFC;
	fRegs.lutReadGreen	= rgb.fGreen & 0xFC;
	fRegs.lutReadBlue	= rgb.fBlue & 0xFC;
}


// ---------------------------------------------------------------------------
//		¥ EmRegsSED1376::PrvGetPalette
// ---------------------------------------------------------------------------

void EmRegsSED1376::PrvGetPalette (RGBList& thePalette)
{
	Bool	mono		= (fRegs.displayMode & sed1376MonoMask) != 0;
	int32	bpp			= 1 << ((fRegs.displayMode & sed1376BPPMask) >> sed1376BPPShift);
	int32	numColors	= 1 << bpp;

	thePalette.resize (numColors);

	for (int ii = 0; ii < numColors; ++ii)
	{
		if (mono)
		{
			uint8	green = fClutData[ii].fGreen;
			thePalette[ii].fRed		= green;
			thePalette[ii].fGreen	= green;
			thePalette[ii].fBlue	= green;
		}
		else
		{
			thePalette[ii] = fClutData[ii];
		}
	}
}


#pragma mark -

// ---------------------------------------------------------------------------
//		¥ EmRegsSED1376VisorPrism::EmRegsSED1376VisorPrism
// ---------------------------------------------------------------------------

EmRegsSED1376VisorPrism::EmRegsSED1376VisorPrism (emuptr baseRegsAddr,
												  emuptr baseVideoAddr) :
	EmRegsSED1376 (baseRegsAddr, baseVideoAddr)
{
}


// ---------------------------------------------------------------------------
//		¥ EmRegsSED1376VisorPrism::~EmRegsSED1376VisorPrism
// ---------------------------------------------------------------------------

EmRegsSED1376VisorPrism::~EmRegsSED1376VisorPrism (void)
{
}


// ---------------------------------------------------------------------------
//		¥ EmRegsSED1376VisorPrism::SetSubBankHandlers
// ---------------------------------------------------------------------------

void EmRegsSED1376VisorPrism::SetSubBankHandlers (void)
{
	// Install base handlers.

	EmRegsSED1376::SetSubBankHandlers ();

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

#undef INSTALL_HANDLER
#define INSTALL_HANDLER(read, write, reg)			\
	this->SetHandler (	(ReadFunction) &EmRegsSED1376VisorPrism::read,		\
						(WriteFunction) &EmRegsSED1376VisorPrism::write,		\
						addressof (reg),			\
						fRegs.reg.GetSize ())

	INSTALL_HANDLER (StdReadBE,			reservedWrite,			reserved);
}


// ---------------------------------------------------------------------------
//		¥ EmRegsSED1376VisorPrism::GetLCDBeginEnd
// ---------------------------------------------------------------------------

void EmRegsSED1376VisorPrism::GetLCDBeginEnd (emuptr& begin, emuptr& end)
{
	// Get the screen metrics.

	// The hardware is written to in reverse, so the mainStartOffsetX registers 
	// report the END of the frame buffer, not the beginning.
	emuptr	baseAddr	= fBaseVideoAddr;

	int32	width		= ((fRegs.horizontalPeriod + 1) * 8);
	int32	height		= ((fRegs.verticalPeriod1 << 8) | fRegs.verticalPeriod0) + 1;
	int32	rowBytes	= ((width * this->PrvGetLCDDepth ()) / 8);

	begin = baseAddr;
	end = baseAddr + rowBytes * height;
}


// ---------------------------------------------------------------------------
//		¥ EmRegsSED1376VisorPrism::GetLCDScanlines
// ---------------------------------------------------------------------------

void EmRegsSED1376VisorPrism::GetLCDScanlines (EmScreenUpdateInfo& info)
{
	// Get the screen metrics.

	Bool	byteSwapped	= (fRegs.specialEffects & sed1376ByteSwapMask) != 0;
	Bool	mono		= (fRegs.displayMode & sed1376MonoMask) != 0;
	int32	bpp			= 1 << ((fRegs.displayMode & sed1376BPPMask) >> sed1376BPPShift);

	// The hardware is written to in reverse, so the mainStartOffsetX registers 
	// report the END of the frame buffer, not the beginning.
	emuptr	baseAddr	= fBaseVideoAddr;

	int32	width		= ((fRegs.horizontalPeriod + 1) * 8);
	int32	height		= ((fRegs.verticalPeriod1 << 8) | fRegs.verticalPeriod0) + 1;
	int32	rowBytes	= ((width * this->PrvGetLCDDepth ()) / 8);

	info.fLeftMargin	= 0;

	if (bpp <= 8)
	{
		EmPixMapFormat	format	=	bpp == 1 ? kPixMapFormat1 :
									bpp == 2 ? kPixMapFormat2 :
									bpp == 4 ? kPixMapFormat4 :
									kPixMapFormat8;

		RGBList	colorTable;
		this->PrvGetPalette (colorTable);

		// Set format, size, and color table of EmPixMap.

		info.fImage.SetSize			(EmPoint (width, height));
		info.fImage.SetFormat		(format);
		info.fImage.SetRowBytes		(rowBytes);
		info.fImage.SetColorTable	(colorTable);

		// Determine first and last scanlines to fetch, and fetch them.

		info.fFirstLine		= (info.fScreenLow - baseAddr) / rowBytes;
		info.fLastLine		= (info.fScreenHigh - baseAddr - 1) / rowBytes + 1;

		long	firstLineOffset	= info.fFirstLine * rowBytes;
		long	lastLineOffset	= info.fLastLine * rowBytes;

		EmMem_memcpy (
			(void*) ((uint8*) info.fImage.GetBits () + firstLineOffset),
			baseAddr + firstLineOffset,
			lastLineOffset - firstLineOffset);
	}
	else
	{
		// Set depth, size, and color table of EmPixMap.

		info.fImage.SetSize (EmPoint (width, height));
		info.fImage.SetFormat (kPixMapFormat24RGB);

		// Determine first and last scanlines to fetch.

		info.fFirstLine		= (info.fScreenLow - baseAddr) / rowBytes;
		info.fLastLine		= (info.fScreenHigh - baseAddr - 1) / rowBytes + 1;

		// Get location and rowBytes of source bytes.

		uint8*	srcStart		= EmMemGetRealAddress (baseAddr);
		int32	srcRowBytes		= rowBytes;
		uint8*	srcPtr			= srcStart + srcRowBytes * info.fFirstLine;
		uint8*	srcPtr0			= srcPtr;

		// Get location and rowBytes of destination bytes.

		uint8*	destStart		= (uint8*) info.fImage.GetBits ();
		int32	destRowBytes	= info.fImage.GetRowBytes ();
		uint8*	destPtr			= destStart + destRowBytes * info.fFirstLine;
		uint8*	destPtr0		= destPtr;

		// Get height of range to copy.

		int32	height = info.fLastLine - info.fFirstLine;

		// Copy the pixels from source to dest.

		for (int yy = 0; yy < height; ++yy)
		{
			for (int xx = 0; xx < width; ++xx)
			{
				uint8	p1 = EmMemDoGet8 (srcPtr++);	// GGGBBBBB
				uint8	p2 = EmMemDoGet8 (srcPtr++);	// RRRRRGGG

				// Merge the two together so that we get RRRRRGGG GGGBBBBB

				uint16	p;

				if (!byteSwapped)
					p = (p2 << 8) | p1;
				else
					p = (p1 << 8) | p2;

				// Shift the bits around, forming RRRRRrrr, GGGGGGgg, and
				// BBBBBbbb values, where the lower-case bits are copies of
				// the least significant bits in the upper-case bits.
				//
				// Note that all of this could also be done with three 64K
				// lookup tables.  If speed is an issue, we might want to
				// investigate that.

				if (mono)
				{
					uint8	green = ((p >> 3) & 0xFC) | ((p >>  5) & 0x03);
					*destPtr++ = green;
					*destPtr++ = green;
					*destPtr++ = green;
				}
				else
				{
					*destPtr++ = ((p >> 8) & 0xF8) | ((p >> 11) & 0x07);
					*destPtr++ = ((p >> 3) & 0xFC) | ((p >>  5) & 0x03);
					*destPtr++ = ((p << 3) & 0xF8) | ((p >>  0) & 0x07);
				}
			}

			srcPtr	= srcPtr0 += srcRowBytes;
			destPtr	= destPtr0 += destRowBytes;
		}
	}
}


// ---------------------------------------------------------------------------
//		¥ EmRegsSED1376VisorPrism::PrvGetLCDDepth
// ---------------------------------------------------------------------------

int32 EmRegsSED1376VisorPrism::PrvGetLCDDepth (void)
{
	UInt8	depth = fRegs.displayMode;

	depth &= sed1376DisplayModeDepthMask;

	switch (depth)
	{ 
		case sed1376DisplayModeDepth16: return 16;		
		case sed1376DisplayModeDepth8:  return 8;
		case sed1376DisplayModeDepth4:  return 4;
		case sed1376DisplayModeDepth2:  return 2;
		case sed1376DisplayModeDepth1:  return 1;
		default: EmAssert (false);
	}

	return 8;
}


// ---------------------------------------------------------------------------
//		¥ EmRegsSED1376VisorPrism::reservedWrite
// ---------------------------------------------------------------------------

void EmRegsSED1376VisorPrism::reservedWrite (emuptr address, int size, uint32 value)
{
	UNUSED_PARAM (address);
	UNUSED_PARAM (size);
	UNUSED_PARAM (value);
}


#pragma mark -

// ---------------------------------------------------------------------------
//		¥ EmRegsSED1376PalmGeneric::EmRegsSED1376PalmGeneric
// ---------------------------------------------------------------------------

EmRegsSED1376PalmGeneric::EmRegsSED1376PalmGeneric (emuptr baseRegsAddr,
													emuptr baseVideoAddr) :
	EmRegsSED1376 (baseRegsAddr, baseVideoAddr)
{
}


// ---------------------------------------------------------------------------
//		¥ EmRegsSED1376PalmGeneric::~EmRegsSED1376PalmGeneric
// ---------------------------------------------------------------------------

EmRegsSED1376PalmGeneric::~EmRegsSED1376PalmGeneric (void)
{
}


// ---------------------------------------------------------------------------
//		¥ EmRegsSED1376PalmGeneric::GetLCDBeginEnd
// ---------------------------------------------------------------------------

void EmRegsSED1376PalmGeneric::GetLCDBeginEnd (emuptr& begin, emuptr& end)
{
	// Get the screen metrics.

//	Bool	wordSwapped	= (fRegs.specialEffects & sed1376WordSwapMask) != 0;
//	Bool	byteSwapped	= (fRegs.specialEffects & sed1376ByteSwapMask) != 0;
//	int32	bpp			= 1 << ((fRegs.displayMode & sed1376BPPMask) >> sed1376BPPShift);
#if !OVERLAY_IS_MAIN
//	int32	width		= ((fRegs.horizontalPeriod + 1) * 8);
	int32	height		= ((fRegs.verticalPeriod1 << 8) | fRegs.verticalPeriod0) + 1;
	int32	rowBytes	= ((fRegs.mainLineAddressOffset1 << 8) | fRegs.mainLineAddressOffset0) * 4;
	uint32	offset		= (fRegs.mainStartAddress2 << 18) |
						  (fRegs.mainStartAddress1 << 10) |
						  (fRegs.mainStartAddress0 <<  2);
#else
//	int32	left		= ((fRegs.ovlyStartXPosition1	<< 8) | fRegs.ovlyStartXPosition0)	* 32 / bpp;
//	int32	right		= ((fRegs.ovlyEndXPosition1		<< 8) | fRegs.ovlyEndXPosition0)	* 32 / bpp;
	int32	top			= ((fRegs.ovlyStartYPosition1	<< 8) | fRegs.ovlyStartYPosition0);
	int32	bottom		= ((fRegs.ovlyEndYPosition1		<< 8) | fRegs.ovlyEndYPosition0);

//	int32	width		= right - left + (32 / bpp);
	int32	height		= bottom - top + 1;
	int32	rowBytes	= ((fRegs.ovlyLineAddressOffset1 << 8) | fRegs.ovlyLineAddressOffset0) * 4;
	uint32	offset		= (fRegs.ovlyStartAddress2 << 18) |
						  (fRegs.ovlyStartAddress1 << 10) |
						  (fRegs.ovlyStartAddress0 <<  2);
#endif
	emuptr	baseAddr	= fBaseVideoAddr + offset;

	begin = baseAddr;
	end = baseAddr + rowBytes * height;
}


// ---------------------------------------------------------------------------
//		¥ EmRegsSED1376PalmGeneric::GetLCDScanlines
// ---------------------------------------------------------------------------

void EmRegsSED1376PalmGeneric::GetLCDScanlines (EmScreenUpdateInfo& info)
{
	// Get the screen metrics.

//	Bool	wordSwapped	= (fRegs.specialEffects & sed1376WordSwapMask) != 0;
	Bool	byteSwapped	= (fRegs.specialEffects & sed1376ByteSwapMask) != 0;
	Bool	mono		= (fRegs.displayMode & sed1376MonoMask) != 0;
	int32	bpp			= 1 << ((fRegs.displayMode & sed1376BPPMask) >> sed1376BPPShift);
#if !OVERLAY_IS_MAIN
	int32	width		= ((fRegs.horizontalPeriod + 1) * 8);
	int32	height		= ((fRegs.verticalPeriod1 << 8) | fRegs.verticalPeriod0) + 1;
	int32	rowBytes	= ((fRegs.mainLineAddressOffset1 << 8) | fRegs.mainLineAddressOffset0) * 4;
	uint32	offset		= (fRegs.mainStartAddress2 << 18) |
						  (fRegs.mainStartAddress1 << 10) |
						  (fRegs.mainStartAddress0 <<  2);
#else
	int32	left		= ((fRegs.ovlyStartXPosition1	<< 8) | fRegs.ovlyStartXPosition0)	* 32 / bpp;
	int32	right		= ((fRegs.ovlyEndXPosition1		<< 8) | fRegs.ovlyEndXPosition0)	* 32 / bpp;
	int32	top			= ((fRegs.ovlyStartYPosition1	<< 8) | fRegs.ovlyStartYPosition0);
	int32	bottom		= ((fRegs.ovlyEndYPosition1		<< 8) | fRegs.ovlyEndYPosition0);

	int32	width		= right - left + (32 / bpp);
	int32	height		= bottom - top + 1;
	int32	rowBytes	= ((fRegs.ovlyLineAddressOffset1 << 8) | fRegs.ovlyLineAddressOffset0) * 4;
	uint32	offset		= (fRegs.ovlyStartAddress2 << 18) |
						  (fRegs.ovlyStartAddress1 << 10) |
						  (fRegs.ovlyStartAddress0 <<  2);
#endif
	emuptr	baseAddr	= fBaseVideoAddr + offset;

	info.fLeftMargin	= 0;

	if (bpp <= 8)
	{
		EmPixMapFormat	format	=	bpp == 1 ? kPixMapFormat1 :
									bpp == 2 ? kPixMapFormat2 :
									bpp == 4 ? kPixMapFormat4 :
									kPixMapFormat8;

		RGBList	colorTable;
		this->PrvGetPalette (colorTable);

		// Set format, size, and color table of EmPixMap.

		info.fImage.SetSize			(EmPoint (width, height));
		info.fImage.SetFormat		(format);
		info.fImage.SetRowBytes		(rowBytes);
		info.fImage.SetColorTable	(colorTable);

		// Determine first and last scanlines to fetch, and fetch them.

		info.fFirstLine		= (info.fScreenLow - baseAddr) / rowBytes;
		info.fLastLine		= (info.fScreenHigh - baseAddr - 1) / rowBytes + 1;

		long	firstLineOffset	= info.fFirstLine * rowBytes;
		long	lastLineOffset	= info.fLastLine * rowBytes;

		EmMem_memcpy (
			(void*) ((uint8*) info.fImage.GetBits () + firstLineOffset),
			baseAddr + firstLineOffset,
			lastLineOffset - firstLineOffset);
	}
	else
	{
		// Set depth, size, and color table of EmPixMap.

		info.fImage.SetSize (EmPoint (width, height));
		info.fImage.SetFormat (kPixMapFormat24RGB);

		// Determine first and last scanlines to fetch.

		info.fFirstLine		= (info.fScreenLow - baseAddr) / rowBytes;
		info.fLastLine		= (info.fScreenHigh - baseAddr - 1) / rowBytes + 1;

		// Get location and rowBytes of source bytes.

		uint8*	srcStart		= EmMemGetRealAddress (baseAddr);
		int32	srcRowBytes		= rowBytes;
		uint8*	srcPtr			= srcStart + srcRowBytes * info.fFirstLine;
		uint8*	srcPtr0			= srcPtr;

		// Get location and rowBytes of destination bytes.

		uint8*	destStart		= (uint8*) info.fImage.GetBits ();
		int32	destRowBytes	= info.fImage.GetRowBytes ();
		uint8*	destPtr			= destStart + destRowBytes * info.fFirstLine;
		uint8*	destPtr0		= destPtr;

		// Get height of range to copy.

		int32	height = info.fLastLine - info.fFirstLine;

		// Copy the pixels from source to dest.

		for (int yy = 0; yy < height; ++yy)
		{
			for (int xx = 0; xx < width; ++xx)
			{
				uint8	p1 = EmMemDoGet8 (srcPtr++);	// GGGBBBBB
				uint8	p2 = EmMemDoGet8 (srcPtr++);	// RRRRRGGG

				// Merge the two together so that we get RRRRRGGG GGGBBBBB

				uint16	p;

				if (!byteSwapped)
					p = (p2 << 8) | p1;
				else
					p = (p1 << 8) | p2;

				// Shift the bits around, forming RRRRRrrr, GGGGGGgg, and
				// BBBBBbbb values, where the lower-case bits are copies of
				// the least significant bits in the upper-case bits.
				//
				// Note that all of this could also be done with three 64K
				// lookup tables.  If speed is an issue, we might want to
				// investigate that.

				if (mono)
				{
					uint8	green = ((p >> 3) & 0xFC) | ((p >>  5) & 0x03);
					*destPtr++ = green;
					*destPtr++ = green;
					*destPtr++ = green;
				}
				else
				{
					*destPtr++ = ((p >> 8) & 0xF8) | ((p >> 11) & 0x07);
					*destPtr++ = ((p >> 3) & 0xFC) | ((p >>  5) & 0x03);
					*destPtr++ = ((p << 3) & 0xF8) | ((p >>  0) & 0x07);
				}
			}

			srcPtr	= srcPtr0 += srcRowBytes;
			destPtr	= destPtr0 += destRowBytes;
		}
	}

	if (!this->GetLCDBacklightOn ())
	{
		info.fImage.ChangeTone (-10, info.fFirstLine, info.fLastLine);
	}
}