home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD v1.2 / amidev_cd_12.iso / reference / amiga_mail_vol1 / dos / tricksados2 < prev    next >
Text File  |  1990-01-26  |  8KB  |  289 lines

  1. (c)  Copyright 1989 Commodore-Amiga, Inc.   All rights reserved.
  2. The information contained herein is subject to change without notice, and 
  3. is provided "as is" without warranty of any kind, either expressed or implied.  
  4. The entire risk as to the use of this information is assumed by the user.
  5.  
  6.  
  7.  
  8.                   Tricks with AmigaDOS, Part II
  9.  
  10.                        by Andy Finkel
  11.  
  12.  
  13. As you may recall, part one was all about finding the window pointer and
  14. console.device IO Request Block from a DOS window.  Part II is about how
  15. to go the other way: make an Intuition window into a DOS window.  
  16.  
  17. Specifically, this is used to get a DOS window to open in a custom screen. 
  18. There are reasons why this is something you might want to do, such as using 
  19. the Execute command to initialize a new disk in a program that doesn't use 
  20. the Workbench screen.  Or for those of you writing shells, under V1.2 the 
  21. ability to switch a window in or out of RAW mode via an AmigaDOS packet 
  22. can be used to good advantage.
  23.  
  24. There are 3 files:  window.c which contains most of the program, console.asm
  25. which contains the assembler interface calls to the BCPL routines of 
  26. AmigaDOS, and window.i, the include file I use when I am doing tricks
  27. like this.
  28.  
  29. Two warnings:
  30.  
  31. 1) I only compiled this under Greenhills C.  Some slight changes may be 
  32.    needed for other compilers.  Also, I'm only linking with the amiga.lib on 
  33.    this one.
  34.  
  35. 2) I used 3 of the BCPL global routines.  They are loaddevice, finddevice
  36.    and send-packet.
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44. ***********************************************************************
  45. * window.i
  46. * contents: useful macros/definitions from Tim King
  47. * 9/15/86
  48. *
  49. * (c) 1986 Commodore-Amiga, Inc.
  50. * This file may be used in any manner, as long as this copyright notice
  51. * remains intact.
  52. *         andy finkel
  53. *        Commodore-Amiga
  54. *
  55. ***********************************************************************
  56.  
  57. procst  macro
  58.         link    a6,\1
  59.         movem.l \2,-(sp)
  60.         sub.l   z,z
  61.         endm
  62.  
  63. return  macro
  64.         movem.l (sp)+,\1
  65.         unlk    a6
  66.         rts
  67.         endm
  68.  
  69. callg   macro
  70.         move.l  a6,-(sp)
  71.         move.l  #\1,d0
  72.         move.l  _DOSBase,a6
  73.         jsr     -28(a6)
  74.         move.l  (sp)+,a6
  75.         endm
  76.  
  77. * Registers
  78. Z       equr    a0
  79. *P      equr    a1
  80. *G      equr    a2
  81. L       equr    a3
  82. B       equr    a4
  83. S       equr    a5
  84. R       equr    a6
  85.  
  86. arg1    equ     8
  87. arg2    equ     12
  88. arg3    equ     16
  89. arg4    equ     20
  90.  
  91. *****************************
  92. * end of file window.i
  93. *****************************
  94.  
  95. -------------------------CUT HERE -------------------------------
  96. /*        window.c
  97.    or, how to open a DOS window in a custom screen
  98.    and do something like format a disk
  99.    (c) 1986 Commodore-Amiga, Inc.
  100.    This file may be used in any manner, as long as this copyright notice
  101.    remains intact.
  102.           andy finkel
  103.          Commodore-Amiga
  104. */
  105. #include "exec/types.h"
  106. #include "exec/libraries.h"
  107. #include "graphics/gfx.h"
  108. #include "intuition/intuition.h"
  109. #include "libraries/dos.h"
  110. #include "libraries/dosextens.h"
  111.  
  112. #define BLUE 0 
  113. #define WHITE 1 
  114. #define BLACK 2 
  115. #define RED 3 
  116.  
  117. struct GfxBase *GfxBase; 
  118. LONG *IntuitionBase;
  119. LONG *DosBase;
  120.  
  121. extern struct Library *OpenLibrary();
  122. extern struct Screen *OpenScreen();
  123. extern struct Window *OpenWindow();
  124.  
  125. extern struct MsgPort  *NewConsole();
  126.  
  127. struct Window   *window=NULL;
  128. struct Screen   *screen=NULL;
  129. struct MsgPort  *task=NULL;
  130. struct Process  *process=NULL;
  131.  
  132. LONG handle=NULL;
  133.  
  134. struct NewScreen ns = {
  135.         0,0,
  136.         320,200,4, /* & depth */
  137.         BLUE,WHITE,
  138.         NULL,  /* viewmodes */
  139.         CUSTOMSCREEN,
  140.         NULL, /* default font */
  141.         "Window Test Program",
  142.         NULL, /* no user gadgets */
  143.         NULL
  144. };
  145.  
  146. struct NewWindow nw = {
  147.         0, 12,          /* starting position (left,top) */
  148.         320,186,        /* width, height */
  149.         BLUE,WHITE,    /* detailpen, blockpen */
  150.         NULL,  /* flags for idcmp */
  151.         SMART_REFRESH|WINDOWDEPTH|WINDOWSIZING|WINDOWDRAG|ACTIVATE, /* window gadget flags */
  152.         NULL,           /* pointer to 1st user gadget */
  153.         NULL,           /* pointer to user check */
  154.         NULL,            /* no title */
  155.         NULL,           /* pointer to window screen (add after it is open */
  156.         NULL,           /* pointer to super bitmap */
  157.         50,50,         /* min width, height */
  158.         320,200,        /* max width, height */
  159.         CUSTOMSCREEN};
  160.  
  161. main()
  162. {
  163. if((IntuitionBase = OpenLibrary("intuition.library",0)) == NULL)cleanup(20);
  164. if((DosBase = OpenLibrary(DOSNAME, 0)) == NULL) cleanup(20);
  165. if((GfxBase = OpenLibrary("graphics.library", 0)) ==NULL) cleanup(20);
  166.  
  167. if((screen=OpenScreen(&ns)) == NULL)cleanup(20);
  168. nw.Screen=screen;
  169. if((window=OpenWindow(&nw)) == NULL)cleanup(20); 
  170.  
  171. /* Start up new console handler task; pass it new window */
  172.  
  173. if(!(task = NewConsole(window)))cleanup(20);
  174.  
  175. /* Change AmigaDOS consoletask location. All later calls to */
  176. /* Open("*") by this process will refer to the new window */
  177.  
  178. process = (struct Process *)FindTask(NULL); 
  179. process -> pr_ConsoleTask = task;
  180.  
  181. process->pr_WindowPtr=window; /*reset error screen so requesters appear here*/
  182.  
  183. if (!(handle = Open("*", MODE_OLDFILE))) { /* get a handle on the window */
  184.     CloseConsole(task); /* open failed, kill our console task */
  185.     cleanup(20);
  186.    }
  187.  
  188.     Write(handle,"\033[20hHello world\n",17);
  189.  
  190.     Write(handle,"I'm about to format drive 1\n",28);
  191. /* SAMPLE COMMAND; THIS IS OPTIONAL, FOR DEMO PURPOSES ONLY) */
  192.     Execute("format <* >* drive df1: name test",0,0);
  193.  
  194.     cleanup(0);
  195. }
  196.  
  197.  
  198. cleanup(code)
  199. {
  200. struct Process *process;
  201.  
  202. process = (struct Process *)FindTask(NULL); /* reset error window */
  203. process->pr_WindowPtr=NULL;
  204. process -> pr_ConsoleTask = NULL;;
  205.  
  206. if(handle)Close(handle);
  207. if(screen)CloseScreen(screen);
  208.  
  209. if(GfxBase)CloseLibrary(GfxBase);
  210. if(DosBase)CloseLibrary(DosBase);
  211.  
  212. OpenWorkBench(); /* just in case */
  213. if(IntuitionBase)CloseLibrary(IntuitionBase); 
  214.  
  215. exit(code);
  216.  
  217. }
  218. /* end of file window.c */
  219.  
  220. -------------------------CUT HERE ---------------------
  221. **********************************************
  222. * console.asm
  223. * contents: code to spawn a new console task  
  224. * From Tim King (more or less)
  225. * (C) 1986 Commodore-Amiga
  226. *
  227. * (c) 1986 Commodore-Amiga, Inc.
  228. * This file may be used in any manner, as long as this copyright notice
  229. * remains intact.
  230. *         andy finkel
  231. *        Commodore-Amiga
  232. *
  233. ************************************
  234.     include    "window.i"
  235.  
  236.     xdef    _NewConsole
  237.     xdef    _CloseConsole
  238.     xref    _DOSBase
  239.  
  240. startup    equ    28    offset into device style DevList structure
  241.             * (the include file said the DevList structure
  242.             * needed some work !)
  243.  
  244. act_end        equ    1007
  245.  
  246. g_sendpkt    equ    48
  247. g_loaddevice    equ    112
  248. g_finddevice    equ    124
  249.  
  250. * task = NewConsole(Window)
  251. * create a console task in an already opened window
  252. * and return its handle
  253.  
  254. _NewConsole:
  255.     procst    #0,d2/a2/a5
  256.     move.l    #conname,d1    d1 = address of "CON" string
  257.     lsr.l    #2,d1        arg1 = BCPL address of string
  258.     callg    g_finddevice    get console device node
  259.     move.l    d0,d1        send it in arg1
  260.     lsl.l    #2,d0        d0 = address of node
  261.     move.l    d0,a2        save it in a2
  262.     move.l    #-1,startup(a2)    tell it not to create another window
  263.     move.l    arg1(a6),d2    arg2 = window structure pointer
  264.     callg    g_loaddevice
  265.     clr.l    startup(a2)    zero startup- we're cool now
  266.     return    d2/a2/a5
  267.  
  268. * CloseConsole( task )
  269. * shutdown the console task
  270. _CloseConsole:
  271.     procst    #0,d2-d4
  272.     move.l    arg1(a6),d2    d2 = destination task
  273.     move.l    #act_end,d3    d3 = action
  274.     callg    g_sendpkt    send the pkt off
  275.     return    d2-d4
  276.  
  277.     cnop    0,4
  278.  
  279. conname    dc.b    3,'C','O','N'
  280.  
  281.     end
  282.  
  283. ****************************
  284. * end of file console.asm
  285. ****************************
  286. -------------------------CUT HERE *********************
  287.  
  288.