6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sat Apr 27, 2024 6:51 am

All times are UTC




Post new topic Reply to topic  [ 8 posts ] 
Author Message
PostPosted: Sat Jul 13, 2019 11:46 am 
Offline

Joined: Sat Jul 06, 2019 8:20 am
Posts: 9
Hi All,

As a teenager, I didn't get much exposure to the 6502 (my machines were generally Z80) - but I did a bit of 6502 assembly language programming on an AIM-65 whilst at college.

Some years ago, I came across the KimUno - which was a 6502 emulated by an Atmel ATMega328 - running under the Arduino IDE. This uses 6502 emulation code written by Mike Chambers (already well known amongst this forum's members) - but you can find the code at the first posting of this link

https://forum.arduino.cc/index.php?topic=193216.0

With recent 6502 emulation activity over on the Gigatron Forum, I thought I'd have a go at porting the 6502 emulator code to a faster target, using the Arduino IDE and Boards Manager to (hopefully) do all the hard work.

My target board is the $25, 400MHz STM32H743ZI Nucleo board

Arduino IDE now supports this board if you install the STM32 boards using Board Manager.

Mike's code runs ehBASIC on this board without modification, but you may wish to increase the RAMSIZE to 48K  (49152) and increase the serial speed to 921600 .

Using this program it will print the numbers 0 to 10000 in about 8 seconds

Code:
10 FOR I = 0 TO 10000
20 PRINT I
30 NEXT I


If you omit line 20, and increase to 100,000 empty loops - it runs in slightly less than 15 seconds

For something a little more taxing - there is the Trig-Test that prints trig functions from 1 to 89 degrees

Code:
5  REM TRIGONOMETRIC FUNCTIONS TEST 1..89 DEGREE
10 PH = 3.141592653/2.0
15 REM DEFINE ARCSIN AND ARCCOS
20 DEF FN ASN(X) = ATN(X/SQR(1.0-X*X))
30 DEF FN ACS(X) = PH-ATN(X/SQR(1.0-X*X))
35 REM TR, TD - TO RAD, TO DEG
40 TR = 3.141592653 / 180.0
50 TD = 180.0 / 3.141592653
55 REM INPUT IN DEGREE (1..89)
60 FOR D = 1 TO 89
70 R = D * TR
80 S = FN ASN(FN ACS(ATN(TAN(COS(SIN(R))))))
90 T = S * TD
100 PRINT T; " "; D; " "; T-D; " "; FRE(1)
110 NEXT D
120 END


It will complete this in about 2 seconds.

I'm sure if I used some of the modifications and tweaks as discussed in the Arduino 6502 thread it could be a lot quicker - but if you want a quick and dirty 6502 emulation in a hurry, on a stock Nucleo board, this will only take about 30 minutes to get running


regards


Ken


Top
 Profile  
Reply with quote  
PostPosted: Sat Jul 13, 2019 4:00 pm 
Offline
User avatar

Joined: Tue Mar 05, 2013 4:31 am
Posts: 1373
Interesting project!

I decided to test your two programs on a pair of my recent 65C02 Pocket SBC boards, one running at 6MHz and one running at 8MHz. Note that console output for both boards using a NXP SCC2691 UART is set at 38,400 baud.

6MHz board:

- Printing 1-10,000 = 17.92 seconds
- Printing Trig functions = 3.06 seconds

8MHz board:

- Printing 1-10,000 = 17.91 seconds
- Printing Trig functions = 2.30 seconds

In the first test, the vast majority of execution time is based on console character speed. The total time to send all of the characters would be about 15.625 seconds.
The second test shows more of the actual CPU clock speed being the difference versus character output speed, albeit there's still a fair number of characters that are being sent.

Not sure if this is of much interest, but at least it shows some numbers from an actual 65C02 based system.

_________________
Regards, KM
https://github.com/floobydust


Top
 Profile  
Reply with quote  
PostPosted: Sun Jul 14, 2019 9:16 am 
Offline

Joined: Sat Jul 06, 2019 8:20 am
Posts: 9
Hi KM,

Thank you for supplying some timings from real 65C02 processors - most interesting.

As you say, much of the execution time is dominated by the actual time to print character output - something that I could minimise by running at 921,600 baud.

The other metric I tried was 1,000,000 empty FOR-NEXT loops, which almost eliminates the overhead of serial output. This ran in 111 seconds.

For me, the appeal of this emulator project is just how easily and quickly it was ported to a low cost, yet high performance ARM microcontroller, and running on the bare metal in standard C code.

Whilst the emulator currently only exercises the cpu and the uart peripheral, - these STM ARM microcontrollers are loaded with a multitude of modern peripherals including ADC, DAC, Timers, GPIO, SPI, I2C, DMA, PWM, LCD (VGA) etc. It's virtually a complete 1980's 6502 microcomputer on a single device.

Not only does it give another access method into the whole 6502 software ecosystem, but offers potential for emulating other classic microprocessors or even minicomputers on a very compact, yet capable Nucleo pcb.

I don't want to offend anyone here - as this is clearly not a 6502 - but a low effort emulation. I'd be happy to continue the discussion over on the anycpu.org forum


regards


Ken


Top
 Profile  
Reply with quote  
PostPosted: Sun Jul 14, 2019 1:56 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10793
Location: England
It's a good topic here - we had a thread which gradually transformed into a catalogue of inexpensive microcontroller dev boards. Mostly ARM! I think 400MHz for $25 is very interesting.


Top
 Profile  
Reply with quote  
PostPosted: Sun Jul 14, 2019 3:30 pm 
Offline
User avatar

Joined: Tue Mar 05, 2013 4:31 am
Posts: 1373
Hi Ken,

I did the same empty loop on both boards using 1,000,000 as the count:

6MHz: 207.22 seconds

8MHz: 155.20 seconds

Based on this, I'd take a SWAG that your emulated setup seems to be close to a 12MHz clock rate, which is quite admirable. Some other interesting EhBasic benchmarks were done earlier, for Sieve and Mandelbrot. It would be interesting to see how your Nucleo performs on those as well.

For Sieve:

viewtopic.php?f=1&t=5198

For Mandelbrot:

viewtopic.php?f=5&t=5184#p60638

Is your emulator doing a 6502 or 65C02?

_________________
Regards, KM
https://github.com/floobydust


Top
 Profile  
Reply with quote  
PostPosted: Sun Jul 14, 2019 8:38 pm 
Offline

Joined: Sat Jul 06, 2019 8:20 am
Posts: 9
Hi KM,

AFAIK - Mike Chambers emulator is for 6502.

Thanks for running the "million empty loops" test - that's gives another good data point to compare what this un-optimised C emulator can achieve.

I will have a go at Sieve and Mandelbrot later.

Ed - thanks for pointing me to to the emulatior thread. Some of those comments are nearly 9 years ago - so by way of an update, it is worthwhile noting how the technology has moved on since then.

The latest STM32H743 has been cranked up to 480MHz - another 20% on the 400MHz part I am currently using.

I must stress that this worked first time, using Mike Chambers' unmodified code.

Of course, more efficient implementations would be possible - and some of these have been discussed on the Arduino forum.

The Arduino IDE gave a quick and easy route to running Mike Chambers' code and getting some comparative benchmarks in EhBASIC.

I wonder how much of a BBC Model B, could be emulated on the Nucleo board?

regards


Ken


Top
 Profile  
Reply with quote  
PostPosted: Mon Jul 15, 2019 3:41 am 
Offline
User avatar

Joined: Sun Jun 30, 2013 10:26 pm
Posts: 1926
Location: Sacramento, CA, USA
Nice, Ken. Please be aware that Mike Chambers' original code didn't handle BCD appropriately, and that might eventually become an issue for you as you widen the scope of your experiments.

viewtopic.php?f=2&t=2052&p=37758&hilit=chambers#p37758

_________________
Got a kilobyte lying fallow in your 65xx's memory map? Sprinkle some VTL02C on it and see how it grows on you!

Mike B. (about me) (learning how to github)


Top
 Profile  
Reply with quote  
PostPosted: Mon Jul 15, 2019 7:46 am 
Offline

Joined: Sat Jul 06, 2019 8:20 am
Posts: 9
Thanks Mike,

I came across your BCD patch - when looking into the original thread on Mike Chambers' code.

Much Appreciated

Ken


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: