/*------------------------------------------------------ ww_expand.c WonderWitchでビットマップ拡大をしてみるテスト LSI-C(16bit?)でコンパイル確認。 ブレゼンハム使用 ■PEACE CODE さ〜 ::sanami@aya.or.jp ::http://webs.to/D5./ ------------------------------------------------------*/ #include #include #include /* これがないときついっす */ #define WORD unsigned short /* 拡大速度 */ #define ZOOM_SPEED 3 /* バナー */ #include "Coder.h" /* FPS表示用 */ #include "Num.h" /* 転送元バッファサイズ */ #define WIDTH 256 #define HEIGHT 40 #define CHAR_WIDTH (WIDTH/8) #define CHAR_HEIGHT (HEIGHT/8) /* 表示サイズ */ #define WIN_WIDTH (128/8) #define WIN_HEIGHT (40/8) /* クリア用キャラクタ */ #define CLEAR_CHAR ((CHAR_WIDTH * CHAR_HEIGHT) + (num_WIDTH * num_HEIGHT) -1) /* FPSの文字 */ #define FPS_CHAR (CLEAR_CHAR -2) /* 小数点 */ #define POINT_CHAR (FPS_CHAR -1) /* 数字0 */ #define NUM_CHAR (CHAR_WIDTH * CHAR_HEIGHT) /* 転送元バッファ */ static WORD tempBuf[WIDTH * HEIGHT]; /* インラインアセンブラ用ダミー定義 */ void _asm_expand_first(char *, WORD, WORD, WORD); void _asm_expand(char *); WORD _asm_expand_return(char *); WORD _asm_expand_gett(char *, WORD); void main(void) { WORD dx, dy, cnt, sy; WORD yIndex; int sx; int i, j; int key; WORD prev = 0; /*ディスプレイ設定*/ display_control(0); /* SPR/SCR2/SCR1 ALL OFF */ /*スクロール値初期化*/ screen_set_scroll(SCREEN1, 0, 0); screen_set_scroll(SCREEN2, 0, 0); /*0番からbmpを割り当て*/ font_set_colordata(NUM_CHAR, num_WIDTH, bmp_num); /*まず、画面全体をクリア(0番のキャラでフィル)*/ screen_fill_char(SCREEN1, 0, 0, 32, 32, CLEAR_CHAR); /* 画面中央にバナー表示 */ cnt = 0; sx = (28 -WIN_WIDTH)/2; sy = (18 -WIN_HEIGHT)/2; for(dy = sy; dy < sy +WIN_HEIGHT; dy ++) for(dx = sx; dx < sx +WIN_WIDTH; dx ++) screen_fill_char(SCREEN1, dx, dy, 1, 1, cnt++); /* 画面右下にFPS表示 */ screen_fill_char(SCREEN1, 22, 17, 1, 1, NUM_CHAR); screen_fill_char(SCREEN1, 23, 17, 1, 1, NUM_CHAR); screen_fill_char(SCREEN1, 24, 17, 1, 1, POINT_CHAR); screen_fill_char(SCREEN1, 25, 17, 1, 1, NUM_CHAR); screen_fill_char(SCREEN1, 26, 17, 1, 1, FPS_CHAR); screen_fill_char(SCREEN1, 27, 17, 1, 1, FPS_CHAR +1); /* 転送元バッファをクリア */ memset(tempBuf, 0, WIDTH * HEIGHT * sizeof(WORD)); /* 転送元バッファへ展開 */ cnt = 0; /* 展開するキャラクタカウンタ */ sx = (WIDTH - coder_WIDTH*8)/2; /* 転送元バッファ左端 */ sy = (HEIGHT - coder_HEIGHT*8)/2; /* 転送元バッファ上端 */ for (dy = 0; dy < coder_HEIGHT; dy++) { for (dx = 0; dx < coder_WIDTH; dx++) { WORD c = dy * coder_WIDTH + dx; /* 展開するキャラクタ */ for(j = 0; j < 8; j ++) { WORD t = bmp_coder[c*8 + j]; /* 展開するライン */ for(i = 0; i < 8; i ++) { tempBuf[dx*8 +sx +i +(dy*8 +sy +j) *WIDTH] = (((t & 0x8080) >> 7) + 0x7f7f) ^ 0x7f7f; t <<= 1; } } } } /*LCD階調データ初期化*/ lcd_set_color(0x6420,0xfca8); /*パレット初期化*/ palette_set_color(0, 0x7531); /*ディスプレイ設定*/ display_control(DCM_SCR1); prev = (WORD)sys_get_tick_count( ); do { static int ratio = 0x100; /* 拡大率 */ static int mv = -ZOOM_SPEED; /* 拡大速度 */ static int count = 1; /* FPS計測用 */ /* キー入力処理 */ key = key_press_check( ); if(key == KEY_START) break; /* 拡大レート変更処理 */ ratio += mv; if(ratio < 0x010) mv = ZOOM_SPEED; if(ratio > 0x100) { mv = -ZOOM_SPEED; ratio = 0x100; } cnt = 0; yIndex = 0; for(dy = 0; dy < WIN_HEIGHT; dy ++) { WORD ty, bx; sx = - ratio; /* 横方向のブレゼンハムの計数初期化 */ bx = ((WIDTH/2)<<8) - ((WIN_WIDTH/2*8) * ratio); /* 左端の位置を求める */ bx >>= 8; ty = yIndex; for(dx = 0; dx < WIN_WIDTH; dx ++) { WORD t[8]; WORD btx, pixel, write; /* 縦8ラインを処理するので、ブレゼンハムの計数を保存 */ short tx; tx = sx; btx = bx; yIndex = ty; for(j = 0; j < 8; j ++) { sx = tx; /* 保存しておいた計数を復帰 */ bx = btx; _asm_expand_first("", sx, bx +yIndex, ratio); /* 最初のピクセルを読み込み */ _asm_expand("push di\npush si\npush dx\n"); _asm_expand("shl bx, 1\n"); _asm_expand("mov si, [_tempBuf + bx]\n"); _asm_expand("and si, 0x8080\n"); _asm_expand("mov di, si\n"); /* 2 */ _asm_expand("add ax, cx\n"); /* 0x100 == ratio -> コード書き換えしてください */ _asm_expand("js expand_label_2\n"); _asm_expand("add bx, 2\n"); _asm_expand("sub ax, 0x100\n"); /* 0x100 == 転送元幅 */ _asm_expand("mov di, [_tempBuf + bx]\n"); _asm_expand("and di, 0x8080\n"); _asm_expand("expand_label_2:\n"); _asm_expand("shr di, 1\n"); _asm_expand("or si, di\n"); /* 3 */ _asm_expand("add ax, cx\n"); /* 0x100 == ratio -> コード書き換えしてください */ _asm_expand("js expand_label_3\n"); _asm_expand("add bx, 2\n"); _asm_expand("sub ax, 0x100\n"); /* 0x100 == 転送元幅 */ _asm_expand("mov di, [_tempBuf + bx]\n"); _asm_expand("and di, 0x4040\n"); _asm_expand("expand_label_3:\n"); _asm_expand("shr di, 1\n"); _asm_expand("or si, di\n"); /* 4 */ _asm_expand("add ax, cx\n"); /* 0x100 == ratio -> コード書き換えしてください */ _asm_expand("js expand_label_4\n"); _asm_expand("add bx, 2\n"); _asm_expand("sub ax, 0x100\n"); /* 0x100 == 転送元幅 */ _asm_expand("mov di, [_tempBuf + bx]\n"); _asm_expand("and di, 0x2020\n"); _asm_expand("expand_label_4:\n"); _asm_expand("shr di, 1\n"); _asm_expand("or si, di\n"); /* 5 */ _asm_expand("add ax, cx\n"); /* 0x100 == ratio -> コード書き換えしてください */ _asm_expand("js expand_label_5\n"); _asm_expand("add bx, 2\n"); _asm_expand("sub ax, 0x100\n"); /* 0x100 == 転送元幅 */ _asm_expand("mov di, [_tempBuf + bx]\n"); _asm_expand("and di, 0x1010\n"); _asm_expand("expand_label_5:\n"); _asm_expand("shr di, 1\n"); _asm_expand("or si, di\n"); /* 6 */ _asm_expand("add ax, cx\n"); /* 0x100 == ratio -> コード書き換えしてください */ _asm_expand("js expand_label_6\n"); _asm_expand("add bx, 2\n"); _asm_expand("sub ax, 0x100\n"); /* 0x100 == 転送元幅 */ _asm_expand("mov di, [_tempBuf + bx]\n"); _asm_expand("and di, 0x0808\n"); _asm_expand("expand_label_6:\n"); _asm_expand("shr di, 1\n"); _asm_expand("or si, di\n"); /* 7 */ _asm_expand("add ax, cx\n"); /* 0x100 == ratio -> コード書き換えしてください */ _asm_expand("js expand_label_7\n"); _asm_expand("add bx, 2\n"); _asm_expand("sub ax, 0x100\n"); /* 0x100 == 転送元幅 */ _asm_expand("mov di, [_tempBuf + bx]\n"); _asm_expand("and di, 0x0404\n"); _asm_expand("expand_label_7:\n"); _asm_expand("shr di, 1\n"); _asm_expand("or si, di\n"); /* 8 */ _asm_expand("add ax, cx\n"); /* 0x100 == ratio -> コード書き換えしてください */ _asm_expand("js expand_label_8\n"); _asm_expand("add bx, 2\n"); _asm_expand("sub ax, 0x100\n"); /* 0x100 == 転送元幅 */ _asm_expand("mov di, [_tempBuf + bx]\n"); _asm_expand("and di, 0x0202\n"); _asm_expand("expand_label_8:\n"); _asm_expand("shr di, 1\n"); _asm_expand("or si, di\n"); sx = _asm_expand_return(""); bx = _asm_expand_return("mov ax, bx\nshr ax, 1\n") - yIndex; t[j] = _asm_expand_return("mov ax, si\npop dx\npop si\npop di\n"); yIndex += 0x100; } font_set_colordata(cnt ++, 1, (char far*)t); } } /* FPSを表示 */ if((count & 63) == 0) { WORD current, num; current = (WORD)sys_get_tick_count( ); num = 10*(75*64) / (current - prev); screen_fill_char(SCREEN1, 25, 17, 1, 1, NUM_CHAR + (num%10)); num /= 10; screen_fill_char(SCREEN1, 23, 17, 1, 1, NUM_CHAR + (num%10)); num /= 10; screen_fill_char(SCREEN1, 22, 17, 1, 1, NUM_CHAR + (num%10)); count = 0; prev = current; } /* sys_wait(1);*/ count ++; } while(TRUE); }