All files / src/web accessibility-switches.js

100% Statements 7/7
100% Branches 2/2
100% Functions 4/4
100% Lines 6/6

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27                      28x 28x 28x     17x           68x 32x      
/**
 * The accessibility switches on the user port. Bits 0-7 correspond to switches
 * 1-8, active low: 0xff = no switches pressed; a clear bit = that switch held.
 *
 * On real hardware, the Brilliant Computing switch interface box and special-ed
 * joystick connect to the User Port only; they do not touch the analogue port
 * or the System VIA fire buttons (PB4/PB5), which belong to the standard
 * analogue joystick connector.
 */
export class AccessibilitySwitches {
    constructor() {
        this.switchState = 0xff;
        const switches = this;
        this.userPort = {
            write() {},
            read() {
                return switches.switchState;
            },
        };
    }
 
    setSwitch(index, held) {
        if (held) this.switchState &= ~(1 << index);
        else this.switchState |= 1 << index;
    }
}