Esempio n. 1
0
        /****************** External interaction code goes here *****************/
        //returns an assembler which has the correct instruction set and produces correct code for this CPU
        public Assembler2 getCompatibleAssembler()
        {
            //create the instruction set for the assembler

            Dictionary<String, Instruction> Instr = new Dictionary<String, Instruction>();
            //to add:
            //movil
            //andi, ori, xori
            //all float instructions
            //rdx and other strange but possible instructions

            //add all instructions by the order of their values
            /*****************************************************************************************/
            //arithmetic
            Instr.Add("add", new Instruction(0x00, true, true, true, false, false, false, true, false, 0));
            Instr.Add("sub", new Instruction(0x01, true, true, true, false, false, false, false, false, 0));
            Instr.Add("mul", new Instruction(0x02, true, true, true, false, false, false, false, false, 0));
            Instr.Add("div", new Instruction(0x03, true, true, true, false, false, false, false, false, 0));
            Instr.Add("and", new Instruction(0x04, true, true, true, false, false, false, false, false, 0));
            Instr.Add("or", new Instruction(0x05, true, true, true, false, false, false, false, false, 0));
            Instr.Add("xor", new Instruction(0x06, true, true, true, false, false, false, false, false, 0));
            Instr.Add("not", new Instruction(0x07, false, false, true, false, false, false, false, false, 0));
            Instr.Add("addi", new Instruction(0x08, true, true, false, true, false, false, false, true, 0));
            Instr.Add("subi", new Instruction(0x09, true, true, false, true, false, false, false, true, 0));
            Instr.Add("muli", new Instruction(0x0a, true, true, false, true, false, false, false, true, 0));
            Instr.Add("divi", new Instruction(0x0b, true, true, false, true, false, false, false, true, 0));
            Instr.Add("andi", new Instruction(0x0c, true, true, false, true, false, false, false, true, 0));
            Instr.Add("ori", new Instruction(0x0d, true, true, false, true, false, false, false, true, 0));
            Instr.Add("xori", new Instruction(0x0e, true, true, false, true, false, false, false, true, 0));
            //0x0f --

            /*****************************************************************************************/
            //extended arithmetic
            Instr.Add("flcmp", new Instruction(0x10, true, true, true, false, false, false, false, false, 0));
            Instr.Add("shr", new Instruction(0x11, true, true, true, false, false, false, false, false, 0));
            Instr.Add("shl", new Instruction(0x12, true, true, true, false, false, false, false, false, 0));
            Instr.Add("ax", new Instruction(0x13, true, false, true, false, false, false, false, false, 0));
            Instr.Add("sx", new Instruction(0x14, true, false, true, false, false, false, false, false, 0));
            //0x15 float
            Instr.Add("fadd", new Instruction(0x15, false, false, false, false, false, false, false, false, 0));
            Instr.Add("fsub", new Instruction(0x15, false, false, false, false, false, false, false, false, 1));
            Instr.Add("fmul", new Instruction(0x15, false, false, false, false, false, false, false, false, 2));
            Instr.Add("fdiv", new Instruction(0x15, false, false, false, false, false, false, false, false, 3));
            Instr.Add("fmerge", new Instruction(0x15, false, false, false, false, false, false, false, false, 4));
            Instr.Add("ftoi", new Instruction(0x15, false, false, false, false, false, false, false, false, 5));
            Instr.Add("ftof", new Instruction(0x15, false, false, false, false, false, false, false, false, 6));
            //Instr.Add("fadd", new Instruction(0x15, false, false, false, false, false, false, false, false, 7));
            Instr.Add("fpop", new Instruction(0x15, true, false, false, false, false, false, false, false, 8));
            Instr.Add("fpush", new Instruction(0x15, true, false, false, false, false, false, false, false, 9));
            Instr.Add("fsel0", new Instruction(0x15, false, false, false, false, false, false, false, false, 10));
            Instr.Add("fsel1", new Instruction(0x15, false, false, false, false, false, false, false, false, 11));
            Instr.Add("fflush", new Instruction(0x15, false, false, false, false, false, false, false, false, 12));
            Instr.Add("fpush1", new Instruction(0x15, false, false, false, false, false, false, false, false, 13));
            Instr.Add("fpushn1", new Instruction(0x15, false, false, false, false, false, false, false, false, 14));
            Instr.Add("fpushpi", new Instruction(0x15, false, false, false, false, false, false, false, false, 15));
            //0x16 extended instruction set, register instructions
            //Instr.Add("nop", new Instruction(0x16, true, true, true, false, false, false, false, false, 0x0000));
            //Instr.Add("movbr", new Instruction(0x16, true, true, true, false, false, false, false, false, 0x0800));
            //Instr.Add("movhwr", new Instruction(0x16, true, true, true, false, false, false, false, false, 0x0900));
            //Instr.Add("movblr", new Instruction(0x1e6 true, true, true, false, false, false, false, false, 0x0a00));
            //Instr.Add("movhwlr", new Instruction(0x16, true, true, true, false, false, false, false, false, 0x0b00));
            Instr.Add("cmp", new Instruction(0x17, true, true, true, false, false, false, false, false, 0));
            //0x18 flcmpi
            Instr.Add("sri", new Instruction(0x19, true, true, false, true, false, false, false, false, 0));
            Instr.Add("sli", new Instruction(0x1a, true, true, false, true, false, false, false, false, 0));
            //0x1b axi
            //0x1c sxi
            //0x1d --
            //0x1e extended instruction set, immediate instructions
            //Instr.Add("nop", new Instruction(0x1e, true, true, false, true, false, false, false, false, 0x0000));
            Instr.Add("movb", new Instruction(0x1e, true, true, false, true, false, false, false, false, 0x0800));
            Instr.Add("movhw", new Instruction(0x1e, true, true, false, true, false, false, false, false, 0x0900));
            Instr.Add("movbl", new Instruction(0x1e, true, true, false, true, false, false, false, false, 0x0a00));
            Instr.Add("movhwl", new Instruction(0x1e, true, true, false, true, false, false, false, false, 0x0b00));
            //0x1f cmpi

            /****************************************************************************************/
            //branching
            Instr.Add("brr", new Instruction(0x20, false, false, true, false, false, false, false, false, 0));
            //0x21 bner
            Instr.Add("jmpr", new Instruction(0x22, false, false, true, false, false, false, false, false, 0));
            //0x23 blr
            //0x24 bler
            //0x25 bxr
            Instr.Add("callr", new Instruction(0x26, false, false, true, false, false, false, false, false, 0));
            //0x27 eret
            Instr.Add("br", new Instruction(0x28, false, false, false, true, false, false, true, false, 0));
            Instr.Add("halt", new Instruction(0x28, false, false, false, false, false, false, false, false, -1));
            Instr.Add("beq", new Instruction(0x28, true, true, false, true, false, false, true, false, 0));
            Instr.Add("bne", new Instruction(0x29, true, true, false, true, false, false, true, false, 0));
            Instr.Add("bi", new Instruction(0x29, true, false, false, true, false, false, true, false, 0));
            Instr.Add("jmp", new Instruction(0x2a, false, false, false, true, false, false, false, true, 0));
            Instr.Add("bl", new Instruction(0x2b, true, true, false, true, false, false, true, false, 0));
            Instr.Add("ble", new Instruction(0x2c, true, true, false, true, false, false, true, false, 0));
            Instr.Add("bx", new Instruction(0x2d, false, false, false, true, false, false, true, false, 0));
            Instr.Add("call", new Instruction(0x2e, false, false, false, true, false, false, true, false, 0));
            Instr.Add("eret", new Instruction(0x2f, false, false, false, false, false, false, false, false, 0));

            /***************************************************************************************/
            //data move
            Instr.Add("mov", new Instruction(0x30, true, false, true, false, false, false, false, false, 0));
            Instr.Add("nop", new Instruction(0x30, false, false, false, false, false, false, false, false, 0));
            //0x31 --
            //0x32 --
            //0x33 --
            Instr.Add("push", new Instruction(0x34, false, false, true, false, false, false, false, false, 0));
            Instr.Add("pop", new Instruction(0x35, true, false, false, false, false, false, false, false, 0));
            //0x36 --
            Instr.Add("int", new Instruction(0x37, false, false, true, false, false, false, false, false, 0));
            Instr.Add("movi", new Instruction(0x38, true, false, false, true, false, false, false, true, 0));
            Instr.Add("movil", new Instruction(0x38, true, false, false, true, true, false, false, true, 0));
            Instr.Add("movhi", new Instruction(0x39, true, false, false, true, false, false, false, true, 0));
            Instr.Add("rd", new Instruction(0x3a, true, true, false, true, false, false, false, true, 0));
            Instr.Add("wr", new Instruction(0x3b, true, true, false, true, false, false, false, true, 0));
            //0x3c --
            //0x3d --
            Instr.Add("rdx", new Instruction(0x3e, false, true, false, true, false, false, false, true, 0));
            //0x3f --

            //initialise the assembler
            Assembler2 assembler = new Assembler2(Instr);

            return assembler;
        }
Esempio n. 2
0
        private void init()
        {
            //initialise cpu-emulator
            lastLoaded = 128;
            CPU = new CPUem();

            removeExternalGUI();
            monitor = new Monitor(CPU.Memory, 63488, 65024, 63472, 42);
            keyb = new Keyboard();
            initExternalGUI();

            //connect keyboard to serial port
            connect(keyb, 1);

            running = false;
            //init default values in memory
            CPU.Memory[41] = 1024;//init vector precision
            CPU.Memory[43] = 16;//default speed precision
            int i = 65024;
            foreach (UInt32 font in monitor.getDefaultFont()) {
                CPU.Memory[i] = (Int32)font;
                ++i;
            }
            i = 63472;
            foreach (Int32 col in monitor.getDefaultColors()) {
                CPU.Memory[i] = col;
                ++i;
            }

            //initialise the assembler
            assembler = CPU.getCompatibleAssembler();
            assembler.bindGlobalCall("GLOBAL_MAINTHROTTLE", 0);//init all globaly shared memory positions
            assembler.bindGlobalCall("GLOBAL_YAW", 1);
            assembler.bindGlobalCall("GLOBAL_PITCH", 2);
            assembler.bindGlobalCall("GLOBAL_ROLL", 3);
            assembler.bindGlobalCall("GLOBAL_SURFACE_EAST", 4);
            assembler.bindGlobalCall("GLOBAL_SURFACE_UP", 7);
            assembler.bindGlobalCall("GLOBAL_SURFACE_NORTH", 10);
            assembler.bindGlobalCall("GLOBAL_VESSEL_X", 13);
            assembler.bindGlobalCall("GLOBAL_VESSEL_Y", 16);
            assembler.bindGlobalCall("GLOBAL_VESSEL_HEADING", 16);//ALTERNATE
            assembler.bindGlobalCall("GLOBAL_VESSEL_Z", 19);
            assembler.bindGlobalCall("GLOBAL_ORBITSPEED", 22);
            assembler.bindGlobalCall("GLOBAL_SURFACESPEED", 25);
            assembler.bindGlobalCall("GLOBAL_ANGULARVELOCITY", 28);
            assembler.bindGlobalCall("GLOBAL_ALTITUDE", 31);
            assembler.bindGlobalCall("GLOBAL_NUMPAD_OUT", 32);
            assembler.bindGlobalCall("GLOBAL_NUMPAD_MSG", 36);
            assembler.bindGlobalCall("GLOBAL_NUMPAD_IN", 37);
            assembler.bindGlobalCall("GLOBAL_NUMPAD_NEWIN", 38);
            assembler.bindGlobalCall("GLOBAL_NUMPAD_FORMAT", 39);
            assembler.bindGlobalCall("GLOBAL_TIMER", 40);
            assembler.bindGlobalCall("GLOBAL_VECTORACCURACY", 41);
            assembler.bindGlobalCall("GLOBAL_SCREEN_MODE", 42);
            assembler.bindGlobalCall("GLOBAL_SPEEDACCURACY", 43);
            assembler.bindGlobalCall("GLOBAL_IENABLE", 44);
            assembler.bindGlobalCall("GLOBAL_CLOCK", 45);
            assembler.bindGlobalCall("GLOBAL_IADRESS", 46);
            assembler.bindGlobalCall("GLOBAL_TIMER_MAX", 47);
            assembler.bindGlobalCall("GLOBAL_PILOT_THROTTLE", 48);
            assembler.bindGlobalCall("GLOBAL_PILOT_YAW", 49);
            assembler.bindGlobalCall("GLOBAL_PILOT_PITCH", 50);
            assembler.bindGlobalCall("GLOBAL_PILOT_ROLL", 51);
            assembler.bindGlobalCall("GLOBAL_PILOT_RCS_RIGHT", 52);
            assembler.bindGlobalCall("GLOBAL_PILOT_RCS_UP", 53);
            assembler.bindGlobalCall("GLOBAL_PILOT_RCS_FORWARD", 54);
            assembler.bindGlobalCall("GLOBAL_RCS_RIGHT", 52);
            assembler.bindGlobalCall("GLOBAL_RCS_UP", 53);
            assembler.bindGlobalCall("GLOBAL_RCS_FORWARD", 54);
            assembler.bindGlobalCall("GLOBAL_ACTIONGROUP", 55);

            //serial buses
            assembler.bindGlobalCall("GLOBAL_GSB0", 64);
            assembler.bindGlobalCall("GLOBAL_GSB1", 68);
            assembler.bindGlobalCall("GLOBAL_GSB2", 72);
            assembler.bindGlobalCall("GLOBAL_GSB3", 76);
            assembler.bindGlobalCall("GLOBAL_GSB4", 80);
            assembler.bindGlobalCall("GLOBAL_GSB5", 84);
            assembler.bindGlobalCall("GLOBAL_GSB6", 88);
            assembler.bindGlobalCall("GLOBAL_GSB7", 92);

            //monitor stuff
            assembler.bindGlobalCall("GLOBAL_SCREEN", 63488);
            assembler.bindGlobalCall("GLOBAL_SCREEN_COLOR", 63472);
            assembler.bindGlobalCall("GLOBAL_SCREEN_FONT", 65024);

            //other stuff
            assembler.bindGlobalCall("CPU_CLOCKRATE", CPU.ClockRate);
            assembler.bindGlobalCall("CPU_RAM", CPU.Memory.Length);
            assembler.bindGlobalCall("CPU_MAXADDRESS", CPU.Memory.Length-1);
        }
Esempio n. 3
0
        /*
         * are these really not needed anymore?
        protected override void onPartDestroy()
        {
            if (partActive) {
                vessel.OnFlyByWire -= new FlightInputCallback(performManouvers);

                //remove manouver-stuff when the part is destroyed
                if (this.vessel.isActiveVessel) {
                    RenderingManager.RemoveFromPostDrawQueue(3, new Callback(drawGUI)); //close the GUI
                    RenderingManager.RemoveFromPostDrawQueue(3, new Callback(monitor.draw));
                    RenderingManager.RemoveFromPostDrawQueue(3, new Callback(keyb.draw));//start the keyboard
                }
            }
        }

        protected override void onDisconnect()
        {
            //remove manouver sFlyByWire stuff when the part is disconnected
            if (this.vessel.isActiveVessel && partActive) {
                vessel.OnFlyByWire -= new FlightInputCallback(performManouvers);//this is in here to avoid potential nastiness related to removing nonexistant FlightInputCallbacks.
                RenderingManager.RemoveFromPostDrawQueue(3, new Callback(drawGUI)); //close the GUI
                RenderingManager.RemoveFromPostDrawQueue(3, new Callback(monitor.draw));
                RenderingManager.RemoveFromPostDrawQueue(3, new Callback(keyb.draw));//start the keyboard
            }
        }
        */
        private void init()
        {
            //print("PROGCOM INITIALISING");
            //initialise cpu-emulator
            //lastLoaded = 128;
            CPU = new CPUem();

            windowID = Util.random();

            //connect various peripherals to the CPU
            //when possible, separate these out as normal partmodules

            //connect the console memory wrapper
            CPU.hwConnect(ConsoleMemWrapper);

            running = false;

            //iterate through all partmodules connected to the part, make sure all partmodules are aware of this part.
            print("scanning for local progCom hardware...");
            foreach (PartModule pm in this.part.Modules) {
                if (pm == this) continue;
                //connect all hardware to this part
                if (pm is IPCHardware) {
                    //print("HARDWARE IS FOUND");
                    print("found " + pm.GetType().ToString());
                    try {
                        CPU.hwConnect((IPCHardware)pm);
                    }
                    catch (ArgumentException e) {
                        consoleWrite("Error when connecting hardware:");
                        consoleWrite(e.Message);
                    }
                    catch (Exception e) {
                        consoleWrite("Unexpected error when connecting hardware:");
                        consoleWrite(e.Message);
                    }
                }
                //make sure all partmodules can read the gui state
                if (pm is PCGUIListener) {
                    //print("GUIListener found!");
                    try {
                        ((PCGUIListener)pm).recGUIState(GUIstate);
                    }
                    catch (Exception e) {
                        consoleWrite("Error when connecting gui:");
                        consoleWrite(e.Message);
                    }
                }
            }

            //initialise the assembler
            assembler = new Assembler2();
        }