[Coco] 512k test

William Astle lost at l-w.ca
Fri Dec 6 23:43:59 EST 2013


On 2013-12-06 20:36, Mathieu Bouchard wrote:
> Le 2013-12-06 à 18:34:00, Arthur Flexser a écrit :
>
>> 10 LPOKE &H22345,99:LPOKE &H12345,23
>> 20 P=LPEEK(&H22345):IF P=23 THEN PRINT "UH-OH" ELSE IF P=99 THEN PRINT
>> "LOOKS GOOD SO FAR" ELSE PRINT "HUH??"
>
> Doesn't a simple LPEEK do the job ? LPEEK and LPOKE do a ?FC ERROR if
> the address is too far.

As has been mentioned by others, no, LPEEK and LPOKE cannot tell you 
directly if you only have 128K memory. Here is the more detailed 
explanation for those interested.

On a 128K system, the memory present is ghosted four times, from $00000 
to $1FFFF, $20000 to $3FFFF, $40000 to $5FFFF, and $60000 to $7FFFF. For 
various reasons which are related to hardware design, it is the upper 
segment that is directly used by basic which means on 512K, $00000 
through $5FFFF are completely unused by basic.

Now, even if memory didn't ghost, you still wouldn't be able to detect 
the presence of memory by just reading or writing it. Reading 
non-existent memory (as opposed to ghosted memory) simply returns junk 
from the bus. Writing acts as a bit bucket. Neither causes a problem.

There is a way to detect the memory size, of course, and the basic 
program above is mostly right, but it gets a detail wrong. The ghosting 
happens in 128K blocks, not 64K blocks. Instead of &H12345 for the 
second LPOKE, it should just be &H2345. Otherwise, you're not matching 
the address between the two ghost instances. With that change, the 
program above will print "UH-OH" if you only have 128K, "LOOKS GOOD SO 
FAR" if you have 512K, and if, for some reason, the memory isn't working 
right, you might get "HUH?", say if you had a bad 512K board.




More information about the Coco mailing list