<commit_before>/**
 **
 **     6502 JavaScript Emulator
 **     Author: <NAME>
 **
 **/
(function (scope) {
    'use strict';
    // Register Indexes
    var A = 0,
        X = 1,
        Y = 2,
        N = 3,
        V = 4,
        B = 6,
        D = 7,
        I = 8,
        Z = 9,
        C = 10,
        // Register array
        reg = new Uint8Array(11),
        // Program counter
        PC = new Uint16Array(1),
        // Stack pointer
        SP = new Uint8Array(1),
        stackAddress = 0x01FF,
        // 64KB of RAM
        RAM = new Uint8Array(65536),
        // Cached 16 bit addr
        addr = new Uint16Array(1),
        lsb,
        msb,
        tmp,
        getBit = function (value, bit) {
            return (value >> bit) & 1;
        },
        eatByte = function () {
            return RAM[PC[0] ++];
        },
        // Address modes
        // Zero Page
        addrZP = function () {
            return eatByte();
        },
        // Zero Page X
        addrZPX = function () {
            return addrZP() + reg[X];
        },
        // Zero Page Y
        addrZPY = function () {
            return addrZP() + reg[Y];
        },
        // Absolute
        addrAB = function () {
            lsb = eatByte();
            msb = eatByte();
            return (msb << 8) | (lsb & 0xff);
        },
        // Absolute X
        addrABX = function () {
            return addrAB() + reg[X];
        },
        // Absolute Y
        addrABY = function () {
            return addrAB() + reg[Y];
        },
        // Indirect X
        addrIDX = function () {
            return RAM[eatByte() + reg[X]];
        },
        // Indirect Y
        addrIDY = function () {
            return RAM[eatByte()] + reg[Y];
        },
        // Branch Relative
        brchREL = function () {
            addr[0] = eatByte();
            PC[0] = PC[0] + addr[0];
        },
        // Instruction set.
        ADC = function (m) {
            tmp = reg[A] + m + reg[C];
            reg[V] = getBit(reg[A], 7) != getBit(tmp, 7) ? 1 : 0;
            reg[N] = getBit(reg[A], 7);
            reg[Z] = tmp == 0 ? 1 : 0;
            //TODO: Implement decimal mode operation.
            reg[C] = tmp > 0xFF ? 1 : 0;
            reg[A] = tmp;
        },
        AND = function (m) {
            reg[A] &= m;
            reg[N] = getBit(reg[A], 7);
            reg[Z] = reg[A] == 0 ? 1 : 0;
        },
        ASL = function (m) {
            reg[C] = getBit(m, 7);
            m = (m << 1) & 0xFE;
            reg[N] = getBit(m);
            reg[Z] = m == 0 ? 1 : 0;
            return m;
        },
        BIT = function (m) {
            tmp = reg[A] & m;
            reg[N] = getBit(tmp, 7);
            reg[V] = getBit(tmp, 6);
            reg[Z] = tmp == 0 ? 1 : 0;
        },
        CMP = function (m) {
            tmp = reg[A] - m;
            reg[N] = getBit(tmp, 7);
            reg[C] = reg[A] >= m ? 1 : 0;
            reg[Z] = tmp == 0 ? 1 : 0;
        },
        // Instruction addr
        INSTADDR = {
            // $69 ADC IM
            105: function () {
                ADC(eatByte());<commit_msg>Instructions added: CPX, CPY, DEC, DEX and DEY<commit_after>/**
 **
 **     6502 JavaScript Emulator
 **     Author: <NAME>
 **
 **/
(function (scope) {
    'use strict';
    // Register Indexes
    var A = 0,
        X = 1,
        Y = 2,
        N = 3,
        V = 4,
        B = 6,
        D = 7,
        I = 8,
        Z = 9,
        C = 10,
        // Register array
        reg = new Uint8Array(11),
        // Program counter
        PC = new Uint16Array(1),
        // Stack pointer
        SP = new Uint8Array(1),
        stackAddress = 0x01FF,
        // 64KB of RAM
        RAM = new Uint8Array(65536),
        // Cached 16 bit addr
        addr = new Uint16Array(1),
        lsb,
        msb,
        tmp,
        getBit = function (value, bit) {
            return (value >> bit) & 1;
        },
        eatByte = function () {
            return RAM[PC[0] ++];
        },
        // Address modes
        // Zero Page
        addrZP = function () {
            return eatByte();
        },
        // Zero Page X
        addrZPX = function () {
            return addrZP() + reg[X];
        },
        // Zero Page Y
        addrZPY = function () {
            return addrZP() + reg[Y];
        },
        // Absolute
        addrAB = function () {
            lsb = eatByte();
            msb = eatByte();
            return (msb << 8) | (lsb & 0xff);
        },
        // Absolute X
        addrABX = function () {
            return addrAB() + reg[X];
        },
        // Absolute Y
        addrABY = function () {
            return addrAB() + reg[Y];
        },
        // Indirect X
        addrIDX = function () {
            return RAM[eatByte() + reg[X]];
        },
        // Indirect Y
        addrIDY = function () {
            return RAM[eatByte()] + reg[Y];
        },
        // Branch Relative
        brchREL = function () {
            addr[0] = eatByte();
            PC[0] = PC[0] + addr[0];
        },
        // Instruction set.
        ADC = function (m) {
            tmp = reg[A] + m + reg[C];
            reg[V] = getBit(reg[A], 7) != getBit(tmp, 7) ? 1 : 0;
            reg[N] = getBit(reg[A], 7);
            reg[Z] = tmp == 0 ? 1 : 0;
            //TODO: Implement decimal mode operation.
            reg[C] = tmp > 0xFF ? 1 : 0;
            reg[A] = tmp;
        },
        AND = function (m) {
            reg[A] &= m;
            reg[N] = getBit(reg[A], 7);
            reg[Z] = reg[A] == 0 ? 1 : 0;
        },
        ASL = function (m) {
            reg[C] = getBit(m, 7);
            m = (m << 1) & 0xFE;
            reg[N] = getBit(m);
            reg[Z] = m == 0 ? 1 : 0;
            return m;
        },
        BIT = function (m) {
            tmp = reg[A] & m;
            reg[N] = getBit(tmp, 7);
            reg[V] = getBit(tmp, 6);
            reg[Z] = tmp == 0 ? 1 : 0;
        },
        CMP = function (m) {
            tmp = reg[A] - m;
            reg[N] = getBit(tmp, 7);
            reg[C] = reg[A] >= m ? 1 : 0;
            reg[Z] = tmp == 0 ? 1 : 0;
        },
        CPX = function (m) {
            tmp = reg[X]  - m;
            reg[N] = getBit(tmp, 7);
            reg[C] = reg[X] >= m ? 1 : 0;
            reg[Z] = tmp == 0 ? 1 : 0;
        },
        CPY = function (m) {
            tmp = reg[Y]  - m;
            reg[N] = getBit(tmp, 7);
            reg[C] = reg[Y] >= m ? 1 : 0;
            reg[Z] = tmp == 0 ? 1 : 0;
        },
        DEC = function (m) {
            tmp = (m - 1) & 0xFF;
            reg[N] = getBit(m, 7);
            reg[Z] = m == 0 ? 1 : 0;
            return tmp;
        },
        DEX = function () {
            reg[X] = reg[X] - 1;
            reg[Z] = reg[X] == 0 ? 1 : 0;
            reg[N] = getBit(reg[X], 7);
        },
        DEY = function () {
            reg[Y] = reg[Y] - 1;
            reg[Z] = reg[Y] == 0 ? 1 : 0;
            reg[N] = getBit(reg[Y], 7);
        },
        // Instruction addr
        INSTADDR = {
            // $69 ADC IM
            105: function () {
                ADC(eatByte());
{'fraction_non_alphanumeric': 0.15584415584415584, 'fraction_numerical': 0.02737047898338221, 'mean_word_length': 1.0363946545351153, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '567131', 'n_tokens_mistral': 2522, 'n_tokens_neox': 2338, 'n_words': 615}