LocoPad, a web-based code editor for CPC devs

Just wondering… is there a limit to the size of the .BAS file that LocoPad will save to a .dsk file?

When I try to run something like the BASIC code for Sultan’s Maze, the resulting DISC.BAS file is 16K, and only contains around half the code.

Ok, that was great feedback (haven’t tested it with edge cases), and that’s a bug actually. The data is there, but only a single dir entry was written, capping it at 16kb and not chaining the rest of the blocks.

back to the drawing board, adding this fix to the next release.

Cool, looking forward to it!

ROUND, REMAIN, WINDOW SWAP, ON BREAK GOSUB and ON BREAK STOP are all available in BASIC 1.0. The SWAP command isn’t used on its own, as far as I know.

LocoPad Update: New Features & Bug Fixes

Ok, after a lot of effort (and the reason why I have been absent from actual posts), I can give you the next version.

The following features were suggested by someone who wanted to stay anonymous - no idea why (you know who you are :grin:), you can be the judges of how useful they are:

New Tools

  • 8x8 Sprite & UDG Studio: Visual pixel editor for glyphs and sprites, live 1×/2×/4× scaling preview, AND one-click SYMBOL or DATA code generation.
  • Sound Studio: 3-channel synthesizer with panning, pitch/period calculator, envelope/pitch modulation curves (ENV/ENT), and SOUND statement export. Some basic fx thrown in for good measure :smiley:
  • Mode & Coordinate Calculator: Interactive canvas for all modes with palette LOCATE text cell to graphics coordinate mapping, and VRAM base offset calculator (&C000, &4000, &8000). Really unsure about how well this works because I can’t test it properly, not knowing the workflow it may be used in (I think I understand the thought behind it, but I just implemented the request!)
  • Curated Snippets Library: Searchable reference library covering joystick input, raster interrupts, firmware vectors, and AMSDOS disk calls . The purpose of this is demonstrative at best - thanks to the same anonymous user for providing them, but I haven’t tested them and can’t judge them. The point is, we can add such stuff if so inclined.

Code help & Versions Distinction

  • Locomotive BASIC Linter: Real-time checking for line numbering range/order, 255-character line limits, unclosed strings/parens, keyword typos, unclosed or mismatched FOR/NEXT loops, STEP 0, open branches (GOTO, GOSUB, RESTORE), and undeclared array bounds (DIM).. Any other checks I should add?
  • BASIC 1.0 vs 1.1 Compatibility (Corrected):
    • Thanks to @Nich I double-checked the manuals and corrected the command list. ROUND, REMAIN, WINDOW SWAP, and ON BREAK were actually supported in BASIC 1.0 all along indeed (and standalone SWAP isn’t a Locomotive BASIC keyword) (I think I made a mistake when compiling the initial json lists)
    • The linter and Symbol Inspector now accurately target only the real 7 BASIC 1.1 exclusives: FRAME, FILL, COPYCHR$, DEC$, GRAPHICS PEN, GRAPHICS PAPER, and MASK.
    • Provides linter hints and inspector badges with standard 464 workarounds (e.g. CALL &BD19 for FRAME).

Export & Sharing

  • .SNA Export
  • One-Click Link Sharing: Encode and share complete BASIC programs directly in the URL. This uses zero server storage. Everything happens in the URL with a deflated base64 encoding of your content. As such, there are inherent URL length-related issues. If you can think of a way to do it in a more efficient way without needing accounts or server storage, I’d be reeeeally interested to hear from you!

Bug Fix

  • DSK 16 KB cut-off: Please test and report - I tested it with random data and verified fine for me. I don’t have a listing that big.

  • Tune Demo Crash: Fixed an Improper argument crash in Project 4 caused by an invalid negative step count in the ENV 1 statement (sorry about the typo!).

…and a few other things I forget.

Absolutely outstanding!!!

So many great features.

It looks like the 16KB cut-off is fixed, as it was able to build and run a dsk from the Sultan’s Maze code!

One small problem though. The BAS file seems to be saved untokenised, so takes a long time to load.

Ha, I ran into this issue when I was testing the cut-off fix and I thought that the process had hanged until I looked into it. Then I decided that this is a problem for my future self and left it at it :smiley:

I really need to do some reading on it because I thought it was easier than what I later realised. If you’ve got any sources, please throw them my way :slight_smile:

PS thanks for the kind words :slight_smile:

PS2 how long does it take for you to run Sultan’s Maze?
PS3 I guess it shouldn’t be called 1.0.2, but it ballooned after I started fixing some stuff :smiley:

To decrease size of URL, I suppose you have already zipped it?

Also to decrease global size of BASIC on the CPC, maybe you can add a ‘remove comment’ option?
Imagine:

10 REM First comment
20 A=10 : REM Initializer
30 GOSUB 1000
40 END: ' End of program
1000 REM SubRoutine
1010 FOR I=1 TO A:PRINT I:NEXT
1020 RETURN

can be sent to CPC like this:

20 A=10
30 GOSUB 1010
40 END
1010 FOR I=1 TO A:PRINT I:NEXT
1020 RETURN

Note that line 30 has been automagicaly modified to use 1010 because 1000 was a complete comment and it was used inside a GOTO, GOSUB or THEN statement. I don’t really remamber if Locomotive Basic accepts IF THEN 1000 or not…
This part can be forgotten if needed: just keep full comment lines ’ for easier handling.

10 '
20 A=10
30 GOSUB 1000
40 END
1000 '
1010 FOR I=1 TO A:PRINT I:NEXT
1020 RETURN

I have made a CPCBasicator that is aimed to tokenize ASCII Basic from PC Notepad. It’s in python but you can take whatever you want from it for your needs.

Thanks for your replies, @SagaDS !

Let’s take them one by one:

  1. yes, the URL has already been compressed using the browser native CompressionStream('deflate') . Base64 has the inherent downside that it introduces a ~33% overhead. We could use Base85 or Base91 for better compression, but these introduce %XX characters that will actually make the URL longer.
  2. Yeah, removing REM or ’ lines is easy, and what’s more there’s already a renumber function that can take care of the issues arising from completely removing those lines (else we could turn something like “10 REM this is a comment” to simply “10 '”, shaving off bytes.
    1. But this got me thinking that maybe we could build a more complete BASIC minifier of sorts. Like removing extra spaces, or chaining short lines with a ‘:’. Or removing unreferenced lines. Stuff like that (can’t think of anything else but I’m sure there is).
  3. CPCBasicator: this is sweet! Found the script, could we use it in LocoPad as-is? I’ll provide credit of course!

To minify more, you can also rename variables to one or two letters.

No issue for using my script, you can credit or not, I don’t really care.
Feel free to modify it if issues are raised. Just keep me informed so I can update the repository with bug fixes. And of course I will help you work on bugs too :slight_smile:

Thanks man, you just made my work so much easier :slightly_smiling_face:

Thanks for sharing CPCBasicator.

I can see only a one-sentence introduction, mention of one commit but no code. Can you check in e.g. an unauthenticated private browsing session if it’s a permission issue?

It takes almost exactly 60 seconds for RUN"DISC" to load the game.

If I export the DSK, load it in WinAPE, LOAD"DISC" and then SAVE"DISC" it saves it in tokenised form.

Then RUN"DISC" takes less than 4 seconds.

The project is public and I can go to files even if not connected… Strange.
PM me to check together without adding to much noise to thread.

Here is the python file if you just want to check it.

CPCBasicator.zip (5,2 Ko)

@ervin, yes other way to do it, is to save the ascii into dsk / launch emulation / open BAS / save (tokenized) / exit emulation / get new dsk. Not sure that can be done easily with the emulator though.

Can you share the Sultan Maze BAS/DSK? It’d be a good test for the minification engine…

Sure!

sultan.zip (12.4 KB)

sultan_untokenised.dsk (190.3 KB)

sultan_tokenised.dsk (190.3 KB)

Awesome, thanks!

Edit: just took a look, pretty impressive what you can do with that amount of code!

Ok, just did a test of my minifier routines on Sultan’s Maze and I got a line reduction of 43% (659->375) and a total size reduction of 14.3% (34,708->29,740B).

Now to test things…

I’ll include your files, @ervin , in LocoPad as a project if that’s ok with you (no idea about their status?).

I am debugging my python code with sultan.bas also…
Need to work on variables that use ‘.’ inside. Didn’t know it was possible in Locomotive BASIC :slight_smile: Like “ghost.drawn”: Already corrected.

But now, I need to work on variables that look like a real token : “next.f” (it work everywhere but not inside IF THEN conditions… Line 5430