eeprom.pp 2.2 KB

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