Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,31 @@ link.exe /nologo /SUBSYSTEM:EFI_APPLICATION /ENTRY:EFI_MAIN /MACHINE:X64 space.o
The compiled BOOTX64.EFI program must be placed in the EFI/BOOT/ directory of an EFI partition on a disk using a GPT. <br>
The program can be run by entering the firmware settings, turning off secure boot, and selecting the disk as the device to boot from.

## Building on Linux

### Prerequisites
Install the required tools:
```bash
sudo apt-get install asmc-linux qemu-system-x86 ovmf dosfstools
```

### Build
Build the game and create an ESP disk image:
```bash
sudo ./build.sh
```

### Run in QEMU
Launch the game in QEMU with UEFI:
```bash
./run_qemu.sh
```

The game should boot automatically. If you see the UEFI Shell instead, type:
```
FS0:
\EFI\BOOT\BOOTX64.efi
```

## Built in Options
### Hardware upscaling
Expand Down
64 changes: 64 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/bin/bash

# Build script for Space Game x64 on Linux
# Requires: asmc-linux, binutils, dosfstools

set -e

# Test for root privileges (needed for mounting)
if [ "$EUID" -ne 0 ]; then
echo "Please run as root (sudo ./build.sh)"
exit 1
fi

echo "=== Building Space Game x64 for UEFI ==="

# Check for required tools
echo "Checking for required tools..."
command -v asmc >/dev/null 2>&1 || { echo "asmc not found. Install with: apt-get install asmc-linux"; exit 1; }
command -v ld >/dev/null 2>&1 || { echo "ld not found. Install with: apt-get install binutils"; exit 1; }
command -v mkfs.vfat >/dev/null 2>&1 || command -v /sbin/mkfs.vfat >/dev/null 2>&1 || { echo "mkfs.vfat not found. Install with: apt-get install dosfstools"; exit 1; }

# Clean previous builds
echo "Cleaning previous builds..."
rm -f space.o BOOTX64.efi esp.img

# Assemble
echo "Assembling space.s..."
asmc -win64 space.s -c -Fo space.o
if [ ! -f space.o ]; then
echo "Assembly failed!"
exit 1
fi

# Link as UEFI PE executable
echo "Linking as UEFI executable..."
ld -m i386pep --oformat=pei-x86-64 --subsystem=10 -e EFI_MAIN space.o -o BOOTX64.efi
if [ ! -f BOOTX64.efi ]; then
echo "Linking failed!"
exit 1
fi

# Create ESP disk image
echo "Creating ESP disk image..."
dd if=/dev/zero of=esp.img bs=1M count=100 status=none
/sbin/mkfs.vfat -F 32 esp.img >/dev/null 2>&1 || mkfs.vfat -F 32 esp.img >/dev/null 2>&1

# Mount and copy files
echo "Mounting ESP image and copying files..."
mkdir -p esp_mount
mount -o loop esp.img esp_mount
mkdir -p esp_mount/EFI/BOOT
cp BOOTX64.efi esp_mount/EFI/BOOT/
sync
umount esp_mount
rmdir esp_mount

# Fix permissions so user can run QEMU without sudo
chmod 644 esp.img
chown $SUDO_USER:$SUDO_USER esp.img BOOTX64.efi 2>/dev/null || true

echo "=== Build complete! ==="
echo "ESP image created: esp.img"
echo "EFI executable: BOOTX64.efi"
echo "Run with: ./run_qemu.sh"
42 changes: 42 additions & 0 deletions run_qemu.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/bash

# Run Space Game x64 in QEMU with UEFI

set -e

# Check for required files
if [ ! -f esp.img ]; then
echo "Error: esp.img not found. Run ./build.sh first"
exit 1
fi

# Check for QEMU
command -v qemu-system-x86_64 >/dev/null 2>&1 || { echo "qemu-system-x86_64 not found. Install with: apt-get install qemu-system-x86"; exit 1; }

# Find OVMF firmware
OVMF=""
if [ -f /usr/share/ovmf/OVMF.fd ]; then
OVMF="/usr/share/ovmf/OVMF.fd"
elif [ -f /usr/share/OVMF/OVMF_CODE.fd ]; then
OVMF="/usr/share/OVMF/OVMF_CODE.fd"
elif [ -f /usr/share/edk2-ovmf/x64/OVMF_CODE.fd ]; then
OVMF="/usr/share/edk2-ovmf/x64/OVMF_CODE.fd"
else
echo "Error: OVMF UEFI firmware not found. Install with: apt-get install ovmf"
exit 1
fi

echo "Starting QEMU with UEFI firmware..."
echo "The game should auto-boot. If it drops to UEFI Shell, type:"
echo " FS0:"
echo " \\EFI\\BOOT\\BOOTX64.efi"
echo ""

# Run QEMU
qemu-system-x86_64 \
-cpu qemu64,+rdrand \
-bios "$OVMF" \
-drive file=esp.img,format=raw \
-m 2048

echo "QEMU exited."
21 changes: 13 additions & 8 deletions space.s
Original file line number Diff line number Diff line change
Expand Up @@ -4288,15 +4288,20 @@ EFI_MAIN PROC
OR RAX, RDX
ADD RAX, CYCLESPERFRAME
MOV NEXTFRAME@, RAX ;SET TIME TO NEXT FRAME

; WAIT WITH VGA VSYNC FOR NEXT FRAME
WAITNEXTFRAME:
RDTSC
SHL RDX, 20H
OR RAX, RDX
CMP NEXTFRAME@, RAX
JA WAITNEXTFRAME ;IF NOT AT NEXT FRAME TIME, KEEP WAITING
ADD RAX, CYCLESPERFRAME
MOV NEXTFRAME@, RAX ;SET TIME TO NEXT FRAME

MOV DX, 03DAH ; VGA STATUS REGISTER
WAITNEXTFRAME_L1:
IN AL, DX ; READ STATUS
TEST AL, 8 ; TEST VSYNC BIT
JNZ WAITNEXTFRAME_L1 ; WAIT WHILE IN RETRACE
WAITNEXTFRAME_L2:
IN AL, DX ; READ STATUS
TEST AL, 8 ; TEST VSYNC BIT
JZ WAITNEXTFRAME_L2 ; WAIT UNTIL RETRACE STARTS
; TODO: HERE YOU COULD SWITCH THE FRAMEBUFFER FOR DOUBLE BUFFERING

RUNFRAME:
MOV RAX, TITLEON
CMP AL, 00H
Expand Down