static PyObject * Rawhid_open(Rawhid* self, PyObject *args, PyObject *keywords)
{
    // close automatically if already opened
    if (self->opened)
    {
        if (!PyObject_CallMethod((PyObject *)self, "close", NULL))
        {
            return NULL;
        }
    }

    /* We don't expose the 'maximum number of devices' parameter to rawhid; it
     * complicates the Python interface and I couldn't think of a use for it.
     * If you want it, send me an email. */
    static char *kwlist[] = {"vid", "pid", "usage_page", "usage", "product", NULL};

    int vid = 0x16c0;
    int pid = 0x0480;
    int usage_page = 0xffab;
    int usage = 0x0200;
    char *product = NULL; // null-terminated

    int ok = PyArg_ParseTupleAndKeywords(args, keywords, "|iiiiz", kwlist, &vid, &pid, &usage_page, &usage, &product);
    if (!ok)
        return NULL;

    //printf("vid = 0x%x, pid = 0x%x, up = 0x%x, u = 0x%x, product = '%s'\n", vid, pid, usage_page, usage, product);

    int dev = rawhid_open(1, vid, pid, usage_page, usage, product);

    if (dev)
    {
        // found a device
        self->opened = 1;
        Py_RETURN_NONE;
    }
    else
    {
        PyErr_SetString(PyExc_IOError, "No device found");
        return NULL;
    }
}
Example #2
0
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{
Example #3
0
JNIEXPORT jint JNICALL Java_org_waxbee_RawHid_open(JNIEnv *env, jclass clazz,
		jint max, jint vid, jint pid, jint usage_page, jint usage)
{
	return rawhid_open(max, vid, pid, usage_page, usage);
}