10.03.2019 - Round 1 results of our "A Love Letter For FreeBASIC" game dev competition have been published. Please be sure to check the results thread: http://games.freebasic.net/forum/index.php?topic=629.0. Don't forget that the competition is continuing with a round 2, lasting till 29th of April, 300 USD first prize. Stay tuned!

Author Topic: Possible GET bug?  (Read 1652 times)

ecxjoe

  • Novice
  • ***
  • Posts: 78
    • View Profile
    • Delta Code
Possible GET bug?
« on: May 06, 2010, 03:12:49 PM »
This is a small program that prints out and captures the ascii characters as sprites. It saves the sprites to a file, then loads them back in and displays them to verify they were captured and saved correctly.

I had to code my own GetSprite() sub because FreeBasic's GET function wasn't capturing graphics the correct way. As it is, it calls my GetSprite() sub. Run the program, then uncomment the line "GET (x0, y0)-(x1, y1), sprFont(n*BPS)" and comment "GetSprite x0, y0, x1, y1, @sprFont(n*BPS)" and run the program again to see the problem using FreeBasic's GET command causes. When they are PUT back to the screen, the sprites have numerous artifacts.

I shouldn't need more than 260 bytes per sprite. They are 8x8 sprites in 32bit mode, so the formula is 8*8*4+4 bytes or 8*8+1 integers. FreeBasic's PUT has no problem rendering the sprites I captured with my GetSprite() sub, so what am I doing wrong with the GET command?

Code: [Select]
SUB GetSprite (x0 AS INTEGER, y0 AS INTEGER, x1 AS INTEGER, y1 AS INTEGER, pSprite AS INTEGER PTR)
   
    pSprite[0] = (8 SHL 16) OR 64
   
    DIM x AS INTEGER, y AS INTEGER
    DIM n AS INTEGER: n = 1
    FOR y = y0 TO y1
        FOR x = x0 TO x1
            pSprite[n] = POINT(x, y)
            n += 1
        NEXT x
    NEXT y
   
END SUB


CONST BPS = 8*8+1
DIM sprFont(BPS*96) AS INTEGER

SCREENRES 320, 240, 32

DIM n AS INTEGER
FOR n = 32 TO 127
    PRINT CHR$(n);
NEXT n

DIM x AS INTEGER, y AS INTEGER
DIM x0 AS INTEGER, y0 AS INTEGER
DIM x1 AS INTEGER, y1 AS INTEGER
'- get graphics
n = 0
FOR y = 0 TO 2
    FOR x = 0 TO 39
        x0 = x*8: y0 = y*8
        x1 = x0+7: y1 = y0+7
        'GET (x0, y0)-(x1, y1), sprFont(n*BPS)
        GetSprite x0, y0, x1, y1, @sprFont(n*BPS)
        n += 1
        IF n >= 96 THEN EXIT FOR
    NEXT x
NEXT y

LOCATE 7, 1: PRINT "Capture Graphics"

SLEEP
BSAVE "font.bsv", @sprFont(0), BPS*96*4

BLOAD "font.bsv", @sprFont(0)
CLS
'- put graphics to verify capture
n = 0
FOR y = 0 TO 2
    FOR x = 0 TO 39
        PUT (x*8, y*8), sprFont(n*BPS), PSET
        n += 1
        IF n >= 96 THEN EXIT FOR
    NEXT x
NEXT y

LOCATE 7, 1: PRINT "Verify Graphics"

SLEEP
END

ecxjoe

  • Novice
  • ***
  • Posts: 78
    • View Profile
    • Delta Code
Re: Possible GET bug?
« Reply #1 on: May 07, 2010, 03:44:56 PM »