Skip to content

Commit 953f09c

Browse files
Tests: Add helpers for ejecting/swapping disks
These directly expose MAME's `device_image_interface` which gives :load() and :unload() methods, which seems fine. They do abstract over the various ways hardware produces Disk II controllers in slot 6, at least.
1 parent cdf8fd0 commit 953f09c

File tree

3 files changed

+104
-54
lines changed

3 files changed

+104
-54
lines changed

notes/testplan.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1346,7 +1346,7 @@ Run these tests on a system without a real-time clock:
13461346
* Launch DeskTop. Open a window for a volume that is not the startup disk. Apple Menu > Run Basic Here. Verify that the PREFIX is set correctly.
13471347
* Configure a system with a RAMCard. Launch DeskTop, ensure it copies itself to RAMCard. Ensure `BASIC.SYSTEM` is present on the startup disk. Open a window. Apple Menu > Run Basic Here. Verify that `BASIC.SYSTEM` starts.
13481348

1349-
## Joystick - coverage in `tests/joystick.lua`
1349+
## Joystick - covered by `tests/joystick.lua`
13501350

13511351
* Configure a system with only a single joystick (or paddles 0 and 1). Run the DA. Verify that only a single indicator is shown.
13521352
* Configure a system with two joysticks (or paddles 2 and 3). Run the DA. Verify that after the second joystick is moved, a second indicator is shown.

tests/lib/apple2.lua

Lines changed: 84 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ local keyboard = {
3737
["Reset"] = { port = ":keyb_special", field = "RESET" },
3838
}
3939

40+
local images = {
41+
S6D1 = ":sl6:diskiing:0:525",
42+
S6D2 = ":sl6:diskiing:1:525",
43+
}
44+
4045
function get_device(pattern)
4146
for name,dev in pairs(machine.devices) do
4247
if name:match(pattern) then return dev end
@@ -62,6 +67,18 @@ elseif machine.system.name:match("^apple2c") then
6267
y = { port = ":mse_y", field = "Mouse Y" },
6368
b = { port = ":mse_button", field = "Mouse Button" },
6469
}
70+
images = {
71+
S6D1 = ":sl6:0:525",
72+
S6D2 = ":sl6:1:525",
73+
}
74+
if machine.system.name:match("^apple2cp") then
75+
images = {
76+
S6D1 = ":fdc:0:525",
77+
S6D2 = ":fdc:1:525",
78+
FDC2 = ":fdc:2:35dd",
79+
FDC3 = ":fdc:3:35dd",
80+
}
81+
end
6582
elseif machine.system.name:match("^las.*128") then
6683
-- Laser 128
6784
-- * built-in mouse port
@@ -104,6 +121,13 @@ elseif machine.system.name:match("^apple2gs") then
104121
-- Other
105122
["Reset"] = { port = ":macadb:KEY5", field = "Reset / Power" },
106123
}
124+
125+
images = {
126+
S6D1 = ":fdc:0:525",
127+
S6D2 = ":fdc:1:525",
128+
FDC2 = ":fdc:2:35dd",
129+
FDC3 = ":fdc:3:35dd",
130+
}
107131
elseif machine.system.name:match("^ace500") then
108132
-- Franklin ACE 500
109133
-- * has built-in mouse port
@@ -667,6 +691,66 @@ function apple2.WriteSSW(symbol, value)
667691
apple2.WriteMemory(ssw[symbol], value)
668692
end
669693

694+
695+
--------------------------------------------------
696+
-- Disks/Drives
697+
--------------------------------------------------
698+
699+
-- These return image, objects:
700+
-- https://docs.mamedev.org/luascript/ref-devices.html#image-device-interface
701+
-- Useful methods:
702+
-- image:load(path_to_image_file) -- swap
703+
-- image:unload() -- eject, for floppies only!
704+
705+
-- SCSI controller devices
706+
function apple2.GetSCSIHD(slot, id)
707+
local image = manager.machine.images[":sl"..slot..":scsi:scsibus:"..id..":harddisk:image"]
708+
if not image then
709+
error("No SCSI in slot "..slot.." and/or hard disk at ID " .. id)
710+
end
711+
return image
712+
end
713+
function apple2.GetSCSICD(slot, id)
714+
local image = manager.machine.images[":sl"..slot..":scsi:scsibus:"..id..":cdrom:image"]
715+
if not image then
716+
error("No SCSI in slot "..slot.." and/or CD-ROM at ID " .. id)
717+
end
718+
return image
719+
end
720+
721+
-- These abstract over the various hardware that looks like S6,Dn to most software
722+
function apple2.GetDiskIIS6D1()
723+
local image = manager.machine.images[images.S6D1]
724+
if not image then
725+
error("No Disk II in S6,D2")
726+
end
727+
return image
728+
end
729+
730+
function apple2.GetDiskIIS6D2()
731+
local image = manager.machine.images[images.S6D2]
732+
if not image then
733+
error("No Disk II in S6,D2")
734+
end
735+
return image
736+
end
737+
738+
-- For Apple IIgs and Apple IIc+ only (so far)
739+
function apple2.Get35Drive1()
740+
local image = manager.machine.images[images.FDC2]
741+
if not image then
742+
error("No 3.5\" drive 1")
743+
end
744+
return image
745+
end
746+
function apple2.Get35Drive2()
747+
local image = manager.machine.images[images.FDC3]
748+
if not image then
749+
error("No 3.5\" drive 1")
750+
end
751+
return image
752+
end
753+
670754
--------------------------------------------------
671755
-- Misc Utilities
672756
--------------------------------------------------
@@ -727,7 +811,6 @@ function apple2.DHRDarkness()
727811
end
728812
end
729813
end
730-
731814
--------------------------------------------------
732815

733816
return apple2

tests/playground.lua

Lines changed: 19 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
--[[ BEGINCONFIG ========================================
22
33
MODEL="apple2ee"
4-
MODELARGS="-sl2 mouse -sl7 cffa2 -aux ext80"
5-
DISKARGS="-hard1 $HARDIMG"
4+
MODELARGS="-sl2 mouse -sl7 scsi -aux ext80"
5+
DISKARGS="-hard1 $HARDIMG -flop1 $FLOP1IMG"
66
77
======================================== ENDCONFIG ]]--
88

@@ -13,32 +13,6 @@ DISKARGS="-hard1 $HARDIMG"
1313
1414
============================================================]]--
1515

16-
test.Step(
17-
"Sample Media",
18-
function()
19-
a2d.SelectAndOpen("A2.DESKTOP")
20-
a2d.SelectAndOpen("SAMPLE.MEDIA")
21-
test.Snap("Sample Media")
22-
23-
-- Change window size
24-
a2d.OAShortcut("G")
25-
apple2.RightArrowKey()
26-
apple2.RightArrowKey()
27-
apple2.RightArrowKey()
28-
apple2.RightArrowKey()
29-
apple2.ReturnKey()
30-
a2d.WaitForRepaint()
31-
test.Snap("Changed window size")
32-
33-
-- Open MONARCH (image preview)
34-
a2d.SelectAndOpen("MONARCH")
35-
emu.wait(5) -- load big file
36-
test.Snap("Image preview")
37-
apple2.EscapeKey()
38-
a2d.WaitForRepaint()
39-
test.Snap("Back to desktop")
40-
end)
41-
4216
test.Step(
4317
"Move Mouse",
4418
function()
@@ -51,29 +25,22 @@ test.Step(
5125
test.Snap("Mouse to 0,0")
5226
end)
5327

54-
function IsHi(ident)
55-
if apple2.ReadSSW(ident) > 127 then
56-
return "true"
57-
else
58-
return "false"
59-
end
60-
end
28+
test.Step(
29+
"swap images",
30+
function()
6131

62-
print("text? " .. IsHi("RDTEXT"))
63-
print("mixed? " .. IsHi("RDMIXED"))
64-
print("page2? " .. IsHi("RDPAGE2"))
65-
print("hires? " .. IsHi("RDHIRES"))
66-
print("altchr? " .. IsHi("RDALTCHR"))
67-
print("80vid? " .. IsHi("RD80VID"))
32+
apple2.GetSCSIHD(7, 6):load("/Users/josh/dev/a2d/res/tests.hdv")
33+
a2d.InvokeMenuItem(a2d.SPECIAL_MENU, a2d.SPECIAL_CHECK_ALL_DRIVES)
34+
a2d.WaitForRepaint()
35+
test.Snap("swapped hard1")
6836

69-
--[[
70-
local last = apple2.ReadMemory(0x2000)
71-
while true do
72-
emu.wait(5/60)
73-
local cur = apple2.ReadMemory(0x2000)
74-
if cur ~= last then
75-
print("Now is " .. cur)
76-
last = cur
77-
end
78-
end
79-
]]--
37+
apple2.GetDiskIIS6D1():unload()
38+
a2d.InvokeMenuItem(a2d.SPECIAL_MENU, a2d.SPECIAL_CHECK_ALL_DRIVES)
39+
a2d.WaitForRepaint()
40+
test.Snap("flop1 ejected")
41+
42+
apple2.GetDiskIIS6D2():unload() -- harmless if already empty
43+
a2d.InvokeMenuItem(a2d.SPECIAL_MENU, a2d.SPECIAL_CHECK_ALL_DRIVES)
44+
a2d.WaitForRepaint()
45+
test.Snap("flop2 ejected")
46+
end)

0 commit comments

Comments
 (0)