Hello, Guest the thread was viewed3k times and contains 11 replies

last post from Snoopy at the

New version of BASIC 65.EX (now with inline assembler)

  • I've been testing for a few days now and after some bug fixes I think I can now release the new version of BASIC 65.EX (220316) into the wild. Which of course does not mean that there are no more bugs. I can never completely exclude that with the complexity. ;)


    What is new now? Except for bugfixes, the commands for procedures have remained as they were in this version. Everything remains at least 99.9% compatible to BASIC 65 (in version 920300 from January 22, 2022). So everything that runs with it, runs also with the new BASIC 65.EX.


    Completely new is now an inline assembler, which makes it possible with three new commands to use - in the manner of the inline assembler with the BBC BASIC - assembler routines as simply as possible in the interaction with BASIC. All 256 opcodes of the 65CE02 are supported and for jumps also labels can be used (thanks to the 2 pass assembler forward and backward).


    Since I had to squeeze all this into the already small space in the ROM and I still wanted to remain compatible to the BASIC 65, I "cleaned up" and restructured a bit and very carefully in some places in the ROM.


    Because of this memory limitation, the inline assembler is of course not what one usually expects from a complete assembler.


    With wishes and suggestions "Macros would be still great!" I ask to consider that currently in the ROM still 17 bytes are free for program code. :D



    What does the inline assembler offer?


    The key point is the new keyword .. (two dots) at the beginning of a BASIC line. These must stand in each case under the command line ASM. The first line, which does not begin with the keyword .. marks then the end of this assembler routine.


    Thus one of the 256 assembler commands of the 65CE02 can be entered in each line. Please note that the parameters can only be entered in hexadecimal format. So $xx or $xxxx. Decimal numbers or variable names etc. are not recognized.


    Here is an overview of the 256 possible assembler commands:


    Furthermore you can define up to 41 labels per assembler routine. A label is specified with .. @xxxx. It must be exactly 4 characters or digits (not more and not less). So for example .. @0001 or .. @here or .. @AAAA.


    Comments require a separate line each, which allows both // and ; or * as comment characters after the ...


    Furthermore with .. ! it is also possible to directly specify bytes to be written to the respective memory address instead of an opcode. Here, in contrast to the assembler commands, decimal values and also numeric variables can be specified in addition to hex values.


    To visually distinguish them from BASIC lines, the lines with .. are displayed in yellow in the listing.



    What can't the inline assembler do?


    It cannot define macros, variable names or constant names.


    Labels can only be used for long branches and jumps.


    It has no dissassembler. For this purpose the dissassembler integrated in MONITOR is more than useful.



    The more extensive the assembler routine becomes, the more the limitations of the BASIC editor become important. For example, each line must still have a line number.


    No errors are output during compilation except for missing or wrong labels at jumps or branches. If an assembler command cannot be recognized, then this line is simply skipped.


    :achtung Therefore it is important to have saved the program in any case before starting it. :achtung


    Assembler routines cannot damage the MEGA65, but they can cause a crash and the program is lost if it has not been saved. :prof:



    What are the advantages?


    It is simply included in BASIC and is there immediately. Switch on and use it! :loet


    It can be included uncomplicatedly in the BASIC program and also several routines independent of each other can be stored in the memory.


    The assembler routines do not have to be reloaded extra or set with POKE sequences, but can be simply stored and loaded in readable assembler code together with the BASIC program.


    Of course an assembler routine can also be stored separately with BSAVE if required.




    The English and German manuals are still being revised and supplemented, so just as a first introduction and start a few short explanations of the new commands:


    ASM <address>,<bank>


    define start of an assembler routine

    <adress> is a memory address ($2000-$BFFF) from which on the following code will be stored

    <bank> is the bank (0,1,4,5) which should be used for the code.



    .. <65CE02 assembler instruction>


    bra/bne/beq/... @<label> (branch codes)


    jmp/jsr @<label> (jmp codes)


    .. @<label> (label has to be any exactly 4 letter/number string)


    .. !<byte> [,<byte>] ...


    CALL <address>,<bank> [,a,x,y,z,s]


    calls the ML code which is stored at <address> in <bank>

    hereby the values of the variables a&, s&, x&, y&, z& are written into the a,s,x,y and z registers

    before returning to BASIC, the values of a,s,x,y and z registes are written into a&, s&, x&, y& and z&.

    so it's easy to handle a small data exchange between BASIC and the assemblerroutine.


    besides that you can also use CALL <address>,<bank> with additional arguments for the a,x,y,z and s register as you know it from the SYS command.


    I also have a few screenshot examples here, so you can get a first impression of how the whole thing is conceived and designed. The programs are also all included on the attached D81 image.


    basic65ex_dir_a.png







    And apart from all that there is also the new MAN command. This simply shows an overview of all available keywords.




    The ROM can still be patched and downloaded from my site here. You just have to upload a 911001-ROM from the C65 (911001.bin) and when that has passed the correctness check, the BASIC 65.EX-ROM will be patched and offered for download.


    As already mentioned, with 17 bytes of free space for program code in the ROM, the possibilities are more than limited, but I would still appreciate feedback. I would try to correct errors in any case. :loet


    If you want to try the new BASIC 65.EX, have fun with it! :)


    And if you have any questions, please ask! Especially with assembler routines the whole thing is quite complex and I surely forgot to mention one or the other thing here. ;)

  • I tried your rom

    8\|

    I like the possibility to include assembler codes.

    8\|

    One question: Is it possible to include multiple short assembler programs and also call them or is only one possible?

    Yes, you can define as many assembly routines as you like. You just have to be careful that the memory areas do not overlap.


    The respective routine is called with CALL <address>,<bank>, where address and bank are the values with which you defined the routine.


    Here's a simple example I wrote:



    If you have any other questions, feel free to contact me again. I'm glad you're interested. :thumbup:

  • I've cleaned out and tidied up the ROM a bit, so I've freed up space to include the three commands mentioned here, as I find them very useful and handy.:loet


    MODE 40 switches to 40 column mode

    MODE 80 switches to 80 column mode


    TEXT x,y,value[,flag]

    Set character at x,y to value (if flag == 1 or flag is missing)

    Set color attribute at x,y, to value (if flag == 2)


    RTEXT(x,y,flag)

    Returns char value at position x,y (if flag == 1)

    Returns color attribute at position x,y (if flag == 2)


    TEXT and RTEXT work in both text modes (40 and 80 col), there you can use x from 0...39 or 0...79 depending on the mode.



    The patched, current ROM 220523 is available on the usual page


    https://65site.de/patches.php


    after uploading the ROM 911001. :)