@@ -3,11 +3,10 @@
# include "bootpack.h"
# include <stdio.h>
void make_window8 ( unsigned char * buf , int xsize , int ysize , char * title ) ;
void make_window8 ( unsigned char * buf , int xsize , int ysize , char * title , char act );
void putfonts8_asc_sht ( struct SHEET * sht , int x , int y , int c , int b , char * s , int l ) ;
void make_textbox8 ( struct SHEET * sht , int x0 , int y0 , int sx , int sy , int c ) ;
void task_b_main ( struct SHEET * sht_back ) ;
void task_b_main ( struct SHEET * sht_win_b ) ;
void HariMain ( void )
{
@@ -15,14 +14,11 @@ void HariMain(void)
struct FIFO32 fifo ;
char s [ 40 ] ;
int fifobuf [ 128 ] ;
struct TIMER * timer , * timer2 , * timer3 ;
int mx , my , i , cursor_x , cursor_c ;
unsigned int memtotal ;
struct MOUSE_DEC mdec ;
struct MEMMAN * memman = ( struct MEMMAN * ) MEMMAN_ADDR ;
struct SHTCTL * shtctl ;
struct SHEET * sht_back , * sht_mouse , * sht_win ;
unsigned char * buf_back , buf_mouse [ 256 ] , * buf_win ;
static char keytable [ 0x54 ] = {
0 , 0 , ' 1 ' , ' 2 ' , ' 3 ' , ' 4 ' , ' 5 ' , ' 6 ' , ' 7 ' , ' 8 ' , ' 9 ' , ' 0 ' , ' - ' , ' ^ ' , 0 , 0 ,
' Q ' , ' W ' , ' E ' , ' R ' , ' T ' , ' Y ' , ' U ' , ' I ' , ' O ' , ' P ' , ' @ ' , ' [ ' , 0 , 0 , ' A ' , ' S ' ,
@@ -31,28 +27,21 @@ void HariMain(void)
0 , 0 , 0 , 0 , 0 , 0 , 0 , ' 7 ' , ' 8 ' , ' 9 ' , ' - ' , ' 4 ' , ' 5 ' , ' 6 ' , ' + ' , ' 1 ' ,
' 2 ' , ' 3 ' , ' 0 ' , ' . '
} ;
struct TASK * task _b;
unsigned char * buf_back , buf_mouse [ 256 ] , * buf_win , * buf_win _b;
struct SHEET * sht_back , * sht_mouse , * sht_win , * sht_win_b [ 3 ] ;
struct TASK * task_a , * task_b [ 3 ] ;
struct TIMER * timer ;
init_gdtidt ( ) ;
init_pic ( ) ;
io_sti ( ) ; /* IDT/PIC的初始化已经完成, 于是开放CPU的中断 */
fifo32_init ( & fifo , 128 , fifobuf ) ;
fifo32_init ( & fifo , 128 , fifobuf , 0 );
init_pit ( ) ;
init_keyboard ( & fifo , 256 ) ;
enable_mouse ( & fifo , 512 , & mdec ) ;
io_out8 ( PIC0_IMR , 0xf8 ) ; /* 设定PIT和PIC1以及键盘为许可(11111000) */
io_out8 ( PIC1_IMR , 0xef ) ; /* 开放鼠标中断(11101111) */
timer = timer_alloc ( ) ;
timer_init ( timer , & fifo , 10 ) ;
timer_settime ( timer , 1000 ) ;
timer2 = timer_alloc ( ) ;
timer_init ( timer2 , & fifo , 3 ) ;
timer_settime ( timer2 , 300 ) ;
timer3 = timer_alloc ( ) ;
timer_init ( timer3 , & fifo , 1 ) ;
timer_settime ( timer3 , 50 ) ;
memtotal = memtest ( 0x00400000 , 0xbfffffff ) ;
memman_init ( memman ) ;
memman_free ( memman , 0x00001000 , 0x0009e000 ) ; /* 0x00001000 - 0x0009efff */
@@ -60,51 +49,77 @@ void HariMain(void)
init_palette ( ) ;
shtctl = shtctl_init ( memman , binfo - > vram , binfo - > scrnx , binfo - > scrny ) ;
task_a = task_init ( memman ) ;
fifo . task = task_a ;
/* sht_back */
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 ) ; /* 透明色号99 */
sheet_setbuf ( sht_win , buf_win , 160 , 52 , - 1 ) ; /* 没有透明色 */
sheet_setbuf ( sht_back , buf_back , binfo - > scrnx , binfo - > scrny , - 1 ) ; /* 无透明色 */
init_screen8 ( buf_back , binfo - > scrnx , binfo - > scrny ) ;
init_mouse_cursor8 ( buf_mouse , 99 ) ; /* 背景色号99 */
make_window8 ( buf_win , 160 , 52 , " window " ) ;
make_textbox8 ( sht_win , 8 , 28 , 144 , 16 , COL8_FFFFFF ) ;
/* sht_win_b */
for ( i = 0 ; i < 3 ; i + + ) {
sht_win_b [ i ] = sheet_alloc ( shtctl ) ;
buf_win_b = ( unsigned char * ) memman_alloc_4k ( memman , 144 * 52 ) ;
sheet_setbuf ( sht_win_b [ i ] , buf_win_b , 144 , 52 , - 1 ) ; /* 无透明色 */
sprintf ( s , " task_b%d " , i ) ;
make_window8 ( buf_win_b , 144 , 52 , s , 0 ) ;
task_b [ i ] = task_alloc ( ) ;
task_b [ i ] - > tss . esp = memman_alloc_4k ( memman , 64 * 1024 ) + 64 * 1024 - 8 ;
task_b [ i ] - > tss . eip = ( int ) & task_b_main ;
task_b [ i ] - > tss . es = 1 * 8 ;
task_b [ i ] - > tss . cs = 2 * 8 ;
task_b [ i ] - > tss . ss = 1 * 8 ;
task_b [ i ] - > tss . ds = 1 * 8 ;
task_b [ i ] - > tss . fs = 1 * 8 ;
task_b [ i ] - > tss . gs = 1 * 8 ;
* ( ( int * ) ( task_b [ i ] - > tss . esp + 4 ) ) = ( int ) sht_win_b [ i ] ;
task_run ( task_b [ i ] ) ;
}
/* sht_win */
sht_win = sheet_alloc ( shtctl ) ;
buf_win = ( unsigned char * ) memman_alloc_4k ( memman , 160 * 52 ) ;
sheet_setbuf ( sht_win , buf_win , 144 , 52 , - 1 ) ; /* 无透明色 */
make_window8 ( buf_win , 144 , 52 , " task_a " , 1 ) ;
make_textbox8 ( sht_win , 8 , 28 , 128 , 16 , COL8_FFFFFF ) ;
cursor_x = 8 ;
cursor_c = COL8_FFFFFF ;
sheet_slide ( sht_back , 0 , 0 ) ;
mx = ( binfo - > scrnx - 16 ) / 2 ; /* 按显示在画面中央来计算坐标 */
timer = timer_alloc ( ) ;
timer_init ( timer , & fifo , 1 ) ;
timer_settime ( timer , 50 ) ;
/* sht_mouse */
sht_mouse = sheet_alloc ( shtctl ) ;
sheet_setbuf ( sht_mouse , buf_mouse , 16 , 16 , 99 ) ;
init_mouse_cursor8 ( buf_mouse , 99 ) ;
mx = ( binfo - > scrnx - 16 ) / 2 ; /* 计算坐标使其位于画面中央 */
my = ( binfo - > scrny - 28 - 16 ) / 2 ;
sheet_slide ( sht_back , 0 , 0 ) ;
sheet_slide ( sht_win_b [ 0 ] , 168 , 56 ) ;
sheet_slide ( sht_win_b [ 1 ] , 8 , 116 ) ;
sheet_slide ( sht_win_b [ 2 ] , 168 , 116 ) ;
sheet_slide ( sht_win , 8 , 56 ) ;
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 ) ;
sheet_updown ( sht_back , 0 ) ;
sheet_updown ( sht_win_b [ 0 ] , 1 ) ;
sheet_updown ( sht_win_b [ 1 ] , 2 ) ;
sheet_updown ( sht_win_b [ 2 ] , 3 ) ;
sheet_updown ( sht_win , 4 ) ;
sheet_updown ( sht_mouse , 5 ) ;
sprintf ( s , " (%3d, %3d) " , mx , my ) ;
putfonts8_asc_sht ( sht_back , 0 , 0 , COL8_FFFFFF , COL8_008484 , s , 10 ) ;
sprintf ( s , " memory %dMB free : %dKB " ,
memtotal / ( 1024 * 1024 ) , memman_total ( memman ) / 1024 ) ;
putfonts8_asc_sht ( sht_back , 0 , 32 , COL8_FFFFFF , COL8_008484 , s , 40 ) ;
task_init ( memman ) ;
task_b = task_alloc ( ) ;
task_b - > tss . esp = memman_alloc_4k ( memman , 64 * 1024 ) + 64 * 1024 - 8 ;
task_b - > tss . eip = ( int ) & task_b_main ;
task_b - > tss . es = 1 * 8 ;
task_b - > tss . cs = 2 * 8 ;
task_b - > tss . ss = 1 * 8 ;
task_b - > tss . ds = 1 * 8 ;
task_b - > tss . fs = 1 * 8 ;
task_b - > tss . gs = 1 * 8 ;
* ( ( int * ) ( task_b - > tss . esp + 4 ) ) = ( int ) sht_back ;
task_run ( task_b ) ;
for ( ; ; ) {
io_cli ( ) ;
if ( fifo32_status ( & fifo ) = = 0 ) {
io_stihlt ( ) ;
task_sleep ( task_a ) ;
io_sti ( ) ;
} else {
i = fifo32_get ( & fifo ) ;
io_sti ( ) ;
@@ -112,7 +127,7 @@ void HariMain(void)
sprintf ( s , " %02X " , i - 256 ) ;
putfonts8_asc_sht ( sht_back , 0 , 16 , COL8_FFFFFF , COL8_008484 , s , 2 ) ;
if ( i < 0x54 + 256 ) {
if ( keytable [ i - 256 ] ! = 0 & & cursor_x < 144 ) {
if ( keytable [ i - 256 ] ! = 0 & & cursor_x < 128 ) {
s [ 0 ] = keytable [ i - 256 ] ;
s [ 1 ] = 0 ;
putfonts8_asc_sht ( sht_win , cursor_x , 28 , COL8_000000 , COL8_FFFFFF , s , 1 ) ;
@@ -163,19 +178,15 @@ void HariMain(void)
sheet_slide ( sht_win , mx - 80 , my - 8 ) ;
}
}
} else if ( i = = 10 ) { /* 10秒定时器 */
putfonts8_asc_sht ( sht_back , 0 , 64 , COL8_FFFFFF , COL8_008484 , " 10[sec] " , 7 ) ;
} else if ( i = = 3 ) { /* 3秒定时器 */
putfonts8_asc_sht ( sht_back , 0 , 80 , COL8_FFFFFF , COL8_008484 , " 3[sec] " , 6 ) ;
} else if ( i < = 1 ) { /* 光标用定时器*/
if ( i ! = 0 ) {
timer_init ( timer3 , & fifo , 0 ) ; /* 下面设定0 */
timer_init ( timer , & fifo , 0 ) ; /* 下面设定0 */
cursor_c = COL8_000000 ;
} else {
timer_init ( timer3 , & fifo , 1 ) ; /* 下面设定1 */
timer_init ( timer , & fifo , 1 ) ; /* 下面设定1 */
cursor_c = COL8_FFFFFF ;
}
timer_settime ( timer3 , 50 ) ;
timer_settime ( timer , 50 ) ;
boxfill8 ( sht_win - > buf , sht_win - > bxsize , cursor_c , cursor_x , 28 , cursor_x + 7 , 43 ) ;
sheet_refresh ( sht_win , cursor_x , 28 , cursor_x + 8 , 44 ) ;
}
@@ -183,7 +194,7 @@ void HariMain(void)
}
}
void make_window8 ( unsigned char * buf , int xsize , int ysize , char * title )
void make_window8 ( unsigned char * buf , int xsize , int ysize , char * title , char act )
{
static char closebtn [ 14 ] [ 16 ] = {
" OOOOOOOOOOOOOOO@ " ,
@@ -202,7 +213,14 @@ void make_window8(unsigned char *buf, int xsize, int ysize, char *title)
" @@@@@@@@@@@@@@@@ "
} ;
int x , y ;
char c ;
char c , tc , tbc ;
if ( act ! = 0 ) {
tc = COL8_FFFFFF ;
tbc = COL8_000084 ;
} else {
tc = COL8_C6C6C6 ;
tbc = COL8_848484 ;
}
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 ) ;
@@ -210,10 +228,10 @@ void make_window8(unsigned char *buf, int xsize, int ysize, char *title)
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 , tbc , 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 ) ;
putfonts8_asc ( buf , xsize , 24 , 4 , tc , title ) ;
for ( y = 0 ; y < 14 ; y + + ) {
for ( x = 0 ; x < 16 ; x + + ) {
c = closebtn [ y ] [ x ] ;
@@ -251,21 +269,18 @@ void make_textbox8(struct SHEET *sht, int x0, int y0, int sx, int sy, int c)
boxfill8 ( sht - > buf , sht - > bxsize , COL8_000000 , x0 - 2 , y0 - 2 , x0 - 2 , y1 + 0 ) ;
boxfill8 ( sht - > buf , sht - > bxsize , COL8_C6C6C6 , x0 - 2 , y1 + 1 , x1 + 0 , y1 + 1 ) ;
boxfill8 ( sht - > buf , sht - > bxsize , COL8_C6C6C6 , x1 + 1 , y0 - 2 , x1 + 1 , y1 + 1 ) ;
boxfill8 ( sht - > buf , sht - > bxsize , c , x0 - 1 , y0 - 1 , x1 + 0 , y1 + 0 ) ;
boxfill8 ( sht - > buf , sht - > bxsize , c , x0 - 1 , y0 - 1 , x1 + 0 , y1 + 0 ) ;
return ;
}
void task_b_main ( struct SHEET * sht_back )
void task_b_main ( struct SHEET * sht_win_b )
{
struct FIFO32 fifo ;
struct TIMER * timer_put , * timer_ 1s ;
struct TIMER * timer_1s ;
int i , fifobuf [ 128 ] , count = 0 , count0 = 0 ;
char s [ 12 ] ;
fifo32_init ( & fifo , 128 , fifobuf ) ;
timer_put = timer_alloc ( ) ;
timer_init ( timer_put , & fifo , 1 ) ;
timer_settime ( timer_put , 1 ) ;
fifo32_init ( & fifo , 128 , fifobuf , 0 );
timer_1s = timer_alloc ( ) ;
timer_init ( timer_1s , & fifo , 100 ) ;
timer_settime ( timer_1s , 100 ) ;
@@ -278,13 +293,9 @@ void task_b_main(struct SHEET *sht_back)
} else {
i = fifo32_get ( & fifo ) ;
io_sti ( ) ;
if ( i = = 1 ) {
sprintf ( s , " %11d " , count ) ;
putfonts8_asc_sht ( sht_back , 0 , 144 , COL8_FFFFFF , COL8_008484 , s , 11 ) ;
timer_settime ( timer_put , 1 ) ;
} else if ( i = = 100 ) {
if ( i = = 100 ) {
sprintf ( s , " %11d " , count - count0 ) ;
putfonts8_asc_sht ( sht_back , 0 , 1 28, COL8_FFFFFF , COL8_008484 , s , 11 ) ;
putfonts8_asc_sht ( sht_win_b , 24 , 28 , COL8_000000 , COL8_C6C6C6 , s , 11 ) ;
count0 = count ;
timer_settime ( timer_1s , 100 ) ;
}