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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
|
%global _empty_manifest_terminate_build 0
Name: python-cynes
Version: 0.0.3
Release: 1
Summary: C/C++ NES emulator with Python bindings
License: GPL-3.0
URL: https://github.com/Youlixx/cynes
Source0: https://mirrors.nju.edu.cn/pypi/web/packages/a7/c8/cfda82c672256997d70eefedd010df6c0acc1a654754b07766d0e0de5eac/cynes-0.0.3.tar.gz
Requires: python3-numpy
Requires: python3-pysdl2-dll
Requires: python3-pysdl2
%description
# cynes - C/C++ NES emulator with Python bindings
cynes is a lightweight multiplatform NES emulator providing a simple Python interface. The core of the emulation is based on the very complete documentation provided by the [Nesdev Wiki](https://wiki.nesdev.com/w/index.php?title=NES_reference_guide). The current implementation consists of
- A cycle-accurate CPU emulation
- A cycle-accurate PPU emulation
- A cycle-accurate APU emulation (even though it does not produce any sound)
- Few basic NES mappers (more to come)
The Python bindings allow to interact easily with one or several NES emulators at the same time, ideal for machine learning application.
## Installation
cynes can be installed using pip :
```
pip install cynes
```
It can also be built from source using [cython](https://github.com/cython/cython).
```
python setup.py build
```
## How to use
A cynes NES emulator can be created by instanticiating a new NES object. The following code is the minimal code to run a ROM file.
```python
from cynes import NES
# We initialize a new emulator by specifying the ROM file used
nes = NES("smb.nes")
# While the emulator should not be close, we can continue the emulation
while not nes.should_close():
# The step method run the emulation for a single frame
# It also returns the content of the frame buffer as a numpy array
frame = nes.step()
```
Multiple emulators can be created at once by instantiating several NES objects.
### Windowed / Headless modes
A cynes NES emulator can either be run in windowed or headless mode.
```python
from cynes import NESHeadless, NES
# We can create a NES emulator without a rendering window
nes_headless = NESHeadless("smb.nes")
# And with the rendering window
nes = NES("smb.nes")
```
While the rendering overhead is quite small, running in headless mode can improve the performances when the window is not needed. The content of the frame buffer can still be accessed in the same way as previously, using the `step` method.
### Controller
The state of the controller can be directly modified using the following syntax :
```python
from cynes import *
# Simple input
nes.controller = NES_INPUT_RIGHT
# Multiple button presses at once
nes.controller = NES_INPUT_RIGHT | NES_INPUT_A
# Chaining multiple button presses at once
nes.controller = NES_INPUT_START
nes.controller |= NES_INPUT_B
nes.controller |= NES_INPUT_SELECT
# Undefined behavior
nes.controller = NES_INPUT_RIGHT | NES_INPUT_LEFT
nes.controller = NES_INPUT_DOWN | NES_INPUT_UP
# Run the emulator with the specified controller state for 5 frames
nes.step(frames=5)
```
Note that the state of the controller is maintain even after the `step` method is called. This means that it has to be reset to 0 to release the buttons.
Two controllers can be used at the same time. The state of the second controller can be modified by updating the 8 most significant bits of the same variable.
```python
# P1 will press left and P2 will press the right button
nes.controller = NES_INPUT_LEFT | NES_INPUT_RIGHT << 8
```
### Key handlers
Key handlers are a simple way of associating custom actions to shortcuts. This feature is only present with the windowed mode. The key events (and their associated handlers) are fired when calling the `step` method.
```python
# Disable the default window controls
nes = NES("smb.nes", default_handlers=False)
# Custom key handlers can be defined using the register method
import sdl2
def kill():
nes.close()
nes.register(sdl2.SDL_SCANCODE_O, kill)
```
By default, the emulator comes with key handlers that map window keys to the controller buttons. The mapping is the following :
- the arrow keys for the D-pad
- the keys X and Z for the A and B buttons respectively
- the keys A and S for the SELECT and START buttons respectively
### Save states
The state of the emulator can be saved as a numpy array and later be restored.
```python
# The state of the emulator can be dump using the save method
save_state = nes.save()
# And restored using the load method
nes.load(save_state)
```
Memory modification should never be performed directly on a save state, as it is prone to memory corruption. Theses two methods can be quite slow, therefore, they should be called sparsely.
### Memory access
The memory of the emulator can be read from and written to using the following syntax :
```python
# The memory content can be accessed as if the emulator was an array
player_state = nes[0x000E]
# And can be written in a similar fashion
nes[0x075A] = 0x8
```
Note that only the CPU RAM `$0000 - $1FFFF` and the mapper RAM `$6000 - $7FFF` should be accessed. Trying to read / write a value to other addresses may desynchronize the components of the emulator, resulting in a undefined behavior.
### Closing
An emulator is automatically closed when the object is released by Python. In windowed mode, the `close` method can be use to close the window without having to wait for Python to release the object.
It can also be closed manualy using the `close` method.
```python
# In windowed mode, this can be use to close the window
nes.close()
# Deleting the emulator in windowed mode also closes the window
del nes
# The method should_close indicates whether or not the emulator function should be called
nes.close()
nes.should_close() # True
```
When the emulator is closed, but the object is not deleted yet, the `should_close` method will return True, indicating that calling any NES function will not work properly. This method can also return True in two other cases :
- When the CPU of the emulator is frozen. When the CPU hits a JAM instruction (illegal opcode), it is frozen until the emulator is reset. This should never happen, but memory corruptions can cause them, so be careful when accessing the NES memory.
- In windowed mode, when the window is closed or when the ESC key is pressed.
## License
This project is licensed under GPL-3.0
```plain
cynes - C/C++ NES emulator with Python bindings
Copyright (C) 2021 Combey Theo
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
```
%package -n python3-cynes
Summary: C/C++ NES emulator with Python bindings
Provides: python-cynes
BuildRequires: python3-devel
BuildRequires: python3-setuptools
BuildRequires: python3-pip
BuildRequires: python3-cffi
BuildRequires: gcc
BuildRequires: gdb
%description -n python3-cynes
# cynes - C/C++ NES emulator with Python bindings
cynes is a lightweight multiplatform NES emulator providing a simple Python interface. The core of the emulation is based on the very complete documentation provided by the [Nesdev Wiki](https://wiki.nesdev.com/w/index.php?title=NES_reference_guide). The current implementation consists of
- A cycle-accurate CPU emulation
- A cycle-accurate PPU emulation
- A cycle-accurate APU emulation (even though it does not produce any sound)
- Few basic NES mappers (more to come)
The Python bindings allow to interact easily with one or several NES emulators at the same time, ideal for machine learning application.
## Installation
cynes can be installed using pip :
```
pip install cynes
```
It can also be built from source using [cython](https://github.com/cython/cython).
```
python setup.py build
```
## How to use
A cynes NES emulator can be created by instanticiating a new NES object. The following code is the minimal code to run a ROM file.
```python
from cynes import NES
# We initialize a new emulator by specifying the ROM file used
nes = NES("smb.nes")
# While the emulator should not be close, we can continue the emulation
while not nes.should_close():
# The step method run the emulation for a single frame
# It also returns the content of the frame buffer as a numpy array
frame = nes.step()
```
Multiple emulators can be created at once by instantiating several NES objects.
### Windowed / Headless modes
A cynes NES emulator can either be run in windowed or headless mode.
```python
from cynes import NESHeadless, NES
# We can create a NES emulator without a rendering window
nes_headless = NESHeadless("smb.nes")
# And with the rendering window
nes = NES("smb.nes")
```
While the rendering overhead is quite small, running in headless mode can improve the performances when the window is not needed. The content of the frame buffer can still be accessed in the same way as previously, using the `step` method.
### Controller
The state of the controller can be directly modified using the following syntax :
```python
from cynes import *
# Simple input
nes.controller = NES_INPUT_RIGHT
# Multiple button presses at once
nes.controller = NES_INPUT_RIGHT | NES_INPUT_A
# Chaining multiple button presses at once
nes.controller = NES_INPUT_START
nes.controller |= NES_INPUT_B
nes.controller |= NES_INPUT_SELECT
# Undefined behavior
nes.controller = NES_INPUT_RIGHT | NES_INPUT_LEFT
nes.controller = NES_INPUT_DOWN | NES_INPUT_UP
# Run the emulator with the specified controller state for 5 frames
nes.step(frames=5)
```
Note that the state of the controller is maintain even after the `step` method is called. This means that it has to be reset to 0 to release the buttons.
Two controllers can be used at the same time. The state of the second controller can be modified by updating the 8 most significant bits of the same variable.
```python
# P1 will press left and P2 will press the right button
nes.controller = NES_INPUT_LEFT | NES_INPUT_RIGHT << 8
```
### Key handlers
Key handlers are a simple way of associating custom actions to shortcuts. This feature is only present with the windowed mode. The key events (and their associated handlers) are fired when calling the `step` method.
```python
# Disable the default window controls
nes = NES("smb.nes", default_handlers=False)
# Custom key handlers can be defined using the register method
import sdl2
def kill():
nes.close()
nes.register(sdl2.SDL_SCANCODE_O, kill)
```
By default, the emulator comes with key handlers that map window keys to the controller buttons. The mapping is the following :
- the arrow keys for the D-pad
- the keys X and Z for the A and B buttons respectively
- the keys A and S for the SELECT and START buttons respectively
### Save states
The state of the emulator can be saved as a numpy array and later be restored.
```python
# The state of the emulator can be dump using the save method
save_state = nes.save()
# And restored using the load method
nes.load(save_state)
```
Memory modification should never be performed directly on a save state, as it is prone to memory corruption. Theses two methods can be quite slow, therefore, they should be called sparsely.
### Memory access
The memory of the emulator can be read from and written to using the following syntax :
```python
# The memory content can be accessed as if the emulator was an array
player_state = nes[0x000E]
# And can be written in a similar fashion
nes[0x075A] = 0x8
```
Note that only the CPU RAM `$0000 - $1FFFF` and the mapper RAM `$6000 - $7FFF` should be accessed. Trying to read / write a value to other addresses may desynchronize the components of the emulator, resulting in a undefined behavior.
### Closing
An emulator is automatically closed when the object is released by Python. In windowed mode, the `close` method can be use to close the window without having to wait for Python to release the object.
It can also be closed manualy using the `close` method.
```python
# In windowed mode, this can be use to close the window
nes.close()
# Deleting the emulator in windowed mode also closes the window
del nes
# The method should_close indicates whether or not the emulator function should be called
nes.close()
nes.should_close() # True
```
When the emulator is closed, but the object is not deleted yet, the `should_close` method will return True, indicating that calling any NES function will not work properly. This method can also return True in two other cases :
- When the CPU of the emulator is frozen. When the CPU hits a JAM instruction (illegal opcode), it is frozen until the emulator is reset. This should never happen, but memory corruptions can cause them, so be careful when accessing the NES memory.
- In windowed mode, when the window is closed or when the ESC key is pressed.
## License
This project is licensed under GPL-3.0
```plain
cynes - C/C++ NES emulator with Python bindings
Copyright (C) 2021 Combey Theo
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
```
%package help
Summary: Development documents and examples for cynes
Provides: python3-cynes-doc
%description help
# cynes - C/C++ NES emulator with Python bindings
cynes is a lightweight multiplatform NES emulator providing a simple Python interface. The core of the emulation is based on the very complete documentation provided by the [Nesdev Wiki](https://wiki.nesdev.com/w/index.php?title=NES_reference_guide). The current implementation consists of
- A cycle-accurate CPU emulation
- A cycle-accurate PPU emulation
- A cycle-accurate APU emulation (even though it does not produce any sound)
- Few basic NES mappers (more to come)
The Python bindings allow to interact easily with one or several NES emulators at the same time, ideal for machine learning application.
## Installation
cynes can be installed using pip :
```
pip install cynes
```
It can also be built from source using [cython](https://github.com/cython/cython).
```
python setup.py build
```
## How to use
A cynes NES emulator can be created by instanticiating a new NES object. The following code is the minimal code to run a ROM file.
```python
from cynes import NES
# We initialize a new emulator by specifying the ROM file used
nes = NES("smb.nes")
# While the emulator should not be close, we can continue the emulation
while not nes.should_close():
# The step method run the emulation for a single frame
# It also returns the content of the frame buffer as a numpy array
frame = nes.step()
```
Multiple emulators can be created at once by instantiating several NES objects.
### Windowed / Headless modes
A cynes NES emulator can either be run in windowed or headless mode.
```python
from cynes import NESHeadless, NES
# We can create a NES emulator without a rendering window
nes_headless = NESHeadless("smb.nes")
# And with the rendering window
nes = NES("smb.nes")
```
While the rendering overhead is quite small, running in headless mode can improve the performances when the window is not needed. The content of the frame buffer can still be accessed in the same way as previously, using the `step` method.
### Controller
The state of the controller can be directly modified using the following syntax :
```python
from cynes import *
# Simple input
nes.controller = NES_INPUT_RIGHT
# Multiple button presses at once
nes.controller = NES_INPUT_RIGHT | NES_INPUT_A
# Chaining multiple button presses at once
nes.controller = NES_INPUT_START
nes.controller |= NES_INPUT_B
nes.controller |= NES_INPUT_SELECT
# Undefined behavior
nes.controller = NES_INPUT_RIGHT | NES_INPUT_LEFT
nes.controller = NES_INPUT_DOWN | NES_INPUT_UP
# Run the emulator with the specified controller state for 5 frames
nes.step(frames=5)
```
Note that the state of the controller is maintain even after the `step` method is called. This means that it has to be reset to 0 to release the buttons.
Two controllers can be used at the same time. The state of the second controller can be modified by updating the 8 most significant bits of the same variable.
```python
# P1 will press left and P2 will press the right button
nes.controller = NES_INPUT_LEFT | NES_INPUT_RIGHT << 8
```
### Key handlers
Key handlers are a simple way of associating custom actions to shortcuts. This feature is only present with the windowed mode. The key events (and their associated handlers) are fired when calling the `step` method.
```python
# Disable the default window controls
nes = NES("smb.nes", default_handlers=False)
# Custom key handlers can be defined using the register method
import sdl2
def kill():
nes.close()
nes.register(sdl2.SDL_SCANCODE_O, kill)
```
By default, the emulator comes with key handlers that map window keys to the controller buttons. The mapping is the following :
- the arrow keys for the D-pad
- the keys X and Z for the A and B buttons respectively
- the keys A and S for the SELECT and START buttons respectively
### Save states
The state of the emulator can be saved as a numpy array and later be restored.
```python
# The state of the emulator can be dump using the save method
save_state = nes.save()
# And restored using the load method
nes.load(save_state)
```
Memory modification should never be performed directly on a save state, as it is prone to memory corruption. Theses two methods can be quite slow, therefore, they should be called sparsely.
### Memory access
The memory of the emulator can be read from and written to using the following syntax :
```python
# The memory content can be accessed as if the emulator was an array
player_state = nes[0x000E]
# And can be written in a similar fashion
nes[0x075A] = 0x8
```
Note that only the CPU RAM `$0000 - $1FFFF` and the mapper RAM `$6000 - $7FFF` should be accessed. Trying to read / write a value to other addresses may desynchronize the components of the emulator, resulting in a undefined behavior.
### Closing
An emulator is automatically closed when the object is released by Python. In windowed mode, the `close` method can be use to close the window without having to wait for Python to release the object.
It can also be closed manualy using the `close` method.
```python
# In windowed mode, this can be use to close the window
nes.close()
# Deleting the emulator in windowed mode also closes the window
del nes
# The method should_close indicates whether or not the emulator function should be called
nes.close()
nes.should_close() # True
```
When the emulator is closed, but the object is not deleted yet, the `should_close` method will return True, indicating that calling any NES function will not work properly. This method can also return True in two other cases :
- When the CPU of the emulator is frozen. When the CPU hits a JAM instruction (illegal opcode), it is frozen until the emulator is reset. This should never happen, but memory corruptions can cause them, so be careful when accessing the NES memory.
- In windowed mode, when the window is closed or when the ESC key is pressed.
## License
This project is licensed under GPL-3.0
```plain
cynes - C/C++ NES emulator with Python bindings
Copyright (C) 2021 Combey Theo
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
```
%prep
%autosetup -n cynes-0.0.3
%build
%py3_build
%install
%py3_install
install -d -m755 %{buildroot}/%{_pkgdocdir}
if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi
if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi
if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi
if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi
pushd %{buildroot}
if [ -d usr/lib ]; then
find usr/lib -type f -printf "/%h/%f\n" >> filelist.lst
fi
if [ -d usr/lib64 ]; then
find usr/lib64 -type f -printf "/%h/%f\n" >> filelist.lst
fi
if [ -d usr/bin ]; then
find usr/bin -type f -printf "/%h/%f\n" >> filelist.lst
fi
if [ -d usr/sbin ]; then
find usr/sbin -type f -printf "/%h/%f\n" >> filelist.lst
fi
touch doclist.lst
if [ -d usr/share/man ]; then
find usr/share/man -type f -printf "/%h/%f.gz\n" >> doclist.lst
fi
popd
mv %{buildroot}/filelist.lst .
mv %{buildroot}/doclist.lst .
%files -n python3-cynes -f filelist.lst
%dir %{python3_sitearch}/*
%files help -f doclist.lst
%{_docdir}/*
%changelog
* Mon May 15 2023 Python_Bot <Python_Bot@openeuler.org> - 0.0.3-1
- Package Spec generated
|