Hallo Besucher, der Thread wurde 10k mal aufgerufen und enthält 9 Antworten

letzter Beitrag von deft am

C65 ROM patch - flexible GOSUB/GOTO parameter in BASIC 10

  • Last week, while programming a small BASIC 10 program, I was annoyed that it is so complicated to implement several case distinctions. If, for example, based on the value of a variable, I have over 50 possible branches, then BASIC 10 becomes really complex, because you can only use fix line number with GOTO or GOSUB.


    That annoyed me so much that I sat down at the ROM at the weekend and dig me into the GOSUB/GOTO code. :syshack:


    As a result of this weekend, I can publish a patch that extends the GOSUB and GOTO commands of the BASIC 10, so that they no longer only accept fix line numbers as parameters, but also formulas and variables.





    So it is very easy to program branches depending on a value of a variable.




    The patch work with the latest C65 ROM 911210 and the 911001. The easiest way to patch your ROM is to use M65Connect from the MEGA Filehost. It is available there on the homepage for Windows, Linux and Mac.


    I will describe the procedure with Linux, but with Windows and Mac it's nearly the same.


    1.) If not still installed, load M65Connect and unzip it.


    2.) Load the attached patch and unzip it too.


    3.) Start M65Connect and select the "Abort" button after start if you don't be connected to your DevKit/MEGA65 or if you don't have one.


    c65_goto_e.png


    4.) Select "File - Apply ROM patch file"



    5.) Select your ROM file you want to patch in "Source ROM file" and the unzipped attached patch file in "ROM patch file"



    6.) Save the patched file with "Save patched ROM as..." to your prefered folder



    7.) Rename your patched ROM file to "MEGA65.ROM" for use it with your MEGA65/DevKit/Nexys board. For using it with xc65 or xmega65 emulator from LGB-Z or hernandp you can select it from SDcard menu or rename it "c65-system" in the xemu ROM folder.


    That's it! :)


    Please be aware: :achtung


    If the result of a GOSUB/GOTO parameter isn't a valid line number then you still get an error as it is known with normal GOTO/GOSUB.


    The ROM changes apply only GOSUB and GOTO. The use of ON ... GOTO .... and ON ... GOSUB ... is another code part in the C65 ROM. I think it's makes less sense to modify them too, because the selection of the GOTO/GOSUB line will be done by the variable after ON.


    The attached patch only modify the GOSUB/GOTO code of the C65 ROM. No other changes are made with this patch. But you can use the patch also with a still patched 911210 or 911001 if you like.


    The patched ROM is still 100% compatible to existing BASIC 10 programs which uses GOTO or GOSUB. But if you use the flexible parameter with GOSUB or GOTO in your program they will cause errors while trying to run it on a unpatched ROM. It will only work with a unpatched ROM if you only use fix line number at GOTO/GOSUB.


    The patch works with the 911210 and 911001 C65 ROM. It will not work with the new MEGA65 ROMs (92....) with this patch. If the MEGA team is interested, the changes can of course also be implemented there.


    I have tested the patch yesterday and find no errors. Please send a feedback if you will find any errors!


    Now if you are interested, have fun with flexible GOSUB/GOTO parameters! :)

  • Snoopy

    Hat den Titel des Themas von „C65 ROM patch - flexible GOSUB/GOTO parameter“ zu „C65 ROM patch - flexible GOSUB/GOTO parameter in BASIC 10“ geändert.
  • Very nice addition Snoopy .


    Thanks alot.

  • Interesting! Hasn't it got any performance impact, that executing GOTO/GOSUB needs now to call some expression evaluator to be able to handle the non-constant line number as well?

    Yes, because of this the GOTO/GOSUB is slower with the patched ROM. I haven't made more test, but e.g. this simple test program (which calls 2000 times a subroutine with GOSUB 20) needs about 11% more time with the patched ROM compared to the unpatched one (with the xc65 emulator).



    But BASIC 10 is so slow anyway that I gladly accept this extra time for the gain in comfort.;)


    Besides that, who needs thousands of GOTOs in his program which will slow down the program signifanct? :D


    For the new ROM it would also be conceivable to provide this extension as an additional command (maybe FGOTO/FGOSUB or so for flex GOTO/GOSUB), so that the user can choose which variant he wants to use at the moment?

  • And here a small screenshot of the FGOTO/FGOSUB command on the MEGA65 ROM implementation:



    Thanks to Snoopy we now can use both itterations and again this makes BASIC10 more powerful.

    The RENUMBER command still works, but of course you have to be careful now when using the FGOTO, have a look and you see what i mean. The programm would not work as intended anymore:



    But very nice addition. Thanks to Snoopy and Bit Shifter

  • Hey Snoopy,


    great work as always! May I suggest you get in contact with Bit Shifter and put those changes into the source code, instead (or besides)

    releasing patches on the binary level? As you know the MEGA65 ROM is constantly evolving so it would (in my opinion) be more convenient

    and effective to add enhancements to the source code so they are included in ALL further builds.


    best

    deft