Package drivers
Class UDPHandler
java.lang.Object
drivers.UDPHandler
This handles UDP 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 Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetSocket
(int key) Gets the socket.void
handleTrap
(MC68000Cpu cpu) This handles all the SMSQE "trap" calls related to this device.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.static final int
writeCString
(MC68000Cpu cpu, int address, String s, int maxlength) Writes a null terminated string to (a buffer in) memory.static final int
writeCStringUnsafe
(MC68000Cpu cpu, int address, String s) Writes a null terminated string to memory without know how much mem I have.
-
Field Details
-
IP_ERROR
Error strings, always in english.
-
-
Constructor Details
-
UDPHandler
public UDPHandler()Creates the object.
-
-
Method Details
-
handleTrap
This handles all the SMSQE "trap" calls related to this device.- Parameters:
cpu
- the cpu used.
-
getSocket
Gets the socket.- Parameters:
key
- which socket to get.- Returns:
- the socket retrieved, null if not found.
-
writeCStringUnsafe
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 usedaddress
- where to write tos
- the string to write- Returns:
- nbr of bytes written
-
writeCString
Writes a null terminated string to (a buffer in) memory.- Parameters:
cpu
- the CPU usedaddress
- where to write tos
- the string to writemaxlength
- max length of buffer- Returns:
- nbr of bytes written
-
readCString
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.
-