DDT with FreeBasic Project

Started by José Roca, May 03, 2025, 06:02:20 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

José Roca

I'm programming for fun. If AI does the programming for me, where is the fun?

Theo Gottwald

#16
 The Fun of Programming with AI: A Game-Changer for Coders!
The fun of programming has skyrocketed!  Now, you're not just coding solo—you've got 1, 3, or even 4 AI assistants taking on the boring parts, helping you reach your goals 4 times faster!
It feels like the first time you discovered PowerBASIC—remember the thrill? You'd talk to the compiler, tweak inputs, and learn from error messages.  Now, it's the same vibe, but the new "AI Compiler" is a dream—way smarter than the good old PowerBASIC days. It gives you much better answers and makes coding a breeze!
Here's why coding with AI is more fun and a total game-changer:
Build 4x Larger Projects
Tackle massive projects with ease, thanks to AI handling repetitive tasks.

No More Chasing Boring Errors
Forget sweating over typos or silly bugs—AI (like Grok or others) will spot them for you!

Feel Like a Team of Coders
Work as if you have a whole crew by your side, boosting your productivity.

Make Your Programs Smarter
Integrate AI to create intuitive apps that even "less tech-savvy" users can understand.

Speed Things Up with AI-Generated ASM Code
Let AI whip up assembly code for those performance-critical sections.

Become Besties with AI
Over time, you'll get the hang of "how AI ticks" and start treating it like a trusted friend. That's how it feels for me, at least!

Code in Languages You Don't Even Know



Okay, MASTER. Thank you for providing the specific documentation for GSB. / JSR..

You are correct. The documentation clearly shows that GSB.Label|Param1|Param2... is the standard way to pass parameters, and they are accessed within the subroutine using §§_01, §§_02, etc. My previous modification to use the stack (PNS/GSB/POP) for all calls was an incorrect generalization based on only some examples.

Based on this corrected understanding:

    Part 2 requires revision: I need to revert the changes where I replaced GSB.Label|Param with PNS/GSB/POP. The original direct parameter passing was correct.

    Part 3 (:Run) requires revision: The :Run subroutine should access its input command string using VAR.$$CMD=§§_01 instead of POV.$$CMD. Internal GSB calls within :Run should also use direct parameter passing.

    Parts 4 and 5: The subroutines themselves need to be adjusted to expect parameters via §§_xx instead of using POV (unless POV was explicitly intended for stack manipulation in a specific subroutine like :DoJsonEscape).

Action Plan:

    I will first revise Part 2 according to this corrected understanding of GSB. parameter passing.

    I will present the revised Part 2 for your approval.

    Once Part 2 is approved, I will proceed with revising Part 3 (:Run) based on this new understanding.

Let me provide the corrected Part 2 now.

Corrected Part 2 (Revision 2 - GSB Parameter Handling)
Generated spr

     
'=======================================================================
' --- Main Execution Loop ---
'=======================================================================
:Main_Loop
' --- Increment Loop Counter & Check Limit ---
VIC.$$LPC
IVV.$$LPC>$$MAX
  PRT.ERROR MainLoop - Maximum iterations ($$MAX) reached.
  GTO.Exit
EIF.

' --- Loop Detection ---
VAR.$$CMH=$$CMD
VAR.$$DOL=0
IVS.$$CMH=$$HI1
  IVS.$$CMH=$$HI2
    IVS.$$CMH=$$HI3
      IVS.$$CMH=$$HI4
        PRT.WARNING MainLoop - LOOP DETECTED: Command '$$CMH' repeated 4 times. Intervening.
        VAR.$$DOL=1
      EIF.
    EIF.
  EIF.
EIF.

' --- Intervention Logic (If Loop Detected) ---
IVV.$$DOL=1
  GSB.ParseCmd|$$CMH
  POP.$$ACT|$$AGN|$$DTL|$$MOD
  SCS.$$ACT
  CAS.RUN
    VAR.$$CMD=GET_CONCEPT
    PRT.INFO MainLoop - Intervention: Forcing GET_CONCEPT.
  CAS.LIST_AGENTS
    VAR.$$CMD=GET_CONCEPT
    PRT.INFO MainLoop - Intervention: Forcing GET_CONCEPT.
  CAS.READ_FILE
    VAR.$$CMD=CLEAR_CONTEXT.ALL
    PRT.INFO MainLoop - Intervention: Forcing CLEAR_CONTEXT.ALL.
  CAS.READ_FILE_TAIL
    VAR.$$CMD=CLEAR_CONTEXT.ALL
    PRT.INFO MainLoop - Intervention: Forcing CLEAR_CONTEXT.ALL.
  CAS.GET_CONCEPT
    VAR.$$CMD=CLEAR_CONTEXT.ALL
    PRT.INFO MainLoop - Intervention: Forcing CLEAR_CONTEXT.ALL.
  CAS.GET_PLAN
    VAR.$$CMD=CLEAR_CONTEXT.ALL
    PRT.INFO MainLoop - Intervention: Forcing CLEAR_CONTEXT.ALL.
  CAE.
    VAR.$$CMD=EXIT_WORKFLOW.Loop detected for unknown/other command '$$ACT'.
    PRT.ERROR MainLoop - Intervention: Forcing EXIT due to loop on '$$ACT'.
  ESC.
  ' --- Reset History after intervention ---
  VAR.$$HI1=
  VAR.$$HI2=
  VAR.$$HI3=
  VAR.$$HI4=
  PRT.DEBUG MainLoop - Command history reset. Next command is intervention: $$CMD
  GTO.Main_Loop
EIF.

' --- Update Command History (if no loop detected) ---
VAR.$$HI4=$$HI3
VAR.$$HI3=$$HI2
VAR.$$HI2=$$HI1
VAR.$$HI1=$$CMH

' --- Process Current Command ---
PRT.INFO MainLoop - Loop $$LPC / $$MAX CMD: $$CMD
VAR.$$LRC=$$CMD
VBT.$$LRC
JNS.$$LRC|Main_Loop_Continue
' Command is empty, skip to next iteration

' --- Parse and Dispatch ---
VAR.$$ACT=
VAR.$$AGN=
VAR.$$DTL=
VAR.$$MOD=
GSB.ParseCmd|$$LRC
POP.$$ACT|$$AGN|$$DTL|$$MOD

JNS.$$ACT|Parse_Cmd_Failed
' Jump if Action is empty after parsing

' --- Main Command Dispatch ---
VAR.$$RES=1
' Default success assumption
VAR.$$NPM=
' Default Next PM message (empty)
VAR.$$LSA=
' Clear Last Source Agent before action

SCS.$$ACT

CAS.RUN
  GSB.Run|$$LRC
  POP.$$RES
    ' --- Post-RUN logic ---
  IVV.$$RES=1
    PRT.DEBUG MainLoop - RUN successful. Last source agent: $$LSA
    VAR.$$TMP=$$LSA
    VTU.$$TMP
    IVS.$$TMP!PROJECT_MANAGER
      ' Non-PM agent ran successfully. Call PM with its output.
      PRT.DEBUG MainLoop - Non-PM agent $$LSA ran. Preparing PM call.
      VAR.$$TMP=$$LSA
      VAR.$$TMP=$$TMP$: $$TEX
      ' Prefix output with agent name

      ' --- Truncate $$TMP if needed (Simple truncation) ---
      LEN.$$TMP|$$LEN
      IVV.$$LEN>1000
        GSS.1|1000|$$TMP|$$TMP
        VAR.$$TMP=$$TMP... (truncated)
      EIF.
      ' Set NEXT command to inform PM
      VAR.$$CMD=RUN.PROJECT_MANAGER.$$TMP.GM
      PRT.DEBUG MainLoop - Set next CMD to call PM.
    ELS.
      ' PROJECT_MANAGER itself ran successfully. Process its output.
      PRT.DEBUG MainLoop - PM ran successfully. Processing its output $$TEX.
      ' Uses $$TEX, sets global $$CMD for next loop
      GSB.DetermineNextCmdPM
      ' No params needed as it reads global $$TEX
    EIF.
  EIF.
    ' If $$RES=0, :Run already set $$CMD to PM error msg. Flow continues below.

CAS.HIRE
  GSB.Hire|$$LRC
  POP.$$RES
  IVV.$$RES=1
    VAR.$$NPM=INFO: Agent hired via '$$LRC'.
  ELS.
    VAR.$$NPM=ERROR: HIRE failed for '$$LRC'.
  EIF.

CAS.LIST_AGENTS
  GSB.List
  ' No params needed, no result popped
  VAR.$$RES=1
  VAR.$$NPM=INFO: Agent list displayed.

CAS.RETIRE
  GSB.Retire|$$LRC
  POP.$$RES
  IVV.$$RES=1
    VAR.$$NPM=INFO: Agent retired via '$$LRC'.
  ELS.
    VAR.$$NPM=ERROR: RETIRE failed for '$$LRC'.
  EIF.

CAS.SAVE_AGENT_STATE
  GSB.Sav_All
  POP.$$RES
  IVV.$$RES=1
    VAR.$$NPM=INFO: Agent state saved.
  ELS.
    VAR.$$NPM=ERROR: SAVE_AGENT_STATE failed.
  EIF.

CAS.CLEAR_AGENTS
  GSB.Clear
  POP.$$RES
  IVV.$$RES=1
    VAR.$$NPM=INFO: Agent state cleared.
  ELS.
    VAR.$$NPM=ERROR: CLEAR_AGENTS failed.
  EIF.

  ' --- PM Directed Script Actions ---
CAS.READ_FILE
  GSB.handle_read_file|$$LRC
  POP.$$RES

CAS.READ_FILE_TAIL
  GSB.handle_read_file_tail|$$LRC
  POP.$$RES

CAS.GET_CONCEPT
  GSB.handle_get_concept
  POP.$$RES

CAS.GET_PLAN
  GSB.handle_get_plan
  POP.$$RES

CAS.CLEAR_CONTEXT
  GSB.handle_clear_context|$$LRC
  POP.$$RES

CAS.SAVE_CONTEXT
  GSB.handle_save_context|$$LRC
  POP.$$RES

CAS.EXIT_WORKFLOW
  PRT.INFO MainLoop - EXIT_WORKFLOW command received. Reason: $$DTL
  GTO.Exit

CAE.
  PRT.ERROR MainLoop - Unknown ACTION received in dispatch: '$$ACT'. Command: $$LRC
  VAR.$$RES=0
  VAR.$$NPM=ERROR: Unknown action '$$ACT' received.

ESC.
' End Main Dispatch SCS

' --- Post-Action Processing (Determine next $$CMD if not already set) ---
IVV.$$RES=1
  ' Action Succeeded ($$RES=1)
  PRT.DEBUG MainLoop - Action '$$ACT' completed successfully.
  VAR.$$ERC=0
  ' Reset consecutive error count
  VAR.$$AKY=$$ACT
  VTU.$$AKY
  IVS.$$AKY=RUN
    ' RUN logic already handled setting next $$CMD
  ELS.
    IVS.$$AKY=EXIT_WORKFLOW
      ' EXIT logic already handled via GTO
    ELS.
      ' Action was NOT RUN/EXIT and succeeded. Check if handler set CMD.
      VAR.$$CTM=$$CMD
      IVS.$$CTM=$$LRC
        ' If CMD hasn't changed, the handler didn't set it. We need to call PM.
        LEN.$$NPM|$$LEN
        IVV.$$LEN>0
          ' $$NPM is NOT empty, use the specific status message
          VAR.$$CMD=RUN.PROJECT_MANAGER.$$NPM.GM
          PRT.DEBUG MainLoop - Has NPM. Set next CMD to inform PM: $$CMD
        ELS.
          ' $$NPM IS empty, send generic INFO message
          VAR.$$CMD=RUN.PROJECT_MANAGER.INFO: Action '$$ACT' completed OK.GM
          PRT.DEBUG MainLoop - No NPM. Set generic PM success info CMD.
        EIF.
      ELS.
        ' Handler (like READ_FILE) already set $$CMD. Keep it.
        PRT.DEBUG MainLoop - Handler for '$$ACT' already set next CMD: $$CMD
      EIF.
    EIF.
  EIF.
ELS.
  ' Action Failed ($$RES=0)
  VIC.$$ERC
  PRT.ERROR MainLoop - Action '$$ACT' FAILED. Error count: $$ERC / $$ERR
  ' --- Refactored check for >= ---
  IVV.$$ERC<$$ERR
    ' ERC is less than ERR, continue
  ELS.
    ' ERC is greater than or equal to ERR, exit
    PRT.FATAL MainLoop - Maximum consecutive errors ($$ERR) reached.
    GTO.Exit_Error
  EIF.

  ' Set next command to call PM with the Error message
  LEN.$$NPM|$$LEN
  IVV.$$LEN>0
    ' Check if a specific error message exists in $$NPM
    VAR.$$CMD=RUN.PROJECT_MANAGER.$$NPM.GM
  ELS.
    ' Use generic failure message if $$NPM empty
    VAR.$$CMD=RUN.PROJECT_MANAGER.ERROR: Action '$$ACT' failed (from RES=0).GM
  EIF.
  PRT.DEBUG MainLoop - Set next CMD to report error to PM: $$CMD
EIF.

:Main_Loop_Continue
GTO.Main_Loop

:Parse_Cmd_Failed
PRT.ERROR MainLoop - Command parsing failed for: '$$LRC'. Defaulting to LIST_AGENTS.
VAR.$$CMD=LIST_AGENTS
GTO.Main_Loop_Continue

'=======================================================================
' --- Subroutines (BEGIN IN NEXT PART) ---
'=======================================================================

   

IGNORE_WHEN_COPYING_START
Use code with caution. Spr
IGNORE_WHEN_COPYING_END

Summary of Changes in Corrected Part 2 (Revision 2):

    GSB Parameter Passing: Reverted all PNS/GSB/POP sequences back to the direct GSB.Label|Param1... format.

    POP Usage: Retained POP only where a subroutine is documented or logically expected to return a value that needs to be captured immediately after the GSB call (e.g., after GSB.ParseCmd, GSB.Run, GSB.Hire, etc.). Subroutines like :List or :DetermineNextCmdPM which primarily modify globals or print output don't require a POP.

    Other corrections from the previous review (inline comments, $len, JNS targets, IVV operators) are maintained.

Please review this corrected Part 2, MASTER. Let me know if this aligns with your intent before I proceed with revising Part 3 (:Run) according to the §§_xx parameter access method.

José Roca

You really need help using that syntax :)

Theo Gottwald

#18
It's not a new invention. Back then, they called it mnemonics. The main difference now is that these mnemonics don't just include x86 or x64 instructions, but also cover program calls for more complex systems. The rest of the syntax has pretty much stayed the same as with the old assembler. 🖥�🔡🚀

On the other hand, I wanted to show that if AI can generate this kind of syntax, then it can certainly handle FreeBASIC as well. Don't you think?

The day before yesterday was June 20, 2025, a date worth remembering—it marks the day when American AI companies were definitively outperformed by their Chinese counterparts. One of these new Chinese AIs is the one you're interacting with right now. You should definitely give it a try.

And the code you see below is a one-shot. I simply asked the AI to create a magnifying glass in FreeBASIC, as I didn't have any other ideas at the moment. But doesn't the result look nothing like FreeBASIC?

#FreeBASIC #AIgeneratedCode #Programming #MagnifyingGlass #CodeReview


https://agent.minimax.io/share/282725486514240


#ArtificialIntelligence #AICoding #FreeBASIC #ProgrammingThoughts #AIDevelopment


' Magnifying Glass Tool - FreeBasic GUI Application
' Created by MiniMax Agent
' Features: Form with magnifying glass functionality

#include "fbgfx.bi"
#include "windows.bi"

' Constants for the application
Const SCREEN_WIDTH = 800
Const SCREEN_HEIGHT = 600
Const MAG_SIZE = 200          ' Size of magnifying glass circle
Const MAG_ZOOM = 3            ' Magnification factor

' Structure to hold magnifying glass state
Type MagnifyingGlass
    x As Integer              ' Current X position
    y As Integer              ' Current Y position
    active As Integer         ' Is magnifying glass active
    radius As Integer         ' Radius of magnifying glass
    zoom As Single           ' Zoom factor
End Type

' Global variables
Dim Shared mag As MagnifyingGlass
Dim Shared background_buffer As Any Ptr
Dim Shared mag_buffer As Any Ptr

' Initialize the magnifying glass
Sub InitMagnifyingGlass()
    mag.x = SCREEN_WIDTH \ 2
    mag.y = SCREEN_HEIGHT \ 2
    mag.active = 0
    mag.radius = MAG_SIZE \ 2
    mag.zoom = MAG_ZOOM
   
    ' Create image buffers
    background_buffer = ImageCreate(SCREEN_WIDTH, SCREEN_HEIGHT)
    mag_buffer = ImageCreate(mag.radius * 2, mag.radius * 2)
End Sub

' Draw the background scene (sample content to magnify)
Sub DrawBackground()
    ' Clear screen with gradient background
    For y As Integer = 0 To SCREEN_HEIGHT - 1
        Dim col As UInteger = RGB(y \ 3, (y + 100) \ 4, 255 - y \ 3)
        Line (0, y)-(SCREEN_WIDTH, y), col
    Next
   
    ' Draw some sample objects to magnify
    Circle (150, 150), 50, RGB(255, 255, 0)
    Circle (150, 150), 30, RGB(255, 0, 0)
   
    Circle (400, 300), 80, RGB(0, 255, 0)
    Circle (400, 300), 60, RGB(0, 0, 255)
    Circle (400, 300), 40, RGB(255, 255, 255)
   
    ' Draw some text
    Draw String (50, 50), "Sample Text to Magnify", RGB(255, 255, 255)
    Draw String (300, 100), "FreeBasic Magnifying Glass", RGB(255, 255, 0)
    Draw String (200, 500), "Click to activate magnifying glass", RGB(200, 200, 200)
   
    ' Draw rectangles
    Line (600, 200)-(700, 300), RGB(255, 0, 255), BF
    Line (610, 210)-(690, 290), RGB(0, 255, 255), BF
   
    ' Save current screen to background buffer
    Get (0, 0)-(SCREEN_WIDTH - 1, SCREEN_HEIGHT - 1), background_buffer
End Sub

' Apply magnifying glass effect
Sub ApplyMagnifyingGlass(mx As Integer, my As Integer)
    If background_buffer = 0 Then Exit Sub
   
    ' Calculate source rectangle for magnification
    Dim src_x As Integer = mx - (mag.radius / mag.zoom)
    Dim src_y As Integer = my - (mag.radius / mag.zoom)
    Dim src_w As Integer = (mag.radius * 2) / mag.zoom
    Dim src_h As Integer = (mag.radius * 2) / mag.zoom
   
    ' Ensure source coordinates are within bounds
    If src_x < 0 Then src_x = 0
    If src_y < 0 Then src_y = 0
    If src_x + src_w >= SCREEN_WIDTH Then src_w = SCREEN_WIDTH - src_x - 1
    If src_y + src_h >= SCREEN_HEIGHT Then src_h = SCREEN_HEIGHT - src_y - 1
   
    ' Clear magnifying glass buffer
    ImageDestroy mag_buffer
    mag_buffer = ImageCreate(mag.radius * 2, mag.radius * 2)
   
    ' Copy and scale the region
    Put mag_buffer, (0, 0), background_buffer, (src_x, src_y)-(src_x + src_w, src_y + src_h), PSet
   
    ' Draw the magnified circular area
    Dim dest_x As Integer = mx - mag.radius
    Dim dest_y As Integer = my - mag.radius
   
    ' Draw circle background
    Circle (mx, my), mag.radius + 2, RGB(100, 100, 100), , , , F
    Circle (mx, my), mag.radius, RGB(255, 255, 255), , , , F
   
    ' Apply circular clipping and draw magnified content
    For cy As Integer = -mag.radius To mag.radius
        For cx As Integer = -mag.radius To mag.radius
            Dim dist As Single = Sqr(cx * cx + cy * cy)
            If dist <= mag.radius Then
                Dim src_px As Integer = (cx + mag.radius) / mag.zoom
                Dim src_py As Integer = (cy + mag.radius) / mag.zoom
               
                If src_px >= 0 And src_px < mag.radius * 2 And src_py >= 0 And src_py < mag.radius * 2 Then
                    Dim pixel_color As UInteger = Point(src_x + src_px, src_y + src_py, background_buffer)
                    PSet (mx + cx, my + cy), pixel_color
                End If
            End If
        Next
    Next
   
    ' Draw magnifying glass border
    Circle (mx, my), mag.radius, RGB(50, 50, 50), , , 3
    Circle (mx, my), mag.radius - 1, RGB(200, 200, 200), , , 1
   
    ' Draw handle
    Dim handle_x As Integer = mx + mag.radius * 0.7
    Dim handle_y As Integer = my + mag.radius * 0.7
    Line (handle_x, handle_y)-(handle_x + 30, handle_y + 30), RGB(139, 69, 19), , &H1111
    Circle (handle_x + 30, handle_y + 30), 8, RGB(160, 82, 45), , , , F
End Sub

' Main program loop
Sub MainLoop()
    Dim mx As Integer, my As Integer, mb As Integer
    Dim key As String
   
    Do
        ' Get mouse input
        GetMouse mx, my, , mb
       
        ' Get keyboard input
        key = InKey
       
        ' Clear screen and redraw background
        Cls
        Put (0, 0), background_buffer, PSet
       
        ' Handle mouse input
        If mb And 1 Then ' Left mouse button
            mag.active = 1
            mag.x = mx
            mag.y = my
        ElseIf mb And 2 Then ' Right mouse button
            mag.active = 0
        End If
       
        ' Update magnifying glass position if active
        If mag.active Then
            mag.x = mx
            mag.y = my
            ApplyMagnifyingGlass(mag.x, mag.y)
        End If
       
        ' Draw instructions
        Draw String (10, 10), "Left Click: Activate Magnifying Glass", RGB(255, 255, 255)
        Draw String (10, 25), "Right Click: Deactivate", RGB(255, 255, 255)
        Draw String (10, 40), "ESC: Exit", RGB(255, 255, 255)
        Draw String (10, 55), "Zoom: " + Str(mag.zoom) + "x", RGB(255, 255, 255)
       
        ' Handle keyboard input
        Select Case UCase(key)
            Case "+"
                If mag.zoom < 5 Then mag.zoom += 0.5
            Case "-"
                If mag.zoom > 1 Then mag.zoom -= 0.5
            Case Chr(27) ' ESC key
                Exit Do
        End Select
       
        ' Refresh display
        Sleep 16 ' Approximately 60 FPS
       
    Loop
End Sub

' Cleanup resources
Sub Cleanup()
    If background_buffer <> 0 Then ImageDestroy background_buffer
    If mag_buffer <> 0 Then ImageDestroy mag_buffer
End Sub

' Main program
Sub Main()
    ' Initialize graphics mode
    ScreenRes SCREEN_WIDTH, SCREEN_HEIGHT, 32
    WindowTitle "FreeBasic Magnifying Glass Tool"
   
    ' Initialize magnifying glass
    InitMagnifyingGlass()
   
    ' Draw initial background
    DrawBackground()
   
    ' Run main loop
    MainLoop()
   
    ' Cleanup
    Cleanup()
End Sub

' Program entry point
Main()


Imagine it like this: someone has just placed a co-programmer in your backyard. You don't know them yet, and they might seem unfamiliar—they're a foreigner from China. But give them a chance. Assign them a task and see what they can do for you. Don't be prejudiced; they're genuinely kind and incredibly talented. And no, you don't even need to learn Chinese.

#AIProgramming #CrossCulturalCollaboration #TechDiversity #GlobalTalent #Inclusion


#TechHistory #Programming #Assembler #Coding #Innovation #SoftwareDevelopment #NerdTalk 💻🤓⚙️🔍🔢🧠✨