All pastes #251641 Raw Edit

Miscellany

public text v1 · immutable
#251641 ·published 2006-11-18 12:21 UTC
rendered paste body
// Includes
#include <PA9.h>       // Include for PA_Lib
#include <stdio.h>
#include <stdlib.h>

void loadSprite(char *file, unsigned short *sprite,unsigned short *pallete){
        FAT_FILE *element;
        int data[4095];
        int i=0;
        element = FAT_fopen(file,"r");
        while((data[i]=FAT_fgetc(element))){
                i++;
        }
        FAT_fclose(element);
        int x,y,tmp,last=0;
        for(x=0;x<4096;x++){
                tmp=data[x];
                for(y=0;y<256;y++){
                        if(*pallete == tmp){
                                *sprite = y;
                                sprite++;
                        } else if (*pallete != tmp && y == 255){
                                pallete = pallete - 255 + last;
                                *pallete = tmp;
                                last++;
                                pallete = pallete - last + 255;
                        }
                        pallete++;

                }
                pallete = pallete - 255;
        }
}
// Function: main()
int main(int argc, char ** argv)
{
        unsigned short sprite1[4095] __attribute__ ((aligned (4)));
        unsigned short pal1[255] __attribute__ ((aligned (4)));

        PA_Init();    // Initializes PA_Lib
        PA_InitVBL(); // Initializes a standard VBL
        PA_Init8bitBg(0,1);
        FAT_InitFiles();
        loadSprite("/test.bmp",&sprite1[0],&pal1[0]);
        PA_LoadSpritePal(0,0,(void*)pal1);
        PA_CreateSprite(0,0,(void*)sprite1,OBJ_SIZE_64X64,1,0,50,50);
        // Infinite loop to keep the program running
        while (1)
        {
                PA_WaitForVBL();
        }

        return 0;
} // End of main()