Oxygen Basic

Programming => Problems & Solutions => Topic started by: Peter on February 26, 2013, 06:04:27 AM

Title: Horror Pointer
Post by: Peter on February 26, 2013, 06:04:27 AM
Deleted.
Title: Re: Horror Pointer
Post by: Charles Pegge on February 26, 2013, 09:21:11 AM
(http://www.codinghorror.com/blog/images/coding-horror-official-logo-small.png)

Actually, it turned out to be a sensitivity to tabs in the #define macros. How devious is that!

Thanks Peter.

PS Oxygen updated later in this thread


Title: Re: Horror Pointer
Post by: Charles Pegge on February 26, 2013, 11:02:26 AM
Yes let is useful, it automatically creates an appropriate variable type and assigns a value, including pointered types.

The bug was definitely a tab problem. My examples are now working. Is the new dll in the right place?
Title: Re: Horror Pointer
Post by: Charles Pegge on February 26, 2013, 12:13:45 PM
Depending on how you have declared PollEvents:

extern DECLSPEC int SDLCALL SDL_PollEvent(SDL_Event *event);

I could not find the defintion for SDL_Event, but I think the  parameter shout not have the addressof prefix '@'
Title: Re: Horror Pointer
Post by: Charles Pegge on February 26, 2013, 03:22:11 PM
As I lay there half way between dreaming and waking, I thought " Hey! Peter is not using cdecl!"

Without cdecl, a loop will eventually drain your entire stack whenever you go into a loop.

Currently bind does not support cdecl. It just makes the call.

The alternative is to use standard declarations, with or without parameter specifiers (...).

extern cdecl lib "sdl.dll"
  ! SDL_AddTimer
  ! SDL_AllocRW
  ! SDL_AudioDriverName
  !SDL_AudioInit
  ! SDL_AudioQuit
...
end extern

If you define your functions this way,(unprototyped), then of course you need to use the @ operator for passing params byref.

Charles
 
Title: Re: Horror Pointer
Post by: JRS on February 26, 2013, 06:36:09 PM
Peter,

Isn't there a C example for SDL that can give you some guidance with this? When things don't work for me, I try and find examples that are close enough that do work.

This is what separates the men from the boys. Don't give up, take a break and come back to it.

John
Title: Re: Horror Pointer
Post by: Charles Pegge on February 26, 2013, 11:59:55 PM

Using proper C or Basic headers is one solution, but don't give up yet Peter, I haven't. There is something else I need to do to make cdecl work with unprototyped declarations.
Title: Re: Horror Pointer
Post by: Charles Pegge on February 27, 2013, 02:17:46 AM
I have made a few corrections here and implemented cdecl support for both bind and unprototyped declarations - so you now have a choice, Peter. I used your sdl.inc here

I found Google was the best way to get information about SDL. The online documentation is very good.

Code: [Select]
extern cdecl lib "sdl.dll"
  include "sdl.inc"
end extern
SDL_Init SDL_INIT_EVERYTHING

SDL_SURFACE *image
SDL_SURFACE *screen

SDL_Event   Event

sys hfile 'rwops pointer treated as a handle

@screen=SDL_SetVideoMode 320,240,32,SDL_DOUBLEBUF | SDL_SWSURFACE  
hfile=SDL_RWFromFile "bmp\alienmoon.bmp","rb"
@Image=SDL_LoadBMP_RW hfile,1
SDL_UpperBlit @image, 0, @screen, 0
SDL_FreeSurface @image
SDL_Flip @screen
do
  e=SDL_PollEvent(@Event)
  if e
    'print event.type
    if Event.type=SDL_xQUIT
      SDL_Quit
    end if
  end if
  Sdl_Delay(10)
end do

Charles

Oxygen reposter later
Title: Re: Horror Pointer
Post by: Aurel on February 27, 2013, 04:32:21 AM
I also want try this but i am not sure that i have right version of sdl.dll
so which version to use ?
Title: Re: Horror Pointer
Post by: Aurel on February 27, 2013, 04:43:11 AM
Ok i download from SDL site,
It looks that Charles example work and load image on black background
but after closing app stuck in memory,look into Task manager.
So i think that SDL_Quit not work properly... :-\
Title: Re: Horror Pointer
Post by: Charles Pegge on February 27, 2013, 05:04:10 AM
Yes I get the same problem, Aurel. Will investigate...
Title: Re: Horror Pointer
Post by: Charles Pegge on February 27, 2013, 05:31:22 AM
This does a clean exit :)

Code: [Select]
extern cdecl lib "sdl.dll"
  include "sdl.inc"
end extern
SDL_Init SDL_INIT_EVERYTHING

SDL_SURFACE *image
SDL_SURFACE *screen

SDL_Event   Event

sys hfile 'rwops pointer treated as a handle

@screen=SDL_SetVideoMode 320,240,32,SDL_DOUBLEBUF | SDL_SWSURFACE 
hfile=SDL_RWFromFile "bmp\alienmoon.bmp","rb"
@Image=SDL_LoadBMP_RW hfile,1
SDL_UpperBlit @image, 0, @screen, 0
SDL_Flip @screen
do
  e=SDL_PollEvent(@Event)
  if e
    'print event.type
    if Event.type=SDL_xQUIT
      exit do
    end if
  end if
  Sdl_Delay(10)
end do

SDL_FreeSurface @image
SDL_FreeSurface @screen
SDL_Quit
Title: Re: Horror Pointer
Post by: JRS on February 27, 2013, 07:31:52 AM
Peter,

I downloaded your attachments (.bmp / fonts) but there was no DLL or .inc file. Are we suppose to use the original for this example?

John
Title: Re: Horror Pointer
Post by: JRS on February 27, 2013, 09:14:37 AM
Peter,

Code: [Select]
if Event.key.keysym.sym = SDLK_ESCAPE   '< key trouble    


/** Keyboard event structure */
typedef struct SDL_KeyboardEvent {
   Uint8 type;   /**< SDL_KEYDOWN or SDL_KEYUP */
   Uint8 which;   /**< The keyboard device index */
   Uint8 state;   /**< SDL_PRESSED or SDL_RELEASED */
   SDL_keysym keysym;
} SDL_KeyboardEvent;


I couldn't locate the SDL_keysym type structure in SDL_events.h.


John
Title: Re: Horror Pointer
Post by: JRS on February 27, 2013, 11:01:31 AM
I hope Charles (O2) does a better job of finding structures in .h files then I.  >:(

The structure was 4 levels down into the INCLUDE stack so I don't feel so bad.

Title: Re: Horror Pointer
Post by: JRS on February 27, 2013, 12:32:27 PM
Peter,

Remind me to invite you to our next camping trip. You sound like just the right person to tell scary stories by campfire.  :D

John
Title: Re: Horror Pointer
Post by: Charles Pegge on February 28, 2013, 06:29:34 AM
Hi Peter,

Quite a lot of C stuff is available: (without needing semicolons of course :) )
Perhaps this is the stuff you don't want..

== != >> << ++ --

Code: C
  1. int f cdecl (int a)
  2. {
  3.   a=2
  4.   switch a
  5.   {
  6.     case 1 : print "A" : break
  7.     case 2 : print "B" : break
  8.     case 3 : print "C" : break
  9.   }
  10. }
  11.  
  12. f(2)
  13.  

Charles

Title: Re: Horror Pointer
Post by: JRS on February 28, 2013, 09:18:21 AM
Reminds me of my event loop for IUP and weeding out mouse movement events I didn't request callbacks for and return a NULL handles. Before SB even sees an event I filter these out in the extension module DLL.

Title: Re: Horror Pointer
Post by: Charles Pegge on February 28, 2013, 11:01:52 AM
Hi Peter,

something like this:

Code: OxygenBasic
  1. Sub DoEvents
  2.     pushad
  3.     lea   eax,Event
  4.     call  SDL_PollEvent eax
  5.     movzx edx,Event.type
  6.     cmp   edx,SDL_xQUIT    
  7.     jz    n1
  8.     cmp   edx,SDL_KEYDOWN
  9.     jz    n1
  10.     popad
  11.     ret    
  12. .n1 mov   run,0
  13.     call  SDL_Quit
  14.     popad
  15. End Sub
  16.  
  17. '===>
  18.  
  19. while (run)
  20.   DoEvents
  21.   SDL_Delay (10)
  22. wend
  23.  
  24. sys run=1
  25.  
  26. Sub DoEvents()
  27.   SDL_PollEvent @Event 'assume no prototype for this call
  28.  select Event.type
  29.   case SDL_xQUIT   : 'fall thru
  30.  case SDL_KEYDOWN : 'fall thru
  31.  case else        : exit sub
  32.   end select
  33.   run=0
  34.   SDL_Quit
  35. end sub
  36.  
  37. while (run)
  38.   DoEvents
  39.   SDL_Delay (10)
  40. wend
  41.  
  42.  

Charles
Title: Re: Horror Pointer
Post by: JRS on February 28, 2013, 01:29:55 PM
Quote
But if this constructs doesn't go with OxygenBasic, then I will quit.
I have no interesting to go with dirty tricks.

Peter,

OxygenBasic is in it's alpha development stage. That means your use and feedback help shape O2's future. If it gets too hot in the kitchen then maybe your not cut out to be a cook and better off sitting out front waiting to be served. I think you're a bright and interesting person from my dealings with you here and other forums. It's okay to disagree, just don't be disagreeable.

John
Title: Re: Horror Pointer
Post by: Charles Pegge on February 28, 2013, 02:27:13 PM

I have not encountered enumerations placed inside typedefs before. This is arcane but I will see what can be done.

Good reason for using case blocks: they are significantly faster and smaller than conditional statements.

John, I now have ScriptBasic chatting with the SAPI voice. Nice big hurdle to jump over :)
Title: Re: Horror Pointer
Post by: Aurel on February 28, 2013, 02:33:12 PM
Quote
If OxygenBasic cannot handle this structures then is purposeless to work with my project.
Hmmm ...interesting standpoint,there is no ideal lang but hey programming in oxygen for me is somehow
cool....
Title: Re: Horror Pointer
Post by: JRS on February 28, 2013, 02:36:05 PM
Quote
John, I now have ScriptBasic chatting with the SAPI voice. Nice big hurdle to jump over.

Now that is something to talk about!  :o

BTW: Can you put a date next to the work in progress download link on the site? I would be happy to setup a mailing list for announcements for those of us developing / contributing as you go.

Title: Re: Horror Pointer
Post by: Charles Pegge on March 01, 2013, 01:51:53 AM
Hi Peter

in sdl.inc:
Code: OxygenBasic
  1. packed
  2. typedef struct SDL_keysym{
  3.   byte scancode
  4.   long sym
  5.   long mod
  6.   short unicode
  7. } SDL_keysym
  8.  
  9. typedef struct SDL_KeyboardEvent{
  10.   Uint8 type
  11.   Uint8 which
  12.   Uint8 state
  13.   SDL_keysym keysym
  14. } SDL_KeyboardEvent
  15.  

View Keyboard events in detail:

Code: OxygenBasic
  1. extern cdecl lib "sdl.dll"
  2.   include "sdl.inc"
  3. end extern
  4. SDL_Init SDL_INIT_EVERYTHING
  5.  
  6. 'SDL_SURFACE *image
  7. SDL_SURFACE *screen
  8.  
  9.  
  10. 'sys hfile 'rwops pointer treated as a handle
  11.  
  12. @screen=SDL_SetVideoMode 320,240,32,SDL_DOUBLEBUF | SDL_SWSURFACE  
  13. 'hfile=SDL_RWFromFile "bmp\alienmoon.bmp","rb"
  14. '@Image=SDL_LoadBMP_RW hfile,1
  15. 'SDL_UpperBlit @image, 0, @screen, 0
  16. 'SDL_Flip @screen
  17.  
  18. '#recordof SDL_KeyboardEvent
  19.  
  20. SDL_Event   Event
  21.  
  22. SDL_EnableUNICODE 1
  23.  
  24. cr=chr(13,10)
  25. tab=chr(9)
  26. do
  27.   if SDL_PollEvent(@Event)
  28.     'print event.type
  29.    select event.type
  30.     case SDL_xQUIT           : exit do
  31.     case SDL_KEYDOWN         :
  32.       print "Keyboard Event Data:" cr cr+
  33.       "type    " tab hex(event.key.type)            cr+
  34.       "which   " tab hex(event.key.which)           cr+
  35.       "state   " tab hex(event.key.state)           cr+
  36.       "scancode" tab hex(event.key.keysym.scancode) cr+
  37.       "sym     " tab hex(event.key.keysym.sym)      cr+
  38.       "mod     " tab hex(event.key.keysym.mod)      cr+
  39.       "unicode " tab hex(event.key.keysym.unicode)  cr+
  40.       ""
  41.       if event.key.keysym.sym=27 then exit do
  42.     case SDL_KEYUP           :
  43.     case SDL_MOUSEMOTION     :
  44.     case SDL_MOUSEBUTTONDOWN : 'exit do
  45.    case SDL_MOUSEBUTTONUP   :
  46.     end select
  47.   end if
  48.   Sdl_Delay(10)
  49. end do
  50.  
  51. 'SDL_FreeSurface @image
  52. SDL_FreeSurface @screen
  53. SDL_Quit
  54.  

Charles
Title: Re: Horror Pointer
Post by: JRS on March 01, 2013, 12:05:13 PM
Peter,

FYI - You are violating the GNU license by wrapping the SDL library as a closed source project. Please make your source available!

John
Title: Re: Horror Pointer
Post by: Charles Pegge on March 01, 2013, 12:19:54 PM
Yes, source code much preferred.

I am in deep code trance to resolve some subtle typedef alignment issues.

(http://hewhohasearslethimhear.files.wordpress.com/2010/08/yoga.jpg?w=120&h=100)
Title: Re: Horror Pointer
Post by: Charles Pegge on March 02, 2013, 09:21:47 AM
Voila!

The enumeration types will no longer disrupt type definitions, and the byte alignments are a bit smarter, so no need for 'packed' directives.

X