-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.py
139 lines (102 loc) · 3.69 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
import machine
import time
import utime
# http://problemkaputt.de/psx-spx.htm#cdromprotectionmodchips
# DATA is responsible for transferring the SCEX data
# MM3 Equivalent is Pin 6
DATA = 14 # GPIO14 - D5
# GATE is required to be LOW to allow the modchip to inject
# MM3 Equivalent is Pin 5
GATE = 12 # GPIO12 - D6
# LID is whether or not the LID is connected
# MM3 Equivalent is Pin 7
LID = 13 # GPIO13 - D7
# MM3 for GND is Pin 8
# MM3 for VCC/PWR is Pin 1
FIRST_BOOT = True
NEW_PS_MODEL = False
SCEE_data = (1,0,0,1,1,0,1,0,1,0,0,1,0,0,1,1,1,1,0,1,0,0,1,0,1,0,1,1,1,0,1,0,0,1,0,1,0,1,1,1,0,1,0,0)
SCEA_data = (1,0,0,1,1,0,1,0,1,0,0,1,0,0,1,1,1,1,0,1,0,0,1,0,1,0,1,1,1,0,1,0,0,1,0,1,1,1,1,1,0,1,0,0)
SCEI_data = (1,0,0,1,1,0,1,0,1,0,0,1,0,0,1,1,1,1,0,1,0,0,1,0,1,0,1,1,1,0,1,0,0,1,0,1,1,0,1,1,0,1,0,0)
def inject():
utime.sleep_ms(6900)
machine.Pin(DATA, machine.Pin.OUT)
machine.Pin(DATA).value(0)
utime.sleep_ms(100)
machine.Pin(GATE, machine.Pin.OUT)
machine.Pin(GATE).value(0)
for i in range(8):
for data in (SCEA_data, SCEE_data, SCEI_data):
for bit in data:
if bit:
machine.Pin(DATA, machine.Pin.IN)
utime.sleep_us(4000)
else:
if NEW_PS_MODEL:
# machine.Pin(DATA, machine.Pin.OUT)
# now = utime.ticks_ms()
# while ( (utime.ticks_ms() - now) < 4000 ):
# pass
machine.Pin(DATA, machine.Pin.OUT)
machine.Pin(DATA).value(0)
utime.sleep_us(4000)
else:
machine.Pin(DATA, machine.Pin.OUT)
machine.Pin(DATA).value(0)
utime.sleep_us(4000)
utime.sleep_ms(90)
machine.Pin(DATA, machine.Pin.IN)
machine.Pin(GATE, machine.Pin.IN)
utime.sleep_ms(11000)
machine.Pin(GATE, machine.Pin.OUT)
machine.Pin(GATE).value(0)
for i in range(20):
for data in (SCEA_data, SCEE_data, SCEI_data):
for bit in data:
if bit:
machine.Pin(DATA, machine.Pin.IN)
utime.sleep_us(4000)
else:
if NEW_PS_MODEL:
# machine.Pin(DATA, machine.Pin.OUT)
# now = utime.ticks_ms()
# while ( (utime.ticks_ms() - now) < 4000 ):
# pass
machine.Pin(DATA, machine.Pin.OUT)
machine.Pin(DATA).value(0)
utime.sleep_us(4000)
else:
machine.Pin(DATA, machine.Pin.OUT)
machine.Pin(DATA).value(0)
utime.sleep_us(4000)
utime.sleep_ms(90)
machine.Pin(DATA, machine.Pin.IN)
machine.Pin(GATE, machine.Pin.IN)
machine.Pin(DATA, machine.Pin.IN)
machine.Pin(GATE, machine.Pin.IN)
machine.Pin(LID, machine.Pin.IN)
high_count = 0
low_count = 0
now = utime.ticks_ms()
while ( (utime.ticks_ms() - now) < 1000 ):
if machine.Pin(GATE).value() == 1:
high_count += 1
if machine.Pin(GATE).value() == 0:
low_count += 1
utime.sleep_us(200)
if low_count > 100:
NEW_PS_MODEL = True
# else: NEW_PS_MODEL is False by default
time.sleep_ms(1200)
while True:
lid_status = machine.Pin(LID).value()
# LID=1 means CD drive is open
# LID=0 means CD drive is closed
if FIRST_BOOT:
inject()
FIRST_BOOT = False
else:
time.sleep_ms(50)
if lid_status != 0:
time.sleep_ms(100)
inject()