2: 2005-01-28 (金) 22:21:37 |
3: 2005-01-28 (金) 22:21:37 |
| -質問とか感想とかはこめんと欄にレッツゴー。 | | -質問とか感想とかはこめんと欄にレッツゴー。 |
| | | |
- | -''(以下未編集)'' | + | *** move |
- | | + | -C版:"movec2.c" [tolset08では 681バイト] |
- | *** countdown | + | /* "movec2.c" */ |
- | -C版:"cntdwnc1.c" [osa_dir2では 617バイト] | + | /* stack:4k malloc:2k */ |
- | /* "cntdwnc1.c":countdwnをC言語で記述した例 */ | + | |
- | /* stack:4k malloc:1k */ | + | |
| | | |
| #include <guigui00.h> | | #include <guigui00.h> |
| | | |
- | #define AUTO_MALLOC 0 | + | #define AUTO_MALLOC 0 |
| + | #define REWIND_CODE 1 |
| | | |
- | void setdec3(int i, char *s); | + | static int *signalbox0, *sig_ptr; |
| + | void initsignalbox(); |
| + | int getsignal(); |
| | | |
| void OsaskMain() | | void OsaskMain() |
| struct LIB_WINDOW *window; | | struct LIB_WINDOW *window; |
| struct LIB_TEXTBOX *wintitle, *textbox; | | struct LIB_TEXTBOX *wintitle, *textbox; |
- | int count; | + | int x, y, c; |
- | static char msg[] = "000"; | + | |
| | | |
| /* ライブラリ初期化 */ | | /* ライブラリ初期化 */ |
| lib_init(AUTO_MALLOC); | | lib_init(AUTO_MALLOC); |
| + | |
| + | /* シグナルボックス初期化 */ |
| + | initsignalbox(); |
| | | |
| /* ウィンドウオープン */ | | /* ウィンドウオープン */ |
- | window = lib_openwindow(AUTO_MALLOC, 0x0200, 18 * 8, 1 * 16); | + | window = lib_openwindow(AUTO_MALLOC, 0x0200, 20 * 8, 8 * 16); |
- | wintitle = lib_opentextbox(0x1000, AUTO_MALLOC, 0, 8, 1, 0, 0, window, 0x00c0, 0); | + | wintitle = lib_opentextbox(0x1000, AUTO_MALLOC, 0, 6, 1, 0, 0, window, 0x00c0, 0); |
- | textbox = lib_opentextbox(0x0000, AUTO_MALLOC, 0, 3, 1, 56, 0, window, 0x00c0, 0); | + | textbox = lib_opentextbox(0x0001, AUTO_MALLOC, 0, 20, 8, 0, 0, window, 0x00c0, 0); |
- | lib_putstring_ASCII(0x0000, 0, 0, wintitle, 0, 0, "cntdwnc1"); | + | lib_putstring_ASCII(0x0000, 0, 0, wintitle, 0, 0, "movec2"); |
| + | |
| + | /* シグナル定義 */ |
| + | lib_definesignal1p0(3, 0x0100, 0x00ac, window, 4); /* カーソルキー(計4つ) */ |
| + | lib_definesignal1p0(0, 0x0100, ' ', window, 8); /* スペースバー */ |
| + | lib_definesignal0p0(0, 0, 0, 0); |
| + | |
| + | /* まず表示 */ |
| + | x = 9; y = 3; c = 11; |
| + | lib_putstring_ASCII(0x0000, x, y, textbox, c, 0, "O"); |
| | | |
| /* メインループ */ | | /* メインループ */ |
| for (;;) { | | for (;;) { |
- | for (count = 100; count > 0; count--) { | + | int ox = x, oy = y, oc = c; |
- | setdec3(count, msg); | + | |
- | lib_putstring_ASCII(0x0000, 0, 0, textbox, 0, 0, msg); | + | switch (getsignal()) { |
- | lib_waitsignaltime(0x0007, 0, 0, 0, 1, 0); /* 1秒待つ */ | + | case 0: |
| + | /* シグナルがないので、シグナルが来るまでスリープ */ |
| + | lib_waitsignal(0x0001, 0, 0); |
| + | continue; |
| + | |
| + | case 4 /* left */: |
| + | if (x > 0) |
| + | x--; |
| + | break; |
| + | |
| + | case 5 /* rigth */: |
| + | if (x < 19) |
| + | x++; |
| + | break; |
| + | |
| + | case 6 /* up */: |
| + | if (y > 0) |
| + | y--; |
| + | break; |
| + | |
| + | case 7 /* down */: |
| + | if (y < 7) |
| + | y++; |
| + | break; |
| + | |
| + | case 8 /* chagne */: |
| + | c = (c + 1) & 0x0f; |
| + | break; |
| + | } |
| + | |
| + | /* 何らかの変化があれば表示し直す */ |
| + | if (x != ox || y != oy || c != oc) { |
| + | lib_putstring_ASCII(0x0000, ox, oy, textbox, 0, 0, " "); |
| + | lib_putstring_ASCII(0x0000, x, y, textbox, c, 0, "O"); |
| } | | } |
- | lib_putstring_ASCII(0x0000, 0, 0, textbox, 0, 0, "GO!"); | |
- | lib_waitsignaltime(0x0007, 0, 0, 0, 10, 0); /* 10秒待つ */ | |
| } | | } |
| } | | } |
| | | |
- | void setdec3(int i, char *s) | + | void initsignalbox() |
- | /* 注意:このルーチンでは、0~999までしか扱えない */ | + | /* シグナルボックス初期化 */ |
| { | | { |
- | s[0] = '0' + i / 100; i %= 100; | + | sig_ptr = signalbox0 = lib_opensignalbox(256, AUTO_MALLOC, 0, REWIND_CODE); |
- | s[1] = '0' + i / 10; | + | |
- | s[2] = '0' + i % 10; | + | |
- | if (s[0] == '0') { | + | |
- | s[0] = ' '; | + | |
- | if (s[1] == '0') | + | |
- | s[1] = ' '; | + | |
- | } | + | |
| return; | | return; |
| } | | } |
| | | |
| + | int getsignal() |
| + | /* 0が返されたら、シグナルなし */ |
| + | { |
| + | int signal; |
| + | if (*sig_ptr == REWIND_CODE) { |
| + | /* REWINDシグナルを受け取った */ |
| + | /* 直後の値の分だけシグナルを処理したことにして、ポインタを先頭に戻す */ |
| + | lib_waitsignal(0x0000, *(sig_ptr + 1), 0); |
| + | sig_ptr = signalbox0; |
| + | } |
| + | signal = *sig_ptr; |
| + | if (signal != 0) { |
| + | sig_ptr++; |
| + | /* 1シグナル受け取ったことをライブラリに通知 */ |
| + | lib_waitsignal(0x0000, 1, 0); |
| + | } |
| + | return signal; |
| + | } |
| | | |
| + | -''(以下未編集)'' |
| -ASKA版:"cntdwna1.ask" [osa_dir2では 249バイト] | | -ASKA版:"cntdwna1.ask" [osa_dir2では 249バイト] |
| /* "cntdwna1.ask":countdwnをASKAで記述した例 */ | | /* "cntdwna1.ask":countdwnをASKAで記述した例 */ |