     */
     func stopLoop()
     {
-        self.isLooping = false;
+        self.isLooping = false
     }
     
     /**
      * The main loop
      */
-    func loop()
+    private func loop()
     {
         // Handle the next instruction
         self.tickInstruction()
-        
+return
         // Make sure the timers countdown
         self.countdownTimers()
         
         // Make sound if needed
         self.makeNoise()
         
-        // And update the screen with the correct graphics
-        self.drawGraphics()
-        
         // Determine if we should continue the loop
-        if(self.isLooping)
+//        if(self.isLooping)
+        if(self.pc < 6)
         {
             // Delaying one 60th of a second
-            let delay = dispatch_time(DISPATCH_TIME_NOW, Int64(60 * NSEC_PER_SEC))
+            let delay = dispatch_time(DISPATCH_TIME_NOW, Int64(1/60 * Double(NSEC_PER_SEC)))
             
             // And call self recursively after that delay
             dispatch_after(delay, dispatch_get_main_queue(), self.loop)

    /**
     * Determines if the attached sound perpherals should make noise
     */
    func makeNoise()
    {
        if(self.soundtimer > 0)
        {
            self.sound.bleep();
        }
    }
    
    func drawGraphics()
    {
        // Draw the graphics
    }
    
    /**
     * Counts the timers in the system down
     */
    func countdownTimers()
    {
        // Decrement the delay timer
        if(self.delayTimer > 0)

    var delayTimer : UInt8 = 0
    
    // Used for sounding a beep when it is non zero, counts down at 60hz
    var soundTimer : UInt8 = 0
    
    // Flag to stop looping if needed
    var isLooping = false
    
    // The peripherals
    let graphics : Graphics
    let sound : Sound
    let keyboard : Keyboard
    
    // Mapping every opcode to a closure
    
    // Using the following info in the naming of the methods, the first part is the assembly name that would happen, after the underscore what is being moved, copied or checked
    // ADDR - A 12-bit value, the lowest 12 bits of the instruction
    // N  - A nibble (4-bit) value
    // BYTE a byte
    // V - a register
    // I - the I (address) register
    // DT - delay timer
    // ST - sound timer
    // K - keyboard button
    // F - Reference to the hexidecimal font in memory
    
    // Since we are checking on the AND value, order here is important

    lazy var mapping : [Int: ((Int) -> Void)] = {
        
        return [
            
            // CLS (clear the display)
            0x00E0: { arg in
                print("Clear \(arg)")
            },
            
            // RET (return from a subroutine)
            0x00EE: { arg in
                // Set the program counter to the current item on the stack
                self.pc = self.stack[self.sp]
                
                // Decrement stack pointer
                self.sp--
            },
            
            // JP_ADDR (jump to a memory address)
            0x1000: { arg in
                // Set the program counter to jump
                self.pc = arg
            },
            
            // CALL_ADDR (call address on subroutine)
            0x2000: { arg in
                // Place current address on top of stack
                self.sp++
                self.stack[self.sp] = self.pc
            },
            
            // SE_V_BYTE ( skip next instruction if register equals value )
            0x3000: { arg in
                
            },
        ]
    }()

//    let mapping = [
//

//        0x4000: "sne_v_byte", // skip next instruction if register not equals value
//        0x5000: "se_v_v", // skip next instruction if register equals other register
//        0x6000: "ld_v_byte", // set register with value
//        0x7000: "add_v_byte", // add value to register v
//        0x8001: "or_v_v", // OR two registers and store result in first register
//        0x8002: "and_v_v", // AND two registers and store result in first register
//        0x8003: "xor_v_v", // XOR two registers and store result in first register
//        0x8004: "add_v_v", // Add two registers and store result in first register carry flag is set
//        0x8005: "sub_v_v", // Subtract the second register from the first and store result in first register, borrow flag is set when there is no borrow
//        0x8006: "shr_v", // Shift the first register right by one the flag will contain the LSB before the shift (last nibble is ignored in opcode)
//        0x8007: "subn_v_v", // Subtract the first register from the second register and store the result in the first register, borrow flag is set when there is no borrow
//        0x800E: "shl_v", // Shift the first register left by one the flag will containt the RSB before the shift (last nibble is ignored in opcode)
//        0x8000: "ld_v_v", // copy register to another register
//        0x9000: "sne_v_v", // Skip next instruction if the first register does not match the second register
//        0xA000: "ld_i_addr", // The I register is set with the address
//        0xB000: "jp_v0_addr", // Jump to the address of addr + v0
//        0xC000: "rnd_v_byte", // Generates a random byte value which then AND is applied to that value based on the byte parameter and placed in the register v
//        0xD000: "drw_v_v_n", // Draw sprite of length n on memory address I on coordinates of the passed registers VF is set on collision
//        0xE09E: "skp_v", // Skips the next instruction if the key which represents the value in register v is pressed
//        0xE0A1: "sknp_v", // Skips the next instruction if the key which represents the valine in register v is not pressed
//        0xF007: "ld_v_dt", // Set the register v to the value in dt
//        0xF00A: "ld_v_k", // Set the register v to the value of the keypress by the keyboard (will wait for keypress)
//        0xF015: "ld_dt_v", // Set the delay timer to the value in register v
//        0xF018: "ld_st_v", // Set the sound timer to the value in register v
//        0xF01E: "add_i_v", // The results of I and v are added and stored in i
//        0xF029: "ld_f_v", // I is set to the address of the corresponding font block representing the value in register v
//        0xF033: "ld_b_v", // Stores the binary decimal representation of the value of register v in I
//        0xF055: "ld_i_v", // Stores the registers v0 to v(x) starting in memory location i,
//        0xF066: "ld_v_i" // Reads from memory location i and stores it in registers V0 to v(x)
////        0x0000: "sys", // Todo: (not required it seems)
//    ]
    
    // Hooks up the peripherals to the Chip8 system
    init(graphics: Graphics, sound: Sound, keyboard: Keyboard)
    {
        self.graphics = graphics
        self.sound = sound
        self.keyboard = keyboard

        super.init()

        self.resest()
    }
    
    /**
