From add9d783f81bca2497d2feb9fed08a13a761568b Mon Sep 17 00:00:00 2001 From: Patrick Surry Date: Mon, 11 Sep 2023 20:23:57 -0400 Subject: [PATCH 1/4] Fix python3 byte decoding for non-windows platforms --- py65/utils/console.py | 67 +++++++++++++++++++++---------------------- 1 file changed, 32 insertions(+), 35 deletions(-) diff --git a/py65/utils/console.py b/py65/utils/console.py index cc9987f..ed4127e 100644 --- a/py65/utils/console.py +++ b/py65/utils/console.py @@ -24,10 +24,7 @@ if sys.platform[:3] == "win": is available. Does not echo the character. The stdin argument is for function signature compatibility and is ignored. """ - c = msvcrt.getch() - if isinstance(c, bytes): # Python 3 - c = c.decode('latin-1') - return c + return maybedecode(msvcrt.getch()) def getch_noblock(stdin): """ Read one character from the Windows console without blocking. @@ -142,38 +139,8 @@ else: # Quietly ignore termios errors, such as stdin not being a tty. pass - def getch(stdin): - """ Read one character from stdin, blocking until one is available. - Does not echo the character. - """ - # Try to get a character with a non-blocking read. + def _getchnb(stdin): char = '' - noncanonical_mode(stdin) - # If we didn't get a character, ask again. - while char == '': - try: - # On OSX, calling read when no data is available causes the - # file handle to never return any future data, so we need to - # use select to make sure there is at least one char to read. - rd,wr,er = select([stdin], [], [], 0.01) - if rd != []: - char = stdin.read(1) - except KeyboardInterrupt: - # Pass along a CTRL-C interrupt. - raise - except: - pass - return char - - def getch_noblock(stdin): - """ Read one character from stdin without blocking. Does not echo the - character. If no character is available, an empty string is returned. - """ - char = '' - - # Using non-blocking read - noncanonical_mode(stdin) - try: # On OSX, calling read when no data is available causes the # file handle to never return any future data, so we need to @@ -186,6 +153,30 @@ else: raise except: pass + return maybedecode(char) + + def getch(stdin): + """ Read one character from stdin, blocking until one is available. + Does not echo the character. + """ + # Try to get a character with a non-blocking read. + noncanonical_mode(stdin) + # If we didn't get a character, ask again. + while True: + char = _getchnb(stdin) + if len(char): + break + + return char + + def getch_noblock(stdin): + """ Read one character from stdin without blocking. Does not echo the + character. If no character is available, an empty string is returned. + """ + # Using non-blocking read + noncanonical_mode(stdin) + + char = _getchnb(stdin) # Convert linefeeds to carriage returns. if len(char) and ord(char) == 10: @@ -193,6 +184,12 @@ else: return char +def maybedecode(c): + if len(c) and isinstance(c, bytes): # Python 3 + c = c.decode('latin-1') + return c + + def line_input(prompt='', stdin=sys.stdin, stdout=sys.stdout): """ Read a line from stdin, printing each character as it is typed. Does not echo a newline at the end. This allows the calling program From 18859c908d873f1230dac6c0901c49b8594da893 Mon Sep 17 00:00:00 2001 From: Patrick Surry Date: Mon, 11 Sep 2023 20:46:31 -0400 Subject: [PATCH 2/4] Fix asm/dasm bugs --- py65/devices/mpu65c02.py | 2 +- py65/disassembler.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/py65/devices/mpu65c02.py b/py65/devices/mpu65c02.py index ef37f74..7e52839 100644 --- a/py65/devices/mpu65c02.py +++ b/py65/devices/mpu65c02.py @@ -167,7 +167,7 @@ class MPU(mpu6502.MPU): def inst_0x5a(self): self.stPush(self.y) - @instruction(name="STZ", mode="imp", cycles=3) + @instruction(name="STZ", mode="zpg", cycles=3) def inst_0x64(self): self.opSTZ(self.ZeroPageAddr) self.pc += 1 diff --git a/py65/disassembler.py b/py65/disassembler.py index 9b8caf8..af02e30 100644 --- a/py65/disassembler.py +++ b/py65/disassembler.py @@ -102,8 +102,8 @@ class Disassembler: elif addressing == 'zpi': zp_address = self._mpu.ByteAt(pc + 1) address_or_label = self._address_parser.label_for( - zp_address, '($' + self.byteFmt % zp_address + ')') - disasm += ' %s' % address_or_label + zp_address, '$' + self.byteFmt % zp_address) + disasm += ' (%s)' % address_or_label length = 2 elif addressing == 'zpg': From a77dc76f0e3ee828d7e5a81f4d328ff213bcbc1a Mon Sep 17 00:00:00 2001 From: Patrick Surry Date: Mon, 11 Sep 2023 20:50:29 -0400 Subject: [PATCH 3/4] separate issue77 fix --- py65/utils/console.py | 67 ++++++++++++++++++++++--------------------- 1 file changed, 35 insertions(+), 32 deletions(-) diff --git a/py65/utils/console.py b/py65/utils/console.py index ed4127e..cc9987f 100644 --- a/py65/utils/console.py +++ b/py65/utils/console.py @@ -24,7 +24,10 @@ if sys.platform[:3] == "win": is available. Does not echo the character. The stdin argument is for function signature compatibility and is ignored. """ - return maybedecode(msvcrt.getch()) + c = msvcrt.getch() + if isinstance(c, bytes): # Python 3 + c = c.decode('latin-1') + return c def getch_noblock(stdin): """ Read one character from the Windows console without blocking. @@ -139,8 +142,38 @@ else: # Quietly ignore termios errors, such as stdin not being a tty. pass - def _getchnb(stdin): + def getch(stdin): + """ Read one character from stdin, blocking until one is available. + Does not echo the character. + """ + # Try to get a character with a non-blocking read. char = '' + noncanonical_mode(stdin) + # If we didn't get a character, ask again. + while char == '': + try: + # On OSX, calling read when no data is available causes the + # file handle to never return any future data, so we need to + # use select to make sure there is at least one char to read. + rd,wr,er = select([stdin], [], [], 0.01) + if rd != []: + char = stdin.read(1) + except KeyboardInterrupt: + # Pass along a CTRL-C interrupt. + raise + except: + pass + return char + + def getch_noblock(stdin): + """ Read one character from stdin without blocking. Does not echo the + character. If no character is available, an empty string is returned. + """ + char = '' + + # Using non-blocking read + noncanonical_mode(stdin) + try: # On OSX, calling read when no data is available causes the # file handle to never return any future data, so we need to @@ -153,30 +186,6 @@ else: raise except: pass - return maybedecode(char) - - def getch(stdin): - """ Read one character from stdin, blocking until one is available. - Does not echo the character. - """ - # Try to get a character with a non-blocking read. - noncanonical_mode(stdin) - # If we didn't get a character, ask again. - while True: - char = _getchnb(stdin) - if len(char): - break - - return char - - def getch_noblock(stdin): - """ Read one character from stdin without blocking. Does not echo the - character. If no character is available, an empty string is returned. - """ - # Using non-blocking read - noncanonical_mode(stdin) - - char = _getchnb(stdin) # Convert linefeeds to carriage returns. if len(char) and ord(char) == 10: @@ -184,12 +193,6 @@ else: return char -def maybedecode(c): - if len(c) and isinstance(c, bytes): # Python 3 - c = c.decode('latin-1') - return c - - def line_input(prompt='', stdin=sys.stdin, stdout=sys.stdout): """ Read a line from stdin, printing each character as it is typed. Does not echo a newline at the end. This allows the calling program From 0ef2a864ef72c52f563cf16d2d9aa5e42479492f Mon Sep 17 00:00:00 2001 From: Patrick Surry Date: Tue, 12 Sep 2023 07:43:11 -0400 Subject: [PATCH 4/4] Fix incorrect test for 65c02 STZ --- py65/tests/test_assembler.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/py65/tests/test_assembler.py b/py65/tests/test_assembler.py index a4715b1..d256778 100644 --- a/py65/tests/test_assembler.py +++ b/py65/tests/test_assembler.py @@ -501,8 +501,8 @@ class AssemblerTests(unittest.TestCase): def test_assembles_64_65c02(self): mpu = MPU65C02() - self.assertEqual([0x64], - self.assemble('STZ', 0x0000, mpu)) + self.assertEqual([0x64, 0x12], + self.assemble('STZ $12', 0x0000, mpu)) def test_assembles_65(self): self.assertEqual([0x65, 0x44],