当前位置:首页 » 操作系统 » desc源码

desc源码

发布时间: 2022-12-19 06:06:58

❶ 谁能帮我看看这些源码

请尝试VC++

❷ windows 进程管理源代码详解,要详细的,

Windows 是闭源开发的商业软件,受商业版权法保护,别说大家都没有,就算有也不能给你的(被微软起诉那可不是小事)。

linux的是开源的,干嘛不去读Linux源码呢?

新版本的太长,写不开,给你最经典的0.11版的进程管理源码。其他的你自己去查。作为一个好的程序员,必须学会充分利用搜索引擎。

---------------------------------------

linux0.11通过一个进程数组管理进程,最大允许64个进程存在。进程的状态有就绪态,运行态,暂停态,睡眠态和僵死态等。睡眠态又可分为可中断和不可中断两种。对于进程的管理,我觉得按照进程的状态来讲会清晰一些。
1.0号任务
0号比较特殊,是"纯手工制作",下面就是制作过程
mem_init(main_memory_start,memory_end);
trap_init();
blk_dev_init();
char_dev_init();
tty_init();
time_init();
sched_init();
buffer_init(buffer_memory_end);
hd_init();
floppy_init();
sti();
move_to_user_mode();
这么多init当然不全是为0任务准备的,他们是初始化系统。对任务0来说,重要的是sched_init()和move_to_user_mode()两个。sched_init()中手动设置了任务0的任务段描述符tss和局部段描述符ldt,并设置了tr和ldtr寄存器:
set_tss_desc(gdt+FIRST_TSS_ENTRY,&(init_task.task.tss)); //设置tss段描述符
set_ldt_desc(gdt+FIRST_LDT_ENTRY,&(init_task.task.ldt));//设置ldt描述符
...
ltr(0); //加载tss描述符地址到tr
lldt(0); //加载ldt描述符地址到ldtr

我们来看一下任务0的tss和ldt是什么样子
/*ldt*/ {0,0},\
{0x9f,0xc0fa00},\
{0x9f,0xc0f200},\
/*tss*/{0,PAGE_SIZE+(long)&init_task,0x10,0,0,0,0,(long)&pg_dir,\
0,0,0,0,0,0,0,0,\
0,0,0x17,0x17,0x17,0x17,0x17,0x17,\
_LDT(0),0X80000000,\
{}\
},\
从ldt 可以看到,任务的代码和数据段均为640k,基址为0,DPL=3。这说明虽然任务0的代码还是处在内核段内,但是任务的级别已经是用户态了。从tss也可以看到这一点,代码和数据都被置为0x17,也就是局部段描述符表第2项。还可以看到任务0的内核太堆栈被设置在init_task之后的一页处,用户态堆栈就是move_to_user_mode之前的内核态堆栈。这和普通进程不一样,普通进程的用户态堆栈在其64Mb地址空间的末端。
move_to_user_mode是在堆栈中创建一个任务切换的假象,用iret跳转到外层3,这样cpu就会自动根据tr加载tss,并初始化各个寄存器运行任务0。所以,任务0其实就是内核空间中的用户态任务。
2.进程的创建
进程创建是由系统调用sys_fork完成的,主要使用了两个函数find_empty_process和_process。前者在进程在进程数组中找一个不用的进程号给子进程,后者完成子进程信息的创建,主要是复制父进程的信息。
我们来看一下_process的代码:
int _process(int nr,long ebp,long edi,long esi,long gs,long none,
long ebx,long ecx,long edx,long fs,long es,long ds,
long eip,long cs,long eflags,long esp,long ss)
{
struct task_struct *p;
int i;
struct file *f;
//首先为子进程的进程描述符分配一块内存
p=(struct task_struct *)get_free_page();
if(!p)
return -EAGAIN;
//将新任务结构指针加入数组中
task[nr]=p;
//复制当前用户的任务结构到子进程中。当然堆栈不复制
*p=*current;
//将子进程的状态设为不可中断等待,防止现在被调度
p->state=TASK_UNINTERRUPTIBLE;
P->pid=last_pid;
p->father=current->pid;
p->count=p->priority;
p->signal=0;
p->alarm=0;
p->leader=0;
p->utime=p->stime=0;
p->cutime=p->cstime=0;
p->start_time=jiffies;
p->tss.back_link=0;
//新进程的内核态堆栈在进程描述符页末端
p->tss.esp0=PAGE_SIZE+(long)p;
P->tss.ss0=0x10;
//ip为父进程调用fork的下一条指令
p->tss.eip=eip;
//fork的返回值对子进程来说是0,对父进程来说是它的pid,通过这个区别,在fork调用返回后,父子进程的代码段便被分割来,
p->tss.eax=0;
//虽然他们是在一个代码文件中写的
p->tss.ecx=ecx;
p->tss.edx=edx;
p->tss.ebx=ebx;
p->tss.esp=esp;
p->tss.ebp=ebp;
p->tss.esi=esi;
p->tss.edi=edi;
p->tss.es=es&0xffff;
p->tss.cs=cs&0xffff;
p->tss.ss=ss&0xffff;
p->tss.ds=ds&0xffff;
p->tss.fs=fs&0xffff;
p->tss.gs=gs&0xffff;
p->tss.ldt=_LDT(nr);
p->tss.trace_bitmap=0x80000000;
//如果父任务使用了协处理器,还要保存到tss中
if(last_task_used_math==current)
_asm("clts;fnsave %0"::"m"(p->tss.i387));
//为新任务设置新的代码和数据段基地址。注意,因为linux0.11只支持64M的进程空间,所以进程的线性地址空间在64M的边界处。
//然后为新任务复制父进程的页表。通过_page_tales,父子任务此时共用一个只读的代码数据段。在写操作时,写时复制会为新进程申请新的物理页面。
if(_mem(nr,p)){
task[nr]=NULL;
free_page((long)p);
return -EAGAIN;
}
for(i=0;i<NR_OPEN;i++)
if(f=p->filp)
f->f_count++;
if(current->pwd)
current->pwd->i_count++;
if(current->root)
current->root->i_count++;
if(current->executable)
current->executable->i_count++;
//设置新任务的tss和ldt描述符
set_tss_desc(gdt+(nr<<1)+FIRST_TSS_ENTRY,&(p->tss));
set_ldt_desc(gdt+(nr<<1)+FIRST_LDT_ENTRY,&(p->ldt));
//返回子进程的pid
return last_pid;
}
参数都是堆栈中的值,nr是调用_process之前的find_empty_process的返回值,作为任务数组的序号。
3.进程的调度
进程创建之后并不是立即执行。系统会在适当的时刻调用系统调度函数schele,它会选择适当的进程运行。调度函数可能在系统调用结束之后,进程暂停/ 睡眠/退出,时钟中断等多个地方调用。调度函数主要是通过进程的时间片来选择一个运行时间最短的进程运行。如果没有找到就运行空闲pause系统调用,在 Pause中,调度函数又会被调用。下面是主要代码
while(1){
c=-1;
next=0;
i=NR_TASKS;
p=&task[NR_TASKS];
//寻找就绪任务中运行时间最短的任务
while(--i){
if(!(*--p))
continue;
if((*p)->state==TASK_RUNNING&&(*p)->counter>c)
c=(*p)->counter,next=i;
}
//如果找到,就退出。否则重新计算任务的时间片。注意,如果没有任务,next始终为0,结果就被切换到任务0
if(c)break;
for(p=&LAST_TASK;p>&FIRST_TASK;--p)
if(*p)
(*p)->counter=((*p)->counter>>1)+(*)->priority;
}
switch_to(next);//通过长跳转,转换任务到新任务。
}
时钟中断是执行调度的重要措施,正是由于不断的执行调度,系统才能在多个任务之间进行切换,完成多任务操作系统的目标。在调度器初始化时,除了手动设置了任务0,还对8253开启了定时器中断,对系统"点火".中断中调用了do_timer函数。现在这是个很短的函数:
void do_timer(long cpl)
{
...
//根据优先级调整进程运行时间
if(cpl)
current->utime++;
else
current->stime++;
//处理定时器中断队列
if(next_timer){
next_timer->jiffies--;
while(next_timer&&next_timer->jiffies<=0){
void(*fn)(void);
fn=next_timer->fn;
next_timer->fn=NULL;
next_timer=next_timer->next;
(fn)();
}
}
..
//对进程时间片减1。如果大于0 ,表示时间片还没有用完,继续
if((--current->counter>0)return;
//注意,内核态任务是不可抢占的,在0.11中,除非内核任务主动放弃处理器,它将一直运行。
if(!cpl)return;
//调度
schele();
}
4.进程的终止
进程可以自己中止,也可以被中止信号中止。do_exit执行退出。如果它有子进程的话,子进程就会成为孤儿进程,这里会将它的孩子托付给进程1(即init进程)管理。在成为僵死进程之后,还要通知父进程,因为他的父进程可能在等它呢。

java源代码分析 实在是不太会,求高手教教我。

packagetest2;

importjava.io.BufferedReader;
importjava.io.File;
importjava.io.FileInputStream;
importjava.io.FileOutputStream;
importjava.io.IOException;
importjava.io.InputStream;
importjava.io.InputStreamReader;
importjava.util.HashMap;
importjava.util.Map;
importjava.util.Set;

publicclassJavaCodeAnalyzer{
publicstaticvoidanalyze(Filefile)throwsIOException{
//FileOutputStreamfos=newFileOutputStream("F;"+File.separator+"result.txt");
if(!(file.getName().endsWith(".txt")||file.getName().endsWith(".java"))){
System.out.println("输入的分析文件格式不对!");
}
InputStreamis=newFileInputStream(file);
BufferedReaderbr=newBufferedReader(newInputStreamReader(is));
Stringtemp;
intcount=0;
intcountSpace=0;
intcountCode=0;
intcountDesc=0;
Map<String,Integer>map=getKeyWords();
while((temp=br.readLine())!=null){
countKeys(temp,map);
count++;
if(temp.trim().equals("")){
countSpace++;
}elseif(temp.trim().startsWith("/*")||temp.trim().startsWith("//")){
countDesc++;
}else{
countCode++;
}
}
System.out.printf("代码行数:"+countCode+"占总行数的%4.2f ",(double)countCode/count);
System.out.printf("空行数:"+countSpace+"占总行数的%4.2f ",(double)countSpace/count);
System.out.printf("注释行数:"+countDesc+"占总行数的%4.2f ",(double)countDesc/count);
System.out.println("总行数:"+count);
System.out.println("出现最多的5个关键字是:");
System.out.println("");
System.out.println("");
System.out.println("");
System.out.println("");
System.out.println("");
}
publicstaticvoidmain(String[]args){
getKeyWords();
Filefile=newFile("F://Test.java");
try{
analyze(file);
}catch(IOExceptione){
//TODO自动生成catch块
e.printStackTrace();
}
}
publicstaticMap<String,Integer>getKeyWords(){
Map<String,Integer>map=newHashMap<String,Integer>();
String[]keywords={"abstract","assert","boolean","break","byte","case","catch","char","class","continue","default","do","double","else","enum","extends","final","finally","float","for","if","implements","import","instanceof","int","interface","long","native","new","package","private","protected","public","return","strictfp","short","static","super","switch","synchronized","this","throw","throws","transient","try","void","volatile","while","goto","const"};
for(Strings:keywords){
map.put(s,0);
}
returnmap;
}
publicstaticvoidcountKeys(Strings,Map<String,Integer>map){
Set<String>keys=map.keySet();
for(Stringss:keys){
if(s.indexOf(ss)!=-1){
map.put(ss,map.get(ss)+1);
}
}
}
}

上班没啥时间了,还有点没写完,你在想想。

❹ vb如何连接sql数据库,求源码

Public My_Cnn As New ADODB.Connection '连接数据库
StrCnn = "Provider=SQLOLEDB.1;Password=密码;Persist Security Info=True;User ID=用户名;Initial Catalog=数据库名;Data Source=服务器名"
My_Cnn.CursorLocation = adUseClient
My_Cnn.Open StrCnn

使用数据库
Dim sql As String
Dim My_temp As New ADODB.Recordset

执行SQL语句(一般插入,删除数据)
sql = "数据库语句"
My_cnn.Execute sql

读取数据
sql = "查询语句"
My_temp.Open sql, My_cnn, adOpenDynamic, adLockOptimistic

My_temp.field("字段名")

❺ number-precision 实现js高精度运算 源码

type numType = number | string;

/**

* @desc 解决浮动运算问题,避免小数点后产生多位数和计算精度损失。

* 问题示例:2.3 + 2.4 = 4.699999999999999,1.0 - 0.9 = 0.09999999999999998

*/

/**

* 把错误的数据转正

* strip(0.09999999999999998)=0.1

*/

function strip(num: numType, precision = 15): number {

  return +parseFloat(Number(num).toPrecision(precision));

}

/**

* Return digits length of a number

* @param {*number} num Input number

*/

function digitLength(num: numType): number {

  // Get digit length of e

  const eSplit = num.toString().split(/[eE]/);

  const len = (eSplit[0].split('.')[1] || '').length - +(eSplit[1] || 0);

  return len > 0 ? len : 0;

}

/**

* 把小数转成整数,支持科学计数法。如果是小数则放大成整数

* @param {*number} num 输入数

*/

function float2Fixed(num: numType): number {

  if (num.toString().indexOf('e') === -1) {

    return Number(num.toString().replace('.', ''));

  }

  const dLen = digitLength(num);

  return dLen > 0 ? strip(Number(num) * Math.pow(10, dLen)) : Number(num);

}

/**

* 检测数字是否越界,如果越界给出提示

* @param {*number} num 输入数

*/

function checkBoundary(num: number) {

  if (_boundaryCheckingState) {

    if (num > Number.MAX_SAFE_INTEGER || num < Number.MIN_SAFE_INTEGER) {

      console.warn(`${num} is beyond boundary when transfer to integer, the results may not be accurate`);

    }

  }

}

/**

* 精确乘法

*/

function times(num1: numType, num2: numType, ...others: numType[]): number {

  if (others.length > 0) {

    return times(times(num1, num2), others[0], ...others.slice(1));

  }

  const num1Changed = float2Fixed(num1);

  const num2Changed = float2Fixed(num2);

  const baseNum = digitLength(num1) + digitLength(num2);

  const leftValue = num1Changed * num2Changed;

  checkBoundary(leftValue);

  return leftValue / Math.pow(10, baseNum);

}

/**

* 精确加法

*/

function plus(num1: numType, num2: numType, ...others: numType[]): number {

  if (others.length > 0) {

    return plus(plus(num1, num2), others[0], ...others.slice(1));

  }

  const baseNum = Math.pow(10, Math.max(digitLength(num1), digitLength(num2)));

  return (times(num1, baseNum) + times(num2, baseNum)) / baseNum;

}

/**

* 精确减法

*/

function minus(num1: numType, num2: numType, ...others: numType[]): number {

  if (others.length > 0) {

    return minus(minus(num1, num2), others[0], ...others.slice(1));

  }

  const baseNum = Math.pow(10, Math.max(digitLength(num1), digitLength(num2)));

  return (times(num1, baseNum) - times(num2, baseNum)) / baseNum;

}

/**

* 精确除法

*/

function divide(num1: numType, num2: numType, ...others: numType[]): number {

  if (others.length > 0) {

    return divide(divide(num1, num2), others[0], ...others.slice(1));

  }

  const num1Changed = float2Fixed(num1);

  const num2Changed = float2Fixed(num2);

  checkBoundary(num1Changed);

  checkBoundary(num2Changed);

  // fix: 类似 10 ** -4 为 0.00009999999999999999,strip 修正

  return times(num1Changed / num2Changed, strip(Math.pow(10, digitLength(num2) - digitLength(num1))));

}

/**

* 四舍五入

*/

function round(num: numType, ratio: number): number {

  const base = Math.pow(10, ratio);

  return divide(Math.round(times(num, base)), base);

}

let _boundaryCheckingState = true;

/**

* 是否进行边界检查,默认开启

* @param flag 标记开关,true 为开启,false 为关闭,默认为 true

*/

// 这里可以设置边界检查(默认是true)

function enableBoundaryChecking(flag = true) {

  _boundaryCheckingState = flag;

}

// 输出上面的方法

export { strip, plus, minus, times, divide, round, digitLength, float2Fixed, enableBoundaryChecking };

export default {

  strip,

  plus,

  minus,

  times,

  divide,

  round,

  digitLength,

  float2Fixed,

  enableBoundaryChecking,

};

❻ 俄罗斯方块的c语言源代码 api实现

TC下面的

/************************************
* Desc: 俄罗斯方块游戏
* By: hoodlum1980
* Email: [email protected]
* Date: 2008.03.12 22:30
************************************/
#include <stdio.h>
#include <bios.h>
#include <dos.h>
#include <graphics.h>
#include <string.h>
#include <stdlib.h>
#define true 1
#define false 0
#define BoardWidth 12
#define BoardHeight 23
#define _INNER_HELPER /*inner helper method */
/*Scan Codes Define*/
enum KEYCODES
{
K_ESC =0x011b,
K_UP =0x4800, /* upward arrow */
K_LEFT =0x4b00,
K_DOWN =0x5000,
K_RIGHT =0x4d00,
K_SPACE =0x3920,
K_P =0x1970
};

/* the data structure of the block */
typedef struct tagBlock
{
char c[4][4]; /* cell fill info array, 0-empty, 1-filled */
int x; /* block position cx [ 0,BoardWidht -1] */
int y; /* block position cy [-4,BoardHeight-1] */
char color; /* block color */
char size; /* block max size in width or height */
char name; /* block name (the block's shape) */
} Block;

/* game's global info */
int FrameTime= 1300;
int CellSize= 18;
int BoardLeft= 30;
int BoardTop= 30;

/* next block grid */
int NBBoardLeft= 300;
int NBBoardTop= 30;
int NBCellSize= 10;

/* score board position */
int ScoreBoardLeft= 300;
int ScoreBoardTop=100;
int ScoreBoardWidth=200;
int ScoreBoardHeight=35;
int ScoreColor=LIGHTCYAN;

/* infor text postion */
int InfoLeft=300;
int InfoTop=200;
int InfoColor=YELLOW;

int BorderColor=DARKGRAY;
int BkGndColor=BLACK;
int GameRunning=true;
int TopLine=BoardHeight-1; /* top empty line */
int TotalScore=100;
char info_score[20];
char info_help[255];
char info_common[255];

/* our board, Board[x][y][0]-isFilled, Board[x][y][1]-fillColor */
unsigned char Board[BoardWidth][BoardHeight][2];
char BufferCells[4][4]; /* used to judge if can rotate block */
Block curBlock; /* current moving block */
Block nextBlock; /* next Block to appear */

/* function list */
int GetKeyCode();
int CanMove(int dx,int dy);
int CanRotate();
int RotateBlock(Block *block);
int MoveBlock(Block *block,int dx,int dy);
void DrawBlock(Block *block,int,int,int);
void EraseBlock(Block *block,int,int,int);
void DisplayScore();
void DisplayInfo(char* text);
void GenerateBlock(Block *block);
void NextBlock();
void InitGame();
int PauseGame();
void QuitGame();

/*Get Key Code */
int _INNER_HELPER GetKeyCode()
{
int key=0;
if(bioskey(1))
{
key=bioskey(0);
}
return key;
}

/* display text! */
void _INNER_HELPER DisplayInfo(char *text)
{
setcolor(BkGndColor);
outtextxy(InfoLeft,InfoTop,info_common);
strcpy(info_common,text);
setcolor(InfoColor);
outtextxy(InfoLeft,InfoTop,info_common);
}

/* create a new block by key number,
* the block anchor to the top-left corner of 4*4 cells
*/
void _INNER_HELPER GenerateBlock(Block *block)
{
int key=(random(13)*random(17)+random(1000)+random(3000))%7;
block->size=3;/* because most blocks' size=3 */
memset(block->c,0,16);
switch(key)
{
case 0:
block->name='T';
block->color=RED;
block->c[1][0]=1;
block->c[1][1]=1, block->c[2][1]=1;
block->c[1][2]=1;
break;
case 1:
block->name='L';
block->color=YELLOW;
block->c[1][0]=1;
block->c[1][1]=1;
block->c[1][2]=1, block->c[2][2]=1;
break;
case 2:
block->name='J';
block->color=LIGHTGRAY;
block->c[1][0]=1;
block->c[1][1]=1;
block->c[1][2]=1, block->c[0][2]=1;
break;
case 3:
block->name='z';
block->color=CYAN;
block->c[0][0]=1, block->c[1][0]=1;
block->c[1][1]=1, block->c[2][1]=1;
break;
case 4:
block->name='5';
block->color=LIGHTBLUE;
block->c[1][0]=1, block->c[2][0]=1;
block->c[0][1]=1, block->c[1][1]=1;
break;
case 5:
block->name='o';
block->color=BLUE;
block->size=2;
block->c[0][0]=1, block->c[1][0]=1;
block->c[0][1]=1, block->c[1][1]=1;
break;
case 6:
block->name='I';
block->color=GREEN;
block->size=4;
block->c[1][0]=1;
block->c[1][1]=1;
block->c[1][2]=1;
block->c[1][3]=1;
break;
}
}

/* get next block! */
void NextBlock()
{
/* the nextBlock to curBlock */
curBlock.size=nextBlock.size;
curBlock.color=nextBlock.color;
curBlock.x=(BoardWidth-4)/2;
curBlock.y=-curBlock.size;
memcpy(curBlock.c,nextBlock.c,16);
/* generate nextBlock and show it */
EraseBlock(&nextBlock,NBBoardLeft,NBBoardTop,NBCellSize);
GenerateBlock(&nextBlock);
nextBlock.x=1,nextBlock.y=0;
DrawBlock(&nextBlock,NBBoardLeft,NBBoardTop,NBCellSize);
}

/* rotate the block, update the block struct data */
int _INNER_HELPER RotateCells(char c[4][4],char blockSize)
{
char temp,i,j;
switch(blockSize)
{
case 3:
temp=c[0][0];
c[0][0]=c[2][0], c[2][0]=c[2][2], c[2][2]=c[0][2], c[0][2]=temp;
temp=c[0][1];
c[0][1]=c[1][0], c[1][0]=c[2][1], c[2][1]=c[1][2], c[1][2]=temp;
break;
case 4: /* only 'I' block arived here! */
c[1][0]=1-c[1][0], c[1][2]=1-c[1][2], c[1][3]=1-c[1][3];
c[0][1]=1-c[0][1], c[2][1]=1-c[2][1], c[3][1]=1-c[3][1];
break;
}
}

/* judge if the block can move toward the direction */
int CanMove(int dx,int dy)
{
int i,j,tempX,tempY;
for(i=0;i<curBlock.size;i++)
{
for(j=0;j<curBlock.size;j++)
{
if(curBlock.c[i][j])
{
/* cannot move leftward or rightward */
tempX = curBlock.x + i + dx;
if(tempX<0 || tempX>(BoardWidth-1)) return false; /* make sure x is valid! */
/* cannot move downward */
tempY = curBlock.y + j + dy;
if(tempY>(BoardHeight-1)) return false; /* y is only checked lower bound, maybe negative!!!! */
/* the cell already filled, we must check Y's upper bound before check cell ! */
if(tempY>=0 && Board[tempX][tempY][0]) return false;
}
}
}
return true;
}

/* judge if the block can rotate */
int CanRotate()
{
int i,j,tempX,tempY;
/* update buffer */
memcpy(BufferCells, curBlock.c, 16);
RotateCells(BufferCells,curBlock.size);
for(i=0;i<curBlock.size;i++)
{
for(j=0;j<curBlock.size;j++)
{
if(BufferCells[i][j])
{
tempX=curBlock.x+i;
tempY=curBlock.y+j;
if(tempX<0 || tempX>(BoardWidth-1))
return false;
if(tempY>(BoardHeight-1))
return false;
if(tempY>=0 && Board[tempX][tempY][0])
return false;
}
}
}
return true;
}

/* draw the block */
void _INNER_HELPER DrawBlock(Block *block,int bdLeft,int bdTop,int cellSize)
{
int i,j;
setfillstyle(SOLID_FILL,block->color);
for(i=0;i<block->size;i++)
{
for(j=0;j<block->size;j++)
{
if(block->c[i][j] && (block->y+j)>=0)
{
floodfill(
bdLeft+cellSize*(i+block->x)+cellSize/2,
bdTop+cellSize*(j+block->y)+cellSize/2,
BorderColor);
}
}
}
}

/* Rotate the block, if success, return true */
int RotateBlock(Block *block)
{
char temp,i,j;
int b_success;
if(block->size==2)
return true;
if(( b_success=CanRotate()))
{
EraseBlock(block,BoardLeft,BoardTop,CellSize);
memcpy(curBlock.c,BufferCells,16);
DrawBlock(block,BoardLeft,BoardTop,CellSize);
}
return b_success;
}

/* erase a block, only fill the filled cell with background color */
void _INNER_HELPER EraseBlock(Block *block,int bdLeft,int bdTop,int cellSize)
{
int i,j;
setfillstyle(SOLID_FILL,BkGndColor);
for(i=0;i<block->size;i++)
{
for(j=0;j<block->size;j++)
{
if(block->c[i][j] && (block->y+j>=0))
{
floodfill(
bdLeft+cellSize*(i+block->x)+cellSize/2,
bdTop+cellSize*(j+block->y)+cellSize/2,
BorderColor);
}
}
}
}

/* move by the direction if can, donothing if cannot
* return value: true - success, false - cannot move toward this direction
*/
int MoveBlock(Block *block,int dx,int dy)
{
int b_canmove=CanMove(dx,dy);
if(b_canmove)
{
EraseBlock(block,BoardLeft,BoardTop,CellSize);
curBlock.x+=dx;
curBlock.y+=dy;
DrawBlock(block,BoardLeft,BoardTop,CellSize);
}
return b_canmove;
}

/* drop the block to the bottom! */
int DropBlock(Block *block)
{
EraseBlock(block,BoardLeft,BoardTop,CellSize);
while(CanMove(0,1))
{
curBlock.y++;
}
DrawBlock(block,BoardLeft,BoardTop,CellSize);
return 0;/* return value is assign to the block's alive */
}

/* init the graphics mode, draw the board grid */
void InitGame()
{
int i,j,gdriver=DETECT,gmode;
struct time sysTime;
/* draw board cells */
memset(Board,0,BoardWidth*BoardHeight*2);
memset(nextBlock.c,0,16);
strcpy(info_help,"P: Pause Game. --by hoodlum1980");
initgraph(&gdriver,&gmode,"");
setcolor(BorderColor);
for(i=0;i<=BoardWidth;i++)
{
line(BoardLeft+i*CellSize, BoardTop, BoardLeft+i*CellSize, BoardTop+ BoardHeight*CellSize);
}
for(i=0;i<=BoardHeight;i++)
{
line(BoardLeft, BoardTop+i*CellSize, BoardLeft+BoardWidth*CellSize, BoardTop+ i*CellSize);
}
/* draw board outer border rect */
rectangle(BoardLeft-CellSize/4, BoardTop-CellSize/4,
BoardLeft+BoardWidth*CellSize+CellSize/4,
BoardTop+BoardHeight*CellSize+CellSize/4);

/* draw next block grids */
for(i=0;i<=4;i++)
{
line(NBBoardLeft+i*NBCellSize, NBBoardTop, NBBoardLeft+i*NBCellSize, NBBoardTop+4*NBCellSize);
line(NBBoardLeft, NBBoardTop+i*NBCellSize, NBBoardLeft+4*NBCellSize, NBBoardTop+ i*NBCellSize);
}

/* draw score rect */
rectangle(ScoreBoardLeft,ScoreBoardTop,ScoreBoardLeft+ScoreBoardWidth,ScoreBoardTop+ScoreBoardHeight);
DisplayScore();

/* set new seed! */
gettime(&sysTime);
srand(sysTime.ti_hour*3600+sysTime.ti_min*60+sysTime.ti_sec);

GenerateBlock(&nextBlock);
NextBlock(); /* create first block */
setcolor(DARKGRAY);
outtextxy(InfoLeft,InfoTop+20,"Up -rotate Space-drop");
outtextxy(InfoLeft,InfoTop+35,"Left-left Right-right");
outtextxy(InfoLeft,InfoTop+50,"Esc -exit");
DisplayInfo(info_help);
}

/* set the isFilled and fillcolor data to the board */
void _INNER_HELPER FillBoardData()
{
int i,j;
for(i=0;i<curBlock.size;i++)
{
for(j=0;j<curBlock.size;j++)
{
if(curBlock.c[i][j] && (curBlock.y+j)>=0)
{
Board[curBlock.x+i][curBlock.y+j][0]=1;
Board[curBlock.x+i][curBlock.y+j][1]=curBlock.color;
}
}
}
}

/* draw one line of the board */
void _INNER_HELPER PaintBoard()
{
int i,j,fillcolor;
for(j=max((TopLine-4),0);j<BoardHeight;j++)
{
for(i=0;i<BoardWidth;i++)
{
fillcolor=Board[i][j][0]? Board[i][j][1]:BkGndColor;
setfillstyle(SOLID_FILL,fillcolor);
floodfill(BoardLeft+i*CellSize+CellSize/2,BoardTop+j*CellSize+CellSize/2,BorderColor);
}
}
}

/* check if one line if filled full and increase the totalScore! */
void _INNER_HELPER CheckBoard()
{
int i,j,k,score=10,sum=0,topy,lines=0;
/* we find the top empty line! */
j=topy=BoardHeight-1;
do
{
sum=0;
for(i=0;i< BoardWidth; i++)
{
sum+=Board[i][topy][0];
}
topy--;
} while(sum>0 && topy>0);

/* remove the full filled line (max remove lines count = 4) */
do
{
sum=0;
for(i=0;i< BoardWidth; i++)
sum+=Board[i][j][0];

if(sum==BoardWidth)/* we find this line is full filled, remove it! */
{
/* move the cells data down one line */
for(k=j; k > topy;k--)
{
for(i=0;i<BoardWidth;i++)
{
Board[i][k][0]=Board[i][k-1][0];
Board[i][k][1]=Board[i][k-1][1];
}
}
/*make the top line empty! */
for(i=0;i<BoardWidth;i++)
{
Board[i][topy][0]=0;
Board[i][topy][1]=0;
}
topy++; /* move the topline downward one line! */
lines++; /* lines <=4 */
TotalScore+=score;
score*=2; /* adding: 10, 30, 70, 150 */
}
else
j--;
} while(sum>0 && j>topy && lines<4);
/* speed up the game when score is high, minimum is 400 */
FrameTime=max(1200-100*(TotalScore/200), 400);
TopLine=topy;/* update the top line */
/* if no lines remove, only add 1: */
if(lines==0)
TotalScore++;
}

/* display the score */
void _INNER_HELPER DisplayScore()
{
setcolor(BkGndColor);
outtextxy(ScoreBoardLeft+5,ScoreBoardTop+5,info_score);
setcolor(ScoreColor);
sprintf(info_score,"Score: %d",TotalScore);
outtextxy(ScoreBoardLeft+5,ScoreBoardTop+5,info_score);
}

/* we call this function when a block is inactive. */
void UpdateBoard()
{
FillBoardData();
CheckBoard();
PaintBoard();
DisplayScore();
}

/* pause the game, and timer handler stop move down the block! */
int PauseGame()
{
int key=0;
DisplayInfo("Press P to Start or Resume!");
while(key!=K_P && key!=K_ESC)
{
while(!(key=GetKeyCode())){}
}
DisplayInfo(info_help);
return key;
}

/* quit the game and do cleaning work. */
void QuitGame()
{
closegraph();
}

/* the entry point function. */
void main()
{
int i,flag=1,j,key=0,tick=0;
InitGame();
if(PauseGame()==K_ESC)
goto GameOver;
/* wait until a key pressed */
while(key!=K_ESC)
{
/* wait until a key pressed */
while(!(key=GetKeyCode()))
{
tick++;
if(tick>=FrameTime)
{
/* our block has dead! (can't move down), we get next block */
if(!MoveBlock(&curBlock,0,1))
{
UpdateBoard();
NextBlock();
if(!CanMove(0,1))
goto GameOver;
}
tick=0;
}
delay(100);
}
switch(key)
{
case K_LEFT:
MoveBlock(&curBlock,-1,0);
break;
case K_RIGHT:
MoveBlock(&curBlock,1,0);
break;
case K_DOWN:
MoveBlock(&curBlock,0,1);
break;
case K_UP:
RotateBlock(&curBlock);
break;
case K_SPACE:
DropBlock(&curBlock);
break;
case K_P:
PauseGame();
break;
}
}
GameOver:
DisplayInfo("GAME OVER! Press any key to exit!");
getch(); /* wait the user Press any key. */
QuitGame();
}

❼ 如何自定义电脑开机动画

、第三屏:开机动画

这个阶段就是大家能看到的系统启动过程中,显示完"A N D R O I D"字样后显示的图片,类似进度条一样,图片内容也是“A N D R O I D”字样。这里怎么修改呢?其实这个部分的动画是使用两个图片显示出来的,具体的图片文件所在路径为:frameworks/base/core/res/assets/images,大家看一下就知道了,也就知道怎么修改了。但是还没完。和这部分相关的源码文件主要是如下几个:frameworks/base/cmds/bootanimation下面的几个文件就是的了,可以看看BootAnimation.cpp文件的内容,有如下代码片段:
bool BootAnimation::android()
{
initTexture(&mAndroid[0], mAssets, "images/android-logo-mask.png");
initTexture(&mAndroid[1], mAssets, "images/android-logo-shine.png");
}
这就是设置显示的前景图片和背景图片。接着看还有如下代码:
#define USER_BOOTANIMATION_FILE "/data/local/bootanimation.zip"
#define SYSTEM_BOOTANIMATION_FILE "/system/media/bootanimation.zip"
#define SYSTEM_ENCRYPTED_BOOTANIMATION_FILE "/system/media/bootanimation-encrypted.zip"
看宏名相信大家就知道了,这就是设置动画文件的名称了。为什么会又显示图片又设置动画显示呢,这个Android版本有关。显示两个图片:前景和背景图片是在1.5版本用,后来就改为了设置动画文件,就是:bootanimation.zip,是zip格式的,这个文件包含三个内容:两个目录:part0和part1,一个文件desc.txt。两个目录用来包含要显示的图片,分为第一阶段和第二阶段。剩下的文件就是设置关于如何显示的信息:
示例如下:
480 800 15
p 1 0 part0

❽ Android源码发开记录-修改开机logo启动页、开机动画

开机logo主要与kernel/drivers/video/logo下的logo_linux_clut224.ppm有关。
现kernel源码内一般以提供厂商的logo为主。
我们需要替换的文件也就是该ppm文件。

这里直接提供png转ppm的sh脚本。前提是必须安装了以下工具(pngtopnm,pnmquant,pnmtoplainpnm)

./png2ppm.sh XX.png

用生成的同名ppm文件替换logo_linux_clut224.ppm。
同时删除kernel/drivers/video/logo下的logo_linux_clut224.c和logo_linux_clut224.o

Android开机动画主要是由一个zip格式的压缩包bootanimation.zip组成,压缩包里面包含数张png格式的图片,还有一个desc.txt的文本文档,开机时按desc.txt里面的指令,屏幕上会按文件名称顺序连续的播放一张张的图片。、

这个一般flash制作或者选择交给美工制作了。图片张数尽量不要太多。
关键:图片一定要按顺序命名。

重点在于desc.txt文件。
其中1188 624代表分辨率,表示帧动画以这个分辨率显示。分辨率不是越高越好,容易造成开机卡顿,不流畅。
25表示的是帧数,就是每秒播放的图片数量。
p1(代表着播放一次) 0(空指令)part0 */这句指令就代表这part0文件夹内的图片只按名称顺序播放一次
p0(重复播放)0 (空指令)part1 */这一句指令代表着part1文件夹内的图片会循环反复播放

打包要用zip格式,而不是rar格式。另外压缩的时候压缩方式要选择存储。将压缩包名修改为bootanimation.zip。

1)可直接将生成的bootanimation.zip放入设备/system/meida目录下重启验证开机动画效果。
2)源码上可直接将bootanimation.zip拷贝至/out/target/proct/rk3288/system/media目录下,最终打包进成型固件中。

❾ 如何修改android6.0源码的开机动画

开机动画很多人都会换,很多地方都有教程,重点来了,怎么换开机声音呢?我这里的换并非可以自定义,当然自定义不是不可能,那得会编程。 1) 手机必须ROOT了的 2) 装个可以进去系统文件的文件浏览器 ,如:RE管理器 (复制覆盖系统文件时,记得修改 “只读” “读写”权限) 3) 在你看中的ROM里面把bootanimation.zip复制出来。bootanimation.zip在哪里呢?ROM包一般是ZIP格式,先在电脑桌面建个文件夹,把它解压到那新建文件夹里面。打开后不外乎就几个文件夹和文件: 自己动手做过精简包的人,基本都会,也知道里面是什么。具体不详细说了,回归主题,bootanimation.zip一般就在system\media 里面。如果没有就查看system其他文件夹,bootanimation.zip这样格式和名字的文件只有一个,但bin里面的绝对不是,后面再说bin,这个是关乎开机声音的。 bootanimation.zip里面装的就是开机动画了,里面基本是由 part文件夹 和 desc文档 组成,part文件夹放的是png , desc则是运行参数,可以编辑图象大小、动画帧、时间频率什么的。 4) 把bootanimation.zip复制到SD卡里面,然后用RE管理器,复制,然后寻找手机系统里面原带的bootanimation.zip并覆盖(记得改读写权限,不然无权覆盖系统文件),这样就把开机动画更换好了。 6) 重重点来了,就这么把这两个文件搬到系统,只会有开机动画,还是不会有声音滴。。上面提到的bin文件夹,位置是system\bin 在里面寻找到 bootanimation 文件。把它复制并覆盖到手机system\bin 里面的 bootanimation(记得改读写权限,不然无权覆盖系统文件),这样就大功告成了。在bin里面的 bootanimation 是说明和引导文,编程方面的,C语言吧,运行编写之类的。绝对的自定义开机声,倒不是小白们不能做到的,把自己想要的声音,名字和格式该成转化成源声音文件名字格式,然后覆盖就可以了。 RE管理器 rootexplorer 二维码扫描下载 分类:系统管理 评分: 支持平台:Android

❿ 求一个记事本的JAVA源代码

/*
* WriteBoard.java
*
* Created on 2006年12月19日, 下午7:26
*/

/**
*
* @author LecH.giF
*/
import java.awt.datatransfer.*;
import java.awt.event.*;
import java.awt.*;
import java.io.*;
import java.awt.FileDialog;
public class WriteBoard extends java.awt.Frame {
Clipboard clipboard =null;
FileDialog fc = new FileDialog(this);

/** Creates new form WriteBoard */
public WriteBoard() {
clipboard = getToolkit().getSystemClipboard();
initComponents();
}

/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">
private void initComponents() {
textArea1 = new java.awt.TextArea();
menuBar1 = new java.awt.MenuBar();
menu1 = new java.awt.Menu();
menuItem1 = new java.awt.MenuItem();
menuItem2 = new java.awt.MenuItem();
menuItem3 = new java.awt.MenuItem();
menuItem4 = new java.awt.MenuItem();
menuItem5 = new java.awt.MenuItem();
menu2 = new java.awt.Menu();
menuItem6 = new java.awt.MenuItem();
menuItem7 = new java.awt.MenuItem();
menuItem8 = new java.awt.MenuItem();

setTitle("WriteBoard");
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
exitForm(evt);
}
});

add(textArea1, java.awt.BorderLayout.CENTER);

menu1.setLabel("Menu");
menuItem1.setLabel("\u65b0\u5efa");
menuItem1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
newText(evt);
}
});

menu1.add(menuItem1);

menuItem2.setLabel("\u6253\u5f00");
menuItem2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
open(evt);
}
});

menu1.add(menuItem2);

menuItem3.setLabel("\u4fdd\u5b58");
menuItem3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
menuItem3ActionPerformed(evt);
}
});

menu1.add(menuItem3);

menuItem4.setLabel("\u53e6\u5b58\u4e3a");
menuItem4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
menuItem4ActionPerformed(evt);
}
});

menu1.add(menuItem4);

menuItem5.setLabel("\u9000\u51fa");
menuItem5.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
exit(evt);
}
});

menu1.add(menuItem5);

menuBar1.add(menu1);

menu2.setLabel("\u7f16\u8f91");
menuItem6.setLabel("\u526a\u5207");
menuItem6.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
menuItem6ActionPerformed(evt);
}
});

menu2.add(menuItem6);

menuItem7.setLabel("\u590d\u5236");
menuItem7.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
menuItem7ActionPerformed(evt);
}
});

menu2.add(menuItem7);

menuItem8.setLabel("\u7c98\u8d34");
menuItem8.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
menuItem8ActionPerformed(evt);
}
});

menu2.add(menuItem8);

menuBar1.add(menu2);

setMenuBar(menuBar1);

pack();
}// </editor-fold>

private void menuItem4ActionPerformed(java.awt.event.ActionEvent evt) {
fc.show();

if(fc.getFile()!=null){

File file = new File(fc.getFile());

try {
PrintWriter pw = new PrintWriter(file);
pw.print(textArea1.getText());
pw.flush();
pw.close();

} catch (FileNotFoundException ex) {
ex.printStackTrace();
}
}

else{
return;
}
}

private void menuItem3ActionPerformed(java.awt.event.ActionEvent evt) {
fc.show();
if(fc.getFile()!=null){

File file = new File(fc.getFile());

try {
PrintWriter pw = new PrintWriter(file);
pw.print(textArea1.getText());
pw.flush();
pw.close();

} catch (FileNotFoundException ex) {
ex.printStackTrace();
}
}

else{
return;
}
}

private void menuItem8ActionPerformed(java.awt.event.ActionEvent evt) {
Transferable contents = clipboard.getContents(this);
DataFlavor flavor = DataFlavor.stringFlavor;
if(contents.isDataFlavorSupported(flavor))
try{
String str;
str=(String)contents.getTransferData(flavor);
textArea1.append(str);
}catch(Exception e){}
}

private void menuItem7ActionPerformed(java.awt.event.ActionEvent evt) {
String temp = this.textArea1.getSelectedText();
StringSelection text = new StringSelection(temp);

clipboard.setContents(text,null);
}

private void menuItem6ActionPerformed(java.awt.event.ActionEvent evt) {
String temp = this.textArea1.getSelectedText();
StringSelection text = new StringSelection(temp);
clipboard.setContents(text,null);
int start = textArea1.getSelectionStart();
int end = textArea1.getSelectionEnd();
textArea1.replaceRange("",start,end);
}

private void open(java.awt.event.ActionEvent evt) {
fc.show();
if(fc.getFile()!=null){

File file = new File(fc.getFile());
try {
FileReader fr = new FileReader(file);
BufferedReader br = new BufferedReader(fr);
String s;
try {
while((s= br.readLine())!=null){
textArea1.append(s+"\n");
}
fr.close();
br.close();
} catch (IOException ex) {
ex.printStackTrace();
}

} catch (FileNotFoundException ex) {
ex.printStackTrace();
}

}
else{
return;
}
}

private void newText(java.awt.event.ActionEvent evt) {
this.textArea1.setText("");
}

private void exit(java.awt.event.ActionEvent evt) {
System.exit(0);
}

/** Exit the Application */
private void exitForm(java.awt.event.WindowEvent evt) {
System.exit(0);
}

/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new WriteBoard().setVisible(true);
}
});
}

// Variables declaration - do not modify
private java.awt.Menu menu1;
private java.awt.Menu menu2;
private java.awt.MenuBar menuBar1;
private java.awt.MenuItem menuItem1;
private java.awt.MenuItem menuItem2;
private java.awt.MenuItem menuItem3;
private java.awt.MenuItem menuItem4;
private java.awt.MenuItem menuItem5;
private java.awt.MenuItem menuItem6;
private java.awt.MenuItem menuItem7;
private java.awt.MenuItem menuItem8;
private java.awt.TextArea textArea1;
// End of variables declaration

}

热点内容
interbase数据库 发布:2025-05-14 13:49:50 浏览:691
微商海报源码 发布:2025-05-14 13:49:42 浏览:346
分布式缓存部署步骤 发布:2025-05-14 13:24:51 浏览:611
php获取上一月 发布:2025-05-14 13:22:52 浏览:90
购买云服务器并搭建自己网站 发布:2025-05-14 13:20:31 浏览:689
sqlserver建立视图 发布:2025-05-14 13:11:56 浏览:485
搭建httpsgit服务器搭建 发布:2025-05-14 13:09:47 浏览:256
新电脑拿回来我该怎么配置 发布:2025-05-14 13:09:45 浏览:241
视频服务器新建ftp用户 发布:2025-05-14 13:03:09 浏览:226
php花生 发布:2025-05-14 12:54:30 浏览:551