Class: Amaterasu::GameBoy::Serial
- Inherits:
-
Object
- Object
- Amaterasu::GameBoy::Serial
- Defined in:
- lib/amaterasu/game_boy/serial.rb
Overview
Models the Serial Port present in the Game Boy.
-
Very useful for performing community accuracy tests, they use the serial to output results.
Instance Attribute Summary collapse
-
#message_buffer ⇒ Object
readonly
Returns an Array with all the bytes from the serial transfer.
-
#sb ⇒ Object
Returns the 8-bit value stored in the SB (Serial Transfer Data) register.
Instance Method Summary collapse
-
#initialize(interrupts, trace_serial: false) ⇒ Serial
constructor
Creates a serial port instance.
-
#sc ⇒ Object
Returns the 8-bit value stored in the SC (Serial Transfer Control) register.
-
#sc=(value) ⇒ Object
Sets a 8-bit value into the SC register.
Constructor Details
#initialize(interrupts, trace_serial: false) ⇒ Serial
Creates a serial port instance.
-
Needs to hold an instance of interrupts to request a :serial interrupt.
-
Holds the state of the Transfer Data and Control registers.
19 20 21 22 23 24 25 26 27 |
# File 'lib/amaterasu/game_boy/serial.rb', line 19 def initialize(interrupts, trace_serial: false) @interrupts = interrupts @trace_serial = trace_serial @sb = 0x00 @sc = 0xFF @message_buffer = Array.new end |
Instance Attribute Details
#message_buffer ⇒ Object (readonly)
Returns an Array with all the bytes from the serial transfer.
13 14 15 |
# File 'lib/amaterasu/game_boy/serial.rb', line 13 def @message_buffer end |
#sb ⇒ Object
Returns the 8-bit value stored in the SB (Serial Transfer Data) register.
10 11 12 |
# File 'lib/amaterasu/game_boy/serial.rb', line 10 def sb @sb end |
Instance Method Details
#sc ⇒ Object
Returns the 8-bit value stored in the SC (Serial Transfer Control) register.
-
In the actual hardware only Bit 7 and Bit 0 are wired.
-
Bits 6-1 always return 1 when read.
33 34 35 |
# File 'lib/amaterasu/game_boy/serial.rb', line 33 def sc @sc | 0b01111110 end |
#sc=(value) ⇒ Object
Sets a 8-bit value into the SC register.
-
Bits 6-1 are ignored since they are not wired to anything.
-
If bit 7 goes from 0 -> 1, a transfer is started.
46 47 48 49 50 |
# File 'lib/amaterasu/game_boy/serial.rb', line 46 def sc=(value) @sc = value & 0b10000001 start_transfer if transfer_enabled? end |