Classic Computer Magazine Archive COMPUTE! ISSUE 73 / JUNE 1986 / PAGE 11

Readers Feedback

The Editors and Readers of COMPUTE!

If you have any questions, comments, or suggestions you would like to see addressed in this column, write to "Readers' Feedback," COMPUTE!, P.O. Box 5406, Greensboro, NC 27403. Due to the volume of mail we receive, we regret that we cannot provide personal answers to technical questions.

64 RAM Report
Can you give me a short program that tests the RAM in my 64? I have had trouble running a particular BASIC program and think that my computer must have a defective RAM chip.

Fred Wayne

Though it's tempting to blame the hardware when things go awry, RAM chips rarely fail. Every time you turn on a Commodore 64, it performs a RAM verification as part of its normal power-up sequence. It tests every RAM address from location 1024 (the start of screen memory) upward until it hits a ROM (Read Only Memory) location that can't be written to. Unless a cartridge is installed, the test includes all of the BASIC programming space (locations 2048-40959).
    Here's how the power-up test works. After saving the original contents of the tested memory location, the computer stores the value 85 ($55) there, then reads the contents back to make sure the operation was successful. Then it stores the value 170 ($AA) there and reads the contents again. To understand why those particular values are used, look at them in binary form:

01010101 = $55 = 85
10101010 = $AA = 170

    As you can see, every one bit in the first number is a zero bit in the second and vice versa. While you could test a location by successively writing and reading back every value from 0 to 255 (the maximum range for a single address), this method checks whether you can write and read back a one and a zero in each of the location's eight bits-which amounts to much the same thing. If a RAM address passes both tests, the 64 restores its original contents and proceeds to the next higher location, stopping as soon as it finds a read-back value that doesn't match what was just written. This normally happens at location 40960, the start of BASIC ROM. The location just below that (40959) is used as the top of BASIC memory.
    Later in the startup sequence, the 64 subtracts 2048 from the top-of-memory value to calculate the number of bytes free for the startup message. Since 40959 - 2048 = 38911, the familiar message 38911 BASIC BYTES FREE tells you that the 64 just wrote and read back two values for every address in BASIC program space without detecting any errors.
    If you're not convinced by the builtin test, here's a short ML program that tests the 64's RAM somewhat more thoroughly, writing and reading back every value from 0 to 255 before it concludes that a RAM address is functional. Be sure to save the program before you run it since the ML portion erases the BASIC loader:

FK 10 ADR=49152
JG 20 READ BYT:IF BYT<>256 THE
      N POKE ADR,BYT:ADR=ADR+1
      :CK=CK+BYT:GOTO 20
RC 30 IF CK<>11516 THEN PRINT"
      ERROR IN DATA STATEMENTS
      --CHECK TYPING":END
JA 40 PRINT "PRESS RETURN TO C
      HECK BASIC RAM":PRINT
FB 50 PRINT "SYS 49152"CHR$(14
      5)CHR$(145)CHR$(145)
DR 49152 DATA 169,0,133,251,16
         9,8,133,252,32,228,25
         5
PD 49158 DATA 208,58,166,251,1
         65,252,32,205,189,169
         ,32
SQ 49164 DATA 32,210,255,160,0
         ,162,0,202,138,145,25
         1
FP 49170 DATA 209,251,240,18,1
         52,72,138,72,169,72,1
         60
JA 49176 DATA 192,32,30,171,10
         4,170,104,168,76,59,1
         92
DQ 49182 DATA 224,0,208,226,23
         0,251,208,2,230,252,1
         65
RQ 49188 DATA 252,201,160,208,
         193,96,157,95,18,66,6
         5
BX 49194 DATA 68,146,32,0,256


    This program checks the 51199 RAM locations from 2048 to 53247, which includes all of BASIC program space as well as the 8K of RAM underneath BASIC ROM and the 4K RAM zone from 49152 to 53247. If a location passes the test, its address is printed. If not, you'll see the message BAD in reverse video with an arrow pointing to the address. Since it performs over 13 million (51199*256) read/write operations, this program takes about 15 minutes to run. You can cut it short by pressing any key.