Testing for sideways RAM

From BeebWiki
Revision as of 17:55, 12 November 2017 by Jgharston (talk | contribs) (Slight formatting changes.)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

The standard way to test if a sideways ROM/RAM bank contains RAM is to try to change the binary version number at &8008. If you can change it, it must be RAM, if you can't change it, it must be ROM (or empty). You use the binary version number as that is defined as only ever displayed and not affecting the operation of any code. For example, if you changed &8000 and the test code failed to restore it (eg, Break was pressed) then you would be left with non-functioning code at &8000.

Testing for sideways RAM

 \ Code to test for sideways RAM
 \ -----------------------------
 \ This code must run from main memory
 \ The bank to be tested must be paged in
 \ Returns Y=0,1 for ROM,RAM
 LDY #0                              :\ Preload Y=0 for ROM
 LDA &8008:EOR #&AA:STA &8008        :\ Modify version byte
 CMP &AAAA:CMP &8008:BNE RomTestDone :\ NE=ROM or empty
 EOR #&AA:STA &8008                  :\ Restore byte
 INY                                 :\ Y=1 for RAM
 .RomTestDone

The test is done twice as with some systems the data bus floats so that an empty ROM socket looks like it is RAM. Testing twice and testing a different location allows the data bus to settle so an empty socket is seen as empty.

This routine finishes with Y holding 0,1 for ROM,RAM, giving zero for non-writable memory and non-zero for writable memory.

Testing for EEPROM

It is possible to use EEPROMs (Electrically Erasable Programmable ROMs) with BBCs/Masters/Electrons, [1] [2] [3] but when testing when EEPROM is present you have to be careful as whenever a write is made to the EEPROM it effectively vanishes for 20,000 instruction cycles while it processes the write. [4] So, you must make sure that the EEPROM isn't inadvertantly called during this write process and must wait until the write process finishes and the EEPROM contents are visible again.

 \ Code to test for sideways RAM or EEPROM
 \ ---------------------------------------
 \ This code must run from main memory
 \ The bank to be tested must be paged in
 \ Returns Y=0,1,2 for ROM,RAM,EEPROM
 PHP:SEI                           :\ Disable IRQs, prevent background ROM calls
 LDY #0                            :\ Preload Y=0 for ROM
 LDA &8008:EOR #&AA:STA &8008      :\ Modify version byte
 NOP                               :\ Wait for floating bus to settle
 CMP &8008:PHP                     :\ EQ=RAM, NE=ROM/EEPROM/empty
 EOR #&AA:STA &8008                :\ Restore byte
 .RomTestLp
 LDA &8008:EOR &8008:BEQ RomTestOk :\ Bytes match
 ASL A:BPL RomTestOk               :\ Empty socket, bit 6 not toggling
 LDY #2:BNE RomTestLp              :\ Toggling, must be EEPROM/empty, Y=2
 .RomTestOk
 PLP:BNE RomTestNotRam             :\ NE from earlier, ROM or EEPROM or empty
 LDY #1                            :\ EQ from earlier, must be RAM, Y=1
 .RomTestNotRam
 PLP                               :\ Restore IRQs

This routine finishes with Y holding 0,1,2 for ROM,RAM,EEPROM, giving zero for non-writable memory and non-zero for some form of writable memory. Other values could be used, for example the AP6 support ROM uses 0, 'R' and 'E'.

References

Jgharston (talk) 07:21, 27 January 2016 (UTC)