(self, port)
Get the value in an emulated machine port.
Get the value in an emulated machine port.
Get the value in an emulated machine port .
def inp(self, port):
        """Get the value in an emulated machine port."""
        keyboard = self._keyboard
        stick = self._stick
        # keyboard
        if port == 0x60:
            return keyboard.last_scancode
        # game port (joystick)
        elif port == 0x201:
            value = (
                (not stick.is_firing[0][0]) * 0x40 +
                (not stick.is_firing[0][1]) * 0x20 +
                (not stick.is_firing[1][0]) * 0x10 +
                (not stick.is_firing[1][1]) * 0x80)
            decay = stick.decay()
            if decay < stick.axis[0][0] * self.joystick_time_factor:
                value += 0x04
            if decay < stick.axis[0][1] * self.joystick_time_factor:
                value += 0x02
            if decay < stick.axis[1][0] * self.joystick_time_factor:
                value += 0x01
            if decay < stick.axis[1][1] * self.joystick_time_factor:
                value += 0x08
            return value
        elif port in (0x379, 0x279):
            # parallel port input ports
            # http://www.aaroncake.net/electronics/qblpt.htm
            # http://retired.beyondlogic.org/spp/parallel.htm
            lpt_port_nr = 0 if port >= 0x378 else 1
            base_addr = {0: 0x378, 1: 0x278}
            if self.lpt_device[lpt_port_nr].stream is None:
                return 0
            # get status port
            busy, ack, paper, select, err = self.lpt_device[lpt_port_nr].stream.get_status()
            return busy * 0x80 | ack * 0x40 | paper * 0x20 | select * 0x10 | err * 0x8
        else:
            # serial port machine ports
            # http://www.qb64.net/wiki/index.php/Port_Access_Libraries#Serial_Communication_Registers
            # http://control.com/thread/1026221083
            for base_addr, com_port_nr in iteritems(self.com_base):
                com_port = self.com_device[com_port_nr]
                if not com_port.available():
                    continue
                # Line Control Register: base_address + 3 (r/w)
                if port == base_addr + 3:
                    _, parity, bytesize, stopbits = com_port.get_params()
                    value = self.com_enable_baud_write[com_port_nr] * 0x80
                    value += self.com_break[com_port_nr] * 0x40
                    value += {b'S': 0x38, b'M': 0x28, b'E': 0x18, b'O': 0x8, b'N': 0}[parity]
                    if stopbits > 1:
                        value += 0x4
                    value += bytesize - 5
                    return value
                # Line Status Register: base_address + 5 (read only)
                elif port == base_addr + 5:
                    # bit 6: data holding register empty
                    # bit 5: transmitter holding register empty
                    # distinction between bit 5 and 6 not implemented
                    # bit 0: data ready
                    # other bits not implemented:
                    #   1 - overrun, 2 - parity 3 - framing errors;
                    #   4 - break interrupt; 7 - at least one error in received FIFO
                    in_waiting, out_waiting = com_port.io_waiting()
                    return (1-out_waiting) * 0x60 + in_waiting
                # Modem Status Register: base_address + 6 (read only)
                elif port == base_addr + 6:
                    cd, ri, dsr, cts = com_port.get_pins()
                    # delta bits not implemented
                    return (cd*0x80 + ri*0x40 + dsr*0x20 + cts*0x10)
            # addr isn't one of the covered ports
            return 0
def inp ( self , port ) : keyboard = self . _keyboard stick = self . _stick # keyboard if port == 0x60 : return keyboard . last_scancode # game port (joystick) elif port == 0x201 : value = ( ( not stick . is_firing [ 0 ] [ 0 ] ) * 0x40 + ( not stick . is_firing [ 0 ] [ 1 ] ) * 0x20 + ( not stick . is_firing [ 1 ] [ 0 ] ) * 0x10 + ( not stick . is_firing [ 1 ] [ 1 ] ) * 0x80 ) decay = stick . decay ( ) if decay < stick . axis [ 0 ] [ 0 ] * self . joystick_time_factor : value += 0x04 if decay < stick . axis [ 0 ] [ 1 ] * self . joystick_time_factor : value += 0x02 if decay < stick . axis [ 1 ] [ 0 ] * self . joystick_time_factor : value += 0x01 if decay < stick . axis [ 1 ] [ 1 ] * self . joystick_time_factor : value += 0x08 return value elif port in ( 0x379 , 0x279 ) : # parallel port input ports # http://www.aaroncake.net/electronics/qblpt.htm # http://retired.beyondlogic.org/spp/parallel.htm lpt_port_nr = 0 if port >= 0x378 else 1 base_addr = { 0 : 0x378 , 1 : 0x278 } if self . lpt_device [ lpt_port_nr ] . stream is None : return 0 # get status port busy , ack , paper , select , err = self . lpt_device [ lpt_port_nr ] . stream . get_status ( ) return busy * 0x80 | ack * 0x40 | paper * 0x20 | select * 0x10 | err * 0x8 else : # serial port machine ports # http://www.qb64.net/wiki/index.php/Port_Access_Libraries#Serial_Communication_Registers # http://control.com/thread/1026221083 for base_addr , com_port_nr in iteritems ( self . com_base ) : com_port = self . com_device [ com_port_nr ] if not com_port . available ( ) : continue # Line Control Register: base_address + 3 (r/w) if port == base_addr + 3 : _ , parity , bytesize , stopbits = com_port . get_params ( ) value = self . com_enable_baud_write [ com_port_nr ] * 0x80 value += self . com_break [ com_port_nr ] * 0x40 value += { b'S' : 0x38 , b'M' : 0x28 , b'E' : 0x18 , b'O' : 0x8 , b'N' : 0 } [ parity ] if stopbits > 1 : value += 0x4 value += bytesize - 5 return value # Line Status Register: base_address + 5 (read only) elif port == base_addr + 5 : # bit 6: data holding register empty # bit 5: transmitter holding register empty # distinction between bit 5 and 6 not implemented # bit 0: data ready # other bits not implemented: #   1 - overrun, 2 - parity 3 - framing errors; #   4 - break interrupt; 7 - at least one error in received FIFO in_waiting , out_waiting = com_port . io_waiting ( ) return ( 1 - out_waiting ) * 0x60 + in_waiting # Modem Status Register: base_address + 6 (read only) elif port == base_addr + 6 : cd , ri , dsr , cts = com_port . get_pins ( ) # delta bits not implemented return ( cd * 0x80 + ri * 0x40 + dsr * 0x20 + cts * 0x10 ) # addr isn't one of the covered ports return 0