From ed659bbf7550db3cea8445f6acfa4b70dfcdcd2a Mon Sep 17 00:00:00 2001 From: Adam Gastineau Date: Tue, 27 Jun 2023 12:45:53 -0700 Subject: [PATCH] fix: Manifest port order and groundLastIndex calculation --- support/extraction/src/extract.ts | 15 +++++++++----- support/extraction/src/mame/inputs.ts | 29 +++++++++++++++++++++++---- 2 files changed, 35 insertions(+), 9 deletions(-) diff --git a/support/extraction/src/extract.ts b/support/extraction/src/extract.ts index 69d10c1..8661fc4 100644 --- a/support/extraction/src/extract.ts +++ b/support/extraction/src/extract.ts @@ -66,8 +66,17 @@ const run = () => { const portMap = parseInputs(body, name); + ports[name] = portMap; + } + + ports = collapseInputs(ports); + + // Add grounded ports + for (const deviceName of Object.keys(ports)) { + const portMap = ports[deviceName]; + const constructorMatch = file.match( - PUBLIC_CONSTRUCTOR_REGEX_BUILDER(`${name}_state`) + PUBLIC_CONSTRUCTOR_REGEX_BUILDER(`${deviceName}_state`) ); if (constructorMatch) { @@ -89,12 +98,8 @@ const run = () => { } } } - - ports[name] = portMap; } - ports = collapseInputs(ports); - const consoles: { [name: string]: PlatformSpecification; } = {}; diff --git a/support/extraction/src/mame/inputs.ts b/support/extraction/src/mame/inputs.ts index dae15ca..a1029dd 100644 --- a/support/extraction/src/mame/inputs.ts +++ b/support/extraction/src/mame/inputs.ts @@ -180,9 +180,9 @@ export const parseInputs = ( }) .sort((a, b) => { const portIndex = (port: Port): number => { - switch (a.type) { + switch (port.type) { case "s": - return a.index; + return port.index; // S takes 0-7, start at 8 case "b": return 8; @@ -212,6 +212,7 @@ export const collapseInputs = (ports: { } = {}; for (const [deviceName, port] of Object.entries(ports)) { + let outputPort: PlatformPortMapping; if (port.include) { const flatPortMap: { [id: string]: Port; @@ -271,13 +272,33 @@ export const collapseInputs = (ports: { } } - collapsedPorts[deviceName] = { + outputPort = { ...port, ports: [...Object.values(flatPortMap)], }; } else { - collapsedPorts[deviceName] = port; + outputPort = port; } + + const sortedPorts = outputPort.ports.sort((a, b) => { + const portIndex = (port: Port): number => { + switch (port.type) { + case "s": + return port.index; + // S takes 0-7, start at 8 + case "b": + return 8; + case "ba": + return 9; + case "acl": + return 10; + } + }; + + return portIndex(a) - portIndex(b); + }); + + collapsedPorts[deviceName] = { ...outputPort, ports: sortedPorts }; } return collapsedPorts;