Sunday, September 06, 2015

A Graphical User Interface for Low Level Hacking

Disassember Window
Over the last couple of days - spare time permitting, I have written a simple application to assist in the development of code for a FPGA soft core processor.

So far, this consists of a memory view, a register view, stacks and a disassembler window.  The windows into memory are animated such that the actions of the instruction set on memory and registers may be viewed whilst single-stepping through the code.

The novel thing about this simple application, is that it has been written in Arduino C++ code, and once compiled, it runs on a ZPUino softcore processor hosted on a FPGA.  Additionally, the hardware which generates the 800x600 VGA display is also hosted on the FPGA. So we have a complete computer system consisting of cpu, memory and video generation hardware supplied on the Papilio Duo FPGA board.

The first part of this exercise was to get the graphical parts of the user interface working.  These consist of the hex memory dump window and the various stack, registers and disassemnler windows.

Now, whilst the ZPUino is itself a stack based processor, and these tools will eventually be used to examine it's operation, it was decided that initially I would use the ZPUino to emulate an even simpler stack processor.  The candidate is James Bowman's J1 Forth Processor (also available as a softcore for FPGA use) - which has the advantage of a very small instruction set, and a processor behaviour that is easily modelled in C code.

This may appear a somewhat round-about route but was chosen for the following reasons:

1.  The ZPUino can be programmed in "Arduino code" using DesignLab - the Papilio Duo IDE
2.  The ZPUino interfaces in hardware to the 800x600 VGA engine
3.  Adafruit's GFX graphics library has been ported to ZPUino
4.  A compact C model, and sufficient documentation exist for the J1 processor
5.  I wanted to understand how the J1 works, and what it's limitations are
6.  This is a programming project that meets my elementary coding skills

So my approach is to make use of the tools available.  James Bowman is working on an implementation of the J1 to run specifically on the Papillio Duo board, and make use of its 2Mbyte of SRAM. Whether he will develop it to the point where a VGA engine is supported is unknown - so for the moment I have to be content emulating the J1 with the ZPUino in C, with the heavy burden of the GFX library calls.

If we can develop sufficient momentum, then there might be a srong case to put a fast Forth soft core on a FPGA with VGA. This however is beyond my coding skills - but on my wish list for the future.

Disassembler Window

This does a very simple disassembly on the instructions in memory. The jump, branch, call and ALU instructions are decode to their mnemonics for easier reading. The animated display shows the instructions highlighted in cyan as they are executed by the processor emulator.

More Interaction

So far only the graphical code has been prototyped - just enough to see the animation of the J1 processor emulation.  For complete user interaction, it will require more code,  in particular that to support keyboard, mouse and a text editor window.

I have ordered a Classic Computing shield for the Papilio Duo from Gadget Factory in Denver. This includes sockets for PS2 keyboard and mouse, VGA output, microSD card and a pair of Atari style joystick connectors. This will allow keyboard and mouse interaction to be developed, plus program and data storage on the microSD card.  The thought had occurred to me that the Atari ports might be useful to accept switch presses from some form of custom keypad - a bit like Chuck Moore uses with his OKAD and colorForth environment.

Text Editor

The existing graphical layout allows for a text window of about 90 character columns by 75 rows.  This should be sufficient for 80 column mode plus a few clickable buttons.  The mouse will be used extensively for click and drag type operations - so a routine that links mouse position to the position of objects on the screen will be central to the user interaction.

As most coding languages are text based - the efficient manipulation of text leads to high productivity whilst programming. The use of colour text and highlighting of selected areas will enhance the user experience. The text window will additionally be used for serial output and command line input, and the use of the microSD card will allow source code to be saved and retrieved from "disk".

Assembler and Compiler

The J1 is a "Forth" processor, in as much that it is stack based, and almost all of it's instructions are Forth primitives. This allows it to execute the Forth language efficiently.  However, a modern Forth consists of about 200 definitions, and these have to be encoded in the native instruction set of the processor.  Fortunately, this is something that Bowman, and others have already done.

No comments: