Fast enough for an emulator?

BlitzMax Forums/BlitzMax Programming/Fast enough for an emulator?

Rick_72(Posted 2011) [#1]
Hi guys,

I was wondering whether BMax is fast to run a simple emulator of an 6809 system (at 1.5 MHz) with a simple video output. Actually I plan to build a Vextrex emulator.

Of course this depends on the hardware it is ran on and the cleanness of software design. My machine is quite fast so I am not worried about my machine specs. Of course this is not matter of programming languages - I am aware of that.

Given that is all mentioned above is almost perfect (design) what would think about this project? Does any of you have experience in building such machine?

Tx,
Rick


BlitzSupport(Posted 2011) [#2]
Have a look at this...

http://sites.google.com/site/rveilleux/blitzmaxarcadeemulatortutorial

I know someone did a Spectrum emulator many years ago, too, and seem to recall that ran full speed.


Jesse(Posted 2011) [#3]
I'm no expert on the subject so I don't know how efficiently it can emulate different processors and it's corresponding hardware so I can't really be much help but somebody here made an emulator for the arcade Space Invaders that works quite well. you can find it here:
http://www.blitzmax.com/Community/posts.php?topic=76057

[edit]
oops!
same post as James.

Last edited 2011


Rick_72(Posted 2011) [#4]
Very cool indeed!
Thanks for your fast replies! That really helps.


Floyd(Posted 2011) [#5]
I would say yes, based on no experience at all.

How could BlitzMax not be adequate when the hardware is more than a thousand times as fast? I know Vectex was vector-based, but you ought to able to emulate that even if you were drawing pixels. But I assume it would really be done with the 3D hardware drawing vectors as skinny polygons.


col(Posted 2011) [#6]
Hi, BMax is certainly more than fast enough. I've made a Z80 emulator than can run most (not all) Z80 code, in fact it runs the arcade ROM of the original Pacman.

You need to do LOTS of research for the processors and co-processors. There may be some undocumented instructions that 'some' old school programmers knew about, if you want those softwares to run then you obviously need to incorporate those 'extra' instructions too.

Of course there's more to do than just emulating the processors, you have code keys, disc/tape/cartridge, sound and display ( to name a few ) to consider too. Its great fun to do. Give it a go :o)

Last edited 2011


GW(Posted 2011) [#7]
I agree with col, I hacked up a NES emulator with Bmax, and speed was never an issue.


Mahan(Posted 2011) [#8]
BMX runs about ½ as fast as pure C-speed (give or take), so that should not be an issue since good emulators have been around since 486 and Pentium times, and computing power has doubled many times since then.

EDIT: Due to concerns below I'll add this statement:

I have no empirical test, statistics or facts to base the above statement on.

1. ½ speed of "pure C" is my "guesstimate". Not a fact. It's based on my feelings and inner convictions. I am however always ready to change these views if I'm presented with scientific data that proves otherwise.

2. You should have no problems with the speed of the language implementing an 8-bit game console.

Last edited 2011


Czar Flavius(Posted 2011) [#9]
LOL according to what?

It depends entirely what you are doing. What's pure C anyway?


Gabriel(Posted 2011) [#10]
What's pure C anyway?

It's what people say when they're explicitly not counting C++. Pure C is slightly faster than C++.


Czar Flavius(Posted 2011) [#11]
It was a rhetorical question. Again, it depends what you are doing. There is no difference between a function which takes a pointer to a struct and modifies it, and a method of the struct that does the same thing, but you can only do the latter in C++.

Likewise, a struct with some kind of id number and a function with a switch statement that does something different depending on the id, isn't too different to a virtual function overridden by different classes. People compare "slow" virtual functions to normal functions all the time but fail to realise a virtual function doesn't just replace a function, it replaces a function and a decision.

The problem is when people don't understand all the alternatives or how they work deeply and just use virtual functions and dynamic memory here, there and everywhere and the result is a slow, bloated C++ program. But that's not C++'s fault.

In other words, "X language is faster than Y language" is the kind of meaningless, simplistic statement I wouldn't expect from an experienced programmer like yourself.


Mahan(Posted 2011) [#12]
@Czar Flavius:

I didn't mean to start any religious war about this, and I'm sorry if I sounded a bit dogmatic.

What I meant is simply how I have perceived it programming GCC/VC++ vs BMX.

And Gabriel is right in what I meant by "pure C":

C++: Writing code that relies on the C++ superset of C (i.e. Classes, Templates etc.)
C: Writing code that relies purely on pointers and addresses, or what is sometimes jokingly called "portable assembler".


Gabriel(Posted 2011) [#13]
In other words, "X language is faster than Y language" is the kind of meaningless, simplistic statement I wouldn't expect from an experienced programmer like yourself.

A simplistic statement is all the subject requires. It's not remotely meaningless for Mahan to tell the guy that the languages are a factor of two apart, when he only needs to know whether it's a factor of two or a factor of a thousand. That's exactly what the original poster needs to know.

Sometimes, you don't need PI to 471 digits.

Last edited 2011


Czar Flavius(Posted 2011) [#14]
It's not the accuracy, it's the fact the number was just made up. I use facts to make my decisions.

But you're right! Who needs PI to any decimal places? Because 471 is too much, let's just use it to 0 decimal places.


skidracer(Posted 2011) [#15]
Saying BlitzMax is half the speed of C/C++ is an insult.

It is typically closer to 90% while delivering to the developer, at a guess, a 327% increase in productivity.


GfK(Posted 2011) [#16]
It is typically closer to 90% while delivering to the developer, at a guess, a 327% increase in productivity.
You were close - its actually a 341% increase.

Mahan should be a politician with his made-up "facts".


Gabriel(Posted 2011) [#17]
It's not the accuracy, it's the fact the number was just made up. I use facts to make my decisions.

Ok, well tell you what then. You benchmark the two languages against one another, on a broad array of different tests. Compute an average over all the tests, and come back and report it. If it's closer to 1000:1 than it is 2:1, I know I'd be only to happy to apologize profusely for aiding in the distribution of inaccurate information. Assuming you'll be prepared to apologize profusely for nitpicking if it's closer to 2:1.

It's got to be worth it. Just think of all that benchmarking you get to do, regardless of the outcome.

But you're right! Who needs PI to any decimal places? Because 471 is too much, let's just use it to 0 decimal places.

Funny you should say that. I came very close to listing you an example where it is generally recommended to do precisely that.

Last edited 2011


Czar Flavius(Posted 2011) [#18]
You have totaly missed my point. I don't care about nitpicking over the decimal place. I just don't like it when people announce facts as if they had done those tests. The "give or take" added an extra air of authority. Even if I did do the benchmarks and it was closer to 2:1 I wouldn't have anything to apologise for as I never said it wasn't 2:1. I just said, don't say it's something if you don't know. Just because by chance you may or may not be right with your guess, what difference does that make?

People search these forums for information and can often find things in threads that aren't strictly related to what they're searching for. Let's work together to make it informative and helpful for the busy programmer with a quick, specific query.

As for the X faster than Y, if you like that then go to GameDev where BlitzMax is worse than Java and is just an interpreted language for babies that doesn't even have scoped variables or pointers or even numbers probably with some of the rubbish I've seen said about it over the years (<= half of those claims I have actually seen!). I just don't run on anecdotes and one-liners, sorry.

Last edited 2011


Gabriel(Posted 2011) [#19]
People search these forums for information and can often find things in threads that aren't strictly related to what they're searching for. Let's work together to make it informative and helpful for the busy programmer with a quick, specific query.

You're right, there forums would be a much better place if no one ever answered a question because there's always some Forum Nazi hanging around taking your answers out of context of the question and demanding that every answer you give be relevant to completely different questions just on the offchance that someone goes looking for answers in entirely the wrong place.

If you're that committed to answer unrelated questions that haven't been asked, you go and do all the research and testing needed to answer those unasked questions. Then add it all onto the bottom of any thread that bothers you with it's unproven information, and then maybe if anyone ever asks the right wrong question and finds the wrong answer to it he'll benefit from it. Until such time as a moderator asks me to do otherwise, I'm going to continue answering the question that's actually asked because I at least know that someone will actually benefit from that. I hope Mahan does the same.

You have totaly missed my point.

I so haven't. You can't argue with anything that Mahan said but you're criticising him for not doing a test to prove something he's already confirmed by years of just using it. Pedantic doesn't even begin to cover it.

This is a forum, not a physics exam. I don't see a "now show your working" section below the post content box.

Last edited 2011


skidracer(Posted 2011) [#20]
You so have. Establishing an urban myth that BlitzMax is give or take half the speed of C++ does nobody any favors what so ever.

Resorting to insults instead of polite discussion doesn't do you any favors either Gabriel.

Last edited 2011


Czar Flavius(Posted 2011) [#21]
I am sorry for behavior in this discussion. I have had a really bad day.

Last edited 2011


Mahan(Posted 2011) [#22]
Guys, this just escalated to dimensions I didn't neither want or expect.

I already admitted that my statement was based on my own "guesstimate", and I know very well that is no fact.

I'll even edit my post to reflect that.

While I understand your above concerns for not damaging the reputation of BMX I think some of this near rabid fanboi:ism is just as damaging for the reputation of the community.


Gabriel(Posted 2011) [#23]
Resorting to insults instead of polite discussion doesn't do you any favors either Gabriel.

I don't see what I said that's insulting. Czar Flavius opined that the forums would be a much better place if we behaved in a certain way and I replied that the forums would be full of Forum Nazis if we behaved that way. Disagree with it if you like, but I don't see anything insulting about it. I certainly didn't take it as an insult when I was told I was making meaningless, simplistic statements as that too is an opinion.

You so have. Establishing an urban myth that BlitzMax is give or take half the speed of C++ does nobody any favors what so ever.

Then correct it. All this "Don't answer a question unless - even if it's a perfect answer to the question asked - unless you're going to back it up with empirical evidence in case some part is taken literally" is just going to frighten people away from answering questions.

I know I'm seriously reconsidering it (since I did say that I would do so if asked by a moderator.)

Last edited 2011


Gabriel(Posted 2011) [#24]
I went off to email Czar Flavius, since he's presumably left the thread, but there's no email address in his profile, so I'll just post it here and hope he reads it.

Sorry you've had a really bad day, and sorry if I've added to it. I thought we were having a pretty robust discussion over forum etiquette but I didn't feel insulted by you, nor did I intend to insult you. Apparently Skidracer thinks otherwise, so if you also thought that, I can only apologize. I still believe that discouraging people from answering questions is to be avoided at all costs, and that inaccuracies or half-truths can easily be explained in more depths by others if they feel the original reply was unhelpful. I respect that you think differently.


Czar Flavius(Posted 2011) [#25]
Thank you for your apology. Friends? :)

Last edited 2011


Gabriel(Posted 2011) [#26]
Of course.


AdamRedwoods(Posted 2011) [#27]
I apologize in advance for this:

BlitzMax is fast. I did some image processing with it on several 1MB images and when compared to a "C" subroutine I made trying to squeeze out more speed, it turned out the difference between C and BMax was <1ms.

Now this was for basic loop processing and math. I think MOST languages, even interpreted ones, will be able to handle loops and math quickly.

With "pure C" I believe, at a minimum, you're doing your own garbage collection, which may indeed be faster in some occasions.


In my opinion, difference in speed comes from things such as garbage collecting, assigning global variables vs. registered variables, stack handling, CPU optimizations, etc. So many different aspects that nowadays, comparing languages solely for execution speed is a narrow perspective. If one needs more speed, the optimization might not be with the language but rather with the task itself.

Blitzmax is fast enough, but its true speed comes in human development time. (less computer dev = more family dev)

If you want to see Blitzmax struggle speedwise, check out my photon mapping ray tracer multi-thread example, and compare it to the original javascript version. Although again, the code could be optimized (hint: a single processor version is much faster).
http://blitzmax.com/Community/posts.php?topic=93169

Last edited 2011


Mahan(Posted 2011) [#28]
Hi guys. I've started a new thread for the C/C++ vs BMX speed discussion, in a more proper place than in this emulator thread: http://blitzmax.com/Community/posts.php?topic=93727

Also I wanted to add that I'm not angry/upset/etc. at anyone, and if somebody feels offended/angry/upset/etc. i apologize for this and kindly ask you to PM me so we can sort it out.