Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
/*
|
2021-03-12 06:03:05 +00:00
|
|
|
* Copyright 2010-2021 Will Scullin <scullin@scullinsteel.com>
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, distribute, and sell this software and its
|
|
|
|
* documentation for any purpose is hereby granted without fee, provided that
|
|
|
|
* the above copyright notice appear in all copies and that both that
|
|
|
|
* copyright notice and this permission notice appear in supporting
|
|
|
|
* documentation. No representations are made about the suitability of this
|
|
|
|
* software for any purpose. It is provided "as is" without express or
|
|
|
|
* implied warranty.
|
|
|
|
*/
|
|
|
|
|
2021-03-06 23:04:13 +00:00
|
|
|
import { Memory, MemoryPages, byte, word } from './types';
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
import { debug, toHex } from './util';
|
|
|
|
|
|
|
|
export interface CpuOptions {
|
|
|
|
'65C02'?: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface CpuState {
|
2020-11-07 16:54:49 +00:00
|
|
|
a: byte,
|
|
|
|
x: byte,
|
|
|
|
y: byte,
|
|
|
|
s: byte,
|
|
|
|
pc: word,
|
|
|
|
sp: byte,
|
|
|
|
cycles: number
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 06:03:05 +00:00
|
|
|
export type Mode =
|
2020-11-07 16:54:49 +00:00
|
|
|
'accumulator' | // A (Accumulator)
|
|
|
|
'implied' | // Implied
|
|
|
|
'immediate' | // # Immediate
|
|
|
|
'absolute' | // a Absolute
|
|
|
|
'zeroPage' | // zp Zero Page
|
|
|
|
'relative' | // r Relative
|
|
|
|
'absoluteX' | // a,X Absolute, X
|
|
|
|
'absoluteY' | // a,Y Absolute, Y
|
|
|
|
'zeroPageX' | // zp,X Zero Page, X
|
|
|
|
'zeroPageY' | // zp,Y Zero Page, Y
|
|
|
|
'absoluteIndirect' | // (a) Indirect
|
|
|
|
'zeroPageXIndirect' | // (zp,X) Zero Page Indexed Indirect
|
|
|
|
'zeroPageIndirectY' | // (zp),Y Zero Page Indexed with Y
|
|
|
|
'zeroPageIndirect' | // (zp),
|
|
|
|
'absoluteXIndirect' | // (a, X),
|
|
|
|
'zeroPage_relative'; // zp, Relative
|
|
|
|
|
2021-03-12 06:03:05 +00:00
|
|
|
export type Modes = Record<Mode, number>;
|
2020-11-07 16:54:49 +00:00
|
|
|
|
|
|
|
/** Addressing mode name to instruction size mapping. */
|
2021-03-12 06:03:05 +00:00
|
|
|
export const sizes: Modes = {
|
2020-11-07 16:54:49 +00:00
|
|
|
accumulator: 1,
|
2020-11-24 16:48:14 +00:00
|
|
|
implied: 1,
|
|
|
|
immediate: 2,
|
|
|
|
absolute: 3,
|
|
|
|
zeroPage: 2,
|
|
|
|
relative: 2,
|
2020-11-07 16:54:49 +00:00
|
|
|
|
2020-11-24 16:48:14 +00:00
|
|
|
absoluteX: 3,
|
|
|
|
absoluteY: 3,
|
|
|
|
zeroPageX: 2,
|
|
|
|
zeroPageY: 2,
|
2020-11-07 16:54:49 +00:00
|
|
|
|
2020-11-24 16:48:14 +00:00
|
|
|
absoluteIndirect: 3,
|
|
|
|
zeroPageXIndirect: 2,
|
|
|
|
zeroPageIndirectY: 2,
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
|
|
|
|
/* 65c02 */
|
2020-11-24 16:48:14 +00:00
|
|
|
zeroPageIndirect: 2,
|
|
|
|
absoluteXIndirect: 3,
|
|
|
|
zeroPage_relative: 3
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/** Status register flag numbers. */
|
2021-03-12 06:03:05 +00:00
|
|
|
export type flag = 0x80 | 0x40 | 0x20 | 0x10 | 0x08 | 0x04 | 0x02 | 0x01;
|
|
|
|
|
|
|
|
export type DebugInfo = {
|
|
|
|
pc: word,
|
|
|
|
ar: byte,
|
|
|
|
xr: byte,
|
|
|
|
yr: byte,
|
|
|
|
sr: byte,
|
|
|
|
sp: byte,
|
|
|
|
cmd: byte[],
|
|
|
|
};
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
|
|
|
|
/** Flags to status byte mask. */
|
2021-03-12 06:03:05 +00:00
|
|
|
export const flags: { [key: string]: flag } = {
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
N: 0x80, // Negative
|
|
|
|
V: 0x40, // oVerflow
|
|
|
|
B: 0x10, // Break
|
|
|
|
D: 0x08, // Decimal
|
|
|
|
I: 0x04, // Interrupt
|
|
|
|
Z: 0x02, // Zero
|
|
|
|
C: 0x01 // Carry
|
|
|
|
};
|
|
|
|
|
|
|
|
/** CPU-referenced memory locations. */
|
|
|
|
const loc = {
|
|
|
|
STACK: 0x100,
|
|
|
|
NMI: 0xFFFA,
|
|
|
|
RESET: 0xFFFC,
|
|
|
|
BRK: 0xFFFE
|
|
|
|
};
|
|
|
|
|
2021-03-06 23:04:13 +00:00
|
|
|
interface ResettablePageHandler extends MemoryPages {
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
reset(): void;
|
|
|
|
}
|
|
|
|
|
2021-03-06 23:04:13 +00:00
|
|
|
function isResettablePageHandler(pageHandler: MemoryPages | ResettablePageHandler): pageHandler is ResettablePageHandler {
|
2020-11-24 16:48:14 +00:00
|
|
|
return (pageHandler as ResettablePageHandler).reset !== undefined;
|
|
|
|
}
|
|
|
|
|
2021-03-06 23:04:13 +00:00
|
|
|
const BLANK_PAGE: Memory = {
|
2020-11-24 16:48:14 +00:00
|
|
|
read: function () { return 0; },
|
|
|
|
write: function () { }
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
interface Opts {
|
|
|
|
rwm?: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
type ReadFn = () => byte;
|
|
|
|
type WriteFn = (val: byte) => void;
|
|
|
|
type ReadAddrFn = (opts?: Opts) => word;
|
2020-11-07 16:54:49 +00:00
|
|
|
type ImpliedFn = () => void
|
|
|
|
|
2020-11-16 02:51:05 +00:00
|
|
|
interface Instruction<T = any> {
|
2020-11-07 16:54:49 +00:00
|
|
|
name: string
|
2020-11-16 02:51:05 +00:00
|
|
|
mode: Mode
|
2020-11-07 16:54:49 +00:00
|
|
|
op: (fn: T) => void
|
|
|
|
modeFn: T
|
|
|
|
}
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
|
2020-11-16 02:51:05 +00:00
|
|
|
type StrictInstruction =
|
|
|
|
Instruction<ReadFn> |
|
|
|
|
Instruction<WriteFn> |
|
|
|
|
Instruction<ReadAddrFn> |
|
|
|
|
Instruction<ImpliedFn> |
|
|
|
|
Instruction<flag> |
|
2020-12-29 14:40:58 +00:00
|
|
|
Instruction<flag|0> |
|
2020-11-16 02:51:05 +00:00
|
|
|
Instruction<byte>
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
|
2020-11-16 02:51:05 +00:00
|
|
|
type Instructions = Record<byte, StrictInstruction>
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
|
2020-11-16 02:51:05 +00:00
|
|
|
type callback = (cpu: CPU6502) => void;
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
|
|
|
|
export default class CPU6502 {
|
2020-12-29 14:40:58 +00:00
|
|
|
private readonly is65C02: boolean;
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
|
|
|
|
/* Registers */
|
2021-03-12 06:03:05 +00:00
|
|
|
private pc: word = 0; // Program Counter
|
|
|
|
private sr: byte = 0x20; // Process Status Register
|
|
|
|
private ar: byte = 0; // Accumulator
|
|
|
|
private xr: byte = 0; // X Register
|
|
|
|
private yr: byte = 0; // Y Register
|
|
|
|
private sp: byte = 0xff; // Stack Pointer
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
|
2021-03-06 23:04:13 +00:00
|
|
|
private memPages: Memory[] = new Array(0x100);
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
private resetHandlers: ResettablePageHandler[] = [];
|
|
|
|
private cycles = 0;
|
|
|
|
private sync = false;
|
|
|
|
|
2020-11-07 16:54:49 +00:00
|
|
|
private readonly opary: Instruction[];
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
|
|
|
|
constructor(options: CpuOptions = {}) {
|
|
|
|
this.is65C02 = options['65C02'] ? true : false;
|
|
|
|
|
2020-11-24 16:48:14 +00:00
|
|
|
this.memPages.fill(BLANK_PAGE);
|
|
|
|
this.memPages.fill(BLANK_PAGE);
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
|
|
|
|
// Create this CPU's instruction table
|
2020-11-07 16:54:49 +00:00
|
|
|
|
2020-11-16 02:51:05 +00:00
|
|
|
let ops = { ...this.OPS_6502 };
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
if (this.is65C02) {
|
2020-11-07 16:54:49 +00:00
|
|
|
ops = { ...ops, ...this.OPS_65C02 };
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Certain browsers benefit from using arrays over maps
|
2020-11-16 02:51:05 +00:00
|
|
|
const opary: Instruction[] = new Array(0x100);
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
|
|
|
|
for (let idx = 0; idx < 0x100; idx++) {
|
2020-11-07 23:49:05 +00:00
|
|
|
opary[idx] = ops[idx] || this.unknown(idx);
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
}
|
|
|
|
this.opary = opary;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set or clears `f` in the status register. `f` must be a byte with a
|
|
|
|
* single bit set.
|
|
|
|
*/
|
2020-12-29 14:40:58 +00:00
|
|
|
private setFlag(f: flag, on: boolean) {
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
this.sr = on ? (this.sr | f) : (this.sr & ~f);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Updates the status register's zero flag and negative flag. */
|
|
|
|
private testNZ(val: byte) {
|
|
|
|
this.sr = val === 0 ? (this.sr | flags.Z) : (this.sr & ~flags.Z);
|
|
|
|
this.sr = (val & 0x80) ? (this.sr | flags.N) : (this.sr & ~flags.N);
|
|
|
|
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Updates the status register's zero flag. */
|
|
|
|
private testZ(val: byte) {
|
|
|
|
this.sr = val === 0 ? (this.sr | flags.Z) : (this.sr & ~flags.Z);
|
|
|
|
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns `a + b`, unless `sub` is true, in which case it performs
|
|
|
|
* `a - b`. The status register is updated according to the result.
|
|
|
|
*/
|
|
|
|
private add(a: byte, b: byte, sub: boolean) {
|
|
|
|
// KEGS
|
2020-11-07 23:49:05 +00:00
|
|
|
let c, v;
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
if ((this.sr & flags.D) !== 0) {
|
|
|
|
// BCD
|
|
|
|
c = (a & 0x0f) + (b & 0x0f) + (this.sr & flags.C);
|
|
|
|
if (sub) {
|
|
|
|
if (c < 0x10)
|
|
|
|
c = (c - 0x06) & 0x0f;
|
|
|
|
c += (a & 0xf0) + (b & 0xf0);
|
|
|
|
v = (c >> 1) ^ c;
|
|
|
|
if (c < 0x100)
|
|
|
|
c = (c + 0xa0) & 0xff;
|
|
|
|
} else {
|
|
|
|
if (c > 0x09)
|
|
|
|
c = (c - 0x0a) | 0x10; // carry to MSN
|
|
|
|
c += (a & 0xf0) + (b & 0xf0);
|
|
|
|
v = (c >> 1) ^ c;
|
|
|
|
if (c > 0x99)
|
|
|
|
c += 0x60;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
c = a + b + (this.sr & flags.C);
|
|
|
|
v = (c ^ a) & 0x80;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (((a ^ b) & 0x80) !== 0) {
|
|
|
|
v = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.setFlag(flags.C, c > 0xff);
|
|
|
|
this.setFlag(flags.V, !!v);
|
|
|
|
|
|
|
|
return this.testNZ(c & 0xff);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Increments `a` and returns the value, setting the status register. */
|
|
|
|
private increment(a: byte) {
|
|
|
|
return this.testNZ((a + 0x01) & 0xff);
|
|
|
|
}
|
|
|
|
|
|
|
|
private decrement(a: byte) {
|
|
|
|
return this.testNZ((a + 0xff) & 0xff);
|
|
|
|
}
|
|
|
|
|
|
|
|
private readBytePC(): byte {
|
2020-11-07 23:49:05 +00:00
|
|
|
const addr = this.pc,
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
page = addr >> 8,
|
|
|
|
off = addr & 0xff;
|
|
|
|
|
2020-11-24 16:48:14 +00:00
|
|
|
const result = this.memPages[page].read(page, off);
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
|
|
|
|
this.pc = (this.pc + 1) & 0xffff;
|
|
|
|
|
|
|
|
this.cycles++;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
private readByte(addr: word): byte {
|
2020-11-07 23:49:05 +00:00
|
|
|
const page = addr >> 8,
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
off = addr & 0xff;
|
|
|
|
|
2020-11-24 16:48:14 +00:00
|
|
|
const result = this.memPages[page].read(page, off);
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
|
|
|
|
this.cycles++;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
private readByteDebug(addr: word) {
|
2020-11-07 23:49:05 +00:00
|
|
|
const page = addr >> 8,
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
off = addr & 0xff;
|
|
|
|
|
2020-11-24 16:48:14 +00:00
|
|
|
return this.memPages[page].read(page, off);
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private writeByte(addr: word, val: byte) {
|
2020-11-07 23:49:05 +00:00
|
|
|
const page = addr >> 8,
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
off = addr & 0xff;
|
|
|
|
|
2020-11-24 16:48:14 +00:00
|
|
|
this.memPages[page].write(page, off, val);
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
|
|
|
|
this.cycles++;
|
|
|
|
}
|
|
|
|
|
|
|
|
private readWord(addr: word): word {
|
|
|
|
return this.readByte(addr) | (this.readByte(addr + 1) << 8);
|
|
|
|
}
|
|
|
|
|
|
|
|
private readWordPC(): word {
|
|
|
|
return this.readBytePC() | (this.readBytePC() << 8);
|
|
|
|
}
|
|
|
|
|
|
|
|
private readZPWord(addr: byte): word {
|
2020-11-07 23:49:05 +00:00
|
|
|
const lsb = this.readByte(addr & 0xff);
|
|
|
|
const msb = this.readByte((addr + 1) & 0xff);
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
|
|
|
|
return (msb << 8) | lsb;
|
|
|
|
}
|
|
|
|
|
|
|
|
private pushByte(val: byte) {
|
|
|
|
this.writeByte(loc.STACK | this.sp, val);
|
|
|
|
this.sp = (this.sp + 0xff) & 0xff;
|
|
|
|
}
|
|
|
|
|
|
|
|
private pushWord(val: word) {
|
|
|
|
this.pushByte(val >> 8);
|
|
|
|
this.pushByte(val & 0xff);
|
|
|
|
}
|
|
|
|
|
|
|
|
private pullByte(): byte {
|
|
|
|
this.sp = (this.sp + 0x01) & 0xff;
|
|
|
|
return this.readByte(loc.STACK | this.sp);
|
|
|
|
}
|
|
|
|
|
|
|
|
private pullWordRaw(): word {
|
2020-11-07 23:49:05 +00:00
|
|
|
const lsb = this.pullByte();
|
|
|
|
const msb = this.pullByte();
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
|
|
|
|
return (msb << 8) | lsb;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2020-11-07 16:54:49 +00:00
|
|
|
* Implied function
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
*/
|
|
|
|
|
2020-11-07 16:54:49 +00:00
|
|
|
implied() {
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
}
|
|
|
|
|
2020-11-07 16:54:49 +00:00
|
|
|
/*
|
|
|
|
* Read functions
|
|
|
|
*/
|
|
|
|
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
// #$00
|
2020-11-07 16:54:49 +00:00
|
|
|
readImmediate = (): byte => {
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
return this.readBytePC();
|
|
|
|
}
|
|
|
|
|
|
|
|
// $0000
|
2020-11-07 16:54:49 +00:00
|
|
|
readAbsolute = (): byte => {
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
return this.readByte(this.readWordPC());
|
|
|
|
}
|
|
|
|
|
|
|
|
// $00
|
2020-11-16 02:51:05 +00:00
|
|
|
readZeroPage = (): byte => {
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
return this.readByte(this.readBytePC());
|
|
|
|
}
|
|
|
|
|
|
|
|
// $0000,X
|
2020-11-16 02:51:05 +00:00
|
|
|
readAbsoluteX = (): byte => {
|
2020-11-07 23:49:05 +00:00
|
|
|
let addr = this.readWordPC();
|
|
|
|
const oldPage = addr >> 8;
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
addr = (addr + this.xr) & 0xffff;
|
2020-11-07 23:49:05 +00:00
|
|
|
const newPage = addr >> 8;
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
if (newPage != oldPage) {
|
2020-11-07 23:49:05 +00:00
|
|
|
const off = addr & 0xff;
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
this.readByte(oldPage << 8 | off);
|
|
|
|
}
|
|
|
|
return this.readByte(addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
// $0000,Y
|
2020-11-07 16:54:49 +00:00
|
|
|
readAbsoluteY = (): byte => {
|
2020-11-07 23:49:05 +00:00
|
|
|
let addr = this.readWordPC();
|
|
|
|
const oldPage = addr >> 8;
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
addr = (addr + this.yr) & 0xffff;
|
2020-11-07 23:49:05 +00:00
|
|
|
const newPage = addr >> 8;
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
if (newPage != oldPage) {
|
2020-11-07 23:49:05 +00:00
|
|
|
const off = addr & 0xff;
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
this.readByte(oldPage << 8 | off);
|
|
|
|
}
|
|
|
|
return this.readByte(addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
// $00,X
|
2020-11-07 16:54:49 +00:00
|
|
|
readZeroPageX = (): byte => {
|
2020-11-07 23:49:05 +00:00
|
|
|
const zpAddr = this.readBytePC();
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
this.readByte(zpAddr);
|
|
|
|
return this.readByte((zpAddr + this.xr) & 0xff);
|
|
|
|
}
|
|
|
|
|
|
|
|
// $00,Y
|
2020-11-07 16:54:49 +00:00
|
|
|
readZeroPageY = (): byte => {
|
2020-11-07 23:49:05 +00:00
|
|
|
const zpAddr = this.readBytePC();
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
this.readByte(zpAddr);
|
|
|
|
return this.readByte((zpAddr + this.yr) & 0xff);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ($00,X)
|
2020-11-07 16:54:49 +00:00
|
|
|
readZeroPageXIndirect = (): byte => {
|
2020-11-07 23:49:05 +00:00
|
|
|
const zpAddr = this.readBytePC();
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
this.readByte(zpAddr);
|
2020-11-07 23:49:05 +00:00
|
|
|
const addr = this.readZPWord((zpAddr + this.xr) & 0xff);
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
return this.readByte(addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ($00),Y
|
2020-11-07 16:54:49 +00:00
|
|
|
readZeroPageIndirectY = (): byte => {
|
2020-11-07 23:49:05 +00:00
|
|
|
let addr = this.readZPWord(this.readBytePC());
|
|
|
|
const oldPage = addr >> 8;
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
addr = (addr + this.yr) & 0xffff;
|
2020-11-07 23:49:05 +00:00
|
|
|
const newPage = addr >> 8;
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
if (newPage != oldPage) {
|
2020-11-07 23:49:05 +00:00
|
|
|
const off = addr & 0xff;
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
this.readByte(oldPage << 8 | off);
|
|
|
|
}
|
|
|
|
return this.readByte(addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ($00) (65C02)
|
2020-11-07 16:54:49 +00:00
|
|
|
readZeroPageIndirect = (): byte => {
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
return this.readByte(this.readZPWord(this.readBytePC()));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Write Functions
|
|
|
|
*/
|
|
|
|
|
|
|
|
// $0000
|
2020-11-07 16:54:49 +00:00
|
|
|
writeAbsolute = (val: byte) => {
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
this.writeByte(this.readWordPC(), val);
|
|
|
|
}
|
|
|
|
|
|
|
|
// $00
|
2020-11-07 16:54:49 +00:00
|
|
|
writeZeroPage = (val: byte) => {
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
this.writeByte(this.readBytePC(), val);
|
|
|
|
}
|
|
|
|
|
|
|
|
// $0000,X
|
2020-11-07 16:54:49 +00:00
|
|
|
writeAbsoluteX = (val: byte) => {
|
2020-11-07 23:49:05 +00:00
|
|
|
let addr = this.readWordPC();
|
|
|
|
const oldPage = addr >> 8;
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
addr = (addr + this.xr) & 0xffff;
|
2020-11-07 23:49:05 +00:00
|
|
|
const off = addr & 0xff;
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
this.readByte(oldPage << 8 | off);
|
|
|
|
this.writeByte(addr, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
// $0000,Y
|
2020-11-07 16:54:49 +00:00
|
|
|
writeAbsoluteY = (val: byte) => {
|
2020-11-07 23:49:05 +00:00
|
|
|
let addr = this.readWordPC();
|
|
|
|
const oldPage = addr >> 8;
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
addr = (addr + this.yr) & 0xffff;
|
2020-11-07 23:49:05 +00:00
|
|
|
const off = addr & 0xff;
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
this.readByte(oldPage << 8 | off);
|
|
|
|
this.writeByte(addr, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
// $00,X
|
2020-11-07 16:54:49 +00:00
|
|
|
writeZeroPageX = (val: byte) => {
|
2020-11-07 23:49:05 +00:00
|
|
|
const zpAddr = this.readBytePC();
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
this.readByte(zpAddr);
|
|
|
|
this.writeByte((zpAddr + this.xr) & 0xff, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
// $00,Y
|
2020-11-07 16:54:49 +00:00
|
|
|
writeZeroPageY = (val: byte) => {
|
2020-11-07 23:49:05 +00:00
|
|
|
const zpAddr = this.readBytePC();
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
this.readByte(zpAddr);
|
|
|
|
this.writeByte((zpAddr + this.yr) & 0xff, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ($00,X)
|
2020-11-07 16:54:49 +00:00
|
|
|
writeZeroPageXIndirect = (val: byte) => {
|
2020-11-07 23:49:05 +00:00
|
|
|
const zpAddr = this.readBytePC();
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
this.readByte(zpAddr);
|
2020-11-07 23:49:05 +00:00
|
|
|
const addr = this.readZPWord((zpAddr + this.xr) & 0xff);
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
this.writeByte(addr, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ($00),Y
|
2020-11-07 16:54:49 +00:00
|
|
|
writeZeroPageIndirectY = (val: byte) => {
|
2020-11-07 23:49:05 +00:00
|
|
|
let addr = this.readZPWord(this.readBytePC());
|
|
|
|
const oldPage = addr >> 8;
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
addr = (addr + this.yr) & 0xffff;
|
2020-11-07 23:49:05 +00:00
|
|
|
const off = addr & 0xff;
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
this.readByte(oldPage << 8 | off);
|
|
|
|
this.writeByte(addr, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ($00) (65C02)
|
2020-11-07 16:54:49 +00:00
|
|
|
writeZeroPageIndirect = (val: byte) => {
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
this.writeByte(this.readZPWord(this.readBytePC()), val);
|
|
|
|
}
|
|
|
|
|
|
|
|
// $00
|
2020-11-16 02:51:05 +00:00
|
|
|
readAddrZeroPage = () => {
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
return this.readBytePC();
|
|
|
|
}
|
|
|
|
|
|
|
|
// $00,X
|
2020-11-07 16:54:49 +00:00
|
|
|
readAddrZeroPageX = () => {
|
2020-11-07 23:49:05 +00:00
|
|
|
const zpAddr = this.readBytePC();
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
this.readByte(zpAddr);
|
|
|
|
return (zpAddr + this.xr) & 0xff;
|
|
|
|
}
|
|
|
|
|
|
|
|
// $0000 (65C02)
|
2020-11-07 16:54:49 +00:00
|
|
|
readAddrAbsolute = (): word => {
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
return this.readWordPC();
|
|
|
|
}
|
|
|
|
|
|
|
|
// ($0000) (6502)
|
2020-11-07 16:54:49 +00:00
|
|
|
readAddrAbsoluteIndirectBug = (): word => {
|
2020-11-07 23:49:05 +00:00
|
|
|
const addr = this.readWordPC();
|
|
|
|
const page = addr & 0xff00;
|
|
|
|
const off = addr & 0x00ff;
|
|
|
|
const lsb = this.readByte(addr);
|
|
|
|
const msb = this.readByte(page | ((off + 0x01) & 0xff));
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
return msb << 8 | lsb;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ($0000) (65C02)
|
2020-11-07 16:54:49 +00:00
|
|
|
readAddrAbsoluteIndirect = (): word => {
|
2020-11-07 23:49:05 +00:00
|
|
|
const lsb = this.readBytePC();
|
|
|
|
const msb = this.readBytePC();
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
this.readByte(this.pc);
|
|
|
|
return this.readWord(msb << 8 | lsb);
|
|
|
|
}
|
|
|
|
|
|
|
|
// $0000,X
|
2020-11-07 16:54:49 +00:00
|
|
|
readAddrAbsoluteX = (opts: Opts = {}): word => {
|
2020-11-07 23:49:05 +00:00
|
|
|
const addr = this.readWordPC();
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
if (!this.is65C02 || opts.rwm) {
|
|
|
|
this.readByte(addr);
|
|
|
|
} else {
|
|
|
|
this.readByte(this.pc);
|
|
|
|
}
|
|
|
|
return (addr + this.xr) & 0xffff;
|
|
|
|
}
|
|
|
|
|
|
|
|
// $(0000,X) (65C02)
|
2020-11-07 16:54:49 +00:00
|
|
|
readAddrAbsoluteXIndirect = (): word => {
|
2020-11-07 23:49:05 +00:00
|
|
|
const address = this.readWordPC();
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
this.readByte(this.pc);
|
|
|
|
return this.readWord((address + this.xr) & 0xffff);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Break */
|
2020-11-07 16:54:49 +00:00
|
|
|
brk = (readFn: ReadFn) => {
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
readFn();
|
|
|
|
this.pushWord(this.pc);
|
|
|
|
this.pushByte(this.sr | flags.B);
|
|
|
|
if (this.is65C02) {
|
|
|
|
this.setFlag(flags.D, false);
|
|
|
|
}
|
|
|
|
this.setFlag(flags.I, true);
|
|
|
|
this.pc = this.readWord(loc.BRK);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Load Accumulator */
|
2020-11-07 16:54:49 +00:00
|
|
|
lda = (readFn: ReadFn) => {
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
this.ar = this.testNZ(readFn());
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Load X Register */
|
2020-11-07 16:54:49 +00:00
|
|
|
ldx = (readFn: ReadFn) => {
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
this.xr = this.testNZ(readFn());
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Load Y Register */
|
2020-11-07 16:54:49 +00:00
|
|
|
ldy = (readFn: ReadFn) => {
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
this.yr = this.testNZ(readFn());
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Store Accumulator */
|
2020-11-07 16:54:49 +00:00
|
|
|
sta = (writeFn: WriteFn) => {
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
writeFn(this.ar);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Store X Register */
|
2020-11-07 16:54:49 +00:00
|
|
|
stx = (writeFn: WriteFn) => {
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
writeFn(this.xr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Store Y Register */
|
2020-11-07 16:54:49 +00:00
|
|
|
sty = (writeFn: WriteFn) => {
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
writeFn(this.yr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Store Zero */
|
2020-11-07 16:54:49 +00:00
|
|
|
stz = (writeFn: WriteFn) => {
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
writeFn(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Add with Carry */
|
2020-11-07 16:54:49 +00:00
|
|
|
adc = (readFn: ReadFn) => {
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
this.ar = this.add(this.ar, readFn(), /* sub= */ false);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Subtract with Carry */
|
2020-11-07 16:54:49 +00:00
|
|
|
sbc = (readFn: ReadFn) => {
|
2020-11-16 02:51:05 +00:00
|
|
|
this.ar = this.add(this.ar, readFn() ^ 0xff, /* sub= */ true);
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Increment Memory */
|
2020-11-07 16:54:49 +00:00
|
|
|
incA = () => {
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
this.readByte(this.pc);
|
|
|
|
this.ar = this.increment(this.ar);
|
|
|
|
}
|
|
|
|
|
2020-11-07 16:54:49 +00:00
|
|
|
inc = (readAddrFn: ReadAddrFn) => {
|
2020-11-24 16:48:14 +00:00
|
|
|
const addr = readAddrFn({ rwm: true });
|
2020-11-07 23:49:05 +00:00
|
|
|
const oldVal = this.readByte(addr);
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
this.writeByte(addr, oldVal);
|
2020-11-07 23:49:05 +00:00
|
|
|
const val = this.increment(oldVal);
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
this.writeByte(addr, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Increment X */
|
2020-11-07 16:54:49 +00:00
|
|
|
inx = () => {
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
this.readByte(this.pc);
|
|
|
|
this.xr = this.increment(this.xr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Increment Y */
|
2020-11-07 16:54:49 +00:00
|
|
|
iny = () => {
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
this.readByte(this.pc);
|
|
|
|
this.yr = this.increment(this.yr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Decrement Memory */
|
2020-11-07 16:54:49 +00:00
|
|
|
decA = () => {
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
this.readByte(this.pc);
|
|
|
|
this.ar = this.decrement(this.ar);
|
|
|
|
}
|
|
|
|
|
2020-11-07 16:54:49 +00:00
|
|
|
dec = (readAddrFn: ReadAddrFn) => {
|
2020-11-24 16:48:14 +00:00
|
|
|
const addr = readAddrFn({ rwm: true });
|
2020-11-07 23:49:05 +00:00
|
|
|
const oldVal = this.readByte(addr);
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
this.writeByte(addr, oldVal);
|
2020-11-07 23:49:05 +00:00
|
|
|
const val = this.decrement(oldVal);
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
this.writeByte(addr, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Decrement X */
|
2020-11-07 16:54:49 +00:00
|
|
|
dex = () => {
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
this.readByte(this.pc);
|
|
|
|
this.xr = this.decrement(this.xr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Decrement Y */
|
2020-11-07 16:54:49 +00:00
|
|
|
dey = () => {
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
this.readByte(this.pc);
|
|
|
|
this.yr = this.decrement(this.yr);
|
|
|
|
}
|
|
|
|
|
2020-11-07 16:54:49 +00:00
|
|
|
shiftLeft = (val: byte) => {
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
this.setFlag(flags.C, !!(val & 0x80));
|
|
|
|
return this.testNZ((val << 1) & 0xff);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Arithmetic Shift Left */
|
2020-11-07 16:54:49 +00:00
|
|
|
aslA = () => {
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
this.readByte(this.pc);
|
|
|
|
this.ar = this.shiftLeft(this.ar);
|
|
|
|
}
|
|
|
|
|
2020-11-07 16:54:49 +00:00
|
|
|
asl = (readAddrFn: ReadAddrFn) => {
|
2020-11-24 16:48:14 +00:00
|
|
|
const addr = readAddrFn({ rwm: true });
|
2020-11-07 23:49:05 +00:00
|
|
|
const oldVal = this.readByte(addr);
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
this.writeByte(addr, oldVal);
|
2020-11-07 23:49:05 +00:00
|
|
|
const val = this.shiftLeft(oldVal);
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
this.writeByte(addr, val);
|
|
|
|
}
|
|
|
|
|
2020-11-07 16:54:49 +00:00
|
|
|
shiftRight = (val: byte) => {
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
this.setFlag(flags.C, !!(val & 0x01));
|
|
|
|
return this.testNZ(val >> 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Logical Shift Right */
|
2020-11-07 16:54:49 +00:00
|
|
|
lsrA = () => {
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
this.readByte(this.pc);
|
|
|
|
this.ar = this.shiftRight(this.ar);
|
|
|
|
}
|
|
|
|
|
2020-11-07 16:54:49 +00:00
|
|
|
lsr = (readAddrFn: ReadAddrFn) => {
|
2020-11-24 16:48:14 +00:00
|
|
|
const addr = readAddrFn({ rwm: true });
|
2020-11-07 23:49:05 +00:00
|
|
|
const oldVal = this.readByte(addr);
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
this.writeByte(addr, oldVal);
|
2020-11-07 23:49:05 +00:00
|
|
|
const val = this.shiftRight(oldVal);
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
this.writeByte(addr, val);
|
|
|
|
}
|
|
|
|
|
2020-11-07 16:54:49 +00:00
|
|
|
rotateLeft = (val: byte) => {
|
2020-11-07 23:49:05 +00:00
|
|
|
const c = (this.sr & flags.C);
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
this.setFlag(flags.C, !!(val & 0x80));
|
|
|
|
return this.testNZ(((val << 1) | (c ? 0x01 : 0x00)) & 0xff);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Rotate Left */
|
2020-11-07 16:54:49 +00:00
|
|
|
rolA = () => {
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
this.readByte(this.pc);
|
|
|
|
this.ar = this.rotateLeft(this.ar);
|
|
|
|
}
|
|
|
|
|
2020-11-07 16:54:49 +00:00
|
|
|
rol = (readAddrFn: ReadAddrFn) => {
|
2020-11-24 16:48:14 +00:00
|
|
|
const addr = readAddrFn({ rwm: true });
|
2020-11-07 23:49:05 +00:00
|
|
|
const oldVal = this.readByte(addr);
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
this.writeByte(addr, oldVal);
|
2020-11-07 23:49:05 +00:00
|
|
|
const val = this.rotateLeft(oldVal);
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
this.writeByte(addr, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
private rotateRight(a: byte) {
|
2020-11-07 23:49:05 +00:00
|
|
|
const c = (this.sr & flags.C);
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
this.setFlag(flags.C, !!(a & 0x01));
|
|
|
|
return this.testNZ((a >> 1) | (c ? 0x80 : 0x00));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Rotate Right */
|
2020-11-07 16:54:49 +00:00
|
|
|
rorA = () => {
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
this.readByte(this.pc);
|
|
|
|
this.ar = this.rotateRight(this.ar);
|
|
|
|
}
|
|
|
|
|
2020-11-07 16:54:49 +00:00
|
|
|
ror = (readAddrFn: ReadAddrFn) => {
|
2020-11-24 16:48:14 +00:00
|
|
|
const addr = readAddrFn({ rwm: true });
|
2020-11-07 23:49:05 +00:00
|
|
|
const oldVal = this.readByte(addr);
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
this.writeByte(addr, oldVal);
|
2020-11-07 23:49:05 +00:00
|
|
|
const val = this.rotateRight(oldVal);
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
this.writeByte(addr, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Logical And Accumulator */
|
2020-11-07 16:54:49 +00:00
|
|
|
and = (readFn: ReadFn) => {
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
this.ar = this.testNZ(this.ar & readFn());
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Logical Or Accumulator */
|
2020-11-07 16:54:49 +00:00
|
|
|
ora = (readFn: ReadFn) => {
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
this.ar = this.testNZ(this.ar | readFn());
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Logical Exclusive Or Accumulator */
|
2020-11-07 16:54:49 +00:00
|
|
|
eor = (readFn: ReadFn) => {
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
this.ar = this.testNZ(this.ar ^ readFn());
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Reset Bit */
|
|
|
|
|
2020-11-07 16:54:49 +00:00
|
|
|
rmb = (b: byte) => {
|
2020-11-07 23:49:05 +00:00
|
|
|
const bit = (0x1 << b) ^ 0xFF;
|
|
|
|
const addr = this.readBytePC();
|
|
|
|
let val = this.readByte(addr);
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
this.readByte(addr);
|
|
|
|
val &= bit;
|
|
|
|
this.writeByte(addr, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set Bit */
|
|
|
|
|
2020-11-07 16:54:49 +00:00
|
|
|
smb = (b: byte) => {
|
2020-11-07 23:49:05 +00:00
|
|
|
const bit = 0x1 << b;
|
|
|
|
const addr = this.readBytePC();
|
|
|
|
let val = this.readByte(addr);
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
this.readByte(addr);
|
|
|
|
val |= bit;
|
|
|
|
this.writeByte(addr, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Test and Reset Bits */
|
2020-11-07 16:54:49 +00:00
|
|
|
trb = (readAddrFn: ReadAddrFn) => {
|
2020-11-07 23:49:05 +00:00
|
|
|
const addr = readAddrFn();
|
|
|
|
const val = this.readByte(addr);
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
this.testZ(val & this.ar);
|
|
|
|
this.readByte(addr);
|
|
|
|
this.writeByte(addr, val & ~this.ar);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Test and Set Bits */
|
2020-11-07 16:54:49 +00:00
|
|
|
tsb = (readAddrFn: ReadAddrFn) => {
|
2020-11-07 23:49:05 +00:00
|
|
|
const addr = readAddrFn();
|
|
|
|
const val = this.readByte(addr);
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
this.testZ(val & this.ar);
|
|
|
|
this.readByte(addr);
|
|
|
|
this.writeByte(addr, val | this.ar);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Bit */
|
2020-11-07 16:54:49 +00:00
|
|
|
bit = (readFn: ReadFn) => {
|
2020-11-07 23:49:05 +00:00
|
|
|
const val = readFn();
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
this.setFlag(flags.Z, (val & this.ar) === 0);
|
|
|
|
this.setFlag(flags.N, !!(val & 0x80));
|
|
|
|
this.setFlag(flags.V, !!(val & 0x40));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Bit Immediate*/
|
2020-11-07 16:54:49 +00:00
|
|
|
bitI = (readFn: ReadFn) => {
|
2020-11-07 23:49:05 +00:00
|
|
|
const val = readFn();
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
this.setFlag(flags.Z, (val & this.ar) === 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
private compare(a: byte, b: byte) {
|
|
|
|
b = (b ^ 0xff);
|
2020-11-07 23:49:05 +00:00
|
|
|
const c = a + b + 1;
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
this.setFlag(flags.C, c > 0xff);
|
|
|
|
this.testNZ(c & 0xff);
|
|
|
|
}
|
|
|
|
|
2020-11-07 16:54:49 +00:00
|
|
|
cmp = (readFn: ReadFn) => {
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
this.compare(this.ar, readFn());
|
|
|
|
}
|
|
|
|
|
2020-11-07 16:54:49 +00:00
|
|
|
cpx = (readFn: ReadFn) => {
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
this.compare(this.xr, readFn());
|
|
|
|
}
|
|
|
|
|
2020-11-07 16:54:49 +00:00
|
|
|
cpy = (readFn: ReadFn) => {
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
this.compare(this.yr, readFn());
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Branches */
|
2020-11-07 16:54:49 +00:00
|
|
|
brs = (f: flag) => {
|
2020-11-07 23:49:05 +00:00
|
|
|
const off = this.readBytePC(); // changes pc
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
if ((f & this.sr) !== 0) {
|
|
|
|
this.readByte(this.pc);
|
2020-11-07 23:49:05 +00:00
|
|
|
const oldPage = this.pc >> 8;
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
this.pc += off > 127 ? off - 256 : off;
|
2021-02-22 05:26:07 +00:00
|
|
|
this.pc &= 0xffff;
|
2020-11-07 23:49:05 +00:00
|
|
|
const newPage = this.pc >> 8;
|
|
|
|
const newOff = this.pc & 0xff;
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
if (newPage != oldPage) this.readByte(oldPage << 8 | newOff);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-29 14:40:58 +00:00
|
|
|
brc = (f: flag|0) => {
|
2020-11-07 23:49:05 +00:00
|
|
|
const off = this.readBytePC(); // changes pc
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
if ((f & this.sr) === 0) {
|
|
|
|
this.readByte(this.pc);
|
2020-11-07 23:49:05 +00:00
|
|
|
const oldPage = this.pc >> 8;
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
this.pc += off > 127 ? off - 256 : off;
|
2021-02-22 05:26:07 +00:00
|
|
|
this.pc &= 0xffff;
|
2020-11-07 23:49:05 +00:00
|
|
|
const newPage = this.pc >> 8;
|
|
|
|
const newOff = this.pc & 0xff;
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
if (newPage != oldPage) this.readByte(oldPage << 8 | newOff);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* WDC 65C02 branches */
|
|
|
|
|
2020-11-07 23:49:05 +00:00
|
|
|
bbr = (b: byte) => {
|
|
|
|
const zpAddr = this.readBytePC();
|
|
|
|
const val = this.readByte(zpAddr);
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
this.readByte(zpAddr);
|
2020-11-07 23:49:05 +00:00
|
|
|
const off = this.readBytePC(); // changes pc
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
|
|
|
|
if (((1 << b) & val) === 0) {
|
2020-11-07 23:49:05 +00:00
|
|
|
const oldPc = this.pc;
|
|
|
|
const oldPage = oldPc >> 8;
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
this.readByte(oldPc);
|
|
|
|
this.pc += off > 127 ? off - 256 : off;
|
2021-02-22 05:26:07 +00:00
|
|
|
this.pc &= 0xffff;
|
2020-11-07 23:49:05 +00:00
|
|
|
const newPage = this.pc >> 8;
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
if (oldPage != newPage) {
|
|
|
|
this.readByte(oldPc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-07 23:49:05 +00:00
|
|
|
bbs = (b: byte) => {
|
|
|
|
const zpAddr = this.readBytePC();
|
|
|
|
const val = this.readByte(zpAddr);
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
this.readByte(zpAddr);
|
2020-11-07 23:49:05 +00:00
|
|
|
const off = this.readBytePC(); // changes pc
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
|
|
|
|
if (((1 << b) & val) !== 0) {
|
2020-11-07 23:49:05 +00:00
|
|
|
const oldPc = this.pc;
|
|
|
|
const oldPage = oldPc >> 8;
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
this.readByte(oldPc);
|
|
|
|
this.pc += off > 127 ? off - 256 : off;
|
2021-02-22 05:26:07 +00:00
|
|
|
this.pc &= 0xffff;
|
2020-11-07 23:49:05 +00:00
|
|
|
const newPage = this.pc >> 8;
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
if (oldPage != newPage) {
|
|
|
|
this.readByte(oldPc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Transfers and stack */
|
2020-11-07 16:54:49 +00:00
|
|
|
tax = () => { this.readByte(this.pc); this.testNZ(this.xr = this.ar); }
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
|
2020-11-07 16:54:49 +00:00
|
|
|
txa = () => { this.readByte(this.pc); this.testNZ(this.ar = this.xr); }
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
|
2020-11-07 16:54:49 +00:00
|
|
|
tay = () => { this.readByte(this.pc); this.testNZ(this.yr = this.ar); }
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
|
2020-11-07 16:54:49 +00:00
|
|
|
tya = () => { this.readByte(this.pc); this.testNZ(this.ar = this.yr); }
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
|
2020-11-07 16:54:49 +00:00
|
|
|
tsx = () => { this.readByte(this.pc); this.testNZ(this.xr = this.sp); }
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
|
2020-11-07 16:54:49 +00:00
|
|
|
txs = () => { this.readByte(this.pc); this.sp = this.xr; }
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
|
2020-11-07 16:54:49 +00:00
|
|
|
pha = () => { this.readByte(this.pc); this.pushByte(this.ar); }
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
|
2020-11-07 16:54:49 +00:00
|
|
|
pla = () => { this.readByte(this.pc); this.readByte(0x0100 | this.sp); this.testNZ(this.ar = this.pullByte()); }
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
|
2020-11-07 16:54:49 +00:00
|
|
|
phx = () => { this.readByte(this.pc); this.pushByte(this.xr); }
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
|
2020-11-24 16:48:14 +00:00
|
|
|
plx = () => { this.readByte(this.pc); this.readByte(0x0100 | this.sp); this.testNZ(this.xr = this.pullByte()); }
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
|
2020-11-07 16:54:49 +00:00
|
|
|
phy = () => { this.readByte(this.pc); this.pushByte(this.yr); }
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
|
2020-11-07 16:54:49 +00:00
|
|
|
ply = () => { this.readByte(this.pc); this.readByte(0x0100 | this.sp); this.testNZ(this.yr = this.pullByte()); }
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
|
2020-11-07 16:54:49 +00:00
|
|
|
php = () => { this.readByte(this.pc); this.pushByte(this.sr | flags.B); }
|
|
|
|
|
|
|
|
plp = () => { this.readByte(this.pc); this.readByte(0x0100 | this.sp); this.sr = (this.pullByte() & ~flags.B) | 0x20; }
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
|
|
|
|
/* Jump */
|
2020-11-07 16:54:49 +00:00
|
|
|
jmp = (readAddrFn: ReadAddrFn) => {
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
this.pc = readAddrFn();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Jump Subroutine */
|
2020-11-07 16:54:49 +00:00
|
|
|
jsr = () => {
|
2020-11-07 23:49:05 +00:00
|
|
|
const lsb = this.readBytePC();
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
this.readByte(0x0100 | this.sp);
|
|
|
|
this.pushWord(this.pc);
|
2020-11-07 23:49:05 +00:00
|
|
|
const msb = this.readBytePC();
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
this.pc = (msb << 8 | lsb) & 0xffff;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return from Subroutine */
|
2020-11-07 16:54:49 +00:00
|
|
|
rts = () => {
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
this.readByte(this.pc);
|
|
|
|
this.readByte(0x0100 | this.sp);
|
2020-11-07 23:49:05 +00:00
|
|
|
const addr = this.pullWordRaw();
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
this.readByte(addr);
|
|
|
|
this.pc = (addr + 1) & 0xffff;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return from Interrupt */
|
2020-11-07 16:54:49 +00:00
|
|
|
rti = () => {
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
this.readByte(this.pc);
|
|
|
|
this.readByte(0x0100 | this.sp);
|
|
|
|
this.sr = this.pullByte() & ~flags.B;
|
|
|
|
this.pc = this.pullWordRaw();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set and Clear */
|
2020-11-07 16:54:49 +00:00
|
|
|
set = (flag: flag) => {
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
this.readByte(this.pc);
|
|
|
|
this.sr |= flag;
|
|
|
|
}
|
|
|
|
|
2020-11-07 16:54:49 +00:00
|
|
|
clr = (flag: flag) => {
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
this.readByte(this.pc);
|
|
|
|
this.sr &= ~flag;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* No-Op */
|
2020-11-16 02:51:05 +00:00
|
|
|
nop = (impliedFn: ImpliedFn) => {
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
this.readByte(this.pc);
|
2020-11-16 02:51:05 +00:00
|
|
|
impliedFn();
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private unknown(b: byte) {
|
2020-11-16 02:51:05 +00:00
|
|
|
let unk: StrictInstruction;
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
|
|
|
|
if (this.is65C02) {
|
2020-11-07 16:54:49 +00:00
|
|
|
unk = {
|
|
|
|
name: 'NOP',
|
|
|
|
op: this.nop,
|
|
|
|
modeFn: this.implied,
|
|
|
|
mode: 'implied',
|
2020-11-07 23:49:05 +00:00
|
|
|
};
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
} else {
|
2020-11-16 02:20:58 +00:00
|
|
|
const cpu = this;
|
2020-11-07 16:54:49 +00:00
|
|
|
unk = {
|
|
|
|
name: '???',
|
2020-11-24 16:48:14 +00:00
|
|
|
op: function (_impliedFn: ImpliedFn) {
|
2020-11-07 23:49:05 +00:00
|
|
|
debug('Unknown OpCode: ' + toHex(b) +
|
2020-11-16 01:54:27 +00:00
|
|
|
' at ' + toHex(cpu.pc - 1, 4));
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
},
|
2020-11-07 16:54:49 +00:00
|
|
|
modeFn: this.implied,
|
|
|
|
mode: 'implied'
|
2020-11-07 23:49:05 +00:00
|
|
|
};
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
}
|
|
|
|
return unk;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-12 06:03:05 +00:00
|
|
|
public step(cb?: callback) {
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
this.sync = true;
|
2020-11-07 23:49:05 +00:00
|
|
|
const op = this.opary[this.readBytePC()];
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
this.sync = false;
|
2020-11-07 16:54:49 +00:00
|
|
|
op.op(op.modeFn);
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
|
2021-03-12 06:03:05 +00:00
|
|
|
cb?.(this);
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 06:03:05 +00:00
|
|
|
public stepN(n: number, cb?: callback) {
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
for (let idx = 0; idx < n; idx++) {
|
|
|
|
this.sync = true;
|
2020-11-07 23:49:05 +00:00
|
|
|
const op = this.opary[this.readBytePC()];
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
this.sync = false;
|
2020-11-07 16:54:49 +00:00
|
|
|
op.op(op.modeFn);
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
|
2021-03-14 00:08:24 +00:00
|
|
|
if (cb?.(this)) {
|
|
|
|
return;
|
|
|
|
}
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public stepCycles(c: number) {
|
2020-11-07 23:49:05 +00:00
|
|
|
const end = this.cycles + c;
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
|
|
|
|
while (this.cycles < end) {
|
|
|
|
this.sync = true;
|
2020-11-07 23:49:05 +00:00
|
|
|
const op = this.opary[this.readBytePC()];
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
this.sync = false;
|
2020-11-07 16:54:49 +00:00
|
|
|
op.op(op.modeFn);
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-12 06:03:05 +00:00
|
|
|
public stepCyclesDebug(c: number, cb?: callback): void {
|
2020-11-07 23:49:05 +00:00
|
|
|
const end = this.cycles + c;
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
|
|
|
|
while (this.cycles < end) {
|
|
|
|
this.sync = true;
|
2020-11-07 23:49:05 +00:00
|
|
|
const op = this.opary[this.readBytePC()];
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
this.sync = false;
|
2020-11-07 16:54:49 +00:00
|
|
|
op.op(op.modeFn);
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
|
2021-03-14 00:08:24 +00:00
|
|
|
if (cb?.(this)) {
|
|
|
|
return;
|
|
|
|
}
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-06 23:04:13 +00:00
|
|
|
public addPageHandler(pho: (MemoryPages | ResettablePageHandler)) {
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
for (let idx = pho.start(); idx <= pho.end(); idx++) {
|
2020-11-24 16:48:14 +00:00
|
|
|
this.memPages[idx] = pho;
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
}
|
|
|
|
if (isResettablePageHandler(pho))
|
|
|
|
this.resetHandlers.push(pho);
|
|
|
|
}
|
|
|
|
|
|
|
|
public reset() {
|
|
|
|
// cycles = 0;
|
|
|
|
this.sr = 0x20;
|
|
|
|
this.sp = 0xff;
|
|
|
|
this.ar = 0;
|
|
|
|
this.yr = 0;
|
|
|
|
this.xr = 0;
|
|
|
|
this.pc = this.readWord(loc.RESET);
|
|
|
|
|
|
|
|
for (let idx = 0; idx < this.resetHandlers.length; idx++) {
|
|
|
|
this.resetHandlers[idx].reset();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* IRQ - Interrupt Request */
|
|
|
|
public irq() {
|
|
|
|
if ((this.sr & flags.I) === 0) {
|
|
|
|
this.pushWord(this.pc);
|
|
|
|
this.pushByte(this.sr & ~flags.B);
|
|
|
|
if (this.is65C02) {
|
|
|
|
this.setFlag(flags.D, false);
|
|
|
|
}
|
|
|
|
this.setFlag(flags.I, true);
|
|
|
|
this.pc = this.readWord(loc.BRK);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* NMI Non-maskable Interrupt */
|
|
|
|
public nmi() {
|
|
|
|
this.pushWord(this.pc);
|
|
|
|
this.pushByte(this.sr & ~flags.B);
|
|
|
|
if (this.is65C02) {
|
|
|
|
this.setFlag(flags.D, false);
|
|
|
|
}
|
|
|
|
this.setFlag(flags.I, true);
|
|
|
|
this.pc = this.readWord(loc.NMI);
|
|
|
|
}
|
|
|
|
|
|
|
|
public getPC() {
|
|
|
|
return this.pc;
|
|
|
|
}
|
|
|
|
|
|
|
|
public setPC(pc: word) {
|
|
|
|
this.pc = pc;
|
|
|
|
}
|
|
|
|
|
2021-03-12 06:03:05 +00:00
|
|
|
public getDebugInfo(): DebugInfo {
|
|
|
|
const b = this.readByteDebug(this.pc);
|
|
|
|
const op = this.opary[b];
|
|
|
|
const size = sizes[op.mode];
|
|
|
|
const cmd = new Array(size);
|
|
|
|
cmd[0] = b;
|
|
|
|
for (let idx = 1; idx < size; idx++) {
|
|
|
|
cmd[idx] = this.readByteDebug(this.pc + idx);
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 06:03:05 +00:00
|
|
|
return {
|
|
|
|
pc: this.pc,
|
|
|
|
ar: this.ar,
|
|
|
|
xr: this.xr,
|
|
|
|
yr: this.yr,
|
|
|
|
sr: this.sr,
|
|
|
|
sp: this.sp,
|
|
|
|
cmd
|
|
|
|
};
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
}
|
2020-11-16 01:54:13 +00:00
|
|
|
public getSync() {
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
return this.sync;
|
|
|
|
}
|
|
|
|
|
2020-11-16 01:54:13 +00:00
|
|
|
public getCycles() {
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
return this.cycles;
|
|
|
|
}
|
|
|
|
|
2021-03-12 06:03:05 +00:00
|
|
|
public getOpInfo(opcode: byte) {
|
|
|
|
return this.opary[opcode];
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public getState(): CpuState {
|
|
|
|
return {
|
|
|
|
a: this.ar,
|
|
|
|
x: this.xr,
|
|
|
|
y: this.yr,
|
|
|
|
s: this.sr,
|
|
|
|
pc: this.pc,
|
|
|
|
sp: this.sp,
|
|
|
|
cycles: this.cycles
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
public setState(state: CpuState) {
|
|
|
|
this.ar = state.a;
|
|
|
|
this.xr = state.x;
|
|
|
|
this.yr = state.y;
|
|
|
|
this.sr = state.s;
|
|
|
|
this.pc = state.pc;
|
|
|
|
this.sp = state.sp;
|
|
|
|
this.cycles = state.cycles;
|
|
|
|
}
|
|
|
|
|
2021-03-12 06:03:05 +00:00
|
|
|
public read(addr: word): byte;
|
|
|
|
public read(page: byte, off: byte): byte;
|
|
|
|
|
|
|
|
public read(a: number, b?: number): byte {
|
|
|
|
let page, off;
|
|
|
|
if (b !== undefined) {
|
|
|
|
page = a;
|
|
|
|
off = b;
|
|
|
|
} else {
|
|
|
|
page = a >> 8;
|
|
|
|
off = a & 0xff;
|
|
|
|
}
|
2020-11-24 16:48:14 +00:00
|
|
|
return this.memPages[page].read(page, off);
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 06:03:05 +00:00
|
|
|
public write(addr: word, val: byte): void;
|
|
|
|
public write(page: byte, off: byte, val: byte): void;
|
|
|
|
|
|
|
|
public write(a: number, b: number, c?: byte): void {
|
|
|
|
let page, off, val;
|
|
|
|
|
|
|
|
if (c !== undefined ) {
|
|
|
|
page = a;
|
|
|
|
off = b;
|
|
|
|
val = c;
|
|
|
|
} else {
|
|
|
|
page = a >> 8;
|
|
|
|
off = a & 0xff;
|
|
|
|
val = b;
|
|
|
|
}
|
2020-11-24 16:48:14 +00:00
|
|
|
this.memPages[page].write(page, off, val);
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
}
|
|
|
|
|
2020-11-07 16:54:49 +00:00
|
|
|
OPS_6502: Instructions = {
|
|
|
|
// LDA
|
|
|
|
0xa9: { name: 'LDA', op: this.lda, modeFn: this.readImmediate, mode: 'immediate' },
|
|
|
|
0xa5: { name: 'LDA', op: this.lda, modeFn: this.readZeroPage, mode: 'zeroPage' },
|
|
|
|
0xb5: { name: 'LDA', op: this.lda, modeFn: this.readZeroPageX, mode: 'zeroPageX' },
|
|
|
|
0xad: { name: 'LDA', op: this.lda, modeFn: this.readAbsolute, mode: 'absolute' },
|
|
|
|
0xbd: { name: 'LDA', op: this.lda, modeFn: this.readAbsoluteX, mode: 'absoluteX' },
|
|
|
|
0xb9: { name: 'LDA', op: this.lda, modeFn: this.readAbsoluteY, mode: 'absoluteY' },
|
|
|
|
0xa1: { name: 'LDA', op: this.lda, modeFn: this.readZeroPageXIndirect, mode: 'zeroPageXIndirect' },
|
|
|
|
0xb1: { name: 'LDA', op: this.lda, modeFn: this.readZeroPageIndirectY, mode: 'zeroPageIndirectY' },
|
|
|
|
|
|
|
|
// LDX
|
|
|
|
0xa2: { name: 'LDX', op: this.ldx, modeFn: this.readImmediate, mode: 'immediate' },
|
|
|
|
0xa6: { name: 'LDX', op: this.ldx, modeFn: this.readZeroPage, mode: 'zeroPage' },
|
|
|
|
0xb6: { name: 'LDX', op: this.ldx, modeFn: this.readZeroPageY, mode: 'zeroPageY' },
|
|
|
|
0xae: { name: 'LDX', op: this.ldx, modeFn: this.readAbsolute, mode: 'absolute' },
|
|
|
|
0xbe: { name: 'LDX', op: this.ldx, modeFn: this.readAbsoluteY, mode: 'absoluteY' },
|
|
|
|
|
|
|
|
// LDY
|
|
|
|
0xa0: { name: 'LDY', op: this.ldy, modeFn: this.readImmediate, mode: 'immediate' },
|
|
|
|
0xa4: { name: 'LDY', op: this.ldy, modeFn: this.readZeroPage, mode: 'zeroPage' },
|
|
|
|
0xb4: { name: 'LDY', op: this.ldy, modeFn: this.readZeroPageX, mode: 'zeroPageX' },
|
|
|
|
0xac: { name: 'LDY', op: this.ldy, modeFn: this.readAbsolute, mode: 'absolute' },
|
|
|
|
0xbc: { name: 'LDY', op: this.ldy, modeFn: this.readAbsoluteX, mode: 'absoluteX' },
|
|
|
|
|
|
|
|
// STA
|
|
|
|
0x85: { name: 'STA', op: this.sta, modeFn: this.writeZeroPage, mode: 'zeroPage' },
|
|
|
|
0x95: { name: 'STA', op: this.sta, modeFn: this.writeZeroPageX, mode: 'zeroPageX' },
|
|
|
|
0x8d: { name: 'STA', op: this.sta, modeFn: this.writeAbsolute, mode: 'absolute' },
|
|
|
|
0x9d: { name: 'STA', op: this.sta, modeFn: this.writeAbsoluteX, mode: 'absoluteX' },
|
|
|
|
0x99: { name: 'STA', op: this.sta, modeFn: this.writeAbsoluteY, mode: 'absoluteY' },
|
|
|
|
0x81: { name: 'STA', op: this.sta, modeFn: this.writeZeroPageXIndirect, mode: 'zeroPageXIndirect' },
|
|
|
|
0x91: { name: 'STA', op: this.sta, modeFn: this.writeZeroPageIndirectY, mode: 'zeroPageIndirectY' },
|
|
|
|
|
|
|
|
// STX
|
|
|
|
0x86: { name: 'STX', op: this.stx, modeFn: this.writeZeroPage, mode: 'zeroPage' },
|
|
|
|
0x96: { name: 'STX', op: this.stx, modeFn: this.writeZeroPageY, mode: 'zeroPageY' },
|
|
|
|
0x8e: { name: 'STX', op: this.stx, modeFn: this.writeAbsolute, mode: 'absolute' },
|
|
|
|
|
|
|
|
// STY
|
|
|
|
0x84: { name: 'STY', op: this.sty, modeFn: this.writeZeroPage, mode: 'zeroPage' },
|
|
|
|
0x94: { name: 'STY', op: this.sty, modeFn: this.writeZeroPageX, mode: 'zeroPageX' },
|
|
|
|
0x8c: { name: 'STY', op: this.sty, modeFn: this.writeAbsolute, mode: 'absolute' },
|
|
|
|
|
|
|
|
// ADC
|
|
|
|
0x69: { name: 'ADC', op: this.adc, modeFn: this.readImmediate, mode: 'immediate' },
|
|
|
|
0x65: { name: 'ADC', op: this.adc, modeFn: this.readZeroPage, mode: 'zeroPage' },
|
|
|
|
0x75: { name: 'ADC', op: this.adc, modeFn: this.readZeroPageX, mode: 'zeroPageX' },
|
|
|
|
0x6D: { name: 'ADC', op: this.adc, modeFn: this.readAbsolute, mode: 'absolute' },
|
|
|
|
0x7D: { name: 'ADC', op: this.adc, modeFn: this.readAbsoluteX, mode: 'absoluteX' },
|
|
|
|
0x79: { name: 'ADC', op: this.adc, modeFn: this.readAbsoluteY, mode: 'absoluteY' },
|
|
|
|
0x61: { name: 'ADC', op: this.adc, modeFn: this.readZeroPageXIndirect, mode: 'zeroPageXIndirect' },
|
|
|
|
0x71: { name: 'ADC', op: this.adc, modeFn: this.readZeroPageIndirectY, mode: 'zeroPageIndirectY' },
|
|
|
|
|
|
|
|
// SBC
|
|
|
|
0xe9: { name: 'SBC', op: this.sbc, modeFn: this.readImmediate, mode: 'immediate' },
|
|
|
|
0xe5: { name: 'SBC', op: this.sbc, modeFn: this.readZeroPage, mode: 'zeroPage' },
|
|
|
|
0xf5: { name: 'SBC', op: this.sbc, modeFn: this.readZeroPageX, mode: 'zeroPageX' },
|
|
|
|
0xeD: { name: 'SBC', op: this.sbc, modeFn: this.readAbsolute, mode: 'absolute' },
|
|
|
|
0xfD: { name: 'SBC', op: this.sbc, modeFn: this.readAbsoluteX, mode: 'absoluteX' },
|
|
|
|
0xf9: { name: 'SBC', op: this.sbc, modeFn: this.readAbsoluteY, mode: 'absoluteY' },
|
|
|
|
0xe1: { name: 'SBC', op: this.sbc, modeFn: this.readZeroPageXIndirect, mode: 'zeroPageXIndirect' },
|
|
|
|
0xf1: { name: 'SBC', op: this.sbc, modeFn: this.readZeroPageIndirectY, mode: 'zeroPageIndirectY' },
|
|
|
|
|
|
|
|
// INC
|
|
|
|
0xe6: { name: 'INC', op: this.inc, modeFn: this.readAddrZeroPage, mode: 'zeroPage' },
|
|
|
|
0xf6: { name: 'INC', op: this.inc, modeFn: this.readAddrZeroPageX, mode: 'zeroPageX' },
|
|
|
|
0xee: { name: 'INC', op: this.inc, modeFn: this.readAddrAbsolute, mode: 'absolute' },
|
|
|
|
0xfe: { name: 'INC', op: this.inc, modeFn: this.readAddrAbsoluteX, mode: 'absoluteX' },
|
|
|
|
|
|
|
|
// INX
|
|
|
|
0xe8: { name: 'INX', op: this.inx, modeFn: this.implied, mode: 'implied' },
|
|
|
|
|
|
|
|
// INY
|
|
|
|
0xc8: { name: 'INY', op: this.iny, modeFn: this.implied, mode: 'implied' },
|
|
|
|
|
|
|
|
// DEC
|
|
|
|
0xc6: { name: 'DEC', op: this.dec, modeFn: this.readAddrZeroPage, mode: 'zeroPage' },
|
|
|
|
0xd6: { name: 'DEC', op: this.dec, modeFn: this.readAddrZeroPageX, mode: 'zeroPageX' },
|
|
|
|
0xce: { name: 'DEC', op: this.dec, modeFn: this.readAddrAbsolute, mode: 'absolute' },
|
|
|
|
0xde: { name: 'DEC', op: this.dec, modeFn: this.readAddrAbsoluteX, mode: 'absoluteX' },
|
|
|
|
|
|
|
|
// DEX
|
|
|
|
0xca: { name: 'DEX', op: this.dex, modeFn: this.implied, mode: 'implied' },
|
|
|
|
|
|
|
|
// DEY
|
|
|
|
0x88: { name: 'DEY', op: this.dey, modeFn: this.implied, mode: 'implied' },
|
|
|
|
|
|
|
|
// ASL
|
|
|
|
0x0A: { name: 'ASL', op: this.aslA, modeFn: this.implied, mode: 'accumulator' },
|
|
|
|
0x06: { name: 'ASL', op: this.asl, modeFn: this.readAddrZeroPage, mode: 'zeroPage' },
|
|
|
|
0x16: { name: 'ASL', op: this.asl, modeFn: this.readAddrZeroPageX, mode: 'zeroPageX' },
|
|
|
|
0x0E: { name: 'ASL', op: this.asl, modeFn: this.readAddrAbsolute, mode: 'absolute' },
|
|
|
|
0x1E: { name: 'ASL', op: this.asl, modeFn: this.readAddrAbsoluteX, mode: 'absoluteX' },
|
|
|
|
|
|
|
|
// LSR
|
|
|
|
0x4A: { name: 'LSR', op: this.lsrA, modeFn: this.implied, mode: 'accumulator' },
|
|
|
|
0x46: { name: 'LSR', op: this.lsr, modeFn: this.readAddrZeroPage, mode: 'zeroPage' },
|
|
|
|
0x56: { name: 'LSR', op: this.lsr, modeFn: this.readAddrZeroPageX, mode: 'zeroPageX' },
|
|
|
|
0x4E: { name: 'LSR', op: this.lsr, modeFn: this.readAddrAbsolute, mode: 'absolute' },
|
|
|
|
0x5E: { name: 'LSR', op: this.lsr, modeFn: this.readAddrAbsoluteX, mode: 'absoluteX' },
|
|
|
|
|
|
|
|
// ROL
|
|
|
|
0x2A: { name: 'ROL', op: this.rolA, modeFn: this.implied, mode: 'accumulator' },
|
|
|
|
0x26: { name: 'ROL', op: this.rol, modeFn: this.readAddrZeroPage, mode: 'zeroPage' },
|
|
|
|
0x36: { name: 'ROL', op: this.rol, modeFn: this.readAddrZeroPageX, mode: 'zeroPageX' },
|
|
|
|
0x2E: { name: 'ROL', op: this.rol, modeFn: this.readAddrAbsolute, mode: 'absolute' },
|
|
|
|
0x3E: { name: 'ROL', op: this.rol, modeFn: this.readAddrAbsoluteX, mode: 'absoluteX' },
|
|
|
|
|
|
|
|
// ROR
|
|
|
|
0x6A: { name: 'ROR', op: this.rorA, modeFn: this.implied, mode: 'accumulator' },
|
|
|
|
0x66: { name: 'ROR', op: this.ror, modeFn: this.readAddrZeroPage, mode: 'zeroPage' },
|
|
|
|
0x76: { name: 'ROR', op: this.ror, modeFn: this.readAddrZeroPageX, mode: 'zeroPageX' },
|
|
|
|
0x6E: { name: 'ROR', op: this.ror, modeFn: this.readAddrAbsolute, mode: 'absolute' },
|
|
|
|
0x7E: { name: 'ROR', op: this.ror, modeFn: this.readAddrAbsoluteX, mode: 'absoluteX' },
|
|
|
|
|
|
|
|
// AND
|
|
|
|
0x29: { name: 'AND', op: this.and, modeFn: this.readImmediate, mode: 'immediate' },
|
|
|
|
0x25: { name: 'AND', op: this.and, modeFn: this.readZeroPage, mode: 'zeroPage' },
|
|
|
|
0x35: { name: 'AND', op: this.and, modeFn: this.readZeroPageX, mode: 'zeroPageX' },
|
|
|
|
0x2D: { name: 'AND', op: this.and, modeFn: this.readAbsolute, mode: 'absolute' },
|
|
|
|
0x3D: { name: 'AND', op: this.and, modeFn: this.readAbsoluteX, mode: 'absoluteX' },
|
|
|
|
0x39: { name: 'AND', op: this.and, modeFn: this.readAbsoluteY, mode: 'absoluteY' },
|
|
|
|
0x21: { name: 'AND', op: this.and, modeFn: this.readZeroPageXIndirect, mode: 'zeroPageXIndirect' },
|
|
|
|
0x31: { name: 'AND', op: this.and, modeFn: this.readZeroPageIndirectY, mode: 'zeroPageIndirectY' },
|
|
|
|
|
|
|
|
// ORA
|
|
|
|
0x09: { name: 'ORA', op: this.ora, modeFn: this.readImmediate, mode: 'immediate' },
|
|
|
|
0x05: { name: 'ORA', op: this.ora, modeFn: this.readZeroPage, mode: 'zeroPage' },
|
|
|
|
0x15: { name: 'ORA', op: this.ora, modeFn: this.readZeroPageX, mode: 'zeroPageX' },
|
|
|
|
0x0D: { name: 'ORA', op: this.ora, modeFn: this.readAbsolute, mode: 'absolute' },
|
|
|
|
0x1D: { name: 'ORA', op: this.ora, modeFn: this.readAbsoluteX, mode: 'absoluteX' },
|
|
|
|
0x19: { name: 'ORA', op: this.ora, modeFn: this.readAbsoluteY, mode: 'absoluteY' },
|
|
|
|
0x01: { name: 'ORA', op: this.ora, modeFn: this.readZeroPageXIndirect, mode: 'zeroPageXIndirect' },
|
|
|
|
0x11: { name: 'ORA', op: this.ora, modeFn: this.readZeroPageIndirectY, mode: 'zeroPageIndirectY' },
|
|
|
|
|
|
|
|
// EOR
|
|
|
|
0x49: { name: 'EOR', op: this.eor, modeFn: this.readImmediate, mode: 'immediate' },
|
|
|
|
0x45: { name: 'EOR', op: this.eor, modeFn: this.readZeroPage, mode: 'zeroPage' },
|
|
|
|
0x55: { name: 'EOR', op: this.eor, modeFn: this.readZeroPageX, mode: 'zeroPageX' },
|
|
|
|
0x4D: { name: 'EOR', op: this.eor, modeFn: this.readAbsolute, mode: 'absolute' },
|
|
|
|
0x5D: { name: 'EOR', op: this.eor, modeFn: this.readAbsoluteX, mode: 'absoluteX' },
|
|
|
|
0x59: { name: 'EOR', op: this.eor, modeFn: this.readAbsoluteY, mode: 'absoluteY' },
|
|
|
|
0x41: { name: 'EOR', op: this.eor, modeFn: this.readZeroPageXIndirect, mode: 'zeroPageXIndirect' },
|
|
|
|
0x51: { name: 'EOR', op: this.eor, modeFn: this.readZeroPageIndirectY, mode: 'zeroPageIndirectY' },
|
|
|
|
|
|
|
|
// CMP
|
|
|
|
0xc9: { name: 'CMP', op: this.cmp, modeFn: this.readImmediate, mode: 'immediate' },
|
|
|
|
0xc5: { name: 'CMP', op: this.cmp, modeFn: this.readZeroPage, mode: 'zeroPage' },
|
|
|
|
0xd5: { name: 'CMP', op: this.cmp, modeFn: this.readZeroPageX, mode: 'zeroPageX' },
|
|
|
|
0xcD: { name: 'CMP', op: this.cmp, modeFn: this.readAbsolute, mode: 'absolute' },
|
|
|
|
0xdD: { name: 'CMP', op: this.cmp, modeFn: this.readAbsoluteX, mode: 'absoluteX' },
|
|
|
|
0xd9: { name: 'CMP', op: this.cmp, modeFn: this.readAbsoluteY, mode: 'absoluteY' },
|
|
|
|
0xc1: { name: 'CMP', op: this.cmp, modeFn: this.readZeroPageXIndirect, mode: 'zeroPageXIndirect' },
|
|
|
|
0xd1: { name: 'CMP', op: this.cmp, modeFn: this.readZeroPageIndirectY, mode: 'zeroPageIndirectY' },
|
|
|
|
|
|
|
|
// CPX
|
|
|
|
0xE0: { name: 'CPX', op: this.cpx, modeFn: this.readImmediate, mode: 'immediate' },
|
|
|
|
0xE4: { name: 'CPX', op: this.cpx, modeFn: this.readZeroPage, mode: 'zeroPage' },
|
|
|
|
0xEC: { name: 'CPX', op: this.cpx, modeFn: this.readAbsolute, mode: 'absolute' },
|
|
|
|
|
|
|
|
// CPY
|
|
|
|
0xC0: { name: 'CPY', op: this.cpy, modeFn: this.readImmediate, mode: 'immediate' },
|
|
|
|
0xC4: { name: 'CPY', op: this.cpy, modeFn: this.readZeroPage, mode: 'zeroPage' },
|
|
|
|
0xCC: { name: 'CPY', op: this.cpy, modeFn: this.readAbsolute, mode: 'absolute' },
|
|
|
|
|
|
|
|
// BIT
|
|
|
|
0x24: { name: 'BIT', op: this.bit, modeFn: this.readZeroPage, mode: 'zeroPage' },
|
|
|
|
0x2C: { name: 'BIT', op: this.bit, modeFn: this.readAbsolute, mode: 'absolute' },
|
|
|
|
|
|
|
|
// BCC
|
|
|
|
0x90: { name: 'BCC', op: this.brc, modeFn: flags.C, mode: 'relative' },
|
|
|
|
|
|
|
|
// BCS
|
|
|
|
0xB0: { name: 'BCS', op: this.brs, modeFn: flags.C, mode: 'relative' },
|
|
|
|
|
|
|
|
// BEQ
|
|
|
|
0xF0: { name: 'BEQ', op: this.brs, modeFn: flags.Z, mode: 'relative' },
|
|
|
|
|
|
|
|
// BMI
|
|
|
|
0x30: { name: 'BMI', op: this.brs, modeFn: flags.N, mode: 'relative' },
|
|
|
|
|
|
|
|
// BNE
|
|
|
|
0xD0: { name: 'BNE', op: this.brc, modeFn: flags.Z, mode: 'relative' },
|
|
|
|
|
|
|
|
// BPL
|
|
|
|
0x10: { name: 'BPL', op: this.brc, modeFn: flags.N, mode: 'relative' },
|
|
|
|
|
|
|
|
// BVC
|
|
|
|
0x50: { name: 'BVC', op: this.brc, modeFn: flags.V, mode: 'relative' },
|
|
|
|
|
|
|
|
// BVS
|
|
|
|
0x70: { name: 'BVS', op: this.brs, modeFn: flags.V, mode: 'relative' },
|
|
|
|
|
|
|
|
// TAX
|
|
|
|
0xAA: { name: 'TAX', op: this.tax, modeFn: this.implied, mode: 'implied' },
|
|
|
|
|
|
|
|
// TXA
|
|
|
|
0x8A: { name: 'TXA', op: this.txa, modeFn: this.implied, mode: 'implied' },
|
|
|
|
|
|
|
|
// TAY
|
|
|
|
0xA8: { name: 'TAY', op: this.tay, modeFn: this.implied, mode: 'implied' },
|
|
|
|
|
|
|
|
// TYA
|
|
|
|
0x98: { name: 'TYA', op: this.tya, modeFn: this.implied, mode: 'implied' },
|
|
|
|
|
|
|
|
// TSX
|
|
|
|
0xBA: { name: 'TSX', op: this.tsx, modeFn: this.implied, mode: 'implied' },
|
|
|
|
|
|
|
|
// TXS
|
|
|
|
0x9A: { name: 'TXS', op: this.txs, modeFn: this.implied, mode: 'implied' },
|
|
|
|
|
|
|
|
// PHA
|
|
|
|
0x48: { name: 'PHA', op: this.pha, modeFn: this.implied, mode: 'implied' },
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
|
2020-11-07 16:54:49 +00:00
|
|
|
// PLA
|
|
|
|
0x68: { name: 'PLA', op: this.pla, modeFn: this.implied, mode: 'implied' },
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
|
2020-11-07 16:54:49 +00:00
|
|
|
// PHP
|
|
|
|
0x08: { name: 'PHP', op: this.php, modeFn: this.implied, mode: 'implied' },
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
|
2020-11-07 16:54:49 +00:00
|
|
|
// PLP
|
|
|
|
0x28: { name: 'PLP', op: this.plp, modeFn: this.implied, mode: 'implied' },
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
|
2020-11-07 16:54:49 +00:00
|
|
|
// JMP
|
|
|
|
0x4C: {
|
|
|
|
name: 'JMP', op: this.jmp, modeFn: this.readAddrAbsolute, mode: 'absolute'
|
|
|
|
},
|
|
|
|
0x6C: {
|
|
|
|
name: 'JMP', op: this.jmp, modeFn: this.readAddrAbsoluteIndirectBug, mode: 'absoluteIndirect'
|
|
|
|
},
|
|
|
|
// JSR
|
|
|
|
0x20: { name: 'JSR', op: this.jsr, modeFn: this.readAddrAbsolute, mode: 'absolute' },
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
|
2020-11-07 16:54:49 +00:00
|
|
|
// RTS
|
|
|
|
0x60: { name: 'RTS', op: this.rts, modeFn: this.implied, mode: 'implied' },
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
|
2020-11-07 16:54:49 +00:00
|
|
|
// RTI
|
|
|
|
0x40: { name: 'RTI', op: this.rti, modeFn: this.implied, mode: 'implied' },
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
|
2020-11-07 16:54:49 +00:00
|
|
|
// SEC
|
|
|
|
0x38: { name: 'SEC', op: this.set, modeFn: flags.C, mode: 'implied' },
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
|
2020-11-07 16:54:49 +00:00
|
|
|
// SED
|
|
|
|
0xF8: { name: 'SED', op: this.set, modeFn: flags.D, mode: 'implied' },
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
|
2020-11-07 16:54:49 +00:00
|
|
|
// SEI
|
|
|
|
0x78: { name: 'SEI', op: this.set, modeFn: flags.I, mode: 'implied' },
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
|
2020-11-07 16:54:49 +00:00
|
|
|
// CLC
|
|
|
|
0x18: { name: 'CLC', op: this.clr, modeFn: flags.C, mode: 'implied' },
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
|
2020-11-07 16:54:49 +00:00
|
|
|
// CLD
|
|
|
|
0xD8: { name: 'CLD', op: this.clr, modeFn: flags.D, mode: 'implied' },
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
|
2020-11-07 16:54:49 +00:00
|
|
|
// CLI
|
|
|
|
0x58: { name: 'CLI', op: this.clr, modeFn: flags.I, mode: 'implied' },
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
|
2020-11-07 16:54:49 +00:00
|
|
|
// CLV
|
|
|
|
0xB8: { name: 'CLV', op: this.clr, modeFn: flags.V, mode: 'implied' },
|
|
|
|
|
|
|
|
// NOP
|
|
|
|
0xea: { name: 'NOP', op: this.nop, modeFn: this.implied, mode: 'implied' },
|
|
|
|
|
|
|
|
// BRK
|
|
|
|
0x00: { name: 'BRK', op: this.brk, modeFn: this.readImmediate, mode: 'immediate' }
|
|
|
|
};
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
|
2020-11-07 23:49:05 +00:00
|
|
|
/* 65C02 Instructions */
|
Typescript conversion of several files, including js/cpu6502 (#38)
* Convert `js/util.js` to Typescript and add tests
Besides converting `js/util.js` to Typescript, this change also adds
`js/types.ts` that defines common types used in apple2js. Some of
these types, like `byte` and `word` are for information only.
* Convert `js/base64.js` to Typescript
This also adds a new type, `memory`, that is either an array of
numbers, or a Uint8Array.
* Convert `js/ram.js` to Typescript
This change does not convert `RAM` to a class; it just introduces types.
* Basic typing of cpu6502
This is a really rough first pass. There are some problems that can't
be fixed until this is turned into a real class, but at least all of
the function arguments are now typed. This caught a few cases where
extra arguments were being passed in.
* Convert `js/cpu6502` to a class
In theory, idiomatic classes should be better than the previous
closure-based classes. However, this conversion shows that the
instruction table does not fit well with idiomatic classes as method
referenced in the table need to be called with the correct `this`
everywhere.
This should, at best, be considered a first attempt.
2020-11-01 16:43:48 +00:00
|
|
|
|
2020-11-07 16:54:49 +00:00
|
|
|
OPS_65C02: Instructions = {
|
|
|
|
// INC / DEC A
|
|
|
|
0x1A: { name: 'INC', op: this.incA, modeFn: this.implied, mode: 'accumulator' },
|
|
|
|
0x3A: { name: 'DEC', op: this.decA, modeFn: this.implied, mode: 'accumulator' },
|
|
|
|
|
|
|
|
// Indirect Zero Page for the masses
|
|
|
|
0x12: { name: 'ORA', op: this.ora, modeFn: this.readZeroPageIndirect, mode: 'zeroPageIndirect' },
|
|
|
|
0x32: { name: 'AND', op: this.and, modeFn: this.readZeroPageIndirect, mode: 'zeroPageIndirect' },
|
|
|
|
0x52: { name: 'EOR', op: this.eor, modeFn: this.readZeroPageIndirect, mode: 'zeroPageIndirect' },
|
|
|
|
0x72: { name: 'ADC', op: this.adc, modeFn: this.readZeroPageIndirect, mode: 'zeroPageIndirect' },
|
|
|
|
0x92: { name: 'STA', op: this.sta, modeFn: this.writeZeroPageIndirect, mode: 'zeroPageIndirect' },
|
|
|
|
0xB2: { name: 'LDA', op: this.lda, modeFn: this.readZeroPageIndirect, mode: 'zeroPageIndirect' },
|
|
|
|
0xD2: { name: 'CMP', op: this.cmp, modeFn: this.readZeroPageIndirect, mode: 'zeroPageIndirect' },
|
|
|
|
0xF2: { name: 'SBC', op: this.sbc, modeFn: this.readZeroPageIndirect, mode: 'zeroPageIndirect' },
|
|
|
|
|
|
|
|
// Better BIT
|
|
|
|
0x34: { name: 'BIT', op: this.bit, modeFn: this.readZeroPageX, mode: 'zeroPageX' },
|
|
|
|
0x3C: { name: 'BIT', op: this.bit, modeFn: this.readAbsoluteX, mode: 'absoluteX' },
|
|
|
|
0x89: { name: 'BIT', op: this.bitI, modeFn: this.readImmediate, mode: 'immediate' },
|
|
|
|
|
|
|
|
// JMP absolute indirect indexed
|
|
|
|
0x6C: {
|
|
|
|
name: 'JMP', op: this.jmp, modeFn: this.readAddrAbsoluteIndirect, mode: 'absoluteIndirect'
|
|
|
|
},
|
|
|
|
0x7C: {
|
|
|
|
name: 'JMP', op: this.jmp, modeFn: this.readAddrAbsoluteXIndirect, mode: 'absoluteXIndirect'
|
|
|
|
},
|
|
|
|
|
|
|
|
// BBR/BBS
|
|
|
|
0x0F: { name: 'BBR0', op: this.bbr, modeFn: 0, mode: 'zeroPage_relative' },
|
|
|
|
0x1F: { name: 'BBR1', op: this.bbr, modeFn: 1, mode: 'zeroPage_relative' },
|
|
|
|
0x2F: { name: 'BBR2', op: this.bbr, modeFn: 2, mode: 'zeroPage_relative' },
|
|
|
|
0x3F: { name: 'BBR3', op: this.bbr, modeFn: 3, mode: 'zeroPage_relative' },
|
|
|
|
0x4F: { name: 'BBR4', op: this.bbr, modeFn: 4, mode: 'zeroPage_relative' },
|
|
|
|
0x5F: { name: 'BBR5', op: this.bbr, modeFn: 5, mode: 'zeroPage_relative' },
|
|
|
|
0x6F: { name: 'BBR6', op: this.bbr, modeFn: 6, mode: 'zeroPage_relative' },
|
|
|
|
0x7F: { name: 'BBR7', op: this.bbr, modeFn: 7, mode: 'zeroPage_relative' },
|
|
|
|
|
|
|
|
0x8F: { name: 'BBS0', op: this.bbs, modeFn: 0, mode: 'zeroPage_relative' },
|
|
|
|
0x9F: { name: 'BBS1', op: this.bbs, modeFn: 1, mode: 'zeroPage_relative' },
|
|
|
|
0xAF: { name: 'BBS2', op: this.bbs, modeFn: 2, mode: 'zeroPage_relative' },
|
|
|
|
0xBF: { name: 'BBS3', op: this.bbs, modeFn: 3, mode: 'zeroPage_relative' },
|
|
|
|
0xCF: { name: 'BBS4', op: this.bbs, modeFn: 4, mode: 'zeroPage_relative' },
|
|
|
|
0xDF: { name: 'BBS5', op: this.bbs, modeFn: 5, mode: 'zeroPage_relative' },
|
|
|
|
0xEF: { name: 'BBS6', op: this.bbs, modeFn: 6, mode: 'zeroPage_relative' },
|
|
|
|
0xFF: { name: 'BBS7', op: this.bbs, modeFn: 7, mode: 'zeroPage_relative' },
|
|
|
|
|
|
|
|
// BRA
|
|
|
|
0x80: { name: 'BRA', op: this.brc, modeFn: 0, mode: 'relative' },
|
|
|
|
|
|
|
|
// NOP
|
|
|
|
0x02: { name: 'NOP', op: this.nop, modeFn: this.readImmediate, mode: 'immediate' },
|
|
|
|
0x22: { name: 'NOP', op: this.nop, modeFn: this.readImmediate, mode: 'immediate' },
|
|
|
|
0x42: { name: 'NOP', op: this.nop, modeFn: this.readImmediate, mode: 'immediate' },
|
|
|
|
0x44: { name: 'NOP', op: this.nop, modeFn: this.readImmediate, mode: 'immediate' },
|
|
|
|
0x54: { name: 'NOP', op: this.nop, modeFn: this.readImmediate, mode: 'immediate' },
|
|
|
|
0x62: { name: 'NOP', op: this.nop, modeFn: this.readImmediate, mode: 'immediate' },
|
|
|
|
0x82: { name: 'NOP', op: this.nop, modeFn: this.readImmediate, mode: 'immediate' },
|
|
|
|
0xC2: { name: 'NOP', op: this.nop, modeFn: this.readImmediate, mode: 'immediate' },
|
|
|
|
0xD4: { name: 'NOP', op: this.nop, modeFn: this.readImmediate, mode: 'immediate' },
|
|
|
|
0xE2: { name: 'NOP', op: this.nop, modeFn: this.readImmediate, mode: 'immediate' },
|
|
|
|
0xF4: { name: 'NOP', op: this.nop, modeFn: this.readImmediate, mode: 'immediate' },
|
|
|
|
0x5C: { name: 'NOP', op: this.nop, modeFn: this.readAbsolute, mode: 'absolute' },
|
|
|
|
0xDC: { name: 'NOP', op: this.nop, modeFn: this.readAbsolute, mode: 'absolute' },
|
|
|
|
0xFC: { name: 'NOP', op: this.nop, modeFn: this.readAbsolute, mode: 'absolute' },
|
|
|
|
|
|
|
|
// PHX
|
|
|
|
0xDA: { name: 'PHX', op: this.phx, modeFn: this.implied, mode: 'implied' },
|
|
|
|
|
|
|
|
// PHY
|
|
|
|
0x5A: { name: 'PHY', op: this.phy, modeFn: this.implied, mode: 'implied' },
|
|
|
|
|
|
|
|
// PLX
|
|
|
|
0xFA: { name: 'PLX', op: this.plx, modeFn: this.implied, mode: 'implied' },
|
|
|
|
|
|
|
|
// PLY
|
|
|
|
0x7A: { name: 'PLY', op: this.ply, modeFn: this.implied, mode: 'implied' },
|
|
|
|
|
|
|
|
// RMB/SMB
|
|
|
|
|
|
|
|
0x07: { name: 'RMB0', op: this.rmb, modeFn: 0, mode: 'zeroPage' },
|
|
|
|
0x17: { name: 'RMB1', op: this.rmb, modeFn: 1, mode: 'zeroPage' },
|
|
|
|
0x27: { name: 'RMB2', op: this.rmb, modeFn: 2, mode: 'zeroPage' },
|
|
|
|
0x37: { name: 'RMB3', op: this.rmb, modeFn: 3, mode: 'zeroPage' },
|
|
|
|
0x47: { name: 'RMB4', op: this.rmb, modeFn: 4, mode: 'zeroPage' },
|
|
|
|
0x57: { name: 'RMB5', op: this.rmb, modeFn: 5, mode: 'zeroPage' },
|
|
|
|
0x67: { name: 'RMB6', op: this.rmb, modeFn: 6, mode: 'zeroPage' },
|
|
|
|
0x77: { name: 'RMB7', op: this.rmb, modeFn: 7, mode: 'zeroPage' },
|
|
|
|
|
|
|
|
0x87: { name: 'SMB0', op: this.smb, modeFn: 0, mode: 'zeroPage' },
|
|
|
|
0x97: { name: 'SMB1', op: this.smb, modeFn: 1, mode: 'zeroPage' },
|
|
|
|
0xA7: { name: 'SMB2', op: this.smb, modeFn: 2, mode: 'zeroPage' },
|
|
|
|
0xB7: { name: 'SMB3', op: this.smb, modeFn: 3, mode: 'zeroPage' },
|
|
|
|
0xC7: { name: 'SMB4', op: this.smb, modeFn: 4, mode: 'zeroPage' },
|
|
|
|
0xD7: { name: 'SMB5', op: this.smb, modeFn: 5, mode: 'zeroPage' },
|
|
|
|
0xE7: { name: 'SMB6', op: this.smb, modeFn: 6, mode: 'zeroPage' },
|
|
|
|
0xF7: { name: 'SMB7', op: this.smb, modeFn: 7, mode: 'zeroPage' },
|
|
|
|
|
|
|
|
// STZ
|
|
|
|
0x64: { name: 'STZ', op: this.stz, modeFn: this.writeZeroPage, mode: 'zeroPage' },
|
|
|
|
0x74: { name: 'STZ', op: this.stz, modeFn: this.writeZeroPageX, mode: 'zeroPageX' },
|
|
|
|
0x9C: { name: 'STZ', op: this.stz, modeFn: this.writeAbsolute, mode: 'absolute' },
|
|
|
|
0x9E: { name: 'STZ', op: this.stz, modeFn: this.writeAbsoluteX, mode: 'absoluteX' },
|
|
|
|
|
|
|
|
// TRB
|
|
|
|
0x14: { name: 'TRB', op: this.trb, modeFn: this.readAddrZeroPage, mode: 'zeroPage' },
|
|
|
|
0x1C: { name: 'TRB', op: this.trb, modeFn: this.readAddrAbsolute, mode: 'absolute' },
|
|
|
|
|
|
|
|
// TSB
|
|
|
|
0x04: { name: 'TSB', op: this.tsb, modeFn: this.readAddrZeroPage, mode: 'zeroPage' },
|
|
|
|
0x0C: { name: 'TSB', op: this.tsb, modeFn: this.readAddrAbsolute, mode: 'absolute' }
|
|
|
|
}
|
2020-11-07 23:49:05 +00:00
|
|
|
}
|