aboutsummaryrefslogtreecommitdiff
path: root/SrcShared/Hardware/EmRegs328Symbol1700.cpp
blob: 0b5a305155a85bae81acffd2860c0a193fa0328d (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
/* -*- 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 "EmRegs328Symbol1700.h"
#include "EmRegs328Prv.h"

#define keyBitTrigLeft		0x0400
#define keyBitTrigCenter	0x0800
#define keyBitTrigRight		0x1000
#define keyBitPageUpLeft	keyBitPageUp
#define keyBitPageUpRight	keyBitPageDown
#define keyBitPageDownLeft	0x2000
#define keyBitPageDownRight	0x4000


#define	keyBitMask			0x0F	// Which bits in port D we use for keys

#define portDKbdCols		0xF0
#define portDKbdRows		0x0F

#define portDKbdCol0		0x10
#define portDKbdCol1		0x20
#define portDKbdCol2		0x40
#define portDKbdCol3		0x80

#define portDKbdRow0		0x01
#define portDKbdRow1		0x02
#define portDKbdRow2		0x04
#define portDKbdRow3		0x08


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

const uint16	kButtonMap[kNumButtonRows][kNumButtonCols] =
{
	{ keyBitPower,		keyBitTrigLeft,		keyBitTrigCenter,	keyBitTrigRight		},
	{ keyBitHard1,		keyBitHard2,		keyBitHard3,		keyBitHard4			},
	{ keyBitPageUpLeft,	keyBitPageUpRight,	keyBitPageDownLeft,	keyBitPageDownRight	},
	{ keyBitContrast,	0,					0,					0					}
};


// ---------------------------------------------------------------------------
//		¥ EmRegs328Symbol1700::GetKeyBits
// ---------------------------------------------------------------------------

uint8 EmRegs328Symbol1700::GetKeyBits (void)
{
	uint8	portDData = READ_REGISTER (portDData);

	Bool	cols[4];
	cols[0]	= (portDData & portDKbdCol0) == 0;
	cols[1]	= (portDData & portDKbdCol1) == 0;
	cols[2]	= (portDData & portDKbdCol2) == 0;
	cols[3]	= (portDData & portDKbdCol3) == 0;

	uint8	keyData = 0;

	// Walk the columns, looking for one that is requested.

	for (int col = 0; col < kNumButtonCols; ++col)
	{
		if (cols[col])
		{
			// Walk the rows.

			for (int row = 0; row < kNumButtonRows; ++row)
			{
				// Get the key corresponding to this row and column.
				// If we've recorded (in fgKeyBits) that this key is
				// pressed, then set its row bit.

				if ((fKeyBits & kButtonMap[row][col]) != 0)
				{
					keyData |= 1 << (col + 4);
					keyData |= 1 << row;
				}
			}
		}
	}

	return keyData;
}


// ---------------------------------------------------------------------------
//		¥ EmRegs328Symbol1700::ButtonToBits
// ---------------------------------------------------------------------------

uint16 EmRegs328Symbol1700::ButtonToBits (SkinElementType button)
{
	uint16 bitNumber = 0;
	switch (button)
	{
		default:
			bitNumber = EmRegs328PalmPilot::ButtonToBits (button);
			break;

		case kElement_TriggerLeft:		bitNumber = keyBitTrigLeft;			break;
		case kElement_TriggerCenter:	bitNumber = keyBitTrigCenter;		break;
		case kElement_TriggerRight:		bitNumber = keyBitTrigRight;		break;
		case kElement_UpButtonLeft:		bitNumber = keyBitPageUpLeft;		break;
		case kElement_UpButtonRight:	bitNumber = keyBitPageUpRight;		break;
		case kElement_DownButtonLeft:	bitNumber = keyBitPageDownLeft;		break;
		case kElement_DownButtonRight:	bitNumber = keyBitPageDownRight;	break;
	}

	return bitNumber;
}