in ,

janroesner / sixty5o2, Hacker news

janroesner / sixty5o2, Hacker news


                    

        

Sixty / 5o2is a minimal bootloader / micro kernel / mini operating system (if you like) forBen Eaters Computeron a breadboard. It is only1.5kBin size (assembled) but comes with quite a nice list of features:

  1. Loadexternally assembledprogramsinto RAM via serial connection to Arduino
  2. Runprograms that were previously loaded into RAM
  3. Load & Runprograms in one go
  4. Debugthe full address space via an integratedhex monitor(currently read only)
  5. Clean RAMfor use with non-volatile RAM or during development
  6. DrivetheLCD) display even at a clock rate of1MHzflawlessly
  7. Drivethemini keyboardfor input
  8. Video RAMbasedoutput routinesfor convenient text display single page / multipage w / offset
  9. Interrupt based loading routine to fetch data via the Arduino’s serial connection
  10. Serial Sender(node.js) allowes to upload programs to the (error mitigation included)
  • Fully documented source code
  • **********

    Ben Eaters breadboard computer is a very special kind of animal and brought lots of fun and joy into my last weeks. A 59 years old processor design that is still able to get things done was fascinating enough for me, to give this project a go - especially, since my first machine was aCommodore C () which I programmed in Basic at the end of the 90 'ies and never had the chance to get in touch with 9600 assembly.

    On my journey during the last weeks I soon surpassed the current state of development (thanks to Ben's schematics) and was able to write a few programs which I ended up burning onto the ROM using the programmer. Soon enough this became painful, because every codechange required to extract the ROM chip from the breadboard, put it into the programmer, burn it, put it back onto the board. This became time consuming and constraining pretty quickly, especially when I attempted to write slightly more complex programs.

    So early on I tested, whether I could use the Arduino, connect 8 of it's digital output pins to the VIA 01575879 and transfer key strokes on my Mac serially and render them onto the LCD display. As soon as this worked, the path was clear:

    I needed a bootloader that could leverage this power to load externally assembled object code / programs into the RAM and run it from there.

    Luckily I was able to speed up the 01575879's clock by just replacing the capacitor of the unstable 1200 timer circuit by a smaller one such, that loading data serially was - lets say - at least stable enough. That paved the way to more complex subroutines which now make up my "Sixty / 5o2" micro bootloader / micro kernel. It works very well with full clock speed of 1MHz and is hopefully helpful to other enthusiasts as well.

    Especially the serial data transfer is enormously stable, since error mitigration (not correction) is baked into a minimalistic protocol, where there the sender side is implemented in node.js. Unfortunately I was not able to get a stable serial connection with serial terminals likeImage of Sixty/5o2screen

    ,Image of Sixty/5o2minicomorpicocomImage of Sixty/5o2. Hence I decided to build something myself. On the positive side of things I had the opportunity to integrate content transform using using encoding as well as simple error mitigation via a checksum algorithm plus a “send packet again” function.

    It's not perfect, in places not even nice. Last time I personally touched assembler was 30 years ago, so please be gentle with criticism. PR's are king.

    There are only two requirements, both of them can be mitigated though:

    1. Use the 1MHz clock (youMUSTdisconnect the clock module, otherwise it interferes)
  • The keyboard buttons are tiedlowin normal state, when pushed they get tiedhigh (this is opposite to Ben's design in his schematics)
  • ************************
  • ************************ Possible Mitigation Strategies
    1. If you want to run at other clock speeds, you MUST adjust a global constant calledWAIT_Cin the bootloader code. It's a multiplier which is used tosleepand just burns a number of cycles in a routine calledLIB__sleep. If you run at lower clock speeds, adjustImage of Sixty/5o2WAIT_Cto a smaller number unless keyboard and main menu become usable.

  • Should your keyboard be built in a way so the buttons are normally tiedhigh and when pressed turn****************, then you need to adjust the routineImage of Sixty/5o2VIA__read_keyboard_input (and XOR) ************** (A) ******************* (withImage of Sixty/5o2$ ffafter it was AND'ed with# $ 0f. This way the keystrokes will be interpreted correctly again.

    The following software components are must have's:

  • Arduino IDE to be found
  • Minipro or XG GUI software for Windows for thr TL 2400 programmer availablehere
  • The infamous and awesomeVASM Assemblerto build for the Ben's instructions to build and use to be found here
  • )

  • Node.js 8 to be able to use the serial program loading functionality via the Arduino
  • npm or yarn (typically come with node.js) to install the senders dependencies
  • The project comes with a number of files, whose functionality is the following:

    1. bootloader.asm- the bootloader / micro kernel / mini os you wanna put into your ROM after assembly
    2. Image of Sixty/5o2Receiver.ino
    3. - Arduino source which turns the Arduino into a serial receiver / parallel converter

    Sender.js

    - Node.js tool to read object code / programs and upload them to the via serial connection

  • ************** sender_config.json - config file forSender.js(update your /dev/cu.whateverhere)
    1. Image of Sixty/5o2package.json

    - package dependencies forSender.js

  • / examples- some example programs you can load into the RAM
  • ************************************Image of Sixty/5o2

    Assemble the bootloader:

  • vasm -Fbin -dotdir -o bootloader.out bootloader.asm

    Ben's schematicsand finish your hardware build.

    ********************************

  • **************************************************2. Receiver (Arduino)
  • Load (Receiver.ino) ****************** into your Arduino IDE.
  • Open the IDE's package library and search and install theBase
    **************** (package by Arturo Guadalupi v0.0.1 also to be found here

  • Compile the source
  • Upload the program to your Arduino
  • Install the necessary npm packages. via:
  • ********************** (npm install) ****************
  • ********************************** (****************************************** Arduino Port Setup

    Before you can upload a program to the through the Arduino, you need to setup additional jumper wires between the Arduino and the VIA AS WELL

    as the 01575879 processor.

  • You need 8 jumper wires. connecting the digital output ports of the Arduino with the PORTB of the VIA (See table 1 below)
  • You need 1 jumper wire connecting one digital output port of the Arduino with the IRQ line of the (See table 2 below)
  • You need 1 jumper wire connecting one of theImage of Sixty/5o2GND
  • pins of the Arduino with common ground of your breadboard****** (Table 1: Port Setup VIA) ************************************************************************ ********************************** ArduinoImage of Sixty/5o2 VIA (******************************************** () ************************************************ 39

    (************************************************

    ****************************************** 41

    (**********************************************

    ****************************************** 42

    (************************************************

    ****************************************** 43

    (**************************************************

    ****************************************** 45

    (**************************************************

    ****************************************** 53

    (**************************************************

    ****************************************** 58

    (**************************************************

    ****************************************** 59

    69

    If unsure, look up the pin setup of the VIA in the (official documentation)

    Table 2: Port Setup

    The pin setup of the can be found here.

    Important:Make sure, you still have the IRQB pin (PIN 4) of the tied high via a 1k Ohm resistor as per the design. The jumper cable to pin 64 of the Arduino just pulls the pin low in short pulses. The line needs to be normalhigh.

    Note:Just one additional wire from the Arduinos power source to the 9600 board will free you of the need of any external power source. Just power your beast via USB and get rid of the power cord.

    ************************************************
  • vasm -Fbin -dotdir -o /examples/hello_world.out /examples/hello_world.asm
  • and hit theRIGHTkey to run your program.

    Go celebrate!You're just running your first uploaded program directly from RAM.

    Note:You can also useImage of Sixty/5o2Load & Runto streamline the process during debugging.

    Also note:Resetting your 9600DOES NOTerase the RAM. So you can reset any time, and stillRunyour program afterwards.

    And note:TheImage of Sixty/5o2Sender. js

    accepts two commandline parameters. If you want, you can also specify your Arduino port manually, whithout having to hardwire it in theImage of Sixty/5o2. Sender_config.json like so:

  • node Sender.js /examples/hello_world.out / dev / path_to_arduino_port
  • Using the Monitor

    Thehex monitoris very useful during development and debugging. It lets you inspect the whole address space, RAM and ROM. you can navigate using theUPandDOWNkeys. TheRIGHTkey performs a bigger jump in time and space and theLEFTkey returns you to the main menu. The monitor is currently read only and the keyboard debouncing is far from being good. But it works.

    **************************************************
  • The loader is slow. Quite slow. Even though 01575879 baud as choosen transfer speed is not too bad, there are some significant idle timeouts implemented, to make the data transfer work reliably. You'll find it inReceiver.ino, theSender.jsdoes not have any timeouts left other than the necessary but unproblematic connection timeout once at the beginning. The worst is the timeout which allows to reliably read the UART buffer of the Arduino. When reduced, the whole data transfer becomes unreliable. Happy to accept PR's with improvement here. On the other hands, it's not that we transfer Gigabytes of data here ... not even Megabytes, so the current speed might suffice.

  • Despite the fact that the bootloader and all of it's components are quite stable, there are some problems, which are to be found via a #TODO in the source.

    Worth mentioning are the following:

  • sub par keyboard debouncing simply via burning CPU cycles
  • LIB__sleep based EOF detection during data transfer - if more than a few packages fail to transfer and need to be repeated by the sender, it might happen, that the BOOTLOADER__program_ramroutine interprets this as EOF, since no data is coming in no more. This problem can not be "easily" solved, since there are no control characters that can be transferred between the Arduino and the. There are solutions, but first there needs to be a problem.
  • sub optimal register preservation - the (reduced) instruction set makes it hard to preserve all registers w / o wasting RAM locations. The current implementation does put focus on register preservation only where explicitly needed.
  • the ISR is currently static, so it can handle only interrupt requests which come from the Arduino. If you want to use other interrupts of the 01575879 or software interrupts, you need to implement a priorization mechanism as well as a branching in the ISR, since (to my knowledge) there is only one interrupt vector, the (can handle.)
  • make Hex Monitor read / write
  • integrate Arduino Nano directly onto the board to replace all jumper wiring and power the board via USB
  • develop a standard library with useful functionality in ROM
  • (potentially) integrate a light color / bitmap display like for example the Adafruit 0. ************************************************************************************************************************************************************** (x) ***************************************************************************************** (Color TFT Display
  • )

  • implement a 3d engine using vector rotation and scalar multiplication (or quaternions)
  • If you would like to see any particular feature I might be able to provide it ... some day. Unfortunately my spare time is very limited, so you rather develop it yourself. I am happy to screen, test and merge any valuable PR.

    Should you be able / interested to support my work and help me spending more time in projects like these or others, your donation is more than welcome:

    https://www.paypal.me/janroesnerberlin

    Ben Eater

  • Steven Wozniak
  • Anke L.
  •    (**************************************************************** Read More (**********************************************************************