RCA 1802 – Cold War Computing https://coldwarcomputing.com Retrocomputing Blog Thu, 18 Aug 2022 03:12:55 +0000 en-US hourly 1 https://wordpress.org/?v=6.5.5 198232181 1802 RetroShield – SPI RAM https://coldwarcomputing.com/2022/01/25/1802-retroshield-spi-ram/ https://coldwarcomputing.com/2022/01/25/1802-retroshield-spi-ram/#respond Tue, 25 Jan 2022 23:57:17 +0000 https://coldwarcomputing.com/?p=224 In the original 1802 Monitor + Tiny Basic Arduino code by Erturk Kocalar, the memory map is divided into three sections: ROM, onboard RAM, and external/simulated RAM.

  • ROM is hardcoded in the Arduino’s program memory, is of variable length, and starts at address 0x0000.
  • Onboard RAM starts at 0x8000 and is 6K in length if SPI RAM is not used, or 2K in length if it is not. (The 4K difference is instead used for caching the SPI RAM.)
  • If SPI RAM is used, the remainder of the memory map to 0xFFFF is cached SPI RAM. If SPI RAM is not used, the remainder of the memory map to 0xFFFF is hardcoded to 0xFF.

Instructions for adding 128K SPI RAM to a RetroShield project can be found here, and a discussion of the caching scheme used in the default project is here.

My goal right now is to leave the functionality the same if SPI RAM is not used, but change the behavior when SPI RAM is used so that the full 64K memory map is cached SPI RAM. For now, the ROM will still be located in program memory, but will be copied into RAM at startup. The eventual goal is to have no ROM, instead having system software loaded from SD on startup.

The first change to the default project was to enable the SPI RAM:

////////////////////////////////////////////////////////////////////
// Options
//   USE_SPI_RAM: Enable Microchip 128KB SPI-RAM  (Details coming up)
//   USE_LCD_KEYPAD: Enable LCD/Keyboard Shield
//   outputDEBUG: Print memory access debugging messages.
//   TPB_SOFTWARE: Generate TPB internally so access SC0 signal. 
////////////////////////////////////////////////////////////////////
#define USE_SPI_RAM     1
#define USE_LCD_KEYPAD  0
#define outputDEBUG     0
#define TPB_SOFTWARE    1

Next, I changed the Memory Layout constants to match my desired layout:

////////////////////////////////////////////////////////////////////
// MEMORY LAYOUT
////////////////////////////////////////////////////////////////////

#if (USE_SPI_RAM)
  // 2K MEMORY
  //#define RAM_START   0x8000
  //#define RAM_END     0x87FF
  //byte    RAM[RAM_END-RAM_START+1];
  #define RAM_START 0x0000
  #define RAM_END   0xFFFF
#else
  // 6K MEMORY
  #define RAM_START   0x8000
  #define RAM_END     0x97FF
  byte    RAM[RAM_END-RAM_START+1];
#endif

I changed the code that reads memory so that if SPI RAM is enabled, all reads come from SPI RAM.

#if (USE_SPI_RAM)
    DATA_latched = cache_read_byte(uP_ADDR);
#else
    // ROM?
    if ( (ROM_START <= uP_ADDR) && (uP_ADDR <= ROM_END) )
    {
      DATA_latched = pgm_read_byte_near(rom_bin + (uP_ADDR - ROM_START));
    }
    else
    // Execute from RAM?
    if ( (RAM_START <= uP_ADDR) && (uP_ADDR <= RAM_END) )
      DATA_latched = RAM[uP_ADDR - RAM_START];
    else
      // Dummy 0xFF (eeprom style) out for unmapped memory locations
      DATA_latched = 0xFF;      
#endif

And the same for the code that writes memory.

    // Memory Write
#if (USE_SPI_RAM)
    cache_write_byte(uP_ADDR, DATA_latched);
#else
    if ( (RAM_START <= uP_ADDR) && (uP_ADDR <= RAM_END) )
      RAM[uP_ADDR - RAM_START] = DATA_latched;    
#endif

I added a function to copy the ROM from program memory to SPI-RAM.

#if (USE_SPI_RAM)
void rom_init() {
  unsigned int i;

  for(i=ROM_START; i<=ROM_END; i++) {
    cache_write_byte(i, pgm_read_byte_near(rom_bin + (i - ROM_START)));
  }

  Serial.print(i - ROM_START); Serial.println(" bytes of ROM copied to RAM.");
}
#endif

And finally, I added a call to this function inside the setup() function.

#if (USE_SPI_RAM)
  // Initialize memory subsystem
  spi_init();
  cache_init();
  rom_init();
#endif

]]>
https://coldwarcomputing.com/2022/01/25/1802-retroshield-spi-ram/feed/ 0 224
1802 RetroShield https://coldwarcomputing.com/2022/01/21/1802-retroshield/ https://coldwarcomputing.com/2022/01/21/1802-retroshield/#respond Fri, 21 Jan 2022 14:57:24 +0000 https://coldwarcomputing.com/?p=218

After receiving this Hackerbox, I was very intrigued by the idea of exploring vintage 8-bit CPUs via an Arduino Mega, and with WiFi no less. It turns out that 8bitforce has designed RetroShields for a variety of 8-bit microprocessors, including the RCA 1802 (aka COSMAC). I grabbed the Gerber files from here and submitted them to NextPCB. The PCBs took less than two weeks to arrive. Meanwhile, I ordered some 1802 chips off of EBay, which ultimately came from Hardware for Hackers. The SMD components needed to complete the assembly of the RetroShields were ordered from Amazon.

Assembly of the board required some SMD capacitors and resistors, and their values can be found on this schematic. Other than that, I added a socket for the 1802, two LEDs, and headers for the Arduino and individual 1802 pins.

The PCBs contain a warning that the software should be uploaded to the Arduino before attaching the RetroShield, so I installed this Tiny Basic sketch. After attaching the RetroShield and powering up the Arduino again, success! A menu is transmitted to the Arduino Serial Monitor, allowing a number of operations including Tiny Basic.

]]>
https://coldwarcomputing.com/2022/01/21/1802-retroshield/feed/ 0 218