/** * 往里面添加内存模块,每种类型的内存最多只能安装一个.<p> * ram为null不会抛出异常,且不会改变RamManager的任何状态 * @param ram 需要安装的内存 * @throws IllegalStateException 已经安装了这种类型的内存 * @see #uninstall */ public void install(Ram.Ram ram) { if (ram == null) { return; } switch (ram.getRamType()) { case RamConst.RAM_RUNTIME_TYPE: if (runRam != null) { //throw new IllegalStateException("Runtime Ram was installed!"); } runRam = (RuntimeRam)ram; break; case RamConst.RAM_GRAPH_TYPE: if (graphRam != null) { //throw new IllegalStateException("Graph Ram was installed!"); } graphRam = (RelativeRam)ram; screen = graphRam.getScreenModel(); break; case RamConst.RAM_BUFFER_TYPE: if (bufferRam != null) { //throw new IllegalStateException("Buffer Ram was installed!"); } bufferRam = (RelativeRam)ram; break; case RamConst.RAM_STRING_TYPE: if (strRam != null) { //throw new IllegalStateException("String Ram was installed!"); } strRam = (StringRam)ram; break; case RamConst.RAM_TEXT_TYPE: if (textRam != null) { //throw new IllegalStateException("Text Ram was installed!"); } textRam = (RelativeRam)ram; break; } resetRamAddress(); }
/// <summary> /// 设置用于显示的ScreenModel,并作适当的初始化 /// </summary> /// <param name="screen"></param> public void setScreenModel(ScreenModel screen) { if (screen == null) { //throw new IllegalArgumentException("Screen must't be null!"); } if (this.screen != screen) { this.screen = screen; this.buffer = new sbyte[(screen.getWidth() / 6) * (screen.getHeight() / 13)]; this.getter = new ByteArrayGetter(buffer); this.ram = new ByteArrayRam(buffer, screen); this.render = screen.getRender(); } else { ram.Clear(); } this.curCol = this.curRow = 0; this.isBigMode = true; this.maxCol = screen.getWidth() / 8; this.maxRow = screen.getHeight() / 16; }