Using the Flash


Edit (Feb. 12, 2014):
An issue involving Flash programming on a CoCo 1 has been discovered.
Please see the page titled "CoCo 1 Motherboard Issue" for details.


The CoCo SDC contains 128K of Flash memory which is divided into eight banks of 16K. All eight banks of the Flash are user-programmable. The board is provided with SDC-DOS pre-programmed into bank 0 and stock Disk Basic 1.1 in bank 1. SDC-DOS adds extensions to the Disk Basic commands which make it easy to take advantage of the Flash memory.

Care should be taken when using these commands to avoid accidental destruction of data. You should always keep copies of the Flashed data elsewhere so it can be re-programmed if necessary.

Running a Cartridge Image

The Flash memory will typically be used to hold images of cartridge-based software (Program Paks). The RUN command in SDC-DOS has been extended to facilitate the execution of a cartridge image from any of the 8 Flash banks. Simply pass the bank number, prefixed with the @ character, as an argument to the RUN command.

  RUN @2

This has the effect of activating the specified bank and performing a cold re-boot of the CoCo. If the first two bytes of the cartridge image are "DK" then the normal start-up process occurs, allowing Extended Basic to transfer control to the cartridge image at C002 during initialization.  If anything else appears in the first two bytes then control is transferred to C000 immediately after the hardware is initialized.

Normally, pressing the RESET button on the CoCo will re-activate the Flash bank set by the DIP switches on the CoCo SDC board. You can force the system to retain the bank selection of the RUN command by suffixing the command with ,R :

  RUN @2,R

After using this option you will need to fully power-down the CoCo (and Multi-Pak Interface) in order to restore the normal Reset behavior.

Erasing Banks and Sectors

The active Flash bank appears in the CoCo memory map from C000 to FEFF. Each of the 16K banks is further divided into four sectors of 4K:

 Sector  Address Range 
   0 C000 - CFFF
   1 D000 - DFFF
   2 E000 - EFFF
   3 F000 - FEFF
On a CoCo 3, the last 256 bytes (FE00 to FEFF) are not accessible using SDC-DOS 1.2 or earlier.

The Flash chip uses the sector divisions for erase operations. Before programming data into the Flash, the sectors to be programmed should first be erased. Erasing the flash has the effect of setting all bits to '1' resulting in byte values of FF. The KILL MEM command can be used to erase a single sector or an entire bank.

  KILL MEM @3           - erase all four sectors of bank 3
  KILL MEM @6,&HE000    - erase only sector 2 of bank 6

When erasing a single sector you can specify any address from C000 to FEFF. The entire sector containing that address will be erased. You are not allowed to erase any part of the active bank (the one from which SDC-DOS is running).
 

Writing to the Flash

Writing data to the Flash involves a process where one or more bits in a byte are cleared to '0'. Once a bit has been cleared it can only be changed to a '1' through an Erase operation. The WRITE MEM command is used to program one or more bytes.

  WRITE MEM @bank, source, destination, count

    @bank         - bank number in which the data will be written (0-7)
    source        - starting address of the source data
    destination   - address in the Flash where the data will be written (C000-FEFF)
    count         - number of bytes to write

The count argument will be clipped if necessary to prevent writing past the end of the Flash address space.

Copying a Block of Memory

When creating a utility program to manage the Flash, one feature that is often needed is the ability to quickly move a block of memory. Consider the situation where you wanted to copy the contents of one Flash bank to another. This would require that data from the source bank first be copied to a temporary buffer in RAM before writing it to the destination bank. The COPY MEM command has been provided for this purpose.

  COPY MEM [@bank,] sourcedestinationcount [USING slot]

    @bank         - the Flash bank number to activate during the copy (0-7)
    source        - starting address of the source block
    destination   - address where the block will be copied to
    count         - number of bytes in the block
    USING slot    - the Multi-Pak Interface slot to activate during the copy (1-4)

The bank and slot arguments are both optional and mutually exclusive. You can provide one or the other, but not both. The bank argument can be provided when you are copying data from a specific Flash bank on the CoCo SDC board. The slot argument allows you to copy data from the ROM of another cartridge when using a Multi-Pak Interface.

Be careful when using the COPY MEM command as it can easily crash the CoCo if a block is copied to a location used by the system.

The Basic program listing below shows how to copy the contents of a ROM cartridge into one of the Flash banks of the CoCo SDC. The example assumes an MPI is attached and the CoCo has at least 32K RAM. It does not perform any validation of the input parameters. 

10 CLEAR 200,&H3FFF ' RESERVE A 16K RAM BUFFER AT $4000
20 INPUT "COPY FROM MPI SLOT";SL
30 COPY MEM &HC000,&H4000,16384-256 USING SL
40 INPUT "DESTINATION BANK";BK
50 KILL MEM @BK ' ERASE BEFORE WRITE
60 WRITE MEM @BK,&H4000,&HC000,16384-256



Downloads:
SST 39SF010A datasheet