Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 14:45 02 May 2025 Privacy Policy
Jump to

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 : PicoMite V6.00.02 release candidates - all versions

     Page 33 of 35    
Author Message
twofingers
Guru

Joined: 02/06/2014
Location: Germany
Posts: 1519
Posted: 04:50pm 24 Apr 2025
Copy link to clipboard 
Print this post

I accidentally edited my answer.
causality ≠ correlation ≠ coincidence
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 7464
Posted: 05:51pm 24 Apr 2025
Copy link to clipboard 
Print this post

Bear in mind how big string arrays tend to get. They can use a lot of RAM. Adding two string arrays to make a third means finding space for all three. You would like some programming space left, wouldn't you?  ;)
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
twofingers
Guru

Joined: 02/06/2014
Location: Germany
Posts: 1519
Posted: 06:03pm 24 Apr 2025
Copy link to clipboard 
Print this post

Hi Mick, it's not the job of Array ADD to combine two arrays into a third. It's analogous to
MATH ADD in(), num ,out()

This adds the value 'num' to every element of the matrix in() and puts the
answer in out(). Works for arrays of any dimensionality of both integer and
float and can convert between. Setting num to 0 is optimised and is a fast way
of copying an entire array. in() and out() can be the same array.


Array ADD in$(), Str$, out$()

should add a string to each element of an array and store it in a new (or the old) array. Additionally, it would be a quick way to copy (STR$=""), delete (?), and fill (?) a string array.
Regards
Michael
causality ≠ correlation ≠ coincidence
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10000
Posted: 06:09pm 24 Apr 2025
Copy link to clipboard 
Print this post

I've updated RC18 if you want to download

Improves error detection in MID$ command
Improves error detection in INC command when using strings

Adds new command

ARRAY ADD in(), data, out()

Supports integers, floats AND strings
 
twofingers
Guru

Joined: 02/06/2014
Location: Germany
Posts: 1519
Posted: 06:30pm 24 Apr 2025
Copy link to clipboard 
Print this post

Peter, you scare me!    

Thanks a lot!
causality ≠ correlation ≠ coincidence
 
electricat

Senior Member

Joined: 30/11/2020
Location: Lithuania
Posts: 288
Posted: 07:29pm 24 Apr 2025
Copy link to clipboard 
Print this post

HDMI/USB/2350 RC17
@Peter,

Did not tested latest RC18 but as I found it in EDITOR it might be still here.Try this to replicate:
Inside editor type in any text. But at least one underscore '_' must be used.
asadasfsd_asdasasf


Now move using left or right arrows but you must pass that underscore '_' and you`ll notice underscore just dissapears. With more underscores even more fun effect
It`s only visual thing, does not saves F1.
Restores on screen redraws etc.
My MMBasic 'sand box'
 
bfwolf
Regular Member

Joined: 03/01/2025
Location: Germany
Posts: 68
Posted: 11:45am 25 Apr 2025
Copy link to clipboard 
Print this post

  javavi said  Hello Peter, Geoff and everyone who is in the know,
I'm just an amateur, maybe this is a stupid question but it's better to ask, so I'll ask here!
In my practice of programming in MMBASIC, in some cases I encountered the need to have Aliases for Variables.
For example, when I want to select one of the variables for subsequent typical processing in the algorithm.
1) ALIAS NAMES for VARIABLES
DIM A% = 123
DIM B% = 456
...
IF condition THEN ALIAS C = A% else ALIAC C = B%
...
...

To pass a value by reference to the C alias, just as it currently works when calling subroutines and functions.

2) ALIAS NAMES for ARRAYS with variable dimensions
DIM Arr2D%(100,1)
ALIAS Arr1%(100) = Arr2D%(100,0)
ALIAS Arr2%(100) = Arr2D%(100,1)
...
SORT Arr1%()

An array alias that can be assigned by reference to one of the fields of a multidimensional array, for example for processing with the SORT command.
For large volumes of processed arrays, we would like to avoid copying them for such processing, and work with an alias by reference.
Such aliases exist in other programming languages,
Is it possible to implement this in MMBASIC in the near future, of course?


Passing an array by reference to a subroutine works. This allows you to switch between arrays without having to copy the elements. Same for simple variables. This would eliminate the need for an "ALIAS":


Option Explicit

Sub AddArrVal(byref arr%() As integer)
 Local i As integer
 For i=1 To Bound(arr%())
   arr%(i) = arr%(i) + 3
 Next
End Sub

Dim MyArr%(10) As integer
Dim MyAr2%(10) As integer
Dim i% As integer

For i=1 To Bound(MyArr%())
 MyArr%(i) = i
Next
For i=1 To Bound(MyAr2%())
 MyAr2%(i) = i + 2
Next
AddArrVal(MyArr%())
AddArrVal(MyAr2%())
Print "Works as expected:"
For i=1 To Bound(MyArr%())
 Print MyArr%(i),
Next
Print
For i=1 To Bound(MyAr2%())
 Print MyAr2%(i),
Next
Print

Print "Fails as expected:"
Dim MyA2%(10,10) As integer
AddArrVal(MyA2%(1,))

End


Saved 596 bytes
> run
Works as expected:
4       5       6       7       8       9       10      11      12      13
6       7       8       9       10      11      12      13      14      15
Fails as expected:
[34] AddArrVal(MyA2%(1,))
Error : Dimensions
>


@Peter, Question:
Wouldn't an array anyway have been passed implicitly "byref," so that the "byref" could be omitted?
Of course, it's clearer and cleaner to enforce "byref" explicitly!

And to be clear: I don't expect that a multidimensional array, e.g. MyA2%(10,10), can be passed as a one-dimensional array (vector) by writing MyA2%(1,) (i.e., leaving the last index empty) - that was just an idea, because that's how it would work in C - but I expected it to be forbidden and generate an error message!
But perhaps MMBasic already has a builtin solution for this?
Edited 2025-04-25 21:49 by bfwolf
 
twofingers
Guru

Joined: 02/06/2014
Location: Germany
Posts: 1519
Posted: 01:36pm 25 Apr 2025
Copy link to clipboard 
Print this post

  matherp said  
  Quote  In addition to a mechanism for passing partial string arrays to subs.


For the avoidance of doubt - this will never happen


Regards
Michael
causality ≠ correlation ≠ coincidence
 
bfwolf
Regular Member

Joined: 03/01/2025
Location: Germany
Posts: 68
Posted: 04:19pm 25 Apr 2025
Copy link to clipboard 
Print this post

  twofingers said  
  matherp said  
  Quote  In addition to a mechanism for passing partial string arrays to subs.


For the avoidance of doubt - this will never happen


Regards
Michael


Was that referring to my previous post?

Didn't you read my paragraph at the end?: It was pretty clear to me that it doesn't work, and I don't expect it to work (in the future) either!
I also read Peter's post, which you quoted again, and I share his opinion. I tried it "just for fun" to see if it might work "accidentally."

But I figured out a workaround myself beforehand:


Option Explicit

Sub Add2nDimArrVal(byref arr%() As integer, byref ix%() As integer)
 Local i As integer, nD As Integer = 0, nDims As integer = 0
 Local ptr As integer

 i = 1
 Do
   nD = Bound(arr%(), i)
   If nD <> 0 Then
     nDims = nDims + 1 : i = i + 1
   EndIf
 Loop Until nD = 0

 'Print nDims

 For i=1 To Bound(arr%(), nDims)
   Select Case nDims
   Case 1
     ptr = Peek(VARADDR arr%(i))
   Case 2
     ptr = Peek(VARADDR arr%(ix%(1), i))
   Case 3
     ptr = Peek(VARADDR arr%(ix%(1), ix%(2), i))
   End Select
   ' Print ptr,
   Poke integer ptr, (Peek(integer ptr) + 3)
 Next
 Print
End Sub

Dim i As integer, j As integer
Const MyAD% = 2 ' nDims of MyA2%
Dim MyA2%(10,10) As integer
Dim MyAI%(MyAD%) As integer

Print "Works as hoped: :-D"

' Set index values of all dimensions before last dim:
MyAI%(1) = 5 ' : MyAI%(MyAD%) = 0

For j=1 To Bound(MyA2%(),1)
 For i=1 To Bound(MyA2%(),MyAD%)
   If j = MyAI%(1) Then
     MyA2%(j, i) = i + 10
   Else
     MyA2%(j, i) = 0
   EndIf
 Next
Next

Add2nDimArrVal(MyA2%(), MyAI%())

For i=1 To Bound(MyA2%(),MyAD%)
 Print MyA2%(MyAI%(1), i),
Next
Print

End


> run
Works as hoped: :-D

14      15      16      17      18      19      20      21      22      23
>


Regards, bfwolf
 
twofingers
Guru

Joined: 02/06/2014
Location: Germany
Posts: 1519
Posted: 04:37pm 25 Apr 2025
Copy link to clipboard 
Print this post

  bfwolf said  Was that referring to my previous post? ...

I was just worried that Peter might get the impression that they wanted to push the topic further. I think Peter put a lot of effort into it.

I appreciate your research! I don't have the opportunity to test everything at the moment, but I'm glad that the topic is being approached from different perspectives.

Basically, IMHO, Vadim's question (see FileManager thread) was about partially passing partial string arrays to a sub-routine for example, to be able to sort them there.

There seems to be agreement that arrays can only be passed by reference, how else?

By the way, the first parameter passed to a subroutine is never optional, but the others are.

Best regards
Michael
causality ≠ correlation ≠ coincidence
 
bfwolf
Regular Member

Joined: 03/01/2025
Location: Germany
Posts: 68
Posted: 05:03pm 25 Apr 2025
Copy link to clipboard 
Print this post

  twofingers said  I was just worried that Peter might get the impression that they wanted to push the topic further. I think Peter put a lot of effort into it.

Yes, I also know the big work, Peter is investing. And I think, one shouldn't blow up the language too much, if there is no "real need" for new language elements.

  twofingers said  I appreciate your research! I don't have the opportunity to test everything at the moment, but I'm glad that the topic is being approached from different perspectives.

Basically, IMHO, Vadim's question (see FileManager thread) was about partially passing partial string arrays to a sub-routine for example, to be able to sort them there.

Thx! Vadim's question inspired me.. Perhaps I've found a soulution for his problem?
And by playing with this, I found out, that with "ptr=Peek(VARADDR var)", "val=Peek(<TYPE> ptr)" and "Poke <TYPE> ptr, val" the C pointers can nearly completely substituted..

  twofingers said  There seems to be agreement that arrays can only be passed by reference, how else?

Yes! And this should remain, as is. Passing big arrays by value(s) leads to ugly performance and stack overflow danger!

  twofingers said  By the way, the first parameter passed to a subroutine is never optional, but the others are.

Thx again! Good hint! Didn't know it 'til now..

Regards, bfwolf
Edited 2025-04-26 03:06 by bfwolf
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10000
Posted: 08:27am 26 Apr 2025
Copy link to clipboard 
Print this post

I've just updated RC18 to include the new command

ARRAY SET data,array()

This works the same as MATH SET (see manual) but also now supports strings

e.g.

dim s$(9,9) length 20
array set "Whatever", s$()
? s$(8,8)
array set "", s$()
? s$(8,8)

Together with ARRAY ADD, ARRAY SLICE, and ARRAY INSERT you now have fast commands for doing most likely bulk manipulations with strings. In all cases see the equivalent MATH commands in the manual for details
Edited 2025-04-26 18:28 by matherp
 
twofingers
Guru

Joined: 02/06/2014
Location: Germany
Posts: 1519
Posted: 08:44am 26 Apr 2025
Copy link to clipboard 
Print this post

  matherp said  ... Together with ARRAY ADD, ARRAY SLICE, and ARRAY INSERT you now have fast commands for doing most likely bulk manipulations with strings. ...

I am very happy! Thanks!
Michael
causality ≠ correlation ≠ coincidence
 
toml_12953
Guru

Joined: 13/02/2015
Location: United States
Posts: 383
Posted: 05:10pm 26 Apr 2025
Copy link to clipboard 
Print this post

Since updating to 6.00.xx, the Del function on my I2C keyboard no longer works. Shift-Del does go to the end of the line but Del by itself doesn't work.
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10000
Posted: 05:59pm 26 Apr 2025
Copy link to clipboard 
Print this post

  Quote  the Del function on my I2C keyboard no longer works.


Which I2C keyboard?
 
toml_12953
Guru

Joined: 13/02/2015
Location: United States
Posts: 383
Posted: 07:06pm 26 Apr 2025
Copy link to clipboard 
Print this post

  matherp said  
  Quote  the Del function on my I2C keyboard no longer works.


Which I2C keyboard?


The one onboard the PicoCalc. Since Del worked in MMBasic v 5.xx and doesn't in 6.xx I was wondering if there was a change in keyboard handling.
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10000
Posted: 07:12pm 26 Apr 2025
Copy link to clipboard 
Print this post

Nothing I can help with. The solderparty keyboard which is the supported version works perfectly on V6.00.02RC17 - just tested
 
homa

Guru

Joined: 05/11/2021
Location: Germany
Posts: 451
Posted: 07:35pm 26 Apr 2025
Copy link to clipboard 
Print this post

I'm back from my short holiday. And I'm looking forward to testing again. If there are still so many great additions, will the textbuffer layer be added after all?  
 
toml_12953
Guru

Joined: 13/02/2015
Location: United States
Posts: 383
Posted: 01:15am 27 Apr 2025
Copy link to clipboard 
Print this post

  matherp said  Nothing I can help with. The solderparty keyboard which is the supported version works perfectly on V6.00.02RC17 - just tested


Thanks for checking, anyway. I finally figured out that a typical keyboard returns 0x7f for DEL but the PicoCalc returns 0xd4. It seems like the maker of PicoCalc patched the files to account for that but the people who are continuing the PicoCalc releases didn't
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 4244
Posted: 11:19am 27 Apr 2025
Copy link to clipboard 
Print this post

Hi Peter,

Not sure what has happened here, but I believe it is a regression:
> option list
PicoMite MMBasic RP2040 Edition V6.00.02RC18
OPTION SYSTEM SPI GP6,GP3,GP4
OPTION COLOURCODE ON
OPTION CPUSPEED (KHz) 252000
OPTION LCDPANEL CONSOLE
OPTION DISPLAY 20, 40
OPTION LCDPANEL ILI9341, RLANDSCAPE,GP2,GP1,GP0
OPTION TOUCH GP5,GP7
GUI CALIBRATE 0, 407, 267, 897, 677
OPTION SDCARD GP22
OPTION AUDIO GP20,GP21', ON PWM CHANNEL 2
OPTION MODBUFF ENABLE  192
OPTION PLATFORM Game*Mite

> list "wtf.bas"
Print de_format$("rtrue")
Function de_format$(a$)
 Local p, s$
 s$ = " "
 p = Len(a$) + 1
 Print "'" a$ "'"
 Print "'" s$ "'"
 Print p
 Cat s$, Left$(a$, p - 1)
 de_format$ = s$
End Function

> run "wtf.bas"
'rtrue'
' '
6
[10] Cat s$, Left$(a$, p - 1)
Error : String too long


Best wishes,

Tom
MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
     Page 33 of 35    
Print this page
The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025