Simple Tools for Low Level Hacking


monsonite

Recommended Posts

Hi Jack & All,

 

After yesterday's faux-pas of forgetting to reload the FPGA circuit (doh!)  I have now made some progress with the VGA graphics at 800x600x60Hz - running on the ZPUino with 2MB of SRAM.

 

My intention is to create a suite of simple tools, written in C, which can explore, and help to debug the application running on the ZPUino.

 

The first of these is a Hex memory dump, which allows the contents of a range of RAM addresses to be viewed.

 

Currently it's just dumping 1K x 16bit words -  which is almost a screen full at a VGA resolution of 800x600.

 

It takes just under a second to dump Address + 16 columns of hex memory contents. So it's not the fastest hexdump known to mankind.

 

I believe that there are about 16K words left available to ZPUino, after it has taken care of the video RAM.

 

This is in preparation for running a simulator of James Bowman's J1 Forth processor - so I can single step instructions and see what the memory and stacks/pc etc are doing.

 

This is all leading towards a recreation of a simple "retro-style" computer - which runs entirely out of the PapilioDuo - fitted with a Computing Shield - for Keyboard, mouse, uSD and VGA support.

 

At the moment, all the code is written on the ZPUino, but I am keen ultimately to explore other FPGA softcore processors. First I need a crash-course in VHDL/Verilog and simulation.

 

I reach 50 in August - I have been looking at hexdumps since summer of '78 when a friend first dumped the memory of "Space Invaders" running on an early Z80 CP/M machine. He showed me which bytes to modify to alter the speed, add more bases/less spaceships etc. 

 

This is part nostalgic and part a learning exercise, programming doesn't come easy to me - but I'd rather code and keep my mind fresh - than do endless Suduko puzzles in my retirement.

 

This will be the first, hopefully of a series of posts - as I undertake this project.

 

 

Ken 

 

London

 

 

 

 

Link to comment
Share on other sites

Only an Englishman would call a computer the "Nige Machine" - I'm Scottish - so I think it's hilarious

 

 

It's a soft core running on a Spartan 3, which executes native Forth.

 

This video introduces some of the capability of a self contained system running on a FPGA.

 

 

With a 50MHz to 100MHz stack processor available (ZPUino 2.0) - this should be seriously quick - and useful.

 

 

Ken 

 

London

Link to comment
Share on other sites

Jack,

 

Thanks for your interest.

 

Hopefully this weekend, I can make some progress on coding up some more of the low level toolset.

 

I'm doing it all in Arduino code - because this has become a kind of lingua franca between the AVR and the ZPUino.

 

(Not to mention the "Arduino_STM32" which is an extension to the Arduino IDE to allow it to program the ST Microelectronics STM32F103xx range of ARM Cortex M3.)

 

So we can now share code across a wide range of cpu platforms.

 

I ordered a Classic computing shield on Monday - and like you suggested, the USPS took 2 days to get it from Westminster to Aurora and then another 2 days to drive it to LA. So it's taken 4 days to go 2000 miles in the wrong direction! - like you say the randomness of the USPS :)  Expecting it sometime in early May!

 

Never mind - this gives me loads of time to code up some of the basics.

 

I got James Bowman's J1 Forth processor running as an emulated device on a standard Arduino (ATmega328) earlier today. Single stepping through the instructions of a new processor - whilst watching what the memory, stack and major registers are doing  - is a real enlightenment to how the instructions actually work. OK - slowed down to one instruction per second gives you the opportunity to see, and understand, exactly what's happening.

 

 

Best Regards from sunny London

 

 

Ken

Link to comment
Share on other sites

Jack & All

 

The attached photo shows a classic "hex dump" display - hosted entirely on the Papilio Duo board running a ZPUino.

 

The code to generate this is written in Arduino code, running on the ZPUino, and making use of the Adafruit GFX graphics library to generate the 800 x 600 VGA display.

 

The main display  is 1K 16-bit words, which can be selectively highlighted - for example to show change in contents whilst single stepping through code.

 

On the right in green and yellow are displays showing stack contents - on the data stack and the return stack.

 

To further enhance this - in the unused white rectangle, there will be a disassembly view - showing approximately 32 instructions, plus the mnemonics of the processor being emulated and any other useful data.  There will be the ability to single step through the code and watch the memory, stack and timing cycles update as each instruction is executed.

 

Interactive use of the PS2 mouse, keyboard and probably also the inputs from the Atari joystick, for selecting modes etc  - will allow the user to navigate quickly through the code.

 

As this will ultimately be a tool for interactive Forth hacking - there will also be the means to highlight a Forth definition in memory, selectively  edit its source code, execute it etc.

 

 

regards

 

 

Ken

 

 

 

 

post-38539-0-27707100-1429963431_thumb.j

Link to comment
Share on other sites

post-38539-0-87117100-1430052714_thumb.j

 

A brief update

 

The disassembler window and register windows are now working - see photos.

 

A simple model of the J1 Forth processor has been added - which the ZPUino now emulates, providing an animated display.

 

Memory, register, stack and disassembler windows now all update and get highlighted as the ZPUino chomps through the instructions.

 

Because of the graphical display overhead - redrawing etc - the maximum speed is about 10 instructions per second.  However at about 1 instruction per second you can understand what regs are changing as a result of the execution.

 

I have created a Github Gist with the code as it stands, if anyone wishes to try this

 

https://gist.github.com/anonymous/559008675da22f909053

 

 

regards

 

 

 

Ken

 

 

London

post-38539-0-06718900-1429986608_thumb.j

Link to comment
Share on other sites

Ken, take a look at ZPUino_GFX. It should contain all info you need.

 

For 8-bit color (rgb332) the framebuffer uses a byte per pixel. For 16-bit (rgb565) it uses two bytes. Endianness is big-endian. Stride is equal to the resolution width times number of bytes per pixel.

 

A function called getFramebuffer() returns the framebuffer, as a 1-dimensional array. An helper function (getPosition(x,y)) returns a pointer to pixel @ x,y. You can use this pointer for faster access.

 

Here are two examples from ZPUino_GFX, for RGB332 (uint8_t as pixel type). First one draws a vertical line, second one draws an horizontal line.

void drawFastVLine(int x, int y, int h, uint8_t color){    int delta = width();    uint8_t *p = getPosition(x,y);    while (h--) {        *p=color;        p+=delta; /* Move to next line */    }}void drawFastHLine(int x, int y, int w, uint8_t color){    uint8_t *p = getPosition(x,y);    while (w--) {        *p=color;        p++; /* Move to next column */    }}

Alvie

Link to comment
Share on other sites

Hi Jack, Alvie

 

Alvie has sent me what I need (and where to look) in the GFX library.

 

Next thing - is there a working example of the PS2 Mouse and keyboard when attached to the ZPUino via the Classic Computing shield?

 

If not, it might make a good tutorial.

 

 

 

Thanks in advance

 

 

Ken

Link to comment
Share on other sites

Hey Ken,

 

There is no published examples or libraries for the PS2 Mouse and Keyboard yet. I have used Arduino libraries in the past with very little effort, so that is probably the easiest method. If you want to use VHDL I did record these two videos about turning Hamster's PS2 Keyboard code into DesignLab libraries:

http://gadgetfactory.net/learn/2015/04/03/designlab-libraries-library-from-internet-code/

http://gadgetfactory.net/learn/2015/04/03/designlab-libraries-make-a-wishbone-library/

 

That takes care of the Keyboard side, not sure about mouse side though.

 

Jack.

Link to comment
Share on other sites

Hi Jack

 

Thanks for the advice.  

 

I think I'll follow the Arduino route for the moment, till I bite the bullet and have a crack at the VHDL.

 

Tonight, my aim is to refactor my hex dump code to allow a quicker response when values change in the memory dump window.

 

I am also going to do some speed tests to see how long the GFX library is taking to print characters - as I think this may be the limiting factor.

 

I see from the USPS tracking that my Classic Computing shield is now in the UK - having landed at Heathrow on Saturday afternoon. Hopefully I will get that tomorrow.

 

regards

 

 

Ken

Link to comment
Share on other sites

  • 2 weeks later...

Jack & All

 

My Classic Computing shield turned up today - it got detained in the UK customs and postal system for over a week!

 

I have got some simple sketches working to read the keyboard code and mouse position and clicks. In the end I just used the Arduino ps2 library - which is fairly simple to use.

 

I am now developing some routines to allow the mouse to be hovered over the various data fields of the hex memory dump, so that RAM data can be selected and manipulated.

 

So far, I can move the mouse pointer over a memory location and watch the data change in real time. I will develop this further so that it becomes a hex editor - allowing new data to be entered into the memory with the click of the mouse.

 

The code is running a really slow simulator of James Bowman's J1 Forth processor - all emulated in C.  THe J1 instructions are a simple loop that cause the value stored at address 0x0010 to be incremented each time around the loop.  If you hover the mouse over address 0x0010 - you will see it update. Clicking the left mouse button will flash it red.

 

The code is kind of quirky at the moment - but I've put the latest up on Github Gist - if anyone wants to look over it.  You will need a computing shield with the mouse plugged into PS2/A and install the PS2 library from the Arduino playground.

 

The code is here:   https://gist.github.com/anonymous/892a097bc8bbbbf1c5ca

 

regards

 

 

 

Ken

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.