parent
1d837fffb8
commit
ae697778f7
Binary file not shown.
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,35 @@
|
||||
#ifndef __ALL_H__
|
||||
#define __ALL_H__
|
||||
|
||||
|
||||
struct pho {
|
||||
long color;
|
||||
long x;
|
||||
long y;
|
||||
long dx;
|
||||
long dy;
|
||||
};
|
||||
struct user_timer{
|
||||
long init_jiffies;
|
||||
long jiffies;
|
||||
int type; // 1为一次闹钟
|
||||
// 0为无数次闹钟
|
||||
int pid; // 哪个进程创建的定时器
|
||||
struct user_timer * next;
|
||||
};
|
||||
struct message{
|
||||
long mid;
|
||||
long pid; //当前进程为-1
|
||||
};
|
||||
extern struct message msg_que[1024];
|
||||
extern void post_message(int type);
|
||||
|
||||
// mid取值
|
||||
#define MSG_MOUSE_LEFT_DOWN 1
|
||||
#define MSG_MOUSE_RIGHT_DOWN 2
|
||||
#define MSG_MOUSE_CENTER_DOWN 3
|
||||
#define MSG_USER_TIMER 4
|
||||
#define TYPE_USER_TIMER_INFTY 5
|
||||
#define TYPE_USER_TIMER_ONCE 6
|
||||
|
||||
#endif
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,28 @@
|
||||
#include<linux/sched.h>
|
||||
#include<asm/segment.h>
|
||||
#include<all.h>
|
||||
struct message msg_que[1024];
|
||||
unsigned int msg_que_fron = NULL, msg_que_rear = NULL;
|
||||
void post_message(int type){
|
||||
if (msg_que_rear != msg_que_fron - 1) {
|
||||
struct message msg;
|
||||
msg.mid = type;
|
||||
msg.pid = current->pid;
|
||||
msg_que[msg_que_rear] = msg;
|
||||
msg_que_rear = (msg_que_rear + 1) % 1024;
|
||||
}
|
||||
}
|
||||
int sys_get_message(struct message *msg) {
|
||||
struct message tmp;
|
||||
if(msg_que_rear == msg_que_fron){
|
||||
put_fs_long(-1,&msg->mid);
|
||||
put_fs_long(-1,&msg->pid);
|
||||
return;
|
||||
}
|
||||
|
||||
tmp = msg_que[msg_que_fron];
|
||||
msg_que[msg_que_fron].mid = 0;
|
||||
msg_que_fron = (msg_que_fron + 1) % 1024;;
|
||||
put_fs_long(tmp.mid,&msg->mid);
|
||||
put_fs_long(current->pid,&msg->pid);
|
||||
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,10 @@
|
||||
#define __LIBRARY__
|
||||
#include<unistd.h>
|
||||
#include<all.h>
|
||||
_syscall0(int,init_graphics)
|
||||
|
||||
int main(void)
|
||||
{
|
||||
init_graphics();
|
||||
}
|
||||
|
@ -1,19 +1,10 @@
|
||||
#define __LIBRARY__
|
||||
#include<unistd.h>
|
||||
#include<stdio.h>
|
||||
#include<stdlib.h>
|
||||
#include<assert.h>
|
||||
#include<all.h>
|
||||
_syscall0(int,initgraphics)
|
||||
|
||||
_syscall1(void ,get_message ,struct message ,* msg)
|
||||
|
||||
int main()
|
||||
int main(void)
|
||||
{
|
||||
struct message *msg;
|
||||
int i;
|
||||
for(i=0;i<10;i++)
|
||||
{
|
||||
get_message(msg);
|
||||
printf("mid:%d pid:%d\n",msg->mid,msg->pid);
|
||||
}
|
||||
return 0;
|
||||
initgraphics();
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,16 @@
|
||||
#define __LIBRARY__
|
||||
#include<all.h>
|
||||
#include<unistd.h>
|
||||
_syscall0(int,init_graphics);
|
||||
_syscall1(int,repaint,struct pho *,pho);
|
||||
int main(void)
|
||||
{
|
||||
struct pho my_rect;
|
||||
init_graphics();
|
||||
my_rect.color = 12;
|
||||
my_rect.x = 50;
|
||||
my_rect.y = 50;
|
||||
my_rect.dx = 10;
|
||||
my_rect.dy = 10;
|
||||
repaint(&my_rect);
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
#define __LIBRARY__
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <all.h>
|
||||
_syscall1(int,get_message,struct message *,msg);
|
||||
_syscall2(int,timercreate,long,ms,int,type);
|
||||
|
||||
struct message msg;
|
||||
|
||||
int main()
|
||||
{
|
||||
timercreate(1000,TYPE_USER_TIMER_INFTY);
|
||||
while(1)
|
||||
{
|
||||
get_message(&msg);
|
||||
/* printf("msg.mid:%d\n", msg.mid); */
|
||||
if (msg.mid > 0)
|
||||
{
|
||||
switch(msg.mid)
|
||||
{
|
||||
case MSG_USER_TIMER:
|
||||
printf("MSG_USER_TIMER\n");
|
||||
break;
|
||||
case MSG_MOUSE_LEFT_DOWN:
|
||||
printf("MSG_MOUSE_LEFT_DOWN\n");
|
||||
break;
|
||||
case MSG_MOUSE_RIGHT_DOWN:
|
||||
printf("MSG_MOUSE_RIGHT_DOWN\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
#define __LIBRARY__
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <all.h>
|
||||
_syscall1(void,get_message,struct message *,msg);
|
||||
_syscall2(int,timercreate,long,ms,int,type);
|
||||
|
||||
struct message msg;
|
||||
|
||||
int main()
|
||||
{
|
||||
timercreate(1000,TYPE_USER_TIMER_INFTY);
|
||||
while(1)
|
||||
{
|
||||
get_message(&msg);
|
||||
/* printf("msg.mid:%d\n", msg.mid); */
|
||||
if (msg.mid > 0)
|
||||
{
|
||||
switch(msg.mid)
|
||||
{
|
||||
case MSG_USER_TIMER:
|
||||
printf("MSG_USER_TIMER\n");
|
||||
break;
|
||||
case MSG_MOUSE_LEFT_DOWN:
|
||||
printf("MSG_MOUSE_LEFT_DOWN\n");
|
||||
break;
|
||||
case MSG_MOUSE_RIGHT_DOWN:
|
||||
printf("MSG_MOUSE_RIGHT_DOWN\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
#ifndef __ALL_H__
|
||||
#define __ALL_H__
|
||||
|
||||
|
||||
struct pho {
|
||||
long color;
|
||||
long x;
|
||||
long y;
|
||||
long dx;
|
||||
long dy;
|
||||
};
|
||||
struct user_timer{
|
||||
long init_jiffies;
|
||||
long jiffies;
|
||||
int type;
|
||||
|
||||
int pid;
|
||||
struct user_timer * next;
|
||||
};
|
||||
struct message{
|
||||
long mid;
|
||||
long pid;
|
||||
} message;
|
||||
extern struct message msg_que[1024];
|
||||
extern void post_message(int type);
|
||||
|
||||
|
||||
#define MSG_MOUSE_LEFT_DOWN 1
|
||||
#define MSG_MOUSE_RIGHT_DOWN 2
|
||||
#define MSG_MOUSE_CENTER_DOWN 3
|
||||
#define MSG_USER_TIMER 4
|
||||
#define TYPE_USER_TIMER_INFTY 5
|
||||
#define TYPE_USER_TIMER_ONCE 6
|
||||
|
||||
#endif
|
@ -0,0 +1,35 @@
|
||||
#ifndef __ALL_H__
|
||||
#define __ALL_H__
|
||||
|
||||
|
||||
struct pho {
|
||||
long color;
|
||||
long x;
|
||||
long y;
|
||||
long dx;
|
||||
long dy;
|
||||
};
|
||||
struct user_timer{
|
||||
long init_jiffies;
|
||||
long jiffies;
|
||||
int type; // 1为一次闹钟
|
||||
// 0为无数次闹钟
|
||||
int pid; // 哪个进程创建的定时器
|
||||
struct user_timer * next;
|
||||
};
|
||||
struct message{
|
||||
long mid;
|
||||
long pid; //当前进程为-1
|
||||
} message;
|
||||
extern struct message msg_que[1024];
|
||||
extern void post_message(int type);
|
||||
|
||||
// mid取值
|
||||
#define MSG_MOUSE_LEFT_DOWN 1
|
||||
#define MSG_MOUSE_RIGHT_DOWN 2
|
||||
#define MSG_MOUSE_CENTER_DOWN 3
|
||||
#define MSG_USER_TIMER 4
|
||||
#define TYPE_USER_TIMER_INFTY 5
|
||||
#define TYPE_USER_TIMER_ONCE 6
|
||||
|
||||
#endif
|
@ -1,100 +1,178 @@
|
||||
#define __LIBRARY__
|
||||
#include<stdio.h>
|
||||
#include<unistd.h>
|
||||
#include<stdlib.h>
|
||||
#include<errno.h>
|
||||
#include<time.h>
|
||||
#include<linux/tty.h>
|
||||
#define vga_graph_memstart 0xA0000
|
||||
#define vga_graph_memsize 64000
|
||||
#define cursor_side 6
|
||||
#define vga_width 320
|
||||
#define vga_height 200
|
||||
#include<all.h>
|
||||
|
||||
#define BIRD_X 120
|
||||
#define BIRD_Y 100
|
||||
#define BIRD_WIDTH 10
|
||||
#define BIRD_HEIGHT 8
|
||||
#define MAX 40
|
||||
|
||||
char *p;
|
||||
int i,j,x_pos,y_pos,k;
|
||||
struct message *msg;
|
||||
int cnt;
|
||||
int bird_y;
|
||||
int px[MAX];
|
||||
int py[MAX];
|
||||
int h[MAX];
|
||||
char *pp;
|
||||
int ii,jj;
|
||||
int nn;
|
||||
|
||||
#define MAX_BARRIER 20
|
||||
|
||||
#define CLOCK_TRIGGER 400
|
||||
#define DROP_PER_TRIGGER 1
|
||||
#define UP_PER_CLICK 10
|
||||
#define LEFT_PER_TRIGGER 1
|
||||
|
||||
#define BIRD_COLOR 12
|
||||
#define BARRIER_COLOR 12
|
||||
#define BACKGROUND_COLOR 3
|
||||
#define GAME_OVER_COLOR 12
|
||||
|
||||
#define VAG_WIDTH 320
|
||||
#define VGA_HEIGHT 200
|
||||
|
||||
#define BARRIER_WIDTH 10
|
||||
#define BARRIER_INTERVAL 20
|
||||
#define BARRIER_HEIGHT (rand()%(VGA_HEIGHT*3/4))
|
||||
|
||||
|
||||
_syscall0(int,init_graphics)
|
||||
_syscall1(int,get_message,struct message * ,msg)
|
||||
_syscall3(int,repaint,int ,x,int ,y,int ,h)
|
||||
_syscall1(int,repaint,struct pho *,pho)
|
||||
_syscall2(int,timercreate,long,ms,int,type)
|
||||
|
||||
int fron, rear;
|
||||
struct pho barrier[MAX_BARRIER];
|
||||
int i;
|
||||
struct message msg;
|
||||
struct pho obj;
|
||||
struct pho background0,gameover;
|
||||
struct pho bird;
|
||||
|
||||
|
||||
int init_all()
|
||||
{
|
||||
bird.x = BIRD_X;
|
||||
bird.y = BIRD_Y;
|
||||
bird.dx = BIRD_WIDTH;
|
||||
bird.dy = BIRD_HEIGHT;
|
||||
bird.color = BIRD_COLOR;
|
||||
|
||||
fron = rear = 0;
|
||||
|
||||
background0.color = BACKGROUND_COLOR;
|
||||
background0.x = 0;
|
||||
background0.y = 0;
|
||||
background0.dx = VAG_WIDTH;
|
||||
background0.dy = VGA_HEIGHT;
|
||||
|
||||
gameover.color = GAME_OVER_COLOR;
|
||||
gameover.x = 0;
|
||||
gameover.y = 0;
|
||||
gameover.dx = VAG_WIDTH;
|
||||
gameover.dy = VGA_HEIGHT;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*paint*/
|
||||
int paint_barrier(void) /*paint barrier*/
|
||||
{
|
||||
int i;
|
||||
struct pho rect;
|
||||
for (i = fron; i != rear; i = (i+1)%MAX_BARRIER) {
|
||||
rect.color = BARRIER_COLOR;
|
||||
rect.x = barrier[i].x;
|
||||
rect.y = barrier[i].y;
|
||||
rect.dx = barrier[i].dx;
|
||||
rect.dy = barrier[i].dy;
|
||||
if (repaint(&rect) < 0)
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
int paint_all()/*all*/
|
||||
{
|
||||
if (repaint(&background0) < 0)
|
||||
return -1;
|
||||
if (repaint(&bird) < 0)
|
||||
return -1;
|
||||
if (paint_barrier() < 0)
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int push_obj(struct pho * obj) {
|
||||
if (rear != (fron + MAX_BARRIER - 1) % MAX_BARRIER) {
|
||||
barrier[rear].x = obj->x;
|
||||
barrier[rear].y = obj->y;
|
||||
barrier[rear].dx = obj->dx;
|
||||
barrier[rear].dy = obj->dy;
|
||||
rear = (rear + 1) % MAX_BARRIER;
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int pop_obj(struct pho * obj) {
|
||||
if (rear == fron)
|
||||
return -1;
|
||||
if (obj != NULL) {
|
||||
obj->x = barrier[fron].x;
|
||||
obj->y = barrier[fron].y;
|
||||
obj->dx = barrier[fron].dx;
|
||||
obj->dy = barrier[fron].dy;
|
||||
}
|
||||
fron = (fron + 1) % MAX_BARRIER;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
x_pos=20;
|
||||
y_pos=20;
|
||||
bird_y=BIRD_Y;
|
||||
init_graphics();
|
||||
px[0]=BIRD_X;
|
||||
py[0]=bird_y;
|
||||
h[0]=BIRD_HEIGHT;
|
||||
cnt=30;
|
||||
for(i=1;i<cnt;i++)
|
||||
{
|
||||
if(i%2==0)
|
||||
{
|
||||
px[i]=120+20*i;
|
||||
py[i]=0;
|
||||
h[i]=90+i*2;
|
||||
}
|
||||
timercreate(CLOCK_TRIGGER, TYPE_USER_TIMER_INFTY); /* create time */
|
||||
init_graphics(); /*Graphical interface*/
|
||||
|
||||
if(init_all()!=0)/*initialize*/
|
||||
{printf("bird error 1\n");return -1;}
|
||||
while(1)
|
||||
{ //sleep(1);
|
||||
get_message(&msg);
|
||||
if(msg.mid<0)
|
||||
continue;
|
||||
if(msg.mid==MSG_MOUSE_LEFT_DOWN)
|
||||
{bird.y -= UP_PER_CLICK;}
|
||||
else
|
||||
{
|
||||
px[i]=30+20*i;
|
||||
h[i]=h[i-1]-13*i%17;
|
||||
py[i]=200-1-h[i];
|
||||
}
|
||||
}
|
||||
msg=NULL;
|
||||
nn=50;
|
||||
while(--nn)
|
||||
{
|
||||
repaint(px[0],py[0],h[0]);
|
||||
for(i=1;i<cnt;i++)
|
||||
{
|
||||
px[i]-=20;
|
||||
repaint(px[i],py[i],h[i]);
|
||||
}
|
||||
k=3;
|
||||
while(k>0)
|
||||
{
|
||||
--k;
|
||||
get_message(msg);
|
||||
if(msg!=NULL)py[0]-=10;
|
||||
sleep(2);
|
||||
}
|
||||
sleep(4);
|
||||
for(k=1;k<cnt;k++)
|
||||
{
|
||||
if(k%2==0)
|
||||
if(px[0]+6>px[k] && px[0]+6<px[k]+10 && py[0]<h[k])
|
||||
{
|
||||
repaint(44,44,44);
|
||||
return 0;
|
||||
}else{
|
||||
if(px[0]+6>px[k] && px[0]+6<px[k]+10 && py[0]+6+h[k]>199)
|
||||
{
|
||||
repaint(44,44,44);
|
||||
return 0;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
{bird.y += DROP_PER_TRIGGER;}
|
||||
if(paint_all() != 0)
|
||||
{printf("bird error 2\n");return -1;}
|
||||
for (i = fron; i != rear; i = (i+1)%MAX_BARRIER) /*Determine if the game has failed*/
|
||||
if (barrier[i].x < bird.x+bird.dx && bird.x < barrier[i].x+barrier[i].dx)
|
||||
if (barrier[i].y < bird.y+bird.dy && bird.y < barrier[i].y+barrier[i].dy)
|
||||
{
|
||||
repaint(&gameover);
|
||||
return 0;
|
||||
}
|
||||
for (i = fron; i != rear; i = (i+1)%MAX_BARRIER) /* bird is stationary ,need barriers move*/
|
||||
barrier[i].x -= LEFT_PER_TRIGGER;
|
||||
if (fron == rear) /* there is no barriers,add barriers */
|
||||
{
|
||||
obj.dx = BARRIER_WIDTH;
|
||||
obj.dy = BARRIER_HEIGHT;
|
||||
obj.x = VAG_WIDTH;
|
||||
obj.y = 0;
|
||||
push_obj(&obj);
|
||||
}
|
||||
else /* add new barriers,delete old barriers */
|
||||
{
|
||||
if (barrier[(rear+MAX_BARRIER-1)%MAX_BARRIER].x+barrier[(rear+MAX_BARRIER-1)%MAX_BARRIER].dx+BARRIER_INTERVAL <= VAG_WIDTH) {
|
||||
obj.dx = BARRIER_WIDTH;
|
||||
obj.dy = BARRIER_HEIGHT;
|
||||
obj.x = VAG_WIDTH;
|
||||
if (barrier[(rear+MAX_BARRIER-1)%MAX_BARRIER].y)
|
||||
obj.y = 0;
|
||||
else
|
||||
obj.y = VGA_HEIGHT - obj.dy;
|
||||
push_obj(&obj);
|
||||
}
|
||||
if (barrier[fron].x+barrier[fron].dx <= 0)
|
||||
pop_obj(NULL);
|
||||
}
|
||||
}
|
||||
repaint(44,44,44);
|
||||
repaint(&gameover);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Binary file not shown.
@ -1,19 +0,0 @@
|
||||
#define __LIBRARY__
|
||||
#include<unistd.h>
|
||||
#include<stdio.h>
|
||||
#include<stdlib.h>
|
||||
#include<assert.h>
|
||||
|
||||
_syscall1(void ,get_message ,struct message ,* msg)
|
||||
|
||||
int main()
|
||||
{
|
||||
struct message *msg;
|
||||
int i;
|
||||
for(i=0;i<10;i++)
|
||||
{
|
||||
get_message(msg);
|
||||
printf("mid:%d pid:%d\n",msg->mid,msg->pid);
|
||||
}
|
||||
return 0;
|
||||
}
|
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue