MCPcopy Create free account
hub / github.com/TASEmulators/fceux / LoadTable

Function LoadTable

src/drivers/win/memview.cpp:381–435  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

379}
380
381int LoadTable(const char* nameo)
382{
383 char str[50];
384 FILE *FP;
385 int i, line, charcode1, charcode2;
386
387 for(i = 0;i < 256;i++){
388 chartable[i] = 0;
389 }
390
391 FP = fopen(nameo,"r");
392 line = 0;
393 while((fgets(str, 45, FP)) != NULL){/* get one line from the file */
394 line++;
395
396 if(strlen(str) < 3)continue;
397
398 charcode1 = charcode2 = -1;
399
400 if((str[0] >= 'a') && (str[0] <= 'f')) charcode1 = str[0]-('a'-0xA);
401 if((str[0] >= 'A') && (str[0] <= 'F')) charcode1 = str[0]-('A'-0xA);
402 if((str[0] >= '0') && (str[0] <= '9')) charcode1 = str[0]-'0';
403
404 if((str[1] >= 'a') && (str[1] <= 'f')) charcode2 = str[1]-('a'-0xA);
405 if((str[1] >= 'A') && (str[1] <= 'F')) charcode2 = str[1]-('A'-0xA);
406 if((str[1] >= '0') && (str[1] <= '9')) charcode2 = str[1]-'0';
407
408 if(charcode1 == -1){
409 UnloadTableFile();
410 fclose(FP);
411 return line; //we have an error getting the first input
412 }
413
414 if(charcode2 != -1) charcode1 = (charcode1<<4)|charcode2;
415
416 for(i = 0;i < (int)strlen(str);i++)if(str[i] == '=')break;
417
418 if(i == strlen(str)){
419 UnloadTableFile();
420 fclose(FP);
421 return line; //error no '=' found
422 }
423
424 i++;
425 //ORing i with 32 just converts it to lowercase if it isn't
426 if(((str[i]|32) == 'r') && ((str[i+1]|32) == 'e') && ((str[i+2]|32) == 't'))
427 charcode2 = 0x0D;
428 else charcode2 = str[i];
429
430 chartable[charcode1] = charcode2;
431 }
432 TableFileLoaded = 1;
433 fclose(FP);
434 return -1;
435}
436
437//should return -1, otherwise returns the line number it had the error on
438int LoadTableFile()

Callers 2

LoadTableFileFunction · 0.85
MemViewCallBFunction · 0.85

Calls 1

UnloadTableFileFunction · 0.85

Tested by

no test coverage detected