Exemple #1
0
double readDouble (FILE *hatFile)
{
    unsigned long bytes[2];
    *(bytes+1) = readFourBytes(hatFile);
    *(bytes) = readFourBytes(hatFile);
    
    return (double)(*bytes);
}
Exemple #2
0
position readPosition (FILE *hatFile)  /* reads only position beginning, not end */
{
    position returnVal;
    unsigned long posn = readFourBytes(hatFile);
    
    returnVal.line = posn / 10000;
    returnVal.column = posn % 10000;
    
    return returnVal;
}
Exemple #3
0
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// CompressedFilter::ReadFromFile():
//      Reads the compressed filter from the specified open file.
//
errorT
CompressedFilter::ReadFromFile (FILE * fp)
{
    ASSERT (fp != NULL);
    if (CompressedData) { delete[] CompressedData; }

    CFilterSize = readFourBytes (fp);
    CFilterCount = readFourBytes (fp);
    CompressedLength = readFourBytes (fp);
    CompressedData = NULL;
    if(CompressedLength > 0)
    {
        CompressedData = new byte [CompressedLength];
        byte * pb = CompressedData;
        for (uint i=0; i < CompressedLength; i++, pb++) {
            *pb = readOneByte(fp);
        }
    }
    return OK;
}
Exemple #4
0
struct Track * readTrack(int file)
{
    struct Track * trk = &tracks[curr_track++];
    rb->memset(trk, 0, sizeof(struct Track));

    trk->size = readFourBytes(file);
    trk->pos = 0;
    trk->delta = 0;

    int numEvents=0;

    int pos = rb->lseek(file, 0, SEEK_CUR);

    while(readEvent(file, NULL))    /* Memory saving technique                   */
        numEvents++;                /* Attempt to read in events, count how many */
                                    /* THEN allocate memory and read them in     */
    rb->lseek(file, pos, SEEK_SET);

    int trackSize = (numEvents+1) * sizeof(struct Event);
    void * dataPtr = malloc(trackSize);
    trk->dataBlock = dataPtr;

    numEvents=0;

    while(readEvent(file, dataPtr))
    {
        if(trackSize < dataPtr-trk->dataBlock)
        {
            printf("Track parser memory out of bounds");
            exit(1);
        }
        dataPtr+=sizeof(struct Event);
        numEvents++;
    }
    trk->numEvents = numEvents;

    return trk;
}
Exemple #5
0
struct MIDIfile * loadFile(const char * filename)
{
    struct MIDIfile * mfload;
    int file = rb->open (filename, O_RDONLY);

    if(file < 0)
    {
        printf("Could not open file");
        return NULL;
    }

    mfload = &midi_file;

    rb->memset(mfload, 0, sizeof(struct MIDIfile));

    int fileID = readID(file);
    if(fileID != ID_MTHD)
    {
        if(fileID == ID_RIFF)
        {
            printf("Detected RMID file");
            printf("Looking for MThd header");
            char dummy[17];
            rb->read(file, &dummy, 16);
            if(readID(file) != ID_MTHD)
            {
                rb->close(file);
                printf("Invalid MIDI header within RIFF.");
                return NULL;
            }

        } else
        {
            rb->close(file);
            printf("Invalid file header chunk.");
            return NULL;
        }
    }

    if(readFourBytes(file)!=6)
    {
        rb->close(file);
        printf("Header chunk size invalid.");
        return NULL;
    }

    if(readTwoBytes(file)==2)
    {
        rb->close(file);
        printf("MIDI file type 2 not supported");
        return NULL;
    }

    mfload->numTracks = readTwoBytes(file);
    mfload->div = readTwoBytes(file);

    int track=0;

    printf("File has %d tracks.", mfload->numTracks);

    while(! eof(file) && track < mfload->numTracks)
    {
        unsigned char id = readID(file);


        if(id == ID_EOF)
        {
            if(mfload->numTracks != track)
            {
                printf("Warning: file claims to have %d tracks. I only see %d here.", mfload->numTracks, track);
                mfload->numTracks = track;
            }
            rb->close(file);
            return mfload;
        }

        if(id == ID_MTRK)
        {
            mfload->tracks[track] = readTrack(file);
            track++;
        } else
        {
            printf("SKIPPING TRACK");
            int len = readFourBytes(file);
            while(--len)
                readChar(file);
        }
    }

    rb->close(file);
    return mfload;

}
Exemple #6
0
void main(void) {
    static uint32_t dataPointer = 0;
    static uint32_t readPointer = 0;
    static uint32_t dataAddress;
    static uint32_t dataLength;
    static uint16_t bufPointer = 0;
    uint8_t c = 0;
    uint8_t uart = 0;

    wdtDisable();

    // Move Interrupt Vectors into Bootloader Section
    c = INTERRUPTMOVE;
    INTERRUPTMOVE = c | (1 << IVCE);
    INTERRUPTMOVE = c | (1 << IVSEL);

    TCRA |= (1 << WGM21); // CTC Mode
#if F_CPU == 16000000
    TCRB |= (1 << CS22); // Prescaler: 64
    OCR = 250;
#else
#error F_CPU not compatible with timer module. DIY!
#endif
    TIMS |= (1 << OCIE); // Enable compare match interrupt

    for (uint8_t i = 0; i < serialAvailable(); i++) {
        serialInit(i, BAUD(BAUDRATE, F_CPU));
    }
    sei();
    set(buf, 0xFF, sizeof(buf));

    debugPrint("YASAB ");
    debugPrint(VERSION);
    debugPrint(" by xythobuz\n");

    while (systemTime < BOOTDELAY) {
        for (uint8_t i = 0; i < serialAvailable(); i++) {
            if (serialHasChar(i)) {
                c = serialGet(i); // Clear rx buffer
                uart = i;
                goto ok; // Yeah, shame on me...
            }
        }
    }
    gotoApplication();

ok:
    serialWrite(uart, OKAY);
    while (!serialTxBufferEmpty(uart)); // Wait till it's sent

    uint32_t t = systemTime;
    while (systemTime < (t + BOOTDELAY)) {
        if (serialHasChar(uart)) {
            if (serialGet(uart) == CONFIRM) {
                goto ack; // I deserve it...
            }
        }
    }
    gotoApplication();

ack:
    serialWrite(uart, ACK);
    while (!serialTxBufferEmpty(uart));

    dataAddress = readFourBytes(uart, serialGetBlocking(uart));
    serialWrite(uart, OKAY);
    while (!serialTxBufferEmpty(uart)); // Wait till it's sent
    debugPrint("Got address!\n");

    dataLength = readFourBytes(uart, serialGetBlocking(uart));
    if ((dataAddress + dataLength) >= BOOTSTART) {
        serialWrite(uart, ERROR);
    } else {
        serialWrite(uart, OKAY);
    }
    while (!serialTxBufferEmpty(uart));
    debugPrint("Got length!\n");

    while (readPointer < dataLength) {
        buf[bufPointer] = serialGetBlocking(uart);
        readPointer++;
        if (bufPointer < (SPM_PAGESIZE - 1)) {
            bufPointer++;
        } else {
            bufPointer = 0;
            program(uart, dataPointer + dataAddress, buf);
            dataPointer += SPM_PAGESIZE;
            set(buf, 0xFF, sizeof(buf));
            serialWrite(uart, OKAY);
        }
    }

    debugPrint("Got data!\n");

    if (bufPointer != 0) {
        program(uart, dataPointer + dataAddress, buf);
        serialWrite(uart, OKAY);
    }

    uint8_t sreg = SREG;
    cli();
    boot_spm_busy_wait();
    boot_rww_enable(); // Allows us to jump to application
    SREG = sreg;

    gotoApplication();
}
Exemple #7
0
errorT
TreeCache::ReadFile (const char * fname)
{
    // Only read the file if the cache is empty:
    if (NumInUse > 0) { return OK; }
#ifdef WINCE
    /*FILE * */Tcl_Channel fp;
    fileNameT fullname;
    strCopy (fullname, fname);
    strAppend (fullname, TREEFILE_SUFFIX);

    //fp = fopen (fullname, "rb");
    fp = mySilent_Tcl_OpenFileChannel(NULL, fullname, "r", 0666);
    if (fp == NULL) {
        return ERROR_FileOpen;
    }
 my_Tcl_SetChannelOption(NULL, fp, "-encoding", "binary");
 my_Tcl_SetChannelOption(NULL, fp, "-translation", "binary");

    uint magic = readFourBytes (fp);
    if (magic != TREEFILE_MAGIC) {
        //fclose (fp);
        my_Tcl_Close(NULL, fp);

#else
    FILE * fp;
    fileNameT fullname;
    strCopy (fullname, fname);
    strAppend (fullname, TREEFILE_SUFFIX);

    fp = fopen (fullname, "rb");
    if (fp == NULL) {
        return ERROR_FileOpen;
    }

    uint magic = readFourBytes (fp);
    if (magic != TREEFILE_MAGIC) {
        fclose (fp);
#endif
        return ERROR_Corrupt;
    }
    readTwoBytes (fp);  // Scid Version; unused
    uint cacheSize = readFourBytes (fp);
    SetCacheSize (cacheSize);
    NumInUse = readFourBytes (fp);
    LowestTotal = readFourBytes (fp);
    LowestTotalIndex = readFourBytes(fp);

    for (uint count=0; count < NumInUse; count++) {
        cachedTreeT * ctree = &(Cache[count]);
        ctree->toMove = readOneByte (fp);
        for (squareT sq=0; sq < 64; sq++) {
            ctree->board[sq] = readOneByte (fp);
        }

        // Read the moves:
        ctree->tree.moveCount = readFourBytes (fp);
        ctree->tree.totalCount = readFourBytes (fp);

        uint numMoves = ctree->tree.moveCount;
        for (uint i=0; i < numMoves; i++) {
            // Read this move node:

            treeNodeT * tnode = &(ctree->tree.node[i]);
            readSimpleMove (fp, &(tnode->sm));
            readString (fp, tnode->san, 8);
            for (uint res = 0; res < 4; res++) {
                tnode->freq[res] = readFourBytes (fp);
            }
            tnode->total = readFourBytes (fp);
            tnode->score = readFourBytes (fp);
            tnode->ecoCode = readTwoBytes (fp);
            tnode->eloCount = readFourBytes (fp);
            tnode->eloSum = readFourBytes (fp);
            tnode->perfCount = readFourBytes (fp);
            tnode->perfSum = readFourBytes (fp);
            tnode->yearCount = readFourBytes (fp);
            tnode->yearSum = readFourBytes (fp);
        }

        // Read the compressed filter:
        ctree->cfilter = new CompressedFilter;
        ctree->cfilter->ReadFromFile (fp);
    }
#ifdef WINCE
     my_Tcl_Close(NULL, fp);
#else
    fclose (fp);
#endif
    return OK;
}
Exemple #8
0
float readFloat (FILE *hatFile)
{
    return readFourBytes(hatFile);
}
Exemple #9
0
unsigned long readInt (FILE *hatFile)
{
    return readFourBytes(hatFile);
}
Exemple #10
0
unsigned long readPointer (FILE *hatFile)
{
    return readFourBytes(hatFile);
}