Category Archives: Programming

Building your own game using pygame

These days I was experimenting with pygame and found out that how easy game development can be done with pygame. I build a ‘Space War’ clone using pygame with some sound effects. Now I’m making a HOWTO on building the games using pygame. When it is complete I will post it here..

Space War


1 Comment

Filed under Linux, Programming, Python

Self Printing C Code

Have you ever tried writing a C code that prints the source itself. Its a little bit tricky anyway. But the solution is here

char *program = "#include  %c char *program = %c%s%c;%c int main()%c{%cprintf(program, 10, 34, program, 34, 10, 10, 10, 10, 10, 10);%c    return 0;%c}%c";
int main()
        printf(program, 10, 34, program, 34, 10, 10, 10, 10, 10, 10);
        return 0;

Another program can be written in a single line



  • The program is run on an ASCII machine.
  • No newline is needed at the end of the source.
  • char * does not lose any information when converted to int.
  • int has the same bit representation, size, and argument passing convention as char *.
  • A random return value from main does not cause problems.
  • printf works without prototype.

Comments Off on Self Printing C Code

Filed under Programming

Microsoft XNA Game Studio 2.0

Microsoft XNA Game Studio 2.0 is a set of tools based on supported versions of Microsoft Visual Studio tools that allow students and hobbyists to build games for both Microsoft Windows and Xbox 360. XNA Game Studio also includes the XNA Framework, which is a set of managed libraries based on the Microsoft .NET Framework 2.0 that are designed for game development. This documentation collection contains technology overviews, tutorials, and reference material related to XNA Game Studio.

Visit Official Site

Leave a comment

Filed under Applications, Programming

Setting Java (Sun JDK) Class Paths

After you’ve downloaded and installed the latest JDK form the Sun servers, you need to set up the class paths so that you can run java and javac from the terminal (Sun’s JAVA instead GNU GCJ). Here is the steps to set the classpaths

  1. Move the extracted files to /usr/java (if not exist, create a new directory)
  2. open a terminal and type vim .bashrc
  3. Insert the following lines

export PATH=/usr/java/jdk1.6.0_03/bin:$PATH
export JAVA_HOME=”/usr/java/jdk1.6.0_03″
export CLASSPATH=.:/usr/java/jdk1.6.0_03

Save & Exit, then Reboot the system. That’s all

Note: Set your path accordingly. ie if your JDK is 1.5 then the path will be like /usr/java/jdk1.5

1 Comment

Filed under Configuration, Linux, Programming, Tips, Ubuntu

Python Networking: Send Emails using smtplib

Here is a small application in Python for sending email messages via SMTP


import smtplib

fromAddr = raw_input(‘From: ‘)
toAddr = raw_input(‘To: ‘)

Subject = raw_input(‘Subject: ‘)
Message = raw_input(‘Message: ‘)

Email = ‘Subject: ‘+Subject+’\n\n’+Message

Server = smtplib.SMTP(“BlackPearl”,25)
Server.sendmail(fromAddr, toAddr, Email)
print ‘Your Email has been sent to ‘, toAddr


If your system has two users “root” and “leaf” you should have two email accounts like root@localhost and leaf@localhost (Assuming hostname to be localhost. Here in this example its BlackPearl)

Run using python

To view the email type mail and type the email number to read it.

Leave a comment

Filed under Linux, Programming, Python

AVR port for SDCC

I’m implementing an AVR port to the SDCC (Small Device C Compiler) as College project. I think this will help me in improving my knowledge about AVR architecture and compiler design.

This document is inherited from SDCC AVR implementation page.

Design Document for AVR Port

The first release will support all AVR architectures except ATMega & ATtiny
(i.e. all variants with 64K or less of code/data space will be supported)

All functions will be REENTRANT .

I) Language extensions

a) Storage classes

“bit” – not applicable (will be returned to user name space)
“data” – not applicable (will be returned to user name space)
“idata” – not applicable (will be returned to user name space)
“xdata” – not applicable (will be returned to user name space)
“code” – will place variable in “code” space. NOTE code space is NOT read-only.
“eeprom”- (new) will place the variable in eeprom (read & write)
“sram” – (new) will place the variable in “SRAM” after the SFRs (default).

b) register/sfr bit access.

Operator ‘.’ will be overloaded ( the compiler will decide if it
is a structure access or register bit access depending on context)

sfr SOME_SFR = 0x40;
sfr SOME_OTHER_SFR = 0x41;

SOME_SFR.4 = 1; // set bit 4 of sfr SOME_SFR

SOME_SFR.5 = SOME_OTHER_SFR.6; // copy bit 6 of SOME_OTHER_SFR to SOME_SFR’s bit 5.


II) Pointers

As mentioned above initial releases will NOT support ATMega.

Keeping with the three byte pointers for generic pointers,
the compiler will treat unqualified pointers as 3 byte pointers,
the storage area will be saved in the upper nibble of the third byte
(this will facilitate later support for ATMega). Here we differ for
IAR (they seem to make copies of variables in code & other address
spaces into data space, seemed like a needless waste of data space).

pointer declaration examples.

char *cp; /* generic three byte pointer */
code char *cp; /* pointer to code space */
eeprom char *cp; /* pointer to data in eepromp */
sram char *cp; /* pointer to data in SRAM space */

III) Function calls

The previous issue of function calls has been somewhat resolved.
SDCC will NOT support ATtiny & other variants (such as AT90S1200)
which have limited stack depth. It will however support variants
with 8 bit stack pointers.

IV) Register Usage

R0-R7 – Paramter passing & return value (differs from IAR I don’t
like IAR’s usage of R16-R23, specially since R0-R1 has
to be kept free anyway for divide & multiply operations)
R8-R25 – General purpose registers for local variables.
R28-R29(Y) – Stack Frame (Same as IAR)
R26-R27(X) – GPRs assigned to pointers (non generic pointers).
R30-R31(Z) – GPRs assigned to pointers (non generic pointers).

V) Parameter passing & return values

Registers R0-R7 (eight) registers will be used for parameter passing.
Unlike the 8051 port the AVR port will pass the first eight bytes of
parameters in a registers (8051 passes only yhe first parameter in
registers), the exception being.. part of a paramter will not be put
into registers.

int foo (char a,long b);
R0 <- a,
R1-R4 <- b;

int foo (long a, char b, long c)
R0-R3 <- a,
R4 <- b,
(STACK) <- c;

int foo (long a,long b)
R0-R3 <- a,
R4-R7 <- b;

Return values will be placed in registers R0-R3;

VI) Memory models

The memory model will be used primarily to determine the
width of the stack pointer.

–model-small – stack pointer 8 bit
–model-large – stack pointer 16 bit.

Leave a comment

Filed under Linux, Programming

8 Queen puzzle solution using C

This is a Backtracking solution for 8 Queen problem check it out.


Leave a comment

Filed under Linux, Programming