A pair of Tiny BASICs

Let's talk about anything related to the 6502 microprocessor.
User avatar
VinCBR900
Posts: 53
Joined: 08 Sep 2017
Location: UK Expat living in Washington State, US

A pair of Tiny BASICs

Post by VinCBR900 »

Hello everyone, below are a couple of Tiny and Small integer BASICs ive been working on.

https://github.com/VinCBR900/65c02-Tiny-BASIC

Enjoy!
User avatar
BigEd
Posts: 11463
Joined: 11 Dec 2008
Location: England
Contact:

Re: A pair of Tiny BASICs

Post by BigEd »

Looks great - a very thorough README. And I like the inclusion of two c emulators. Thanks!

A couple of points from me:
- Hans Otten is the correct spelling
- any of the standard open source licenses would be a huge improvement: even CC0 if you really don't mind.
- how might I decide where in RAM is fairly safe to put something, like some machine code, or a PEEK/POKE array of bytes?
User avatar
VinCBR900
Posts: 53
Joined: 08 Sep 2017
Location: UK Expat living in Washington State, US

Re: A pair of Tiny BASICs

Post by VinCBR900 »

Evening,
The assembly has a directive for available ram, currently set to 4kbyte. So anywhere outside that works with kowalski simulator and my toy simulators.

Oops typo on Han’s, I’ll fix tomorrow.

Re license, chatgpt recommends MIT but even then there’s nothing to force people to comply. I’ll toggle the flag and maybe update the headers on the next update.
User avatar
BigEd
Posts: 11463
Joined: 11 Dec 2008
Location: England
Contact:

Re: A pair of Tiny BASICs

Post by BigEd »

Thanks, MIT is a fine choice - visual6502 uses it, for example.

For memory allocation, I was thinking of TOP, LOMEM and HIMEM kinds of pseudo-variables. In some cases users are expected to PEEK the respective zero page locations to figure out where things are. In some cases one might use a string constant for machine code, in some cases a REM statement. It certainly a problem the user can figure out, even if there's no guidance, so it's not a huge problem. As you describe it, we could consider HIMEM to be absolute address 0x1000 and could freely use RAM above that.
teamtempest
Posts: 443
Joined: 08 Nov 2009
Location: Minnesota
Contact:

Re: A pair of Tiny BASICs

Post by teamtempest »

Neat! Thanks for contributing it.

I notice that at one point you use an instruction that is technically not part of the original 65C02 instruction set. It is one of those Rockwell extensions that is included in the W65C02S instruction set, though. It would only be an issue if the processor in use happened not to be a Rockwell or W65C02S chip.
User avatar
VinCBR900
Posts: 53
Joined: 08 Sep 2017
Location: UK Expat living in Washington State, US

Re: A pair of Tiny BASICs

Post by VinCBR900 »

teamtempest wrote:
I notice that at one point you use an instruction that is technically not part of the original 65C02 instruction set. It is one of those Rockwell extensions that is included in the W65C02S instruction set, though.
Oops, my mistake - which one?
Martin_H
Posts: 837
Joined: 08 Jan 2014

Re: A pair of Tiny BASICs

Post by Martin_H »

Interesting project.

I followed your link and see that you used Claude AI and read about your development process. It's an interesting process and that it was able to produce something usable. My experience with Gemini's coding ability is that it's lackluster.

Update: I tried Claude AI and had it output some 65816 assembly to do 32-bit addition, subtraction, and multiplication. It was much better than ChatGPT or Gemini, but its multiplication code had minor bugs. For example, it had inefficient code where it dropped into an 8-bit accumulator. But it was overall much better.

Also, the claim that Claude AI generated a C compiler is considered controversial because Claude had access to the GNU C compiler source as part of its training data. The project also relied on a test harness where the human operator used GCC as an "oracle" to validate the AI's output.
jds
Posts: 196
Joined: 10 Mar 2016

Re: A pair of Tiny BASICs

Post by jds »

I am getting good results with using Claude for debugging. I have huge trace files from my emulator and it is very tedious to look through them to determine where the code path goes wrong. This is an excellent use for AI.

In general I find AI very useful, but you have to work closely with it and check everything.
User avatar
VinCBR900
Posts: 53
Joined: 08 Sep 2017
Location: UK Expat living in Washington State, US

Re: A pair of Tiny BASICs

Post by VinCBR900 »

In my case I tried Gemini but it gave incorrect code eg non existent opcodes.

Claude was much better, but the real breakthrough came with the c based simulator and debugger is it could iterate without me in a tight loop, until my free account time was consumed, then wait 4hrs and continue.
Martin_H
Posts: 837
Joined: 08 Jan 2014

Re: A pair of Tiny BASICs

Post by Martin_H »

VinCBR900 wrote:
Claude was much better, but the real breakthrough came with the c based simulator and debugger is it could iterate without me in a tight loop, until my free account time was consumed, then wait 4hrs and continue.
Your test harness was a really good idea as it reduced AI hallucinations and kept Claude honest.

Last night I became curious and tried Claude again with a project prompt. I was impressed because it asked good clarifying questions and reacted appropriately to my stated constraints (e.g. use ca65 syntax, ROM ready code). Eventually it produced about 4,000 lines of source, a build script, and a README.md. But it wouldn't assemble as it used illegal addressing modes in several places, and duplicate labels. But the basic ideas were correct, and this was the first time an LLM produced code I didn't find completely bonkers.

This makes me wonder if I can rescue the code with a line-by-line review. Would that be faster than writing 4,000 lines from scratch? I'm not sure.
Last edited by Martin_H on Thu Mar 26, 2026 11:12 am, edited 1 time in total.
User avatar
BigEd
Posts: 11463
Joined: 11 Dec 2008
Location: England
Contact:

Re: A pair of Tiny BASICs

Post by BigEd »

Does the included emulator pass Klaus Dorman's test suite? That's always a good thing to try, especially for new code.
https://github.com/Klaus2m5/6502_65C02_functional_tests
User avatar
VinCBR900
Posts: 53
Joined: 08 Sep 2017
Location: UK Expat living in Washington State, US

Re: A pair of Tiny BASICs

Post by VinCBR900 »

Probably not, as I only just heard of it and I don't know if all opcodes are implemented, only those needed to compile the Tiny BASICs
Last edited by VinCBR900 on Fri Mar 13, 2026 2:13 pm, edited 2 times in total.
User avatar
BigEd
Posts: 11463
Joined: 11 Dec 2008
Location: England
Contact:

Re: A pair of Tiny BASICs

Post by BigEd »

It's worth trying - if an emulator can run a Basic, it's probably pretty good, so you'll just be needing to fix some corner cases. It might be that LLM tools can help with that.
teamtempest
Posts: 443
Joined: 08 Nov 2009
Location: Minnesota
Contact:

Re: A pair of Tiny BASICs

Post by teamtempest »

Quote:
Oops, my mistake - which one?
Oops, my mistake - I think I confused your code with that of another recently posted BASIC implementation. The instruction I was referring to appeared in a floating point implementation, which of course your Tiny BASICs do not support.
pjdennis
Posts: 51
Joined: 15 Apr 2022
Location: San Antonio, TX, USA

Re: A pair of Tiny BASICs

Post by pjdennis »

VinCBR900 wrote:
Claude was much better, but the real breakthrough came with the c based simulator and debugger is it could iterate without me in a tight loop
I've had similar results recently using Claude. I have been working on a self-hosting 6502 assembler bootstrap chain (some day I'll get around to writing it up) and before using Claude, got to something usable, but with limited capabilities and a non-standard implementation-friendly syntax. I'm also using a c based simulator. There is no debugger, but I used Claude to create an automated test suite for the assembler which it reverse-engineered from the existing code samples.

With the emulator and test suite available, Claude can work without my intervention for extended periods of time enhancing the assembler, troubleshooting and fixing issues along the way. With Claude I added modern syntax support, basic expressions, conditional compilation, macro capabilities and more.

I think another big factor is the new models that came out in December - What I described above was with Claude Opus 4.6 and it's proved significantly more capable than any of the earlier versions I tried.
Post Reply