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

All times are UTC




Post new topic Reply to topic  [ 36 posts ]  Go to page 1, 2, 3  Next
Author Message
PostPosted: Mon Mar 25, 2019 3:01 am 
Offline

Joined: Fri Jan 25, 2019 5:40 am
Posts: 346
Location: Knoxville, TN
Hello all, I'd like to present to you a project I've been working on for about a week now, and I believe it is finally ready for first usage testing.

It's called BSFOTA: Backspace Sixty Five O Two Assembler.

I built this assembler out of frustration trying to use other ones that are available, since most do not work on modern operating systems or have quirks that make them odd to use. The ultimate goals of this program are:

-Portability
-Compatibility
-No nonsense
-Ease of use

The assembler, as it presently stands, is fairly lenient on most syntax when it comes to math and numbers, although there are still "quirks" to the design that I will be working out as I go, to fulfill the "No nonsense" goal of the design. The program comes with a man page accessed by -man that has information on most of the quirks, but I'll list a few here (one of which I know isn't in that file explicitly)

First, the one not included in the file. I did not support octal notation yet, but it's very easy to add, and is the next thing I'm working on
INA must be used for incrementing A, other syntaxes are not allowed. This is to allow A to be used as a var name, in macros for instance.
Not many directives are supported yet, although the necessary ones are, they are: .ORG .x8 .x16 .m8 .m16
There is no "follow along" support yet for managing data widths for immediate and indexed data. This was planned from the beginning, and a system is in place to keep track of P, but it is not being used presently, since it can get rather messy in certain scenarios. It will be added as an optional feature later, I wanted something that was offered the user full control over what gets laid out and when.
Advanced Macro support is not implemented yet. By this I mean "IF, UNTIL, REPEAT, etc". However, conditional compilation by using IFMA keyword is implemented and available for use.

There are a few other quirks but you can read the man page for all of them. On to some of the design.

The program is written in Java, targeting Java SE 8, which is currently the standard LTS release, Java 11 is the next LTS, and it should be compatible with 11 as well.
The jar binaries I will be releasing are executable, no need to point java to the class it needs to start at. Simply open a command window, and type "java -jar <name-of-jar>" in the same folder as where the jar is located. If java is not in your PATH on windows you may need to get it. The program should run fine on either x86 or x86_64 java. It should probably run fine on OpenJDK as well, and any ARM revisions of java out there.
The program was built to mimic many Linux programs as far as switch design. -i is for input file, -o is for output file, and other switches are as short as possible while being unique to what they do. Running the program without any arguments will show the help page, or -h can be used to get to the help page. -man can be used to get to the manual page (which needs expanding).
The project is released under GPL v2, it is FOSS and I plan to keep it that way. I forsee this assembler as being the assembler for the future, where others may die off or become incompatible, this one should remain compatible for many years to come, and if it becomes incompatible, the source is available and can be modified to make it compatible.

This is the first assembler I've built for a real processor. I've built assemblers for some custom scripting languages that worked off opcodes and operands before, but this is definitely still new to me. Because of this, I urge caution on using it, you should verify the code it outputs against a known working assembler, and please let me know if it is making errors.

You can find the git repo here I've added wiki and issue tracking to the repo so the community can help improve this project.

Please feel free to give any suggestions for changes or features or anything really. This is a passion project for me, and I really do want it to be as useful as possible.

I'll use this thread as the main discussion area for this, and I will attempt to post any updates here as well.


Top
 Profile  
Reply with quote  
PostPosted: Mon Mar 25, 2019 3:21 am 
Offline

Joined: Fri Jan 25, 2019 5:40 am
Posts: 346
Location: Knoxville, TN
New version 0.0.2

Octal notation numbers are now supported format is o123 or 123O (case insensitive)


Top
 Profile  
Reply with quote  
PostPosted: Mon Mar 25, 2019 4:00 am 
Offline

Joined: Sat Dec 13, 2003 3:37 pm
Posts: 1004
backspace119 wrote:
I built this assembler out of frustration trying to use other ones that are available, since most do not work on modern operating systems or have quirks that make them odd to use.


ca65, part of the cc65, is pretty robust and portable. It's just plain C, and compiles in seconds at least on Mac and Linux boxes (at least the assembler does, the litany of support files take longer). It has Windows executable, but it you could build and run under Cygwin, or the Window Unix user land that they have now.

I wrote my own assembler as well, in Java, but ca65 is much more capable, and not quirky. The fact that it supports a full development suite of tools, notably object modules, a linker, and a librarian, makes it even better.

The hard part about ca65 is getting your memory layout figured out, and folks here can help with that.


Top
 Profile  
Reply with quote  
PostPosted: Mon Mar 25, 2019 4:53 am 
Offline

Joined: Fri Jan 25, 2019 5:40 am
Posts: 346
Location: Knoxville, TN
whartung wrote:
backspace119 wrote:
I built this assembler out of frustration trying to use other ones that are available, since most do not work on modern operating systems or have quirks that make them odd to use.


ca65, part of the cc65, is pretty robust and portable. It's just plain C, and compiles in seconds at least on Mac and Linux boxes (at least the assembler does, the litany of support files take longer). It has Windows executable, but it you could build and run under Cygwin, or the Window Unix user land that they have now.

I wrote my own assembler as well, in Java, but ca65 is much more capable, and not quirky. The fact that it supports a full development suite of tools, notably object modules, a linker, and a librarian, makes it even better.

The hard part about ca65 is getting your memory layout figured out, and folks here can help with that.


Thanks, I had heard some mention of this but I hadn't fully looked into it yet, as I was wanting to work from the ground up, starting with assembly then getting into languages like C and FORTH. My project might not present anything useful to the community, but at the very least it has provided a good base of understanding of 65xx assembly for me.

I'll definitely take a look at ca65 soon to get into more complex programs.

EDIT: I see that ca65 supports straight assembly too....not sure why I didn't find this listed on the page about assemblers, or maybe I over looked it. I sorted them by searching for 65816 or 65c816 to only get the ones that were capable of assembling for this cpu. At any rate, I'm still having a lot of fun with making this, but maybe it's more something that's only useful as a learning experience to me.


Top
 Profile  
Reply with quote  
PostPosted: Mon Mar 25, 2019 8:09 am 
Offline
User avatar

Joined: Wed Feb 14, 2018 2:33 pm
Posts: 1466
Location: Scotland
backspace119 wrote:
EDIT: I see that ca65 supports straight assembly too....not sure why I didn't find this listed on the page about assemblers, or maybe I over looked it. I sorted them by searching for 65816 or 65c816 to only get the ones that were capable of assembling for this cpu. At any rate, I'm still having a lot of fun with making this, but maybe it's more something that's only useful as a learning experience to me.


Make sure you're looking at the correct page for the cc65 suite - Original development was taken over some years back and moved off https://www.cc65.org/ and onto a Github page at https://cc65.github.io/
I inadvertently got the older one originally - which worked well, except for an obscure Sweet16 operation.

-Gordon

_________________
--
Gordon Henderson.
See my Ruby 6502 and 65816 SBC projects here: https://projects.drogon.net/ruby/


Top
 Profile  
Reply with quote  
PostPosted: Mon Mar 25, 2019 9:27 am 
Offline
User avatar

Joined: Tue Mar 02, 2004 8:55 am
Posts: 996
Location: Berkshire, UK
Typo in Assembler.java line 19 'OCATL_PATTERN'.

Checking for direct page addresses with expressions like ...
Code:
            if(replaceHex(line) > 0xFF)
            {
                return standard2(0x84,line);
            }else {
                return standard3(0x8C,line);
            }

... doesn't really work for the '816 as the direct page does not have to be at $0000.

My Java based cross platform relocating macro assembler is here https://github.com/andrew-jacobs/dev65

_________________
Andrew Jacobs
6502 & PIC Stuff - http://www.obelisk.me.uk/
Cross-Platform 6502/65C02/65816 Macro Assembler - http://www.obelisk.me.uk/dev65/
Open Source Projects - https://github.com/andrew-jacobs


Top
 Profile  
Reply with quote  
PostPosted: Mon Mar 25, 2019 11:47 am 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10938
Location: England
Great project - thanks for open-sourcing it!

Because the '816 is so stateful, it's probably best to have both
- directives to say what the state is (or should be!)
- heuristics to follow state changes

As for adding octal - is binary already in there?


Top
 Profile  
Reply with quote  
PostPosted: Mon Mar 25, 2019 11:51 am 
Offline

Joined: Fri Jan 25, 2019 5:40 am
Posts: 346
Location: Knoxville, TN
BitWise wrote:
Typo in Assembler.java line 19 'OCATL_PATTERN'.

Checking for direct page addresses with expressions like ...
Code:
            if(replaceHex(line) > 0xFF)
            {
                return standard2(0x84,line);
            }else {
                return standard3(0x8C,line);
            }

... doesn't really work for the '816 as the direct page does not have to be at $0000.

My Java based cross platform relocating macro assembler is here https://github.com/andrew-jacobs/dev65


I'm actually checking for direct addressing mode, I was following the syntax found here

If it's definitely wrong than I can look further into it, but I actually came back here to report that I've run a few programs assembled from it and it seems to work quite well. (I've not released my latest code yet, there's a few extras that are still very much WIP, such as the serial link to an arduino programmer I built in when using the -w switch)

I'm going to try out some more complex programs with it, and see how it does, but I just got the emulation light to dim with this program compiled through my assembler:

Code:
.m8
.x8
ST:
SEI
CLC
XCE
LDA #$FF
STA $00
LDA #$00
LOOP:
INA
CMP $00
BEQ CONT
BRA LOOP
CONT:
SEC
XCE
LDA #$00
L2:
INA
CMP $00
BEQ RET
BRA L2
RET:
BRA ST


I realized I needed the x8 and m8 because I've not initialized those values in the P register in the assembler to 1, which I'm about to do so x8 and m8 won't be required at the beginning of every program.


Top
 Profile  
Reply with quote  
PostPosted: Mon Mar 25, 2019 11:52 am 
Offline

Joined: Fri Jan 25, 2019 5:40 am
Posts: 346
Location: Knoxville, TN
BigEd wrote:
Great project - thanks for open-sourcing it!

Because the '816 is so stateful, it's probably best to have both
- directives to say what the state is (or should be!)
- heuristics to follow state changes

As for adding octal - is binary already in there?


Yes, binary is in there, and I got octal added as of 0.0.2.

Thanks for the compliment, and I wouldn't dream of not open sourcing something like this, this is a really cool hobby and the easier it is for people to get into, the better.

EDIT:
about your other points that I forgot to address

I'm working on a follow along heuristics system, and I'm also working on more directives, presently, only the ones listed exist though.


Top
 Profile  
Reply with quote  
PostPosted: Mon Mar 25, 2019 11:56 am 
Offline

Joined: Fri Jan 25, 2019 5:40 am
Posts: 346
Location: Knoxville, TN
drogon wrote:
backspace119 wrote:
EDIT: I see that ca65 supports straight assembly too....not sure why I didn't find this listed on the page about assemblers, or maybe I over looked it. I sorted them by searching for 65816 or 65c816 to only get the ones that were capable of assembling for this cpu. At any rate, I'm still having a lot of fun with making this, but maybe it's more something that's only useful as a learning experience to me.


Make sure you're looking at the correct page for the cc65 suite - Original development was taken over some years back and moved off https://www.cc65.org/ and onto a Github page at https://cc65.github.io/
I inadvertently got the older one originally - which worked well, except for an obscure Sweet16 operation.

-Gordon


I think I found the right one, but it seems the documentation for full usage of it is a bit dense. I'm definitely going to look into using it when I move to C, but for right now my assembler is simpler, it's one program that does it all, and I'm learning a lot by building it.


Top
 Profile  
Reply with quote  
PostPosted: Mon Mar 25, 2019 12:15 pm 
Offline

Joined: Fri Jan 25, 2019 5:40 am
Posts: 346
Location: Knoxville, TN
And I just found out why certain programs weren't working.

I made a dumb mistake and was treating JSR like BRL, with relative addressing.

Now that that's fixed, my emulation mode light blinks with this program compiled with my assembler:

Code:
.m8
.x8
ST:
SEI
CLC
XCE
JSR WASTETIME
SEC
XCE
JSR WASTETIME
BRA ST
WASTETIME:
LDA #$FF
STA $00
LDA #$00
STA $01
LOOP:
INA
CMP $00
BEQ NXT
BRA LOOP
NXT:
INC $01
CMP $01
BEQ RET
BRA LOOP
RET:
RTS


To give you a sample of the side by side output, here's what it generated:

Code:


ST
C000 78      SEI
C001 18      CLC
C002 FB      XCE
C003 200DC0      JSR WASTETIME
C006 38      SEC
C007 FB      XCE
C008 200DC0      JSR WASTETIME
C00B 80F3      BRA ST
WASTETIME
C00D A9FF      LDA #255
C00F 8500      STA 0
C011 A900      LDA #0
C013 8501      STA 1
LOOP
C015 1A      INA
C016 C500      CMP 0
C018 F002      BEQ NXT
C01A 80F9      BRA LOOP
NXT
C01C E601      INC 1
C01E C501      CMP 1
C020 F002      BEQ RET
C022 80F1      BRA LOOP
RET
C024 60      RTS


EDIT: unfortunately a limitation of side by side output currently is that it outputs lines with numbers parsed to decimal, and it also gets rid of a few things. I'm working on getting it to be a true side by side.


Top
 Profile  
Reply with quote  
PostPosted: Mon Mar 25, 2019 1:11 pm 
Offline

Joined: Fri Jan 25, 2019 5:40 am
Posts: 346
Location: Knoxville, TN
I have now successfully run a sort of complicated program through it, found out the reason it wasn't working was I mixed up 8D and 8F (STA abs and STA long). I'm so close to having this do something cool, I can feel it.

EDIT: sort of wrong thread, but related to my assembler, so w/e


Top
 Profile  
Reply with quote  
PostPosted: Mon Mar 25, 2019 4:21 pm 
Offline
User avatar

Joined: Tue Mar 02, 2004 8:55 am
Posts: 996
Location: Berkshire, UK
backspace119 wrote:
I'm actually checking for direct addressing mode, I was following the syntax found here


On the '816 the direct page is can start at any address in bank 0 so you can have code like this ...
Code:
                             ; These routines expect the caller to have set $DF00 as the direct page address
                             ; so that direct-page instructions are used to access hardware registers.
                             
         00000020          = SPI_SCK         .equ    1<<5
         00000040          = SPI_MOSI        .equ    1<<6
         00000080          = SPI_MISO        .equ    1<<7
                             
                                             .dpage  $df00
                             
                                             .longa  ?
                                             .longi  ?
                             SpiInit:
00:F177  08                :                 php
                                             short_a
                           +                 .longa  off
00:F178  E220              +                 sep     #$20            ; Make A register 8-bit
00:F17A  A920              :                 lda     #SPI_SCK        ; Set SCK as lo output
00:F17C  0424              :                 tsb     PDD4
00:F17E  1420              :                 trb     PD4
00:F180  A940              :                 lda     #SPI_MOSI       ; Set MOSI as an output
00:F182  0424              :                 tsb     PDD4
00:F184  A980              :                 lda     #SPI_MISO       ; Set MISO as an input
00:F186  1424              :                 trb     PDD4
00:F188  28                :                 plp
00:F189  60                :                 rts

.. where the hardware registers PDD4 (at $DF24) and PD4 (at $DF20) can be accessed with direct page instructions as they are here.

_________________
Andrew Jacobs
6502 & PIC Stuff - http://www.obelisk.me.uk/
Cross-Platform 6502/65C02/65816 Macro Assembler - http://www.obelisk.me.uk/dev65/
Open Source Projects - https://github.com/andrew-jacobs


Top
 Profile  
Reply with quote  
PostPosted: Mon Mar 25, 2019 4:41 pm 
Offline

Joined: Sat Dec 13, 2003 3:37 pm
Posts: 1004
BitWise wrote:
On the '816 the direct page is can start at any address in bank 0 so you can have code like this ...
Code:
                             ; These routines expect the caller to have set $DF00 as the direct page address
                             ; so that direct-page instructions are used to access hardware registers.
                             
         00000020          = SPI_SCK         .equ    1<<5
         00000040          = SPI_MOSI        .equ    1<<6
         00000080          = SPI_MISO        .equ    1<<7
                             
                                             .dpage  $df00

What, exactly, does that .dpage directive do? Notably, why does the assembler care where the Direct Page is located? What assumptions is it making?


Top
 Profile  
Reply with quote  
PostPosted: Mon Mar 25, 2019 6:23 pm 
Offline
User avatar

Joined: Tue Mar 02, 2004 8:55 am
Posts: 996
Location: Berkshire, UK
The .dpage directive tells the assembler where the application will set the direct page at execution time so it can determine if a direct page address can be used. By default the assembler assumes the direct page will be at $0000 as it is on the 6502 and 65C02.

_________________
Andrew Jacobs
6502 & PIC Stuff - http://www.obelisk.me.uk/
Cross-Platform 6502/65C02/65816 Macro Assembler - http://www.obelisk.me.uk/dev65/
Open Source Projects - https://github.com/andrew-jacobs


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

All times are UTC


Who is online

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