6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sun Nov 24, 2024 5:32 pm

All times are UTC




Post new topic Reply to topic  [ 11 posts ] 
Author Message
PostPosted: Sun Sep 29, 2013 8:54 am 
Offline

Joined: Mon Jan 07, 2013 2:42 pm
Posts: 576
Location: Just outside Berlin, Germany
As one of the people using the Ophis assembler (https://github.com/michaelcmartin/Ophis), I'm stuck with lots of code that is written in a more "standard" syntax. So I've put together a small Python script to help me convert from one format to another: asm2ophis (included).

What it does is convert things like "ALIAS = NUMBER" to ".alias ALIAS NUMBER", add semicolons to labels, and justify comments the way I prefer them, etc. One of the biggest problems was converting "unmarked" inline comments -- remarks that don't start with a ";" such as in VTL2 -- to the Ophis syntax. It's only half-automatic, the end result needs to be edited by hand for a whole bunch of things, but it does relieve me of a lot of the time-consuming grunt work. What it does not do is include any of the more advanced Ophis features. As a Python program, it should run on any platform. I've tried to comment as much as I can.

So far, I've only used it with VTL 2.0 and FIG Forth, two of the large programs I hope to incorporate in the Übersquirrel. Anything else is bound to create new problems. A more serious version of this tool would have to first figure out which assembler format is being used first and then approach the whole problem appropriately, but for the moment, I'm getting by with this -- pardon my German -- half-assed script.

I've included a file with the raw output of processing the VTL02a2b source so people can get a feeling for what this can't or cannot do. Below is the listing of the problems asm2ophis spit out on the command line when this was generated. You'll notice a bunch of warnings about "inc" instructions -- there are so many variations even in the syntax of those two files I just ask the user to handle them ("inc", "inc a", "inc <alias>", "inc <address>"). This is true for lsr, asl, dec, and a few others.

There is a whole bunch of stuff that could be improved very quickly, but I'll be doing other things for the next couple of days and thought I'd offer what I had here in case somebody could use this. Of course, I'm grateful for suggestions and corrections.

Code:
Line 2: Error: Found unexpected dot-command .lf
Line 3: Error: Found unexpected dot-command .cr
Line 4: Error: Found unexpected dot-command .tf
Line 157: Error: Found unexpected dot-command .or
Line 163: Warning: Found '/', convert manually.
Line 167: Warning: Found '/', convert manually.
Line 270: Warning: Opcode 'dec' found, convert manually
Line 284: Warning: Opcode 'inc' found, convert manually
Line 286: Warning: Opcode 'inc' found, convert manually
Line 320: Warning: Opcode 'dec' found, convert manually
Line 321: Warning: Opcode 'dec' found, convert manually
Line 400: Warning: Opcode 'inc' found, convert manually
Line 401: Warning: Opcode 'inc' found, convert manually
Line 415: Warning: Opcode 'inc' found, convert manually
Line 480: Warning: Opcode 'rol' found, convert manually
Line 486: Warning: Opcode 'rol' found, convert manually
Line 570: Warning: Opcode 'dec' found, convert manually
Line 595: Warning: Opcode 'inc' found, convert manually
Line 604: Warning: Opcode 'inc' found, convert manually
Line 606: Warning: Opcode 'inc' found, convert manually
Line 661: Warning: Opcode 'lsr' found, convert manually
Line 663: Warning: Opcode 'ror' found, convert manually
Line 663: Warning: Found '/', convert manually.
Line 666: Warning: Opcode 'asl' found, convert manually
Line 668: Warning: Opcode 'rol' found, convert manually
Line 687: Warning: Opcode 'asl' found, convert manually
Line 689: Warning: Opcode 'rol' found, convert manually
Line 690: Warning: Opcode 'rol' found, convert manually
Line 691: Warning: Opcode 'rol' found, convert manually
Line 701: Warning: Opcode 'inc' found, convert manually
Line 702: Warning: Opcode 'dec' found, convert manually
Line 716: Warning: Opcode 'inc' found, convert manually
Line 724: Warning: Opcode 'inc' found, convert manually
Line 728: Warning: Opcode 'rol' found, convert manually
Line 747: Warning: Opcode 'asl' found, convert manually
Line 752: Warning: Opcode 'asl' found, convert manually
Line 753: Warning: Opcode 'rol' found, convert manually
Line 809: Warning: Found '/', convert manually.
Line 815: Warning: Opcode 'inc' found, convert manually
Line 838: Warning: Found '/', convert manually.
Line 850: Warning: Opcode 'inc' found, convert manually
Warning: File may contain unmarked comments (line 752 for instance).

Done. Wrote 870 lines.


Attachments:
vtl02-test.asm [24.95 KiB]
Downloaded 144 times
asm2ophis-b01.py.zip [7.18 KiB]
Downloaded 146 times
Top
 Profile  
Reply with quote  
PostPosted: Sun Sep 29, 2013 4:01 pm 
Offline
User avatar

Joined: Sun Jun 30, 2013 10:26 pm
Posts: 1951
Location: Sacramento, CA, USA
I feel slightly bad that I didn't use a more 'universal' source syntax for VTL02 ... I especially regret not placing
leading semi-colons on the end-of-line comments, as that would have eliminated >90% of the drudgery. I plan
to continue using San's cross-assembler, but I will be more considerate to others in future endeavors.

Thanks,

Mike


Top
 Profile  
Reply with quote  
PostPosted: Tue Oct 01, 2013 12:22 am 
Offline

Joined: Mon Jan 07, 2013 2:42 pm
Posts: 576
Location: Just outside Berlin, Germany
Nah, it's fine, I learned a lot doing this. VTL02 is so (amazingly) short I probably could have done this all by hand in the same time, but you know how it is. -- At some point, I'll actually get around to getting it running with my kernel (which isn't ready yet), and then will probably go through again to see about adapting it to the 65c02. Again, amazing little program.


Top
 Profile  
Reply with quote  
PostPosted: Wed Dec 04, 2013 4:21 pm 
Offline
User avatar

Joined: Sun Jun 30, 2013 10:26 pm
Posts: 1951
Location: Sacramento, CA, USA
scotws wrote:
... running with my kernel (which isn't ready yet), and then will probably go through again to see about adapting it to the 65c02...


Hello again, scotws ... [bump]

As someone who knows and uses the 'c02 (others welcome to comment as well), do you like and use the TRB and TSB instructions much? I see an immediate and frequent use for BRA, PHX, PHY, PLX, PLY, STZ, and a few others, but I'm not so sure about those two, probably because my brain is entrenched in '02 mode from years of habit.

The reason that I'm asking is that I have a couple of op-code slots left in my 65m32 map, and I want to know if I should stick a 32-bit version of those two in there, or leave those slots open for something else that might wind up being more important.

Thanks,

Mike


Top
 Profile  
Reply with quote  
PostPosted: Wed Dec 04, 2013 7:10 pm 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8514
Location: Midwestern USA
barrym95838 wrote:
As someone who knows and uses the 'c02 (others welcome to comment as well), do you like and use the TRB and TSB instructions much?

I use TRB and TSB in a lot of places.

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


Top
 Profile  
Reply with quote  
PostPosted: Wed Dec 04, 2013 7:37 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8546
Location: Southern California
I use them quite a bit in I/O.

_________________
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  
PostPosted: Thu Dec 05, 2013 10:48 pm 
Offline

Joined: Mon Jan 07, 2013 2:42 pm
Posts: 576
Location: Just outside Berlin, Germany
I actually don't think I have used them at all yet, for the reason you just mentioned: Not on the '02, so don't think that way yet. I keep meaning to sit down and work through a bunch of examples to get comfortable with them, and then go back and look at my code again.


Top
 Profile  
Reply with quote  
PostPosted: Thu Oct 31, 2019 11:28 pm 
Offline

Joined: Wed Jan 08, 2014 3:31 pm
Posts: 578
I just stumbled onto this thread.

I just re-purposed my Python TinyComp compiler's tokenizer to read 6502 assembler, and then pretty print it into the Ophis format. I haven't uploaded it to GitHub yet, but if there's interest I could upload it to my TinyComp repo.

As an aside I should probably back port the pretty print feature into TinyComp as that's kind of a useful feature.


Top
 Profile  
Reply with quote  
PostPosted: Fri Nov 01, 2019 6:18 am 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10986
Location: England
Please do share your code!


Top
 Profile  
Reply with quote  
PostPosted: Fri Nov 01, 2019 3:36 pm 
Offline

Joined: Wed Jan 08, 2014 3:31 pm
Posts: 578
OK I uploaded it to my FIG Forth Github repo: https://github.com/Martin-H1/FigForth

It contains the original FIG FORTH source, my finished port, and asm2oph.py which converted about 95% of the source. It couldn't handle the equate to .alias directive, ASL A to ASL, .org to .origin, and .advance. But after processing and a few passes with Ophis everything looked reasonable to me. The Makefile contains a target Fig6502_asm.oph which runs the command:

Code:
python asm2oph.py FIG6502.ASM > Fig6502_asm.oph


Top
 Profile  
Reply with quote  
PostPosted: Mon Nov 04, 2019 10:12 am 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10986
Location: England
Thanks!


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 11 posts ] 

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 32 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: