/* "movec2.c" */
/* stack:4k malloc:2k */
#include <guigui00.h>
#define AUTO_MALLOC 0
#define REWIND_CODE 1
static int *signalbox0, *sig_ptr;
void initsignalbox();
int getsignal();
void OsaskMain()
{
struct LIB_WINDOW *window;
struct LIB_TEXTBOX *wintitle, *textbox;
int x, y, c;
/* ライブラリ初期化 */
lib_init(AUTO_MALLOC);
/* シグナルボックス初期化 */
initsignalbox();
/* ウィンドウオープン */
window = lib_openwindow(AUTO_MALLOC, 0x0200, 20 * 8, 8 * 16);
wintitle = lib_opentextbox(0x1000, AUTO_MALLOC, 0, 6, 1, 0, 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, "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 (;;) {
int ox = x, oy = y, oc = c;
switch (getsignal()) {
case 0:
/* シグナルがないので、シグナルが来るまでスリープ */
lib_waitsignal(0x0001, 0, 0);
continue;
case 4 /* left */:
if (x > 0)
x--;
break;
case 5 /* right */:
if (x < 19)
x++;
break;
case 6 /* up */:
if (y > 0)
y--;
break;
case 7 /* down */:
if (y < 7)
y++;
break;
case 8 /* change */:
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");
}
}
}
void initsignalbox()
/* シグナルボックス初期化 */
{
sig_ptr = signalbox0 = lib_opensignalbox(256, AUTO_MALLOC, 0, REWIND_CODE);
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;
}
/* "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
CMP AL,16
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文字分)