19#ifdef BUILDING_XPADMAN
45u32 vblankStartCount = 0;
46s32 mainThreadCount = 0;
48static void TransferThread(
void *arg)
54 WaitClearEvent(vblankData.eventflag, EF_VB_TRANSFER, WEF_AND|WEF_CLEAR, NULL);
56 SetEventFlag(vblankData.eventflag, EF_VB_TRANSFER_DONE);
60u32 padSetupEEButtonData(u32 port, u32 slot,
padState_t *pstate)
62 u8 *data = pad_ee_addr ? pstate->ee_pdata.data : pstate->ee_old_pdata.data;
63 if(padState[port][slot].buttonDataReady == 1)
68 data[1] = padState[port][slot].modeCurId;
69 data[31] = padState[port][slot].buttonStatus[2];
72 data[i] = padState[port][slot].buttonStatus[i+1];
74 if(padState[port][slot].modeCurId == 0x12)
83 if(padState[port][slot].modeCurId == 0x79)
88 value = ~((data[2] << 8) | data[3]);
242 for(i=1; i < 32; i++)
250static void DmaSendEE(
void)
254 dma_stat = sceSifDmaStat(sifdma_id);
258 if( (frame_count % 240) == 0)
260 M_KPRINTF(
"DMA Busy ID = %08x ret = %d\n", sifdma_id, dma_stat);
261 M_KPRINTF(
" SB_STAT = %08x\n", SB_STAT);
267 u32 sifdma_count = 0;
279 sif_buffer[1] = pad_portdata[0];
280 sif_buffer[2] = pad_portdata[1];
284 if( (sif_buffer[0] % 2) == 0)
285 sifdma_td[sifdma_count].dest = (
void *)(((u8 *)pad_ee_addr) + 128);
287 sifdma_td[sifdma_count].dest = pad_ee_addr;
289 sifdma_td[sifdma_count].src = sif_buffer;
290 sifdma_td[sifdma_count].size = 128;
291 sifdma_td[sifdma_count].attr = 0;
295 for(port=0; port < 2; port++)
297 for(slot=0; slot < 4; slot++)
299 if( (openSlots[port] >> slot) & 1 )
304 p->ee_pdata.frame = p->frame;
305 p->ee_pdata.findPadRetries = p->findPadRetries;
306 p->ee_pdata.modeConfig = p->modeConfig;
307 p->ee_pdata.modeCurId = p->modeCurId;
308 p->ee_pdata.model = p->model;
309 p->ee_pdata.buttonDataReady = p->buttonDataReady;
310 p->ee_pdata.nrOfModes = p->numModes;
311 p->ee_pdata.modeCurOffs = p->modeCurOffs;
312 p->ee_pdata.nrOfActuators = p->numActuators;
313 p->ee_pdata.numActComb = p->numActComb;
314 p->ee_pdata.val_c6 = p->val_c6;
315 p->ee_pdata.mode = p->mode;
316 p->ee_pdata.lock = p->lock;
317 p->ee_pdata.actDirSize = p->ee_actDirectSize;
318 p->ee_pdata.state = p->state;
319 p->ee_pdata.reqState = p->reqState;
320 p->ee_pdata.currentTask = p->currentTask;
321 p->ee_old_pdata.frame = p->frame;
322 p->ee_old_pdata.model = p->model;
323 p->ee_old_pdata.state = p->state;
324 if (p->state == PAD_STATE_ERROR && p->findPadRetries != 0)
326 p->ee_old_pdata.state = PAD_STATE_FINDPAD;
328 p->ee_old_pdata.reqState = p->reqState;
332 p->ee_pdata.runTask = p->runTask;
334 p->ee_pdata.actDirData[0] = p->ee_actDirectData.data32[0];
335 p->ee_pdata.actDirData[1] = p->ee_actDirectData.data32[1];
336 p->ee_pdata.actAlignData[0] = p->ee_actAlignData.data32[0];
337 p->ee_pdata.actAlignData[1] = p->ee_actAlignData.data32[1];
339 p->ee_pdata.actData[0] = p->actData.data32[0];
340 p->ee_pdata.actData[1] = p->actData.data32[1];
341 p->ee_pdata.actData[2] = p->actData.data32[2];
342 p->ee_pdata.actData[3] = p->actData.data32[3];
343 p->ee_pdata.combData[0] = p->combData.data32[0];
344 p->ee_pdata.combData[1] = p->combData.data32[1];
345 p->ee_pdata.combData[2] = p->combData.data32[2];
346 p->ee_pdata.combData[3] = p->combData.data32[3];
348 p->ee_pdata.modeTable[0] = p->modeTable.data32[0];
349 p->ee_pdata.modeTable[1] = p->modeTable.data32[1];
351 p->ee_pdata.stat70bit = p->stat70bit;
353 *((pad_ee_addr) ? &(p->ee_pdata.length) : &(p->ee_old_pdata.length)) = (p->buttonDataReady == 1) ? padSetupEEButtonData(port, slot, p) : 0;
355 if( (p->frame & 1) == 0)
356 sifdma_td[sifdma_count].dest = (
void*)p->padarea_ee_addr;
358 sifdma_td[sifdma_count].dest = (
void*)(p->padarea_ee_addr + (pad_ee_addr ? 128 : 64));
360 sifdma_td[sifdma_count].src = pad_ee_addr ? (
void *)&p->ee_pdata : (void *)&p->ee_old_pdata;
361 sifdma_td[sifdma_count].size = pad_ee_addr ? 128 : 64;
362 sifdma_td[sifdma_count].attr = 0;
369 if(sifdma_count != 0)
375 sifdma_id = sceSifSetDma( sifdma_td, sifdma_count);
380 M_KPRINTF(
"sceSifSetDma failed\n");
390 if( ReferThreadStatus(state->updatepadTid, &tinfo) == 0)
392 if( (tinfo.status & THS_DORMANT) == 0)
count++;
395 if( ReferThreadStatus(state->querypadTid, &tinfo) == 0)
397 if( (tinfo.status & THS_DORMANT) == 0)
count++;
400 if( ReferThreadStatus(state->setmainmodeTid, &tinfo) == 0)
402 if( (tinfo.status & THS_DORMANT) == 0)
count++;
405 if( ReferThreadStatus(state->setactalignTid, &tinfo) == 0)
407 if( (tinfo.status & THS_DORMANT) == 0)
count++;
410 if( ReferThreadStatus(state->setbuttoninfoTid, &tinfo) == 0)
412 if( (tinfo.status & THS_DORMANT) == 0)
count++;
415 if( ReferThreadStatus(state->setvrefparamTid, &tinfo) == 0)
417 if( (tinfo.status & THS_DORMANT) == 0)
count++;
428 DeleteThread(state->updatepadTid);
429 DeleteThread(state->querypadTid);
430 DeleteThread(state->setmainmodeTid);
431 DeleteThread(state->setactalignTid);
432 DeleteThread(state->setbuttoninfoTid);
433 DeleteThread(state->setvrefparamTid);
436static void MainThread(
void *arg)
446#ifdef BUILDING_XPADMAN
447 if( mainThreadCount % 30 == 0 ) sio2_mtap_update_slots();
450 for(port=0; port < 2; port++)
452 for(slot=0; slot < 4; slot++)
454 if( ((openSlots[port] >> slot) & 0x1) == 1)
456 pdSetActive(port, slot, 0);
458 padState[port][slot].stat70bit = pdGetStat70bit(port, slot);
460 if(padState[port][slot].runTask != TASK_NONE)
462 if(padState[port][slot].runTask == TASK_PORT_CLOSE)
464 padState[port][slot].currentTask = padState[port][slot].runTask;
465 padState[port][slot].runTask = TASK_NONE;
466 padState[port][slot].reqState = PAD_RSTAT_BUSY;
468 SetEventFlag(padState[port][slot].eventflag, EF_EXIT_THREAD);
472 if(padState[port][slot].currentTask == TASK_UPDATE_PAD)
475 StartThread(padState[port][slot].taskTid, NULL);
476 padState[port][slot].currentTask = padState[port][slot].runTask;
477 padState[port][slot].runTask = TASK_NONE;
478 padState[port][slot].reqState = PAD_RSTAT_BUSY;
482 padState[port][slot].runTask = TASK_NONE;
483 padState[port][slot].reqState = PAD_RSTAT_FAILED;
489 switch(padState[port][slot].currentTask)
491 case TASK_UPDATE_PAD:
493 SetEventFlag(padState[port][slot].eventflag, EF_UPDATE_PAD);
494 WaitEventFlag(padState[port][slot].eventflag, EF_PAD_TRANSFER_START, 0x10, 0);
495 pdSetActive(port, slot, 1);
500 padState[port][slot].buttonDataReady = 0;
502 SetEventFlag(padState[port][slot].eventflag, EF_QUERY_PAD);
503 WaitEventFlag(padState[port][slot].eventflag, EF_PAD_TRANSFER_START, 0x10, 0);
504 pdSetActive(port, slot, 1);
507 case TASK_PORT_CLOSE:
509 if(GetThreadsStatus( &padState[port][slot] ) == 1)
511 padState[port][slot].currentTask = TASK_NONE;
512 padState[port][slot].reqState = PAD_RSTAT_COMPLETE;
513 openSlots[port] ^= (1 << slot);
515 DeleteThreads( &padState[port][slot] );
516 SetEventFlag(padState[port][slot].eventflag, EF_PORT_CLOSE);
521 case TASK_SET_MAIN_MODE:
523 padState[port][slot].buttonDataReady = 0;
525 SetEventFlag(padState[port][slot].eventflag, EF_SET_MAIN_MODE);
526 WaitEventFlag(padState[port][slot].eventflag, EF_PAD_TRANSFER_START, 0x10, 0);
527 pdSetActive(port, slot, 1);
530 case TASK_SET_ACT_ALIGN:
532 padState[port][slot].buttonDataReady = 0;
534 SetEventFlag(padState[port][slot].eventflag, EF_SET_ACT_ALIGN);
535 WaitEventFlag(padState[port][slot].eventflag, EF_PAD_TRANSFER_START, 0x10, 0);
536 pdSetActive(port, slot, 1);
539 case TASK_SET_BUTTON_INFO:
541 padState[port][slot].buttonDataReady = 0;
543 SetEventFlag(padState[port][slot].eventflag, EF_SET_SET_BUTTON_INFO);
544 WaitEventFlag(padState[port][slot].eventflag, EF_PAD_TRANSFER_START, 0x10, 0);
545 pdSetActive(port, slot, 1);
548 case TASK_SET_VREF_PARAM:
550 padState[port][slot].buttonDataReady = 0;
552 SetEventFlag(padState[port][slot].eventflag, EF_SET_VREF_PARAM);
553 WaitEventFlag(padState[port][slot].eventflag, EF_PAD_TRANSFER_START, 0x10, 0);
554 pdSetActive(port, slot, 1);
562 vblankData.stopTransfer = 0;
563 WaitClearEvent(vblankData.eventflag, EF_VB_TRANSFER_DONE, WEF_AND|WEF_CLEAR, NULL);
565 if( (openSlots[0] != 0) || (openSlots[1] != 0))
567 for(port=0; port < 2; port++)
569 for(slot=0; slot < 4; slot++)
571 if(pdIsActive(port, slot) == 1)
575 SetEventFlag(padState[port][slot].eventflag, EF_PAD_TRANSFER_DONE);
576 WaitEventFlag(padState[port][slot].eventflag, EF_TASK_DONE, 0x10, 0);
588 if(mainThreadCount2 >= 8)
590 if(mainThreadCount % 30 != 0)
592 if( pdIsActive(pad_port, pad_slot) == 1)
594 if( padState[pad_port][pad_slot].state == PAD_STATE_DISCONN)
595 pad_portdata[pad_port] &= ~(1 << pad_slot);
597 pad_portdata[pad_port] |= (1 << pad_slot);
601 if( pdCheckConnection(pad_port, pad_slot) == 1)
602 pad_portdata[pad_port] |= (1 << pad_slot);
604 pad_portdata[pad_port] &= ~(1 << pad_slot);
615 if(pad_port >= 2) pad_port = 0;
618 mainThreadCount2 = 0;
629 if( iReferThreadStatus(vData->tid_1, &tinfo) == 0)
631 if( (tinfo.status & THS_DORMANT) == 0 )
635 if( iReferThreadStatus(vData->tid_2, &tinfo) == 0)
637 if( (tinfo.status & THS_DORMANT) == 0 )
644int VblankStart(
void *arg)
652 if((vData->init == 1) && (vData->stopTransfer == 0))
654 vData->stopTransfer = 1;
655 iSetEventFlag(vData->eventflag, EF_VB_TRANSFER);
659 if(vData->padEnd == 1)
661 if( VbReferThreadStatus(vData) == 0 )
662 iSetEventFlag(vData->eventflag, EF_VB_WAIT_THREAD_EXIT);
669int VblankEnd(
void *arg)
685 M_PRINTF(
"Refresh request from EE\n.");
689 vblankData.padEnd = 0;
691 vblankData.stopTransfer = 1;
693 pad_ee_addr = ee_addr;
696 mainThreadCount2 = 0;
702 sio2cmdInitFindPads();
704 sio2cmdInitNegicon();
705 sio2cmdInitKonamiGun();
706 sio2cmdInitDigital();
707 sio2cmdInitJoystick();
708 sio2cmdInitNamcoGun();
721 vblankData.eventflag = CreateEventFlag(&
event);
723 if( vblankData.eventflag == 0)
725 M_PRINTF(
"padInit: CreateEventFlag failed (%d).\n", vblankData.eventflag);
730 thread.thread = &TransferThread;
732 thread.priority = thpri_hi;
734 vblankData.tid_2 = CreateThread(&
thread);
736 if(vblankData.tid_2 == 0)
738 M_PRINTF(
"padInit: CreateThread TransferThread failed (%d)\n.", vblankData.tid_2);
742 StartThread(vblankData.tid_2, NULL);
745 thread.thread = MainThread;
746 thread.stacksize = 0x1000;
747 thread.priority = thpri_lo;
749 vblankData.tid_1 = CreateThread(&
thread);
751 if(vblankData.tid_1 == 0)
753 M_PRINTF(
"padInit: CreateThread MainThread failed (%d)\n.", vblankData.tid_1);
757 StartThread(vblankData.tid_1, NULL);
761 RegisterVblankHandler(0, 16, &VblankStart, (
void*)&vblankData);
762 RegisterVblankHandler(1, 16, &VblankEnd, (
void*)&vblankData);
int CpuResumeIntr(int state)
int CpuSuspendIntr(int *state)
u32 count
start sector of fragmented bd/file