/* "cntdwnc1.c":countdwnをC言語で記述した例 */ /* stack:4k malloc:1k */ #include <guigui00.h> #define AUTO_MALLOC 0 void setdec3(int i, char *s); void OsaskMain() { struct LIB_WINDOW *window; struct LIB_TEXTBOX *wintitle, *textbox; int count; static char msg[] = "000"; /* ライブラリ初期化 */ lib_init(AUTO_MALLOC); /* ウィンドウオープン */ window = lib_openwindow(AUTO_MALLOC, 0x0200, 18 * 8, 1 * 16); wintitle = lib_opentextbox(0x1000, AUTO_MALLOC, 0, 8, 1, 0, 0, window, 0x00c0, 0); textbox = lib_opentextbox(0x0000, AUTO_MALLOC, 0, 3, 1, 56, 0, window, 0x00c0, 0); lib_putstring_ASCII(0x0000, 0, 0, wintitle, 0, 0, "cntdwnc1"); /* メインループ */ for (;;) { for (count = 100; count > 0; count--) { setdec3(count, msg); lib_putstring_ASCII(0x0000, 0, 0, textbox, 0, 0, msg); lib_waitsignaltime(0x0007, 0, 0, 0, 1, 0); /* 1秒待つ */ } 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) /* 注意:このルーチンでは、0~999までしか扱えない */ { s[0] = '0' + i / 100; i %= 100; s[1] = '0' + i / 10; s[2] = '0' + i % 10; if (s[0] == '0') { s[0] = ' '; if (s[1] == '0') s[1] = ' '; } return; }
/* "cntdwna1.ask":countdwnをASKAで記述した例 */ /* stack:4k malloc:0k */ segment CODE(USE32, PARA); default(code == CODE); asmout("[FILE 'cntdwna1.ask']"); asmout("GLOBAL _OsaskMain"); void setdec3(); /* EAXをDS:ESIに書き込む */ void _OsaskMain() { asmout("MOV EBX,data.init"); CALL(0xc7, 0); for (;;) { unsigned int count == EAX; count = 100; do { asmout("MOV EBX,data.putnum"); LEA(ESI, [EBX + 36]); setdec3(); CALL(0xc7, 0); count--; } while (!= 0); asmout("MOV EBX,data.putgo"); CALL(0xc7, 0); } } void setdec3() { char *s == DS:ESI; PUSH(EDX); PUSH(ECX); PUSH(EAX); EDX = 0; ECX = 10; DIV(ECX); /* EDX:EAX / ECX = EAX ... EDX */ DIV(CL); /* AX / CL = AL ... AH */ EAX |= 0x3030; /* '00' */ DL |= 0x30; if (AL == 0x30) { AL = 0x20; /* ' ' */ if (AH == 0x30) AH = 0x20; } s[0] = AL; s[1] = AH; s[2] = DL; POP(EAX); POP(ECX); POP(EDX); return; } asmout("[SECTION .data]"); void data() { ALIGNB(4); init: asmout("DD 0x0004, data.work"); /* lib_init */ asmout("DD 0x0020, data.window, 0x0200, 18 * 8, 1 * 16"); /* lib_openwindow */ asmout("DD 0x0028, 0x1000, data.wintitle, 0, 8, 1, 0, 0, data.window, 0x00c0, 0"); /* lib_opentextbox */ asmout("DD 0x0028, 0x0000, data.textbox, 0, 3, 1, 56, 0, data.window, 0x00c0, 0"); /* lib_opentextbox */ asmout("DD 0x0040, 0x1000, 0, 0, data.wintitle, 0, 0, 0, 8, 'cntdwna1'"); /* lib_putstring1 */ DD(0x0000); /* end of functions */ putnum: asmout("DD 0x0040, 0x1000, 0, 0, data.textbox, 0, 0, 0, 3, '000'"); /* lib_putstring1 */ DD(0x0018, 0x0007, 0, 0, 0, 1, 0); /* lib_waitsignaltime */ DD(0x0000); /* end of functions */ putgo: asmout("DD 0x0040, 0x1000, 0, 0, data.textbox, 0, 0, 0, 3, 'GO!'"); /* lib_putstring1 */ DD(0x0018, 0x0007, 0, 0, 0, 10, 0); /* lib_waitsignaltime */ DD(0x0000); /* end of functions */ ALIGNB(8); work: RESB(256); /* func_initに必要な256バイトのワークエリア */ window: RESB(128); /* ウィンドウ構造体 */ wintitle: RESB(64); /* テキストボックス構造体 */ RESB(64); /* 8x1文字分 (8 * 1 * 8) */ textbox: RESB(64); /* テキストボックス構造体 */ RESB(24); /* 3x1文字分 (3 * 1 * 8) */ }
; "cntdwnn1.nas":countdwnをnaskで記述した例 ; stack:4k malloc:0k [FORMAT "WCOFF"] [INSTRSET "i486p"] [OPTIMIZE 1] [OPTION 1] [BITS 32] [FILE "cntdwnn1.nas"] [SECTION .text] GLOBAL _OsaskMain _OsaskMain: MOV EBX,init CALL 0xc7:0 .mainloop: MOV EAX,100 .countloop: MOV EBX,putnum LEA ESI,[EBX+36] CALL setdec3 CALL 0xc7:0 DEC EAX JNZ .countloop MOV EBX,putgo CALL 0xc7:0 JMP .mainloop setdec3: PUSH EDX PUSH ECX PUSH EAX XOR EDX,EDX MOV ECX,10 DIV ECX DIV CL OR EAX,'00' OR DL,'0' CMP AL,'0' JNE .skip MOV AL,' ' CMP AH,'0' JNE .skip MOV AH,' ' .skip: MOV [ESI+0],AL MOV [ESI+1],AH MOV [ESI+2],DL POP EAX POP ECX POP EDX RET [SECTION .data] ALIGNB 4 init: DD 0x0004, work ; lib_init DD 0x0020, window, 0x0200, 18 * 8, 1 * 16 ; lib_openwindow DD 0x0028, 0x1000, wintitle, 0, 8, 1, 0, 0, window, 0x00c0, 0 ; lib_opentextbox DD 0x0028, 0x0000, textbox, 0, 3, 1, 56, 0, window, 0x00c0, 0 ; lib_opentextbox DD 0x0040, 0x1000, 0, 0, wintitle, 0, 0, 0, 8, 'cntdwnn1' ; lib_putstring1 DD 0x0000 ; end of functions putnum: DD 0x0040, 0x1000, 0, 0, textbox, 0, 0, 0, 3, '000' ; lib_putstring1 DD 0x0018, 0x0007, 0, 0, 0, 1, 0 ; lib_waitsignaltime DD 0x0000 ; end of functions putgo: DD 0x0040, 0x1000, 0, 0, textbox, 0, 0, 0, 3, 'GO!' ; lib_putstring1 DD 0x0018, 0x0007, 0, 0, 0, 10, 0 ; lib_waitsignaltime DD 0x0000 ; end of functions ALIGNB 8 work: RESB 256 ; func_initに必要な256バイトのワークエリア window: RESB 128 ; ウィンドウ構造体 wintitle: RESB 64 + 8 * 1 * 8; テキストボックス構造体(8x1文字分) textbox: RESB 64 + 3 * 1 * 8; テキストボックス構造体(3x1文字分)
(This host) = http://osask.net