Drivers for the MNT ZZ9000 graphics and ARM coprocessor card for classic Amigas.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

123 lines
2.5 KiB

  1. #include <exec/resident.h>
  2. #include <exec/errors.h>
  3. #include <exec/memory.h>
  4. #include <exec/lists.h>
  5. #include <exec/alerts.h>
  6. #include <exec/tasks.h>
  7. #include <exec/io.h>
  8. #include <libraries/expansion.h>
  9. #include <devices/trackdisk.h>
  10. #include <devices/timer.h>
  11. #include <devices/scsidisk.h>
  12. #include <dos/filehandler.h>
  13. #include <proto/exec.h>
  14. #include <proto/disk.h>
  15. #include <proto/expansion.h>
  16. #include "mntsd_cmd.h"
  17. //#define bug(x,args...) kprintf(x ,##args);
  18. //#define debug(x,args...) bug("%s:%ld " x "\n", __func__, (unsigned long)__LINE__ ,##args)
  19. void sd_reset(void* registers) {
  20. volatile struct MNTUSBSRegs* regs = (volatile struct MNTUSBSRegs*)registers;
  21. regs->status = 0; // reset command
  22. }
  23. #define BLOCKS_AT_ONCE 32
  24. uint16 sdcmd_read_blocks(void* registers, uint8* data, uint32 block, uint32 len) {
  25. uint32 i=0, j=0;
  26. uint32 offset=0;
  27. uint32 num_blocks=1;
  28. volatile struct MNTUSBSRegs* regs = (volatile struct MNTUSBSRegs*)registers;
  29. Forbid();
  30. while (i<len) {
  31. offset = i<<SD_SECTOR_SHIFT;
  32. num_blocks = BLOCKS_AT_ONCE;
  33. if ((len-i)<BLOCKS_AT_ONCE) {
  34. num_blocks = len-i;
  35. }
  36. regs->status = num_blocks;
  37. regs->rx_hi = ((block+i)>>16);
  38. regs->rx_lo = (block+i)&0xffff;
  39. // FIXME: more specific error?
  40. if (regs->status == 0) {
  41. return SDERRF_PARAM;
  42. }
  43. for (j=0; j<num_blocks; j++) {
  44. regs->bufsel = j;
  45. memcpy(data+offset+(j<<SD_SECTOR_SHIFT), registers-0xd0+0xa000, 512);
  46. }
  47. i += num_blocks;
  48. }
  49. Permit();
  50. return 0;
  51. }
  52. uint16 sdcmd_write_blocks(void* registers, uint8* data, uint32 block, uint32 len) {
  53. uint32 i=0, j=0;
  54. uint32 offset=0;
  55. uint16 status=0;
  56. uint32 num_blocks=1;
  57. struct MNTUSBSRegs* regs = (struct MNTUSBSRegs*)registers;
  58. Forbid();
  59. while (i<len) {
  60. offset = i<<SD_SECTOR_SHIFT;
  61. num_blocks = BLOCKS_AT_ONCE;
  62. if ((len-i)<BLOCKS_AT_ONCE) {
  63. num_blocks = len-i;
  64. }
  65. for (j=0; j<num_blocks; j++) {
  66. regs->bufsel = j;
  67. memcpy(registers-0xd0+0xa000, data+offset+(j<<SD_SECTOR_SHIFT), 512);
  68. }
  69. regs->status = num_blocks;
  70. regs->tx_hi = ((block+i)>>16);
  71. regs->tx_lo = (block+i)&0xffff;
  72. // FIXME: more specific error?
  73. if (regs->status == 0) {
  74. return SDERRF_PARAM;
  75. }
  76. i += num_blocks;
  77. }
  78. Permit();
  79. return 0;
  80. }
  81. uint16 sdcmd_present() {
  82. // FIXME
  83. return 1;
  84. }
  85. uint16 sdcmd_detect() {
  86. return 0;
  87. }
  88. uint32 sdcmd_capacity(void* registers) {
  89. struct MNTUSBSRegs* regs = (struct MNTUSBSRegs*)registers;
  90. if (regs->status == 0) {
  91. return 0;
  92. }
  93. return regs->capacity;
  94. }