home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 1997 March / VPR9703A.ISO / VPR_DATA / DOGA / SOURCES / REND.LZH / REND / CRTWIN.C < prev    next >
C/C++ Source or Header  |  1996-07-16  |  17KB  |  677 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4. #undef FLOAT
  5. #include <windows.h>
  6. #define crtprintf __crtprintf
  7. #include "reader.h"
  8. #undef crtprintf
  9. #include "glib.h"
  10. #include "rend.h"
  11. #include "rend.rh"
  12. char    *program = "Do-GA C.G.A System Rendering Program" ;
  13.  
  14. static char *RendClass = "REND";
  15. static char *RendTitle = "REND for Windows";
  16.  
  17. #define MESSAGES 5
  18.  
  19. #define MAXARGV 256
  20. #define WIDTH 512
  21.  
  22. #define ID_COPY 2000
  23. #define ID_SAVE 2001
  24.  
  25. static HWND HMainWindow = NULL;
  26. static HWND HText[MESSAGES];
  27.  
  28. static int winx, winy;
  29. static int borderx, bordery;
  30. static int offsetx = 0, offsety = (16*MESSAGES);
  31. static int maxy = 0;
  32. #define WINX (winx+borderx+offsetx)
  33. #define WINY (winy+bordery+offsety)
  34.  
  35. static HDC dc = NULL;
  36. static HDC graphdc = NULL;
  37. static HPALETTE hpal = NULL;
  38. static BYTE *pBuffer;
  39. static BITMAPINFO *pbmi;
  40. static LOGPALETTE *plgpl;
  41.  
  42. static int headersize, imagesize;
  43.  
  44.  
  45. static BYTE *err_r, *err_g, *err_b;
  46. static BYTE *err_nr, *err_ng, *err_nb;
  47.  
  48. static enum {PAL8, RGB16, RGB24} crtmode = PAL8;
  49. char profile[128];
  50.  
  51. static int posx = CW_USEDEFAULT, posy = 0;
  52.  
  53. void ReadProfile(HANDLE hInstance)
  54. {
  55.     char *p;
  56.     GetModuleFileName(hInstance, profile, sizeof(profile));
  57.     if ((p = strrchr(profile, '.')) == NULL) {
  58.         p = profile + strlen(profile);
  59.     }
  60.     strcpy(p, ".ini");
  61.  
  62.     posx = GetPrivateProfileInt("Rend", "PositionX", posx, profile);
  63.     posy = GetPrivateProfileInt("Rend", "PositionY", posy, profile);
  64. }
  65.  
  66. void WriteProfile(void)
  67. {
  68.     char buf[128];
  69. #if 0
  70.     RECT rc;
  71.     GetWindowRect(HMainWindow, &rc);
  72.     sprintf(buf, "%d", rc.left);
  73.     WritePrivateProfileString("Rend", "PositionX", buf, profile);
  74.     sprintf(buf, "%d", rc.top);
  75.     WritePrivateProfileString("Rend", "PositionY", buf, profile);
  76. #else
  77.     sprintf(buf, "%d", posx);
  78.     WritePrivateProfileString("Rend", "PositionX", buf, profile);
  79.     sprintf(buf, "%d", posy);
  80.     WritePrivateProfileString("Rend", "PositionY", buf, profile);
  81. #endif
  82. }
  83.  
  84.  
  85. int CreateMessageWindow(HANDLE hInstance, int nCmdShow)
  86. {
  87.     int i;
  88.     int sx, sy;
  89.     HMENU sysmenu;
  90.     sx = GetSystemMetrics(SM_CXSCREEN);
  91.     sy = GetSystemMetrics(SM_CYSCREEN);
  92.     winx = WIDTH;
  93.     winy = 0;
  94.     borderx = GetSystemMetrics(SM_CXFRAME) + GetSystemMetrics(SM_CXBORDER);
  95.     bordery = GetSystemMetrics(SM_CYFRAME) + GetSystemMetrics(SM_CYCAPTION) + 3;
  96.  
  97.     if (posx + WINX > sx) posx = sx - WINX;
  98.     if (posy + WINY > sy) posy = sy - WINY;
  99.     if (posx < 0) posx = 0;
  100.     if (posy < 0) posy = 0;
  101.  
  102.     HMainWindow = CreateWindow(RendClass, RendTitle,
  103.         (WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU |
  104.         WS_THICKFRAME | WS_MINIMIZEBOX),
  105.         posx, posy, WINX, WINY,
  106.         HWND_DESKTOP, NULL, hInstance, NULL);
  107.     if(HMainWindow==NULL) return FALSE;
  108.  
  109.     sysmenu = GetSystemMenu(HMainWindow, FALSE);
  110.     InsertMenu(sysmenu, 0, MF_BYPOSITION|MF_STRING, ID_COPY, "コピー(&C)");
  111.     InsertMenu(sysmenu, 1, MF_BYPOSITION|MF_STRING, ID_SAVE, "名前を付けて保存(&A)");
  112.     InsertMenu(sysmenu, 2, MF_BYPOSITION|MF_SEPARATOR, -1, NULL);
  113.  
  114.     for (i = 0; i < MESSAGES; ++i) {
  115.         HText[i] = CreateWindow("STATIC", "", WS_CHILD | WS_VISIBLE, 0,  i*16, WIDTH, 16, HMainWindow, NULL, hInstance, NULL);
  116.     }
  117.     ShowWindow(HMainWindow, nCmdShow);
  118.     UpdateWindow(HMainWindow);
  119.  
  120.     return TRUE;
  121. }
  122.  
  123.  
  124. LRESULT _export CALLBACK RendProc(
  125.     HWND hwnd, UINT msg,
  126.     WPARAM wParam, LPARAM lParam)
  127. {
  128.     switch(msg)
  129.     {
  130.     case WM_CLOSE:
  131.         WriteProfile();
  132.         break;
  133.     case WM_DESTROY:
  134.         if (dc != NULL) {
  135.             ReleaseDC(HMainWindow, dc);
  136.             dc = NULL;
  137.         }
  138.         if (hpal != NULL) {
  139.             DeleteObject(hpal);
  140.             hpal = NULL;
  141.         }
  142.         PostQuitMessage(0);
  143.         return 0;
  144.     case WM_MOVE:
  145.         {
  146.             WINDOWPLACEMENT wndpl;
  147.             memset(&wndpl, 0, sizeof(WINDOWPLACEMENT));
  148.             wndpl.length = sizeof(WINDOWPLACEMENT);
  149.             GetWindowPlacement(HMainWindow, &wndpl);
  150.             if (wndpl.showCmd == SW_NORMAL) {
  151.                 posx = (int) LOWORD(lParam);    /* 水平方向の位置    */
  152.                 posy = (int) HIWORD(lParam);    /* 垂直方向の位置    */
  153.             }
  154.         }
  155.         return 0;
  156.     case WM_ACTIVATE:
  157.         if (dc && crtmode == PAL8) {
  158.             RealizePalette(dc);
  159.         }
  160.         return 0;
  161.     case WM_PAINT:
  162.         if (dc != NULL && (graphdc == dc) && maxy > 0 && pBuffer != NULL
  163.          && (crtmode != PAL8 || pbmi != NULL)) {
  164.             SetDIBitsToDevice(dc,
  165.                 offsetx, offsety, winx, maxy,
  166.                 0, winy - maxy,
  167.                 0, winy, pBuffer, pbmi, DIB_RGB_COLORS);
  168.         }
  169.         break;
  170.     case WM_PALETTECHANGED:
  171.         if((HWND)wParam==hwnd) return 0L;
  172.         if (dc != NULL && graphdc == dc && crtmode == PAL8) {
  173.             RealizePalette(dc);
  174. /*            InvalidateRect(hwnd, NULL, FALSE);*/
  175.         }
  176.         break;
  177.     case WM_QUERYNEWPALETTE:
  178.         if (dc && graphdc == dc && crtmode == PAL8) {
  179.             RealizePalette(dc);
  180.             InvalidateRect(hwnd, NULL, FALSE);
  181.         }
  182.         return 0;
  183.     case WM_SYSCOMMAND:
  184.     case WM_COMMAND:
  185.         if (wParam == ID_COPY) {
  186.             HGLOBAL hmem;
  187.             BYTE *p;
  188.             int l;
  189.             hmem = GlobalAlloc(GMEM_MOVEABLE, headersize + imagesize);
  190.             p = GlobalLock(hmem);
  191.             memcpy(p, pbmi, headersize);
  192.             memcpy(p + headersize, pBuffer, imagesize);
  193.             GlobalUnlock(hmem);
  194.  
  195.             OpenClipboard(hwnd);
  196.             EmptyClipboard();
  197.             SetClipboardData(CF_DIB, hmem);
  198.             CloseClipboard();
  199.  
  200.             return 0;
  201.         } else if (wParam == ID_SAVE) {
  202.             char szFile[256];
  203.             OPENFILENAME ofn;
  204.             char chReplace;
  205.             int i;
  206.             memset(&ofn, 0, sizeof(OPENFILENAME));
  207.             ofn.lStructSize=sizeof(OPENFILENAME);
  208.             ofn.hwndOwner=hwnd;
  209.             ofn.lpstrFilter="*.BMP\0";
  210.             ofn.nFilterIndex=1;
  211.             ofn.lpstrFile=szFile;
  212.             szFile[0] = '\0';
  213.             ofn.nMaxFile=256;
  214.             ofn.lpstrFileTitle=NULL;
  215.             ofn.lpstrInitialDir=NULL;
  216.             ofn.Flags = OFN_PATHMUSTEXIST | OFN_OVERWRITEPROMPT;
  217.             ofn.lpstrDefExt = "BMP";
  218.             if (GetSaveFileName(&ofn)) {
  219.                 FILE *fp;
  220.                 if ((fp = fopen(szFile, "wb")) == NULL) {
  221.                     MessageBox(hwnd, "ファイル出力に失敗しました",
  222.                         RendTitle, MB_ICONEXCLAMATION | MB_OK);
  223.                 } else {
  224.                     BITMAPFILEHEADER bfh;
  225.                     memset(&bfh, 0, sizeof(BITMAPFILEHEADER));
  226.                     bfh.bfType = 'BM';
  227.                     bfh.bfSize = (sizeof(BITMAPFILEHEADER)+headersize+imagesize+3)/4;
  228.                     bfh.bfOffBits = sizeof(BITMAPFILEHEADER)+headersize;
  229.                     fwrite(&bfh, 1, sizeof(BITMAPFILEHEADER), fp);
  230.                     fwrite(pbmi, 1, headersize, fp);
  231.                     fwrite(pBuffer, 1, imagesize, fp);
  232.                     fclose(fp);
  233.                 }
  234.             }
  235.             return 0;
  236.         }
  237.         break;
  238.     }
  239.     return DefWindowProc(
  240.         hwnd, msg, wParam, lParam);
  241. }
  242.  
  243. int RegisterRendClass(HANDLE hInstance)
  244. {
  245.     WNDCLASS wc;
  246.  
  247.     wc.style=CS_GLOBALCLASS;
  248.     wc.lpfnWndProc=RendProc;
  249.     wc.cbClsExtra=0;
  250.     wc.cbWndExtra=0;
  251.     wc.hInstance=hInstance;
  252.     wc.hIcon=LoadIcon(hInstance, MAKEINTRESOURCE(ID_REND));
  253.     wc.hCursor=NULL;
  254.     wc.hbrBackground=(HBRUSH)(COLOR_WINDOW);
  255.     wc.lpszMenuName=NULL;
  256.     wc.lpszClassName=RendClass;
  257.     return RegisterClass(&wc);
  258. }
  259.  
  260. int PASCAL WinMain ( HANDLE hInstance, HANDLE hPrevInstance,
  261.                     LPSTR lpszCmdParam, int nCmdShow )
  262. {
  263.     extern int Main(int argc, char *argv[]);
  264.     int argc;
  265.     char *argv[MAXARGV], *param, *p;
  266.     param = malloc(strlen(lpszCmdParam)+1);
  267.     strcpy(param, lpszCmdParam);
  268.  
  269.     argc = 1;
  270.     argv[0] = param;
  271.     for (p = param; *p; ++p) {
  272.         if (isspace(*p)) {
  273.             *p = '\0';
  274.             while (p[1] != '\0' && isspace(p[1])) {
  275.                 p++;
  276.             }
  277.             if (p[1] == '\0') break;
  278.             argv[argc++] = p+1;
  279.         }
  280.     }
  281.     argv[argc] = NULL;
  282.     if(hPrevInstance==NULL) {
  283.         RegisterRendClass(hInstance);
  284.     }
  285.  
  286.     ReadProfile(hInstance);
  287.     CreateMessageWindow(hInstance, nCmdShow);
  288.  
  289.     Main(argc, argv);
  290.     if (nflag) {
  291.         MSG msg;
  292.         while (GetMessage(&msg, NULL, 0, 0)) {
  293.             TranslateMessage(&msg);
  294.             DispatchMessage(&msg);
  295.         }
  296.     }
  297.     WriteProfile();
  298.     return 0;
  299. }
  300.  
  301. void check_winmessage(void)
  302. {
  303.     MSG msg;
  304.     while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
  305.         if (msg.message == WM_QUIT) {
  306.             exit(1);
  307.         }
  308.         TranslateMessage(&msg);
  309.         DispatchMessage(&msg);
  310.     }
  311. }
  312.  
  313. static int status = 0;
  314.  
  315. void    crtmessage(char *str)
  316. {
  317.     int i;
  318.     if (offsety == 0) {
  319.         check_winmessage();
  320.         return;
  321.     }
  322.     if (strncmp(str, "Read", 4) == 0) {
  323.         SetWindowText(HText[0], str);
  324.         for (i = 1; i < MESSAGES; ++i) {
  325.             SetWindowText(HText[i], "");
  326.         }
  327.         status = 1;
  328.     } else {
  329.         if (status == MESSAGES) {
  330.             char buf[128];
  331.             for (i = 1; i < MESSAGES-1; ++i) {
  332.                 GetWindowText(HText[i+1], buf, 128);
  333.                 SetWindowText(HText[i], buf);
  334.             }
  335.             SetWindowText(HText[MESSAGES-1], str);
  336.         } else {
  337.             SetWindowText(HText[status++], str);
  338.         }
  339.     }
  340.     check_winmessage();
  341. }
  342.  
  343. void palinit(void)
  344. {
  345.     int i;
  346.     RGBQUAD *p;
  347.     PALETTEENTRY *pal;
  348.  
  349.     dc = GetDC(HMainWindow);
  350.     if (graphdc == NULL) {
  351.         graphdc = dc;
  352.     }
  353.     pbmi = malloc(sizeof(BITMAPINFOHEADER)+sizeof(RGBQUAD)*256);
  354.     pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
  355.     pbmi->bmiHeader.biWidth = winx;
  356.     pbmi->bmiHeader.biHeight = winy;
  357.     pbmi->bmiHeader.biPlanes = 1;
  358.     pbmi->bmiHeader.biBitCount = 8;
  359.     pbmi->bmiHeader.biCompression = BI_RGB;
  360.     pbmi->bmiHeader.biSizeImage = 0;
  361.     pbmi->bmiHeader.biClrUsed = 0;
  362.     pbmi->bmiHeader.biClrImportant = 0;
  363.     if (GetDeviceCaps(dc, RASTERCAPS) & RC_PALETTE) {
  364.         crtmode = PAL8;
  365.         headersize = sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD)*256;
  366.         imagesize = ((winx+3)/4) * 4 * winy;
  367.         pBuffer = malloc(imagesize);
  368.         err_r  = malloc((winx+2)*6);
  369.         err_g  = err_r + (winx+2);
  370.         err_b  = err_g + (winx+2);
  371.         err_nr = err_b + (winx+2);
  372.         err_ng = err_nr + (winx+2);
  373.         err_nb = err_ng + (winx+2);
  374.         plgpl = malloc(sizeof(LOGPALETTE) + sizeof(PALETTEENTRY)*256);
  375.  
  376.         pbmi->bmiHeader.biBitCount = 8;
  377.         pbmi->bmiHeader.biClrUsed = 216;
  378.  
  379.         plgpl->palVersion = 0x300;
  380.         plgpl->palNumEntries = 216;
  381.  
  382.         p = pbmi->bmiColors;
  383.         pal = plgpl->palPalEntry;
  384. #if 0
  385.         pal->peBlue  = p->rgbBlue     = 0;
  386.         pal->peGreen = p->rgbGreen    = 0;
  387.         pal->peRed   = p->rgbRed      = 0;
  388.         pal->peFlags = p->rgbReserved = 0;
  389.         p++;
  390.         pal++;
  391. #endif
  392.         for (i = 0; i < 6; ++i) {
  393.             int j;
  394.             for (j = 0; j < 6; ++j) {
  395.                 int k;
  396.                 for (k = 0; k < 6; ++k) {
  397.                     pal->peBlue  = p->rgbBlue     = (BYTE)k*51;
  398.                     pal->peGreen = p->rgbGreen    = (BYTE)j*51;
  399.                     pal->peRed   = p->rgbRed      = (BYTE)i*51;
  400.                     pal->peFlags = p->rgbReserved = 0;
  401.                     p++;
  402.                     pal++;
  403.                 }
  404.             }
  405.         }
  406.         hpal = CreatePalette(plgpl);
  407.         if (dc == graphdc) {
  408.             SelectPalette(dc, hpal, FALSE);
  409.             RealizePalette(dc);
  410.         }
  411.     } else if (GetDeviceCaps(dc, BITSPIXEL) < 24) {
  412.         crtmode = RGB16;
  413.         headersize = sizeof(BITMAPINFOHEADER);
  414.         imagesize = ((winx*3+3)/4)* 4 * winy;
  415.         pBuffer = malloc(imagesize);
  416.         pbmi->bmiHeader.biBitCount = 24;
  417.     } else {
  418.         crtmode = RGB24;
  419.         headersize = sizeof(BITMAPINFOHEADER);
  420.         imagesize = ((winx*3+3)/4)* 4 * winy;
  421.         pBuffer = malloc(imagesize);
  422.         pbmi->bmiHeader.biBitCount = 24;
  423.     }
  424. }
  425.  
  426. void    crtinit( line )
  427. int        line ;
  428. {
  429.     extern    int        antiareas ;        /*    アンチエリアシング            */
  430.     extern    int        XPixel, YPixel ;        /*    ピクセル数                */
  431.     int i;
  432.     int sx, sy;
  433.     RECT rc;
  434.     WINDOWPLACEMENT wndpl;
  435.     for (i = 0; i < MESSAGES; ++i) {
  436.         SetWindowText(HText[i], "");
  437.     }
  438.     status = 0;
  439.  
  440.     sx = GetSystemMetrics(SM_CXSCREEN);
  441.     sy = GetSystemMetrics(SM_CYSCREEN);
  442.  
  443.     GetWindowRect(HMainWindow, &rc);
  444.  
  445.     memset(&wndpl, 0, sizeof(WINDOWPLACEMENT));
  446.     wndpl.length = sizeof(WINDOWPLACEMENT);
  447.     GetWindowPlacement(HMainWindow, &wndpl);
  448.     if (wndpl.showCmd == SW_NORMAL) {
  449.         posx = rc.left;
  450.         posy = rc.top;
  451.     }
  452.     if (posx + WINX > sx) posx = sx - WINX;
  453.     if (posy + WINY > sy) posy = sy - WINY;
  454.     if (posx < 0) posx = 0;
  455.     if (posy < 0) posy = 0;
  456.  
  457.     winx = XPixel / antiareas;
  458.     winy = YPixel / antiareas;
  459.     if (graphdc == dc) {
  460.         if (nflag) {
  461.             offsety = 0;
  462.             for (i = 0; i < MESSAGES; ++i) {
  463.                 ShowWindow(HText[i], SW_HIDE);
  464.             }
  465.         } else {
  466.             offsety = 16 * MESSAGES;
  467.         }
  468.         MoveWindow(HMainWindow, posx, posy, WINX, WINY, TRUE);
  469.     } else {
  470.         MoveWindow(HMainWindow, posx, posy, WINX, bordery + MESSAGES*16, TRUE);
  471.     }
  472.  
  473.     maxy = 0;
  474.     palinit();
  475.     check_winmessage();
  476. }
  477.  
  478. /*    CRTのクリア    */
  479. void    crtclr()
  480. {
  481.     int i;
  482. //    HDC dc;
  483.     HGDIOBJ hgdiold;
  484. //    HPALETTE hpal;
  485. //    dc = GetDC(HMainWindow);
  486.     if (dc != NULL) {
  487.         if (dc == graphdc) {
  488.             hgdiold = SelectObject(dc,(HGDIOBJ)COLOR_WINDOW);
  489.             Rectangle(dc, 0, 0, winx, WINY);
  490.             SelectObject(dc, hgdiold);
  491.             if (crtmode == PAL8)        RealizePalette(dc);
  492.         } else {
  493.             hgdiold = SelectObject(dc,(HGDIOBJ)COLOR_WINDOW);
  494.             Rectangle(dc, 0, 0, winx, 16*MESSAGES);
  495.             SelectObject(dc, hgdiold);
  496.  
  497.             hgdiold = SelectObject(graphdc,(HGDIOBJ)COLOR_WINDOW);
  498.             Rectangle(graphdc, offsetx, offsety, winx, winy);
  499.             SelectObject(graphdc, hgdiold);
  500.         }
  501.     }
  502. //    DeleteObject(hpal);
  503. //    ReleaseDC(HMainWindow, dc);
  504.  
  505.     for (i = 0; i < MESSAGES; ++i) {
  506.         SetWindowText(HText[i], "");
  507.     }
  508.     status = 0;
  509.     maxy = 0;
  510.     if (crtmode == PAL8) {
  511.         memset(err_r,  0, winx+2); memset(err_g,  0, winx+2); memset(err_b,  0, winx+2);
  512.         memset(err_nr, 0, winx+2); memset(err_ng, 0, winx+2); memset(err_nb, 0, winx+2);
  513.     }
  514.     check_winmessage();
  515. }
  516.  
  517. void crtout24(framebuf, xlen, y)
  518. ColorCode*    framebuf ;
  519. int        xlen ;
  520. int        y ;
  521. {
  522.     int x;
  523.     BYTE *p;
  524.     if (crtmode == PAL8) {
  525.         int er = 0, eg = 0, eb = 0, ee;
  526.         int r,g,b;
  527.         p = err_nr; err_nr = err_r; err_r = p;
  528.         p = err_ng; err_ng = err_g; err_g = p;
  529.         p = err_nb; err_nb = err_b; err_b = p;
  530.         memset(err_nr, 0, winx+2); memset(err_ng, 0, winx+2); memset(err_nb, 0, winx+2);
  531.         p = pBuffer + winx * (winy - 1 - y);
  532. #define STEP 43
  533. #define STEP 32
  534.         for (x = 0; x < xlen; ++x) {
  535.             ee = ((framebuf[x] >> 16) & 255) + er + err_r[x+1];
  536.             r = ee / STEP; ee = ee % STEP;
  537.             er = (ee * 3 + 4) / 8;
  538.             err_nr[x+1] += er;
  539.             err_nr[x+2] += ee - er*2;
  540.  
  541.             ee = ((framebuf[x] >> 24) & 255) + eg + err_g[x+1];
  542.             g = ee / STEP; ee = ee % STEP;
  543.             eg = (ee * 3 + 4) / 8;
  544.             err_ng[x+1] += eg;
  545.             err_ng[x+2] += ee - eg*2;
  546.  
  547.             ee = ((framebuf[x] >>  8) & 255) + eb + err_b[x+1];
  548.             b = ee / STEP; ee = ee % STEP;
  549.             eb = (eb * 3 + 4) / 8;
  550.             err_nb[x+1] += eb;
  551.             err_nb[x+2] += ee - eb*2;
  552.             if (--r < 0) r = 0;
  553.             if (r > 5) r = 5;
  554.             if (--g < 0) g = 0;
  555.             if (g > 5) g = 5;
  556.             if (--b < 0) b = 0;
  557.             if (b > 5) b = 5;
  558.  
  559.             *p++ = (BYTE)(r * 36 + g * 6 + b);
  560.         }
  561.         p = pBuffer + winx * (winy - 1 - y);
  562. #define DRAWUNIT 16
  563. #if 1
  564.         if (y+1 == winy || ((y+1) % DRAWUNIT) == 0) {
  565.             int line;
  566.             line = (y % DRAWUNIT) + 1;
  567.             SetDIBitsToDevice(graphdc, offsetx, offsety + (y-line+1), winx, line, 0, 0,
  568.                 0, line, p, pbmi, DIB_RGB_COLORS);
  569.         }
  570. #else
  571.         SetDIBitsToDevice(graphdc, offsetx, offsety + y, winx, 1, 0, 0,
  572.             0, 1, p, pbmi, DIB_RGB_COLORS);
  573. #endif
  574.     } else if (crtmode == RGB24) {
  575.         p = pBuffer + winx * (winy - 1 - y) * 3;
  576.         for (x = 0; x < xlen; ++x) {
  577.             *p++ = (framebuf[x] >>  8) & 255;
  578.             *p++ = (framebuf[x] >> 24) & 255;
  579.             *p++ = (framebuf[x] >> 16) & 255;
  580.         }
  581.         p = pBuffer + winx * (winy - 1 - y) * 3;
  582. #if 1
  583.         if (y+1 == winy || ((y+1) % DRAWUNIT) == 0) {
  584.             int line;
  585.             line = (y % DRAWUNIT) + 1;
  586.             SetDIBitsToDevice(graphdc, offsetx, offsety + (y-line+1), winx, line, 0, 0,
  587.                 0, line, p, pbmi, DIB_RGB_COLORS);
  588.         }
  589. #else
  590.         SetDIBitsToDevice(graphdc, offsetx, offsety + y, winx, 1, 0, 0,
  591.             0, 1, p, pbmi, DIB_RGB_COLORS);
  592. #endif
  593.     }
  594.     maxy = y+1;
  595.     check_winmessage();
  596. }
  597.  
  598. /*    CRT出力    */
  599. void    crtout( framebuf, xlen, y )
  600. unsigned short *framebuf ;
  601. int        xlen ;
  602. int        y ;
  603. {
  604.     if (crtmode == RGB16) {
  605.         int x;
  606.         BYTE *p;
  607.         p = pBuffer + winx * (winy - 1 - y) * 3;
  608.         for (x = 0; x < xlen; ++x) {
  609.             *p++ = (framebuf[x] & 0x003e) << 2;
  610.             *p++ = (framebuf[x] & 0xf800) >> 8;
  611.             *p++ = (framebuf[x] & 0x07c0) >> 3;
  612.         }
  613.         p = pBuffer + winx * (winy - 1 - y) * 3;
  614. #if 1
  615.         if (y+1 == winy || ((y+1) % DRAWUNIT) == 0) {
  616.             int line;
  617.             line = (y % DRAWUNIT) + 1;
  618.             SetDIBitsToDevice(graphdc, offsetx, offsety + (y-line+1), winx, line, 0, 0,
  619.                 0, line, p, pbmi, DIB_RGB_COLORS);
  620.         }
  621. #else
  622.         SetDIBitsToDevice(graphdc, offsetx, offsety + y, winx, 1, 0, 0,
  623.             0, 1, p, pbmi, DIB_RGB_COLORS);
  624. #endif
  625.     }
  626. }
  627.  
  628. void    crtline( x1, y1, x2, y2 )
  629. int        x1, y1, x2, y2 ;
  630. {
  631. //    HDC dc;
  632.     x1 += offsetx;
  633.     x2 += offsetx;
  634.     y1 += offsety;
  635.     y2 += offsety;
  636. //    dc = GetDC(HMainWindow);
  637.     MoveToEx(graphdc, x1, y1, NULL);
  638.     LineTo(graphdc, x2, y2);
  639. //    ReleaseDC(HMainWindow, dc);
  640. }
  641.  
  642. static char buf[1024];
  643.  
  644. int     printwarning(const char *format, ...)
  645. {
  646.     va_list arglist;
  647.  
  648.     va_start(arglist, format);
  649.     vsprintf(buf, format, arglist);
  650.     va_end(arglist);
  651.  
  652.     MessageBox(HMainWindow, buf, RendTitle, MB_ICONEXCLAMATION | MB_OK);
  653.     return 0;
  654. }
  655.  
  656. int     crtprintf(FILE * fp, const char * format, ...)
  657. {
  658.     int l;
  659.     va_list arglist;
  660.  
  661.     va_start(arglist, format);
  662.     l = vsprintf(buf, format, arglist);
  663.     va_end(arglist);
  664.  
  665.     if (fp == stderr || fp == stdout) {
  666.         crtmessage(buf);
  667.     } else {
  668.         fputs(buf, fp);
  669.     }
  670.     return l;
  671. }
  672.  
  673.  
  674.  
  675.  
  676.  
  677.