manager.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. * Mapper manager - The peTI-NESulator Project
  3. * manager.c
  4. *
  5. * Created by Manoël Trapier.
  6. * Copyright (c) 2002-2019 986-Studio.
  7. *
  8. */
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <mappers/manager.h>
  12. #include <os_dependent.h>
  13. MapperIRQ mapper_irqloop;
  14. MapperDump mapper_dump;
  15. MapperWriteHook mapper_hook;
  16. typedef struct Mapper_
  17. {
  18. uint8_t id;
  19. char *name;
  20. MapperInit init;
  21. MapperIRQ irq;
  22. MapperDump dump;
  23. } Mapper;
  24. #include "mappers_list.h"
  25. void mapper_list()
  26. {
  27. Mapper *ptr = &(Mappers[0]);
  28. console_printf(Console_Default, "Available mappers:\n");
  29. while (ptr->name != NULL)
  30. {
  31. console_printf(Console_Default, "%d - %s\n", ptr->id, ptr->name);
  32. ptr++;
  33. }
  34. }
  35. int mapper_init(NesCart *cart)
  36. {
  37. Mapper *ptr = &(Mappers[0]);
  38. console_printf(Console_Default, "Search for a compatible mapper ID #%d:\n", cart->MapperID);
  39. while (ptr->name != NULL)
  40. {
  41. if (ptr->id == cart->MapperID)
  42. {
  43. console_printf(Console_Default, "Found mapper ID #%d - '%s'\n", ptr->id, ptr->name);
  44. if (ptr->init)
  45. {
  46. ptr->init(cart);
  47. }
  48. mapper_irqloop = ptr->irq;
  49. mapper_dump = ptr->dump;
  50. return 0;
  51. }
  52. ptr++;
  53. }
  54. console_printf(Console_Default, "No compatible mapper found!\n");
  55. return -1;
  56. }