6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Fri Nov 01, 2024 5:27 am

All times are UTC




Post new topic Reply to topic  [ 17 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: python for 6502?
PostPosted: Thu Jul 30, 2015 5:48 am 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10971
Location: England
Posting this as a placeholder in case anyone feels brave.

Elsewhere Scot mused
scotws wrote:
there is no way that Python will run on an 8-bit CPU

which prompted me to have a look. It turns out there are a couple of miniature pythons, although they are both a bit large for a 64k address space and have not, I think, yet been ported to 6502. They are C projects - is cc65 up to the task? I don't know.

PyMite requires roughly 55 KB program memory, initializes in 4KB RAM; print "hello world" needs 5KB; 8KB is the minimum recommended RAM.

Micro Python takes around 75kb of ROM and can run in as little as 8kb RAM

I think PyMite puts only the execution engine on the target - you compile your python source down to bytecode on a more capable host. With Micro Python, it looks like you get the full interpreter on the target.

There's also PyNES, which has a game-writing library, not sure if it's good for general python. There are a couple of video presentations too (which I confess I haven't yet watched).


Top
 Profile  
Reply with quote  
 Post subject: Re: python for 6502?
PostPosted: Thu Jul 30, 2015 6:19 am 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8468
Location: Midwestern USA
BigEd wrote:
Posting this as a placeholder in case anyone feels brave.

Elsewhere Scot mused
scotws wrote:
there is no way that Python will run on an 8-bit CPU

which prompted me to have a look. It turns out there are a couple of miniature pythons, although they are both a bit large for a 64k address space and have not, I think, yet been ported to 6502. They are C projects - is cc65 up to the task? I don't know.

PyMite requires roughly 55 KB program memory, initializes in 4KB RAM; print "hello world" needs 5KB; 8KB is the minimum recommended RAM.

Micro Python takes around 75kb of ROM and can run in as little as 8kb RAM

I think PyMite puts only the execution engine on the target - you compile your python source down to bytecode on a more capable host. With Micro Python, it looks like you get the full interpreter on the target.

There's also PyNES, which has a game-writing library, not sure if it's good for general python. There are a couple of video presentations too (which I confess I haven't yet watched).

Python is not something in which I'm interested, but I do have to wonder if the best approach for running it on 65xx hardware is to "port" it to assembly language. I've yet to meet a 6502 C compiler that emits succinct code. Even the output of WDC's C compiler tends to be somewhat corpulent. Of course, the "port" would probably include a lot of tedium...but that's to be expected.

_________________
x86?  We ain't got no x86.  We don't NEED no stinking x86!


Top
 Profile  
Reply with quote  
 Post subject: Re: python for 6502?
PostPosted: Fri Jul 31, 2015 6:30 pm 
Offline

Joined: Wed Jan 08, 2014 3:31 pm
Posts: 578
Is the goal of this project to produce something useful, or just a a proof of concept?

One way to squeeze a miniature Python into a 64K address space might be to use a byte code VM at the expense of performance. If I recall correctly Sweet16 code is considerably more compact than native 6502 code at 1/10 the speed of native code. So have a C compiler target a bytecode VM, then having a C compiler target that VM might be a way to port it.


Top
 Profile  
Reply with quote  
 Post subject: Re: python for 6502?
PostPosted: Fri Jul 31, 2015 6:50 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10971
Location: England
Martin_H wrote:
Is the goal of this project to produce something useful, or just a a proof of concept?

On my part, merely musing on what might be possible.

Quote:
One way to squeeze a miniature Python into a 64K address space might be to use a byte code VM at the expense of performance. If I recall correctly Sweet16 code is considerably more compact than native 6502 code at 1/10 the speed of native code. So have a C compiler target a bytecode VM, then having a C compiler target that VM might be a way to port it.

I think PyMite is like this: the 6502 part is only the VM, with the upfront compilation done on the more powerful host. (Python bytecode article.)

To know whether the 6502 need only be the execution environment, or also the host, is a question for the user! As Python is a much bigger language and almost infinitely harder to parse than Forth, it's certain to be more of a challenge. The payoff would be in the programmer productivity. But you'd have to ask why do this on a 6502...


Top
 Profile  
Reply with quote  
 Post subject: Re: python for 6502?
PostPosted: Sat Aug 01, 2015 1:13 am 
Offline

Joined: Wed Jan 08, 2014 3:31 pm
Posts: 578
BigEd wrote:
But you'd have to ask why do this on a 6502...

Not on the 6502 forum!

Having this be a demonstration project greatly increases your range of options. There's a project called the worst Linux PC ever: http://hackaday.com/2012/03/28/building ... x-pc-ever/

It boots Linux on an AVR running an ARM emulator attached to external memory. If someone can shoehorn Linux on an eight bit microcontroller then Python on a 6502 should be possible.


Top
 Profile  
Reply with quote  
 Post subject: Re: python for 6502?
PostPosted: Sat Aug 01, 2015 1:27 am 
Online
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8534
Location: Southern California
Martin_H wrote:
There's a project called the worst Linux PC ever: http://hackaday.com/2012/03/28/building ... x-pc-ever/

That's hilarious. Its performance is undoubtedly even worse than what I know I'd get if I emulated the 65Org32 on an 8-bit microcontroller.

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Top
 Profile  
Reply with quote  
 Post subject: Re: python for 6502?
PostPosted: Sat Aug 01, 2015 7:09 am 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10971
Location: England
Martin_H wrote:
BigEd wrote:
But you'd have to ask why do this on a 6502...

Not on the 6502 forum!

Having this be a demonstration project greatly increases your range of options.

Agreed!


Top
 Profile  
Reply with quote  
 Post subject: Re: python for 6502?
PostPosted: Sat Aug 22, 2015 7:01 pm 
Offline
User avatar

Joined: Tue Nov 16, 2010 8:00 am
Posts: 2353
Location: Gouda, The Netherlands
If you want a scripting language on 6502, maybe start with Lua instead.


Top
 Profile  
Reply with quote  
 Post subject: Re: python for 6502?
PostPosted: Sun Jul 24, 2022 11:09 pm 
Offline

Joined: Mon Oct 12, 2015 5:19 pm
Posts: 255
Why?

Because of fools like me.

I am the kind of guy who gets thistles in his garden, or moles, or whatever, and looks around in his shed to see he has none of the proper tools. But a can of gas. And a lighter. This has potential. But how to not burn down the entire property? Aha! A garden hose. I envision a solution.

So, having made a reasonable beta-test "Technopoly / 6502-opoly" game, I am thinking of ways to perfect it.

In keeping with open source and FOSS, and GPL GNU/Linux etc principles, and the original game of Lizzie Magie (not to mention the 1970s guy who fought Parker brothers in Court; or the circa 1990s Microsoft employee who made a "anti-monoply", technopoly game, too), I have decided the plan of the physical game should be open and free. Completely.

Plus I prattled on and bragged about it here for about a decade now. It would be hard to keep it a secret.

But I recently (in the last 4 or 5 years) noticed there are SBCs (Single Board Computers) for sale at WDC. Cheap and / or reasonable.

I should design a board into each of my boards. No reason for a board game to be boring. Lets put the 'tech" in technopoly!

But, in addition to plopping an SBC in the middle of the physical board; I am interested in commericalization of a fully computertized version of the game (s). The design of my game has 352 IPS (intellectual properties) instead of 22 physical properties. Its more like real life. Too many things out there to monopolize them all!!! And a hassle to keep the cards organized and hand them back and forth. Computer "windows" and a computer game, makes more sense for such complexity (no "clean up time afterwards! OR annoying time to "set up" a new game, from the last set of people who didnt put everything away properly; or lost the pieces!)

So, thus, my gasoline and garden hose analogy. I can't code. Barely an assembly language / machine language guy. Putting together my "Ben Eater" 6502 kit, right now. But I cobbled together two or three python (pygames "plugins" or "libraries") "monopoly" snippets of code, from on-line, and academic sources, and have a reasonably functional board, with pieces that go around and land on squares.

Pretty neat for a guy who is competent in 0.5 high level languages.

So. It probably runs on a raspberry pi. I have pi zeros. I think I ran it there once? But right now just coding on a Windows 10. Some editor. Notepad ++ maybe?

But I think my system is glitchy there? So I shuffle the files over on a flash drive to run on my Linux computer instead. (Both windows and linux computers are Dell latitudes; 6420 and 6520). A sturdy, no frills machine. Both of them. I think.

I should github the whole thing. In case I have to move this year. Which I might have to.

Or at least start posting some files of the pieces and boards on this forum somewhere. And the intial rules. While I beta test.

But anyhoo. garden hose. gasoline. I see a job that needs doin, and I get innovative with tools I have no business using.

But python on 6502? I like the idea. In case its the only language I ever learn.

But if I can get the physical game working, and a good python version of the game, too, next step is to try to write an android version.

Upload to an app store.

Make a BO-Zillion dollars !!!!!

But first? Make a playable game, that is fun.

Oh yeah? My Byte Dice !!!! I lost them in Vermont !!!! Now that I have landed in Vancouver, and I have some spade bits... I should find some extra wood and some pennies. But Canada outlawed the penny!!! I'll have to use Nickels !!!!

Inflation.

You just can't get good byte dice for 8 cents + sweat and electrons anymore. 5 * 8 = 40 cents Canadian. or 30 cents Uh?Murican ...


Top
 Profile  
Reply with quote  
 Post subject: Re: python for 6502?
PostPosted: Mon Jul 25, 2022 12:44 am 
Offline

Joined: Tue Feb 21, 2017 8:32 pm
Posts: 38
I think its a neat idea. Not sure how useable it would be just due to sheer limited resources. You may find yourself out of memory pretty quickly.

After I made a CC65 target for my SBC a couple of people on discord made a comment about how the compiled code is bulky and slower than ASM. I mean, of course it is. But that's often the trade off of a higher level language. Quicker development -> bulkier slower code. I was able to whip up a game of snakes in 20 minutes in C, that ran at full speed and was under 6k in size. If I wrote it in ASM would it of been faster? Yes. Would it of been smaller? Yes. Would of it of taken me a lot longer... ...yes.

I'm relatively new to 6502 but I've been programming in multiple languages for years, it always irks me when someone complains that Language A is better than Language B. It's relatively objective if the language you use, fits your design criteria and runs your application within spec.


Top
 Profile  
Reply with quote  
 Post subject: Re: python for 6502?
PostPosted: Mon Jul 25, 2022 1:19 am 
Online
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8534
Location: Southern California
ChaseHQ85 wrote:
it always irks me when someone complains that Language A is better than Language B. It's relatively objective if the language you use, fits your design criteria and runs your application within spec.

One language is better than another. But which language is best for you depends on several factors, including how your particular brain works, which may be different from how the next guy's does.

Quote:
If I wrote it in ASM would it of been faster? Yes. Would it of been smaller? Yes. Would of it of taken me a lot longer... ...yes.

Assembly language can be faster to develop than most people think though, by making good use of macros including for nestable program flow control structures to make it a lot more clear what you're doing and eliminate the spaghetti. Mine has very few labels.

I'd be interested to hear why Python requires so much memory (to satisfy my mild interest without researching it myself when I have too many other projects in front of it. :lol: )

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Top
 Profile  
Reply with quote  
 Post subject: Re: python for 6502?
PostPosted: Mon Jul 25, 2022 1:23 am 
Offline

Joined: Sat Feb 19, 2022 10:14 pm
Posts: 147
I looked into Python for the 6502 before settling on Forth for my system. The options that BigEd listed are the ones I found in my search. The power of Python is in its multitude of libraries. It'll hard to replicate that for the 6502. I like a challenge but that is a steep hill to climb.


Top
 Profile  
Reply with quote  
 Post subject: Re: python for 6502?
PostPosted: Mon Jul 25, 2022 9:21 am 
Offline

Joined: Thu Mar 12, 2020 10:04 pm
Posts: 704
Location: North Tejas
GARTHWILSON wrote:
I'd be interested to hear why Python requires so much memory (to satisfy my mild interest without researching it myself when I have too many other projects in front of it. :lol: )

Python implementations are big because the language is interpreted. The interpreter includes all of the features of the language whether they are used or not.


Top
 Profile  
Reply with quote  
 Post subject: Re: python for 6502?
PostPosted: Mon Jul 25, 2022 9:26 am 
Offline

Joined: Thu Mar 12, 2020 10:04 pm
Posts: 704
Location: North Tejas
Many trips around the sun ago, I joined a makerspace where I experimented with the Arduino and began to learn Python. I thought Arduino is popular and Python is popular. Why can't we program an Arduino in Python?"

I set out to implement a Python compiler. Yes, a compiler. By not requiring an interpreter implementing the entire language, we have a fighting chance to get some programs to run on the microcontroller of the Arduino.

Initially, I had concerns around the 2K bytes of RAM in the Arduino. Because a Commodore 128 was on display at the makerspace available for me to use, I chose the 6502 as the initial target.

The list of features currently implemented:

Dynamic typing
Types: integer, string, True, False, function (partial)
Automatic memory management (using reference counting)
Variable precision integers
Integer operators +, -, *, //, %, &, ^, |, <<, >>
Variable length strings
String operators +, *
Relational operators ==, !=, <, <=, >, >=
if else elif
while else break continue
print function, including sep and end keyword arguments
input function
hardware access functions: peek, poke
randint function
int function
hex, oct and bin functions
str function
exception handling
find method for string type

The negative is that it is a cross compiler running on a PC clone. You cannot interactively write a program on a 6502.


Top
 Profile  
Reply with quote  
 Post subject: Re: python for 6502?
PostPosted: Mon Jul 25, 2022 9:55 am 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10971
Location: England
That's an impressive list of features!


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 17 posts ]  Go to page 1, 2  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 8 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: