Skip to content

Commit

Permalink
Merge pull request #90 from davidgiven/tests
Browse files Browse the repository at this point in the history
Add MAME-based emulator tests for smoke testing the platforms.
  • Loading branch information
davidgiven authored Dec 20, 2023
2 parents 3be4489 + fa7cd11 commit 54ad628
Show file tree
Hide file tree
Showing 21 changed files with 469 additions and 30 deletions.
40 changes: 24 additions & 16 deletions .github/workflows/ccpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,41 @@ jobs:
- uses: actions/checkout@v3
with:
repository: 'davidgiven/cpm65'
path: 'cpm65'

- name: apt
run: sudo apt update && sudo apt install cc1541 cpmtools libfmt-dev fp-compiler moreutils
run: sudo apt update && sudo apt install cc1541 cpmtools libfmt-dev fp-compiler moreutils mame

- name: install llvm-mos
run: |
wget -O - https://github.com/llvm-mos/llvm-mos-sdk/releases/latest/download/llvm-mos-linux.tar.xz | tar xJf - -C $HOME
wget -q -O - https://github.com/llvm-mos/llvm-mos-sdk/releases/latest/download/llvm-mos-linux.tar.xz | tar xJf - -C $HOME
- name: install roms
run: |
sh scripts/get-roms.sh
#- name: Setup upterm session
# uses: lhotari/action-upterm@v1
# with:
# limit-access-to-actor: true

- name: make
run: make -C cpm65 LLVM=$HOME/llvm-mos/bin
run: make LLVM=$HOME/llvm-mos/bin -j`nproc` +all +mametest

- name: Upload build artifacts
uses: actions/upload-artifact@v2
with:
name: ${{ github.event.repository.name }}.${{ github.sha }}
path: |
cpm65/apple2e.po
cpm65/atari800.atr
cpm65/atari800hd.atr
cpm65/atari800xlhd.atr
cpm65/bbcmicro.ssd
cpm65/c64.d64
cpm65/diskdefs
cpm65/oric.dsk
cpm65/pet4032.d64
cpm65/pet8032.d64
cpm65/pet8096.d64
cpm65/x16.zip
apple2e.po
atari800.atr
atari800hd.atr
atari800xlhd.atr
bbcmicro.ssd
c64.d64
diskdefs
oric.dsk
pet4032.d64
pet8032.d64
pet8096.d64
x16.zip
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ export OBJ = .obj
.PHONY: all
all: +all

TARGETS = +all +mametest
include build/ab.mk
16 changes: 13 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,26 @@ is available out of the box. Once installed, you should just be able to run the
Makefile and you'll get bootable disk images for the Commodore 64 (with 1541
drive) and BBC Micro (producing a 200kB SSSD DFS disk):

make LLVM=<your llvm-mos bin directory here>/
make LLVM=<your llvm-mos bin directory here>/ -j$(nproc)

Building CP/M-65 is a bit of a performance because it's aggregating lots of
other software, all of which need building in turn. You'll need: a C and C++
compiler, cc1541 (for creating 1541 disk images), cpmtools (for creating CP/M
disk images), libfmt (all the C++ tools use this), ninja-build (for the build
disk images), libfmt (all the C++ tools use this), python3 (for the build
system), and FreePascal (because the MADS assembler is written in Pascal). Use
these Debian packages:

cc1541 cpmtools libfmt-dev ninja-build fp-compiler
cc1541 cpmtools libfmt-dev python3 fp-compiler

There are also automated tests which use `mame` to emulate a reasonable number
of the platforms, to verify that they actually work. To use this, install
`mame`, and then run `scripts/get-roms.sh` to download the necessary system
ROMs. Then do:

make LLVM=<your llvm-mos bin directory here>/ -j$(nproc) +mametest

You can add `+all` to that if you want to do a normal build and run the tests at
the same time.

### BBC Micro notes

Expand Down
15 changes: 15 additions & 0 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,18 @@
"x16.zip": "src/arch/x16+diskimage",
},
)

export(
name="mametest",
deps=[
"src/arch/bbcmicro+mametest",
"src/arch/commodore+c64_mametest",
"src/arch/commodore+pet4032_mametest",
"src/arch/commodore+pet8032_mametest",
# Works locally, but not on github CI.
#"src/arch/apple2e+mametest",
# Fails everywhere.
#"src/arch/atari800+mametest",
"src/arch/oric+mametest",
],
)
4 changes: 3 additions & 1 deletion build/ab.mk
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,13 @@ clean::
@echo CLEAN
$(hide) rm -rf $(OBJ) bin

TARGETS ?= +all

export PYTHONHASHSEED = 1
build-files = $(shell find . -name 'build.py') $(wildcard build/*.py) $(wildcard config.py)
$(OBJ)/build.mk: Makefile $(build-files)
@echo "AB"
@mkdir -p $(OBJ)
$(hide) $(PYTHON) -X pycache_prefix=$(OBJ) build/ab.py -t +all -o $@ \
$(hide) $(PYTHON) -X pycache_prefix=$(OBJ) build/ab.py $(patsubst %,-t %,$(TARGETS)) -o $@ \
build.py || rm -f $@

37 changes: 37 additions & 0 deletions scripts/get-roms.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/sh
set -e

get_rom() {
rom=$2
if [ "$rom" = "" ]; then
rom=$(basename $1)
fi
if ! [ -f roms/$rom ]; then
mkdir -p roms
wget -q -O roms/$rom $1
fi
}

URL='https://archive.org/download/MAME217RomsOnlyMerged/MAME%200.217%20ROMs%20%28merged%29.zip'

get_rom $URL/a2diskiing.zip
get_rom $URL/a800xl.zip
get_rom $URL/apple2e.zip
get_rom $URL/bbcm.zip
get_rom $URL/c1541.zip
get_rom $URL/c64.zip
get_rom $URL/d2fdc.zip
get_rom $URL/oric1.zip
get_rom $URL/oric_microdisc.zip
get_rom $URL/saa5050.zip
get_rom $URL/vic1001.zip
get_rom $URL/pet4016.zip
get_rom $URL/pet4032b.zip
get_rom $URL/pet8032.zip
get_rom $URL/c8050.zip
get_rom $URL/c8050fdc.zip
get_rom $URL/c4040.zip
get_rom $URL/c2040_fdc.zip
get_rom $URL/vic20_fe3.zip vic20.zip
get_rom $URL/votrax.zip
cp roms/votrax.zip roms/votrsc01a.zip
7 changes: 7 additions & 0 deletions scripts/mame-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh
set -e

diskimage=/tmp/$$.$4
trap "rm -f $diskimage" EXIT
cp $2 $diskimage
SDL_VIDEODRIVER=dummy SDL_AUDIODRIVER=dummy chronic mame $1 -flop1 $diskimage -video none -autoboot_script $3 -nothrottle -nosleep -snapshot_directory snap -sound none -rompath roms
7 changes: 7 additions & 0 deletions scripts/oric-mame-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh
set -e

diskimage=/tmp/$$.$4
trap "rm -f $diskimage" EXIT
cp $2 $diskimage
SDL_VIDEODRIVER=dummy SDL_AUDIODRIVER=dummy chronic mame $1 -ext microdisc -flop $diskimage -video none -autoboot_script $3 -nothrottle -nosleep -snapshot_directory snap -sound none -rompath roms
11 changes: 9 additions & 2 deletions src/arch/apple2e/build.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from build.ab import normalrule
from tools.build import mkdfs, mkcpmfs, shuffle
from tools.build import mkcpmfs, shuffle, mametest
from build.llvm import llvmrawprogram, llvmcfile
from config import (
MINIMAL_APPS,
Expand Down Expand Up @@ -58,3 +57,11 @@
| BIG_APPS
| BIG_APPS_SRCS,
)

mametest(
name="mametest",
target="apple2e",
diskimage=".+diskimage",
imagetype=".po",
script="./mame-test.lua",
)
43 changes: 43 additions & 0 deletions src/arch/apple2e/mame-test.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
local c = coroutine.create(function()
local machine = manager.machine
local kbd = machine.natkeyboard
local video = machine.video

local function wait_kbd()
while kbd.is_posting do
emu.wait(0.1)
end
end

emu.wait(6)

kbd:post_coded("BEDIT{ENTER}")
emu.wait(3)
kbd:post_coded("10 lda #18{ENTER}") wait_kbd()
kbd:post_coded("20 ldx #35{ENTER}") wait_kbd()
kbd:post_coded("30 ldy #52{ENTER}") wait_kbd()
kbd:post_coded("40 label: jmp label{ENTER}") wait_kbd()
kbd:post_coded("save \"test.asm\"{ENTER}") wait_kbd()
emu.wait(8)
kbd:post_coded("quit{ENTER}") wait_kbd()
emu.wait(1)
kbd:post_coded("asm test.asm test.com{ENTER}") wait_kbd()
emu.wait(20)
kbd:post_coded("test{ENTER}") wait_kbd()
emu.wait(3)

local cpu = manager.machine.devices[':maincpu']
if (tostring(cpu.state.A) == "12") and (tostring(cpu.state.X) == "23") and (tostring(cpu.state.Y) == "34") then
print("success!")
os.exit(0)
end

print("fail")
video:snapshot()
for k, v in pairs(cpu.state) do
print(k, type(v), tostring(v))
end

os.exit(1)
end)
coroutine.resume(c)
16 changes: 12 additions & 4 deletions src/arch/atari800/build.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from build.ab import normalrule
from tools.build import mkcpmfs
from tools.build import mkcpmfs, mametest
from build.llvm import llvmrawprogram, llvmclibrary
from config import (
MINIMAL_APPS,
Expand All @@ -23,7 +23,7 @@
name="atari800_rawdiskimage",
format="atari90",
bootimage=".+atari800_bios",
size=128*720,
size=128 * 720,
items={
"0:ccp.sys@sr": "src+ccp",
"0:bdos.sys@sr": "src+bdos",
Expand Down Expand Up @@ -58,7 +58,7 @@
name="atari800hd_rawdiskimage",
format="atarihd",
bootimage=".+atari800hd_bios",
size=128*8190,
size=128 * 8190,
items={
"0:ccp.sys@sr": "src+ccp",
"0:bdos.sys@sr": "src+bdos",
Expand Down Expand Up @@ -105,7 +105,7 @@
name="atari800xlhd_rawdiskimage",
format="atarihd",
bootimage=".+atari800xlhd_bios",
size=128*8190,
size=128 * 8190,
items={
"0:ccp.sys@sr": "src+ccp",
"0:bdos.sys@sr": "src+bdos",
Expand Down Expand Up @@ -139,3 +139,11 @@
],
label="MAKEATR",
)

mametest(
name="mametest",
target="a800xlp",
diskimage=".+atari800_diskimage",
imagetype=".atr",
script="./mame-test.lua",
)
43 changes: 43 additions & 0 deletions src/arch/atari800/mame-test.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
local c = coroutine.create(function()
local machine = manager.machine
local kbd = machine.natkeyboard
local video = machine.video

local function wait_kbd()
while kbd.is_posting do
emu.wait(0.1)
end
end

emu.wait(4)

kbd:post_coded("BEDIT{ENTER}")
emu.wait(2)
kbd:post_coded("10 lda #0x12{ENTER}") wait_kbd()
kbd:post_coded("20 ldx #0x23{ENTER}") wait_kbd()
kbd:post_coded("30 ldy #0x34{ENTER}") wait_kbd()
kbd:post_coded("40 label: jmp label{ENTER}") wait_kbd()
kbd:post_coded("save \"test.asm\"{ENTER}") wait_kbd()
emu.wait(3)
kbd:post_coded("quit{ENTER}") wait_kbd()
emu.wait(3)
kbd:post_coded("asm test.asm test.com{ENTER}") wait_kbd()
emu.wait(20)
kbd:post_coded("test{ENTER}") wait_kbd()
emu.wait(5)

local cpu = manager.machine.devices[':maincpu']
if (tostring(cpu.state.A) == "12") and (tostring(cpu.state.X) == "23") and (tostring(cpu.state.Y) == "34") then
print("success!")
os.exit(0)
end

print("fail")
video:snapshot()
for k, v in pairs(cpu.state) do
print(k, type(v), tostring(v))
end

os.exit(1)
end)
coroutine.resume(c)
10 changes: 9 additions & 1 deletion src/arch/bbcmicro/build.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from build.ab import normalrule
from tools.build import mkdfs, mkcpmfs
from tools.build import mkdfs, mkcpmfs, mametest
from build.llvm import llvmrawprogram
from config import (
MINIMAL_APPS,
Expand Down Expand Up @@ -40,3 +40,11 @@
"cpmfs": ".+cpmfs",
},
)

mametest(
name="mametest",
target="bbcm",
diskimage=".+diskimage",
imagetype=".img",
script="./mame-test.lua",
)
Loading

0 comments on commit 54ad628

Please sign in to comment.