JSON parser written in 6502 assembly language
github.com
github.com
See this presentation, too: https://www.youtube.com/watch?v=R7EEoWg6Ekk
PHB: Bundle PowerPoint?! That's... genius! I can see a bright future for you here.
Dev: ...
Or test it rewritten for a KimKlone. (-:
* https://www.laughtonelectronics.com/Arcana/KimKlone/Kimklone...
So you would likely need custom/new hardware, but in terms of how, it's a solved problem.
The 8051 and Z80 fill similar roles today --- when even the cheapest ARM core is too expensive.
Not knocking JSON. Just thinking it wouldn’t be the right thing for this situation.
Seriously though, it's been a while since I've had to work with assembly or IDA but JSON is great as an interoperable data format. Sure, it's not maximally efficient, but what needs to be?
I'm guessing most things written for a 6502
Until it does, like with limited hardware.
After trying several other solutions I ended up with JSON over USB serial.
I tried several of the binary JSON-like variants, but they were all a PITA to port or ended up eating a lot of space, either in RAM or Flash or both. For this project I wasn't too concerned about message size or performance as such, as long as it could be read or generated in small portions.
I ended up adapting two JSON libraries, a one for parsing and for generating. The parser was SAX-like, so worked just fine for incremental parsing. Worked quite well, in total considerably smaller both in RAM and Flash than the alternatives.
A custom binary protocol would certainly be smaller but would take a lot more time to develop and debug.
This is a bit of a reach.
There is no world in which these and JSON appropriately intersect. If you’re parsing json then you’re probably dealing with enough need for sanitization that you have already fucked up if you’re at the point of an 8 bit MCU — how did the json get there in the first place?
The 6502 used to be a General purpose CPU, so for some retro hacking stuff that may be different.
As it happens, I'm coding on the 6502 for fun (demo maker :-)). And of course, I want to build my own super coll tools to help my development. However, I always come to the same conclusion : developping tools makes sense only if other people will use it (ie the effort I put in that must be amortized).
Now, if you say the 6502 is still a thing, then I may have some incentive to complete these tools...
It boggles the mind that we have a high quality JSON parser that supports this on such a constrained system, where many of the high-level language libraries that run on massively faster hardware don't.
edit: Forgot to explicitly clarify that it was ARM
Actually the 6502 designers really intended it more for control systems / embedded.
The 6809 is the best of the bunch tho.
It would be rare however for there to be a direct "bake off" between the two CPUs -- any given design organization was either an 8080/Z80 shop or a 6800/6502/6809 shop. There weren't sufficiently great differences in price/performance between the two to make it worthwhile changing.
Then add the 8MHz ARM1 board and watch it smoke the rest into dust, I suppose.
* https://laughtonelectronics.com/Arcana/KimKlone/Kimklone_sho... (https://news.ycombinator.com/item?id=16564257 https://news.ycombinator.com/item?id=3070169 https://news.ycombinator.com/item?id=26292235)
I enjoyed the 6502, but I enjoyed the 6809 more.
The 6502 has a lot going for it -- very small instruction set, simple instruction timing, etc.
But it's also a challenge because it's only got 3 registers, a fixed stack location, the zeropage, and some other strange properties. It's taken a little while to figure out how to use it effectively.
At least a little of hobbyists writing assembly in 6502 comes from nostalgia for early Apple, early Nintendo, early Commodore, etc.
Also, yeah as someone who's undergrad included a MOS 6502 "micro-controller" lab and Motorola 68k "microprocessor" lab courses, I can tell you from hands on experience that the 6502 really was in a fantastic place for writing clean, easy to debug assembly. That was a big time crunch factor in dealing with breadboarded machines where debugging the hardware was an equal or greater challenge. Given the choice between the two assembly languages I know which one I'd pick up again.
Of course the author is a highly skilled person who also did this for his enjoyment. But am I missing some way in which what he did would be more than incrementally better than what I would do? Aren't these tools pretty much as good as the best humans at solving this problem?
That said, 6502 is probably one of the LEAST featureful assembly languages I've ever used. I remember finding out it didn't have an ADD instruction - you clear carry, then add with carry.
It's only the core (https://github.com/ppelleti/json65/blob/master/src/json65.s) which is written in asm. The rest are C.
Seems neat anyway, let's fire a 6502 emulator :)
But, hey! it's still pretty hardcore. Not something I'd be doing.
Yes, it actually contains perl and haskell code [0].
[0]: https://github.com/ppelleti/json65/blob/master/run-tests.pl https://github.com/ppelleti/json65/tree/master/tools
However, because SAX is a callback-oriented parsing method, you can design your own data structure and write your own callback functions and do without this tree structure.
The additional C code provides similar nice-to-haves, such as string pool interning, a function to print out the aforementioned tree structure, and a wrapper function to parse json from a file.
Though I do not know any, I'm pretty sure in 2021 there *are* mission/security-critical applications running on 6502s in a number of places in the world.
Sometimes the world makes me grin.
Very cool. Things like this make me admire people's patience.
> However, there is no limit on the length of a line,
I'm a little confused by this.. Can someone explain ?
{'key': 'string that is limited'}Probably due to the index registers being 8 bits themselves.
LDA (pointer to string), X