GeorgRottensteiner / C64Studio

C64Studio is a .NET based IDE specializing in game development for the C64 in assembler and BASIC
Other
260 stars 38 forks source link

Workflow for doing multi-file BASIC build - reusable BASIC Libs #66

Closed mwedmark closed 1 month ago

mwedmark commented 2 years ago

It would be nice if the tool supported Mulit-file BASIC build. Is this possible today? If selected wisely (either as labelled listing without duplicate labels or with non-overlapping Start/Range-addresses per file), all files could be automatically added to one file before build. For example I'm writing a Chip8 Emulator as we speak. It will be alot of lines of BASIC. I've already created 13 different files to test different parts of the application.

GeorgRottensteiner commented 2 years ago

Interesting; it's not possible for BASIC yet. You could of course do a lot of trickery in the Pre and custom build events to manually combine the single files in a full file.

I'm thinking about doing a sort of meta macro (with the # comments).

What would be your preferred way? Manually put the macro to include a specific BASIC file, or let C64Studio combine the files itself (order by numbering for example). Although the latter would either mean to automatically merge all BASIC files in a project, or require a separate configuration for the files to use.

mwedmark commented 2 years ago

Thanks for the feedback! Yea I just discovered the Prebuild/Build/Postbuild and sat with in yesterday. What is the command for building a BASIC-file if I want to create a custom build step for BASIC? Maybe an example of such a multi-file BASIC build setup would be a good addition to all your current examples. I couldn't figure it out yesterday.

#INCLUDE But if wanting to add it like a first class member into the application... Maybe a pre-processor macro like the following would be intuitive enough and pretty straight-forward to implement. Similar to C: REM #INCLUDE "3DLIB.BAS" 1000 GOSUB 1500 1010 PRINT "HELLO" ...

The problem with "#include" here would of course be that, if you put the numbers in the wrong number the current build process would complain? But I guess that could be overridden when doing these kind of builds, or limited to only checking that rule within each file. If not, I think this would be confusing. Of course, if all files used LABEL-mode that wouldn't be a problem anymore. But that would make my other suggestion even more useful (freely named labels)

C64STUDIO NUMBERING To have C64Studio decide the ordering by number would of course fix the above problem. How would that be implemented? Another Build setting dialog for choosing files? Or could something you already have be reused in some smart way? Just add another alternative in some drop-down?

I guess the first idea would be easier to implement? Regardless of which that would be a "killer"-feature for bigger BASIC-programs. Maybe having the possibility to actually see the result BASIC file output for clarity and trouble-shooting.

GeorgRottensteiner commented 2 years ago

I actually have to check whether it's possible at all to do a manual BASIC compile. There's the command line C64Ass, but I can't remember out of my head if it actually does support BASIC as well.

The generic #INCLUDE would be easy to implement. It should work for label mode directly, the numbering might cause an issue. I could do auto-renumbers on the included parts, of course that will abort, if renumbering fails due to an syntax error. You also couldn't really GOTO/SUB at locations in the included files.

GeorgRottensteiner commented 2 years ago

I've updated the WIP link (https://www.georg-rottensteiner.de/webmisc/C64StudioRelease.zip) with a version that does have an include statement. On a (rather simple) example it works fine. It has no auto-renumbering yet though. To use:

INCLUDE "OTHERFILENAME.BAS"

It's simply inserting the lines of the other file at that location. Let me know if that fits your requirements. Could well be that there are issues I didn't encounter yet, so please make a backup of your code.

mwedmark commented 2 years ago

Thanks for the WIP! Yes I like that! It does not change the original files, create a sum of all code and it does the job, great work!

Currently it only works in Line Numbering Mode I guess, when swtiching both to Label Mode , it currently crashes the program with "Unhandled Exception: The path is not of a legal form"

But numbering is what I currently use so that is OK.

I'm gonna test this some more, with my big Chip8 Emulator. Renumbering all my files to non-overlapping ranges and making sure they are ordered in the correct (increasing) order.

Other suggestions? Either a working user-definable naming of label (as my other improvement suggestion) or possibly a simpler solution using a pre-processor named alias for a referring to a line number/numbers like:

IDEA 1 - SPECIFICALLY FOR LABELS

MAIN.BAS
#INCLUDE "LIB.BAS"
PRINT "THIS IS FROM MAIN"
PRINT "LET*S DRAW A ";:GOSUB #LABEL DRAWTRIANGLE

LIB.BAS
-snip-
#LABEL DRAWTRIANGLE
500 PRINT "TRIANGLE"
510 RETURN
-snip-

IDEA 2 - GENERALIZED BASIC DEFINES LIKE C

MAIN.BAS
#INCLUDE "LIB.BAS"
PRINT "THIS IS FROM MAIN"
PRINT "LET*S DRAW A ";:GOSUB #DRAWTRIANGLE

LIB.BAS
-snip-
#DEFINE DRAWTRIANGLE 500
500 PRINT "TRIANGLE"
510 RETURN
-snip-
mwedmark commented 2 years ago

Hello again! Mostly for testing this function but also somewhat functional my main basic program now looks like this. It still works the same, executing a full Chip8 program with 100 opcodes!! The solution has gone from 1 file to 18 files using the #INCLUDE directive, really nice! The main BASIC file went from 443 lines to 53 lines! Maybe a good thing would be to be able to comment on the same line, so I could at least manually write the range of lines included in the file. Example:

INCLUDE "LIBRARY.BAS" : THIS FILE USES LINE NUMBERS 1010-1099

image

GeorgRottensteiner commented 1 month ago

This looks solved, if you find another issue please feel free to reopen.