gokernel
(usa Linux Mint)
Enviado em 13/07/2014 - 11:01h
Projeto atualizado ( cs_1.0.0_BUILD_12.zip ):
WORDS:
-------------------------------------------------
int, float, struct,
print, for, if, break, function, return,
include, library, import,
char, asm, assembly;
-------------------------------------------------
DETALHE:
Apaguei alguns posts para evitar "poluição visual".
Caso alguém teste e encontre algum BUG, por gentileza favor me notifique ...
Um pequeno exemplo ( library, import ) usando SDL:
Esse programa sai ao clicar em algum quadrado ou ao teclar ESC.
Usando "C":
/*
**-------------------------------------------------------------------
**
** A simple example ( library, import ) using SDL
**
** FILE:
** sdl_pure.cs
**
** BY: Francisco G. A.
**
**-------------------------------------------------------------------
*/
library
"SDL" // Windows: SDL.dll
"libSDL" // Linux: libSDL.so
;
import
"SDL_Init"
"SDL_SetVideoMode"
"SDL_FillRect"
"SDL_Flip"
"SDL_PollEvent"
"SDL_Delay"
"SDL_Quit"
;
// sizeof(SDL_Event) = 20
//
struct Event {
char type; // used
char a;
char button; // mouse_button
char c;
short x, y; // mouse_x, mouse_y
int key; // used
};
struct Rect {
short x, y;
short w, h;
int color;
};
struct Rect rect[4]={
{ 100, 100, 100, 100, 63488 }, // color red
{ 400, 100, 100, 100, 2016 }, // color green
{ 100, 400, 100, 100, 31 }, // color blue
{ 400, 400, 100, 100, 64515 } // color orange
};
//-----------------------------------------------
//################# VARIABLES #################
//-----------------------------------------------
struct Event *ev; // sizeof: 20
struct Rect *r;
char *screen;
int i;
//-----------------------------------------------
function main()
{
SDL_Init (32);
screen = SDL_SetVideoMode (800, 600, 16, 0); // color 16
ev = malloc (25);
SDL_FillRect (screen, r, 1050); // NULL: bg full
// draw 4 box ( red, green, blue, orange ):
//
r = rect;
for(i=0;i<4;i++){
SDL_FillRect (screen, r, r->color);
r++;
}
SDL_Flip (screen);
printf ("\nTo exit of loop press the KEY ESCAPE\n\n");
//---------------------------------------------
//################ main loop ################
//---------------------------------------------
//
for(;;){
if (SDL_PollEvent(ev)) {
if (ev->type == 2) { // SDL_KEYDOWN
printf ("KEY: %d = (%c)\n", ev->key, ev->key);
// SDLK_ESCAPE = 27
//
if (ev->key == 27) { break; }
}
if (ev->type == 4) { //SDL_MOUSEMOTION
printf ("x: %d, y: %d\n", ev->x, ev->y);
}
//
// click in box ( red, green, blue, orange )
//
// !exit of loop:
//
if (ev->type == 5) { // SDL_MOUSEBUTTONDOWN
r = rect;
for(i=0;i<4;i++){
if (ev->x > r->x && ev->y > r->y && ev->x < r->x+r->w && ev->y < r->y+r->h) {
printf ("Cliking in rect[ %d ]\n", i);
asm ("jmp LABEL_LOOP_END");
}
r++;
}
}
}//: if (SDL_PollEvent(ev)) {
//<<<<<<<<<< HANDLE HERE >>>>>>>>>>
SDL_Delay(10);
}//: for(;;)
asm ("LABEL_LOOP_END:");
SDL_Quit();
}
main();
//code("main");
DETALHE:
Implementei/mudei as chamadas de funcoes ASM colocando um ( * ) no inicio da chamada ... motivo: para ficar mais rápida a compilação e evitar ficar procurando funcoes a todo tempo.
EXEMPLO:
----------------------------
asm ("*FuncName args");
----------------------------