Until I have compiled the other executables from source, using binfmt+qemu is the
easiest way to run Malban's Pi5 release of Vide.

# basic binfmt setup
sudo apt-get install binfmt-support qemu-user-static
sudo dpkg -add-architecture amd64
sudo apt-get update
sudo apt-get upgrade

# added i386 to also allow running the binaries in Linux32
sudo dpkg -add-architecture i386
sudo apt-get update
sudo apt-get upgrade

# also tried this but didn't appear to entirely succeed. May not be needed,
# although it actually looks like x86_64 is being used by Linux64 rather than amd64
sudo dpkg -add-architecture x86-64
sudo apt-get update
sudo apt-get upgrade

sudo update-binfmts -display

# there's probably a better way to get these but I couldn't find it…

# this was needed to run all the 64-bit Intel binaries in Linux64. Obviously you can't copy these from my system but you should be able to find them elsewhere.
sudo mkdir -p /etc/qemu-binfmt/x86_64/lib64
sudo scp gtoal@192.168.2.251:/lib64/ld-2.27.so /etc/qemu-binfmt/x86_64/lib64/ld-linux-x86-64.so.2
sudo scp gtoal@192.168.2.251:/lib64/libc.so.6 /etc/qemu-binfmt/x86_64/lib64/libc.so.6

# and also i386
sudo mkdir -p /etc/qemu-binfmt/i386/lib
sudo scp gtoal@192.168.2.251:/lib/i386-linux-gnu/ld-2.27.so /etc/qemu-binfmt/i386/lib/ld-linux.so.2
sudo scp gtoal@192.168.2.251:/lib/i386-linux-gnu/libc-2.27.so /etc/qemu-binfmt/i386/lib/libc.so.6

# (I also installed this later but I don't think it was needed, unless maybe it would
#  have been the source of those missing libraries that I had already copied manually)
sudo apt-get install gcc-multilib-i686-linux-gnu gcc-i686-linux-gnu

I've built aslink, as6809, and the srec utilities from source (the sources are in this directory
- not sure which version of aslink is best to use) but haven't yet rebuilt cc1 for the pi5 environment -
a previous attempt at running the gcc 6809 cross-compiler is in /home/gtoal/gtoal.com/src/gcc6809
but I don't think that approach using wine was too smart, so I'm ignoring that previous project
for now. (It was for an unrelated (not Vectrex) 6809 board I built)
It *is* possible to run the windows cc1 under wine on a pi5 but you do need to add kernel=kernel8.img
to config.txt to fix a problem with 4K vs 16K vm pages.  It's much easier to just run the amd686
Linux compilation of cc1 under binfmt.  I haven't yet managed to rebuild gcc 6809 from source.

Vide creates a .cnt file but I believe does so from the java GUI code, so I've resurrected an
old make_cnt utility of Malban's (converted from old c++ to modern C) but I have no idea how to
invoke it or on which files!  I'll check with Malban when he returns from his trip...

btw a helpful utility to find out which files are being accessed behind the scenes when it isn't
obvious, is to use the fuse 'loggedfs' filesystem.  Info at https://github.com/rflament/loggedfs
and install with sudo apt-get install loggedfs


I added a couple of comments to my test main.c to remind me how to do some of the Emacs tweaks,
at least one of which (I think it might have been the clang-format support?) I had to install
from within emacs itself.  Also using rcs is a great way to backtrack to previous working version
when something breaks.  I'll bind the longer commands to a key soon...


// $Id: main.c,v 1.4 2025/06/20 20:39:02 vide Exp vide $

// Easiest to work in the project directory *above* the source/ directory containing this program.

// $Log: main.c,v $
// Revision 1.4  2025/06/20 20:39:02  vide
// *** empty log message ***
//
// Revision 1.3  2025/06/20 20:37:01  vide
// added comments with Emacs hints...
//
// Revision 1.2  2025/06/20 20:28:09  vide
// simplified.  RCS headers added.

// Emacs help:
// ^c u   to reformat all,  ^c i   to indent a block highlighted using F1.
// M-x compile <cr> cd .. && make -k<cr>   to build
// ^u M-| command <cr>   to pipe a region through a unix filter

#include <vectrex.h>

int main(void) {
  for (;;) {
    Wait_Recal();
    Print_Str_d(0, -70, "HELLO WORLD\x80");
  }
  return 0;
}


However, as well as having the full GUI Vide experience on the Pi5, it's rather nice
to also be able to work from within Emacs and build using make...

This is the example Makefile I'm using in the 'newproj' directory:

# Makefile for a 'Peer C' project
VIDEROOT=/home/vide/Vide.RPI5/
VLIB=$(VIDEROOT)C/PeerC/vectrex/lib/static
PROJECT=newproj
P_VERSION=1.0
ARGS=-quiet \
       -fno-tree-vrp -fno-ipa-reference -ftree-ter -fno-gcse -fverbose-asm \
       -W -Wall -Wextra -Wconversion -Werror \
       -fno-strict-overflow -fomit-frame-pointer -fno-toplevel-reorder \
       -mint8 -msoft-reg-count=0 -std=gnu99 -fno-time-report \
       -I$(VIDEROOT)C/PeerC/vectrex/include \
       -DP_VERSION_80="$(P_VERSION)\x80" -DP_VERSION_0="$(P_VERSION)" \
       -D__RUM_FUNCTION=1 \
       -DOMMIT_FRAMEPOINTER=1 -DOMIT_FRAMEPOINTER=1 \
       -Iinclude
LIBS=-l rum.lib -l libgcc.lib -l gcc.lib -l assert.lib
CC1=$(VIDEROOT)C/Linux64/bin/cc1
AS6809=$(VIDEROOT)C/Linux64/bin/as6809
ASLINK=$(VIDEROOT)C/Linux64/bin/aslink
SREC2BIN=$(VIDEROOT)C/Linux64/bin/srec2bin
OBJLIBS=$(VLIB)/vec_rum_0xe7.rel \
       $(VLIB)/vec_ram_0xc8_2.rel \
       $(VLIB)/vec_rom_0xfc_0.rel \
       $(VLIB)/vec_rom_dped_0.rel \
       $(VLIB)/vec_rum_0xf0.rel \
       $(VLIB)/vec_rom_0xfe_0.rel \
       $(VLIB)/vec_rum_0xf5.rel \
       $(VLIB)/vec_ram_dpcb_1.rel \
       $(VLIB)/vec_rom_dpfd_0.rel \
       $(VLIB)/vec_ram_dpc8_2.rel \
       $(VLIB)/vec_ram_0xc8_0.rel \
       $(VLIB)/vec_ram_dpd0_1.rel \
       $(VLIB)/vec_rum_0xf1.rel \
       $(VLIB)/vec_rum_0xf4.rel \
       $(VLIB)/vec_rum_0xe9.rel \
       $(VLIB)/vec_ram_0xd0_1.rel \
       $(VLIB)/vec_rum_0xf9.rel \
       $(VLIB)/vec_rom_dpff_0.rel \
       $(VLIB)/vec_ram_0xcb_3.rel \
       $(VLIB)/vec_ram_dpc8_1.rel \
       $(VLIB)/vec_rom_dpfe_0.rel \
       $(VLIB)/vec_ram_dpc8_0.rel \
       $(VLIB)/vec_rom_0xed_0.rel \
       $(VLIB)/vec_ram_dpcb_2.rel \
       $(VLIB)/vec_rum_0xff.rel \
       $(VLIB)/vec_rum_0xf8.rel \
       $(VLIB)/vec_rum_0xf2.rel \
       $(VLIB)/vec_ram_dpcb_0.rel \
       $(VLIB)/vec_rum_0xf7.rel \
       $(VLIB)/vec_ram_0xcb_0.rel \
       $(VLIB)/vec_ram_0xc8_1.rel \
       $(VLIB)/vec_rum_0xf3.rel \
       $(VLIB)/vec_rom_0xff_0.rel \
       $(VLIB)/vec_rum_0xf6.rel \
       $(VLIB)/vec_ram_0xcb_1.rel \
       $(VLIB)/vec_ram_dpcb_3.rel \
       $(VLIB)/vec_ram_0xcb_2.rel \
       $(VLIB)/vec_ram_0xd0_0.rel \
       $(VLIB)/vec_rom_0xfd_0.rel \
       $(VLIB)/vec_ram_dpd0_0.rel \
       $(VLIB)/vec_rom_dpfe_1.rel \
       $(VLIB)/vec_rum_0xea.rel \
       $(VLIB)/vec_rom_0xfe_1.rel \
       $(VLIB)/vec_rom_dpfc_0.rel

all: bin/$(PROJECT)_$(P_VERSION).bin
	echo All up to date.

build/lib/main.i: source/main.c
	$(CC1) $(ARGS) -E source/main.c -o build/lib/main.i

build/lib/cartridge.i: source/cartridge.c
	$(CC1) $(ARGS) -E source/cartridge.c -o build/lib/cartridge.i

build/lib/main.s: build/lib/main.i
	$(CC1) $(ARGS) source/main.c -o build/lib/main.s

build/lib/cartridge.s: build/lib/cartridge.i
	$(CC1) $(ARGS) source/cartridge.c -o build/lib/cartridge.s

build/lib/main.rel: build/lib/main.s
	$(AS6809) -x -p -l -o -y -g build/lib/main.rel build/lib/main.s

build/lib/cartridge.rel: build/lib/cartridge.s
	$(AS6809) -x -p -l -o -y -g build/lib/cartridge.rel build/lib/cartridge.s

build/$(PROJECT).s19: build/lib/main.rel build/lib/cartridge.rel $(VIDEROOT)C/PeerC/vectrex/lib/crt0.rel $(OBJLIBS)
	$(ASLINK) -n -m -u -w -s -k $(VIDEROOT)C/PeerC/vectrex/lib/ $(LIBS) build/$(PROJECT).s19 $(VIDEROOT)C/PeerC/vectrex/lib/crt0.rel build/lib/main.rel build/lib/cartridge.rel $(OBJLIBS)

build/$(PROJECT)_rom.bin: build/$(PROJECT).s19
	$(SREC2BIN) -q build/$(PROJECT)_rom.s19 build/$(PROJECT)_rom.bin # also creates build/$(PROJECT)_rom.s19

bin/$(PROJECT)_$(P_VERSION).bin: build/$(PROJECT)_rom.bin
	cp build/$(PROJECT)_rom.bin bin/$(PROJECT)_$(P_VERSION).bin # not sure where bin/$(PROJECT)_$(P_VERSION).cnt comes from

clean:
	rm -f build/lib/*.??? build/lib/*.? build/*.??? build/*.? bin/*.???
