Author Topic: CODE EDITS FOR OLD SDL-BRANCH OF QB64 GO HERE  (Read 1598 times)

Galleon

  • Administrator
  • Hero Member
  • *****
  • Posts: 5485
  • QB Forever
CODE EDITS FOR OLD SDL-BRANCH OF QB64 GO HERE
« on: December 30, 2012, 03:21:11 pm »
As you know I'm no longer developing the SDL branch of QB64 in favour of the newer GL branch. By community request, I've added this topic so experienced QB64 users can post bug fixes etc to apply to the SDL branch. Any change requiring major code overhaul will be flat-out rejected. Nor is this a place to add your own custom mods or make feature requests. Keep your proposals simple and be specific about the files and locations you wish to change. Do so by replying to this post.
Something old... Something new... Something borrowed... Something blue...

SMcNeill

  • Moderator
  • Hero Member
  • *****
  • Posts: 6022
Re: CODE EDITS FOR OLD SDL-BRANCH OF QB64 GO HERE
« Reply #1 on: December 30, 2012, 04:35:16 pm »
The repair for the WRITE bug in SDL QB64:

All that needs to change is down about on line 8662, SDL version or line 8724, GL version, there needs to be a call to the error handler (if needed), before the call out to the finished routine.

Change:
Code: [Select]
                IF firstelement$ = "WRITE" THEN 'write
                    xwrite ca$, n
                    GOTO finishedline
                END IF '"write"

To:
Code: [Select]
                IF firstelement$ = "WRITE" THEN 'write
                    xwrite ca$, n
                    IF Error_Happened THEN GOTO errmes
                    GOTO finishedline
                END IF '"write"

From my testing, this corrects the issue and doesn't seem to cause any other issues to pop-up in return. 
http://bit.ly/TextImage -- Library of QB64 code to manipulate text and images, as a BM library.

http://bit.ly/Color32 -- A set of color CONST for use in 32 bit mode, as a BI library.

SMcNeill

  • Moderator
  • Hero Member
  • *****
  • Posts: 6022
Re: CODE EDITS FOR OLD SDL-BRANCH OF QB64 GO HERE
« Reply #2 on: December 30, 2012, 04:43:55 pm »
Fix for SDL _MEM for string support.

For fixed length strings, the problem seems to be down on line 17097 (SDL version).

Simply change:
Code: [Select]
evaluatetotyp$ = "(ptrszint)" + e$ + "," + bytes$ + "," + str2(t) + "," + bytes$ + ",sf_mem_lock"
to:
Code: [Select]
evaluatetotyp$ = "(ptrszint)" + e$ + "->chr," + bytes$ + "," + str2(t) + "," + bytes$ + ",sf_mem_lock"
The pointer is simply going to the wrong place, making _MEM and strings reference the wrong things.

**************************

For string arrays to work with _MEM, change lines 19755 - 19758 (SDL version) from:
Code: [Select]
        IF (typ AND ISFIXEDLENGTH) THEN
            offset$ = "&((uint8*)(" + n$ + "[0]))[(" + a$ + ")*" + str2(id.tsize) + "]"
            r$ = "qbs_new_fixed(" + offset$ + "," + str2(id.tsize) + ",1)"
        ELSE

to:
Code: [Select]
    IF (typ AND ISSTRING) THEN
        IF (typ AND ISFIXEDLENGTH) THEN
            IF a$ = "0" THEN
                r$ = "((uint8*)(" + n$ + "[0]))[(" + a$ + ")*" + str2(id.tsize) + "]"
            ELSE
                offset$ = "&((uint8*)(" + n$ + "[0]))[(" + a$ + ")*" + str2(id.tsize) + "]"
                r$ = "qbs_new_fixed(" + offset$ + "," + str2(id.tsize) + ",1)"
                typ = typ + ISPOINTER + ISREFERENCE
            END IF
         ELSE


These changes allow for:

Code: [Select]
dim x as string * 10
dim x(10) as string * 10
dim m as _mem
dim n as _mem

m = _mem(x)
n = _mem(x())

However, they don't allow for m = _mem(x(1)).  To get that type of result one would need to use m = _memelement(x(1)). 
http://bit.ly/TextImage -- Library of QB64 code to manipulate text and images, as a BM library.

http://bit.ly/Color32 -- A set of color CONST for use in 32 bit mode, as a BI library.