Minor type improvements (#50)

* Improve typing for `base64_encode`

* Better typing for `BRA` and `is65C02`
This commit is contained in:
Ian Flanigan 2020-12-29 15:40:58 +01:00 committed by GitHub
parent 72ecce113a
commit 565da09575
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 5 deletions

View File

@ -3,7 +3,9 @@ import { memory } from './types';
const B64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
/** Encode an array of bytes in base64. */
export function base64_encode(data: memory) {
export function base64_encode(data: null | undefined): undefined;
export function base64_encode(data: memory): string;
export function base64_encode(data: memory | null | undefined): string | undefined {
// Twacked by Will Scullin to handle arrays of 'bytes'
// http://kevin.vanzonneveld.net
@ -28,7 +30,7 @@ export function base64_encode(data: memory) {
const tmp_arr = [];
if (!data) {
return data;
return undefined;
}
do { // pack three octets into four hexets

View File

@ -140,6 +140,7 @@ type StrictInstruction =
Instruction<ReadAddrFn> |
Instruction<ImpliedFn> |
Instruction<flag> |
Instruction<flag|0> |
Instruction<byte>
type Instructions = Record<byte, StrictInstruction>
@ -147,7 +148,7 @@ type Instructions = Record<byte, StrictInstruction>
type callback = (cpu: CPU6502) => void;
export default class CPU6502 {
private readonly is65C02;
private readonly is65C02: boolean;
/* Registers */
private pc = 0; // Program Counter
@ -190,7 +191,7 @@ export default class CPU6502 {
* Set or clears `f` in the status register. `f` must be a byte with a
* single bit set.
*/
private setFlag(f: byte, on: boolean) {
private setFlag(f: flag, on: boolean) {
this.sr = on ? (this.sr | f) : (this.sr & ~f);
}
@ -844,7 +845,7 @@ export default class CPU6502 {
}
}
brc = (f: flag) => {
brc = (f: flag|0) => {
const off = this.readBytePC(); // changes pc
if ((f & this.sr) === 0) {
this.readByte(this.pc);