Recent posts

#1
OxygenBasic Examples / Re: Axis + triangle
Last post by Frank Brübach - Yesterday at 02:47:26 PM
Hello all..

What happened to Charles? He's i'll or busy? I dont want to talk to an AI Here so WE can better close this Forum for oxygen Basic Users?


Only the marks I have added are too long in my new example..

I have fixed three Problems of the AI (Theo used this unnamed AI) so this example Works correct

Oxygen OpenGL Update 2

  ' -- opgl test with axis and sin cos curves
  '
  $ FileName "t.exe"
  $ title    "Triangle and Axis with sin cos curves"
  int width=800
  int height=600

  uses OpenglSceneFrame

  function KeyState(int k) as int
  ===============================
  return GetAsyncKeyState(k) and 0x8000 'key down
  end function

  sub Initialize(sys hWnd)
  '=======================
  end sub
  '
  '--------------------------------------------- //
  sub Scene(sys hWnd)
    'angle = radians(i) ' what is radians(i) it's rad(i) ?

  static single ang1, angi1 = 1
  dim i as integer
  dim x, y, angle as single
  dim radius as single = 2.0
  'dim radius as single = 100.0 ' Larger radius for better curve visibility

 
  glClearColor 0.3, 0.3, 0.5, 0
  glClear GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT
 
  glLoadIdentity
 
  gltranslatef 0.0, 0.0, -8.0 '-4.0
  glrotatef ang1, 0.0, 0.0, 1.0
 
  glBegin GL_TRIANGLES
  glColor3f 1.0, 0.0, 0.0 : glVertex3f 0.0, 1.0, 0.0
  glColor3f 0.0, 1.0, 0.0 : glVertex3f -1.0, -1.0, 0.0
  glColor3f 0.0, 0.0, 1.0 : glVertex3f 1.0, -1.0, 0.0
  glEnd
 
  ' Draw axis
  glBegin GL_LINES
  glLineWidth 2.0
  gltranslatef 0,0,-6 '-1
  glscalef 0.01,0.01,0.01
 
  glColor4ub 250,50,0,0 ' X axis color
  glVertex2i -500,0
  glVertex2i 500,0
 
  glColor4ub 0,0,255,0 ' Y axis color
  glVertex2i 0,500
  glVertex2i 0,-500
  glEnd
 
  glBegin GL_LINES
  gltranslatef 0,0,-6
  glscalef 0.5,0.5,0.5
  glColor4ub 0,255,255,0

  ' -- some Marks on axes ---------- //
      for i = -5 to 5 step 1.025
        glVertex2i  i, -0.5001 ' too long and wide the marks (length)
        glVertex2i  i,  0.5001 ' values below 0.5 aren't working
       
        glVertex2i -0.5001, i ' too long and wide the marks (length)
        glVertex2i  0.5001, i ' values below 0.5 aren't working
      next
  glEnd
 
  ' Draw rounded, smooth sine and cosine curves
    'int pi = 3.1415926536

    glLineWidth 2.0
    glColor4ub 255, 200, 0, 0 
    glBegin GL_LINE_STRIP
        for i = -360 to 360
            angle = i * 3.1415926536 / 180  ' Correct conversion from degrees to radians
            glVertex2f i / 360.0 * 2.0 * 3.1415926536, sin(angle)           
        next
    glEnd

  glBegin GL_LINE_STRIP
    glColor4ub 0, 255, 200, 0
    for i = -360 to 360 'step 5
      angle = i * 3.1415926536 / 180 ' Convert degrees to radians
      glVertex2f i / 360.0 * 2.0 * 3.1415926536, cos(angle) 
    next
  glEnd
  '
  'UPDATE ROTATION ANGLES
  '----------------------
  '
  'ang1+=angi1
  'if ang1>360 then ang1-=360
  '
  end sub


  sub Release(sys hwnd)
  '====================
  end sub


#2
OxygenBasic Examples / Re: Axis + triangle
Last post by Theo Gottwald - Yesterday at 06:57:05 AM
Quote from: Frank Brübach on Yesterday at 05:31:08 AM' -- opgl test with axis and sin cos curves
  '
  $ FileName "t.exe"
  $ title    "Triangle and Axis with sin cos curves"
  int width=640
  int height=480

  uses OpenglSceneFrame

  function KeyState(int k) as int
  ===============================
  return GetAsyncKeyState(k) and 0x8000 'key down
  end function

  sub Initialize(sys hWnd)
  '=======================
  end sub
  '
  '--------------------------------------------- //
  sub Scene(sys hWnd)
    'angle = radians(i) ' what is radians(i) it's rad(i) ?

  static single ang1, angi1 = 1
  dim i as integer
  dim x, y, angle as single
  dim radius as single = 2.0
 
  glClearColor 0.3, 0.3, 0.5, 0
  glClear GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT
 
  glLoadIdentity
 
  gltranslatef 0.0, 0.0, -6.0 '-4.0
  glrotatef ang1, 0.0, 0.0, 1.0
 
  glBegin GL_TRIANGLES
  glColor3f 1.0, 0.0, 0.0 : glVertex3f 0.0, 1.0, 0.0
  glColor3f 0.0, 1.0, 0.0 : glVertex3f -1.0, -1.0, 0.0
  glColor3f 0.0, 0.0, 1.0 : glVertex3f 1.0, -1.0, 0.0
  glEnd
 
  ' Draw axis
  glBegin GL_LINES
  glLineWidth 1.0
  gltranslatef 0,0,-4 '-1
  glscalef 0.01,0.01,0.01
 
  glColor4ub 250,50,0,0 ' X axis color
  glVertex2i -500,0
  glVertex2i 500,0
 
  glColor4ub 0,0,255,0 ' Y axis color
  glVertex2i 0,500
  glVertex2i 0,-500
  glEnd
 
  ' Draw rounded, smooth sine and cosine curves
  glLineWidth 2.0
  glBegin GL_LINE_STRIP

'--- how I can set a rounded smooth sin cos curve line?
'--------------------- problem zone -------------------------------- //
  for i = -45 to 45
    'angle = radians(i) 'angle in radians * 180/pi ' pi 3.1415926536

    angle = rad(i*180/3.1415) ' ? circle ok but not sin cos curves
 '
    x = radius * cos(angle)
    y = radius * sin(angle)
    glColor4ub 255, 200, 0, 0 ' Sine curve color
    glVertex2f x, y
   
    x = radius * cos(angle + 1)
    y = radius * sin(angle + 1)
    glVertex2f x, y
  next
'--- how I can set a rounded smooth sin cos curve line?

'--------------------- problem zone -------------------------------- // 
  glEnd
 
  '
  'UPDATE ROTATION ANGLES
  '----------------------
  '
           
  'if not action then
  'print "Key pressed: 0x%x\n^" + KeyState(k) 
  'end if

  'ang1+=angi1
  'if ang1>360 then ang1-=360
  '
  end sub


  sub Release(sys hwnd)
  '====================
  end sub


The script you provided sets up a simple OpenGL scene using O2 Basic. Here's what it does step by step, and what visual output it likely produces:

1. Setup and Background
Sets the window dimensions to 640x480.
Initializes OpenGL and sets the background color to a medium blue (RGB: 0.3, 0.3, 0.5).
Clears the color and depth buffers to reset the frame.
2. Transformation and Triangle Drawing
Resets the current matrix and applies a translation to move the scene 6 units into the view (making it visible).
Applies a rotation based on ang1, which appears to be intended to rotate around the Z-axis, but without updating ang1 within the scene function, the triangle won't rotate in this script.
Draws a triangle with vertices colored differently: red, green, and blue, creating a simple RGB triangle.
3. Axis Drawing
Attempts to draw two axes (X and Y) in the middle of the scene. It uses very thin lines scaled down significantly, which might not be visible due to the small scale and the translation into the depth. The colors used are orange for the X-axis and blue for the Y-axis.
4. Sine and Cosine Curves
Attempts to draw what seems intended to be smooth sine and cosine curves but has several errors and misunderstandings in the implementation:
The for loop intended to draw these curves uses incorrect conversions and misunderstandings of how trigonometric functions and radians are handled in OpenGL.
The calculation angle = rad(i*180/3.1415) is incorrect and seems to be a confused attempt at converting degrees to radians (the correct formula for converting degrees d to radians is d * PI / 180).
The script is trying to draw a sine and cosine curve using polar coordinates but ends up trying to draw them in a form that would create a circle due to using cos(angle) and sin(angle) as x, y coordinates for each point.
The code snippet implies an attempt to draw the sine and cosine values directly along the axis, but it ends up drawing in polar coordinates instead.
5. Potential Visual Output
A static RGB triangle at the center, slightly in front of the blue background.
Two nearly invisible axes due to scaling issues.
A misshapen or incorrect "curve," likely forming a circle instead of proper sine and cosine waves.
Corrections Needed:
To correctly draw sine and cosine curves:

Remove the unnecessary and incorrect polar coordinate calculation.
Use proper radian conversion for sine and cosine functions.
Draw each curve separately using GL_LINE_STRIP and iterate through a reasonable range (e.g., -360 to 360 degrees) with correct radian conversion.
Adjust the x, y plotting to scale and position correctly according to your viewport settings.
Here's a simplified and corrected version for drawing just a sine curve correctly:

glLineWidth 2.0
glColor4ub 255, 200, 0, 0  ' Sine curve color
glBegin GL_LINE_STRIP
  for i = -360 to 360
    angle = i * 3.1415926536 / 180  ' Correct conversion from degrees to radians
    glVertex2f i / 360.0 * 2.0 * 3.1415926536, sin(angle)  ' Scale x appropriately and calculate y as sine of angle
  next
glEnd
This will render a sine wave across a range matching the setup of your scene, scaled to be visible within the given dimensions.

' Filename: t.exe
' Title: Triangle and Axis with sin cos curves
' Dimensions
int width = 640
int height = 480

' Uses
uses OpenglSceneFrame

' Function to check key state
function KeyState(int k) as int
  return GetAsyncKeyState(k) and 0x8000 ' Key down
end function

' Initialization sub
sub Initialize(sys hWnd)
end sub

' Main scene rendering sub
sub Scene(sys hWnd)
  ' Variables
  static single ang1, angi1 = 1
  dim i as integer
  dim x, y, angle as single
  dim radius as single = 100.0 ' Larger radius for better curve visibility

  ' Clear the screen and depth buffer
  glClearColor 0.3, 0.3, 0.5, 0
  glClear GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT

  ' Reset transformations
  glLoadIdentity
  gltranslatef 0.0, 0.0, -6.0

  ' Rotate the whole scene
  glrotatef ang1, 0.0, 0.0, 1.0

  ' Draw a triangle
  glBegin GL_TRIANGLES
    glColor3f 1.0, 0.0, 0.0: glVertex3f 0.0, 1.0, 0.0
    glColor3f 0.0, 1.0, 0.0: glVertex3f -1.0, -1.0, 0.0
    glColor3f 0.0, 0.0, 1.0: glVertex3f 1.0, -1.0, 0.0
  glEnd

  ' Draw axes
  glBegin GL_LINES
    glLineWidth 2.0
    glColor4ub 250, 50, 0, 0 ' X axis color
    glVertex2i -320, 0
    glVertex2i 320, 0
    glColor4ub 0, 0, 255, 0 ' Y axis color
    glVertex2i 0, 240
    glVertex2i 0, -240
  glEnd

  ' Draw sine and cosine curves
  glBegin GL_LINE_STRIP
    glColor4ub 255, 200, 0, 0 ' Sine curve color
    for i = -360 to 360 step 5
      angle = i * 3.1415926536 / 180 ' Convert degrees to radians
      glVertex2f i, sin(angle) * radius
    next
  glEnd

  glBegin GL_LINE_STRIP
    glColor4ub 0, 255, 200, 0 ' Cosine curve color
    for i = -360 to 360 step 5
      angle = i * 3.1415926536 / 180 ' Convert degrees to radians
      glVertex2f i, cos(angle) * radius
    next
  glEnd

  ' Update rotation angles if necessary
  ' ang1 += angi1
  ' if ang1 > 360 then ang1 -= 360

end sub

' Cleanup resources
sub Release(sys hwnd)
end sub
#3
OxygenBasic Examples / Re: Axis + triangle
Last post by Theo Gottwald - Yesterday at 06:53:42 AM
Current Curve Rendering
The current approach in your script uses a simple line drawing (GL_LINES) method, which inherently produces a polygonal line that connects each set of points. Given the loop from -45 to 45 and the increment of 1, this will create straight segments between each integer point on the sine and cosine curves. This approach will not produce smooth curves but rather angular or "cornered" lines.

Smooth Curve Implementation
To achieve a smooth rendering of sine and cosine curves, consider the following modifications and enhancements:

Higher Sampling Rate: Use a smaller step value in your loop to increase the number of segments, reducing the angle between them and making the curve appear smoother. A smaller increment, such as 0.1 or even smaller, can significantly improve the appearance.
Use Line Strip Instead of Lines: Switch from using GL_LINES to GL_LINE_STRIP. GL_LINE_STRIP connects each vertex with the next, making it easier to draw continuous curves without manually defining both endpoints for each line segment.
Scale and Translation Adjustments: The sine and cosine functions return values in the range [-1,1], but your axis setup seems intended for much larger values. You might need to scale these values appropriately to make them visible in your current axis configuration.
Updated Code Snippet for Smooth Curves
Here's how you can modify your loop to use GL_LINE_STRIP and a smaller step size for smoother curves:


glLineWidth 2.0

' Drawing sine curve
glColor4ub 255, 200, 0, 0  ' Orange color
glBegin GL_LINE_STRIP   
    for i = -360 to 360 step 1 ' Increase range and decrease step for smoothness
        glVertex2f i * 0.1, sin(i * PI / 180) * 100  ' Convert degrees to radians and scale up
    next
glEnd

' Drawing cosine curve
glColor4ub 0, 255, 200, 0  ' Teal color
glBegin GL_LINE_STRIP   
    for i = -360 to 360 step 1
        glVertex2f i * 0.1, cos(i * PI / 180) * 100
    next
glEnd
Considerations
Coordinate System and Scaling: Adjust the scaling factor (* 100 in the example) and the range of i according to your specific needs and the size of your OpenGL viewport.
Performance: Drawing very fine curves with a lot of segments can affect performance. If performance is a concern, experiment with the increment in the loop to find a good balance between smoothness and performance.
Implement these changes to create more visually appealing and smooth sine and cosine curves in your OpenGL scene.
#4
OxygenBasic Examples / Re: Axis + triangle
Last post by Frank Brübach - Yesterday at 05:31:08 AM
Good morning

Now I need only to know how to translate a radians(i) function or If I can use angle = Rad(i) for my example to build correct Sin cos curves ?

Updated Code expl openGl

  ' -- opgl test with axis and sin cos curves
  '
  $ FileName "t.exe"
  $ title    "Triangle and Axis with sin cos curves"
  int width=640
  int height=480

  uses OpenglSceneFrame

  function KeyState(int k) as int
  ===============================
  return GetAsyncKeyState(k) and 0x8000 'key down
  end function

  sub Initialize(sys hWnd)
  '=======================
  end sub
  '
  '--------------------------------------------- //
  sub Scene(sys hWnd)
    'angle = radians(i) ' what is radians(i) it's rad(i) ?

  static single ang1, angi1 = 1
  dim i as integer
  dim x, y, angle as single
  dim radius as single = 2.0
 
  glClearColor 0.3, 0.3, 0.5, 0
  glClear GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT
 
  glLoadIdentity
 
  gltranslatef 0.0, 0.0, -6.0 '-4.0
  glrotatef ang1, 0.0, 0.0, 1.0
 
  glBegin GL_TRIANGLES
  glColor3f 1.0, 0.0, 0.0 : glVertex3f 0.0, 1.0, 0.0
  glColor3f 0.0, 1.0, 0.0 : glVertex3f -1.0, -1.0, 0.0
  glColor3f 0.0, 0.0, 1.0 : glVertex3f 1.0, -1.0, 0.0
  glEnd
 
  ' Draw axis
  glBegin GL_LINES
  glLineWidth 1.0
  gltranslatef 0,0,-4 '-1
  glscalef 0.01,0.01,0.01
 
  glColor4ub 250,50,0,0 ' X axis color
  glVertex2i -500,0
  glVertex2i 500,0
 
  glColor4ub 0,0,255,0 ' Y axis color
  glVertex2i 0,500
  glVertex2i 0,-500
  glEnd
 
  ' Draw rounded, smooth sine and cosine curves
  glLineWidth 2.0
  glBegin GL_LINE_STRIP

'--- how I can set a rounded smooth sin cos curve line?
'--------------------- problem zone -------------------------------- //
  for i = -45 to 45
    'angle = radians(i) 'angle in radians * 180/pi ' pi 3.1415926536

    angle = rad(i*180/3.1415) ' ? circle ok but not sin cos curves
 '
    x = radius * cos(angle)
    y = radius * sin(angle)
    glColor4ub 255, 200, 0, 0 ' Sine curve color
    glVertex2f x, y
   
    x = radius * cos(angle + 1)
    y = radius * sin(angle + 1)
    glVertex2f x, y
  next
'--- how I can set a rounded smooth sin cos curve line?

'--------------------- problem zone -------------------------------- // 
  glEnd
 
  '
  'UPDATE ROTATION ANGLES
  '----------------------
  '
           
  'if not action then
  'print "Key pressed: 0x%x\n^" + KeyState(k) 
  'end if

  'ang1+=angi1
  'if ang1>360 then ang1-=360
  '
  end sub


  sub Release(sys hwnd)
  '====================
  end sub


My Test Shows an interesting result ;)

#5
OxygenBasic Examples / Axis + triangle
Last post by Frank Brübach - April 18, 2024, 07:08:51 PM
Hi Charles have built a simple example with OpenGL triangle and an Axis for a coordinate system but the sin and cos curves arent round and smooth whats Missing?

Thx, Frank

OpenGL oxygen

  includepath "$\inc\"
  $ FileName "t.exe"
  'include  "RTL32.inc"
  'include  "RTL64.inc"
  $ title    "Triangle and Axis"
  int width=640
  int height=480

  uses OpenglSceneFrame
'  uses console


  function KeyState(int k) as int
  ===============================
  return GetAsyncKeyState(k) and 0x8000 'key down
  end function

  sub Initialize(sys hWnd)
  '=======================
  end sub
  '

  sub Scene(sys hWnd)
  '==================
  '
  static single ang1,angi1=1
  int action,k

  '
  glClearColor 0.3, 0.3, 0.5, 0
  glClear GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT
  '
  glLoadIdentity
  '
  '
  gltranslatef    0.0, 0.0, -6.0 '-4.0
  glrotatef ang1, 0.0, 0.0,  1.0
  '
  glBegin GL_TRIANGLES
  glColor3f  1.0, 0.0, 0.0 : glVertex3f  0.0,  1.0, 0.0
  glColor3f  0.0, 1.0, 0.0 : glVertex3f  -1.0, -1.0, 0.0
  glColor3f  0.0, 0.0, 1.0 : glVertex3f  1.0, -1.0, 0.0
  glEnd

  ' axis --------- //
  glBegin GL_LINES
  glLineWidth 1.0

  'glrotatef    ang1, 0,0,1
  gltranslatef 0,0,-4 '-1
  glscalef    0.01,0.01,0.01
  '
  'glBegin GL_LINES
  glColor4ub  250,50,0,0
  'glColor4ub  0,0,0,0
' -- X axis
  glVertex2i -500,0
  glVertex2i 500,0
  '-- Y axis     
  glVertex2i 0,500
  glVertex2i 0,-500
  glEnd

'--- how I can set a rounded smooth sin cos curve line?
'
int i
  glLineWidth 2.0
  glBegin GL_LINES   
      for i = -45 to 45 step 1 '-25 to 25
        glColor4ub 255, 200, 0, 0
        glVertex2i i, sin(i)
        glVertex2i i+1, sin(i+1)
        'glVertex2i i+0.1, sin(i+0.1)

        glColor4ub 0, 255, 200, 0
        glVertex2i i, cos(i)
        glVertex2i i+1, cos(i+1) '0.1
        'glVertex2i i+0.1, sin(i+0.1)
      next 
  glEnd
'
'--- how I can set a rounded smooth sin cos curve line?
  '
  'UPDATE ROTATION ANGLES
  '----------------------
  '
           
  if not action then
  'print "Key pressed: 0x%x\n^" + KeyState(k) 
  end if

  'ang1+=angi1
  'if ang1>360 then ang1-=360
  '
  end sub


  sub Release(sys hwnd)
  '====================
  end sub

#6
OxygenBasic Examples / Re: Class example salary
Last post by Theo Gottwald - April 18, 2024, 06:49:30 PM
When using Powerbasic Classes, to get B-String Parameters into Threads,I found that when opening and destroying classes, there is some memory Leak in Powerbasic. therefore it an not be used for all cases.
I wonder it would work better in O2, getting String and other Parameters inside Threads and out of there.
#7
OxygenBasic Examples / Class example salary
Last post by Frank Brübach - April 16, 2024, 11:28:20 PM
Hello all

Made some minutes ago this little class example  and its Working well


' simple class example with data
' by frank bruebach, oxygen, 16-04-2024
'
' Oxygen Class example
'
' how I can make a salary add for john with 500 euros?
'
class Employee
    string names2
    string depts2
    integer salarys2

    method constructor(String name1="John", string dept1="Computer Lab", integer salary=2000)
        names2 = name1
        depts2 = dept1
        salarys2 = salary
        print "construct!"
    End method

method destructor()
===================
'destroy bstrings
del names2
del depts2
      del salarys2
print "destruct!"
end method

method act() as string
======================
return names2 ",  " depts2 ", " salarys2
end method

end class

new Employee john("John","Computer Lab", 2000)
print john.act
del john

' how I can make a salary add for john with 500 euros?

[

How I can make a salary increase for John with 500 Euros?

Solved :)

' simple class example2 with data
' by frank bruebach, oxygen, 16-04-2024
'
' Oxygen Class example
'
' how I can make a salary add for john with 500 euros?
'
class Employee
    string names2
    string depts2
    integer salarys2

    method constructor(String name1="John", string dept1="Computer Lab", integer salary=2000)
        names2 = name1
        depts2 = dept1
        salarys2 = salary
        print "construct!"
    End method

method destructor()
===================
'destroy bstrings
del names2
del depts2
      del salarys2
print "destruct!"
end method

method act() as string
======================
return names2 ",  " depts2 ", " salarys2
end method

method act2() as string
======================
return names2 ",  " depts2 ", " salarys2+500
end method

end class

new Employee john("John","Computer Lab", 2000)
print john.act
print john.act2
del john


#8
Quality production. Good coverage of the subject.

Best Documentary
14 apr 2024

#9
Source Code and Discussions / "IsLike" Patternmatcher in 2 V...
Last post by Theo Gottwald - April 15, 2024, 01:39:53 PM
Original "IsLike" Function.

The provided PowerBasic function, Is_Like, is designed to check if a given string (a) matches a pattern defined in another string (b). The function supports several wildcard characters for pattern matching, such as *, ?, #, and character ranges using [ and ]. The lCase parameter determines whether the comparison should be case-sensitive or not.

While the function appears to be well-written and covers most of the edge cases, there are a few minor issues that need to be addressed:

In the case of the # wildcard, the function only checks for numeric digits (0-9). However, the # wildcard is typically used to match any single character, not just digits. If you want to match any single character, you should change the range from (48-57) to (32-126) or any other desired range.
In the case of the [ wildcard, the function does not handle the situation where the closing bracket ] is the first character after the opening bracket. For example, the pattern [abc] would not be handled correctly. To fix this, you should add a check for the closing bracket as the first character and treat it as a literal character to match.
The function does not handle escaped wildcard characters properly. For example, if you want to match a literal * or ? in the pattern, the function does not provide a way to escape these characters. You may want to consider adding support for escaping wildcard characters using a backslash \ or another appropriate escape character.
Once these issues are addressed, the function should work as expected for most cases. However, it is always a good idea to thoroughly test the function with various input strings and patterns to ensure it behaves correctly.



FUNCTION Is_Like(BYVAL a AS STRING, BYVAL b AS STRING,BYVAL lCase AS LONG) AS LONG

  DIM x        AS BYTE PTR
  DIM y        AS BYTE PTR
  DIM matc    AS LONG
  DIM PrevChar AS BYTE
  DIM NextChar AS BYTE

  IF lCase THEN
    a        = a + CHR$(0)
    b        = b + CHR$(0)
  ELSE
    a        = UCASE$(a + CHR$(0))
    b        = UCASE$(b + CHR$(0))
  END IF

  x        = STRPTR(a)
  y        = STRPTR(b)

  FUNCTION = %FALSE

  DO

    IF @x = 0 THEN
      IF @y = 0 THEN
        FUNCTION = %TRUE
      END IF
      EXIT FUNCTION
    END IF

    SELECT CASE @y

      CASE 0  'NUL  pre-mature end
        EXIT FUNCTION

      CASE 35 '#    match a single numeric digit
        IF (@x < 48) OR (@x > 57) THEN
          EXIT FUNCTION
        END IF

      CASE 42 '*
        INCR y                 ' next char in expression
        DO
          IF @x = @y THEN      ' do they match?
            EXIT DO            ' yes exit
          ELSEIF @x = 0 THEN   ' end of source string?
            EXIT DO            ' yes exit
          END IF
          INCR x               ' next char in source string
        LOOP
        IF @x = 0 THEN         ' end of source string?
          IF @y = 0 THEN       ' also end of expression?
            FUNCTION = %TRUE
          END IF
          EXIT FUNCTION
        END IF

      CASE 63 '?    match any single char
        ' nothing, it's a match

      CASE 91 '[
        matc = %TRUE          ' assume we have to match chars
        INCR y                 ' next char in expression

        IF @y = 33 THEN        ' ! indicates do not match
          matc = %FALSE
          INCR y
        END IF

        DO
          IF @y = 93 THEN      ' ]
            EXIT FUNCTION
          ELSEIF @y = 0 THEN   ' NUL
            EXIT FUNCTION
          ELSEIF @y = 45 THEN  ' -
            DECR y             ' move to previous char in expression
            PrevChar = @y      ' save previous char
            y = y + 2          ' move to next char in expression
            NextChar = @y      ' save next char
            DECR y             ' restore current char in expression
            IF (PrevChar = 91) OR (PrevChar = 33) OR (NextChar = 93) THEN
              IF @y = @x THEN
                IF matc = %FALSE THEN  'if matching is false, exit
                  EXIT FUNCTION
                ELSE
                    EXIT DO
                END IF
              END IF
            ELSE
              IF (@x >= PrevChar) AND (@x =< NextChar) THEN
                IF matc = %FALSE THEN
                  EXIT FUNCTION
                ELSE
                  EXIT DO
                END IF
              ELSE
                INCR y
              END IF
            END IF
          ELSEIF @y = @x THEN  ' do they match?
            IF matc = %FALSE THEN  'if matching is false, exit
              EXIT FUNCTION
            ELSE
              EXIT DO
            END IF
          END IF
          INCR y               'next char in expression
        LOOP

        DO                     'find the closing bracket
          IF @y = 93 THEN
            EXIT DO
          ELSEIF @y = 0 THEN
            EXIT FUNCTION
          END IF
          INCR y
        LOOP

      CASE ELSE
        IF @x <> @y THEN
          EXIT DO
        END IF

    END SELECT

    INCR x    ' next char in source string
    INCR y    ' next char in expression

  LOOP

END FUNCTION


Here's an improved version of the Is_Like function that addresses the issues mentioned earlier:

The ? wildcard now matches any single character.
The # wildcard now matches just numeric digits.
The [ wildcard now handles the closing bracket ] as the first character after the opening bracket.
The function now supports escaping wildcard characters using a backslash \.
Here's the updated PowerBasic function:


FUNCTION Is_Like(BYVAL a AS STRING, BYVAL b AS STRING, BYVAL lCase AS LONG) AS LONG

  DIM x        AS BYTE PTR
  DIM y        AS BYTE PTR
  DIM matc    AS LONG
  DIM PrevChar AS BYTE
  DIM NextChar AS BYTE
  DIM result   AS LONG

  IF lCase THEN
    a = a + CHR$(0)
    b = b + CHR$(0)
  ELSE
    a = UCASE$(a + CHR$(0))
    b = UCASE$(b + CHR$(0))
  END IF

  x = STRPTR(a)
  y = STRPTR(b)

  result = %FALSE

  DO

    IF @x = 0 THEN
      IF @y = 0 THEN
        result = %TRUE
        GOTO ExitFunction
      END IF
      GOTO ExitFunction
    END IF

    SELECT CASE @y

      CASE 0  'NUL  pre-mature end
        GOTO ExitFunction

      CASE 92 '\    escape character
        IF @y + 1 = 0 THEN
          GOTO ExitFunction ' invalid escape at the end of the pattern
        END IF
        y = y + 1
        IF @x <> @y THEN
          GOTO ExitFunction
        END IF
        INCR x
        INCR y
        ITERATE LOOP

      CASE 35 '#    match a single digit
        IF (@x < 48) OR (@x > 57) THEN
          GOTO ExitFunction
        END IF

      CASE 42 '*
        INCR y                 ' next char in expression
        DO
          IF @x = @y THEN      ' do they match?
            EXIT DO            ' yes exit
          ELSEIF @x = 0 THEN   ' end of source string?
            EXIT DO            ' yes exit
          END IF
          INCR x               ' next char in source string
        LOOP
        IF @x = 0 THEN         ' end of source string?
          IF @y = 0 THEN       ' also end of expression?
            result = %TRUE
            GOTO ExitFunction
          END IF
          GOTO ExitFunction
        END IF

      CASE 63 '?    match any single char
        IF @x = 0 THEN
          GOTO ExitFunction
        END IF

      CASE 91 '[
        matc = %TRUE          ' assume we have to match chars
        INCR y                 ' next char in expression

        IF @y = 93 THEN        ' handle ] as the first character after [
          IF @x <> @y THEN
            GOTO ExitFunction
          END IF
          INCR x
          INCR y
          ITERATE LOOP
        ELSEIF @y = 33 THEN  ' ! indicates do not match
          matc = %FALSE
          INCR y
        END IF

        DO
          IF @y = 93 THEN      ' ]
            INCR y             ' Move to the next character after the closing bracket
            EXIT DO
          ELSEIF @y = 0 THEN   ' NUL
            GOTO ExitFunction
          ELSEIF @y = 45 THEN  ' -
            DECR y             ' move to previous char in expression
            PrevChar = @y      ' save previous char
            y = y + 2          ' move to next char in expression
            NextChar = @y      ' save next char in expression
            DECR y             ' restore current char in expression
            IF (PrevChar = 91) OR (PrevChar = 33) OR (NextChar = 93) THEN
              IF @y = @x THEN
                IF matc = %FALSE THEN  'if matching is false, exit
                  GOTO ExitFunction
                ELSE
                    EXIT DO
                END IF
              END IF
            ELSE
              IF (@x >= PrevChar) AND (@x =< NextChar) THEN
                IF matc = %FALSE THEN
                  GOTO ExitFunction
                ELSE
                  EXIT DO
                END IF
              ELSE
                INCR y
              END IF
            END IF
          ELSEIF @y = @x THEN  ' do they match?
            IF matc = %FALSE THEN  'if matching is false, exit
              GOTO ExitFunction
            ELSE
              EXIT DO
            END IF
          END IF
          INCR y               'next char in expression
        LOOP

      CASE ELSE
        IF @x <> @y THEN
          GOTO ExitFunction
        END IF

    END SELECT

    INCR x    ' next char in source string
    INCR y    ' next char in expression

  LOOP

ExitFunction:
  FUNCTION = result

END FUNCTION


This updated function should handle the mentioned issues and provide better wildcard pattern matching.

#10
You can implement different types of neurons for a neural network using assembly or similar low-level code. However, it's important to note that assembly code is not typically used for implementing neural networks due to its complexity and lack of readability. High-level languages like Python, with libraries such as TensorFlow or PyTorch, are more commonly used for this purpose.

That being said, here's an example of a simple ReLU (Rectified Linear Unit) neuron and a sigmoid neuron using the fastest available floating-point data type (EXTENDED) in assembly-like code. Note that this is a simplified example and does not include any optimizations or additional features that would be needed for a real-world neural network implementation.

**ReLU Neuron:**

MACRO FUNCTION ReLUNeuron_Extended(input)
  MACROTEMP output
  DIM output AS EXTENDED

  !fld input       'load input value
  !fldz            'load 0.0
  !fcomip st(1), st(0) 'compare input with 0.0
  !fnstsw ax       'store FPU flags in ax
  !sahf            'transfer FPU flags to CPU flags
  !jb .Lnegative  'jump to .Lnegative if input < 0.0

  !fstp output     'store input value as output if input >= 0.0
  !jmp .Lend

.Lnegative:
  !fstp input      'discard input value
  !fldz            'load 0.0
  !fstp output     'store 0.0 as output

.Lend:
END MACRO = output

**Sigmoid Neuron:**

MACRO FUNCTION SigmoidNeuron_Extended(input)
  MACROTEMP output
  DIM output AS EXTENDED

  !fld input       'load input value
  !fldl2e          'load log2(e)
  !fyl2x           'compute input * log2(e)
  !frndint         'round to nearest integer
  !f2xm1           'compute 2^(input * log2(e)) - 1
  !fld1            'load 1.0
  !faddp           'compute 1.0 + (2^(input * log2(e)) - 1)
  !fld1            'load 1.0
  !fscale          'compute 1.0 / (1.0 + (2^(input * log2(e)) - 1))
  !fstp output     'store output value

END MACRO = output

Backpropagation

**Backpropagation in Assembly-like Code for ReLU and Sigmoid Neurons**

**🚀 Forward Pass:**
1. **Calculate Outputs:** Sequentially compute and store the output for each neuron from input to output layers.

**🎯 Output Layer Error Calculation:**
1. **Compute Error:** Use mean squared error (MSE) for each neuron by \( \frac{{(\text{expected value} - \text{output value})^2}}{2} \).

**⏪ Backward Pass:**
1. **Error Propagation:** Using errors from subsequent layers, compute errors for the previous layers.
2. **Activation Derivatives:**
  - **ReLU:** Derivative is 1 if input > 0; otherwise, it's 0.
  - **Sigmoid:** Derivative is output * (1 - output).
3. **Gradient Calculation:** Multiply error by the derivative to get the gradient.

**🔧 Weight Update:**
1. **Adjust Weights:** Apply updates using SGD; \( \text{weight} = \text{weight} - \text{learning rate} \times \text{gradient} \).

**Example for a ReLU Neuron Backward Pass and Weight Update:**
; Assuming eax holds the input to the neuron
; ebx holds the derivative
; ecx holds the error from the next layer
; edx holds the learning rate

cmp eax, 0          ; Check if input is positive
jle .zero_gradient  ; Jump if not positive, derivative is zero
mov ebx, 1          ; Set derivative to 1
jmp .continue      ; Continue computation

.zero_gradient:
mov ebx, 0          ; Set derivative to zero

.continue:
; Calculate gradient: gradient = error * derivative
mul ebx, ecx        ; Multiply error by derivative to get gradient

; Update weight: weight -= learning_rate * gradient
; Assuming esi points to weight
mov eax, [esi]      ; Load current weight
sub eax, edx        ; Subtract learning rate times gradient from weight
mov [esi], eax      ; Store updated weight back

This is just a simplified example demonstrates the process for managing backpropagation for ReLU neurons using assembly-like pseudocode.

Following is real code.

'##################################################################################################
'
'##################################################################################################
' BackpropagateReLUNeuron_Extended(P1, P2, P3, P4)
'
' This macro performs backpropagation for a single ReLU neuron using the provided parameters:
'
' P1 (input, EXTENDED): The input value to the neuron.
'   Value range: Any real number.
'
' P2 (error, EXTENDED): The error value for the neuron, calculated based on the output error and the weights from the subsequent layer.
'   Value range: Any real number.
'
' P3 (weight, EXTENDED): The weight value for the neuron.
'   Value range: Any real number.
'   On output, the updated weight value is stored back into this memory location.
'
' P4 (learning_rate, EXTENDED): The learning rate value used for updating the weight.
'   Value range: A positive real number, typically between 0.0 and 1.0.

MACRO BackpropagateReLUNeuron_Extended(P1, P2, P3, P4)
  MACROTEMP gradient
  DIM gradient AS EXTENDED

  !fld P1          'load input value
  !fldz            'load 0.0
  !fcomip st(1), st(0) 'compare input with 0.0
  !fnstsw ax       'store FPU flags in ax
  !sahf            'transfer FPU flags to CPU flags
  !jb .Lnegative  'jump to .Lnegative if input < 0.0

  !fld P2          'load error value
  !fmul P1         'compute gradient = error * input
  !fstp gradient   'store gradient value
  !jmp .Lend

.Lnegative:
  !fldz            'load 0.0
  !fstp gradient   'store gradient value as 0.0

.Lend:
  !fld P3          'load weight value
  !fld P4          'load learning rate value
  !fmul gradient   'compute learning_rate * gradient
  !fsubp           'compute weight - learning_rate * gradient
  !fstp P3         'store updated weight value

END MACRO