QB64.org Forum

Active Forums => Programs => Topic started by: bplus on January 31, 2022, 01:30:22 pm

Title: A Replacement Method for Data Statements
Post by: bplus on January 31, 2022, 01:30:22 pm
Welcome @MrGW454

I saw you difficulty on Discord, here is alternate to DATA statements

Code: QB64: [Select]
  1. _Title "Replacement Method for Data statements" 'b+ 2022-01-31
  2.  
  3. 'our Data as string(s)
  4. dat$ = "bplus,SMcNeill,FellippeHeitor,vince,"
  5. dat$ = dat$ + "Qwerkey,Ashish,Luke,RCcola87,MrGW454"
  6.  
  7. 'Load into this array
  8. ReDim members$(1 To 1) ' use REDIM for dynamic array that we can change size of
  9. Split dat$, ",", members$() ' Load data into members$()
  10.  
  11. 'Show it worked
  12. For i = 1 To UBound(members$)
  13.     Print members$(i)
  14.  
  15. ' note: I buggered this twice now, FOR base 1 array REDIM MyArray (1 to 1) AS ... the (1 to 1) is not same as (1) which was the Blunder!!!
  16. 'notes: REDIM the array(0) to be loaded before calling Split '<<<< IMPORTANT dynamic array and empty, can use any lbound though
  17. 'This SUB will take a given N delimited string, and delimiter$ and create an array of N+1 strings using the LBOUND of the given dynamic array to load.
  18. 'notes: the loadMeArray() needs to be dynamic string array and will not change the LBOUND of the array it is given.  rev 2019-08-27
  19. Sub Split (SplitMeString As String, delim As String, loadMeArray() As String)
  20.     Dim curpos As Long, arrpos As Long, LD As Long, dpos As Long 'fix use the Lbound the array already has
  21.     curpos = 1: arrpos = LBound(loadMeArray): LD = Len(delim)
  22.     dpos = InStr(curpos, SplitMeString, delim)
  23.     Do Until dpos = 0
  24.         loadMeArray(arrpos) = Mid$(SplitMeString, curpos, dpos - curpos)
  25.         arrpos = arrpos + 1
  26.         If arrpos > UBound(loadMeArray) Then ReDim _Preserve loadMeArray(LBound(loadMeArray) To UBound(loadMeArray) + 1000) As String
  27.         curpos = dpos + LD
  28.         dpos = InStr(curpos, SplitMeString, delim)
  29.     Loop
  30.     loadMeArray(arrpos) = Mid$(SplitMeString, curpos)
  31.     ReDim _Preserve loadMeArray(LBound(loadMeArray) To arrpos) As String 'get the ubound correct
  32.  
  33.  
Title: Re: A Replacement Method for Data Statements
Post by: MrGW454 on January 31, 2022, 02:17:00 pm
I really appreciate the follow up on this and the helpful suggestion/example.

Is this an official open bug for QB64 right now?

Thanks!
Title: Re: A Replacement Method for Data Statements
Post by: bplus on January 31, 2022, 02:19:29 pm
I really appreciate the follow up on this and the helpful suggestion/example.

Is this an official open bug for QB64 right now?

Thanks!

No bug really, Data statements work everywhere except where you tried it in a Pi apparently.
Title: Re: A Replacement Method for Data Statements
Post by: George McGinn on February 01, 2022, 12:06:09 pm
I have DATA statements working on ARM processors, including the Raspberry PI.

I am testing changes to the QB64 install script that will detect whether or not it is being installed on a ARM or RPI, change the required files and download the prerequisite libraries, which does not occur now.

If you want to test this script on your RPI, let me know and I will post a copy of it here.

The only issue I am running into is getting InForm to run on an ARM processor. QB64 so far is fine.
 

No bug really, Data statements work everywhere except where you tried it in a Pi apparently.
Title: Re: A Replacement Method for Data Statements
Post by: bplus on February 01, 2022, 12:11:38 pm
Be really cool getting QB64 working on those devices.

I checked out a Pi a couple years ago, the screen was smaller than a phone's, not going to work with old eyes!, I returned the kit and appreciate my laptop all the more!

But that kind of thing is the base of young computer hobbyists for today!
Title: Re: A Replacement Method for Data Statements
Post by: MrGW454 on March 09, 2022, 12:46:36 pm
I have DATA statements working on ARM processors, including the Raspberry PI.

I am testing changes to the QB64 install script that will detect whether or not it is being installed on a ARM or RPI, change the required files and download the prerequisite libraries, which does not occur now.

If you want to test this script on your RPI, let me know and I will post a copy of it here.

The only issue I am running into is getting InForm to run on an ARM processor. QB64 so far is fine.

Hi George,

I would appreciate it if you could share the solution for getting DATA statements working on a Raspberry Pi.  I'm happy to test and post my results.

Thank you!
Title: Re: A Replacement Method for Data Statements
Post by: tomxp411 on March 09, 2022, 02:26:07 pm
No bug really, Data statements work everywhere except where you tried it in a Pi apparently.

I actually found a but in the READ statement that was fixed within an hour of me reporting it. @MrGW454 if you are not running the latest version, you'll want to compile from source. If you have a packaged binary, you may still have the bug, since there has not been an official release since then. Meaning you would still have the bug where READ sometimes grabs the last line of source code, rather than the correct DATA value.

Also... could you post the original Discord message, so we know what the actual problem is?
Title: Re: A Replacement Method for Data Statements
Post by: bplus on March 09, 2022, 02:31:24 pm
I actually found a but in the READ statement that was fixed within an hour of me reporting it. @MrGW454 if you are not running the latest version, you'll want to compile from source.

Also... could you post the original Discord message, so we know what the actual problem is?

Ha! you can't blame him if I started thread.

I didn't know bug was fixed so quickly what was it?
Title: Re: A Replacement Method for Data Statements
Post by: tomxp411 on March 09, 2022, 02:33:17 pm
Be really cool getting QB64 working on those devices.

I checked out a Pi a couple years ago, the screen was smaller than a phone's, not going to work with old eyes!, I returned the kit and appreciate my laptop all the more!

But that kind of thing is the base of young computer hobbyists for today!

You probably got one of the handheld portable kits. The Pi is designed to use any HDMI display, so you can use it on any modern TV or computer monitor.
Title: Re: A Replacement Method for Data Statements
Post by: MrGW454 on March 09, 2022, 03:15:57 pm
I actually found a but in the READ statement that was fixed within an hour of me reporting it. @MrGW454 if you are not running the latest version, you'll want to compile from source. If you have a packaged binary, you may still have the bug, since there has not been an official release since then. Meaning you would still have the bug where READ sometimes grabs the last line of source code, rather than the correct DATA value.

Also... could you post the original Discord message, so we know what the actual problem is?

I'll grabbed the latest source and compile.

Here's the link to the message I left on Discord:

https://discord.com/channels/592061709485735966/592061709485735974/937745171163017226

.. and here's the message text:

Code: QB64: [Select]
  1. [10:24 AM] MrGW454: Hello - not sure if this is the correct place to ask for assistance with QB64 compiler issues.
  2.  
  3. I have a BASIC program that compiles fine under Linux (64 bit) and Windows using the latest QB64 from git.  It will not compile correctly on a Raspberry Pi 4.
  4. Since there is no binary package available for QB64 on the Pi, I compiled the source (after editing the "../internal/c/common.h" file and adding "#define QB64_NOT_X86" at the top.
  5.  
  6. The error I get when compiling the BASIC program I have is:
  7.  
  8. QB64 Compiler V2.1
  9.  
  10. Beginning C++ output from QB64 code...
  11. [..................................................] 100%
  12.  
  13. Compiling C++ code into executable...
  14. ERROR: C++ compilation failed.
  15. Check ./internal/temp/compilelog.txt for details.
  16.  
  17.  
  18. pi@raspberrypi:~/source/qb64-git $ cat internal/temp/compilelog.txt
  19. objcopy: architecture i386 unknown
  20. g++: error: ../temp/data.o: No such file or directory
  21.  
  22.  
  23.  
  24. It looks like QB64 is trying to compile for i386 and not ARM.  Strange thing is, some other (smaller) BASIC programs I wrote are compiling fine.
  25. I tried doing some searching online, but no luck so far.
  26.  
  27. Thanks for any help someone might be able to provide!
  28. [10:26 AM] MrGW454: I should clarify, that QB64 (the program) works.  The IDE comes up and everything.  I just can't get one specific BASIC program I have to compile.  I did not want to confuse anyone thinking I was having issues trying to compile QB64 itself.  Thanks.
  29.  
Title: Re: A Replacement Method for Data Statements
Post by: tomxp411 on March 09, 2022, 03:37:00 pm
Thanks. That helps.

I am not sure if I've actually used QB64 on my Pi. I have been meaning to try it, as I want my programs to work on Linux, as well as Windows. I'll have to remember to start testing on the Pi, once in a while.
Title: Re: A Replacement Method for Data Statements
Post by: bplus on March 09, 2022, 03:52:11 pm
Quote
FellippeHeitor — 01/31/2022
Do you use DATA statements?
It is known not to work on arm
You'll need a workaround for now
Store your data another way
MrGW454 — 01/31/2022
I sure do.  Let me see what I can do.  I'm requesting access to the QB64 forum.  Is that mentioned in there/.
FellippeHeitor — 01/31/2022
It's been brought up before


Don't see where it's been fixed.

That's why I offered a work around DATA statements. Maybe putting the DATA into an array doesn't work?
Title: Re: A Replacement Method for Data Statements
Post by: MrGW454 on March 09, 2022, 04:05:24 pm
Thanks. That helps.

I am not sure if I've actually used QB64 on my Pi. I have been meaning to try it, as I want my programs to work on Linux, as well as Windows. I'll have to remember to start testing on the Pi, once in a while.

I pulled current development source from git.  It successfully compiled for the RPi but I still get the same error when trying to compile my BASIC source code.  If I remove the DATA statement references, it works. 

The exact same BASIC code compiles fine in QB64 under Windows or Linux (x86 or x64).  It just doesn't work for ARM.
Title: Re: A Replacement Method for Data Statements
Post by: MrGW454 on March 09, 2022, 04:09:00 pm
Don't see where it's been fixed.

That's why I offered a work around DATA statements. Maybe putting the DATA into an array doesn't work?

Hi bplus,

Your method does appear to work.  I'm not the original author of the BASIC code and did forward your solution to them.  We both appreciated your quick response on this.

I was just following up on since I feel the DATA statement issue should be resolved for ARM architectures and make it behave like the other platforms.

 

Title: Re: A Replacement Method for Data Statements
Post by: bplus on March 09, 2022, 05:13:28 pm
Quote
I was just following up on since I feel the DATA statement issue should be resolved for ARM architectures and make it behave like the other platforms.

Right! I think it a point of pride that the team make QB64 as cross platform as possible. I don't know if any have ARM OS to test code?
Title: Re: A Replacement Method for Data Statements
Post by: SMcNeill on March 09, 2022, 06:17:01 pm
did you edit the file common.h and add #define QB64_NOT_X86 ?  It's usually the one big change required for ARM processors to work properly.

Add the define.
Purge all libraries with the batch file for your OS.
Rebuild QB64 with the change at the top of common.h.
Title: Re: A Replacement Method for Data Statements
Post by: George McGinn on March 21, 2022, 04:11:07 pm
@MrGW454 @bplus

I haven't been around in a while as I have been researching a possible project in crypto.

Anyway, I have solved the issue on ARM involving DATA statements - I am going to assume I am looking at posts before MrGW454 contacted me, as from our discussion on Discord, it works.

@bplus - if you want the fix for this, I will be happy to give it to you. I actually ran into a number of issues that I guess others gave up on, until I ran into an issue involving misaligned addresses on the PI's ARM that was fixed in the x86 chip (hardware fix) that may have been done in the Apple M1 ARM processor, which until July I will not have one to test my changes with.

Also an issue is that QB64 does not work on a PI running a 64bit OS. I am looking into that, but I suspect from all the technical documents I've read (and contacts with some in the IEEE) that the PI ARM may not be a fully compliant chip, where I was told the M1 should be,
Title: Re: A Replacement Method for Data Statements
Post by: bplus on March 21, 2022, 04:57:35 pm
Quote
@bplus - if you want the fix for this,

Nah, just trying to help with a work around, thanks.
Title: Re: A Replacement Method for Data Statements
Post by: George McGinn on March 21, 2022, 05:25:02 pm
That is part of the changes, but does not fix everything, including the DATA statement issue.

Here are the changes needed to run QB64 on a Raspberry PI. Sig Bus errors are the product of a hardware fix that was made on the x86 chips, and not carried over on the ARM chip on the PI:

For common.h:
Code: [Select]
//Modification for Raspbian OS: doppler/George McGinn.
#ifdef __arm__
#define QB64_NOT_X86
#define POST_PACKED_STRUCTURE
#else
#define POST_PACKED_STRUCTURE __attribute__((__packed__))
#endif /* ARM */

For the makedat_ln32.txt file:
Code: [Select]
objcopy -Ibinary -Oelf32-littlearm -Barm
1. Add the code for common.h at the top of that source file.
2. Replace the makedat_ln32.txt file in its entirety with the above line.
3. Rerun the setup_lnx.sh script to recompile the qb64 binary.

In common.h, the statement `   #define POST_PACKED_STRUCTURE` is needed for most of the misaligned address errors (some that the x86 hardware fix will not work with this) and the `makedat` file corrects the DATA statement issue, ASAN (AddressSanitizer) errors, malformed binary executable issues. (The POST_PACKED also is part of that issue as far as I can tell).

I also have a script that will do steps two and three (I haven't got around yet to changing it to add the code to common.h yet). I have run this script on a clean copy of Raspbian OS 32bit version, and it now installs all the prerequisites and properly creates the files. QB64 does not work on the Raspbian 64bit version of the OS.

Before you run this script, you will need to add the lines above to common.h before running the setup_lnx.sh script.

Here is my update setup_lnx.sh script:
Code: Bash: [Select]
  1. #!/bin/bash
  2. #QB64 Installer -- Shell Script -- Matt Kilgore 2013
  3. #Version 5 -- January 2020
  4.  
  5. #This version includes the updates to sucessfully install QB64 on the PI
  6. #or any ARM processor (Current version only tested on the Raspberry PI and
  7. #sets the DISTRO to "raspbian".) -- George McGinn (2/1/2022)
  8.  
  9. #This checks the currently installed packages for the one's QB64 needs
  10. #And runs the package manager to install them if that is the case
  11. pkg_install() {
  12.   #Search
  13.   packages_to_install=
  14.   for pkg in $pkg_list; do
  15.     if [ -z "$(echo "$installed_packages" | grep $pkg)" ]; then
  16.       packages_to_install="$packages_to_install $pkg"
  17.     fi
  18.   done
  19.   if [ -n "$packages_to_install" ]; then
  20.     echo "Installing required packages. If prompted to, please enter your password."
  21.     $installer_command $packages_to_install
  22.   fi
  23.  
  24. }
  25.  
  26. #Make sure we're not running as root
  27. if [ $EUID == "0" ]; then
  28.   echo "You are trying to run this script as root. This is highly unrecommended."
  29.   echo "This script will prompt you for your sudo password if needed to install packages."
  30.   exit 1
  31. fi
  32.  
  33. GET_WGET=
  34. #Path to Icon
  35. #Relative Path to icon -- Don't include beginning or trailing '/'
  36. QB64_ICON_PATH="internal/source"
  37.  
  38. #Name of the Icon picture
  39. QB64_ICON_NAME="qb64icon32.png"
  40.  
  41. DISTRO=
  42.  
  43. lsb_command=`which lsb_release 2> /dev/null`
  44. if [ -z "$lsb_command" ]; then
  45.   lsb_command=`which lsb_release 2> /dev/null`
  46. fi
  47.  
  48. #Outputs from lsb_command:
  49.  
  50. #Arch Linux  = arch
  51. #Debian      = debian
  52. #Fedora      = Fedora
  53. #KUbuntu     = ubuntu
  54. #LUbuntu     = ubuntu
  55. #Linux Mint  = linuxmint
  56. #Ubuntu      = ubuntu
  57. #Raspbian    = raspbian
  58. #Slackware   = slackware
  59. #VoidLinux   = voidlinux
  60. #XUbuntu     = ubuntu
  61. #Zorin       = Zorin
  62. if [ -n "$lsb_command" ]; then
  63.   DISTRO=`$lsb_command -si | tr '[:upper:]' '[:lower:]'`
  64. elif [ -e /etc/arch-release ]; then
  65.   DISTRO=arch
  66. elif [ -e /etc/debian_version ] || [ -e /etc/debian_release ]; then
  67.   DISTRO=debian
  68. elif [ -e /etc/fedora-release ]; then
  69.   DISTRO=fedora
  70. elif [ -e /etc/redhat-release ]; then
  71.   DISTRO=redhat
  72. elif [ -e /etc/centos-release ]; then
  73.   DISTRO=centos
  74. elif $(arch | grep arm > /dev/null); then
  75.   DISTRO=raspbian
  76. fi
  77.  
  78. echo "DISTRO detected = $DISTRO"
  79.  
  80. #Find and install packages
  81. if [ "$DISTRO" == "arch" ]; then
  82.   echo "ArchLinux detected."
  83.   pkg_list="gcc zlib xorg-xmessage $GET_WGET"
  84.   installed_packages=`pacman -Q`
  85.   installer_command="sudo pacman -S "
  86.   pkg_install
  87. elif [ "$DISTRO" == "linuxmint" ] || [ "$DISTRO" == "ubuntu" ] || [ "$DISTRO" == "debian" ] || [ "$DISTRO" == "zorin" ] || [ "$DISTRO" == "raspbian" ]; then
  88.   echo "Debian/Raspian based distro detected."
  89.   pkg_list="g++ x11-utils mesa-common-dev libglu1-mesa-dev libasound2-dev zlib1g-dev $GET_WGET"
  90.   installed_packages=`dpkg -l`
  91.   installer_command="sudo apt-get -y install "
  92.   pkg_install
  93. elif [ "$DISTRO" == "fedora" ] || [ "$DISTRO" == "redhat" ] || [ "$DISTRO" == "centos" ]; then
  94.   echo "Fedora/Redhat based distro detected."
  95.   pkg_list="gcc-c++ xmessage mesa-libGLU-devel alsa-lib-devel zlib-devel $GET_WGET"
  96.   installed_packages=`yum list installed`
  97.   installer_command="sudo yum install "
  98.   pkg_install
  99. elif [ "$DISTRO" == "voidlinux" ]; then
  100.    echo "VoidLinux detected."
  101.    pkg_list="gcc xmessage glu-devel zlib-devel alsa-lib-devel $GET_WGET"
  102.    installed_packages=`xbps-query -l |grep -v libgcc`
  103.    installer_command="sudo xbps-install -Sy "
  104.    pkg_install
  105. elif [ -z "$DISTRO" ]; then
  106.   echo "Unable to detect distro, skipping package installation"
  107.   echo "Please be aware that for QB64 to compile, you will need the following installed:"
  108.   echo "  OpenGL developement libraries"
  109.   echo "  ALSA development libraries"
  110.   echo "  GNU C++ Compiler (g++)"
  111.   echo "  xmessage (x11-utils)"
  112.   echo "  zlib"
  113. fi
  114.  
  115. echo "Compiling and installing QB64..."
  116.  
  117. ### Build process
  118. find . -name "*.sh" -exec chmod +x {} \;
  119. find internal/c/parts -type f -iname "*.a" -exec rm -f {} \;
  120. find internal/c/parts -type f -iname "*.o" -exec rm -f {} \;
  121. find internal/c/libqb -type f -iname "*.o" -exec rm -f {} \;
  122. rm ./internal/temp/*
  123.  
  124. #if [ "$DISTRO" == "raspbian" ]; then
  125. if $(arch | grep arm > /dev/null); then
  126.   echo "Updating files for the ARM processor..."
  127.   echo "updating makedat_lnx32.txt file..."
  128.   pushd internal/c >/dev/null
  129.   cat > makedat_lnx32.txt <<EOF
  130. objcopy -Ibinary -Oelf32-littlearm -Barm
  131. EOF
  132.   echo "updating makedat_lnx64.txt file..."
  133.   cat > makedat_lnx64.txt <<EOF
  134. objcopy -Ibinary -Oelf64-littlearm -Barm
  135. EOF
  136.   popd >/dev/null
  137. fi
  138.  
  139. echo "Building library 'LibQB'"
  140. pushd internal/c/libqb/os/lnx >/dev/null
  141. rm -f libqb_setup.o
  142. ./setup_build.sh
  143. popd >/dev/null
  144.  
  145. echo "Building library 'FreeType'"
  146. pushd internal/c/parts/video/font/ttf/os/lnx >/dev/null
  147. rm -f src.o
  148. ./setup_build.sh
  149. popd >/dev/null
  150.  
  151. echo "Building library 'Core:FreeGLUT'"
  152. pushd internal/c/parts/core/os/lnx >/dev/null
  153. rm -f src.a
  154. ./setup_build.sh
  155. popd >/dev/null
  156.  
  157. echo "Building 'QB64'"
  158. cp -r ./internal/source/* ./internal/temp/
  159. pushd internal/c >/dev/null
  160. g++ -no-pie -w qbx.cpp libqb/os/lnx/libqb_setup.o parts/video/font/ttf/os/lnx/src.o parts/core/os/lnx/src.a -lGL -lGLU -lX11 -lpthread -ldl -lrt -D FREEGLUT_STATIC -o ../../qb64
  161. popd
  162.  
  163. if [ -e "./qb64" ]; then
  164.   echo "Done compiling!!"
  165.  
  166.   echo "Creating ./run_qb64.sh script..."
  167.   _pwd=`pwd`
  168.   echo "#!/bin/sh" > ./run_qb64.sh
  169.   echo "cd $_pwd" >> ./run_qb64.sh
  170.   echo "./qb64 &" >> ./run_qb64.sh
  171.  
  172.   chmod +x ./run_qb64.sh
  173.   #chmod -R 777 ./
  174.   echo "Adding QB64 menu entry..."
  175.   cat > ~/.local/share/applications/qb64.desktop <<EOF
  176. [Desktop Entry]
  177. Name=QB64 Programming IDE
  178. GenericName=QB64 Programming IDE
  179. Exec=$_pwd/run_qb64.sh
  180. Icon=$_pwd/$QB64_ICON_PATH/$QB64_ICON_NAME
  181. Terminal=false
  182. Type=Application
  183. Categories=Development;IDE;
  184. Path=$_pwd
  185. StartupNotify=false
  186. EOF
  187.  
  188.   echo "Running QB64..."
  189.   ./qb64 &
  190.   echo "QB64 is located in this folder:"
  191.   echo "`pwd`"
  192.   echo "There is a ./run_qb64.sh script in this folder that should let you run qb64 if using the executable directly isn't working."
  193.   echo
  194.   echo "You should also find a QB64 option in the Programming/Development section of your menu you can use."
  195. else
  196.   ### QB64 didn't compile
  197.   echo "It appears that the qb64 executable file was not created, this is usually an indication of a compile failure (You probably saw lots of error messages pop up on the screen)"
  198.   echo "Usually these are due to missing packages needed for compilation. If you're not running a distro supported by this compiler, please note you will need to install the packages listed above."
  199.   echo "If you need help, please feel free to post on the QB64 Forums detailing what happened and what distro you are using."
  200.   echo "Also, please tell them the exact contents of this next line:"
  201.   echo "DISTRO: $DISTRO"
  202. fi
  203. echo
  204. echo "Thank you for using the QB64 installer."
  205.  

did you edit the file common.h and add #define QB64_NOT_X86 ?  It's usually the one big change required for ARM processors to work properly.

Add the define.
Purge all libraries with the batch file for your OS.
Rebuild QB64 with the change at the top of common.h.
Title: Re: A Replacement Method for Data Statements
Post by: MrGW454 on March 23, 2022, 09:24:33 am
Code: [Select]
[quote author=George McGinn link=topic=4617.msg141500#msg141500 date=1647897902]
That is part of the changes, but does not fix everything, including the DATA statement issue.

Here are the changes needed to run QB64 on a Raspberry PI. Sig Bus errors are the product of a hardware fix that was made on the x86 chips, and not carried over on the ARM chip on the PI:

ank you for using the QB64 installer."
[/quote]

Hi George - your fix has been working well for me.  I've performed about a dozen compilations of various BASIC programs with DATA statements and so far there have been no issues.  I'm looking to test some more complex code soon, but wanted to give you this feedback and thank you again for all your help.