Pages - Menu

Monday 10 September 2012

Me and Detective Conan


Seriously I’m kinda boring on this semester break because of all my best friend were already continue their study. Yeah, UTP quite weird not because of student but because of it have three semesters in one year. That gonna make learning progress super-fast but seriously no life. So after all my family already sleeps, I climb my cupboard and try to find something interesting. And after quite some time, I found my old comic stuff.  During my high school, I am one of the Detective Conan fans. So lot of stuff that related to it I bought during that time. One of it is comic. 
1box of Detective Conan (proud face)
Besides that, I also a Gempak supporters. This is because lot of material inside that quite catchy and give information about games and related matters. But this doesn’t take much because my parent not allows me to buy it again. They said, this does not have any beneficial. So I stop once I enter form 5.

Tadaaa!!! Not Much, maybe 20 volume


Than after more deeper I search finally I found something that memorable to me. 





That is PMR Gold Awards that I got from Yayasan Terengganu. Waaa... Still remember that on that day I greet Minister of Terengganu, Ahmad Said I think. 



I want to continue my blog writing but my Top Gear Seasons 19 already finish download. So Bye2... 







Wednesday 5 September 2012

Final Stucture programming


#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/io.h>

#define STRSIZ 200

typedef struct
{
char question[STRSIZ];
char symbol[STRSIZ];
int answer1;
int answer2;
int answer3;
int answer4;
} quiz_data;

typedef struct
{
quiz_data quiz_num[11];
}maths;

void question1();
void question2();
void question3();
void question4();

maths quiz_info;
void delay1 ();
void delay2 ();
void delay3 ();
void delay4 ();
void in_out();
void display_score(int n);
void review_rules();
void file_open(FILE *fp);
void high_score(int highscore);

main (int argc,char **argv)
{
FILE *fp;
FILE *fp2;
FILE *fp3;
FILE *fp4;
fp = fopen("data.txt", "w+");
fp2=fopen("answer.txt","w+");
fp3=fopen("total_score.txt","r+");
fp4=fopen("high_score.txt","r");
file_open(fp);
file_open(fp2);
file_open(fp3);
file_open(fp4);


{
if(ioperm(0x378,1,1))
fprintf(stderr, "COuldnt get the port at 0x378\n"),exit(1);
if(ioperm(0x379,1,1))
fprintf(stderr, "COuldnt get the port at 0x379\n"),exit(1);
if(ioperm(0x37A,1,1))
fprintf(stderr, "COuldnt get the port at 0x37A\n"),exit(1);
outb(0x08,0x37A);

}

int i;
int total_score=0;
int highscore;


strcpy(quiz_info.quiz_num[0].question, "1)What is the result for 10 + 12? " );
strcpy(quiz_info.quiz_num[0].symbol, "S" );
quiz_info.quiz_num[0].answer1= 21;
quiz_info.quiz_num[0].answer2 = 22;
quiz_info.quiz_num[0].answer3= 23;
quiz_info.quiz_num[0].answer4 = 24;

strcpy(quiz_info.quiz_num[1].question, "2)This is our ___th merdeka celebration. ");
strcpy(quiz_info.quiz_num[1].symbol, "T");
quiz_info.quiz_num[1].answer1 = 52;
quiz_info.quiz_num[1].answer2 = 53;
quiz_info.quiz_num[1].answer3 = 54;
quiz_info.quiz_num[1].answer4 = 55;

strcpy(quiz_info.quiz_num[2].question, "3)1+3=? ");
strcpy(quiz_info.quiz_num[2].symbol, "U");
quiz_info.quiz_num[2].answer1 = 1;
quiz_info.quiz_num[2].answer2 = 4;
quiz_info.quiz_num[2].answer3 = 3;
quiz_info.quiz_num[2].answer4 = 2;

strcpy(quiz_info.quiz_num[3].question, "4)11-1=? ");
strcpy(quiz_info.quiz_num[3].symbol, "V");
quiz_info.quiz_num[3].answer1 = 11;
quiz_info.quiz_num[3].answer2 = 13;
quiz_info.quiz_num[3].answer3 = 12;
quiz_info.quiz_num[3].answer4 = 10;



if (fp==NULL)
{
  printf("Cannot Open file \n");
  exit(1);
}

for(i=0; i<=3; i++)
{
fprintf(fp,"%s", quiz_info.quiz_num[i].question);
fprintf(fp,"%s", quiz_info.quiz_num[i].symbol);
fprintf(fp,"A. %d\n", quiz_info.quiz_num[i].answer1);
fprintf(fp,"B. %d\n", quiz_info.quiz_num[i].answer2);
fprintf(fp,"C. %d\n", quiz_info.quiz_num[i].answer3);
fprintf(fp,"D. %d\n\n", quiz_info.quiz_num[i].answer4);
}




review_rules();
display_score(total_score);

long k;
long a=0;
int  read;

        do
        {
read = inb(0x379);
if (read==184)
{
printf("Lets Begin Now!!!! ");
a++;
}
}
while(a<1);

        question1(); //question 1...
        for(k=0;k<10000000;k++){
int a,b,c,d,e,f,g;
read = inb(0x379);

if  (read==232)
{
printf("CORRECT! You just gain 3 marks!!\n");
outb(0x01,0x37A);
for (d=0;d<20;d++)
{
outb(0xE7,0x378);
delay4();
outb(0xDB,0x378);
delay4();
outb(0xFC,0x378);
delay4();
outb(0x3F,0x378);
delay4();
outb(0xFC,0x378);
delay4();
outb(0xDB,0x378);
delay4();
outb(0xE7,0x378);
delay4();
}
k=100000000;
delay4();

total_score=total_score+3;
fprintf(fp2, "Question 1: \n(B) 50\n");
display_score(total_score);
}


  if(read==240)
{
printf("WRONG!\n");
k=100000000;
delay4();
fprintf(fp2, "Question 1: \n(A) 20\n");
outb(0x0F,0x37A);
delay3 ();
outb(0x00,0x37A); //buzzer sound 1x8
delay4 ();
}
 if(read==216)
{
printf("WRONG!\n");
k=100000000;
delay4();
fprintf(fp2, "Question 1: \n(C) 10\n");
outb(0x0F,0x37A);
delay3 ();
outb(0x00,0x37A); //buzzer sound 1x8
delay4 ();}
 if(read==120)
{
printf("WRONG!\n");
k=100000000;
delay4();
fprintf(fp2, "Question 1: \n(D) 70\n");
outb(0x0F,0x37A);
delay3 ();
outb(0x00,0x37A); //buzzer sound 1x8
delay4 ();}



if(k==3333333||k==6666666)
{ {

outb(0x01,0x37A); //select LED
outb(0x00,0x378); //LED light up for 22222222

delay4 ();


outb(0xFF,0x378); //LED off for 2x8

delay4 ();


outb(0x00,0x378); //LED on 2x8

delay4 ();


outb(0xFF,0x378); //LED off 2x8

delay4 ();

}

outb(0x0F,0x37A);
delay4 ();
delay4 ();
outb(0x00,0x37A); //buzzer sound 1x8
delay4 ();
}
if(k==9999999)
{
outb(0x0F,0x37A);

for(b =0;b<3;b++)
{
delay3 ();

}

for(e = 0; e<10; e++)
{
outb(0x01,0x37A); //select LED
outb(0x00,0x378); //LED light up for 22222222
for(f =0;f<3;f++)
{
delay4 ();
}

outb(0xFF,0x378); //LED off for 2x8
for(f =0;f<3;f++)
{
delay4 ();
}

outb(0x00,0x378); //LED on 2x8
for(f =0;f<3;f++)
{
delay4 ();
}

outb(0xFF,0x378); //LED off 2x8
for(f =0;f<3;f++)
{
delay4 ();
}
}
outb(0x09,0x37A);
outb(0x00,0x37A); //buzzer sound 1x8
delay4 ();
}
}
if(read!=248){
while(read!=248){
printf("\nPlease push all the switch up for the next question !\n");
int q;
for(q=0;q<3;q++)
{
delay4 ();
delay4 ();
delay4 ();
}
read=inb(0x379);
if(read==248){read==248;}}
}

display_score(total_score);
question2();

for(k=0;k<10000000;k++){
int a,b,c,d,e,f;
read = inb(0x379);

if  (read==120)
{
printf("CORRECT! You just gain 3 marks!!\n");
outb(0x01,0x37A);
for (d=0;d<20;d++)
{
outb(0xE7,0x378);
delay4();
outb(0xDB,0x378);
delay4();
outb(0xFC,0x378);
delay4();
outb(0x3F,0x378);
delay4();
outb(0xFC,0x378);
delay4();
outb(0xDB,0x378);
delay4();
outb(0xE7,0x378);
delay4();
}
k=100000000;
delay4();
total_score=total_score+3;
fprintf(fp2, "Question 2: \n(D) 10\n");
display_score(total_score);
}


  if(read==240)
{
printf("WRONG!\n");
k=100000000;
delay4();
fprintf(fp2, "Question 2: \n(A) 20\n");
outb(0x0F,0x37A);
delay3 ();
outb(0x00,0x37A); //buzzer sound 1x8
delay4 ();}
 if(read==232)
{
printf("WRONG!\n");
k=100000000;
delay4();
fprintf(fp2, "Question 2: \n(B) 16\n");
outb(0x0F,0x37A);
delay3 ();
outb(0x00,0x37A); //buzzer sound 1x8
delay4 ();}
 if(read==216)
{
printf("WRONG!\n");
k=100000000;
delay4();
fprintf(fp2, "Question 2: \n(C) 9\n");
outb(0x0F,0x37A);
delay3 ();
outb(0x00,0x37A); //buzzer sound 1x8
delay4 ();}
if(k==3333333||k==6666666)
{{

outb(0x01,0x37A); //select LED
outb(0x00,0x378); //LED light up for 22222222

delay4 ();


outb(0xFF,0x378); //LED off for 2x8

delay4 ();


outb(0x00,0x378); //LED on 2x8

delay4 ();


outb(0xFF,0x378); //LED off 2x8

delay4 ();

}

outb(0x0F,0x37A);
delay4 ();
delay4 ();
outb(0x00,0x37A); //buzzer sound 1x8
delay4 ();
}
if(k==9999999)
{outb(0x0F,0x37A);
for(b =0;b<3;b++)
{
delay3 ();
}

for(e = 0; e<10; e++)
{
outb(0x01,0x37A); //select LED
outb(0x00,0x378); //LED light up for 22222222
for(f =0;f<3;f++)
{
delay4 ();
}

outb(0xFF,0x378); //LED off for 2x8
for(f =0;f<3;f++)
{
delay4 ();
}

outb(0x00,0x378); //LED on 2x8
for(f =0;f<3;f++)
{
delay4 ();
}

outb(0xFF,0x378); //LED off 2x8
for(f =0;f<3;f++)
{
delay4 ();
}
}

outb(0x09,0x37A);
outb(0x00,0x37A); //buzzer sound 1x8
delay4 ();
}
}
if(read!=248){
while(read!=248){
printf("\nPlease push all the switch up for the next question !\n");
int q;
for(q=0;q<3;q++)
{
delay4 ();
delay4 ();
delay4 ();
}
read=inb(0x379);
if(read==248){read==248;}}
}

display_score(total_score);
question3();
for(k=0;k<10000000;k++){
int a,b,c,d,e,f;
read = inb(0x379);

if  (read==232)
{
printf("CORRECT! You just gain 3 marks!!\n");
outb(0x01,0x37A);
for (d=0;d<20;d++)
{
outb(0xE7,0x378);
delay4();
outb(0xDB,0x378);
delay4();
outb(0xFC,0x378);
delay4();
outb(0x3F,0x378);
delay4();
outb(0xFC,0x378);
delay4();
outb(0xDB,0x378);
delay4();
outb(0xE7,0x378);
delay4();
}
k=100000000;
delay4();
total_score=total_score+3;
fprintf(fp2, "Question 3: \n(B) 650\n");
display_score(total_score);
}


  if(read==240)
{
printf("WRONG!\n");
k=100000000;
delay4();
fprintf(fp2, "Question 3: \n(A) 600\n");
outb(0x0F,0x37A);
delay3 ();
outb(0x00,0x37A); //buzzer sound 1x8
delay4 ();}
 if(read==216)
{
printf("WRONG!\n");
k=100000000;
delay4();
fprintf(fp2, "Question 3: \n(C) 65\n");
outb(0x0F,0x37A);
delay3 ();
outb(0x00,0x37A); //buzzer sound 1x8
delay4 ();}
 if(read==120)
{
printf("WRONG!\n");
k=100000000;
delay4();
fprintf(fp2, "Question 3: \n(D) 19\n");
outb(0x0F,0x37A);
delay3 ();
outb(0x00,0x37A); //buzzer sound 1x8
delay4 ();}

if(k==3333333||k==6666666)
{{

outb(0x01,0x37A); //select LED
outb(0x00,0x378); //LED light up for 22222222

delay4 ();


outb(0xFF,0x378); //LED off for 2x8

delay4 ();


outb(0x00,0x378); //LED on 2x8

delay4 ();


outb(0xFF,0x378); //LED off 2x8

delay4 ();

}

outb(0x0F,0x37A);
delay4 ();
delay4 ();
outb(0x00,0x37A); //buzzer sound 1x8
delay4 ();
}
if(k==9999999)
{outb(0x0F,0x37A);
for(b =0;b<3;b++)
{
delay3 ();
}

for(e = 0; e<10; e++)
{
outb(0x01,0x37A); //select LED
outb(0x00,0x378); //LED light up for 22222222
for(f =0;f<3;f++)
{
delay4 ();
}

outb(0xFF,0x378); //LED off for 2x8
for(f =0;f<3;f++)
{
delay4 ();
}

outb(0x00,0x378); //LED on 2x8
for(f =0;f<3;f++)
{
delay4 ();
}

outb(0xFF,0x378); //LED off 2x8
for(f =0;f<3;f++)
{
delay4 ();
}
}

outb(0x09,0x37A);
outb(0x00,0x37A); //buzzer sound 1x8
delay4 ();
}
}
if(read!=248){
while(read!=248){
printf("\nPlease push all the switch up for the next question !\n");
int q;
for(q=0;q<3;q++)
{
delay4 ();
delay4 ();
delay4 ();
}
read=inb(0x379);
if(read==248){read==248;}}
}
display_score(total_score);
question4();
for(k=0;k<10000000;k++){
int a,b,c,d,e,f;
read = inb(0x379);

if  (read==120)
{
printf("CORRECT! You just gain 3 marks!!\n");
outb(0x01,0x37A);
for (d=0;d<20;d++)
{
outb(0xE7,0x378);
delay4();
outb(0xDB,0x378);
delay4();
outb(0xFC,0x378);
delay4();
outb(0x3F,0x378);
delay4();
outb(0xFC,0x378);
delay4();
outb(0xDB,0x378);
delay4();
outb(0xE7,0x378);
delay4();
}
k=100000000;
delay4();
total_score=total_score+3;
fprintf(fp2, "Question 4: \n(D) 802\n");
display_score(total_score);
}


   if(read==240)
{
printf("WRONG!\n");
k=100000000;
delay4();
fprintf(fp2, "Question 4: \n(A) 111\n");
outb(0x0F,0x37A);
delay3 ();
outb(0x00,0x37A); //buzzer sound 1x8
delay4 ();}
 if(read==232)
{
printf("WRONG!\n");
k=100000000;
delay4();
fprintf(fp2, "Question 4: \n(B) 112\n");
outb(0x0F,0x37A);
delay3 ();
outb(0x00,0x37A); //buzzer sound 1x8
delay4 ();}
 if(read==216)
{
printf("WRONG!\n");
k=100000000;
delay4();
fprintf(fp2, "Question 4: \n(C) 141\n");
outb(0x0F,0x37A);
delay3 ();
outb(0x00,0x37A); //buzzer sound 1x8
delay4 ();}

if(k==3333333||k==6666666)
{{

outb(0x01,0x37A); //select LED
outb(0x00,0x378); //LED light up for 22222222

delay4 ();


outb(0xFF,0x378); //LED off for 2x8

delay4 ();


outb(0x00,0x378); //LED on 2x8

delay4 ();


outb(0xFF,0x378); //LED off 2x8

delay4 ();

}

outb(0x0F,0x37A);
delay4 ();
delay4 ();
outb(0x00,0x37A); //buzzer sound 1x8
delay4 ();
}
if(k==9999999)
{outb(0x0F,0x37A);
for(b =0;b<3;b++)
{
delay3 ();
}

for(e = 0; e<10; e++)
{
outb(0x01,0x37A); //select LED
outb(0x00,0x378); //LED light up for 22222222
for(f =0;f<3;f++)
{
delay4 ();
}

outb(0xFF,0x378); //LED off for 2x8
for(f =0;f<3;f++)
{
delay4 ();
}

outb(0x00,0x378); //LED on 2x8
for(f =0;f<3;f++)
{
delay4 ();
}

outb(0xFF,0x378); //LED off 2x8
for(f =0;f<3;f++)
{
delay4 ();
}
}

outb(0x09,0x37A);
outb(0x00,0x37A); //buzzer sound 1x8
delay4 ();
}
}
if(read!=248){
while(read!=248){
printf("\nPlease push all the switch up for the next question !\n");
int q;
for(q=0;q<3;q++)
{
delay4 ();
delay4 ();
delay4 ();
}
read=inb(0x379);
if(read==248){read==248;}}
}

 

fscanf(fp4, "%d", &highscore);
printf("Your Highscore is %d\n", highscore);
if(highscore < total_score){
printf("You've break the highscore!");
highscore = total_score;
high_score(highscore);
}

fprintf(fp3, "%d\t", total_score);
printf("Congrates, quiz finished!\n");

fclose(fp);fclose(fp2);fclose(fp3);fclose(fp4);
}

void file_open(FILE *fp)
{
if (fp==NULL)
{
printf("Cannot open file\n");
exit(1);
}
}


void question1()
{
char input[30]={"S"};
int j=0;
while (j<4)
{
    if (strcmp(quiz_info.quiz_num[j].symbol,input)==0)
    printf("\n\n %s\n A. %d\n B. %d\n C. %d\n D. %d\n\n ",quiz_info.quiz_num[j].question,quiz_info.quiz_num         [j].answer1,quiz_info.quiz_num[j].answer2,quiz_info.quiz_num[j].answer3,quiz_info.quiz_num[j].answer4);
j++;
}
return;
}

void question2()
{
char input[30]={"T"};
int j=0;
while (j<4)
{
    if (strcmp(quiz_info.quiz_num[j].symbol,input)==0)
    printf("\n\n %s\n A. %d\n B. %d\n C. %d\n D. %d\n\n ",quiz_info.quiz_num[j].question,quiz_info.quiz_num         [j].answer1,quiz_info.quiz_num[j].answer2,quiz_info.quiz_num[j].answer3,quiz_info.quiz_num[j].answer4);
j++;
}
return;
}

void question3()
{
char input[30]={"U"};
int j=0;
while (j<4)
{
    if (strcmp(quiz_info.quiz_num[j].symbol,input)==0)
    printf("\n\n %s\n A. %d\n B. %d\n C. %d\n D. %d\n\n ",quiz_info.quiz_num[j].question,quiz_info.quiz_num         [j].answer1,quiz_info.quiz_num[j].answer2,quiz_info.quiz_num[j].answer3,quiz_info.quiz_num[j].answer4);
j++;
}
return;
}

void question4()
{
char input[30]={"V"};
int j=0;
while (j<4)
{
    if (strcmp(quiz_info.quiz_num[j].symbol,input)==0)
    printf("\n\n %s\n A. %d\n B. %d\n C. %d\n D. %d\n\n ",quiz_info.quiz_num[j].question,quiz_info.quiz_num         [j].answer1,quiz_info.quiz_num[j].answer2,quiz_info.quiz_num[j].answer3,quiz_info.quiz_num[j].answer4);
j++;
}
return;
}


void delay1 ()
{
long b,c;
for(b=0;b<111111111;b++)
c=b;
return;
}
void delay2 ()
{
long e,f;
for(e=0;e<888888888;e++)
f=e;
return;
}

void delay3 ()
{
long e,f;
for(e=0;e<999999999;e++)
f=e;
return;
}

void delay4 ()
{
long e,f;
for(e=0;e<22222222;e++)
f=e;
return;
}

void display_score(int n)
{
int zero, three, six, nine, twelve;
switch(n){
case 0 : zero=0xC0; outb(0x08, 0x37A); outb(zero, 0x378); break;
case 3 : three=0x70; outb(0x08, 0x37A); outb(three, 0x378); break;
case 6: six=0x42; outb(0x08, 0x37A); outb(six, 0x378); break;
case 9 : nine=0x50; outb(0x08, 0x37A); outb(nine, 0x378); break;
case 12 : twelve=0x24; outb(0x08, 0x37A); outb(twelve, 0x378); break;
        }
}

void review_rules(){
        printf("\n\n");
printf("-------------This is a Quiz Master-------------\n");
        printf("-------You need to answer all 4 question-------\n");
        printf("---------Each question you got 60 second-------\n");
        printf("Move only one of the switches for selecting an answer \n");
        printf("----One mark will be given to each correct-----\n");
        printf("------------Press button to start--------------\n");
        printf("----------------Good Luck----------------------\n");
       
}

void high_score(int highscore)
{
FILE *high;
high=fopen("high_score.txt","w");
fprintf(high,"%d",highscore);
fclose(high);
}