6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Fri Sep 20, 2024 4:11 am

All times are UTC




Post new topic Reply to topic  [ 8 posts ] 
Author Message
PostPosted: Tue Aug 25, 2020 2:51 pm 
Offline

Joined: Tue Jul 07, 2020 10:35 am
Posts: 40
Location: Amsterdam, NL
Is there an open-source, super lightweight WDC 65C02 assembler? My needs are somewhat strange: I can't run it as a standalone binary, I need to be able to simply include it as a static lib as part of another project. Due to this, I'm guessing that an open-source version can be adapted in this way. Other than that, anything in the C family should work: C, C++, hell even Objective-C. Any ideas?


Top
 Profile  
Reply with quote  
PostPosted: Tue Aug 25, 2020 3:57 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10938
Location: England
Hmm, can't think of anything. Assemblers are usually self contained and operate file to file.
There are many listed in the reference section:
http://6502.org/tools/asm/

What does an assembler library look like to you? Does it take a massive text blob and produce a large binary blob? Or is it some kind of line-by-line mini-assembler, with barely a symbol table?


Top
 Profile  
Reply with quote  
PostPosted: Wed Aug 26, 2020 5:05 am 
Offline

Joined: Sun Nov 08, 2009 1:56 am
Posts: 395
Location: Minnesota
Aw, Ed - what about the assembler included in your beloved Beeb's BASIC? It's possible he's thinking along those lines!


Top
 Profile  
Reply with quote  
PostPosted: Wed Aug 26, 2020 6:38 am 
Offline

Joined: Tue Jul 07, 2020 10:35 am
Posts: 40
Location: Amsterdam, NL
A giant text blob would be ideal. It can operate on files if necessary, it just would be a library rather than a forked, standalone process.


Top
 Profile  
Reply with quote  
PostPosted: Wed Aug 26, 2020 7:03 am 
Offline
User avatar

Joined: Sat Dec 01, 2018 1:53 pm
Posts: 727
Location: Tokyo, Japan
It looks as if ca65 from the cc65 suite would do what you need. The input abstraction is a CharSource with a simple set of functions:
Code:
struct CharSourceFunctions {
    void (*MarkStart) (CharSource*);    /* Mark the start pos of a token */
    void (*NextChar) (CharSource*);     /* Read next char from input */
    void (*Done) (CharSource*);         /* Close input source */
};

So basically you'd need to write a driver for this that sets that up and calls the assembler, similar to how it's done in main():
Code:
    /* Initialize the scanner, open the input file */
    InitScanner (InFile);

    /* Define the default options */
    SetOptions ();

    /* Assemble the input */
    Assemble ();

(If you follow down through InitScanner you'll see how it sets up the CharSource.) Then you just link your driver against those files and you should be set!

_________________
Curt J. Sampson - github.com/0cjs


Top
 Profile  
Reply with quote  
PostPosted: Wed Aug 26, 2020 7:13 am 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10938
Location: England
Good find Curt!

Indeed, using the 16k ROM of BBC Basic would be a way, perhaps with lib6502 to emulate it. A 64k-sized emulation of a 6502 machine running a Basic interpreter isn't all that large in terms of modern software - that's not a point which naturally occurs to me! Lib6502 is written to be an emulation library, and is plain C and freely reusable.
https://www.piumarta.com/software/lib6502/

An emulation library isn't quite the same as an assembler library, so Curt's answer is surely the better approach.


Top
 Profile  
Reply with quote  
PostPosted: Thu Sep 03, 2020 11:16 am 
Offline

Joined: Tue Jul 07, 2020 10:35 am
Posts: 40
Location: Amsterdam, NL
Yes I don't need an emulation library, I built my own (though I did refer to lib6502 often in my implementation) I just need an in-process assembler. Looking at ca65 but I haven't done C in quite awhile and it's taking me a bit of time adapting it. Thank you for suggestions, though! Will update with progress at some point, I hope.


Top
 Profile  
Reply with quote  
PostPosted: Wed Oct 07, 2020 4:29 pm 
Offline

Joined: Thu Feb 10, 2011 3:14 am
Posts: 79
I wrote a fairly simple assembler (no macros) as part of the C02 project. Right now it reads and writes to files, but it should be simple enough to adapt it to use text and binary blobs. The files are a02.c and a02.h at https://github.com/RevCurtisP/C02.


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 26 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: