Qbasicnews.com

Full Version: Assembly bug?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I've started to port my work to fb, and I've run into a problem.

Code:
defint a-z
'option explicit

'$include: "sdl\sdl.bi"
declare sub PSET ( x as integer , y as integer, R as UBYTE , G as UBYTE, B as UBYTE )
declare sub flipScreen()
dim shared screen as SDL_Surface ptr
dim tim as integer
'dim a as string
'Dim X as integer
'Dim Y as integer
Dim T as UBYTE
dim shared MouseX as integer
dim shared MouseY as integer
dim oldtimer as double
DIM a AS SINGLE
DIM ang AS SINGLE
DIM map(0 TO 11, 0 TO 11)
DIM colrs(0 TO 150)
FOR a = 0 TO 5
    colrs(a) = 31 - ((a / 50) * 16)
NEXT a

DIM angle
DIM x, y
CONST pi = 3.141579
DIM lin(0 TO 320)  AS INTEGER
DIM z(0 TO 320)              AS INTEGER


screen = SDL_SetVideoMode( 320, 240, 32, SDL_HWSURFACE or SDL_DOUBLEBUF)
if screen = 0 then
SDL_Quit
end 1
end if


oldtimer = timer
tim = 0


FOR a = 1 TO 10
        linvar = linvar + 1
        FOR b = 1 TO 10
                IF INT(RND(1) * 5) = 1 THEN map(a, b) = INT(RND(1) * 5)
        NEXT b
NEXT a

x = 50
y = 50
linvar = 0
WHILE k$ <> " "
  linvar = 0


FOR b = 1 TO 200
bb! = b / 4
FOR a = 1 TO 320
aa! = a / 4

  clr = 0
  IF lin(aa!) > 0 AND bb! > z(aa!) AND bb! < (-z(aa!) + 50) THEN
    'IF aa! > 50 THEN aa! = 50
    'clr = 31 - (z(aa!) / 50) * z(aa!)
    clr = 31 - colrs(z(aa!))'31 - (z(aa!) / 50) * z(aa!)
  END IF
   pset a,b,clr,clr,clr
  
NEXT a

NEXT b

k$ = INKEY$

IF k$ = "a" THEN ang = ang - (pi / 18)
IF k$ = "d" THEN ang = ang + (pi / 18)
IF k$ = "s" THEN x = 0! + x + (2 * COS(ang + (pi / 8))): y = y + (2 * COS(ang + (pi / 8)))
IF k$ = "w" THEN x = 0! + x - (2 * COS(ang + (pi / 8))): y = y - (2 * COS(ang + (pi / 8)))

lastb = 100
lowestb = 30000

IF initb = 3000 THEN initc = 0 ELSE initc = initb
  FOR a = (pi) + ang TO (1.5 * pi) + ang STEP pi / (180)

lin(linvar) = 0
z(linvar) = 1
FOR b = initc TO lastb STEP 2

  x1 = x + (b * COS(a))
  y1 = y + (b * SIN(a))
  IF x1 > 100 THEN EXIT FOR
  IF y1 > 100 THEN EXIT FOR
  IF x1 < 0 THEN EXIT FOR
  IF y1 < 0 THEN EXIT FOR
  'PSET (x1, y1), 1
  IF (map(x1 / 10, y1 / 10) > 0) THEN
    lin(linvar) = map(x1 / 10, y1 / 10)
    z(linvar) = b / 2
    IF b < lowestb THEN lowestb = b
    EXIT FOR
  END IF
  NEXT b
  linvar = linvar + 1
NEXT a
FlipScreen ()

   'IF chengeb THEN lastb = lastb + 4 ELSE lastb = lastb - 1
   'initb = lowestb * .8
   'tim = tim + 1
   'IF tim = 3 THEN initb = 2: lowestb = 1: tim = 0
   'initb = initb + initb MOD 2
   'oldlowestb = lowestb
   LOCATE 1, 1
   PRINT "initb"; initb
WEND
SDL_Quit
end

sub FlipScreen ()
    SDL_unlocksurface screen
    'SDL_PollEvent ( event )
    SDL_Flip screen
    SDL_LockSurface (screen)
    SDL_PumpEvents
end sub


sub PSET ( x as integer , y as integer, R as UBYTE , G as UBYTE, B as UBYTE) 'A as UBYTE
dim cl as uinteger ptr
dim colkey as uinteger
dim Colptr as UBYTE ptr

colptr = @colkey : *colptr = R
colptr = @colkey + 1 : *colptr = G
colptr = @colkey + 2 : *colptr = B
'colptr = @colkey + 3 : *colptr = A
cl = screen->pixels + y * screen->pitch + x * len( integer )
*cl = colkey
end sub

spits out the error

Code:
C:\freeBASIC\hello.asm: Assembler messages:
C:\freeBASIC\hello.asm:297: Error: `%dl' not allowed with `movl'
C:\freeBASIC\hello.asm:303: Error: `%dl' not allowed with `movl'
C:\freeBASIC\hello.asm:309: Error: `%dl' not allowed with `movl'

The error is on the pset line. I changed it from pset x,y,255-clr,255-clr,255-clr to pset x,y,clr,clr,clr and the error appeared.
Fixed, download the lastest version: http://prdownloads.sourceforge.net/fbc/f...p?download

Also, the SDL hearders were updated, there's no more BYREF arguments, to map better the C version. If you must pass a pointer of a structure, use @ or varptr( ) on it.


Btw, to improve that code you could:

1) always declare the function arguments as BYVAL, or you can use the OPTION BYVAL statement to set it by default (then use BYREF if you really need an argument passed by reference).

2) instead of all that colptr + colkey's, just do *cl = r shl 16 or g shl 8 or b, much faster also
Did you remove cl = screen->pixels + y * screen->pitch + x * len( integer ) ?
better version of the sdl pixel ploter


defint a-z
option explicit

'$include: "sdl\sdl.bi"


declare sub PSET (screen as SDL_Surface ptr , x as integer , y as integer, R as UBYTE , G as UBYTE, B as UBYTE)

dim screen as SDL_Surface ptr

Dim X as integer
Dim Y as integer

Dim Shared ColorDepth as Integer
dim result as unsigned integer

result = SDL_Init(SDL_INIT_EVERYTHING)
if result <> 0 then
SDL_Quit
end 1
end if
ColorDepth = 8 ' color depth var the ploter support 8, 16, 32
'oh ya if somone can get info from
'screen->format->PixelperByte this color depth var woudn't be needed

screen = SDL_SetVideoMode(640, 480, ColorDepth, SDL_HWSURFACE or SDL_DOUBLEBUF or SDL_FULLSCREEN)
if screen = 0 then
SDL_Quit
end 1
end if
cls



do
SDL_PumpEvents 'Kills app if you click the mouse
result = SDL_GetMouseState( byval 0, byval 0 )'
if result > 0 then exit do '

SDL_LockSurface (screen)
For X = 1 to 100
for Y = 1 to 100
Pset screen,x,y,20,43,12
next
next
SDL_unlocksurface (screen)
SDL_Flip screen
loop

SDL_Quit
end


sub PSET (screen as SDL_Surface ptr , x as integer , y as integer, R as UBYTE , G as UBYTE, B as UBYTE)


dim colkey as uinteger
colkey = SDL_MapRGB (screen->format, R, G, B)
Select case ColorDepth
Case 32
dim cl_32bit as uinteger ptr
cl_32bit = screen->pixels + y * screen->pitch + x * len( integer )
*cl_32bit = colkey
Case 16
Dim cl_16bit as USHORT ptr
cl_16bit = screen->pixels + y * screen->pitch + x * len( SHORT )
*cl_16Bit = colkey
Case 8
Dim cl_8bit as UBYTE ptr
cl_8bit = screen->pixels + y * screen->pitch + x * len( BYTE )
*cl_8Bit = colkey
end select

end sub
Yeah, I'm just doing really horribly with stupid bugs at the moment. I'm going to leave you alone until I'm sure that I actually have a bug next time. :/

This is what happens after you start drinking; you get a huge amount of work ethic, but your prudence and not getting bugs ability starts to leave you. Smile