A little more progress on OS/2

This commit is contained in:
David Schmidt
2010-06-01 07:07:43 +00:00
parent 6d1b9c3a23
commit bebb4c2c39

View File

@@ -59,7 +59,7 @@ int g_win_capslock_down = 0;
extern int g_border_sides_refresh_needed; extern int g_border_sides_refresh_needed;
extern int g_border_special_refresh_needed; extern int g_border_special_refresh_needed;
extern int g_status_refresh_needed; extern int g_status_refresh_needed;
extern int g_needfullrefreshfornextframe;
extern int g_lores_colors[]; extern int g_lores_colors[];
extern int g_cur_a2_stat; extern int g_cur_a2_stat;
@@ -73,8 +73,14 @@ extern word32 g_a2_screen_buffer_changed;
BITMAPINFO2 *g_bmapinfo_ptr = 0; BITMAPINFO2 *g_bmapinfo_ptr = 0;
volatile BITMAPINFOHEADER2 *g_bmaphdr_ptr = 0; volatile BITMAPINFOHEADER2 *g_bmaphdr_ptr = 0;
HDC g_hdc; HDC g_hdc_screen, g_hdc_memory;
HPS g_hps; HPS g_hps_screen, g_hps_memory;
extern word32 g_palette_8to1624[256];
extern word32 g_a2palette_8to1624[256];
extern char *g_status_ptrs[MAX_STATUS_LINES];
VOID DispErrorMessage();
int int
win_nonblock_read_stdin(int fd, char *bufptr, int len) win_nonblock_read_stdin(int fd, char *bufptr, int len)
@@ -98,6 +104,7 @@ x_show_alert(int is_fatal, const char *str)
int int
main(int argc, char **argv) main(int argc, char **argv)
{ {
DEVOPENSTRUC pszData;
ULONG flCreate; /* Window creation control flags*/ ULONG flCreate; /* Window creation control flags*/
int height; int height;
SIZEL sizel; SIZEL sizel;
@@ -117,7 +124,7 @@ SIZEL sizel;
)) ))
os2_abort(g_hwnd_frame, g_hwnd_client); /* Terminate the application */ os2_abort(g_hwnd_frame, g_hwnd_client); /* Terminate the application */
height = X_A2_WINDOW_HEIGHT + (MAX_STATUS_LINES*16) + 32; height = X_A2_WINDOW_HEIGHT + (MAX_STATUS_LINES*16);
g_main_height = height; g_main_height = height;
flCreate = FCF_STANDARD & /* Set frame control flags to */ flCreate = FCF_STANDARD & /* Set frame control flags to */
@@ -146,13 +153,17 @@ SIZEL sizel;
)) ))
os2_abort(g_hwnd_frame, g_hwnd_client); /* Terminate the application */ os2_abort(g_hwnd_frame, g_hwnd_client); /* Terminate the application */
g_hdc = WinOpenWindowDC(g_hwnd_frame); g_hdc_screen = WinOpenWindowDC(g_hwnd_client);
sizel.cx = X_A2_WINDOW_WIDTH; sizel.cx = X_A2_WINDOW_WIDTH;
sizel.cy = height; sizel.cy = height;
g_hps = GpiCreatePS(g_hab,g_hdc, &sizel, PU_ARBITRARY | GPIT_MICRO | GPIA_ASSOC); g_hps_screen = GpiCreatePS(g_hab,g_hdc_screen, &sizel, PU_PELS | GPIF_LONG | GPIA_ASSOC);
g_hdc_memory = DevOpenDC(g_hab, OD_MEMORY, "*", 4, (PDEVOPENDATA)&pszData, NULL);
g_hps_memory = GpiCreatePS(g_hab,g_hdc_memory, &sizel, PU_ARBITRARY | GPIT_MICRO | GPIA_ASSOC);
// Call gsportmain // Call gsportmain
return gsportmain(argc, argv); return gsportmain(argc, argv);
} }
@@ -168,6 +179,9 @@ SIZEL sizel;
*************************************************************************/ *************************************************************************/
MRESULT EXPENTRY MyWindowProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 ) MRESULT EXPENTRY MyWindowProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 )
{ {
HPS hps;
RECTL rcl;
switch( msg ) switch( msg )
{ {
case WM_CREATE: case WM_CREATE:
@@ -209,27 +223,16 @@ MRESULT EXPENTRY MyWindowProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 )
/* /*
* Window contents are drawn here in WM_PAINT processing. * Window contents are drawn here in WM_PAINT processing.
*/ */
{ hps = WinBeginPaint(hwnd, NULLHANDLE, &rcl);
HPS hps; /* Presentation Space handle */ WinEndPaint(hps);
RECTL rc; /* Rectangle coordinates */ g_needfullrefreshfornextframe = 1;
POINTL pt; /* String screen coordinates */
/* Create a presentation space */
hps = WinBeginPaint( hwnd, 0L, &rc );
WinFillRect( hps, &rc, SYSCLR_WINDOW);
pt.x = 50; pt.y = 50; /* Set the text coordinates, */
GpiSetColor( hps, CLR_NEUTRAL ); /* colour of the text, */
GpiSetBackColor( hps, CLR_BACKGROUND ); /* its background and */
GpiSetBackMix( hps, BM_OVERPAINT ); /* how it mixes, */
/* and draw the string...*/
//GpiCharStringAt( hps, &pt, (LONG)strlen( szString ), szString );
WinEndPaint( hps ); /* Drawing is complete */
break; break;
}
case WM_CLOSE: case WM_CLOSE:
/* /*
* This is the place to put your termination routines * This is the place to put your termination routines
*/ */
WinPostMsg( hwnd, WM_QUIT, (MPARAM)0,(MPARAM)0 ); /* Cause termination*/ WinPostMsg( hwnd, WM_QUIT, (MPARAM)0,(MPARAM)0 ); /* Cause termination*/
exit(0);
break; break;
default: default:
/* /*
@@ -239,6 +242,7 @@ MRESULT EXPENTRY MyWindowProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 )
return WinDefWindowProc( hwnd, msg, mp1, mp2 ); return WinDefWindowProc( hwnd, msg, mp1, mp2 );
} }
return (MRESULT)FALSE; return (MRESULT)FALSE;
} /* End of MyWindowProc */ } /* End of MyWindowProc */
@@ -251,25 +255,15 @@ check_input_events()
* until WinGetMsg returns FALSE, indicating a WM_QUIT message. * until WinGetMsg returns FALSE, indicating a WM_QUIT message.
*/ */
/* Need to peek messages, i.e. while(WinPeekMsg(g_hab, &qmsg, g_hwnd_frame, 0, 0, PM_NOREMOVE)) {
if(WinGetMsg(g_hab, &qmsg, 0L, 0, 0) > 0) {
while(PeekMessage(&msg, g_hwnd_main, 0, 0, PM_NOREMOVE)) { //TranslateMessage(&qmsg);
if(GetMessage(&msg, g_hwnd_main, 0, 0) > 0) { WinDispatchMsg(g_hab, &qmsg);
TranslateMessage(&msg);
DispatchMessage(&msg);
} else { } else {
printf("GetMessage returned <= 0\n"); printf("GetMessage returned <= 0\n");
my_exit(2); my_exit(2);
} }
} }
*/
while( WinGetMsg( g_hab, &qmsg, 0L, 0, 0 ) )
WinDispatchMsg( g_hab, &qmsg );
WinDestroyWindow(g_hwnd_frame); /* Tidy up... */
WinDestroyMsgQueue( g_hmq ); /* Tidy up... */
WinTerminate( g_hab ); /* Terminate the application */
} }
@@ -315,10 +309,11 @@ x_get_kimage(Kimage *kimage_ptr)
if(depth == g_screen_depth) { if(depth == g_screen_depth) {
/* Use g_bmapinfo_ptr, adjusting width, height */ /* Use g_bmapinfo_ptr, adjusting width, height */
g_bmaphdr_ptr->cx = width; g_bmaphdr_ptr->cx = width;
g_bmaphdr_ptr->cy = -height; g_bmaphdr_ptr->cy = height;
kimage_ptr->dev_handle = GpiCreateBitmap( kimage_ptr->dev_handle = GpiCreateBitmap(
(HPS)g_hps, (PBITMAPINFOHEADER2)g_bmaphdr_ptr,
(HPS)g_hps_memory, (PBITMAPINFOHEADER2)g_bmaphdr_ptr,
0L, (PBYTE)kimage_ptr->data_ptr, 0L, (PBYTE)kimage_ptr->data_ptr,
(PBITMAPINFO2)g_bmapinfo_ptr); (PBITMAPINFO2)g_bmapinfo_ptr);
@@ -356,6 +351,9 @@ x_get_kimage(Kimage *kimage_ptr)
void void
dev_video_init() dev_video_init()
{ {
int lores_col;
int i;
printf("Preparing graphics system\n"); printf("Preparing graphics system\n");
g_screen_depth = 24; g_screen_depth = 24;
@@ -365,7 +363,7 @@ dev_video_init()
g_bmaphdr_ptr = (BITMAPINFOHEADER2 *)g_bmapinfo_ptr; g_bmaphdr_ptr = (BITMAPINFOHEADER2 *)g_bmapinfo_ptr;
g_bmaphdr_ptr->cbFix = sizeof(BITMAPINFOHEADER2); g_bmaphdr_ptr->cbFix = sizeof(BITMAPINFOHEADER2);
g_bmaphdr_ptr->cx = A2_WINDOW_WIDTH; g_bmaphdr_ptr->cx = A2_WINDOW_WIDTH;
g_bmaphdr_ptr->cy = -A2_WINDOW_HEIGHT; g_bmaphdr_ptr->cy = A2_WINDOW_HEIGHT;
g_bmaphdr_ptr->cPlanes = 1; g_bmaphdr_ptr->cPlanes = 1;
g_bmaphdr_ptr->cBitCount = g_screen_mdepth; g_bmaphdr_ptr->cBitCount = g_screen_mdepth;
g_bmaphdr_ptr->ulCompression = BCA_UNCOMP; g_bmaphdr_ptr->ulCompression = BCA_UNCOMP;
@@ -379,6 +377,12 @@ dev_video_init()
g_screen_mdepth); g_screen_mdepth);
} }
for(i = 0; i < 256; i++) {
lores_col = g_lores_colors[i & 0xf];
video_update_color_raw(i, lores_col);
g_a2palette_8to1624[i] = g_palette_8to1624[i];
}
g_installed_full_superhires_colormap = 1; g_installed_full_superhires_colormap = 1;
printf("Done with dev_video_init\n"); printf("Done with dev_video_init\n");
@@ -388,6 +392,33 @@ dev_video_init()
void void
x_redraw_status_lines() x_redraw_status_lines()
{ {
int line,len,height;
POINTL pt;
char *buf;
printf("x_redraw_status_lines() called\n");
/*
if (g_status_ptrs[0] != NULL)
{
height = 16;
pt.x = 5; pt.y = 0;
GpiSetColor( g_hps_screen, CLR_NEUTRAL );
GpiSetBackColor( g_hps_screen, CLR_BACKGROUND );
GpiSetBackMix( g_hps_screen, BM_OVERPAINT );
for (line = 0; line < MAX_STATUS_LINES; line++)
{
buf = g_status_ptrs[line];
if (buf != 0)
{
pt.y = height * (line+1);
len = strlen(buf);
GpiCharStringAt( g_hps_screen, &pt, (LONG)strlen( buf ), buf );
}
}
}
*/
} }
@@ -395,6 +426,39 @@ void
x_push_kimage(Kimage *kimage_ptr, int destx, int desty, int srcx, int srcy, x_push_kimage(Kimage *kimage_ptr, int destx, int desty, int srcx, int srcy,
int width, int height) int width, int height)
{ {
RECTL rc;
POINTL pt[4];
HBITMAP hbmOld;
char *szString = "Hello, world!\0";
printf("x_push_kimage() called: Src: (%d,%d) Dest: (%d,%d) Width: %d Height: %d\n",srcx,srcy,destx,desty,width,height);
pt[0].x = destx; /* Target X1 */
pt[0].y = desty+(MAX_STATUS_LINES*16); /* Target Y1 */
pt[1].x = destx+width; /* Target X2 */
pt[1].y = desty+height+(MAX_STATUS_LINES*16); /* Target Y2: Translate up, make room for status border */
pt[2].x = srcx; /* Source X */
pt[2].y = srcy; /* Source Y */
pt[3].x = srcx+width;
pt[3].y = srcy+height;
hbmOld = GpiSetBitmap(g_hps_memory, (HBITMAP)kimage_ptr->dev_handle);
GpiBitBlt(g_hps_screen,g_hps_memory,4L,pt,ROP_SRCCOPY, BBO_IGNORE);
GpiSetBitmap(g_hps_memory, hbmOld);
}
// OG Adding release
void x_release_kimage(Kimage* kimage_ptr)
{
if (kimage_ptr->dev_handle == (void*)-1)
{
free(kimage_ptr->data_ptr);
kimage_ptr->data_ptr = NULL;
}
else
{
}
} }
void void
@@ -423,25 +487,45 @@ x_full_screen(int do_full)
return; return;
} }
int x_calc_ratio(float ratiox,float ratioy)
// OG Adding release
void x_release_kimage(Kimage* kimage_ptr)
{ {
if (kimage_ptr->dev_handle == (void*)-1) return 0; // not stretched
{
free(kimage_ptr->data_ptr);
kimage_ptr->data_ptr = NULL;
}
} }
// OG Addding ratio /**************************************************************************/
int x_calc_ratio(float x,float y) /* DispErrorMsg -- report an error returned from an API service. */
/* */
/* The error message is displayed using a message box */
/* */
/**************************************************************************/
VOID DispErrorMessage()
{ {
return 1; PERRINFO pErrInfoBlk;
PSZ pszOffSet, pszErrMsg;
ERRORID ErrorId;
PCH ErrorStr;
ErrorId = WinGetLastError(g_hab);
if ((pErrInfoBlk = WinGetErrorInfo(g_hab)) != (PERRINFO)NULL)
{
pszOffSet = ((PSZ)pErrInfoBlk) + pErrInfoBlk->offaoffszMsg;
pszErrMsg = ((PSZ)pErrInfoBlk) + *((PULONG)pszOffSet);
WinMessageBox(HWND_DESKTOP, /* Parent window is desk top */
g_hwnd_frame, /* Owner window is our frame */
pszErrMsg, /* PMWIN Error message */
"Error", /* Title bar message */
0, /* Message identifier */
MB_MOVEABLE | MB_CANCEL ); /* Flags */
WinFreeErrorInfo(pErrInfoBlk);
}
} }
void void
os2_abort(HWND g_hwnd_frame, HWND g_hwnd_client) os2_abort(HWND g_hwnd_frame, HWND g_hwnd_client)
{ {
exit(-1); exit(-1);
} }