Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.
|
Forum Index : Microcontroller and PC projects : CMM2: V5.05.06RC1
Page 3 of 4 | |||||
Author | Message | ||||
LeoNicolas Guru Joined: 07/10/2020 Location: CanadaPosts: 445 |
Peter It's much better with this keyboard config. Thank you |
||||
vegipete Guru Joined: 29/01/2013 Location: CanadaPosts: 1083 |
Something slightly odd appears to happen when a program ends if the font has been changed. mode 1,8 cls box 300,0,400,100 font 5 print "123456" pause 1000 end Watch closely. The image on screen scrolls downwards when the test program ends. If you comment out "font 5", nothing moves. The size of the scroll depends on the size of the particular font. If you change back to font 1 before ending, nothing moves. Visit Vegipete's *Mite Library for cool programs. |
||||
thwill Guru Joined: 16/09/2019 Location: United KingdomPosts: 3848 |
May be a bug, may be a cheap USB keyboard, run the following: Do If keydown(0) > 0 Then Print keydown(0); For i = 1 To keydown(0) Print keydown(i); Next i EndIf Loop If I hold down Q,W,E,R then I get the output: 4, 113, 119, 101, 114 But if I hold down R,T,Y then is starts registering 0 keysdown and reports nothing. T,Y works, but T,Y,U doesn't. Also isn't there a potential race condition with keydown() if keys are pressed and released quickly enough between calls ? Best wishes, Tom Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
TassyJim Guru Joined: 07/08/2011 Location: AustraliaPosts: 5913 |
GUI CURSOR colour. Running the test program, if you end the program while the red cursor is showing, the next run of the program will start with a red cursor. It looks like, if you just run "GUI CURSOR ON" instead of "GUI CURSOR ON 0,x,y" the last colour is used, even surviving a restart. Perhaps program start should default to white. 'mouse and cursor test CLS MODE 1 GUI CURSOR ON CONTROLLER MOUSE OPEN 2, leftclick, rightclick SETTICK 20, myint DO : LOOP UNTIL INKEY$ <> "" ' GUI CURSOR OFF CONTROLLER MOUSE CLOSE 2 END SUB myint GUI CURSOR MOUSE(x,2),MOUSE(y,2) END SUB ' SUB leftclick STATIC INTEGER n LOCAL INTEGER x=MOUSE(x,2),y=MOUSE(y,2) GUI CURSOR OFF GUI CURSOR ON 1,x,y, RGB(RED) n=n+1 PRINT @(100,100)"left",n END SUB ' SUB rightclick STATIC INTEGER n=0 LOCAL INTEGER x=MOUSE(x,2),y=MOUSE(y,2) GUI CURSOR OFF GUI CURSOR ON 0,x,y n=n+1 PRINT @(200,100)"Right",n END SUB Jim VK7JH MMedit  MMBasic Help |
||||
twofingers Guru Joined: 02/06/2014 Location: GermanyPosts: 1133 |
Bug report regarding SORT() for integers (MMBASIC v5.05.06RC2) Hi Peter, I think there is a less important issue with SORT() for integers (maybe other sorting functions too?). If the number of elements exceeds 2 ^ 16 - 1, the program crashes. Maybe the manual should mention the limit? FYI: My new quicksort CSUB is working correctly now and sorts an array with up to ~260000 (262132=4*&HFFFF-8) elements in 435ms. So far I haven't been able to figure out why it crashes too over this number (recursion?) ' Usage: Quicksort ArrayOfIntegers%(), NumberOfIntegers ' Sort starts at element 0 ' Based on Quicksort @ Rosetta code ' Limit: 262132 elements 'File quicksort.bas written 22-10-2020 01:06:04 CSUB quicksort INTEGER,INTEGER 00000000 'quicksort 4FF0E92D 7800E9D1 2F02B089 F1789000 E9CD0100 DB5B7802 24000879 32FFF117 01C1EB00 F14846A2 46A333FF 46A63808 94059404 6700E9D1 4502E9F0 EB7542B4 DB260107 EB019900 E9DC0CC2 45468900 0109EB77 F112DA11 99003CFF EB019001 F11201CC 468C32FF 8902E871 33FFF143 EB774546 DBF40009 45929801 0103EB7B F112DA0E F14332FF E9C033FF E9CC8900 F11A4500 F04F0A01 F14B0E01 E7CB0B00 0F00F1BE E9CDD001 E9DDAB04 A9044502 020AEBB4 EB659C00 4620030B 2306E9CD FF9EF7FF A9069804 00C0EB04 FF98F7FF E8BDB009 BF008FF0 End CSUB Regards Michael |
||||
vegipete Guru Joined: 29/01/2013 Location: CanadaPosts: 1083 |
Could the built-in mouse pointers be changed slightly to improve visibility? The center of the pointer could be black instead of transparent. The cross hair could have a black perimeter, and the very center pixel could be transparent. ======== Hopefully more than 1 user defined pointer is possible too. For example, two players might each have a mouse, requiring two different pointers. Visit Vegipete's *Mite Library for cool programs. |
||||
matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 8592 |
Will fix Thanks - will fix Pixels can't be black as that is the transparent colour Edited 2020-10-22 17:09 by matherp |
||||
twofingers Guru Joined: 02/06/2014 Location: GermanyPosts: 1133 |
Hi Peter, I have to report that the MMBasic SORT for string arrays also has a problem. This test program occasionally crashes. The larger the array or the MAX_LENGTH of the string, the more frequently it occurs. 'Stringsort for CMM2 (5.05.06RC2/400MHz) - test program option base 0 option explicit CONST LF$ =chr$(10) DIM INTEGER MAX_ARRAY =1000 DIM INTEGER MAX_LENGTH= 30 DIM S$(MAX_ARRAY) LENGTH MAX_LENGTH DIM temp$ DIM INTEGER N(MAX_ARRAY),i,j,ts PRINT "Creating"MAX_ARRAY" random strings ..." FOR j = 1 TO 100 FOR i = 3 TO MAX_ARRAY-1 S$(i) = RNDSTR$(MAX_LENGTH) NEXT i TIMER = 0 Sort S$(), N() ts=TIMER temp$=S$(0) FOR i = 0 TO MAX_ARRAY-1 PRINT S$(i),temp$,N(i),j IF S$(i)<temp$ THEN PRINT "Sorting Error at element " i:END temp$=S$(i) NEXT i PRINT LF$ "Array successfully sorted!" ts "ms for " MAX_ARRAY " elements" NEXT J END '************************************************************* ' create a random string Function Rndstr$(s_len as integer) as string LOCAL i FOR i = 1 TO s_len Rndstr$=Rndstr$+CHR$(65+(RND*25)) NEXT i End Function The SORT for floats works also only below &HFFFF elements. System: CMM2/400MHz/MMBASIC 5.05.06RC2 Kind regards Michael |
||||
matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 8592 |
The latest experimental version has fixes for the SORT command and the BOX command (bug when the border and fill colours are the same) |
||||
twofingers Guru Joined: 02/06/2014 Location: GermanyPosts: 1133 |
Thanks, Peter! My system: MMBasic 5.05.06EXP (23.10.2020)/400 MHz/Option RAM Sort for integers now works stable for up to 229,374 elements (with=2950ms/without indexarray=1150ms). For arrays >229,374 (&H37FFE) elements (with/without indexarray) I get occasionally crashes. The sorting time without indexarray increases up to 3316ms (from 1150ms for one element less). Sort for floats now works stable for up to ~240,000 elements (with=2850ms/without indexarray=1320ms). With 500,000 elements (without index array), crashes will almost certainly occur. My Quicksort for integers (without index array!) works perfectly now after I included the RoutineChecks-routine (580000 integers in 1200ms). Thanks for the hint! BTW. Can you please describe the conditions when the "RoutineChecks"-routine should/must be used? Are there guidelines? #include "ARMCFunctions.h" // quicksort from rosetta stone void quicksort(long long A[], unsigned long long *nElements) { unsigned long long len=*nElements; // or uint64_t if (len < 2) return; unsigned long long pivot = A[len / 2]; unsigned long long i, j, h; unsigned long long temp; for (i = 0, j = len - 1; ; i++, j--) { while (A[i] < pivot) i++; while (A[j] > pivot) j--; if (i >= j) break; temp = A[i]; A[i] = A[j]; A[j] = temp; } h=len-i; RoutineChecks(); quicksort(A, &i); quicksort(A + i, &h); } 'File quicksort_2.bas written 24-10-2020 02:15:12 CSUB quicksort_2 INTEGER, INTEGER 00000000 'quicksort 4FF0E92D 4500E9D1 2D00B089 BF089001 E9CD2C02 D35C4502 F1140861 F04F32FF EB000400 F14501C1 46A233FF 380846A3 940446A6 E9D19405 E9F06700 42BD4502 42B4BF08 9901D323 0CC2EB01 8900E9DC BF08454F D20E4546 3CFFF112 01CCEB01 32FFF112 E871468C F1438902 454F33FF 4546BF08 459BD3F4 4592BF08 F112D20E F14332FF E9C033FF E9CC8900 F11A4500 F04F0A01 F14B0E01 E7CE0B00 0F00F1BE E9CDD001 E9DDAB04 4B0B4502 010AEBB4 EB65681B 9106020B 47989207 A9049C01 F7FF4620 9804FF9D EB04A906 F7FF00C0 B009FF97 8FF0E8BD 0800033C End CSUB I haven't finished testing the string sort yet. It is noticeable that it appears extremely slow for large amounts of data. Much more than expected. Kind regards Michael Edited 2020-10-24 10:58 by twofingers |
||||
vegipete Guru Joined: 29/01/2013 Location: CanadaPosts: 1083 |
Does that mean the 2 built-in cursors are mono-chrome? Only transparent and white pixels where white is changeable with the GUI CURSOR COLOUR command? Visit Vegipete's *Mite Library for cool programs. |
||||
twofingers Guru Joined: 02/06/2014 Location: GermanyPosts: 1133 |
Hi Peter, unfortunately I have to inform you that the CMM2 string sort is technically unusable. A minor bug eats the biggest string and sets the first value to zero length. EDIT: The same bug bothers "float" and "integer". Creating 10 random strings ... 0>00000000< 1>11111111< 2>22222222< 3>33333333< 4>44444444< 5>55555555< 6>66666666< 7>77777777< 8>88888888< 9>99999999< Sorting ... (output) 0>< 0 1>00000000< 8 2>11111111< 8 3>22222222< 8 4>33333333< 8 5>44444444< 8 6>55555555< 8 7>66666666< 8 8>77777777< 8 9>88888888< 8 It should more look like this, obviously: Creating 10 random strings ... 0>00000000< 1>11111111< 2>22222222< 3>33333333< 4>44444444< 5>55555555< 6>66666666< 7>77777777< 8>88888888< 9>99999999< Sorting ... 0>00000000< 8 1>11111111< 8 2>22222222< 8 3>33333333< 8 4>44444444< 8 5>55555555< 8 6>66666666< 8 7>77777777< 8 8>88888888< 8 9>99999999< 8 My system: CMM2 MMBasic 5.05.06EXP (23.10.2020)/400 MHz/Option RAM Test code: 'Stringsort for CMM2 (5.05.06RC2/400MHz) - test program option base 0 option explicit CONST LF$ =chr$(10) DIM INTEGER MAX_ARRAY =10 DIM INTEGER MAX_LENGTH= 8 DIM S$(MAX_ARRAY) LENGTH MAX_LENGTH DIM temp$ DIM INTEGER N(MAX_ARRAY),i,j,ts PRINT "Creating"MAX_ARRAY" random strings ..." FOR i = 0 TO MAX_ARRAY-1 S$(i) = RNDSTR$(MAX_LENGTH) PRINT i">"s$(i)"<":' if i >10 then end NEXT i PRINT "Sorting ..." TIMER = 0 ' Sort S$() ', N()' 1233s/66000 elements/random strings '1430s/66000 elements/sorted strings StringSort S$(), MAX_ARRAY,MAX_LENGTH '870s/66000 elements/random strings '0.052s/66000 elements/sorted strings ts=TIMER temp$=S$(0) FOR i = 0 TO MAX_ARRAY-1 PRINT i">"S$(i)"<"len(s$(i)) IF S$(i)<temp$ THEN PRINT "Sorting Error at element " i:END temp$=S$(i) NEXT i PRINT LF$ "Array successfully sorted!" ts "ms for " MAX_ARRAY " elements" END '************************************************************* ' create a random string Function Rndstr$(s_len as integer) as string LOCAL integer ii 'FOR ii = 1 TO s_len:Rndstr$=Rndstr$+CHR$(65+(RND*25)):NEXT ii 'random string FOR ii = 1 TO s_len:Rndstr$=Rndstr$+CHR$(48+i):NEXT ii 'Presorted string End Function 'File StringSort.bas written 25-10-2020 00:37:15 CSUB StringSort STRING, INTEGER, INTEGER 00000000 'stringsort 4FF0E92D B0912300 26014683 27009308 33016813 E9D19305 E9CD2300 E9DD2302 429F2302 4296BF08 80B9F080 F11646B0 9B0530FF FB033601 F147F808 FB030700 F81BB000 23009008 A000F890 0C08EB0B 45D14649 4651BF28 F112B2CA F14334FF 290035FF 80B2F000 46614686 F81E9000 F8112F01 429A3F01 EA54D3D1 F0000005 F11480A1 F14534FF 429A35FF 9800D0EF 0204F108 F10045CA 445A0304 46CABF38 0900F04F BF38459C FA5F4290 F0C0F88A F1BA8091 F2400F04 F118808D 46E60301 930A4601 0300F149 F1B8930B F1490303 089B32FF 7382EA43 0A92EA4F 33012200 F14A9306 93070300 E9CD2300 E9CD6700 E9CD4508 4665890E 460746D9 AB06E9DD 68083201 C000F8DE 0300F143 CB04F841 F84E455B BF080B04 D3F14552 46CB9907 46AC4638 9906008B 890EE9DD EA43008A EBB87391 44100102 910C4494 0103EB69 890AE9DD 6700E9DD 910D4599 4590BF08 7803D01C 2000F89C 890CE9DD F88C7002 EA583000 D0110309 F89C7843 70422001 F88C4642 464B3001 BF082B00 D0052A01 F89C7883 70822002 3002F88C 93082301 2302E9DD BF08429F F4FF4296 4B1BAF47 4798681B B3739B08 2302E9DD BF082B00 D3222A02 F8DD2300 46588014 27002602 E73E9308 9800429A AF62F47F F4BF45D1 E75DAF26 F1183801 F81038FF F89C3F01 F1492000 700239FF 3FFFF1B9 3B01F80C F1B8BF08 D1EE3FFF 4B04E7C8 B011681B 4FF0E8BD B0114718 8FF0E8BD 0800033C End CSUB ------------------ About speed: The CMM2 Sort (without indexarray) needs 1233s/66000 elements for random strings and 1430s/66000 elements for (pre-)sorted strings. The CSUB StringSort needs 870s/66000 elements for random strings and 0.052s/66000 elements for (pre-)sorted strings. Kind regards Michael Edited 2020-10-26 00:51 by twofingers |
||||
matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 8592 |
Unfortunately you have fallen into the array dimension trap. How many elements are there in an array declared? OPTION BASE 0 DIM array(10) |
||||
twofingers Guru Joined: 02/06/2014 Location: GermanyPosts: 1133 |
Thanks Peter. I'm relieved! OPTION BASE 0 DIM array(10) My best guess? 11. You are correct, my fault! Sorry. I know that you are currently under heavy strain! Not completely (for MMBasic 5.05.06EXP (23.10.2020))! Crashes still occur with arrays larger than 4 * & Hffff. For the CSUB Integersort and stringsort, the inclusion of the RoutineChecks() helped. As I asked above: Can you please describe the conditions when the "RoutineChecks"-routine should/must be used? Are there guidelines? Many thanks! Michael |
||||
matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 8592 |
Can you please describe the conditions when the "RoutineChecks"-routine should/must be used? Are there guidelines? Every millisecond of processing is a good starting point. For CSUBs that take less than 1 mSec it can be omitted. It does four things: Pokes the watchdog if required Checks for SDcard presence polls the USB port Updates sound buffers if any music playing In all cases it will return immediately if nothing to be done so the overhead is very small Try the latest posted. Also if you are doing serial output as in your earlier example you are filling the output TX buffer which is then blocking and serial I/O is still happening when you start the next sort - try waiting for output to stop I've just sorted 600,001 random floats on a 400MHz processor which took 4.57 seconds dim a(600000) for i=0 to 600000 a(i)=rnd next i timer=0 sort a() ? timer Edited 2020-10-26 04:15 by matherp |
||||
twofingers Guru Joined: 02/06/2014 Location: GermanyPosts: 1133 |
Every millisecond of processing is a good starting point. For CSUBs that take less than 1 mSec it can be omitted. It does four things: Pokes the watchdog if required Checks for SDcard presence polls the USB port Updates sound buffers if any music playing In all cases it will return immediately if nothing to be done so the overhead is very small Thanks Peter, that helped a bit, makes it clearer. But it doesn't explain why a routine crashes that doesn't use any of the four things you're describing. Try the latest posted. EDIT: I loaded 2020-10-26_001301_CMM2V1.5.zip (5.05.06RC6) into my CMM2 and ran your little test code. Result: RUN Error: System fault - possible causes - Incorrect use of POKE - Faulty CSUB - Reserved words used as variables - Firmware problem > RUN 4588.915 > RUN Error: System fault - possible causes - Incorrect use of POKE - Faulty CSUB - Reserved words used as variables - Firmware problem > RUN Error: System fault - possible causes - Incorrect use of POKE - Faulty CSUB - Reserved words used as variables - Firmware problem > RUN Error: System fault - possible causes - Incorrect use of POKE - Faulty CSUB - Reserved words used as variables - Firmware problem > RUN Error: System fault - possible causes - Incorrect use of POKE - Faulty CSUB - Reserved words used as variables - Firmware problem > RUN 4573.616 > RUN Error: System fault - possible causes - Incorrect use of POKE - Faulty CSUB - Reserved words used as variables - Firmware problem > RUN Error: System fault - possible causes - Incorrect use of POKE - Faulty CSUB - Reserved words used as variables - Firmware problem > RUN 4562.95 > RUN Error: System fault - possible causes - Incorrect use of POKE - Faulty CSUB - Reserved words used as variables - Firmware problem > RUN 4495.262 Edited 2020-10-26 06:17 by twofingers |
||||
twofingers Guru Joined: 02/06/2014 Location: GermanyPosts: 1133 |
Bad news! This test code for integer sort dim integer a(600000) do for i=0 to 600000 a(i)=rnd*200000 next i timer=0 sort a() ? timer loop end results in occasional, fairly frequent crashes.. CMM2 MMBasic 5.05.06RC6/400 MHz/Option FLASH Edited 2020-10-26 08:38 by twofingers |
||||
matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 8592 |
I'm not quite sure the point of using all the memory for a single array and sorting it however it is easily fixed by moving the routinechecks() call to the inner loop. I'll be posting a new experimental version later today but I want to get to the bottom of a nasty BLIT issue when both pages are in SDRAM and the move isn't word aligned first Edited 2020-10-27 02:05 by matherp |
||||
twofingers Guru Joined: 02/06/2014 Location: GermanyPosts: 1133 |
Thanks, Peter! I don't know if that helps (probably not), anyway this is the code for the CSUB StringSort (made by Matherp) that worked for me with no problems and minimal loss of speed. Just for comparing purposes. #include "ARMCFunctions.h" // function to sort an array of strings // StringSort ArrayOfStrings$(), NbrOfStrings, ElementLength void stringsort(unsigned char *sarray, long long *nstring, long long *maxlength){ unsigned long long i, ii, n=*nstring; int s=1, k, offset=*maxlength+1; unsigned char *s1,*s2,*p1,*p2; unsigned char temp; while (s){ s=0; for(i=1;i<n;i++){ s2=i*offset+sarray; s1=(i-1)*offset+sarray; ii = *s1 < *s2 ? *s1 : *s2; //get the smaller length p1 = s1 + 1; p2 = s2 + 1; k=0; //assume the strings match while((ii--) && (k==0)) { if(*p1 > *p2){ k=1; //earlier in the array is bigger } if(*p1 < *p2){ k=-1; //later in the array is bigger } p1++; p2++; } // if up to this point the strings match // make the decision based on which one is shorter if(k==0){ if(*s1 > *s2) k=1; if(*s1 < *s2) k=-1; } if (k==1){ // if earlier is bigger swap them round ii = *s1 > *s2 ? *s1 : *s2; //get the bigger length ii++; p1=s1;p2=s2; while(ii--){ temp=*p1; *p1=*p2; *p2=temp; p1++; p2++; } s=1; } } RoutineChecks(); } } Michael |
||||
matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 8592 |
Try the latest code just posted on the performance gains thread - should be fixed in that |
||||
Page 3 of 4 |
Print this page |