mirror of
https://github.com/siemens-mobile-hacks/web-devtools.git
synced 2026-11-25 23:57:40 +00:00
Support 32-bit addresses
This commit is contained in:
parent
1a550fa909
commit
0a7bfb320d
2 changed files with 37 additions and 20 deletions
|
|
@ -3,6 +3,7 @@ import { Form } from "solid-bootstrap";
|
|||
import clsx from "clsx";
|
||||
import {
|
||||
type CalculatorFieldName,
|
||||
MAX_C166_ADDRESS,
|
||||
useC166CalculatorState,
|
||||
} from "@/pages/C166Calculator/store/c166CalculatorState";
|
||||
import "@/pages/C166Calculator/C166CalculatorPage.scss";
|
||||
|
|
@ -11,6 +12,7 @@ interface CalculatorInputProps {
|
|||
id: string;
|
||||
value: string;
|
||||
active: boolean;
|
||||
disabled?: boolean;
|
||||
stacked?: boolean;
|
||||
ariaLabel?: string;
|
||||
onInput: (value: string) => void;
|
||||
|
|
@ -20,11 +22,12 @@ const columns: Array<{
|
|||
label: string;
|
||||
field: CalculatorFieldName;
|
||||
bytesField: CalculatorFieldName;
|
||||
c166?: boolean;
|
||||
}> = [
|
||||
{ label: "Physical", field: "physicalAddress", bytesField: "physicalAddressBytes" },
|
||||
{ label: "Offset", field: "fileOffset", bytesField: "fileOffsetBytes" },
|
||||
{ label: "SEG:SOF (CODE)", field: "codePointer", bytesField: "codePointerBytes" },
|
||||
{ label: "PAG:POF (DATA)", field: "dataPointer", bytesField: "dataPointerBytes" },
|
||||
{ label: "SEG:SOF (CODE)", field: "codePointer", bytesField: "codePointerBytes", c166: true },
|
||||
{ label: "PAG:POF (DATA)", field: "dataPointer", bytesField: "dataPointerBytes", c166: true },
|
||||
];
|
||||
|
||||
const CalculatorInput: Component<CalculatorInputProps> = (props) => (
|
||||
|
|
@ -37,6 +40,7 @@ const CalculatorInput: Component<CalculatorInputProps> = (props) => (
|
|||
props.active && "c166-calculator-input--source"
|
||||
)}
|
||||
value={props.value}
|
||||
disabled={props.disabled}
|
||||
aria-label={props.ariaLabel}
|
||||
autocomplete="off"
|
||||
spellcheck={false}
|
||||
|
|
@ -46,6 +50,7 @@ const CalculatorInput: Component<CalculatorInputProps> = (props) => (
|
|||
|
||||
const C166CalculatorPage: Component = () => {
|
||||
const [state, calculator] = useC166CalculatorState();
|
||||
const c166Disabled = () => state.physicalAddress > MAX_C166_ADDRESS;
|
||||
|
||||
return (
|
||||
<>
|
||||
|
|
@ -56,8 +61,8 @@ const C166CalculatorPage: Component = () => {
|
|||
</Form.Label>
|
||||
<input
|
||||
id="c166-fullflash-base"
|
||||
size={8}
|
||||
maxLength={8}
|
||||
size={10}
|
||||
maxLength={10}
|
||||
class="form-control font-monospace"
|
||||
value={state.baseValue}
|
||||
autocomplete="off"
|
||||
|
|
@ -76,12 +81,14 @@ const C166CalculatorPage: Component = () => {
|
|||
id={`c166-${column.field}`}
|
||||
value={calculator.getFieldValue(column.field)}
|
||||
active={state.source === column.field}
|
||||
disabled={column.c166 && c166Disabled()}
|
||||
onInput={(value) => calculator.setFieldValue(column.field, value)}
|
||||
/>
|
||||
<CalculatorInput
|
||||
id={`c166-${column.bytesField}`}
|
||||
value={calculator.getFieldValue(column.bytesField)}
|
||||
active={state.source === column.bytesField}
|
||||
disabled={column.c166 && c166Disabled()}
|
||||
stacked
|
||||
ariaLabel={`${column.label} bytes`}
|
||||
onInput={(value) => calculator.setFieldValue(column.bytesField, value)}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,8 @@ import {
|
|||
} from "@/utils/c166";
|
||||
import { formatAddress, formatLittleEndian32 } from "@/utils/format";
|
||||
|
||||
const MAX_PHYSICAL_ADDRESS = 0xFFFFFF;
|
||||
export const MAX_C166_ADDRESS = 0xFFFFFF;
|
||||
const MAX_ADDRESS = 0xFFFFFFFF;
|
||||
|
||||
export type CalculatorFieldName =
|
||||
| "physicalAddress"
|
||||
|
|
@ -64,18 +65,16 @@ const parsePackedPointer = (value: string, maximumPage: number, maximumOffset: n
|
|||
const getPhysicalAddress = (field: CalculatorFieldName, value: string, base: number): number | undefined => {
|
||||
switch (field) {
|
||||
case "physicalAddress":
|
||||
return parseHex(value, MAX_PHYSICAL_ADDRESS);
|
||||
case "physicalAddressBytes": {
|
||||
const address = parseLittleEndian32(value);
|
||||
return address !== undefined && address <= MAX_PHYSICAL_ADDRESS ? address : undefined;
|
||||
}
|
||||
return parseHex(value, MAX_ADDRESS);
|
||||
case "physicalAddressBytes":
|
||||
return parseLittleEndian32(value);
|
||||
case "fileOffset": {
|
||||
const offset = parseHex(value, MAX_PHYSICAL_ADDRESS);
|
||||
return offset !== undefined && base + offset <= MAX_PHYSICAL_ADDRESS ? base + offset : undefined;
|
||||
const offset = parseHex(value, MAX_ADDRESS);
|
||||
return offset !== undefined && base + offset <= MAX_ADDRESS ? base + offset : undefined;
|
||||
}
|
||||
case "fileOffsetBytes": {
|
||||
const offset = parseLittleEndian32(value);
|
||||
return offset !== undefined && base + offset <= MAX_PHYSICAL_ADDRESS ? base + offset : undefined;
|
||||
return offset !== undefined && base + offset <= MAX_ADDRESS ? base + offset : undefined;
|
||||
}
|
||||
case "codePointer": {
|
||||
const pointer = parsePointer(value, 0xFF, 0xFFFF);
|
||||
|
|
@ -97,19 +96,30 @@ const getPhysicalAddress = (field: CalculatorFieldName, value: string, base: num
|
|||
};
|
||||
|
||||
const calculateValues = (physicalAddress: number, base: number): CalculatorValues => {
|
||||
const codePointer = physicalToC166CodePointer(physicalAddress);
|
||||
const dataPointer = physicalToC166DataPointer(physicalAddress);
|
||||
const fileOffset = physicalAddress >= base ? physicalAddress - base : undefined;
|
||||
let codePointer = "";
|
||||
let dataPointer = "";
|
||||
let codePointerBytes = "";
|
||||
let dataPointerBytes = "";
|
||||
|
||||
if (physicalAddress <= MAX_C166_ADDRESS) {
|
||||
const code = physicalToC166CodePointer(physicalAddress);
|
||||
const data = physicalToC166DataPointer(physicalAddress);
|
||||
codePointer = `${formatHex(code.segment, 2)}:${formatHex(code.offset, 4)}`;
|
||||
dataPointer = `${formatHex(data.page, 4)}:${formatHex(data.offset, 4)}`;
|
||||
codePointerBytes = formatLittleEndian32(code.segment * 0x10000 + code.offset);
|
||||
dataPointerBytes = formatLittleEndian32(data.page * 0x10000 + data.offset);
|
||||
}
|
||||
|
||||
return {
|
||||
physicalAddress: formatAddress(physicalAddress),
|
||||
physicalAddressBytes: formatLittleEndian32(physicalAddress),
|
||||
fileOffset: fileOffset === undefined ? "" : formatAddress(fileOffset),
|
||||
fileOffsetBytes: fileOffset === undefined ? "" : formatLittleEndian32(fileOffset),
|
||||
codePointer: `${formatHex(codePointer.segment, 2)}:${formatHex(codePointer.offset, 4)}`,
|
||||
dataPointer: `${formatHex(dataPointer.page, 4)}:${formatHex(dataPointer.offset, 4)}`,
|
||||
codePointerBytes: formatLittleEndian32(codePointer.segment * 0x10000 + codePointer.offset),
|
||||
dataPointerBytes: formatLittleEndian32(dataPointer.page * 0x10000 + dataPointer.offset),
|
||||
codePointer,
|
||||
dataPointer,
|
||||
codePointerBytes,
|
||||
dataPointerBytes,
|
||||
};
|
||||
};
|
||||
|
||||
|
|
@ -137,7 +147,7 @@ export const useC166CalculatorState = createStoreWithApi(
|
|||
setBaseValue(value: string) {
|
||||
setState("baseValue", value);
|
||||
|
||||
const base = parseHex(value, MAX_PHYSICAL_ADDRESS);
|
||||
const base = parseHex(value, MAX_ADDRESS);
|
||||
if (base === undefined)
|
||||
return;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue