Qbasicnews.com

Full Version: Emulating a 3mhz computer with 1ms threads.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hey, I'm here on business. Can anyone send some links my way on simulating clocked CPU cycles at more than 1000 cycles a second (e.g. threads) ?

I have a final design project for one of my CmpE courses, in which I'm writing an simulator for a silly little amigobot used in the course, powered by a 1Mhz single-register computer we wrote in VHDL and programmed into an Altera Flex board. This, along with a BIOS diagnostic for the robot, has been sucking up 16 hours day.

Now, what I have done, with javascript being my most knowledgable langauge, is written a simulator for the robot, that compiles assembly code into a virtual memory dump, interprets the bytecode, and simulates the I/O ports. There's an incomplete implementation here:

http://www.betterwebber.com/stuff/AlteraSim.zip

The problem with this (in progress) javascript implementation, however, is that the fastest this thing can ever go is 1000Hz, and that's like super-ideal because Javascript can only thread in milliseconds time (looping locks up the parent browser). I still want to finish it because it's 100% cross platform, but, well, you know, when this thing gets into sonar and IR simulation, it's going to take a hit in speed.

So, this is my chance to finally explore Freebasic and make a complementary port, so I can develop a full-speed simulator side by side. But from my knowledge, Win32 threads also execute at 1ms. How do emulators and virtual machines for 3mHz computers execute like this? My knowledge of event based programming has been cuddled under virtual languages like javascript and java until now. With a 1mHz clock, this thing needs to be able to perform 333,000 instructions per second, without clogging up Windows, to be full speed. Does anyone have experience with this?

I'm thinking, and only guess, that I'd have to make a single thread, and figure out if Windows has some sort of microsecond timer or something.
i sense your last assumption is correct. first look up high precision timers ( in win32 search for queryhighperformancecounter ). though on some win you won't get a precise enough timer that has 1ms precision. i also believe that 1 ms is a hard to achive precision with the high performance counters. but as i said. look that crap up.


and as a side note: wtf, you are simulating threading with multiple browsers open, one parent browser opens child prowers ??? you must be one little insane man Smile
Hahaha...

You can execute pseudothreads in Javascript by calling:
handle = window.setTimeout(myfunction, milliseconds)
though opening a new window for each new thread would be pretty funny.

And then calling the same thing inside myfunction. It runs surprisingly well. It doesn't *have* to execute 333,000 instructions a second. But it has to at least beat the couple hundred or so that the javascript simulator pulls off.

Running QueryHighPerformanceCounter in a thread seems to be exactly what I'm looking for, thank you. Next up: a tabbed GUI (groan).
No need to use QueryPerformanceCounter and similar... in 0.13 TIMER uses it underneath anyway, so if you explicitely use such Win32 APIs, you achieve the same performance of TIMER, but you loose portability...
Wow! You guys are fantastic.