void free_kittens(KittenManager * litter) { free_entity(litter->mother); Mix_FreeChunk(litter->child->claw); free(litter->child); free(litter); }
void player_destructor(Entity * me, gpointer dat) { Player * player = (Player *) dat; free_entity(me); free(player->attack_timer); Mix_FreeChunk(player->fire); free(player); }
/* Close an IO entity */ int io_close(uintptr_t handle) { int result = 0; assert(is_valid_entity(handle)); io_entity_t *entity = (io_entity_t *)handle; io_dev_info_t *dev = entity->dev_handle; /* Absence of registered function implies NOP here */ if (dev->funcs->close != NULL) result = dev->funcs->close(entity); /* Ignore improbable free_entity failure */ (void)free_entity(entity); return result; }
/* Open an IO entity */ int io_open(uintptr_t dev_handle, const uintptr_t spec, uintptr_t *handle) { int result; assert((spec != (uintptr_t)NULL) && (handle != NULL)); assert(is_valid_dev(dev_handle)); io_dev_info_t *dev = (io_dev_info_t *)dev_handle; io_entity_t *entity; result = allocate_entity(&entity); if (result == 0) { assert(dev->funcs->open != NULL); result = dev->funcs->open(dev, spec, entity); if (result == 0) { entity->dev_handle = dev; set_handle(handle, entity); } else free_entity(entity); } return result; }
/*------------------------------------------------------------------*/ void pr_out(ADAPTER *a) { byte e_no; ENTITY *this = NULL; BUFFERS *X; word length; word i; word clength; REQ *ReqOut; byte more; byte ReadyCount; byte ReqCount; byte Id; dtrc(dprintf("pr_out")); /* while a request is pending ... */ e_no = look_req(a); if (!e_no) { dtrc(dprintf("no_req")); return; } ReadyCount = pr_ready(a); if (!ReadyCount) { dtrc(dprintf("not_ready")); return; } ReqCount = 0; while (e_no && ReadyCount) { next_req(a); this = entity_ptr(a, e_no); #ifdef USE_EXTENDED_DEBUGS if (!this) { DBG_FTL(("XDI: [%02x] !A%d ==> NULL entity ptr - try to ignore", xdi_xlog_sec++, (int)((ISDN_ADAPTER *)a->io)->ANum)) e_no = look_req(a); ReadyCount--; continue; } { DBG_TRC((">A%d Id=0x%x Req=0x%x", ((ISDN_ADAPTER *)a->io)->ANum, this->Id, this->Req)) } #else dbug(dprintf("out:Req=%x,Id=%x,Ch=%x", this->Req, this->Id, this->ReqCh)); #endif /* get address of next available request buffer */ ReqOut = (REQ *)&PR_RAM->B[a->ram_inw(a, &PR_RAM->NextReq)]; #if defined(DIVA_ISTREAM) if (!(a->tx_stream[this->Id] && this->Req == N_DATA)) { #endif /* now copy the data from the current data buffer into the */ /* adapters request buffer */ length = 0; i = this->XCurrent; X = PTR_X(a, this); while (i < this->XNum && length < 270) { clength = min((word)(270 - length), (word)(X[i].PLength-this->XOffset)); a->ram_out_buffer(a, &ReqOut->XBuffer.P[length], PTR_P(a, this, &X[i].P[this->XOffset]), clength); length += clength; this->XOffset += clength; if (this->XOffset == X[i].PLength) { this->XCurrent = (byte)++i; this->XOffset = 0; } } #if defined(DIVA_ISTREAM) } else { /* Use CMA extension in order to transfer data to the card */ i = this->XCurrent; X = PTR_X(a, this); while (i < this->XNum) { diva_istream_write(a, this->Id, PTR_P(a, this, &X[i].P[0]), X[i].PLength, ((i + 1) == this->XNum), 0, 0); this->XCurrent = (byte)++i; } length = 0; } #endif a->ram_outw(a, &ReqOut->XBuffer.length, length); a->ram_out(a, &ReqOut->ReqId, this->Id); a->ram_out(a, &ReqOut->ReqCh, this->ReqCh); /* if it's a specific request (no ASSIGN) ... */ if (this->Id & 0x1f) { /* if buffers are left in the list of data buffers do */ /* do chaining (LL_MDATA, N_MDATA) */ this->More++; if (i < this->XNum && this->MInd) { xdi_xlog_request(XDI_A_NR(a), this->Id, this->ReqCh, this->MInd, a->IdTypeTable[this->No]); a->ram_out(a, &ReqOut->Req, this->MInd); more = true; } else { xdi_xlog_request(XDI_A_NR(a), this->Id, this->ReqCh, this->Req, a->IdTypeTable[this->No]); this->More |= XMOREF; a->ram_out(a, &ReqOut->Req, this->Req); more = false; if (a->FlowControlIdTable[this->ReqCh] == this->Id) a->FlowControlSkipTable[this->ReqCh] = true; /* Note that remove request was sent to the card */ if (this->Req == REMOVE) { a->misc_flags_table[e_no] |= DIVA_MISC_FLAGS_REMOVE_PENDING; } } /* if we did chaining, this entity is put back into the */ /* request queue */ if (more) { req_queue(a, this->No); } } /* else it's a ASSIGN */ else { /* save the request code used for buffer chaining */ this->MInd = 0; if (this->Id == BLLC_ID) this->MInd = LL_MDATA; if (this->Id == NL_ID || this->Id == TASK_ID || this->Id == MAN_ID ) this->MInd = N_MDATA; /* send the ASSIGN */ a->IdTypeTable[this->No] = this->Id; xdi_xlog_request(XDI_A_NR(a), this->Id, this->ReqCh, this->Req, this->Id); this->More |= XMOREF; a->ram_out(a, &ReqOut->Req, this->Req); /* save the reference of the ASSIGN */ assign_queue(a, this->No, a->ram_inw(a, &ReqOut->Reference)); } a->ram_outw(a, &PR_RAM->NextReq, a->ram_inw(a, &ReqOut->next)); ReadyCount--; ReqCount++; e_no = look_req(a); } /* send the filled request buffers to the ISDN adapter */ a->ram_out(a, &PR_RAM->ReqInput, (byte)(a->ram_in(a, &PR_RAM->ReqInput) + ReqCount)); /* if it is a 'unreturncoded' UREMOVE request, remove the */ /* Id from our table after sending the request */ if (this && (this->Req == UREMOVE) && this->Id) { Id = this->Id; e_no = a->IdTable[Id]; free_entity(a, e_no); for (i = 0; i < 256; i++) { if (a->FlowControlIdTable[i] == Id) a->FlowControlIdTable[i] = 0; } a->IdTable[Id] = 0; this->Id = 0; } }
/*------------------------------------------------------------------*/ static byte isdn_rc(ADAPTER *a, byte Rc, byte Id, byte Ch, word Ref, dword extended_info_type, dword extended_info) { ENTITY *this; byte e_no; word i; int cancel_rc; #ifdef USE_EXTENDED_DEBUGS { DBG_TRC(("<A%d Id=0x%x Rc=0x%x", ((ISDN_ADAPTER *)a->io)->ANum, Id, Rc)) } #else dbug(dprintf("isdn_rc(Rc=%x,Id=%x,Ch=%x)", Rc, Id, Ch)); #endif /* check for ready interrupt */ if (Rc == READY_INT) { xdi_xlog_rc_event(XDI_A_NR(a), Id, Ch, Rc, 0, 0); if (a->ReadyInt) { a->ReadyInt--; return 0; } return 2; } /* if we know this Id ... */ e_no = a->IdTable[Id]; if (e_no) { this = entity_ptr(a, e_no); xdi_xlog_rc_event(XDI_A_NR(a), Id, Ch, Rc, 0, a->IdTypeTable[this->No]); this->RcCh = Ch; /* if it is a return code to a REMOVE request, remove the */ /* Id from our table */ if ((a->misc_flags_table[e_no] & DIVA_MISC_FLAGS_REMOVE_PENDING) && (Rc == OK)) { if (a->IdTypeTable[e_no] == NL_ID) { if (a->RcExtensionSupported && (extended_info_type != DIVA_RC_TYPE_REMOVE_COMPLETE)) { dtrc(dprintf("XDI: N-REMOVE, A(%02x) Id:%02x, ignore RC=OK", XDI_A_NR(a), Id)); return (0); } if (extended_info_type == DIVA_RC_TYPE_REMOVE_COMPLETE) a->RcExtensionSupported = true; } a->misc_flags_table[e_no] &= ~DIVA_MISC_FLAGS_REMOVE_PENDING; a->misc_flags_table[e_no] &= ~DIVA_MISC_FLAGS_NO_RC_CANCELLING; free_entity(a, e_no); for (i = 0; i < 256; i++) { if (a->FlowControlIdTable[i] == Id) a->FlowControlIdTable[i] = 0; } a->IdTable[Id] = 0; this->Id = 0; /* --------------------------------------------------------------- If we send N_DISC or N_DISK_ACK after we have received OK_FC then the card will respond with OK_FC and later with RC==OK. If we send N_REMOVE in this state we will receive only RC==OK This will create the state in that the XDI is waiting for the additional RC and does not delivery the RC to the client. This code corrects the counter of outstanding RC's in this case. --------------------------------------------------------------- */ if ((this->More & XMOREC) > 1) { this->More &= ~XMOREC; this->More |= 1; dtrc(dprintf("XDI: correct MORE on REMOVE A(%02x) Id:%02x", XDI_A_NR(a), Id)); } } if (Rc == OK_FC) { a->FlowControlIdTable[Ch] = Id; a->FlowControlSkipTable[Ch] = false; this->Rc = Rc; this->More &= ~(XBUSY | XMOREC); this->complete = 0xff; xdi_xlog_rc_event(XDI_A_NR(a), Id, Ch, Rc, 1, a->IdTypeTable[this->No]); CALLBACK(a, this); return 0; } /* New protocol code sends return codes that comes from release of flow control condition marked with DIVA_RC_TYPE_OK_FC extended information element type. If like return code arrives then application is able to process all return codes self and XDI should not cances return codes. This return code does not decrement XMOREC partial return code counter due to fact that it was no request for this return code, also XMOREC was not incremented. */ if (extended_info_type == DIVA_RC_TYPE_OK_FC) { a->misc_flags_table[e_no] |= DIVA_MISC_FLAGS_NO_RC_CANCELLING; this->Rc = Rc; this->complete = 0xff; xdi_xlog_rc_event(XDI_A_NR(a), Id, Ch, Rc, 1, a->IdTypeTable[this->No]); DBG_TRC(("XDI OK_FC A(%02x) Id:%02x Ch:%02x Rc:%02x", XDI_A_NR(a), Id, Ch, Rc)) CALLBACK(a, this); return 0; } cancel_rc = !(a->misc_flags_table[e_no] & DIVA_MISC_FLAGS_NO_RC_CANCELLING); if (cancel_rc && (a->FlowControlIdTable[Ch] == Id)) { a->FlowControlIdTable[Ch] = 0; if ((Rc != OK) || !a->FlowControlSkipTable[Ch]) { this->Rc = Rc; if (Ch == this->ReqCh) { this->More &= ~(XBUSY | XMOREC); this->complete = 0xff; } xdi_xlog_rc_event(XDI_A_NR(a), Id, Ch, Rc, 1, a->IdTypeTable[this->No]); CALLBACK(a, this); } return 0; } if (this->More & XMOREC) this->More--; /* call the application callback function */ if (((!cancel_rc) || (this->More & XMOREF)) && !(this->More & XMOREC)) { this->Rc = Rc; this->More &= ~XBUSY; this->complete = 0xff; xdi_xlog_rc_event(XDI_A_NR(a), Id, Ch, Rc, 1, a->IdTypeTable[this->No]); CALLBACK(a, this); } return 0; } /* if it's an ASSIGN return code check if it's a return */ /* code to an ASSIGN request from us */ if ((Rc & 0xf0) == ASSIGN_RC) { e_no = get_assign(a, Ref); if (e_no) { this = entity_ptr(a, e_no); this->Id = Id; xdi_xlog_rc_event(XDI_A_NR(a), Id, Ch, Rc, 2, a->IdTypeTable[this->No]); /* call the application callback function */ this->Rc = Rc; this->More &= ~XBUSY; this->complete = 0xff; #if defined(DIVA_ISTREAM) /* { */ if ((Rc == ASSIGN_OK) && a->ram_offset && (a->IdTypeTable[this->No] == NL_ID) && ((extended_info_type == DIVA_RC_TYPE_RX_DMA) || (extended_info_type == DIVA_RC_TYPE_CMA_PTR)) && extended_info) { dword offset = (*(a->ram_offset)) (a); dword tmp[2]; extended_info -= offset; #ifdef PLATFORM_GT_32BIT a->ram_in_dw(a, (void *)ULongToPtr(extended_info), (dword *)&tmp[0], 2); #else a->ram_in_dw(a, (void *)extended_info, (dword *)&tmp[0], 2); #endif a->tx_stream[Id] = tmp[0]; a->rx_stream[Id] = tmp[1]; if (extended_info_type == DIVA_RC_TYPE_RX_DMA) { DBG_TRC(("Id=0x%x RxDMA=%08x:%08x", Id, a->tx_stream[Id], a->rx_stream[Id])) a->misc_flags_table[this->No] |= DIVA_MISC_FLAGS_RX_DMA; } else { DBG_TRC(("Id=0x%x CMA=%08x:%08x", Id, a->tx_stream[Id], a->rx_stream[Id])) a->misc_flags_table[this->No] &= ~DIVA_MISC_FLAGS_RX_DMA; a->rx_pos[Id] = 0; a->rx_stream[Id] -= offset; } a->tx_pos[Id] = 0; a->tx_stream[Id] -= offset; } else { a->tx_stream[Id] = 0; a->rx_stream[Id] = 0; a->misc_flags_table[this->No] &= ~DIVA_MISC_FLAGS_RX_DMA; } #endif /* } */ CALLBACK(a, this); if (Rc == ASSIGN_OK) { a->IdTable[Id] = e_no; } else { free_entity(a, e_no); for (i = 0; i < 256; i++) { if (a->FlowControlIdTable[i] == Id) a->FlowControlIdTable[i] = 0; } a->IdTable[Id] = 0; this->Id = 0; } return 1; } } return 2; }
/* * Optimize the frame type of an irg by removing * never touched entities. */ void opt_frame_irg(ir_graph *irg) { ir_type *frame_tp = get_irg_frame_type(irg); ir_entity *ent, *list; ir_node *frame, *sel; size_t i, n = get_class_n_members(frame_tp); int o; if (n <= 0) return; assure_irg_properties(irg, IR_GRAPH_PROPERTY_CONSISTENT_OUTS); irp_reserve_resources(irp, IRP_RESOURCE_ENTITY_LINK); /* clear all entity links */ for (i = n; i > 0;) { ent = get_class_member(frame_tp, --i); set_entity_link(ent, NULL); } /* look for uses */ frame = get_irg_frame(irg); /* mark all used entities */ for (o = get_irn_n_outs(frame) - 1; o >= 0; --o) { sel = get_irn_out(frame, o); if (is_Sel(sel)) { ent = get_Sel_entity(sel); /* only entities on the frame */ if (get_entity_owner(ent) == frame_tp) set_entity_link(ent, ent); } } /* link unused ones */ list = NULL; for (i = n; i > 0;) { ent = get_class_member(frame_tp, --i); /* beware of inner functions: those are NOT unused */ if (get_entity_link(ent) == NULL && !is_method_entity(ent)) { set_entity_link(ent, list); list = ent; } } if (list != NULL) { /* delete list members */ for (ent = list; ent; ent = list) { list = (ir_entity*)get_entity_link(ent); free_entity(ent); } /* we changed the frame type, its layout should be redefined */ set_type_state(frame_tp, layout_undefined); } irp_free_resources(irp, IRP_RESOURCE_ENTITY_LINK); /* we changed the type, this affects none of the currently known graph * properties, but I don't use ALL because I don't know if someone adds * type-based properties at some point */ confirm_irg_properties(irg, IR_GRAPH_PROPERTIES_CONTROL_FLOW | IR_GRAPH_PROPERTY_NO_BADS | IR_GRAPH_PROPERTY_NO_TUPLES | IR_GRAPH_PROPERTY_CONSISTENT_OUT_EDGES | IR_GRAPH_PROPERTY_CONSISTENT_OUTS | IR_GRAPH_PROPERTY_CONSISTENT_ENTITY_USAGE | IR_GRAPH_PROPERTY_MANY_RETURNS); }
static byte isdn_rc(ADAPTER * a, byte Rc, byte Id, byte Ch, word Ref) { ENTITY * this; byte e_no; #ifdef USE_EXTENDED_DEBUGS { ISDN_ADAPTER *io = (ISDN_ADAPTER *)a->io ; DPRINTF(("IDI: <A%d Id=0x%x Rc=0x%x", io->ANum, Id, Rc)) } #else DPRINTF(("IDI: <RC(Rc=%x,Id=%x,Ch=%x)",Rc,Id,Ch)); #endif /* check for ready interrupt */ if(Rc==READY_INT) { if(a->ReadyInt) { a->ReadyInt--; return 0; } return 2; } /* if we know this Id ... */ e_no = a->IdTable[Id]; if(e_no) { this = entity_ptr(a,e_no); this->RcCh = Ch; /* if it is a return code to a REMOVE request, remove the */ /* Id from our table */ if(this->Req==REMOVE && Rc==OK) { free_entity(a, e_no); a->IdTable[Id] = 0; this->Id = 0; /**************************************************************/ if ((this->More & XMOREC) > 1) { this->More &= ~XMOREC; this->More |= 1; DPRINTF(("isdn_rc, Id=%x, correct More on REMOVE", Id)); } } if (Rc==OK_FC) { this->Rc = Rc; this->More = (this->More & (~XBUSY | XMOREC)) | 1; this->complete = 0xFF; CALLBACK(a, this); return 0; } if(this->More &XMOREC) this->More--; /* call the application callback function */ if(this->More &XMOREF && !(this->More &XMOREC)) { this->Rc = Rc; this->More &=~XBUSY; this->complete=0xff; CALLBACK(a, this); } return 0; } /* if it's an ASSIGN return code check if it's a return */ /* code to an ASSIGN request from us */ if((Rc &0xf0)==ASSIGN_RC) { e_no = get_assign(a, Ref); if(e_no) { this = entity_ptr(a,e_no); this->Id = Id; /* call the application callback function */ this->Rc = Rc; this->More &=~XBUSY; this->complete=0xff; CALLBACK(a, this); if(Rc==ASSIGN_OK) { a->IdTable[Id] = e_no; } else { free_entity(a, e_no); a->IdTable[Id] = 0; this->Id = 0; } return 1; } } return 2; }
void DivasOut(ADAPTER * a) { byte e_no; ENTITY * this = NULL; BUFFERS *X; word length; word i; word clength; REQ * ReqOut; byte more; byte ReadyCount; byte ReqCount; byte Id; /* while a request is pending ... */ e_no = look_req(a); if(!e_no) { return; } ReadyCount = pr_ready(a); if(!ReadyCount) { DPRINTF(("IDI: card not ready for next request")); return; } ReqCount = 0; while(e_no && ReadyCount) { next_req(a); this = entity_ptr(a, e_no); #ifdef USE_EXTENDED_DEBUGS if ( !this ) { ISDN_ADAPTER *io = (ISDN_ADAPTER *)a->io ; DBG_FTL(("!A%d ==> NULL entity ptr - try to ignore", (int)io->ANum)) e_no = look_req(a) ; ReadyCount-- ; continue ; } { ISDN_ADAPTER *io = (ISDN_ADAPTER *)a->io ; DPRINTF(("IDI: >A%d Id=0x%x Req=0x%x", io->ANum, this->Id, this->Req)) } #else DPRINTF(("IDI: >REQ=%x,Id=%x,Ch=%x",this->Req,this->Id,this->ReqCh)); #endif /* get address of next available request buffer */ ReqOut = (REQ *)&PR_RAM->B[a->ram_inw(a, &PR_RAM->NextReq)]; /* now copy the data from the current data buffer into the */ /* adapters request buffer */ length = 0; i = this->XCurrent; X = PTR_X(a,this); while(i<this->XNum && length<270) { clength = (word)(270-length); if (clength > X[i].PLength-this->XOffset) clength = X[i].PLength-this->XOffset; a->ram_out_buffer(a, &ReqOut->XBuffer.P[length], PTR_P(a,this,&X[i].P[this->XOffset]), clength); length +=clength; this->XOffset +=clength; if(this->XOffset==X[i].PLength) { this->XCurrent = (byte)++i; this->XOffset = 0; } } a->ram_outw(a, &ReqOut->XBuffer.length, length); a->ram_out(a, &ReqOut->ReqId, this->Id); a->ram_out(a, &ReqOut->ReqCh, this->ReqCh); /* if its a specific request (no ASSIGN) ... */ if(this->Id &0x1f) { /* if buffers are left in the list of data buffers do */ /* do chaining (LL_MDATA, N_MDATA) */ this->More++; if(i<this->XNum && this->MInd) { a->ram_out(a, &ReqOut->Req, this->MInd); more = TRUE; } else { this->More |=XMOREF; a->ram_out(a, &ReqOut->Req, this->Req); more = FALSE; } /* if we did chaining, this entity is put back into the */ /* request queue */ if(more) { req_queue(a,this->No); } } /* else it's a ASSIGN */ else { /* save the request code used for buffer chaining */ this->MInd = 0; if (this->Id==BLLC_ID) this->MInd = LL_MDATA; if (this->Id==NL_ID || this->Id==TASK_ID || this->Id==MAN_ID ) this->MInd = N_MDATA; /* send the ASSIGN */ this->More |=XMOREF; a->ram_out(a, &ReqOut->Req, this->Req); /* save the reference of the ASSIGN */ assign_queue(a, this->No, a->ram_inw(a, &ReqOut->Reference)); } a->ram_outw(a, &PR_RAM->NextReq, a->ram_inw(a, &ReqOut->next)); ReadyCount--; ReqCount++; e_no = look_req(a); } /* send the filled request buffers to the ISDN adapter */ a->ram_out(a, &PR_RAM->ReqInput, (byte)(a->ram_in(a, &PR_RAM->ReqInput) + ReqCount)); /* if it is a 'unreturncoded' UREMOVE request, remove the */ /* Id from our table after sending the request */ if(this->Req==UREMOVE && this->Id) { Id = this->Id; e_no = a->IdTable[Id]; free_entity(a, e_no); a->IdTable[Id] = 0; this->Id = 0; } }