30天自制操作系统笔记(十一十二)——源码

来源:互联网 发布:js 页面后退 编辑:程序博客网 时间:2024/05/17 08:49

这里我们只给出新增部分和修改部分的源码:

系统运行截图http://blog.csdn.net/ucan23/article/details/17088983点击打开链接

/* filename:    timer.c * description: 定时器函数 * author:      Howard * date:        2013-12-02 * version:     v1.0 */  #include "bootpack.h"  struct TIMERCTL timerctl;  void init_pit(void){int i;io_out8(PIT_CTRL, 0x34);io_out8(PIT_CNT0, 0x9c);io_out8(PIT_CNT0, 0x2e);timerctl.count = 0;timerctl.next = 0xffffffff;for (i=0; i<MAX_TIMER; i++){timerctl.timers0[i].flags = 0;   /*未使用*/}return;}struct TIMER *timer_alloc(void){int i;for (i=0; i<MAX_TIMER; i++){if (timerctl.timers0[i].flags == 0){timerctl.timers0[i].flags = TIMER_FLAGS_ALLOC;return &timerctl.timers0[i];}}return 0;}void timer_free(struct TIMER *timer){timer->flags = 0;return;}void timer_init(struct TIMER *timer, struct FIFO8 *fifo, unsigned char data){timer->fifo = fifo;timer->data = data;return;}void timer_settime(struct TIMER *timer, unsigned int timeout){int e, i, j; timer->timeout = timeout + timerctl.count;timer->flags = TIMER_FLAGS_USING;e = io_load_eflags();io_cli();for (i=0; i<timerctl.using; i++){if (timerctl.timers[i]->timeout>timer->timeout){break;}}for (j=timerctl.using; j>i; j--){timerctl.timers[j] = timerctl.timers[j-1];}timerctl.using ++;timerctl.timers[i] = timer;timerctl.next = timerctl.timers[0]->timeout;io_store_eflags(e);return;}void inthandler20(int *esp){int i, j;io_out8(PIC0_OCW2, 0x60);timerctl.count ++;if (timerctl.next>timerctl.count){return;}for (i=0; i<timerctl.using; i++){if (timerctl.timers[i]->timeout>timerctl.count){break;}timerctl.timers[i]->flags = TIMER_FLAGS_ALLOC;fifo8_put(timerctl.timers[i]->fifo, timerctl.timers[i]->data);} timerctl.using -=i;for (j=0; j<timerctl.using; j++){timerctl.timers[j] = timerctl.timers[i+j];}if (timerctl.using>0){timerctl.next = timerctl.timers[0]->timeout;}else{timerctl.next = 0xffffffff;}return;}
/* filename:    sheet.c * description: 对图层的管理 * author:      Howard * date:        2013-12-01 * version:     v1.0 */ #include "bootpack.h" struct SHTCTL *shtctl_init(struct MEMMAN *memman, unsigned char *vram, int xsize, int ysize){struct SHTCTL *ctl;int i;ctl = (struct SHTCTL *) memman_alloc_4k(memman, sizeof (struct SHTCTL));if (0==ctl){goto err;}ctl->map = (unsigned char *) memman_alloc_4k(memman, xsize*ysize);if (0==ctl->map) {memman_free_4k(memman, (int) ctl, sizeof (struct SHTCTL));goto err;}ctl->vram = vram;ctl->xsize = xsize;ctl->ysize = ysize;ctl->top = -1; /*一个sheet也没有*/for (i=0; i<MAX_SHEETS; i++){ctl->sheets0[i].flags = 0; /*标记为未使用*/ctl->sheets0[i].ctl = ctl; /*记录所属*/}err:return ctl;}struct SHEET *sheet_alloc(struct SHTCTL *ctl){struct SHEET *sht;int i;for (i=0; i<MAX_SHEETS; i++){if (0==ctl->sheets0[i].flags){sht = &ctl->sheets0[i];sht->flags = SHEET_USE;sht->height = -1;return sht;}}return 0;}void sheet_setbuf(struct SHEET *sht, unsigned char *buf, int xsize, int ysize, int col_inv){sht->buf = buf;sht->bxsize = xsize;sht->bysize = ysize;sht->col_inv = col_inv;return;}void sheet_refreshmap(struct SHTCTL *ctl, int vx0, int vy0, int vx1, int vy1, int h0){int h, bx, by, vx, vy, bx0, by0, bx1, by1;unsigned char *buf, sid, *map = ctl->map;struct SHEET *sht;if (vx0 < 0) { vx0 = 0; }if (vy0 < 0) { vy0 = 0; }if (vx1 > ctl->xsize) { vx1 = ctl->xsize; }if (vy1 > ctl->ysize) { vy1 = ctl->ysize; }for (h = h0; h <= ctl->top; h++) {sht = ctl->sheets[h];sid = sht - ctl->sheets0; buf = sht->buf;bx0 = vx0 - sht->vx0;by0 = vy0 - sht->vy0;bx1 = vx1 - sht->vx0;by1 = vy1 - sht->vy0;if (bx0 < 0) {bx0 = 0; }if (by0 < 0) { by0 = 0; }if (bx1 > sht->bxsize) {bx1 = sht->bxsize; }if (by1 > sht->bysize) { by1 = sht->bysize; }for (by = by0; by < by1; by++) {vy = sht->vy0 + by;for (bx = bx0; bx < bx1; bx++) {vx = sht->vx0 + bx;if (buf[by * sht->bxsize + bx] != sht->col_inv) {map[vy * ctl->xsize + vx] = sid;}}}}return;}void sheet_refreshsub(struct SHTCTL *ctl, int vx0, int vy0, int vx1, int vy1, int h0, int h1){int h, bx, by, vx, vy, bx0, by0, bx1, by1;unsigned char *buf, *vram = ctl->vram, *map = ctl->map, sid;struct SHEET *sht;/*如果refresh超出了画面则修正*/if (vx0<0){vx0 = 0;}if (vy0<0){vy0 = 0;}if (vx1>ctl->xsize){vx1 = ctl->xsize;}if (vy1>ctl->ysize){vy1 = ctl->ysize;}for (h = h0; h <= h1; h++) {sht = ctl->sheets[h];buf = sht->buf;sid = sht - ctl->sheets0;bx0 = vx0 - sht->vx0;by0 = vy0 - sht->vy0;bx1 = vx1 - sht->vx0;by1 = vy1 - sht->vy0;if (bx0<0){bx0 = 0;}if (by0<0){by0 = 0;}if (bx1>sht->bxsize){bx1 = sht->bxsize;}if (by1>sht->bysize){by1 = sht->bysize;}for (by = by0; by < by1; by++) {vy = sht->vy0 + by;for (bx = bx0; bx < bx1; bx++) {vx = sht->vx0 + bx;//c = buf[by * sht->bxsize + bx];if (sid == map[vy*ctl->xsize+vx]) {vram[vy * ctl->xsize + vx] = buf[by*sht->bxsize+bx];}}}}return;}void sheet_updown(struct SHEET *sht, int height){struct SHTCTL *ctl = sht->ctl;int h, old = sht->height;/*存储设置前的高度信息*//*如果指定的高度过低则进行修正*/if (height>ctl->top+1){height = ctl->top + 1;}if (height<-1){height = -1;}sht->height = height; /*设置高度*//*sheets[]的重新排列*/if (old>height){if (height>=0){for (h = old; h>height;h--){ctl->sheets[h] = ctl->sheets[h-1];ctl->sheets[h]->height = h;}ctl->sheets[height] = sht;sheet_refreshmap(ctl, sht->vx0, sht->vy0, sht->vx0 + sht->bxsize, sht->vy0 + sht->bysize, height + 1);sheet_refreshsub(ctl, sht->vx0, sht->vy0, sht->vx0 + sht->bxsize, sht->vy0 + sht->bysize, height + 1, old);} else {if (ctl->top>old){for (h=old; h<ctl->top; h++){ctl->sheets[h] = ctl->sheets[h+1];ctl->sheets[h]->height = h;}}ctl->top --;sheet_refreshmap(ctl, sht->vx0, sht->vy0, sht->vx0 + sht->bxsize, sht->vy0 + sht->bysize, 0);sheet_refreshsub(ctl, sht->vx0, sht->vy0, sht->vx0 + sht->bxsize, sht->vy0 + sht->bysize, 0, old-1);}//sheet_refresh(ctl);//sheet_refreshsub(ctl, sht->vx0, sht->vy0, sht->vx0 + sht->bxsize, sht->vy0 + sht->bysize);} else if (old<height){if (old>=0){for (h=old; h<height; h++){ctl->sheets[h] = ctl->sheets[h+1];ctl->sheets[h]->height = h;}ctl->sheets[height] = sht;} else {for (h=ctl->top; h>=height; h--){ctl->sheets[h+1] = ctl->sheets[h];ctl->sheets[h+1]->height = h + 1;}ctl->sheets[height] = sht;ctl->top ++;}//sheet_refresh(ctl);//sheet_refreshsub(ctl, sht->vx0, sht->vy0, sht->vx0 + sht->bxsize, sht->vy0 + sht->bysize);sheet_refreshmap(ctl, sht->vx0, sht->vy0, sht->vx0 + sht->bxsize, sht->vy0 + sht->bysize, height);sheet_refreshsub(ctl, sht->vx0, sht->vy0, sht->vx0 + sht->bxsize, sht->vy0 + sht->bysize, height, height);}return;}void sheet_refresh(struct SHEET *sht, int bx0, int by0, int bx1, int by1){if (sht->height >= 0) { sheet_refreshsub(sht->ctl, sht->vx0 + bx0, sht->vy0 + by0, sht->vx0 + bx1, sht->vy0 + by1, sht->height, sht->height);}return;}/*void sheet_refresh(struct SHTCTL *ctl){int h, bx, by, vx, vy;unsigned char *buf, c, *vram = ctl->vram;struct SHEET *sht;for (h=0; h<=ctl->top; h++){sht = ctl->sheets[h];buf = sht->buf;for (by=0; by<sht->bysize; by++){vy = sht->vy0 + by;for (bx=0; bx<sht->bxsize; bx++){vx = sht->vx0 +bx;c = buf[by*sht->bxsize + bx];if (c!=sht->col_inv){vram[vy*ctl->xsize+vx] = c;}}}}return;}*/void sheet_slide(struct SHEET *sht, int vx0, int vy0){struct SHTCTL *ctl = sht->ctl;int old_vx0 = sht->vx0, old_vy0 = sht->vy0;sht->vx0 = vx0;sht->vy0 = vy0;if (sht->height>=0){//sheet_refresh(ctl);//sheet_refreshsub(sht->ctl, old_vx0, old_vy0, old_vx0 + sht->bxsize, old_vy0 + sht->bysize, 0);//sheet_refreshsub(sht->ctl, vx0, vy0, vx0 + sht->bxsize, vy0 + sht->bysize, sht->height);sheet_refreshmap(ctl, old_vx0, old_vy0, old_vx0 + sht->bxsize, old_vy0 + sht->bysize, 0);sheet_refreshmap(ctl, vx0, vy0, vx0 + sht->bxsize, vy0 + sht->bysize, sht->height);sheet_refreshsub(ctl, old_vx0, old_vy0, old_vx0 + sht->bxsize, old_vy0 + sht->bysize, 0, sht->height - 1);sheet_refreshsub(ctl, vx0, vy0, vx0 + sht->bxsize, vy0 + sht->bysize, sht->height, sht->height);}return;}void sheet_free(struct SHEET *sht){if (sht->height>=0){sheet_updown(sht, -1);}sht->flags = 0;return;}

dsctbl.nas包含了对中断的处理的函数

[FORMAT "WCOFF"][INSTRSET "i486p"][OPTIMIZE 1][OPTION 1][BITS 32]EXTERN_load_gdtrEXTERN_load_idtrEXTERN_asm_inthandler20EXTERN_asm_inthandler21EXTERN_asm_inthandler27EXTERN_asm_inthandler2c[FILE "dsctbl.c"][SECTION .text]GLOBAL_init_gdtidt_init_gdtidt:PUSHEBPMOVEBP,ESPPUSHESIPUSHEBXMOVESI,2555904MOVEBX,8191L6:PUSH0PUSH0PUSH0PUSHESIADDESI,8CALL_set_segmdescADDESP,16DECEBXJNSL6PUSH16530MOVESI,2553856PUSH0MOVEBX,255PUSH-1PUSH2555912CALL_set_segmdescPUSH16538PUSH2621440PUSH524287PUSH2555920CALL_set_segmdescADDESP,32PUSH2555904PUSH65535CALL_load_gdtrPOPEAXPOPEDXL11:PUSH0PUSH0PUSH0PUSHESIADDESI,8CALL_set_gatedescADDESP,16DECEBXJNSL11PUSH2553856PUSH2047CALL_load_idtrPUSH142PUSH16PUSH_asm_inthandler20PUSH2554112CALL_set_gatedescPUSH142PUSH16PUSH_asm_inthandler21PUSH2554120CALL_set_gatedescADDESP,40PUSH142PUSH16PUSH_asm_inthandler27PUSH2554168CALL_set_gatedescPUSH142PUSH16PUSH_asm_inthandler2cPUSH2554208CALL_set_gatedescLEAESP,DWORD [-8+EBP]POPEBXPOPESIPOPEBPRETGLOBAL_set_segmdesc_set_segmdesc:PUSHEBPMOVEBP,ESPPUSHEBXMOVEDX,DWORD [12+EBP]MOVECX,DWORD [16+EBP]MOVEBX,DWORD [8+EBP]MOVEAX,DWORD [20+EBP]CMPEDX,1048575JBEL17SHREDX,12OREAX,32768L17:MOVWORD [EBX],DXMOVBYTE [5+EBX],ALSHREDX,16SAREAX,8ANDEDX,15MOVWORD [2+EBX],CXANDEAX,-16SARECX,16OREDX,EAXMOVBYTE [4+EBX],CLMOVBYTE [6+EBX],DLSARECX,8MOVBYTE [7+EBX],CLPOPEBXPOPEBPRETGLOBAL_set_gatedesc_set_gatedesc:PUSHEBPMOVEBP,ESPPUSHEBXMOVEDX,DWORD [8+EBP]MOVEAX,DWORD [16+EBP]MOVEBX,DWORD [20+EBP]MOVECX,DWORD [12+EBP]MOVWORD [2+EDX],AXMOVBYTE [5+EDX],BLMOVWORD [EDX],CXMOVEAX,EBXSAREAX,8SARECX,16MOVBYTE [4+EDX],ALMOVWORD [6+EDX],CXPOPEBXPOPEBPRET

dsctbl.c文件增加了这么一行

set_gatedesc(idt + 0x20, (int) asm_inthandler20, 2 * 8, AR_INTGATE32);

Makefile文件变量部分改为

OBJS_BOOTPACK = bootpack.obj naskfunc.obj yezfont.obj graphic.obj dsctbl.obj \int.obj fifo.obj keyboard.obj mouse.obj memory.obj sheet.obj \timer.obj

naskfunc.nas文件变为

; naskfunc; TAB=4[FORMAT "WCOFF"] [INSTRSET "i486p"] [BITS 32] [FILE "naskfunc.nas"] GLOBAL_io_hlt,_write_mem8GLOBAL_io_cli, _io_sti, _io_stihltGLOBAL_io_in8, _io_in16, _io_in32GLOBAL_io_out8, _io_out16, _io_out32GLOBAL_io_load_eflags, _io_store_eflagsGLOBAL_load_gdtr, _load_idtrGLOBAL  _load_cr0, _store_cr0GLOBAL_asm_inthandler20, _asm_inthandler21GLOBAL _asm_inthandler27, _asm_inthandler2cGLOBAL_memtest_subEXTERN_inthandler20, _inthandler21EXTERN  _inthandler2c, _inthandler27[SECTION .text]_io_hlt:; void io_hlt(void);HLTRET_write_mem8:; void write_mem8(int addr, int data);MOVECX,[ESP+4];  MOVAL,[ESP+8];  MOV[ECX],ALRET _io_cli:;void io_cli(void);CLIRET_io_sti:;void io_sti(void);STIRET_io_stihlt:;void io_stihlt(void);STIHLTRET_io_in8:;int io_in8(int port);MOVEDX, [ESP+4];portMOVEAX, 0INAL, DXRET_io_in16:;int io_in16(int port);MOVEDX, [ESP+4]MOVEAX, 0INAX, DXRET_io_in32:;io_in32(int port);MOVEDX, [ESP+4]INEAX, DXRET_io_out8:;io_out8(int port, int data);MOVEDX, [ESP+4] ;PORTMOVAL, [ESP+8];DATAOUTDX, ALRET_io_out16:;io_out16(int port, int data);MOVEDX, [ESP+4]MOVEAX, [ESP+8]OUTDX, AX_io_out32:;io_out32(int port, int data);MOVEDX, [ESP+4]MOVEAX, [ESP+8]OUTDX, EAXRET_io_load_eflags:;io_load_eflags(int eflags);PUSHFDPOPEAXRET_io_store_eflags:;io_store_eflags(int eflags);MOVEAX, [ESP+4]PUSHEAXPOPFDRET_load_gdtr:;void load_gdtr(int limit, int addr);MOVAX,[ESP+4];limitMOV [ESP+6], AXLGDT[ESP+6]RET_load_idtr:;void load_idtr(int limit, int addr);MOVAX, [ESP+4]MOV[ESP+6], AXLIDT[ESP+6]RET_load_cr0:;int load_cr0(void)MOVEAX, CR0RET_store_cr0:;void load_cr0(int cr0)MOVEAX, [ESP+4]MOVCR0, EAXRET_asm_inthandler20:PUSHESPUSHDSPUSHADMOVEAX, ESPPUSHEAXMOVAX, SSMOVDS, AXMOV ES, AXCALL_inthandler20POPEAXPOPADPOPDSPOPESIRETD_asm_inthandler21:PUSHESPUSHDSPUSHADMOVEAX, ESPPUSH EAXMOVAX, SSMOVDS, AXMOVES,AXCALL_inthandler21POPEAXPOPADPOPDSPOPESIRETD_asm_inthandler27:PUSHESPUSHDSPUSHADMOVEAX, ESPPUSHEAXMOVAX, SSMOVDS, AXMOVES, AXCALL_inthandler27POPEAXPOPADPOPDSPOPESIRETD_asm_inthandler2c:PUSHESPUSHDSPUSHADMOVEAX, ESPPUSHEAXMOVAX, SSMOVDS, AXMOVES, AXCALL_inthandler2cPOPEAXPOPADPOPDSPOPESIRETD_memtest_sub:; unsigned int memtest_sub(unsigned int start, unsigned int end);PUSHEDIPUSHESIPUSHEBXMOVESI, 0xaa55aa55MOVEDI, 0x55aa55aaMOVEAX, [ESP+12+4]mts_loop:MOVEBX, EAXADDEBX, 0xffcMOVEDX, [EBX]MOV[EBX], ESIXORDWORD [EBX], 0xffffffffCMPEDI, [EBX]JNEmts_finXORDWORD [EBX], 0xffffffffCMPESI, [EBX]JNEmts_finMOV[EBX], EDXADDEAX, 0x1000CMPEAX, [ESP+12+8]JBEmts_loopPOPEBXPOPESIPOPEDIRETmts_fin:MOV[EBX], EDXPOPEBXPOPESIPOPEDIRET

最后给出的主函数所在的文件

/* filename:    bootpack.c * description: the UcanMain()file * author:      Howard * date:        2013-11-28 * version:     v1.0 */#include <stdio.h>#include "bootpack.h"extern struct FIFO8 keyfifo, mousefifo;void UcanMain(void){char *vram;char s[50], mcursor[256], keybuf[32], mousebuf[128], timerbuf[8], timerbuf2[8], timerbuf3[8];int mx, my;//鼠标的(x,y)int xsize, ysize;int i;unsigned int memtotal, count = 0;struct MOUSE_DEC mdec; /*鼠标解码缩放的数据*/struct SHTCTL *shtctl;struct FIFO8 timerfifo, timerfifo2, timerfifo3;struct TIMER *timer, *timer2, *timer3;struct SHEET *sht_back, *sht_mouse, *sht_win;unsigned char *buf_back, buf_mouse[256], *buf_win;struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR;struct BOOTINFO *binfo = (struct BOOTINFO *) 0x0ff0; init_gdtidt();init_pic();io_sti();fifo8_init(&keyfifo, 32, keybuf);fifo8_init(&mousefifo, 128, mousebuf);fifo8_init(&timerfifo, 8, timerbuf);fifo8_init(&timerfifo2, 8, timerbuf2);fifo8_init(&timerfifo3, 8, timerbuf3);init_pit();timer = timer_alloc();timer2 = timer_alloc();timer3 = timer_alloc();timer_init(timer, &timerfifo, 1);timer_init(timer2, &timerfifo2, 1);timer_init(timer3, &timerfifo3, 1);timer_settime(timer, 1000);timer_settime(timer2, 300);timer_settime(timer3, 50);//settimer(1000, &timerfifo, 1);io_out8(PIC0_IMR, 0xf8);io_out8(PIC1_IMR, 0xef);init_keyboard();enable_mouse(&mdec);memtotal = memtest(0x00400000, 0xbfffffff);memman_init(memman);memman_free(memman, 0x00001000, 0x0009e000);memman_free(memman, 0x00400000, memtotal - 0x00400000);init_palette();shtctl = shtctl_init(memman, binfo->vram, binfo->scrnx, binfo->scrny);sht_back = sheet_alloc(shtctl);sht_mouse = sheet_alloc(shtctl);sht_win = sheet_alloc(shtctl);buf_back = (unsigned char *)memman_alloc_4k(memman, binfo->scrnx*binfo->scrny);buf_win = (unsigned char *)memman_alloc_4k(memman, 160*52);sheet_setbuf(sht_back, buf_back, binfo->scrnx, binfo->scrny, -1);sheet_setbuf(sht_mouse, buf_mouse, 16, 16, 99);sheet_setbuf(sht_win, buf_win, 160, 52, -1);//init_screen(binfo->vram, binfo->scrnx, binfo->scrny);init_screen(buf_back, binfo->scrnx, binfo->scrny);init_mouse_cursor8(buf_mouse, 99);make_window8(buf_win, 160, 52, "Counter");//putfonts8_asc(buf_win, 160, 24, 28, COL8_000000, "Welcome to");//putfonts8_asc(buf_win, 160, 24, 44, COL8_000000, "      Ucan-OS!");sheet_slide(sht_back, 0, 0);//init_mouse_cursor8(mcursor, 99);xsize = (*binfo).scrnx;ysize = (*binfo).scrny;vram = (*binfo).vram;mx = (binfo->scrnx-16) / 2;my = (binfo->scrny-28-16) /2;sheet_slide(sht_mouse, mx, my);sheet_slide(sht_win, 80, 72);sheet_updown(sht_back,  0);sheet_updown(sht_win,   1);sheet_updown(sht_mouse, 2);//putblock8_8(buf_back, binfo->scrnx, 16, 16, mx, my, buf_mouse, 16);putfonts8_asc(buf_back, binfo->scrnx, 8, 8, COL8_FFFFFF, "Hello, world!");putfonts8_asc(buf_back, binfo->scrnx, 31, 31, COL8_000000, "Ucan23-OS");putfonts8_asc(buf_back, binfo->scrnx, 30, 30, COL8_FFFFFF, "Ucan23-OS");sprintf(s, "scrnx = %d", binfo->scrnx);putfonts8_asc(buf_back, binfo->scrnx, 16, 64, COL8_FFFFFF, s);sprintf(s, "(%d, %d)", mx, my);putfonts8_asc(buf_back, binfo->scrnx, mx+16, my+16, COL8_FFFFFF, s);//io_out8(PIC0_IMR, 0xf9);//io_out8(PIC1_IMR, 0xef);sprintf(s, "Memory %dMB  free: %dKB", memtotal/(1024*1024), memman_total(memman)/1024);putfonts8_asc(buf_back, binfo->scrnx, 0, 136, COL8_FFFFFF, s);sheet_refresh(sht_back, 0, 0, binfo->scrnx, binfo->scrny);for (;;){/*计数器程序*///count ++;sprintf(s, "%010d", timerctl.count);boxfill8(buf_win, 160, COL8_C6C6C6, 40, 28, 119, 43);putfonts8_asc(buf_win, 160,  40, 28, COL8_000000, s);sheet_refresh(sht_win, 40, 28, 120, 44);io_cli();    /*执行nashfunc.nas里的_io_hlt*/if (0==(fifo8_status(&keyfifo)+fifo8_status(&mousefifo)+fifo8_status(&timerfifo)+ \fifo8_status(&timerfifo2)+fifo8_status(&timerfifo3))){io_sti();} else {if (0!=fifo8_status(&keyfifo)){i = fifo8_get(&keyfifo);io_sti();sprintf(s, "%02X", i);boxfill8(buf_back, binfo->scrnx, COL8_000000, 0, 120, 15, 135);putfonts8_asc(buf_back, binfo->scrnx, 0, 120, COL8_FFFFFF, s);sheet_refresh(sht_back, 0, 120, 15*8, 136);} else if (0!=fifo8_status(&mousefifo)){i = fifo8_get(&mousefifo);io_sti();if (0 != mouse_decode(&mdec, i)){sprintf(s, "[lcr %4d %4d]", mdec.x, mdec.y);if ((mdec.btn & 0x01)!=0){s[1] = 'L';}if ((mdec.btn & 0x02)!=0){s[3] = 'R';}if ((mdec.btn & 0x04)!=0){s[2] = 'C';}boxfill8(buf_back, binfo->scrnx, COL8_008484, 32, 120, 32+15*8-1,135);putfonts8_asc(buf_back, binfo->scrnx, 32, 120, COL8_FFFFFF, s);sheet_refresh(sht_back, 32, 120, 32+15*8, 136);/*鼠标指针的移动*///boxfill8(buf_back, binfo->scrnx, COL8_008484, mx, my, mx+15, my+15);/*隐藏鼠标*/mx += mdec.x;my += mdec.y;if (mx<0){mx = 0;}if (my<0){my = 0;}if (mx>binfo->scrnx-1){mx = binfo->scrnx-1;}if (my>binfo->scrny-1){my = binfo->scrny-1;}sprintf(s, "(%3d, %3d)", mx, my);boxfill8(buf_back, binfo->scrnx, COL8_008484,binfo->scrnx-100,120,binfo->scrnx , 136);putfonts8_asc(buf_back, binfo->scrnx, binfo->scrnx-100, 120, COL8_FFFFFF,s);sheet_refresh(sht_back, binfo->scrnx-100, 120, binfo->scrnx, 136);//putblock8_8(binfo->vram,binfo->scrnx, 16, 16, mx, my, mcursor, 16);sheet_slide(sht_mouse, mx, my);}} else if (0!=fifo8_status(&timerfifo)){i = fifo8_get(&timerfifo);io_sti();//boxfill8(buf_back, binfo->scrnx, COL8_008484,binfo->scrnx-100,0,binfo->scrnx , 16);putfonts8_asc(buf_back, binfo->scrnx, binfo->scrnx-100, 0, COL8_FFFFFF, "10[sec]" );sheet_refresh(sht_back, binfo->scrnx-100, 0, binfo->scrnx, 16);//putfonts8_asc(buf_back, binfo->scrnx, 0, 64, COL8_FFFFFF, "10[sec]" );//sheet_refresh(sht_back, 0, 64, 56, 80);} else if(0!=fifo8_status(&timerfifo2)) {i = fifo8_get(&timerfifo2);io_sti();putfonts8_asc(buf_back, binfo->scrnx, binfo->scrnx-100, 16, COL8_FFFFFF, "3[sec]" );sheet_refresh(sht_back, binfo->scrnx-100, 16, binfo->scrnx, 32);} else if (0!=fifo8_status(&timerfifo3)){i = fifo8_get(&timerfifo3);io_sti();if (0!=i){timer_init(timer3, &timerfifo3, 0);putfonts8_asc(buf_back, binfo->scrnx, binfo->scrnx-100, 32, COL8_FFFFFF, "1" );//boxfill8(buf_back, binfo->scrnx, COL8_FFFFFF, binfo->scrnx-92, 32, binfo->scrnx-98, 48);}else {timer_init(timer3, &timerfifo3, 1);putfonts8_asc(buf_back, binfo->scrnx, binfo->scrnx-100, 32, COL8_008484, "1" );//boxfill8(buf_back, binfo->scrnx, COL8_008484, binfo->scrnx-92, 32, binfo->scrnx-98, 48);}timer_settime(timer3, 50);sheet_refresh(sht_back, binfo->scrnx-100, 32, binfo->scrnx, 48);}}}}void make_window8(unsigned char *buf, int xsize, int ysize, char *title){static char closebtn[14][16] = {"OOOOOOOOOOOOOOO@","OQQQQQQQQQQQQQ$@","OQQQQQQQQQQQQQ$@","OQQQ@@QQQQ@@QQ$@","OQQQQ@@QQ@@QQQ$@","OQQQQQ@@@@QQQQ$@","OQQQQQQ@@QQQQQ$@","OQQQQQ@@@@QQQQ$@","OQQQQ@@QQ@@QQQ$@","OQQQ@@QQQQ@@QQ$@","OQQQQQQQQQQQQQ$@","OQQQQQQQQQQQQQ$@","O$$$$$$$$$$$$$$@","@@@@@@@@@@@@@@@@"};int x, y;char c;boxfill8(buf, xsize, COL8_C6C6C6, 0,         0,         xsize - 1, 0        );boxfill8(buf, xsize, COL8_FFFFFF, 1,         1,         xsize - 2, 1        );boxfill8(buf, xsize, COL8_C6C6C6, 0,         0,         0,         ysize - 1);boxfill8(buf, xsize, COL8_FFFFFF, 1,         1,         1,         ysize - 2);boxfill8(buf, xsize, COL8_848484, xsize - 2, 1,         xsize - 2, ysize - 2);boxfill8(buf, xsize, COL8_000000, xsize - 1, 0,         xsize - 1, ysize - 1);boxfill8(buf, xsize, COL8_C6C6C6, 2,         2,         xsize - 3, ysize - 3);boxfill8(buf, xsize, COL8_000084, 3,         3,         xsize - 4, 20       );boxfill8(buf, xsize, COL8_848484, 1,         ysize - 2, xsize - 2, ysize - 2);boxfill8(buf, xsize, COL8_000000, 0,         ysize - 1, xsize - 1, ysize - 1);putfonts8_asc(buf, xsize, 24, 4, COL8_FFFFFF, title);for (y = 0; y < 14; y++) {for (x = 0; x < 16; x++) {c = closebtn[y][x];if (c == '@') {c = COL8_000000;} else if (c == '$') {c = COL8_848484;} else if (c == 'Q') {c = COL8_C6C6C6;} else {c = COL8_FFFFFF;}buf[(5 + y) * xsize + (xsize - 21 + x)] = c;}}return;}



原创粉丝点击