UTILITY #5: ATARI MEMORY TEST

16K Cassette or Disk


by Tony Messina


Glancing at my calendar I see that it's time once again for another installment of (trumpet fanfare) UTILITY WORLD!...but first a brief message.

I would once again like to thank everyone who has written with questions, comments and additions to the utilities presented in this series. I am answering your questions as quickly as possible, so please be patient - I promise you will get a reply. Now, back to our program.

For the past three issues (8,9,10) 1 have been directing my utilities towards the disk drive crowd while leaving my cassette-based friends in the dark. For this I apologize and I hereby make it up to you by presenting this issue's utility (number 5), entitled ATARI MEMORY TEST. There are two program listings. One will create a disk file while the other will create a boot cassette. Prior to discussing the details of the test, let's talk about memory tests in general.

What Is A Memory Test?

A simple answer would be that a memory test tests your memory to see if it's OK. To be a bit more specific, a memory test should test the integrity of your memory chips to insure that any and all values stored into them remain there. Please keep in mind that I am speaking of RAM or Random Access Memory. And now...

Believe It Or Not

Believe it or not, when memory chips go flaky, it is possible to store a number in a location, load the number immediately back in and find that it is completely different! Or, how about this: storing a 0 into a location, immediately loading the contents of that location and finding out that it's not 0!! Weird, huh? just think of the headaches . in debugging programs where you store or load values from flaky memory chip locations. To bring this point home, the following story is true (at least that's what my informant told me). Only the names have been changed to protect the innocent victims.

A Memorable Story

Mr. X wrote a little math drill program on his ZAFARI at home. Mrs. X, a teacher at a local elementary school, thought this program was really neat and wanted to take it in to show her class. After all, Mr. Happy Face, who appeared and played music when a correct answer was given, and Mr. Frown Face, who appeared when an incorrect answer was given, were both really cute.

The next day Mrs. X, math program in hand, secured a ZAFARI from the school library, set it up for her class and even invited the principal down to see this unique program in action. Little Tommy Tucker was first. The program asked "How much is 2+2, Tommy?" to which little Tommy typed in 4 and hit return. At this point everything hit the fan. Mr. Frown Face appeared with half his head missing and the rest looking like he got hit by baseball bat (I'd frown too!). The music played but sounded like something you hear in a swamp after sunset. To top it all off, the answer line said "I'm sorry Tommy, but 2+2=12615"! Mrs. X was shocked, the principal was shocked, little Tommy Tucker was shocked. Mrs. Tucker, having heard about the incident after school, called the principal asking him what kind of a &$#%#" computer came up with 2+2=12615?! Needless to say, after all the smoke cleared it was found that a whole section of one memory board was flaky. Upon replacing it, everyone was pleased with the program and they all lived happily ever after. 'Nuff said.

OK? How Do We Test Memory?

The most comprehensive and reliable methods of testing memory (at least on 8 bit machines) write values from 1 to 255 in each byte of memory to be tested, verifying each value written and halting if an error is detected. Often this procedure will be repeated several times. Although this algorithm is thorough, one might guess that it does require a great deal of time (and it does.) I have such a test and it takes about 30 seconds to test 1K or 24 minutes to test 48K! I don't know about you but I don't feel like waiting that long. Fortunately there are other ways to achieve the same results with only a slight sacrifice in efficiency. This issue's utility uses one of the fastest methods available. Before discussing the algorithm I must make a confession.

Credits, Or "Someone Please Help"

The memory test I'm presenting this issue, or at least the algorithm that performs the actual testing, was not written by me. I found this code on a faded handwritten paper stuffed inside an MOS programming manual which I purchased at a flea market for $2.00! The title written on this piece of paper was 6502 Memory Test and was written for some other computer, since the original program's origin was set at 0. Anyone recognizing this code (lines 795-1195 of the source listing) please call and let me know who wrote it as I would like to give credit where credit is due. I will take credit for the bells and whistles, code commenting (the original had zip), conversion of the program into a multipass test, fitting the program in a reasonable address space of the ATARI, and the error address isolation printout routine. OK, with that out of the way, let's get down to the meat of this program.

The Meat Of This Program

Rather than give a blow-by-blow, line-by-line description of the source code, I suggest that you run the appropriate BASIC program to create a bootable image and then run the actual memory test to see the display created when it is run. Then read through the source code to see how it was done. I will, however, discuss the algorithm. The area tested runs from page 7 to the top of available user memory. Rather than have the test run from one specific memory location to another, it is designed to test memory as a series of pages. This not only simplifies things but also allows the test to run much quicker. The program origin is at $0480. This is normally the floating point storage area but since we run our test without the BASIC cartridge there isn't a conflict. I coded the program so it will run on any memory configuration up to 48K. So don't worry if you only have 8K or 16K... the program will figure out where it can test. The program goes through 10 iterations (0-9). Each iteration consists of the following steps.

  1. Write the value $FF to all locations in the test area.
  2. Write 00 in the one out of every three bytes in memory. Memory looks like FF FF 00 FF FF 00...etc...
  3. Test the memory area and ensure the pattern above is there. Halt giving the memory address, Test value, and actual value if there is an error.
  4. If no error write all FF again.
  5. Write new pattern FF 00 FF FF 00 FF, etc....
  6. Verify memory has FF 00 FF etc...halt if error.
  7. If no error write FF.
  8. Write new pattern 00 FF FF 00 FF FF etc.
  9. Test and halt if necessary.
  10. This ends the all FF phase.
  11. Now write 00 to all locations.
  12. Write pattern 00 00 FF.
  13. Test and halt if error.
  14. No error write 00 to all memory.
  15. Write pattern 00 FF 00.
  16. Test pattern and halt if error.
  17. No error write 00 to all memory.
  18. Write pattern FF 00 00.
  19. Test and halt if error.
  20. END OF 1 ITERATION.

The program does all of the above steps 10 times! As you can see we are turning all bits on and off in the test area by using FF or 00. What we are actually doing is checking to ensure that we can set and clear all bits within the memory area. Any change to our pattern indicates flaky memory in the form of stuck bits, or erratic retaining properties of the address flagged in error. Having the test do 10 iterations just makes things tougher for it to pass. You might think that this test would take a lot of time, right? Would you believe 11 seconds per iteration on a 48K ATARI?? Believe it! This test will waste about a minute and a half of your time if you have 48K and less if you don't have 48K. The secret is in the paging technique, zero page indirect addressing and keeping the major part of the program data on page 0. Check out the source. Whoever wrote the algorithm sure knew his 6502!!

Program Drawbacks

Because of the way I implemented this program, it will not test pages 0-6 nor will it test the area of memory containing the display list and screen data for graphics mode 0. It will test the area of memory used by your BASIC programs and the majority of memory where we all tend to store our ML things. This was the price I paid for bells and whistles! If you have heartburn about this, then a modification to have the program move itself to an already tested area could be made. This is just a program and as with all programs in this series, it is open for discussion, modification and just plain study. I hope you use it and enjoy.

Disk Directions

Listing I will create self-executing disk files. Type it in, save it and then run it. Be sure you have a disk that contains DOS 2 in drive I when you run it. The file created will be called MEMTST.OBJ. When the file has been created, pull out the BASIC cartridge and Reboot with only DOS 2. When the DOS Menu appears, do a binary load of MEMTST.OBJ. The program will load and execute. DOS will be creamed by this program but don't worry.

Cassette Directions

Listing 2 will create an auto-boot cassette for you. Type in the program and then run. When you hear the 2 beeps, insert a blank cassette into your tape drive, push record and play and hit return. The tape will be created. To load it, turn off your ATARI. Rewind the tape to the start of the program just created. Push play. Hold down the START key on your ATARI and at the same time turn on the power. You will hear a beep. Press return and the tape will load. When done, the program will start automatically.

FINAL ITEMS

The test will halt if it encounters a faulty memory location. The format of the message will be:

ERROR @->$A01A TVAL->$FF AVAL->$CD

For sample purposes the above message would mean address $A01A failed our test. The Test value (TVAL) was $FF but the actual value (AVAL) in address $A01A was $CD.

The program will print TEST DONE if no errors appear.

That's it for this article. I hope to hear from someone...anyone...if they know who wrote the original implementation. As always, any questions can be directed to me here at the A.N.A.L.O.G. offices. Keep hacking and may all your memories read true.