From: no-one@nowhere.land (F.H. Gilbert)
Newsgroups: comp.sys.hp48
Subject: Re: memory management
Date: Mon, 7 Dec 1998 10:25:47 +0100
Organization: no email - pas de courriel
Lines: 452
Message-ID: <1djnnvc.1iowi8u107ly0oN@tntrasp20-191.abo.wanadoo.fr>
References: <733ip1$b0f$1@nnrp1.dejanews.com> <1disva3.15c4puxielp0aN@tntrasp18-17.abo.wanadoo.fr> <73e1kk$d4s$1@nnrp1.dejanews.com> <85da2.3881$Jl.1384609@news3.mia> <1djm5h2.1wiv1fk6n9wckN@tntrasp18-18.abo.wanadoo.fr> <zwFa2.8057$gl.2842437@news2.mia>
NNTP-Posting-Host: tntrasp20-191.abo.wanadoo.fr
x-server2: news.wanadoo.fr
X-Newsreader: MacSOUP 2.3
Xref: republic.btigate.com comp.sys.hp48:19460

Tommy wrote:

> Well, I'm interested if you wish to elaborate.....

(I'll assume from now on you're a ML coder)

The HP's memory is divided in 6 modules. As you know it does contain
nibbles, each one being stored at a specific address. The Saturn chip
can acceed memory using 20 bits, that's 2^20 = 1048576 different
adresses available (that is, 512 Ko), which we number from #00000h to
#FFFFFh using hexadecimal base, using 5 nibbles.

But, there are much more nibbles available, so a same address will have
to be used to point different nibbles in memory; as memory is divided in
six parts, there is a hierarchy between those modules. When you use an
address that corresponds to several nibbles, the module with the highest
priority will have the nibble acceeded to you.

Memory looks like it's contiguous to you, but in fact some modules with
higher priority will be "over" others. Those ones are said to be
"covered" and you'll have to reconfigure memory to get access to them
(I'll explain that too).

Here are the modules, from higher priority to lesser one:

  1. The I/O RAM
  2. The internal RAM (32 Kb or 128 Kb)
  3. The bank manager
  4. Card in slot 1
  5. Card in slot 2
  6. ROM

If you have an address like #abcde (5 nibbles) it points to the nibble
in the most prioritary module; here is an example:

the pointer #00101 does exist in ROM (which is 512 Kb long) but if you
try to peek nibbles there, because the RAM I/O has a higher priority,
it's covering that part of ROM, and #00101 will get you into I/O RAM,
not ROM.

Each module of memory, may it be RAM, ROM, cards and so on, uses a set
of adresses (from #abcde to #fghij). Please note: some modules won't
have a start address of #00000 ! Like: the I/O RAM starts at #00100h up
to #0013Fh

If we want access over a memory module, we have to configure it. To do a
configuration, we have to give the module:

  1. a size
  2. a start address

Of course, the memory has a standard RAM configuration, but you can
alter it so some "covered" parts are no longer, and thus available to
you, so you can look there ;-)

We'll then "move" a module from an address to another one, so it no
longer "covers" the part we want to acceed to. First, we deconfigure it,
and then we configure it somewhere else.

To unconfigure, we use the ML command UNCNFG, we'll give to that command
the address of the module to unconfigure. You'll do that:

  1. Put in register C(A) the start address of the module to
     unconfigure; like a LC(5)  #abcdef

  2. UNCNFG

The first module that starts at #abcdef will be unconfigured.

Like: if we have module 3 we want to acceed to, and module 2 above it,
both starting at address #abcdef; by using UNCNFG we'll unconfigure the
module that has the higher priority, that is module 2 (which covers
module 3).

Sometimes, because you have two cards (on a GX) you'll have to do a
double-unconfiguration, if you want to acceed some part of ROM, like
ones which are covered by card 1 and card 2 (card2 being covered by
card1). Here is an example: my HP has two cards, a 128 Kb one in the
slot 1, and a 512 Kb one in slot 2. I want to peek nibbles in ROM, so
I'll do that to "uncover" ROM:

LC(5)     #C0000
UNCNFG
UNCNFG

The first one loads #C0000 onto C(A); #C0000h is the start of the cards
module in slot 1 and 2.

The first UNCNFG does unconfigure the card in slot 1. Now, the 128 Kb of
the card in slot 1 are no longer covering the 128 Kb of the selected
bank of my 512 Kb card, which is in slot 2. But, that 128 Kb bank of the
card of slot 2 is covering the ROM part I want to peek into, so I do an
another UNCNFG to unconfigure it. Now, the ROM is uncovered, I can peek
into like a pig! :-) (a french expression, means I'll peek in ROM like a
pig eats..)

To configure a module is more tricky (which means that's is much more
fun to code too!). To configure a module, we have to give it a size, and
a start address:

 1. The start address is from where all the nibbles will be numbered,
    a kind of "base" address.

 2. The size can be played with :-)
    You can give the module its size. No problemo.
    But, you can give it a smaller size, so you'll only have access
    to the part you gave the size to.
    Finally, you can give a greater size that the module's one,
    and you'll get a kind of circular data access. Like: if the module
    has a size of 10 Kb, and you give it a size of 20 Kb, you'll get
    two copies of the 10 Kb module.. when you reach the end of a part,
    you found a new copy of it, and so on as long there is enough
    space in the newly configured module.

So when you configure a module, you get the start address (the one you
gave) and an end address (which is size+lenght you gave).

We use CONFIG to configure a module. You have to put in C(A) the size of
the module. There is a trick there: it must be encoded using
complementation. Look at that:

    #100000h - #<module_size> = #<size_we_give_it>

So if we want to give the module a size of #100h, we have to find:

    #100000h - #<module_size> = #100h

So #<module_size> is: #FFF00h

This is the value I'll put onto C(A)

So I do a: LC(5)   #FFF00

Now, I do a CONFIG.

I have to tell it now the address at which the module I gave the size of
has to be configured. It has to be put inside C(A). I do an another LC
with the address, and then I call again CONFIG.

Note: it is very important to give sizes and start addresses using
5-nibbles. The size given to a module MUST be a multiple of 2 Ko.

NOTE: the ROM is the ONLY module that cannot be unconfigured or
reconfigurated (it's the last one in priority).

Usually, a good thing it to unconfigure a module, and reconfigure it at
another address. That will do one UNCNFG, and two CONFIG.

Like: I can reduce my HP48 GX RAM size, so it behaves like a HP48G, so
I'll have better access to covered ROM parts (this is a reason why the
HP48 G looks a bit faster than the GX, a lesser part of the ROM is
covered on the G). Let's do it =)

LC(5)   #80000     ; start address of my 128 Kb RAM
UNCNFG             ; I unconfigure it
LC(5)   #F0000     ; new size: 32 Kb

As you see, I don't load #10000 (which is 32 * 1024 * 2) into C(A), I do
calculate:

#100000h - #value = #10000h

So #value is: #F0000h (#100000h - #10000h)

CONFIG
LC(5)   #80000
CONFIG

Here, I do give the RAM a new size of 32 Kb. I don't want to move it,
just change its size, so the address I give to it for reconfiguration is
still #80000h (there is a trick that is to move the RAM to #00000, it's
easier to manage interruptions from there)

The first CONFIG here gives the RAM a size of 32 Kb, and then the second
CONFIG gives the address where it starts, which is the same as before
for the 128 Kb RAM: #80000h

Now, the RAM looks like it's 32 Kb, and the less prioritary modules
(card1, card2, ROM) are visible.

To give the RAM its original size, we do:

LC(5)    #80000
UNCNFG
LC(5)    #C0000
CONFIG
LC(5)    #80000
CONFIG

128 Kb is 128 * 1024 * 2 nibbles, that is: #40000h nibbles, so we have
to put #100000h - #40000h = #C0000h

----- some cool info!

This is the HP48G memory configuration:
---------------------------------------

from #00000h
to   #000FFh         256 nibbles of ROM

from #00100h         64 nibbles of I/O RAM
to   #0013Fh         which hide 64 nibbles of ROM

from #00140h
to   #7DFFFh         51576 nibbles of ROM (about 252 Ko)

from #7E000h         empty slot 1, configured to a 2 kb size
to   #7EFFFh         empty slot 2, covered by the 2 kb of the
                     empty slot 1; 2 Kb of ROM are covered
                     there by the 2 kb given to the empty slot 1

from #7F000h         bank manager, given 2 kb
to   #7FFFFh         which covers 2 kb of ROM

from #80000h         32 kb of RAM
to   #8FFFFh         which covers 32 Kb of ROM

from #90000h         the rest of ROM, about 224 Kb
to   #FFFFFh

Now, we have 4 other memory configurations:

  1. HP48 GX without any cards
  2. HP48 GX with 32 kb in port 1
  3. HP48 GX with 128 kb in port 1
  4. HP48 GX with 128 kb in port 1 & 2

  (we could add 32 Kb port 1, 128 Kb port 2 too)

HP48GX without RAM card:
------------------------

from #00000h         256 nibbles of ROM
to   #000FFh

from #00100h         I/O RAM (64 nibbles)
to   #0013Fh         which cover 64 nibbles of ROM

from #00140h
to   #7DFFFh         about 252 kb of ROM

from #7E000h         empty port 1, given 2 Kb of size
to   #7EFFFh         covers empty port 2 (2 kb) with
                     2 kb of ROM covered by both

from #7F000h         bank switcher, 2 kb; covers 2 kb
to   #7FFFFh         or ROM

from #80000h         128 Kb RAM
to   #BFFFFh         covers 128 Kb of ROM

from #C0000h         128 Kb of ROM
to   #FFFFFh         (uncovered)

HP48GX with 32 Kb in port 1:
----------------------------

from #00000h         256 nibbles of ROM
to   #000FFh

from #00100h         I/O RAM (64 nibbles)
to   #0013Fh         which cover 64 nibbles of ROM

from #00140h
to   #7DFFFh         about 252 kb of ROM

from #7E000h         empty port 2, given 2 Kb of size
to   #7EFFFh         covers 2 kb of ROM

from #7F000h         bank switcher, 2 kb; covers 2 kb
to   #7FFFFh         or ROM

from #80000h         128 Kb RAM
to   #BFFFFh         covers 128 Kb of ROM

from #C0000h         32 Kb card in slot 1
to   #CFFFFh         which covers 32 kb of ROM

from #D0000h         96 Kb of ROM
to   #FFFFFh         (uncovered)

HP48GX with 128 Kb in port 1:
-----------------------------

from #00000h         256 nibbles of ROM
to   #000FFh

from #00100h         I/O RAM (64 nibbles)
to   #0013Fh         which cover 64 nibbles of ROM

from #00140h
to   #7DFFFh         about 252 kb of ROM

from #7E000h         empty port 2, given 2 Kb of size
to   #7EFFFh         covers 2 kb of ROM

from #7F000h         bank switcher, 2 kb; covers 2 kb
to   #7FFFFh         or ROM

from #80000h         128 Kb RAM
to   #BFFFFh         covers 128 Kb of ROM

from #C0000h         128 Kb card in slot 1
to   #FFFFFh         which covers 128 kb of ROM

HP48GX with 128 Kb in port 1 and 2:
-----------------------------------

from #00000h         256 nibbles of ROM
to   #000FFh

from #00100h         I/O RAM (64 nibbles)
to   #0013Fh         which cover 64 nibbles of ROM

from #00140h
to   #7EFFFh         about 253 kb of ROM

from #7F000h         bank switcher, 2 kb; covers 2 kb
to   #7FFFFh         or ROM

from #80000h         128 Kb RAM
to   #BFFFFh         covers 128 Kb of ROM

from #C0000h         128 Kb card in slot 1
to   #FFFFFh         which covers 128 kb of slot 2
                     and 128 Kb of ROM covered by both

As you see, there a two parts of ROM which are never covered:

from #00000h        from #00140h
to   #000FFh        to   #7DFFFh

If the card on slot 2 is bigger than 128 Kb, only one bank of 128 Kb is
available, and the bank manager is used to select the bank you want to
have access to.

As you have seen, we have six modules which have each one a priority.
This is linked to their position on the internal bus, and the Saturn
processor.

On HP48 models, memory is divided in 128 Kb parts, each one being called
a bank of memory. If you put a RAM card of 4 Mb in slot 2, it will have
to be divided in parts of 128 Kb, and only one will be "visible" at one
moment. If you want so "select" the bank n of a card, just do that: read
a byte at #7F040 + 2n

Example: I want to select bank 2 of my 512 Kb card, I do:

D1=(5)    #7F044
C=DAT1    B

The byte read must be thrown away. It's only used to tell the bank
manager to select a specific bank.

The bank driver uses 2 kb of RAM. The port 1 selection zone is located
from #7F000h to #7F03Eh and for port 2 it goes from #7F040h to #7F07Eh

funny stuff:
------------

If you have a GX, and no cards in slot 1 or 2, you can free up this area
used by the bank manager. As you see, EVEN if the port 1 can only
receive 32 Kb or 128 Kb RAM/ROM cards, it has a selection table like the
port 2 does!!!

When the Saturn wants to send data, it uses the bus. When two modules
have the same address, the one which is CLOSER to the CPU is the one to
be prioritary.

Note: you can move the I/O RAM module, but its size is FIXED, that is:
64 nibbles.

Even if a module is absent (card in slot 1 or 2) it MUST have its
manager configured, so the system gives it the MINIMAL size, which is 2
Kb (because the modules size must be a multiple of 2 Kb, or #1000h
nibbles).

Each memory module has a manager, and they are all linked together by
the "daisy chain". When an information is sent on the bus by the Saturn,
the first manager receives it. The manager looks at it, and if the
information is for it, the concerned memory module manages it;
otherwise, the information is pushed to the following manager on the
daisy chain. This will continue until we get to the ROM; the ROM doesn't
have a manager.

The daisy chain is:

     SATURN  -->  I/O RAM  -->  RAM  -->  Bank Switcher  --|
                                                           |
                                                           |
                    ROM <--  Card in slot 2  <--  Card in slot 1

When two memory modules have been configured at the same address, the
access to data will be done on the module which has the biggest
priority. If you want to alter that, you'll have to unconfigure a
module.

Each module has a line in, called "Daisy-in" and one that goes out,
called "Daisy-out". When a signal comes in, it's thru the daisy-in, etc.

Daisy-in and Daisy-out can have two levels: UP (=1) or DOWN (=0)

A module which is UNCONFIGURED has a DOWN level on Daisy-OUT

The RESET command can be used to unconfigure ALL modules. Then, CONFIG
can be used to configure some of.

Like: we use RESET to turn all to unconfigured, and if we want the card
in port 1 to be configured, we must turn its Daisy-in and Daisy-out to
different levels; because: a module which daisy-in and out have
DIFFERENT LEVELS is configured.

If we want the I/O RAM to be configured, we'll have its daisy-in to UP,
and its daisy-out to DOWN

If you look at the daisy-chain diagram above, you'll see the card in
slot 2 will be the last one to be configured (because the ROM doesn't
have any manager)

Because the G has the same hardware as the GX, it has all the GX
managers, it can manage the same volume of memory, so it can receive the
connectors it lacks, or more memory :-)

You can use C=ID to see which modules is configured;

  -  if none, you'll get #00000h in C(A)
  -  is the current module is configured, you'll have to see
     what's inside C(B):

     #F2h  : card in slot 2
     #F4h  : internal RAM
     #F6h  : bank manager
     #F8h  : card in slot 1

You can get the last address used for the current memory module, by
removing the last two nibbles of C (doing a: C=0    B)

  - if the current memory module is the I/O RAM, C(A) will contain
    the last config address + #19h (usually, #00019h)

If the current memory module is unconfigured (no base address nor size)
you'll find in C(B) two nibbles that will tell you what the module is:

 #01h : card in slot 2
 #03h : internal RAM
 #05h : bank manager
 #07h : card in slot 1

Sorry if some words look strange, but I'm mostly french  :o)

-Gilb-
43E2 61F7 4ECA 6A7C AAFE  FE2F C1B1 FFE6 D7B0 48E3