home *** CD-ROM | disk | FTP | other *** search
- /////////////////////////////////////////////////////////////////////////////// //
- // $Id: Loader.cxx,v 1.1 1994/02/18 20:19:04 bmott Exp $
- /////////////////////////////////////////////////////////////////////////////// //
- // Loader.cxx
- //
- // Class to load object files
- //
- // Sim68000 "Motorola 68000 Simulator"
- // Copyright (c) 1993
- // By: Bradford W. Mott
- // November 5,1993
- //
- ///////////////////////////////////////////////////////////////////////////////
- // $Log: Loader.cxx,v $
- // Revision 1.1 1994/02/18 20:19:04 bmott
- // Initial revision
- //
- ///////////////////////////////////////////////////////////////////////////////
-
- #include <iostream.h>
- #include <fstream.h>
- #include "BasicCPU.hxx"
- #include "Tools.hxx"
- #include "Loader.hxx"
-
- ///////////////////////////////////////////////////////////////////////////////
- // Load the named file into the address space
- ///////////////////////////////////////////////////////////////////////////////
- String Loader::Load(const char* filename, int space)
- {
- String error;
-
- // Open the file for reading
- fstream file(filename, ios::in);
-
- // Make sure the file was opened
- if(file.bad())
- {
- error="ERROR: Could not open file!!!";
- return(error);
- }
-
- error=LoadMotorolaSRecord(file,space);
-
- return(error);
- }
-
- ///////////////////////////////////////////////////////////////////////////////
- // Load in a Motorola S-Record file into an address space
- ///////////////////////////////////////////////////////////////////////////////
- String Loader::LoadMotorolaSRecord(fstream& file,int space)
- {
- unsigned long address;
- String line;
- int t,length,byte;
-
- while(!file.eof())
- {
- file >> line;
- if(line[0]!='S')
- {
- return("ERROR: Incorrect file format!!!");
- }
- else if(line[1]=='1')
- {
- line.del(0,2);
- length=StringToInt(line(0,2));
- line.del(0,2);
- address=StringToInt(line(0,4));
- line.del(0,4);
- for(t=0;t<length-3;++t)
- {
- byte=StringToInt(line(0,2));
- line.del(0,2);
- CPU()->address_space[space].Poke(address+t,(unsigned char)byte);
- }
- }
- else if(line[1]=='2')
- {
- line.del(0,2);
- length=StringToInt(line(0,2));
- line.del(0,2);
- address=StringToInt(line(0,6));
- line.del(0,6);
- for(t=0;t<length-4;++t)
- {
- byte=StringToInt(line(0,2));
- line.del(0,2);
- CPU()->address_space[space].Poke(address+t,(unsigned char)byte);
- }
- }
- else if(line[1]=='3')
- {
- line.del(0,2);
- length=StringToInt(line(0,2));
- line.del(0,2);
- address=StringToInt(line(0,8));
- line.del(0,8);
- for(t=0;t<length-5;++t)
- {
- byte=StringToInt(line(0,2));
- line.del(0,2);
- CPU()->address_space[space].Poke(address+t,(unsigned char)byte);
- }
- }
- else if(line[1]=='7')
- {
- break;
- }
- else if(line[1]=='8')
- {
- break;
- }
- else if(line[1]=='9')
- {
- break;
- }
- }
- return("");
- }
-