README.md (21509B)
1 # Overview 2 3 ## Hardware 4 5 Eris 2010 is homebrew 8-Bit computer in the style of the 6 microcomputers of the 1970/80s. It is build around the WDC 65C02 7 MPU. This is a slightly updated version of the legendary MOS 6502 used 8 for example in the Commodore VIC20 and the Apple I and ][. The other 9 main components are 32 KB RAM and 8 KB EEPROM. While the old home 10 computers from the 1970/80s came with a keyboard and connected to a TV 11 or monitor, this design provides a serial communication 12 interface. Therefore it is more similar to modern microcontrollers or 13 very early home computers like the Altair 8800 than to later computers 14 of the home computer era like the Commodore 64 or the Apple ][. The 15 serial interface is provided by a 6551 ACAI. This chip has been used 16 in computers from the era like the Commodore PET and the Commodore 17 Plus/4 to connect a modem. In the Eris 2010, the 6551 ACAI connects to 18 a (modern) USB2Serial adapter. This allows to use a standard laptop or 19 desktop computer as a terminal for the 8-bit machine. 20 21 The second auxiliary chip is a 6522 VIA. Among other things, this chip 22 provides a bunch of GPIO lines. A few of them are used to connect an 23 SD card reader, providing a mass storage device to Eris 2010. The 24 remaining lines are freely programmable I/O ports. SD cards are 25 written in a very simple, proprietary data format. When the computer 26 is powered, the "operating system" in EEPROM presents a list of the 27 programs on the SD card and acts as a bootloader. Alternatively, 28 programs can be uploaded via the serial interface. 29 30 The bus is orchestrated by an ATF16V8 EEPLD. While the first chips 31 with programmable logic were developed in the 1970/80s, most computers 32 of the era did not use programmable logic, but discrete logic 33 chips. Using an EEPLD allows to keep the chip count low, and I wanted 34 to play with programmable logic a bit. 35 36 Reset logic is based on the good old 555 chip. We find similar 37 circuits in home computers as well. 38 39 The first version of the computer was build on a breadboard. Once the 40 breadboard design was functionally complete and stable at 4 Mhz, the 41 design was fixed on a PCB in through-hole technology. In order to 42 allow connection of additional peripheral devices and extensions, two 43 interfaces were added: A user port to provide access to the free I/O 44 ports, and an expansion port exposing the buses and other internal 45 lines. The KiCad design files of the PCB are included in the 46 repository. 47 48 ## Software 49 50 Eris 2010 can be programmed in assembler, C, and Forth. Directory 51 `sw/` contains the games Snake and Tic-Tac-Toe (no fan of WarGames 52 should go without one), the famous 10 PRINT program (check out [this 53 book](https://10print.org/ "10 PRINT") on the cultural significance of 54 10 PRINT if you do not know it already), and some test programs. The 55 `contrib/` directory contains additional third party software ported 56 to Eris 2010. Most notably, it contains a port of Tali Forth 2, a 57 very capable Forth system for 65C02 MPUs. Other software includes 58 Wozmon, Steve Wozniak's "operating system" for the Apple I, 59 Microchess, the first commercial game for microcomputers, some other 60 games, and a port of Eliza. The contrib directory also contains a port 61 of Tiny BASIC, so you can even program the system in BASIC, just like 62 in the old days. 63 64 All components of the system (except for the third party software in 65 `contrib/`) are free soft- and hardware. You can find all source code 66 in the repository linked at the top of this page. 67 68 ---------------------------------------------------------------- 69 70 # User Manual 71 72 So you are one of the lucky few who got a pre-assembled Eris 2010 73 computer including an SD card with some software! 74 75 ## Getting started 76 77 Insert the SD card that comes with your Eris 2010 into the SD card 78 reader. The standard way to communication with this 8 bit computer is 79 via the USB2Serial adapter. For this connect your Eris 2010 via a Mini 80 USB cable to your computer. On your desktop or laptop computer, you 81 need a terminal program. 82 83 ### Linux 84 85 Run a terminal program like `tio`. `tio` should be available in the 86 package store of your distribution. If not try `minicom` or 87 `picocom`. The interface is probably available as `/dev/ttyUSB0`. Make 88 sure your user account has access rights to this device! Connect to 89 Eris 2010 by 90 91 `tio -b 19200 /dev/ttyUSB0` 92 93 Press a key or the reset button on Eris 2010. If this does not work, 94 try the command above with `/dev/ttyUSB1`, `/dev/ttyUSB2`, ... 95 96 ### Windows 97 98 When you connect Eris 2010 to your desktop or laptop computer, you 99 first have to install the device driver for the USB2Serial 100 connector. You can download it from [the 101 manufacturer](https://www.ftdichip.com/Drivers/CDM/CDM21228_Setup.zip). Now 102 connect Eris2010 to a USB port. Next, you have install a terminal 103 program. For Windows users, a common terminal program is 104 [PuTTY](https://www.putty.org/). After installation, there is a folder 105 PuTTY in your start menu. From this folder, choose PuTTY. 106 107 When putty starts, click the radio button "Serial". Set "Serial line" 108 to "COM3", and "Speed" to "19200". Click "Open". In the terminal 109 windows, type any character or push the reset button on Eris 2010. You 110 should now be connected to the computer. If this does not work, try 111 "COM1", "COM2", ... for "Serial Line". 112 113 The default font of PuTTY does not support the Unicode characters used 114 by the 10 PRINT program. I order to run this program, choose 115 "Window/Appearance" and change the font to e.g. @NSimSun. 116 117 ## Running programs 118 119 You should now see a choice of programs. Typing a number starts the 120 corresponding program. The more interesting programs are: 121 122 ### Tic-Tac-Toe 123 124 This should be self explanatory. 125 126 ### Microchess 127 128 Press 'c' to set up a new board. Enter moves by giving the field 129 numbers followed by enter, e.g. '6444'<Enter>. Push 'p' for the next 130 move of the computer. You can switch the board with 'e'. 'q' quits the 131 game. 132 133 Microchess is third party software. 134 135 ### TINY BASIC 136 137 All input must be in caps! 138 139 Tiny BASIC is third party software. 140 141 ## Abandoned Farmhouse 142 143 A small text adventure game. 144 145 ## Eliza 146 147 A version of Weizenbaum's famous ELIZA. This version diverges quite a 148 bit from Weizenbaum's original program, which was more advanced. 149 150 ## Mastermind 151 152 A version of Mastermind. There are some divergences from the original 153 rules: When you a number appears once in the code but the player 154 guesses it multiple times,"+" will be output for every wrong spot of 155 the number. 156 157 ## Wumpus 158 159 Hunt the Wumpus, a classical computer game: 160 <https://en.wikipedia.org/wiki/Hunt_the_Wumpus>. 161 162 ---------------------------------------------------------------- 163 164 # Developer Documentation 165 166 ## Repository Directory Structure 167 168 - `case/` - Minimal case consisting of top and bottom plates for laser cutting. 169 - `contrib/` - Third party software. See `contrib/README.md` for a description. 170 - `hw/` - Hardware description 171 - `tools/` - PC programs to upload programs and write SD card 172 - `roms/` - ROM images. See `roms/README.md` for a description. 173 - `sw/` - "Userland" software to be loaded into RAM by a suitable ROM. Eris2010 174 can be programmed in assembler and C. 175 176 ## Main Components 177 178 The computer is based on a 65C02 running at 4 Mhz with 32K RAM 179 (AS6C62256-70PCN) and 8 K EEPROM (AT28C64B-15PU). A W65C51N ACAI 180 provides a serial communication interface. A VIA 65C22 provides a GPIO 181 interface. Four of the lines connect an SD card reader via SPI. Bus 182 logic is provided by a ATF16V8B EEPLD. The reset logic is based on a 183 NE555 in a monostable configuration with a little help (an inverter on 184 the AFT16V8B). 185 186 The hardware design is rather straightforward; see 187 `hw/pcb/eris2010/eris210.sch` for schematics (this is a KiCad file). The 188 bus logic is documented in `hw/bus_logic/bus_logic.pld`. The only tricky 189 part was getting RAM access synced with the CPU clock. 190 191 ## Memory Map 192 193 Lowest 32K are RAM, highest 8K are ROM. Up to 4 I/O devices (ACAI or 194 VIA) can be accessed at addresses below the ROM. One ACAI and one VIA 195 are required to operate the computer, because they provide a serial 196 interface (ACIA) and an interface to the SD card reader (VIA). Two 197 more devices can be connected via the Extension Port. The third I/O 198 device is active when `io_select5` is high and `io_select4` low. The 199 fourth I/O device is active when `io_select5` is low and `io_select4` is 200 high. See `hw/bus_logic/BUS_LOGIC.PLD` for details. 201 202 |Area |Content |Location | 203 |--- |:----------:|--------------:| 204 |ROM | OS | $E000 - $FFFF | 205 | | | | 206 |IO | EXP2 | $D800 - $DFFF | 207 | | EXP1 | $D000 - $D7FF | 208 | | VIA | $C800 - $CFFF | 209 | | ACIA | $C000 - $C7FF | 210 | | | | 211 |RAM | IRQ Vector | $7FFE - $7FFF | 212 | | Heap | ... - $7FFD | 213 | | ... | ... | 214 | | Data Stack | ... | 215 | | Program | $0200 - ... | 216 | | HW Stack | $0100 - $01FF | 217 | | Zero Page | $0000 - $00FF | 218 219 The reset vector points to $E000, the begin of the ROM. Programs are 220 loaded to $0200. The IRQ handler jumps to the address stored in RAM at 221 $7FFE. For assembler programs, the data stack is located right after 222 the program code and grows up, as shown in the diagram above. For C 223 programs, the RAM layout is different. They use two stacks in addition 224 to the hardware stack: The assembler stack (used by assembler 225 functions in ROM) is located at the top of the RAM below the IRQ 226 vector ($7DFE - $7FFD), below it, the C stack occupies $6DFE - 227 $7DFD. Everything in between the program and the stacks is heap. 228 229 ## Reset logic 230 231 Resets can be triggered in two ways: A reset button is connected to an 232 NE555 in a monostable configuration. Alternatively, a reset can be 233 triggered by setting DTR of the serial interface to high. The latter 234 is used to automatically trigger a reset before program 235 upload. `tools/boot.py` uses this to trigger a reset and get Eris 2010 236 ready for program upload. The disadvantage of wiring DTR to rest is 237 that Eris 2010 only operates when a terminal is connected; when no 238 terminal is connected, it stays in reset mode. Therefore a hardware 239 switch allows to disconnect DTR from the reset line, allowing Eris 240 2010 to run even if no terminal is connected. In this configuration, 241 resets for program upload have to be triggered manually. See also 242 section Booting. 243 244 Another way to run Eris 2010 even if no terminal program is running on 245 your main computer is to configure your computer's serial interface 246 to keep DTR low at all times (Linux: `stty -F <serial interface> 247 -hup`). 248 249 Note that the reset line of the 65C02 is active on low. We use the 250 AFT16V8B - which mainly provides the bus logic - as an inverter. 251 252 ## Booting 253 254 The "standard" ROM is `roms/os/os.bin`. This ROM includes the standard 255 library (for serial communication, accessing SD card, RNG, ...). It 256 provides three methods to load a program: 257 258 ### Via serial line 259 260 After a reset, the ROM listens for a serial data transmission at 19200 261 BPS 8N1. If byte $ff is sent, the download sequence is initiated. The 262 next byte is the number of half-blocks of 256 bit to be loaded. (Block 263 size is 512 bit, because this is the block size of SD cards.) The 264 number of half-blocks is followed by the data. Data is stored at 265 $0200. Once the upload is completed, the upload program returns a 266 two-byte checksum. The first byte is the sum of all bytes transmitted 267 mod 256. The second byte is the xor of all bytes transmitted. The 268 upload program than starts executing the loaded program at $0200. 269 270 On the PC, use `tools/boot.py` for upload. 271 272 ### From SD Card 273 274 The boot ROM includes `sw/load_from_card/load_from_card.asm`, the 275 program to load programs from SD card. This program is executed when 276 no program is transmitted via serial line. 277 278 SD cards can store up to 10 programs. The file system format is as 279 follows: 280 281 Block $00000000 is loaded on initialization. The first two bytes 282 should be $E215. This indicates the file system type. The third byte 283 should be $00. This is the version of the file system. The fourth byte 284 is the number of the program to start automatically, or $ff. In case 285 of $ff, a menu of the programs on the card is presented for the user 286 to choose. 287 288 The storage space for the first program starts at $00000001. The 289 storage space for the second program starts at $00010001, for the 290 third program at $00020001, ... Thus, each program has a total of 291 $ffff blocks of 512 bytes each available. The first block of each 292 program is the program header. It contains the number of blocks to be 293 loaded, and the app name, a null-terminated string. The actual program 294 code starts with the next block. The program is loaded to address 295 $0200 and executed. 296 297 On the PC, use `tools/kfs.py` to write the SD card. 298 299 ## Interfaces 300 301 Two interface modules are part of the computer system: A serial 302 interface connected to a USB2Serial adapter provides character I/O and 303 program upload facilities. An SD card reader provides access to SD 304 cards with a rudimentary file system. The default operating system 305 allows to read and execute programs stored on an SD card. 306 307 In addition, a user port on the PCB provides access to all GPIO lines 308 not occupied by the SD card communication interface, and an expansion 309 port provides access to the buses and other internal lines. The 310 expansion port carries two select lines for additional peripheral 311 devices. See section Memory Map above. 312 313 ## Interrupts 314 315 The I/O interfaces are wired to IRQ. NMI can be triggered by pushing a 316 physical button. User programs can write their own ISRs for IRQs. The 317 ISR for NMIs is set in the ROM. The default ISR dumps the 318 RAM. Alternatively NMIs may jump into Wozmon. For this, set flag 319 `WOZMON_ON_NMI` in `roms/os/os.asm`. Beware that compiling Wozmon into 320 the kernel does not conform to the GNU GPL v3 license, because Wozmon 321 is not offically free software. However I, Gerd Beuster, the author of 322 the kernel, grant you the right to compile Wozmon into it. 323 324 ## Toolchain 325 326 ### Hardware 327 328 You can find all files related to the hardware design in 329 `hw/pcb/eris2010`. The design uses [some additional library 330 symbols](https://github.com/Alarm-Siren/6502-kicad-library). These 331 additional symbols are copyright (c) 2018, Nicholas Parks Young and 332 licensed under the GNU LGPL v2.1. The hardware schematics and PCB 333 layout were designed in KiCad. FreeRouting (part of LayoutEditor) has 334 been used for routing. 335 336 An ATF16V8B-15PU EEPLD is used for the bus logic. It is programmed in 337 [GALasm](https://github.com/daveho/GALasm). 338 339 Both the EEPROM and the EEPLD can be burned with 340 [minipro](https://gitlab.com/DavidGriffith/minipro/). 341 342 ### Assembler 343 344 All core parts of Eris 2010 have written in assembler. They can be 345 translated with 64tass. The Makefiles generate binary code both for 346 Eris 2010 and Symon. [Symon](https://github.com/sethm/symon), a 6502 347 emulator written in Java, has been used for debugging. 348 349 ## Standard Library 350 351 A standard library is part of the boot ROM located at `roms/os/`. In 352 order to use it, import `roms/os/os.inc` into your program. 353 354 The standard library includes a data stack with subroutines and macros 355 for local variables and parameter passing. See `roms/os/os.asm` for 356 documentation and `sw/stack_test/stack_test.asm` for examples. 357 358 The following functionality is provided: 359 360 - Serial communication interface 361 All serial communication is conducted at 19200BPS with 8N1. Various 362 input and output functions are provided, including a function that 363 initializes the RNG (see LFSR) by counting ticks when waiting for user 364 input. 365 366 - ANSI Terminal 367 On top of the serial communication interface, the core ANSI escape 368 sequences are supported. 369 370 - LFSR 371 A 16 bit LFSR with maximum period length is provided as PRNG. 372 373 - SPI 374 SPI messages can be send via the VIA. 375 376 - SD Card 377 SD cards can accessed in SPI mode. All addresses are 32 bit, referring 378 to 512 bit blocks on the card. Note that this implementation does not 379 work with all cards. See section [bugs](#bugs) below. 380 381 - Data Stack 382 A data stack in software for local variables and parameter passing. In 383 difference to most stacks, the stack grows from bottom to top. The 384 recommended memory layout is program code, followed by heap (if 385 applicable), followed by stack. You have to manually create and delete 386 stack frames with calls to create_stack_frame and delete_stack_frame. 387 Pull and push operations do not push actual data on the stack, but 388 just move the stack pointer. Local variables on the stack are 389 represented by integers and accessed by `lda_LOCAL \<number\>`, 390 `sta_LOCAL \<number\>`, and similar macros. Parameters passed by 391 `sta_PARAM \<number\>` can be accessed by the callee by `lda_LOCAL 392 \<number\>`. Macro `CALL` may be used to call a subroutine with 393 parameters. Refer to `sw/stack_test/stack_test.bin` and 394 `sw/load_from_card/load_from_card.asm` for examples. 395 396 ### C 397 398 You can program Eris 2010 in C using the CC65 C compiler, available at 399 <https://cc65.github.io/>. Suitable configuration and Makefiles, as 400 well as implementations of the conio and dio libraries, are 401 located in directory `sw/c/cc65_eris`. You have to run `make` once in 402 this directory in order to generate `eris2010.lib`. After that, you 403 can compile the programs in the other subdirectories. The programs 404 here are simple test programs. Check out `contrib/c/` for ports of 405 (more or less) useful programs. 406 407 #### The conio Library 408 409 The conio library for console input/output has been ported to use the 410 serial connection. Since the serial connection is the main I/O 411 connection of Eris 2010, conio and not the serial library is used to 412 access it. Some functions of conio have not been ported because the 413 functionality is not available via a serial line with ANSI encoding: 414 415 - bgcolor 416 - bordercolor 417 - cpeekc 418 - cpeekcolor 419 - cpeekrevers 420 - cpeeks 421 422 #### The dio Library 423 424 The dio library provides low level file system access. dio uses 16 bit 425 sector numbers. Since SD cards use 32 bit sector numbers, we use a 426 hack to be able to access all sectors of the SD card while maintaining 427 compatibility to the dio library: The upper 16 bits of the sector 428 number are encoded as the device handle. 429 430 In order to access the SD card, you have to call `dio_open` 431 once. Neither the `device` number you pass into this function nor the 432 handle returned matter. `dio_write` and `dio_read` treat `handle` as 433 an unsigned int indicating the upper 16 bits of the sector 434 number. (`dio_write_verify` is not implemented.) 435 436 Due to our file system structure, this `handle` is identical to the 437 application number of the application whose data you are 438 accessing. The application number is a (the) parameter of `main`. Use 439 it to make sure that your program only writes to its own storage space. 440 441 ### Forth 442 443 Tali Forth 2 (<https://github.com/scotws/TaliForth2>) has been ported 444 to Eris 2010. It resides in directory `contrib/forth`. Note that Tali 445 Forth 2 is included as a submodule. Either checkout the Eris 2010 446 repository with option `--recurse-submodules` or run `git submodule 447 init && git submodule update` in the Eris 2010 directory. If you want 448 to use Tali Forth 2 for any other purpose than running it on Eris 449 2010, I recommend to use the version from the original repository, not 450 the one adapted to Eris 2010 used here. 451 452 Due to memory constraints, `ed` has been removed. Even after removing 453 `ed`, only approximately 7 KB are free. 454 455 Following the SD card structure of Eris 2010, the two upper bytes of 456 the block number are fixed to $00 (MSB) and the application number 457 (second MSB). Since SD card blocks are 512B, but Forth blocks are 458 1024B, a total of $7fff blocks are available from within the Forth 459 system. These blocks represent the SD card memory available to the 460 Forth application, i.e. the Forth application itself resides in the 461 blocks 0 to 31. If you write to any of these blocks, you overwrite the 462 Forth system! Blocks above 31 are free to use. 463 464 ## Tools 465 466 ### kfs.py 467 468 Program for formatting, listing, and writing SD card in a format 469 readable by Eris 2010. 470 471 ### boot.py 472 473 Script to upload programs via serial line. 474 475 ### reset.py 476 477 Triggers a reset by toggling DTR. 478 479 ## Case 480 481 The main purpose of the case is to expose the mainboard. :-) 482 Therefore it just consists of a top and bottom acrylic plates, 483 separated by spacer bolts. Laser cutter cutout files are located in 484 directory `case/` 485 486 ## Bugs 487 488 The communication protocol for SD cards is rather complex. The 489 implementation for Eris 2010 worked with 5 out of 6 cards tested. If 490 it does not work with your card, try a different card (or fix the 491 protocol implementation). :-) 492 493 ## ChangeLog 494 495 - v1.2 496 Tali Forth 2 and Snake added. 497 - v1.1 498 Support for C programming language. 499 - v1.0 500 First public version. 501 502 ## Copyright and License 503 504 The software in directory `contrib/` comes from third parties. Check the 505 subdirectories of `contrib/` for author, copyright, and licensing 506 information. 507 508 Everything else: 509 510 Copyright © 2021 Gerd Beuster <gerd@frombelow.net> 511 512 This project is free soft- and hardware: you can redistribute it 513 and/or modify it under the terms of the GNU General Public License as 514 published by the Free Software Foundation, either version 3 of the 515 License, or (at your option) any later version. 516 517 This project is distributed in the hope that it will be useful, but 518 WITHOUT ANY WARRANTY; without even the implied warranty of 519 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 520 General Public License for more details. 521 522 You should have received a copy of the GNU General Public License 523 along with this project. If not, see <http://www.gnu.org/licenses/>.