-
Notifications
You must be signed in to change notification settings - Fork 1
/
DiskController.cpp
97 lines (88 loc) · 3.23 KB
/
DiskController.cpp
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
/* ES40 emulator.
* Copyright (C) 2007 by the ES40 Emulator Project
*
* WWW : http://sourceforge.net/projects/es40
* E-mail : [email protected]
*
* 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.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Although this is not required, the author would appreciate being notified of,
* and receiving any modifications you may make to the source code that might serve
* the general public.
*/
/**
* \file
* Contains definitions for the disk controller base class.
*
* X-1.12 Camiel Vanderhoeven 14-JAN-2008
* Removed unreferenced variable.
*
* X-1.11 Brian Wheeler 13-JAN-2008
* Avoid deleting Disk devices twice.
*
* X-1.9 Camiel Vanderhoeven 12-JAN-2008
* Made register_disk void and virtual.
*
* X-1.8 Camiel Vanderhoeven 29-DEC-2007
* Fix memory-leak.
*
* X-1.7 Camiel Vanderhoeven 28-DEC-2007
* Keep the compiler happy.
*
* X-1.6 Camiel Vanderhoeven 18-DEC-2007
* Initialize pointers to 0 in constructor. (doh!)
*
* X-1.5 Camiel Vanderhoeven 17-DEC-2007
* Removed excessive whitespace.
*
* X-1.4 Brian Wheeler 16-DEC-2007
* Added newline at end of file.
*
* X-1.3 Camiel Vanderhoeven 16-DEC-2007
* Include Disk.h, so children's destructors can be called.
*
* X-1.2 Camiel Vanderhoeven 14-DEC-2007
* Delete children upon destruction.
*
* X-1.1 Camiel Vanderhoeven 12-DEC-2007
* Initial version in CVS.
**/
#include "StdAfx.h"
#include "DiskController.h"
#include "Disk.h"
CDiskController::CDiskController(CConfigurator * cfg, CSystem * c, int pcibus, int pcidev, int num_busses, int num_devices) : CPCIDevice(cfg,c,pcibus,pcidev)
{
num_bus = num_busses;
num_dev = num_devices;
disks = (CDisk**) calloc(num_bus*num_dev,sizeof(CDisk*));
}
CDiskController::~CDiskController(void)
{
free(disks);
}
void CDiskController::register_disk(class CDisk * dsk, int bus, int dev)
{
if (bus>=num_bus)
FAILURE("Can't register disk: bus number out of range");
if (dev>=num_dev)
FAILURE("Can't register disk: device number out of range");
disks[bus*num_bus+dev] = dsk;
}
class CDisk * CDiskController::get_disk(int bus, int dev)
{
if (bus>=num_bus) return 0;
if (dev>=num_dev) return 0;
return disks[bus*num_bus+dev];
}