home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
FM Towns: Free Software Collection 3
/
FREEWARE.BIN
/
towns_os
/
look
/
source
/
wind.c
< prev
Wrap
Text File
|
1980-01-02
|
20KB
|
857 lines
/********************************
ウインド-型コンソ-ル
89/04/14 Make By Ken
89/04/21 VRAM Direct Sring display & Scroll
********************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <mmi.h>
#include <egb.h>
#include <mos.h>
#define PAGE0 0
#define PAGE1 0x040000
#define SHORT short int
#define UCHAR unsigned char
#define NOTBAK ((wfp->wd_mode & 0x0001) != 0)
#define TIFF ((wfp->wd_mode & 0x0002) != 0)
#define WLX wfp->wd_lx
#define WLY wfp->wd_ly
#define WRX wfp->wd_rx
#define WRY wfp->wd_ry
#define WFRA wfp->wd_fra
#define WBAK wfp->wd_bak
typedef struct wdtmp {
SHORT wd_mode;
SHORT wd_lx, wd_ly;
SHORT wd_rx, wd_ry;
char *wd_img;
struct wdtmp *wd_forwfp;
struct wdtmp *wd_nxtwfp;
SHORT wd_fntsiz;
SHORT wd_x, wd_y; /* グラフィック座標 */
SHORT wd_len;
char wd_buf[256];
SHORT wd_dx, wd_dy; /* グラフィック・表示座標 */
SHORT wd_cx, wd_cy; /* コンソ-ル座標 */
SHORT wd_mx, wd_my; /* コンソ-ル・サイズ */
SHORT wd_tab;
SHORT wd_offx;
SHORT wd_fra, wd_bak, wd_chr;
SHORT wd_valsiz;
SHORT wd_valtop;
int wd_entsiz;
int wd_bufsiz;
char *wd_bftop;
char *wd_bfbtm;
char *wd_dptop;
char *wd_dpptr;
SHORT wd_dpflg;
char wd_ttl[80];
} WINDFP;
extern void box(int x1,int y1,int x2,int y2,int col,int mode);
extern void fbox(int x1,int y1,int x2,int y2,int col,int bcol,int mode);
extern void wrtptn(char *ptn,int x,int y,int sx,int sy,int col,int bak);
extern void wrtstr(char *str,int x,int y,int font,int ccol,int bcol);
extern char *getvram(int x1,int y1,int x2,int y2);
extern void putvram(char *vram,int x1,int y1,int x2,int y2);
extern WINDFP *GRA_open(char *f,int lx,int ly,int rx,int ry,int f,int b);
extern int ofx,ofy,dspoff;
extern char *work;
extern char lftptn[],ritptn[];
static WINDFP *topwfp = NULL;
static int topsip=0;
static char upbar[]={
0xFF,0xFF,0x80,0x01,0x80,0x01,0x81,0x81,
0x83,0xC1,0x87,0xE1,0x8F,0xF1,0x9F,0xF9,
0x83,0xC1,0x83,0xC1,0x83,0xC1,0x83,0xC1,
0x83,0xC1,0x80,0x01,0x80,0x01,0xFF,0xFF };
static char downbar[]={
0xFF,0xFF,0x80,0x01,0x80,0x01,0x83,0xC1,
0x83,0xC1,0x83,0xC1,0x83,0xC1,0x83,0xC1,
0x9F,0xF9,0x8F,0xF1,0x87,0xE1,0x83,0xC1,
0x81,0x81,0x80,0x01,0x80,0x01,0xFF,0xFF };
static char dspbar[]={
0x3F,0xFC,0x40,0x02,0x80,0x01,0x80,0x01,
0x80,0x01,0x80,0x01,0x80,0x01,0x80,0x01,
0x80,0x01,0x80,0x01,0x80,0x01,0x80,0x01,
0x80,0x01,0x80,0x01,0x40,0x02,0x3F,0xFC };
static char erabar[]={
0x80,0x01,0x80,0x01,0x80,0x01,0x80,0x01,
0x80,0x01,0x80,0x01,0x80,0x01,0x80,0x01,
0x80,0x01,0x80,0x01,0x80,0x01,0x80,0x01,
0x80,0x01,0x80,0x01,0x80,0x01,0x80,0x01 };
static char closeptn[]={
0x03, 0xA0, 0x07, 0xD0, 0x03, 0xE8, 0x01, 0xF0,
0x02, 0xF8, 0x04, 0x7C, 0x08, 0xB8, 0x11, 0x10,
0x22, 0x00, 0x14, 0x00, 0x08, 0x00, 0xD3, 0xB6,
0x92, 0xA4, 0x92, 0xB6, 0x92, 0x94, 0xDB, 0xB6 };
static char menuptn[]={
0x03, 0x80, 0x0D, 0x60, 0x31, 0x18, 0x25, 0x08,
0x29, 0x08, 0x21, 0x08, 0x21, 0x08, 0x23, 0x88,
0x2C, 0x68, 0x30, 0x18, 0x00, 0x00, 0x56, 0xAA,
0x74, 0xEA, 0x76, 0xEA, 0x54, 0xEA, 0x56, 0xA4 };
static char resizeptn[]={
0xFF, 0xFF, 0xF8, 0xF9, 0xFF, 0xF9, 0x80, 0x09,
0xBF, 0x09, 0x80, 0x09, 0xBC, 0x09, 0x80, 0x09,
0x80, 0x09, 0x80, 0x09, 0x80, 0x09, 0xFF, 0xF9,
0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0xFF, 0xFF };
void WIN_bakput(wfp)
register WINDFP *wfp;
{
fbox(WLX+2,WLY+2,WRX-2,WLY+20,2,2,4);
if ( NOTBAK )
return;
MOS_disp(0);
VRAM_move(wfp->wd_dx, wfp->wd_dy,
wfp->wd_mx * 8, wfp->wd_my * wfp->wd_fntsiz,
PAGE0, PAGE1, 0, dspoff);
VRAM_clear(wfp->wd_dx, wfp->wd_dy,
wfp->wd_mx * 8, wfp->wd_my * wfp->wd_fntsiz,
0, PAGE0, 0);
MOS_disp(1);
}
void WIN_bakget(wfp)
register WINDFP *wfp;
{
fbox(WLX+2,WLY+2,WRX-2,WLY+20,2,2,4);
if ( NOTBAK )
return;
MOS_disp(0);
VRAM_move(wfp->wd_dx, wfp->wd_dy,
wfp->wd_mx * 8, wfp->wd_my * wfp->wd_fntsiz,
PAGE1, PAGE0, dspoff, 0);
VRAM_clear(wfp->wd_dx, wfp->wd_dy,
wfp->wd_mx * 8, wfp->wd_my * wfp->wd_fntsiz,
0, PAGE1, dspoff);
MOS_disp(1);
}
void VRAM_roll(wfp)
register WINDFP *wfp;
{
int i;
i = dspoff;
dspoff += wfp->wd_fntsiz; dspoff &= 0x3FFFF;
EGB_writePage(work,1);
EGB_displayStart(work,1,ofx,(ofy + dspoff) & (512 - 1));
VRAM_clear(wfp->wd_dx, wfp->wd_dy + (wfp->wd_my - 1) * wfp->wd_fntsiz,
wfp->wd_mx * 8, wfp->wd_fntsiz,
WBAK, PAGE1, dspoff);
VRAM_clear(wfp->wd_dx, wfp->wd_dy,
wfp->wd_mx * 8, wfp->wd_fntsiz,
0, PAGE1, i);
EGB_writePage(work,0);
}
void VRAM_broll(wfp)
register WINDFP *wfp;
{
int i;
i = dspoff;
dspoff -= wfp->wd_fntsiz; dspoff &= 0x3FFFF;
EGB_writePage(work,1);
EGB_displayStart(work,1,ofx,(ofy + dspoff) & (512 - 1));
VRAM_clear(wfp->wd_dx, wfp->wd_dy,
wfp->wd_mx * 8, wfp->wd_fntsiz,
WBAK, PAGE1, dspoff);
VRAM_clear(wfp->wd_dx, wfp->wd_dy + (wfp->wd_my - 1) * wfp->wd_fntsiz,
wfp->wd_mx * 8, wfp->wd_fntsiz,
0, PAGE1, i);
EGB_writePage(work,0);
}
void WIN_valmove(wfp)
register WINDFP *wfp;
{
int i,j,top;
if ( TIFF )
return;
if ( wfp->wd_entsiz == 0 )
top = 0;
else {
i = (int)wfp->wd_dptop - (int)wfp->wd_bftop;
top = i * wfp->wd_valsiz / wfp->wd_entsiz;
}
j = (WLY + 39);
if ( wfp->wd_valtop != (-1) )
wrtptn(erabar,WRX-18,wfp->wd_valtop+j,16,16,WFRA,WBAK);
wrtptn(dspbar,WRX-18,top+j,16,16,WFRA,WBAK);
wfp->wd_valtop = top;
}
void WIN_display(wfp)
register WINDFP *wfp;
{
int i;
void WIN_reprint();
fbox(WLX,WLY,WRX,WRY,WFRA,WBAK,0);
fbox(WLX+2,WLY+2,WRX-2,WLY+20,WFRA,WFRA,0);
i = WLX + (WRX - WLX) / 2 - strlen(wfp->wd_ttl) * 4;
wrtstr(wfp->wd_ttl,i,WLY+4,1,WBAK,WFRA);
wrtptn(upbar,WRX-18,WLY+22,16,16,WFRA,WBAK);
box(WRX-18,WLY+38,WRX-3,WRY-37,WFRA,0);
wrtptn(downbar,WRX-18,WRY-36,16,16,WFRA,WBAK);
wrtptn(lftptn,WLX+2,WRY-18,16,16,WFRA,WBAK);
box(WLX+18,WRY-18,WRX-37,WRY-3,WFRA,0);
wrtptn(ritptn,WRX-36,WRY-18,16,16,WFRA,WBAK);
wrtptn(resizeptn,WRX-18,WRY-18,16,16,WFRA,WBAK);
wrtptn(closeptn,WLX+5,WLY+4,16,16,WBAK,WFRA);
wrtptn(menuptn,WRX-17,WLY+4,16,16,WBAK,WFRA);
WIN_bakput(wfp);
if ( wfp->wd_entsiz > 0 )
WIN_reprint(wfp);
wfp->wd_valtop = (-1);
wfp->wd_valsiz = (WRY - 55) - (WLY + 38);
WIN_valmove(wfp);
}
char *WIN_cls(wfp)
WINDFP *wfp;
{
int i;
if ( wfp->wd_img != NULL )
free(wfp->wd_img);
WIN_bakget(wfp);
wfp->wd_img = getvram(WLX,WLY,WRX,WRY);
return wfp->wd_img;
}
void WIN_redsp(wfp)
WINDFP *wfp;
{
if ( wfp->wd_img != NULL )
putvram(wfp->wd_img,WLX,WLY,WRX,WRY);
}
int WIN_activ(wfp)
register WINDFP *wfp;
{
WINDFP *p;
if ( wfp == topwfp )
return 1;
if ( WIN_cls(topwfp) == NULL )
return 0;
if ( (p = wfp->wd_forwfp) != NULL )
p->wd_nxtwfp = wfp->wd_nxtwfp;
if ( (p = wfp->wd_nxtwfp) != NULL )
p->wd_forwfp = wfp->wd_forwfp;
topwfp->wd_nxtwfp = wfp;
wfp->wd_forwfp = topwfp;
wfp->wd_nxtwfp = NULL;
WIN_redsp(wfp);
topwfp = wfp;
if ( wfp->wd_img != NULL )
free(wfp->wd_img);
wfp->wd_img = NULL;
WIN_bakput(wfp);
return 1;
}
void WIN_alldsp(wfp)
register WINDFP *wfp;
{
WINDFP *p,*n;
for ( p = n = wfp->wd_forwfp ; p != NULL ; n = p, p = p->wd_forwfp );
EGB_writePage(work,1);
EGB_displayStart(work,1,ofx,ofy);
for ( ; n != NULL && n != wfp ; n = n->wd_nxtwfp )
WIN_redsp(n);
MOS_disp(0);
VRAM_move(WLX, WLY,
(WRX - WLX + 8) & 0xFFF8,
WRY - WLY + 1,
PAGE1, PAGE0, 0, 0);
EGB_writePage(work,0);
VRAM_allclear(PAGE1);
MOS_disp(1);
dspoff = 0;
}
WINDFP *WIN_open(ttl,file,size,mode,lx,ly,rx,ry,fra,bak,chr)
char *ttl,*file;
int size,mode;
SHORT lx,ly,rx,ry;
int fra,bak,chr;
{
FILE *fp;
register WINDFP *wfp;
if ( (wfp = GRA_open(file,lx,ly,rx,ry,fra,bak)) != NULL )
return wfp;
if ( (wfp = (WINDFP *)malloc(sizeof(WINDFP))) == NULL )
return NULL;
if ( (wfp->wd_bftop = malloc(size)) == NULL ) {
free(wfp);
return NULL;
}
if ( topwfp != NULL ) {
if ( WIN_cls(topwfp) == NULL )
return NULL;
wfp->wd_forwfp = topwfp;
topwfp->wd_nxtwfp = wfp;
} else
wfp->wd_forwfp = NULL;
wfp->wd_nxtwfp = NULL;
lx &= 0xfffe; rx &= 0xfffe;
fbox(lx,ly,rx,ry,fra,bak,0);
wfp->wd_mode = mode;
wfp->wd_fntsiz = 16;
wfp->wd_entsiz = 0; wfp->wd_bufsiz = size;
wfp->wd_bfbtm = wfp->wd_dptop = wfp->wd_dpptr = wfp->wd_bftop;
wfp->wd_img = NULL;
strcpy(wfp->wd_ttl,ttl);
if ( file != NULL && (fp = fopen(file,"r")) != NULL ) {
wfp->wd_entsiz = fread(wfp->wd_bftop,sizeof(char),size,fp);
wfp->wd_bfbtm = wfp->wd_bftop + wfp->wd_entsiz;
fclose(fp);
}
WLX = lx; WLY = ly;
WRX = rx; WRY = ry;
WFRA = fra; WBAK = bak; wfp->wd_chr = chr;
lx += 4; ly += 24;
rx -= 24; ry -= 4;
wfp->wd_cx = wfp->wd_cy = wfp->wd_len = 0;
wfp->wd_dx = lx; wfp->wd_dy = ly;
wfp->wd_mx = (rx - lx) / 8; wfp->wd_my = (ry- ly - 18) / wfp->wd_fntsiz;
wfp->wd_x = wfp->wd_dx; wfp->wd_y = wfp->wd_dy;
wfp->wd_tab = 4;
wfp->wd_offx = 0;
WIN_display(wfp);
topwfp = wfp;
return wfp;
}
WINDFP *WIN_dmyopen(lx,ly,rx,ry)
int lx,ly,rx,ry;
{
WINDFP *wfp;
if ( (wfp = (WINDFP *)malloc(sizeof(WINDFP))) == NULL )
return NULL;
if ( topwfp != NULL ) {
WIN_cls(topwfp);
wfp->wd_forwfp = topwfp;
topwfp->wd_nxtwfp = wfp;
} else
wfp->wd_forwfp = NULL;
wfp->wd_nxtwfp = NULL;
wfp->wd_mode = 0x001;
wfp->wd_img = NULL;
WLX = lx; WLY = ly;
WRX = rx; WRY = ry;
topwfp = wfp;
WIN_bakput(wfp);
return wfp;
}
void WIN_era(wfp)
WINDFP *wfp;
{
WIN_bakget(wfp);
WIN_alldsp(wfp);
}
void WIN_close(wfp)
register WINDFP *wfp;
{
WINDFP *p;
WIN_era(wfp);
if ( (p = wfp->wd_nxtwfp) != NULL )
p->wd_forwfp = wfp->wd_forwfp;
if ( (p = wfp->wd_forwfp) != NULL )
p->wd_nxtwfp = wfp->wd_nxtwfp;
if ( topwfp == wfp ) {
topwfp = wfp->wd_forwfp;
WIN_bakput(topwfp);
}
if ( wfp->wd_img != NULL )
free(wfp->wd_img);
free(wfp->wd_bftop);
free(wfp);
}
void WIN_allclose(wfp)
WINDFP *wfp;
{
WINDFP *p,*n;
for ( p = n = wfp->wd_forwfp ; p != NULL ; n = p, p = p->wd_forwfp );
for ( ; n != NULL ; n = p->wd_nxtwfp ) {
p = n;
if ( n != wfp ) {
if ( n->wd_img != NULL )
free(n->wd_img);
if ( n->wd_bftop != NULL )
free(n->wd_bftop);
free(n);
}
}
topwfp = wfp;
wfp->wd_nxtwfp = wfp->wd_forwfp = NULL;
WIN_cls(wfp);
MOS_disp(0);
VRAM_allclear(PAGE1);
VRAM_allclear(PAGE0);
MOS_disp(1);
WIN_redsp(wfp);
WIN_bakput(wfp);
}
void WIN_flush(wfp)
register WINDFP *wfp;
{
if ( wfp->wd_len > 0 ) {
wfp->wd_buf[wfp->wd_len] = '\0';
VRAM_wrtstr(wfp->wd_buf,
wfp->wd_x, wfp->wd_y, wfp->wd_fntsiz,
wfp->wd_chr, WBAK, PAGE1, dspoff);
}
wfp->wd_len = 0;
wfp->wd_x = wfp->wd_dx + wfp->wd_cx * 8;
wfp->wd_y = wfp->wd_dy + wfp->wd_cy * wfp->wd_fntsiz;
}
void WIN_scroll(wfp)
WINDFP *wfp;
{
if ( ++wfp->wd_cy >= wfp->wd_my ) {
wfp->wd_cy = wfp->wd_my -1;
WIN_flush(wfp);
VRAM_roll(wfp);
} else
WIN_flush(wfp);
}
void WIN_nxtptr(wfp)
register WINDFP *wfp;
{
int i,n;
char *p;
p = wfp->wd_dpptr;
wfp->wd_len = 0;
for ( i=0 ; i < (wfp->wd_offx + wfp->wd_mx) &&
p != wfp->wd_bfbtm && *p != '\n' ; p++ ) {
if ( *p == '\t' ) {
n = i & (wfp->wd_tab - 1);
while ( i < (wfp->wd_offx + wfp->wd_mx) && n++ < wfp->wd_tab ) {
if ( i++ >= wfp->wd_offx )
wfp->wd_buf[wfp->wd_len++] = ' ';
}
} else if ( iskanji((UCHAR)*p) && iskanji2((UCHAR)*(p+1)) ) {
p++;
if ( (i + 2) > (wfp->wd_offx + wfp->wd_mx) )
break;
if ( i++ >= wfp->wd_offx ) {
wfp->wd_buf[wfp->wd_len++] = *(p-1);
i++;
wfp->wd_buf[wfp->wd_len++] = *p;
} else {
if ( i++ >= wfp->wd_offx )
wfp->wd_buf[wfp->wd_len++] = ' ';
}
} else if ( *p != '\r' && *p != '\0' ) {
if ( i++ >= wfp->wd_offx )
wfp->wd_buf[wfp->wd_len++] = *p;
}
}
for ( ; i < 120 && p != wfp->wd_bfbtm && *p != '\n' ; i++,p++ );
if ( p != wfp->wd_bfbtm && *p == '\n' ) {
if ( *(++p) == '\r' && p != wfp->wd_bfbtm )
p++;
}
wfp->wd_dpptr = p;
}
void WIN_reprint(wfp)
register WINDFP *wfp;
{
int i;
if ( wfp->wd_mode != 0 )
return;
wfp->wd_dpptr = wfp->wd_dptop;
wfp->wd_cx = wfp->wd_len = 0;
for ( i = 0 ; i < wfp->wd_my ; i++ ) {
wfp->wd_cy = i;
WIN_flush(wfp);
WIN_nxtptr(wfp);
while ( wfp->wd_len < wfp->wd_mx )
wfp->wd_buf[wfp->wd_len++] = ' ';
}
WIN_flush(wfp);
wfp->wd_mode &= 0xFF7F;
wfp->wd_dpflg = 1;
i = (WRX - WLX - 72) * wfp->wd_offx / 120;
fbox(WLX+18,WRY-18,WRX-37,WRY-3,WFRA,WBAK,0);
wrtptn(dspbar,WLX+18+i,WRY-18,16,16,WFRA,WBAK);
}
void WIN_imgup(wfp)
register WINDFP *wfp;
{
int i;
char *p;
if ( wfp->wd_dptop == wfp->wd_bfbtm )
return;
p = wfp->wd_dpptr;
wfp->wd_dpptr = wfp->wd_dptop;
WIN_nxtptr(wfp);
wfp->wd_dptop = wfp->wd_dpptr;
if ( wfp->wd_dpflg == 0 ) {
for ( i=0 ; i < wfp->wd_my ; i++ )
WIN_nxtptr(wfp);
wfp->wd_dpflg = 1;
} else {
wfp->wd_dpptr = p;
WIN_nxtptr(wfp);
}
VRAM_roll(wfp);
wfp->wd_x = wfp->wd_dx;
wfp->wd_y = wfp->wd_dy + (wfp->wd_my - 1) * wfp->wd_fntsiz;
WIN_flush(wfp);
}
void WIN_bakptr(wfp)
register WINDFP *wfp;
{
int i;
char *p,*b;
i = 0;
if ( (b = p = wfp->wd_dpptr) == wfp->wd_bftop ) {
wfp->wd_len = 0;
return;
}
while ( --p != wfp->wd_bftop ) {
if ( *p == '\n' ) {
if ( i != 0 )
break;
i++;
}
}
if ( p != wfp->wd_bftop ) {
for ( ; p != wfp->wd_bfbtm ; p++ ) {
if ( *p != '\n' && *p != '\r' )
break;
else if ( *p == '\n' ) {
if ( i == 0 )
break;
i--;
}
}
}
wfp->wd_dpptr = p;
do {
p = wfp->wd_dpptr;
WIN_nxtptr(wfp);
} while ( wfp->wd_dpptr < b );
wfp->wd_dpptr = p;
}
void WIN_imgdown(wfp)
register WINDFP *wfp;
{
if ( wfp->wd_dptop == wfp->wd_bftop )
return;
wfp->wd_dpptr = wfp->wd_dptop;
WIN_bakptr(wfp);
wfp->wd_dptop = wfp->wd_dpptr;
VRAM_broll(wfp);
wfp->wd_x = wfp->wd_dx;
wfp->wd_y = wfp->wd_dy;
WIN_flush(wfp);
wfp->wd_dpflg = 0;
}
void WIN_move(wfp)
register WINDFP *wfp;
{
int b,x,y,sx,sy,ox,oy;
int x1,y1,x2,y2;
char *tmp;
MOS_rdpos(&b,&ox,&oy);
x1 = WLX; y1 = WLY;
x2 = WRX; y2 = WRY;
sx = WRX - WLX;
sy = WRY - WLY;
ox -= WLX; oy -= WLY;
do {
box(x1,y1,x2,y2,15,4);
do {
MOS_rdpos(&b,&x,&y);
x -= ox; y -= oy;
} while ( (b & 1) != 0 &&
x == x1 && y == y1 );
box(x1,y1,x2,y2,15,4);
if ( x < 0 ) x = 0;
if ( y < 0 ) y = 0;
if ( (x + sx) >= 1024 ) x = 1022 - sx;
if ( (y + sy) >= 512 ) y = 510 - sy;
x &= 0xfffe;
x1 = x; y1 = y; x2 = x + sx; y2 = y + sy;
} while ( (b & 1) != 0 );
WIN_bakget(wfp);
if ( (tmp = getvram(WLX,WLY,WRX,WRY)) == NULL ) {
WIN_bakput(wfp);
return;
}
WIN_alldsp(wfp);
WLX = x1; WLY = y1;
WRX = x2; WRY = y2;
if ( wfp->wd_mode == 0 ) {
wfp->wd_dx = WLX + 4;
wfp->wd_dy = WLY + 24;
wfp->wd_x = wfp->wd_dx + wfp->wd_cx * 8;
wfp->wd_y = wfp->wd_dy + wfp->wd_cy * wfp->wd_fntsiz;
}
putvram(tmp,x1,y1,x2,y2);
WIN_bakput(wfp);
free(tmp);
}
void WIN_size(wfp)
register WINDFP *wfp;
{
int b,x,y;
int x1,y1,x2,y2;
x1 = WLX;
y1 = WLY;
x2 = WRX;
y2 = WRY;
do {
box(x1,y1,x2,y2,WFRA,4);
do {
MOS_rdpos(&b,&x,&y);
} while ( (b & 1) != 0 &&
x == x2 && y == y2 );
box(x1,y1,x2,y2,WFRA,4);
x &= 0xfffe;
if ( x >= (x1 + 140) )
x2 = x;
if ( y >= (y1 + 100) )
y2 = y;
} while ( (b & 1) != 0 );
WIN_era(wfp);
WRX = x2;
WRY = y2;
if ( wfp->wd_mode == 0 ) {
wfp->wd_cx = wfp->wd_cy = wfp->wd_len = 0;
wfp->wd_mx = ((WRX - 24) - wfp->wd_dx) / 8;
wfp->wd_my = ((WRY - 4) - wfp->wd_dy - 20) / wfp->wd_fntsiz;
}
WIN_display(wfp);
}
void WIN_seek(wfp)
register WINDFP *wfp;
{
int i,j,new,od,ou;
int b,x,y,sx=0,sy=0;
MOS_rdpos(&b,&x,&y);
if ( x >= (WRX - 18) && x <= WRX &&
y >= (WLY + 36) && y <= (WRY - 38) ) {
new = (y - (WLY + 36)) * wfp->wd_entsiz / wfp->wd_valsiz;
if ( (wfp->wd_dpptr = wfp->wd_bftop + new) > wfp->wd_bfbtm )
wfp->wd_dpptr = wfp->wd_bfbtm;
WIN_bakptr(wfp);
wfp->wd_dptop = wfp->wd_dpptr;
WIN_reprint(wfp);
}
wrtmos(2);
MOS_horizon(WRX-18,WRX-8);
MOS_vertical(WLY + 20,WRY - 32);
i = j = 0;
od = ou = (int)wfp->wd_dptop - (int)wfp->wd_bftop;
do {
MOS_rdpos(&b,&x,&y);
if ( x >= (WRX - 18) && x <= WRX &&
y >= (WLY + 20) && y <= (WRY - 16) ) {
new = (y - (WLY + 36)) * wfp->wd_entsiz / wfp->wd_valsiz;
if ( new < od ) {
ou = od;
WIN_imgdown(wfp);
od = (int)wfp->wd_dptop - (int)wfp->wd_bftop;
j = 1;
} else if ( new > ou ) {
od = ou;
WIN_imgup(wfp);
ou = (int)wfp->wd_dptop - (int)wfp->wd_bftop;
j = 1;
} else if ( j != 0 ) {
WIN_valmove(wfp);
i = j = 0;
}
if ( j != 0 && i++ >= 20 ) {
WIN_valmove(wfp);
i = 0;
}
}
} while ( (b & 1) != 0 );
WIN_valmove(wfp);
MOS_horizon(0,1023);
MOS_vertical(0,511);
wrtmos(0);
}
void WIN_xseek(wfp)
register WINDFP *wfp;
{
int i;
int b,x,y;
wrtmos(2);
MOS_horizon(WLX,WRX-20);
MOS_vertical(WRY-18,WRY-2);
do {
MOS_rdpos(&b,&x,&y);
if ( x < (WLX + 18) && y >= (WRY - 18) ) {
if ( --wfp->wd_offx < 0 ) wfp->wd_offx = 0;
WIN_reprint(wfp);
} else if ( x >= (WRX - 36) && x <= (WRX - 16) && y >= (WRY-18 ) ) {
if ( ++wfp->wd_offx > 120 ) wfp->wd_offx = 120;
WIN_reprint(wfp);
} else if ( x >= (WLX + 18) && x < (WRX - 36) && y >= (WRY - 18) ) {
wfp->wd_offx = (x - WLX - 18) * 120 / (WRX - WLX - 72);
if ( wfp->wd_offx > 120 ) wfp->wd_offx = 120;
WIN_reprint(wfp);
}
} while ( (b & 1) != 0 );
MOS_horizon(0,1023);
MOS_vertical(0,511);
wrtmos(0);
}
void WIN_subcom(wfp)
WINDFP *wfp;
{
static char *menu[]={"TAB SIZE","FONT SIZE",NULL};
int i;
i = MENU_select(menu);
if ( i == 0 ) {
wfp->wd_tab = (wfp->wd_tab == 4) ? 8 : 4;
WIN_display(wfp);
} else if ( i == 1 ) {
if ( wfp->wd_fntsiz == 16 )
wfp->wd_fntsiz = 10;
else
wfp->wd_fntsiz = 16;
wfp->wd_my = (((WRY - 4) - wfp->wd_dy) - 20) / wfp->wd_fntsiz;
WIN_display(wfp);
}
}
int WIN_event(wfp)
register WINDFP *wfp;
{
int b,x,y;
WINDFP *p,*n;
MOS_rdpos(&b,&x,&y);
if ( b != 0 &&
x >= WLX && x <= WRX &&
y >= WLY && y <= WRY ) {
if ( WIN_activ(wfp) == 0 )
return (-1);
if ( TIFF )
return TIF_select(wfp);
else if ( NOTBAK )
return 7;
else if ( x <= (WLX + 16) && y <= (WLY + 16) )
return 1;
else if ( x >= (WRX - 16) && y >= (WRY - 16) )
return 2;
else if ( x >= (WRX - 16) && y <= (WLY + 16) )
return 3;
else if ( x >= (WRX - 18) )
return 4;
else if ( y <= (WLY + 20) )
return 5;
else if ( x < (WRX - 16) && y >= (WRY - 20) )
return 6;
return 7;
} else if ( (b & 2) != 0 && topwfp != NULL ) {
for ( p=n=topwfp ; p != NULL ; n=p,p=p->wd_forwfp );
if ( WIN_activ(n) == 0 )
return (-1);
}
return 0;
}
WINDFP *WIN_allevent(ev)
int *ev;
{
WINDFP *wfp;
wfp = topwfp;
while ( wfp != NULL ) {
if ( (*ev = WIN_event(wfp)) != 0 )
return wfp;
wfp = wfp->wd_forwfp;
}
return NULL;
}
int WIN_select(WINDFP *wfp,int ev)
{
switch(ev) {
case 0: return FALSE;
case 1: WIN_close(wfp); break;
case 2: WIN_size(wfp); break;
case 3: WIN_subcom(wfp); break;
case 4: WIN_seek(wfp); break;
case 5: WIN_move(wfp); break;
case 6: WIN_xseek(wfp); break;
}
return TRUE;
}
void WIN_allselect(void)
{
int i,b,x,y;
WINDFP *dmy;
while ( topwfp != NULL ) {
if ( (dmy = WIN_allevent(&i)) != NULL )
WIN_select(dmy,i);
}
}