NESCarts.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*
  2. * Cart manager - The TI-NESulator Project
  3. * NESCart.c
  4. *
  5. * Created by Manoel TRAPIER.
  6. * Copyright (c) 2003-2008 986Corp. All rights reserved.
  7. *
  8. * $LastChangedDate$
  9. * $Author$
  10. * $HeadURL$
  11. * $Revision$
  12. *
  13. */
  14. /* System Headers */
  15. #if !defined(__TIGCC__) && !defined(__GCC4TI__) && !defined(__GTC__)
  16. #include <stdlib.h>
  17. #include <stdio.h>
  18. #include <memory.h>
  19. #else /* Support for TI-68k compilation */
  20. #define TIGCC_COMPAT
  21. #include <tigcclib.h>
  22. #endif
  23. /* TI-NES headers */
  24. #include <os_dependent.h>
  25. #include <NESCarts.h>
  26. #include <os_dependent.h>
  27. #include <mappers/manager.h>
  28. void DumpCartProperties(FILE *out, NesCart * cart)
  29. {
  30. console_printf(Console_Verbose,
  31. "'%s' informations:\n"
  32. " Total ROM Size : 0x%06lX | Total VROM Size : 0x%06lX\n"
  33. " Mapper ID : 0x%06X | Mirroring ? : %s\n"
  34. " Battery ? : %s | 4 Screen ? : %s \n"
  35. " PROMBanks start at : %p |\n"
  36. " VROMBanks start at : %p |\n",
  37. cart->FileName,
  38. cart->PROMSize,
  39. cart->VROMSize,
  40. cart->MapperID,
  41. cart->Flags & iNES_MIRROR? "Horizontal" : "Vertical",
  42. cart->Flags & iNES_BATTERY? "Yes": "No ",
  43. cart->Flags & iNES_4SCREEN? "Yes": "No ",
  44. cart->PROMBanks,
  45. cart->VROMBanks);
  46. }
  47. int LoadCart(const char *filename, NesCart * cart)
  48. {
  49. char buffer[6];
  50. /* Load the cart into memory */
  51. cart->File = (byte *)LoadFilePtr((char *)filename);
  52. if ((cart->File == NULL) || ((int)cart->File == -1))
  53. return -1;
  54. sprintf(buffer, "%c%c%c%c", 0x4E, 0x45, 0x53, 0x1A);
  55. /* Verify that this is a real iNES valid file */
  56. if (memcmp(cart->File, buffer, 4))
  57. return -1;
  58. /* Before go elsewhere, verify that the header is clean !
  59. (aka no DiskDude! in it) */
  60. if (memcmp(cart->File+7, "DiskDude!", 9) == 0)
  61. {
  62. console_printf(Console_Warning, "\n"
  63. "*******************WARNING****************\n"
  64. "* The header of this game is not clean *\n"
  65. "* (DiskDude! pollution) I will only use *\n"
  66. "* basic MapperID (mapper 0-15). This can *\n"
  67. "* led to unexpected behavior... *\n"
  68. "* *\n"
  69. "* PLEASE CLEAN THIS FILE! *\n"
  70. "******************WARNING*****************\n\n");
  71. /* So this rom file is not clean, we can only rely on the "basic" mapperID */
  72. cart->MapperID = cart->File[6]>>4; /* Mapper Type */
  73. }
  74. else
  75. { /* This rom file is clean, we can read the extended MapperID */
  76. cart->MapperID = (cart->File[6]>>4)|(cart->File[7]&0xF0); /* Mapper Type */
  77. }
  78. /* Now fill the structure */
  79. cart->FileName = (char *)filename;
  80. cart->PROMSize = cart->File[4] * 16 * 1024; /* Size of PROM */
  81. cart->VROMSize = cart->File[5] * 8 * 1024; /* Size of VROM */
  82. cart->Flags = cart->File[6] & 0x0F;
  83. /* We don't and we will never support trainer-ed ROM */
  84. if (cart->Flags & iNES_TRAINER)
  85. {
  86. console_printf(Console_Error, "\n"
  87. "********************ERROR*****************\n"
  88. "* This cart have an embedded trainer. *\n"
  89. "* There is NO support for them. *\n"
  90. "* Please use a CLEAN dump if you want *\n"
  91. "* to play this game. *\n"
  92. "********************ERROR*****************\n\n");
  93. return -1;
  94. }
  95. cart->PROMBanks = cart->File + 16; /* Pointer on the first PROM */
  96. cart->VROMBanks = cart->PROMBanks + cart->PROMSize; /* Pointer on the first VROM */
  97. DumpCartProperties(stdout, cart);
  98. return 0;
  99. }