Posted: 05:25am 07 Jun 2025 Copy link to clipboard
phil99 Guru
BYVAL appears not to adhere to that.
> LIST ' Test prog 1 Dim integer a=5, b=6, c=7 Print "a, b, c =";a;b;c test a,,c
Sub test(BYVAL a, BYVAL b, BYVAL c) If a = 5 Then a = 10 Print "In Sub a, b, c =";a;b;c EndIf End Sub
Print "After Sub a, b, c =";a;b;c > RUN a, b, c = 5 6 7 In Sub a, b, c = 10 6 7 After Sub a, b, c = 5 6 7 >
> LIST ' Test prog 1 Dim integer a=5, b=6, c=7 Print "a, b, c =";a;b;c test a,,c
Sub test(a, b, c) If a = 5 Then a = 10 Print "In Sub a, b, c =";a;b;c EndIf End Sub
Print "After Sub a, b, c =";a;b;c > RUN a, b, c = 5 6 7 In Sub a, b, c = 10 0 7 After Sub a, b, c = 5 6 7 >
BYVAL appears to be the default anyway.
Senility advancing. Edited 2025-06-07 16:01 by phil99
Posted: 06:29am 07 Jun 2025 Copy link to clipboard
JohnS Guru
Oops - looks like a bug in MMBasic!
(b should default to 0 in test.)
John
Posted: 07:13am 07 Jun 2025 Copy link to clipboard
matherp Guru
Oops - looks like a bug in MMBasic!
(b should default to 0 in test.)
No it isn't. You are just printing the value of a global variable which wasn't passed. Try
' Test prog 1 Dim integer a=5, b=6, c=7 Print "a, b, c =";a;b;c test a,,c
Sub test(BYVAL x%, BYVAL y%, BYVAL z%) If x% = 5 Then x% = 10 Print "In Sub x% y%, z% =";x%;y%;z% EndIf End Sub
Print "After Sub a, b, c =";a;b;c > RUN a, b, c = 5 6 7 In Sub a, b, c = 10 6 7 After Sub a, b, c = 5 6 7 >
Posted: 07:23am 07 Jun 2025 Copy link to clipboard
toml_12953 Guru
When calling a subroutine you can supply less than the required number of values and in that case the missing values will be assumed to be either zero or an empty string.
BYVAL appears not to adhere to that.
> LIST ' Test prog 1 Dim integer a=5, b=6, c=7 Print "a, b, c =";a;b;c test a,,c
Sub test(BYVAL a, BYVAL b, BYVAL c) If a = 5 Then a = 10 Print "In Sub a, b, c =";a;b;c EndIf End Sub
Print "After Sub a, b, c =";a;b;c > RUN a, b, c = 5 6 7 In Sub a, b, c = 10 6 7 After Sub a, b, c = 5 6 7 >
Oops - looks like a bug in MMBasic!
(b should default to 0 in test.)
John
It doesn't look like a bug to me. Variables that aren't passed are global unless declared as LOCAL. The variable b wasn't passed so it retained its value of 6. Try changing b in the sub and see what happens. It will have the changed value after exiting the sub.
Posted: 07:24am 07 Jun 2025 Copy link to clipboard
TassyJim Guru
If you use OPTION EXPLICIT
RUN a, b, c = 5 6 7 In Sub x% y%, z% = 10 [10] Print "In Sub x% y%, z% =";x%;y%;z% Error : Y is not declared >
Perhaps a warning in the manual to take care with empty parameters and BYVAL
Jim
Posted: 07:28am 07 Jun 2025 Copy link to clipboard
AlbertR Newbie
there should also be a different if the "AS INTEGER" is used
Option EXPLICIT Dim integer a a = 2 Print "a at start "a test1 Print "test without par:"a a = 2 test1(a) Print "test1: "a a = 2 test2(a) Print "test2: "a a = 2 test3(a) Print "test3: "a a = 2 test4(a) Print "test4: "a a = 2 test5(a) Print "test5: "a a = 2 test6(a) Print "test6: "a '------------------------------------ Sub test1( b ) If b = 2 Then b = 23 End Sub
Sub test2( b As integer ) If b = 2 Then b = 23 End Sub
Sub test3(byval b ) If b = 2 Then b = 23 End Sub
Sub test4(byval b As integer) If b = 2 Then b = 23 End Sub
Sub test5(byref b As integer) If b = 2 Then b = 23 End Sub
Sub test6(byref b ) If b = 2 Then b = 23 End Sub
>RUN a at start 2 test without par: 2 test1: 2 test2: 23 test3: 2 test4: 2 test5: 23 [23] test6(a) Error : BYREF requires same types: a
Posted: 11:38am 07 Jun 2025 Copy link to clipboard
JohnS Guru
Oops - looks like a bug in MMBasic!
(b should default to 0 in test.)
No it isn't. You are just printing the value of a global variable which wasn't passed. Try
' Test prog 1 Dim integer a=5, b=6, c=7 Print "a, b, c =";a;b;c test a,,c
Sub test(BYVAL x%, BYVAL y%, BYVAL z%) If x% = 5 Then x% = 10 Print "In Sub x% y%, z% =";x%;y%;z% EndIf End Sub
Print "After Sub a, b, c =";a;b;c > RUN a, b, c = 5 6 7 In Sub a, b, c = 10 6 7 After Sub a, b, c = 5 6 7 >
I don't see how that can print In Sub a, b, c = 10 6 7 as it should be In Sub x% y%, z% etc
But addressing the main issue: normally defining a SUB with parameters makes each of those parameters a sort of locally defined variable, so the original example would have both a global variable b and a parameter b. The parameter would in effect hide the global one.
It's OK if that is not how MMBasic is supposed to work but it is most unusual/odd.
John Edited 2025-06-07 21:38 by JohnS
Posted: 03:56pm 08 Jun 2025 Copy link to clipboard
mozzie Senior Member
G'day Peter,
Finally managed to read the EDID data from the two 7" 1024x600 displays here and decoded them, both totally different.
Searching around it appears there are as many settings for the 1024x600 displays as there are displays... and 800x480 looks like a similar situation.
Sadly, as you suggest, there is no real "standard" at this resolution.
With that in mind, would you consider the following:
A "HDMI USER" mode / resolution, with the parameters input by the user, I imagine this would require 2 sets: Mode 1 in monochrome with tiles Mode 2,3 or 4 in color.
This would require the user to do the calculations for the clock frequency and divider / PLL ratios to suit, thankfully a lot of the porch and blanking information is available in the datasheets.
Whilst this would not be for the beginner, a database could be formed with setting data for the more common displays from Waveshare / Buydisplay etc.
This does of course assume that the above is even possible.
Regards, Lyle.
Posted: 11:21am 09 Jun 2025 Copy link to clipboard
mozzie Senior Member
G'day, Another possible gremlin, can anyone else confirm?
Setting system I2C to "slow" or opening I2C/I2C2 at 100khz stops the "I2C check" and "List System I2C" functions from working.
This is on a different system with DS3231 RTC but shows the same symptoms. Also "I2C/I2C2 check" as example in previous post. Have tried from RC15-RC26 and same result.
Regards, Lyle.
Posted: 12:59pm 09 Jun 2025 Copy link to clipboard
phil99 Guru
Yes, similar result. Also manual doesn't mention MM.I2C can return 2. Reading a EEPROM it fails to read all the requested bytes, but maybe 100kHz is too slow for the EEPROM. Reads the full amount at 400kHz.
Posted: 01:30pm 09 Jun 2025 Copy link to clipboard
matherp Guru
I know why this is happening - will fix in the release
Posted: 05:38am 10 Jun 2025 Copy link to clipboard
phil99 Guru
In RC26
Reading a EEPROM it fails to read all the requested bytes, but maybe 100kHz is too slow for the EEPROM. Reads the full amount at 400kHz
Did a proper count of the bytes returned at 400kHz and the maximum is 82 out of 128 the remainder are NUL. In RC19 I got all requested bytes. Edited 2025-06-10 16:03 by phil99
Posted: 07:18am 10 Jun 2025 Copy link to clipboard
matherp Guru
Reading a EEPROM it fails to read all the requested bytes, but maybe 100kHz is too slow for the EEPROM. Reads the full amount at 400kHz
Code for me to test with?
Posted: 08:03am 10 Jun 2025 Copy link to clipboard
phil99 Guru
This writes and reads all pages on a 24C32. If you don't want write to them all reduce For n = 0 To 127 to 4 or more. If you already have data on the EEPROM just use :- Sub Read_24C32_All ' Read all data from 24C32 EEPROM at the bottom.
Edit. It uses System I2C.
24C32 EEPROM tester 2.bas ' Test program to fill a 24C32 EEPROM with 128 x 32 byte pages. Dim Integer n, dummy, I2C.addr, Mem.addr Dim D$, R$, txt$
For n = &H50 To &H58 'find the I2C address - if more than one the first or last can be used I2C CHECK n If Not MM.I2C Then ' test for slave response. 1 = no response I2C.addr = n Print "&H";Hex$(I2C.addr), EndIf Next Print
' Write to all pages on 24C32 EEPROM Print "Assembled I2C data, including the 2 pointer address bytes."
For n = 0 To 127 'make 32 byte pages Mem.addr = n * 32 'set the memory pointer D$ = "<-ptr A="+Str$(Mem.addr,4)+", Page "+Str$(n,3)+", A="+Str$(Mem.addr+31,4)+"->" 'make a page D$ = Chr$(Mem.addr>>8) + Chr$(Mem.addr And 255) + D$ 'Add 2 byte Mem. address to the start of the Data' I2C WRITE I2C.addr,0,Len(D$),D$ 'write 2 memory address bytes + data bytes For m=1 To 34 : If Asc(Mid$(D$,m,1))<32 Or Asc(Mid$(D$,m,1))>127 Then : MID$(D$,m,1)="." : EndIf : Next Print d$+" "; :If n Mod 4 = 3 Then :Print :EndIf 'show the pages written, non-ASCII characters shown as "." Pause 6 'allow time to write Next
Print :Print :Print "Data read from EEPROM" Read_24C32_All
Sub Read_24C32_All ' Read all data from 24C32 EEPROM Mem.addr = 0 : I2C WRITE I2C.addr, 0, 2, Mem.addr >> 8, Mem.addr And 255 'return the pointer to 0 For n = 0 To 31 I2C read I2C.addr, 0, 128, R$ 'print all data, 4 pages per line, showing non-ASCII characters as "." For m=1 To 32 : If Asc(Mid$(R$,m,1))<32 Or Asc(Mid$(R$,m,1))>127 Then : MID$(R$,m,1)="." : EndIf : Next Print R$ Next End Sub
End
Edited 2025-06-10 18:07 by phil99
Posted: 08:12am 10 Jun 2025 Copy link to clipboard
matherp Guru
I'm getting reams of output. How do I know if it has worked?
It looks like you are only getting 52 characters out of 128 per line. As the EEPROM address pointer stops incrementing at the point where it stops reading the next 128 byte read starts where the last finished but once again stops short so the last half of it doesn't get read. The last page shown is 52 out of 128 that were written. Edited 2025-06-10 18:38 by phil99
Posted: 08:43am 10 Jun 2025 Copy link to clipboard
matherp Guru
Any chance of a simpler program?
Posted: 08:47am 10 Jun 2025 Copy link to clipboard
phil99 Guru
Ok I will start on it after dinner. The <- and -> point to the start and end of each 32 byte page and the A= is the byte address at the start and end. Edited 2025-06-10 18:51 by phil99
Page 51 of 52
The Back Shed's forum code is written, and hosted, in Australia.