git-svn-id: https://profuse.googlecode.com/svn/branches/v2@99 aa027e90-d47c-11dd-86d7-074df07e0730

This commit is contained in:
ksherlock 2009-11-24 03:56:19 +00:00
parent 9f0b5f1004
commit 2209b44225
4 changed files with 20 additions and 112 deletions

View File

@ -1,6 +1,7 @@
#include "DavexDiskImage.h"
#include "MappedFile.h"
#include "Buffer.h"
#include "Endian.h"
#include <cerrno>
#include <cstdlib>
@ -10,6 +11,7 @@
#include <cstdio>
using namespace ProFUSE;
using namespace LittleEndian;
/*
http://www.umich.edu/~archive/apple2/technotes/ftn/FTN.E0.8004
@ -41,7 +43,7 @@ void DavexDiskImage::Validate(MappedFile *f)
#define __METHOD__ "DavexDiskImage::Validate"
size_t size = f->fileSize();
void * data = f->fileData();
const void * data = f->fileData();
bool ok = false;
unsigned blocks = (size / 512) - 1;
@ -54,15 +56,15 @@ void DavexDiskImage::Validate(MappedFile *f)
break;
// file format.
if (f->read8(16) != 0)
if (Read8(data, 0x10) != 0)
break;
// total blocks
if (f->read32(33, LittleEndian) != blocks)
if (Read32(data, 33) != blocks)
break;
// file number -- must be 1
if (f->read8(64) != 1)
if (Read8(data, 64) != 1)
break;
ok = true;

View File

@ -87,7 +87,7 @@ protected:
setIndex(unsigned index)
{
_index = index;
_index = index;w
}

View File

@ -1,10 +1,12 @@
#include "DiskCopy42Image.h"
#include "MappedFile.h"
#include "Buffer.h"
#include "Endian.h"
#include <stdio.h>
#include <cstdio>
using namespace ProFUSE;
using namespace BigEndian;
DiskCopy42Image::DiskCopy42Image(MappedFile *f) :
DiskImage(f),
@ -24,12 +26,14 @@ DiskCopy42Image::~DiskCopy42Image()
if (_changed)
{
MappedFile *f = file();
void *data = file->fileData();
if (f)
{
uint32_t cs = Checksum(f->offset() + (uint8_t *)f->fileData(),
uint32_t cs = Checksum(f->offset() + (uint8_t *)data,
f->blocks() * 512);
f->write32(72, cs, BigEndian);
Write32(data, 72, cs);
f->sync();
}
// TODO -- checksum
@ -137,6 +141,7 @@ void DiskCopy42Image::Validate(MappedFile *file)
{
size_t bytes = 0;
size_t size = file->fileSize();
const void *data = file->fileData();
bool ok = false;
uint32_t checksum;
@ -144,26 +149,26 @@ void DiskCopy42Image::Validate(MappedFile *file)
if (size < 84) break;
// name must be < 64
if (file->read8(0) > 63) break;
if (Read8(data, 0) > 63) break;
if (file->read32(82, BigEndian) != 0x100)
if (Read32(data, 82) != 0x100)
break;
// bytes, not blocks.
bytes = file->read32(64, BigEndian);
bytes = Read32(data, 64);
if (bytes % 512) break;
if (size < 84 + bytes) break;
// todo -- checksum.
checksum = file->read32(72, BigEndian);
checksum = Read32(data, 72);
ok = true;
} while (false);
uint32_t cs = Checksum(64 + (uint8_t *)file->fileData(), bytes);
uint32_t cs = Checksum(64 + (uint8_t *)data, bytes);
if (cs != checksum)
{

View File

@ -218,103 +218,4 @@ void MappedFile::reset()
_dosOrder = false;
}
/*
uint8_t MappedFile::read8(size_t location) const
{
// check for size?
uint8_t *map = (uint8_t *)_map;
return map[location];
}
*/
uint16_t MappedFile::read16(size_t location, int byteOrder) const
{
// check for size?
uint8_t *map = (uint8_t *)_map;
switch(byteOrder)
{
case LittleEndian:
return (map[location + 1] << 8)
| (map[location]);
case BigEndian:
return (map[location] << 8)
| (map[location+1]);
default:
return 0;
}
}
uint32_t MappedFile::read32(size_t location, int byteOrder) const
{
// check for size?
uint8_t *map = (uint8_t *)_map;
switch(byteOrder)
{
case LittleEndian:
return (map[location+3] << 24)
| (map[location+2] << 16)
| (map[location+1] << 8)
| (map[location])
;
case BigEndian:
return (map[location] << 24)
| (map[location+1] << 16)
| (map[location+2] << 8)
| (map[location+3])
;
default:
return 0;
}
}
/*
void MappedFile::write8(size_t location, uint8_t data)
{
uint8_t *map = (uint8_t *)_map;
map[location] = data;
}
*/
void MappedFile::write16(size_t location, uint16_t data, int byteOrder)
{
uint8_t *map = (uint8_t *)_map;
switch(byteOrder)
{
case LittleEndian:
map[location] = data & 0xff;
map[location+1] = (data >> 8) & 0xff;
break;
case BigEndian:
map[location] = (data >> 8) & 0xff;
map[location+1] = data & 0xff;
break;
}
}
void MappedFile::write32(size_t location, uint32_t data, int byteOrder)
{
uint8_t *map = (uint8_t *)_map;
switch(byteOrder)
{
case LittleEndian:
map[location] = data & 0xff;
map[location+1] = (data >> 8) & 0xff;
map[location+2] = (data >> 16) & 0xff;
map[location+3] = (data >> 24) & 0xff;
break;
case BigEndian:
map[location] = (data >> 24) & 0xff;
map[location+1] = (data >> 16) & 0xff;
map[location+2] = (data >> 8) & 0xff;
map[location+3] = data & 0xff;
break;
}
}