home *** CD-ROM | disk | FTP | other *** search
/ Amiga Dream 59 / CDDream59.ISO / Amiga / Emulation / cp4.lha / cp4 / c2p_src / c2p_mono.c < prev    next >
C/C++ Source or Header  |  1998-11-30  |  8KB  |  229 lines

  1. /* :ts=4                            c2p_mono.c
  2.  *
  3.  *    cp4 - Commodore C+4 emulator
  4.  *    Copyright (C) 1998 Gßti Gergely
  5.  *
  6.  *    This program is free software; you can redistribute it and/or modify
  7.  *    it under the terms of the GNU General Public License as published by
  8.  *    the Free Software Foundation; either version 2 of the License, or
  9.  *    (at your option) any later version.
  10.  *
  11.  *    This program is distributed in the hope that it will be useful,
  12.  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  *    GNU General Public License for more details.
  15.  *
  16.  *    You should have received a copy of the GNU General Public License
  17.  *    along with this program; if not, write to the Free Software Foundation,
  18.  *    Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  19.  *
  20.  *    e-mail: gatig@dragon.klte.hu
  21.  */
  22. #include <proto/graphics.h>
  23. #include <proto/exec.h>
  24. #include <proto/intuition.h>
  25.  
  26. #define C2P_INFO        "Monochrome driver on an Intuition Screen."
  27. #define C2P_VERSION        "1"
  28. #define C2P_REVISION    "1"
  29. #define C2P_AUTHOR        "gega <Gßti Gergely>"
  30. #define C2P_NAME        "Mono"
  31. #define C2P_BUFFERING    3
  32.  
  33. #include "c2p_module.c"
  34.  
  35. extern void REGARGS convfullasm(    REG(a0,void *chunkyaddr),
  36.                                     REG(a1,void *planaraddr) );
  37. extern void REGARGS convdeltaasm(    REG(a0,void *chunkyaddr),
  38.                                     REG(d0,void *delta),
  39.                                     REG(a1,void *planaraddr) );
  40.  
  41. struct GfxBase *GfxBase=NULL;
  42. struct ExecBase *SysBase;
  43. struct IntuitionBase *IntuitionBase=NULL;
  44. static int winsleeped=0;
  45. static struct Requester InvisibleRequester;
  46. static ULONG Palette[]={
  47.     2<<16,
  48.     0x00000000,0x00000000,0x00000000,
  49.     0xffffffff,0xffffffff,0xffffffff,
  50.     0L
  51. };
  52. static struct BitMap *bmap[3];
  53. static unsigned char *planars[3];
  54. static struct Screen *scr=NULL;
  55. static struct Window *win=NULL;
  56. static UWORD *nopointer=NULL;
  57. static struct ScreenBuffer *scrb[3];
  58.     int bmx;
  59. static unsigned char *lineskip;
  60. /*
  61.  * conversion table, 00/ff
  62.  */
  63. static unsigned char table[]={
  64. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  65. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  66. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  67. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  68. 0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  69. 0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  70. 0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  71. 0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  72.  
  73. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  74. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  75. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  76. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  77. 0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  78. 0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  79. 0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  80. 0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF
  81. };
  82. unsigned char *tablep=table;
  83.  
  84. /*
  85. extern void REGARGS ChunkyToPlanarFull(    REG(a0,void *chunkyaddr),
  86.                                         REG(a1,void *planaraddr),
  87.                                         REG(d0,int bmx) );
  88. extern void REGARGS ChunkyToPlanarDelta(REG(a0,void *chunkyaddr),
  89.                                         REG(a1,void *deltaaddr),
  90.                                         REG(a2,void *planaraddr),
  91.                                         REG(a3,void *lineskipaddr),
  92.                                         REG(d0,int bmx) );
  93. */
  94.  
  95.  
  96. char *SAVEDS minit(ULONG scrmode, ULONG overscan, unsigned char *linedeltatab) {
  97.     ULONG bf=BMF_CLEAR|BMF_DISPLAYABLE;
  98.  
  99.     lineskip=linedeltatab;
  100.     if(scrmode==~0) return("No ScreenMode Specified");
  101.  
  102.     SysBase=*((struct ExecBase **)4L);
  103.     if((GfxBase=(struct GfxBase *)OpenLibrary("graphics.library",39))==NULL) return("Can't open Graphics.library V39");
  104.     if(!(IntuitionBase=(struct IntuitionBase *)OpenLibrary("intuition.library",37))) return("Can't open Intuition.library V37");
  105.  
  106.     /* Allocate mem for nopointer
  107.      */
  108.     if(NULL==(nopointer=AllocVec(24,MEMF_CHIP|MEMF_CLEAR))) return(C2P_NOMEM);
  109.  
  110.     /* Allocate bitmaps
  111.      */
  112.     bmap[0]=AllocBitMap(SCRWIDTH,SCRHEIGHT,1,bf,NULL);
  113.     bmap[1]=AllocBitMap(SCRWIDTH,SCRHEIGHT,1,bf,NULL);
  114.     bmap[2]=AllocBitMap(SCRWIDTH,SCRHEIGHT,1,bf,NULL);
  115.     if(bmap[0]==NULL||bmap[1]==NULL||bmap[2]==NULL) return(C2P_NOMEM);
  116.     bmx=GetBitMapAttr(bmap[0],BMA_WIDTH)/8;
  117.     planars[0]=(unsigned char *)bmap[0]->Planes[0];
  118.     planars[1]=(unsigned char *)bmap[1]->Planes[0];
  119.     planars[2]=(unsigned char *)bmap[2]->Planes[0];
  120.  
  121.     /* Open Screen
  122.      */
  123.     if(NULL==(scr=OpenScreenTags(NULL,
  124.                 SA_DisplayID, scrmode,
  125.                 SA_Depth, 1,
  126.                 SA_ShowTitle,FALSE,
  127.                 SA_Quiet, TRUE,
  128.                    SA_Width,SCRWIDTH,
  129.                    SA_Height,SCRHEIGHT,
  130.                    SA_BitMap, (ULONG)bmap[0],
  131.                    SA_Behind, TRUE,
  132.                    SA_Colors32, (ULONG)Palette,
  133.                 SA_Overscan, overscan,
  134.                 TAG_DONE,0L )))
  135.         return("Can't open Screen");
  136.     vec.c2p_Scr=scr;
  137.  
  138.     /* Open window
  139.      */
  140.     if((win=(struct Window *)OpenWindowTags(NULL,
  141.                 WA_NoCareRefresh, TRUE,
  142.                 WA_Activate, TRUE,
  143.                 WA_Borderless, TRUE,
  144.                 WA_Backdrop, TRUE,
  145.                 WA_CustomScreen, (ULONG)scr,
  146.                 WA_RMBTrap, TRUE,
  147.                 WA_RptQueue, 25,
  148.                 TAG_DONE,0L ))==NULL)
  149.         return("Can't open Window");
  150.     vec.c2p_Win=win;
  151.     winsleeped=0;
  152.  
  153.     /* set nopointer
  154.      */
  155.     SetPointer(win,nopointer,1,16,0,0);
  156.  
  157.     /* Allocate screen buffers
  158.      */
  159.     scrb[0]=AllocScreenBuffer(scr,bmap[0],NULL);
  160.     scrb[1]=AllocScreenBuffer(scr,bmap[1],NULL);
  161.     scrb[2]=AllocScreenBuffer(scr,bmap[2],NULL);
  162.     if(scrb[0]==NULL||scrb[1]==NULL||scrb[2]==NULL) return(C2P_NOMEM);
  163.     scrb[0]->sb_DBufInfo->dbi_DispMessage.mn_ReplyPort=NULL;
  164.     scrb[0]->sb_DBufInfo->dbi_SafeMessage.mn_ReplyPort=NULL;
  165.     scrb[1]->sb_DBufInfo->dbi_DispMessage.mn_ReplyPort=NULL;
  166.     scrb[1]->sb_DBufInfo->dbi_SafeMessage.mn_ReplyPort=NULL;
  167.     scrb[2]->sb_DBufInfo->dbi_DispMessage.mn_ReplyPort=NULL;
  168.     scrb[2]->sb_DBufInfo->dbi_SafeMessage.mn_ReplyPort=NULL;
  169.     return(NULL);
  170. } // minit
  171.  
  172.  
  173. void SAVEDS mfree(void) {
  174.     mawake();
  175.     if(GfxBase) WaitTOF();
  176.     if(scrb[0]) { FreeScreenBuffer(scr,scrb[0]); scrb[0]=NULL; }
  177.     if(scrb[1]) { FreeScreenBuffer(scr,scrb[1]); scrb[1]=NULL; }
  178.     if(scrb[2]) { FreeScreenBuffer(scr,scrb[2]); scrb[2]=NULL; }
  179.     if(win) ClearPointer(win);
  180.     if(nopointer) { FreeVec(nopointer); nopointer=NULL; }
  181.     if(win) { CloseWindow(win); win=NULL; }
  182.     vec.c2p_Win=NULL;
  183.     if(scr) { CloseScreen(scr); scr=NULL; }
  184.     vec.c2p_Scr=NULL;
  185.     if(bmap[0]) { FreeBitMap(bmap[0]); bmap[0]=NULL; }
  186.     if(bmap[1]) { FreeBitMap(bmap[1]); bmap[1]=NULL; }
  187.     if(bmap[2]) { FreeBitMap(bmap[2]); bmap[2]=NULL; }
  188.     if(GfxBase) CloseLibrary((struct Library *)GfxBase);
  189.     if(IntuitionBase) { CloseLibrary((struct Library *)IntuitionBase); IntuitionBase=NULL; }
  190.     return;
  191. } // free
  192.  
  193.  
  194. int SAVEDS mdo(unsigned char *chunky,unsigned char *delta,int numscreen) {
  195.     convdeltaasm(chunky,delta,planars[numscreen]);
  196.     ChangeScreenBuffer(scr,scrb[numscreen]);
  197.     return(RET_OK);
  198. } // do
  199.  
  200. int SAVEDS mdofull(unsigned char *chunky,int numscreen) {
  201.     convfullasm(chunky,planars[numscreen]);
  202.     ChangeScreenBuffer(scr,scrb[numscreen]);
  203.     return(RET_OK);
  204. } // dofull
  205.  
  206. int SAVEDS mdont(void) {
  207.     return(RET_OK);
  208. } // dont
  209.  
  210. void SAVEDS msleep(void) {
  211.     if(win) {
  212.         InitRequester(&InvisibleRequester);
  213.         Request(&InvisibleRequester,win);
  214.         SetWindowPointer(win,WA_BusyPointer,TRUE,TAG_DONE);
  215.         winsleeped=1;
  216.     }
  217. }
  218.  
  219.  
  220. void SAVEDS mawake(void) {
  221.     if(winsleeped) {
  222.         if(win) {
  223.             EndRequest(&InvisibleRequester,win);
  224.             SetWindowPointerA(win,NULL);
  225.             winsleeped=0;
  226.         }
  227.     }
  228. }
  229.