Skip to content

Commit b33c49b

Browse files
Tests: more helpers, less shelling out
1 parent 311db5c commit b33c49b

File tree

2 files changed

+39
-13
lines changed

2 files changed

+39
-13
lines changed

tests/date_and_time.lua

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -107,18 +107,17 @@ test.Step(
107107
a2d.Restart()
108108

109109
-- Create new folder
110-
a2d.OpenPath("/RAM1")
111-
a2d.InvokeMenuItem(a2d.FILE_MENU, a2d.FILE_NEW_FOLDER)
112-
apple2.ReturnKey()
110+
a2d.CreateFolder("/RAM1/NOT.TODAY")
113111

114112
-- Change date again to avoid "Today"
115113
a2d.SetProDOSDate(1999,9,13)
116114

117115
-- Inspect file
118-
a2d.SelectPath("/RAM1/NEW.FOLDER")
116+
a2d.SelectPath("/RAM1/NOT.TODAY")
119117
a2d.InvokeMenuItem(a2d.FILE_MENU, a2d.FILE_GET_INFO)
120118
test.Snap("verify date matches set previously set date")
121119
a2d.DialogOK()
120+
a2d.DeletePath("/RAM1/NOT.TODAY")
122121
a2d.CloseAllWindows()
123122
end)
124123

@@ -305,12 +304,11 @@ test.Step(
305304
"Today",
306305
function()
307306
-- Create file with known date
308-
a2d.OpenPath("/A2.DESKTOP/EXTRAS/BASIC.SYSTEM")
309-
a2d.WaitForRestart()
307+
local y,m,d = a2d.GetProDOSDate()
310308
a2d.SetProDOSDate(1999, 9, 13)
311-
apple2.TypeLine("CREATE /RAM1/WILL.BE.TODAY")
312-
apple2.TypeLine("PR#7")
313-
a2d.WaitForRestart()
309+
a2d.CreateFolder("/RAM1/WILL.BE.TODAY")
310+
-- Change the date so it's not current
311+
a2d.SetProDOSDate(y,m,d)
314312

315313
-- Show window and resize/move it
316314
a2d.OpenPath("/RAM1")

tests/lib/a2d.lua

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,18 @@ function a2d.DeletePath(path)
310310
a2d.DeleteSelection()
311311
end
312312

313+
function a2d.CreateFolder(path)
314+
local base, name = path:match("^(.*)/([^/]+)$")
315+
if base ~= "" then
316+
a2d.OpenPath(base)
317+
end
318+
a2d.InvokeMenuItem(a2d.FILE_MENU, a2d.FILE_NEW_FOLDER)
319+
apple2.ControlKey("X") -- clear
320+
apple2.Type(name)
321+
apple2.ReturnKey()
322+
a2d.WaitForRepaint()
323+
end
324+
313325
function a2d.EraseVolume(name)
314326
a2d.SelectPath("/"..name)
315327
a2d.InvokeMenuItem(a2d.SPECIAL_MENU, a2d.SPECIAL_ERASE_DISK)
@@ -551,16 +563,32 @@ end
551563

552564
--------------------------------------------------
553565

566+
local DATELO, DATEHI, TIMELO, TIMEHI = 0xBF90, 0xBF91, 0xBF92, 0xBF93
567+
554568
function a2d.SetProDOSDate(y,m,d)
555569
local hi = (y % 100) << 1 | (m >> 3)
556570
local lo = (m << 5) | d
557-
apple2.WriteRAMDevice(0xBF90, lo)
558-
apple2.WriteRAMDevice(0xBF91, hi)
571+
apple2.WriteRAMDevice(DATELO, lo)
572+
apple2.WriteRAMDevice(DATEHI, hi)
573+
end
574+
575+
function a2d.GetProDOSDate()
576+
local word = (apple2.ReadRAMDevice(DATEHI) << 8) | apple2.ReadRAMDevice(DATELO)
577+
local y = (word >> 9) & 0x7F
578+
local m = (word >> 5) & 0xF
579+
local d = word & 0x1F
580+
return y,m,d
559581
end
560582

561583
function a2d.SetProDOSTime(h, m)
562-
apple2.WriteRAMDevice(0xBF92, h)
563-
apple2.WriteRAMDevice(0xBF93, m)
584+
apple2.WriteRAMDevice(TIMELO, m)
585+
apple2.WriteRAMDevice(TIMEHI, h)
586+
end
587+
588+
function a2d.GetProDOSTime()
589+
local m = apple2.ReadRAMDevice(TIMELO) & 0x3F
590+
local h = apple2.ReadRAMDevice(TIMEHI) & 0x1F
591+
return h,m
564592
end
565593

566594
--------------------------------------------------

0 commit comments

Comments
 (0)