card.inc 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. (*
  2. ------------------------------------------------------------------------------
  3. Copyright (C) 2005
  4. Jason Rogers (dovoto)
  5. Dave Murphy (WinterMute)
  6. This software is provided 'as-is', without any express or implied
  7. warranty. In no event will the authors be held liable for any
  8. damages arising from the use of this software.
  9. Permission is granted to anyone to use this software for any
  10. purpose, including commercial applications, and to alter it and
  11. redistribute it freely, subject to the following restrictions:
  12. 1. The origin of this software must not be misrepresented; you
  13. must not claim that you wrote the original software. If you use
  14. this software in a product, an acknowledgment in the product
  15. documentation would be appreciated but is not required.
  16. 2. Altered source versions must be plainly marked as such, and
  17. must not be misrepresented as being the original software.
  18. 3. This notice may not be removed or altered from any source
  19. distribution.
  20. ------------------------------------------------------------------------------
  21. Conversion by Legolas (http://itaprogaming.free.fr) for freepascal compiler
  22. (http://www.freepascal.org)
  23. ------------------------------------------------------------------------------
  24. *)
  25. {$ifdef NDS_INTERFACE}
  26. const
  27. // Card bus
  28. CARD_COMMAND : pcuint8 = pointer($040001A8);
  29. REG_ROMCTRL : pcuint32 = pointer($040001A4);
  30. REG_AUXSPICNT : pcuint16 = pointer($040001A0);
  31. REG_AUXSPICNTH : pcuint8 = pointer($040001A1);
  32. REG_AUXSPIDATA : pcuint8 = pointer($040001A2);
  33. CARD_DATA_RD : pcuint32 = pointer($04100010);
  34. CARD_1B0 : pcuint32 = pointer($040001B0);
  35. CARD_1B4 : pcuint32 = pointer($040001B4);
  36. CARD_1B8 : pcuint16 = pointer($040001B8);
  37. CARD_1BA : pcuint16 = pointer($040001BA);
  38. CARD_CR1_ENABLE = $80; // in byte 1, i.e. 0x8000
  39. CARD_CR1_IRQ = $40; // in byte 1, i.e. 0x4000
  40. // SPI EEPROM COMMANDS
  41. EEPROM_WRSR = $01;
  42. EEPROM_WRDI = $04;
  43. EEPROM_RDSR = $05;
  44. EEPROM_WREN = $06;
  45. EEPROM_RDID = $9f;
  46. // ROMCTRL register:
  47. CARD_ACTIVATE = (1 shl 31); // when writing, get the ball rolling
  48. CARD_WR = (1 shl 30);
  49. CARD_nRESET = (1 shl 29); // value on the /reset pin (1 = high out, not a reset state, 0 = low out = in reset)
  50. CARD_SEC_LARGE = (1 shl 28); // when writing
  51. CARD_CLK_SLOW = (1 shl 27); // when writing
  52. CARD_SEC_CMD = (1 shl 22); // The command transfer will be hardware encrypted (KEY2)
  53. CARD_SEC_SEED = (1 shl 15); // Apply encryption (KEY2) seed to hardware registers
  54. CARD_SEC_EN = (1 shl 14); // Security enable
  55. CARD_SEC_DAT = (1 shl 13); // The data transfer will be hardware encrypted (KEY2)
  56. function CARD_BLK_SIZE(n: cint): cint; inline;
  57. function CARD_DELAY2(n: cint): cint; inline;
  58. function CARD_DELAY1(n: cint): cint; inline;
  59. const
  60. // 3 bits in b10..b8 indicate something
  61. // read bits
  62. CARD_BUSY = (1 shl 31); // when reading, still expecting incomming data?
  63. CARD_DATA_READY = (1 shl 23); // when reading, CARD_DATA_RD or CARD_DATA has another word of data and is good to go
  64. // Card commands
  65. CARD_CMD_DUMMY = $9F;
  66. CARD_CMD_HEADER_READ = $00;
  67. CARD_CMD_HEADER_CHIPID = $90;
  68. CARD_CMD_ACTIVATE_BF = $3C; // Go into blowfish (KEY1) encryption mode
  69. CARD_CMD_ACTIVATE_SEC = $40; // Go into hardware (KEY2) encryption mode
  70. CARD_CMD_SECURE_CHIPID = $10;
  71. CARD_CMD_SECURE_READ = $20;
  72. CARD_CMD_DISABLE_SEC = $60; // Leave hardware (KEY2) encryption mode
  73. CARD_CMD_DATA_MODE = $A0;
  74. CARD_CMD_DATA_READ = $B7;
  75. CARD_CMD_DATA_CHIPID = $B8;
  76. procedure cardWriteCommand(const command: pcuint8); cdecl; external;
  77. procedure cardPolledTransfer(flags: cuint32; destination: pcuint32; length: cuint32; const command: pcuint8); cdecl; external;
  78. procedure cardStartTransfer(const command: pcuint8; destination: pcuint32; channel: cint; flags: cuint32); cdecl; external;
  79. function cardWriteAndRead(const command: pcuint8; flags: cuint32): cuint32; cdecl; external;
  80. procedure cardParamCommand(command: cuint8; parameter, flags: cuint32; destination: pcuint32; length: cuint32); cdecl; external;
  81. procedure cardReadHeader(header: pcuint8); cdecl; external;
  82. function cardReadID(flags: cuint32): cuint32; cdecl; external;
  83. procedure cardReadEeprom(address: cuint32; data: pcuint8; length: cuint32; addrtype: cuint32); cdecl; external;
  84. procedure cardWriteEeprom(address: cuint32; data: pcuint8; length: cuint32; addrtype: cuint32); cdecl; external;
  85. function cardEepromReadID(): cuint32; cdecl; external;
  86. function cardEepromCommand(command: cuint8): cuint8; cdecl; external;
  87. function cardEepromGetType({void}): cint; cdecl; external;
  88. function cardEepromGetSize(): cuint32; cdecl; external;
  89. procedure cardEepromChipErase({void}); cdecl; external;
  90. procedure cardEepromSectorErase(address: cuint32); cdecl; external;
  91. {$endif NDS_INTERFACE}
  92. {$ifdef NDS_IMPLEMENTATION}
  93. function CARD_BLK_SIZE(n: cint): cint; inline;
  94. begin
  95. result := (n and $7) shl 24;
  96. end;
  97. function CARD_DELAY2(n: cint): cint; inline;
  98. begin
  99. result := (n and $3F) shl 16;
  100. end;
  101. function CARD_DELAY1(n: cint): cint; inline;
  102. begin
  103. result := (n and $1FFF);
  104. end;
  105. {$endif NDS_IMPLEMENTATION}