Advertisement
Guest User

Untitled

a guest
Mar 5th, 2014
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 9.55 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #include <stdint.h>
  5. #define CHECK_BIT(var,pos) ((var) & (1<<(pos)))
  6. #define BITTOP 14
  7. #define true 1
  8. #define false 0
  9. #define h 4
  10. #define v 4
  11.  
  12. //typedef unsigned short uint16_t;
  13. //uint16_t uint16val;
  14. //0123>>3210
  15. //shiftal16(int data)
  16. shiftal16(uint16_t uval16){
  17.     uint16_t b0,b1,b2,b3;
  18.     b0=(uval16>>12)&0xf; //0xxx(B)->xxx0
  19.     b1=(uval16>>8)&0xf; //1 x1xx(B)->xx1x
  20.     b2=(uval16>>4)&0xf; //2 xx2x(B)->x2xx
  21.     b3=(uval16)&0xf; //3 xxx3(B)->3xxx
  22. return (b3<<12|b2<<8|b1<<4|b0); //align & shift
  23. }
  24.  
  25. //prints bit (dec) value
  26. int bit(int val){
  27. int bitcnt=0;
  28. for(bitcnt=BITTOP;bitcnt>=0;bitcnt--){
  29.     if((val&(1<<bitcnt))) printf("1");
  30.     else printf("0");}
  31.     printf(" (");
  32. for(bitcnt=BITTOP;bitcnt>=0;bitcnt--){
  33.     printf("[%d",CHECK_BIT(val,bitcnt));
  34.     printf("]");
  35. }
  36. printf(") \n");
  37. }
  38. //counts hex string
  39. int hexcnt(int val){
  40.     int pat_cnt=0;while ((val>>pat_cnt)!=0) pat_cnt=pat_cnt+1;
  41.     pat_cnt=pat_cnt/sizeof(val);
  42.     return pat_cnt;
  43. }
  44. //strhex(phys_add,start,pattern);
  45. int strhex(int memseg, int data, int pattern){
  46. int final=0,*temp,p1,p2;
  47. typedef unsigned short uint16_t;
  48. uint16_t uint16p1=0,uint16p2=0,datcnt16,patcnt16;
  49.  
  50. temp=(int*)malloc(memseg);//alloc 6MB ram
  51. if(!temp) printf("error alocating %d bytes",memseg);
  52. if(!memcpy(temp,&data,sizeof(data))) //copy data into ram
  53. printf("error copying %d blob to p* %d",data,&temp);
  54.  
  55. patcnt16=hexcnt(pattern); //count hex pattern
  56. datcnt16=hexcnt(data); //count hex data
  57.  
  58. for(p1=sizeof(pattern)*(patcnt16+1);p1>0;p1=p1-8){ //1 word pattern 0xff
  59.  uint16p1=(pattern >> p1-8)& 0xff;//word (2byte) pass //pointer-8 starts at index 0  
  60.         for(p2=sizeof(data)*(datcnt16+1);p2>0;p2=p2-8){//l00k3r
  61.             uint16p2=(data >> p2-8)& 0xff;
  62.             if(p2==(sizeof(data)*(datcnt16+1))&&p1==(sizeof(pattern)*(patcnt16+1))){
  63.                 printf("/hex------------ptr-------------status/ \n---------------------------------------- \n");
  64.             }
  65.             if(uint16p1==uint16p2){    
  66.                 printf("(0x%x+*%d) (0x%x) found! \n ",memseg,*temp&uint16p2,uint16p2);
  67.                 bit(uint16p2);
  68.                 printf("-- \n");
  69.                 final=final+uint16p2;
  70.             }
  71.         }
  72. }
  73. if(final==0)printf("0x%x(0x%x), pattern:0x%x was not found!",memseg,data,pattern);
  74. //end
  75. }
  76.  
  77. //draw(*stack_collection,n)
  78. draw(int* obj,int n){
  79.     int x,last=0;
  80.  //*obj+(inccol);
  81.    for(x=0;x<h*n;x++){
  82.      (*((obj+x+last)) & 1) ? printf("(%d)",
  83.      *(obj+x+last)):printf(" - ",(obj+x+last));
  84.  
  85.     if (((x+1)%4)==0) last=last+12; //mat[0][0]+=16 //next 4x4
  86.    }
  87.    printf("\n");
  88.    last=4;
  89.    for(x=0;x<h*n;x++){
  90.      (*((obj+x+last)) & 1) ? printf("(%d)",
  91.      *(obj+x+last)):printf(" - ",(obj+x+last));
  92.  
  93.     if (((x+1)%4)==0) last=last+12; //mat[0][0]+=16 //next 4x4
  94.    }
  95.    printf("\n");
  96.    last=8;
  97.    for(x=0;x<h*n;x++){
  98.      (*((obj+x+last)) & 1) ? printf("(%d)",
  99.      *(obj+x+last)):printf(" - ",(obj+x+last));
  100.  
  101.     if (((x+1)%4)==0) last=last+12; //mat[0][0]+=16 //next 4x4
  102.    }
  103.    printf("\n");
  104.    last=12;
  105.    for(x=0;x<h*n;x++){
  106.      (*((obj+x+last)) & 1) ? printf("(%d)",
  107.      *(obj+x+last)):printf(" - ",(obj+x+last));
  108.  
  109.     if (((x+1)%4)==0) last=last+12; //mat[0][0]+=16 //next 4x4
  110.    }
  111.    
  112. }
  113. //allocates 4x4*n integer matrix with 0xFF
  114. create_buffer(int* obj,int buf_size){
  115.     //obj+(16*26);//next buffer from abc_z (free onwards)
  116.     int i;
  117.     for(i=0;i<(h*v)*buf_size;i++){
  118.         memset(obj+(16*26)+i,0xFF,1);
  119.     }
  120.     return 16*26;
  121. }
  122.  
  123. //w_write(word,offset_start,block_size,abc_index)
  124. w_write(char obj[],int* temp_ptr,int size,int abc_index){
  125.     int i,str_size,*stack_pos,alloc_buf;
  126.     str_size=strlen(obj);
  127.  
  128.     //we need to create a buffer for n words (as read --> 4*line because printf)
  129.     alloc_buf=create_buffer(temp_ptr,str_size);
  130.    
  131.     //upon created we point to that buffer, copy word contents to it
  132.     for(i=0;i<str_size;i++){  
  133.         switch(*(obj+i)) //word 0x41 -- 0x7a
  134.         {
  135.         case(0x61): //a
  136.         //temp_ptr+16*1; //physical abc_word address
  137.         //obj_copy(*screen_obj,n)
  138.         memcpy(temp_ptr+alloc_buf+(16*i),temp_ptr+(16*1),64);
  139.         break;
  140.         case(0x62): //b
  141.         memcpy(temp_ptr+alloc_buf+(16*i),temp_ptr+(16*2),64);
  142.         break;
  143.         case(0x63): //c
  144.         memcpy(temp_ptr+alloc_buf+(16*i),temp_ptr+(16*3),64);
  145.         break;
  146.         case(0x64): //d
  147.         memcpy(temp_ptr+alloc_buf+(16*i),temp_ptr+(16*4),64);
  148.         break;
  149.         case(0x65): //e
  150.         memcpy(temp_ptr+alloc_buf+(16*i),temp_ptr+(16*5),64);
  151.         break;
  152.         case(0x66): //f
  153.         memcpy(temp_ptr+alloc_buf+(16*i),temp_ptr+(16*6),64);
  154.         break;
  155.         case(0x67): //g
  156.         memcpy(temp_ptr+alloc_buf+(16*i),temp_ptr+(16*7),64);
  157.         break;
  158.         case(0x68): //h
  159.         memcpy(temp_ptr+alloc_buf+(16*i),temp_ptr+(16*8),64);
  160.         break;
  161.         case(0x69): //i
  162.         memcpy(temp_ptr+alloc_buf+(16*i),temp_ptr+(16*9),64);
  163.         break;
  164.         case(0x6a): //j
  165.         memcpy(temp_ptr+alloc_buf+(16*i),temp_ptr+(16*10),64);
  166.         break;
  167.         case(0x6b): //k
  168.         memcpy(temp_ptr+alloc_buf+(16*i),temp_ptr+(16*11),64);
  169.         break;
  170.         case(0x6c): //l
  171.         memcpy(temp_ptr+alloc_buf+(16*i),temp_ptr+(16*12),64);
  172.         break;
  173.         case(0x6d): //m
  174.         memcpy(temp_ptr+alloc_buf+(16*i),temp_ptr+(16*13),64);
  175.         break;
  176.         case(0x6e): //n
  177.         memcpy(temp_ptr+alloc_buf+(16*i),temp_ptr+(16*14),64);
  178.         break;
  179.         case(0x6f): //o
  180.         memcpy(temp_ptr+alloc_buf+(16*i),temp_ptr+(16*15),64);
  181.         break;
  182.         case(0x70): //p
  183.         memcpy(temp_ptr+alloc_buf+(16*i),temp_ptr+(16*16),64);
  184.         break;
  185.         case(0x71): //q
  186.         memcpy(temp_ptr+alloc_buf+(16*i),temp_ptr+(16*17),64);
  187.         break;
  188.         case(0x72): //r
  189.         memcpy(temp_ptr+alloc_buf+(16*i),temp_ptr+(16*18),64);
  190.         break;
  191.         case(0x73): //s
  192.         memcpy(temp_ptr+alloc_buf+(16*i),temp_ptr+(16*19),64);
  193.         break;
  194.         case(0x74): //t
  195.         memcpy(temp_ptr+alloc_buf+(16*i),temp_ptr+(16*20),64);
  196.         break;
  197.         case(0x75): //u
  198.         memcpy(temp_ptr+alloc_buf+(16*i),temp_ptr+(16*21),64);
  199.         break;
  200.         case(0x76): //v
  201.         memcpy(temp_ptr+alloc_buf+(16*i),temp_ptr+(16*22),64);
  202.         break;
  203.         case(0x77): //w1+w2  (16*23 & 16*24)
  204.         memcpy(temp_ptr+alloc_buf+(16*i),temp_ptr+(16*23),64);
  205.         break;
  206.         case(0x78): //x
  207.         memcpy(temp_ptr+alloc_buf+(16*i),temp_ptr+(16*25),64);
  208.         break;
  209.         case(0x79): //y
  210.         memcpy(temp_ptr+alloc_buf+(16*i),temp_ptr+(16*26),64);
  211.         break;
  212.         case(0x7a): //z
  213.         memcpy(temp_ptr+alloc_buf+(16*i),temp_ptr+(16*27),64);
  214.         break;
  215.         }//switch
  216.     }//for
  217.    
  218.     //then draw
  219.     draw(temp_ptr+alloc_buf,str_size);
  220. }
  221.     int screen[h][v]={
  222.     0,1,0,0,
  223.     0,0,0,0,
  224.     0,0,0,0,
  225.     0,0,0,0};
  226.    
  227.     int abc_a[h][v]={
  228.     1,1,1,1,
  229.     1,0,0,1,
  230.     1,1,1,1,
  231.     1,0,0,1};
  232.    
  233.     int abc_b[h][v]={
  234.     1,0,0,0,
  235.     1,1,1,0,
  236.     1,0,0,1,
  237.     1,1,1,1};
  238.    
  239.     int abc_c[h][v]={
  240.     1,1,1,1,
  241.     1,0,0,0,
  242.     1,0,0,0,
  243.     1,1,1,1};
  244.    
  245.     int abc_d[h][v]={
  246.     1,1,1,0,
  247.     1,0,0,1,
  248.     1,0,0,1,
  249.     1,1,1,0};
  250.    
  251.     int abc_e[h][v]={
  252.     1,1,1,0,
  253.     1,0,1,0,
  254.     1,1,0,0,
  255.     1,1,1,1};
  256.    
  257.     int abc_f[h][v]={
  258.     1,1,1,1,
  259.     1,0,0,0,
  260.     1,1,1,0,
  261.     1,0,0,0};
  262.    
  263.     int abc_g[h][v]={
  264.     1,1,1,1,
  265.     1,0,0,0,
  266.     1,0,1,1,
  267.     1,1,1,1};
  268.    
  269.     int abc_h[h][v]={
  270.     1,0,0,1,
  271.     1,0,0,1,
  272.     1,1,1,1,
  273.     1,0,0,1};
  274.  
  275.     int abc_i[h][v]={
  276.     0,1,1,1,
  277.     0,0,1,0,
  278.     0,0,1,0,
  279.     0,1,1,1};
  280.    
  281.     int abc_j[h][v]={
  282.     0,1,1,1,
  283.     0,0,1,0,
  284.     1,0,1,0,
  285.     0,1,1,0};
  286.    
  287.     int abc_k[h][v]={
  288.     1,0,0,1,
  289.     1,0,1,0,
  290.     1,1,1,0,
  291.     1,0,0,1};
  292.    
  293.     int abc_l[h][v]={
  294.     1,0,0,0,
  295.     1,0,0,0,
  296.     1,0,0,0,
  297.     1,1,1,0};
  298.    
  299.     int abc_m[h][v]={
  300.     1,0,0,1,
  301.     0,1,1,0,
  302.     1,0,0,1,
  303.     1,0,0,1};
  304.    
  305.     int abc_n[h][v]={
  306.     1,0,0,1,
  307.     1,1,0,1,
  308.     1,0,1,1,
  309.     1,0,0,1};
  310.    
  311.     int abc_o[h][v]={
  312.     0,1,1,0,
  313.     1,0,0,1,
  314.     1,0,0,1,
  315.     0,1,1,0};
  316.    
  317.     int abc_p[h][v]={
  318.     1,1,1,1,
  319.     1,0,0,1,
  320.     1,1,1,1,
  321.     1,0,0,0};
  322.    
  323.     int abc_q[h][v]={
  324.     0,1,1,0,
  325.     1,0,0,1,
  326.     0,1,1,0,
  327.     0,0,0,1};
  328.    
  329.     int abc_r[h][v]={
  330.     1,1,1,0,
  331.     1,0,0,1,
  332.     1,1,1,0,
  333.     1,0,0,1};
  334.    
  335.     int abc_s[h][v]={
  336.     0,1,1,1,
  337.     1,0,0,0,
  338.     0,0,1,1,
  339.     1,1,0,0};
  340.    
  341.     int abc_t[h][v]={
  342.     0,1,1,1,
  343.     0,0,1,0,
  344.     0,0,1,0,
  345.     0,0,1,0};
  346.    
  347.     int abc_u[h][v]={
  348.     1,0,0,1,
  349.     1,0,0,1,
  350.     1,0,0,1,
  351.     0,1,1,0};
  352.    
  353.     int abc_v[h][v]={
  354.     1,0,0,1,
  355.     1,0,0,1,
  356.     1,0,0,1,
  357.     0,0,1,0};
  358.    
  359.     int abc_w1[h][v]={
  360.     1,0,0,0,
  361.     1,0,1,0,
  362.     0,1,0,0,
  363.     0,0,0,0};
  364.    
  365.     int abc_w2[h][v]={
  366.     0,0,1,0,
  367.     1,0,1,0,
  368.     0,1,0,0,
  369.     0,0,0,0};
  370.    
  371.     int abc_x[h][v]={
  372.     1,0,0,1,
  373.     0,1,0,0,
  374.     0,0,1,0,
  375.     1,0,0,1};
  376.    
  377.     int abc_y[h][v]={
  378.     1,0,1,0,
  379.     1,0,1,0,
  380.     0,1,0,0,
  381.     0,1,0,0};
  382.    
  383.     int abc_z[h][v]={
  384.     1,1,1,1,
  385.     0,0,1,0,
  386.     0,1,0,0,
  387.     1,1,1,1};
  388.    
  389.  
  390. int main(){
  391.     //draw[fb]<-draw[font] (word)
  392.     //draw(fb) (4*4)
  393.     // * * * *
  394.     // * * * *
  395.     // * * * *
  396.     // * * * *
  397.     int bl_size=sizeof(screen);//blocksize
  398.     int abc_index=(&abc_z[0][0]-&screen[0][0])/16;//abc index
  399.     //w_write(word,offset_start,blocksize,abc[n])
  400.     w_write("hello gbatemp",*screen,bl_size,abc_index);
  401. //end
  402. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement