Add slinky and clock (#112)

This commit is contained in:
Will Scullin 2022-05-12 07:59:12 -07:00 committed by GitHub
parent 7e0901cfc2
commit 26796900a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 85 additions and 15 deletions

View File

@ -3,17 +3,12 @@ import { Card, Memory, MemoryPages, TapeData, byte, Restorable } from './types';
import { debug, garbage } from './util';
import { VideoModes } from './videomodes';
type slot = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7;
type button = 0 | 1 | 2;
type paddle = 0 | 1 | 2 | 3;
type annunciator = 0 | 1 | 2 | 3;
export type slot = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7;
export type button = 0 | 1 | 2;
export type paddle = 0 | 1 | 2 | 3;
export type annunciator = 0 | 1 | 2 | 3;
interface Annunciators {
0: boolean;
1: boolean;
2: boolean;
3: boolean;
}
type Annunciators = Record<annunciator, boolean>;
export interface Apple2IOState {
annunciators: Annunciators;

View File

@ -3,13 +3,15 @@ import cs from 'classnames';
import {useEffect, useRef, useState } from 'preact/hooks';
import { Apple2 as Apple2Impl } from '../apple2';
import Apple2IO from '../apple2io';
import CPU6502 from '../cpu6502';
import { ControlStrip } from './ControlStrip';
import { Inset } from './Inset';
import { Keyboard } from './Keyboard';
import { Mouse } from './Mouse';
import { Screen } from './Screen';
import { Drives } from './Drives';
import CPU6502 from 'js/cpu6502';
import { Slinky } from './Slinky';
import { ThunderClock } from './ThunderClock';
/**
* Interface for the Apple2 component.
@ -62,7 +64,9 @@ export const Apple2 = (props: Apple2Props) => {
return (
<div className={cs('outer', { apple2e: e})}>
<Screen screen={screen} />
<Mouse cpu={cpu} screen={screen} io={io} />
<Mouse cpu={cpu} screen={screen} io={io} slot={4} />
<Slinky io={io} slot={4} />
<ThunderClock io={io} slot={5} />
<Inset>
<Drives io={io} sectors={sectors} />
</Inset>

View File

@ -1,22 +1,35 @@
import { RefObject } from 'preact';
import Apple2IO from '../apple2io';
import Apple2IO, { slot } from '../apple2io';
import { MouseUI } from '../ui/mouse';
import MouseCard from '../cards/mouse';
import CPU6502 from '../cpu6502';
import { useEffect } from 'preact/hooks';
/**
* Mouse component properties.
*/
export interface MouseProps {
cpu: CPU6502 | undefined;
io: Apple2IO | undefined;
screen: RefObject<HTMLCanvasElement>;
slot: slot;
}
export const Mouse = ({ cpu, screen, io }: MouseProps) => {
/**
* Mouse card component that adds a simple mouse driver.
*
* @param cpu CPU6502 object
* @param screen Screen element reference
* @param io Apple2IO object
* @param slot Slot to register card in
* @returns Mouse component
*/
export const Mouse = ({ cpu, screen, io, slot }: MouseProps) => {
useEffect(() => {
if (cpu && io && screen.current) {
const mouseUI = new MouseUI(screen.current);
const mouse = new MouseCard(cpu, mouseUI);
io.setSlot(4, mouse);
io.setSlot(slot, mouse);
}
}, [cpu, io]);

30
js/components/Slinky.tsx Normal file
View File

@ -0,0 +1,30 @@
import { useEffect } from 'preact/hooks';
import Apple2IO, { slot } from '../apple2io';
import RAMFactor from '../cards/ramfactor';
/**
* Slinky component properties
*/
export interface SlinkyProps {
io: Apple2IO | undefined;
slot: slot;
}
/**
* RAMFactory (Slinky) memory card component. Adds
* 1MB of slinky compatible memory.
*
* @param io Apple2IO object
* @param slot Slot to register card in
* @returns Slinky component
*/
export const Slinky = ({ io, slot }: SlinkyProps) => {
useEffect(() => {
if (io) {
const slinky = new RAMFactor(1024 * 1024);
io.setSlot(slot, slinky);
}
}, [io]);
return null;
};

View File

@ -0,0 +1,28 @@
import { useEffect } from 'preact/hooks';
import Apple2IO, { slot } from '../apple2io';
import ThunderClockCard from '../cards/thunderclock';
/**
* ThunderClock component properties.
*/
export interface ThunderClockProps {
io: Apple2IO | undefined;
slot: slot;
}
/**
* ThunderClock card component.
*
* @param io Apple2IO object
* @param slot Slot to register card in
*/
export const ThunderClock = ({ io, slot }: ThunderClockProps) => {
useEffect(() => {
if (io) {
const clock = new ThunderClockCard();
io.setSlot(slot, clock);
}
}, [io]);
return null;
};