import { usePersistantStore } from "@/stores/persistantStore"; import styles from "./CodeView.module.css"; import { useDebuggerActions, useDebuggerStore } from "@/stores/debuggerStore"; import { formatHex } from "@/utils/format"; import { ActionIcon, Group, Stack, Text } from "@mantine/core"; import { IconArrowRight, IconCircleDot } from "@tabler/icons-react"; import { useEffect, useState } from "react"; type CodeLine = { address: number; value?: string; }; function CodeView(props: { execAddress: number; baseAddress: number; pageStart: number; pageSize: number; }) { const [hovered, setHovered] = useState(null); const breakpoints = useDebuggerStore((state) => state.breakpoints); const instructionCache = useDebuggerStore((state) => state.instructionCache); const decodeDepth = usePersistantStore((state) => state.decodeDepth); const { removeBreak, addBreak, decode } = useDebuggerActions(); useEffect(() => { decode(decodeDepth); }, [props.execAddress, decodeDepth, decode]); const generateLines = () => { const lines: CodeLine[] = []; for (let i = 0; i < props.pageSize; i += 2) { const address = props.baseAddress + props.pageStart + i; const instr = instructionCache[address]; lines.push({ address, value: instr?.value }); if (instr?.size == 4) i += 2; } return lines; }; const lines = generateLines(); return ( {lines.map((line) => { const isBreakpoint = breakpoints.entries.has(line.address); return ( isBreakpoint ? removeBreak(line.address) : addBreak(line.address) } gap={0} > {props.execAddress === line.address ? ( ) : ( setHovered(line.address)} onMouseLeave={() => setHovered(null)} > )} {formatHex(line.address)}: {line.value ? ( {line.value} ) : ( <UNKNOWN> )} ); })} ); } export default CodeView;