memtestmarch.asm 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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. memtestmarch2:
  21. ld a,0f0h ;00b0 ?????
  22. out (0c8h),a
  23. spt_ld_iya7
  24. out (0c5h),a ;This should be start floppy before memory test ends
  25. spt_ld_iya6
  26. out (0c0h),a ;00bf Program map B base
  27. memtestmarch:
  28. xor a
  29. ld e,a ; reset error accumulator
  30. ld d,a ; set the first testing value to 0
  31. checkabsent: ; quick test for completely missing bank
  32. memtest_ld_hl_base
  33. ld b,h
  34. ld c,1
  35. cpl ; A := FF
  36. .redo ld (hl),a ; write FF to base
  37. cpl ; A := 0
  38. ld (bc),a ; write 00 to base+1
  39. cp (hl) ; compare to base (should be FF, should not match)
  40. jr z,.allbad ; if they match, all bits are bad, but double-check
  41. cp 0 ; are we on the first round?
  42. jr z,.redo ; yes, redo with reversed bits
  43. jr mtm1
  44. .allbad:
  45. ld e,$FF ; report all bits bad
  46. jr mtm_done_bounce
  47. mtm1:
  48. memtest_loadregs
  49. mtm1loop: ; fill initial value upwards
  50. ld (hl),d
  51. inc hl
  52. dec bc
  53. ld a,c
  54. or b
  55. jr nz,mtm1loop
  56. mtm2: ; read value, write complement upwards
  57. memtest_loadregs
  58. mtm2loop:
  59. ld a,(hl)
  60. cp d ; compare to value
  61. jr z, mtm2cont ; memory changed, report
  62. xor d ; calculate errored bits
  63. or e
  64. ld e,a ; save error bits to e
  65. ld a,d ; reload a with correct value
  66. mtm2cont:
  67. cpl ; take the complement
  68. ld (hl),a ; write the complement
  69. inc hl
  70. dec bc
  71. ld a,c
  72. or b
  73. jr nz,mtm2loop
  74. mtm3: ; read complement, write original value upwards
  75. memtest_loadregs
  76. mtm3loop:
  77. ld a,(hl)
  78. cpl
  79. cp d ; compare to the complement
  80. jr z, mtm3cont ; memory changed, report
  81. xor d ; calculate errored bits
  82. or e
  83. ld e,a ; save error bits to e
  84. ld a,d ; reload a with correct value
  85. mtm3cont:
  86. ld (hl),d ; fill with test value
  87. inc hl
  88. dec bc
  89. ld a,c
  90. or b
  91. jr nz,mtm3loop
  92. jr mtm4
  93. mtm_done_bounce:
  94. jr mtm_done
  95. mtm1_bounce:
  96. jr mtm1
  97. mtm4: ; read test value, write complement downwards
  98. memtest_loadregs
  99. add hl,bc ; move to end of the test area
  100. dec hl
  101. mtm4loop:
  102. ld a,(hl)
  103. cp d ; compare to value
  104. jr z, mtm4cont
  105. xor d ; calculate errored bits
  106. or e
  107. ld e,a ; save error bits to e
  108. ld a,d ; reload a with correct value
  109. mtm4cont:
  110. cpl ; take the complement
  111. ld (hl),a ; write complement
  112. dec hl
  113. dec bc
  114. ld a,c
  115. or b
  116. jr nz,mtm4loop
  117. mtm5: ; read complement, write value downwards
  118. memtest_loadregs
  119. add hl,bc ; move to end of the test area
  120. dec hl
  121. mtm5loop:
  122. ld a,(hl)
  123. cpl
  124. cp d
  125. jr z, mtm5cont
  126. xor d ; calculate errored bits
  127. or e
  128. ld e,a ; save error bits to e
  129. ld a,d ; reload a with correct value
  130. mtm5cont:
  131. ld (hl),d
  132. dec hl
  133. dec bc
  134. ld a,c
  135. or b
  136. jr nz,mtm5loop
  137. mtm6: ; final check that all are zero
  138. memtest_loadregs
  139. add hl,bc ; move to end of the test area
  140. dec hl
  141. mtm6loop:
  142. ld a,(hl)
  143. cp d
  144. jr z,mtm6cont
  145. xor d ; calculate errored bits
  146. or e
  147. ld e,a ; save error bits to e
  148. ld a,d ; reload a with correct value
  149. mtm6cont:
  150. dec hl
  151. dec bc
  152. ld a,c
  153. or b
  154. jr nz,mtm6loop
  155. mtmredo:
  156. ld a,d
  157. cp 0 ; if our test value is 0
  158. ld d,$55
  159. jr z,mtm1_bounce ; then rerun the tests with value $55
  160. mtm_done:
  161. sub a ; set carry flag if e is nonzero
  162. or e
  163. mtm_return:
  164. ret z
  165. scf
  166. ret
  167. memtestmarch_end equ $
  168. ;-----------------------------------------------------------------------------