From 565da09575606aa0f21151905f88113dd170cbcc Mon Sep 17 00:00:00 2001 From: Ian Flanigan Date: Tue, 29 Dec 2020 15:40:58 +0100 Subject: [PATCH] Minor type improvements (#50) * Improve typing for `base64_encode` * Better typing for `BRA` and `is65C02` --- js/base64.ts | 6 ++++-- js/cpu6502.ts | 7 ++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/js/base64.ts b/js/base64.ts index b40a82f..b0f0216 100644 --- a/js/base64.ts +++ b/js/base64.ts @@ -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 diff --git a/js/cpu6502.ts b/js/cpu6502.ts index 9855c00..54ab765 100644 --- a/js/cpu6502.ts +++ b/js/cpu6502.ts @@ -140,6 +140,7 @@ type StrictInstruction = Instruction | Instruction | Instruction | + Instruction | Instruction type Instructions = Record @@ -147,7 +148,7 @@ type Instructions = Record 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);