Skip to content

Commit 9b46c56

Browse files
committedApr 28, 2019
first commit
0 parents  commit 9b46c56

24 files changed

+3488
-0
lines changed
 

‎.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.pyc

‎README.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Basic GB emulator based of https://github.com/trekawek/coffee-gb (used as reference) and http://marc.rawer.de/Gameboy/Docs/GBCPUman.pdf
2+
3+
[http://blog.rekawek.eu/2017/02/09/coffee-gb/](http://blog.rekawek.eu/2017/02/09/coffee-gb/)
4+
5+
Uses
6+
- sdl2 and sdl2mixer
7+
- pysdl2
8+
- `sudo apt-get install -y libsdl2-mixer-2.0-0`
9+
- use `pypy` sicne python c is slow

‎cartridge.py

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
2+
3+
4+
class cartridgeTypes:
5+
types = {
6+
"ROM ": 0x00,
7+
"ROM_MBC1 ": 0x01,
8+
"ROM_MBC1_RAM ": 0x02,
9+
"ROM_MBC1_RAM_BATTERY ": 0x03,
10+
"ROM_MBC2 ": 0x05,
11+
"ROM_MBC2_BATTERY ": 0x06,
12+
"ROM_RAM ": 0x08,
13+
"ROM_RAM_BATTERY ": 0x09,
14+
"ROM_MMM01 ": 0x0b,
15+
"ROM_MMM01_SRAM ": 0x0c,
16+
"ROM_MMM01_SRAM_BATTERY ": 0x0d,
17+
"ROM_MBC3_TIMER_BATTERY ": 0x0f,
18+
"ROM_MBC3_TIMER_RAM_BATTERY ": 0x10,
19+
"ROM_MBC3 ": 0x11,
20+
"ROM_MBC3_RAM ": 0x12,
21+
"ROM_MBC3_RAM_BATTERY ": 0x13,
22+
"ROM_MBC5 ": 0x19,
23+
"ROM_MBC5_RAM ": 0x1a,
24+
"ROM_MBC5_RAM_BATTERY ": 0x01b,
25+
"ROM_MBC5_RUMBLE ": 0x1c,
26+
"ROM_MBC5_RUMBLE_SRAM ": 0x1d,
27+
"ROM_MBC5_RUMBLE_SRAM_BATTERY ": 0x1e
28+
}
29+
gotID = None
30+
def getById(self, Typeid):
31+
self.gotID = self.types.keys()[self.types.values().index(Typeid)]
32+
return self.gotID
33+
34+
def isType(self, typeName):
35+
return typeName in self.types.keys()[self.types.values().index(Typeid)]
36+
37+
def getRomBanks(self, romid):
38+
if(romid == 0):
39+
return 2
40+
elif(romid == 1):
41+
return 4
42+
elif(romid == 2):
43+
return 8
44+
elif(romid == 3):
45+
return 16
46+
elif(romid == 4):
47+
return 32
48+
elif(romid == 5):
49+
return 64
50+
elif(romid == 6):
51+
return 128
52+
elif(romid == 0x52):
53+
return 72
54+
elif(romid == 0x53):
55+
return 80
56+
elif(romid == 0x54):
57+
return 96
58+
else:
59+
raise Exception("Bug . defiently")
60+
61+
def getRamBanks(self, ramid):
62+
if(ramid == 0):
63+
return 0
64+
elif(ramid == 1):
65+
return 1
66+
elif(ramid == 2):
67+
return 1
68+
elif(ramid == 3):
69+
return 4
70+
elif(ramid == 4):
71+
return 16
72+
else:
73+
raise Exception("Bug defiently")
74+
75+
76+
77+
78+
79+
80+

‎controllers.py

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
2+
3+
4+
5+
class buttons:
6+
avaible = {
7+
"RIGHT":(0x01, 0x10),
8+
"LEFT" : (0x02, 0x10),
9+
"UP" : (0x04, 0x10),
10+
"DOWN" : (0x08, 0x10),
11+
"A" : (0x01, 0x20),
12+
"B" : (0x02, 0x20),
13+
"SELECT" : (0x04, 0x20),
14+
"START" : (0x08, 0x20)
15+
}
16+
17+
18+
line = 0
19+
mask = 0
20+
21+
22+
def __init__(self):
23+
pass
24+
25+
def getMask(self):
26+
return self.mask
27+
28+
def getLine(self):
29+
return self.line
30+
31+
class joycontrollers:
32+
def __init__(self, interruptManager):
33+
self.interruptManager = interruptManager
34+
self.activeButtons = {}
35+
self.p1 = 0
36+
37+
self.buttonids = buttons()
38+
39+
def buttonPress(self, buttonID):
40+
self.interruptManager.requestInterrupt(self.interruptManager.get("P10_13"))
41+
self.activeButtons[buttonID] = self.buttonids.avaible[buttonID]
42+
43+
def buttonUnPress(self, buttonID):
44+
self.activeButtons.pop(buttonID, None)
45+
46+
47+
48+
def setByte(self, address, value):
49+
self.p1 = value & 0b00110000;
50+
51+
def getByte(self, address):
52+
result = self.p1 | 0b00001111;
53+
for buttonid, buttonvalue in self.activeButtons.items():
54+
if ((buttonvalue[1] & self.p1) == 0):
55+
result &= 0xff & ~buttonvalue[0]
56+
#print(result)
57+
#print("happy")
58+
return result
59+
60+
61+
62+
63+
64+
65+

‎counter.py

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2+
3+
class Counter:
4+
frequency = 0
5+
counter = 0
6+
clocks = 0
7+
8+
def __init__(self, frequency):
9+
self.frequency = frequency
10+
11+
def tick(self):
12+
self.clocks += 1
13+
if (self.clocks == 4194304 / self.frequency):
14+
self.clocks = 0
15+
self.counter = (self.counter + 1) & 0xff
16+
return True
17+
else:
18+
return False
19+
20+
def getCounter(self):
21+
return self.counter
22+
23+
def resetCounter(self):
24+
self.counter = 0
25+
26+
def setCounter(self, counter):
27+
self.counter = counter
28+
29+

0 commit comments

Comments
 (0)
Please sign in to comment.