Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions src/ui/controls/speeddropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,30 @@ import { turtleIcon } from "../img/icon_turtle"
const speedNames = ["0.1 MHz (Snail)", "0.5 MHz (Slow)", "1 MHz", "2 MHz",
"3 MHz", "4 MHz (Fast)", "Ludicrous"]

export const MaximumSpeedMode = speedNames.length - 2 - 1

export const SpeedDropdown = (props: { updateDisplay: UpdateDisplay }) => {
const speedMode = handleGetSpeedMode()
const iconSize = 22
const icons = [
<svg key="-2" width="27" height="27" className="fill-color">{snailIcon}</svg>,
<svg key="-1" width="27" height="27" className="fill-color">{turtleIcon}</svg>,
<FontAwesomeIcon key="0" icon={faWalking} style={{ fontSize: `${iconSize}px` }}/>,
<FontAwesomeIcon key="1" icon={faPersonRunning} style={{ fontSize: `${iconSize}px` }}/>,
<FontAwesomeIcon key="2" icon={faPersonBiking} style={{ fontSize: `${iconSize}px` }}/>,
<FontAwesomeIcon key="3" icon={faTruckFast} style={{ fontSize: `${iconSize}px` }}/>,
<FontAwesomeIcon key="4" icon={faRocket} style={{ fontSize: `${iconSize}px` }}/>
<FontAwesomeIcon key="0" icon={faWalking} style={{ fontSize: `${iconSize}px` }} />,
<FontAwesomeIcon key="1" icon={faPersonRunning} style={{ fontSize: `${iconSize}px` }} />,
<FontAwesomeIcon key="2" icon={faPersonBiking} style={{ fontSize: `${iconSize}px` }} />,
<FontAwesomeIcon key="3" icon={faTruckFast} style={{ fontSize: `${iconSize}px` }} />,
<FontAwesomeIcon key="4" icon={faRocket} style={{ fontSize: `${iconSize}px` }} />
]
const icon = icons[speedMode + 2] // Adjust for the first two modes (snail and turtle)

return (
<DropdownButton
currentIndex = {speedMode + 2}
itemNames = {speedNames}
closeCallback = {(index: number) => {setPreferenceSpeedMode(index - 2); props.updateDisplay()}}
icon ={icon}
icons = {icons}
tooltip = "Emulator Speed"
<DropdownButton
currentIndex={speedMode + 2}
itemNames={speedNames}
closeCallback={(index: number) => { setPreferenceSpeedMode(index - 2); props.updateDisplay() }}
icon={icon}
icons={icons}
tooltip="Emulator Speed"
/>
)
}
58 changes: 48 additions & 10 deletions src/ui/inputparams.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { COLOR_MODE, UI_THEME } from "../common/utility"
import { useGlobalContext } from "./globalcontext"
import { passSpeedMode, passSetRamWorks, passPasteText, handleGetState6502, passSetShowDebugTab, passSetMachineName, passSetBinaryBlock } from "./main2worker"
import { passSpeedMode, passSetRamWorks, passPasteText, handleGetState6502, passSetShowDebugTab, passSetMachineName, passSetBinaryBlock, handleGetSpeedMode } from "./main2worker"
import { setDefaultBinaryAddress, handleSetDiskFromURL } from "./devices/disk/driveprops"
import { audioEnable } from "./devices/audio/speaker"
import { setAppMode, setCapsLock, setColorMode, setGhosting, setHotReload, setShowScanlines, setTheme } from "./ui_settings"
import * as pako from "pako"
import { MaximumSpeedMode } from "./controls/speeddropdown"
import { setPreferenceSpeedMode } from "./localstorage"
import { Expectin } from "./expectin"

export const handleInputParams = (paramString = "") => {
// Most parameters are case insensitive. The only exception is the BASIC
Expand Down Expand Up @@ -154,15 +157,18 @@ export const handleInputParams = (paramString = "") => {
if (text) {
const trimmed = text.trim()
const hasLineNumbers = /^[0-9]/.test(trimmed) || /[\n\r][0-9]/.test(trimmed)
const cmd = trimmed + ((hasLineNumbers && doRun) ? "\nRUN\n" : "\n")
const waitForBoot = setInterval(() => {
// Wait a bit to give the emulator time to start and boot any disks.
const cycleCount = handleGetState6502().cycleCount
if (cycleCount > 2000000) {
clearInterval(waitForBoot)
passPasteText(cmd)
}
}, 100)
const sentinel = `REM ${Date.now()}`
const cmd = `${trimmed}\n${sentinel}\n`

sendTextAndWait("", "]", () => {
const prevSpeedMode = handleGetSpeedMode()
setPreferenceSpeedMode(MaximumSpeedMode)

sendTextAndWait(cmd, sentinel, () => {
setPreferenceSpeedMode(prevSpeedMode)
passPasteText((hasLineNumbers && doRun) ? "\nRUN\n" : "\n")
})
})
}

return hasBasicProgram
Expand Down Expand Up @@ -204,3 +210,35 @@ export const handleFragment = async (updateDisplay: UpdateDisplay, hasBasicProgr
handleSetDiskFromURL("blank.po", updateDisplay)
}
}

const sendTextAndWait = (sendText: string, waitText: string, callback: () => void) => {
const expectinJson =
{
"commands": [
{
"send": sendText
},
{
"expect": [
{
"match": waitText,
"commands": [
{
"disconnect": {}
}
]
}
]
}
]
}
const expectin = new Expectin(JSON.stringify(expectinJson))
expectin.Run()

const interval = window.setInterval(() => {
if (!expectin.IsRunning()) {
clearInterval(interval)
callback()
}
}, 100)
}