當前位置:首頁 » 操作系統 » 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

}

熱點內容
分布式緩存部署步驟 發布:2025-05-14 13:24:51 瀏覽:609
php獲取上一月 發布:2025-05-14 13:22:52 瀏覽:88
購買雲伺服器並搭建自己網站 發布:2025-05-14 13:20:31 瀏覽:687
sqlserver建立視圖 發布:2025-05-14 13:11:56 瀏覽:484
搭建httpsgit伺服器搭建 發布:2025-05-14 13:09:47 瀏覽:255
新電腦拿回來我該怎麼配置 發布:2025-05-14 13:09:45 瀏覽:240
視頻伺服器新建ftp用戶 發布:2025-05-14 13:03:09 瀏覽:225
php花生 發布:2025-05-14 12:54:30 瀏覽:550
java人才 發布:2025-05-14 12:29:10 瀏覽:649
如何打開軟密碼 發布:2025-05-14 12:28:55 瀏覽:427