memtestsplit.asm 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. ; code: language=asm-collection tabSize=8
  2. ; Requirements:
  3. ; This function must be RELOCATABLE (only relative jumps), and use NO RAM or STACK.
  4. ; These restrictions lead to somewhat long-winded, repetative code.
  5. ;; March C- algorithm:
  6. ;; 1: (up w0) write each location bottom to top with test value
  7. ;; 2: (up r0,w1) read each location bottom to top, compare to test value, then write complement
  8. ;; 3: (up r1,w0) read each location bottom to top, compare to complement, then write test value
  9. ;; 4: (dn r0,w1) read each location top to bottom, compare to test value, then write complement
  10. ;; 5: (dn r1,w0) read each location top to bottom, compare to complement, then write test value
  11. ;; 6: (dn r0) read each location top to bottom, compare to test value
  12. ; Arguments:
  13. ; hl = current memory position under test
  14. ; bc = bytes remaining to test
  15. ; iy = test data structure
  16. ; returns:
  17. ; e = all errored bits found in this block/bank/range of memory
  18. ; destroys: a,bc,d,hl
  19. ; preserves: ix
  20. memtest_init:
  21. xor a
  22. ld e,a ; reset error accumulator
  23. ret
  24. memtest_absent:
  25. ld b,h
  26. ld c,1
  27. cpl ; A := FF
  28. .redo ld (hl),a ; write FF to base
  29. cpl ; A := 0
  30. ld (bc),a ; write 00 to base+1
  31. cp (hl) ; compare to base (should be FF, should not match)
  32. jr z,.allbad ; if they match, all bits are bad, but double-check
  33. cp 0 ; are we on the first round?
  34. jr z,.redo ; yes, redo with reversed bits
  35. ret ; didn't find missing ram, exit without error
  36. .allbad:
  37. ld e,$FF ; report all bits bad
  38. ret
  39. memtest_march_w_up:
  40. .loop: ; fill upwards
  41. ld (hl),d
  42. inc hl
  43. dec bc
  44. ld a,c
  45. or b
  46. jr nz,.loop
  47. ret
  48. memtest_march_rw_up:
  49. .loop:
  50. ld a,(hl)
  51. cp d ; compare to value
  52. jr z, .cont ; memory changed, report
  53. xor d ; calculate errored bits
  54. or e
  55. ld e,a ; save error bits to e
  56. ld a,d ; reload a with correct value
  57. .cont:
  58. cpl ; take the complement
  59. ld (hl),a ; write the complement
  60. inc hl
  61. dec bc
  62. ld a,c
  63. or b
  64. jr nz,.loop
  65. ret
  66. memtest_march_rw_dn:
  67. add hl,bc ; move to end of the test area
  68. dec hl
  69. .loop:
  70. ld a,(hl)
  71. cp d ; compare to value
  72. jr z, .cont
  73. xor d ; calculate errored bits
  74. or e
  75. ld e,a ; save error bits to e
  76. ld a,d ; reload a with correct value
  77. .cont:
  78. cpl ; take the complement
  79. ld (hl),a ; write complement
  80. dec hl
  81. dec bc
  82. ld a,c
  83. or b
  84. jr nz,.loop
  85. ret
  86. memtest_march_r_dn:
  87. add hl,bc ; move to end of the test area
  88. dec hl
  89. .loop:
  90. ld a,(hl)
  91. cp d
  92. jr z,.cont
  93. xor d ; calculate errored bits
  94. or e
  95. ld e,a ; save error bits to e
  96. ld a,d ; reload a with correct value
  97. .cont:
  98. dec hl
  99. dec bc
  100. ld a,c
  101. or b
  102. jr nz,.loop
  103. ret
  104. mtmredo:
  105. ld a,d
  106. cp 0 ; if our test value is 0
  107. ld d,$55
  108. jr z,mtm1_bounce ; then rerun the tests with value $55
  109. mtm_done:
  110. sub a ; set carry flag if e is nonzero
  111. or e
  112. mtm_return:
  113. ret z
  114. scf
  115. ret
  116. memtest_march:
  117. xor a
  118. ld e,a ; reset error accumulator
  119. push hl ; save the test regs
  120. push bc
  121. call memtest_absent
  122. ld d,0
  123. .redo:
  124. memtest_split_end equ $
  125. ;-----------------------------------------------------------------------------