DiskController.cpp

Go to the documentation of this file.
00001 /* ES40 emulator.
00002  * Copyright (C) 2007-2008 by the ES40 Emulator Project
00003  *
00004  * WWW    : http://sourceforge.net/projects/es40
00005  * E-mail : camiel@camicom.com
00006  * 
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  * 
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  * 
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00020  * 
00021  * Although this is not required, the author would appreciate being notified of, 
00022  * and receiving any modifications you may make to the source code that might serve
00023  * the general public.
00024  */
00025 
00069 #include "StdAfx.h"
00070 #include "DiskController.h"
00071 #include "Disk.h"
00072 
00073 CDiskController::CDiskController(CConfigurator*  cfg, CSystem*  c, int pcibus,
00074                                  int pcidev, int num_busses, int num_devices) : CPCIDevice(cfg, c, pcibus, pcidev)
00075 {
00076   num_bus = num_busses;
00077   num_dev = num_devices;
00078 
00079   disks = (CDisk**) calloc(num_bus * num_dev, sizeof(CDisk *));
00080 }
00081 
00082 CDiskController::~CDiskController(void)
00083 {
00084   free(disks);
00085 }
00086 
00087 void CDiskController::register_disk(class CDisk* dsk, int bus, int dev)
00088 {
00089   if(bus >= num_bus)
00090     FAILURE(Configuration, "Can't register disk: bus number out of range");
00091   if(dev >= num_dev)
00092     FAILURE(Configuration, "Can't register disk: device number out of range");
00093 
00094   disks[bus * num_bus + dev] = dsk;
00095 }
00096 
00097 class CDisk*  CDiskController::get_disk(int bus, int dev)
00098 {
00099     if(bus >= num_bus)
00100       return 0;
00101     if(dev >= num_dev)
00102       return 0;
00103 
00104     return disks[bus * num_bus + dev];
00105 }

SourceForge.net Logo
Project space on SourceForge.net