📄 windos.c
字号:
/*
Routines which simulate DOS functions in the existing
Fractint for DOS
*/
#include "windows.h"
#include "drivinit.h"
#include "fractint.h"
#include "winfract.h"
#include <string.h>
#include <time.h>
#include <stdarg.h>
#include <stdio.h>
#ifndef TIMERINFO
/* define TIMERINFO stuff, if needs be */
typedef struct tagTIMERINFO {
DWORD dwSize;
DWORD dwmsSinceStart;
DWORD dwmsThisVM;
} TIMERINFO;
BOOL far pascal TimerCount(TIMERINFO FAR *);
#endif
int stopmsg(int ,CHAR far *);
int farread(int, LPSTR, WORD);
int farwrite(int, LPSTR, WORD);
extern unsigned char FullPathName[];
extern int FileFormat;
int save_system; /* tag identifying Fractint for Windows */
int save_release; /* tag identifying version number */
extern int win_release; /* tag identifying version number (in WINDOS2.C) */
extern BOOL bTrack, bMove; /* TRUE if user is selecting a region */
extern BOOL zoomflag; /* TRUE is a zoom-box selected */
extern HWND hwnd; /* handle to main window */
extern HANDLE hInst;
extern HANDLE hAccTable; /* handle to accelerator table */
extern char szHelpFileName[]; /* Help file name*/
extern int xdots, ydots, colors, maxiter;
extern int xposition, yposition, win_xoffset, win_yoffset, xpagesize, ypagesize;
extern int win_xdots, win_ydots;
extern int last_written_y; /* last line written */
extern int screen_to_be_cleared; /* clear screen flag */
extern int time_to_act; /* time to take some action? */
extern int time_to_restart; /* time to restart? */
extern int time_to_resume; /* time to resume? */
extern int time_to_quit; /* time to quit? */
extern int time_to_reinit; /* time to reinitialize? */
extern int time_to_load; /* time to load? (DECODE) */
extern int time_to_save; /* time to save? (ENCODE) */
extern int time_to_print; /* time to print? (PRINTER) */
extern int time_to_cycle; /* time to begin color-cycling? */
extern int time_to_starfield; /* time to make a starfield? */
extern int time_to_orbit; /* time to activate orbits? */
extern unsigned char dacbox[256][3];
extern BOOL win_systempaletteused; /* flag system palette set */
extern unsigned char far temp_array[]; /* temporary spot for Encoder rtns */
extern HANDLE hpixels; /* handle to the DIB pixels */
extern unsigned char huge *pixels; /* the device-independent bitmap pixels */
int pixels_per_byte; /* pixels/byte in the pixmap */
long pixels_per_bytem1; /* pixels / byte - 1 (for ANDing) */
int pixelshift_per_byte; /* 0, 1, 2, or 3 */
int bytes_per_pixelline; /* pixels/line / pixels/byte */
long win_bitmapsize; /* bitmap size, in bytes */
extern int win_overlay3d;
extern int win_display3d;
BOOL dont_wait_for_a_key = TRUE;
#ifdef __BORLANDC__
/* Too many functions defaulting to a type 'int' return that should be
a type 'void'. I'll just get rid of the warning message for this file
only. MCP 8-6-91 */
#pragma warn -rvl
int LPTNumber;
int stackavail() { return(10240 + (signed int)_SP); }
#else
int printf() {}
int _bios_serialcom(){}
#endif
extern int far wintext_textmode, far wintext_AltF4hit;
int getakey()
{
int i;
if (time_to_orbit) { /* activate orbits? */
zoomflag = FALSE;
time_to_orbit = 0;
i = 'o';
return(i);
}
dont_wait_for_a_key = FALSE;
i = keypressed();
dont_wait_for_a_key = TRUE;
zoomflag = FALSE;
return(i);
}
int keypressed()
{
MSG msg;
int time_to;
/* is a text-mode screen active? */
if (wintext_textmode == 2 || wintext_AltF4hit) {
if (dont_wait_for_a_key)
return(fractint_getkeypress(0));
else
return(fractint_getkeypress(1));
}
if (dont_wait_for_a_key)
if (PeekMessage(&msg, NULL, NULL, NULL, PM_NOREMOVE) == 0) {
time_to = time_to_act + time_to_reinit+time_to_restart+time_to_quit+
time_to_load+time_to_save+time_to_print+time_to_cycle+
time_to_resume+time_to_starfield;
if (time_to_orbit) { /* activate orbits? */
time_to = 'o';
}
/* bail out if nothing is happening */
return(time_to);
}
while (GetMessage(&msg, NULL, NULL, NULL)) {
if (!TranslateAccelerator(hwnd, hAccTable, &msg)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
CheckMathTools();
if (!bTrack && !bMove) { /* don't do this if mouse-button is down */
time_to = time_to_act+time_to_reinit+time_to_restart+time_to_quit+
time_to_load+time_to_save+time_to_print+time_to_cycle+
time_to_starfield;
if (time_to_orbit) { /* activate orbits? */
time_to = 'o';
}
if (dont_wait_for_a_key || time_to)
return(time_to);
}
}
if (!dont_wait_for_a_key)
time_to_quit = 1;
/* bail out if nothing is happening */
time_to = time_to_act+time_to_reinit+time_to_restart+time_to_quit+
time_to_load+time_to_save+time_to_print+time_to_cycle;
if (time_to_orbit) { /* activate orbits? */
time_to = 'o';
}
return(time_to);
}
int farread(int handle, LPSTR buf, WORD len)
{
int i;
i = _lread(handle, buf, len);
return(i);
}
int farwrite(int handle, LPSTR buf, WORD len)
{
return(_lwrite(handle, buf, len));
}
extern int win_fastupdate;
time_t last_time;
time_t update_time;
long minimum_update;
long pixelsout;
int top_changed, bottom_changed;
/* Made global, MCP 6-16-91 */
unsigned char win_andmask[8];
unsigned char win_notmask[8];
unsigned char win_bitshift[8];
void putcolor(int x, int y, int color)
{
RECT tempRect; /* temporary rectangle structure */
long i;
int temp_top_changed, temp_bottom_changed;
time_t this_time;
last_written_y = y;
if (y < top_changed) top_changed = y;
if (y > bottom_changed) bottom_changed = y;
i = win_ydots-1-y;
i = (i * win_xdots) + x;
if (x >= 0 && x < xdots && y >= 0 && y < ydots) {
if (pixelshift_per_byte == 0) {
pixels[i] = color % colors;
}
else {
unsigned int j;
j = i & pixels_per_bytem1;
i = i >> pixelshift_per_byte;
pixels[i] = (pixels[i] & win_notmask[j]) +
(((unsigned char)(color % colors)) << win_bitshift[j]);
}
/* check the time every nnn pixels */
if (win_fastupdate || ++pixelsout > 100) {
pixelsout = 0;
this_time = time(NULL);
/* time to update the screen? */
if (win_fastupdate || (this_time - last_time) > update_time ||
(minimum_update*(this_time-last_time)) > (bottom_changed-top_changed)) {
temp_top_changed = top_changed - win_yoffset;
temp_bottom_changed = bottom_changed - win_yoffset;
if (!(temp_top_changed >= ypagesize || temp_bottom_changed < 0)) {
if (temp_top_changed < 0) temp_top_changed = 0;
if (temp_bottom_changed < 0) temp_bottom_changed = 0;
if (temp_top_changed > ypagesize) temp_top_changed = ypagesize;
if (temp_bottom_changed > ypagesize) temp_bottom_changed = ypagesize;
tempRect.top = temp_top_changed;
tempRect.bottom = temp_bottom_changed+1;
tempRect.left = 0;
tempRect.right = xdots;
if (win_fastupdate == 1) {
tempRect.left = x-win_xoffset;
tempRect.right = x-win_xoffset+1;
}
InvalidateRect(hwnd, &tempRect, FALSE);
/*
EndDeferWindowPos(BeginDeferWindowPos(0));
*/
}
if (win_fastupdate) {
extern int kbdcount;
if (kbdcount > 5)
kbdcount = 5;
win_fastupdate = 1;
}
keypressed(); /* force a look-see at the screen */
last_time = this_time;
top_changed = win_ydots;
bottom_changed = 0;
}
}
}
}
int getcolor(int x, int y)
{
long i;
i = win_ydots-1-y;
i = (i * win_xdots) + x;
if (x >= 0 && x < xdots && y >= 0 && y < ydots) {
if (pixelshift_per_byte == 0) {
return(pixels[i]);
}
else {
unsigned int j;
j = i & pixels_per_bytem1;
i = i >> pixelshift_per_byte;
return((int)((pixels[i] & win_andmask[j]) >> win_bitshift[j]));
}
}
else
return(0);
}
int put_line(int rownum, int leftpt, int rightpt, unsigned char *localvalues)
{
int i, len;
long startloc;
len = rightpt - leftpt;
if (rightpt >= xdots) len = xdots - 1 - leftpt;
startloc = win_ydots-1-rownum;
startloc = (startloc * win_xdots) + leftpt;
if (rownum < 0 || rownum >= ydots || leftpt < 0) {
return(0);
}
if (pixelshift_per_byte == 0) {
for (i = 0; i <= len; i++)
pixels[startloc+i] = localvalues[i];
}
else {
unsigned int j;
long k;
for (i = 0; i <= len; i++) {
k = startloc + i;
j = k & pixels_per_bytem1;
k = k >> pixelshift_per_byte;
pixels[k] = (pixels[k] & win_notmask[j]) +
(((unsigned char)(localvalues[i] % colors)) << win_bitshift[j]);
}
}
pixelsout += len;
if (win_fastupdate)
win_fastupdate = 2; /* force 'putcolor()' to update a whole scanline */
putcolor(leftpt, rownum, localvalues[0]);
}
int get_line(int rownum, int leftpt, int rightpt, unsigned char *localvalues)
{
int i, len;
long startloc;
len = rightpt - leftpt;
if (rightpt >= xdots) len = xdots - 1 - leftpt;
startloc = win_ydots-1-rownum;
startloc = (startloc * win_xdots) + leftpt;
if (rownum < 0 || rownum >= ydots || leftpt < 0 || rightpt >= xdots) {
for (i = 0; i <= len; i++)
localvalues[i] = 0;
return(0);
}
if (pixelshift_per_byte == 0) {
for (i = 0; i <= len; i++)
localvalues[i] = pixels[startloc+i];
}
else {
unsigned int j;
long k;
for (i = 0; i <= len; i++) {
k = startloc + i;
j = k & pixels_per_bytem1;
k = k >> pixelshift_per_byte;
localvalues[i] = (pixels[k] & win_andmask[j]) >> win_bitshift[j];
}
}
}
extern int rowcount;
int out_line(unsigned char *localvalues, int numberofdots)
{
put_line(rowcount++, 0, numberofdots, localvalues);
}
extern LPBITMAPINFO pDibInfo; /* pointer to the DIB info */
int clear_screen(int forceclear)
{
long numdots;
int i;
/* set up the videoentry values */
strcpy(videoentry.name, "Windows Video Image");
strcpy(videoentry.comment,"Generated using Winfract");
videoentry.keynum = 40;
videoentry.videomodeax = 3;
videoentry.videomodebx = 0;
videoentry.videomodecx = 0;
videoentry.videomodedx = 0;
videoentry.dotmode = 1;
videoentry.xdots = xdots;
videoentry.ydots = ydots;
videoentry.colors = colors;
win_xdots = (xdots+3) & 0xfffc;
win_ydots = ydots;
pixelshift_per_byte = 0;
pixels_per_byte = 1;
pixels_per_bytem1 = 0;
if (colors == 16) {
win_xdots = (xdots+7) & 0xfff8;
pixelshift_per_byte = 1;
pixels_per_byte = 2;
pixels_per_bytem1 = 1;
win_andmask[0] = 0xf0; win_notmask[0] = 0x0f; win_bitshift[0] = 4;
win_andmask[1] = 0x0f; win_notmask[1] = 0xf0; win_bitshift[1] = 0;
}
if (colors == 2) {
win_xdots = (xdots+31) & 0xffe0;
pixelshift_per_byte = 3;
pixels_per_byte = 8;
pixels_per_bytem1 = 7;
win_andmask[0] = 0x80; win_notmask[0] = 0x7f; win_bitshift[0] = 7;
for (i = 1; i < 8; i++) {
win_andmask[i] = win_andmask[i-1] >> 1;
win_notmask[i] = (win_notmask[i-1] >> 1) + 0x80;
win_bitshift[i] = win_bitshift[i-1] - 1;
}
}
numdots = (long)win_xdots * (long) win_ydots;
update_time = 2;
/* disable the long delay logic
if (numdots > 200000L) update_time = 4;
if (numdots > 400000L) update_time = 8;
*/
last_time = time(NULL) - update_time + 1;
minimum_update = 7500/xdots; /* assume 75,000 dots/sec drawing speed */
last_written_y = -1;
pixelsout = 0;
top_changed = win_ydots;
bottom_changed = 0;
bytes_per_pixelline = win_xdots >> pixelshift_per_byte;
/* Create the Device-independent Bitmap entries */
pDibInfo->bmiHeader.biWidth = win_xdots;
pDibInfo->bmiHeader.biHeight = win_ydots;
pDibInfo->bmiHeader.biSizeImage = (DWORD)bytes_per_pixelline * win_ydots;
pDibInfo->bmiHeader.biBitCount = 8 / pixels_per_byte;
/* hard to believe, but this is the fast way to clear the pixel map */
if (hpixels) {
GlobalUnlock(hpixels);
GlobalFree(hpixels);
}
win_bitmapsize = (numdots >> pixelshift_per_byte)+1;
if (!(hpixels = GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT, win_bitmapsize)))
return(0);
if (!(pixels = (char huge *)GlobalLock(hpixels))) {
GlobalFree(hpixels);
return(0);
}
/* adjust the colors for B&W or default */
if (colors == 2) {
dacbox[0][0] = dacbox[0][1] = dacbox[0][2] = 0;
dacbox[1][0] = dacbox[1][1] = dacbox[1][2] = 63;
spindac(0,1);
}
else
restoredac(); /* color palette */
screen_to_be_cleared = 1;
InvalidateRect(hwnd, NULL, TRUE);
if (forceclear)
keypressed(); /* force a look-see at the screen */
return(1);
}
int flush_screen()
{
last_written_y = 0;
InvalidateRect(hwnd, NULL, FALSE);
}
void buzzer(int i)
{
MessageBeep(0);
}
#define MAXFARMEMALLOCS 50 /* max active farmemallocs */
int farmemallocinit = 0; /* any memory been allocated yet? */
HANDLE farmemallochandles[MAXFARMEMALLOCS]; /* handles */
void far *farmemallocpointers[MAXFARMEMALLOCS]; /* pointers */
void far * cdecl farmemalloc(long bytecount)
{
int i;
HANDLE temphandle;
void far *temppointer;
if (!farmemallocinit) { /* never been here yet - initialize */
farmemallocinit = 1;
for (i = 0; i < MAXFARMEMALLOCS; i++) {
farmemallochandles[i] = (HANDLE)0;
farmemallocpointers[i] = NULL;
}
}
for (i = 0; i < MAXFARMEMALLOCS; i++) /* look for a free handle */
if (farmemallochandles[i] == (HANDLE)0) break;
if (i == MAXFARMEMALLOCS) /* uh-oh - no more handles */
return(NULL); /* can't get far memory this way */
if (!(temphandle = GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT, bytecount)))
return(NULL); /* can't allocate the memory */
if ((temppointer = (void far *)GlobalLock(temphandle)) == NULL) {
GlobalFree(temphandle);
return(NULL); /* ?? can't lock the memory ?? */
}
farmemallochandles[i] = temphandle;
farmemallocpointers[i] = temppointer;
return(temppointer);
}
void farmemfree(void far *bytepointer)
{
int i;
if (bytepointer == (void far *)NULL) return;
for (i = 0; i < MAXFARMEMALLOCS; i++) /* search for a matching pointer */
if (farmemallocpointers[i] == bytepointer)
break;
if (i < MAXFARMEMALLOCS) { /* got one */
GlobalUnlock(farmemallochandles[i]);
GlobalFree(farmemallochandles[i]);
farmemallochandles[i] = (HANDLE)0;
}
}
debugmessage(char *msg1, char *msg2)
{
MessageBox (
GetFocus(),
msg2,
msg1,
MB_ICONASTERISK | MB_OK);
}
texttempmsg(char *msg1)
{
MessageBox (
GetFocus(),
msg1,
"Encoder",
MB_ICONASTERISK | MB_OK);
}
stopmsg(int flags, unsigned char far *msg1)
{
int result;
if (! (flags & 4)) MessageBeep(0);
result = IDOK;
if (!(flags & 2))
MessageBox (
NULL,
msg1,
"Fractint for Windows",
MB_TASKMODAL | MB_ICONASTERISK | MB_OK);
else
result = MessageBox (
NULL,
msg1,
"Fractint for Windows",
MB_TASKMODAL | MB_ICONQUESTION | MB_OKCANCEL);
if (result == 0 || result == IDOK || result == IDYES)
return(0);
else
return(-1);
}
extern char readname[];
extern int fileydots, filexdots, filecolors;
extern int iNumColors; /* Number of colors supported by device */
extern int iRasterCaps; /* Raster capabilities */
win_load()
{
int i;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -