scan-sd.4th 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. \ scan-disk
  2. base @ decimal
  3. variable error-count
  4. variable max-time
  5. variable min-time
  6. 128 constant number-of-sectors
  7. 0 max-time !
  8. $7fffffff min-time !
  9. : scan-sector ( u -- ticks f )
  10. timer-read >r
  11. >r here 1024 + number-of-sectors r> read-sectors timer-read >r ?dup
  12. if drop
  13. 0 12 lcd-at-xy s" error count:" lcd-type
  14. 14 12 lcd-at-xy
  15. 1 error-count +! error-count @ lcd-number true
  16. filesystem-init
  17. else false then
  18. 2r> swap - number-of-sectors / swap
  19. ;
  20. : scan-disk-from ( u -- )
  21. begin
  22. dup 14 3 lcd-at-xy lcd-number
  23. dup scan-sector if 2drop exit then
  24. dup 14 5 lcd-at-xy lcd-number
  25. dup
  26. min-time @ min dup min-time !
  27. 14 7 lcd-at-xy lcd-number
  28. max-time @ max dup max-time !
  29. 14 9 lcd-at-xy lcd-number
  30. number-of-sectors +
  31. button?
  32. until
  33. drop
  34. ;
  35. : test-sd ( -- )
  36. key-flush
  37. ctp-flush
  38. button-flush
  39. lcd-cls s" Reading SD card" lcd-type
  40. 0 3 lcd-at-xy s" sector count:" lcd-type
  41. 0 5 lcd-at-xy s" sector time:" lcd-type
  42. 0 7 lcd-at-xy s" min. time:" lcd-type
  43. 0 9 lcd-at-xy s" max. time:" lcd-type
  44. 9 lcd-text-rows 1- lcd-at-xy s" Clear Exit" lcd-type
  45. begin
  46. 0 scan-disk-from
  47. ctp-pos? if ctp-flush then
  48. key? if key-flush then
  49. button?
  50. if
  51. button
  52. case
  53. button-left of
  54. 0 error-count !
  55. endof
  56. button-centre of
  57. endof
  58. button-right of
  59. exit
  60. endof
  61. endcase
  62. then
  63. again
  64. ;
  65. base !