File: EmRegsUSBVisor.cpp

package info (click to toggle)
pose 3.5-7
  • links: PTS
  • area: contrib
  • in suites: sarge
  • size: 14,136 kB
  • ctags: 29,490
  • sloc: cpp: 93,990; ansic: 62,838; sh: 27,519; perl: 1,891; python: 1,242; makefile: 652
file content (164 lines) | stat: -rw-r--r-- 4,771 bytes parent folder | download | duplicates (3)
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
/* -*- 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 "EmRegsUSBVisor.h"

#include "EmSession.h"			// GetDevice
#include "EmHAL.h"				// EmHAL::GetROMSize
#include "EmBankROM.h"			// EmBankROM::GetMemoryStart


// 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) &EmRegsUSBVisor::read,		\
						(WriteFunction) &EmRegsUSBVisor::write,		\
						addressof (reg),			\
						fRegs.reg.GetSize ())


// ---------------------------------------------------------------------------
//		 EmRegsUSBVisor::EmRegsUSBVisor
// ---------------------------------------------------------------------------

EmRegsUSBVisor::EmRegsUSBVisor (void)
{
}


// ---------------------------------------------------------------------------
//		 EmRegsUSBVisor::~EmRegsUSBVisor
// ---------------------------------------------------------------------------

EmRegsUSBVisor::~EmRegsUSBVisor (void)
{
}


// ---------------------------------------------------------------------------
//		 EmRegsUSBVisor::Initialize
// ---------------------------------------------------------------------------

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


// ---------------------------------------------------------------------------
//		 EmRegsUSBVisor::Reset
// ---------------------------------------------------------------------------

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

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


// ---------------------------------------------------------------------------
//		 EmRegsUSBVisor::Save
// ---------------------------------------------------------------------------

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


// ---------------------------------------------------------------------------
//		 EmRegsUSBVisor::Load
// ---------------------------------------------------------------------------

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


// ---------------------------------------------------------------------------
//		 EmRegsUSBVisor::Dispose
// ---------------------------------------------------------------------------

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


// ---------------------------------------------------------------------------
//		 EmRegsUSBVisor::SetSubBankHandlers
// ---------------------------------------------------------------------------

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

	EmRegs::SetSubBankHandlers ();

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

	INSTALL_HANDLER (StdReadBE,			StdWriteBE,				data);
	INSTALL_HANDLER (StdReadBE,			StdWriteBE,				command);
}


// ---------------------------------------------------------------------------
//		 EmRegsUSBVisor::GetRealAddress
// ---------------------------------------------------------------------------

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


// ---------------------------------------------------------------------------
//		 EmRegsUSBVisor::GetAddressStart
// ---------------------------------------------------------------------------

emuptr EmRegsUSBVisor::GetAddressStart (void)
{
	/* 
		Auto-detect USB hardware base address.  In the Visor, the USB hardware 
		is at CSA1, which resides just after the ROM (CSA0) in memory.  
	*/

	EmDevice device = gSession->GetDevice ();
	if (device.HardwareID () == 0x0a /*halModelIDVisorPrism*/)	// in Prism it is not at CSA1
		return (emuptr) 0x10800000L;

	return EmBankROM::GetMemoryStart() + EmHAL::GetROMSize ();
}


// ---------------------------------------------------------------------------
//		 EmRegsUSBVisor::GetAddressRange
// ---------------------------------------------------------------------------

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