From c8a0464c520d7dac3f2f7294b52526ce41a8febd Mon Sep 17 00:00:00 2001 From: Yourtion Date: Fri, 13 May 2016 10:45:55 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=9B=B4=E5=A4=9A=E7=9A=84?= =?UTF-8?q?=E9=A2=9C=E8=89=B2=EF=BC=882=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 25_day/Makefile | 10 +++++++++- 25_day/color2.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 25_day/color2.c diff --git a/25_day/Makefile b/25_day/Makefile index 719005f..a53ff0f 100644 --- a/25_day/Makefile +++ b/25_day/Makefile @@ -176,10 +176,17 @@ color.bim : color.obj a_nask.obj Makefile color.hrb : color.bim Makefile $(BIM2HRB) color.bim color.hrb 56k +color2.bim : color2.obj a_nask.obj Makefile + $(OBJ2BIM) @$(RULEFILE) out:color2.bim stack:1k map:color2.map \ + color2.obj a_nask.obj + +color2.hrb : color2.bim Makefile + $(BIM2HRB) color2.bim color2.hrb 56k + haribote.img : ipl10.bin haribote.sys Makefile \ hello.hrb hello2.hrb a.hrb hello3.hrb hello4.hrb hello5.hrb \ winhelo.hrb winhelo2.hrb winhelo3.hrb star1.hrb stars.hrb stars2.hrb \ - lines.hrb walk.hrb noodle.hrb beepdown.hrb beepup.hrb color.hrb + lines.hrb walk.hrb noodle.hrb beepdown.hrb beepup.hrb color.hrb color2.hrb $(EDIMG) imgin:../z_tools/fdimg0at.tek \ wbinimg src:ipl10.bin len:512 from:0 to:0 \ copy from:haribote.sys to:@: \ @@ -203,6 +210,7 @@ haribote.img : ipl10.bin haribote.sys Makefile \ copy from:beepdown.hrb to:@: \ copy from:beepup.hrb to:@: \ copy from:color.hrb to:@: \ + copy from:color2.hrb to:@: \ imgout:haribote.img # 其他指令 diff --git a/25_day/color2.c b/25_day/color2.c new file mode 100644 index 0000000..c063768 --- /dev/null +++ b/25_day/color2.c @@ -0,0 +1,42 @@ +int api_openwin(char *buf, int xsiz, int ysiz, int col_inv, char *title); +void api_initmalloc(void); +char *api_malloc(int size); +void api_refreshwin(int win, int x0, int y0, int x1, int y1); +void api_linewin(int win, int x0, int y0, int x1, int y1, int col); +int api_getkey(int mode); +void api_end(void); + +unsigned char rgb2pal(int r, int g, int b, int x, int y); + +void HariMain(void) +{ + char *buf; + int win, x, y; + api_initmalloc(); + buf = api_malloc(144 * 164); + win = api_openwin(buf, 144, 164, -1, "color2"); + for (y = 0; y < 128; y++) { + for (x = 0; x < 128; x++) { + buf[(x + 8) + (y + 28) * 144] = rgb2pal(x * 2, y * 2, 0, x, y); + } + } + api_refreshwin(win, 8, 28, 136, 156); + api_getkey(1); /*等待按下任意键*/ + api_end(); +} + +unsigned char rgb2pal(int r, int g, int b, int x, int y) +{ + static int table[4] = { 3, 1, 0, 2 }; + int i; + x &= 1; /*判断是偶数还是奇数*/ + y &= 1; + i = table[x + y * 2]; /*用来生成中间色的常量*/ + r = (r * 21) / 256; /* r为0~20*/ + g = (g * 21) / 256; + b = (b * 21) / 256; + r = (r + i) / 4; /* r为0~5*/ + g = (g + i) / 4; + b = (b + i) / 4; + return 16 + r + g * 6 + b * 36; +}