<commit_before>import {Memory} from "../memory/memory";

/**
 * Created by hkamran on 12/16/2016.
 */
export class Registers {
    public scx: number = 0;
    public scy: number = 0;

    //Window overlay
    public wx: number = 0;
    public wy: number = 0;


    //OAM
    public bcps: number = 0;
    public bcpd: number = 0;
    public ocps: number = 0;
    public ocpd: number = 0;

    public dma: number = 0;
    public bgp: number = 0;
    public obp0: number = 0;
    public obp1: number = 0;


    //@formatter:off
    // LCD Controller
    public lcdc  = (function(){
        let _val = 0x00;
        return { //Toggles for the flags
            set : {
                lcdon :     function(){ _val ^= 0x80 },
                bgwin :     function(){ _val ^= 0x40 },
                winon :     function(){ _val ^= 0x20 },
                tilemap :   function(){ _val ^= 0x10 },
                bgmap :     function(){ _val ^= 0x08 },
                objsize :   function(){ _val ^= 0x04 },
                objon :     function(){ _val ^= 0x02 },
                bgon :      function(){ _val ^= 0x01 },
            },
            lcdon :     function(){ return (_val &= 0x80) ? 1 : 0  },
            bgwin :     function(){ return (_val &= 0x40) ? 1 : 0  },
            winon :     function(){ return (_val &= 0x20) ? 1 : 0  },
            tilemap :   function(){ return (_val &= 0x10) ? 1 : 0  },
            bgmap :     function(){ return (_val &= 0x08) ? 1 : 0  },
            objsize :   function(){ return (_val &= 0x04) ? 1 : 0  },
            objon :     function(){ return (_val &= 0x02) ? 1 : 0  },
            bgon :      function(){ return (_val &= 0x01) ? 1 : 0  },
            get : function(){ return _val },
        }
    })();

    // Status of LCD Controller pg 55
    // 00 : enable cpu access to display RAM
    // 01 : In VBLANK
    // 02 : Searching
    // 03 : VRAM read mode
    public stat = (function(){
        let _val = 0x00;
        return {
            get : function() { return _val; },
            set : function(val) { _val = val },
            interrupts : {
                lycoincidence:  function () { _val |= 0x40; },
                oaminterrupt:   function () { _val |= 0x20; },
                vblank:         function () { _val |= 0x11; },
                hblank:         function () { _val |= 0x8; },
            },
            modeFlag : {
                hblank:     function() {_val &= 0xFC},
                vblank:     function() {_val &= 0xFC; _val += 1},
                oamlock:    function() {_val &= 0xFC; _val += 2},
                ovramlock:  function() {_val &= 0xFC; _val += 3}
            }<commit_msg>Passing in self into the lcdc type objects to allow access<commit_after>import {Memory} from "../memory/memory";

/**
 * Created by hkamran on 12/16/2016.
 */
export class Registers {
    public scx: number = 0;
    public scy: number = 0;

    //Window overlay
    public wx: number = 0;
    public wy: number = 0;


    //OAM
    public bcps: number = 0;
    public bcpd: number = 0;
    public ocps: number = 0;
    public ocpd: number = 0;

    public dma: number = 0;
    public bgp: number = 0;
    public obp0: number = 0;
    public obp1: number = 0;


    //@formatter:off
    // LCD Controller
    public lcdc  = (function(self : Registers){
        let _val = 0x00;
        return { //Toggles for the flags
            set : {
                lcdon :     function(){
                                _val ^= 0x80
                                if(!this.lcdon){
                                    //Set ly
                                    self.setLY(0);
                                }
                            },
                bgwin :     function(){ _val ^= 0x40 },
                winon :     function(){ _val ^= 0x20 },
                tilemap :   function(){ _val ^= 0x10 },
                bgmap :     function(){ _val ^= 0x08 },
                objsize :   function(){ _val ^= 0x04 },
                objon :     function(){ _val ^= 0x02 },
                bgon :      function(){ _val ^= 0x01 },
            },
            lcdon :     function(){ return (_val &= 0x80) ? 1 : 0  ;},
            bgwin :     function(){ return (_val &= 0x40) ? 1 : 0  },
            winon :     function(){ return (_val &= 0x20) ? 1 : 0  },
            tilemap :   function(){ return (_val &= 0x10) ? 1 : 0  },
            bgmap :     function(){ return (_val &= 0x08) ? 1 : 0  },
            objsize :   function(){ return (_val &= 0x04) ? 1 : 0  },
            objon :     function(){ return (_val &= 0x02) ? 1 : 0  },
            bgon :      function(){ return (_val &= 0x01) ? 1 : 0  },
            get : function(){ return _val },
        }
    })(this);

    // Status of LCD Controller pg 55
    // 00 : enable cpu access to display RAM
    // 01 : In VBLANK
    // 02 : Searching
    // 03 : VRAM read mode
    public stat = (function(){
        let _val = 0x00;
        return {
            get : function() { return _val; },
            set : function(val) { _val = val },
            interrupts : {
                lycoincidence:  function () { _val |= 0x40; },
                oaminterrupt:   function () { _val |= 0x20; },
                vblank:         function () { _val |= 0x11; },
                hblank:         function () { _val |= 0x8; },
            },
            modeFlag : {
                hblank:     function() {_val &= 0xFC},
                vblank:     function() {_val &= 0xFC; _val += 1},
                oamlock:    function() {_val &= 0xFC; _val += 2},
                ovramlock:  function() {_val &= 0xFC; _val += 3}
            }
{'fraction_non_alphanumeric': 0.13458473525765893, 'fraction_numerical': 0.04267752789091553, 'mean_word_length': 1.3015484922575387, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4089426', 'n_tokens_mistral': 1928, 'n_tokens_neox': 1684, 'n_words': 510}