LocoPad, a web-based code editor for CPC devs

I’m certainly ok with it being included as a project.

I don’t know about the code’s status either, but the game has been available for decades online with the source code freely accessible. :man_shrugging:

An another parallel point: snippets are really nice addition for beginners. But maybe we could make them as fast as possible for BASIC. Some examples:

  • Direction handling can use less IF THEN and do only mathematic
  • Collision can work without SQR, etc…

Can we provide some ‘faster’ implementations in parallel of easy to understand ones?

The purpose of the snippets addition was not to offer really useful snippets from the go, but to showcase the ability to do so.

So, anyone who could offer such snippets would be welcome to do so and I’ll incorporate them very easily!

This is really great, and good to see it being developed - it will make it far easier to write CPC stuff on the go and that should result in more CPC entries for the 10 liners compos :smile: (although you will have to add token counting per line for this mode of development, it’s not just 255 characters, there’s a token limit too IIRC).

Would be great to integrate one of the BASIC compilers but I know that there are compatibility issues with full basic coverage. IIRC there was one recently written and talked about here (have been stupidly busy this year :frowning: )

And then Locomotive BASIC 2 / 2.1 support with labels and subroutines and so on (for the CPC that would have to be used with a compiler only I guess, or (for labels) line number substitution on export)

I’ve got a few features I’m working on, seems every time I implement something I think of something else! So thanks for the great ideas to push the next release further back :smiley:

Yeah, that’s very easy to do, on both counts, and I’ll take a look at stuff like 10-liner compo rules to see if there’s something useful there (in terms of limitations etc).

yeah, that’s a tough one unless there’s already a Wasm-assembled compiler out there already? Because porting one is definitely outside my skill level. True, I could Claude my way through something, but I lack the knowledge to properly test it afterwards.

Huh. Haven’t ever touched that. Is there really interest for it?

Thanks again for your comments =)

Maybe it would be good in the IDE to support labels for GOSUB and GOTO at least, even if at dsk generation these are replaced with the actual line numbers at the time.

100 .start_loop: PRINT “Processing data…”

…

200 IF A = 0 THEN GOTO .start_loop

Obviously this starts making a source file that different from the runnable ascii dsk basic file, so if you want the IDE source on the disk then that’s another file to save I guess (filename.src maybe).

I tried it, but take care of something: there is a bad " at the end of listing that seems to provoke some issues with the copy / paste. I have modified my parser so it accepts it… But not sure that is a good way to do it.

I have pushed a version of CPCBasicator in repository that goes to the end of source without error. Now I need to compare with official tokenized version taken from emulator and test if runtime is ok or not.

The copy paste of the full source in WinApe seems to produce some errors (I have the line 5880 - 5890 truncated)… Maybe there is a need to do it in chunks.

This is an interesting idea, but I think that implementing it would move this in another direction. Once we’re doing stuff like that, is it BASIC and more?

What we could do is introduce some tools like bookmarking for routines etc, but I don’t think many would use it…?

I just played around with it and it works nicely. One thing I recognized is that if I press ESC that I can’t stop the current BASIC program for e.g. debugging as the whole emulator will close. Is that something that can be changed?

Hmm, not sure exactly what you mean? Pressing esc doesn’t really shut down the emulator? Something else?

Esc should be a BREAK to stop the basic program. But here it stops the emulator.

That’s why I used WinApe to get SULTAN tokenized, because with autorun in Locopad and Esc exiting, I cannot load and save it to make the tokenized version.

:man_facepalming:

That was so stupid.

Yeah, I’ll fix it, of course.

Ok, fixed and replaced with shift+ESC. Sorry about that, it was pretty silly on my part.

Hello everyone!

I’m happy to announce LocoPad v1.5 with a few exciting features :slight_smile:

  1. LocoPad Goes AI!!! :

    • This was the biggest one and, frankly, although I know some of you won’t like this, I think it works beautifully. I’ve tried it with a few projects and, although it won’t give you Chase HQ 3, it’s more than competent for some fun. Keep in mind it does cost real money to run so I had to cap it - if you get an error message, just wait a bit to re-run your prompt. To use it, just press the AI button at the top right (intentionally not bringing it forward more to keep the costs down)
  2. Locomotive BASIC 2 Language Support:

    • Structured statements: SUB, END SUB, FUNCTION, END FUNCTION, RECORD, END RECORD, DECLARE, FIXED, CONST, LABEL, SHARED, SELECT CASE, CASE, END SELECT, END IF, EXIT FOR, EXIT WHILE, and inline ASM.
    • Extended syntax: memory address operator @ (@LABEL, @DATA, @var), record field dot notation (person.name$), bracket dimensions [ ].
    • Scope tracking & semantic linter: tracks procedure-local variables/parameters, flags missing function returns, validates loop exits and jump targets, and auto-indents structured blocks (2 spaces).
    • 29 dedicated BASIC 2 reference cards added to the built-in documentation drawer.
  3. ABASC Z80 Compiler Suite (@Fragarco ) :

    • Cross-compiles Locomotive BASIC & BASIC 2 programs directly into native Z80 machine code binaries.
    • Built-in compiler modal with selectable optimization levels (-O0 to -O3), memory start/data addresses, and 128-byte AMSDOS binary header wrapping.
    • Tabbed diagnostics viewer for the live compiler output log and generated Z80 assembly (.asm).
    • One-click export of standalone .BIN executables and bootable 40-track .DSK floppy images with auto-boot loaders (DISC.BAS).
    • 3 bundled sample programs: Procedures & Scoping, Records & Structs, and a fast Compiled Benchmark.
  4. Native Bytecode Tokenizer & Instant Boot (@SagaDS**)** :

    • Compiles ASCII source directly into AMSDOS binary bytecode (&0170).
    • Instant floppy disk booting in emulators and real hardware.
    • 100% token coverage for all 187 keywords, 40-bit floating-point numbers, and branching references.
  5. BASIC Minifier & Crunch Suite :

    • Smart remark removal (REM, ') with automatic forward branching retargeting (GOTO, GOSUB, THEN, ELSE, RESTORE) without code renumbering.
    • Trailing comment removal, colon statement merging (up to 255 chars), whitespace squashing, and variable crunching (A–Z, A0–Z9).
  6. BASIC 10-Liners Compo Assistant :

    • This came as a natural follow-up to the previous point.
    • Official competition rule checking: PUR-80, PUR-120, and EXTREME-256.
    • In-gutter character and tokenized byte counters (${chars}c · ${tokens}B).
    • 255-byte hardware input buffer overflow protection (detects Error 24).
    • Contest verification report, 10-line skeleton generator, and clean listing exporter.
  7. Floppy Disk (.DSK) & Cassette Tape (.CDT) Tools:

    • 40-track AMSDOS floppy catalog explorer and binary .BAS detokenizer back to editable ASCII.
    • Cassette tape export and import with 2000-baud, 64-byte AMSDOS tape headers, and detokenization.
    • Multi-file project bundling into 40-track AMSDOS disks.
  8. Companion Studios:

    • Full-Screen Image / Art Converter: Converts PNG, JPEG, WebP to CPC Modes 0, 1, 2 with Gate Array 27-color quantization, dithering, BASIC loaders, and 16 KB .SCR screen dumps.
    • 3-Channel AY Tracker: This won’t compete with anything that’s out there, but it was fun to do. 16-step sequencer with Web Audio PSG preview and Locomotive BASIC SOUND / DATA export.
    • Variable Cross-Referencer: Static analysis indexing variables by type (%, !, $, ()), tracking assignments/reads, detecting single-use typos, and providing clickable code jump tags.
    • Navigation: Ctrl+G jump by editor line or BASIC line number with live preview.
  9. Workspace Management & Themes:

    • 10 visual themes: Amstrad CPC Classic, PCW 8256 (Green Phosphor), PCW 9512 (Paper White), Tokyo Night, Catppuccin, Nord, and light themes.
    • Full workspace backup and migration (export/import JSON with merge or replace options).
    • 4-step vector wireframe onboarding walkthrough.
  10. Various bugs fixed (such as ESC closing the emulator instead of BREAKing the program running)


Acknowledgements

  • Francisco Garcia (fragarco): For the open-source ABASC compiler suite vendored in tools/abasc/ powering native Z80 machine code generation.
  • Juan Carlos González Amestoy: For RetroVirtualMachine and the RVMPlayer WebAssembly core providing in-browser CPC 6128 emulation.
  • Xavier Jollet (SagaDS): For CPCBasicator, from which LocoPad’s authentic AMSDOS bytecode tokenizer and token mapping were ported.
  • Ervin: For contributing the complete 659-line Sultan’s Maze!!!

I’ve now ran out of ideas for features. Please test it and let me know what you think!

Apologies, AI wasn’t working because of CF issues, had to bust the cache to make it load properly.

Thanks Gryzor for this milestone. It’s a huge one.

Some points:

It is not clear how to add the generated screen artwork inside the project.
‘Add to project’ creates the 1KB scr file in DSK with the loader inside (not the graphism)… If I download the scr file, how should I add it to project?

I like the minifier interface, clear and easy to understand. Small possible improvement (but big development like always): pack DATA statements into less lines (have to keep track of RESTORE statements first to not mess things).

On other hands, here are my first test issues (I used SULTAN.BAS as a base):

Minifier has an issue with Data Strings with double quotes. Check the words data after variable minifying. All word are transformed in A0-Z9: huge bug to correct.
Also, I noticed that some lines that finished with a GOSUB/GOTO are marked as ‘do not pack next line’… Why? I understand for IF THEN ELSE and Lines that are used as a target for a GOTO / GOSUB, RESUME, but not for this case.

‘Variables’ reports hexa values &A000 as variable A000.
Also it does not take into account defint / defreal / defstr: in SULTAN there is a DEFINT a-z so A (line 80) should be seen as Integer. By default all variables are Float if I remember well.
REMAIN() and SQ() are considered as array but they are Basic functions.
Some strings that are used on same line so are reported as single used.
It seems that SULTAN declares its dim variables with bracket???(line 170) I didn’t know it was possible. Variables don’t see them.

Linter is not really Locomotive BASIC aware, no?
CLS issue, TAG issue, PRINT issue, next.f issue (I know this one :slight_smile: ). It seems that ‘:’ is treated as a label identifier for this linter.

One editor does not have a search feature? Using Ctrl+F3 inside CodeMirror 8 doesn’t seem to search things, as I don’t know this editor, it’s maybe ‘normal’. I switched to the other one :slight_smile:

Thanks so much for this feedback! Greatly appreciated :slight_smile:

It’s obvious where the problem lies with most of these issues so I’ll try to fix them today and will get back to you. The scr content is a code regression, I already have this working.

Will get back to you soon (crossing fingers, that is)

I’m probably blind - how can I add a binary to my project? I have a RSX which I want to include in my BASIC program and I can’t find a way to add the BIN to the project.

That’s a design oversight on my part, but:

  1. just drag and drop one onto the workspace
  2. the Import button imports bin files as well
  3. drag and drop a dsk image onto the workspace, locate your bin file and import it.

Haven’t used it extensively, but it works.