![]() |
Forum Index : Microcontroller and PC projects : CMM2: V5.05.04b3a: CSUBs - not for the faint hearted!!!!
![]() ![]() ![]() ![]() |
|||||
Author | Message | ||||
abraxas Regular Member ![]() Joined: 16/06/2020 Location: CanadaPosts: 99 |
All every astute points Tom. I'm just trying to figure out where CSUBs could go next. If we had CSUBs that are self contained within Maximite there would be no reason why CMM2 could not be directly pitched vis-a-vis projects like CommanderX 16 and ZX Spectrum Next. Embedding a rudimentary C compiler really isn't impossible even on small hardware. As long as we don't need aggressive optimizations to realize a good speedup (which we probably don't) then even something like c4 might suffice. C4 is a rudimentary C compiler in a single C file that is ~500 lines long: https://github.com/rswier/c4 Is that small enough and fast enough to be worth it? Only Pete would have the answer. |
||||
Sasquatch![]() Guru ![]() Joined: 08/05/2020 Location: United StatesPosts: 376 |
One of the issues you may run into is that this is NOT a simple 8-Bit CPU. These ARM-7 beasts are far more complex than what we were using back in the 80's or even 90's. Modern compilers are also highly complex with specific optimizations targeted at specific CPU architectures. For example the GCC compiler used to compile CSubs has been in constant development since 1987 as an open source project. Having said all that, the development team has indicated that the source code for MMBasic will be available when things settle down a bit, so we will see where the community takes it. My suspicion is that most CMM2 users won't really want to peek behind the curtain. -Carl |
||||
MauroXavier Guru ![]() Joined: 06/03/2016 Location: BrazilPosts: 303 |
When I was young and develop using Turbo Pascal, I loved to use the assembly lines to speed up the video engine, that I called after MXMISC Library and used in all my pascal games. Obviously I would like to see something like this in the CMM2, but I´m not waiting for this because isn´t the project focus. But I see that CMM2 have the power to make great things. My Wolfenstein 3D port currently is running at a reasonable speed with all objects and enemies on screen (finally I made it!)... ...And I didn´t make any optimization yet and didn't worry about first 4 letters (the majority of variables have the same 4 letters in the beginning!) or embedded commands instead subroutines and so on. It´s running good in totally crude source code with almost no optimization (I will think about it soon). What I´m trying to say is that BASIC is so fun and can be very challenging to gain speed in certain situations (as you doing in your Boulder Dash). My little demo of Boulder Dash it was focused in the first CMM, not the CMM2. I made it totally thinking in the limits of the first CMM, and was so enjoyable develop it in my free time. Sometimes I´m fell me tempted to program into CMM1 again to embrace that limitation. This is why I loving developing to the CMM2, and why I´m insisting on developing a raycaster game: THE CHALLENGE. I always look in the mirror and challenge myself to be better than me yesterday, this is my most beloved hobby when talking about developing programs since my teenage. PS.: Only a shame that my job consumes a lot of my time, I have only one or two hours for a day to play with CMM2... |
||||
JohnS Guru ![]() Joined: 18/11/2011 Location: United KingdomPosts: 3998 |
You'd have to get permission as currently the ARM variant is restricted. Probably not a problem if TCC used as a separate program (but that begs how). BTW did you get c4 to work? As downloaded it doesn't for me and I don't right now feel inclined to debug it. edit: I found why it fails - it uses the ridiculous #define int long long Also, c4 isn't a "single file" as it needs various #include files. Doesn't mean it can't be made to work, but it does add more hassle. edit (again): in addition, it's going to need a back-end ARM code generator (doable, if a pain) edit (another): it doesn't support #define, #include (or any other #), float or double, typedef, struct (& probably lots more...) John Edited 2020-07-10 02:31 by JohnS |
||||
vegipete![]() Guru ![]() Joined: 29/01/2013 Location: CanadaPosts: 1122 |
Is there a way to access trig functions like sin and cos from csubs? Visit Vegipete's *Mite Library for cool programs. |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10067 |
Only if I add them to the header and the firmware. Check the MATH command as this is intended to speed up things like Euler calcs UPDATE: I've added Sine to RC2, the rest you can calculate - untested Edited 2020-07-14 18:38 by matherp |
||||
Sasquatch![]() Guru ![]() Joined: 08/05/2020 Location: United StatesPosts: 376 |
Here is a DOS Batch file I use to build CSubs. Usage: Make cfilename [-m|-j] Note: don't include the .c file extension on cfilename Make.zip And here is a slightly modified version of ArmCFGen.BAS. This version will accept command line parameters. It will still prompt for any missing parameters as before.. Usage: MMBasic Armcfgenv142.bas filename.elf [-m|-j] armcfgenV142.zip Edited 2020-07-24 07:41 by Sasquatch -Carl |
||||
lizby Guru ![]() Joined: 17/05/2016 Location: United StatesPosts: 3309 |
Would it be possible and not too inconvenient to get around the token number constraints for the dropped functions from the pi-cromite, JSON$ and FIELD$, by providing them as CSUBs, since the code is already written? PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed |
||||
twofingers Guru ![]() Joined: 02/06/2014 Location: GermanyPosts: 1526 |
Hi Peter, a dream becomes true! ![]() ![]() And it seems to be much easier than I expected. As a first try, I converted your string sort (MM2) and it works like a charm! I'm totally excited. ![]() ![]() To sort a string array of 1000 elements with length of 20 takes 0,5s (2000 ~ 2,5s). I used your C-code with almost none (sic!) modifications! 'Stringsort for CMM2 (5.05.04RC5/400MHz) - test program option base 0 option explicit const MAX_ARRAY =1000 const MAX_LENGTH= 20 const LF$ =chr$(10) DIM S$(MAX_ARRAY) LENGTH MAX_LENGTH DIM temp$,i,ts S$(0) = "John" S$(1) = "Aaron" S$(2) = "Eric" for i = 0 to 2 ? S$(i) next ? "Creating"MAX_ARRAY" random strings ..." for i = 3 to MAX_ARRAY-1 S$(i) = RNDSTR$(20) next timer = 0 StringSort S$(), MAX_ARRAY, 20 ts=timer temp$=S$(0) 'S$(30)="AAAAA" ' just for testing! for i = 0 to MAX_ARRAY-1 ? S$(i),temp$ if S$(i)<temp$ then ? "Sorting Error at element " i:end temp$=S$(i) next ? LF$ "Array successfully sorted!" ts "ms for " MAX_ARRAY " elements" ' create a random string Function Rndstr$(s_len as integer) as string local i% for i% = 1 to s_len Rndstr$=Rndstr$+chr$(rnd*32+64) next i% ' ? Rndstr$ End Function end '************************************************************* 'File StringSort.bas written 26-07-2020 15:54:17 'matherp's StringSort for MM2 ported to CMM2 'StringSort ArrayOfStrings$(), NbrOfStrings, ElementLength CSUB StringSort 00000000 'stringsort B091B480 60F8AF00 607A60B9 E9D3687B 46132300 627B3301 637B2301 E9D368BB 46132300 E08D623B 637B2300 63BB2301 6BBBE083 FB026A7A 461AF303 441368FB 6BBB61FB 6A7A3B01 F303FB02 68FB461A 61BB4413 781A69FB 781B69BB BF284293 B2DB4613 69BB63FB 62FB3301 330169FB 230062BB E016633B 781A6AFB 781B6ABB D901429A 633B2301 781A6AFB 781B6ABB D202429A 33FFF04F 6AFB633B 62FB3301 33016ABB 6BFB62BB 63FA1E5A D0022B00 2B006B3B 6B3BD0E0 D1102B00 781A69BB 781B69FB D901429A 633B2301 781A69BB 781B69FB D202429A 33FFF04F 6B3B633B D1272B01 781A69FB 781B69BB BF384293 B2DB4613 6BFB63FB 63FB3301 62FB69BB 62BB69FB 6AFBE00F 75FB781B 781A6ABB 701A6AFB 7DFA6ABB 6AFB701A 62FB3301 33016ABB 6BFB62BB 63FA1E5A D1EA2B00 637B2301 33016BBB 6BBA63BB 429A6A3B AF77F6FF 2B006B7B AF6EF47F 3744BF00 F85D46BD 47707B04 End CSUB BTW. I am surprised that the CMM2 editor "?" to "PRINT" and the like (ie commands in lower case to upper case) no longer converted. I miss that because I'm lazy. ![]() ![]() Best regards Michael causality ≠correlation ≠coincidence |
||||
lizby Guru ![]() Joined: 17/05/2016 Location: United StatesPosts: 3309 |
can you provide a link to the original post/thread (or at least a listing of the C code you converted)? ~ Edited 2020-07-27 06:12 by lizby PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed |
||||
twofingers Guru ![]() Joined: 02/06/2014 Location: GermanyPosts: 1526 |
Hi lizby, sure, I can. This is the modified C-code (Peter's demo code from the latest MicroMite package) and my Make file: StringSort.zip My "Work" directory - thats all you need - to make the things clearer: 1. C-compiler 2. arm-gcc-link.ld (linker file) 3. ARMCFunctions.h (Header file for ARM CPU to include in your C-file) 4. armcfgenV142.bas (CSUB-converter/generator) 5. MMBasic for DOS (to run "armcfgenV142.bas") 6. Your Make file 7. (Notepad++) 8. ... your C-code To open a command window, hold down the Shift key and press the right mouse button. Open command window. Then simply enter "Make" plus the name of your C code file, eg "stringsort" plus> Enter <. Regards Michael Edited 2020-07-27 10:04 by twofingers causality ≠correlation ≠coincidence |
||||
lizby Guru ![]() Joined: 17/05/2016 Location: United StatesPosts: 3309 |
Thanks very much. PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed |
||||
lizby Guru ![]() Joined: 17/05/2016 Location: United StatesPosts: 3309 |
After some struggles with the path, I've made progress, but where does the file, "arm-gcc-link.ld" come from? C:\dl\micromite\CMM2\CSUB>make_for_stringsort stringsort Press any key to continue . . . \gccarm\bin\arm-none-eabi-ld: cannot open linker script file arm-gcc-link.ld: No such file or directory PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10067 |
First post on page one of the thread, 3rd link |
||||
lizby Guru ![]() Joined: 17/05/2016 Location: United StatesPosts: 3309 |
Ok, with stringsort.c, ran to completion and when merged with Michael's basic code, ran on the CMM2. I printed 50 strings to show that they were sorted. Thanks, Peter, and thanks, Michael. This is powerful. PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed |
||||
twofingers Guru ![]() Joined: 02/06/2014 Location: GermanyPosts: 1526 |
Hi, This is the CSUB for IntegerSort (Peters Integer "Shell Sort" for MicroMites). 'File IntegerSort.bas written 31-07-2020 01:26:41 CSUB IntegerSort INTEGER, INTEGER 00000000 ' B089B480 6078AF00 683B6039 2300E9D3 613B4613 61FB693B 69FBE040 E03961BB 00DB69BB 4413687A 2300E9D3 2302E9C7 617B69BB 697AE011 1AD369FB 687A00DB 697A4413 687900D2 E9D34411 E9C12300 697A2300 1AD369FB 697A617B 429A69FB 697ADB0D 1AD369FB 687A00DB E9D34413 E9D72300 42900102 0303EB71 697BDBDB 687A00DB E9D718D1 E9C12302 69BB2300 61BB3301 693B69BA DBC1429A 2B0069FB 3301DA00 61FB105B 2B0069FB BF00D1B5 3724BF00 F85D46BD 47707B04 End CSUB IntegerSort.zip It contains a test program and the C source (bug fixed). Sorting 3000 integers takes 6ms, 30000 takes 125ms. Regards Michael causality ≠correlation ≠coincidence |
||||
twofingers Guru ![]() Joined: 02/06/2014 Location: GermanyPosts: 1526 |
Hi all, this is the CSUB for quicksort of integers (Source: Rosetta code) #include "ARMCFunctions.h" // quicksort from rosetta stone void quicksort(long long A[], long long *nElements) { long len=*nElements; if (len < 2) return; long long pivot = A[len / 2]; long long i, j; for (i = 0, j = len - 1; ; i++, j--) { while (A[i] < pivot) i++; while (A[j] > pivot) j--; if (i >= j) break; long long temp = A[i]; A[i] = A[j]; A[j] = temp; } quicksort(A, i); quicksort(A + i, len - i); } CSUB ' File quicksort.bas written 01-08-2020 22:45:21 ' quicksort ArrayOfIntegers%(), MAXELEM% ' staring at element 0! CSUB quicksort INTEGER,INTEGER 00000000 'quicksort 4FB0E92D AF00B092 61396178 E9D3693B 46132300 6BFB63FB F3402B01 6BFB80A4 DA002B00 105B3301 697A00DB E9D34413 E9C72300 F04F230C F04F0200 E9C70300 6BFB2308 461A3B01 73E2EA4F 2310E9C7 E9D7E00A 1C512308 F14360B9 60FB0300 2302E9D7 2308E9C7 2308E9D7 00DB4613 4413697A 0100E9D3 230CE9D7 EB714290 DBE60303 E9D7E00B F1122310 603931FF 33FFF143 E9D7607B E9C72300 6C3B2310 697A00DB E9D34413 E9D72300 4290010C 0303EB71 E9D7DBE7 E9D70108 42902310 0303EB71 E9D7DA30 46132308 697A00DB E9D34413 E9C72300 6C3B230A 697A00DB E9D718D0 46132308 697A00DB E9D018D1 E9C12300 6C3B2300 697A00DB E9D718D1 E9C1230A E9D72300 F1122308 F1430A01 E9C70B00 E9D7AB08 F1122310 F14338FF E9C739FF E7938910 6BFBBF00 EA4F4618 E9D771E0 1A842308 0503EB61 4506E9C7 0320F107 69784619 FF5AF7FF 2308E9D7 00DB4613 4413697A 0218F107 46184611 FF4EF7FF BF00E000 46BD3748 8FB0E8BD End CSUB quicksort.zip It contains a test program and the C source. Sorting 3000 integers takes 4ms, 30000 takes 62ms. (400Mhz CMM2) That is a lot faster than Shell sort (for random integers). I tried also Comb sort (nCombsort.zip) and it is slower - 150ms for 30000 random integers -, slower than Quick sort and slower than Shell sort. *************************************************************** Here is again a list of Peters (old but useful) tutorials for CFunctions (for Micromites!): CFunctions - learning by example (1) CFunctions - learning by example (2) CFunctions - learning by example (3) CFunctions - learning by example (4) ********************************************************************** BTW Sasquatch wrote this nice code example:CMM2 Barnsley Fern CSUB version Regards Michael EDIT: @matherp Hi Peter, Is there an ns (nanosecond) timer like for the MicroMite 2)?: asm volatile("mtc0 %0, $9": "+r"(current_ticks)); Edited 2020-08-16 02:00 by twofingers causality ≠correlation ≠coincidence |
||||
GerryL Newbie ![]() Joined: 24/01/2019 Location: AustraliaPosts: 36 |
Hi twofingers, good stuff with the quicksort CSub, just on this shouldn't the last two lines of the source code be passing a pointer as the second parameter?, it compiles and runs OK if this is changed to pointers. I assume your final source code version does use pointers as it generates identical code to my altered source code. Gerry |
||||
twofingers Guru ![]() Joined: 02/06/2014 Location: GermanyPosts: 1526 |
Hi Gerry, you are right! ![]() At least now I know that this thread is of interest to some people. ![]() The corrected file: Quicksort.zip #include "ARMCFunctions.h" // quicksort from rosetta stone void quicksort(long long A[], long long *nElements) { long len=*nElements; if (len < 2) return; long long pivot = A[len / 2]; long long i, j, h; for (i = 0, j = len - 1; ; i++, j--) { while (A[i] < pivot) i++; while (A[j] > pivot) j--; if (i >= j) break; long long temp = A[i]; A[i] = A[j]; A[j] = temp; } h=len-i; quicksort(A, &i); quicksort(A + i, &h); } Kind regards Michael causality ≠correlation ≠coincidence |
||||
GerryL Newbie ![]() Joined: 24/01/2019 Location: AustraliaPosts: 36 |
Hi All, Attached is my prototype Windows application I use for creating CMM2 CSubs you may find useful as the C source code file to be converted can be in any folder and easily selected using the standard windows GUI. If wanted it will also send the created CSub to the CMM2 SD card over the console link, and if selected and you have a MMBasic file containing test code for the CSub it will append the just created CSub to the test code, send it and then automatically run it on the CMM2. Essentially it allows me to create and test CSubs without leaving the comfort of Windows. I can now efficiently lockup my CMM2 in half the time due to my bad CSubs. javascript:AddSmileyIcon(' ![]() Gerry CSub Gen Instructions.zip CSUBGen.zip ![]() |
||||
![]() ![]() ![]() ![]() |
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |