Baremetal PiTrex


Changelog:

23rd of May 2025
- changes of the last 4 years (Phu - probably not all), more or less a copy/paste of the blog age entry.

- added VTerm, a communication from MAME with PiTrex over serial cable (912000 baud).
  more documentation needs to be added, in case I forget, see: https://www.youtube.com/watch?v=yAPHGBM2sQ8

Lunar lander made "better", optimized etc. to many small steps to mention all
I got the (very basic) SBT version in VecSim to run – but it makes no real difference speed-wise.
So for the moment, I’m not pursuing it further – and I’m also not currently willing to invest more time into the SBT code generation.
But I know Graham has an ongoing project in that regard, so – who knows what will be next?

Instruction:

Button #4 + #1
Enter Dip Switch Settings
Button #4 + #2
Self Test mode (not available)
Button #4 + #3
“Slam”
Button #4
Left coin
Button #3
Right coin
Button #2
Start and Abort
Button #1
Start
X-Axis
Rotate
Y-Axis
Propulsion

Changes 0
Added “native” Vectrex support for 256kB ROMs
Nice—but somehow the original Vectorblade is not working anymore (new compiles do).
It has to do with the way I handle “flash support.”
“piserial” tool (Linux/Windows) added
can be used to access pi from a unix envirnoment via serial connection.
limited terminal usage. Copy of files and reset/reboot/to loader commands are available
no need for SD swapping anymore). Of cause, a serial interface is needed.
the PiTrex Vectrex now supports 3d Imager games, now the “native” library should work completly… lightpen, normal games and 3d-Imager
a couple of bugfixed were also done… the last release had some “weirdness” e.g. display and input  of cleansweep – and some other carts… did not test enough.
directory support for the VectrexExact menu entry. Yes – you can now browse and change directories (within the “vectrex” directory).
also entries are now sorted alphabetically / directories first

Vide and PiTRex can now "connect", Vide has a terminal mode, in which a vectrexexact emulation can be used on the PiTrex.

minal mode is full “duplex.” PiTrex outputs its serial messages to this terminal—but you can also control the PiTrex via commands (type “h” for help).

The disk icon allows you to upload (any) Vectrex BIN to the PiTrex and run it.
The “Reset-Button” well… it resets your Vectrex.

The “Dev”-beauty of the PiTrex solution is (what some people see as a weakness) that the Pi emulates the Vectrex rather than playing on the real Vectrex.

In this case, I say this is great!
A little reminder… the emulation on the PiTrex only emulates the CPU. All analog things, all VIA, all DAC, and everything else are original and use the original hardware. What you see on a PiTrex-setup is REAL Vectrex.
Only the CPU is emulated. The 6809 CPU is by now really well-known and is emulated very well!
(I never cared about adding undocumented features, though.)

That is the reason why, in nearly all aspects, the emulation of the PiTrex of the Vectrex comes to be very, VERY close to the original.

Emulating the CPU, rather than running on the native 6809 CPU of the Vectrex, allows us to have much more control than other devices.
If your Vectrex crashes while in your own developed program—you can just reset it! You don’t have to switch it off/on.
If you want to load another program—you just do, no need to go back to some menu.
Everything is smooth and direct.
Also (but I have not integrated it yet), it allows you debug methods not possible otherwise:

You can dump your CPU state to Vide.
You can access registers in real-time.
You can set breakpoints on the “real” Vectrex.
You can download (and upload) the complete RAM and register states.

From the Debugger in Vide you can “dump” the currently bin to PiTrex – while running.
Just type “tp” (ToPiTrex) – and the bin will run on the PiTrex (actuall there also is a tf “toFever” command…)

The Vide Editor:


Features a “PiTrex” checkbox – when checked each run program of yours – will after a compile directly run on a PiTrex (no need to press a reset button – or go back to some menu).

When you want to look at your own vector drawings – how they look on a real vectrex:


check the checkbox for PiTrex – and the vectorlist will be displayed on the PiTrex!

Once configured – the PiTrex will “autoconnect”…



CHANGES 1
For a fellow Vectrexer, I slightly changed the Vectrex-Exact emulation for PiTrex.
If your text appeared “screwed up” in the past, you may try a new option in the vectrex.ini file:

INTERNAL_STRING_DISPLAY = 1
This will draw all BIOS strings using the PiTrex drawing routines – which is more cycle-exact than using the original Vectrex BIOS.

Other changes:

Support for 48kB cartridges
Support for autostart of .bin files
Corrected the startup sequence, so vectrexexact.img can be used correctly as a boot file
See also the vectrex.ini file.

Funny anecdote:
When booting directly into VectrexExact without supplying a boot cartridge file, it goes to a little ROM selection menu within the “Vectrex”.
I programmed that years ago and had totally forgotten about it… but it still works!

For any programmers/debuggers out there:
Internally, I changed the serial speed from 115200 to 921600. So, if you use an old loader with a new Vectrex image, you’ll need to switch your terminal program to the new speed.

CHANGES 2
Posted to the PiTrex Dev mailing list:

I built a package with a new option in vectrexInterface.ini:

SWAP_JOYSTICK_PORTS = 1
If set to 1, joystick ports 1 and 2 are swapped. This should work with all PiTrex, Arcade, and other programs.
With the Vectrex emulators, it only works if programs use BIOS functions. Vectrex programs that access the hardware directly via the VIA (and not the BIOS) will still try to access port 1 (e.g., Hyperchase, Vectorblade, Frogger, Release, etc.).

Other changes (since December 2021):

Added native Vectrex support for 256kB ROMs – nice!
(Though the original Vectorblade is no longer working. New compiles are fine. The issue lies in how I handle flash support.)
The PiTrex Vectrex now supports 3D Imager games. The native Vectrex library should now fully support light pen, normal games, and 3D Imager functionality.
A couple of bugfixes were also applied.
The last release had some weird behavior – e.g., display/input issues with Clean Sweep and a few other carts… I hadn’t tested enough.
Directory support added to the VectrexExact menu.
Yes – you can now browse and change directories (within the “vectrex” folder). Entries are now sorted alphabetically, with directories listed first.
Battlezone now includes two new joystick configurations: Stramash (Port 1 / 2)
Vide interface added (to be documented / video to come). See the Vide blog entry “Two Years Gone By…” for a preview.
I will create extra documentation for these changes! (Blog-title image is a hint for that.)
Brightness settings (min, max, mul) can now be adjusted in vectrexInterface.ini.
Default setting for IN_GAME_SETTINGS is now 0. It currently crashes when set to 1.
CHANGES 3
INI files are now saved whenever you exit the in-game settings.
Settings are saved to the last loaded INI file.

INI files are always loaded in this order (if found):

vectrexInterface.ini
Emulator-specific INI (e.g., vectrex.ini, sim.ini)
Game-specific INI (e.g., starwars.ini)
The most recently loaded settings are the active ones.

You can prevent overwriting your INI file by setting:

INI_OVERWRITE_ALLOWED = 0
(this is the default.)
If you set it to 1, overwriting is allowed.

If overwriting is forbidden, the file will be saved using the same name but with the extension .in2 instead of .ini.
That way, changes are preserved, but old options won’t be overwritten, and the new settings won’t load automatically.




21th of December 2021
- some days ago, fixed bankswitching in vectrex emulator for 64k 
- added options to invert joystick y-direction (common ini)
  (each individual ini file can now have the option (INVERT_Y_AXIS = 1/0)
- added "analog" scroll for vectrex exact selection of files
- added VOOM
- added lineArt demo!
- added Rebel Defender (no sound)
- thought about adding: icbm3d, xinv3d, xlander
  but these are not my kind of games, I don't like them, unless someone "begs" to add them
  I leave them be, sources can be found under "new.not_done"


14th of December 2021
    added support for PiZero2
	changed menu system to only display "machines" not different emulators
	added quite a few icons
	added Star Wars SBT version, with also added performance tuning and first sounds
	added BattleZone 2 (beta) (Peter Hirschberg) not optimized yet and without sound, this is another c++ program easily ported to baremetal!
	added WW Vi (beta), sounds are only played via samples, using for the first time the vectrex library's mixing feature. Sound terrible!
	added for Warrior and Armor Attack virtual overlays
	source code started restructuring - the bare metal part, to get rid of the different GPIO/BCM access functions
	due to support for PiZero2 all images are now TWICE on the SD card - in subdirectories PiZero1 and PiZero2
	booting should work out of the box with both Pi's (copy the COMPLETE files, you need the newest "start.elf, fixup.dat and bootcode.bin"
	

15th of June 2021
As many changes as I remember…
    z80 emulation is now working in AAE
    68000 emulation is now working in AAE
    except (I think) two games all of the original AAE games are now working, loadable and sometimes playable
    sound and beautifying was NOT done
    “general” input methods were implemented (input.c) – if the emulators support these, than they can be played, in general:
    START 1 = joystick 1 button 1+2 at the same time
    START 2 = joystick 2 button 1+2 at the same time
    COIN 1 = joystick 1 button 3+4 at the same time
    COIN 2 = joystick 2 button 3+4 at the same time
    player 1 buttons 1-4 = joystick 1 button 1-4
    player 2 buttons 1-4 = joystick 2 button 1-4
    player 1 digital UP/DOWN/LEFT RIGHT = joystick 1
    player 2 digital UP/DOWN/LEFT RIGHT = joystick 2
    player 1 analog UP/DOWN/LEFT RIGHT = joystick 1
    player 2 analog UP/DOWN/LEFT RIGHT = joystick 2
    Asteroids (SBT) two player mode fixed (the emulation did not support the RAMSWP flag), also the explosions now differ slightly
    Elite (a new kind) is in beta state.
    It should be completely playable (except bugs). To play one NEEDS a keyboard attached to the PiTrex.
    The game is fully controllable via keyboard, but steering/shooting can also be done via joystick 1.
    The keyboard layout is as described in “elite_readme.txt”.
    I have not tested the complete game, as it contains MANY faccets – feedback/reports welcome.
    The game could use some overlay, since not all screen elements are self explanatory in the vectrex version.

    Left side:
    FS: Front shield
    AS: Aft shield
    FU: Fuel
    CT: Cabin temperature
    LT: Laser Temperature
    AL: Altitude
    Missiles (up to 4), green, yellow, red

    Right side:
    SP: Speed
    RL: Roll
    DC: Climb
    1: Energy banks 1
    2: Energy banks 2
    3: Energy banks 3
    4: Energy banks 4
    E – ECM active
    S – Station (is in range)

    Internal changes/additions to the vectrexInterface.
    – a new “widget” Itemlist, Elite now uses this quite a lot (inspired by Thomas…)
    It seems to be a “bad” idea to configure USB keyboard twice in the same program, therefore keyboard support in the “loader” has been disabled.
    I started supporting bi-directional strings, this is theoretically working, but I do not use them, and would like to keep it that way, 
	they always seem to “fork” near the edges – and I can’t get rid of it. There are 4 new configuration items in the settings, 
	but since I don’t use this – these are also useless :-).

7th of May 2021
    added GS BASIC (https://vectrex32.com/)
    BASIC starts in the directory “/basic” – since no directory changes can be done from BASIC, this is the BASIC “home”
    gsbasic.ini for some “option”, more information in the file:
    GS_BASIC.txtm OtherTitle.txt VXTRON.txt
    GS BASIC Copyright (c) 2021 Robert E. Alexander
    Usage and distribution is granted under the MIT licence, see MIT_licence.txt
    THX! Bob!
    also included (amongst others) is VxTRON
    VxTron32 (c) 2020, Jaymz Julian
    in s slightly modified version
    added support of USB keyboards (see source code distribution: usb_readme.txt)
    I started the USB keyboard thing, because I wanted to control “Elite a new Kind” via keyboard, rather than invent tricky button double/tripple usages.
    “Elite a new Kind” is as of now only included as a “demo” version (start screen), since GS BASIC came along an stole my time 🙂 – 
	actually the whole game is compiled, but I haven’t configured the keyboard in, and didn’t look at/fix any of the non vector gfx yet
    I started porting the MAME z80 processor emulation to be used in AAE, it compiles now without flaws, but I have as yet not changed 
	the API to fit AAE. Once I have done, almost all SEGA games should work.
    I am also thinking about (as a quick hack) to add USB keyboard to AAE, than the default key mapping
    settings should work for all games out of the box, and they would be playable via keyboard – not optimal, but better than “waiting” 
	to manually configuring each and every game to the vectrex controls
    Asteroids (sbt) can now in the ini file be configured to use/not use samples
    during the above changes… some bugs were discovered and fixed in the vectrexInterface, can’t remember them all
    osWrapper.c is “wrappier” than before 🙂 e.g. if keyboard is configured you can use fgetc() to “wait” for keyboard input, 
	also added a “good”malloc() implementation, but as of now I am not using it. I rely on the stdlib, after implementing a rudimentary sbrk(). 
	C++ new() and delete() should that way work also ok.
    vectrexInterface can be configured to use two sample channels, these will be mixed. Default this is “off” – but it DOES work!
    started looking at bitmaps again, one of the next things will be to add bitmap output to the IRQMode (as of now, this os not yet supported)
    changed the “structure” of the baremetal directories, vectrexInterface (and others) are now build as libraries, not several object files. 
	All Makefiles were changed (slightly) GS BASIC is written in c++, thus c++ is now supported to be built.
    As an example look at GS BASIC. For now, the global/static constructors must be called “manually” in the main() function (6 lines of code), 
	if you intend to program c++, these lines must be copied!
    also implemented the afore mentioned “persitent vectors”, but as of now they are configured “out”. With GS BASIC I could not use them afterall. 
	These are not completely debugged, so I am not sure that they work under all circumstances.
    added emulation of the TMS5220 to sample out (Star Wars), although since star wars is to slow, the output is rather choppy

12th of April 2021
    added the possibilty to play samples alongside vectordisplay
    (digitized sound will be barely audiable on noBuzz vectrex – there is nothing I can do about it!)
    added for asteroids 2 samples (explosions)
    tweaked battlezone, for “english” settings output might be smoother than before (other languages not supported yet)
    added “1 joystick mode” for battlezone, this is the new default
    for battlezone added dipswitches
    for battlezone highscore saving/loading added
    added sound to battlezone (except the engine sound)
    added the start of AAE emulation the aae emulator can be access from the menu (last arcade emulator)
    then you can chose which game to “play”
    loadable and with “input”: Star Wars (6809) and Major Havoc (6502), but I have not really tried optimizing them – and one can see that!
    Cinematronics games (ccpu) are loadable as well, but I have not configured input
    I forgott to switch IRQ mode on for the AAE emulator, so if configured right, there would be a probably more than 20% speed increase
    I am still waiting on feedback in relation to the Z80 CPU. Once I get a working copy, probably all SEGA games can be supported as well.
    AAE roms are not included – and I don’t know what version you need, but “clues” can be found in the readme in the ROM directory
    many tweaks to the vectrexInterface…

26th of March 2021
    default calibration is back to zero, on the todo list -> calibration for noBuzz vectrex
    added configuration (ini file) for input settings, as of now asteroids only, look at the ini file
    added dipswitch settings (ini file), as of now asteroids only, look at ini file, in game these can be called with button 1+4 on joypad 1
    fixed asteroids output to accomodate the 4 different languages
    fixed a “calibration 0” bug with in the vectrex library, y pos could be always “0” after calibration (visible with asteroids shots)
    fixed “speedy vectrex” raster output
    added ini setting “IN_GAME_SETTINGS” which enables or disables Button 2 of Joypad 2 to invoke settings menu. Per default this is OFF
    vectrex save state, if enabled (ini setting HANDLE_STATES), it asks you whether to save or not, also shows a “SAVING…”.
    Saving seems to take sometimes up to 18 seconds (with my SD cart, less than a second…)


24th of March 2021
    IRQ mode implemented, vectrex output about 20% faster
    if you are a PiTrex baremetal programmer, contact me, to get notified of changes you have to be aware of!
    game update frequency is disjunct from the vectrex display frequency
    asteroids now has a “hyperjump” button
    asteroids saves / loads highscores
    XSH delay is now correctly implemented, that should “correct” the last seen screen garbles on some vectrex

15th of March 2021
    removed all settings files
    removed all “old” ini files
    the “main” ini file is now vectrexInterface.ini
    Settings can be changed from the menu, if reached via the menu, the settings will be saved to sd drive
    settings “in game” can be called by pressing button 2 of joystick 2, these will be active but not saved (yet)
    games/ emulators can still have own ini files, but I did not create default ones
    all games/emulators have now sensible default values to start with
    Settings are now applied in following order
    a) Settings from vectrexInterface.ini
    b) default settings inside the emulator
    c) Settings from the emulator specific ini file
    Navigation within the “settings”:
    Joystick port one:
    UP/DOWN – change configuration item
    LEFT/RIGHT – change the settings for the current item
    Button 1 – show help for the current selected item
    Button 2 – change the shown vector list
    Button 4 – exit (and save)
    Button 2+3 together – reset current configuration item to default settings
    Button 3+Joystick – move vector list
    Button 2+Joystick LEFT/RIGHT – change settings value in larger steps
    vectorblade bugfix (emulation, not vector blade)
    added config to battle zone (see battlezone.ini)
    corrected after “calibration” weirdness
    corrected “after dot move”
    added config to leave dots in there list position
    added clipping to some emulators
    changed the intro + “bouncing PiTrex”

11th of March 2021
    added additional logging on save state of vectrex – pls test that again and send me the output
    additionally on vectrex Joypad 2- button 1 saves the state, Button 4 loads the state.
    Does this also crash? – Pls report back!
    the pipeline “timing” in vectrex interface was changed from using the pi TIMER to using the pi cycle timer, which is much more exact (100 times!). Thus internally seemingly a lot changed!
    I spent much time with improving asteroids.
    The display should be much more stable. The Asteroids should move much smoother!
    The display should not shake or wobble (as much) when a UFO appears, bright shots are fired or the “PUSH START” appears. Still left to do: speed up (so the game over text appears flicker free), save highscores.
    This – although it cannot really be seen – proved to be not really “simple” – but this also layed the ground work for improving other emulators. We now have the ability to identify vector clusters and react to them “outside” of the emulation. As a showcase for that, you can configure in the ini file whether you want to see the atari copyright in game or not.
    added the before only on raspbian available game “ZBLAST”, including high score save, sound and background music. The music was given to me by Roald Strauss, who also has a website (IndieGameMusic.com), where he offers free – and royalty based – music scores of different kinds. From chip tunes and mod files to MP3. Thank you!
    added the before only on raspbian available game “Hyperoids”, including sound.
    both additions would not have been possible without the vectrexInterface / svgalib interface programmed by Kevin Koster. Using his base it was a matter of a couple of hours to support these two games.
    added several “icons” to the menu.

02nd of March 2021
    I have completed the dumb/stupid/boring task, to change ALL needed arcade emulation roms to MAME compatible roms (I tested loading with MAME roms 201 and 229, so “everything” newer than 2 years old should work)
    also supported are ZIP files, thus – just copying MAME roms to the “roms” folder is enough to get started with arcade emulations
    This means to run arcade emulation, you MUST provide new zip/rom files!
    I have added all “current” emulators that appear to at least run a little bit. I have not found many “cinematronics” emulations that run really well.
    best is probably tailgunner, starhawk, barrier…
    also added all “sim” emulators most of them boot up and are actually playable – although without sound
    I am astonished, that the “sim” asteroids emulation actually crashes after a while… there must still be something wrong in the 6502 emulation core… (the roms are identical to to sbt version)
    “icons” for those are missing… I have to get some more podcast to star drawing again… this will be put off for a time
    all emulators support now “ini” files, these can also be specific for each emulated rom
    I added a new option to the ini file “LOG_OUTPUT=1; if different than 0 – than log all “printf” outputs also to SD”, once you can test the new version and the
    screen still goes black upon returning – I hope the captured output can help me identify the problem 
    for the “atari”/sim emulators I added “sensible” ini files


----


