void GuiDlgStateSelect::UpdateScreenShot(char *file)
{
    if( sprScreenShot != NULL ) {
        RemoveAndDelete(sprScreenShot, GuiEffectFade(SSEL_FADE_FRAMES, file? SSEL_FADE_DELAY:0));
        sprScreenShot = NULL;
    }
    if( file != NULL ) {
        int size;
        void* buffer = zipLoadFile(file, "screenshot.png", &size);

        sprScreenShot = new GuiSprite(this, "screenshot");
        if( buffer == NULL || !sprScreenShot->LoadImage((const unsigned char*)buffer) ) {
            GuiImages::AssignSpriteToImage(sprScreenShot, "image_noise");
        }
        if( buffer != NULL ) {
            free(buffer);
        }
        sprScreenShot->SetPosition(posx+sizex-283-SSEL_X_SPACING-2*SSEL_MENU_SPACING,
                                   posy+sizey/2-106);
        sprScreenShot->SetRefPixelPosition(0, 0);
        sprScreenShot->SetScaledWidth(283.0f);
        sprScreenShot->SetScaledHeight(212.0f);
        AddTop(sprScreenShot, GuiEffectFade(SSEL_FADE_FRAMES));
    }
}
SaveState* saveStateOpenForRead(const char* fileName) {
    SaveState* state = (SaveState*)malloc(sizeof(SaveState));
    Int32 size = 0;
    void* buffer = zipLoadFile(stateFile, getIndexedFilename(fileName), &size);

    state->allocSize = size;
    state->buffer = buffer;
    state->size = size / sizeof(UInt32);
    state->offset = 0;
    state->fileName[0] = 0;

    return state;
}
Exemple #3
0
UInt8* romLoad(const char *fileName, const char *fileInZipFile, int* size)
{
    UInt8* buf = NULL;
    FILE *file;

    if (fileName == NULL || strlen(fileName) == 0) {
        goto error;
    }

    if (fileInZipFile != NULL && strlen(fileInZipFile) == 0) {
        fileInZipFile = NULL;
    }

    if (fileInZipFile != NULL) {
        buf = zipLoadFile(fileName, fileInZipFile, size);
        if (buf == NULL)
           goto error;
        return buf;
    }

    file = fopen(fileName, "rb");
    if (file == NULL) {
        goto error;
    }

    fseek(file, 0, SEEK_END);
    *size = ftell(file);
    if (*size == 0) {
        fclose(file);
        return malloc(1);
    }

    fseek(file, 0, SEEK_SET);

    buf = malloc(*size);
    
    *size = fread(buf, 1, *size, file);
    fclose(file);

    return buf;

error:
    if (fileName && fileName[0])
    {
      printf("cannot open file : %s\n", fileName);
      fflush(stdout);
    }
    return NULL;
}
Exemple #4
0
int tapeInsert(char *name, const char *fileInZipFile)
{
    FILE* file;
    Properties* pProperties = propGetGlobalProperties();

    if (ramImageBuffer != NULL) {
        file = fopen(tapePosName, "w");
        if (file != NULL) {
            char buffer[32];
            sprintf(buffer, "POS:%d", ramImagePos);
            fwrite(buffer, 1, 32, file);
            fclose(file);
        }

        if (*tapeName && tapeRdWr) {
            tapeSave(tapeName, tapeFormat);
        }

        free(ramImageBuffer);
        ramImageBuffer = NULL;
    }

    *tapeName = 0;

    if(!name) {
        return 1;
    }

    // Create filename for tape position file
    sprintf(tapePosName, "%s" DIR_SEPARATOR "%s", tapeBaseDir, stripPath(name));
    if (fileInZipFile == NULL) {
        strcpy(tapeName, name);
    }
    else {
        strcat(tapePosName, stripPath((char*)fileInZipFile));
    }
    strcat(tapePosName, ".pos");

    ramImagePos = 0;

    // Load and verify tape position
    file = fopen(tapePosName, "rb");
    if (file != NULL) {
        char buffer[32] = { 0 };
        fread(buffer, 1, 31, file);
        sscanf(buffer, "POS:%d", &ramImagePos);
        fclose(file);
    }

    if (fileInZipFile != NULL) {
        ramImageBuffer = zipLoadFile(name, fileInZipFile, &ramImageSize);
        if (ramImagePos > ramImageSize) {
            ramImagePos = ramImageSize;
        }
    }
    else {
        file = fopen(name,"rb");
        if (file != NULL) {
            // Load file into RAM buffer
            fseek(file, 0, SEEK_END);
            ramImageSize = ftell(file);
            fseek(file, 0, SEEK_SET);
            ramImageBuffer = malloc(ramImageSize);
            if (ramImageBuffer != NULL) {
                if (ramImageSize != fread(ramImageBuffer, 1, ramImageSize, file)) {
                    free(ramImageBuffer);
                    ramImageBuffer = NULL;
                }
            }
            fclose(file);
        }
    }

    if (rewindNextInsert&&pProperties->cassette.rewindAfterInsert) ramImagePos=0;
    rewindNextInsert=0;

    if (ramImageBuffer != NULL) {
        UInt8* ptr = ramImageBuffer + ramImageSize - 17;
        int cntFMSXDOS = 0;
        int cntFMSX98  = 0;
        int cntSVICAS  = 0;

        while (ptr >= ramImageBuffer) {
            if (!memcmp(ptr, hdrFMSXDOS, sizeof(hdrFMSXDOS))) {
                cntFMSXDOS++;
            }
            if (!memcmp(ptr, hdrFMSX98, sizeof(hdrFMSX98))) {
                cntFMSX98++;
            }
            if (!memcmp(ptr, hdrSVICAS, sizeof(hdrSVICAS))) {
                cntSVICAS++;
            }
            ptr--;
        }

        if (cntSVICAS > cntFMSXDOS && cntSVICAS > cntFMSX98) {
            tapeFormat     = TAPE_SVICAS;
            tapeHeader     = hdrSVICAS;
            tapeHeaderSize = sizeof(hdrSVICAS);
        }
        else if (cntFMSXDOS >= cntFMSX98) {
            tapeFormat     = TAPE_FMSXDOS;
            tapeHeader     = hdrFMSXDOS;
            tapeHeaderSize = sizeof(hdrFMSXDOS);
        }
        else {
            tapeFormat     = TAPE_FMSX98AT;
            tapeHeader     = hdrFMSX98;
            tapeHeaderSize = sizeof(hdrFMSX98);
        }
    }

    if (ramImagePos > ramImageSize) {
        ramImagePos = ramImageSize;
    }

    return ramImageBuffer != NULL;
}