LONG ti_Init(Global_T *g) { #ifdef DISABLED return 1; #else LONG RetVal = 0; SyncTimer *st = &g->g_SyncTimer; st->st_Pkt = AllocVec(sizeof (DOSPKT), MEMF_CLEAR | MEMF_PUBLIC); st->st_Req = CreateIORequest(g->g_Port, sizeof(struct TimeRequest)); if(st->st_Pkt && st->st_Req) { /* make StandardPacket linkage */ st->st_Pkt->dp_Link = &st->st_Req->Request.io_Message; st->st_Req->Request.io_Message.mn_Node.ln_Name = (UBYTE *) st->st_Pkt; if(OpenDevice(TIMERNAME, UNIT_VBLANK, &st->st_Req->Request, 0) == 0) { st->st_Flags = STF_DEVICE_OPEN; RetVal = 1; } } if(RetVal == 0) ti_Cleanup(g); else ti_StartTimer(st); return RetVal; #endif }
int lib_exec_f_CreateIORequest_2(emumsg_syscall_t *msg) { /* Make real syscall */ msg->arg[0]._aptr = CreateIORequest((struct MsgPort *)msg->arg[0]._aptr, msg->arg[1]._ulong); return HOOK_DONE; }
void OpenAHI( void ) { if( AHIDevice != 0 ) { AHImp = CreateMsgPort(); if( AHImp != NULL ) { AHIio = (struct AHIRequest *) CreateIORequest( AHImp, sizeof( struct AHIRequest ) ); if( AHIio != NULL ) { AHIio->ahir_Version = AHIVERSION; AHIDevice = OpenDevice( AHINAME, AHI_NO_UNIT, (struct IORequest *) AHIio, AHIDF_NOMODESCAN ); } } if( AHIDevice != 0 ) { Printf( "Unable to open %s version %ld\n", (ULONG) AHINAME, AHIVERSION ); cleanup( RETURN_FAIL ); } AHIBase = (struct Library *) AHIio->ahir_Std.io_Device; } }
static int Audio_Available(void) { int ok=0; struct MsgPort *p; struct AHIRequest *req; if(p=CreateMsgPort()) { if(req=(struct AHIRequest *)CreateIORequest(p,sizeof(struct AHIRequest))) { req->ahir_Version=4; if(!OpenDevice(AHINAME,0,(struct IORequest *)req,NULL)) { D(bug("AHI available.\n")); ok=1; CloseDevice((struct IORequest *)req); } DeleteIORequest((struct IORequest *)req); } DeleteMsgPort(p); } D(if(!ok) bug("AHI not available\n")); return ok; }
static void entry(void) { struct MsgPort *port1,*port2; struct Message *msg; Forbid(); port1=FindPort("message test port"); Permit(); port2=CreateMsgPort(); if(port2!=NULL) { msg=(struct Message *)CreateIORequest(port2,sizeof(struct Message)); if(msg!=NULL) { int i; for(i=0;i<10;i++) { msg->mn_Node.ln_Name=(char *)i; PutMsg(port1,msg); WaitPort(port2); GetMsg(port2); } DeleteIORequest((struct IORequest *)msg); } DeleteMsgPort(port2); } Signal(port1->mp_SigTask,1<<port1->mp_SigBit); Wait(0);/* Let the parent remove me */ }
int main(int argc, char* argv[]) { int rc = RETURN_OK; if (argc != 2) { fprintf(stderr, "Usage: %s <audio mode id>\n", argv[0]); rc = RETURN_ERROR; } else { struct MsgPort* mp = CreateMsgPort(); if (mp != NULL) { struct AHIRequest* io = (struct AHIRequest *) CreateIORequest(mp, sizeof(struct AHIRequest)); if (io != NULL) { io->ahir_Version = 4; if (OpenDevice(AHINAME, AHI_NO_UNIT, (struct IORequest *) io, 0) == 0) { AHIBase = (struct Library *) io->ahir_Std.io_Device; BetterAudioID = atol(argv[1]); Forbid(); OldBestAudioIDA = (BestAudioIDA_proto*) SetFunction(AHIBase, _LVOAHI_BestAudioIDA, (ULONG (*)(void)) MyBestAudioIDA ); Wait(SIGBREAKF_CTRL_C); SetFunction(AHIBase, _LVOAHI_BestAudioIDA, (ULONG (*)(void)) OldBestAudioIDA ); rc = 0; Permit(); CloseDevice((struct IORequest *) io); } else { fprintf(stderr, "Unable to open '" AHINAME "' version 4.\n"); rc = RETURN_FAIL; } DeleteIORequest((struct IORequest *) io); } else { fprintf(stderr, "Unable to create IO request.\n"); rc = RETURN_FAIL; } DeleteMsgPort(mp); } else { fprintf(stderr, "Unable to create message port.\n"); rc = RETURN_FAIL; } } return rc; }
BOOL Initialize(void) { LocaleBase = OpenLibrary("locale.library", 38); OpenahiprefsCatalog(); AHImp=CreateMsgPort(); if( AHImp != NULL ) { AHIio = (struct AHIRequest *)CreateIORequest( AHImp,sizeof(struct AHIRequest)); if( AHIio != NULL ) { AHIio->ahir_Version = 4; AHIDevice = OpenDevice(AHINAME,AHI_NO_UNIT,(struct IORequest *)AHIio,NULL); if(AHIDevice == 0) { AHIBase = (struct Library *)AHIio->ahir_Std.io_Device; return TRUE; } } } Printf((char *) msgTextNoOpen, (ULONG) "ahi.device", 4); Printf("\n"); return FALSE; }
void SendEvent(LONG event) { struct IOStdReq *InputRequest; struct MsgPort *InputPort; struct InputEvent *ie; if ((InputPort = (struct MsgPort*)CreateMsgPort())) { if ((InputRequest = (struct IOStdReq*)CreateIORequest(InputPort, sizeof(struct IOStdReq)))) { if (!OpenDevice("input.device", 0, (struct IORequest*)InputRequest, 0)) { if ((ie = AllocVec(sizeof(struct InputEvent), MEMF_PUBLIC | MEMF_CLEAR))) { ie->ie_Class = event; InputRequest->io_Command = IND_WRITEEVENT; InputRequest->io_Data = ie; InputRequest->io_Length = sizeof(struct InputEvent); DoIO((struct IORequest*)InputRequest); FreeVec(ie); } CloseDevice((struct IORequest*)InputRequest); } DeleteIORequest((struct IORequest *)InputRequest); } DeleteMsgPort (InputPort); } }
int main() { APTR ProcessorBase; IPTR args[6] = { 0, 0, 0, 0, 0, 0 }; struct RDArgs *rda; int max_cpus = 0; int max_iter = 0; int req_width = 0, req_height = 0; char tmpbuf[200]; int explicit_mode = 0; struct MsgPort *timerPort = CreateMsgPort(); struct timerequest *tr = CreateIORequest(timerPort, sizeof(struct timerequest)); struct TimerBase *TimerBase = NULL; struct timeval start_time; struct timeval now; struct Window *displayWin; struct BitMap *outputBMap = NULL; IPTR coreCount = 1; struct TagItem tags[] = { {GCIT_NumberOfProcessors, (IPTR)&coreCount}, {0, (IPTR)NULL}}; ProcessorBase = OpenResource(PROCESSORNAME); if (!ProcessorBase) return 0; KernelBase = OpenResource("kernel.resource"); if (!KernelBase) return 0; if (timerPort) { FreeSignal(timerPort->mp_SigBit); timerPort->mp_SigBit = -1; timerPort->mp_Flags = PA_IGNORE; } if (tr) { if (!OpenDevice("timer.device", UNIT_VBLANK, (struct IORequest *)tr, 0)) { TimerBase = (struct TimerBase *)tr->tr_node.io_Device; } } else return 0; GetCPUInfo(tags); D(bug("[SMP-Smallpt] %s: detected %d CPU cores\n", __func__, coreCount);)
void ami_print(struct hlcache_handle *c, int copies) { double height; float scale = nsoption_int(print_scale) / 100.0; if(ami_print_info.msgport == NULL) ami_print_init(); #ifdef __amigaos4__ if(!(ami_print_info.PReq = (struct IODRPTagsReq *)AllocSysObjectTags(ASOT_IOREQUEST, ASOIOR_Size, sizeof(struct IODRPTagsReq), ASOIOR_ReplyPort, ami_print_info.msgport, ASO_NoTrack, FALSE, TAG_DONE))) return; #else if(!(ami_print_info.PReq = (struct IODRPTagsReq *)CreateIORequest(ami_print_info.msgport, sizeof(struct IODRPTagsReq)))) return; #endif if(OpenDevice("printer.device", nsoption_int(printer_unit), (struct IORequest *)ami_print_info.PReq, 0)) { amiga_warn_user("CompError","printer.device"); return; } ami_print_info.PD = (struct PrinterData *)ami_print_info.PReq->io_Device; ami_print_info.PED = &ami_print_info.PD->pd_SegmentData->ps_PED; ami_print_info.ps = print_make_settings(PRINT_DEFAULT, nsurl_access(hlcache_handle_get_url(c)), ami_layout_table); ami_print_info.ps->page_width = ami_print_info.PED->ped_MaxXDots; ami_print_info.ps->page_height = ami_print_info.PED->ped_MaxYDots; ami_print_info.ps->scale = scale; if(!print_set_up(c, &amiprinter, ami_print_info.ps, &height)) { amiga_warn_user("PrintError","print_set_up() returned false"); ami_print_close_device(); return; } height *= ami_print_info.ps->scale; ami_print_info.pages = height / ami_print_info.ps->page_height; ami_print_info.c = c; ami_print_progress(); while(ami_print_cont()); /* remove while() for async printing */ }
int main( int argc, char* argv[] ) { int rc = RETURN_OK; if( argc != 1 ) { fprintf( stderr, "Usage: %s\n", argv[ 0 ] ); rc = RETURN_ERROR; } else { struct MsgPort* mp = CreateMsgPort(); if( mp != NULL ) { struct AHIRequest* io = (struct AHIRequest *) CreateIORequest( mp, sizeof( struct AHIRequest ) ); if( io != NULL ) { // We use 32 bit samples, so we need version 6. io->ahir_Version = 6; if( OpenDevice( AHINAME, AHI_NO_UNIT, (struct IORequest *) io, 0 ) == 0 ) { AHIBase = (struct Library *) io->ahir_Std.io_Device; rc = PlaySineEverywhere(); CloseDevice( (struct IORequest *) io ); } else { fprintf( stderr, "Unable to open '" AHINAME "' version 6.\n" ); rc = RETURN_FAIL; } DeleteIORequest( (struct IORequest *) io ); } else { fprintf( stderr, "Unable to create IO request.\n" ); rc = RETURN_FAIL; } DeleteMsgPort( mp ); } else { fprintf( stderr, "Unable to create message port.\n" ); rc = RETURN_FAIL; } } return rc; }
void main(void) { struct AHIAudioModeRequester *req; BOOL res; if(AHImp=CreateMsgPort()) if(AHIio=(struct AHIRequest *)CreateIORequest(AHImp,sizeof(struct AHIRequest))) { AHIio->ahir_Version = 2; AHIDevice=OpenDevice(AHINAME,AHI_NO_UNIT,(struct IORequest *)AHIio,NULL); } if(AHIDevice) { Printf("Unable to open %s version 2\n",AHINAME); cleanup(RETURN_FAIL); } AHIBase=(struct Library *)AHIio->ahir_Std.io_Device; req=AHI_AllocAudioRequest( AHIR_SleepWindow,TRUE, AHIR_UserData,999, AHIR_PubScreenName,NULL, TAG_DONE); res=AHI_AudioRequest(req, AHIR_TitleText, "Select a mode or cancel", AHIR_NegativeText, "Abort", AHIR_DoMixFreq, TRUE, AHIR_DoDefaultMode, TRUE, AHIR_InitialAudioID, 0x20003, AHIR_InitialMixFreq, 30000, AHIR_FilterTags, ReqFilterTags, TAG_DONE); if(!res) { if(IoErr() == ERROR_NO_FREE_STORE) Printf("AHI ran out of memory!\n"); else if(IoErr() == ERROR_NO_MORE_ENTRIES) Printf("No available modes!\n"); else Printf("Requester cancelled!\n"); } else Printf("Selected AudioMode: 0x%08lx, %ld Hz\n",req->ahiam_AudioID,req->ahiam_MixFreq); AHI_FreeAudioRequest(req); cleanup(RETURN_OK); }
static void openpar(void) { ParMP = CreateMsgPort(); if (!ParMP) cleanup("Failed to create msgport", RETURN_ERROR); ParIO = (struct IOStdReq *)CreateIORequest(ParMP, sizeof(struct IOExtPar)); if (!ParIO) cleanup("Failed to create IO request", RETURN_ERROR); if (OpenDevice("parallel.device", 0, (struct IORequest *)ParIO, 0)) { cleanup("Failed to open parallel.device", RETURN_ERROR); } ParOpen = TRUE; }
int main(int argc, char* argv[]) { int rc = RETURN_OK; if (argc != 4) { fprintf(stderr, "Usage: %s <audio mode id> <mix_freq> <player_freq>\n", argv[0]); rc = RETURN_ERROR; } else { struct MsgPort* mp = CreateMsgPort(); if (mp != NULL) { struct AHIRequest* io = (struct AHIRequest *) CreateIORequest(mp, sizeof(struct AHIRequest)); if (io != NULL) { io->ahir_Version = 4; if (OpenDevice(AHINAME, AHI_NO_UNIT, (struct IORequest *) io, 0) == 0) { AHIBase = (struct Library *) io->ahir_Std.io_Device; rc = MaxPlaySamples(atol(argv[1]), atol(argv[2]), atol(argv[3])); CloseDevice((struct IORequest *) io); } else { fprintf(stderr, "Unable to open '" AHINAME "' version 4.\n"); rc = RETURN_FAIL; } DeleteIORequest((struct IORequest *) io); } else { fprintf(stderr, "Unable to create IO request.\n"); rc = RETURN_FAIL; } DeleteMsgPort(mp); } else { fprintf(stderr, "Unable to create message port.\n"); rc = RETURN_FAIL; } } return rc; }
cdrom_interface::cdrom_interface(char *dev) { char buf[256]; sscanf(dev, "%s%s", amiga_cd_device, buf); amiga_cd_unit = atoi(buf); CDMP = CreateMsgPort(); if (CDMP != NULL) { CDIO = (struct IOExtTD *)CreateIORequest(CDMP, sizeof(struct IOExtTD)); if (CDIO != NULL) { cd_error = OpenDevice(amiga_cd_device, amiga_cd_unit, (struct IORequest *)CDIO, 0); if (cd_error != 0) BX_PANIC(("CD_Open: could not open device %s unit %d\n", amiga_cd_device, amiga_cd_unit)); } } }
struct IORequest *ata_OpenTimer() { struct MsgPort *p = CreateMsgPort(); if (NULL != p) { struct IORequest *io = CreateIORequest(p, sizeof(struct timerequest)); if (NULL != io) { /* * ok. ECLOCK does not have too great resolution, either. * we will have to sacrifice our performance a little bit, meaning, the 400ns will turn into (worst case) 2us. * hopefully we won't have to call that TOO often... */ if (0 == OpenDevice("timer.device", UNIT_MICROHZ, io, 0)) { if (0 == TimerBase) { TimerBase = io->io_Device; ata_Calibrate(io); } return io; } else { bug("[ATA ] Failed to open timer.device, unit MICROHZ\n"); } DeleteIORequest(io); } else { bug("[ATA ] Failed to create timerequest\n"); } DeleteMsgPort(p); } else { bug("[ATA ] Failed to create timer port\n"); } return NULL; }
struct SysNetData *Sys_Net_Init() { struct SysNetData *netdata; netdata = AllocVec(sizeof(*netdata), MEMF_ANY); if (netdata) { SocketBase = OpenLibrary("bsdsocket.library", 0); if (SocketBase) { netdata->timerport = CreateMsgPort(); if (netdata->timerport) { netdata->timerrequest = (struct timerequest *)CreateIORequest(netdata->timerport, sizeof(*netdata->timerrequest)); if (netdata->timerrequest) { if (OpenDevice(TIMERNAME, UNIT_MICROHZ, (struct IORequest *)netdata->timerrequest, 0) == 0) { netdata->timerrequest->tr_node.io_Command = TR_ADDREQUEST; netdata->timerrequest->tr_time.tv_secs = 1; netdata->timerrequest->tr_time.tv_micro = 0; SendIO((struct IORequest *)netdata->timerrequest); AbortIO((struct IORequest *)netdata->timerrequest); return netdata; } DeleteIORequest((struct IORequest *)netdata->timerrequest); } DeleteMsgPort(netdata->timerport); } CloseLibrary(SocketBase); } FreeVec(netdata); } return 0; }
static int load_capslib (void) { if ((CAPS_MsgPort = CreateMsgPort ())) { if ((CAPS_IOReq = CreateIORequest (CAPS_MsgPort, sizeof(struct IORequest)))) { if (!OpenDevice(CAPS_NAME, 0, CAPS_IOReq, 0)) { CapsImageBase = CAPS_IOReq->io_Device; if (CapsImageBase->dd_Library.lib_Version >= 2) { if (CAPSInit () == imgeOk) { atexit (unload_capslib); return 1; } } else write_log ("CAPS: Please install capsimage.device version 2 or newer.\n"); CloseDevice (CAPS_IOReq); } DeleteIORequest (CAPS_IOReq); } DeleteMsgPort (CAPS_MsgPort); } return 0; }
static int add_resethandler(void) { int ok = FALSE; bzero(rhdata, sizeof(*rhdata)); rhdata->SysBase = SysBase; rhdata->Self = FindTask(NULL); rhdata->msgport = CreateMsgPort(); if (rhdata->msgport) { rhdata->ioreq = (struct IOStdReq *) CreateIORequest(rhdata->msgport, sizeof(struct IOStdReq)); if (rhdata->ioreq) { if (OpenDevice("keyboard.device", 0, (struct IORequest *) rhdata->ioreq, 0) == 0) { rhdata->is.is_Node.ln_Type = NT_INTERRUPT; rhdata->is.is_Node.ln_Pri = 64; rhdata->is.is_Node.ln_Name = "distributed.net client"; rhdata->is.is_Data = (APTR) rhdata; rhdata->is.is_Code = (void (*)(void)) resethandler_code; rhdata->ioreq->io_Command = KBD_ADDRESETHANDLER; rhdata->ioreq->io_Data = (APTR) &rhdata->is; DoIO((struct IORequest *) rhdata->ioreq); rhdata->handleradded = TRUE; ok = TRUE; } } } if (!ok) { rem_resethandler(); } return ok; }
static void Sleep(u_long micros) { struct MsgPort *TimerPort; struct timerequest *TimerRequest; if ((TimerPort = CreateMsgPort())) { if ((TimerRequest = CreateIORequest(TimerPort, sizeof(struct timerequest)))) { if (!OpenDevice("timer.device", UNIT_VBLANK, (struct IORequest *)TimerRequest, 0)) { TimerRequest->io_Command = TR_ADDREQUEST; TimerRequest->io_Flags = IOF_QUICK; TimerRequest->tv_secs = micros/1000000; TimerRequest->tv_micro = micros%1000000; DoIO((struct IORequest *)TimerRequest); CloseDevice((struct IORequest *)TimerRequest); } DeleteIORequest(TimerRequest); } DeleteMsgPort(TimerPort); } }
LONG InitTimer(void) { LONG err = ERROR_NO_FREE_STORE; glob->timerport = CreateMsgPort(); if (glob->timerport) { glob->timereq = (struct timerequest *)CreateIORequest(glob->timerport, sizeof(struct timerequest)); if (glob->timereq) { if (OpenDevice("timer.device", UNIT_VBLANK, (struct IORequest *)glob->timereq, 0)) err = ERROR_DEVICE_NOT_MOUNTED; else { glob->timer_active = 0; glob->restart_timer = 1; D(bug("[fat] Timer ready\n")); return 0; } DeleteIORequest((struct IORequest *)glob->timereq); } DeleteMsgPort(glob->timerport); } return err; }
/************************** I/O ******************************************/ struct IOExtTD *openDevice ( struct AFSBase *afsbase, struct MsgPort *mp, STRPTR device, ULONG unit, ULONG flags ) { struct IOExtTD *ioreq; ioreq = (struct IOExtTD *)CreateIORequest(mp, sizeof(struct IOExtTD)); if (ioreq != NULL) { if (OpenDevice(device, unit, (struct IORequest *)ioreq, flags) == 0) { return ioreq; } else showError(afsbase, ERR_DEVICE, device); DeleteIORequest((struct IORequest *)ioreq); } return NULL; }
__saveds void ASERDPort::serial_func(void) { struct ASERDPort *obj = (ASERDPort *)proc_arg; struct MsgPort *proc_port = NULL, *io_port = NULL, *control_port = NULL; struct IOExtSer *read_io = NULL, *write_io = NULL, *control_io = NULL; uint8 orig_params[sizeof(struct IOExtSer)]; bool opened = false; ULONG io_mask = 0, proc_port_mask = 0; // Default: error occured obj->proc_error = true; // Create message port for communication with main task proc_port = CreateMsgPort(); if (proc_port == NULL) goto quit; proc_port_mask = 1 << proc_port->mp_SigBit; // Create message ports for serial.device I/O io_port = CreateMsgPort(); if (io_port == NULL) goto quit; io_mask = 1 << io_port->mp_SigBit; control_port = CreateMsgPort(); if (control_port == NULL) goto quit; // Create IORequests read_io = (struct IOExtSer *)CreateIORequest(io_port, sizeof(struct IOExtSer)); write_io = (struct IOExtSer *)CreateIORequest(io_port, sizeof(struct IOExtSer)); control_io = (struct IOExtSer *)CreateIORequest(control_port, sizeof(struct IOExtSer)); if (read_io == NULL || write_io == NULL || control_io == NULL) goto quit; read_io->IOSer.io_Message.mn_Node.ln_Type = 0; // Avoid CheckIO() bug write_io->IOSer.io_Message.mn_Node.ln_Type = 0; control_io->IOSer.io_Message.mn_Node.ln_Type = 0; // Parse device name char dev_name[256]; ULONG dev_unit; if (sscanf(obj->device_name, "%[^/]/%ld", dev_name, &dev_unit) < 2) goto quit; // Open device if (obj->is_parallel) ((IOExtPar *)read_io)->io_ParFlags = PARF_SHARED; else read_io->io_SerFlags = SERF_SHARED | SERF_7WIRE; if (OpenDevice((UBYTE *) dev_name, dev_unit, (struct IORequest *)read_io, 0) || read_io->IOSer.io_Device == NULL) goto quit; opened = true; // Copy IORequests memcpy(write_io, read_io, sizeof(struct IOExtSer)); memcpy(control_io, read_io, sizeof(struct IOExtSer)); // Attach control_io to control_port and set default values control_io->IOSer.io_Message.mn_ReplyPort = control_port; if (!obj->is_parallel) { control_io->io_CtlChar = SER_DEFAULT_CTLCHAR; control_io->io_RBufLen = 64; control_io->io_ExtFlags = 0; control_io->io_Baud = 9600; control_io->io_BrkTime = 250000; control_io->io_ReadLen = control_io->io_WriteLen = 8; control_io->io_StopBits = 1; control_io->io_SerFlags = SERF_SHARED; control_io->IOSer.io_Command = SDCMD_SETPARAMS; DoIO((struct IORequest *)control_io); memcpy(orig_params, &(control_io->io_CtlChar), (uint8 *)&(control_io->io_Status) - (uint8 *)&(control_io->io_CtlChar)); } // Initialization went well, inform main task obj->proc_port = proc_port; obj->control_io = control_io; obj->proc_error = false; Signal(MainTask, SIGF_SINGLE); // Main loop for (;;) { // Wait for I/O and messages (CTRL_C is used for quitting the task) ULONG sig = Wait(proc_port_mask | io_mask | SIGBREAKF_CTRL_C); // Main task wants to quit us if (sig & SIGBREAKF_CTRL_C) break; // Main task sent a command to us if (sig & proc_port_mask) { struct SerMessage *msg; while (msg = (SerMessage *)GetMsg(proc_port)) { D(bug("serial_proc received %08lx\n", msg->what)); switch (msg->what) { case MSG_QUERY: control_io->IOSer.io_Command = SDCMD_QUERY; DoIO((struct IORequest *)control_io); D(bug(" query returned %08lx, actual %08lx\n", control_io->IOSer.io_Error, control_io->IOSer.io_Actual)); break; case MSG_SET_PARAMS: // Only send SDCMD_SETPARAMS when configuration has changed if (memcmp(orig_params, &(control_io->io_CtlChar), (uint8 *)&(control_io->io_Status) - (uint8 *)&(control_io->io_CtlChar))) { memcpy(orig_params, &(control_io->io_CtlChar), (uint8 *)&(control_io->io_Status) - (uint8 *)&(control_io->io_CtlChar)); memcpy(&(read_io->io_CtlChar), &(control_io->io_CtlChar), (uint8 *)&(control_io->io_Status) - (uint8 *)&(control_io->io_CtlChar)); memcpy(&(write_io->io_CtlChar), &(control_io->io_CtlChar), (uint8 *)&(control_io->io_Status) - (uint8 *)&(control_io->io_CtlChar)); control_io->IOSer.io_Command = SDCMD_SETPARAMS; D(bug(" params %08lx %08lx %08lx %08lx %08lx %08lx\n", control_io->io_CtlChar, control_io->io_RBufLen, control_io->io_ExtFlags, control_io->io_Baud, control_io->io_BrkTime, *(uint32 *)((uint8 *)control_io + 76))); DoIO((struct IORequest *)control_io); D(bug(" set_parms returned %08lx\n", control_io->IOSer.io_Error)); } break; case MSG_SET_PAR_PARAMS: control_io->IOSer.io_Command = PDCMD_SETPARAMS; DoIO((struct IORequest *)control_io); D(bug(" set_par_parms returned %08lx\n", control_io->IOSer.io_Error)); break; case MSG_BREAK: control_io->IOSer.io_Command = SDCMD_BREAK; DoIO((struct IORequest *)control_io); D(bug(" break returned %08lx\n", control_io->IOSer.io_Error)); break; case MSG_RESET: control_io->IOSer.io_Command = CMD_RESET; DoIO((struct IORequest *)control_io); D(bug(" reset returned %08lx\n", control_io->IOSer.io_Error)); break; case MSG_KILL_IO: AbortIO((struct IORequest *)read_io); AbortIO((struct IORequest *)write_io); WaitIO((struct IORequest *)read_io); WaitIO((struct IORequest *)write_io); obj->read_pending = obj->write_pending = false; obj->read_done = obj->write_done = false; break; case MSG_PRIME_IN: read_io->IOSer.io_Message.mn_Node.ln_Name = (char *)msg->pb; read_io->IOSer.io_Data = Mac2HostAddr(ReadMacInt32(msg->pb + ioBuffer)); read_io->IOSer.io_Length = ReadMacInt32(msg->pb + ioReqCount); read_io->IOSer.io_Actual = 0; read_io->IOSer.io_Command = CMD_READ; D(bug("serial_proc receiving %ld bytes from %08lx\n", read_io->IOSer.io_Length, read_io->IOSer.io_Data)); SendIO((struct IORequest *)read_io); break; case MSG_PRIME_OUT: { write_io->IOSer.io_Message.mn_Node.ln_Name = (char *)msg->pb; write_io->IOSer.io_Data = Mac2HostAddr(ReadMacInt32(msg->pb + ioBuffer)); write_io->IOSer.io_Length = ReadMacInt32(msg->pb + ioReqCount); write_io->IOSer.io_Actual = 0; write_io->IOSer.io_Command = CMD_WRITE; D(bug("serial_proc transmitting %ld bytes from %08lx\n", write_io->IOSer.io_Length, write_io->IOSer.io_Data)); #if MONITOR bug("Sending serial data:\n"); uint8 *adr = Mac2HostAddr(ReadMacInt32(msg->pb + ioBuffer)); for (int i=0; i<len; i++) { bug("%02lx ", adr[i]); } bug("\n"); #endif SendIO((struct IORequest *)write_io); break; } } D(bug(" serial_proc replying\n")); ReplyMsg(msg); } } // I/O operation completed if (sig & io_mask) { struct IOExtSer *io; while (io = (struct IOExtSer *)GetMsg(io_port)) { if (io == read_io) { D(bug("read_io complete, %ld bytes received, error %ld\n", read_io->IOSer.io_Actual, read_io->IOSer.io_Error)); uint32 pb = (uint32)read_io->IOSer.io_Message.mn_Node.ln_Name; #if MONITOR bug("Receiving serial data:\n"); uint8 *adr = Mac2HostAddr(ReadMacInt32(msg->pb + ioBuffer)); for (int i=0; i<read_io->IOSer.io_Actual; i++) { bug("%02lx ", adr[i]); } bug("\n"); #endif WriteMacInt32(pb + ioActCount, read_io->IOSer.io_Actual); obj->conv_error(read_io, obj->input_dt); obj->read_done = true; SetInterruptFlag(INTFLAG_SERIAL); TriggerInterrupt(); } else if (io == write_io) { D(bug("write_io complete, %ld bytes sent, error %ld\n", write_io->IOSer.io_Actual, write_io->IOSer.io_Error)); uint32 pb = (uint32)write_io->IOSer.io_Message.mn_Node.ln_Name; WriteMacInt32(pb + ioActCount, write_io->IOSer.io_Actual); obj->conv_error(write_io, obj->output_dt); obj->write_done = true; SetInterruptFlag(INTFLAG_SERIAL); TriggerInterrupt(); } } } } quit: // Close everything if (opened) { if (CheckIO((struct IORequest *)write_io) == 0) { AbortIO((struct IORequest *)write_io); WaitIO((struct IORequest *)write_io); } if (CheckIO((struct IORequest *)read_io) == 0) { AbortIO((struct IORequest *)read_io); WaitIO((struct IORequest *)read_io); } CloseDevice((struct IORequest *)read_io); } if (control_io) DeleteIORequest(control_io); if (write_io) DeleteIORequest(write_io); if (read_io) DeleteIORequest(read_io); if (control_port) DeleteMsgPort(control_port); if (io_port) DeleteMsgPort(io_port); // Send signal to main task to confirm termination Forbid(); Signal(MainTask, SIGF_SINGLE); }
static __saveds void net_func(void) { const char *str; BYTE od_error; struct MsgPort *write_port = NULL, *control_port = NULL; struct IOSana2Req *write_io = NULL, *control_io = NULL; bool opened = false; ULONG read_mask = 0, write_mask = 0, proc_port_mask = 0; struct Sana2DeviceQuery query_data = {sizeof(Sana2DeviceQuery)}; ULONG buffer_tags[] = { S2_CopyToBuff, (uint32)copy_to_buff, S2_CopyFromBuff, (uint32)copy_from_buff, TAG_END }; // Default: error occured proc_error = true; // Create message port for communication with main task proc_port = CreateMsgPort(); if (proc_port == NULL) goto quit; proc_port_mask = 1 << proc_port->mp_SigBit; // Create message ports for device I/O read_port = CreateMsgPort(); if (read_port == NULL) goto quit; read_mask = 1 << read_port->mp_SigBit; write_port = CreateMsgPort(); if (write_port == NULL) goto quit; write_mask = 1 << write_port->mp_SigBit; control_port = CreateMsgPort(); if (control_port == NULL) goto quit; // Create control IORequest control_io = (struct IOSana2Req *)CreateIORequest(control_port, sizeof(struct IOSana2Req)); if (control_io == NULL) goto quit; control_io->ios2_Req.io_Message.mn_Node.ln_Type = 0; // Avoid CheckIO() bug // Parse device name char dev_name[256]; ULONG dev_unit; str = PrefsFindString("ether"); if (str) { const char *FirstSlash = strchr(str, '/'); const char *LastSlash = strrchr(str, '/'); if (FirstSlash && FirstSlash && FirstSlash != LastSlash) { // Device name contains path, i.e. "Networks/xyzzy.device" const char *lp = str; char *dp = dev_name; while (lp != LastSlash) *dp++ = *lp++; *dp = '\0'; if (strlen(dev_name) < 1) goto quit; if (sscanf(LastSlash, "/%ld", &dev_unit) != 1) goto quit; } else { if (sscanf(str, "%[^/]/%ld", dev_name, &dev_unit) != 2) goto quit; } } else goto quit; // Open device control_io->ios2_BufferManagement = buffer_tags; od_error = OpenDevice((UBYTE *) dev_name, dev_unit, (struct IORequest *)control_io, 0); if (od_error != 0 || control_io->ios2_Req.io_Device == 0) { printf("WARNING: OpenDevice(<%s>, unit=%d) returned error %d)\n", (UBYTE *)dev_name, dev_unit, od_error); goto quit; } opened = true; // Is it Ethernet? control_io->ios2_Req.io_Command = S2_DEVICEQUERY; control_io->ios2_StatData = (void *)&query_data; DoIO((struct IORequest *)control_io); if (control_io->ios2_Req.io_Error) goto quit; if (query_data.HardwareType != S2WireType_Ethernet) { WarningAlert(GetString(STR_NOT_ETHERNET_WARN)); goto quit; } // Yes, create IORequest for writing write_io = (struct IOSana2Req *)CreateIORequest(write_port, sizeof(struct IOSana2Req)); if (write_io == NULL) goto quit; memcpy(write_io, control_io, sizeof(struct IOSana2Req)); write_io->ios2_Req.io_Message.mn_Node.ln_Type = 0; // Avoid CheckIO() bug write_io->ios2_Req.io_Message.mn_ReplyPort = write_port; // Configure Ethernet control_io->ios2_Req.io_Command = S2_GETSTATIONADDRESS; DoIO((struct IORequest *)control_io); memcpy(ether_addr, control_io->ios2_DstAddr, 6); memcpy(control_io->ios2_SrcAddr, control_io->ios2_DstAddr, 6); control_io->ios2_Req.io_Command = S2_CONFIGINTERFACE; DoIO((struct IORequest *)control_io); D(bug("Ethernet address %08lx %08lx\n", *(uint32 *)ether_addr, *(uint16 *)(ether_addr + 4))); // Initialization went well, inform main task proc_error = false; Signal(MainTask, SIGF_SINGLE); // Main loop for (;;) { // Wait for I/O and messages (CTRL_C is used for quitting the task) ULONG sig = Wait(proc_port_mask | read_mask | write_mask | SIGBREAKF_CTRL_C); // Main task wants to quit us if (sig & SIGBREAKF_CTRL_C) break; // Main task sent a command to us if (sig & proc_port_mask) { struct NetMessage *msg; while (msg = (NetMessage *)GetMsg(proc_port)) { D(bug("net_proc received %08lx\n", msg->what)); switch (msg->what) { case MSG_CLEANUP: remove_all_protocols(); break; case MSG_ADD_MULTI: control_io->ios2_Req.io_Command = S2_ADDMULTICASTADDRESS; Mac2Host_memcpy(control_io->ios2_SrcAddr, msg->pointer + eMultiAddr, 6); DoIO((struct IORequest *)control_io); if (control_io->ios2_Req.io_Error == S2ERR_NOT_SUPPORTED) { WarningAlert(GetString(STR_NO_MULTICAST_WARN)); msg->result = noErr; } else if (control_io->ios2_Req.io_Error) msg->result = eMultiErr; else msg->result = noErr; break; case MSG_DEL_MULTI: control_io->ios2_Req.io_Command = S2_DELMULTICASTADDRESS; Mac2Host_memcpy(control_io->ios2_SrcAddr, msg->pointer + eMultiAddr, 6); DoIO((struct IORequest *)control_io); if (control_io->ios2_Req.io_Error) msg->result = eMultiErr; else msg->result = noErr; break; case MSG_ATTACH_PH: { uint16 type = msg->type; uint32 handler = msg->pointer; // Protocol of that type already installed? NetProtocol *p = (NetProtocol *)prot_list.lh_Head, *next; while ((next = (NetProtocol *)p->ln_Succ) != NULL) { if (p->type == type) { msg->result = lapProtErr; goto reply; } p = next; } // Allocate NetProtocol, set type and handler p = (NetProtocol *)AllocMem(sizeof(NetProtocol), MEMF_PUBLIC); if (p == NULL) { msg->result = lapProtErr; goto reply; } p->type = type; p->handler = handler; // Set up and submit read requests for (int i=0; i<NUM_READ_REQUESTS; i++) { memcpy(p->read_io + i, control_io, sizeof(struct IOSana2Req)); p->read_io[i].ios2_Req.io_Message.mn_Node.ln_Name = (char *)p; // Hide pointer to NetProtocol in node name p->read_io[i].ios2_Req.io_Message.mn_Node.ln_Type = 0; // Avoid CheckIO() bug p->read_io[i].ios2_Req.io_Message.mn_ReplyPort = read_port; p->read_io[i].ios2_Req.io_Command = CMD_READ; p->read_io[i].ios2_PacketType = type; p->read_io[i].ios2_Data = p->read_buf[i]; p->read_io[i].ios2_Req.io_Flags = SANA2IOF_RAW; BeginIO((struct IORequest *)(p->read_io + i)); } // Add protocol to list AddTail(&prot_list, p); // Everything OK msg->result = noErr; break; } case MSG_DETACH_PH: { uint16 type = msg->type; msg->result = lapProtErr; NetProtocol *p = (NetProtocol *)prot_list.lh_Head, *next; while ((next = (NetProtocol *)p->ln_Succ) != NULL) { if (p->type == type) { remove_protocol(p); msg->result = noErr; break; } p = next; } break; } case MSG_WRITE: { // Get pointer to Write Data Structure uint32 wds = msg->pointer; write_io->ios2_Data = (void *)wds; // Calculate total packet length long len = 0; uint32 tmp = wds; for (;;) { int16 w = ReadMacInt16(tmp); if (w == 0) break; len += w; tmp += 6; } write_io->ios2_DataLength = len; // Get destination address uint32 hdr = ReadMacInt32(wds + 2); Mac2Host_memcpy(write_io->ios2_DstAddr, hdr, 6); // Get packet type uint32 type = ReadMacInt16(hdr + 12); if (type <= 1500) type = 0; // 802.3 packet write_io->ios2_PacketType = type; // Multicast/broadcard packet? if (write_io->ios2_DstAddr[0] & 1) { if (*(uint32 *)(write_io->ios2_DstAddr) == 0xffffffff && *(uint16 *)(write_io->ios2_DstAddr + 4) == 0xffff) write_io->ios2_Req.io_Command = S2_BROADCAST; else write_io->ios2_Req.io_Command = S2_MULTICAST; } else write_io->ios2_Req.io_Command = CMD_WRITE; // Send packet write_done = false; write_io->ios2_Req.io_Flags = SANA2IOF_RAW; BeginIO((IORequest *)write_io); break; } } reply: D(bug(" net_proc replying\n")); ReplyMsg(msg); } } // Packet received if (sig & read_mask) { D(bug(" packet received, triggering Ethernet interrupt\n")); SetInterruptFlag(INTFLAG_ETHER); TriggerInterrupt(); } // Packet write completed if (sig & write_mask) { GetMsg(write_port); WriteMacInt32(ether_data + ed_Result, write_io->ios2_Req.io_Error ? excessCollsns : 0); write_done = true; D(bug(" packet write done, triggering Ethernet interrupt\n")); SetInterruptFlag(INTFLAG_ETHER); TriggerInterrupt(); } } quit: // Close everything remove_all_protocols(); if (opened) { if (CheckIO((struct IORequest *)write_io) == 0) { AbortIO((struct IORequest *)write_io); WaitIO((struct IORequest *)write_io); } CloseDevice((struct IORequest *)control_io); } if (write_io) DeleteIORequest(write_io); if (control_io) DeleteIORequest(control_io); if (control_port) DeleteMsgPort(control_port); if (write_port) DeleteMsgPort(write_port); if (read_port) DeleteMsgPort(read_port); // Send signal to main task to confirm termination Forbid(); Signal(MainTask, SIGF_SINGLE); }
VOID DispatcherThread(struct MOSWriteHandle* h) { struct MsgPort* ahi_port = NULL; struct AHIRequest* ahi_request = NULL; struct AHIAudioCtrl*ahi_control = NULL; BYTE* sample_bufs = NULL; ULONG sample_size = 2; BYTE ahi_device = -1; LONG switch_sig_bit = -1; LONG locked_buf = -1; struct DispatcherStartupMsg *startup_msg; struct DispatcherInitReport *init_report; struct MsgPort *task_port = NULL; struct ExecBase *SysBase = *(struct ExecBase **) 4; init_report = (struct DispatcherInitReport *) AllocVec(sizeof (struct DispatcherInitReport), MEMF_PUBLIC | MEMF_CLEAR); if (init_report == NULL) return; NewGetTaskAttrsA(NULL, &task_port, sizeof (task_port), TASKINFOTYPE_TASKMSGPORT, NULL); NewGetTaskAttrsA(NULL, &startup_msg, sizeof (startup_msg), TASKINFOTYPE_STARTUPMSG, NULL); if (task_port == NULL || startup_msg == NULL) { FreeVec(init_report); return; } startup_msg->dsm_Result = -1; switch_sig_bit = AllocSignal(-1); if (switch_sig_bit != -1 && (ahi_port = CreateMsgPort())) { if ((ahi_request = (struct AHIRequest *) CreateIORequest(ahi_port, sizeof (struct AHIRequest)))) { ahi_request->ahir_Version = 4; if ((ahi_device = OpenDevice(AHINAME, AHI_NO_UNIT, (struct IORequest *) ahi_request, 0)) == 0) { AHIBase = (struct Library*) ahi_request->ahir_Std.io_Device; /*dprintf("AllocAudio with %d channels, %d sounds and frequency %d\n", h->wh_Channels, AHI_BUFFERS, h->wh_Frequency);*/ ahi_control = AHI_AllocAudio(AHIA_AudioID, AHI_DEFAULT_ID, AHIA_Channels, h->wh_Channels, AHIA_Sounds, AHI_BUFFERS, AHIA_MixFreq, h->wh_Frequency, AHIA_SoundFunc, (ULONG) &OpenAL_SoundHook, AHIA_UserData, (ULONG) h, TAG_DONE ); if (ahi_control) { ULONG buf_size; ULONG samples, fs, fm; AHI_GetAudioAttrs(AHI_INVALID_ID, ahi_control, AHIDB_MaxPlaySamples, (ULONG) &samples, TAG_DONE); AHI_ControlAudio(ahi_control, AHIC_MixFreq_Query, (ULONG) &fm, TAG_DONE); fs = h->wh_Frequency; buf_size = samples*fs/fm; /*dprintf("OpenAL: Minimum buffer size is %d, requested buffer size is %d\n", buf_size, h->wh_BufSize);*/ if (buf_size > h->wh_BufSize) h->wh_BufSize = buf_size; sample_bufs = AllocVec(h->wh_BufSize*AHI_BUFFERS, MEMF_PUBLIC | MEMF_CLEAR); if (sample_bufs) { struct Buffer* bn; ULONG buf; LONG err = AHIE_OK; sample_size = AHI_SampleFrameSize(h->wh_SampleType); for (buf = 0; buf < AHI_BUFFERS && err == AHIE_OK; buf++) { bn = &h->wh_Buffers[buf]; bn->bn_SampleNo = buf; bn->bn_SampleInfo.ahisi_Type = h->wh_SampleType; bn->bn_SampleInfo.ahisi_Address = &sample_bufs[buf*h->wh_BufSize]; bn->bn_SampleInfo.ahisi_Length = h->wh_BufSize/sample_size; InitSemaphore(&bn->bn_Semaphore); bn->bn_FillSize = 0; err = AHI_LoadSound(buf, AHIST_DYNAMICSAMPLE, &bn->bn_SampleInfo, ahi_control); } if (err != AHIE_OK) { FreeVec(sample_bufs); sample_bufs = NULL; } } } } } } if (sample_bufs) { BOOL dispatcher_running = TRUE; ULONG signal_mask = 1 << task_port->mp_SigBit; ULONG signal_set; struct MsgPort *reply_port; reply_port = CreateMsgPort(); if (reply_port == NULL) reply_port = task_port; if (startup_msg) startup_msg->dsm_Result = 0; init_report->dir_Msg.mn_Node.ln_Type = NT_MESSAGE; init_report->dir_Msg.mn_ReplyPort = reply_port; init_report->dir_Msg.mn_Length = sizeof (struct DispatcherInitReport); AHI_ControlAudio(ahi_control, AHIC_MixFreq_Query, (ULONG) &init_report->dir_RealFrequency, TAG_DONE); init_report->dir_RealBufSize = h->wh_BufSize; PutMsg(startup_msg->dsm_Msg.mn_ReplyPort, (struct Message*) init_report); WaitPort(reply_port); GetMsg(reply_port); FreeVec(init_report); init_report = NULL; if (reply_port != task_port) DeleteMsgPort(reply_port); h->wh_SwitchSignal = 1UL << switch_sig_bit; h->wh_ReadBuf = 0; while (dispatcher_running) { signal_set = Wait(signal_mask); if (signal_set & (1 << task_port->mp_SigBit)) { struct DispatcherMsg *msg; while ((msg = (struct DispatcherMsg *) GetMsg(task_port))) { if (msg->dm_Msg.mn_Length == sizeof (struct DispatcherMsg)) { switch (msg->dm_Command) { case DISPATCHER_CMD_START: { /* * First buffer has been filled and we were previously not * playing any sound yet */ ULONG chan; ULONG cur_buf; cur_buf = h->wh_ReadBuf; AHI_ControlAudio(ahi_control, AHIC_Play, TRUE, TAG_DONE); /* Lock first audio buffer */ ObtainSemaphore(&h->wh_Buffers[cur_buf].bn_Semaphore); locked_buf = cur_buf; for (chan = 0; chan < h->wh_Channels; chan++) { AHI_SetFreq(chan, h->wh_Frequency, ahi_control, AHISF_IMM); AHI_SetVol(chan, 0x10000L, -0x8000L, ahi_control, AHISF_IMM); AHI_SetSound(chan, cur_buf, 0, 0, ahi_control, AHISF_IMM); } Wait(1 << switch_sig_bit); cur_buf++; if (cur_buf >= AHI_BUFFERS) cur_buf = 0; h->wh_ReadBuf = cur_buf; signal_mask |= 1UL << switch_sig_bit; break; } case DISPATCHER_CMD_PAUSE: case DISPATCHER_CMD_RESUME: AHI_ControlAudio(ahi_control, AHIC_Play, msg->dm_Command == DISPATCHER_CMD_RESUME, TAG_DONE); break; case DISPATCHER_CMD_BREAK: /* Break requests and quit */ /*dprintf("Dispatcher thread: break requested\n");*/ AHI_ControlAudio(ahi_control, AHIC_Play, FALSE, TAG_DONE); dispatcher_running = FALSE; break; } } ReplyMsg((struct Message *) msg); } } if (signal_set & (1UL << switch_sig_bit)) { /* Switch to next read buffer */ ULONG cur_buf; cur_buf = h->wh_ReadBuf; /*dprintf("Dispatcher thread: buffer switch requested. Releasing lock on %d, locking %d\n", locked_buf, cur_buf);*/ memset(h->wh_Buffers[locked_buf].bn_SampleInfo.ahisi_Address, 0, h->wh_BufSize); ReleaseSemaphore(&h->wh_Buffers[locked_buf].bn_Semaphore); cur_buf++; if (cur_buf >= AHI_BUFFERS) cur_buf = 0; ObtainSemaphore(&h->wh_Buffers[cur_buf].bn_Semaphore); locked_buf = cur_buf; h->wh_ReadBuf = cur_buf; /*dprintf("Dispatcher thread: buffer switch done\n");*/ } } } /* Cleanup */ if (init_report) { FreeVec(init_report); init_report = NULL; } if (locked_buf != -1) { ReleaseSemaphore(&h->wh_Buffers[locked_buf].bn_Semaphore); locked_buf = -1; } if (switch_sig_bit != -1) { FreeSignal(switch_sig_bit); switch_sig_bit = -1; } if (ahi_control) { AHI_FreeAudio(ahi_control); /* Also unloads all sounds */ ahi_control = NULL; } if (ahi_request) { CloseDevice((struct IORequest*) ahi_request); DeleteIORequest((struct IORequest*) ahi_request); ahi_request = NULL; ahi_device = -1; } if (sample_bufs) { FreeVec(sample_bufs); sample_bufs = NULL; } if (ahi_port) { DeleteMsgPort(ahi_port); ahi_port = NULL; } }
static int AHI_OpenAudio(_THIS, SDL_AudioSpec *spec) { // int width; D(bug("AHI opening...\n")); /* Determine the audio parameters from the AudioSpec */ switch ( spec->format & 0xFF ) { case 8: { /* Signed 8 bit audio data */ D(bug("Samples a 8 bit...\n")); spec->format = AUDIO_S8; this->hidden->bytespersample=1; if(spec->channels<2) this->hidden->type = AHIST_M8S; else this->hidden->type = AHIST_S8S; } break; case 16: { /* Signed 16 bit audio data */ D(bug("Samples a 16 bit...\n")); spec->format = AUDIO_S16MSB; this->hidden->bytespersample=2; if(spec->channels<2) this->hidden->type = AHIST_M16S; else this->hidden->type = AHIST_S16S; } break; default: { SDL_SetError("Unsupported audio format"); return(-1); } } if(spec->channels!=1 && spec->channels!=2) { D(bug("Wrong channel number!\n")); SDL_SetError("Channel number non supported"); return -1; } D(bug("Before CalculateAudioSpec\n")); /* Update the fragment size as size in bytes */ SDL_CalculateAudioSpec(spec); D(bug("Before CreateMsgPort\n")); if(!(audio_port=CreateMsgPort())) { SDL_SetError("Unable to create a MsgPort"); return -1; } D(bug("Before CreateIORequest\n")); if(!(audio_req[0]=(struct AHIRequest *)CreateIORequest(audio_port,sizeof(struct AHIRequest)))) { SDL_SetError("Unable to create an AHIRequest"); DeleteMsgPort(audio_port); return -1; } audio_req[0]->ahir_Version = 4; if(OpenDevice(AHINAME,0,(struct IORequest *)audio_req[0],NULL)) { SDL_SetError("Unable to open AHI device!\n"); DeleteIORequest((struct IORequest *)audio_req[0]); DeleteMsgPort(audio_port); return -1; } D(bug("AFTER opendevice\n")); /* Set output frequency and size */ this->hidden->freq = spec->freq; this->hidden->size = spec->size; D(bug("Before buffer allocation\n")); /* Allocate mixing buffer */ mixbuf[0] = (Uint8 *)mymalloc(spec->size); mixbuf[1] = (Uint8 *)mymalloc(spec->size); D(bug("Before audio_req allocation\n")); if(!(audio_req[1]=mymalloc(sizeof(struct AHIRequest)))) { SDL_OutOfMemory(); return(-1); } D(bug("Before audio_req memcpy\n")); SDL_memcpy(audio_req[1],audio_req[0],sizeof(struct AHIRequest)); if ( mixbuf[0] == NULL || mixbuf[1] == NULL ) { SDL_OutOfMemory(); return(-1); } D(bug("Before mixbuf memset\n")); SDL_memset(mixbuf[0], spec->silence, spec->size); SDL_memset(mixbuf[1], spec->silence, spec->size); current_buffer=0; playing=0; D(bug("AHI opened: freq:%ld mixbuf:%lx/%lx buflen:%ld bits:%ld channels:%ld\n",spec->freq,mixbuf[0],mixbuf[1],spec->size,this->hidden->bytespersample*8,spec->channels)); /* We're ready to rock and roll. :-) */ return(0); }
int main(void) { if (IntuitionBase->LibNode.lib_Version == VERSION_NUMBER) { struct MsgPort *port = CreateMsgPort(); if (port) { struct IOStdReq *req = CreateIORequest(port, sizeof(*req)); if (req) { if (OpenDevice("input.device", 0, req, 0) == 0) { BYTE old_pri; req->io_Command = IND_ADDHANDLER; req->io_Data = &interrupt; DoIO(req); /* Make sure we have a higher priority than the * input.device, in case it gets trapped in an * endless loop. */ old_pri = SetTaskPri(FindTask(NULL), 50); /* Also dump if intuition's input handler has been * frozen for more than 2s. */ do { ULONG old_secs = IntuitionBase->Seconds; ULONG old_micros = IntuitionBase->Micros; Delay(200); if (old_secs == IntuitionBase->Seconds && old_micros == IntuitionBase->Micros) { REG_A6 = (ULONG)IntuitionBase; MyEmulHandle->EmulCallDirectOS(-152 * 6); do { Delay(50); } while (old_secs == IntuitionBase->Seconds && old_micros == IntuitionBase->Micros); } } while ((SetSignal(0,0) & 0x1000) == 0); SetTaskPri(FindTask(NULL), old_pri); req->io_Command = IND_REMHANDLER; req->io_Data = &interrupt; DoIO(req); CloseDevice(req); } DeleteIORequest(req); } DeleteMsgPort(port); } } return 0; }
void main(int argc, char *argv[]) { BYTE *p1=buffer1,*p2=buffer2,*tmp; ULONG signals; if(AHImp=CreateMsgPort()) { if(AHIio=(struct AHIRequest *)CreateIORequest(AHImp,sizeof(struct AHIRequest))) { AHIio->ahir_Version = 4; AHIDevice=OpenDevice(AHINAME,0,(struct IORequest *)AHIio,NULL); } } if(AHIDevice) { Printf("Unable to open %s/0 version 4\n",AHINAME); cleanup(RETURN_FAIL); } // Initialize the first read AHIio->ahir_Std.io_Command=CMD_READ; AHIio->ahir_Std.io_Data=&buffer1; AHIio->ahir_Std.io_Length=BUFFERSIZE; AHIio->ahir_Std.io_Offset=0; AHIio->ahir_Frequency=FREQUENCY; AHIio->ahir_Type=TYPE; if(!DoIO((struct IORequest *) AHIio)) { // The first buffer is now filled SetIoErr(NULL); for(;;) { ULONG length; length=AHIio->ahir_Std.io_Actual; // Initialize the second read (note that io_Offset is not cleared!) AHIio->ahir_Std.io_Data=p2; AHIio->ahir_Std.io_Length=BUFFERSIZE; AHIio->ahir_Frequency=FREQUENCY; AHIio->ahir_Type=TYPE; SendIO((struct IORequest *) AHIio); // While the second read is in progress, save the first buffer to stdout if(Write(Output(),p1,length) != length) { break; } signals=Wait(SIGBREAKF_CTRL_C | (1L << AHImp->mp_SigBit)); if(signals & SIGBREAKF_CTRL_C) { SetIoErr(ERROR_BREAK); break; } // Remove the reply if(WaitIO((struct IORequest *) AHIio)) { SetIoErr(ERROR_READ_PROTECTED); break; } // Swap buffer pointers and repeat tmp=p1; p1=p2; p2=tmp; } // Abort any pending iorequests AbortIO((struct IORequest *) AHIio); WaitIO((struct IORequest *) AHIio); } if(IoErr()) { PrintFault(IoErr(), argv[0] ); // Oh, common! It's not MY fault that this // routine prints to stdout instead of stderr! cleanup(RETURN_ERROR); } cleanup(RETURN_OK); }
void __setupselect(void) { if (((_tport=CreateMsgPort())==NULL) || ((_treq=CreateIORequest(_tport,sizeof(*_treq)))==NULL)) exit(20); }
int main(int argc, char *argv[]) { BYTE *p1=buffer1,*p2=buffer2; void *tmp; ULONG signals,length; struct AHIRequest *link = NULL; LONG priority = 0; BYTE pri; if(argc == 2) { StrToLong(argv[1], &priority); } pri = priority; Printf("Sound priority: %ld\n", pri); if((AHImp=CreateMsgPort()) != NULL) { if((AHIio=(struct AHIRequest *)CreateIORequest(AHImp,sizeof(struct AHIRequest))) != NULL) { AHIio->ahir_Version = 4; AHIDevice=OpenDevice(AHINAME,0,(struct IORequest *)AHIio,0); } } if(AHIDevice) { Printf("Unable to open %s/0 version 4\n",AHINAME); cleanup(RETURN_FAIL); } // Make a copy of the request (for double buffering) AHIiocopy = AllocMem(sizeof(struct AHIRequest), MEMF_ANY); if(! AHIiocopy) { cleanup(RETURN_FAIL); } CopyMem(AHIio, AHIiocopy, sizeof(struct AHIRequest)); AHIios[0]=AHIio; AHIios[1]=AHIiocopy; SetIoErr(0); for(;;) { // Fill buffer length = Read(Input(),p1,BUFFERSIZE); // Play buffer AHIios[0]->ahir_Std.io_Message.mn_Node.ln_Pri = pri; AHIios[0]->ahir_Std.io_Command = CMD_WRITE; AHIios[0]->ahir_Std.io_Data = p1; AHIios[0]->ahir_Std.io_Length = length; AHIios[0]->ahir_Std.io_Offset = 0; AHIios[0]->ahir_Frequency = FREQUENCY; AHIios[0]->ahir_Type = TYPE; AHIios[0]->ahir_Volume = 0x10000; // Full volume AHIios[0]->ahir_Position = 0x8000; // Centered AHIios[0]->ahir_Link = link; SendIO((struct IORequest *) AHIios[0]); if(link) { // Wait until the last buffer is finished (== the new buffer is started) signals=Wait(SIGBREAKF_CTRL_C | (1L << AHImp->mp_SigBit)); // Check for Ctrl-C and abort if pressed if(signals & SIGBREAKF_CTRL_C) { SetIoErr(ERROR_BREAK); break; } // Remove the reply and abort on error if(WaitIO((struct IORequest *) link)) { SetIoErr(ERROR_WRITE_PROTECTED); break; } } // Check for end-of-sound, and wait until it is finished before aborting if(length != BUFFERSIZE) { WaitIO((struct IORequest *) AHIios[0]); break; } link = AHIios[0]; // Swap buffer and request pointers, and restart tmp = p1; p1 = p2; p2 = tmp; tmp = AHIios[0]; AHIios[0] = AHIios[1]; AHIios[1] = tmp; } // Abort any pending iorequests AbortIO((struct IORequest *) AHIios[0]); WaitIO((struct IORequest *) AHIios[0]); if(link) { // Only if the second request was started AbortIO((struct IORequest *) AHIios[1]); WaitIO((struct IORequest *) AHIios[1]); } if(IoErr()) { PrintFault(IoErr(), argv[0] ); cleanup(RETURN_ERROR); } cleanup(RETURN_OK); return RETURN_OK; // Make compiler happy }