eeprom.pp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. program eeprom;
  2. {$mode objfpc}
  3. uses
  4. ctypes, nds9, sysutils;
  5. var
  6. header1: array [0..511] of cchar;
  7. header2: array [0..511] of cchar;
  8. vtype, vsize: integer;
  9. data: array [0..511] of cchar;
  10. procedure pause();
  11. begin
  12. iprintf('Press start...'#10);
  13. while true do
  14. begin
  15. scanKeys();
  16. if (keysDown() and KEY_START)<>0 then
  17. exit;
  18. swiWaitForVBlank();
  19. end;
  20. scanKeys();
  21. end;
  22. var
  23. x, y: integer;
  24. c: u8;
  25. begin
  26. consoleDemoInit();
  27. iprintf('Reading cart info...'#10);
  28. sysSetBusOwners(true, true); // give ARM9 access to the cart
  29. while true do
  30. begin
  31. // Read the header twice to verify.
  32. // If the card is being encrypted, we will get random junk
  33. cardReadHeader(@header1);
  34. cardReadHeader(@header2);
  35. // Make sure we got the same data twice
  36. while (CompareMem(@header1, @header2, 32)) do
  37. begin
  38. // If not, the card needs ejected and reinserted into the DS
  39. iprintf('Please eject & reinsert DS card.'#10);
  40. pause();
  41. cardReadHeader(@header1);
  42. cardReadHeader(@header2);
  43. end;
  44. // Add a null char right after the game title, so we can print it
  45. header1[32] := cchar(#0);
  46. // Read some various info about the EEPROM
  47. vtype := cardEepromGetType();
  48. vsize := cardEepromGetSize();
  49. iprintf('Game ID: %s'#10, header1[0]);
  50. iprintf('EEPROM:'#10);
  51. iprintf(' Type: %d'#10, vtype);
  52. iprintf(' Size: %d'#10, vsize);
  53. pause();
  54. // Read the first 512 bytes of EEPROM
  55. cardReadEeprom(0, @data, 512, vtype);
  56. iprintf('First 160 bytes of EEPROM: '#10);
  57. // Print 20 rows of 8 bytes each
  58. for y := 0 to 19 do
  59. begin
  60. // print 8 bytes as hex
  61. for x := 0 to 7 do
  62. begin
  63. iprintf('%02x ', data[y*8 + x]);
  64. end;
  65. // print 8 bytes as characters
  66. for x := 0 to 7 do
  67. begin
  68. c := data[y*8 + x];
  69. if not (char(c) in [#0..#7, #14..#31, #127]) then // only display if it's a printable character
  70. iprintf('%c', c)
  71. else
  72. iprintf('.');
  73. end;
  74. end;
  75. iprintf('Insert a new card to read again'#10);
  76. pause();
  77. end;
  78. end.