class Zemu::Config::SerialPort
Serial Input/Output object
Represents a serial connection between the emulated CPU and the host machine, with input and output mapped to Z80 I/O ports.
Public Class Methods
new()
click to toggle source
Constructor.
Takes a block in which the parameters of the serial port can be initialized.
All parameters can be set within this block. They become readonly as soon as the block completes.
@example
Zemu::Config::SerialPort.new do name "serial" in_port 0x00 out_port 0x01 end
Calls superclass method
Zemu::Config::IOPort::new
# File lib/zemu/config.rb, line 348 def initialize super when_setup do "SerialBuffer io_#{name}_buffer_master = { .head = 0, .tail = 0 };\n" + "SerialBuffer io_#{name}_buffer_slave = { .head = 0, .tail = 0 };\n" + "\n" + "zusize zemu_io_#{name}_buffer_size(void)\n" + "{\n" + " zusize start = io_#{name}_buffer_slave.head;\n" + " zusize end = io_#{name}_buffer_slave.tail\n;" + " if (end < start) end += ZEMU_IO_SERIAL_BUFFER_SIZE;\n" + " return end - start;\n" + "}\n" + "\n" + "void zemu_io_#{name}_slave_puts(zuint8 val)\n" + "{\n" + " io_#{name}_buffer_slave.buffer[io_#{name}_buffer_slave.tail] = val;\n" + " io_#{name}_buffer_slave.tail++;\n" + " if (io_#{name}_buffer_slave.tail >= ZEMU_IO_SERIAL_BUFFER_SIZE)\n" + " io_#{name}_buffer_slave.tail = 0;\n" + "}\n" + "\n" + "zuint8 zemu_io_#{name}_slave_gets(void)\n" + "{\n" + " zuint8 val = io_#{name}_buffer_master.buffer[io_#{name}_buffer_master.head];\n" + " io_#{name}_buffer_master.head++;\n" + " if (io_#{name}_buffer_master.head >= ZEMU_IO_SERIAL_BUFFER_SIZE)\n" + " io_#{name}_buffer_master.head = 0;\n" + "\n" + " return val;\n" + "}\n" + "\n" + "void zemu_io_#{name}_master_puts(zuint8 val)\n" + "{\n" + " io_#{name}_buffer_master.buffer[io_#{name}_buffer_master.tail] = val;\n" + " io_#{name}_buffer_master.tail++;\n" + " if (io_#{name}_buffer_master.tail >= ZEMU_IO_SERIAL_BUFFER_SIZE)\n" + " io_#{name}_buffer_master.tail = 0;\n" + "}\n" + "\n" + "zuint8 zemu_io_#{name}_master_gets(void)\n" + "{\n" + " zuint8 val = io_#{name}_buffer_slave.buffer[io_#{name}_buffer_slave.head];\n" + " io_#{name}_buffer_slave.head++;\n" + " if (io_#{name}_buffer_slave.head >= ZEMU_IO_SERIAL_BUFFER_SIZE)\n" + " io_#{name}_buffer_slave.head = 0;\n" + "\n" + " return val;\n" + "}\n" end when_read do "if (port == #{in_port})\n" + "{\n" + " return zemu_io_#{name}_slave_gets();\n" + "}\n" + "else if (port == #{ready_port})\n" + "{\n" + " if (io_#{name}_buffer_master.head == io_#{name}_buffer_master.tail)\n" + " {\n" + " return 0;\n" + " }\n" + " else\n" + " {\n" + " return 1;\n" + " }\n" + "}\n" end when_write do "if (port == #{out_port})\n" + "{\n" + " zemu_io_#{name}_slave_puts(value);\n" + "}\n" end end
Public Instance Methods
functions()
click to toggle source
Defines FFI API which will be available to the instance wrapper if this IO device is used.
# File lib/zemu/config.rb, line 427 def functions [ {"name" => "zemu_io_#{name}_master_puts".to_sym, "args" => [:uint8], "return" => :void}, {"name" => "zemu_io_#{name}_master_gets".to_sym, "args" => [], "return" => :uint8}, {"name" => "zemu_io_#{name}_buffer_size".to_sym, "args" => [], "return" => :uint64} ] end
params()
click to toggle source
Valid parameters for a SerialPort
, along with those defined in [Zemu::Config::IOPort].
Calls superclass method
Zemu::Config::IOPort#params
# File lib/zemu/config.rb, line 437 def params super + %w(in_port out_port ready_port) end