Package smsqmulator

Class IPHandler

java.lang.Object
smsqmulator.IPHandler

public class IPHandler extends Object
This handles TCP connections. This is more complicated than Marcel's C code, since Java has three different objects for socket: Socket (client side TCP socket), ServerSocket and DatagramSocket (UDP),and they are not interchangeable. This class is not thread safe. Only 50 connections can be open at once.
  • Field Details

    • IP_ERROR

      public static final String[] IP_ERROR
      Error strings, always in english.
  • Constructor Details

    • IPHandler

      public IPHandler()
      Creates the object.
  • Method Details

    • handleTrap

      public void handleTrap(MC68000Cpu cpu)
      This handles all the SMSQE "trap" calls related to this device.
      Parameters:
      cpu - the cpu used.
    • getSocket

      public IPSocket getSocket(int key)
      Gets the socket.
      Parameters:
      key - which socket to get.
      Returns:
      the socket retrieved, null if not found.
    • writeCStringUnsafe

      public static final int writeCStringUnsafe(MC68000Cpu cpu, int address, String s)
      Writes a null terminated string to memory without know how much mem I have. Note : This is an awful hack, but: Sometimes I DON'T KNOW THE LENGTH OF THE BUFFER I'M WRITING TO, as the interface doesn't give me that information. So I just use the length of the string (+1 for the terminating 0) as maximum size of the buffer!!!! Hello possible buffer overflow. Just pray, I guess.
      Parameters:
      cpu - the CPU used
      address - where to write to
      s - the string to write
      Returns:
      nbr of bytes written
    • writeCString

      public static final int writeCString(MC68000Cpu cpu, int address, String s, int maxlength)
      Writes a null terminated string to (a buffer in) memory.
      Parameters:
      cpu - the CPU used
      address - where to write to
      s - the string to write
      maxlength - max length of buffer
      Returns:
      nbr of bytes written
    • readCString

      public static final String readCString(MC68000Cpu cpu, int address)
      Reads a "C" type string from memory and converts it to a Java String, with SMSQE char conversion. Note: potentially, this might cause the StringBuilder to overflow if no "0" is found anywhere, but I'll get an out of mem bounds error first.
      Parameters:
      cpu - the cpu with the memory array.
      address - where to read string in the memory.
      Returns:
      the corresponding String.