FloppyController.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 
00071 #include "StdAfx.h"
00072 #include "FloppyController.h"
00073 #include "System.h"
00074 
00078 CFloppyController::CFloppyController(CConfigurator* cfg, CSystem* c, int id) : CSystemComponent(cfg, c)
00079 {
00080   c->RegisterMemory(this, 0, U64(0x00000801fc0003f0) - (0x80 * id), 6);
00081   c->RegisterMemory(this, 1, U64(0x00000801fc0003f7) - (0x80 * id), 1);
00082   iMode = 0;
00083   iID = id;
00084   iActiveRegister = 0;
00085 
00086   iRegisters[0x00] = 0x28;
00087   iRegisters[0x01] = 0x9c;
00088   iRegisters[0x02] = 0x88;
00089   iRegisters[0x03] = 0x78;
00090   iRegisters[0x04] = 0x00;
00091   iRegisters[0x05] = 0x00;
00092   iRegisters[0x06] = 0xff;
00093   iRegisters[0x07] = 0x00;
00094   iRegisters[0x08] = 0x00;
00095   iRegisters[0x09] = 0x00;
00096   iRegisters[0x0a] = 0x00;
00097   iRegisters[0x0b] = 0x00;
00098   iRegisters[0x0c] = 0x00;
00099   iRegisters[0x0d] = 0x03;
00100   iRegisters[0x0e] = 0x02;
00101   iRegisters[0x0f] = 0x00;
00102   iRegisters[0x10] = 0x00;
00103   iRegisters[0x11] = 0x00;
00104   iRegisters[0x12] = 0x00;
00105   iRegisters[0x13] = 0x00;
00106   iRegisters[0x14] = 0x00;
00107   iRegisters[0x15] = 0x00;
00108   iRegisters[0x16] = 0x00;
00109   iRegisters[0x17] = 0x00;
00110   iRegisters[0x18] = 0x00;
00111   iRegisters[0x19] = 0x00;
00112   iRegisters[0x1a] = 0x00;
00113   iRegisters[0x1b] = 0x00;
00114   iRegisters[0x1c] = 0x00;
00115   iRegisters[0x1d] = 0x00;
00116   iRegisters[0x1e] = 0x3c;
00117   iRegisters[0x1f] = 0x00;
00118   iRegisters[0x20] = 0x3c;
00119   iRegisters[0x21] = 0x3c;
00120   iRegisters[0x22] = 0x3d;
00121   iRegisters[0x23] = 0x00;
00122   iRegisters[0x24] = 0x00;
00123   iRegisters[0x25] = 0x00;
00124   iRegisters[0x26] = 0x00;
00125   iRegisters[0x27] = 0x00;
00126   iRegisters[0x28] = 0x00;
00127   iRegisters[0x29] = 0x00;
00128 
00129   printf("%s: $Id: FloppyController.cpp,v 1.13 2008/03/14 15:30:51 iamcamiel Exp $\n",
00130        devid_string);
00131 }
00132 
00136 CFloppyController::~CFloppyController()
00137 { }
00138 void CFloppyController::WriteMem(int index, u64 address, int dsize, u64 data)
00139 {
00140   if(index == 1)
00141     address += 7;
00142 
00143   switch(address)
00144   {
00145   case 0:
00146     switch(data & 0xff)
00147     {
00148     case 0x55:
00149 
00150       //                        if (iMode==1)
00151       //                                printf("Entering configuration mode for floppy controller %d\n", iID);
00152       if(iMode == 0 || iMode == 1)
00153         iMode++;
00154       break;
00155 
00156     case 0xaa:
00157 
00158       //                        if (iMode==2)
00159       //                                printf("Leaving configuration mode for floppy controller %d\n", iID);
00160       iMode = 0;
00161       break;
00162 
00163     default:
00164       if(iMode == 2)
00165         iActiveRegister = (int) (data & 0xff);
00166 
00167       //                        else
00168       //                                printf("Unknown command: %02x on floppy port %d\n",(u32)(data&0xff),(u32)address);
00169     }
00170     break;
00171 
00172   case 1:
00173     if(iMode == 2)
00174     {
00175       if(iActiveRegister < 0x2a)
00176         iRegisters[iActiveRegister] = (u8) (data & 0xff);
00177 
00178       //                        else
00179       //                                printf("Unknown floppy register: %02x\n",iActiveRegister);
00180     }
00181 
00182     //          else
00183     //                  printf("Unknown command: %02x on floppy port %d\n",(u32)(data&0xff),(u32)address);
00184     break;
00185 
00186     //  default:
00187     //          printf("Unknown command: %02x on floppy port %d\n",(u32)(data&0xff),(u32)address);
00188   }
00189 }
00190 
00191 u64 CFloppyController::ReadMem(int index, u64 address, int dsize)
00192 {
00193   if(index == 1)
00194     address += 7;
00195 
00196   switch(address)
00197   {
00198   case 1:
00199     if(iMode == 2)
00200     {
00201       if(iActiveRegister < 0x2a)
00202         return(u64) (iRegisters[iActiveRegister]);
00203     }
00204     break;
00205 
00206   case 4:         //3f4 floppy main status register
00207     return 0x80;  // floppy ready
00208     break;
00209 
00210   case 5:         //3f5 floppy command status register
00211     return 0;
00212     break;
00213 
00214   default:
00215     printf("Unknown read access on floppy port %d\n", (u32) address);
00216   }
00217 
00218   return 0;
00219 }

SourceForge.net Logo
Project space on SourceForge.net