赞
踩
memman
初始化
|
malloc
|
free
|
EDX=8
EBX=memman
的地址
EAX=memman
所管理的内存空间的起始地址
ECX=memman
所管理的内存空间的字节数
|
EDX=9
EBX=memman
的地址
ECX=
需要请求的字节数
EAX=
分配到的内存空间地址
|
EDX=10
EBX=memman
的地址
EAX=
需要释放的内存空间地址
ECX=
需要释放的字节数
|
- _api_initmalloc: ; void api_initmalloc(void);
- PUSH EBX
- MOV EDX,8
- MOV EBX,[CS:0x0020] ; 初始化地址 P494页 0x0020 (DWORD) ……malloc空间的起始地址
- MOV EAX,EBX
- ADD EAX,32*1024 ;分配了32k内存
- MOV ECX,[CS:0x0000]
- SUB ECX,EAX ;包括前32位数据(文件信息)以及32k内存
- INT 0x40
- POP EBX
- RET
-
- _api_malloc: ;char *api_malloc(int size)
- PUSH EBX
- MOV EDX,9
- MOV EBX,[CS:0x0020]
- MOV ECX,[ESP+8] ;size
- INT 0x40
- POP EBX
- RET
-
- _api_free: ;void api_free(char *addr, int size)
- PUSH EBX
- MOV EDX,10
- MOV EBX,[CS:0x0020]
- MOV EAX,[ESP+8] ;addr
- MOV ECX,[ESP+12] ;size
- INT 0x40
- POP EBX
- RET
- /* a_nask.nas */
- _api_point: ;void api_point(int win, int x, int y, int col);
- PUSH EDI
- PUSH ESI
- PUSH EBX
- MOV EDX,11
- MOV EBX,[ESP+16] ;win
- MOV ESI,[ESP+20] ;x
- MOV EDI,[ESP+24] ;y
- MOV EAX,[ESP+28] ;col
- INT 0X40
- POP EBX
- POP ESI
- POP EDI
- RET
-
- /* console.c */
- if(edx == 11){//api_point
- sht = (struct SHEET *) ebx;
- sht->buf[sht->bxsize * edi + esi] = eax;//修改某个点的颜色
- sheet_refresh(sht, esi, edi, esi + 1, edi + 1);
- }
- /* a_nask.nas */
- _api_refreshwin: ;void api_refreshwin(int win, int x0, int y0, int x1, int y1);
- PUSH EDI
- PUSH ESI
- PUSH EBX
- MOV EDX,12
- MOV EBX,[ESP+16] ;win
- MOV EAX,[ESP+20] ;x0
- MOV ECX,[ESP+24] ;y0
- MOV ESI,[ESP+28] ;x1
- MOV EDI,[ESP+32] ;y1
- INT 0X40
- POP EBX
- POP ESI
- POP EDI
- RET
-
- /* console.c */
- int *hrb_api(int edi, int esi, int ebp, int esp, int ebx, int edx, int ecx, int eax){
- (中略)
- if(edx == 1)
- cons_putchar(cons, eax&0xff, 1);
- else if(edx == 2)
- cons_putstr0(cons, (char*)ebx+ds_base);
- else if(edx == 3)
- cons_putstr1(cons, (char*)ebx+ds_base, ecx);
- else if(edx == 4)
- return &(task->tss.esp0);
- else if(edx == 5){
- (中略)
- }else if(edx == 6){
- /*这里*/sht = (struct SHEET *) (ebx&0xfffffffe);
- (中略)
- /*这里*/if(ebx&1 == 0)
- /*这里*/ sheet_refresh(sht, eax, ecx, esi + 1, edi + 1);
- }else if(edx == 8){//memman初始化
- (中略)
- }else if(edx == 9){//malloc
- (中略)
- }else if(edx == 10){//free
- ecx = (ecx+0x0f)&0xfffffff0;//所释放的内存空间的字节数
- memman_free((struct MEMMAN *) (ebx + ds_base), eax, ecx);
- }else if(edx == 11){//api_point
- /*这里*/ sht = (struct SHEET *) (ebx&0xfffffffe);
- sht->buf[sht->bxsize * edi + esi] = eax;
- /*这里*/ if(ebx&1 == 0)//当ebx的最低位为0,也就是没有字符串需要打印时,刷新图层
- /*这里*/ sheet_refresh(sht, esi, edi, esi + 1, edi + 1);
- }else if(edx == 12){
- /*这里*/ sht = (struct SHEET *) ebx;
- /*这里*/ sheet_refresh(sht, eax, ecx, esi, edi);
- }
- return 0;
- }
- /* a_nash.nas */
- _api_linewin: ;void api_linewin(int win, int x0, int y0, int x1, int y1, int col);
- PUSH EDI
- PUSH ESI
- PUSH EBP
- PUSH EBX
- MOV EDX,13
- MOV EBX,[ESP+20] ;win
- MOV EAX,[ESP+24] ;x0
- MOV ECX,[ESP+28] ;y0
- MOV ESI,[ESP+32] ;x1
- MOV EDI,[ESP+36] ;y1
- MOV EBP,[ESP+40] ;col
- INT 0X40
- POP EBX
- POP EBP
- POP ESI
- POP EDI
- RET
-
- /* console.c */
- if(edx == 13){
- sht = (struct SHEET *) (ebx&0xfffffffe);
- hrb_api_linewin(sht, eax, ecx, esi, edi, ebp);
- if(ebx&1 == 0)//当ebx的最低位为0,也就是没有字符串需要打印时,刷新图层
- sheet_refresh(sht, eax, ecx, esi, edi);
- }
-
- void hrb_api_linewin(struct SHEET *sht, int x0, int y0, int x1, int y1,int col){
- int i, x, y, len, dx, dy;
- dx = x1-x0;
- dy = y1-y0;
- x = x0<<10;
- y = y0<<10;
- if(dx < 0)dx = -dx;
- if(dy < 0)dy = -dy;
- if(dx >= dy){
- len = dx+1;
- if(x0 > x1)dx = -1024;
- else dx = 1024;
- if(y0 <= y1)dy = ((y1-y0+1)<<10)/len;
- else dy = ((y1-y0-1)<<10)/len;//-(y0-y1+1) = y1-y0-1
- }else{
- len = dy+1;
- if(y0 > y1)dy = -1024;
- else dy = 1024;
- if(x0 <= x1)dx = ((x1-x0+1)<<10)/len;
- else dx = ((x1-x0-1)<<10)/len;
- }
- for(i = 0; i < len; i++){
- sht->buf[(y>>10)*sht->bxsize+(x>>10)] = col;
- x += dx;
- y += dy;
- }
- return;
- }
- /* a_nask.nas */
- _api_closewin: ;void api_closewin(int win);
- PUSH EBX
- MOV EDX,14
- MOV EBX,[ESP+8] ;win
- INT 0X40
- POP EBX
- RET
-
- /* console.c */
- if(edx == 14){//关闭窗口
- sheet_free((struct SHEET *) ebx);
- }
- /* a_nask.nas */
- _api_getkey: ;int api_getkey(int mode);
- MOV EDX,15
- MOV EAX,[ESP+4]
- INT 0X40
- RET
-
- /* console.c */
- if(edx == 15){
- for(;;){
- io_cli();
- if(fifo32_status(&task->fifo) == 0){
- if(eax != 0)task_sleep(task);//休眠
- else{//没有键盘输入时返回-1,不休眠
- io_sti();
- reg[7] = -1;
- return 0;
- }
- }
- i = fifo32_get(&task->fifo);
- if(i <= 1){//光标
- /*应用程序运行时不需要显示光标,因此总是将下次显示用的值置为1*/
- timer_init(cons->timer, &task->fifo, 1);
- timer_settime(cons->timer, 50);
- }
- if(i == 2)cons->cur_c = COL8_FFFFFF;/*光标ON */
- if(i == 3)cons->cur_c = -1;/*光标OFF */
- if(256 <= i && i <= 511){
- reg[7] = i-256;
- return 0;
- }
- }
- }
- int cmd_app(struct CONSOLE *cons, int *fat, char *cmdline){
- int segsiz, datsiz, esp, dathrb;
- /*这里*/struct SHEET *sht;
- /*这里*/struct SHTCTL *shtctl;
- (中略)
- if (finfo != 0) {
- /* 找到了与字符串相同的文件 */
- p = (char *) memman_alloc_4k(memman, finfo->size);
- file_loadfile(finfo->clustno, finfo->size, p, fat, (char *) (ADR_DISKIMG + 0x003e00));
- if (finfo->size >= 36 && strncmp(p + 4, "Hari", 4) == 0 && *p == 0x00){
- (中略)
- start_app(0x1b, 1003 * 8, esp, 1004*8, &(task->tss.esp0));
- /*从这里开始*/shtctl = (struct SHTCTL *) *((int *) 0x0fe4);/*从这里开始*/
- for(i = 0; i < MAX_SHEETS; i++){
- sht = &(shtctl->sheets0[i]);
- if(sht->flags != 0 && sht->task == task)
- sheet_free(sht);
- /*到这里结束*/}
- memman_free_4k(memman, (int) q, segsiz);
- }else
- cons_putstr0(cons, ".hrb file format error.\n");
- memman_free_4k(memman, (int) p, finfo->size);
- cons_newline(cons);
- return 1;
- }
- return 0;
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。