From 908570a673f24b1862d8bfa9cb05a44328d0de3d Mon Sep 17 00:00:00 2001 From: Yourtion Date: Fri, 13 May 2016 10:38:37 +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=881=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 25_day/Makefile | 10 +++++++++- 25_day/color.c | 27 +++++++++++++++++++++++++++ 25_day/graphic.c | 14 ++++++++++++-- 3 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 25_day/color.c diff --git a/25_day/Makefile b/25_day/Makefile index c77e73f..719005f 100644 --- a/25_day/Makefile +++ b/25_day/Makefile @@ -169,10 +169,17 @@ beepup.bim : beepup.obj a_nask.obj Makefile beepup.hrb : beepup.bim Makefile $(BIM2HRB) beepup.bim beepup.hrb 40k +color.bim : color.obj a_nask.obj Makefile + $(OBJ2BIM) @$(RULEFILE) out:color.bim stack:1k map:color.map \ + color.obj a_nask.obj + +color.hrb : color.bim Makefile + $(BIM2HRB) color.bim color.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 + lines.hrb walk.hrb noodle.hrb beepdown.hrb beepup.hrb color.hrb $(EDIMG) imgin:../z_tools/fdimg0at.tek \ wbinimg src:ipl10.bin len:512 from:0 to:0 \ copy from:haribote.sys to:@: \ @@ -195,6 +202,7 @@ haribote.img : ipl10.bin haribote.sys Makefile \ copy from:noodle.hrb to:@: \ copy from:beepdown.hrb to:@: \ copy from:beepup.hrb to:@: \ + copy from:color.hrb to:@: \ imgout:haribote.img # 其他指令 diff --git a/25_day/color.c b/25_day/color.c new file mode 100644 index 0000000..c004c14 --- /dev/null +++ b/25_day/color.c @@ -0,0 +1,27 @@ +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); + +void HariMain(void) +{ + char *buf; + int win, x, y, r, g, b; + api_initmalloc(); + buf = api_malloc(144 * 164); + win = api_openwin(buf, 144, 164, -1, "color"); + for (y = 0; y < 128; y++) { + for (x = 0; x < 128; x++) { + r = x * 2; + g = y * 2; + b = 0; + buf[(x + 8) + (y + 28) * 144] = 16 + (r / 43) + (g / 43) * 6 + (b / 43) * 36; + } + } + api_refreshwin(win, 8, 28, 136, 156); + api_getkey(1); /*等待按下任意键*/ + api_end(); +} diff --git a/25_day/graphic.c b/25_day/graphic.c index f2df123..4bd6979 100644 --- a/25_day/graphic.c +++ b/25_day/graphic.c @@ -22,10 +22,20 @@ void init_palette(void) 0x00, 0x84, 0x84, /* 14:浅暗蓝 */ 0x84, 0x84, 0x84 /* 15:暗灰 */ }; + unsigned char table2[216 * 3]; + int r, g, b; set_palette(0, 15, table_rgb); + for (b = 0; b < 6; b++) { + for (g = 0; g < 6; g++) { + for (r = 0; r < 6; r++) { + table2[(r + g * 6 + b * 36) * 3 + 0] = r * 51; + table2[(r + g * 6 + b * 36) * 3 + 1] = g * 51; + table2[(r + g * 6 + b * 36) * 3 + 2] = b * 51; + } + } + } + set_palette(16, 231, table2); return; - - /* C语言中的static char语句只能用于数据,相当于汇编中的DB指令 */ } void set_palette(int start, int end, unsigned char *rgb)