[Coco] Question about RAM

William Astle lost at l-w.ca
Wed Oct 27 22:54:45 EDT 2010


On 10-10-27 08:29 PM, Arthur Flexser wrote:
> I think that ghosting would cause that LPOKE/LPEEK method to fail, so that
> you'd see the value you poked in even if the machine was 128K.
> You'd need to Lpoke an address and then Lpeek an address that differed from
> that by 128K;  if the second address contained what you Lpoked in, the
> machine is 128K.  That is, ghosting =>  128K;  lack of ghosting =>  512K or
> greater.

That is correct. However, to make it bullet proof, you need to put a 
known value in the "ghost" location before setting the real location. 
You can actually detect 256K as well using that method. (I don't know 
anyone that ever did 256K but it's theoretically possible.)

If you're assuming only 128K or 512K, then the following would do:

1 LPOKE &H40400,0
2 LPOKE &H00400,1
3 IF LPEEK(&H40400) == 1 THEN M=128 ELSE M=512

I chose 40400 and 00400 to guarantee that nothing crashes during the 
test since that will be the 32 column text screen on a 128K machine and
random unused memory on a 512K machine. I used 4xxxx and 0xxxx because
that pretty much guarantees that if you run into a guy with 256K, it 
will detect as 128K instead of 512K. The opposite would not be 
desirable. This will also detect 512K on machines with more than 512K 
installed.

The reason that works is that on a 128K machine, the 128K is mirrored 
four times, at $00000-$1FFFF, $20000-$3FFFF, $40000-$5FFFF, and 
$60000-$7FFFF. If I recall correctly, Basic uses the top mirror while 
OS9 uses the bottom one.

Note that a similar algorithm can be used in assembly language, in that 
case twiddling the MMU registers directly, which can easily detect up to 
2MB.

-- 
William Astle
lost at l-w.ca




More information about the Coco mailing list