home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / files / other / cled122s / source / gem.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-05-14  |  15.4 KB  |  468 lines

  1. #include "define.h"
  2. #include <obdefs.h>                /* OBJECT DEFINTIONS              */
  3. #include <gemdefs.h>               /* GEM DEFINITIONS                */
  4. #include <osbind.h>                /* BIOS/GEMDOS/XBIOS FUNCTIONS    */
  5. #include <vdibind.h>               /* VDI DECLERATIONS AND BINDINGS  */
  6. #include <aesbind.h>               /* BINDINGS FOR AES               */
  7. #include "cled.h"                  /* RESOURCE FILE CODES            */
  8. #include "window.h"                /* WINDOW RECORD STRUCTURE        */
  9.  
  10. extern int hidden;
  11. extern int handle;
  12. extern unsigned char data[3][40];
  13.  
  14. /****************************************************************************
  15. SUBROUTINE  :  hide/show               VERSION  : 1.0   
  16. AUTHOR      :  ROBERT ALLEY            DATE     :  
  17. DESCRIPTION :  hide or show the mouse pointer
  18. LOGIC USED  :  STEP 1.  If not hidden hide or vice versa.
  19. RETURNS     :  none.
  20. PARAMETERS  :  none.
  21. VARIABLES   :  none.
  22. CONSTANTS   :  none.
  23. REQD. FILES :  None.
  24. REQD. SUBPG.:  none.
  25. NOTES       :  Documented as one to save space.
  26. USAGE       :  hide(); / show();
  27. ****************************************************************************/
  28. hide()
  29.    {
  30.    if (!hidden)
  31.       {
  32.       v_hide_c(handle);
  33.       hidden=1;
  34.       }
  35.    }
  36. show()
  37.    {
  38.    if (hidden)
  39.       {
  40.       v_show_c(handle,0);
  41.       hidden=0;
  42.       }
  43.    }
  44.  
  45. /****************************************************************************
  46. SUBROUTINE  :  check_res               VERSION  : 1.0   
  47. AUTHOR      :  ROBERT ALLEY            DATE     :  
  48. DESCRIPTION :  check the res we are in and abort if not ok
  49. LOGIC USED  :  STEP 1.  Get the current screen res, if not high or medium,
  50.                         form alert box telling user we cant run in other
  51.                         resolutions, exit program.
  52. RETURNS     :  none.
  53. PARAMETERS  :  none.
  54. VARIABLES   :  res         I        Resolution code.
  55. CONSTANTS   :  none.
  56. REQD. FILES :  None.
  57. REQD. SUBPG.:  None.
  58. NOTES       :  None.
  59. USAGE       :  check_res();
  60. ****************************************************************************/
  61. check_res()
  62. {
  63.    int res;
  64.  
  65.   res=Getrez();
  66.    if ((res!=2) && (res!=1)) {
  67.       form_alert(1,"[0][This program only  |  works in Hi/MED-res. |   Terminating.   ][OK]");
  68.       exit(1);
  69.    }
  70. }
  71.  
  72. /****************************************************************************
  73. SUBROUTINE  :  gem_on                  VERSION  : 1.0   
  74. AUTHOR      :  ROBERT ALLEY            DATE     :  
  75. DESCRIPTION :  Start up GEM
  76. LOGIC USED  :  STEP 1.  Get applicvation ID number, open screen as physical
  77.                         workstation.  Open virtual workstation.
  78. RETURNS     :  none.
  79. PARAMETERS  :  nnoe.
  80. VARIABLES   :  none.
  81. CONSTANTS   :  none.
  82. REQD. FILES :  None.
  83. REQD. SUBPG.:  open_vwork
  84. NOTES       :  None.
  85. USAGE       :  gem_on();
  86. ****************************************************************************/
  87. gem_on()
  88. {
  89.    extern int gl_wchar,gl_hchar,gl_wbox,gl_hbox;
  90.    extern int phys_handle;
  91.    extern int gl_apid;
  92.  
  93.    gl_apid=appl_init();
  94.    phys_handle=graf_handle(&gl_wchar,&gl_hchar,&gl_wbox,&gl_hbox);
  95.    open_vwork();
  96.  
  97. }
  98.  
  99. /****************************************************************************
  100. SUBROUTINE  :  gem_off                 VERSION  : 1.01
  101. AUTHOR      :  ROBERT ALLEY            DATE     : 31/05/90
  102. DESCRIPTION :  Finish with GEM
  103. LOGIC USED  :  STEP 1.  Close the virtual workstation, exit application.
  104. RETURNS     :  none.
  105. PARAMETERS  :  none.
  106. VARIABLES   :  none.
  107. CONSTANTS   :  none.
  108. REQD. FILES :  None.
  109. REQD. SUBPG.:  none.
  110. NOTES       :  Added () after appl_exit call.
  111. USAGE       :  gem_off();
  112. ****************************************************************************/
  113. gem_off()
  114. {
  115.    v_clsvwk(handle);
  116.    appl_exit();
  117. }
  118.  
  119. /****************************************************************************
  120. SUBROUTINE  :  open_vwork              VERSION  : 1.0   
  121. AUTHOR      :  ROBERT ALLEY            DATE     :  
  122. DESCRIPTION :  Open a virtual workstation
  123. LOGIC USED  :  STEP 1.  Loop through the worksation parameters, initialising
  124.                         them to 1.  Set work_in[10] to 2 (ie. rect. co-ords)
  125.                         Copy physical workstation handle.  Open virtual
  126.                         workstation.
  127. RETURNS     :  none.
  128. PARAMETERS  :  none.
  129. VARIABLES   :  i           I        Loop counter
  130. CONSTANTS   :  none.
  131. REQD. FILES :  None.
  132. REQD. SUBPG.:  none. 
  133. NOTES       :  None.
  134. USAGE       :  open_vwork();
  135. ****************************************************************************/
  136. open_vwork()
  137. {
  138.  
  139.    extern int work_in[11];                 /* Input to GSX parameter array     */
  140.    extern int work_out[57];                /* Output from GSX parameter array  */
  141.    extern int phys_handle;
  142.    
  143.    int i;
  144.    
  145.    for(i=0;i<10;work_in[i++]=1);
  146.    work_in[10]=2;
  147.    handle=phys_handle;
  148.    v_opnvwk(work_in,&handle,work_out);
  149. }
  150.  
  151. /****************************************************************************
  152. SUBROUTINE  :  open_window             VERSION  : 2.1   
  153. AUTHOR      :  ROBERT ALLEY            DATE     : 28/3/90 
  154. DESCRIPTION :  Open a screen window.
  155. LOGIC USED  :  STEP 1.  If window is allready open send an application 
  156.                         message to top it.  If window isnt yet created
  157.                         create it.  If window was just created or was
  158.                         closed then set the window name.  Draw a growing 
  159.                         box.  Open the window, get the inner co-ordinates. 
  160. RETURNS     :        I     0=window opened, -1=couldnt open.
  161. PARAMETERS  :  wind        *WINDOW  Pointer to window structure.
  162. VARIABLES   :  none.
  163. CONSTANTS   :  none.
  164. REQD. FILES :  None.
  165. REQD. SUBPG.:  None.
  166. NOTES       :  None.
  167. USAGE       :  open_window(&window);
  168. ****************************************************************************/
  169. int open_window(wind)
  170. struct WINDOW *wind;
  171. {
  172.    extern int gl_wbox,gl_hbox;
  173.    extern int gl_apid;
  174.    short msg[8];
  175.  
  176.    
  177.    if (wind->open == 1) {
  178.       msg[0]=WM_TOPPED;
  179.       msg[1]=gl_apid;
  180.       msg[2]=0;
  181.       msg[3]=wind->handle;
  182.       msg[4]=0;
  183.       msg[5]=0;
  184.       msg[6]=0;
  185.       msg[7]=0;
  186.       appl_write( gl_apid, 16, msg);
  187.     }
  188.    if (wind->open == -1) /* If window not yet created, do it */
  189.       wind->handle=wind_create(wind->kind,wind->fullx,wind->fully,wind->fullw,wind->fullh);
  190.    if ( ((wind->open == -1 ) && (wind->handle >= 0)) || (wind->open==0)) {
  191.       wind_set(wind->handle, WF_NAME,wind->title,0,0);
  192.       graf_growbox(wind->outx+wind->outw/2,wind->outy+wind->outh/2,gl_wbox,gl_hbox,wind->outx,wind->outy,wind->outw,wind->outh);
  193.       wind_open(wind->handle,wind->outx,wind->outy,wind->outw,wind->outh);
  194.       wind_get(wind->handle,WF_WORKXYWH,&wind->inx,&wind->iny,&wind->inw,&wind->inh);
  195.       wind->open=1;
  196.    }
  197.    if (wind->handle >= 0) return(0);
  198.    else return(-1);
  199. }
  200.  
  201. /****************************************************************************
  202. SUBROUTINE  :  plot                    VERSION  : 1.0   
  203. AUTHOR      :  ROBERT ALLEY            DATE     :  
  204. DESCRIPTION :  Draw or erase a graphic box.
  205. LOGIC USED  :  STEP 1.  Hide the mouse, set interior and style types (solid)
  206.                         if mode=1 (ie. draw) set colour to 1, if mode=2 set
  207.                         colour to zero.  Draw a box in given area.  Show the
  208.                         mouse.
  209. RETURNS     :  none.
  210. PARAMETERS  :  mode        I        Mode to draw in, 1=draw, 2=erase
  211.                box         I*4      Co-ords to draw box at.
  212. VARIABLES   :  None.
  213. CONSTANTS   :  None.
  214. REQD. FILES :  None.
  215. REQD. SUBPG.:  None.
  216. NOTES       :  None.
  217. USAGE       :  plot(mode,box);
  218. ****************************************************************************/
  219. plot(mode,box)
  220. int mode,box[4];
  221. {
  222.    hide();
  223.    vsf_interior(handle,2);
  224.    vsf_style(handle,8);
  225.  
  226.    if (mode==1)
  227.       vsf_color(handle,1);
  228.    if (mode==2) 
  229.       vsf_color(handle,0);
  230.    v_bar(handle,box);
  231.    show();
  232. }
  233.  
  234. /****************************************************************************
  235. SUBROUTINE  :  clear_window            VERSION  : 1.0   
  236. AUTHOR      :  ROBERT ALLEY            DATE     :  
  237. DESCRIPTION :  Clear the given window 
  238. LOGIC USED  :  STEP 1.  Hide the mouse.  Set up drawing mode to solid box in
  239.                         background colour.  Copy window interior co-ords into
  240.                         temp, draw box over window.  Show the mouse.
  241. RETURNS     :  None.
  242. PARAMETERS  :  wind        *WINDOW  Pointer to window structure
  243. VARIABLES   :  temp        I*4      Temp holder for co-ords.
  244. CONSTANTS   :  None.
  245. REQD. FILES :  None.
  246. REQD. SUBPG.:  None. 
  247. NOTES       :  None.
  248. USAGE       :  clear_window(&window_struct);
  249. ****************************************************************************/
  250. clear_window(wind)
  251. struct WINDOW *wind;
  252. {
  253.    int temp[4];
  254.  
  255.    hide();
  256.    vsf_interior(handle,2);
  257.    vsf_style(handle,8);
  258.    vsf_color(handle,0);
  259.    temp[0]=wind->inx;
  260.    temp[1]=wind->iny;
  261.    temp[2]=wind->inx+wind->inw-1;
  262.    temp[3]=wind->iny+wind->inh-1;
  263.    v_bar(handle,temp);
  264.    show();
  265. }
  266.  
  267. /****************************************************************************
  268. SUBROUTINE  :  load_rsrc               VERSION  : 1.0   
  269. AUTHOR      :  ROBERT ALLEY            DATE     :  
  270. DESCRIPTION :  Load the resource file from disk
  271. LOGIC USED  :  STEP 1.  Load the resource file from disk, if unable to then
  272.                         form an alert, exit program.
  273. RETURNS     :  None.
  274. PARAMETERS  :  None.
  275. VARIABLES   :  None.
  276. CONSTANTS   :  None.
  277. REQD. FILES :  None.
  278. REQD. SUBPG.:  None.
  279. NOTES       :  None.
  280. USAGE       :  load-rsrc(); 
  281. ****************************************************************************/
  282. load_rsrc()
  283. {
  284.    if (!rsrc_load("cled.rsc")) {
  285.       form_alert(1, "[0][Cannot find cled.rsc file|Terminating ...][OK]");
  286.       exit(1);
  287.    }
  288. }
  289.  
  290. /****************************************************************************
  291. SUBROUTINE  :  do_dialog               VERSION  : 1.0   
  292. AUTHOR      :  ROBERT ALLEY            DATE     :  
  293. DESCRIPTION :  form and handle a dialog
  294. LOGIC USED  :  STEP 1.  Get co-ords of centred dialog, reserve space for
  295.                         dialog, draw it, handle input, remove dialog and
  296.                         free up space.
  297. RETURNS     :  None.
  298. PARAMETERS  :  dialog      *OBJECT  Pointer to dialog to form
  299. VARIABLES   :  cx-h        I        Centred co-ords.
  300. CONSTANTS   :  None.
  301. REQD. FILES :  None.
  302. REQD. SUBPG.:  None.
  303. NOTES       :  None.
  304. USAGE       :  do_dialog(&ialog);
  305. ****************************************************************************/
  306. do_dialog(dialog)
  307.    OBJECT *dialog;
  308. {
  309.    int cx, cy, cw, ch;
  310.  
  311.    form_center(dialog, &cx, &cy, &cw, &ch);
  312.    form_dial(FMD_START, 0,0,0,0,cx, cy, cw, ch);
  313.    objc_draw(dialog, 0, 10, cx, cy, cw, ch);
  314.    form_do(dialog, 0);
  315.    form_dial(FMD_FINISH, 0,0,0,0,cx, cy, cw, ch);
  316. }
  317.  
  318. /****************************************************************************
  319. SUBROUTINE  :  scrollv                 VERSION  : 1.0   
  320. AUTHOR      :  ROBERT ALLEY            DATE     : 24/3/90
  321. DESCRIPTION :  Vertically scroll contents of graphic window.
  322. LOGIC USED  :  STEP 1.
  323. RETURNS     :  none.
  324. PARAMETERS  :  wind        &WINDOW   Pointer to window structure of graph 
  325.                                      window
  326.                dir         I         Direction to scroll, 1=down, 2=up
  327. VARIABLES   :  la,lb       I         Loop counters
  328.                last        SI*3*40   Array to hold bits that are rolled over.
  329. CONSTANTS   :  None.
  330. REQD. FILES :  None.
  331. REQD. SUBPG.:  send_redraw
  332. NOTES       :  None.
  333. USAGE       :  scrollv(WINDOW *,int);
  334. ****************************************************************************/
  335. scrollv(wind,dir)
  336. struct WINDOW *wind;
  337. int dir;
  338. {
  339.    int la,lb;
  340.    short int last[3][40];
  341.  
  342.    if (dir==1) {
  343.       for (la=0;la<40;la++) {
  344.          if ((data[2][la]& 1)!=0) last[0][la]=128; 
  345.          else last[0][la]=0;
  346.          if ((data[1][la]& 1)!=0) last[2][la]=128; 
  347.          else last[2][la]=0;
  348.          if ((data[0][la]& 1)!=0) last[1][la]=128; 
  349.          else last[1][la]=0;
  350.       }
  351.    }
  352.    else {
  353.       for (la=0;la<40;la++) {
  354.          if ((data[2][la]& 128)!=0) last[1][la]=1; 
  355.          else last[1][la]=0;
  356.          if ((data[1][la]& 128)!=0) last[0][la]=1; 
  357.          else last[0][la]=0;
  358.          if ((data[0][la]& 128)!=0) last[2][la]=1; 
  359.          else last[2][la]=0;
  360.       }
  361.    }
  362.  
  363.    for (la=0;la<3;la++)
  364.       for (lb=0;lb<40;lb++) {
  365.          if (dir==1) data[la][lb]/=2;
  366.          else data[la][lb]*=2;
  367.          data[la][lb]|=last[la][lb];
  368.       }
  369.    send_redraw(wind);
  370. }
  371.  
  372. /****************************************************************************
  373. SUBROUTINE  :  scrollh                 VERSION  : 1.0   
  374. AUTHOR      :  ROBERT ALLEY            DATE     : 24/03/90
  375. DESCRIPTION :  Scroll contents of graphic window horizontally
  376. LOGIC USED  :  STEP 1.
  377. RETURNS     :  none.
  378. PARAMETERS  :  wind        &WINDOW   Pointer to window structure of graph 
  379.                                      window
  380.                dir         I         Direction to scroll, 1=right, 2=left
  381. VARIABLES   :  la,lb       I         Loop counters
  382.                temp        I         Holds bytes that are rolled over.
  383. CONSTANTS   :  None.
  384. REQD. FILES :  None.
  385. REQD. SUBPG.:  send_redraw
  386. NOTES       :  None.
  387. USAGE       :  scrollh(WINDOW *,int);
  388. ****************************************************************************/
  389. scrollh(wind,dir)
  390. struct WINDOW *wind;
  391. int dir;
  392. {
  393.    int la,lb;
  394.    int temp;
  395.  
  396.    if (dir==1) {
  397.       for (la=0;la<3;la++) {
  398.          for (lb=39;lb>0;lb--) {
  399.             if (lb==39) temp=data[la][lb];
  400.             data[la][lb]=data[la][lb-1];
  401.          }
  402.          data[la][0]=temp;
  403.       }
  404.    }
  405.    else {
  406.       for (la=0;la<3;la++) {
  407.          for (lb=0;lb<39;lb++) {
  408.             if (lb==0) temp=data[la][lb];
  409.             data[la][lb]=data[la][lb+1];
  410.          }
  411.          data[la][39]=temp;
  412.       }
  413.    }
  414.    send_redraw(wind);
  415. }
  416.  
  417. mirror(wind)
  418. struct WINDOW *wind;
  419. {
  420.    int temp;
  421.    int row,col;
  422.  
  423.    for (row=0;row<3;row++)
  424.       for (col=0;col<20;col++) {
  425.          temp=data[row][col];
  426.          data[row][col]=data[row][39-col];
  427.          data[row][39-col]=temp;
  428.       }
  429.    send_redraw(wind);
  430. }
  431.  
  432. /****************************************************************************
  433. SUBROUTINE  :  send_redraw             VERSION  : 1.0
  434. AUTHOR      :  ROBERT ALLEY            DATE     : 24/03/90
  435. DESCRIPTION :  Send a redraw message for the given window
  436. LOGIC USED  :  STEP 1.  Put redraw code, application ID no., 0 (indicates
  437.                         message is standard 16 bytes), window handle and
  438.                         window dimension in message array.  Send message
  439.                         to application.
  440. RETURNS     :  none.
  441. PARAMETERS  :  wind        &WINDOW  Pointer to window struct of window to
  442.                                     redraw.
  443. VARIABLES   :  msg         I*8      Message buffer array.
  444. CONSTANTS   :  None.
  445. REQD. FILES :  None.
  446. REQD. SUBPG.:  None.
  447. NOTES       :  None.
  448. USAGE       :  send_redraw(&WINDOW);
  449. ****************************************************************************/
  450. send_redraw(wind)
  451. struct WINDOW *wind;
  452. {
  453.    extern int gl_apid;
  454.  
  455.    short msg[8];
  456.  
  457.    msg[0]=WM_REDRAW;
  458.    msg[1]=gl_apid;
  459.    msg[2]=0;
  460.    msg[3]=wind->handle;
  461.    msg[4]=wind->inx;
  462.    msg[5]=wind->iny;
  463.    msg[6]=wind->inw;
  464.    msg[7]=wind->inh;
  465.    appl_write( gl_apid, 16, msg);
  466. }
  467.  
  468.