flat assembler
Message board for the users of flat assembler.
Index
> Main > SDL for FASM |
Author |
|
vid 11 Jul 2007, 10:35
hi.
1. there is no reason to use "int8", "uint32" etc. in assembly. Just use plain "db", "dw", "dd", "dq". Also "fix" isn't really the best way to do this, "equ" should be enough. 2. structures look allright. Just again, you can use seach-and-replace to "db", "dw", "dd". Function pointer in 32bit assembly is simply dword. 3. I am afraid you will have to modify constants a little bit. "a | b" is in fasm "a or b". 4. If you are using DLL, it is a dynamic linking (DLL = dynamic link library). |
|||
11 Jul 2007, 10:35 |
|
Christoph 11 Jul 2007, 10:56
Thank you for your reply.
I planned to replace all those Unit, ints, chars with db, dw and so on, but i wasn't sure about the unsigned and signed ones. I will replace the pointer with dw's. So i have to replace KMOD_META = KMOD_LMETA|KMOD_RMETA with KMOD_META = KMOD_LMETA or KMOD_RMETA. On the forum i have seen that hex-numbers in fasm look like this SDL_INIT_AUDIO = 00000010h instead of SDL_INIT_AUDIO = 0x00000010 can fasm do both? or only the first one? Still i dont understand what Uint32 blit_hw:1; Uint32 blit_hw_CC:1; Uint32 blit_hw_A:1; is or how it could be implemented. Is this just one single dw that use some kind of masking? Regards, Christoph |
|||
11 Jul 2007, 10:56 |
|
f0dder 11 Jul 2007, 11:30
":n" inside a struct means this variable is only n bits wide.
signed vs. unsigned doesn't matter in assembly when declaring variables, but it does once you want to do calculations and conditional jumps... |
|||
11 Jul 2007, 11:30 |
|
Christoph 11 Jul 2007, 11:44
Thanks for your help.
So in Assembly i can ignore the :n and just use Uint32 bla:1; -> dd bla ? I have another question, double is in assembly dq right? when a function needs a double as parameter can i just use invoke func, somedoubleparam or do i need to use two dd's like invok func, 1sthalfofdouble, 2ndhalfdouble? When i need a double in a struct can i use the following? Code: struct SDL_AudioCVT dd needed dw src_format dw dest_format dq rate_incr ;double rate_incr dw buf ;Uint8 *buf; dd len dd len_cvt dd len_mult dq len_ratio ;double len_ratio dw filters ;void (*filters[10])(struct SDL_AudioCVT *cvt, Uint16 format); dd filter_index ends |
|||
11 Jul 2007, 11:44 |
|
f0dder 11 Jul 2007, 11:58
Christoph wrote:
Nope, bitfields are packed, so you need to figure out what goes where, and then use the correct sequence of MOV, AND/OR, SHL/SHR etc. when accessing the fields... even more fun if you're dealing with signed bitfields. Christoph wrote:
Yup. I personally prefer the longer names rather than "dx", but that's a matter of taste. Christoph wrote:
Depends on how smart the invoke macro is , but internally it's two pushes, yes. |
|||
11 Jul 2007, 11:58 |
|
Christoph 11 Jul 2007, 12:23
Now i get it
I found a more detailed describtion of the structure with the bitfield (commented), damn they are wasting 23 bits (future flags?). Code: struct SDL_VideoInfo dd flags ;Uint32 hw_available:1; ;Uint32 wm_available:1; ;Uint32 UnusedBits1 :6; ;Uint32 UnusedBits2 :1; ;Uint32 blit_hw :1; ;Uint32 blit_hw_CC :1; ;Uint32 blit_hw_A :1; ;Uint32 blit_sw :1; ;Uint32 blit_sw_CC :1; ;Uint32 blit_sw_A :1; ;Uint32 blit_fill :1; ;Uint32 UnusedBits3 :16; dd video_mem dw vfmt ;SDL_PixelFormat *vfmt; dd current_w dd current_h ends here they wasted even more Code: struct SDL_Overlay dd format dd w dd h dd planes dw pitches ;Uint16 *pitches; dw pixels ;Uint8 **pixels; dd hw_overlay ;Uint32 hw_overlay:1; ;Uint32 UnusedBits:31; ends When i try to compile my source fasm says invalid macro argument at line 283 (struct stdio). Whats wrong? Code: ;typedef struct _iobuf FILE; struct FILE dw _ptr ;char *_ptr; dd _cnt db base ;char *_base; dd _flag; dd _file; dd _charbuf; dd _bufsiz; dw _tmpfname ;char *_tmpfname; ends struct SDL_RWops dw seek ;int (*seek)(struct SDL_RWops *context, int offset, int whence); dw read ;int (*read)(struct SDL_RWops *context, void *ptr, int size, int maxnum); dw write ;int (*write)(struct SDL_RWops *context, const void *ptr, int size, int num); dw close ;int (*close)(struct SDL_RWops *context); dd type union struct stdio dd autoclose dw fp ;FILE *fp ends struct mem dw base ;Uint8 *base; dw here ;Uint8 *here; dw stop ;Uint8 *stop; ends struct unknown dw data1 ;void *data1; ends ends ends Thanks in advance. |
|||
11 Jul 2007, 12:23 |
|
LocoDelAssembly 11 Jul 2007, 13:29
Because you have to define "fieldName type" not "type fieldName" like in C.
|
|||
11 Jul 2007, 13:29 |
|
f0dder 11 Jul 2007, 14:02
Also remember that the structs fields are probably dword-aligned rather than packed...
|
|||
11 Jul 2007, 14:02 |
|
Christoph 14 Sep 2007, 12:45
Hello,
finally I have an almost complete import list for sdl and sdl_image. But still I've got some problems. When I try to import the function SDL_WM_IconifyWindow i get an error about if used, is there a workaround? Code: import sdl,\ ... SDL_WM_IconifyWindow,'SDL_WM_IconifyWindow',\ ... I don't get the Eventhandling working. How can I pass a pointer as argument to the SDL_PeepEvents function? Code: int SDL_PeepEvents(SDL_Event *events, int numevents, SDL_eventaction action, Uint32 mask); ??? invoke SDL_PeepEvents, event, 1, SDL_GETEVENT, SDL_ALLEVENTS And how can I get the type of event. SDL has defined one generic event but also defines multiple other events. Code: typedef union SDL_Event { Uint8 type; SDL_ActiveEvent active; SDL_KeyboardEvent key; SDL_MouseMotionEvent motion; SDL_MouseButtonEvent button; SDL_JoyAxisEvent jaxis; SDL_JoyBallEvent jball; SDL_JoyHatEvent jhat; SDL_JoyButtonEvent jbutton; SDL_ResizeEvent resize; SDL_ExposeEvent expose; SDL_QuitEvent quit; SDL_UserEvent user; SDL_SysWMEvent syswm; } SDL_Event; //these are examples of actual event structures but there are many more /* The "quit requested" event */ typedef struct SDL_QuitEvent { Uint8 type; /* SDL_QUIT */ } SDL_QuitEvent; /* A user-defined event type */ typedef struct SDL_UserEvent { Uint8 type; /* SDL_USEREVENT through SDL_NUMEVENTS-1 */ int code; /* User defined event code */ void *data1; /* User defined data pointer */ void *data2; /* User defined data pointer */ } SDL_UserEvent; Currently I stopped my efford to get the sdl structs defined in fasm (atm to confusing for me) but I think I have all defines that are needed put into fasm (see libsdl.inc). Still I'm not sure if they are all correct, exspecially the shifted masks. Code: SDL_ALLEVENTS = 0xFFFFFFFF SDL_ACTIVEEVENTMASK = 0x00000001 shl SDL_ACTIVEEVENT SDL_KEYDOWNMASK = 0x00000001 shl SDL_KEYDOWN SDL_KEYUPMASK = 0x00000001 shl SDL_KEYUP SDL_KEYEVENTMASK = SDL_KEYDOWNMASK or SDL_KEYUPMASK ;does this work??? I attach my current sources and the libraries you need to run it, use them for whatever you want. Hope you can give me a few tips. Thanks in advance.
|
|||||||||||
14 Sep 2007, 12:45 |
|
0.1 17 Sep 2007, 06:26
Why are you taking so much of trouble?
Why are you writing it in assembly when your are using a library which is written in C? Why are you doing all this? I once tried (2-3 years back) to use SDL + assembly. I was using gas so I did not need any import for functions. I did not define any structs. I was writing a game so along with my game I declared the needed constants, structs (just declared constants with size and offsets of structs) in header files one by one. And my game (a snake game. duh!) was working fine! But it was so tiresome! You should at least use C. |
|||
17 Sep 2007, 06:26 |
|
Christoph 17 Sep 2007, 08:02
Well, I already used SDL with C/C++, but I want to learn assembly a bit more.
Currently I'm not planing doing a whole game in asm, I just want to experiment a bit. I use SDL because once I get it running it is pretty easy to use and it's a nice library. If I really wanted to make a game I would not use SDL and/or asm, I was propably going for C++ and Nebula 2 or something like that. Yes I know it's troublesome and timeconsuming but I'm a student and students have a lot time |
|||
17 Sep 2007, 08:02 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.