|
|
1.1 root 1: /*
2: * UAE - The Un*x Amiga Emulator
1.1.1.4 ! root 3: *
1.1 root 4: * ami-rexx.c
1.1.1.4 ! root 5: *
1.1 root 6: * Copyright 1996 Samuel Devulder.
7: *
8: * History:
9: * 05/09/97: Added UAEEXE support.
1.1.1.2 root 10: * 04/03/98: Added event-hack for SOUND(). Added do_inhibit_frame().
11: * 03/05/98: Modified currprefs to changed_prefs where necessary.
1.1 root 12: */
13:
1.1.1.2 root 14: /****************************************************************************/
15:
16: #if defined(POWERUP)
17: #include <exec/exec.h> /* sam: I've added this or else I have warnings about missing struct def. */
18: #ifndef USE_CLIB
19: #include <powerup/ppcproto/exec.h>
20: #include <powerup/ppcproto/rexxsyslib.h>
21: #include <powerup/ppcproto/dos.h>
22: #else
23: #include <clib/exec_protos.h>
24: #include <clib/alib_protos.h>
25: #endif
26: #else
1.1 root 27: #include <proto/exec.h>
28: #include <proto/rexxsyslib.h>
29: #include <proto/dos.h>
30: #ifndef __SASC
31: #include <proto/alib.h>
32: #endif
1.1.1.2 root 33: #endif
1.1 root 34:
35: #include <rexx/storage.h>
36: #include <rexx/errors.h>
37:
38: /* this prevent a conflict between <rexx/rexxio.h> and <sys/dirent.h> */
1.1.1.4 ! root 39: #undef DT_DIR
1.1 root 40:
41: /****************************************************************************/
42:
43: #include "sysconfig.h"
44: #include "sysdeps.h"
45: #include "uae.h"
46: #include "config.h"
47: #include "options.h"
48: #ifdef __GNUC__
49: #include "../include/memory.h" /* or else gcc includes machdep/memory.h */
1.1.1.2 root 50: #else
51: #include "/include/memory.h"
1.1 root 52: #endif
1.1.1.2 root 53: #include "events.h"
1.1 root 54: #include "custom.h"
55: #include "readcpu.h"
56: #include "newcpu.h"
57: #include "disk.h"
58: #include "gui.h"
59: #include "sound.h"
60: #include "gensound.h"
61: #include "uaeexe.h"
1.1.1.3 root 62: #include "threaddep/thread.h"
1.1 root 63: #include "xwin.h"
64:
65: #include <ctype.h>
66:
67: /****************************************************************************/
68:
69: #define UAE_PORTNAME "UAE"
70: #define RESULT_LEN 1024
71: #define PORT_LEN 80
72: #define CMD_LEN 1024
73:
74: typedef struct
75: {
76: char port[PORT_LEN];
77: char cmd_on[CMD_LEN];
78: char cmd_off[CMD_LEN];
79: } gui_rexx_s;
80:
81: enum {LED_POW, LED_DF0, LED_DF1, LED_DF2, LED_DF3,
82: NAME_DF0, NAME_DF1, NAME_DF2, NAME_DF3,
83: ON_EXIT,
84: GUI_REXX_MAX};
85:
86: /****************************************************************************/
87:
88: int rexx_init(void);
89: void rexx_exit(void);
90: void rexx_led(int led, int on);
91: void rexx_filename(int num, char *name);
92: void rexx_handle_events(void);
1.1.1.2 root 93: int do_inhibit_frame(int); /* from ami-win.c */
1.1 root 94:
95: /****************************************************************************/
96:
97: #ifdef __GNUC__
98: struct RxsLib
99: #else
100: struct Library
101: #endif
1.1.1.4 ! root 102: *RexxSysBase;
1.1 root 103: static struct MsgPort *ARexxPort;
104: static gui_rexx_s gui_rexx[GUI_REXX_MAX];
105: static char RESULT[RESULT_LEN];
106: static int led_state[5];
107:
108: static int ADDRESS(char *hostname, char *cmd);
109: static int matchstr(char **line,char *pat);
110: static void extractstr(char **line, char *result, int len);
111: static int matchnum(char **line);
112:
113: /****************************************************************************/
114:
115: extern int quit_program; /* ami-gui.c */
1.1.1.2 root 116: extern ULONG frame_num; /* ami-win.c */
1.1 root 117: extern void activate_debugger(void); /* debug.c */
118: extern char *to_unix_path(char *s); /* ami-disk.c */
119: extern char *from_unix_path(char *s); /* ami-disk.c */
120:
121: /****************************************************************************/
122:
123: int rexx_init(void)
124: {
125: quit_program = 0;
126: RexxSysBase = (void*)OpenLibrary("rexxsyslib.library",0L);
127: if(!RexxSysBase) {
1.1.1.4 ! root 128: fprintf(stderr, "Can't find rexxsyslib.library!\n");
! 129: return 1;
1.1 root 130: }
131: if(FindPort(UAE_PORTNAME)) {
1.1.1.4 ! root 132: fprintf(stderr, "Port \"%s\" already exists!\n",UAE_PORTNAME);
! 133: return 1;
1.1 root 134: }
135: ARexxPort = CreatePort(UAE_PORTNAME,0);
136: if(!ARexxPort) {
1.1.1.4 ! root 137: fprintf(stderr, "Failed to open AREXX port \"%s\"!\n",UAE_PORTNAME);
! 138: return 1;
1.1 root 139: }
140: fprintf(stderr,"Rexx port \"%s\" installed.\n", UAE_PORTNAME);
141: rexx_handle_events();
142: return 0;
143: }
144:
145: /****************************************************************************/
146:
147: void rexx_exit(void)
148: {
149: if(ARexxPort) {
1.1.1.4 ! root 150: struct RexxMsg *msg;
! 151: gui_rexx_s *gui = &gui_rexx[ON_EXIT];
1.1 root 152:
1.1.1.4 ! root 153: if(gui->port[0] && gui->cmd_on[0]) {
! 154: if(ADDRESS(gui->port, gui->cmd_on) != RC_OK) {
! 155: fprintf(stderr,"%s:%s:%s\n", gui->port,
! 156: gui->cmd_on,
! 157: RESULT);
! 158: }
! 159: gui->port[0] = '\0';
! 160: }
! 161: Forbid();
! 162: while((msg = (struct RexxMsg*)GetMsg(ARexxPort))) {
! 163: msg->rm_Result1 = RC_ERROR;
! 164: msg->rm_Result2 = NULL;
! 165: ReplyMsg((void*)msg);
! 166: }
! 167: DeletePort(ARexxPort);
! 168: Permit();
! 169: ARexxPort = NULL;
1.1 root 170: }
171: if(RexxSysBase) {
1.1.1.4 ! root 172: CloseLibrary((void*)RexxSysBase);
! 173: RexxSysBase = NULL;
1.1 root 174: }
175: }
176:
177: /****************************************************************************/
178:
179: static int EJECT(char *line)
180: {
181: int drive = matchnum(&line);
182: if(drive<0 || drive>3) return RC_WARN;
183: disk_eject(drive);
184: sprintf(RESULT,"Drive %d ejected",drive);
185: return RC_OK;
186: }
187:
188: /****************************************************************************/
189:
190: static int INSERT(char *line)
191: {
192: int drive = matchnum(&line);
193: if(drive<0 || drive>3) return RC_WARN;
194: if(disk_empty(drive)) {
1.1.1.4 ! root 195: char buff[256];
! 196: char *name;
! 197: extractstr(&line, buff, 256);
! 198: name = to_unix_path(buff);
! 199: disk_insert(drive, name);
! 200: free(name);
1.1 root 201: } else {
1.1.1.4 ! root 202: sprintf(RESULT,"Drive %d not empty!",drive);
! 203: return RC_WARN;
1.1 root 204: }
205: return RC_OK;
206: }
207:
208: /****************************************************************************/
209:
210: static void QUIT(void)
211: {
212: broken_in = 1;
213: regs.spcflags |= SPCFLAG_BRK;
214: quit_program = 1;
215: }
216:
217: /****************************************************************************/
218:
219: static int QUERY(char *line)
220: {
221: char *res = NULL;
222: int alc = 0;
223:
224: if (matchstr(&line, "LED_POW")) res = led_state[0]?"1":"0";
225: else if(matchstr(&line, "LED_DF0")) res = led_state[1]?"1":"0";
226: else if(matchstr(&line, "LED_DF1")) res = led_state[2]?"1":"0";
227: else if(matchstr(&line, "LED_DF2")) res = led_state[3]?"1":"0";
228: else if(matchstr(&line, "LED_DF3")) res = led_state[4]?"1":"0";
229: else if(matchstr(&line, "NAME_DF0")) res = from_unix_path(currprefs.df[0]), alc = 1;
230: else if(matchstr(&line, "NAME_DF1")) res = from_unix_path(currprefs.df[1]), alc = 1;
231: else if(matchstr(&line, "NAME_DF2")) res = from_unix_path(currprefs.df[2]), alc = 1;
232: else if(matchstr(&line, "NAME_DF3")) res = from_unix_path(currprefs.df[3]), alc = 1;
233: else if(matchstr(&line, "FAKEJOYSTICK")) res = currprefs.fake_joystick?"1":"0";
234: else if(matchstr(&line, "DISPLAY")) res = inhibit_frame?"0":"1";
235: else if(matchstr(&line, "FRAMERATE")) {
1.1.1.4 ! root 236: sprintf(RESULT,"%d",currprefs.framerate);
! 237: return RC_OK;
1.1.1.2 root 238: } else if(matchstr(&line, "FRAMENUM")) {
1.1.1.4 ! root 239: sprintf(RESULT,"%u",frame_num);
! 240: return RC_OK;
1.1 root 241: } else if(matchstr(&line, "SOUND")) {
1.1.1.4 ! root 242: sprintf(RESULT,"%d",sound_available?currprefs.produce_sound:-1);
! 243: return RC_OK;
! 244: }
1.1 root 245: else return RC_ERROR;
246:
247: if(res) {
1.1.1.4 ! root 248: strncpy(RESULT, res, RESULT_LEN);
! 249: if(alc) free(res);
1.1 root 250: }
251: return RC_OK;
252: }
253:
254: /****************************************************************************/
255:
256: static int FEEDBACK(char *line)
257: {
258: gui_rexx_s *gui = NULL;
259:
260: if (matchstr(&line,"LED_POW")) gui = &gui_rexx[LED_POW];
261: else if(matchstr(&line,"LED_DF0")) gui = &gui_rexx[LED_DF0];
262: else if(matchstr(&line,"LED_DF1")) gui = &gui_rexx[LED_DF1];
263: else if(matchstr(&line,"LED_DF2")) gui = &gui_rexx[LED_DF2];
264: else if(matchstr(&line,"LED_DF3")) gui = &gui_rexx[LED_DF3];
265: else if(matchstr(&line,"NAME_DF0")) gui = &gui_rexx[NAME_DF0];
266: else if(matchstr(&line,"NAME_DF1")) gui = &gui_rexx[NAME_DF1];
267: else if(matchstr(&line,"NAME_DF2")) gui = &gui_rexx[NAME_DF2];
268: else if(matchstr(&line,"NAME_DF3")) gui = &gui_rexx[NAME_DF3];
269: else if(matchstr(&line,"ON_EXIT")) gui = &gui_rexx[ON_EXIT];
270: else return RC_ERROR;
271:
272: while(1) {
1.1.1.4 ! root 273: if(matchstr(&line, "ADDRESS") ||
! 274: matchstr(&line, "PORT")) {
! 275: extractstr(&line, gui->port, PORT_LEN);
! 276: } else if(matchstr(&line,"COMMAND") ||
! 277: matchstr(&line,"CMD") ||
! 278: matchstr(&line,"CMD_ON")) {
! 279: extractstr(&line, gui->cmd_on, CMD_LEN);
! 280: } else if(matchstr(&line,"CMD_OFF")) {
! 281: extractstr(&line, gui->cmd_off, CMD_LEN);
! 282: } else break;
1.1 root 283: }
284: return RC_OK;
285: }
286:
287: /****************************************************************************/
288:
289: static int VERSION(char *line)
290: {
291: if(matchstr(&line,"STRING")) {
1.1.1.4 ! root 292: sprintf(RESULT,
! 293: "UAE-%d.%d.%d (%s%s%s) � by Bernd Schmidt & contributors, "
1.1.1.2 root 294: #ifdef POWERUP
1.1.1.4 ! root 295: "Amiga Port by Samuel Devulder & Holger Jakob (PPC extensions).",
1.1.1.2 root 296: #else
1.1.1.4 ! root 297: "Amiga Port by Samuel Devulder.",
1.1.1.2 root 298: #endif
299: UAEMAJOR, UAEMINOR, UAESUBREV,
300: currprefs.cpu_level==0?"68000":
301: currprefs.cpu_level==1?"68010":
302: currprefs.cpu_level==2?"68020":"68020/68881",
303: currprefs.address_space_24?" 24bits":"",
304: currprefs.cpu_compatible?" compat":"");
1.1 root 305: } else if(matchstr(&line,"NUM")) {
1.1.1.4 ! root 306: sprintf(RESULT,"%d",UAEMAJOR*10000+UAEMINOR*100+UAESUBREV);
1.1 root 307: } else if(matchstr(&line,"AUTHOR")) {
1.1.1.4 ! root 308: sprintf(RESULT,"� by Bernd Schmidt & contributors");
1.1 root 309: } else if(matchstr(&line,"PORT")) {
1.1.1.2 root 310: #ifdef POWERUP
311: sprintf(RESULT,"Amiga Port by Samuel Devulder & Holger Jakob (PPC extensions)");
312: #else
1.1.1.4 ! root 313: sprintf(RESULT,"Amiga Port by Samuel Devulder");
1.1.1.2 root 314: #endif
1.1 root 315: } else return RC_ERROR;
316: return RC_OK;
317: }
318:
319: /****************************************************************************/
320:
321: static int FRAMERATE(char *line)
322: {
323: int num;
324: num = matchnum(&line);
325: if(num>=1 && num<=20) {
1.1.1.4 ! root 326: changed_prefs.framerate = num;
1.1 root 327: } else {
1.1.1.4 ! root 328: sprintf(RESULT,"Invalid frame rate: %d\n", num);
! 329: return RC_WARN;
1.1 root 330: }
331: return RC_OK;
332: }
333:
334: /****************************************************************************/
335:
336: static int FAKEJOYSTICK(char *line)
337: {
1.1.1.2 root 338: if (matchstr(&line,"ON")) changed_prefs.fake_joystick = 2;
339: else if(matchstr(&line,"OFF")) changed_prefs.fake_joystick = 0;
340: else if(matchstr(&line,"TOGGLE")) changed_prefs.fake_joystick =
1.1.1.4 ! root 341: currprefs.fake_joystick?0:2;
1.1 root 342: else return RC_ERROR;
343: return RC_OK;
344: }
345:
346: /****************************************************************************/
347:
348: static int DISPLAY(char *line)
349: {
1.1.1.2 root 350: if (matchstr(&line,"ON")) do_inhibit_frame(0);
351: else if(matchstr(&line,"OFF")) do_inhibit_frame(1);
352: else if(matchstr(&line,"TOGGLE")) do_inhibit_frame(inhibit_frame?0:1);
1.1 root 353: else return RC_ERROR;
354: return RC_OK;
355: }
356:
357: /****************************************************************************/
358:
359: static int SOUND(char *line)
360: {
361: if(!sound_available) {
1.1.1.4 ! root 362: sprintf(RESULT,"Sound not available!");
! 363: return RC_WARN;
1.1 root 364: }
365:
366: if (matchstr(&line,"ON")) currprefs.produce_sound = 2;
367: else if(matchstr(&line,"OFF")) currprefs.produce_sound = 1;
368: else if(matchstr(&line,"BEST")) currprefs.produce_sound = 3;
369: else if(matchstr(&line,"TOGGLE")) currprefs.produce_sound =
1.1.1.4 ! root 370: currprefs.produce_sound<=1?2:1;
1.1 root 371: else return RC_ERROR;
1.1.1.2 root 372:
373: /* sam: the next 2 lines is a hack and I don't like it */
1.1.1.4 ! root 374: /* eventtab[ev_sample].active = (changed_prefs.produce_sound>=2)?1:0;
1.1.1.2 root 375: events_schedule ();
376: */
1.1 root 377: return RC_OK;
378: }
379:
380: /****************************************************************************/
381:
382: static int UAEEXE(char *line)
383: {
384: if(uaeexe(line)) {
1.1.1.4 ! root 385: sprintf(RESULT,"Remote CLI failed!");
! 386: return RC_WARN;
1.1 root 387: }
388: return RC_OK;
389: }
390:
391: /****************************************************************************/
392:
393: static int process_cmd(char *line)
394: {
395: RESULT[0] = '\0';
396: if (matchstr(&line, "EJECT")) return EJECT(line);
397: else if(matchstr(&line, "INSERT")) return INSERT(line);
398: else if(matchstr(&line, "QUERY")) return QUERY(line);
399: else if(matchstr(&line, "FEEDBACK")) return FEEDBACK(line);
400: else if(matchstr(&line, "VERSION")) return VERSION(line);
401: else if(matchstr(&line, "BYE")) QUIT();
402: else if(matchstr(&line, "QUIT")) QUIT();
403: else if(matchstr(&line, "DEBUG")) activate_debugger();
404: else if(matchstr(&line, "RESET")) m68k_reset();
405: else if(matchstr(&line, "DISPLAY")) return DISPLAY(line);
406: else if(matchstr(&line, "FRAMERATE")) return FRAMERATE(line);
407: else if(matchstr(&line, "FAKEJOYSTICK")) return FAKEJOYSTICK(line);
408: else if(matchstr(&line, "SOUND")) return SOUND(line);
409: else if(matchstr(&line, "UAEEXE")) return UAEEXE(line);
410: else return RC_ERROR;
411: return RC_OK;
412: }
413:
414: /****************************************************************************/
415:
416: void rexx_handle_events(void)
417: {
418: struct RexxMsg *msg;
419: while((msg = (struct RexxMsg*)GetMsg(ARexxPort))) {
1.1.1.4 ! root 420: if(!(msg->rm_Action & RXCOMM)) {
! 421: fprintf(stderr,"Unknown action '%08X' recieved!\n",
! 422: msg->rm_Action);
! 423: continue;
! 424: }
! 425: msg->rm_Result1 = process_cmd(msg->rm_Args[0]);
! 426: msg->rm_Result2 = NULL;
! 427: if(msg->rm_Action & RXFF_RESULT) {
! 428: int len=strlen(RESULT); /* holger: trick for powerup */
! 429: msg->rm_Result2 = (LONG)CreateArgstring(RESULT,len);
! 430: }
! 431: ReplyMsg((void*)msg);
1.1 root 432: }
433: }
434:
435: /****************************************************************************/
436:
437: void rexx_led(int led, int on)
438: {
439: gui_rexx_s *gui = NULL;
440:
441: if(led < 0 || led > 4) return;
442: led_state[led] = on;
443:
444: if(led == 0) gui = &gui_rexx[LED_POW];
445: if(led == 1) gui = &gui_rexx[LED_DF0];
446: if(led == 2) gui = &gui_rexx[LED_DF1];
447: if(led == 3) gui = &gui_rexx[LED_DF2];
448: if(led == 4) gui = &gui_rexx[LED_DF3];
449:
450: if(gui->port[0] && gui->cmd_on[0] && gui->cmd_off[0]) {
1.1.1.4 ! root 451: if(ADDRESS(gui->port, on ? gui->cmd_on : gui->cmd_off) != RC_OK) {
! 452: fprintf(stderr,"%s:%s:%s\n", gui->port,
! 453: on ? gui->cmd_on : gui->cmd_off,
! 454: RESULT);
! 455: }
1.1 root 456: }
457: }
458:
459: /****************************************************************************/
460:
461: void rexx_filename(int num, char *filename)
462: {
463: gui_rexx_s *gui = NULL;
464: if(num < 0 || num > 3) return;
465: gui = &gui_rexx[NAME_DF0 + num];
466: if(gui->port[0] && gui->cmd_on[0]) {
1.1.1.4 ! root 467: char buf[CMD_LEN];
! 468: if(!(filename = from_unix_path(filename))) return;
! 469: sprintf(buf, gui->cmd_on, filename);
! 470: free(filename);
! 471: if(ADDRESS(gui->port, buf) != RC_OK) {
! 472: fprintf(stderr,"%s:%s:%s\n", gui->port, buf, RESULT);
! 473: }
1.1 root 474: }
475: }
476:
477: /****************************************************************************/
478: /* send a message to an AREXX port.
479: */
480: static int ADDRESS(char *hostname, char *cmd)
481: {
482: struct MsgPort *RexxPort,
1.1.1.4 ! root 483: *ReplyPort;
1.1 root 484: struct RexxMsg *HostMsg,
1.1.1.4 ! root 485: *answer;
1.1 root 486: int result = RC_WARN;
487:
488: if(!stricmp(hostname, "COMMAND")) {
1.1.1.4 ! root 489: return SystemTagList(cmd,NULL);
1.1 root 490: }
491:
492: if((RexxPort = (void *)FindPort(hostname))) {
1.1.1.4 ! root 493: if((ReplyPort = (void *)CreateMsgPort())) {
! 494: if((HostMsg = CreateRexxMsg(ReplyPort, NULL, hostname))) {
! 495: int len=strlen(cmd); /* holger: trick for powerup */
! 496: if((HostMsg->rm_Args[0] = CreateArgstring(cmd,len))) {
! 497: HostMsg->rm_Action = RXCOMM | RXFF_RESULT;
! 498: PutMsg(RexxPort, (void*)HostMsg);
! 499: WaitPort(ReplyPort);
! 500: while(!(answer = (void *)GetMsg(ReplyPort)));
! 501: result = answer->rm_Result1;
! 502: if(result == RC_OK) {
! 503: if(answer->rm_Result2) {
! 504: strncpy(RESULT,(char *)answer->rm_Result2,RESULT_LEN);
! 505: DeleteArgstring((char *)answer->rm_Result2);
! 506: } else RESULT[0] = '\0';
! 507: }
! 508: DeleteArgstring(HostMsg->rm_Args[0]);
! 509: } else strcpy(RESULT, "Can't create argstring!");
! 510: DeleteRexxMsg(HostMsg);
! 511: } else strcpy(RESULT, "Can't create rexx message!");
! 512: DeleteMsgPort(ReplyPort);
! 513: } else strcpy(RESULT, "Can't alloc reply port!");
1.1 root 514: } else sprintf(RESULT, "Port \"%s\" not found!",hostname);
515: return result;
516: }
517:
518: /****************************************************************************/
519: /* argument parsing routines
520: */
521: static int matchstr(char **line,char *pat)
522: {
523: char *s = *line;
524: char match = 0;
525: while(isspace(*s)) ++s;
526: if(*s=='\"' || *s== '\'') match = *s++;
527: while(*s && (tolower(*s)==tolower(*pat)) && (!match || *s!=match)) {++s;++pat;}
528: if(match && *s==match && s[1]) ++s;
529: if(!*pat && (!*s || isspace(*s))) {
1.1.1.4 ! root 530: while(isspace(*s)) ++s;
! 531: *line = s;
! 532: return 1;
1.1 root 533: }
534: return 0;
535: }
536:
537: /****************************************************************************/
538:
539: static void extractstr(char **line, char *result, int len)
540: {
541: char *s = *line;
542: char match = 0;
543:
544: while(isspace(*s)) ++s;
545:
546: if(*s=='\"' || *s=='\'') match = *s++;
547: while(*s && *s != match) {
1.1.1.4 ! root 548: if(*s == '\\' && (s[1] == '\'' || s[1] == '\"')) ++s;
! 549: if(len > 1) {*result++ = *s;--len;}
! 550: ++s;
! 551: if(!match && isspace(*s)) break;
1.1 root 552: }
553: if(match && *s == match) ++s;
554: while(isspace(*s)) ++s;
555:
556: *result = '\0';
557: *line = s;
558: }
559:
560: /****************************************************************************/
561:
562: static int matchnum(char **line)
563: {
564: char *s = *line, match = 0;
565: int sign = 1, num = 0;
566:
567: while(isspace(*s)) ++s;
568: if(*s=='\"' || *s=='\'') match = *s++;
569: if(*s=='-') {sign = -1;++s;}
570: if(*s=='+') ++s;
571: while(isspace(*s)) ++s;
572: while(*s>='0' && *s<='9') num = num*10 + (*s++ - '0');
573: if(match && *s==match && s[1]) ++s;
574: while(isspace(*s)) ++s;
575: *line = s;
576: return sign>0?num:-num;
577: }
1.1.1.2 root 578:
579: /****************************************************************************/
580:
581: #ifdef POWERUP
1.1.1.4 ! root 582: /* sam: those function should be in the ppc version of the unexisting
! 583: libamiga.a */
1.1.1.2 root 584: #define NEWLIST(l) ((l)->lh_Head = (struct Node *)&(l)->lh_Tail, \
1.1.1.4 ! root 585: /*(l)->lh_Tail = NULL,*/ \
! 586: (l)->lh_TailPred = (struct Node *)&(l)->lh_Head)
1.1.1.2 root 587: struct MsgPort *CreatePort(STRPTR name,LONG pri)
588: { struct MsgPort *port = NULL;
589: UBYTE portsig;
590:
591: if ((BYTE)(portsig=AllocSignal(-1)) >= 0)
592: { if (!(port=PPCAllocMem(sizeof(struct MsgPort),MEMF_CLEAR|MEMF_PUBLIC)))
593: FreeSignal(portsig);
594: else
595: {
596: port->mp_Node.ln_Type=NT_MSGPORT;
597: port->mp_Node.ln_Pri=pri;
598: port->mp_Node.ln_Name=name;
599: /* done via AllocMem
600: port->mp_Flags=PA_SIGNAL;
601: */
602: port->mp_SigBit=portsig;
603: port->mp_SigTask=FindTask(NULL);
604: NEWLIST(&port->mp_MsgList);
605: if (port->mp_Node.ln_Name)
1.1.1.4 ! root 606: AddPort(port);
1.1.1.2 root 607: }
608: }
609: return port;
610: }
611:
612: void DeletePort(struct MsgPort *port)
613: { int i;
614:
615: if (port->mp_Node.ln_Name != NULL)
616: RemPort(port);
617: i=-1;
618: port->mp_Node.ln_Type=i;
619: port->mp_MsgList.lh_Head=(struct Node *)i;
620: FreeSignal(port->mp_SigBit);
621: PPCFreeMem(port,sizeof(struct MsgPort));
622: }
623:
624: struct IORequest *CreateExtIO(struct MsgPort *port,long iosize)
625: {
626: struct IORequest *ioreq=NULL;
627:
628: if (port && (ioreq=PPCAllocMem(iosize,MEMF_CLEAR|MEMF_PUBLIC)))
629: {
630: ioreq->io_Message.mn_Node.ln_Type=NT_REPLYMSG;
631: ioreq->io_Message.mn_ReplyPort=port;
632: ioreq->io_Message.mn_Length=iosize;
633: }
634: return ioreq;
635: }
636:
637: struct IOStdReq *CreateStdIO(struct MsgPort *port)
638: {
639: return (struct IOStdReq *)CreateExtIO(port,sizeof(struct IOStdReq));
640: }
641:
642: void DeleteExtIO(struct IORequest *ioreq)
643: {
644: int i;
645:
646: i=-1;
647: ioreq->io_Message.mn_Node.ln_Type=i;
648: ioreq->io_Device=(struct Device *)i;
649: ioreq->io_Unit=(struct Unit *)i;
650: PPCFreeMem(ioreq,ioreq->io_Message.mn_Length);
651: }
652:
653: void DeleteStdIO(struct IORequest *ioreq) {DeleteExtIO(ioreq);}
654: #endif
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.