/**
 *  Sega Saturn Cartridge Firmware Flash Utility
 *  by cafe-alpha.
 *  WWW: http://ppcenter.free.fr/pskai/
 *
 *  Made from "Sega Saturn cartridge flash tool", by Anders Montonen.
 *
 *  See LICENSE file for details.
**/

#ifndef FLASH_H_
#define FLASH_H_

#include <stdio.h>

typedef void (*FctEraseCallback)(int PageCnt, int Page);

/* Structure used to store write/erase check results. */
typedef struct Romcheck
{
    unsigned long  ErrorOffset;
    unsigned char* pErrorData;
} Romcheck_t;

typedef struct FlashDev
{
    const char*   pVendorString;
    const char*   pDeviceString;
    unsigned long RomSize;
    unsigned long PageSize;
    unsigned long BrickWarning; /* In the case of unknown device ... at your own risk. */
    void        (*EraseFlash)(const struct FlashDev*);
    void        (*WriteFlashPage)(const struct FlashDev*, const unsigned long, const unsigned short*);
    FctEraseCallback EraseCallback;

    /* status about if chip can be flashed or not, or ... maybe. */
#define FLASH_HOPELESS   0
#define FLASH_MAYBEOK    1
#define FLASH_RECOGNIZED 2
    int Flashability;

    /* Write/erase check functions. */
    int (*EraseOK)(const struct FlashDev*, Romcheck_t*);
    int (*WriteOK)(const struct FlashDev*, Romcheck_t*, const unsigned short*);

} FlashDevice_t;

void FillFlashDeviceInfo(const unsigned short VendorID, const unsigned short DeviceID,
                         FlashDevice_t *pFlashDevice);

void SetFlashEraseCallback(FctEraseCallback fct, FlashDevice_t *pFlashDevice);

unsigned short FlashGetVendorID(void);
unsigned short FlashGetDeviceID(void);

#endif /* FLASH_H_ */
