(self, args)
OUT: send a byte to a machine port.
OUT: send a byte to a machine port.
OUT : send a byte to a machine port .
def out_(self, args):
        """OUT: send a byte to a machine port."""
        addr = values.to_int(next(args), unsigned=True)
        val = values.to_int(next(args))
        error.range_check(0, 255, val)
        list(args)
        if addr == 0x201:
            # game port reset
            self._stick.reset_decay()
        elif addr == 0x3c5:
            # officially, requires OUT &H3C4, 2 first (not implemented)
            self._display.mode.memorymap.set_plane_mask(val)
        elif addr == 0x3cf:
            # officially, requires OUT &H3CE, 4 first (not implemented)
            self._display.mode.memorymap.set_plane(val)
        elif addr == 0x3d8:
            # CGA mode control register, see http://www.seasip.info/VintagePC/cga.html
            # bit 5 - enable blink (1) show blink as bright background (0) (not implemented)
            # bit 4 - select 640x200x2 mode (not implemented)
            # bit 3 - (1) enable video output (0) disable, show all as background (not implemented)
            # bit 2 - (1) disable colorburst (0) enable colorburst
            # bit 1 - (1) graphics mode (0) text mode (not implemented)
            # bit 0 - high resolution text (?) (not implemented)
            #OUT &H3D8,&H1A: REM enable color burst
            #OUT &H3D8,&H1E: REM disable color burst
            # 0x1a == 0001 1010     0x1e == 0001 1110
            self._display.colourmap.set_colorburst(val & 4 == 0)
        elif addr == 0x3d9:
            # CGA colour control register, see http://www.seasip.info/VintagePC/cga.html
            # bit 5 - palette 0 = r/g/y 1 = c/m/y/k (320x200x4 only)
            # bit 4 - 1 = high intensity 0 = low intensity (320x200x4 only)
            # bits 3-0: Border / Background / Foreground (not implemented)
            #    These 4 bits select one of the 16 CGA colours
            #    (bit 3 = Intensity, Bit 2 = Red, Bit 1 = Green, Bit 0 = Blue).
            #    In text modes, this colour is used for the border (overscan).
            #    In 320x200 graphics modes, it is used for the background and border.
            #    In 640x200 mode, it is used for the foreground colour.
            self._display.colourmap.set_cga4_palette(bool(val & 0x10))
            self._display.colourmap.set_cga4_intensity(bool(val & 0x8))
        elif addr in (0x378, 0x37A, 0x278, 0x27A):
            # parallel port output ports
            # http://www.aaroncake.net/electronics/qblpt.htm
            # http://retired.beyondlogic.org/spp/parallel.htm
            lpt_port_nr = 0 if addr >= 0x378 else 1
            base_addr = {0: 0x378, 1: 0x278}
            if self.lpt_device[lpt_port_nr].stream is None:
                return
            if addr - base_addr[lpt_port_nr] == 0:
                # set data port
                self.lpt_device[lpt_port_nr].stream.write(int2byte(val))
            else:
                # set control port
                self.lpt_device[lpt_port_nr].stream.set_control(
                    select=val & 0x8, init=val&0x4, lf=val&0x2, strobe=val&0x1
                )
        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
                # ports at base addr and the next one are used for writing baud rate
                # (among other things that aren't implemented)
                if addr in (base_addr, base_addr+1) and self.com_enable_baud_write[com_port_nr]:
                    if addr == base_addr:
                        self.com_baud_divisor[com_port_nr] = (
                            (self.com_baud_divisor[com_port_nr] & 0xff00) + val
                        )
                    elif addr == base_addr + 1:
                        self.com_baud_divisor[com_port_nr] = (
                            val*0x100 + (self.com_baud_divisor[com_port_nr] & 0xff)
                        )
                    if self.com_baud_divisor[com_port_nr]:
                        baudrate, parity, bytesize, stopbits = com_port.get_params()
                        baudrate = 115200 // self.com_baud_divisor[com_port_nr]
                        com_port.set_params(baudrate, parity, bytesize, stopbits)
                # Line Control Register: base_address + 3 (r/w)
                elif addr == base_addr + 3:
                    baudrate, parity, bytesize, stopbits = com_port.get_params()
                    if val & 0x80:
                        self.com_enable_baud_write[com_port_nr] = True
                    # break condition
                    self.com_break[com_port_nr] = (val & 0x40) != 0
                    # parity
                    parity = {0x38: b'S', 0x28: b'M', 0x18: b'E', 0x8: b'O', 0: b'N'}[val&0x38]
                    # stopbits
                    if val & 0x4:
                        # 2 or 1.5 stop bits
                        stopbits = 2
                    else:
                        # 1 stop bit
                        stopbits = 1
                    # set byte size to 5, 6, 7, 8
                    bytesize = (val & 0x3) + 5
                    com_port.set_params(baudrate, parity, bytesize, stopbits)
                    com_port.set_pins(brk=self.com_break[com_port_nr])
                # Modem Control Register: base_address + 4 (r/w)
                elif addr == base_addr + 4:
                    com_port.set_pins(rts=val & 0x2, dtr=val & 0x1)
def out_ ( self , args ) : addr = values . to_int ( next ( args ) , unsigned = True ) val = values . to_int ( next ( args ) ) error . range_check ( 0 , 255 , val ) list ( args ) if addr == 0x201 : # game port reset self . _stick . reset_decay ( ) elif addr == 0x3c5 : # officially, requires OUT &H3C4, 2 first (not implemented) self . _display . mode . memorymap . set_plane_mask ( val ) elif addr == 0x3cf : # officially, requires OUT &H3CE, 4 first (not implemented) self . _display . mode . memorymap . set_plane ( val ) elif addr == 0x3d8 : # CGA mode control register, see http://www.seasip.info/VintagePC/cga.html # bit 5 - enable blink (1) show blink as bright background (0) (not implemented) # bit 4 - select 640x200x2 mode (not implemented) # bit 3 - (1) enable video output (0) disable, show all as background (not implemented) # bit 2 - (1) disable colorburst (0) enable colorburst # bit 1 - (1) graphics mode (0) text mode (not implemented) # bit 0 - high resolution text (?) (not implemented) #OUT &H3D8,&H1A: REM enable color burst #OUT &H3D8,&H1E: REM disable color burst # 0x1a == 0001 1010     0x1e == 0001 1110 self . _display . colourmap . set_colorburst ( val & 4 == 0 ) elif addr == 0x3d9 : # CGA colour control register, see http://www.seasip.info/VintagePC/cga.html # bit 5 - palette 0 = r/g/y 1 = c/m/y/k (320x200x4 only) # bit 4 - 1 = high intensity 0 = low intensity (320x200x4 only) # bits 3-0: Border / Background / Foreground (not implemented) #    These 4 bits select one of the 16 CGA colours #    (bit 3 = Intensity, Bit 2 = Red, Bit 1 = Green, Bit 0 = Blue). #    In text modes, this colour is used for the border (overscan). #    In 320x200 graphics modes, it is used for the background and border. #    In 640x200 mode, it is used for the foreground colour. self . _display . colourmap . set_cga4_palette ( bool ( val & 0x10 ) ) self . _display . colourmap . set_cga4_intensity ( bool ( val & 0x8 ) ) elif addr in ( 0x378 , 0x37A , 0x278 , 0x27A ) : # parallel port output ports # http://www.aaroncake.net/electronics/qblpt.htm # http://retired.beyondlogic.org/spp/parallel.htm lpt_port_nr = 0 if addr >= 0x378 else 1 base_addr = { 0 : 0x378 , 1 : 0x278 } if self . lpt_device [ lpt_port_nr ] . stream is None : return if addr - base_addr [ lpt_port_nr ] == 0 : # set data port self . lpt_device [ lpt_port_nr ] . stream . write ( int2byte ( val ) ) else : # set control port self . lpt_device [ lpt_port_nr ] . stream . set_control ( select = val & 0x8 , init = val & 0x4 , lf = val & 0x2 , strobe = val & 0x1 ) 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 # ports at base addr and the next one are used for writing baud rate # (among other things that aren't implemented) if addr in ( base_addr , base_addr + 1 ) and self . com_enable_baud_write [ com_port_nr ] : if addr == base_addr : self . com_baud_divisor [ com_port_nr ] = ( ( self . com_baud_divisor [ com_port_nr ] & 0xff00 ) + val ) elif addr == base_addr + 1 : self . com_baud_divisor [ com_port_nr ] = ( val * 0x100 + ( self . com_baud_divisor [ com_port_nr ] & 0xff ) ) if self . com_baud_divisor [ com_port_nr ] : baudrate , parity , bytesize , stopbits = com_port . get_params ( ) baudrate = 115200 // self . com_baud_divisor [ com_port_nr ] com_port . set_params ( baudrate , parity , bytesize , stopbits ) # Line Control Register: base_address + 3 (r/w) elif addr == base_addr + 3 : baudrate , parity , bytesize , stopbits = com_port . get_params ( ) if val & 0x80 : self . com_enable_baud_write [ com_port_nr ] = True # break condition self . com_break [ com_port_nr ] = ( val & 0x40 ) != 0 # parity parity = { 0x38 : b'S' , 0x28 : b'M' , 0x18 : b'E' , 0x8 : b'O' , 0 : b'N' } [ val & 0x38 ] # stopbits if val & 0x4 : # 2 or 1.5 stop bits stopbits = 2 else : # 1 stop bit stopbits = 1 # set byte size to 5, 6, 7, 8 bytesize = ( val & 0x3 ) + 5 com_port . set_params ( baudrate , parity , bytesize , stopbits ) com_port . set_pins ( brk = self . com_break [ com_port_nr ] ) # Modem Control Register: base_address + 4 (r/w) elif addr == base_addr + 4 : com_port . set_pins ( rts = val & 0x2 , dtr = val & 0x1 )