aboutsummaryrefslogtreecommitdiff
path: root/SrcShared/Hardware/EmRegsVZTemp.cpp
blob: 36a8521cfa91d6097354adb557ab2016b7a1c260 (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
/* -*- 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 "EmRegsVZTemp.h"
#include "EmRegsVZPrv.h"

#include "EmSPISlaveADS784x.h"	// EmSPISlaveADS784x
#include "EmTransportSerial.h"	// EmTransportSerial


const int		kNumButtonRows = 3;
const int		kNumButtonCols = 4;

const uint16	kButtonMap[kNumButtonRows][kNumButtonCols] =
{
	{ keyBitHard1,	keyBitHard2,	keyBitHard3,	keyBitHard4 },
	{ keyBitPageUp,	keyBitPageDown,	0,				0 },
	{ keyBitPower,	keyBitContrast,	keyBitHard2,	0 }
};



#pragma mark -
#define  hwrVZPortBRADIO_DTR			0x40	// (L) Radio DTR
#define hwrVZPortKRADIO_DSR				0x02	// Radio DTR

#define	hwrVZPalmI705PortDTWISTIRQ		0x20	// Twister IRQ (IRQ2)
#define	hwrVZPalmI705PortDPowerFail	0x80	// (L) Power Fail interrupt (aka IRQ6)

#define	hwrVZPalmI705PortGEL_ON		0x02	// (L) EL_ON
#define	hwrVZPalmI705PortGLCD_DISP_ON	0x04	// (H) LCD_DISP_ON
#define	hwrVZPalmI705PortG232_SHDN_N	0x08	// (L) 232_SHDN#
#define	hwrVZPalmI705PortGADC_CS_N		0x20	// (H) ADC_CS#

#define	hwrVZPalmI705PortKVIB_EN		0x10	// vibarator enable/disable
#define	hwrVZPalmI705PortKKbdRow0		0x20	// (H) Keyboard Row 0
#define	hwrVZPalmI705PortKKbdRow1		0x40	// (H) Keyboard Row 1
#define	hwrVZPalmI705PortKKbdRow2		0x80	// (H) Keyboard Row 2

#define	hwrVZPalmI705PortMIR_SD		0x20	// (L) Infrared Shut-down (UART 2)

// ---------------------------------------------------------------------------
//		¥ EmRegsVZPalmI705::EmRegsVZPalmI705
// ---------------------------------------------------------------------------

EmRegsVZPalmI705::EmRegsVZPalmI705 (void) :
	EmRegsVZ (),
	fSPISlaveADC (new EmSPISlaveADS784x (kChannelSet1))
{
}


// ---------------------------------------------------------------------------
//		¥ EmRegsVZPalmI705::~EmRegsVZPalmI705
// ---------------------------------------------------------------------------

EmRegsVZPalmI705::~EmRegsVZPalmI705 (void)
{
	delete fSPISlaveADC;
}


// ---------------------------------------------------------------------------
//		¥ EmRegsVZPalmI705::GetLCDScreenOn
// ---------------------------------------------------------------------------

Bool EmRegsVZPalmI705::GetLCDScreenOn (void)
{
	return (READ_REGISTER (portGData) & hwrVZPalmI705PortGLCD_DISP_ON) != 0;
}


// ---------------------------------------------------------------------------
//		¥ EmRegsVZPalmI705::GetLCDBacklightOn
// ---------------------------------------------------------------------------

Bool EmRegsVZPalmI705::GetLCDBacklightOn (void)
{
	return (READ_REGISTER (portGData) & hwrVZPalmI705PortGEL_ON) != 0;
}


// ---------------------------------------------------------------------------
//		¥ EmRegsVZPalmI705::GetLineDriverState
// ---------------------------------------------------------------------------
// Return whether or not the line drivers for the given object are open or
// closed.

Bool EmRegsVZPalmI705::GetLineDriverState (EmUARTDeviceType type)
{
	if (type == kUARTSerial)
		return (READ_REGISTER (portGData) & hwrVZPalmI705PortG232_SHDN_N) != 0;

	if (type == kUARTIR)
		return (READ_REGISTER (portMData) & hwrVZPalmI705PortMIR_SD) == 0;

	return false;
}


// ---------------------------------------------------------------------------
//		¥ EmRegsVZPalmI705::GetUARTDevice
// ---------------------------------------------------------------------------
// Return what sort of device is hooked up to the given UART.

EmUARTDeviceType EmRegsVZPalmI705::GetUARTDevice (int uartNum)
{
	Bool	serEnabled	= this->GetLineDriverState (kUARTSerial);
	Bool	irEnabled	= this->GetLineDriverState (kUARTIR);

	// It's probably an error to have them both enabled at the same
	// time.  !!! TBD: make this an error message.

	EmAssert (!(serEnabled && irEnabled));

	/*
		From Van Oler:

			UART #2 is used for serial (rs-232) and IR.  The rs-232 receiver
			and the IR receiver are tristate outouts with individual enables
			to control which one drives the RXD2 input.

			UART1 is not used; only the pins are used for GPIO.

			The Master SPI (on PE0,1,2) is used for data to and from the
			touchscreen A/D and the radio DSP.  Each has individual selects.

			The Master/Slave SPI (on PJ0,1,2) is used for the MMC/SD card slot.

			There is a separate USB chip, the same as tornado.
	*/

	if (uartNum == 1)
	{
		if (serEnabled)
			return kUARTSerial;

		if (irEnabled)
			return kUARTIR;
	}

	return kUARTNone;
}


// ---------------------------------------------------------------------------
//		¥ EmRegsVZPalmI705::GetVibrateOn
// ---------------------------------------------------------------------------

Bool EmRegsVZPalmI705::GetVibrateOn (void)
{
	return (READ_REGISTER (portKData) & hwrVZPalmI705PortKVIB_EN) != 0;
}


// ---------------------------------------------------------------------------
//		¥ EmRegsVZPalmI705::GetPortInputValue
// ---------------------------------------------------------------------------
// Return the GPIO values for the pins on the port.  These values are used
// if the select pins are high.

uint8 EmRegsVZPalmI705::GetPortInputValue (int port)
{
	uint8	result = EmRegsVZ::GetPortInputValue (port);

	return result;
}


// ---------------------------------------------------------------------------
//		¥ EmRegsVZPalmI705::GetPortInternalValue
// ---------------------------------------------------------------------------
// Return the dedicated values for the pins on the port.  These values are
// used if the select pins are low.

uint8 EmRegsVZPalmI705::GetPortInternalValue (int port)
{
	uint8	result = EmRegsVZ::GetPortInternalValue (port);

	if (port == 'D')
	{
		// Make sure that hwrVZPortDPowerFail is set.  If it's clear,
		// the battery code will make the device go to sleep immediately.
		//
		// Also make sure that hwrVZPalmI705PortDTWISTIRQ is set.  If it's clear,
		// the slot driver will think there's a card installed and will try querying it.

		result |= hwrVZPalmI705PortDPowerFail | hwrVZPalmI705PortDTWISTIRQ;
	}

	return result;
}


// ---------------------------------------------------------------------------
//		¥ EmRegsVZPalmI705::GetKeyInfo
// ---------------------------------------------------------------------------

void EmRegsVZPalmI705::GetKeyInfo (int* numRows, int* numCols,
								uint16* keyMap, Bool* rows)
{
	*numRows = kNumButtonRows;
	*numCols = kNumButtonCols;

	memcpy (keyMap, kButtonMap, sizeof (kButtonMap));

	// Determine what row is being asked for.

	UInt8	portKDir	= READ_REGISTER (portKDir);
	UInt8	portKData	= READ_REGISTER (portKData);

	rows[0]	= (portKDir & hwrVZPalmI705PortKKbdRow0) != 0 && (portKData & hwrVZPalmI705PortKKbdRow0) == 0;
	rows[1]	= (portKDir & hwrVZPalmI705PortKKbdRow1) != 0 && (portKData & hwrVZPalmI705PortKKbdRow1) == 0;
	rows[2]	= (portKDir & hwrVZPalmI705PortKKbdRow2) != 0 && (portKData & hwrVZPalmI705PortKKbdRow2) == 0;
}


// ---------------------------------------------------------------------------
//		¥ EmRegsVZPalmI705::GetSPISlave
// ---------------------------------------------------------------------------

EmSPISlave* EmRegsVZPalmI705::GetSPISlave (void)
{
	if ((READ_REGISTER (portGData) & hwrVZPalmI705PortGADC_CS_N) == 0)
	{
		return fSPISlaveADC;
	}

	return NULL;
}




#pragma mark -

#define	hwrVZPalmM125PortDTWISTIRQ		0x20	// Twister IRQ (IRQ2)
#define	hwrVZPalmM125PortDPowerFail	0x80	// (L) Power Fail interrupt (aka IRQ6)

#define	hwrVZPalmM125PortGEL_ON		0x02	// (L) EL_ON
#define	hwrVZPalmM125PortGLCD_DISP_ON	0x04	// (H) LCD_DISP_ON
#define	hwrVZPalmM125PortG232_SHDN_N	0x08	// (L) 232_SHDN#
#define	hwrVZPalmM125PortGADC_CS_N		0x20	// (H) ADC_CS#

#define	hwrVZPalmM125PortKIRShutdown	0x04	// (-) IR_SHDN
#define	hwrVZPalmM125PortKVIB_EN		0x10	// vibarator enable/disable
#define	hwrVZPalmM125PortKKbdRow0		0x20	// (H) Keyboard Row 0
#define	hwrVZPalmM125PortKKbdRow1		0x40	// (H) Keyboard Row 1
#define	hwrVZPalmM125PortKKbdRow2		0x80	// (H) Keyboard Row 2

const uint16	kButtonMapPalmM125[kNumButtonRows][kNumButtonCols] =
{
	{ keyBitHard1,	keyBitHard2,	keyBitHard3,	keyBitHard4 },
	{ 0,			keyBitPageDown,	0,				0 },
	{ keyBitPower,	keyBitPageUp,	0,				0 }
};

// ---------------------------------------------------------------------------
//		¥ EmRegsVZPalmM125::EmRegsVZPalmM125
// ---------------------------------------------------------------------------

EmRegsVZPalmM125::EmRegsVZPalmM125 (void) :
	EmRegsVZ (),
	fSPISlaveADC (new EmSPISlaveADS784x (kChannelSet3))
{
}


// ---------------------------------------------------------------------------
//		¥ EmRegsVZPalmM125::~EmRegsVZPalmM125
// ---------------------------------------------------------------------------

EmRegsVZPalmM125::~EmRegsVZPalmM125 (void)
{
	delete fSPISlaveADC;
}


// ---------------------------------------------------------------------------
//		¥ EmRegsVZPalmM125::GetLCDScreenOn
// ---------------------------------------------------------------------------

Bool EmRegsVZPalmM125::GetLCDScreenOn (void)
{
	return (READ_REGISTER (portKData) & 0x02) != 0;
}


// ---------------------------------------------------------------------------
//		¥ EmRegsVZPalmM125::GetLCDBacklightOn
// ---------------------------------------------------------------------------

Bool EmRegsVZPalmM125::GetLCDBacklightOn (void)
{
	return (READ_REGISTER (portFData) & 0x10) != 0;
}


// ---------------------------------------------------------------------------
//		¥ EmRegsVZPalmM125::GetLineDriverState
// ---------------------------------------------------------------------------
// Return whether or not the line drivers for the given object are open or
// closed.

Bool EmRegsVZPalmM125::GetLineDriverState (EmUARTDeviceType type)
{
	if (type == kUARTSerial)
		return (READ_REGISTER (portEData) & 0x40) != 0;

	if (type == kUARTIR)
		return (READ_REGISTER (portKData) & hwrVZPalmM125PortKIRShutdown) == 0;

	return false;
}


// ---------------------------------------------------------------------------
//		¥ EmRegsVZPalmM125::GetUARTDevice
// ---------------------------------------------------------------------------
// Return what sort of device is hooked up to the given UART.

EmUARTDeviceType EmRegsVZPalmM125::GetUARTDevice (int uartNum)
{
	Bool	serEnabled	= this->GetLineDriverState (kUARTSerial);
	Bool	irEnabled	= this->GetLineDriverState (kUARTIR);

	// It's probably an error to have them both enabled at the same
	// time.  !!! TBD: make this an error message.

	EmAssert (!(serEnabled && irEnabled));

	if (uartNum == 0)
	{
		if (irEnabled)
			return kUARTIR;
	}
	else if (uartNum == 1)
	{
		if (serEnabled)
			return kUARTSerial;
	}

	return kUARTNone;
}


// ---------------------------------------------------------------------------
//		¥ EmRegsVZPalmM125::GetPortInputValue
// ---------------------------------------------------------------------------
// Return the GPIO values for the pins on the port.  These values are used
// if the select pins are high.

uint8 EmRegsVZPalmM125::GetPortInputValue (int port)
{
	uint8	result = EmRegsVZ::GetPortInputValue (port);

	return result;
}


// ---------------------------------------------------------------------------
//		¥ EmRegsVZPalmM125::GetPortInternalValue
// ---------------------------------------------------------------------------
// Return the dedicated values for the pins on the port.  These values are
// used if the select pins are low.

uint8 EmRegsVZPalmM125::GetPortInternalValue (int port)
{
	uint8	result = EmRegsVZ::GetPortInternalValue (port);

	if (port == 'D')
	{
		// Make sure that hwrVZPortDPowerFail is set.  If it's clear,
		// the battery code will make the device go to sleep immediately.
		//
		// Also make sure that hwrVZPalmM125PortDTWISTIRQ is set.  If it's clear,
		// the slot driver will think there's a card installed and will try querying it.

		result |= hwrVZPalmM125PortDPowerFail | hwrVZPalmM125PortDTWISTIRQ;
	}

	return result;
}


// ---------------------------------------------------------------------------
//		¥ EmRegsVZPalmM125::GetKeyInfo
// ---------------------------------------------------------------------------

void EmRegsVZPalmM125::GetKeyInfo (int* numRows, int* numCols,
								uint16* keyMap, Bool* rows)
{
	*numRows = kNumButtonRows;
	*numCols = kNumButtonCols;

	memcpy (keyMap, kButtonMapPalmM125, sizeof (kButtonMapPalmM125));

	// Determine what row is being asked for.

	UInt8	portKDir	= READ_REGISTER (portKDir);
	UInt8	portKData	= READ_REGISTER (portKData);

	rows[0]	= (portKDir & hwrVZPalmM125PortKKbdRow0) != 0 && (portKData & hwrVZPalmM125PortKKbdRow0) == 0;
	rows[1]	= (portKDir & hwrVZPalmM125PortKKbdRow1) != 0 && (portKData & hwrVZPalmM125PortKKbdRow1) == 0;
	rows[2]	= (portKDir & hwrVZPalmM125PortKKbdRow2) != 0 && (portKData & hwrVZPalmM125PortKKbdRow2) == 0;
}


// ---------------------------------------------------------------------------
//		¥ EmRegsVZPalmM125::GetSPISlave
// ---------------------------------------------------------------------------

EmSPISlave* EmRegsVZPalmM125::GetSPISlave (void)
{
	if ((READ_REGISTER (portGData) & hwrVZPalmM125PortGADC_CS_N) == 0)
	{
		return fSPISlaveADC;
	}

	return NULL;
}


#pragma mark -

#define	hwrVZPalmM130PortDTWISTIRQ		0x20	// Twister IRQ (IRQ2)
#define	hwrVZPalmM130PortDPowerFail	0x80	// (L) Power Fail interrupt (aka IRQ6)

#define	hwrVZPalmM130PortGEL_ON		0x02	// (L) EL_ON
#define	hwrVZPalmM130PortGLCD_DISP_ON	0x04	// (H) LCD_DISP_ON
#define	hwrVZPalmM130PortG232_SHDN_N	0x08	// (L) 232_SHDN#
#define	hwrVZPalmM130PortGADC_CS_N		0x20	// (H) ADC_CS#

#define	hwrVZPalmM130PortKIRShutdown	0x04	// (-) IR_SHDN
#define	hwrVZPalmM130PortKVIB_EN		0x10	// vibarator enable/disable
#define	hwrVZPalmM130PortKKbdRow0		0x20	// (H) Keyboard Row 0
#define	hwrVZPalmM130PortKKbdRow1		0x40	// (H) Keyboard Row 1
#define	hwrVZPalmM130PortKKbdRow2		0x80	// (H) Keyboard Row 2

const uint16	kButtonMapPalmM130[kNumButtonRows][kNumButtonCols] =
{
	{ keyBitHard1,	keyBitHard2,	keyBitHard3,	keyBitHard4 },
	{ 0,			keyBitPageDown,	0,				0 },
	{ keyBitPower,	keyBitPageUp,	0,				0 }
};

// ---------------------------------------------------------------------------
//		¥ EmRegsVZPalmM130::EmRegsVZPalmM130
// ---------------------------------------------------------------------------

EmRegsVZPalmM130::EmRegsVZPalmM130 (void) :
	EmRegsVZ (),
	fSPISlaveADC (new EmSPISlaveADS784x (kChannelSet1))
{
}


// ---------------------------------------------------------------------------
//		¥ EmRegsVZPalmM130::~EmRegsVZPalmM130
// ---------------------------------------------------------------------------

EmRegsVZPalmM130::~EmRegsVZPalmM130 (void)
{
	delete fSPISlaveADC;
}


// ---------------------------------------------------------------------------
//		¥ EmRegsVZPalmM130::GetLCDScreenOn
// ---------------------------------------------------------------------------

Bool EmRegsVZPalmM130::GetLCDScreenOn (void)
{
	return (READ_REGISTER (portKData) & 0x02) != 0;
}


// ---------------------------------------------------------------------------
//		¥ EmRegsVZPalmM130::GetLCDBacklightOn
// ---------------------------------------------------------------------------

Bool EmRegsVZPalmM130::GetLCDBacklightOn (void)
{
	return (READ_REGISTER (portFData) & 0x10) != 0;
}


// ---------------------------------------------------------------------------
//		¥ EmRegsVZPalmM130::GetLineDriverState
// ---------------------------------------------------------------------------
// Return whether or not the line drivers for the given object are open or
// closed.

Bool EmRegsVZPalmM130::GetLineDriverState (EmUARTDeviceType type)
{
	if (type == kUARTSerial)
		return (READ_REGISTER (portEData) & 0x40) != 0;

	if (type == kUARTIR)
		return (READ_REGISTER (portKData) & hwrVZPalmM130PortKIRShutdown) == 0;

	return false;
}


// ---------------------------------------------------------------------------
//		¥ EmRegsVZPalmM130::GetUARTDevice
// ---------------------------------------------------------------------------
// Return what sort of device is hooked up to the given UART.

EmUARTDeviceType EmRegsVZPalmM130::GetUARTDevice (int uartNum)
{
	Bool	serEnabled	= this->GetLineDriverState (kUARTSerial);
	Bool	irEnabled	= this->GetLineDriverState (kUARTIR);

	// It's probably an error to have them both enabled at the same
	// time.  !!! TBD: make this an error message.

	EmAssert (!(serEnabled && irEnabled));

	if (uartNum == 0)
	{
		if (irEnabled)
			return kUARTIR;
	}
	else if (uartNum == 1)
	{
		if (serEnabled)
			return kUARTSerial;
	}

	return kUARTNone;
}


// ---------------------------------------------------------------------------
//		¥ EmRegsVZPalmM130::GetPortInputValue
// ---------------------------------------------------------------------------
// Return the GPIO values for the pins on the port.  These values are used
// if the select pins are high.

uint8 EmRegsVZPalmM130::GetPortInputValue (int port)
{
	uint8	result = EmRegsVZ::GetPortInputValue (port);

	return result;
}


// ---------------------------------------------------------------------------
//		¥ EmRegsVZPalmM130::GetPortInternalValue
// ---------------------------------------------------------------------------
// Return the dedicated values for the pins on the port.  These values are
// used if the select pins are low.

uint8 EmRegsVZPalmM130::GetPortInternalValue (int port)
{
	uint8	result = EmRegsVZ::GetPortInternalValue (port);

	if (port == 'D')
	{
		// Make sure that hwrVZPortDPowerFail is set.  If it's clear,
		// the battery code will make the device go to sleep immediately.
		//
		// Also make sure that hwrVZPalmM130PortDTWISTIRQ is set.  If it's clear,
		// the slot driver will think there's a card installed and will try querying it.

		result |= hwrVZPalmM130PortDPowerFail | hwrVZPalmM130PortDTWISTIRQ;
	}

	return result;
}


// ---------------------------------------------------------------------------
//		¥ EmRegsVZPalmM130::GetKeyInfo
// ---------------------------------------------------------------------------

void EmRegsVZPalmM130::GetKeyInfo (int* numRows, int* numCols,
								uint16* keyMap, Bool* rows)
{
	*numRows = kNumButtonRows;
	*numCols = kNumButtonCols;

	memcpy (keyMap, kButtonMapPalmM130, sizeof (kButtonMapPalmM130));

	// Determine what row is being asked for.

	UInt8	portKDir	= READ_REGISTER (portKDir);
	UInt8	portKData	= READ_REGISTER (portKData);

	rows[0]	= (portKDir & hwrVZPalmM130PortKKbdRow0) != 0 && (portKData & hwrVZPalmM130PortKKbdRow0) == 0;
	rows[1]	= (portKDir & hwrVZPalmM130PortKKbdRow1) != 0 && (portKData & hwrVZPalmM130PortKKbdRow1) == 0;
	rows[2]	= (portKDir & hwrVZPalmM130PortKKbdRow2) != 0 && (portKData & hwrVZPalmM130PortKKbdRow2) == 0;
}


// ---------------------------------------------------------------------------
//		¥ EmRegsVZPalmM130::GetSPISlave
// ---------------------------------------------------------------------------

EmSPISlave* EmRegsVZPalmM130::GetSPISlave (void)
{
	if ((READ_REGISTER (portGData) & hwrVZPalmM130PortGADC_CS_N) == 0)
	{
		return fSPISlaveADC;
	}

	return NULL;
}


#pragma mark -

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

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


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

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


// ---------------------------------------------------------------------------
//		¥ EmRegsPLDPalmI705::EmRegsPLDPalmI705
// ---------------------------------------------------------------------------

EmRegsPLDPalmI705::EmRegsPLDPalmI705 (emuptr baseAddr) :
	fBaseAddr (baseAddr)
{
}


// ---------------------------------------------------------------------------
//		¥ EmRegsPLDPalmI705::~EmRegsPLDPalmI705
// ---------------------------------------------------------------------------

EmRegsPLDPalmI705::~EmRegsPLDPalmI705 (void)
{
}


// ---------------------------------------------------------------------------
//		¥ EmRegsPLDPalmI705::Initialize
// ---------------------------------------------------------------------------

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


// ---------------------------------------------------------------------------
//		¥ EmRegsPLDPalmI705::Reset
// ---------------------------------------------------------------------------

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

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


// ---------------------------------------------------------------------------
//		¥ EmRegsPLDPalmI705::Save
// ---------------------------------------------------------------------------

void EmRegsPLDPalmI705::Save (SessionFile& f)
{
	EmRegs::Save (f);
}


// ---------------------------------------------------------------------------
//		¥ EmRegsPLDPalmI705::Load
// ---------------------------------------------------------------------------

void EmRegsPLDPalmI705::Load (SessionFile& f)
{
	EmRegs::Load (f);
}


// ---------------------------------------------------------------------------
//		¥ EmRegsPLDPalmI705::Dispose
// ---------------------------------------------------------------------------

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


// ---------------------------------------------------------------------------
//		¥ EmRegsPLDPalmI705::GetLEDState
// ---------------------------------------------------------------------------

uint16 EmRegsPLDPalmI705::GetLEDState (void)
{
	uint16	result = kLEDOff;

	if (fRegs.green_led)
		result |= kLEDGreen;

	if (fRegs.red_led)
		result |= kLEDRed;

	return result;
}


// ---------------------------------------------------------------------------
//		¥ EmRegsPLDPalmI705::SetSubBankHandlers
// ---------------------------------------------------------------------------

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

	EmRegs::SetSubBankHandlers ();

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

	INSTALL_HANDLER (StdReadBE,			StdWriteBE,				todsln3);
	INSTALL_HANDLER (StdReadBE,			StdWriteBE,				green_led);
	INSTALL_HANDLER (StdReadBE,			StdWriteBE,				pin_notify_enable);
	INSTALL_HANDLER (StdReadBE,			StdWriteBE,				red_led);
	INSTALL_HANDLER (StdReadBE,			StdWriteBE,				acpr);
	INSTALL_HANDLER (low_battRead,		StdWriteBE,				low_batt);
	INSTALL_HANDLER (StdReadBE,			StdWriteBE,				dto3svc_irq);
	INSTALL_HANDLER (StdReadBE,			StdWriteBE,				dsp_irq_enable);
	INSTALL_HANDLER (StdReadBE,			StdWriteBE,				dsp_irq_polarity);
	INSTALL_HANDLER (StdReadBE,			StdWriteBE,				charging_in_progress);
	INSTALL_HANDLER (StdReadBE,			StdWriteBE,				charging_in_prog2);
	INSTALL_HANDLER (StdReadBE,			StdWriteBE,				charging_in_prog_OE);
	INSTALL_HANDLER (StdReadBE,			StdWriteBE,				twister_irq_wake);
	INSTALL_HANDLER (StdReadBE,			StdWriteBE,				low_batt_mask);
	INSTALL_HANDLER (StdReadBE,			StdWriteBE,				acpr_mask);
	INSTALL_HANDLER (StdReadBE,			StdWriteBE,				acpr_polarity);
	INSTALL_HANDLER (usb_intRead,		StdWriteBE,				usb_int);
	INSTALL_HANDLER (StdReadBE,			StdWriteBE,				usb_int_mask);
	INSTALL_HANDLER (bullet_detRead,	StdWriteBE,				bullet_det);
	INSTALL_HANDLER (StdReadBE,			StdWriteBE,				bullet_det_mask);
	INSTALL_HANDLER (StdReadBE,			StdWriteBE,				bullet_det_pol);
}


// ---------------------------------------------------------------------------
//		¥ EmRegsPLDPalmI705::GetRealAddress
// ---------------------------------------------------------------------------

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


// ---------------------------------------------------------------------------
//		¥ EmRegsPLDPalmI705::GetAddressStart
// ---------------------------------------------------------------------------

emuptr EmRegsPLDPalmI705::GetAddressStart (void)
{
	return fBaseAddr;
}


// ---------------------------------------------------------------------------
//		¥ EmRegsPLDPalmI705::GetAddressRange
// ---------------------------------------------------------------------------

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


// ---------------------------------------------------------------------------
//		¥ EmRegsPLDPalmI705::low_battRead
// ---------------------------------------------------------------------------

uint32 EmRegsPLDPalmI705::low_battRead (emuptr address, int size)
{
	uint32	reg = StdReadBE (address, size);

#define hwrPLDlow_battOn	0		//this is inverted!
#define hwrPLDlow_battOff	0x80

	// If we're reading the whole register, or if we're reading the second
	// byte, then set the bit that says that the low-battery condition is off.

	if ((size == 2) || ((size == 1) && ((address & 1) == 1)))
	{
		reg |= hwrPLDlow_battOff;
	}

	return reg;
}


// ---------------------------------------------------------------------------
//		¥ EmRegsPLDPalmI705::usb_intRead
// ---------------------------------------------------------------------------

uint32 EmRegsPLDPalmI705::usb_intRead (emuptr /*address*/, int /*size*/)
{
	// this bit is low-asserted

	return ~0;
}


// ---------------------------------------------------------------------------
//		¥ EmRegsPLDPalmI705::bullet_detRead
// ---------------------------------------------------------------------------

uint32 EmRegsPLDPalmI705::bullet_detRead (emuptr /*address*/, int /*size*/)
{
	// 1 = undocked, 0 = docked

	return ~0;
}