// TODO want to make sure this is executed when we are GCed static PyObject * Rawhid_close(Rawhid* self) { if (self->opened) { rawhid_close(0); self->opened = 0; } Py_RETURN_NONE; }
int main(){ // Program Var int connect; int check = 1; unsigned int verif = 0; unsigned int choixMenu = 0; unsigned int choixMapperType = 0; unsigned int choixSousMenu = 0; unsigned long int buffer_checksum[0xFF] = {0}; // unsigned long int buffer_checksum_flash[0xFF] = {0}; // HID Command Buffer & Var unsigned char HIDcommand[64]; unsigned char buffer_recv[64]; unsigned char *buffer_rom = NULL; unsigned char *buffer_flash = NULL; char gameName[36]; unsigned long address = 0; unsigned long gameSize = 0; unsigned long totalGameSize = 0; unsigned int slotAdr = 0; unsigned int slotSize = 0; unsigned int slotRegister = 0; struct timeval time; long microsec_start = 0; long microsec_end = 0; unsigned long int i=0, checksum_rom=0, checksum_flash=0; unsigned char page=0; // Output File FILE *myfile = NULL; printf("\n*** Sega MASTER SYSTEM,"); printf("\n*** Mark III and SG1000"); printf("\n*** USB Dumper"); printf("\n*** v0a 2017/05/12 - ichigo\n"); printf("-------------------------\n"); printf(" Detecting... \n"); connect = rawhid_open(1, 0x0483, 0x5750, -1, -1); if(connect <= 0){ connect = rawhid_open(1, 0x0483, 0x5750, -1, -1); if(connect <= 0){ printf(" SMS Dumper NOT FOUND!\n Exit...\n\n"); return 0; } } printf(" SMS Dumper detected!\n"); HIDcommand[0] = SMS_WAKEUP; rawhid_send(0, HIDcommand, 64, 15); while(check){ connect = rawhid_recv(0, buffer_recv, 64, 15); if(buffer_recv[0]!=0xFF){ printf("-------------------------\n"); printf(" Error reading\n Exit\n\n"); rawhid_close(0); return 0; }else{ printf(" and ready!\n"); check = 0; buffer_recv[0] = 0; } } printf("\n----------MENU-----------\n"); printf(" 1. Dump ROM\n"); printf(" 2. Dump S-RAM\n"); printf(" 3. Write/Erase S-RAM\n"); printf(" 4. Write FLASH 39SFxxx (max. 512KB)\n"); printf(" 5. Exit\n"); printf(" Enter your choice: "); scanf("%d", &choixMenu); switch(choixMenu){ case 1: // DUMP ROM printf("\n-------MAPPER TYPE-------\n"); printf(" 1. SEGA\n"); printf(" 2. Codemasters\n"); printf(" 3. Korean\n"); printf(" 4. Korean MSX 8kb\n"); printf(" 5. Exit\n"); printf(" Enter your choice: "); scanf("%d", &choixMapperType); if(choixMapperType!=5){ printf(" Size to dump in KB: "); scanf("%ld", &gameSize); printf(" Rom's name (no space/no ext): "); scanf("%32s", gameName); printf("-------------------------\n"); HIDcommand[0] = SMS_READ; totalGameSize = gameSize*1024; buffer_rom = (unsigned char*)malloc(totalGameSize); gettimeofday(&time, NULL); microsec_start = ((unsigned long long)time.tv_sec * 1000000) + time.tv_usec; //only for testing / debug - ONLY SEGA switch(choixMapperType){ case 1: strcat(gameName, "_SEGA.sms"); HIDcommand[7] = 0; //SEGA mapper slotSize = 16384; //16ko - 0x4000 break; case 2: strcat(gameName, "_CODEMASTERS.sms"); HIDcommand[7] = 1; //Codemasters mapper slotSize = 16384; //16ko - 0x4000 break; default: strcat(gameName, "_UNKNOWN.bin"); HIDcommand[7] = 0; break; } while(address < totalGameSize){ /* sega mapper dump 16ko per page = 256 * 64bytes blocs max 256 pages (0xFF) 32mbits slot0 16k - 0x0000 to 0x3FFF A14=0 A15=0 slot1 16k - 0x4000 to 0x7FFF A14=1 A15=0 slot2 16k - 0x8000 to 0xBFFF A14=0 A15=1 */ if(choixMapperType == 1 || choixMapperType == 2){ //SEGA or Codemasters if(address<0x4000){ slotAdr = address; if(choixMapperType==2){ slotRegister = 0; // slot 0 codemasters }else{ slotRegister = 0xFFFD; // slot 0 sega } }else if(address<0x8000){ slotAdr = address; if(choixMapperType==2){ slotRegister = 0x4000; // slot 1 codemasters }else{ slotRegister = 0xFFFE; // slot 1 sega } }else if(address>0x7FFF){ if(choixMapperType==2){ slotRegister = 0x8000; // slot 2 codemasters }else{ slotRegister = 0xFFFF; // slot 2 sega } slotAdr = 0x8000 + (address & 0x3FFF); } HIDcommand[3] = 1; //enable MAPPER HIDcommand[4] = (address/slotSize); //page MAPPER HIDcommand[5] = (slotRegister & 0xFF); //reg MAPPER lo adr HIDcommand[6] = (slotRegister & 0xFF00)>>8; //reg MAPPER hi adr }else if(choixMapperType == 3){ //KOREAN if(address>0x7FFF){ slotRegister = 0xA000; slotAdr = 0x8000 + (address & 0x3FFF); HIDcommand[3] = 1; //enable MAPPER HIDcommand[4] = (address/slotSize); //page MAPPER HIDcommand[5] = (slotRegister & 0xFF); //reg MAPPER lo adr HIDcommand[6] = (slotRegister & 0xFF00)>>8; //reg MAPPER hi adr }else{ slotAdr = address; } }else{
JNIEXPORT void JNICALL Java_org_waxbee_RawHid_close(JNIEnv *env, jclass clazz, jint num) { rawhid_close(num); }