![]() |
Forum Index : Microcontroller and PC projects : CMM2: Memory map?
![]() ![]() ![]() ![]() |
|||||
Author | Message | ||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10315 |
MMbasic has an in-built limitation of 127 in-built commands and 127 in-built functions It currently uses 126 commands and all of the functions. Simply adding more will cause existing functions to have tokens > 128 which means when truncated to 7-bits two commands or functions will have the same token - BAD!!!! I've used all sorts of tricks in the pre-processor to squeeze more "user" commands and functions into the list (135 commands and 133 functions) As mentioned above, the way to add specific functionality is simply to use Basic functions unless you need extreme speed in which case use a CSUB. We are open to adding functionality but it would need to be of very general use, fit into the MMBasic concept and preferably layer on existing commands or functions. So for example, playing a modfile stream was a "contributed" piece of code. Note: re INP and OUP - - why can't you use peek and poke? The address range 0x40000000 to 0x59000000 is available to both |
||||
JohnS Guru ![]() Joined: 18/11/2011 Location: United KingdomPosts: 4044 |
Well, mem just strikes me as "might be quite useful sometimes but clutter otherwise". Ideal for a csub or the like. No penalty if not used. John |
||||
alynna Newbie ![]() Joined: 05/10/2021 Location: United StatesPosts: 28 |
Maybe it would be better that way. John How? Is there some issue with contributing to MMBasic I don't know about? Well, mem just strikes me as "might be quite useful sometimes but clutter otherwise". Ideal for a csub or the like. No penalty if not used. John Is there a guide on how to make csubs? I think i'm just going to do that, That 127 token limit was not something I was aware of. |
||||
alynna Newbie ![]() Joined: 05/10/2021 Location: United StatesPosts: 28 |
It currently uses 126 commands and all of the functions. Simply adding more will cause existing functions to have tokens > 128 which means when truncated to 7-bits two commands or functions will have the same token - BAD!!!! I've used all sorts of tricks in the pre-processor to squeeze more "user" commands and functions into the list (135 commands and 133 functions) As mentioned above, the way to add specific functionality is simply to use Basic functions unless you need extreme speed in which case use a CSUB. We are open to adding functionality but it would need to be of very general use, fit into the MMBasic concept and preferably layer on existing commands or functions. So for example, playing a modfile stream was a "contributed" piece of code. Note: re INP and OUP - - why can't you use peek and poke? The address range 0x40000000 to 0x59000000 is available to both The PEEK/POKE didn't seem to be able to hit those areas, but yeah, csub city. Do csubs go against the program size limit? Am I able to freely distribute csubs? I was hoping to do more low level stuff with this unit and I would hope that I can interact with it in more than just BASIC. |
||||
thwill![]() Guru ![]() Joined: 16/09/2019 Location: United KingdomPosts: 4311 |
Not as such, but can you see my links (to other people's work) here: https://github.com/thwill1000/cmm2-sptools/wiki Peter please correct me if I'm wrong, but they actually count TWICE ![]() Best wishes, Tom Edited 2021-10-08 00:42 by thwill MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
alynna Newbie ![]() Joined: 05/10/2021 Location: United StatesPosts: 28 |
Hmm. Can't load it from a file? Would we want a way to load cfuncs directly from a file while I have the source code sitting up on my screen? |
||||
thwill![]() Guru ![]() Joined: 16/09/2019 Location: United KingdomPosts: 4311 |
If I understand what you are asking, this isn't (easily) possible because in the CMM2 the STM microcontroller is configured with a Harvard type architecture and can only execute code from the "Program" memory, and not the "Data" memory. For the same reason you can't load code into a byte array and have it executed by pointing the program counter into that array. Please note my confidence in what I am stating as "fact" is not 100%. Best wishes, Tom Edited 2021-10-08 01:42 by thwill MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
alynna Newbie ![]() Joined: 05/10/2021 Location: United StatesPosts: 28 |
What I am trying to find right now is the routines that break the csub hex codes down into actual code that can be executed. Because I see no particular reason why the file could not be loaded into the program area the same way, with a format like this: CFunction <name> FILE "Myfuncs.bin" <arguments> If we use the same way it is loaded from the program (which has to have some kind of hex to byte conversion somewhere...), and instead of reading the hex codes, it places the file there instead... Edit: I found them. :) Edited 2021-10-08 04:19 by alynna |
||||
JohnS Guru ![]() Joined: 18/11/2011 Location: United KingdomPosts: 4044 |
Being a csub it's executed by the CPU, so there are no "routines that break the csub hex codes down into actual code". John |
||||
thwill![]() Guru ![]() Joined: 16/09/2019 Location: United KingdomPosts: 4311 |
Being a csub it's executed by the CPU, so there are no "routines that break the csub hex codes down into actual code". John I believe he meant the code that parses the hex text strings and converts it to actual word values in memory. Best wishes, Tom MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
alynna Newbie ![]() Joined: 05/10/2021 Location: United StatesPosts: 28 |
Being a csub it's executed by the CPU, so there are no "routines that break the csub hex codes down into actual code". John I believe he meant the code that parses the hex text strings and converts it to actual word values in memory. Best wishes, Tom Correct. But just to note i'm also a woman. As most would know, the CPU can't execute the hex codes on their own, as they are not machine code. The text "3C" in the csub represents two nybbles ("3", 0011; "C", 1000) which are then combined to make the machine code instruction 0x3c (00111000). I found the routines that do this, there is one for doing it to flash and one to doing it to memory. Since I have found that the BASIC program is already tokenized when this occurs, however the text inside the CSUB is still intact, it should be pretty trivial to make this syntax (I am going to call the binary code files "modules" for now, until someone thinks of better): CSub <name> <arguments> Module <filename.mmm> End CSub CFunction <name> <arguments> as <type> Module <filename.mmm> End CFunction ' And even DefineFont <Number> Module <filename.fnt> End DefineFont I got pretty tired yesterday so I didn't finish working on this, but I see that it is possible, and not altogether that difficult. All I have to do is, while its parsing hex numbers to convert to code, look for the text "Module" as well, and if I see it, open a file, and insert it right where it occurs. |
||||
thwill![]() Guru ![]() Joined: 16/09/2019 Location: United KingdomPosts: 4311 |
My apologies, that did actually occur to me after I posted, but you parachuted onto TBS without any introduction (that I noticed), so the balance of probabilities were that you were a man in his 50s or 60s with a beard and probably not so much coverage on top ![]() I'm curious, and possibly others are too, are you enhancing the firmware 'on spec', or for entertainment, or to overcome some problem you are encountering with a real piece of MMBasic that you are writing. Best wishes, Tom Edited 2021-10-09 01:08 by thwill MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10315 |
Hi alynna As Tom implies, we are not sure what problem you are trying to solve. You can already put CSubs in include files and then include them in any relevant program. If you are looking to include just the binary then that has some merit but it only solves a problem no-one has hit yet - running out of program space in a way which chaining programs can't solve. Sounds like you enjoy programming so if you fancy a real challenge then I would love to include an in-line assembler. This would need the pre-processor to "assemble" the text source and create the binary instructions to include in the program space. I would assume the calling sequence would be the same as CSubs, i.e. passing the parameters by reference as pointers Edited 2021-10-09 01:25 by matherp |
||||
thwill![]() Guru ![]() Joined: 16/09/2019 Location: United KingdomPosts: 4311 |
For the record I think there is another solution to that problem which doesn't require a new concept to be added to MMBasic. As far as I can tell from the extracts of this code I had to look at for the MMB4L port there is no reason that the "hexadecimal text" ever need be copied into the program memory. Instead during the preprocessor pass it just needs to be parsed, converted into byte data and squirreled away somewhere in the CMM2's excessive RAM. Once the 2nd pass has finished writing the program into "flash" then the squirreled away data can be copied onto the end of the program memory/flash as it is currently. Best wishes, Tom MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10315 |
Possibly true for the CMM2 but not for the ArmmiteF4, PicoMite, and ArmmiteH7 which all run the same code (edit/autosave needs the ascii source) so it is not something I'm going to change Edited 2021-10-09 02:07 by matherp |
||||
thwill![]() Guru ![]() Joined: 16/09/2019 Location: United KingdomPosts: 4311 |
Possibly true for the CMM2 but not for the ArmmiteF4, PicoMite, and ArmmiteH7 which all run the same code (edit needs the ascii source) so it is not something I'm going to change It was an observation, I wasn't suggesting you made any changes, as you said "it only solves a problem no-one has hit yet" ![]() Edit: where does it edit the ASCII source from ? does it regenerate it completely from the tokenised form ? ... in which case it could also regenerate the CSUB hexadecimal text from the binary - and I'm still not suggesting you do it. Best wishes, Tom Edited 2021-10-09 01:54 by thwill MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
alynna Newbie ![]() Joined: 05/10/2021 Location: United StatesPosts: 28 |
My apologies, that did actually occur to me after I posted, but you parachuted onto TBS without any introduction (that I noticed), so the balance of probabilities were that you were a man in his 50s or 60s with a beard and probably not so much coverage on top ![]() I'm curious, and possibly others are too, are you enhancing the firmware 'on spec', or for entertainment, or to overcome some problem you are encountering with a real piece of MMBasic that you are writing. Best wishes, Tom I suppose I should introduce myself, yeah. I've had this board for a while now but really haven't entered the community until now, mostly because I hadn't wanted to do anything big with it yet. I've been messing around with it for a few months. I'd like to obtain one of those cases for it.. Anyway, I am Alynna, I'm a 45 year old woman. I am *really* into retro stuff. The CMM2 is retro-ish. In that its got a nice retro face, but underneath, yeah I've been reading a 3000 page spec manual. BTW I removed INP and OUT after I realized that yeah it can hit that area. I contribute code to several projects, including MiSTer (the Amiga and C64 core in particular), the Vampire (specifically, sagasd.device for accessing the SD card), and I also do my own work in VHDL and Verilog trying to make a dream platform I have, a reality. Relevant hardware I have right at my desk are... of course the CMM2, an Ultimate 64, a Vampire V4 standalone, a Nexys4DDR running the Mega65 core (I am trying to code a way to add the DDR to the Mega65 space so that it can have much more RAM), and of course a Minimig MiSTer. I also have an Amiga 1000 with a Vampire V500-2+ in it. I can be found in alot of retro hardware Discord servers. :) My favorite platforms so far are C64 and Amiga. CMM2 is honestly up there too, but I really would like to do more than just stuff with BASIC in it. I have removed INP and OUT from my firmware build (Poke/Peek actually does what they did) and I have moved my MEM() function into MM.INFO(MEM <item>). This saves a token. I wanted this because I could not find functions that really told me how much string space, heap, etc, that I had, so that programs I am writing know they're gonna hit a limit. I plan to send any enhancements I make back to Geoff and Mather(?) for consideration for inclusion. I know I can make CFuncs, and damn do I plan to. However MEM() needs access to stuff I couldn't always get through the API. As for the CFUNCS work, I would like to develop and have my file loader solution added, since it avoids having the source eating memory in the program, and would allow for even more CFuncs to be added. It will NOT break existing CFunction code, of course. Edited 2021-10-09 07:12 by alynna |
||||
alynna Newbie ![]() Joined: 05/10/2021 Location: United StatesPosts: 28 |
The specific course I would like to take is the following: Loading CFuncs, CSub and Fonts are done after tokenization, while loading the program into either RAM or Flash. It of course is reading 32bit words, and then putting them inline with the code being uploaded. Its beautiful and elegant, to be honest. My proposal is, to expand the check for "xxxxxxxx" which a hex code, to also check for "Module" while it is checking. If it sees this, then the next string it finds is considered a filename. That file is loaded, and inserted right where the program pointer is. And then it continues on. Since the file is not in the source code, it doesn't consume program memory twice, only where the program is actually running from. Also the implementation would allow for things like this: (xxxxxxxx are standins for hex words, they are not actually what would be put there..) CFunction Test(x) as Integer xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx Module "ModuleOne" xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx Module "ModuleTwo" xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx End CFunction Each time it encounters "Module" it puts the raw data in the file inline. It mixes in with the code around it, though usually you'd probably want that in the file too. But the provision still would exist for you to put in a hexcode function mixed with loaded modules. What do you all think? |
||||
alynna Newbie ![]() Joined: 05/10/2021 Location: United StatesPosts: 28 |
As Tom implies, we are not sure what problem you are trying to solve. You can already put CSubs in include files and then include them in any relevant program. If you are looking to include just the binary then that has some merit but it only solves a problem no-one has hit yet - running out of program space in a way which chaining programs can't solve. Sounds like you enjoy programming so if you fancy a real challenge then I would love to include an in-line assembler. This would need the pre-processor to "assemble" the text source and create the binary instructions to include in the program space. I would assume the calling sequence would be the same as CSubs, i.e. passing the parameters by reference as pointers I would love to see this too. Probably implemented like this: AsmFunction Test(x) as integer In the code you would either get x in r10+r11 (if its an 64bit integer/double) or pointer to a string (in r10). The return result would always be in r8 and r9. Test will either have a 64bit integer or be pointing at the resulting float or string somewhere else in memory. In the assembler, both x and Test are available to be used here as aliases to registers 10 and 11, example: mov r0, #15 'Unchanged add X, X, r0 'Becomes add r10, r10, r0 mov Test, X 'Becomes mov r8, r10 Because this is a 32 bit operation, dealing with the 64 bit float/integer is NOT automatic. To reference the upper word, you would use >X and >Test here, which would reference r9 and r11. Registers 0-7 are the users playground. We should save any registers required before entry and restore them after entry, after the values are copied to their actual variables. Then of course we end with: End AsmFunction Edited 2021-10-09 07:48 by alynna |
||||
Mixtel90![]() Guru ![]() Joined: 05/10/2019 Location: United KingdomPosts: 7937 |
It's only on the CMM2 that you don't need the ASCII representation of CSUBs in RAM. That's because on all the other platforms the editor and the program are both in RAM at the same time - they are not external file based. The CMM2 keeps the ASCII on the SDcard. Also, because the CMM2 is file-based, it can use #DEFINE & #INCLUDE, which aren't available on other platforms (AFAIK!). This explains Peter's earlier answer: "Possibly true for the CMM2 but not for the ArmmiteF4, PicoMite, and ArmmiteH7 which all run the same code (edit/autosave needs the ascii source) so it is not something I'm going to change". Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
![]() ![]() ![]() ![]() |
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |