├── .gitignore ├── README.md ├── bcomp-assembler ├── pom.xml └── src │ └── main │ └── java │ └── ru │ └── ifmo │ └── cs │ └── bcomp │ ├── assembler │ ├── AddressingMode.java │ ├── AsmNg.java │ ├── Assembler.java │ ├── AssemblerAntlrErrorStrategy.java │ ├── AssemblerException.java │ ├── Instruction.java │ ├── InstructionWord.java │ ├── Label.java │ ├── MemoryWord.java │ ├── Program.java │ └── WordDirective.java │ └── grammar │ ├── BCompNG.g4 │ ├── BCompNGBaseListener.java │ ├── BCompNGBaseVisitor.java │ ├── BCompNGLexer.java │ ├── BCompNGListener.java │ ├── BCompNGParser.java │ └── BCompNGVisitor.java ├── bcomp-ng-ui ├── pom.xml └── src │ └── main │ ├── java │ └── ru │ │ └── ifmo │ │ └── cs │ │ └── bcomp │ │ └── ui │ │ ├── BCompApp.java │ │ ├── CLI.java │ │ ├── GUI.java │ │ ├── MicroCodeDecoder.java │ │ ├── Nightmare.java │ │ ├── components │ │ ├── ALUView.java │ │ ├── ActivateblePanel.java │ │ ├── ActiveBitView.java │ │ ├── AssemblerView.java │ │ ├── BCompComponent.java │ │ ├── BCompLabel.java │ │ ├── BCompPanel.java │ │ ├── BasicView.java │ │ ├── BorderedComponent.java │ │ ├── BusNames.java │ │ ├── BusView.java │ │ ├── CommutView.java │ │ ├── ComponentManager.java │ │ ├── DebugView.java │ │ ├── DisplayStyles.java │ │ ├── FlagView.java │ │ ├── IOView.java │ │ ├── InputRegisterView.java │ │ ├── InputRegisterViewByte.java │ │ ├── MPView.java │ │ ├── MemoryView.java │ │ ├── MicroMemoryView.java │ │ ├── RegisterProperties.java │ │ ├── RegisterView.java │ │ ├── RunningCycleView.java │ │ ├── StateRegisterView.java │ │ ├── TraceView.java │ │ ├── loc.java │ │ └── loc_ru.java │ │ └── io │ │ ├── BComp2BCompIODev.java │ │ ├── ButtonPanel.java │ │ ├── ButtonReady.java │ │ ├── FirstIO.java │ │ ├── FlagIndicator.java │ │ ├── IODevice.java │ │ ├── Keyboard.java │ │ ├── Numpad.java │ │ ├── OutputDevice.java │ │ ├── SecondIO.java │ │ ├── SevenSegmentDisplay.java │ │ ├── TextPrinter.java │ │ ├── ThirdIO.java │ │ └── Ticker.java │ └── resources │ ├── Roboto-Medium.ttf │ ├── Roboto-Regular.ttf │ └── dark.xml ├── bcomp-ng ├── hs_err_pid21904.log ├── pom.xml └── src │ ├── main │ └── java │ │ └── ru │ │ └── ifmo │ │ └── cs │ │ └── bcomp │ │ ├── BasicComp.java │ │ ├── CPU.java │ │ ├── CPU2IO.java │ │ ├── ControlSignal.java │ │ ├── IOBuses.java │ │ ├── IOControlSignal.java │ │ ├── IOCtrl.java │ │ ├── IOCtrlAdv.java │ │ ├── IOCtrlBasic.java │ │ ├── IODevTimer.java │ │ ├── MCDecoder.java │ │ ├── MicroCode.java │ │ ├── ProgramBinary.java │ │ ├── Reg.java │ │ ├── RunningCycle.java │ │ ├── SignalListener.java │ │ └── State.java │ └── test │ └── java │ └── ru │ └── ifmo │ └── cs │ └── bcomp │ └── BasicCompTest.java ├── components ├── pom.xml └── src │ └── main │ └── java │ └── ru │ └── ifmo │ └── cs │ └── components │ ├── And.java │ ├── AutoIncRegister.java │ ├── BasicComponent.java │ ├── Bus.java │ ├── Comparer.java │ ├── Complement.java │ ├── Consts.java │ ├── Control.java │ ├── CtrlBus.java │ ├── DataAdd.java │ ├── DataAnd.java │ ├── DataCheckZero.java │ ├── DataConst.java │ ├── DataDestination.java │ ├── DataPart.java │ ├── DataSource.java │ ├── Decoder.java │ ├── Extender.java │ ├── InputBus.java │ ├── Memory.java │ ├── Not.java │ ├── PartWriter.java │ ├── PassValue.java │ ├── Register.java │ ├── Utils.java │ ├── Valve.java │ ├── ValveAnd.java │ ├── ValveCtrlInput.java │ ├── ValveTwo.java │ ├── ValveValue.java │ └── Xor.java ├── doc ├── BaseInstrSet.html ├── BaseMicroProgram.html ├── ExtendedInstrSet.html ├── ExtendedMicroProgram.html ├── OptimizedMicroProgram.html ├── asm.html ├── bcomp ├── bcomp.html ├── bcomp.jnlp ├── cli.bat ├── cli.html ├── decoder.html ├── gui.bat ├── gui.html ├── index.html ├── io.html └── nightmare.html ├── lab4_test.txt └── pom.xml /.gitignore: -------------------------------------------------------------------------------- 1 | /*/target/ 2 | /*/*.iml 3 | /*.iml 4 | /.idea/ 5 | /*.log -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # BasicComputer 2 | ![БЭВМ](https://i.imgur.com/NspoKvE.png) 3 | 4 | ### Загрузка программы 5 | Загрузка программы позволяет быстро загружать ваши программы из .txt файла. 6 | 7 | Пример: 8 |
 9 | 479a
10 | 0200
11 | EE16
12 | AE12
13 | 0C00
14 | ....
15 | EE04
16 | 0100
17 | 713a
18 | AC01
19 | F309
20 | 6E0B
21 | ....
22 | CE01
23 | AE02
24 | EC01
25 | 
26 | 27 | > где маленькая "a" - указывает с какого адреса начать вводить команды или данные. Так можно указывать несколько раз. Допустим, если вам нужно в другой части памяти записать подпрограмму 28 | 29 | [Пример 4 лабы](https://github.com/HackMemory/BasicComputer/blob/master/lab4_test.txt) 30 | 31 | ### Трассировка 32 | Чтобы выполнить трассировку, указываем сперва начало программы, а после нажимаем выполнение. Полученную трассировку можно экпортировать в csv файл. 33 | ![Трассировка](https://i.imgur.com/1HrCKcC.png) 34 | -------------------------------------------------------------------------------- /bcomp-assembler/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | ru.ifmo.cs 7 | BasicComputer 8 | 2 9 | 10 | ru.ifmo.cs 11 | bcomp-assembler 12 | 1 13 | bcomp-assembler 14 | http://maven.apache.org 15 | 16 | UTF-8 17 | true 18 | true 19 | 1.8 20 | 1.8 21 | 22 | 23 | 24 | junit 25 | junit 26 | 4.10 27 | test 28 | 29 | 30 | org.antlr 31 | antlr4-runtime 32 | 4.8 33 | 34 | 35 | 36 | 37 | 38 | org.antlr 39 | antlr4-maven-plugin 40 | 4.8 41 | 42 | 1.8 43 | 1.8 44 | 45 | 46 | 47 | antlr 48 | 49 | antlr4 50 | 51 | 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /bcomp-assembler/src/main/java/ru/ifmo/cs/bcomp/assembler/AddressingMode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | package ru.ifmo.cs.bcomp.assembler; 7 | 8 | /** 9 | * 10 | * @author serge 11 | */ 12 | public class AddressingMode { 13 | // contains direct numbers: addresses, displacement, direct load numbers 14 | public volatile int number = MemoryWord.UNDEFINED; 15 | public volatile String reference = null; 16 | public AddressingType addressation; 17 | 18 | public enum AddressingType {DIRECT_ABSOLUTE, INDIRECT, POST_INCREMENT, PRE_DECREMENT, 19 | DISPLACEMENT_SP, DIRECT_RELATIVE, DIRECT_LOAD}; 20 | 21 | @Override 22 | public String toString() { 23 | String s = ""; 24 | if(addressation==null) return s; 25 | switch (addressation) { 26 | case DIRECT_ABSOLUTE: 27 | if (number != MemoryWord.UNDEFINED ) {s += "0d"+number; break;} 28 | if (reference != null ) {s = '$'+reference; break;} 29 | s="$undef"; break; 30 | case INDIRECT: 31 | if (reference != null ) {s = '(' + reference + ')'; break;} 32 | s="(undef)"; break; 33 | case POST_INCREMENT: 34 | if (reference != null ) {s = '(' + reference + ")+"; break;} 35 | s="(undef)+"; break; 36 | case PRE_DECREMENT: 37 | if (reference != null ) {s = "-(" + reference + ')'; break;} 38 | s="-(undef)"; break; 39 | case DISPLACEMENT_SP: 40 | if (number != MemoryWord.UNDEFINED ) {s = "&"+number; break;} 41 | s="&undef"; break; 42 | case DIRECT_RELATIVE: 43 | if (reference != null ) {s = reference; break;} 44 | s="undef"; break; 45 | case DIRECT_LOAD: 46 | if (number != MemoryWord.UNDEFINED ) {s = "#"+number; break;} 47 | s="#undef"; break; 48 | default: 49 | s="UNDEF"; 50 | } 51 | return s; 52 | } 53 | 54 | } -------------------------------------------------------------------------------- /bcomp-assembler/src/main/java/ru/ifmo/cs/bcomp/assembler/AssemblerAntlrErrorStrategy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | package ru.ifmo.cs.bcomp.assembler; 7 | 8 | import org.antlr.v4.runtime.DefaultErrorStrategy; 9 | import org.antlr.v4.runtime.Parser; 10 | import org.antlr.v4.runtime.RecognitionException; 11 | import org.antlr.v4.runtime.misc.IntervalSet; 12 | 13 | /** 14 | * 15 | * @author serge 16 | */ 17 | public class AssemblerAntlrErrorStrategy extends DefaultErrorStrategy { 18 | 19 | @Override 20 | public void reportError(Parser recognizer, RecognitionException e) { 21 | //System.err.println(e.getMessage()); 22 | if (!(e instanceof AssemblerException)) { 23 | super.reportError(recognizer, e); 24 | return; 25 | } 26 | AssemblerException ae = (AssemblerException)e; 27 | // if we've already reported an error and have not matched a token 28 | // yet successfully, don't report any errors. 29 | //if (inErrorRecoveryMode(recognizer)) { 30 | //System.err.print("[SPURIOUS] "); 31 | // return; // don't report spurious errors 32 | //} 33 | beginErrorCondition(recognizer); 34 | recognizer.notifyErrorListeners(ae.getOffendingToken(),ae.getMessage(), ae); 35 | } 36 | 37 | @Override 38 | public void recover(Parser recognizer, RecognitionException e) { 39 | // System.out.println("recover in "+recognizer.getRuleInvocationStack()+ 40 | // " index="+recognizer.getInputStream().index()+ 41 | // ", lastErrorIndex="+ 42 | // lastErrorIndex+ 43 | // ", states="+lastErrorStates); 44 | if ( lastErrorIndex==recognizer.getInputStream().index() && 45 | lastErrorStates != null && 46 | lastErrorStates.contains(recognizer.getState()) ) { 47 | // uh oh, another error at same token index and previously-visited 48 | // state in ATN; must be a case where LT(1) is in the recovery 49 | // token set so nothing got consumed. Consume a single token 50 | // at least to prevent an infinite loop; this is a failsafe. 51 | // System.err.println("seen error condition before index="+ 52 | // lastErrorIndex+", states="+lastErrorStates); 53 | // System.err.println("FAILSAFE consumes "+recognizer.getTokenNames()[recognizer.getInputStream().LA(1)]); 54 | recognizer.consume(); 55 | } 56 | lastErrorIndex = recognizer.getInputStream().index(); 57 | if ( lastErrorStates==null ) lastErrorStates = new IntervalSet(); 58 | lastErrorStates.add(recognizer.getState()); 59 | IntervalSet followSet = getErrorRecoverySet(recognizer); 60 | consumeUntil(recognizer, followSet); 61 | } 62 | 63 | } -------------------------------------------------------------------------------- /bcomp-assembler/src/main/java/ru/ifmo/cs/bcomp/assembler/AssemblerException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | package ru.ifmo.cs.bcomp.assembler; 7 | 8 | import org.antlr.v4.runtime.Parser; 9 | import org.antlr.v4.runtime.ParserRuleContext; 10 | import org.antlr.v4.runtime.RecognitionException; 11 | 12 | /** 13 | * 14 | * @author serge 15 | */ 16 | public class AssemblerException extends RecognitionException { 17 | 18 | 19 | public AssemblerException(Parser recognizer) { // LL(1) error 20 | super(recognizer, recognizer.getInputStream(), recognizer.getContext()); 21 | this.setOffendingToken(recognizer.getCurrentToken()); 22 | } 23 | 24 | 25 | public AssemblerException(String msg, Parser recognizer, ParserRuleContext ctx) { 26 | super(msg, recognizer, recognizer.getInputStream(), ctx); 27 | //System.out.println(msg+recognizer.getCurrentToken()); 28 | this.setOffendingToken(recognizer.getCurrentToken()); 29 | } 30 | 31 | public AssemblerException(String msg, Parser recognizer) { 32 | super(msg, recognizer, recognizer.getInputStream(), recognizer.getContext()); 33 | this.setOffendingToken(recognizer.getCurrentToken()); 34 | } 35 | 36 | public ParserRuleContext getParserRuleContext() { 37 | return (ParserRuleContext)getCtx(); 38 | } 39 | 40 | 41 | 42 | } -------------------------------------------------------------------------------- /bcomp-assembler/src/main/java/ru/ifmo/cs/bcomp/assembler/Instruction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * $Id$ 3 | */ 4 | 5 | package ru.ifmo.cs.bcomp.assembler; 6 | import static ru.ifmo.cs.bcomp.assembler.Instruction.Type.*; 7 | 8 | /** 9 | * 10 | * @author Dmitry Afanasiev 11 | */ 12 | public enum Instruction { 13 | 14 | //address 15 | AND(0x2000,ADDR), OR(0x3000 ,ADDR), ADD(0x4000,ADDR), ADC(0x5000,ADDR), 16 | SUB(0x6000,ADDR), CMP(0x7000,ADDR), LOOP(0x8000,ADDR), LD(0xA000,ADDR), 17 | SWAM(0xB000,ADDR), JUMP(0xC000,ADDR), CALL(0xD000,ADDR), ST(0xE000,ADDR), 18 | //addressless 19 | NOP(0x0000,NONADDR), HLT(0x0100,NONADDR), CLA(0x0200,NONADDR), 20 | NOT(0x0280,NONADDR), CLC(0x0300,NONADDR), CMC(0x0380,NONADDR), 21 | ROL(0x0400,NONADDR), ROR(0x0480,NONADDR), ASL(0x0500,NONADDR), 22 | ASR(0x0580,NONADDR), SXTB(0x0600,NONADDR), SWAB(0x0680,NONADDR), 23 | INC(0x0700,NONADDR), DEC(0x0740,NONADDR), NEG(0x0780,NONADDR), 24 | POP(0x0800,NONADDR), POPF(0x0900,NONADDR), RET(0x0A00,NONADDR), 25 | IRET(0x0B00,NONADDR), PUSH(0x0C00,NONADDR), PUSHF(0x0D00,NONADDR), 26 | SWAP(0x0E00,NONADDR), 27 | //branch 28 | BEQ(0xF000,BRANCH), BNE(0xF100,BRANCH), BMI(0xF200,BRANCH), BPL(0xF300,BRANCH), 29 | BCS(0xF400,BRANCH), BCC(0xF500,BRANCH), BVS(0xF600,BRANCH), BVC(0xF700,BRANCH), 30 | BLT(0xF800,BRANCH), BGE(0xF900,BRANCH), BR(0xCE00, BRANCH), 31 | //io 32 | DI(0x1000,NONADDR),EI(0x1100,NONADDR),IN(0x1200,IO),OUT(0x1300,IO),INT(0x1800,IO), 33 | 34 | END(1,Type.NONADDR); 35 | 36 | public static final Instruction [] values = Instruction.values(); 37 | 38 | Instruction(int opcode, Type type) { 39 | this.opcode = opcode; 40 | this.mnemonic = this.name(); 41 | this.type = type; 42 | } 43 | 44 | public enum Type { 45 | ADDR, NONADDR, BRANCH, IO 46 | }; 47 | 48 | public final int opcode; 49 | public final String mnemonic; 50 | public Type type; 51 | 52 | public String getTypeString() { 53 | return type.name(); 54 | } 55 | 56 | } -------------------------------------------------------------------------------- /bcomp-assembler/src/main/java/ru/ifmo/cs/bcomp/assembler/InstructionWord.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | package ru.ifmo.cs.bcomp.assembler; 7 | 8 | /** 9 | * 10 | * @author serge 11 | */ 12 | public class InstructionWord extends MemoryWord { 13 | public volatile Instruction instruction = null; 14 | public volatile AddressingMode operand = null; //only for address command 15 | public volatile Integer device = UNDEFINED; //only for io command IN OUT INTR 16 | 17 | @Override 18 | public String toString() { 19 | return Integer.toHexString(address+0x100000).substring(3) + "| " + 20 | (label != null ? label.name + ": " : "" ) + 21 | instruction.mnemonic + " " + 22 | (instruction.type == Instruction.Type.ADDR? operand.toString(): "") + 23 | (instruction.type == Instruction.Type.BRANCH? " label="+operand.reference: "") + 24 | " \t; type=" + instruction.type + 25 | (value != UNDEFINED? " value=0x"+Integer.toHexString(value): ""); 26 | } 27 | 28 | } -------------------------------------------------------------------------------- /bcomp-assembler/src/main/java/ru/ifmo/cs/bcomp/assembler/Label.java: -------------------------------------------------------------------------------- 1 | 2 | package ru.ifmo.cs.bcomp.assembler; 3 | 4 | /** 5 | * 6 | * @author serge 7 | */ 8 | 9 | public class Label { 10 | public final static int UNDEFINED = -1; 11 | 12 | public String name; 13 | public volatile int address = UNDEFINED; 14 | public boolean referenced = false; 15 | 16 | @Override 17 | public String toString() { 18 | return "Label{" + "name=" + name + ", addr=" + (address != UNDEFINED ? address :"UNDEF") + '}'; 19 | } 20 | 21 | } -------------------------------------------------------------------------------- /bcomp-assembler/src/main/java/ru/ifmo/cs/bcomp/assembler/MemoryWord.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | package ru.ifmo.cs.bcomp.assembler; 7 | 8 | /** 9 | * 10 | * @author serge 11 | */ 12 | public class MemoryWord { 13 | public final static int UNDEFINED = 0xDEADBEEF; 14 | public final static int MAX_ADDRESS = 0x7FF; 15 | public final static int MAX_UNSIGNED = 0xFFFF; 16 | public volatile int address = UNDEFINED; 17 | public volatile Label label = null; 18 | public volatile int value = UNDEFINED; 19 | public volatile String value_addr_reference = null; 20 | 21 | @Override 22 | public String toString() { 23 | return Integer.toHexString(address+0x100000).substring(3) + "| " + 24 | (label != null ? label.name + ": " : "" ) + 25 | "WORD " + 26 | (value != UNDEFINED? " 0x"+Integer.toHexString(value): ""); 27 | } 28 | 29 | 30 | } -------------------------------------------------------------------------------- /bcomp-assembler/src/main/java/ru/ifmo/cs/bcomp/assembler/Program.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | package ru.ifmo.cs.bcomp.assembler; 7 | 8 | import java.util.Collections; 9 | import java.util.HashMap; 10 | import java.util.Iterator; 11 | import java.util.LinkedList; 12 | import java.util.List; 13 | 14 | /** 15 | * This class is only used as container for binary 16 | * @author serge 17 | */ 18 | public class Program { 19 | public final static int UNDEFINED = -1; 20 | public int load_address = UNDEFINED; 21 | public int start_address = UNDEFINED; 22 | 23 | public List binary = null; 24 | public HashMap labels = null; 25 | public HashMap content = null; 26 | 27 | public List getBinaryFormat() { 28 | if (start_address == UNDEFINED || load_address == UNDEFINED || 29 | binary == null || binary.isEmpty()) 30 | throw new RuntimeException("AsmNG Program.getBinaryFormat: Program data is corrupted"); 31 | //actually we can regenerate programm data here if labels and content 32 | //are not null but we would not 33 | LinkedList prog = new LinkedList(binary); 34 | prog.add(0,start_address); 35 | prog.add(0,load_address); 36 | return prog; 37 | } 38 | 39 | public void loadBinaryFormat(List prog) { 40 | Iterator i = prog.iterator(); 41 | if (!i.hasNext()) throw new IndexOutOfBoundsException("AsmNG Program.loadBinaryFormat: Программа пуста: load_address"); 42 | load_address = i.next(); 43 | if (!i.hasNext()) throw new IndexOutOfBoundsException("AsmNG Program.loadBinaryFormat: Программа пуста: start_address"); 44 | start_address = i.next(); 45 | if (prog.size()<3) throw new IndexOutOfBoundsException("AsmNG Program.loadBinaryFormat: Программа пуста: binary body"); 46 | binary = new LinkedList(); 47 | while (i.hasNext()) binary.add(i.next()); 48 | } 49 | 50 | public int getLabelAddr (String label) { 51 | if (labels == null) 52 | throw new RuntimeException("AsmNG Program.getLabelAddr: Labels are not set up"); 53 | if (!labels.containsKey(label)) 54 | throw new IllegalArgumentException("AsmNG Program.getLabelAddr: Label "+label+" not found"); 55 | return labels.get(label).address; 56 | } 57 | 58 | public String toBinaryRepresentation(int columns) { 59 | StringBuilder sb = new StringBuilder(); 60 | int col = 8; 61 | if (columns >= 1) col = columns; 62 | int i = 1; 63 | for (Integer w : getBinaryFormat()) { 64 | String s = "0000"+Integer.toHexString(w); 65 | s = s.substring(s.length()-4, s.length()); 66 | sb.append(s).append(' '); 67 | if (i++ % col == 0) sb.append('\n'); 68 | } 69 | return sb.toString(); 70 | } 71 | 72 | public String toBinaryRepresentation() { 73 | return toBinaryRepresentation(8); 74 | } 75 | 76 | public String toCompiledWords() { 77 | if (content == null) return "UnSet"; 78 | StringBuilder sb = new StringBuilder(); 79 | LinkedList addresses = new LinkedList(content.keySet()); 80 | Collections.sort(addresses); 81 | for (Integer addr : addresses ) { 82 | MemoryWord w = content.get(addr); 83 | sb.append(w).append('\n'); 84 | } 85 | return sb.toString(); 86 | } 87 | 88 | 89 | @Override 90 | public String toString() { 91 | return toBinaryRepresentation(); 92 | } 93 | 94 | } -------------------------------------------------------------------------------- /bcomp-assembler/src/main/java/ru/ifmo/cs/bcomp/assembler/WordDirective.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | package ru.ifmo.cs.bcomp.assembler; 7 | 8 | /** 9 | * 10 | * @author serge 11 | */ 12 | public class WordDirective extends MemoryWord { 13 | 14 | } 15 | -------------------------------------------------------------------------------- /bcomp-assembler/src/main/java/ru/ifmo/cs/bcomp/grammar/BCompNGBaseListener.java: -------------------------------------------------------------------------------- 1 | package ru.ifmo.cs.bcomp.grammar; 2 | 3 | import org.antlr.v4.runtime.ParserRuleContext; 4 | import org.antlr.v4.runtime.tree.ErrorNode; 5 | import org.antlr.v4.runtime.tree.TerminalNode; 6 | 7 | public class BCompNGBaseListener implements BCompNGListener { 8 | 9 | public void enterProg(BCompNGParser.ProgContext ctx) {} 10 | 11 | public void exitProg(BCompNGParser.ProgContext ctx) {} 12 | 13 | public void enterLine(BCompNGParser.LineContext ctx) {} 14 | 15 | public void exitLine(BCompNGParser.LineContext ctx) {} 16 | 17 | public void enterInstructionLine(BCompNGParser.InstructionLineContext ctx) {} 18 | 19 | public void exitInstructionLine(BCompNGParser.InstructionLineContext ctx) {} 20 | 21 | public void enterInstruction(BCompNGParser.InstructionContext ctx) {} 22 | 23 | public void exitInstruction(BCompNGParser.InstructionContext ctx) {} 24 | 25 | public void enterDirective(BCompNGParser.DirectiveContext ctx) {} 26 | 27 | public void exitDirective(BCompNGParser.DirectiveContext ctx) {} 28 | 29 | public void enterOrgAddress(BCompNGParser.OrgAddressContext ctx) {} 30 | 31 | public void exitOrgAddress(BCompNGParser.OrgAddressContext ctx) {} 32 | 33 | public void enterWordDirective(BCompNGParser.WordDirectiveContext ctx) {} 34 | 35 | public void exitWordDirective(BCompNGParser.WordDirectiveContext ctx) {} 36 | 37 | public void enterWordArguments(BCompNGParser.WordArgumentsContext ctx) {} 38 | 39 | public void exitWordArguments(BCompNGParser.WordArgumentsContext ctx) {} 40 | 41 | public void enterWordArgument(BCompNGParser.WordArgumentContext ctx) {} 42 | 43 | public void exitWordArgument(BCompNGParser.WordArgumentContext ctx) {} 44 | 45 | public void enterDupArgument(BCompNGParser.DupArgumentContext ctx) {} 46 | 47 | public void exitDupArgument(BCompNGParser.DupArgumentContext ctx) {} 48 | 49 | public void enterCount(BCompNGParser.CountContext ctx) {} 50 | 51 | public void exitCount(BCompNGParser.CountContext ctx) {} 52 | 53 | public void enterLbl(BCompNGParser.LblContext ctx) {} 54 | 55 | public void exitLbl(BCompNGParser.LblContext ctx) {} 56 | 57 | public void enterLabel(BCompNGParser.LabelContext ctx) {} 58 | 59 | public void exitLabel(BCompNGParser.LabelContext ctx) {} 60 | 61 | public void enterDev(BCompNGParser.DevContext ctx) {} 62 | 63 | public void exitDev(BCompNGParser.DevContext ctx) {} 64 | 65 | public void enterOperand(BCompNGParser.OperandContext ctx) {} 66 | 67 | public void exitOperand(BCompNGParser.OperandContext ctx) {} 68 | 69 | public void enterDirectAbsolute(BCompNGParser.DirectAbsoluteContext ctx) {} 70 | 71 | public void exitDirectAbsolute(BCompNGParser.DirectAbsoluteContext ctx) {} 72 | 73 | public void enterIndirect(BCompNGParser.IndirectContext ctx) {} 74 | 75 | public void exitIndirect(BCompNGParser.IndirectContext ctx) {} 76 | 77 | public void enterPostIncrement(BCompNGParser.PostIncrementContext ctx) {} 78 | 79 | public void exitPostIncrement(BCompNGParser.PostIncrementContext ctx) {} 80 | 81 | public void enterPreDecrement(BCompNGParser.PreDecrementContext ctx) {} 82 | 83 | public void exitPreDecrement(BCompNGParser.PreDecrementContext ctx) {} 84 | 85 | public void enterDisplacementSP(BCompNGParser.DisplacementSPContext ctx) {} 86 | 87 | public void exitDisplacementSP(BCompNGParser.DisplacementSPContext ctx) {} 88 | 89 | public void enterDirectRelative(BCompNGParser.DirectRelativeContext ctx) {} 90 | 91 | public void exitDirectRelative(BCompNGParser.DirectRelativeContext ctx) {} 92 | 93 | public void enterDirectLoad(BCompNGParser.DirectLoadContext ctx) {} 94 | 95 | public void exitDirectLoad(BCompNGParser.DirectLoadContext ctx) {} 96 | 97 | public void enterAddress(BCompNGParser.AddressContext ctx) {} 98 | 99 | public void exitAddress(BCompNGParser.AddressContext ctx) {} 100 | 101 | public void enterString(BCompNGParser.StringContext ctx) {} 102 | 103 | public void exitString(BCompNGParser.StringContext ctx) {} 104 | 105 | public void enterName(BCompNGParser.NameContext ctx) {} 106 | 107 | public void exitName(BCompNGParser.NameContext ctx) {} 108 | 109 | public void enterNumber(BCompNGParser.NumberContext ctx) {} 110 | 111 | public void exitNumber(BCompNGParser.NumberContext ctx) {} 112 | 113 | public void enterComment(BCompNGParser.CommentContext ctx) {} 114 | 115 | public void exitComment(BCompNGParser.CommentContext ctx) {} 116 | 117 | public void enterAddr(BCompNGParser.AddrContext ctx) {} 118 | 119 | public void exitAddr(BCompNGParser.AddrContext ctx) {} 120 | 121 | public void enterNonaddr(BCompNGParser.NonaddrContext ctx) {} 122 | 123 | public void exitNonaddr(BCompNGParser.NonaddrContext ctx) {} 124 | 125 | public void enterBranch(BCompNGParser.BranchContext ctx) {} 126 | 127 | public void exitBranch(BCompNGParser.BranchContext ctx) {} 128 | 129 | public void enterIo(BCompNGParser.IoContext ctx) {} 130 | 131 | public void exitIo(BCompNGParser.IoContext ctx) {} 132 | 133 | public void enterSp(BCompNGParser.SpContext ctx) {} 134 | 135 | public void exitSp(BCompNGParser.SpContext ctx) {} 136 | 137 | public void enterIp(BCompNGParser.IpContext ctx) {} 138 | 139 | public void exitIp(BCompNGParser.IpContext ctx) {} 140 | 141 | public void enterOrg(BCompNGParser.OrgContext ctx) {} 142 | 143 | public void exitOrg(BCompNGParser.OrgContext ctx) {} 144 | 145 | public void enterWord(BCompNGParser.WordContext ctx) {} 146 | 147 | public void exitWord(BCompNGParser.WordContext ctx) {} 148 | 149 | public void enterDup(BCompNGParser.DupContext ctx) {} 150 | 151 | public void exitDup(BCompNGParser.DupContext ctx) {} 152 | 153 | public void enterEnd(BCompNGParser.EndContext ctx) {} 154 | 155 | public void exitEnd(BCompNGParser.EndContext ctx) {} 156 | 157 | public void enterEveryRule(ParserRuleContext ctx) {} 158 | 159 | public void exitEveryRule(ParserRuleContext ctx) {} 160 | 161 | public void visitTerminal(TerminalNode node) {} 162 | 163 | public void visitErrorNode(ErrorNode node) {} 164 | } 165 | -------------------------------------------------------------------------------- /bcomp-assembler/src/main/java/ru/ifmo/cs/bcomp/grammar/BCompNGBaseVisitor.java: -------------------------------------------------------------------------------- 1 | package ru.ifmo.cs.bcomp.grammar; 2 | 3 | import org.antlr.v4.runtime.tree.AbstractParseTreeVisitor; 4 | import ru.ifmo.cs.bcomp.grammar.BCompNGParser; 5 | import ru.ifmo.cs.bcomp.grammar.BCompNGVisitor; 6 | 7 | public class BCompNGBaseVisitor extends AbstractParseTreeVisitor implements BCompNGVisitor { 8 | 9 | public Object visitProg(BCompNGParser.ProgContext ctx) { 10 | return this.visitChildren(ctx); 11 | } 12 | 13 | public Object visitLine(BCompNGParser.LineContext ctx) { 14 | return this.visitChildren(ctx); 15 | } 16 | 17 | public Object visitInstructionLine(BCompNGParser.InstructionLineContext ctx) { 18 | return this.visitChildren(ctx); 19 | } 20 | 21 | public Object visitInstruction(BCompNGParser.InstructionContext ctx) { 22 | return this.visitChildren(ctx); 23 | } 24 | 25 | public Object visitDirective(BCompNGParser.DirectiveContext ctx) { 26 | return this.visitChildren(ctx); 27 | } 28 | 29 | public Object visitOrgAddress(BCompNGParser.OrgAddressContext ctx) { 30 | return this.visitChildren(ctx); 31 | } 32 | 33 | public Object visitWordDirective(BCompNGParser.WordDirectiveContext ctx) { 34 | return this.visitChildren(ctx); 35 | } 36 | 37 | public Object visitWordArguments(BCompNGParser.WordArgumentsContext ctx) { 38 | return this.visitChildren(ctx); 39 | } 40 | 41 | public Object visitWordArgument(BCompNGParser.WordArgumentContext ctx) { 42 | return this.visitChildren(ctx); 43 | } 44 | 45 | public Object visitDupArgument(BCompNGParser.DupArgumentContext ctx) { 46 | return this.visitChildren(ctx); 47 | } 48 | 49 | public Object visitCount(BCompNGParser.CountContext ctx) { 50 | return this.visitChildren(ctx); 51 | } 52 | 53 | public Object visitLbl(BCompNGParser.LblContext ctx) { 54 | return this.visitChildren(ctx); 55 | } 56 | 57 | public Object visitLabel(BCompNGParser.LabelContext ctx) { 58 | return this.visitChildren(ctx); 59 | } 60 | 61 | public Object visitDev(BCompNGParser.DevContext ctx) { 62 | return this.visitChildren(ctx); 63 | } 64 | 65 | public Object visitOperand(BCompNGParser.OperandContext ctx) { 66 | return this.visitChildren(ctx); 67 | } 68 | 69 | public Object visitDirectAbsolute(BCompNGParser.DirectAbsoluteContext ctx) { 70 | return this.visitChildren(ctx); 71 | } 72 | 73 | public Object visitIndirect(BCompNGParser.IndirectContext ctx) { 74 | return this.visitChildren(ctx); 75 | } 76 | 77 | public Object visitPostIncrement(BCompNGParser.PostIncrementContext ctx) { 78 | return this.visitChildren(ctx); 79 | } 80 | 81 | public Object visitPreDecrement(BCompNGParser.PreDecrementContext ctx) { 82 | return this.visitChildren(ctx); 83 | } 84 | 85 | public Object visitDisplacementSP(BCompNGParser.DisplacementSPContext ctx) { 86 | return this.visitChildren(ctx); 87 | } 88 | 89 | public Object visitDirectRelative(BCompNGParser.DirectRelativeContext ctx) { 90 | return this.visitChildren(ctx); 91 | } 92 | 93 | public Object visitDirectLoad(BCompNGParser.DirectLoadContext ctx) { 94 | return this.visitChildren(ctx); 95 | } 96 | 97 | public Object visitAddress(BCompNGParser.AddressContext ctx) { 98 | return this.visitChildren(ctx); 99 | } 100 | 101 | public Object visitString(BCompNGParser.StringContext ctx) { 102 | return this.visitChildren(ctx); 103 | } 104 | 105 | public Object visitName(BCompNGParser.NameContext ctx) { 106 | return this.visitChildren(ctx); 107 | } 108 | 109 | public Object visitNumber(BCompNGParser.NumberContext ctx) { 110 | return this.visitChildren(ctx); 111 | } 112 | 113 | public Object visitComment(BCompNGParser.CommentContext ctx) { 114 | return this.visitChildren(ctx); 115 | } 116 | 117 | public Object visitAddr(BCompNGParser.AddrContext ctx) { 118 | return this.visitChildren(ctx); 119 | } 120 | 121 | public Object visitNonaddr(BCompNGParser.NonaddrContext ctx) { 122 | return this.visitChildren(ctx); 123 | } 124 | 125 | public Object visitBranch(BCompNGParser.BranchContext ctx) { 126 | return this.visitChildren(ctx); 127 | } 128 | 129 | public Object visitIo(BCompNGParser.IoContext ctx) { 130 | return this.visitChildren(ctx); 131 | } 132 | 133 | public Object visitSp(BCompNGParser.SpContext ctx) { 134 | return this.visitChildren(ctx); 135 | } 136 | 137 | public Object visitIp(BCompNGParser.IpContext ctx) { 138 | return this.visitChildren(ctx); 139 | } 140 | 141 | public Object visitOrg(BCompNGParser.OrgContext ctx) { 142 | return this.visitChildren(ctx); 143 | } 144 | 145 | public Object visitWord(BCompNGParser.WordContext ctx) { 146 | return this.visitChildren(ctx); 147 | } 148 | 149 | public Object visitDup(BCompNGParser.DupContext ctx) { 150 | return this.visitChildren(ctx); 151 | } 152 | 153 | public Object visitEnd(BCompNGParser.EndContext ctx) { 154 | return this.visitChildren(ctx); 155 | } 156 | } 157 | -------------------------------------------------------------------------------- /bcomp-assembler/src/main/java/ru/ifmo/cs/bcomp/grammar/BCompNGListener.java: -------------------------------------------------------------------------------- 1 | package ru.ifmo.cs.bcomp.grammar; 2 | 3 | import org.antlr.v4.runtime.tree.ParseTreeListener; 4 | import ru.ifmo.cs.bcomp.grammar.BCompNGParser; 5 | 6 | public interface BCompNGListener extends ParseTreeListener { 7 | 8 | void enterProg(BCompNGParser.ProgContext var1); 9 | 10 | void exitProg(BCompNGParser.ProgContext var1); 11 | 12 | void enterLine(BCompNGParser.LineContext var1); 13 | 14 | void exitLine(BCompNGParser.LineContext var1); 15 | 16 | void enterInstructionLine(BCompNGParser.InstructionLineContext var1); 17 | 18 | void exitInstructionLine(BCompNGParser.InstructionLineContext var1); 19 | 20 | void enterInstruction(BCompNGParser.InstructionContext var1); 21 | 22 | void exitInstruction(BCompNGParser.InstructionContext var1); 23 | 24 | void enterDirective(BCompNGParser.DirectiveContext var1); 25 | 26 | void exitDirective(BCompNGParser.DirectiveContext var1); 27 | 28 | void enterOrgAddress(BCompNGParser.OrgAddressContext var1); 29 | 30 | void exitOrgAddress(BCompNGParser.OrgAddressContext var1); 31 | 32 | void enterWordDirective(BCompNGParser.WordDirectiveContext var1); 33 | 34 | void exitWordDirective(BCompNGParser.WordDirectiveContext var1); 35 | 36 | void enterWordArguments(BCompNGParser.WordArgumentsContext var1); 37 | 38 | void exitWordArguments(BCompNGParser.WordArgumentsContext var1); 39 | 40 | void enterWordArgument(BCompNGParser.WordArgumentContext var1); 41 | 42 | void exitWordArgument(BCompNGParser.WordArgumentContext var1); 43 | 44 | void enterDupArgument(BCompNGParser.DupArgumentContext var1); 45 | 46 | void exitDupArgument(BCompNGParser.DupArgumentContext var1); 47 | 48 | void enterCount(BCompNGParser.CountContext var1); 49 | 50 | void exitCount(BCompNGParser.CountContext var1); 51 | 52 | void enterLbl(BCompNGParser.LblContext var1); 53 | 54 | void exitLbl(BCompNGParser.LblContext var1); 55 | 56 | void enterLabel(BCompNGParser.LabelContext var1); 57 | 58 | void exitLabel(BCompNGParser.LabelContext var1); 59 | 60 | void enterDev(BCompNGParser.DevContext var1); 61 | 62 | void exitDev(BCompNGParser.DevContext var1); 63 | 64 | void enterOperand(BCompNGParser.OperandContext var1); 65 | 66 | void exitOperand(BCompNGParser.OperandContext var1); 67 | 68 | void enterDirectAbsolute(BCompNGParser.DirectAbsoluteContext var1); 69 | 70 | void exitDirectAbsolute(BCompNGParser.DirectAbsoluteContext var1); 71 | 72 | void enterIndirect(BCompNGParser.IndirectContext var1); 73 | 74 | void exitIndirect(BCompNGParser.IndirectContext var1); 75 | 76 | void enterPostIncrement(BCompNGParser.PostIncrementContext var1); 77 | 78 | void exitPostIncrement(BCompNGParser.PostIncrementContext var1); 79 | 80 | void enterPreDecrement(BCompNGParser.PreDecrementContext var1); 81 | 82 | void exitPreDecrement(BCompNGParser.PreDecrementContext var1); 83 | 84 | void enterDisplacementSP(BCompNGParser.DisplacementSPContext var1); 85 | 86 | void exitDisplacementSP(BCompNGParser.DisplacementSPContext var1); 87 | 88 | void enterDirectRelative(BCompNGParser.DirectRelativeContext var1); 89 | 90 | void exitDirectRelative(BCompNGParser.DirectRelativeContext var1); 91 | 92 | void enterDirectLoad(BCompNGParser.DirectLoadContext var1); 93 | 94 | void exitDirectLoad(BCompNGParser.DirectLoadContext var1); 95 | 96 | void enterAddress(BCompNGParser.AddressContext var1); 97 | 98 | void exitAddress(BCompNGParser.AddressContext var1); 99 | 100 | void enterString(BCompNGParser.StringContext var1); 101 | 102 | void exitString(BCompNGParser.StringContext var1); 103 | 104 | void enterName(BCompNGParser.NameContext var1); 105 | 106 | void exitName(BCompNGParser.NameContext var1); 107 | 108 | void enterNumber(BCompNGParser.NumberContext var1); 109 | 110 | void exitNumber(BCompNGParser.NumberContext var1); 111 | 112 | void enterComment(BCompNGParser.CommentContext var1); 113 | 114 | void exitComment(BCompNGParser.CommentContext var1); 115 | 116 | void enterAddr(BCompNGParser.AddrContext var1); 117 | 118 | void exitAddr(BCompNGParser.AddrContext var1); 119 | 120 | void enterNonaddr(BCompNGParser.NonaddrContext var1); 121 | 122 | void exitNonaddr(BCompNGParser.NonaddrContext var1); 123 | 124 | void enterBranch(BCompNGParser.BranchContext var1); 125 | 126 | void exitBranch(BCompNGParser.BranchContext var1); 127 | 128 | void enterIo(BCompNGParser.IoContext var1); 129 | 130 | void exitIo(BCompNGParser.IoContext var1); 131 | 132 | void enterSp(BCompNGParser.SpContext var1); 133 | 134 | void exitSp(BCompNGParser.SpContext var1); 135 | 136 | void enterIp(BCompNGParser.IpContext var1); 137 | 138 | void exitIp(BCompNGParser.IpContext var1); 139 | 140 | void enterOrg(BCompNGParser.OrgContext var1); 141 | 142 | void exitOrg(BCompNGParser.OrgContext var1); 143 | 144 | void enterWord(BCompNGParser.WordContext var1); 145 | 146 | void exitWord(BCompNGParser.WordContext var1); 147 | 148 | void enterDup(BCompNGParser.DupContext var1); 149 | 150 | void exitDup(BCompNGParser.DupContext var1); 151 | 152 | void enterEnd(BCompNGParser.EndContext var1); 153 | 154 | void exitEnd(BCompNGParser.EndContext var1); 155 | } 156 | -------------------------------------------------------------------------------- /bcomp-assembler/src/main/java/ru/ifmo/cs/bcomp/grammar/BCompNGVisitor.java: -------------------------------------------------------------------------------- 1 | package ru.ifmo.cs.bcomp.grammar; 2 | 3 | import org.antlr.v4.runtime.tree.ParseTreeVisitor; 4 | import ru.ifmo.cs.bcomp.grammar.BCompNGParser; 5 | 6 | public interface BCompNGVisitor extends ParseTreeVisitor { 7 | 8 | Object visitProg(BCompNGParser.ProgContext var1); 9 | 10 | Object visitLine(BCompNGParser.LineContext var1); 11 | 12 | Object visitInstructionLine(BCompNGParser.InstructionLineContext var1); 13 | 14 | Object visitInstruction(BCompNGParser.InstructionContext var1); 15 | 16 | Object visitDirective(BCompNGParser.DirectiveContext var1); 17 | 18 | Object visitOrgAddress(BCompNGParser.OrgAddressContext var1); 19 | 20 | Object visitWordDirective(BCompNGParser.WordDirectiveContext var1); 21 | 22 | Object visitWordArguments(BCompNGParser.WordArgumentsContext var1); 23 | 24 | Object visitWordArgument(BCompNGParser.WordArgumentContext var1); 25 | 26 | Object visitDupArgument(BCompNGParser.DupArgumentContext var1); 27 | 28 | Object visitCount(BCompNGParser.CountContext var1); 29 | 30 | Object visitLbl(BCompNGParser.LblContext var1); 31 | 32 | Object visitLabel(BCompNGParser.LabelContext var1); 33 | 34 | Object visitDev(BCompNGParser.DevContext var1); 35 | 36 | Object visitOperand(BCompNGParser.OperandContext var1); 37 | 38 | Object visitDirectAbsolute(BCompNGParser.DirectAbsoluteContext var1); 39 | 40 | Object visitIndirect(BCompNGParser.IndirectContext var1); 41 | 42 | Object visitPostIncrement(BCompNGParser.PostIncrementContext var1); 43 | 44 | Object visitPreDecrement(BCompNGParser.PreDecrementContext var1); 45 | 46 | Object visitDisplacementSP(BCompNGParser.DisplacementSPContext var1); 47 | 48 | Object visitDirectRelative(BCompNGParser.DirectRelativeContext var1); 49 | 50 | Object visitDirectLoad(BCompNGParser.DirectLoadContext var1); 51 | 52 | Object visitAddress(BCompNGParser.AddressContext var1); 53 | 54 | Object visitString(BCompNGParser.StringContext var1); 55 | 56 | Object visitName(BCompNGParser.NameContext var1); 57 | 58 | Object visitNumber(BCompNGParser.NumberContext var1); 59 | 60 | Object visitComment(BCompNGParser.CommentContext var1); 61 | 62 | Object visitAddr(BCompNGParser.AddrContext var1); 63 | 64 | Object visitNonaddr(BCompNGParser.NonaddrContext var1); 65 | 66 | Object visitBranch(BCompNGParser.BranchContext var1); 67 | 68 | Object visitIo(BCompNGParser.IoContext var1); 69 | 70 | Object visitSp(BCompNGParser.SpContext var1); 71 | 72 | Object visitIp(BCompNGParser.IpContext var1); 73 | 74 | Object visitOrg(BCompNGParser.OrgContext var1); 75 | 76 | Object visitWord(BCompNGParser.WordContext var1); 77 | 78 | Object visitDup(BCompNGParser.DupContext var1); 79 | 80 | Object visitEnd(BCompNGParser.EndContext var1); 81 | } 82 | -------------------------------------------------------------------------------- /bcomp-ng-ui/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | ru.ifmo.cs 7 | BasicComputer 8 | 2 9 | 10 | ru.ifmo.cs 11 | bcomp-ng-ui 12 | 1 13 | bcomp-ng-ui 14 | http://maven.apache.org 15 | 16 | UTF-8 17 | 18 | 19 | 20 | 21 | org.codehaus.mojo 22 | buildnumber-maven-plugin 23 | 1.2 24 | 25 | 26 | validate 27 | 28 | create 29 | 30 | 31 | 32 | 33 | false 34 | false 35 | 36 | 37 | 38 | org.apache.maven.plugins 39 | maven-jar-plugin 40 | 2.3.2 41 | 42 | 43 | 44 | ${buildNumber} 45 | 46 | 47 | 48 | 49 | 50 | org.apache.maven.plugins 51 | maven-shade-plugin 52 | 2.1 53 | 54 | 55 | package 56 | 57 | shade 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | ru.ifmo.cs.bcomp.ui.BCompApp 66 | 67 | 68 | bcomp-ng 69 | 70 | 71 | 72 | org.apache.maven.plugins 73 | maven-compiler-plugin 74 | 75 | 8 76 | 8 77 | 78 | 79 | 80 | 81 | 82 | 83 | com.fifesoft 84 | rsyntaxtextarea 85 | 3.1.1 86 | 87 | 88 | junit 89 | junit 90 | 4.10 91 | test 92 | 93 | 94 | ${project.groupId} 95 | components 96 | ${project.version} 97 | 98 | 99 | ${project.groupId} 100 | bcomp-ng 101 | ${project.version} 102 | 103 | 104 | ${project.groupId} 105 | bcomp-assembler 106 | ${project.version} 107 | 108 | 109 | 110 | -------------------------------------------------------------------------------- /bcomp-ng-ui/src/main/java/ru/ifmo/cs/bcomp/ui/BCompApp.java: -------------------------------------------------------------------------------- 1 | /* 2 | * $Id$ 3 | */ 4 | 5 | package ru.ifmo.cs.bcomp.ui; 6 | 7 | import java.io.File; 8 | import java.io.FileInputStream; 9 | import java.nio.charset.Charset; 10 | import ru.ifmo.cs.bcomp.BasicComp; 11 | import ru.ifmo.cs.bcomp.ProgramBinary; 12 | import ru.ifmo.cs.bcomp.assembler.AsmNg; 13 | import ru.ifmo.cs.bcomp.assembler.Program; 14 | 15 | /** 16 | * 17 | * @author Dmitry Afanasiev 18 | */ 19 | public class BCompApp { 20 | public static void main(String[] args) throws Exception { 21 | BasicComp bcomp = new BasicComp(); 22 | String mpname; 23 | String app; 24 | 25 | try { 26 | app = System.getProperty("mode", "gui"); 27 | } catch (Exception e) { 28 | app = "gui"; 29 | } 30 | 31 | try { 32 | String code = System.getProperty("code", null); 33 | File file = new File(code); 34 | FileInputStream fin = null; 35 | 36 | try { 37 | fin = new FileInputStream(file); 38 | byte content[] = new byte[(int)file.length()]; 39 | fin.read(content); 40 | code = new String(content, Charset.forName("UTF-8")); 41 | AsmNg asm = new AsmNg(code); 42 | Program pobj = asm.compile(); 43 | if (asm.getErrors().isEmpty()) { 44 | ProgramBinary prog = new ProgramBinary(pobj.getBinaryFormat()); 45 | bcomp.loadProgram(prog); 46 | } else { 47 | for (String err : asm.getErrors()) 48 | System.out.println(err); 49 | } 50 | } finally { 51 | if (fin != null) 52 | fin.close(); 53 | } 54 | } catch (Exception e) { } 55 | 56 | try { 57 | String debuglevel = System.getProperty("debuglevel", "0"); 58 | bcomp.getCPU().setDebugLevel(Long.parseLong(debuglevel)); 59 | } catch (Exception e) { } 60 | 61 | if (app.equals("gui")) { 62 | GUI gui = new GUI(bcomp); 63 | gui.gui(); 64 | return; 65 | } 66 | 67 | if (app.equals("cli")) { 68 | CLI cli = new CLI(bcomp); 69 | cli.cli(); 70 | return; 71 | } 72 | 73 | if (app.equals("decoder")) { 74 | MicroCodeDecoder mpdecoder = new MicroCodeDecoder(bcomp); 75 | mpdecoder.decode(); 76 | return; 77 | } 78 | 79 | if (app.equals("nightmare")) { 80 | Nightmare nightmare = new Nightmare(bcomp); 81 | return; 82 | } 83 | 84 | System.err.println("Invalid mode selected"); 85 | } 86 | } -------------------------------------------------------------------------------- /bcomp-ng-ui/src/main/java/ru/ifmo/cs/bcomp/ui/GUI.java: -------------------------------------------------------------------------------- 1 | /* 2 | * $Id$ 3 | */ 4 | 5 | package ru.ifmo.cs.bcomp.ui; 6 | 7 | import ru.ifmo.cs.bcomp.BasicComp; 8 | import ru.ifmo.cs.bcomp.CPU; 9 | import ru.ifmo.cs.bcomp.IOCtrl; 10 | import ru.ifmo.cs.bcomp.ui.components.*; 11 | 12 | import javax.swing.*; 13 | import javax.swing.event.ChangeEvent; 14 | import javax.swing.event.ChangeListener; 15 | import java.awt.*; 16 | import java.awt.event.ComponentAdapter; 17 | import java.awt.event.ComponentEvent; 18 | 19 | import static ru.ifmo.cs.bcomp.ui.components.DisplayStyles.PANE_SIZE; 20 | 21 | /** 22 | * 23 | * @author Dmitry Afanasiev 24 | */ 25 | public class GUI extends JApplet { 26 | private ComponentManager cmanager; 27 | private JTabbedPane tabs; 28 | private ActivateblePanel activePanel = null; 29 | private final BasicComp bcomp; 30 | private final CPU cpu; 31 | private boolean isHex = true; 32 | 33 | 34 | public GUI(BasicComp bcomp) { 35 | this.bcomp = bcomp; 36 | this.cpu = bcomp.getCPU(); 37 | } 38 | 39 | 40 | @Override 41 | public void init() { 42 | cmanager = new ComponentManager(this); 43 | 44 | 45 | final ActivateblePanel[] panels = { 46 | new BasicView(this, isHex), 47 | new AssemblerView(this), 48 | new TraceView(this), 49 | new DebugView(this) 50 | }; 51 | 52 | tabs = new JTabbedPane(){ 53 | @Override 54 | protected void paintComponent(Graphics g) { 55 | g.setColor(DisplayStyles.COLOR_BACKGROUND_STYLE); 56 | g.fillRect(0 ,0, this.getWidth(), this.getHeight()); 57 | super.paintComponent(g); 58 | } 59 | }; 60 | 61 | tabs.addKeyListener(cmanager.getKeyListener()); 62 | 63 | tabs.addChangeListener(new ChangeListener() { 64 | 65 | public void stateChanged(ChangeEvent e) { 66 | if (activePanel != null) 67 | activePanel.panelDeactivate(); 68 | 69 | activePanel = (ActivateblePanel)tabs.getSelectedComponent(); 70 | activePanel.panelActivate(); 71 | } 72 | }); 73 | 74 | 75 | tabs.addComponentListener(new ComponentAdapter() { 76 | @Override 77 | public void componentResized(ComponentEvent componentEvent) { 78 | super.componentResized(componentEvent); 79 | for (ActivateblePanel panel : panels) { 80 | panel.revalidate(); 81 | panel.repaint(); 82 | panel.redrawArrows(); 83 | } 84 | } 85 | }); 86 | for (ActivateblePanel pane : panels) { 87 | pane.setPreferredSize(PANE_SIZE); 88 | 89 | tabs.addTab(pane.getPanelName(), pane); 90 | } 91 | 92 | add(tabs); 93 | } 94 | 95 | @Override 96 | public void start() { 97 | cmanager.switchFocus(); 98 | } 99 | 100 | public void gui() throws Exception { 101 | bcomp.startTimer(); 102 | 103 | JFrame frame = new JFrame("БЭВМ"); 104 | 105 | frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); 106 | frame.getContentPane().add(this); 107 | init(); 108 | frame.pack(); 109 | 110 | frame.setVisible(true); 111 | frame.setMinimumSize(frame.getSize()); 112 | start(); 113 | } 114 | 115 | public BasicComp getBasicComp() { 116 | return bcomp; 117 | } 118 | 119 | public CPU getCPU() { 120 | return cpu; 121 | } 122 | 123 | public IOCtrl[] getIOCtrls() { 124 | return bcomp.getIOCtrls(); 125 | } 126 | 127 | public ComponentManager getComponentManager() { 128 | return cmanager; 129 | } 130 | 131 | } 132 | -------------------------------------------------------------------------------- /bcomp-ng-ui/src/main/java/ru/ifmo/cs/bcomp/ui/MicroCodeDecoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * $Id$ 3 | */ 4 | 5 | package ru.ifmo.cs.bcomp.ui; 6 | 7 | import ru.ifmo.cs.bcomp.BasicComp; 8 | import ru.ifmo.cs.bcomp.CPU; 9 | import ru.ifmo.cs.bcomp.MicroCode; 10 | 11 | import static ru.ifmo.cs.bcomp.MCDecoder.getFormattedMC; 12 | import static ru.ifmo.cs.bcomp.RunningCycle.INFETCH; 13 | import static ru.ifmo.cs.bcomp.RunningCycle.RESERVED; 14 | 15 | /** 16 | * 17 | * @author Dmitry Afanasiev 18 | */ 19 | public class MicroCodeDecoder { 20 | private final CPU cpu; 21 | private final MicroCode mc; 22 | 23 | public MicroCodeDecoder(BasicComp bcomp) { 24 | cpu = bcomp.getCPU(); 25 | mc = cpu.getMicroCodeSource(); 26 | cpu.stopCPU(); 27 | } 28 | 29 | public void decode() throws Exception { 30 | int infetch = mc.findLabel(INFETCH.name()); 31 | int reserved = mc.findLabel(RESERVED.name()); 32 | 33 | for (int addr = infetch; addr < reserved; System.out.println(getFormattedMC(cpu, addr++))); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /bcomp-ng-ui/src/main/java/ru/ifmo/cs/bcomp/ui/components/ALUView.java: -------------------------------------------------------------------------------- 1 | /* 2 | * $Id$ 3 | */ 4 | 5 | package ru.ifmo.cs.bcomp.ui.components; 6 | 7 | import javax.swing.*; 8 | import java.awt.*; 9 | 10 | import static ru.ifmo.cs.bcomp.ui.components.DisplayStyles.*; 11 | 12 | /** 13 | * 14 | * @author Dmitry Afanasiev 15 | */ 16 | public class ALUView extends JComponent { 17 | private int xpoints[]; 18 | private int ypoints[]; 19 | 20 | public ALUView(int x, int y, int width, int height) { 21 | int half = width / 2; 22 | int offset = height / 3; 23 | int soffset = offset / 3; 24 | 25 | xpoints = new int[] { 26 | 0, half - soffset, half, half + soffset, width - 1, width - 1 - offset, offset 27 | }; 28 | ypoints = new int[] { 29 | 0, 0, offset, 0, 0, height - 1, height - 1 30 | }; 31 | 32 | JLabel title = new JLabel("ALU", JLabel.CENTER); 33 | title.setFont(FONT_COURIER_BOLD_45); 34 | title.setBounds(offset, offset, width - 2 * offset, height - offset); 35 | title.setForeground(COLOR_TEXT); 36 | add(title); 37 | 38 | setBounds(x, y, width, height); 39 | } 40 | 41 | @Override 42 | public void paintComponent(Graphics g) { 43 | g.setColor(COLOR_TITLE); 44 | g.fillPolygon(xpoints, ypoints, xpoints.length); 45 | g.setColor(COLOR_TEXT); 46 | g.drawPolygon(xpoints, ypoints, xpoints.length); 47 | 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /bcomp-ng-ui/src/main/java/ru/ifmo/cs/bcomp/ui/components/ActivateblePanel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * $Id$ 3 | */ 4 | 5 | package ru.ifmo.cs.bcomp.ui.components; 6 | 7 | import javax.swing.JComponent; 8 | 9 | /** 10 | * 11 | * @author Dmitry Afanasiev 12 | */ 13 | public abstract class ActivateblePanel extends JComponent { 14 | public abstract void panelActivate(); 15 | public abstract void panelDeactivate(); 16 | public abstract String getPanelName(); 17 | public abstract void redrawArrows(); 18 | } 19 | -------------------------------------------------------------------------------- /bcomp-ng-ui/src/main/java/ru/ifmo/cs/bcomp/ui/components/ActiveBitView.java: -------------------------------------------------------------------------------- 1 | /* 2 | * $Id$ 3 | */ 4 | 5 | package ru.ifmo.cs.bcomp.ui.components; 6 | 7 | import javax.swing.JLabel; 8 | import ru.ifmo.cs.components.Utils; 9 | import static ru.ifmo.cs.bcomp.ui.components.DisplayStyles.CELL_HEIGHT; 10 | import static ru.ifmo.cs.bcomp.ui.components.DisplayStyles.COLOR_INPUT_TITLE; 11 | 12 | /** 13 | * 14 | * @author Dmitry Afanasiev 15 | */ 16 | public class ActiveBitView extends BCompComponent { 17 | private final JLabel value = addValueLabel(); 18 | 19 | public ActiveBitView(int x, int y) { 20 | super("",0, COLOR_INPUT_TITLE); 21 | 22 | setBounds(x, y, getValueWidth(2, true)); 23 | value.setBounds(1, 1, width - 2, CELL_HEIGHT); 24 | } 25 | protected void setBounds(int x, int y, int wight){ 26 | setBounds(x,y,this.width=wight,height); 27 | } 28 | 29 | public void setValue(int value) { 30 | this.value.setText(Utils.toHex(value, 1)); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /bcomp-ng-ui/src/main/java/ru/ifmo/cs/bcomp/ui/components/AssemblerView.java: -------------------------------------------------------------------------------- 1 | /* 2 | * $Id$ 3 | */ 4 | 5 | package ru.ifmo.cs.bcomp.ui.components; 6 | 7 | import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea; 8 | import org.fife.ui.rsyntaxtextarea.SyntaxConstants; 9 | import org.fife.ui.rsyntaxtextarea.Theme; 10 | import org.fife.ui.rtextarea.RTextScrollPane; 11 | import ru.ifmo.cs.bcomp.CPU; 12 | import ru.ifmo.cs.bcomp.ProgramBinary; 13 | import ru.ifmo.cs.bcomp.assembler.AsmNg; 14 | import ru.ifmo.cs.bcomp.assembler.Program; 15 | import ru.ifmo.cs.bcomp.ui.GUI; 16 | 17 | import javax.swing.*; 18 | import java.awt.*; 19 | import java.awt.event.ActionEvent; 20 | import java.awt.event.ActionListener; 21 | import java.io.IOException; 22 | import java.util.Date; 23 | 24 | import static ru.ifmo.cs.bcomp.ui.components.DisplayStyles.*; 25 | 26 | /** 27 | * 28 | * @author Dmitry Afanasiev 29 | */ 30 | public class AssemblerView extends BCompPanel implements ActionListener { 31 | private final GUI gui; 32 | private final CPU cpu; 33 | private final ComponentManager cmanager; 34 | private final RSyntaxTextArea text; 35 | private final JTextArea errorarea; 36 | 37 | 38 | 39 | public AssemblerView(final GUI gui) { 40 | super (gui.getComponentManager(),null,null); 41 | this.gui = gui; 42 | this.cpu = gui.getCPU(); 43 | this.cmanager = gui.getComponentManager(); 44 | 45 | JPanel pane = new JPanel(new BorderLayout()); 46 | pane.setBackground(COLOR_BACKGROUND); 47 | 48 | text = new RSyntaxTextArea(); 49 | text.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_ASSEMBLER_X86); 50 | text.setCodeFoldingEnabled(true); 51 | text.setBackground(COLOR_BACKGROUND); 52 | text.setForeground(COLOR_TEXT); 53 | RTextScrollPane scroll = new RTextScrollPane(text); 54 | pane.add(scroll,BorderLayout.CENTER); 55 | Theme theme = null; 56 | try { 57 | theme = Theme.load(DisplayStyles.class.getClassLoader().getResourceAsStream("dark.xml")); 58 | } catch (IOException e) { 59 | e.printStackTrace(); 60 | } 61 | theme.apply(text); 62 | 63 | JButton button = new JButton(cmanager.getRes().getString("compile")); 64 | button.setForeground(COLOR_TEXT); 65 | button.setBackground(COLOR_VALUE); 66 | button.setFont(FONT_COURIER_PLAIN_12); 67 | button.setFocusable(false); 68 | button.addActionListener(this); 69 | JPanel buttonpane = new JPanel(); 70 | //buttonpane.applyComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT); 71 | buttonpane.add(button); 72 | //button.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT); 73 | pane.add(buttonpane,BorderLayout.PAGE_START); 74 | errorarea = new JTextArea(); 75 | //errorarea.setRows(3); 76 | errorarea.setEditable(false); 77 | errorarea.setBackground(COLOR_BACKGROUND); 78 | errorarea.setForeground(COLOR_TEXT); 79 | JScrollPane errscroll = new JScrollPane(errorarea); 80 | errscroll.setBackground(COLOR_BACKGROUND); 81 | pane.add(errscroll,BorderLayout.SOUTH); 82 | 83 | JSplitPane splitpane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, pane, errscroll); 84 | splitpane.setDividerSize(4); 85 | splitpane.setDividerLocation((int)(PANE_HEIGHT*0.8)); // TODO FIX ALL Layouts 86 | add(splitpane); 87 | 88 | } 89 | 90 | @Override 91 | public void panelActivate() { 92 | text.requestFocus(); 93 | } 94 | 95 | @Override 96 | public void panelDeactivate() { } 97 | 98 | @Override 99 | public String getPanelName() { 100 | return cmanager.getRes().getString("assembler"); 101 | } 102 | 103 | private void showError(String msg) { 104 | JOptionPane.showMessageDialog(gui, msg, cmanager.getRes().getString("error"), JOptionPane.ERROR_MESSAGE); 105 | } 106 | 107 | @Override 108 | public void redrawArrows() { 109 | //no arrows no draw 110 | } 111 | 112 | @Override 113 | public void actionPerformed(ActionEvent e) { 114 | if (cpu.isLocked()) { 115 | showError(cmanager.getRes().getString("stopRunning")); 116 | return; 117 | } 118 | 119 | cmanager.saveDelay(); 120 | boolean clock = cpu.getClockState(); 121 | cpu.setClockState(true); 122 | long starttime = System.currentTimeMillis(); 123 | AsmNg asm = new AsmNg(text.getText()); 124 | Program pobj = asm.compile(); 125 | long finishtime = System.currentTimeMillis(); 126 | String errors = new String(); 127 | String st = "Start compilation at "+new Date(starttime)+"\n"; 128 | String ft = "Finish compilation at "+new Date(finishtime)+"\n"; 129 | errors = st; 130 | for (String err: asm.getErrors()) { 131 | errors = errors + err + '\n'; 132 | } 133 | 134 | errors = errors + ft; 135 | if(asm.getErrors().isEmpty()) errors = errors + "\n" + pobj.toCompiledWords(); 136 | 137 | errorarea.setText(errors); 138 | if (pobj != null) { 139 | gui.getBasicComp().loadProgram(new ProgramBinary(pobj.getBinaryFormat())); 140 | } 141 | 142 | cpu.setClockState(clock); 143 | cmanager.clearActiveSignals(); 144 | cmanager.restoreDelay(); 145 | } 146 | 147 | @Override 148 | public void paintComponent(Graphics g) { 149 | 150 | } 151 | } 152 | 153 | -------------------------------------------------------------------------------- /bcomp-ng-ui/src/main/java/ru/ifmo/cs/bcomp/ui/components/BCompComponent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * $Id$ 3 | */ 4 | 5 | package ru.ifmo.cs.bcomp.ui.components; 6 | 7 | import ru.ifmo.cs.components.Utils; 8 | 9 | import javax.swing.*; 10 | import java.awt.*; 11 | 12 | import static ru.ifmo.cs.bcomp.ui.components.DisplayStyles.*; 13 | 14 | /** 15 | * 16 | * @author dima 17 | */ 18 | public class BCompComponent extends BorderedComponent { 19 | protected JLabel title; 20 | 21 | BCompComponent(String title, int ncells, Color color) { 22 | super(3 + CELL_HEIGHT * (ncells + 1)); 23 | 24 | this.title = addLabel(title, FONT_COURIER_BOLD_18, color); 25 | this.title.setForeground(COLOR_TEXT); 26 | } 27 | 28 | public BCompComponent(String title, Color colorTitleBG) { 29 | this(title, 1, colorTitleBG); 30 | } 31 | 32 | public BCompComponent(String title, int ncells) { 33 | this(title, ncells, COLOR_TITLE); 34 | } 35 | 36 | private final JLabel addValueLabel(String value, Color color) { 37 | return addLabel(value, FONT_COURIER_BOLD_21, color); 38 | } 39 | 40 | protected final JLabel addValueLabel(Color color) { 41 | return addValueLabel("", color); 42 | } 43 | 44 | protected JLabel addValueLabel(String value) { 45 | return addValueLabel(value, COLOR_VALUE); 46 | } 47 | 48 | protected final JLabel addValueLabel() { 49 | return addValueLabel("", COLOR_VALUE); 50 | } 51 | 52 | @Override 53 | protected void setBounds(int x, int y, int width) { 54 | super.setBounds(x, y, width); 55 | title.setBounds(1, 1, width - 2, CELL_HEIGHT); 56 | } 57 | 58 | protected int getValueY(int n) { 59 | return 2 + CELL_HEIGHT * (n + 1); 60 | } 61 | 62 | 63 | 64 | private int getPixelWidth(int chars) { 65 | return 2 + FONT_COURIER_BOLD_21_WIDTH * (1 + chars); 66 | } 67 | 68 | protected int getValueWidth(int width) { 69 | return getPixelWidth(Utils.getHexWidth(width)); 70 | } 71 | 72 | protected int getValueWidth(int width, boolean hex) { 73 | return hex ? getValueWidth(width) : getPixelWidth(Utils.getBinaryWidth(width)); 74 | } 75 | 76 | public void setTitle(String title) { 77 | this.title.setText(title); 78 | } 79 | 80 | @Override 81 | public void paintComponent(Graphics g) { 82 | g.drawLine(1, 26, this.width - 2, 26); 83 | g.setColor(DisplayStyles.COLOR_BACKGROUND_STYLE); 84 | g.fillRect(0, 0, this.width, this.height); 85 | super.paintComponent(g); 86 | 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /bcomp-ng-ui/src/main/java/ru/ifmo/cs/bcomp/ui/components/BCompLabel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * $Id$ 3 | */ 4 | 5 | package ru.ifmo.cs.bcomp.ui.components; 6 | 7 | import javax.swing.JLabel; 8 | import static ru.ifmo.cs.bcomp.ui.components.DisplayStyles.*; 9 | 10 | /** 11 | * 12 | * @author Dmitry Afanasiev 13 | */ 14 | public class BCompLabel extends BorderedComponent { 15 | public BCompLabel(int x, int y, int width, String ... text) { 16 | super(text.length * CELL_HEIGHT + 2); 17 | 18 | setBounds(x, y, width); 19 | 20 | for (int i = 0; i < text.length; i++) { 21 | JLabel title = addLabel(text[i], FONT_COURIER_BOLD_21, COLOR_TITLE); 22 | title.setBounds(1, 1 + i * CELL_HEIGHT, width - 2, CELL_HEIGHT); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /bcomp-ng-ui/src/main/java/ru/ifmo/cs/bcomp/ui/components/BCompPanel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * $Id$ 3 | */ 4 | 5 | package ru.ifmo.cs.bcomp.ui.components; 6 | 7 | import ru.ifmo.cs.bcomp.ControlSignal; 8 | import ru.ifmo.cs.bcomp.SignalListener; 9 | 10 | import javax.swing.*; 11 | import java.awt.*; 12 | import java.util.ArrayList; 13 | import java.util.Map; 14 | 15 | import static ru.ifmo.cs.bcomp.ui.components.DisplayStyles.COLOR_ACTIVE; 16 | import static ru.ifmo.cs.bcomp.ui.components.DisplayStyles.COLOR_BUS; 17 | 18 | /** 19 | * 20 | * @author Dmitry Afanasiev 21 | */ 22 | public abstract class BCompPanel extends ActivateblePanel { 23 | protected final ComponentManager cmanager; 24 | private final RegisterProperties[] regProps; 25 | protected Map busesMap; 26 | 27 | private SignalListener[] listeners; 28 | protected RegPanel regPanel; 29 | FlagView[] flags; 30 | 31 | 32 | public BCompPanel(ComponentManager cmanager, RegisterProperties[] regProps, Map baseMap) { 33 | setLayout(new BorderLayout()); 34 | this.cmanager = cmanager; 35 | this.regProps = regProps; 36 | this.busesMap = baseMap; 37 | regPanel = new RegPanel(); 38 | 39 | } 40 | protected class RegPanel extends JComponent { 41 | RegPanel() { 42 | setLayout(new GridBagLayout()); 43 | } 44 | } 45 | 46 | protected void setSignalListeners(SignalListener[] listeners) { 47 | this.listeners = listeners; 48 | } 49 | 50 | protected SignalListener[] getSignalListeners() { 51 | return listeners; 52 | } 53 | 54 | private void drawBuses(Graphics g) { 55 | ArrayList openbuses = new ArrayList(); 56 | ArrayList signals = cmanager.getActiveSignals(); 57 | 58 | for (BusView bus : busesMap.values()) { 59 | for (ControlSignal signal : bus.getSignals()) 60 | if (signals.contains(signal)) 61 | openbuses.add(bus); 62 | 63 | bus.draw(g, COLOR_BUS); 64 | } 65 | 66 | for (BusView bus : openbuses) 67 | bus.draw(g, COLOR_ACTIVE); 68 | } 69 | 70 | private void drawOpenBuses(Color color) { 71 | Graphics g = getGraphics(); 72 | ArrayList signals = cmanager.getActiveSignals(); 73 | 74 | for (BusView bus : busesMap.values()) 75 | for (ControlSignal signal : bus.getSignals()) 76 | if (signals.contains(signal)) 77 | bus.draw(g, color); 78 | } 79 | 80 | public void stepStart() { 81 | drawOpenBuses(COLOR_BUS); 82 | } 83 | 84 | public void stepFinish() { 85 | drawOpenBuses(COLOR_ACTIVE); 86 | } 87 | 88 | @Override 89 | public void panelActivate() { 90 | // for (RegisterProperties prop : regProps) { 91 | // RegisterView reg = cmanager.getRegisterView(prop.reg); 92 | // reg.setProperties(prop.x, prop.y, prop.hex); 93 | // add(reg); 94 | // } 95 | 96 | cmanager.panelActivate(this); 97 | 98 | for (RegisterProperties prop : regProps) { 99 | RegisterView reg = cmanager.getRegisterView(prop.reg); 100 | reg.setProperties(prop.x, prop.y, prop.hex,prop.isLeft); 101 | reg.setPreferredSize(reg.getSize()); 102 | reg.setTitle(prop.reg.toString()); 103 | regPanel.add(reg, prop.constraints); 104 | } 105 | } 106 | 107 | @Override 108 | public void panelDeactivate() { 109 | cmanager.panelDeactivate(); 110 | } 111 | 112 | @Override 113 | public void paintComponent(Graphics g) { 114 | DisplayStyles.setGraphics(g, this); 115 | drawBuses(g); 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /bcomp-ng-ui/src/main/java/ru/ifmo/cs/bcomp/ui/components/BorderedComponent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * $Id$ 3 | */ 4 | 5 | package ru.ifmo.cs.bcomp.ui.components; 6 | 7 | import java.awt.Color; 8 | import java.awt.Font; 9 | import java.awt.Graphics; 10 | import javax.swing.JComponent; 11 | import javax.swing.JLabel; 12 | import static ru.ifmo.cs.bcomp.ui.components.DisplayStyles.COLOR_TEXT; 13 | 14 | /** 15 | * 16 | * @author Dmitry Afanasiev 17 | */ 18 | public class BorderedComponent extends JComponent { 19 | protected int width; 20 | protected final int height; 21 | 22 | protected BorderedComponent(int height) { 23 | this.height = height; 24 | } 25 | 26 | protected final JLabel addLabel(String value, Font font, Color color) { 27 | JLabel label = new JLabel(value, JLabel.CENTER); 28 | label.setFont(font); 29 | label.setBackground(color); 30 | label.setOpaque(true); 31 | add(label); 32 | return label; 33 | } 34 | 35 | protected void setBounds(int x, int y, int width) { 36 | setBounds(x, y, this.width = width, height); 37 | } 38 | 39 | @Override 40 | public void paintComponent(Graphics g) { 41 | g.setColor(COLOR_TEXT); 42 | g.drawRect(0, 0, width - 1, height - 1); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /bcomp-ng-ui/src/main/java/ru/ifmo/cs/bcomp/ui/components/BusNames.java: -------------------------------------------------------------------------------- 1 | package ru.ifmo.cs.bcomp.ui.components; 2 | 3 | public enum BusNames { 4 | DR_ALU, 5 | CR_ALU, 6 | IP_ALU, 7 | SP_ALU, 8 | AC_ALU, 9 | BR_ALU, 10 | PS_ALU, 11 | IR_ALU, 12 | ALU_COMM, 13 | COMM_ALL, 14 | COMM_DR, 15 | COMM_CR, 16 | COMM_IP, 17 | COMM_SP, 18 | COMM_AC, 19 | COMM_AR, 20 | COMM_BR, 21 | COMM_PS, 22 | MEM_IO, 23 | MEM_W, 24 | MEM_R, 25 | CU 26 | 27 | 28 | } 29 | -------------------------------------------------------------------------------- /bcomp-ng-ui/src/main/java/ru/ifmo/cs/bcomp/ui/components/BusView.java: -------------------------------------------------------------------------------- 1 | /* 2 | * $Id: BusView.java 501 2019-10-11 08:23:26Z MATPOCKuH@mini $ 3 | */ 4 | 5 | package ru.ifmo.cs.bcomp.ui.components; 6 | 7 | import java.awt.*; 8 | 9 | 10 | import ru.ifmo.cs.bcomp.ControlSignal; 11 | 12 | import static ru.ifmo.cs.bcomp.ui.components.DisplayStyles.BUS_WIDTH; 13 | import static java.lang.Math.*; 14 | import static ru.ifmo.cs.bcomp.ui.components.DisplayStyles.COLOR_BACKGROUND; 15 | 16 | 17 | /** 18 | * 19 | * @author Dmitry Afanasiev 20 | */ 21 | public class BusView { 22 | private final ControlSignal[] signals; 23 | private int xs[]; 24 | private int ys[]; 25 | private int widths[]; 26 | private int heights[]; 27 | private int[] arrowX = new int[3]; 28 | private int[] arrowY = new int[3]; 29 | 30 | private boolean isVisible = true; 31 | 32 | public BusView( ControlSignal ... signals) { 33 | this.signals = signals; 34 | 35 | } 36 | 37 | public void calcBounds(int[][] points) { 38 | int npoints = points.length - 1; 39 | int x1, x2 = 0, y1, y2 = 0, width = 0, height = 0; 40 | 41 | xs = new int[npoints]; 42 | ys = new int[npoints]; 43 | widths = new int[npoints]; 44 | heights = new int[npoints]; 45 | 46 | for (int i = 0; i < npoints; i++) { 47 | x1 = points[i][0]; 48 | x2 = points[i + 1][0]; 49 | y1 = points[i][1]; 50 | y2 = points[i + 1][1]; 51 | width = x1 - x2; 52 | 53 | if (width != 0) { 54 | xs[i] = (width < 0) ? x1 - BUS_WIDTH : x2 - BUS_WIDTH; 55 | widths[i] = abs(width) + 2 * BUS_WIDTH + 1; 56 | ys[i] = y1 - BUS_WIDTH; 57 | heights[i] = 2 * BUS_WIDTH + 1; 58 | } else { 59 | height = y1 - y2; 60 | 61 | xs[i] = x1 - BUS_WIDTH; 62 | widths[i] = 2 * BUS_WIDTH + 1; 63 | ys[i] = (height < 0) ? y1 - BUS_WIDTH : y2 - BUS_WIDTH; 64 | heights[i] = abs(height) + 2 * BUS_WIDTH + 1; 65 | } 66 | } 67 | 68 | if (width != 0) { 69 | arrowY[0] = y2; 70 | arrowY[1] = y2 - 2 * BUS_WIDTH; 71 | arrowY[2] = y2 + 2 * BUS_WIDTH; 72 | 73 | if (width > 0) { 74 | arrowX[0] = x2 - 3 * BUS_WIDTH - 1; 75 | arrowX[1] = arrowX[2] = x2 - BUS_WIDTH - 1; 76 | } else { 77 | arrowX[0] = x2 + 3 * BUS_WIDTH + 1; 78 | arrowX[1] = arrowX[2] = x2 + BUS_WIDTH + 1; 79 | } 80 | } else { 81 | arrowX[0] = x2; 82 | arrowX[1] = x2 - 2 * BUS_WIDTH; 83 | arrowX[2] = x2 + 2 * BUS_WIDTH; 84 | 85 | if (height > 0) { 86 | arrowY[0] = y2 - 3 * BUS_WIDTH - 1; 87 | arrowY[1] = arrowY[2] = y2 - BUS_WIDTH - 1; 88 | } else { 89 | arrowY[0] = y2 + 3 * BUS_WIDTH + 1; 90 | arrowY[1] = arrowY[2] = y2 + BUS_WIDTH + 1; 91 | } 92 | } 93 | } 94 | 95 | public void draw(Graphics g, Color color) { 96 | if (isVisible) { 97 | g.setColor(color); 98 | } else { 99 | g.setColor(COLOR_BACKGROUND); 100 | } 101 | g.drawPolygon(arrowX, arrowY, arrowX.length); 102 | g.fillPolygon(arrowX, arrowY, arrowX.length); 103 | 104 | for (int i = 0; i < xs.length; i++) 105 | g.fillRect(xs[i], ys[i], widths[i], heights[i]); 106 | } 107 | 108 | 109 | 110 | public ControlSignal[] getSignals() { 111 | return signals; 112 | } 113 | } -------------------------------------------------------------------------------- /bcomp-ng-ui/src/main/java/ru/ifmo/cs/bcomp/ui/components/CommutView.java: -------------------------------------------------------------------------------- 1 | package ru.ifmo.cs.bcomp.ui.components; 2 | 3 | import javax.swing.*; 4 | import java.awt.*; 5 | 6 | import static ru.ifmo.cs.bcomp.ui.components.DisplayStyles.*; 7 | 8 | 9 | public class CommutView extends JComponent { 10 | 11 | 12 | private int x,y,wight,height; 13 | 14 | 15 | public CommutView(int x, int y, int width, int height) { 16 | 17 | this.x=x;this.y=y;this.wight=width;this.height=height; 18 | 19 | JLabel title = new JLabel("Commutator", JLabel.CENTER); 20 | title.setFont(FONT_COURIER_BOLD_21); 21 | title.setBounds(x, y, width, height); 22 | title.setForeground(COLOR_TEXT); 23 | add(title); 24 | 25 | setBounds(x, y, width, height); 26 | } 27 | 28 | @Override 29 | public void paintComponent(Graphics g) { 30 | g.setColor(COLOR_TITLE); 31 | g.fillRect(x, y, wight,height); 32 | g.setColor(COLOR_TEXT); 33 | g.drawRect(x, y,wight-1,height-1); 34 | } 35 | } 36 | 37 | -------------------------------------------------------------------------------- /bcomp-ng-ui/src/main/java/ru/ifmo/cs/bcomp/ui/components/FlagView.java: -------------------------------------------------------------------------------- 1 | package ru.ifmo.cs.bcomp.ui.components; 2 | 3 | import javax.swing.*; 4 | import java.awt.*; 5 | 6 | import static ru.ifmo.cs.bcomp.ui.components.DisplayStyles.*; 7 | 8 | public class FlagView extends JComponent { 9 | JLabel title; 10 | 11 | private int x,y,wight,height; 12 | boolean active; 13 | 14 | 15 | public FlagView(int x, int y, int wigth, int height) { 16 | 17 | this.x=x;this.y=y;this.wight=wigth;this.height=height; 18 | 19 | title = new JLabel("", JLabel.CENTER); 20 | title.setFont(FONT_COURIER_BOLD_21); 21 | title.setBounds(x, y, wigth, height); 22 | add(title); 23 | setBounds(x, y, wigth, height); 24 | 25 | } 26 | 27 | 28 | 29 | public void setTitle(String title) { 30 | this.title = new JLabel(title, JLabel.CENTER) ; 31 | this.title.setFont(FONT_COURIER_BOLD_21); 32 | this.title.setBounds(x, y, wight, height); 33 | this.title.setForeground(COLOR_TEXT); 34 | add(this.title); 35 | } 36 | public void setActive(boolean active){ 37 | this.active=active; 38 | setBackground(active?COLOR_TITLE:COLOR_VALUE); 39 | } 40 | 41 | @Override 42 | public void paintComponent(Graphics g) { 43 | g.setColor(active?COLOR_TITLE:COLOR_VALUE); 44 | g.fillRect(x, y, wight,height); 45 | g.setColor(active?Color.RED:COLOR_TEXT); 46 | g.drawRect(x, y,wight-1,height-1); 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /bcomp-ng-ui/src/main/java/ru/ifmo/cs/bcomp/ui/components/InputRegisterView.java: -------------------------------------------------------------------------------- 1 | /* 2 | * $Id$ 3 | */ 4 | 5 | package ru.ifmo.cs.bcomp.ui.components; 6 | 7 | import ru.ifmo.cs.components.Register; 8 | import ru.ifmo.cs.components.Utils; 9 | 10 | import java.awt.event.*; 11 | 12 | import static ru.ifmo.cs.bcomp.ui.components.DisplayStyles.*; 13 | 14 | /** 15 | * 16 | * @author Dmitry Afanasiev 17 | */ 18 | public class InputRegisterView extends RegisterView { 19 | private final ComponentManager cmanager; 20 | private final Register reg; 21 | private final ActiveBitView activeBitView; 22 | private boolean active = false; 23 | private int regWidth; 24 | private int bitno; 25 | private int formattedWidth; 26 | 27 | public InputRegisterView(ComponentManager cmgr, Register reg) { 28 | super(reg, COLOR_TITLE); 29 | 30 | this.cmanager = cmgr; 31 | this.reg = reg; 32 | activeBitView = cmanager.getActiveBit(); 33 | 34 | bitno = 0; 35 | formattedWidth = Utils.getBinaryWidth(4); 36 | 37 | 38 | 39 | addMouseListener(new MouseAdapter() { 40 | @Override 41 | public void mouseClicked(MouseEvent e) { 42 | if (!value.isFocusOwner()) 43 | reqFocus(); 44 | } 45 | }); 46 | 47 | value.setFocusable(true); 48 | value.addFocusListener(new FocusListener() { 49 | 50 | @Override 51 | public void focusGained(FocusEvent e) { 52 | active = true; 53 | setActiveBit(bitno); 54 | } 55 | 56 | @Override 57 | public void focusLost(FocusEvent e) { 58 | active = false; 59 | setValue(); 60 | } 61 | }); 62 | 63 | value.addKeyListener(new KeyAdapter() { 64 | @Override 65 | public void keyPressed(KeyEvent e) { 66 | switch (e.getKeyCode()) { 67 | case KeyEvent.VK_LEFT: 68 | case KeyEvent.VK_BACK_SPACE: 69 | moveLeft(); 70 | break; 71 | 72 | case KeyEvent.VK_RIGHT: 73 | moveRight(); 74 | break; 75 | 76 | case KeyEvent.VK_UP: 77 | //invertBit(); 78 | break; 79 | 80 | case KeyEvent.VK_0: 81 | case KeyEvent.VK_NUMPAD0: 82 | setBit(0); 83 | break; 84 | 85 | case KeyEvent.VK_1: 86 | case KeyEvent.VK_NUMPAD1: 87 | setBit(1); 88 | break; 89 | 90 | case KeyEvent.VK_2: 91 | case KeyEvent.VK_NUMPAD2: 92 | setBit(2); 93 | break; 94 | 95 | case KeyEvent.VK_3: 96 | case KeyEvent.VK_NUMPAD3: 97 | setBit(3); 98 | break; 99 | 100 | case KeyEvent.VK_4: 101 | case KeyEvent.VK_NUMPAD4: 102 | setBit(4); 103 | break; 104 | 105 | case KeyEvent.VK_5: 106 | case KeyEvent.VK_NUMPAD5: 107 | setBit(5); 108 | break; 109 | 110 | case KeyEvent.VK_6: 111 | case KeyEvent.VK_NUMPAD6: 112 | setBit(6); 113 | break; 114 | 115 | 116 | case KeyEvent.VK_7: 117 | case KeyEvent.VK_NUMPAD7: 118 | setBit(7); 119 | break; 120 | 121 | case KeyEvent.VK_8: 122 | case KeyEvent.VK_NUMPAD8: 123 | setBit(8); 124 | break; 125 | 126 | case KeyEvent.VK_9: 127 | case KeyEvent.VK_NUMPAD9: 128 | setBit(9); 129 | break; 130 | 131 | case KeyEvent.VK_A: 132 | setBit(0xA); 133 | break; 134 | 135 | case KeyEvent.VK_B: 136 | setBit(0xB); 137 | break; 138 | 139 | case KeyEvent.VK_C: 140 | setBit(0xC); 141 | break; 142 | 143 | case KeyEvent.VK_D: 144 | setBit(0xD); 145 | break; 146 | 147 | case KeyEvent.VK_E: 148 | setBit(0xE); 149 | break; 150 | 151 | case KeyEvent.VK_F: 152 | setBit(0xF); 153 | break; 154 | 155 | default: 156 | cmanager.keyPressed(e); 157 | } 158 | } 159 | }); 160 | 161 | /*value.addMouseListener(new MouseAdapter() { 162 | @Override 163 | public void mouseClicked(MouseEvent e) { 164 | if (!value.isFocusOwner()) 165 | reqFocus(); 166 | 167 | int bitno = Utils.getBitNo(e.getX(), e.getX() > value.getWidth() / 2 ? formattedWidth - 1 : formattedWidth, FONT_COURIER_BOLD_21_WIDTH); 168 | 169 | if (bitno < 0) 170 | return; 171 | 172 | setActiveBit(bitno); 173 | 174 | if (e.getClickCount() > 1) 175 | invertBit(); 176 | } 177 | });*/ 178 | } 179 | 180 | private void setActiveBit(int bitno) { 181 | activeBitView.setValue(this.bitno = bitno); 182 | setValue(); 183 | } 184 | 185 | private void moveLeft() { 186 | //JOptionPane.showMessageDialog(null, regWidth, "", JOptionPane.INFORMATION_MESSAGE); 187 | setActiveBit((bitno + 1) % 4); 188 | } 189 | 190 | private void moveRight() { 191 | setActiveBit((bitno == 0 ? 4 : bitno) - 1); 192 | } 193 | 194 | private void invertBit() { 195 | reg.invertBit(bitno); 196 | setValue(); 197 | } 198 | 199 | private void setBit(int value) { 200 | reg.setNibble(value, bitno); 201 | //reg.setValue(value,1,bitno); 202 | moveRight(); 203 | } 204 | 205 | @Override 206 | public void setValue() { 207 | if (active) { 208 | String hex16Chars = String.format("%04X", reg.getValue()); 209 | StringBuilder str = new StringBuilder(HTML + hex16Chars + HTML_END); 210 | 211 | int pos = 6 + formattedWidth - Utils.getBinaryWidth(bitno + 1); 212 | str.insert(pos + 1, COLOR_END); 213 | str.insert(pos, COLOR_ACTIVE_BIT); 214 | setValue(str.toString()); 215 | 216 | //cmanager.getRegisterView(Reg.IR).setValue(String.format("%04X", reg.getValue())); 217 | } else { 218 | String hex16Chars = String.format("%04X", reg.getValue()); 219 | super.setValue(HTML + hex16Chars + HTML_END); 220 | } 221 | } 222 | 223 | public void reqFocus() { 224 | try { 225 | value.requestFocus(); 226 | } catch (Exception e) { } 227 | 228 | value.requestFocusInWindow(); 229 | } 230 | 231 | public void setActive() { 232 | reqFocus(); 233 | active = true; 234 | setActiveBit(bitno); 235 | } 236 | } 237 | -------------------------------------------------------------------------------- /bcomp-ng-ui/src/main/java/ru/ifmo/cs/bcomp/ui/components/InputRegisterViewByte.java: -------------------------------------------------------------------------------- 1 | /* 2 | * $Id$ 3 | */ 4 | 5 | package ru.ifmo.cs.bcomp.ui.components; 6 | 7 | import ru.ifmo.cs.components.Register; 8 | import ru.ifmo.cs.components.Utils; 9 | 10 | import java.awt.event.*; 11 | 12 | import static ru.ifmo.cs.bcomp.ui.components.DisplayStyles.*; 13 | 14 | /** 15 | * 16 | * @author Dmitry Afanasiev 17 | */ 18 | public class InputRegisterViewByte extends RegisterView { 19 | private final ComponentManager cmanager; 20 | private final Register reg; 21 | private final ActiveBitView activeBitView; 22 | private boolean active = false; 23 | private int regWidth; 24 | private int bitno; 25 | private int formattedWidth; 26 | 27 | public InputRegisterViewByte(ComponentManager cmgr, Register reg) { 28 | super(reg, COLOR_TITLE); 29 | 30 | this.cmanager = cmgr; 31 | this.reg = reg; 32 | activeBitView = cmanager.getActiveBit(); 33 | 34 | bitno = (regWidth =(int) reg.width) - 1; 35 | formattedWidth = Utils.getBinaryWidth(regWidth); 36 | 37 | addMouseListener(new MouseAdapter() { 38 | @Override 39 | public void mouseClicked(MouseEvent e) { 40 | if (!value.isFocusOwner()) 41 | reqFocus(); 42 | } 43 | }); 44 | 45 | value.setFocusable(true); 46 | value.addFocusListener(new FocusListener() { 47 | 48 | @Override 49 | public void focusGained(FocusEvent e) { 50 | active = true; 51 | setActiveBit(bitno); 52 | } 53 | 54 | @Override 55 | public void focusLost(FocusEvent e) { 56 | active = false; 57 | setValue(); 58 | } 59 | }); 60 | 61 | value.addKeyListener(new KeyAdapter() { 62 | @Override 63 | public void keyPressed(KeyEvent e) { 64 | switch (e.getKeyCode()) { 65 | case KeyEvent.VK_LEFT: 66 | case KeyEvent.VK_BACK_SPACE: 67 | moveLeft(); 68 | break; 69 | 70 | case KeyEvent.VK_RIGHT: 71 | moveRight(); 72 | break; 73 | 74 | case KeyEvent.VK_UP: 75 | invertBit(); 76 | break; 77 | 78 | case KeyEvent.VK_0: 79 | case KeyEvent.VK_NUMPAD0: 80 | setBit(0); 81 | break; 82 | 83 | case KeyEvent.VK_1: 84 | case KeyEvent.VK_NUMPAD1: 85 | setBit(1); 86 | break; 87 | 88 | default: 89 | cmanager.keyPressed(e); 90 | } 91 | } 92 | }); 93 | 94 | value.addMouseListener(new MouseAdapter() { 95 | @Override 96 | public void mouseClicked(MouseEvent e) { 97 | if (!value.isFocusOwner()) 98 | reqFocus(); 99 | 100 | int bitno = Utils.getBitNo(e.getX(), e.getX() > value.getWidth() / 2 ? formattedWidth - 1 : formattedWidth, FONT_COURIER_BOLD_21_WIDTH); 101 | 102 | if (bitno < 0) 103 | return; 104 | 105 | setActiveBit(bitno); 106 | 107 | if (e.getClickCount() > 1) 108 | invertBit(); 109 | } 110 | }); 111 | } 112 | 113 | private void setActiveBit(int bitno) { 114 | activeBitView.setValue(this.bitno = bitno); 115 | setValue(); 116 | } 117 | 118 | private void moveLeft() { 119 | setActiveBit((bitno + 1) % regWidth); 120 | } 121 | 122 | private void moveRight() { 123 | setActiveBit((bitno == 0 ? regWidth : bitno) - 1); 124 | } 125 | 126 | private void invertBit() { 127 | reg.invertBit(bitno); 128 | setValue(); 129 | } 130 | 131 | private void setBit(int value) { 132 | reg.setValue(value,1,bitno); 133 | moveRight(); 134 | } 135 | 136 | @Override 137 | public void setValue() { 138 | if (active) { 139 | StringBuilder str = new StringBuilder(HTML + 140 | Utils.toBinary((int)reg.getValue(), regWidth) + HTML_END); 141 | 142 | int pos = 6 + formattedWidth - Utils.getBinaryWidth(bitno + 1); 143 | str.insert(pos + 1, COLOR_END); 144 | str.insert(pos, COLOR_ACTIVE_BIT); 145 | setValue(str.toString()); 146 | } else 147 | super.setValue(HTML + Utils.toBinary(reg.getValue(), regWidth) + HTML_END); 148 | } 149 | 150 | public void reqFocus() { 151 | try { 152 | value.requestFocus(); 153 | } catch (Exception e) { } 154 | 155 | value.requestFocusInWindow(); 156 | } 157 | 158 | public void setActive() { 159 | reqFocus(); 160 | active = true; 161 | setActiveBit(bitno); 162 | } 163 | } -------------------------------------------------------------------------------- /bcomp-ng-ui/src/main/java/ru/ifmo/cs/bcomp/ui/components/MPView.java: -------------------------------------------------------------------------------- 1 | /* 2 | * $Id$ 3 | */ 4 | 5 | package ru.ifmo.cs.bcomp.ui.components; 6 | 7 | import java.util.ArrayList; 8 | import javax.swing.JCheckBox; 9 | import ru.ifmo.cs.bcomp.CPU; 10 | 11 | import ru.ifmo.cs.bcomp.SignalListener; 12 | import ru.ifmo.cs.bcomp.ui.GUI; 13 | import static ru.ifmo.cs.bcomp.ui.components.DisplayStyles.*; 14 | 15 | /** 16 | * 17 | * @author Dmitry Afanasiev 18 | */ 19 | public class MPView { 20 | // private final MicroMemoryView mem; 21 | // private final RegisterView regMIP; 22 | // private final RegisterView regMInstr; 23 | // private final RegisterView regBuf; 24 | // private final RegisterView regState; 25 | // private final JCheckBox cucheckbox; 26 | // private static final ControlSignal[] statesignals = { 27 | // }; 28 | // 29 | // public MPView(GUI gui) { 30 | // super(gui.getComponentManager(), 31 | // new RegisterProperties[] { 32 | // new RegisterProperties(CPU.Reg.ADDR, CU_X_IO, CU_Y_IO, true), 33 | // new RegisterProperties(CPU.Reg.IP, REG_IP_X_MP, CU_Y_IO, true), 34 | // new RegisterProperties(CPU.Reg.DATA, CU_X_IO, REG_ADDR_Y_IO, true), 35 | // new RegisterProperties(CPU.Reg.INSTR, REG_INSTR_X_MP, REG_ADDR_Y_IO, true), 36 | // new RegisterProperties(CPU.Reg.ACCUM, CU_X_IO, REG_ACC_Y_MP, true), 37 | // new RegisterProperties(CPU.Reg.STATE, REG_STATE_X, REG_STATE_Y_MP, true) 38 | // }, 39 | // new BusView[] { } 40 | // ); 41 | // 42 | // add(mem = cmanager.getMicroMemory()); 43 | // 44 | // regMIP = cmanager.getRegisterView(CPU.Reg.MIP); 45 | // regMIP.setProperties(400, 1, false); 46 | // add(regMIP); 47 | // 48 | // regMInstr = cmanager.getRegisterView(CPU.Reg.MINSTR); 49 | // regMInstr.setProperties(400, 100, false); 50 | // add(regMInstr); 51 | // 52 | // regBuf = cmanager.getRegisterView(CPU.Reg.BUF); 53 | // regBuf.setProperties(REG_BUF_X_MP, REG_ACC_Y_MP, true); 54 | // add(regBuf); 55 | // 56 | // regState = cmanager.getRegisterView(CPU.Reg.STATE); 57 | // 58 | // setSignalListeners(new SignalListener[] { 59 | // new SignalListener(regState, 60 | // ControlSignal.HALT, 61 | // ControlSignal.BUF_TO_STATE_N, 62 | // ControlSignal.BUF_TO_STATE_Z, 63 | // ControlSignal.DISABLE_INTERRUPTS, 64 | // ControlSignal.ENABLE_INTERRUPTS, 65 | // ControlSignal.IO0_TSF, 66 | // ControlSignal.IO1_TSF, 67 | // ControlSignal.IO2_TSF, 68 | // ControlSignal.IO3_TSF, 69 | // ControlSignal.IO4_TSF, 70 | // ControlSignal.IO5_TSF, 71 | // ControlSignal.IO6_TSF, 72 | // ControlSignal.IO7_TSF, 73 | // ControlSignal.IO8_TSF, 74 | // ControlSignal.IO9_TSF, 75 | // ControlSignal.SET_RUN_STATE, 76 | // ControlSignal.SET_PROGRAM, 77 | // ControlSignal.SET_REQUEST_INTERRUPT), 78 | // new SignalListener(regBuf, 79 | // ControlSignal.ALU_AND, 80 | // ControlSignal.SHIFT_RIGHT, 81 | // ControlSignal.SHIFT_LEFT) 82 | // }); 83 | // 84 | // cucheckbox = cmanager.getMPCheckBox(); 85 | // cucheckbox.setBounds(450, 400, 300, 30); 86 | // add(cucheckbox); 87 | // 88 | // add(new ALUView(ALU_X_MP, REG_IP_Y_IO, ALU_WIDTH, ALU_HEIGHT)); 89 | // } 90 | // 91 | // @Override 92 | // public void panelActivate() { 93 | // mem.updateLastAddr(); 94 | // mem.updateMemory(); 95 | // 96 | // regMIP.setValue(); 97 | // regMInstr.setValue(); 98 | // regBuf.setValue(); 99 | // 100 | // cucheckbox.setSelected(false); 101 | // 102 | // super.panelActivate(); 103 | // } 104 | // 105 | // @Override 106 | // public String getPanelName() { 107 | // return "Работа с МПУ"; 108 | // } 109 | // 110 | // @Override 111 | // public void stepStart() { 112 | // mem.eventRead(); 113 | // } 114 | // 115 | // @Override 116 | // public void stepFinish() { 117 | // ArrayList signals = cmanager.getActiveSignals(); 118 | // 119 | // regMIP.setValue(); 120 | // regMInstr.setValue(); 121 | // } 122 | } 123 | -------------------------------------------------------------------------------- /bcomp-ng-ui/src/main/java/ru/ifmo/cs/bcomp/ui/components/MemoryView.java: -------------------------------------------------------------------------------- 1 | /* 2 | * $Id$ 3 | */ 4 | 5 | package ru.ifmo.cs.bcomp.ui.components; 6 | 7 | import ru.ifmo.cs.components.Utils; 8 | import ru.ifmo.cs.components.Memory; 9 | 10 | import javax.swing.*; 11 | import java.awt.*; 12 | 13 | import static ru.ifmo.cs.bcomp.ui.components.DisplayStyles.*; 14 | 15 | /** 16 | * 17 | * @author Dmitry Afanasiev 18 | */ 19 | public class MemoryView extends BCompComponent { 20 | private Memory mem; 21 | private int addrBitWidth; 22 | private int valueBitWidth; 23 | private int lineX; 24 | private int lastPage = 0; 25 | // Components 26 | private JLabel[] addrs = new JLabel[16]; 27 | private JLabel[] values = new JLabel[16]; 28 | 29 | public MemoryView(Memory mem, int x, int y) { 30 | super("RAM", 16); 31 | this.mem = mem; 32 | 33 | addrBitWidth = (int)mem.getAddrWidth() ; 34 | int addrWidth = FONT_COURIER_BOLD_21_WIDTH * (1 + Utils.getHexWidth(addrBitWidth)); 35 | valueBitWidth =(int) mem.width; 36 | int valueWidth = FONT_COURIER_BOLD_21_WIDTH * (1 + Utils.getHexWidth(valueBitWidth)); 37 | lineX = 1 + addrWidth; 38 | 39 | setBounds(x, y, 3 + addrWidth + valueWidth); 40 | 41 | for (int i = 0; i < 16; i++) { 42 | addrs[i] = addValueLabel(COLOR_TITLE); 43 | addrs[i].setBounds(1, getValueY(i), addrWidth, CELL_HEIGHT); 44 | addrs[i].setForeground(COLOR_TEXT); 45 | 46 | values[i] = addValueLabel(COLOR_VALUE); 47 | values[i].setBounds(lineX + 1, getValueY(i), valueWidth, CELL_HEIGHT); 48 | values[i].setForeground(COLOR_TEXT); 49 | } 50 | } 51 | 52 | @Override 53 | public void paintComponent(Graphics g) { 54 | super.paintComponent(g); 55 | g.drawLine(lineX, CELL_HEIGHT + 2, lineX, height - 2); 56 | g.drawLine(1, CELL_HEIGHT + 1, width - 2, CELL_HEIGHT + 1); 57 | } 58 | 59 | void updateValue(JLabel label, int value) { 60 | label.setText(Utils.toHex(value, valueBitWidth)); 61 | } 62 | 63 | private void updateValue(int offset) { 64 | updateValue(values[offset],(int) mem.getValue(lastPage + offset)); 65 | } 66 | 67 | public void updateMemory() { 68 | for (int i = 0; i < 16; i++) { 69 | addrs[i].setText(Utils.toHex(lastPage + i, addrBitWidth)); 70 | updateValue(i); 71 | } 72 | } 73 | 74 | private int getPage(int addr) { 75 | return addr & (~0xf); 76 | } 77 | 78 | private int getPage() { 79 | return getPage((int)mem.getAddrWidth()); 80 | } 81 | 82 | public void updateLastAddr() { 83 | lastPage = getPage(); 84 | } 85 | 86 | public void eventRead() { 87 | int addr = (int)mem.getLastAccessedAddress(); 88 | int page = getPage(addr); 89 | 90 | if (page != lastPage) { 91 | lastPage = page; 92 | updateMemory(); 93 | } 94 | } 95 | 96 | public void eventWrite() { 97 | int addr = (int)mem.getLastAccessedAddress(); 98 | int page = getPage(addr); 99 | 100 | if (page != lastPage) { 101 | lastPage = page; 102 | updateMemory(); 103 | } else 104 | updateValue(addr - page); 105 | } 106 | 107 | 108 | } 109 | -------------------------------------------------------------------------------- /bcomp-ng-ui/src/main/java/ru/ifmo/cs/bcomp/ui/components/MicroMemoryView.java: -------------------------------------------------------------------------------- 1 | /* 2 | * $Id$ 3 | */ 4 | 5 | package ru.ifmo.cs.bcomp.ui.components; 6 | 7 | import javax.swing.JLabel; 8 | import ru.ifmo.cs.bcomp.CPU; 9 | 10 | 11 | /** 12 | * 13 | * @author Dmitry Afanasiev 14 | */ 15 | public class MicroMemoryView { 16 | // private final MicroProgram mp; 17 | // 18 | // public MicroMemoryView(CPU cpu, int x, int y) { 19 | // super(cpu.getMicroMemory(), x, y); 20 | // this.mp = cpu.getMicroProgram(); 21 | // } 22 | // 23 | // @Override 24 | // void updateValue(JLabel label, int value) { 25 | // super.updateValue(label, value); 26 | // label.setToolTipText(mp.decodeCmd(value)); 27 | // } 28 | } 29 | -------------------------------------------------------------------------------- /bcomp-ng-ui/src/main/java/ru/ifmo/cs/bcomp/ui/components/RegisterProperties.java: -------------------------------------------------------------------------------- 1 | /* 2 | * $Id$ 3 | */ 4 | 5 | package ru.ifmo.cs.bcomp.ui.components; 6 | 7 | 8 | import ru.ifmo.cs.bcomp.Reg; 9 | 10 | import java.awt.*; 11 | 12 | /** 13 | * 14 | * @author Dmitry Afanasiev 15 | */ 16 | public class RegisterProperties { 17 | public final Reg reg; 18 | public final int x; 19 | public final int y; 20 | public final boolean hex; 21 | public final GridBagConstraints constraints; 22 | public final boolean isLeft; 23 | 24 | public RegisterProperties(Reg reg, int x, int y, boolean hex,boolean isLeft,GridBagConstraints constraints) { 25 | this.reg = reg; 26 | this.x = x; 27 | this.y = y; 28 | this.hex = hex; 29 | this.constraints=constraints; 30 | this.isLeft=isLeft; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /bcomp-ng-ui/src/main/java/ru/ifmo/cs/bcomp/ui/components/RegisterView.java: -------------------------------------------------------------------------------- 1 | /* 2 | * $Id$ 3 | */ 4 | 5 | package ru.ifmo.cs.bcomp.ui.components; 6 | 7 | import ru.ifmo.cs.components.Utils; 8 | import ru.ifmo.cs.components.DataDestination; 9 | import ru.ifmo.cs.components.Register; 10 | 11 | import javax.swing.*; 12 | import java.awt.*; 13 | 14 | //import ru.ifmo.cs.components.DataWidth; 15 | import static ru.ifmo.cs.bcomp.ui.components.DisplayStyles.*; 16 | 17 | /** 18 | * 19 | * @author Dmitry Afanasiev 20 | */ 21 | public class RegisterView extends BCompComponent implements DataDestination { 22 | private int formatWidth; 23 | private int valuemask; 24 | private boolean hex; 25 | private boolean isLeft; 26 | 27 | private final Register reg; 28 | protected final JLabel value = addValueLabel(); 29 | 30 | public RegisterView(Register reg, Color colorTitleBG) { 31 | super("", 0,colorTitleBG); 32 | 33 | this.reg = reg; 34 | } 35 | 36 | public RegisterView(Register reg) { 37 | this(reg, COLOR_TITLE); 38 | } 39 | protected void setBounds(int x, int y, int wight){ 40 | 41 | setBounds(x,y,this.width=wight,height); 42 | 43 | } 44 | 45 | protected void setProperties(int x, int y, boolean hex, int regWidth,boolean isLeft) { 46 | this.hex = hex; 47 | this.formatWidth = regWidth; 48 | this.valuemask = (1 << regWidth) - 1; 49 | this.isLeft=isLeft; 50 | setBounds(x, y, getValueWidth(regWidth, false)+REG_TITLE_WIDTH - 10); 51 | setValue(); 52 | 53 | title.setForeground(COLOR_TEXT); 54 | value.setForeground(COLOR_TEXT); 55 | if (!isLeft) { 56 | title.setBounds(1, 1, REG_TITLE_WIDTH, CELL_HEIGHT + 1); 57 | value.setBounds(REG_TITLE_WIDTH, 1, width - REG_TITLE_WIDTH - 1, CELL_HEIGHT + 1); 58 | } else { 59 | title.setBounds(width - 1 - REG_TITLE_WIDTH, 1, REG_TITLE_WIDTH, CELL_HEIGHT + 1); 60 | value.setBounds(1, 1, width - REG_TITLE_WIDTH - 3, CELL_HEIGHT + 1); 61 | } 62 | } 63 | 64 | public void setProperties(int x, int y, boolean hex,boolean isLeft) { 65 | setProperties(x, y, hex, (int)reg.width, isLeft); 66 | } 67 | 68 | protected long getRegWidth(){ 69 | return reg.width; 70 | } 71 | 72 | protected void setValue(String val) { 73 | value.setText(val); 74 | } 75 | 76 | public void setValue() { 77 | setValue(hex ? 78 | Utils.toHex(reg.getValue() & valuemask, formatWidth) : 79 | Utils.toBinary((int)reg.getValue() & valuemask, formatWidth)); 80 | } 81 | 82 | @Override 83 | public void setValue(long value) { 84 | setValue(); 85 | } 86 | 87 | public Register getReg() { 88 | return reg; 89 | } 90 | 91 | @Override 92 | public void paintComponent(Graphics g) { 93 | super.paintComponent(g); 94 | g.setColor(Color.BLACK); 95 | 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /bcomp-ng-ui/src/main/java/ru/ifmo/cs/bcomp/ui/components/RunningCycleView.java: -------------------------------------------------------------------------------- 1 | /* 2 | * $Id$ 3 | */ 4 | 5 | package ru.ifmo.cs.bcomp.ui.components; 6 | 7 | import ru.ifmo.cs.bcomp.CPU; 8 | import ru.ifmo.cs.bcomp.RunningCycle; 9 | 10 | import javax.swing.*; 11 | import java.awt.*; 12 | import java.util.EnumMap; 13 | 14 | import static ru.ifmo.cs.bcomp.ui.components.DisplayStyles.*; 15 | 16 | /** 17 | * 18 | * @author Dmitry Afanasiev 19 | */ 20 | public class RunningCycleView extends BCompComponent { 21 | private CPU cpu; 22 | private static final String[] cycleslabels = { 23 | "Instruction fetch", 24 | "Address fetch", 25 | "Operand fetch", 26 | "Execution", 27 | "Interrupt", 28 | "Operator panel", 29 | "Program" 30 | }; 31 | private EnumMap cycles= new EnumMap(RunningCycle.class); 32 | 33 | private final JLabel[] labels = new JLabel[cycleslabels.length]; 34 | private RunningCycle lastcycle = RunningCycle.STOP; 35 | 36 | public RunningCycleView(CPU cpu, int x, int y) { 37 | super("Control Unit", cycleslabels.length); 38 | 39 | this.cpu = cpu; 40 | 41 | setBounds(x, y, 7*MEM_WIDTH/4); 42 | 43 | for (int i = 0; i < cycleslabels.length; i++) { 44 | labels[i] = addValueLabel(cycleslabels[i]); 45 | labels[i].setBounds(1, getValueY(i), width - 2, CELL_HEIGHT); 46 | labels[i].setForeground(COLOR_TEXT); 47 | } 48 | cycles.put(RunningCycle.INFETCH,0); 49 | cycles.put(RunningCycle.ADFETCH,1); 50 | cycles.put(RunningCycle.OPFETCH,2); 51 | cycles.put(RunningCycle.EXEC,3); 52 | cycles.put(RunningCycle.INT,4); 53 | cycles.put(RunningCycle.START,5); 54 | cycles.put(RunningCycle.READ,5); 55 | cycles.put(RunningCycle.WRITE,5); 56 | cycles.put(RunningCycle.SETIP,5); 57 | } 58 | 59 | public void update() { 60 | RunningCycle newcycle = cpu.getRunningCycle(); 61 | 62 | if (newcycle != lastcycle) { 63 | if (lastcycle != RunningCycle.STOP && lastcycle != RunningCycle.RESERVED) 64 | labels[cycles.get(lastcycle)].setForeground(COLOR_TEXT); 65 | if (newcycle != RunningCycle.STOP && newcycle != RunningCycle.RESERVED) 66 | labels[cycles.get(newcycle)].setForeground(COLOR_ACTIVE); 67 | lastcycle = newcycle; 68 | } 69 | 70 | } 71 | 72 | public void updateProg(boolean prog){ 73 | labels[labels.length-1].setForeground(prog?COLOR_ACTIVE:COLOR_TEXT); 74 | } 75 | 76 | @Override 77 | public void paintComponent(Graphics g) { 78 | super.paintComponent(g); 79 | g.drawLine(1, CELL_HEIGHT + 1, width - 2, CELL_HEIGHT + 1); 80 | } 81 | 82 | @Override 83 | protected JLabel addValueLabel(String value) { 84 | return addLabel(value,FONT_COURIER_BOLD_18,COLOR_VALUE); 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /bcomp-ng-ui/src/main/java/ru/ifmo/cs/bcomp/ui/components/StateRegisterView.java: -------------------------------------------------------------------------------- 1 | /* 2 | * $Id$ 3 | */ 4 | 5 | package ru.ifmo.cs.bcomp.ui.components; 6 | 7 | //import ru.ifmo.cs.bcomp.StateReg; 8 | 9 | 10 | /** 11 | * 12 | * @author Dmitry Afanasiev 13 | */ 14 | public class StateRegisterView{ 15 | // private final int formattedWidth; 16 | // private MouseMotionAdapter listener = new MouseMotionAdapter() { 17 | // private String tooltip = null; 18 | // 19 | // @Override 20 | // public void mouseMoved(MouseEvent e) { 21 | // int bitno = Utils.getBitNo(e.getX(), formattedWidth, FONT_COURIER_BOLD_25_WIDTH); 22 | // 23 | // if (bitno < 0) { 24 | // value.setToolTipText(tooltip = null); 25 | // return; 26 | // } 27 | // 28 | // String newtooltip = StateReg.FULLNAME[bitno]; 29 | // if (newtooltip != tooltip) 30 | // value.setToolTipText(tooltip = newtooltip); 31 | // } 32 | // }; 33 | // 34 | // public StateRegisterView(Register reg) { 35 | // super(reg); 36 | // 37 | // formattedWidth = Utils.getBinaryWidth(reg.getWidth()); 38 | // } 39 | // 40 | // @Override 41 | // public void setProperties(int x, int y, boolean fullView) { 42 | // super.setProperties(x, y, !fullView, fullView ? getRegWidth() : 1); 43 | // 44 | // if (fullView) { 45 | // value.addMouseMotionListener(listener); 46 | // } else { 47 | // value.removeMouseMotionListener(listener); 48 | // value.setToolTipText(null); 49 | // } 50 | // } 51 | } 52 | -------------------------------------------------------------------------------- /bcomp-ng-ui/src/main/java/ru/ifmo/cs/bcomp/ui/components/loc.java: -------------------------------------------------------------------------------- 1 | package ru.ifmo.cs.bcomp.ui.components; 2 | 3 | import java.util.ListResourceBundle; 4 | 5 | public class loc extends ListResourceBundle { 6 | @Override 7 | protected Object[][] getContents() { 8 | return contents; 9 | } 10 | 11 | private static final Object[][] contents = { 12 | 13 | {"read", " F6 Read"}, 14 | {"write", "F5 Write"}, 15 | {"setip", "F4 Enter Address"}, 16 | {"start", "F7 Start"}, 17 | {"continue", "F8 Continue"}, 18 | {"tick", "Shift+F9 Tick"}, 19 | {"run", "F9 Run"}, 20 | {"stop", "F9 Stop "}, 21 | {"basename", "Basic computer"}, 22 | {"assembler", "Assembler"}, 23 | {"output", "CDev-1 (0x2-0x3) Controller of output device"}, 24 | {"input", "CDev-2 (0x4-0x5) Controller of input device"}, 25 | {"IO", "CDev-3 (0x6-0x7) Controller of IO device"}, 26 | {"ready", "Ready"}, 27 | {"DEV-1", "CDev 1"}, 28 | {"DEV-2", "CDev 2"}, 29 | {"DEV-3", "CDev 3"}, 30 | {"DEV-4", "CDev 4"}, 31 | {"DEV-5", "Dev 5"}, 32 | {"DEV-6", "Dev 6"}, 33 | {"DEV-7", "Dev 7"}, 34 | {"DEV-8", "Dev 8"}, 35 | {"DEV-9", "Dev 9"}, 36 | {"printer", "Text printer (0xC-0xF)"}, 37 | {"ticker", "Ticker (0x10-0x13)"}, 38 | {"ssd", "Seven segment display (0x14-0x17)"}, 39 | {"kbd", "Keyboard (0x18-0x1B)"}, 40 | {"numpad", "Numpad (0x1C-0x1F)"}, 41 | {"error", "Error"}, 42 | {"stopRunning", "To compile, stop the running program"}, 43 | {"compile", "Compile"} 44 | }; 45 | } -------------------------------------------------------------------------------- /bcomp-ng-ui/src/main/java/ru/ifmo/cs/bcomp/ui/components/loc_ru.java: -------------------------------------------------------------------------------- 1 | package ru.ifmo.cs.bcomp.ui.components; 2 | 3 | import java.util.ListResourceBundle; 4 | 5 | public class loc_ru extends ListResourceBundle { 6 | @Override 7 | protected Object[][] getContents() { 8 | return contents; 9 | } 10 | 11 | private static final Object[][] contents = { 12 | {"read", "F6 Чтение"}, 13 | {"write", "F5 Запись"}, 14 | {"setip", "F4 Ввод адреса"}, 15 | {"start", "F7 Пуск"}, 16 | {"continue", "F8 Продолжение"}, 17 | {"tick", "Shift+F9 Такт"}, 18 | {"run", "F9 Работа"}, 19 | {"stop", "F9 Останов"}, 20 | {"basename", "Базовая ЭВМ"}, 21 | {"assembler", "Ассемблер"}, 22 | {"output", "КВУ-1 (0x2-0x3) Контроллер уст-ва вывода"}, 23 | {"input", "КВУ-2 (0x4-0x5) Контроллер уст-ва ввода"}, 24 | {"IO", "КВУ-3 (0x6-0x7) Контроллер уст-ва ввода-вывода"}, 25 | {"ready", "Готов"}, 26 | {"DEV-1", "КВУ 1"}, 27 | {"DEV-2", "КВУ 2"}, 28 | {"DEV-3", "КВУ 3"}, 29 | {"DEV-4", "КВУ 4"}, 30 | {"DEV-5", "ВУ 5"}, 31 | {"DEV-6", "ВУ 6"}, 32 | {"DEV-7", "ВУ 7"}, 33 | {"DEV-8", "ВУ 8"}, 34 | {"DEV-9", "ВУ 9"}, 35 | {"printer", "Текстовый принтер (0xC-0xF)"}, 36 | {"ticker", "Бегущая строка (0x10-0x13)"}, 37 | {"ssd", "Семисегментный индикатор (0x14-0x17)"}, 38 | {"kbd", "Клавиатура (0x18-0x1B)"}, 39 | {"numpad", "Цифровая клавиатура (0x1C-0x1F)"}, 40 | {"error", "Ошибка"}, 41 | {"stopRunning", "Для компиляции остановите выполняющуюся программу"}, 42 | {"compile", "Компилировать"} 43 | }; 44 | } -------------------------------------------------------------------------------- /bcomp-ng-ui/src/main/java/ru/ifmo/cs/bcomp/ui/io/BComp2BCompIODev.java: -------------------------------------------------------------------------------- 1 | /* 2 | * $Id$ 3 | */ 4 | package ru.ifmo.cs.bcomp.ui.io; 5 | 6 | import ru.ifmo.cs.bcomp.IOCtrl; 7 | import ru.ifmo.cs.components.DataDestination; 8 | 9 | /** 10 | * 11 | * @author Dmitry Afanasiev 12 | */ 13 | public class BComp2BCompIODev { 14 | // public BComp2BCompIODev(final IOCtrl ioctrl1, final IOCtrl ioctrl2) { 15 | // ioctrl2.setFlag(); 16 | // 17 | // ioctrl1.addDestination(IOCtrl.ControlSignal.OUT, new DataDestination() { 18 | // public void setValue(int value) { 19 | // try { 20 | // ioctrl2.setData(value); 21 | // } catch (Exception e) { } 22 | // } 23 | // }); 24 | // 25 | // ioctrl2.addDestination(IOCtrl.ControlSignal.OUT, new DataDestination() { 26 | // public void setValue(int value) { 27 | // try { 28 | // ioctrl1.setData(value); 29 | // } catch (Exception e) { } 30 | // } 31 | // }); 32 | // 33 | // ioctrl1.addDestination(IOCtrl.ControlSignal.SETFLAG, new DataDestination() { 34 | // public void setValue(int value) { 35 | // if (value == 0) 36 | // ioctrl2.setFlag(); 37 | // } 38 | // }); 39 | // 40 | // ioctrl2.addDestination(IOCtrl.ControlSignal.SETFLAG, new DataDestination() { 41 | // public void setValue(int value) { 42 | // if (value == 0) 43 | // ioctrl1.setFlag(); 44 | // } 45 | // }); 46 | // } 47 | } 48 | -------------------------------------------------------------------------------- /bcomp-ng-ui/src/main/java/ru/ifmo/cs/bcomp/ui/io/ButtonPanel.java: -------------------------------------------------------------------------------- 1 | package ru.ifmo.cs.bcomp.ui.io; 2 | import ru.ifmo.cs.bcomp.ui.components.RegisterView; 3 | import javax.swing.*; 4 | import java.awt.*; 5 | import java.awt.event.ActionEvent; 6 | import java.awt.event.ActionListener; 7 | 8 | import static ru.ifmo.cs.bcomp.ui.components.DisplayStyles.COLOR_VALUE; 9 | 10 | class ButtonPanel extends JPanel { 11 | private RegisterView reg; 12 | 13 | ButtonPanel(RegisterView reg) { 14 | setLayout(new GridBagLayout()); 15 | this.reg = reg; 16 | GridBagConstraints constraints = new GridBagConstraints() {{ 17 | gridy = 0; 18 | gridx = 1; 19 | }}; 20 | 21 | for (int i = 7; i >= 0; i--) { 22 | JButton button = new JButton(); 23 | addListener(button, i); 24 | button.setPreferredSize(new Dimension(14, 14)); 25 | button.setBackground(COLOR_VALUE); 26 | add(button, constraints); 27 | constraints.gridx++; 28 | } 29 | } 30 | 31 | private void addListener(JButton button, int i) { 32 | button.addActionListener(new ActionListener() { 33 | @Override 34 | public void actionPerformed(ActionEvent e) { 35 | reg.getReg().invertBit(i); 36 | reg.setValue(); 37 | } 38 | }); 39 | 40 | } 41 | } -------------------------------------------------------------------------------- /bcomp-ng-ui/src/main/java/ru/ifmo/cs/bcomp/ui/io/ButtonReady.java: -------------------------------------------------------------------------------- 1 | package ru.ifmo.cs.bcomp.ui.io; 2 | import ru.ifmo.cs.bcomp.IOCtrl; 3 | import ru.ifmo.cs.components.DataDestination; 4 | import javax.swing.*; 5 | import java.awt.event.ActionEvent; 6 | import java.awt.event.ActionListener; 7 | import static ru.ifmo.cs.bcomp.ui.components.DisplayStyles.COLOR_ACTIVE; 8 | import static ru.ifmo.cs.bcomp.ui.components.DisplayStyles.COLOR_TEXT; 9 | import static ru.ifmo.cs.bcomp.ui.components.DisplayStyles.FONT_COURIER_PLAIN_12; 10 | 11 | public class ButtonReady extends JButton implements DataDestination { 12 | private IOCtrl ioCtrl; 13 | 14 | ButtonReady(IOCtrl ioCtrl, String title) { 15 | super(title); 16 | setFont(FONT_COURIER_PLAIN_12); 17 | setFocusable(false); 18 | addActionListener(new ActionListener() { 19 | @Override 20 | public void actionPerformed(ActionEvent e) { 21 | ioCtrl.setReady(); 22 | setForeground(COLOR_ACTIVE); 23 | } 24 | }); 25 | this.ioCtrl = ioCtrl; 26 | } 27 | 28 | @Override 29 | public void setValue(long value) { 30 | setForeground(ioCtrl.isReady() ? COLOR_ACTIVE : COLOR_TEXT); 31 | } 32 | } -------------------------------------------------------------------------------- /bcomp-ng-ui/src/main/java/ru/ifmo/cs/bcomp/ui/io/FirstIO.java: -------------------------------------------------------------------------------- 1 | package ru.ifmo.cs.bcomp.ui.io; 2 | import ru.ifmo.cs.bcomp.IOCtrl; 3 | import ru.ifmo.cs.bcomp.ui.components.RegisterView; 4 | import javax.swing.*; 5 | import java.awt.*; 6 | 7 | import static ru.ifmo.cs.bcomp.ui.components.DisplayStyles.*; 8 | 9 | public class FirstIO extends IODevice { 10 | private RegisterView output; 11 | 12 | public FirstIO(IOCtrl ioCtrl) { 13 | super(ioCtrl, "output"); 14 | } 15 | 16 | @Override 17 | protected Component getContent() { 18 | JPanel panel = new JPanel(new GridBagLayout()); 19 | panel.setPreferredSize(new Dimension(500, 150)); 20 | panel.setBackground(COLOR_BACKGROUND); 21 | output = new RegisterView(ioctrl.getRegisters()[0]); 22 | output.setProperties(0, 0, false, false); 23 | output.setPreferredSize(output.getSize()); 24 | output.setMinimumSize(output.getSize()); 25 | output.setTitle("DR"); 26 | GridBagConstraints constraints = new GridBagConstraints() {{ 27 | gridy = 0; 28 | gridx = 3; 29 | gridwidth = GridBagConstraints.REMAINDER; 30 | }}; 31 | ButtonReady button = new ButtonReady(ioctrl,getRes().getString("ready")); 32 | ioctrl.addDestination(1, button); 33 | ioctrl.addDestination(0, output); 34 | panel.add(output, constraints); 35 | constraints.gridy++; 36 | constraints.insets.top += 30; 37 | panel.add(button, constraints); 38 | return panel; 39 | } 40 | } -------------------------------------------------------------------------------- /bcomp-ng-ui/src/main/java/ru/ifmo/cs/bcomp/ui/io/FlagIndicator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * $Id$ 3 | */ 4 | 5 | package ru.ifmo.cs.bcomp.ui.io; 6 | 7 | import ru.ifmo.cs.bcomp.IOCtrl; 8 | import ru.ifmo.cs.components.DataDestination; 9 | 10 | import javax.swing.*; 11 | import java.awt.*; 12 | 13 | /** 14 | * 15 | * @author Dmitry Afanasiev 16 | */ 17 | class FlagIndicator extends JComponent { 18 | private static final Color LED_OFF = new Color(128, 128, 128); 19 | private static final Color LED_ON = new Color(0, 160, 0); 20 | 21 | private final Dimension DIMS; 22 | private final IOCtrl ioctrl; 23 | 24 | protected FlagIndicator(IOCtrl ioctrl, int size) { 25 | this.ioctrl = ioctrl; 26 | 27 | DIMS = new Dimension(size, size); 28 | setMinimumSize(DIMS); 29 | setMaximumSize(DIMS); 30 | setPreferredSize(DIMS); 31 | setSize(DIMS); 32 | setToolTipText("Готовность"); 33 | 34 | ioctrl.addDestination(ioctrl.getRegisters()[1], new DataDestination() { 35 | @Override 36 | public void setValue(long value) { 37 | repaint(); 38 | } 39 | }); 40 | } 41 | 42 | @Override 43 | public void paintComponent(Graphics g) { 44 | g.setColor(ioctrl.isReady() ? LED_ON : LED_OFF); 45 | g.fillOval(DIMS.width / 4, DIMS.height / 4, DIMS.width / 2, DIMS.height / 2); 46 | } 47 | } -------------------------------------------------------------------------------- /bcomp-ng-ui/src/main/java/ru/ifmo/cs/bcomp/ui/io/IODevice.java: -------------------------------------------------------------------------------- 1 | /* 2 | * $Id$ 3 | */ 4 | 5 | package ru.ifmo.cs.bcomp.ui.io; 6 | 7 | import ru.ifmo.cs.bcomp.IOCtrl; 8 | 9 | import javax.swing.*; 10 | import java.awt.*; 11 | import java.util.Locale; 12 | import java.util.ResourceBundle; 13 | 14 | /** 15 | * 16 | * @author Dmitry Afanasiev 17 | */ 18 | public abstract class IODevice { 19 | protected final IOCtrl ioctrl; 20 | protected final String title; 21 | private JFrame frame = null; 22 | private ResourceBundle res = ResourceBundle.getBundle("ru.ifmo.cs.bcomp.ui.components.loc", Locale.getDefault()); 23 | 24 | 25 | public IODevice(final IOCtrl ioctrl, final String title) { 26 | this.ioctrl = ioctrl; 27 | this.title = res.getString(title); 28 | } 29 | 30 | protected abstract Component getContent(); 31 | 32 | public void activate() { 33 | if (frame == null) { 34 | frame = new JFrame(title); 35 | frame.add(getContent()); 36 | frame.pack(); 37 | frame.setMinimumSize(new Dimension(560,170)); 38 | } 39 | 40 | frame.setVisible(true); 41 | frame.requestFocus(); 42 | } 43 | 44 | public JFrame getFrame() { 45 | return frame; 46 | } 47 | 48 | public ResourceBundle getRes() { 49 | return res; 50 | } 51 | } -------------------------------------------------------------------------------- /bcomp-ng-ui/src/main/java/ru/ifmo/cs/bcomp/ui/io/Numpad.java: -------------------------------------------------------------------------------- 1 | /* 2 | * $Id$ 3 | */ 4 | package ru.ifmo.cs.bcomp.ui.io; 5 | 6 | import ru.ifmo.cs.bcomp.IOCtrl; 7 | import ru.ifmo.cs.components.DataDestination; 8 | 9 | import javax.swing.*; 10 | import java.awt.*; 11 | import java.awt.event.ActionEvent; 12 | import java.awt.event.ActionListener; 13 | 14 | /** 15 | * 16 | * @author Dmitry Afanasiev 17 | */ 18 | public class Numpad extends IODevice { 19 | private class NumButton extends JButton { 20 | private final int value; 21 | 22 | public NumButton(final String title, final int value) { 23 | super(title); 24 | 25 | this.value = value; 26 | 27 | addActionListener(new ActionListener() { 28 | @Override 29 | public void actionPerformed(ActionEvent e) { 30 | buttonPressed(value); 31 | } 32 | }); 33 | } 34 | } 35 | 36 | private final NumButton[] buttons = new NumButton[16]; 37 | 38 | public Numpad(final IOCtrl ioctrl) { 39 | super(ioctrl, "numpad"); 40 | } 41 | 42 | @Override 43 | protected Component getContent() { 44 | JPanel content = new JPanel(new GridLayout(4, 4, 0, 0)); 45 | content.add(buttons[0] = new NumButton("7", 0x7)); 46 | content.add(buttons[1] = new NumButton("8", 0x8)); 47 | content.add(buttons[2] = new NumButton("9", 0x9)); 48 | content.add(buttons[3] = new NumButton("/", 0xc)); 49 | content.add(buttons[4] = new NumButton("4", 0x4)); 50 | content.add(buttons[5] = new NumButton("5", 0x5)); 51 | content.add(buttons[6] = new NumButton("6", 0x6)); 52 | content.add(buttons[7] = new NumButton("*", 0xd)); 53 | content.add(buttons[8] = new NumButton("1", 0x1)); 54 | content.add(buttons[9] = new NumButton("2", 0x2)); 55 | content.add(buttons[10] = new NumButton("3", 0x3)); 56 | content.add(buttons[11] = new NumButton("-", 0xa)); 57 | content.add(buttons[12] = new NumButton("0", 0x0)); 58 | content.add(buttons[13] = new NumButton(".", 0xe)); 59 | content.add(buttons[14] = new NumButton("=", 0xf)); 60 | content.add(buttons[15] = new NumButton("+", 0xb)); 61 | 62 | ioctrl.addDestination(ioctrl.getRegisters()[1], new DataDestination() { 63 | @Override 64 | public void setValue(long value) { 65 | for (NumButton button : buttons) 66 | button.setForeground(value == 0 ? Color.black : Color.red); 67 | } 68 | }); 69 | 70 | return content; 71 | } 72 | 73 | private void buttonPressed(int value) { 74 | try { 75 | ioctrl.setData(value); 76 | ioctrl.setReady(); 77 | } catch (Exception e) { } 78 | } 79 | } -------------------------------------------------------------------------------- /bcomp-ng-ui/src/main/java/ru/ifmo/cs/bcomp/ui/io/OutputDevice.java: -------------------------------------------------------------------------------- 1 | /* 2 | * $Id$ 3 | */ 4 | 5 | package ru.ifmo.cs.bcomp.ui.io; 6 | 7 | import ru.ifmo.cs.bcomp.IOCtrl; 8 | 9 | import javax.swing.*; 10 | import javax.swing.event.ChangeEvent; 11 | import javax.swing.event.ChangeListener; 12 | import java.awt.*; 13 | import java.awt.event.ItemEvent; 14 | import java.awt.event.ItemListener; 15 | 16 | /** 17 | * 18 | * @author Dmitry Afanasiev 19 | */ 20 | public abstract class OutputDevice extends IODevice { 21 | private Thread timer = null; 22 | private long sleeptime = 100; 23 | private volatile boolean poweredon = true; 24 | 25 | public OutputDevice(final IOCtrl ioctrl, final String title) { 26 | super(ioctrl, title); 27 | } 28 | 29 | protected abstract void actionPerformed(long value); 30 | 31 | protected Component getSleepSlider() { 32 | JSlider slider = new JSlider(JSlider.HORIZONTAL, 0, 3, 2); 33 | slider.addChangeListener(new ChangeListener() { 34 | @Override 35 | public void stateChanged(ChangeEvent e) { 36 | JSlider source = (JSlider)e.getSource(); 37 | sleeptime = (int)Math.pow(10, source.getValue()); 38 | } 39 | }); 40 | 41 | return slider; 42 | } 43 | 44 | protected Component getPowerChkBox() { 45 | JCheckBox power = new JCheckBox("Вкл", true); 46 | power.addItemListener(new ItemListener() { 47 | @Override 48 | public void itemStateChanged(ItemEvent e) { 49 | switch(e.getStateChange()) { 50 | case ItemEvent.SELECTED: 51 | poweredon = true; 52 | break; 53 | 54 | case ItemEvent.DESELECTED: 55 | poweredon = false; 56 | break; 57 | } 58 | } 59 | }); 60 | 61 | return power; 62 | } 63 | 64 | @Override 65 | public void activate() { 66 | super.activate(); 67 | 68 | if (timer == null) { 69 | timer = new Thread(new Runnable() { 70 | @Override 71 | public void run() { 72 | ioctrl.setReady(); 73 | 74 | for (;;) { 75 | try { 76 | Thread.sleep(sleeptime); 77 | } catch (Exception e) { } 78 | 79 | if (!poweredon) 80 | continue; 81 | 82 | if (!ioctrl.isReady()) { 83 | actionPerformed(ioctrl.getData()); 84 | ioctrl.setReady(); 85 | } 86 | } 87 | } 88 | }, title); 89 | 90 | timer.start(); 91 | } 92 | } 93 | } -------------------------------------------------------------------------------- /bcomp-ng-ui/src/main/java/ru/ifmo/cs/bcomp/ui/io/SecondIO.java: -------------------------------------------------------------------------------- 1 | package ru.ifmo.cs.bcomp.ui.io; 2 | 3 | import ru.ifmo.cs.bcomp.IOCtrl; 4 | import ru.ifmo.cs.bcomp.ui.components.ComponentManager; 5 | import ru.ifmo.cs.bcomp.ui.components.InputRegisterViewByte; 6 | 7 | import javax.swing.*; 8 | import java.awt.*; 9 | 10 | import static ru.ifmo.cs.bcomp.ui.components.DisplayStyles.COLOR_BACKGROUND; 11 | 12 | public class SecondIO extends IODevice { 13 | private ComponentManager componentManager; 14 | private InputRegisterViewByte input; 15 | 16 | public SecondIO(IOCtrl ioCtrl, ComponentManager componentManager) { 17 | super(ioCtrl, "input"); 18 | this.componentManager = componentManager; 19 | } 20 | 21 | @Override 22 | protected Component getContent() { 23 | JPanel panel = new JPanel(new GridBagLayout()); 24 | panel.setPreferredSize(new Dimension(500, 150)); 25 | panel.setBackground(COLOR_BACKGROUND); 26 | input = new InputRegisterViewByte(componentManager, ioctrl.getRegisters()[0]); 27 | input.setProperties(0, 0, false, false); 28 | input.setPreferredSize(input.getSize()); 29 | input.setMinimumSize(input.getSize()); 30 | input.setTitle("DR"); 31 | ButtonReady button = new ButtonReady(ioctrl,getRes().getString("ready")); 32 | ioctrl.addDestination(1,button); 33 | GridBagConstraints constraints = new GridBagConstraints() {{ 34 | gridy = 0; 35 | gridx = 3; 36 | gridwidth = GridBagConstraints.REMAINDER; 37 | }}; 38 | panel.add(input, constraints); 39 | constraints.gridy++; 40 | constraints.insets.top += 30; 41 | panel.add(button, constraints); 42 | return panel; 43 | } 44 | 45 | @Override 46 | public void activate() { 47 | super.activate(); 48 | input.setActive(); 49 | } 50 | } -------------------------------------------------------------------------------- /bcomp-ng-ui/src/main/java/ru/ifmo/cs/bcomp/ui/io/SevenSegmentDisplay.java: -------------------------------------------------------------------------------- 1 | /* 2 | * $Id$ 3 | */ 4 | package ru.ifmo.cs.bcomp.ui.io; 5 | 6 | import ru.ifmo.cs.bcomp.IOCtrl; 7 | 8 | import javax.swing.*; 9 | import java.awt.*; 10 | 11 | /** 12 | * 13 | * @author Dmitry Afanasiev 14 | */ 15 | public class SevenSegmentDisplay extends OutputDevice { 16 | private static final Color LED_OFF = new Color(224, 224, 224); 17 | private static final Color LED_ON = new Color(0, 160, 0); 18 | private static final int COUNT = 8; 19 | private static final int SEGMENT_LENGTH = 16; 20 | private static final int SEGMENT_WIDTH = 2; 21 | private static final Dimension DIMS = new Dimension( 22 | SEGMENT_LENGTH + 4 * SEGMENT_WIDTH, 23 | 2 * SEGMENT_LENGTH + 5 * SEGMENT_WIDTH); 24 | 25 | // Верх, середина, низ, левый верх, левый низ, правый верх, правый низ 26 | private static final boolean NUMBERS[][] = new boolean[][] { 27 | {true, false, true, true, true, true, true}, // 0 28 | {false, false, false, false, false, true, true}, // 1 29 | {true, true, true, false, true, true, false}, // 2 30 | {true, true, true, false, false, true, true}, // 3 31 | {false, true, false, true, false, true, true}, // 4 32 | {true, true, true, true, false, false, true}, // 5 33 | {true, true, true, true, true, false, true}, // 6 34 | {true, false, false, false, false, true, true}, // 7 35 | {true, true, true, true, true, true, true}, // 8 36 | {true, true, true, true, false, true, true}, // 9 37 | {false, true, false, false, false, false, false}, // A "-" 38 | {false, false, false, false, false, false, false}, // B 39 | {false, false, false, false, false, false, false}, // C 40 | {false, false, false, false, false, false, false}, // D 41 | {false, false, false, false, false, false, false}, // E 42 | {false, false, false, false, false, false, false} // F 43 | }; 44 | private static final int COORDINATES[][] = new int[][] { 45 | {pos(0, 2), pos(0, 1), SEGMENT_LENGTH, SEGMENT_WIDTH}, // Верх 46 | {pos(0, 2), pos(1, 2), SEGMENT_LENGTH, SEGMENT_WIDTH}, // Середина 47 | {pos(0, 2), pos(2, 3), SEGMENT_LENGTH, SEGMENT_WIDTH}, // Низ 48 | {pos(0, 1), pos(0, 2), SEGMENT_WIDTH, SEGMENT_LENGTH}, // Левый верх 49 | {pos(0, 1), pos(1, 3), SEGMENT_WIDTH, SEGMENT_LENGTH}, // Левый низ 50 | {pos(1, 2), pos(0, 2), SEGMENT_WIDTH, SEGMENT_LENGTH}, // Правый верх 51 | {pos(1, 2), pos(1, 3), SEGMENT_WIDTH, SEGMENT_LENGTH}, // Правый низ 52 | }; 53 | private final SSD ssd[] = new SSD[COUNT]; 54 | 55 | private class SSD extends JComponent { 56 | private int value = 0xf; 57 | 58 | public SSD() { 59 | setMinimumSize(DIMS); 60 | setMaximumSize(DIMS); 61 | setPreferredSize(DIMS); 62 | setSize(DIMS); 63 | } 64 | 65 | 66 | @Override 67 | public void paintComponent(Graphics g) { 68 | for (int i = 0; i < COORDINATES.length; i++) { 69 | g.setColor(NUMBERS[value][i] ? LED_ON : LED_OFF); 70 | g.fillRect( 71 | COORDINATES[i][0], COORDINATES[i][1], 72 | COORDINATES[i][2], COORDINATES[i][3]); 73 | } 74 | } 75 | } 76 | 77 | public SevenSegmentDisplay(IOCtrl ioctrl) { 78 | super(ioctrl, "ssd"); 79 | } 80 | 81 | private static int pos(int length, int width) { 82 | return length * SEGMENT_LENGTH + width * SEGMENT_WIDTH; 83 | } 84 | 85 | @Override 86 | protected Component getContent() { 87 | JPanel content = new JPanel(new BorderLayout()); 88 | 89 | JPanel center = new JPanel(new FlowLayout()); 90 | for (int i = COUNT; i > 0; center.add(ssd[--i] = new SSD())); 91 | content.add(BorderLayout.CENTER, center); 92 | 93 | JPanel north = new JPanel(new FlowLayout(FlowLayout.LEFT)); 94 | north.add(getSleepSlider()); 95 | north.add(getPowerChkBox()); 96 | north.add(new FlagIndicator(ioctrl, 30)); 97 | content.add(BorderLayout.NORTH, north); 98 | 99 | return content; 100 | } 101 | 102 | @Override 103 | protected void actionPerformed(long value) { 104 | int pos = ((int)value >> 4) & 0x7; 105 | 106 | ssd[pos].value = ((int)value) & 0xf; 107 | ssd[pos].repaint(); 108 | } 109 | } -------------------------------------------------------------------------------- /bcomp-ng-ui/src/main/java/ru/ifmo/cs/bcomp/ui/io/TextPrinter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * $Id$ 3 | */ 4 | 5 | package ru.ifmo.cs.bcomp.ui.io; 6 | 7 | import ru.ifmo.cs.bcomp.IOCtrl; 8 | 9 | import javax.swing.*; 10 | import javax.swing.text.BadLocationException; 11 | import java.awt.*; 12 | import java.awt.event.ActionEvent; 13 | import java.awt.event.ActionListener; 14 | import java.io.UnsupportedEncodingException; 15 | 16 | import static ru.ifmo.cs.bcomp.ui.components.DisplayStyles.FONT_COURIER_BOLD_21; 17 | 18 | /** 19 | * 20 | * @author Dmitry Afanasiev 21 | */ 22 | public class TextPrinter extends OutputDevice { 23 | private JTextArea text = null; 24 | private String charset = null; 25 | 26 | public TextPrinter(IOCtrl ioctrl) { 27 | super(ioctrl, "printer"); 28 | } 29 | 30 | @Override 31 | protected Component getContent() { 32 | JPanel content = new JPanel(new BorderLayout()); 33 | 34 | text = new JTextArea(10, 40); 35 | text.setFont(FONT_COURIER_BOLD_21); 36 | text.setEditable(false); 37 | 38 | JScrollPane sp = new JScrollPane(text); 39 | content.add(BorderLayout.CENTER, sp); 40 | 41 | JPanel north = new JPanel(new FlowLayout(FlowLayout.LEFT)); 42 | 43 | JComboBox charsetbox = new JComboBox(new String[] {charset = "KOI8-R", "ISO8859-5", "CP866", "CP1251"}); 44 | charsetbox.addActionListener(new ActionListener() { 45 | @Override 46 | public void actionPerformed(ActionEvent e) { 47 | JComboBox source = (JComboBox) e.getSource(); 48 | charset = (String)source.getSelectedItem(); 49 | } 50 | }); 51 | north.add(new JLabel("Кодировка")); 52 | north.add(charsetbox); 53 | 54 | north.add(new JLabel("Задержка")); 55 | north.add(getSleepSlider()); 56 | 57 | north.add(getPowerChkBox()); 58 | north.add(new FlagIndicator(ioctrl, 30)); 59 | 60 | content.add(BorderLayout.NORTH, north); 61 | 62 | return content; 63 | } 64 | 65 | @Override 66 | protected void actionPerformed(long value) { 67 | if (value == 0) { 68 | text.setText(""); 69 | } else if (value == 8) { 70 | try { 71 | text.setText(text.getText(0, text.getText().length() - 1)); 72 | } catch (BadLocationException e) { } 73 | } else { 74 | byte[] array = new byte[] { (byte)value }; 75 | try { 76 | text.append(new String(array, charset)); 77 | } catch (UnsupportedEncodingException ex) { } 78 | } 79 | } 80 | } -------------------------------------------------------------------------------- /bcomp-ng-ui/src/main/java/ru/ifmo/cs/bcomp/ui/io/ThirdIO.java: -------------------------------------------------------------------------------- 1 | package ru.ifmo.cs.bcomp.ui.io; 2 | import ru.ifmo.cs.bcomp.IOCtrl; 3 | import ru.ifmo.cs.bcomp.ui.components.RegisterView; 4 | import javax.swing.*; 5 | import java.awt.*; 6 | 7 | import static ru.ifmo.cs.bcomp.ui.components.DisplayStyles.*; 8 | 9 | public class ThirdIO extends IODevice { 10 | private RegisterView output; 11 | 12 | public ThirdIO(IOCtrl ioCtrl) { 13 | super(ioCtrl, "IO"); 14 | } 15 | 16 | @Override 17 | protected Component getContent() { 18 | JPanel panel = new JPanel(new GridBagLayout()); 19 | panel.setPreferredSize(new Dimension(500, 150)); 20 | panel.setBackground(COLOR_BACKGROUND); 21 | output = new RegisterView(ioctrl.getRegisters()[0]); 22 | output.setProperties(0, 0, false, false); 23 | output.setPreferredSize(output.getSize()); 24 | output.setMinimumSize(output.getSize()); 25 | output.setTitle("DR"); 26 | ButtonPanel input = new ButtonPanel(output); 27 | ButtonReady buttonReady = new ButtonReady(ioctrl,getRes().getString("ready")); 28 | ioctrl.addDestination(1,buttonReady); 29 | ioctrl.addDestination(0, output); 30 | GridBagConstraints constraints = new GridBagConstraints() {{ 31 | gridy = 0; 32 | gridx = 3; 33 | gridwidth = GridBagConstraints.REMAINDER; 34 | }}; 35 | panel.add(output, constraints); 36 | constraints.gridy++; 37 | constraints.insets.left = REG_TITLE_WIDTH; 38 | constraints.insets.top += 10; 39 | panel.add(input, constraints); 40 | constraints.gridy++; 41 | constraints.insets.top += 15; 42 | constraints.insets.left = 0; 43 | panel.add(buttonReady, constraints); 44 | return panel; 45 | } 46 | } -------------------------------------------------------------------------------- /bcomp-ng-ui/src/main/java/ru/ifmo/cs/bcomp/ui/io/Ticker.java: -------------------------------------------------------------------------------- 1 | /* 2 | * $Id$ 3 | */ 4 | package ru.ifmo.cs.bcomp.ui.io; 5 | 6 | import ru.ifmo.cs.bcomp.IOCtrl; 7 | 8 | import javax.swing.*; 9 | import java.awt.*; 10 | import java.util.Arrays; 11 | 12 | /** 13 | * 14 | * @author Dmitry Afanasiev 15 | */ 16 | public class Ticker extends OutputDevice { 17 | private static final Color LED_OFF = new Color(224, 224, 224); 18 | private static final Color LED_ON = new Color(0, 160, 0); 19 | private static final int ELEMENTS_COUNT = 32; 20 | private static final int ELEMENTS_HEIGHT = 8; 21 | private static final int ELEMENT_SIZE = 4; 22 | private static final int ELEMENT_SPACE = 2; 23 | private static final int ELEMENT_FULL_SIZE = ELEMENT_SIZE + ELEMENT_SPACE; 24 | 25 | private final int elements[] = new int[ELEMENTS_COUNT]; 26 | private int position = ELEMENTS_COUNT - 1; 27 | private TickerString ticker; 28 | 29 | private class TickerString extends JComponent { 30 | public TickerString() { 31 | Dimension d = new Dimension( 32 | ELEMENTS_COUNT * ELEMENT_FULL_SIZE + ELEMENT_SPACE, 33 | ELEMENTS_HEIGHT * ELEMENT_FULL_SIZE + ELEMENT_SPACE); 34 | setMinimumSize(d); 35 | setMaximumSize(d); 36 | setPreferredSize(d); 37 | setSize(d); 38 | } 39 | 40 | @Override 41 | public void paintComponent(Graphics g) { 42 | for (int x = 0; x < ELEMENTS_COUNT; x++) { 43 | int value = elements[(x + position) % ELEMENTS_COUNT]; 44 | 45 | for (int y = 0; y < ELEMENTS_HEIGHT; y++) { 46 | g.setColor(((value >> (ELEMENTS_HEIGHT - y - 1)) & 1) == 1 ? LED_ON : LED_OFF); 47 | g.fillRect( 48 | x * ELEMENT_FULL_SIZE + ELEMENT_SPACE, 49 | y * ELEMENT_FULL_SIZE + ELEMENT_SPACE, 50 | ELEMENT_SIZE, ELEMENT_SIZE); 51 | } 52 | } 53 | } 54 | } 55 | 56 | public Ticker(IOCtrl ioctrl) { 57 | super(ioctrl, "ticker"); 58 | 59 | Arrays.fill(elements, 0); 60 | } 61 | 62 | @Override 63 | protected Component getContent() { 64 | JPanel content = new JPanel(new BorderLayout()); 65 | 66 | JPanel center = new JPanel(new FlowLayout()); 67 | center.add(ticker = new TickerString()); 68 | content.add(BorderLayout.CENTER, center); 69 | 70 | JPanel north = new JPanel(new FlowLayout(FlowLayout.LEFT)); 71 | north.add(getSleepSlider()); 72 | north.add(getPowerChkBox()); 73 | north.add(new FlagIndicator(ioctrl, 30)); 74 | content.add(BorderLayout.NORTH, north); 75 | 76 | return content; 77 | } 78 | 79 | @Override 80 | protected void actionPerformed(long value) { 81 | elements[position] = (int)value; 82 | position = (position + 1) % ELEMENTS_COUNT; 83 | ticker.repaint(); 84 | } 85 | } -------------------------------------------------------------------------------- /bcomp-ng-ui/src/main/resources/Roboto-Medium.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HackMemory/BasicComputer/9c08095ee8ee6c5b2123c80be59c1ac43d46a931/bcomp-ng-ui/src/main/resources/Roboto-Medium.ttf -------------------------------------------------------------------------------- /bcomp-ng-ui/src/main/resources/Roboto-Regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HackMemory/BasicComputer/9c08095ee8ee6c5b2123c80be59c1ac43d46a931/bcomp-ng-ui/src/main/resources/Roboto-Regular.ttf -------------------------------------------------------------------------------- /bcomp-ng-ui/src/main/resources/dark.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 |