Skip to content
Merged
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
2 changes: 1 addition & 1 deletion Bubilator88.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -957,7 +957,7 @@
repositoryURL = "https://github.com/bubio/Bubilator88Core.git";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 1.11.0;
minimumVersion = 1.12.0;
};
};
/* End XCRemoteSwiftPackageReference section */
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ <h1>Control from AI Tools</h1>
<h2>What the AI Can Do</h2>
<table>
<tr><th>Area</th><th>Description</th></tr>
<tr><td>Running</td><td>Reset, run a given number of frames, pause and resume</td></tr>
<tr><td>Running</td><td>Reset, run a given number of frames, run until text appears or the screen settles, pause and resume</td></tr>
<tr><td>Input</td><td>Press keys, type text, record and replay input</td></tr>
<tr><td>Screen</td><td>Take screenshots and read the text screen</td></tr>
<tr><td>Media</td><td>Mount disks and tapes, save and load states</td></tr>
<tr><td>Screen and sound</td><td>Take screenshots, read the text screen, check that sound is playing and record it to WAV</td></tr>
<tr><td>Media</td><td>Insert and eject disks, CDs and tapes, boot tapes, load memory images, write-protect disks, save and load states</td></tr>
<tr><td>Development</td><td>Read and write registers and memory, disassemble, set breakpoints, watch memory writes, and time code</td></tr>
</table>
<p>What the AI does shows on the screen and in the debugger window as it happens.</p>
Expand All @@ -57,13 +57,18 @@ <h3>Starting and Playing a Game</h3>
<tr><td>"Enter BUBIO on the name screen and start the game."</td><td>Checks the screen for the entry field, types the name and presses <kbd>RETURN</kbd></td></tr>
<tr><td>"I'm right before the boss. Save a state."</td><td>Saves a <code>.b88s</code> file where you say. Ask "load that state" later to go back</td></tr>
<tr><td>"Read the message on the screen and summarize it in English."</td><td>Reads the text screen. Text drawn as graphics is read from a screenshot</td></tr>
<tr><td>"Insert ~/CD/game.cue and boot it."</td><td>Inserts the CD and boots from it. Needs CDBIOS.ROM</td></tr>
<tr><td>"Take the CD out and boot from the disk again."</td><td>Ejects the CD and resets. A CD in the drive boots ahead of the disks, so the AI checks for one first</td></tr>
<tr><td>"How many disks are in ~/Games/bar.d88? Put the second one in drive 2."</td><td>Lists the disks in the file and mounts the one you name</td></tr>
<tr><td>"Check that the music is actually playing."</td><td>Records the sound for a while and reports its level for FM, SSG, ADPCM, rhythm and CD. It can also save a WAV file</td></tr>
</table>

<h3>Using BASIC</h3>
<table>
<tr><th>Ask</th><th>What the AI does</th></tr>
<tr><td>"Type in an N88-BASIC program that draws ten circles, and run it."</td><td>Writes the program, types it on the keyboard, enters <code>RUN</code> and checks the result on screen</td></tr>
<tr><td>"Load this tape (~/Tapes/bar.cmt) with CLOAD and run it."</td><td>Mounts the tape, types <code>CLOAD</code> and <code>RUN</code>, and runs until loading finishes</td></tr>
<tr><td>"Load this tape (~/Tapes/bar.cmt) and run it."</td><td>Mounts the tape, types <code>LOAD "CAS:"</code> and <code>RUN</code> as <strong>Tape &gt; Auto Boot</strong> does, and runs until loading finishes</td></tr>
<tr><td>"Load ~/Mem/baz.n80."</td><td>Restarts in N-BASIC, restores the PC-8001 memory image and types <code>RUN</code> if it needs it</td></tr>
<tr><td>"If there's an error, find the cause, fix it and run it again."</td><td>Reads the error message on screen, retypes the line and runs the program</td></tr>
</table>

Expand Down Expand Up @@ -106,6 +111,7 @@ <h2>Tips</h2>
<ul>
<li><strong>Give full paths</strong> — Name disks and states by a location starting with <code>~/</code> or <code>/Users/…</code>.</li>
<li><strong>The emulator pauses while the AI works</strong> — The AI runs the emulator as many frames as it needs, as fast as it can, and stops there. To play on yourself, ask it to "run in real time" or choose <strong>Emulator &gt; Resume</strong> (<kbd>&#8984;P</kbd>).</li>
<li><strong>Say when to stop</strong> — Ask for something like "run until the title screen" or "wait for it to finish loading", and the AI runs in one go until the text appears or the screen settles.</li>
<li><strong>No kanji</strong> — The AI can type letters, digits, symbols and half-width katakana.</li>
<li><strong>Reading the screen</strong> — Text on the text screen is read exactly. Text drawn as graphics, and pictures, the AI judges by looking at a screenshot.</li>
</ul>
Expand Down
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ <h1>AI ツールからの操作</h1>
<h2>AI ができること</h2>
<table>
<tr><th>種類</th><th>内容</th></tr>
<tr><td>実行</td><td>リセット、指定したフレーム数だけ進める、一時停止と再開</td></tr>
<tr><td>実行</td><td>リセット、指定したフレーム数だけ進める、画面に文字が出るまで・画面が止まるまで進める、一時停止と再開</td></tr>
<tr><td>入力</td><td>キー操作、文字列の入力、入力の記録と再生</td></tr>
<tr><td>画面</td><td>スクリーンショット、テキスト画面の読み取り</td></tr>
<tr><td>メディア</td><td>ディスクとテープのマウント、ステートの保存と読み込み</td></tr>
<tr><td>画面と音</td><td>スクリーンショット、テキスト画面の読み取り、音が鳴っているかの確認と WAV への録音</td></tr>
<tr><td>メディア</td><td>ディスク・CD・テープの出し入れ、テープの自動起動、メモリイメージの読み込み、ディスクの書き込み保護、ステートの保存と読み込み</td></tr>
<tr><td>開発</td><td>レジスタやメモリの読み書き、逆アセンブル、ブレークポイント、メモリ書き込みの監視、処理時間の計測</td></tr>
</table>
<p>AI の操作は、そのまま画面やデバッガのウィンドウに反映されます。</p>
Expand All @@ -57,13 +57,18 @@ <h3>ゲームを起動して進める</h3>
<tr><td>「名前入力の画面で BUBIO と入力して、ゲームを始めて」</td><td>画面を見て入力欄を確かめ、文字を入力して <kbd>RETURN</kbd> を押します</td></tr>
<tr><td>「ボス戦の手前まで来たので、ステートを保存しておいて」</td><td>指定した場所に <code>.b88s</code> ファイルを保存します。あとで「さっきのステートを読み込んで」と頼めば戻れます</td></tr>
<tr><td>「いま画面に出ているメッセージを読んで、日本語で要約して」</td><td>テキスト画面を読み取ります。グラフィックで描かれた文字はスクリーンショットから読みます</td></tr>
<tr><td>「~/CD/game.cue を入れて起動して」</td><td>CD を入れて、CD から起動します。CDBIOS.ROM が必要です</td></tr>
<tr><td>「CD を取り出して、ディスクから起動し直して」</td><td>CD を取り出してリセットします。CD が入っているとディスクより先に CD から起動するので、AI はまず CD の有無を確かめます</td></tr>
<tr><td>「~/Games/bar.d88 にはディスクが何枚入っている? 2 枚目をドライブ 2 に入れて」</td><td>ファイルの中のディスクを一覧にして、指定したものをマウントします</td></tr>
<tr><td>「BGM がちゃんと鳴っているか確かめて」</td><td>しばらく進めながら音を取り込み、音量を FM・SSG・ADPCM・リズム・CD ごとに報告します。WAV ファイルに保存もできます</td></tr>
</table>

<h3>BASIC を使う</h3>
<table>
<tr><th>頼み方</th><th>AI が行うこと</th></tr>
<tr><td>「N88-BASIC で、円を 10 個描くプログラムを入力して実行して」</td><td>プログラムを考えてキーボードから入力し、<code>RUN</code> を実行して、結果の画面を確かめます</td></tr>
<tr><td>「このテープ (~/Tapes/bar.cmt) を CLOAD で読み込んで実行して」</td><td>テープをマウントし、<code>CLOAD</code> と <code>RUN</code> を入力して、読み込みが終わるまで進めます</td></tr>
<tr><td>「このテープ (~/Tapes/bar.cmt) を読み込んで実行して」</td><td>テープをマウントし、<strong>テープ &gt; 自動起動</strong> と同じ手順で <code>LOAD "CAS:"</code> と <code>RUN</code> を入力して、読み込みが終わるまで進めます</td></tr>
<tr><td>「~/Mem/baz.n80 を読み込んで」</td><td>N-BASIC で起動し直して PC-8001 のメモリイメージを戻し、必要なら <code>RUN</code> を入力します</td></tr>
<tr><td>「エラーが出たら原因を調べて、直して再実行して」</td><td>画面のエラーメッセージを読み、該当行を入力し直して実行します</td></tr>
</table>

Expand Down Expand Up @@ -106,6 +111,7 @@ <h2>うまく頼むコツ</h2>
<ul>
<li><strong>ファイルはフルパスで伝える</strong> — ディスクやステートは、<code>~/</code> や <code>/Users/…</code> から始まる場所で指定します。</li>
<li><strong>AI が進めている間は一時停止する</strong> — AI はエミュレータを必要なフレーム数だけ高速に進め、そこで止めます。続きを自分で遊ぶときは「実時間で動かして」と頼むか、<strong>エミュレータ &gt; 再開</strong>(<kbd>&#8984;P</kbd>)を選んでください。</li>
<li><strong>「〜が出るまで」と頼む</strong> — 「タイトル画面が出るまで進めて」「読み込みが終わるまで待って」のように終わりを伝えると、AI は画面に文字が出るまで、または画面が止まるまで一度に進めます。</li>
<li><strong>漢字は入力できない</strong> — AI が入力できるのは英数字・記号と半角カタカナです。</li>
<li><strong>画面の読み取り</strong> — テキスト画面の文字は正確に読めます。グラフィックで描かれた文字や絵は、スクリーンショットを AI が見て判断します。</li>
</ul>
Expand Down
Binary file not shown.
Binary file not shown.
35 changes: 34 additions & 1 deletion Bubilator88/ViewModel/EmulatorViewModel+Automation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ nonisolated final class AppAutomationHost: AutomationHost, @unchecked Sendable {
}

func runFrames(_ count: Int, beforeEach: (PC88) -> Bool) throws -> Int {
try runFrames(count, beforeEach: beforeEach, afterEach: { _ in })
}

func runFrames(_ count: Int, beforeEach: (PC88) -> Bool, afterEach: (PC88) -> Void) throws -> Int {
// The AI takes the machine over: real-time running stops and stays
// stopped, so the next look at the screen shows what these frames did.
let viewModel = try onMain { viewModel in
Expand All @@ -125,6 +129,7 @@ nonisolated final class AppAutomationHost: AutomationHost, @unchecked Sendable {
guard !viewModel.emulationLoop.shouldRun, beforeEach(pc88) else { return false }
viewModel.applyPendingInput()
viewModel.runHostFrame()
afterEach(pc88)
// Nothing plays while paused; drop the sound rather than let it
// burst out when real time resumes.
_ = pc88.takeAudioSamples()
Expand Down Expand Up @@ -219,7 +224,9 @@ nonisolated final class AppAutomationHost: AutomationHost, @unchecked Sendable {
throw AutomationError("Cannot read \(url.path).")
}
return try onMain { viewModel in
guard viewModel.mountTape(url: url), let format = viewModel.tapeFormat else {
// The tool boots the tape itself when asked (tape boot), keeping the
// machine paused; Auto Boot would set it running.
guard viewModel.insertTape(url: url), let format = viewModel.tapeFormat else {
throw AutomationError("Cannot load \(url.lastPathComponent) as a tape.")
}
return format
Expand All @@ -233,4 +240,30 @@ nonisolated final class AppAutomationHost: AutomationHost, @unchecked Sendable {
func ejectTape() throws {
try onMain { $0.ejectTape() }
}

func mountCD(url: URL) throws {
try onMain { viewModel in
do {
try viewModel.insertCD(url: url)
} catch {
throw AutomationError(viewModel.cdMountErrorMessage(error, url: url))
}
}
}

func ejectCD() throws {
try onMain { $0.ejectCD() }
}

func setWriteProtect(drive: Int, protected: Bool) throws {
try onMain { $0.setWriteProtect(drive: drive, protected: protected) }
}

var cdName: String? {
try? onMain { $0.isCDMounted ? $0.cdName : nil }
}

var tapeName: String? {
try? onMain { $0.isTapeMounted ? $0.tapeName : nil }
}
}
18 changes: 12 additions & 6 deletions Bubilator88/ViewModel/EmulatorViewModel+CD.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,14 @@ extension EmulatorViewModel {
return false
}
do {
try emuQueue.sync { try pc88.mountCD(url: url) }
try insertCD(url: url)
} catch {
showAlert(
title: String(localized: "CD Load Error", comment: "Alert title"),
message: cdMountErrorMessage(error, url: url)
)
return false
}
Settings.shared.addRecentFile(url: url, kind: .cd)
cdName = url.deletingPathExtension().lastPathComponent
cdSourceURL = url
isCDMounted = true
// The storage rather than `bootMode` / `clock8MHz`, whose setters each
// reset the machine; the reset below picks both up.
_bootModeStorage = .n88v2
Expand All @@ -45,6 +41,16 @@ extension EmulatorViewModel {
return true
}

/// Put a CD in the drive and show it, without resetting: the drive and
/// the CD BIOS come in at the next reset.
func insertCD(url: URL) throws {
try emuQueue.sync { try pc88.mountCD(url: url) }
Settings.shared.addRecentFile(url: url, kind: .cd)
cdName = url.deletingPathExtension().lastPathComponent
cdSourceURL = url
isCDMounted = true
}

/// Entry point for a `.cue` / `.ccd` opened from Finder. A cold launch
/// can deliver it before `ContentView.onAppear` has loaded the ROMs and
/// started the loop, so it waits for `consumePendingCD()` then.
Expand Down Expand Up @@ -128,7 +134,7 @@ extension EmulatorViewModel {
}
}

private func cdMountErrorMessage(_ error: Error, url: URL) -> String {
func cdMountErrorMessage(_ error: Error, url: URL) -> String {
switch error as? CDImageError {
case .imageFileNotFound(let name):
return String(localized: "\(name) not found next to \(url.lastPathComponent)",
Expand Down
7 changes: 6 additions & 1 deletion Bubilator88/ViewModel/EmulatorViewModel+Disk.swift
Original file line number Diff line number Diff line change
Expand Up @@ -564,9 +564,14 @@ extension EmulatorViewModel {
/// Toggle the write-protect flag on the disk mounted in the specified drive.
/// No-op when the drive is empty.
func toggleWriteProtect(drive: Int) {
setWriteProtect(drive: drive, protected: !(drive == 0 ? drive0WriteProtected : drive1WriteProtected))
}

/// Set the write-protect flag on the disk mounted in the specified drive.
/// No-op when the drive is empty.
func setWriteProtect(drive: Int, protected newValue: Bool) {
let name = drive == 0 ? drive0Name : drive1Name
guard name != "Empty" else { return }
let newValue = !(drive == 0 ? drive0WriteProtected : drive1WriteProtected)
emuQueue.sync {
pc88.setWriteProtect(drive: drive, protected: newValue)
}
Expand Down
14 changes: 11 additions & 3 deletions Bubilator88/ViewModel/EmulatorViewModel+Tape.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,19 @@ extension EmulatorViewModel {
/// Mount a cassette-tape image (`.cmt` / `.t88`, or an archive
/// containing one). Multi-entry archives mount the first hit — PC-88
/// tape ZIPs in the wild are almost always single-file so a picker
/// isn't justified here.
/// isn't justified here. Boots it when Tape > Auto Boot is on.
@discardableResult
func mountTape(url: URL) -> Bool {
guard insertTape(url: url) else { return false }
// Every way of opening a tape ends here, the picker and Recent Files alike.
if Settings.shared.tapeAutoBoot { startTapeAutoBoot() }
return true
}

/// Put a cassette in and show it, without booting it: what AI tools use,
/// which boot a tape themselves and keep the machine paused.
@discardableResult
func insertTape(url: URL) -> Bool {
let accessing = url.startAccessingSecurityScopedResource()
defer { if accessing { url.stopAccessingSecurityScopedResource() } }
guard let data = try? Data(contentsOf: url) else {
Expand Down Expand Up @@ -44,8 +54,6 @@ extension EmulatorViewModel {
// Set here rather than waiting for the 4Hz sampler, so the menus and the
// status bar update on the same run loop turn as the mount.
isTapeMounted = true
// Every way of opening a tape ends here, the picker and Recent Files alike.
if Settings.shared.tapeAutoBoot { startTapeAutoBoot() }
return true
}

Expand Down
4 changes: 2 additions & 2 deletions Shared/BlankDisks/manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"core_revision": "de585718dafabaa8e089cee2febabc39aa0a47ae",
"core_version": "1.11.0",
"core_revision": "2ac66c2f4964c8626c9453099086056c821725cd",
"core_version": "1.12.0",
"images": {
"2D-basic.d88": {
"size": 348848,
Expand Down
2 changes: 1 addition & 1 deletion docs/develop
10 changes: 7 additions & 3 deletions windows/Bubilator88.Windows.Tests/AutomationSessionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ private sealed class Commands : IEmulatorAppCommands
public void Reset(EmulatorBootMode? mode, bool? clock8MHz) => throw new InvalidOperationException("Host command refused for testing.");
public string MountDisk(int drive, string path, int imageIndex, bool writeProtected) => "Disk name";
public void EjectDisk(int drive) { }
public (int Drive, bool Protected)? WriteProtect;
public void SetWriteProtect(int drive, bool protectedFlag) => WriteProtect = (drive, protectedFlag);
public void SaveState(string path) { }
public void LoadState(string path) { }
}
Expand All @@ -46,12 +48,14 @@ public async Task Http_RoundTripsThroughNativeAppHost()
int frames = 0;
var sync = new object();
var host = new AppAutomationHost(commands, action => { lock (sync) action(); },
(before, token) =>
(before, after, token) =>
{
lock (sync)
{
if (commands.IsRunning || !before()) return false;
NativeApi.b88_run_frame(machine); frames++; return true;
NativeApi.b88_run_frame(machine); frames++;
after?.Invoke();
return true;
}
}, new AutomationUiDispatcher(action => { action(); return true; }));
try
Expand Down Expand Up @@ -96,7 +100,7 @@ public async Task Dispose_CancelsQueuedUiCallbackBeforeDestroyingSession()
IntPtr machine = NativeApi.b88_create();
using var entered = new ManualResetEventSlim();
Action? queued = null;
var host = new AppAutomationHost(new Commands(), action => action(), (_, _) => false,
var host = new AppAutomationHost(new Commands(), action => action(), (_, _, _) => false,
new AutomationUiDispatcher(action => { queued = action; entered.Set(); return true; }));
try
{
Expand Down
Loading
Loading