(self, addr)
return -1
Retrieve data from low memory.
Retrieve data from low memory.
Retrieve data from low memory .
def _get_low_memory(self, addr):
        """Retrieve data from low memory."""
        addr -= 0
        # from MEMORY.ABC: PEEKs and POKEs (Don Watkins)
        # http://www.qbasicnews.com/abc/showsnippet.php?filename=MEMORY.ABC&snippet=6
        # 108-115 control Ctrl-break capture; not implemented (see PC Mag POKEs)
        if addr == 124:
            return self.ram_font_addr % 256
        elif addr == 125:
            return self.ram_font_addr // 256
        elif addr == 126:
            return self.ram_font_segment % 256
        elif addr == 127:
            return self.ram_font_segment // 256
        # 1040 monitor type
        elif addr == 1040:
            if self._display.is_monochrome:
                # mono
                return 48 + 6
            else:
                # 80x25 graphics
                return 32 + 6
        # http://textfiles.com/programming/peekpoke.txt
        #   "(PEEK (1041) AND 14)/2" WILL PROVIDE NUMBER OF RS232 PORTS INSTALLED.
        #   "(PEEK (1041) AND 16)/16" WILL PROVIDE NUMBER OF GAME PORTS INSTALLED.
        #   "(PEEK (1041) AND 192)/64" WILL PROVIDE NUMBER OF PRINTERS INSTALLED.
        elif addr == 1041:
            return (
                2 * (
                    self._files.device_available(b'COM1:') +
                    self._files.device_available(b'COM2:')
                ) + 16 + 64 * (
                    self._files.device_available(b'LPT1:') +
                    self._files.device_available(b'LPT2:') +
                    self._files.device_available(b'LPT3:')
                )
            )
        # &h40:&h17 keyboard flag
        # &H80 - Insert state active
        # &H40 - CapsLock state has been toggled
        # &H20 - NumLock state has been toggled
        # &H10 - ScrollLock state has been toggled
        # &H08 - Alternate key depressed
        # &H04 - Control key depressed
        # &H02 - Left shift key depressed
        # &H01 - Right shift key depressed
        elif addr == 1047:
            return self.keyboard.mod
        # &h40:&h18 keyboard flag
        # &H80 - Insert key is depressed
        # &H40 - CapsLock key is depressed
        # &H20 - NumLock key is depressed
        # &H10 - ScrollLock key is depressed
        # &H08 - Suspend key has been toggled
        # not implemented: peek(1048)==4 if sysrq pressed, 0 otherwise
        elif addr == 1048:
            return 0
        elif addr == 1049:
            return int(self.keyboard.keypad_ascii or 0)%256
        elif addr == 1050:
            # keyboard ring buffer starts at n+1024; lowest 1054
            return (self.keyboard.buf.start*2 + self.key_buffer_offset) % 256
        elif addr == 1051:
            return (self.keyboard.buf.start*2 + self.key_buffer_offset) // 256
        elif addr == 1052:
            # ring buffer ends at n + 1023
            return (self.keyboard.buf.stop*2 + self.key_buffer_offset) % 256
        elif addr == 1053:
            return (self.keyboard.buf.stop*2 + self.key_buffer_offset) // 256
        elif addr in range(1024+self.key_buffer_offset, 1024+self.key_buffer_offset+32):
            index = (addr-1024-self.key_buffer_offset) // 2
            odd = (addr-1024-self.key_buffer_offset) % 2
            c, scan = self.keyboard.buf.ring_read(index)
            if odd:
                return scan or 0
            elif c == b'':
                return 0
            else:
                # however, arrow keys (all extended scancodes?) give 0xe0 instead of 0
                return ord(c[0:1])
        # 1097 screen mode number
        elif addr == 1097:
            # these are the low-level mode numbers used by mode switching interrupt
            return modes.get_mode_number(self._display.mode, self._display.colorswitch)
        # 1098, 1099 screen width
        elif addr == 1098:
            return self._display.mode.width % 256
        elif addr == 1099:
            return self._display.mode.width // 256
        # 1100, 1101 graphics page buffer size (32k for screen 9, 4k for screen 0)
        # 1102, 1103 zero (PCmag says graphics page buffer offset)
        elif addr == 1100:
            return self._display.mode.memorymap.page_size % 256
        elif addr == 1101:
            return self._display.mode.memorymap.page_size // 256
        # 1104 + 2*n (cursor column of page n) - 1
        # 1105 + 2*n (cursor row of page n) - 1
        # we only keep track of one row,col position
        elif addr in range(1104, 1120, 2):
            return self._display.text_screen.current_col - 1
        elif addr in range(1105, 1120, 2):
            return self._display.text_screen.current_row - 1
        # 1120, 1121 cursor shape
        elif addr == 1120:
            # to_line
            return self._display.cursor.shape[1]
        elif addr == 1121:
            # from_line
            return self._display.cursor.shape[0]
        # 1122 visual page number
        elif addr == 1122:
            return self._display.vpagenum
        # 1125 screen mode info
        elif addr == 1125:
            return self._display.get_mode_info_byte()
        # 1126 color
        elif addr == 1126:
            return self._display.get_colour_info_byte()
        # 1296, 1297: zero (PCmag says data segment address)
        return -1
def _get_low_memory ( self , addr ) : addr -= 0 # from MEMORY.ABC: PEEKs and POKEs (Don Watkins) # http://www.qbasicnews.com/abc/showsnippet.php?filename=MEMORY.ABC&snippet=6 # 108-115 control Ctrl-break capture; not implemented (see PC Mag POKEs) if addr == 124 : return self . ram_font_addr % 256 elif addr == 125 : return self . ram_font_addr // 256 elif addr == 126 : return self . ram_font_segment % 256 elif addr == 127 : return self . ram_font_segment // 256 # 1040 monitor type elif addr == 1040 : if self . _display . is_monochrome : # mono return 48 + 6 else : # 80x25 graphics return 32 + 6 # http://textfiles.com/programming/peekpoke.txt #   "(PEEK (1041) AND 14)/2" WILL PROVIDE NUMBER OF RS232 PORTS INSTALLED. #   "(PEEK (1041) AND 16)/16" WILL PROVIDE NUMBER OF GAME PORTS INSTALLED. #   "(PEEK (1041) AND 192)/64" WILL PROVIDE NUMBER OF PRINTERS INSTALLED. elif addr == 1041 : return ( 2 * ( self . _files . device_available ( b'COM1:' ) + self . _files . device_available ( b'COM2:' ) ) + 16 + 64 * ( self . _files . device_available ( b'LPT1:' ) + self . _files . device_available ( b'LPT2:' ) + self . _files . device_available ( b'LPT3:' ) ) ) # &h40:&h17 keyboard flag # &H80 - Insert state active # &H40 - CapsLock state has been toggled # &H20 - NumLock state has been toggled # &H10 - ScrollLock state has been toggled # &H08 - Alternate key depressed # &H04 - Control key depressed # &H02 - Left shift key depressed # &H01 - Right shift key depressed elif addr == 1047 : return self . keyboard . mod # &h40:&h18 keyboard flag # &H80 - Insert key is depressed # &H40 - CapsLock key is depressed # &H20 - NumLock key is depressed # &H10 - ScrollLock key is depressed # &H08 - Suspend key has been toggled # not implemented: peek(1048)==4 if sysrq pressed, 0 otherwise elif addr == 1048 : return 0 elif addr == 1049 : return int ( self . keyboard . keypad_ascii or 0 ) % 256 elif addr == 1050 : # keyboard ring buffer starts at n+1024; lowest 1054 return ( self . keyboard . buf . start * 2 + self . key_buffer_offset ) % 256 elif addr == 1051 : return ( self . keyboard . buf . start * 2 + self . key_buffer_offset ) // 256 elif addr == 1052 : # ring buffer ends at n + 1023 return ( self . keyboard . buf . stop * 2 + self . key_buffer_offset ) % 256 elif addr == 1053 : return ( self . keyboard . buf . stop * 2 + self . key_buffer_offset ) // 256 elif addr in range ( 1024 + self . key_buffer_offset , 1024 + self . key_buffer_offset + 32 ) : index = ( addr - 1024 - self . key_buffer_offset ) // 2 odd = ( addr - 1024 - self . key_buffer_offset ) % 2 c , scan = self . keyboard . buf . ring_read ( index ) if odd : return scan or 0 elif c == b'' : return 0 else : # however, arrow keys (all extended scancodes?) give 0xe0 instead of 0 return ord ( c [ 0 : 1 ] ) # 1097 screen mode number elif addr == 1097 : # these are the low-level mode numbers used by mode switching interrupt return modes . get_mode_number ( self . _display . mode , self . _display . colorswitch ) # 1098, 1099 screen width elif addr == 1098 : return self . _display . mode . width % 256 elif addr == 1099 : return self . _display . mode . width // 256 # 1100, 1101 graphics page buffer size (32k for screen 9, 4k for screen 0) # 1102, 1103 zero (PCmag says graphics page buffer offset) elif addr == 1100 : return self . _display . mode . memorymap . page_size % 256 elif addr == 1101 : return self . _display . mode . memorymap . page_size // 256 # 1104 + 2*n (cursor column of page n) - 1 # 1105 + 2*n (cursor row of page n) - 1 # we only keep track of one row,col position elif addr in range ( 1104 , 1120 , 2 ) : return self . _display . text_screen . current_col - 1 elif addr in range ( 1105 , 1120 , 2 ) : return self . _display . text_screen . current_row - 1 # 1120, 1121 cursor shape elif addr == 1120 : # to_line return self . _display . cursor . shape [ 1 ] elif addr == 1121 : # from_line return self . _display . cursor . shape [ 0 ] # 1122 visual page number elif addr == 1122 : return self . _display . vpagenum # 1125 screen mode info elif addr == 1125 : return self . _display . get_mode_info_byte ( ) # 1126 color elif addr == 1126 : return self . _display . get_colour_info_byte ( ) # 1296, 1297: zero (PCmag says data segment address) return - 1