コード例 #1
0
ファイル: T64File.cpp プロジェクト: dirkwhoffmann/virtualc64
size_t
T64File::getSizeOfItem()
{
    if (selectedItem < 0)
        return 0;
    
    // Compute start and end of the selected item in memory
    size_t offset = 0x42 + (selectedItem * 0x20);
    uint16_t startAddrInMemory = LO_HI(data[offset], data[offset + 1]);
    uint16_t endAddrInMemory = LO_HI(data[offset + 2], data[offset + 3]);
    
    return endAddrInMemory - startAddrInMemory;
}
コード例 #2
0
ファイル: T64File.cpp プロジェクト: dirkwhoffmann/virtualc64
uint16_t
T64File::getDestinationAddrOfItem()
{
    long i = 0x42 + (selectedItem * 0x20);
    uint16_t result = LO_HI(data[i], data[i+1]);
    return result;
}
コード例 #3
0
uint16_t 
T64Archive::getDestinationAddrOfItem(int n)
{
	int i = 0x42 + (n * 0x20);
	uint16_t result = LO_HI(data[i], data[i+1]);
	return result;
}
コード例 #4
0
void 
T64Archive::selectItem(int n)
{
	unsigned i;
    
    if (n < getNumberOfItems()) {

        // Compute start address in container
        i = 0x48 + (n * 0x20);
        if ((fp = LO_LO_HI_HI(data[i], data[i+1], data[i+2], data[i+3])) >= size)
            fprintf(stderr, "PANIC! fp is out of bounds!\n");

        // Compute start address in memory
        i = 0x42 + (n * 0x20);
        uint16_t startAddrInMemory = LO_HI(data[i], data[i+1]);
        
        // Compute end address in memory
        i = 0x44 + (n * 0x20);
        uint16_t endAddrInMemory = LO_HI(data[i], data[i+1]);

        if (endAddrInMemory == 0xC3C6) {
            fprintf(stderr, "WARNING: Corrupted archive. Mostly likely created with CONV64!\n");
            // WHAT DO WE DO ABOUT IT?
        }

        // Compute size of item
        uint16_t length = endAddrInMemory - startAddrInMemory;

        // fprintf(stderr, "start = %d end = %d diff = %d\n", startAddrInMemory, endAddrInMemory, length);
        // fprintf(stderr, "fp = %d fp_eof = %d\n", fp, fp_eof);

        // Store largest offset that belongs to the file
        if ((fp_eof = fp + length) > size)
            fprintf(stderr, "PANIC! fp_eof is out of bounds!\n");
        
        // Return if offset values are safe
        if (fp < size && fp_eof <= size)
            return; // success
    }

    fp = fp_eof = -1; // fail
	return;
}
コード例 #5
0
int 
T64Archive::getNumberOfItems()
{
	int noOfItems;

	// Get number of files from the file header...
    noOfItems = LO_HI(data[0x24], data[0x25]);

	if (noOfItems == 0) {

        // Note: Some archives don't store this value properly.
		// In this case, we can determine the number of files
		// by iterating through the directory area...
		while (directoryItemIsPresent(noOfItems))
			noOfItems++;
	}

	return noOfItems;
}
コード例 #6
0
ファイル: T64File.cpp プロジェクト: dirkwhoffmann/virtualc64
bool
T64File::repair()
{
    unsigned i, n;
    uint16_t noOfItems = numberOfItems();

    //
    // 1. Repair number of items, if this value is zero
    //
    
    if (noOfItems == 0) {

        while (directoryItemIsPresent(noOfItems))
            noOfItems++;

        uint16_t noOfItemsStatedInHeader = numberOfItems();
        if (noOfItems != noOfItemsStatedInHeader) {
        
            debug(1, "Repairing corrupted T64 archive: Changing number of items from %d to %d.\n",
                  noOfItemsStatedInHeader, noOfItems);
        
            data[0x24] = LO_BYTE(noOfItems);
            data[0x25] = HI_BYTE(noOfItems);
            
        }
        assert(noOfItems == numberOfItems());
    }
    
    for (i = 0; i < noOfItems; i++) {

        //
        // 2. Check relative offset information for each item
        //

        // Compute start address in file
        n = 0x48 + (i * 0x20);
        uint16_t startAddrInContainer = LO_LO_HI_HI(data[n], data[n+1], data[n+2], data[n+3]);

        if (startAddrInContainer >= size) {
            warn("T64 archive is corrupt (offset mismatch). Sorry, can't repair.\n");
            return false;
        }
    
        //
        // 3. Check for file end address mismatches (as created by CONVC64)
        //
        
        // Compute start address in memory
        n = 0x42 + (i * 0x20);
        uint16_t startAddrInMemory = LO_HI(data[n], data[n+1]);
    
        // Compute end address in memory
        n = 0x44 + (i * 0x20);
        uint16_t endAddrInMemory = LO_HI(data[n], data[n+1]);
    
        if (endAddrInMemory == 0xC3C6) {

            // Let's assume that the rest of the file data belongs to this file ...
            uint16_t fixedEndAddrInMemory = startAddrInMemory + (size - startAddrInContainer);

            debug(1, "Repairing corrupted T64 archive: Changing end address of item %d from %04X to %04X.\n",
                  i, endAddrInMemory, fixedEndAddrInMemory);

            data[n] = LO_BYTE(fixedEndAddrInMemory);
            data[n+1] = HI_BYTE(fixedEndAddrInMemory);
        }
    }
    
    return 1; // Archive repaired successfully
}
コード例 #7
0
ファイル: T64File.cpp プロジェクト: dirkwhoffmann/virtualc64
int
T64File::numberOfItems()
{
    return LO_HI(data[0x24], data[0x25]);
}
コード例 #8
0
ファイル: G64Archive.cpp プロジェクト: DNSGeek/virtualc64
int
G64Archive::getSizeOfItem(int n)
{
    int offset = getStartOfItem(n);
    return offset ? (LO_HI(data[offset], data[offset+1])) : 0;
}
コード例 #9
0
ファイル: PRGArchive.cpp プロジェクト: DNSGeek/virtualc64
uint16_t 
PRGArchive::getDestinationAddrOfItem(int n)
{
	uint16_t result = LO_HI(data[0], data[1]);
	return result;
}