Mirror of CollapseOS
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.

79 lines
1.4KB

  1. ; *** Consts ***
  2. ; Memory address where the AT28 is configured to start
  3. .equ AT28W_MEMSTART 0x2000
  4. ; Value mismatch during validation
  5. .equ AT28W_ERR_MISMATCH 0x10
  6. ; *** Variables ***
  7. .equ AT28W_MAXBYTES AT28W_RAMSTART
  8. .equ AT28W_RAMEND @+2
  9. ; *** Code ***
  10. at28wMain:
  11. ld de, .argspecs
  12. ld ix, AT28W_MAXBYTES
  13. call parseArgs
  14. jr z, at28wInner
  15. ; bad args
  16. ld a, SHELL_ERR_BAD_ARGS
  17. ret
  18. .argspecs:
  19. .db 0b111, 0b101, 0
  20. at28wInner:
  21. ; Reminder: words in parseArgs aren't little endian. High byte is first.
  22. ld a, (AT28W_MAXBYTES)
  23. ld b, a
  24. ld a, (AT28W_MAXBYTES+1)
  25. ld c, a
  26. ld hl, AT28W_MEMSTART
  27. call at28wBCZero
  28. jr nz, .loop
  29. ; BC is zero, default to 0x2000 (8k, the size of the AT28)
  30. ld bc, 0x2000
  31. .loop:
  32. call blkGetB
  33. jr nz, .loopend
  34. ld (hl), a
  35. ld e, a ; save expected data for verification
  36. ; initiate polling
  37. ld a, (hl)
  38. ld d, a
  39. .wait:
  40. ; as long as writing operation is running, IO/6 will toggle at each
  41. ; read attempt. We know that write is finished when we read the same
  42. ; value twice.
  43. ld a, (hl)
  44. cp d
  45. jr z, .waitend
  46. ld d, a
  47. jr .wait
  48. .waitend:
  49. ; same value was read twice. A contains our final value for this memory
  50. ; address. Let's compare with what we're written.
  51. cp e
  52. jr nz, .mismatch
  53. inc hl
  54. dec bc
  55. call at28wBCZero
  56. jr nz, .loop
  57. .loopend:
  58. ; We're finished. Success!
  59. xor a
  60. ret
  61. .mismatch:
  62. ld a, AT28W_ERR_MISMATCH
  63. ret
  64. at28wBCZero:
  65. xor a
  66. cp b
  67. ret nz
  68. cp c
  69. ret