Shop OBEX P1 Docs P2 Docs Learn Events
P2Si65 - A Path for P2 to Software, Multitasking, OS, …? - Work in Progress — Parallax Forums

P2Si65 - A Path for P2 to Software, Multitasking, OS, …? - Work in Progress

Motivation
Based on a P2 a Self-Hosted Computer might be built.

It should have:

A File System (SD Card)
Multitasking to control something or take measurements
A console user interface
A compiler
An Assembler
Access over WLAN
Plenty of useful Software

If we look at this list, we can see, that Peter Jakacki's Taqoz has nearly all of it. Access over WLAN can be achieved with a ESP-01 Module. Only the last item is not given.

Peter has included a 6502-Simulator in his Source Forge archive.

So the basic idea is:
Have a 6502-Simulator inside Taqoz Forth.
Can we use that to gain access to software?
Old software was often written in assembler to get the speed.
64kBytes of HUB Ram should be plenty for 6502 and still fit nicely into Hub Ram.
Speed must be as fast as an original Computer to be fun: 6502 running at >= 1MHz.

How it went so far
A very first test with the simulator, which is written entirely in Forth, was encouraging. Each assembler code is a Forth word. Very transparent. It worked and it was able to achieve about 0,4MHz with a minimal loop:

$3000 INC $2000
$3003 JMP $3000

Getting rid of debugging code brought it over 1MHz easily. So I decided to go on.
Next part was to bring some little software to it. WOZMON is a famous compact peace of code by Steve Woziak for the Apple I. There is an enhancement, which brings a mnemonic assembler and a disassembler.
AppleI_Manual.pdf (chez.com)

So this peace of code brought to light much to learn for me (My experience with 6502 is rather lowlevel as I never owned one of these computers. - …A carry flag, that alters it's meaning…) and some bugs. Console input and output is done via an unused code $FF which is now TaqozTrap. It can be included easily into any assembler code ".byte $FF". I decided to follow: http://www.z80.eu/dos65/DOS-65_System_Interface_Guide_A.pdf

3rd step should bring more test code for debugging and some more knowledge about speed. So I was glad to to stumble over:
https://www.ele.uva.es/~jesus/onthe6502.pdf which gives a benchmark for the "sieve". - This showed a speed back to 0.3MHz. :-( .

Speed was improved over many smaller steps, which made debugging more easy.
Introducing new Methods brought the steps:
Some Hub assembler code
Bring 6502 Registers and constants into cog Ram
Bring assembler routines into LUT Ram
Last step: A self-repeating main loop word in LUT assembler, which does call Forth words.

4th step was now an additional program to find bugs. It is a "Very Tiny Language 2". It is very impressing once again, what can be acieved with less than 1kByte! A IDE with an interpreter.

Manual:
VTL-2 (altair680kit.com) http://www.altair680kit.com/manuals/Altair_680-VTL-2 Manual-05-Beta_1-Searchable.pdf
Newer Source by Michael T. Barry:
6502-Assembly/VTLC02 at main · barrym95838/6502-Assembly · GitHub
Used Source:
GitHub - Klaus2m5/VTL02: Very Tiny Language for the 6502 series of CPUs

Tools:
A powerful cross assembler:
cc65 - a freeware C compiler for 6502 based systems: https://cc65.github.io/
The linker/assembler creates a listing file with the hex codes. I wrote a routine, which extracts the hex codes with their addresses and inserts them into the 6502 Hub Ram Page.

Kowalski Simulator, a powerful simulator and debugger:
Daryl's Computer Hobby Page (rictor.org) https://sbc.rictor.org/kowalski.html
This is very helpful to find out, what is going on. (Oh, yes, nearly all bugs are my very own…)

At the moment I am wondering, how to go on, after these steps so far. One attractive possibility seems to be EhBasic.
Enhanced 6502 BASIC – Retro Computing (hansotten.nl): http://retro.hansotten.nl/6502-sbc/lee-davison-web-site/enhanced-6502-basic/

Another possibility seems to be a part - emulation of the BBC computer, because this seems to have a clear interface to some sort of BIOS. It's BASIC is powerful and structured.

What would be the best route to make much software (I am not much of a gamer....) accessible for P2?
Any hints appreciated!
Christof

Comments

  • mparkmpark Posts: 1,305

    6502 @ 1.4MHz? Awesome! And that VTL-2 language is cute!

  • Some update.
    After some more debugging, it is now capable to run the full blown Enhanced 6502 Basic! - About 10kBytes of 6502 assembler code.
    retro.hansotten.nl/uploads/leedavison/Enhanced_6502_BASIC_reference_manual.pdf
    This is a niece BASIC interpreter, which does use tokens and has fast FOR...NEXT and fast DO...LOOP UNTIL.

    I added the possibility to execute any Forth word from BASIC: The address of the string containing the word is written in Basic to $FFF4 (of 6502's memory page). If this is found by the trap routine, which is called after each BASIC command to find ctrl C, then the Forth word is executed. This Forth word can write a word to 6502's $FFF6 as a result. In the example below, "get100" gets a timer result in 1/100 secs.

    As Forth words can also be written as "code words" in assembler, full access to P2's hardware is given.

    Benchmark results for comparison can be found here: https://ia800304.us.archive.org/16/items/byte-magazine-1981-09/BYTE_Vol_06-09_1981-09_Artifical_Intelligence.pdf
    With 170 seconds for one iteration it is running faster than the interpreted Microsoft BASICS for Z80@4MHz and Apple II, which also had to use floating point numbers.

  • RossHRossH Posts: 5,351

    @"Christof Eb." said:

    Motivation
    Based on a P2 a Self-Hosted Computer might be built.

    It should have:

    A File System (SD Card)
    Multitasking to control something or take measurements
    A console user interface
    A compiler
    An Assembler
    Access over WLAN
    Plenty of useful Software

    Catalina has all these, possibly excepting "Access over WLAN", because I don't know what that means - but I'm sure it would be trivial to add. Can you clarify?

  • Fascinated and following :+1:

    Craig

  • @RossH said:

    Catalina has all these, possibly excepting "Access over WLAN", because I don't know what that means - but I'm sure it would be trivial to add. Can you clarify?

    Hi,
    yes Catalina together with it's Lua is going in a similar direction. The main difference is, that I think, that it is a good idea to simply accept P2's "limited" HUB RAM. So no SPI RAM is used or necessary. To achieve this, Forth has to be simpler than Lua. And this BASIC interpreter is usable with 64kB or less.

    about your question:
    Here the idea is to use the serial console over WLAN TELNET, while with Taqoz's multitasking and the additional cogs, some controlling process is running in background. You can use all the possibilities of Forth in parallel to the controlling tasks: View and alter data or parameters, compile, assemble, ... Connect from a PC or mobile phone. No additional server is needed.

    I have several ESP-32 modules running here. They use a Forth based on Arduino CC. They have triple access:
    1. TELNET console as described.
    2. possibility to reprogram the ARDUINO code over WLAN
    3. They offer their file system in the WLAN as a remote storage, which can be accessed from Windows like a network disk.
    Perhaps I find a way in future, that a ESP-32 module acts as mass storage for P2 together with TELNET serial modem and network disk server.
    Christof

  • RossHRossH Posts: 5,351
    edited 2023-06-21 23:49

    @"Christof Eb." said:

    @RossH said:

    Catalina has all these, possibly excepting "Access over WLAN", because I don't know what that means - but I'm sure it would be trivial to add. Can you clarify?

    Hi,
    yes Catalina together with it's Lua is going in a similar direction. The main difference is, that I think, that it is a good idea to simply accept P2's "limited" HUB RAM. So no SPI RAM is used or necessary. To achieve this, Forth has to be simpler than Lua. And this BASIC interpreter is usable with 64kB or less.

    about your question:
    Here the idea is to use the serial console over WLAN TELNET, while with Taqoz's multitasking and the additional cogs, some controlling process is running in background. You can use all the possibilities of Forth in parallel to the controlling tasks: View and alter data or parameters, compile, assemble, ... Connect from a PC or mobile phone. No additional server is needed.

    I have several ESP-32 modules running here. They use a Forth based on Arduino CC. They have triple access:
    1. TELNET console as described.
    2. possibility to reprogram the ARDUINO code over WLAN
    3. They offer their file system in the WLAN as a remote storage, which can be accessed from Windows like a network disk.
    Perhaps I find a way in future, that a ESP-32 module acts as mass storage for P2 together with TELNET serial modem and network disk server.
    Christof

    Yes, I figured you would want more than just a WiFi file transfer capability (which would be easy and also gets you the ability to load software via WiFi). The others are a little more difficult, but would be do-able if you really want them.

    If you limit yourself exclusively to Hub RAM I think you may be unnecessarily limiting yourself to assembler-level and/or interpreted languages like Forth, Lisp, Basic or Spin. We already have all of those in various forms, but very few people use them other than already confirmed Propeller-heads. None of them are likely to attract hordes of new users to the Propeller. You need higher level languages to attract serious usage. And the reason is the last item on your list ...

    Plenty of useful Software

    Bu then there is Lua. Yes, Lua is also interpreted, but on the P2 it can run entirely in Hub RAM (it can use External RAM, but does not need to). I note the ESP-32 also supports Lua, as do other microcontrollers. This is because Lua has a low footprint and is easy to port because it is written in what they term "clean C", which is essentially ANSI C. Which means once you have C you have Lua.

    So in Lua we already have on the P2 the ability to write and run software using a modern high-level language that is already used in this space, is growing in popularity and has plenty of support and software.

    If you don't like Lua as much as I do, you could choose mciroJavaScript, microRuby or microPython. It is the "micro" part that puts me off those - I wouldn't want to use anything where I didn't have access to the full language.

    So we are almost there. I notice the P2 WiFi add-on board is no longer available, but when it is again I might add support for it.

    Ross.

  • @RossH said:
    We already have all of those in various forms, but very few people use them other than already confirmed Propeller-heads. None of them are likely to attract hordes of new users to the Propeller. You need higher level languages to attract serious usage.

    Well, in my personal opinion, it is mainly Parallax Marketing policy, which prevents wide usage. The "edge board" is way too expensive for it's performance (and unnecessarily nonhandy to use without USB serial and it's special connector) and they only support their very special own language Spin2. Writing documentation has stalled. No visible efforts to write drivers.

    P2 is the only microcontroller, that I know of, which really needs an inline assembler. When I work with Arduino environment, I have never used Assembler. But with P2 it is mandatory, because you have to use tricks to reduce HUB access and to write drivers. So Lua would need an inline Assembler. Does it fully support 8 cogs?

    I have not tried your Lua, but a simple speed comparison for ESP32 was:
    C:YAFFA-Forth:Lua:Micropython = 1:22:48:145
    (((I sometimes think, that some eager politicians have banned light bulbs in Europe. I do wonder, when they will ban Micropython....)))

    Writing of speed. I yesterday coded the "Byte Sieve" with Taqoz and with it's P2 assembler. For a reduced version for the first 308primes up to 2039 (SIZE=1024) I get:

    P2 loops in assembler, executing from LUT: 0,00054sec (array is in HUB)
    P2 Taqoz Forth, algorithm original: 0,0084sec
    P2Si65, 6502 assembler: 0,858sec (version from post above)
    P2Si65, 6502 EhBasic: 20,1sec
    Actually I have to confess that the version with EhBasic is well fast enough for my personal demands of prime numbers. And doesn't it give a much better feeling, that they are calculated with floating point precision?

    Have fun,
    Christof

  • @"Christof Eb." said:

    Well, in my personal opinion, it is mainly Parallax Marketing policy, which prevents wide usage. The "edge board" is way too expensive for it's performance (and unnecessarily nonhandy to use without USB serial and it's special connector) and they only support their very special own language Spin2. Writing documentation has stalled. No visible efforts to write drivers.

    With utmost respect, as a control systems developer, the Propellers are ridiculously inexpensive and those of us who are mediocre programmers can realise mind-blowing capabilities using a "toy language" such as FlexBASIC.

    In contrast, one of my clients has asked me to source a backup for his discontinued PLC (puny compared to even a P1) and the best price I can find on eBay is £1800 (8-DI and 8-DO)
    There is also an expansion module for reading two quadrature encoders (500,000 counts/sec) and this is £500 (used).

    By definition, the Propellers are "controllers". They don't claim to be "computers".

    I love these bad-boys :+1:

    Craig

  • RossHRossH Posts: 5,351

    @"Christof Eb." said:
    So Lua would need an inline Assembler.

    Lua is designed to be highly integrated with C. When you need more speed than Lua offers, you first drop into C. From there you can drop in to inline assembler if you really need to, but that would be quite rare.

    Does it fully support 8 cogs?

    Catalina includes a multi-processing version of Lua which can use all 8 cogs.

    I have not tried your Lua, but a simple speed comparison for ESP32 was:

    Speed is never going to be one of Lua's strong points. However, for C programmers (and there are lots of those) Lua is still an attractive option. Lua finds much of its use as an embedded scripting language inside larger C programs, because by doing so you can have the speed of C and the rapid prototyping power and flexibility of Lua.

    Ross.

Sign In or Register to comment.