/* Copyright (c) 1996-1997 Swiss Federal Institute of Technology, Computer Engineering and Networks Laboratory. All rights reserved. Written by George Fankhauser . For more documentation please visit http://www.tik.ee.ethz.ch/~gfa. File: $Source: /usr/drwho/vault/cvs/topsy/MipsSim/PSXConsole.java,v $ Author(s): George Fankhauser Affiliation: ETH Zuerich, TIK Version: $Revision: 1.1 $ Creation Date: December 1999 Last Date of Change: $Date: 2000/05/08 18:47:51 $ by: $Author: gfa $ $Log: PSXConsole.java,v $ Revision 1.1 2000/05/08 18:47:51 gfa new playstation stuff... */ import java.io.*; import java.util.*; import MemoryRegion; public class PSXConsole extends MemoryRegion { final int PSXADDRSIZE = 20; final int STATUS_REGISTER = 0x04; final int COMMAND_REGISTER = 0x08; final int TX_REGISTER = 0x0c; final int RX_REGISTER = TX_REGISTER; final int MODE_REGISTER = 0x10; final byte RECV_MASK = 0x01; final byte READY_TO_SEND = 0x04; InputStream in = System.in; int subcycles = 0; public PSXConsole(int baseAddress) { from = baseAddress; to = baseAddress+PSXADDRSIZE; memory = new byte[to-from+1]; } // read byte readByte(int address) throws BusErrorException { int offset = address-from; if (offset == STATUS_REGISTER) { // simulator is always ready to send... return (byte)(memory[STATUS_REGISTER] | READY_TO_SEND); } else if (offset == RX_REGISTER) { memory[STATUS_REGISTER] &= ~RECV_MASK; // clear status return memory[RX_REGISTER]; } else if (offset == MODE_REGISTER) { return memory[MODE_REGISTER]; } return 0; } void writeByte(int address, byte data) throws BusErrorException { int offset = address-from; super.writeByte(address, data); if (offset == TX_REGISTER) { System.out.write(data); System.out.flush(); } else if (offset == MODE_REGISTER) { } } // input on the psx?! void checkInterrupt(Processor p) throws IOException { try { if (in.available() > 0) { memory[RX_REGISTER] = (byte)(in.read()); memory[STATUS_REGISTER] |= RECV_MASK; // set //p.interrupt(xxx); } } catch (IOException e) { System.out.print(e.getClass().getName()+ " ("+ e.getMessage()+")\n"); System.out.println("PSXCon: couldn't read stdin"); } } }