Today on Facebook Vectrex Fans Unite one thing led to another and Bob Alexander offered the source code to his Vectrex32 (link: https://vectrex32.com/) BASIC, so it can be ported to be used on a PiTrex. I jumped onto that wagon and about 1/2 later I had a 2.5MB zip file waiting in my mailbox.
In the following blog entries (only if I succeed!) I will describe my road to success (hopefully not to bumpy, and hopyfully successfull at all 🙂 ).
I’ll stop my other PiTrex activities for now (most of the time). The last thing I was doing was to port the MAME Z80 emulator to AAE. It seems the “old” C-sources of Neil are still a bit buggy and I figured getting his sources to emulate 100% will be more effort than to get a well proven emulator to run.
(Neils assembler core runs very well, but I guess the C version was never really THAT well tested – everyone was working with x86 cpu’s so everyone used those). I also don’t really believe anymore, that my C-sources are “old” (yea sure, nearly 20 years…). In the depth of the web I found version 3.4 of his MakeZ80 sources, which produces ASM code AND C code. That version was used with most emulators at those days, and I am pretty sure these are the ones also used in AAE – only that the C version is buggy.
Anyway, I have gotten the Z80 sources of MAME, I can compile them without errors and warnings (without MAME). The only thing left is to adept the differently names “interfaces” – shouldn’t take me longer than a day or two… but here comes … BASIC!!!
My first look at the code – and I was already sorry I said I would start the port. The source code is written in c++. While I love coding in Java, I learned to appreciate C and am forced at work to write code in c# – I must admit my c++ days are over. Over the years I learned to dislike it. Oh, well, it can’t be helped.
Two options:
a) convert the BASIC interpreter to “C”
b) start making the PiTrex more open to C++, and to not “totally” convert Bobs sources
I guess I will take route “b”, hopefully a few “#ifdef __cplusplus” will get me going. After all “circle” is all done in c++, it must be possible than.
BTW – I still am doing baremetal – I will try to not obfuscate my final conversion to much, so that it should be able to run under raspbian as well – but I make no promises.
So… my first task for today is, not to look at Bobs code at all, but to create a makefile, which compiles the most simple c++ program and lets it run on my PiTrex.
Two files, a “starter”, which includes the initializing:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | #include <cstdlib> #ifdef __cplusplus extern "C" { #endif #include <vectrex/vectrexInterface.h> #ifdef __cplusplus } #endif #include "test.h" int main (void) { vectrexinit(1); v_init(); v_noSound(); v_setRefresh(50); v_setClientHz(50); v_setupIRQHandling(); v_enableJoystickAnalog(1,1,0,0); v_enableSoundOut(1); v_enableButtons(1); HelloWorld hello; hello.run(); } |
And a “class” file, which prints “hello world”:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | #include "test.h" #ifdef __cplusplus extern "C" { #endif #include <vectrex/vectrexInterface.h> #ifdef __cplusplus } #endif HelloWorld::HelloWorld (void) { this->m_message = "HELLO WORLD"; } HelloWorld::~HelloWorld (void) { } void HelloWorld::run() { while (1) { v_WaitRecal(); v_setBrightness(60); v_printString(-10,0, (char *) m_message.c_str(), 7, 64); } } |
Yeah, I know – it does not look very cplusplusee. But that does not really matter, the syntax is there, and the files have an extension of cpp and the compiler “thinks” it is c++ :-).
Actually I had to change some small “code” in the “vectrexInterface.h”, which seemingly was non c++ conform.
In the “main” class, I had to manually add the “#include <cstdlib>” (and before the vectrexInterface.h) – otherwise strange “redefinition” errors occured. But I had similar problems, when starting in “C”.
This has to do with the way I constructed my osWrapper – things.
It seems c++ needs a “_kill” and a “_getpid” reference, I added these to the cstub. But after that everything went on smoothly.
Anyways, together with “finding” the correct Makefile, this took me about 1 1/2 hours. It displays gloriously:
Actually the Makefile didn’t change to much:

… to be continued …