Page 1 of 1
Py65 Help
Posted: Wed Apr 10, 2024 7:05 am
by rob42
I've installed Py65 (from
https://github.com/mnaberez/py65), but I seem to have hit an issue from the get-go.
Running monitor.py does indeed start said and I can enter some commands:
Code: Select all
Py65 Monitor
PC AC XR YR SP NV-BDIZC
6502: 0000 00 00 00 ff 00110000
.assemble 1000 lda #$10
$1000 a9 10 LDA #$10
PC AC XR YR SP NV-BDIZC
6502: 0000 00 00 00 ff 00110000
.add_label 1000 start
PC AC XR YR SP NV-BDIZC
6502: 0000 00 00 00 ff 00110000
.disassemble start:start+10
$1000 a9 10 LDA #$10
$1002 00 BRK
$1003 00 BRK
$1004 00 BRK
$1005 00 BRK
$1006 00 BRK
$1007 00 BRK
$1008 00 BRK
$1009 00 BRK
$100a 00 BRK
$100b 00 BRK
$100c 00 BRK
$100d 00 BRK
$100e 00 BRK
$100f 00 BRK
$1010 00 BRK
PC AC XR YR SP NV-BDIZC
6502: 0000 00 00 00 ff 00110000
.assemble 1002
$1002 _
At this point, I've started the interactive assembler and the monitor is waiting for my input, but as soon as I type anything else, I encounter this Traceback:
Code: Select all
Traceback (most recent call last):
File "/home/rob/6502/py65-main/py65/monitor.py", line 163, in onecmd
result = cmd.Cmd.onecmd(self, line)
File "/usr/lib/python3.10/cmd.py", line 217, in onecmd
return func(arg)
File "/home/rob/6502/py65-main/py65/monitor.py", line 344, in do_assemble
return self._interactive_assemble(args)
File "/home/rob/6502/py65-main/py65/monitor.py", line 382, in _interactive_assemble
line = console.line_input(prompt,
File "/usr/local/lib/python3.10/dist-packages/py65-2.0.0.dev0-py3.10.egg/py65/utils/console.py", line 217, in line_input
line += char
TypeError: can only concatenate str (not "bytes") to str
The error is caught, and Py65 does not crash out, which is smart coding, but what's going on here?
I know that other Forum members have used Py65, so could anyone help me here, please? Are you getting this same issue, or is this something that's wrong with my setup?
I'm running a Linux Mint distro with Python 3.10.12
Thank you, in advance.
Re: Py65 Help
Posted: Wed Apr 10, 2024 7:17 am
by hoglet
Are you running the most recent commit of py65?
It sounds like this issue (or one very like it) was fixed in September 2023:
https://github.com/mnaberez/py65/issues/77
Dave
Re: Py65 Help
Posted: Wed Apr 10, 2024 7:43 am
by rob42
Are you running the most recent commit of py65?
Thank you for the very fast response, Dave.
I simply d/loaded the .zip file, from the front page <> Code tab. The files are date stamped 19 November 2023, so I can only assume that they have to be the latest commit.
Your thoughts?
Re: Py65 Help
Posted: Wed Apr 10, 2024 8:39 am
by hoglet
I simply d/loaded the .zip file, from the front page <> Code tab. The files are date stamped 19 November 2023, so I can only assume that they have to be the latest commit.
That should be the very latest code.
Looking at your stack trace, I see a mix of paths:
but also:
Code: Select all
/usr/local/lib/python3.10/dist-packages/py65-2.0.0.dev0-py3.10.egg/py65/
Do you have another (older) version of py65 installed as a package?
That might account for the error recurring?
Dave
Re: Py65 Help
Posted: Wed Apr 10, 2024 8:46 am
by rob42
Do you have another (older) version of py65 installed as a package?
That might account for the error recurring?
Dave
No, I don't; but I do see your point.
---
I've now run it from from the system directory, but it's the same story:
Code: Select all
Py65 Monitor
PC AC XR YR SP NV-BDIZC
6502: 0000 00 00 00 ff 00110000
.assemble 1000
$1000 Traceback (most recent call last):
File "/usr/local/lib/python3.10/dist-packages/py65-2.0.0.dev0-py3.10.egg/py65/monitor.py", line 163, in onecmd
result = cmd.Cmd.onecmd(self, line)
File "/usr/lib/python3.10/cmd.py", line 217, in onecmd
return func(arg)
File "/usr/local/lib/python3.10/dist-packages/py65-2.0.0.dev0-py3.10.egg/py65/monitor.py", line 344, in do_assemble
return self._interactive_assemble(args)
File "/usr/local/lib/python3.10/dist-packages/py65-2.0.0.dev0-py3.10.egg/py65/monitor.py", line 382, in _interactive_assemble
line = console.line_input(prompt,
File "/usr/local/lib/python3.10/dist-packages/py65-2.0.0.dev0-py3.10.egg/py65/utils/console.py", line 217, in line_input
line += char
TypeError: can only concatenate str (not "bytes") to str
PC AC XR YR SP NV-BDIZC
6502: 0000 00 00 00 ff 00110000
.
Re: Py65 Help
Posted: Wed Apr 10, 2024 9:15 am
by hoglet
Do you have another (older) version of py65 installed as a package?
No, I don't; but I do see your point.
None the less, there does appear to be two installations of py65.
What does the following report? (this is one single line)
Code: Select all
dpkg -S /usr/local/lib/python3.10/dist-packages/py65-2.0.0.dev0-py3.10.egg/py65/utils/console.py
I've now run it from the system directory, but it's the same story:
That's expected I think, because now it's only using the older (broken) version.
Maybe someone else knows the right way to fix this - I'm only a very casual python user.
You somehow need to force it to use the modules from /home/rob/6502/py65-main/py65 rather then the older modules that happen to be installed in the system directory.
Dave
Re: Py65 Help
Posted: Wed Apr 10, 2024 9:24 am
by rob42
Thank you for your help and input, Dave.
I'll hold off trying anything else right now, and see if there are any other users that are having the same issue. I could mess on with this all day, and still get nowhere: I have other things that I need to get to.
Have a good day and thanks for your help.
~ Rob.
Re: Py65 Help
Posted: Wed Apr 10, 2024 9:39 am
by hoglet
OK, this is very confusing....
It looks like the fix for
Issue 77 was merged, then later reverted.
You can see that if you look in detail at the most
recent pull requests that Mike merged.
The fix for issue 77 is in
Pull request 78.
But it's (I think accidentally) been reverted by
Pull request 80.
So the latest code does not include this fix.
This is way above my pay grade now, so I'll defer to someone more involved in the development here.
Dave
Re: Py65 Help
Posted: Wed Apr 10, 2024 12:53 pm
by SamCoVT
This is one of the fun parts about trying to support both Python 2 and Python 3 - byte strings and character strings used to be interchangeable and now in Python 3 they are not. Because you are running Python 3, you can simply adjust the line_input function to convert the character (byte, really) into a string and then the concatenate (adding the letter you just typed to the string) works fine. I was able to reproduce your error, and I edited console.py directly and was able to make it work. On your system, the file will be /usr/local/lib/python3.10/dist-packages/py65-2.0.0.dev0-py3.10.egg/py65/utils/console.py and you'll need to be root to modify it. Here is my replacement line_input function (found at the very bottom of the file):
Code: Select all
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
to overwrite the line by first sending a carriage return ('\r'), which
is useful in modes like the interactive assembler.
"""
stdout.write(prompt)
line = ''
while True:
char = getch(stdin)
code = ord(char)
if code in (0x0A, 0x0D): # LF or CR
break
elif code in (0x7f, 0x08): # backspace
if len(line) > 0:
line = line[:-1]
stdout.write("\r%s\r%s%s" %
(' ' * (len(prompt + line) + 5), prompt, line))
elif code == 0x1b: # escape
pass
else:
line += str(char, 'utf-8')
stdout.write(str(char, 'utf-8'))
stdout.flush()
return line
The changes I made were to convert char to a utf-8 encoded string near the bottom and change it to look at
code instead of
char to detect carriage returns and linefeeds for the line ending. Note that if you upgrade py65mon, this modification will be overwritten. If you ever want to undo this change, just uninstall and reinstall py65.
You should add to issue #64 on Mike's github with all of the info from your first post here. It has everything needed to reproduce the error and shows where the issue is. I don't know if my fix works cross-platform or with Python2, but it should work for you on Linux with Python3.
[Edited to clean up some typos and formatting and note there is already an open issue for this]
[Edited to correct exact file name]
Re: Py65 Help
Posted: Wed Apr 10, 2024 1:45 pm
by SamCoVT
OK, this is very confusing....
It looks like the fix for
Issue 77 was merged, then later reverted.
...So the latest code does not include this fix.
If you look further into that Pull Request, only the code for fixing the STZ instruction in the assembler was actually merged (which makes sense - that's what the title of the PR says it does). The I/O code was not merged. The last changes to console.py are from 3 years ago, so this is likely still an active issue. It looks like issue #64, which exactly describes this issue, is still open and could use a bump to indicate it's still a problem.
Re: Py65 Help
Posted: Wed Apr 10, 2024 2:21 pm
by rob42
... On your system, the file will be /usr/local/lib/python3.10/dist-packages/py65-2.0.0.dev0-py3.10.egg/py65/monitor.py and you'll need to be root to modify it...
I can see how this would get real confusing, real quick. And in fact that's what has happen here, with the file names:
The script that needs to be changed is `/usr/local/lib/python3.10/dist-packages/py65-2.0.0.dev0-py3.10.egg/py65/utils/console.py`
That aside, your 'bug fix' seems to have done the trick. I've not fully tested it, as I don't have the time, just yet, but it has, without any doubt, fixed the issue that I did have.
So, unless this fix breaks something else (which I know, from experience, can happen), it's job done!
Thank you so much for the fix and the time and trouble you went to.
You should add to issue #64 on Mike's github with all of the info from your first post here. It has everything needed to reproduce the error and shows where the issue is. I don't know if my fix works cross-platform or with Python2, but it should work for you on Linux with Python3.
Indeed, it does seem to, so far as I can tell at this stage; I will report to the github page.
On Python2: I'm sure that I saw something to the effect that Python2 support had been dropped, which, given its age, as well as the major differences between v2 and v3, should not be a surprise to anyone.
Thank you, once more.
Have a good day.
~ Rob.
Re: Py65 Help
Posted: Wed Apr 10, 2024 3:02 pm
by SamCoVT
The script that needs to be changed is `/usr/local/lib/python3.10/dist-packages/py65-2.0.0.dev0-py3.10.egg/py65/utils/console.py`
That aside, your 'bug fix' seems to have done the trick. I've not fully tested it, as I don't have the time, just yet, but it has, without any doubt, fixed the issue that I did have.
Oh, yes - it looks like I copy/pasted the wrong file from your error message. I'm glad you were able to figure it out. My fix will work on Linux and Mac, but I'd have to test it on Windows and it may not work on Python 2.x.
On Python2: I'm sure that I saw something to the effect that Python2 support had been dropped, which, given its age, as well as the major differences between v2 and v3, should not be a surprise to anyone.
Python 2 was supposed to sunset almost 10 years ago in 2015, but a lot of Linux distros had packages written in Py2 that had no Py3 replacement and didn't work under Py3, so a lot of the Linux distros were still shipping Py2 even until just a few years ago. Because of this, Py2 support was extended until 2020 - it was finally discontinued (the Python Software Foundation calls it "sunset") at that time with no new updates and no support. Now that Py2 is officially discontinued, I expect py65 will eventually drop support and it will make things much easier - the existing codebase uses only features that both versions have.
I think this particular function is only used by the assembler, so I don't expect you to encounter any breakage anywhere else from this change. The I/O in py65mon is tricky because it switches back and forth between echoed and non-echoed mode so it can handle both commands (with history and cursor motion) as well as raw I/O for the 6502 application. Windows and Linux do this in drastically different ways, and even OSX has some slight differences from Linux when dealing with I/O at this low level.