www.main.lv
Don't think just code it

Search results for 'sdl'

2011-02-18 Intel/Linux/BSD system

FreeBSD assembler sample:
Tools
Simple programm
Hello world
Hello world + libc
C + asm
Links where is somthing useful
Files
Open File

Linux assembler samples:
Hello World
gcc + asm
g++ + asm
Open file 
Make directory

SDL assembler example
SDL programming

FPU Topics
Calculating polinom

SSE
SSE add

Programming sample from various themes.
Basic HTTP server
FPU catch division by zero
BIn2Hex converter
ReprBin
Arp Packet Analyzer
Keyboard LED flush
PC speaker
Xlib, hello world

Interesting themes:
Linux Format String Attack
ELF rewrite function
Assembler scripting language
ELF text section
Linux ShellCode 1
Local Descriptor Table
Nano bug (CVS 2010-1160)
Hooking interrupt descriptor table

Antidebug
Antidebug 1
Antidebug 2
Antidebug 3

2009-11-15 Pascal Triangle

This is Pascal Triangle. And colours is chosen by reminder of division. There are 2 ways how that is made:1. Simple if division reminder is 0 then red else green2. Reminder is like alpha channel of red colour.In gallery shown images are generated by dividing on (17,19,23,41,42,43). There is easy to see that prime numbers (17,19,41,43) has very structured triangle but not prime (42) is different.

./chessboard div_number -

simply show triangle divided by number

./chessboard div image.tga -

save program screen to image.tga

./chessboard div img.tga ant_parm -

changes to second colouring type. Why it I call it chessboard? I were trying make such with OpenGL bet result is Pascal Triangle.
Source

2009-11-08 Linux Assembler

Covering some topics on assembly under Linux. Not all topics are specific for Linux.

SDL example
SDL programming


FPU Topics
Calculating polinom

System
Hello World
gcc + asm
g++ + asm
Open file
Make directory

2009-10-30 Linux assembler SDL

Open SDL window from asm. I tryed to open SDL window from asm. And that worked. Hardest thing is defining all structures from SDL headers. Windows opening and waiting while anykey will pressed.

include 'cdecl.inc'

format ELF

extrn SDL_Init
extrn SDL_SetVideoMode
extrn SDL_PollEvent
extrn SDL_Quit

;video settings
SDL_INIT_VIDEO	equ 0x00000020
SDL_FULLSCREEN	equ 0x80000000

;event settings
SDL_KEYDOWN         equ 2
SDL_MOUSEBUTTONDOWN equ 5

;programm settings
SCREEN_WIDTH equ 800
SCREEN_HEIGHT equ 600
SCREEN_BPP equ 24

struc SDL_keysym
{
	.scancode 	db 0
	.sym 		dd 0
	.mod		dd 0
	.unicode 	dd 0
}

struc SDL_KeyboardEvent
{
	.type  db 0
	.which db 0
	.state db 0
	.keysym SDL_keysym
}

struc SDL_Event
{
	.type db 0
	union SDL_KeyboardEvent
	.empty db 0,0,0
}

section '.text' executable
public _start
_start:
	ccall SDL_Init,SDL_INIT_VIDEO
	ccall SDL_SetVideoMode, SCREEN_WIDTH , SCREEN_HEIGHT , SCREEN_BPP , SDL_FULLSCREEN
	;try to make while loop
while_run:	
	while_polleEvent:
		ccall SDL_PollEvent, event
		cmp eax, 0
		je	while_polleEventquit
		cmp byte [event.type], SDL_KEYDOWN
		jne	while_polleEvent
		mov byte [run], 0
		jmp while_polleEvent
	while_polleEventquit:
	
	; if run != 1 quit
	cmp byte [run], 1	
	je	while_run
	
	ccall SDL_Quit, 0
	
	mov eax, 1
	xor ebx, ebx
	int 80h
	
section '.data' writeable
event		SDL_Event
run 		db 		1

Compile with lines:
fasm sdl.asm sdl.o
ld -dynamic-linker /lib/ld-linux.so.2 sdl.o /usr/lib/libSDL.so -o sdl

Dowload Source

2009-10-24 Making C executables smaller

There are some simple things that can be done to make C executables as small as possible.
Here is some example code we will work with:

#include <SDL/SDL.h>

char quit = 0;

int main()
{
    SDL_Surface *screen,surface;
    SDL_Event e;
    SDL_Init( SDL_INIT_VIDEO );
    screen = SDL_SetVideoMode( 400, 400, 32, SDL_SWSURFACE );
    while(!quit)
        while(SDL_PollEvent(&e)>0)
        {
            if(e.type==SDL_MOUSEBUTTONDOWN) quit=1;
            if(e.type==SDL_KEYDOWN) quit=1;
        }
    SDL_Quit();
}


Compile:
gcc main.c -o main -lSDL

Size before: 5326 bytes
Execute command:
strip main

strip is included in most unix systems. It deletes some info symbols from executables Size after: 3532 bytes
You can also try sstrip which is advanced version of strip. You can download it from ELF kickers webpage. Execute command:
sstrip main
Size after: 1960 bytes
There are some others way to decrease size of programm. GC Masher Allows to bruteforce gcc options for smaller executable size. I where using this options for gcsmaher
-O  -O0  -O1  -O2  -O3  -Os
-ffast-math
-fomit-frame-pointer
-fauto-inc-dec
-mpush-args
-mno-red-zone
-mstackrealign 

After runnig with this options executble size is 5175 bytes and best compiling options are all posible combination.  Combining with sstrip gives 1960 bytes. And there size where not reduced but some time there can be saved some bytes.Now we will change main function with
void _start()
and return change to
asm ( \
      "movl $1,%eax\n" \
      "xor %ebx,%ebx\n" \
      "int $128\n" \
    );
One other thing is to archive your executable and cat it with unpack shell script.
a=/tmp/I;tail -n+2 $0|zcat>$a;chmod +x $a;$a;rm $a;exit
Best options and smallest size now is 563 byte. Nope this is not smallest size try to rename executable name to one symbol and you will get 4 extra bytes.
gcc -Os -ffast-math -fomit-frame-pointer 
-fauto-inc-dec -mpush-args -mno-red-zone -c small.c;
ld -dynamic-linker /lib/ld-linux.so.2 small.o /usr/lib/libSDL.so -o small;
strip -s -R .comment -R .gnu.version small;sstrip small;
7z a -tGZip -mx=9 small.gz small > /dev/null;
cat unpack.header small.gz > small;
chmod a+x small;rm small.gz small.o
Download Source
Rewriting all in asm gives 526 bytes Link.
Link to other resources Link1.
Author in link has 634 bytes. With his options I have 622 bytes and using gcmasher i have 606 bytes. I have used his source in this compare.

2009-02-12 Pygame Border Coalision

I wanted to know how many simple object can be drawn by Pygame. Red point is starting point for flying bullets. And only thing with bullets have coalision is screen border. You can shut new bullets with mouse.
Download Script
After some optimisations script works faster.
Download Script v2
Also I have implemented the same on C++.
Download Source