flat assembler
Message board for the users of flat assembler.

Index > High Level Languages > Android C4Droid, TinyCC, Notepad++. Examples

Author
Thread Post new topic Reply to topic
codestar



Joined: 25 Dec 2014
Posts: 254
codestar 15 Mar 2015, 05:27
My TinyCC distribution + 3 Examples. Setup:

* Run command prompt. Drag EXAMPLE.BAT into console and press ENTER
* To re-compile+run again in the console, press UP then ENTER. In the terminal, UP/DOWN selects previous commands

TCC with Notepad++, free lightweight text editor. Open .C/PP/H with.

Image

Android C4Droid. Download from Android Store. Get plugins GCC and SDL.

* 2 respected C/C++ compilers: TCC (TinyC+uCLibc), GCC + Bionic. Preferences > Select Compiler
* Outputs native code, SDL1/2, QT, OpenGL, NativeActivity
* Easy IDE. Classic console theme. Preferences > Theme, Colors. Multiple document support (MDI). Preferences > Tabs above

My Android phones:
Image

SDL example:
Code:
/* SDL. DRAW RANDOM PIXELS.
OPTIONAL LOAD/DRAW IMAGE.
COMPILER > GCC + BIONIC */

#include <stdio.h>
#include <SDL.h>

typedef unsigned char byte;
typedef unsigned short word;
typedef unsigned uint;

#define WIDTH 640
#define HEIGHT 480

SDL_Surface *screen, *image;
SDL_Event event;  
byte *keys_p;
int running=1;

int set_video();
void draw_screen();
int lock_screen();
void unlock_screen();

#define get_event() SDL_PollEvent(&event)
#define show_screen() SDL_Flip(screen)  
  
//////////////////////////////////////////////////

int set_video() {
  if (SDL_Init(SDL_INIT_VIDEO)<0)
    return 0;
  screen=SDL_SetVideoMode(WIDTH, HEIGHT,
    32, SDL_FULLSCREEN|SDL_HWSURFACE);
  if (!screen) {
    SDL_Quit();
    return 0;
  }
  return 1;
}

int lock_screen() { 
  if (SDL_MUSTLOCK(screen))
    if (SDL_LockSurface(screen)<0)
      return 0;
  return 1;
}
  
void unlock_screen() { 
  if (SDL_MUSTLOCK(screen))
    SDL_UnlockSurface(screen);
}

void draw_pixels() { 
  int x, y; 
  uint *p;
  if (!lock_screen())
    return;
  for (y=0; y<screen->h; y++) {
    for (x=0; x<screen->w; x++) {
      p=(uint*) screen->pixels+
        rand()%(screen->w*screen->h);
      *p=rand()%0xFFFFFF;
    }
  }
  unlock_screen();
  show_screen();
}

void end_video() {
  SDL_Quit();
}

int load_image() {
  image=SDL_LoadBMP("hello.bmp");
  if (!image)
    return 0;
  return 1;
}

int image_x, image_y;
SDL_Rect screen_box, image_box;

void draw_image() {
  screen_box.x=image_x;
  screen_box.y=image_y;
  screen_box.w=image->w;
  screen_box.h=image->h;
  image_box.x=image_box.y=0;
  image_box.w=image->w, image_box.h=image->h;
  SDL_BlitSurface(image, &image_box,
    screen, &screen_box);
}

void destroy_image() {
  SDL_FreeSurface(image);
}

void draw_screen() {
  draw_pixels();
  // draw_image();
}
                
int handle_events() {
  int key;
  while (get_event()) {      
    if (event.type==SDL_KEYDOWN) {
      key=event.key.keysym.sym;
      if (key==SDLK_LEFT)
        image_x-=4;
      if (key==SDLK_RIGHT)
        image_x+=4;
      if (key==SDLK_UP)
        image_y-=4;
      if (key==SDLK_DOWN)
        image_y+=4;
      return 1;
    }
    else if (event.type==SDL_QUIT) {
      running=0;
    }
  }
  return 1;
}

int main(int na, char *as[]) { 
  if (!set_video())
    return 1; 
// if (!load_image())
//   return 1;
  while (running) {
    draw_screen();
    handle_events();
  }
  end_video();
// destroy_image();
  return 0;
}    
Post 15 Mar 2015, 05:27
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.