That seems like it makes the code very hard to follow. I don't even fully understand which jmp goes to which foo in your examplepubby wrote:You're never going to finish a NES game if you spend all your time making tools
With that said, I'd like it if all labels used the anonymous label +/- syntax. For example, if you have multiple labels with the same name, you can use +/- to distinguish them:
In other words, have labels and anonymous labels behave the same. Don't special case either.Code: Select all
jmp foo:+ foo: jmp foo:++ foo: foo: jmp foo:---
Writing my own assembler
Moderator: Moderators
Re: Writing my own assembler
- never-obsolete
- Posts: 411
- Joined: Wed Sep 07, 2005 9:55 am
- Location: Phoenix, AZ
- Contact:
Re: Writing my own assembler
I had a similar problem and ended up forking asm6 and adding RAM/ENDRAM (as well as WRAM/ENDWRAM/SRAM/ENDSRAM, since Mesen seems to differentiate) which is behaves just like ENUM/ENDE does. That way, anything defined with EQU, =, or in an ENUM is not exported to the label file.The problem with that is that all these extra labels will get exported to label files along with the ones that are actually relevant for debugging. Maybe the solution is not to change ENUM, but to take a cue from ca65 and implement two forms of assignment for symbols, one that marks the symbol as a label (:=) and one that doesn't (=).
Years ago I attempted my own assembler, and I took hints on the macro system from (I think) nesasm, where you could do something like this:
Code: Select all
MACRO addvtop
lda pos@0, X
clc
adc vel@0, X
sta @1
ENDM
...and then in code...
addvtop _x, t0
addvtop _y, t1
...which would resolve to...
lda pos_x, X
clc
adc vel_x, X
sta t0
lda pos_y, X
clc
adc vel_y, X
sta t1
edit:
The other thing you might consider supporting is reading in a rom file first, overwriting it with the code your assembler produces, and then writing that to the outfile. This is useful for rom hacking, and the only reason I still use my assembler from time to time.
Re: Writing my own assembler
I _love_ this. I always waste time on a project building a python script to handle converting text to whatever character mapping my game is using. Having that built-in to the assembler sounds great.tokumaru wrote: - CHARACTER MAPPING: Mapping characters to specific indices is important because we usually have few tiles to dedicate to text so we can't afford to be slaves of the ASCII encoding. The idea here is to use a directive to define an index, and then the character to put at that index. The reason to supply the parameters in this order is that after the index, you can supply multiple characters and strings, and the index will auto-increment to accommodate as many characters as necessary (e.g. CHARMAP $00, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", " .!?", $0D).
My games: http://www.bitethechili.com
Re: Writing my own assembler
For simpler projects, I understand how preprocessing text with a script in a scripting language might feel wasteful. But for bigger projects, it's anything but.gauauu wrote:I always waste time on a project building a python script to handle converting text to whatever character mapping my game is using.
In theory, an assembler could use this sort of mapping from multiple characters to one character to support UTF-8 input, where the multiple code units (that is, bytes) that represent a character get translated to a single code unit. It could also apply a dictionary, where commonly encountered groups of letters get translated into shorter groups. But it can't very easily calculate an appropriate dictionary given only a (suitably long) text. I have a preprocessor written in Python to do that; my NES and GB ports of 240p Test Suite and the next versions of Thwaite and the Action 53 menu all use a byte pair encoding (BPE)/digram tree encoding (DTE) engine that I originally wrote for my port of robotfindskitten.
A preprocessor also allows non-programmers, such as the translator you hired to prepare versions in other languages, to edit the text without breaking invariants that your program expects. And you'd need a pretty rich macro system to handle line breaking, pagination, stage directions for NPCs, hyperlinks for your dialogue tree, and other things that tend to get interleaved into your text. One "meant for consolidating repetitive assembly code, not for extending the functionality of the assembler" can't handle it alone.
- samophlange
- Posts: 50
- Joined: Sun Apr 08, 2018 11:45 pm
- Location: Southern California
Re: Writing my own assembler
FWIW - The people in my office that work in JS have switched our projects to using TypeScript. From what I understand it allows you to be more explicit about your intent when writing code, which enables much better compile time type checking. I have never done any real projects in JS, but every time I use it I think that it must be a nightmare to keep things clean on a large project, and I think TypeScript helps with that.
If you're taking feature requests....
Something I've been struggling with as I learn assembly is that I haven't found a "nice" way to do if/else, it seems like it just turns in to a mess of label soup. Maybe this could be smoothed over with some syntactic sugar?
If you're taking feature requests....
Something I've been struggling with as I learn assembly is that I haven't found a "nice" way to do if/else, it seems like it just turns in to a mess of label soup. Maybe this could be smoothed over with some syntactic sugar?
Re: Writing my own assembler
True.pubby wrote:You're never going to finish a NES game if you spend all your time making tools
I kinda like this idea! For anyone who thinks this is confusing, just don't use the feature.In other words, have labels and anonymous labels behave the same. Don't special case either.
That feels way too platform-specific to me, I'm trying to keep things as generic as possible.never-obsolete wrote:I had a similar problem and ended up forking asm6 and adding RAM/ENDRAM (as well as WRAM/ENDWRAM/SRAM/ENDSRAM
You know, NESASM gets a bad rap around these parts, but it actually has some very interesting features that are often overlooked. Too bad it has some quirks that make it unusable to me.Years ago I attempted my own assembler, and I took hints on the macro system from (I think) nesasm
This is an interesting feature, and not hard to implement at all. Maybe an INCBIN that doesn't update the PC is all it takes.The other thing you might consider supporting is reading in a rom file first, overwriting it with the code your assembler produces, and then writing that to the outfile. This is useful for rom hacking, and the only reason I still use my assembler from time to time.
Unless they're really simple to implement or seem really useful to me, no, I'm not!samophlange wrote:If you're taking feature requests....
One of the reasons I like assembly so much is that it isn't bound to the constructs of high-level languages. You can jump anywhere you want, take shortcuts, bypass instructions by making them look like operands, all sorts of convenient little things to get get that extra power from these limited pieces of hardware we write code for. So for me particularly, simulating high-level constructs isn't appealing at all. I'm pretty sure this can be done with macros in most assemblers, though.Something I've been struggling with as I learn assembly is that I haven't found a "nice" way to do if/else, it seems like it just turns in to a mess of label soup. Maybe this could be smoothed over with some syntactic sugar?
-
- Posts: 1565
- Joined: Tue Feb 07, 2017 2:03 am
Re: Writing my own assembler
Seeing as people use JS for so much I had assumed it had evolved enough to be practical, but I see that is mostly incompetent still and you need CS extensions or node or insert a bunch of others to get stuff done. I was thinking one could just write JS and you could use cscript to run neat JS, and then linux/mac could use node if need be or some other js engine. Seems you can't.tepples wrote:Last I checked, cscript.exe was exclusive to Microsoft Windows. I don't run Windows on my primary dev machine; nor does calima. Are there tips for writing a script to make it work on both cscript.exe (for users of Windows) and Node.js (for users of GNU/Linux and macOS)?Oziphantom wrote:cscript.exe will run JS as well without most people having to install something is all.tokumaru wrote:I'm only using Node to run the .js file locally as a command line application
Basically any assembler can do this, TASS64 for example does it.never-obsolete wrote:The other thing you might consider supporting is reading in a rom file first, overwriting it with the code your assembler produces, and then writing that to the outfile. This is useful for rom hacking, and the only reason I still use my assembler from time to time.
Code: Select all
*=$0801
.binary "original.bin"
*=$1000
<patch code goes here>
*=$1800
.byte $2c ; skip command here
You might want to try the https://github.com/Museum-of-Art-and-Di ... nt/macross assembler its the assembler for people who don't like assembly. You can't really do IF ELSE in an assembler as that is a structure system, so at some point it has to know where to jump to, to skip the "else" which is not something assemblers really do, it needs a label. However I would think if one tried you could get it to work with Macros in TASS64, but maybe not with nesting....samophlange wrote:Something I've been struggling with as I learn assembly is that I haven't found a "nice" way to do if/else, it seems like it just turns in to a mess of label soup. Maybe this could be smoothed over with some syntactic sugar?
Re: Writing my own assembler
This is hardly anything new, I use this feature in WLA-DX and other assemblers probably already have it.gauauu wrote:I _love_ this. I always waste time on a project building a python script to handle converting text to whatever character mapping my game is using. Having that built-in to the assembler sounds great.tokumaru wrote: - CHARACTER MAPPING: Mapping characters to specific indices is important because we usually have few tiles to dedicate to text so we can't afford to be slaves of the ASCII encoding. The idea here is to use a directive to define an index, and then the character to put at that index. The reason to supply the parameters in this order is that after the index, you can supply multiple characters and strings, and the index will auto-increment to accommodate as many characters as necessary (e.g. CHARMAP $00, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", " .!?", $0D).
Re: Writing my own assembler
ca65 and cc65 support remapping also, although not in the condensed format above. See the .charmap pseudo-op and #pragma charmap
-
- Posts: 1565
- Joined: Tue Feb 07, 2017 2:03 am
Re: Writing my own assembler
The problem with WLA-DX is it only lets you have one definition.. sub par.Bregalad wrote:This is hardly anything new, I use this feature in WLA-DX and other assemblers probably already have it.gauauu wrote:I _love_ this. I always waste time on a project building a python script to handle converting text to whatever character mapping my game is using. Having that built-in to the assembler sounds great.tokumaru wrote: - CHARACTER MAPPING: Mapping characters to specific indices is important because we usually have few tiles to dedicate to text so we can't afford to be slaves of the ASCII encoding. The idea here is to use a directive to define an index, and then the character to put at that index. The reason to supply the parameters in this order is that after the index, you can supply multiple characters and strings, and the index will auto-increment to accommodate as many characters as necessary (e.g. CHARMAP $00, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", " .!?", $0D).
- cpow
- NESICIDE developer
- Posts: 1097
- Joined: Mon Oct 13, 2008 7:55 pm
- Location: Minneapolis, MN
- Contact:
Re: Writing my own assembler
I'll drink to that.pubby wrote:You're never going to finish a NES game if you spend all your time making tools
Now back to my tools...
Re: Writing my own assembler
The Wikipedia article on lexical analysis seemed helpful when I started writing an assembler.
Also, it would be nice if the assembler supported the bit shift operators in expressions. (Ophis seems to lack them, perhaps because the characters "<" and ">" have other uses.)
Edit: removed a feature request
Also, it would be nice if the assembler supported the bit shift operators in expressions. (Ophis seems to lack them, perhaps because the characters "<" and ">" have other uses.)
Edit: removed a feature request
- cpow
- NESICIDE developer
- Posts: 1097
- Joined: Mon Oct 13, 2008 7:55 pm
- Location: Minneapolis, MN
- Contact:
Re: Writing my own assembler
Back in the days when I rolled my own assembler for NESICIDE I used Lex/Yacc. Looking back on it, it was so much fun I might try to replicate the experience with ANTLR. I see ANTLR already has a contributed 6502 grammar file.qalle wrote:The Wikipedia article on lexical analysis seemed helpful when I started writing an assembler.
- cpow
- NESICIDE developer
- Posts: 1097
- Joined: Mon Oct 13, 2008 7:55 pm
- Location: Minneapolis, MN
- Contact:
Re: Writing my own assembler
I'll never understand the logic of "I can write a better parser from scratch than any of the parser generators available to me." Like any tool, a parser generator allows you to focus on the meat and potatoes, not the plate.yaros wrote:I still think it worth to hack around and write assembler without parser.
Re: Writing my own assembler
I don't plan on using any libraries right now besides the ones I'm required to in order to do basic tasks like interacting with the file system. I am taking a lot of shortcuts in this first moment though... For example, I'm not parsing expressions manually, I'm using JavaScript's eval() for this (don't judge me, this is for my personal use!), after using regular expressions to convert expressions like $8004 + <MyLabel into 0x8004 + executeFunction("<", getSymbol("MyLabel")). The functions "executeFunction" and "getSymbol" will be responsible for returning the correct values or throwing errors when appropriate.