[comp.sys.cbm] 8563 memory size check

fred@cbmvax.UUCP (Fred Bowen) (09/28/87)

Every 8563 (the 80-column display controller) can access up to 64K of DRAM.
Until recently the systems were built with an adequate 16K- more than enough
for text purposes.  But quite a few c128 owners have added more display memory
to their systems, or perhaps you've heard that the newer c128's (such as the US
version of the 128D) have a full 64K 80 column display RAM built-in. Some folks
like the additional memory for the bitmap graphic capabilities (such as BASIC-8
from PATECH),  for the several versions of RAM disks that have been designed to
use it, or for the windowing goodies others have provided.

This note is not to tell you how to get 64K display RAM nor what to do with it.
Rather, I want to describe how to tell from a programming viewpoint if a system
has it.  Many people seem confused regarding this, and it's not surprising-
it is not easy unless you know what's going on in that thar piece of silicon.

What is going on.  Depending upon the type of DRAM used, the 8563 calculates
addresses differently.  You must tell the 8563 what kind of DRAM you're using.
The Kernel does this in its init routine, IOINIT, which is called at power
up, reset, and STOP/RESTORE.  It always assumes 16K, and sets bit 4 of register
28 to zero.  This works just dandy regardless of the actual amount of memory.
This bit tells the 8563 whether the system has bit-wide DRAM or nybble-wide.
The chip addresses each type differently, as described below:

    bit (4116):      A7/A15 A6/A13 A5/A12 A4/A11 A3/A10 A2/A9  A1/A8 A0/A8
    nyb (4164/4464): A7/A15 A6/A14 A5/A13 A4/A12 A3/A11 A2/A10 A1/A9 A0/A8

So that's what's going on- if you are confused, here's what it basically means.
You cannot POKE to a location above $3FFF to test for memory higher than that
and expect to see it show up someplace obvious, like wrapping.  So, how to
tell how much memory there is, short of asking the user (who might not know)?

The program below makes use of the little chart above- it selects an address
that affects more that one RAM location if the memory is only 16K.  We simply
write to one cell, and see if another cell changed- a cell which we determined
should change based upon the screwy 'bit' addressing scheme.  If you are still
confused, pretend it's magic and just run the program :-)

1 REM  FRED'S NIFTY PROGRAM TO DETERMINE SIZE OF 8563 DRAM
2 REM  09/28/87    FRED BOWEN
3 REM
10 BANK15: AD=DEC("D600"): DA=AD+1: GOSUB900             :REM  SETUP ML
20 POKEAD,28: S=PEEK(DA): POKEDA,63                      :REM  SELECT 64K
30 I=16896:SYSW,I/256,18:SYSW,IAND255,19:SYSW,85,31      :REM  WRITE $55
40 I=16896:SYSW,I/256,18:SYSW,IAND255,19:SYSR,,31:RREGC1 :REM   READ HERE
50 I=17152:SYSW,I/256,18:SYSW,IAND255,19:SYSR,,31:RREGC2 :REM   AND HERE
60 I=16896:SYSW,I/256,18:SYSW,IAND255,19:SYSW,170,31     :REM  WRITE $AA
70 I=16896:SYSW,I/256,18:SYSW,IAND255,19:SYSR,,31:RREGC3 :REM   READ HERE
80 I=17152:SYSW,I/256,18:SYSW,IAND255,19:SYSR,,31:RREGC4 :REM   AND HERE
90 POKEAD,28: POKEDA,S: SYSDEC("FF62")                   :REM  RESTORE 16/64K
100 IF C1=C2 AND C3=C4 THEN PRINT"16K": ELSE PRINT"64K"  :REM  DID IT ECHO?
110 END
900 FORI=0TO13: READA$: POKEDEC("1800")+I,DEC(A$): NEXT
910 R=DEC("1800"): DATA 8E,00,D6,AD,01,D6,60   :REM STX $D600 :LDA $D601: RTS
920 W=DEC("1807"): DATA 8E,00,D6,8D,01,D6,60   :REM STX $D600 :STA $D601: RTS
930 RETURN

Now, this is a bit longer than it has to be- I'm just trying to be neat, ok?
To those of you who never diddled with the 8563 directly, well, suffice to say
you cannot simply PEEK and POKE registers like the VIC chip.  I refer you to
the programmer's reference manual.  If all you want to do is visually tell
what's inside, try this.  In 80-column mode type:

	POKEDEC("D600"),28:POKEDEC("D601"),63:SYSDEC("FF62"):SCNCLR

If the screen looks normal says ready and all that, you've got 64K display
memory.  If the screen is full of 0's and looks like a programming nightmare,
you've got 16K (just hit STOP/RESTORE and let Mr. Kernel fix it).

Well, enjoy.  Gotta get back to work.

--
-- 
Fred Bowen			uucp:	{ihnp4|rutgers|caip}!cbmvax!fred
				arpa:	beats me
				tele:	215 431-9100

Commodore Electronics, Ltd.,  1200 Wilson Drive,  West Chester,  PA,  19380