Implement memory map and arithmetic logic

This commit is contained in:
2025-12-21 23:35:08 +09:00
parent a459b81884
commit d459bf4e9f
3 changed files with 220 additions and 19 deletions

View File

@@ -67,17 +67,34 @@ export interface LedObject extends BaseObject {
outputPort: number; // Reads this Output bit to turn on
}
// Memory Map Constants
export const MEMORY_SIZE = 10000;
export const ADDR_USER_START = 0;
export const ADDR_USER_END = 7999;
export const ADDR_AXIS_BASE = 8000;
export const ADDR_AXIS_STRIDE = 100;
// Axis Memory Layout (Offsets from Axis Base)
export const OFF_AXIS_STATUS = 0; // Uint16
export const OFF_AXIS_CURRENT_POS = 2; // Float32
export const OFF_AXIS_TARGET_POS = 6; // Float32
export const OFF_AXIS_SPEED = 10; // Float32
export const OFF_AXIS_ACCEL = 14; // Float32
export const OFF_AXIS_DECEL = 18; // Float32
export type SimObject = AxisObject | CylinderObject | SwitchObject | LedObject;
// Logic Types
export enum LogicTriggerType {
INPUT_BIT = 'INPUT_BIT',
AXIS_COMPARE = 'AXIS_COMPARE',
AXIS_COMPARE = 'AXIS_COMPARE', // Deprecated in favor of MEM_COMPARE, but kept for compatibility
MEM_COMPARE = 'MEM_COMPARE',
}
export enum LogicActionType {
OUTPUT_COIL = 'OUTPUT_COIL',
AXIS_MOVE = 'AXIS_MOVE',
AXIS_MOVE = 'AXIS_MOVE', // Deprecated in favor of Memory Write
MEM_OPERATION = 'MEM_OPERATION',
}
export enum LogicCondition {
@@ -90,12 +107,18 @@ export enum LogicCondition {
LESS_EQUAL = '<=',
}
export enum LogicMathOp {
SET = '=',
ADD = '+',
SUB = '-',
}
export enum LogicAction {
SET_ON = 'ON',
SET_OFF = 'OFF',
TOGGLE = 'TOGGLE',
MOVE_ABS = 'MOVE_ABS',
MOVE_REL = 'MOVE_REL',
MOVE_ABS = 'MOVE_ABS', // Legacy
MOVE_REL = 'MOVE_REL', // Legacy
}
export interface IOLogicRule {
@@ -105,16 +128,27 @@ export interface IOLogicRule {
// Trigger
triggerType: LogicTriggerType;
inputPort: number; // For INPUT_BIT
triggerAxisIndex: number; // For AXIS_COMPARE
triggerCompareOp: LogicCondition; // For AXIS_COMPARE (>, <, ==)
triggerValue: number; // For AXIS_COMPARE
// Axis/Memory Trigger
triggerAxisIndex: number; // For AXIS_COMPARE (Legacy)
triggerCompareOp: LogicCondition; // >, <, ==
triggerValue: number; // For AXIS_COMPARE (Legacy) or MEM_COMPARE Constant
triggerAddress: number; // For MEM_COMPARE (Address to check)
// Action
actionType: LogicActionType;
outputPort: number; // For OUTPUT_COIL
action: LogicAction; // For OUTPUT_COIL (ON/OFF)
targetAxisIndex: number; // For AXIS_MOVE
targetAxisValue: number; // For AXIS_MOVE
action: LogicAction; // For OUTPUT_COIL
// Axis Action (Legacy)
targetAxisIndex: number;
targetAxisValue: number;
// Memory Action
memAddress: number; // Address to write to
memOperation: LogicMathOp; // =, +, -
memOperandValue: number; // Value to add/sub/set
}
// Full Project Export Type
@@ -125,4 +159,6 @@ export interface ProjectData {
inputNames: string[];
outputNames: string[];
axes: AxisData[];
// Memory snapshot could be large, maybe store only non-zero or user logic?
// For now, we won't persist full RAM, only config.
}