Skip to content

Commit

Permalink
v8.3.5: improved sockdrive read cache
Browse files Browse the repository at this point in the history
  • Loading branch information
caiiiycuk committed Oct 24, 2024
1 parent a7b266d commit b5d2745
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 32 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "js-dos",
"version": "8.3.4",
"version": "8.3.5",
"description": "Full-featured DOS player with multiple emulator backends",
"type": "module",
"keywords": [
Expand Down Expand Up @@ -37,7 +37,7 @@
"@typescript-eslint/parser": "^6.20.0",
"autoprefixer": "^10.4.17",
"daisyui": "^3.9.3",
"emulators": "8.3.1",
"emulators": "8.3.2",
"eslint": "^8.56.0",
"eslint-config-google": "^0.14.0",
"postcss": "^8.4.33",
Expand Down
2 changes: 1 addition & 1 deletion src/frame/stats-frame.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export function StatsFrame() {
{driveInfo.map((info, i) => {
return <tr>
<td>HDD { i == 0 ? "C:" : "D:"}</td>
<td>{info.drive} {info.write ? " RW" : " RO" }</td>
<td>{info.drive.replace("/", " ")} {info.write ? " RW" : " RO" }</td>
</tr>;
})}
<tr>
Expand Down
1 change: 0 additions & 1 deletion src/sidebar/sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { SaveButtons } from "./save-buttons";
export function SideBar(props: {}) {
const window = useSelector((state: State) => state.ui.window);
const editor = useSelector((state: State) => state.ui.editor);
const backend = useSelector((state: State) => state.dos.backend);
const kiosk = useSelector((state: State) => state.ui.kiosk);
const networking = !useSelector((state: State) => state.ui.noNetworking);

Expand Down
2 changes: 1 addition & 1 deletion src/sockdrive
2 changes: 1 addition & 1 deletion src/ui.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ function Toast() {
class="shrink-0 w-6 h-6">
{path}
</svg>
<span>{toast}</span>
<span class="break-words">{toast}</span>
</div>
</div>;
}
Expand Down
9 changes: 7 additions & 2 deletions src/window/dos/dos-runtime.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ function useLog(ci: CommandInterface): void {
const t = useT();
useEffect(() => {
const preloadProgress: { [drive: string]: number } = {};
const isFork: { [drive: string]: boolean } = {};
ci.events().onMessage((msgType, ...args: string[]) => {
if (msgType === "error" && args[0]?.startsWith("[panic]")) {
dispatch(uiSlice.actions.showToast({
Expand All @@ -45,7 +46,10 @@ function useLog(ci: CommandInterface): void {
const drive = args[0].substring(args[0].indexOf(" ") + 1, args[0].indexOf(","));
dispatch(uiSlice.actions.cloudSaves(false));
if (args[0]?.indexOf("write=") !== -1) {
console.log("drive", drive, "config:", args[0]);
const name = drive.substring(drive.indexOf("/") + 1);
if (name.startsWith("@")) {
isFork[drive.substring(drive.indexOf(".", drive.indexOf("/")) + 1)] = true;
}
dispatch(dosSlice.actions.addSockdriveInfo({
drive,
write: args[0]?.indexOf("write=false") === -1,
Expand All @@ -57,9 +61,10 @@ function useLog(ci: CommandInterface): void {
preloadProgress[drive] = rest;
}

const name = drive.substring(drive.indexOf("/") + 1);
dispatch(uiSlice.actions.showToast({
message: t("preloading_sockdrive") + " " +
drive.substring(drive.indexOf("/") + 1) + " — " +
(isFork[name] ? "@" + name : name) + " — " +
(Math.round(preloadProgress[drive] - rest) / 1024 / 1024).toFixed(2) + "/" +
(Math.round(preloadProgress[drive] / 1024 / 1024)) + "Mb",
long: true,
Expand Down
8 changes: 5 additions & 3 deletions src/ws/ws-sockdrive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ export interface ReadResponse {
}

export function createSockdrive(
onOpen: (drive: string, read: boolean, write: boolean, imageSize: number) => void,
onOpen: (drive: string, read: boolean, write: boolean, imageSize: number,
realOwner: string, realDrive: string) => void,
onError: (e: Error) => void,
onPreloadProgress: (drive: string, restBytes: number) => void,
onPayload: (owner: string, drive: string, sectorSize: number,
Expand Down Expand Up @@ -77,10 +78,11 @@ export function createSockdrive(
mapping[seq] = new Drive(url, owner, name, token, stats, module, backendCache, true);
return new Promise<{ handle: Handle, aheadRange: number }>((resolve, reject) => {
const drive = owner + "/" + name;
mapping[seq].onOpen((read, write, imageSize, aheadRange) => {
mapping[seq].onOpen((read, write, imageSize, aheadRange, realOwner, realDrive) => {
memory[seq] = new Uint8Array(sectorSize /* write */ + sectorSize * aheadRange);
module.HEAPU8 = memory[seq];
onOpen(drive, read, write, imageSize);
onOpen(drive, read, write, imageSize,
realOwner, realDrive);
resolve({
handle: seq,
aheadRange,
Expand Down
40 changes: 23 additions & 17 deletions src/ws/ws-transport-layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export class WsTransportLayer implements TransportLayer {
this.onSockdrivePreloadProgress.bind(this),
this.onSockdrivePayload.bind(this));
private sockdriveSeq = 1;
private version = 0;

private handler: MessageHandler = () => {/**/};

Expand Down Expand Up @@ -128,7 +129,8 @@ export class WsTransportLayer implements TransportLayer {
const message = serverMessageEnum[id];
switch (message) {
case "ws-ready": {
this.onInit((payload && payload[0] && payload.length > 0) ? payload[0][0] : 0);
this.version = (payload && payload[0] && payload.length > 0) ? payload[0][0] : 0;
this.onInit(this.version);
this.handler(message, {});
} break;
case "ws-server-ready":
Expand Down Expand Up @@ -371,7 +373,7 @@ export class WsTransportLayer implements TransportLayer {
const owner = textDecoder.decode(payload[0]!);
const name = textDecoder.decode(payload[1]!);
this.onSockdriveOpen(owner + "/" + name, true,
payload[2]![0] === 1, this.readUint32(payload[2]!, 1));
payload[2]![0] === 1, this.readUint32(payload[2]!, 1), owner, name);
} break;
default:
console.log("WARN! Unhandled server non standard message", id, payload);
Expand Down Expand Up @@ -495,10 +497,12 @@ export class WsTransportLayer implements TransportLayer {
this.sendMessageToSocket("wc-exit");
}

onSockdriveOpen(drive: string, read: boolean, write: boolean, imageSize: number) {
onSockdriveOpen(drive: string, read: boolean, write: boolean, imageSize: number,
realOwner: string, realDrive: string) {
this.handler("ws-log", {
tag: "worker",
message: "sockdrive: " + drive + ", read=" + read + ", write=" + write +
message: "sockdrive: " + (realOwner ? realOwner + "/" + realDrive : drive) +
", read=" + read + ", write=" + write +
", imageSize=" + Math.round(imageSize / 1024 / 1024) + "Mb",
});
}
Expand All @@ -519,20 +523,22 @@ export class WsTransportLayer implements TransportLayer {

onSockdrivePayload(owner: string, drive: string, sectorSize: number,
aheadRange: number, sectors: number[], row: Uint8Array) {
const sectorsPayload = new Uint8Array(sectors.length * 4 + 2 * 4);
let offset = 0;
for (const sector of sectors) {
offset = this.writeUint32(sectorsPayload, sector, offset);
if (this.version > 3) {
const sectorsPayload = new Uint8Array(sectors.length * 4 + 2 * 4);
let offset = 0;
for (const sector of sectors) {
offset = this.writeUint32(sectorsPayload, sector, offset);
}
offset = this.writeUint32(sectorsPayload, sectorSize, offset);
this.writeUint32(sectorsPayload, aheadRange, offset);

this.sendMessageToSocket(106 /* wc-sockdrive-cache */,
textEncoder.encode(owner),
textEncoder.encode(drive),
sectorsPayload,
row,
);
}
offset = this.writeUint32(sectorsPayload, sectorSize, offset);
this.writeUint32(sectorsPayload, aheadRange, offset);

this.sendMessageToSocket(106 /* wc-sockdrive-cache */,
textEncoder.encode(owner),
textEncoder.encode(drive),
sectorsPayload,
row,
);
}
}

Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1174,10 +1174,10 @@ electron-to-chromium@^1.4.648:
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.653.tgz#832ab25e80ad698ac09c1ca547bd9ee6cce7df10"
integrity sha512-wA2A2LQCqnEwQAvwADQq3KpMpNwgAUBnRmrFgRzHnPhbQUFArTR32Ab46f4p0MovDLcg4uqd4nCsN2hTltslpA==

[email protected].1:
version "8.3.1"
resolved "https://registry.yarnpkg.com/emulators/-/emulators-8.3.1.tgz#25788315876b4176bb9aa0ad929707a59f7f3537"
integrity sha512-rhEVIGKPSINIdCp68Y4Udwofu+nBbfT2eSJNJ/xQiI6wdoV1aIziyROkk6WySM0p5YZ3pu256YuqE3mMNuzMJQ==
[email protected].2:
version "8.3.2"
resolved "https://registry.yarnpkg.com/emulators/-/emulators-8.3.2.tgz#bc1b1007fef87c9ab0902f3dffe0e8f6cc9eaca9"
integrity sha512-MbQS+UEv+/EZsT7Y9MCgW8iOpNLLzrR3oZJtpxTnDFpUUN59n3T9YvmyXqNJrQW65BbF2Q4j0lCvv9/mY8kuaw==

entities@^4.2.0:
version "4.5.0"
Expand Down

0 comments on commit b5d2745

Please sign in to comment.