Skip to content

Instantly share code, notes, and snippets.

@rivy
Forked from DavidEGrayson/README.md
Last active May 21, 2018 17:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rivy/b5e328cbd7b9e871ffdb8f255f0ea285 to your computer and use it in GitHub Desktop.
Save rivy/b5e328cbd7b9e871ffdb8f255f0ea285 to your computer and use it in GitHub Desktop.
Getting started with midipix
#!/bin/sh
set -ue
BASEDIR="$HOME/midipix_src"
DESTDIR1="$HOME/midipix/native"
DESTDIR2="$HOME/midipix/x86_64-nt64-midipix"
for proj in psxtypes; do
git -C "$BASEDIR/$proj" pull origin main
make -C "$BASEDIR/$proj" DESTDIR="$DESTDIR1" install
make -C "$BASEDIR/$proj" DESTDIR="$DESTDIR2" install
done
for proj in dalist pemagine ntapi ntcon ntctty psxscl; do
git -C "$BASEDIR/$proj" pull origin main
rm -rf "$BASEDIR/build-$proj"
mkdir -p "$BASEDIR/build-$proj"
pushd "$BASEDIR/build-$proj"
"$BASEDIR/$proj/configure" --debug --host=x86_64-nt64-midipix
make DESTDIR="$DESTDIR1" install
make DESTDIR="$DESTDIR2" install
popd
done

Getting started with midipix

Let's compile midipix from source and play with it!

  1. Get access to a Linux machine for development.

  2. Install git and gcc on the development machine.

  3. Make the directory ~/midipix_src for holding source code, and navigate to it.

  4. Build the cross-compiler with the following command. This could take a while. It produces build files in ~/temp and puts the compiler files in ~/midipix.

    git clone git://midipix.org/cbb/cbb-gcc && cd cbb-gcc && ./cbb-midipix-cross-gcc.sh
    
  5. Get the cross-compiler on your PATH:

    export PATH=$PATH:~/midipix/bin
    
  6. We now have a working cross-compiler, but it can't do much because we don't have the runtime libraries that the compiled programs need.

  7. See the website midipix.org for information about how to get read access to the latest internal/private git repositories. The publicly-available git repos that you can find easily on the site might be too old and not work for you. Then get the source code for the runtime libraries by running the following multi-line command in your shell from the ~/midipix_src directory. You will need to replace $midipix_internal with something.

    for repo in psxtypes pemagine dalist ntapi ntcon ntctty psxscl; do
      git clone git://midipix.org/$midipix_internal/$repo
    done
    
  8. Copy build.sh from this gist into ~/midipix_src. Run it to update the projects, build them, and install them into the cross-compiler toolchain.

  9. In some new directory, create a file named test.c with a simple "hello world" program:

    #include <stdio.h>
    
    int main()
    {
      printf("hello world\n");
      return 0;
    }
    
  10. Compile the program by running the following command. You should probably wrap it in a Makefile so you don't have to type it every time.

    x86_64-nt64-midipix-gcc test.c -o test.exe
    
  11. Copy test.exe to a Windows machine. (Actually I do my compilation inside a VirtualBox shared folder that is accessible to both the Linux virtual machine and the Windows host machine so I don't need to bother.)

  12. Copy all the shared object (*.so) files from ~/midipix/x86_64-nt64-midipix/lib/ to the Windows machine as well, and put them in the same directory as test.exe so they can be found. (Though for this particular example you should only need libc.so and libpsxscl.so.)

  13. Run .\test.exe on the Windows machine! If you have MSYS2 installed, I recommend running it from a MinTTY bash shell. If you don't have MSYS2 installed, you can run it from a normal Command Prompt, but beware that you won't actually see the program print anything in the Command Prompt. This is not a bug. To get output from the program, pipe its output to a file using a command like .\test.exe > output.txt or run it in mintty.

Thanks to the midipix project author for helping me with these instructions.

  • TODO: figure out how to debug with gdb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment