PS2SDK
PS2 Homebrew Libraries
Loading...
Searching...
No Matches
iop_sbus.c
1/*
2
3IOP-specifc code for PS2 SBUS library.
4
5This file contains the IRX glue, etc needed for an SBUS driver on IOP.
6
7*/
8
9#include <tamtypes.h>
10#include <ps2_sbus.h>
11#include <loadcore.h>
12#include <stdio.h>
13#include <thbase.h>
14#include "sbus_priv.h"
15
16IRX_ID("sbus_driver", 1, 0);
17
18extern struct irx_export_table _exp_sbus;
19
20extern int __local_sbus_irq_handler(void);
21
22void SBUS_check_intr(void)
23{
24 if (!(*R_IOP_I_MASK & IOP_I_STAT_SBUS)) {
25 *R_IOP_I_MASK |= IOP_I_STAT_SBUS;
26 }
27
28 if (*R_IOP_I_STAT & IOP_I_STAT_SBUS) {
29 __local_sbus_irq_handler();
30 *R_IOP_I_STAT &= ~(IOP_I_STAT_SBUS);
31 }
32}
33
34int SBUS_interrupt_remote(int irq)
35{
36 // wait for remote to clear "irq" bit
37 while (SBUS_get_reg(PS2_SBUS_LR_FLAG) & (1 << irq))
38 ;
39
40 // set the SBUS "irq" bit for remote interrupt.
41 SBUS_set_reg(PS2_SBUS_LR_FLAG, 1 << irq);
42
43 // cause SBUS interrupt on remote.
44 *R_IOP_IRQ_CTRL |= (1 << PS2_IRQ_SBUS);
45
46 // clear the SBUS interrupt on remote.
47 *R_IOP_IRQ_CTRL &= ~(1 << PS2_IRQ_SBUS);
48
49 return (irq);
50}
51
52int _start(int argc, char *argv[])
53{
54 (void)argc;
55 (void)argv;
56
57 if (SBUS_init() != 0) {
58 printf("IOP: SBUS_init() failed!\n");
59 return MODULE_NO_RESIDENT_END;
60 }
61 if (SIF2_init() != 0) {
62 printf("IOP: SIF2_init() failed!\n");
63 return MODULE_NO_RESIDENT_END;
64 }
65 if (SIF2_init_cmd() != 0) {
66 printf("IOP: SIF2_init_cmd() failed!\n");
67 return MODULE_NO_RESIDENT_END;
68 }
69 if (RegisterLibraryEntries(&_exp_sbus) != 0) {
70 printf("IOP: Error registering SBUS library!\n");
71 return MODULE_NO_RESIDENT_END;
72 }
73
74 printf("IOP: SBUS driver loaded!\n");
75
76 return MODULE_RESIDENT_END;
77}
78
79int _stop(int argc, char *argv[])
80{
81 (void)argc;
82 (void)argv;
83
84 ReleaseLibraryEntries(&_exp_sbus);
85
86 SBUS_deinit();
87 SIF2_deinit();
88 return MODULE_NO_RESIDENT_END;
89}