eeprom.pp 2.0 KB

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