-
Jul 29th, 2013, 01:17 AM
#1
Lets make a Sega Genesis Emulator
I know I posted a topic about a Sega Genesis emulator before, but havent got a single response about anything on it. Almost as must as Nightwalkers useful post. Heck noone chills in the Games and Graphics area no more like the good ol days of VBForums. Anyways I'm going really off topic here. Lets freaking make a Sega Genesis emulator shall we. Yes this will be a very humerous learning experience in the way I'm typing this.
Ah the language of choice. Well I would love to do C++ but then noone would want to even touch it. At least in VBForums. I would love to make history pulling it off using VB6, which to some people is a dead language but continues to be widely used. Literally, worldwide. But I dont feel like making a thread on debating which language is better. So how bout we try both VB6 and VB.Net as 2 separate programs and see how far we get. Shall we? At least then we can compare in performance. Afterall, who would love to see "Blast Processing" in VB?!! Probably mostly none of you all because youre too busy posting questions on Winsock and SQL programing, and chilling in the VB.Net, VB6 and Chit Chat areas
For those who dont know or remember, there was a huge game console war back in the late 80s and early 90s between Nintendo and Sega. Nintendo had the NES which was an 8 bit system, and Sega had the Genesis which was 16 bit. It was always about bits. Noone really knew what bits meant. I mean what are bits anyways? As long as the graphics and games looked good, thats all that it really meant. Nintendo had really great titles and so did Sega. And this competition led to better games. Then the Super Nintendo came out in 1991 which was also 16 bit. It had better graphics and sound, and was in steady competition with Sega. However the Sega genesis, although its graphics were shallow in comparison due to the lack of colors, had a faster processer than the Super NES. This is when Sega had a huge ad campaign attacking Nintendo with the phrase "Blast Processing." And it worked in some aspects! Along with the phrase Genesis does what Nintendon't.
Whoh I got really off topic. Lets build the emulator. Ok to build the emulator it all starts with the processor. The Sega Genesis uses a Motorola 68000. The chip consist of 64 pins. However the number of opcodes according to my research is not known per say just yet due to the number of combinations. But the closest I've come is this document:
http://emu-docs.org/CPU%2068k/68000inst.txt
A lot of the instructions looks as though it borrowed from the 6502 family. However if you really wanna get complicated, heres a binary version of it:
http://emudocs.org/CPU%2068k/68000obj.txt
I know I'm getting way ahead of myself here but thats where it starts. And I have source code to implement for the instructions thankfully...just not in VB yet. So lets begin coding. We are going to need a basic emulation loop going before we put in the CPU. Now bare in mind, this is just a foundation to work with. It doesnt work on its own yet. So create a new project and add a module:
vb Code:
Option Explicit
Public CPU_Paused As Boolean
Public CPU_Running As Boolean
Public Instruction(256) As Long 'Dont know how many instructions yet so keep it 256 for now
Public Cycles(256) As Long
Public Opcode As Long
Public PC As Long
Public Tick_Count As Long
Public Function ReadMemory(ByVal Address As Long) As Long
ReadMemory = 0
End Function
Public Sub Execute_68000()
If CPU_Paused = True Then
Do Until CPU_Paused = False And CPU_Running = True
DoEvents
Loop
End If
Opcode = ReadMemory(PC) ' Fetch Next Operation
PC = PC + 1
Tick_Count = Tick_Count + Cycles(Opcode)
Select Case Instruction(Opcode)
End Select
DoEvents
End Sub
vb.net Code:
Option Explicit On
Option Strict On
Public Module mod68000
Public CPU_Paused As Boolean
Public CPU_Running As Boolean
Public Instruction(256) As Integer 'Dont know how many instructions yet so keep it 256 for now
Public Cycles(256) As Integer ''Dont know how many instructions yet so keep it 256 for now
Public Opcode As Integer
Public PC As Integer
Public Tick_Count As Integer
Public Function ReadMemory(ByVal Address As Integer) As Integer
Return 0
End Function
Public Sub Execute_68000()
If CPU_Paused = True Then
Do Until CPU_Paused = False And CPU_Running = True
Application.DoEvents()
Loop
End If
Opcode = ReadMemory(PC) ' Fetch Next Operation
PC = PC + 1
Tick_Count = Tick_Count + Cycles(Opcode)
Select Case Instruction(Opcode)
End Select
Application.DoEvents()
End Sub
End Module
Thats all for now. Tomorrow we will actually start building the CPU from scratch one opcode at a time. And there are a lot! Have a good one
-
Jul 29th, 2013, 02:19 AM
#2
Re: Lets make a Sega Genesis Emulator
Does one need to understand every detail of how a processor works to emulate it or are there things one can pass on when dealing with emulation ?
-
Jul 29th, 2013, 08:59 AM
#3
Re: Lets make a Sega Genesis Emulator
The only thing you will need to know about the processor are the Opcodes and Address Modes. Once you understand what each instruction does, then you can code it. Shortly today when I have time, I'm gonna go about them
-
Jul 30th, 2013, 06:22 AM
#4
Re: Lets make a Sega Genesis Emulator
Wow after investigating 2 open source emulators written in C, one being a famous one called DGen, I noticed they both had nearly identical code with the 68k, only it was a lot more complex and not written like a simple NES emulator at all. It literally is working with binary numbers for the instruction set. But I don't want to just guess that it really is. I want to know. So were going to have to dig deeper. A simple google search of Sega Genesis Documentation led me to this page http://www.genny4ever.net/index.php?page=docs#md. So I'm gonna read up on the docs and quite possibly dig for more open source emulators to get a general idea on the 68k processor. The more we learn about it, the more we should be able to emulate it. Once we have a foundation to work with, then we can jump into things such as loading a game from file, reading and writing from memory, the PPU, APU, etc.
Plus this PDF doc should help as well http://www.freescale.com/files/archi.../M68000PRM.pdf
-
Jul 30th, 2013, 07:45 AM
#5
Re: Lets make a Sega Genesis Emulator
After reading that PDF, I gathered more information than anything. So what I'm gonna do is list the instructions. Then later we will logically program the instructions one by one as long as the instruction is associated with the CPU the Genesis uses. Bare in mind not all the instructions go with every M68000 processor as there are multiple versions of the M68000 family such as the MC68010, MC68020, MC68030, MC68040, as well as a CPU32 version. Each have similar instructions but have additional instructions the other processors don't have. What I want to know exactly is which processor does the model 1, 2, and 3 of the Sega Genesis uses, so I'm not wasting time coding on instructions that will never compute. For now I'm gonna list what I believe to be nearly all the instructions the entire M68000 family uses. So here is a list I gathered so far from that PDF found here: http://www.freescale.com/files/archi.../M68000PRM.pdf
1. ABCD - Add Decimal with Extend
2. ADD - Add
3. ADDA - Add Address
4. ADDI - Add Immediate
5. ADDQ - Add Quick
6. ADDX - Add Extended
7. AND - And Logical
8. ANDI - And Immediate
9. ANDI to CCR - CCR AND Immediate
10. ASL - Arithmetic Left Shift
11. ASR - Arithmetic Right Shift
12. Bcc - Branch Conditionally
13. BCHG - Test a Bit and Change
14. BCLR - Test a Bit and Clear
15. BFCHG - Test Bit Field and Change
16. BFCLR - Test Bit Field and Clear
17. BFEXTS - Extract Bit Field Signed
18. BFEXTU - Extract Bit Field Unsigned
19. BFFFO - Find First One in Bit Field
20. BFINS - Insert Bit Field
21. BFSET - Test Bit Field and Set
22. BFTST - Test Bit Field
23. BKPT - Breakpoint
24. BRA - Branch Always
25. BSET - Test Bit and Set
26. BSR - Branch to Subroutine
27. BTST - Test a Bit
28. CALLM - Call Module
29. CAS - Compare and Swap with Operand
30. CAS2 - Compare and Swap with Operand
31. CHK - Check Register Against Bounds
32. CHK2 - Check Register Against Bounds
33. CLR - Clear an Operand
34. CMP - Compare
35. CMPA - Compare Address
36. CMPI - Compare Immediate
37. CMPM - Compare Memory
38. CMP2 - Compare Register Against Bounds
39. cpBcc - Branch on Coprocessor Condition
40. cpDBcc - Test Coprocessor Condition Decrement and Branch
41. cpGEN - Coprocessor General Function
42. cpScc - Set on Coprocessor Condition
43. cpTRAPcc - Trap on Coprocessor Condition
44. DBcc - Test Condition, Decrement, and Branch
45. DIVS - Signed Divide
46. DIVSL - Signed Divide
47. DIVU - Unsigned Divide
48. DIVUL - Unsigned Divide
49. EOR - Exclusive Or Logical
50. EORI - Exclusive Or Immediate
51. EORI to CCR - Exclusive Or Immediate to Condition Code
52. EXG - Exchange Registers
53. EXT - Sign Extend
54. EXTB - Sign Extend
55. ILLEGAL - Take Illegal Instruction Trap
56. JMP - Jump
57. JSR - Jump to Subroutine
58. LEA - Load Effective Address
59. LINK - Link and Allocate
60. LSL - Logical Shift Left
61. LSR - Logical Shift Right
62. MOVE - Move Data from Source to Destination
63. MOVEA - Move Address
64. MOVE from CCR - Move From Condition Code Register
65. MOVE to CCR - Move to Condition Code Register
66. MOVE from SR - Move From Status Register
67. MOVE16 - Move 16 Byte Block
68. MOVEM - Move Multiple Registers
69. MOVEP - Move Peripheral Data
70. MOVEQ - Move Quick
71. MULS - Signed Multiply
72. MULU - Unsigned Multiply
73. NBCD - Negate Decimal with Extend
74. NEG - Negate
75. NEGX - Negate With Extend
76. NOP - No Operation
77. NOT - Logical Complement
78. OR - Inclusive Or Logical
79. ORI - Inclusive Or (Immediate)
80. ORI to CCR - Inclusive Or Immediate to Condition Codes
81. PACK - Pack
82. PEA - Push Effective Address
83. ROL - Rotate (Without Extend) Left
84. ROR - Rotate (Without Extend) Right
85. ROXL - Rotate (With Extend) Left
86. ROXR - Rotate (With Extend) Right
87. RTD - Return and Deallocate
88. RTM - Return From Module
89. RTR - Return and Restore Condition Codes
90. RTS - Return from Subroutine
91. SBCD - Subtract Decimal with Extend
92. Scc - Set According to Condition
93. SUB - Subtract
94. SUBA - Subtract Address
95. SUBI - Subtract Immediate
96. SUBQ - Subtract Quick
97. SUBX - Subtract with Extend
98. SWAP - Swap Register Halves
99. TAS - Test and Set an Operand
100. TRAP - Trap
101. TRAPcc - Trap on Condition
102. TRAPV - Trap on Overflow
103. TST - Test an Operand
104. UNLK - Unlink
105. UNPK - Unpack BCD
Directly Supported Floating Point Instructions:
----------------------------------
FABS - Floating-Point Absolute Value
FADD - Floating-Point Add
FBcc - Floating-Point Branch Conditionally
FCMP - Floating-Point Compare
FDBcc - Floating-Point Test Condition, Decrement, and Branch
FDIV - Floating-Point Divide
FMOVE - Move Floating-Point Data Register
FMOVE - Move Floating-Point System Control Register
FMOVEM - Move Multiple Floating-Point System Data Register
FMOVEM - Move Multiple Floating-Point Control Data Register
FMUL - Floating-Point Multiply
FNEG - Floating-Point Negate
FNOP - No Operation
FRESTORE* - Restore Internal Floating-Point State*
FSAVE* - Save Internal Floating-Point State*
FScc - Set According to Floating-Point Condition
FSORT - Floating-Point Square Root
FSUB - Floating-Point Subtract
FSGLDIV - Floating-Point Single-Precision Divide
FSFLMUL - Floating-Point Single-Precision Multiply
FTRAPcc - Trap on Floating-Point Condition
FTST - Test Floating-Point Operand
Indirectly Supported Floating Point Instructions:
-------------------------------------------------
FACOS - Floating-Point Arc Cosine
FASIN - Floating-Point Arc Sine
FATAN - Floating-Point Arc Tangent
FATANH - Floating-Point Hyperbolic Arc Tangent
FCOS - Floating-Point Cosine
FCOSH - Floating-Point Hyperbolic Cosine
FETOX - Floating-Point e^x
FETOXM1 - Floating-Point e^x– 1
FGETEXP - Floating-Point Get Exponent
FGETMAN - Floating-Point Get Mantissa
FINT - Floating-Point Integer Part
FINTRZ - Floating-Point Integer Part, Round-to- Zero
FLOG10 - Floating-Point Log10
FLOG2 - Floating-Point Log2
FLOGN - Floating-Point Loge
FLOGNP1 - Floating-Point Log e^(x + 1)
FMOD - Floating-Point Modulo Remainder
FMOVECR - Floating-Point Move Constant ROM
FREM - Floating-Point IEEE Remainder
FSCALE - Floating-Point Scale Exponent
FSIN - Floating-Point Sine
FSINCOS - Floating-Point Simultaneous Sine and Cosine
FSINH - Floating-Point Hyperbolic Sine
FTAN - Floating-Point Tangent
FTANH - Floating-Point Hyperbolic Tangent
FTENTOX - Floating-Point 10^x
FTWOTOX - Floating-Point 2^x
-
Jul 30th, 2013, 09:17 AM
#6
Re: Lets make a Sega Genesis Emulator
I'm intrigued. What kinda timeline are you expecting for this. I mean how long would a project like this take to complete ?
-
Jul 30th, 2013, 10:25 AM
#7
Re: Lets make a Sega Genesis Emulator
Honestly since I never made a Sega Emulator before I dont know. But Im passionate about emulation and very curious of the results since noone had the guts to even attempt it in VB. I have both the model 1 and 2 Sega Genesis at my house. So I am gonna take them apart to see what M68000 processor they use. Once I am satisfied, I can eliminate most of the instructions that wont be used.
-
Jul 31st, 2013, 12:55 AM
#8
Re: Lets make a Sega Genesis Emulator
I'm going to have to compare these to the 2 C++ version of the Sega Genesis emulator I currently have and do some research but at least I have a foundation for the M68000 processor's Opcodes source code to work with...in C#
http://sega360.codeplex.com/SourceCo...anipulation.cs
I'm also gonna need a CCR (Condition Code Register) for the opcodes as well, which are these:
X - Extend: Set to the value of the C-bit for arithmetic operations; otherwise not affected or set to a specified result.
N - Negative: Set if the most significant bit of the result is set; otherwise clear.
Z - Zero: Set if the result equals zero; otherwise clear.
V - Overflow: Set if an arithmetic overflow occurs implying that the result cannot be represented in the operand size; otherwise clear.
C - Carry: Set if a carry out of the most significant bit of the operand occurs for an addition, or if a borrow occurs in a subtraction; otherwise clear.
-
Aug 1st, 2013, 11:49 AM
#9
-
Aug 1st, 2013, 12:30 PM
#10
Re: Lets make a Sega Genesis Emulator
Ok so I weeded out the opcode instructions that the Sega Genesis doesn't have. All these instructions are part of the 68000 family according to the PDF. And the floating point instructions are NOT part of the MC68000. In fact the directly supported floating point instructions are only supported in the MC6888X and MC68040, and the indirectly supported floating point instructions are only supported in the MC6888X and MC68040FPSW. With X being I'm guessing version number. Bottom line is they arent supported at all in the Sega Genesis, hence, wont be calculated in the emulator. So now here is the new list of instructions I gathered up:
1. ABCD - Add Decimal with Extend
2. ADD - Add
3. ADDA - Add Address
4. ADDI - Add Immediate
5. ADDQ - Add Quick
6. ADDX - Add Extended
7. AND - And Logical
8. ANDI - And Immediate
9. ANDI to CCR - CCR AND Immediate
10. ASL - Arithmetic Left Shift
11. ASR - Arithmetic Right Shift
12. Bcc - Branch Conditionally
13. BCHG - Test a Bit and Change
14. BCLR - Test a Bit and Clear
15. BRA - Branch Always
16. BSET - Test Bit and Set
17. BSR - Branch to Subroutine
18. BTST - Test a Bit
19. CHK - Check Register Against Bounds
20. CLR - Clear an Operand
21. CMP - Compare
22. CMPA - Compare Address
23. CMPI - Compare Immediate
24. CMPM - Compare Memory
25. DBcc - Test Condition, Decrement, and Branch
26. DIVS - Signed Divide
27. DIVSL - Signed Divide
28. DIVU - Unsigned Divide
29. DIVUL - Unsigned Divide
30. EOR - Exclusive Or Logical
31. EORI - Exclusive Or Immediate
32. EORI to CCR - Exclusive Or Immediate to Condition Code
33. EXG - Exchange Registers
34. EXT - Sign Extend
35. EXTB - Sign Extend
36. ILLEGAL - Take Illegal Instruction Trap
37. JMP - Jump
38. JSR - Jump to Subroutine
39. LEA - Load Effective Address
40. LINK - Link and Allocate
41. LSL - Logical Shift Left
42. LSR - Logical Shift Right
43. MOVE - Move Data from Source to Destination
44. MOVEA - Move Address
45. MOVE to CCR - Move to Condition Code Register
46. MOVE from SR - Move From Status Register
47. MOVEM - Move Multiple Registers
48. MOVEP - Move Peripheral Data
49. MOVEQ - Move Quick
50. MULS - Signed Multiply
51. MULU - Unsigned Multiply
52. NBCD - Negate Decimal with Extend
53. NEG - Negate
54. NEGX - Negate With Extend
55. NOP - No Operation
56. NOT - Logical Complement
57. OR - Inclusive Or Logical
58. ORI - Inclusive Or (Immediate)
59. ORI to CCR - Inclusive Or Immediate to Condition Codes
60. PEA - Push Effective Address
61. ROL - Rotate (Without Extend) Left
62. ROR - Rotate (Without Extend) Right
63. ROXL - Rotate (With Extend) Left
64. ROXR - Rotate (With Extend) Right
65. RTR - Return and Restore Condition Codes
66. RTS - Return from Subroutine
67. SBCD - Subtract Decimal with Extend
68. Scc - Set According to Condition
69. SUB - Subtract
70. SUBA - Subtract Address
71. SUBI - Subtract Immediate
72. SUBQ - Subtract Quick
73. SUBX - Subtract with Extend
74. SWAP - Swap Register Halves
75. TAS - Test and Set an Operand
76. TRAP - Trap
77. TRAPV - Trap on Overflow
78. TST - Test an Operand
79. UNLK - Unlink
We narrowed it down to just 79 opcode instructions. You must bare in mind I'm taking all the information I'm gathering online and from other emulators with a grain of salt. If I see consistancy with any information, I'm gonna say its safe to assume its correct. Due to the fact that the PDF is the official Motorola 68000 chip documentation, I think I did a pretty good job. And just to see if I am truely right when I did narrow it down, there are a list of opcodes on another site which is here: http://emu-docs.org/CPU%2068k/68000inst.txt
-
Aug 1st, 2013, 08:39 PM
#11
Re: Lets make a Sega Genesis Emulator
I made a very simple ui in vb.net today, and writted the code to read the rom header.
I found the "secret" sega document here:
http://emu-docs.org/Genesis/sega2f.htm
I also managed to download de generator source code (an old sega genesis emulator for linux/dos). Maybe we can use something from the sources.
generator-0.15.zip
The interesting thing is that there is a vb.net sdk for windows phone, maybe we can even port the emulator for windows phone when mature.
This weekend I'll see if I look at the CPU.
-
Aug 1st, 2013, 08:59 PM
#12
Re: Lets make a Sega Genesis Emulator
Originally Posted by omundodogabriel
Wow, I barely understood anything in that doc. It would probably take a year of consistent research and study for that doc to actually make sense to me.
-
Aug 1st, 2013, 09:31 PM
#13
Re: Lets make a Sega Genesis Emulator
Nah its no different than how the Nintendo emulator was. Emulate the Opcode instructions, Read/Write from the Memory map only in this case its 32 bit so there are 16777215 addresses (or FFFFFF, see table)
and last but not least emulate the video and sound hardware. Its not rocket science. It just takes mad common sense skills
[EDIT] To Omundodogabriel: I found a good link that shows source code to the opcode instructions along with the CCR registers to each of them just to serve as a basis http://sega360.codeplex.com/SourceCo...anipulation.cs
Last edited by Jacob Roman; Aug 1st, 2013 at 09:46 PM.
-
Aug 2nd, 2013, 12:44 AM
#14
Re: Lets make a Sega Genesis Emulator
Since in the other emulators im not exactly seeing the ABCD instruction (probably because it was sort of embeded into the ADD instruction itself I'm assuming...at least in one of the emulators) we are going to skip that and focus on ADD. So according to the Motorola 68000 PDF documentation:
Code:
ADD
(M68000 Family)
Operation: Source + Destination→Destination
Assembler: ADD < ea > ,Dn
Syntax: ADD Dn, < ea >
Attributes: Size = (Byte, Word, Long)
Description: Adds the source operand to the destination operand using binary addition and stores the result in the destination location. The size of the operation may be specified as byte, word, or long. The mode of the instruction indicates which operand is the source and which is the destination, as well as the operand size.
Condition Codes:
X — Set the same as the carry bit.
N — Set if the result is negative; cleared otherwise.
Z — Set if the result is zero; cleared otherwise.
V — Set if an overflow is generated; cleared otherwise.
C — Set if a carry is generated; cleared otherwise.
Instruction Format:
X *
N *
Z *
V *
C *
|15|14|13|12|11|10|09|08|07|06|05|04|03||02|01|00|
| 1 | 1 | 0| 1 |REGISTER|OPMODE| MODE | REGISTER |
There are also multiple data types used for ADD such as Byte (8 bit), Short (16 Bit), as well as Integer (32 bit). 64 bit instructions are not supported. And according to one emulators I examined, there are 2 different versions of each. One version having condition code registers updated and the other not having condition code registers updated. For example, here is the C# version:
C# Code:
#region Add Helper Functions private sbyte Add(sbyte a, sbyte b, bool updateConditions, bool useX) { int result = useX ? (int)a + (int)b + (this.X ? 1 : 0) : (int)a + (int)b; if (updateConditions) { this.C = this.X = (result & 0x100) > 0; this.V = result > sbyte.MaxValue || result < sbyte.MinValue; this.N = result < 0; if (!useX) { this.Z = result == 0; } } return (sbyte)result; } private short Add(short a, short b, bool updateConditions, bool useX) { int result = useX ? (int)a + (int)b + (this.X ? 1 : 0) : (int)a + (int)b; if (updateConditions) { this.C = this.X = (result & 0x10000) > 0; this.V = result > short.MaxValue || result < short.MinValue; this.N = result < 0; if (!useX) { this.Z = result == 0; } } return (short)result; } private int Add(int a, int b, bool updateConditions, bool useX) { long result = useX ? (long)a + (long)b + (this.X ? 1 : 0) : (long)a + (long)b; if (updateConditions) { this.C = this.X = (result & 0x100000000) > 0; this.V = result > int.MaxValue || result < int.MinValue; this.N = result < 0; if (!useX) { this.Z = result == 0; } } return (int)result; } #endregion Add Helper Functions
The C++ version unfortunately had waaaay too many versions of ADD and I believe was overkill and complex for no reason IMO. I think the main difference was the Program Counter (PC) and thats about it but I will need to examine the code more closely. So this will be the primary focus before we translate it to VB.
-
Aug 2nd, 2013, 03:08 PM
#15
Re: Lets make a Sega Genesis Emulator
I found a simple and good doc about 68k opcodes: http://goldencrystal.free.fr/M68kOpcodes.pdf
NOTE: The hex values of each opcode are represented in binary.
All 68k instructions with descriptions can be found here: http://68k.hax.com/
I wrote the Memory Read/Write functions and CPU Reset.
VBnet Code:
Module MMU Public Memory(&HFFFFFF) As Byte '16 MB Ram #Region "Read Memory" Public Function ReadMemory8(Address As Integer) As Byte 'B Return Memory(Address) End Function Public Function ReadMemory16(Address As Integer) As Integer 'W Return Memory(Address + 1) + _ (Memory(Address) * &H100) End Function Public Function ReadMemory32(Address As Integer) As Long 'L Return Memory(Address + 3) + _ (Memory(Address + 2) * &H100) + _ (Memory(Address + 1) * &H10000) + _ (Memory(Address) * &H1000000) End Function #End Region #Region "Write Memory" Public Sub WriteMemory8(Address As Integer, Value As Byte) 'B Memory(Address) = Value End Sub Public Sub WriteMemory16(Address As Integer, Value As Integer) 'W Memory(Address) = ((Value And &HFF00) / &H100) And &HFF Memory(Address + 1) = (Value And &HFF) And &HFF End Sub Public Sub WriteMemory32(Address As Integer, Value As Long) 'L Memory(Address) = ((Value And &HFF000000) / &H1000000) And &HFF Memory(Address + 1) = ((Value And &HFF0000) / &H10000) And &HFF Memory(Address + 2) = ((Value And &HFF00) / &H100) And &HFF Memory(Address + 3) = (Value And &HFF) And &HFF End Sub #End Region End Module
CPU Reset
VBnet Code:
Module M68k Dim PC As Long Dim Regs(15) As Long '32-bit D0-D7 and A0-A7 Regs Public Sub M68k_Reset() 'Reset Program Counter PC = ReadMemory32(&H4) 'Clear Registers For i As Integer = 0 To 15 Regs(i) = 0 Next MsgBox("Reset to $" & Hex(PC)) End Sub End Module
The next step is start writing the opcodes.
Last edited by omundodogabriel; Aug 2nd, 2013 at 03:25 PM.
-
Aug 6th, 2013, 12:38 PM
#16
Re: Lets make a Sega Genesis Emulator
Ive been away for awhile since Ive been playing a lot of World of Warcraft lately. Rather than talk about one opcode at a time which would be slow and sluggish, Im doing the whole 68000 module. Once its complete in both VB6 and VB.Net you will be able to upload the game ROM and see the opcodes in action. Just no video or sound yet. Thatll be the next step.
-
Aug 11th, 2013, 06:17 PM
#17
New Member
Re: Lets make a Sega Genesis Emulator
Joined the forum just for this project after seeing your NES emulator thread leading here. I'm olaf, the programmer of olafnes and Zega Alpha (two emulators written in VB6). I'd like to hop on this Genesis project.
-
Aug 11th, 2013, 06:18 PM
#18
New Member
Re: Lets make a Sega Genesis Emulator
Here's the current page for Zega Alpha. It's a continuation of vbSMS, a Sega Master System emulator that I spruced up.
http://www.nothackers.com/zegaalpha/
-
Aug 12th, 2013, 08:57 AM
#19
Re: Lets make a Sega Genesis Emulator
Welcome olaf! I saw your emulator olafnes some time ago, I was helping with jacob nes emulator, and researching more about basicnes when I found olafnes page on sourceforge. The basicnes 6502 emulation code was bad written, and had a lot of timing issues, wrong flags and messy code. I rewrote most of the code, based on virtuanes sources and docs from nesdev. Is a lot better now, just need some minor fixes. The wrong timing cause some strange glitches, like the map on battletoads intro, maniac mansion not scrolling correctly...
I VDP is similar to sega master system, then I think we can use the code vdp master system with some minor modifications.
Jacob, how it's going with the 68k CPU emulation? Need some help?
-
Aug 12th, 2013, 09:37 AM
#20
Member
Re: Lets make a Sega Genesis Emulator
Hey, this could be awesome!! I'd love to help. I've been wanting to make a Genesis emulator. I've got experience writing emulators. Mostly in C, but I did create a VB6 8086 PC emulator too. It's posted here: http://www.vbforums.com/showthread.p...6-PC-emulator! and the C version (way way better) is here http://sourceforge.net/projects/fake86
I've also written a completely working NES emulator in both C and FreeBASIC, as well as an Apple II emulator. I wrote all of the code in each of them, including the CPU stuff from scratch. So, I've emulated an 80186 (it has a few more instructions than the 8086) and a 6502. I can definitely help out. Here's a screenshot of my NES emu in action playing Mega Man 2:
Now let's do this, bitches! I really want to see a working Genesis emu in VB. Would be ridiculous! So where are we with this right now? Are you still on the m68k code? If you're stuck, I can help if you provide the current code.
Last edited by miker00lz; Aug 12th, 2013 at 10:15 AM.
-
Aug 12th, 2013, 06:16 PM
#21
New Member
Re: Lets make a Sega Genesis Emulator
Originally Posted by omundodogabriel
Welcome olaf! I saw your emulator olafnes some time ago, I was helping with jacob nes emulator, and researching more about basicnes when I found olafnes page on sourceforge. The basicnes 6502 emulation code was bad written, and had a lot of timing issues, wrong flags and messy code. I rewrote most of the code, based on virtuanes sources and docs from nesdev. Is a lot better now, just need some minor fixes. The wrong timing cause some strange glitches, like the map on battletoads intro, maniac mansion not scrolling correctly...
I VDP is similar to sega master system, then I think we can use the code vdp master system with some minor modifications.
Jacob, how it's going with the 68k CPU emulation? Need some help?
I'd love to see the fixes done to the source code if it's still around. I've been meaning to rework the emulator as I now have a lot more experience with that sort of thing after Zega Alpha. I've really gotten down and dirty with the Master System and Game Gear stuff in recent years, so I can carry that back to my NES project now. Zega Alpha also has the better Game Gear's VDP thanks to Parasyte (ROM hacker, discoverer of the Metroid code) and benryves (programmer of the Cogwheel emulator). I've never looked too much into the technical aspects of the Genesis VDP, but it's probable that the Game Gear's architecture is relatively closer to it. The increased color palette, sprite zooming, and so forth.
Most of my experience prior to working on emulators was application development. Much of what I added to the emulators I based my work off of was full screen, Game Genie, save states, movies, rewinding, PC controller support, memory editors, and so on. However I did fix things like timing issues, added support for peripherals, mappers, and things like that.
Might I suggest if we're welcome to work on the project to keep a shared FTP with the files on it or something? Perhaps also chatting on IRC as a group? I'd be more than happy to make some room on nothackers.com for the project.
-
Aug 12th, 2013, 06:51 PM
#22
Member
Re: Lets make a Sega Genesis Emulator
I second an IRC channel. Great idea. It would definitely be the best way to work in realtime. Everything else is too slow, and it would take forever. I run an IRCd that could be used. Might be better than a full-blown public server for a project like this.
-
Aug 13th, 2013, 08:15 PM
#23
New Member
Re: Lets make a Sega Genesis Emulator
After doing some research on the Sega Genesis, I've found...
- The Sega Master System's Z80 processor is used as a co-processor for the Sega Genesis. So you're welcome to gut that out of Zega Alpha. This Z80 core comes from vbSpec, the Sinclair ZX Spectrum emulator written in VB6. This as well as the VDP and everything else is available to you guys from me.
- Wikipedia says that the Genesis VDP is actually derived from the Master System/Game Gear VDP. It's actually between them in number of possible colors and stuff, so I imagine they are very very close.
- The Texas Instruments SN76489 PSG sound chip is also used from the Master System. I don't have the FM chip also used programmed into my emulator (as only a few games supported it, mostly imports), but MEKA and Genesis emulators are open source so it'd be possible to bring that chip over too. In fact, if I can get a hold of vbt, I may be able to coax him into implementing that. He ported the PSG sound chip in from SMS Plus! for Saturn to VB6 for me.
Anyway, just figured I'd flesh out some more details that are obviously of major use. We could recode stuff as needed. Zega Alpha's source is available here. As far as I know my emulator passes the ZEXALL test ROM as well (an emulator tool to test how accurate your Z80 and VDP emulators are).
Last edited by notolaf; Aug 14th, 2013 at 04:28 PM.
-
Aug 18th, 2013, 11:48 AM
#24
Re: Lets make a Sega Genesis Emulator
Hey guys, sorry about the long wait. I've been having some personal issues lately with my job, my gf (and her birthday), and other things. So I took a little break from VBForums and programming in general until I can get my life back in order. But I'm back now. Yes I will probably need some help and would love for you guys to join in on the project. I think with all of us as a team (including my awesome DirectX programming skills) we can add some "Blast Processing" in VB.
-
Aug 18th, 2013, 12:02 PM
#25
New Member
Re: Lets make a Sega Genesis Emulator
Sounds bueno.
-
Aug 18th, 2013, 02:57 PM
#26
Re: Lets make a Sega Genesis Emulator
Originally Posted by Jacob Roman
Hey guys, sorry about the long wait. I've been having some personal issues lately with my job, my gf (and her birthday), and other things.
Oh please, I know you got hooked on WoW
-
Aug 18th, 2013, 04:11 PM
#27
New Member
Re: Lets make a Sega Genesis Emulator
So are there some skeleton modules we can look at? I'd like to start pitching in during my spare time if possible.
-
Aug 19th, 2013, 12:40 AM
#28
Re: Lets make a Sega Genesis Emulator
Originally Posted by notolaf
So are there some skeleton modules we can look at? I'd like to start pitching in during my spare time if possible.
See post #24 for details. It was that...and WoW
I havent programmed or did anything at that time. Had too many things going on which put a lot of stress on me. But I'm back now. So now I can slowely but surely get a skeleton going.
-
Aug 19th, 2013, 12:46 AM
#29
New Member
Re: Lets make a Sega Genesis Emulator
Alright, keep us posted.
-
Aug 19th, 2013, 05:43 PM
#30
Member
Re: Lets make a Sega Genesis Emulator
The basic structure is pretty much still like a NES emulator I think. Just to play around with the idea, I used somebody's 68000 core in C and created a ROM loader for it, and started emulation with some debug output. I ran Sonic 1, and it runs code. It starts communicating with the VDP registers which sit at $C00000. So, if we started there and then began emulating the VDP's features I'm pretty sure we could at least get a Sonic title screen showing. Of course, we still need to make a 68000 core for VB first.
What I have here seems like it's waiting for some interrupts or the correct status flags from the VDP.
Last edited by miker00lz; Aug 19th, 2013 at 05:47 PM.
-
Aug 20th, 2013, 12:48 AM
#31
New Member
Re: Lets make a Sega Genesis Emulator
http://cgfm2.emuviews.com/txt/genvdp.txt
Notes on the Genesis VDP written by Charles MacDonald. I've chatted with him on many occasions and he's extremely knowledgeable about the Sega consoles and others. He's written SMS Plus, Genesis Plus, and TGEmu. To backup further what I was saying earlier about the VDP probably being based on the Master System and Game Gear's VDP (straight from his document):
Code:
----------------------------------------------------------------------------
1.) Overview
----------------------------------------------------------------------------
The Genesis VDP is derived from the Master System VDP, which in turn
was derived from the Texas Instruments TMS9918. As a result, the VDP is
programmed much like it's earlier counterparts.
Interestingly enough, none of the Sega produced VDP's are similar to the
later VDP models made by Yamaha, which were also based upon the TMS9918.
----------------------------------------------------------------------------
2.) Display Modes
----------------------------------------------------------------------------
To clarify naming conventions, here is a list of display modes used by
the various video chips mentioned:
Mode 0 - TMS9918 specific
Mode 1 - TMS9918 specific
Mode 2 - TMS9918 specific
Mode 3 - TMS9918 specific
Mode 4 - SMS mode
Mode 5 - Genesis mode
Supported mode list:
TMS9918 - Modes 0, 1, 2, 3
SMS - Modes 0, 1, 2, 3, 4
Genesis - Modes 4, 5 (possibly 0 and others as well)
If anybody has some information about how the Game Gear would fit into
this list, let me know. I assume it's identical to the SMS, but I don't
know about the TMS9918 compatability. (if any)
I'm sure there's other documentation around but I just felt like following up before I head to bed. So, the source code to my Master System/Game Gear emulator should actually be a pretty big help in the VDP area as well as sound and the Z80 co-processor.
-
Aug 20th, 2013, 06:10 PM
#32
New Member
Re: Lets make a Sega Genesis Emulator
Also, Gens/GS is the most recently updated and the most accurate open source Genesis emulator these days AFAIK.
http://segaretro.org/Gens/GS
-
Aug 27th, 2013, 07:27 PM
#33
Member
Re: Lets make a Sega Genesis Emulator
I would hate to see this project die! Any updates?
-
Aug 27th, 2013, 09:11 PM
#34
New Member
Re: Lets make a Sega Genesis Emulator
Originally Posted by miker00lz
I would hate to see this project die! Any updates?
This. Please updates. [:
-
Sep 7th, 2021, 09:39 AM
#35
Lively Member
Re: Lets make a Sega Genesis Emulator
hi, please updates.
how i am can load (parsing) the Genesis game .rom file to a VB 6.0 picturebox and display images?
thanks.
-
Sep 7th, 2021, 11:29 AM
#36
Member
Re: Lets make a Sega Genesis Emulator
Originally Posted by xman2000
hi, please updates.
how i am can load (parsing) the Genesis game .rom file to a VB 6.0 picturebox and display images?
thanks.
With lots of research and difficulty.
You need to emulate all of the CPU instructions, the graphics chip, memory subsystem, etc.
I wouldn't use a picturebox. They're slow. You should have a bitmap buffer and blit it using the DirectDraw API for any kind of speed.
If you don't know how emulators work, don't start with the Genesis/Megadrive. Start with CHIP-8 or Space Invaders.
Last edited by miker00lz; Sep 7th, 2021 at 11:32 AM.
-
Sep 7th, 2021, 07:16 PM
#37
Re: Lets make a Sega Genesis Emulator
Originally Posted by xman2000
hi, please updates.
how i am can load (parsing) the Genesis game .rom file to a VB 6.0 picturebox and display images?
thanks.
Yeah you have to emulate every single instruction from the 68000 chip, as well as address modes, what each of the registers do in the memory itself when it comes to reading and writing (which links with the instructions in the CPU) as well as the PPU. You can take a look at my vb6 Nintendo Emulator in my signature below my post to see what I mean. The only difference is that you are literally tackling 16 bits instead of 8 as well as a lot more instructions and OP codes. I've been super busy with life to get around to it, but if you do some research and look up other open source emulators, you should have no difficulty mimicing this 16 bits worth of blast processing. If you need help, I can guide you in the right places.
Originally Posted by miker00lz
With lots of research and difficulty.
You need to emulate all of the CPU instructions, the graphics chip, memory subsystem, etc.
I wouldn't use a picturebox. They're slow. You should have a bitmap buffer and blit it using the DirectDraw API for any kind of speed.
If you don't know how emulators work, don't start with the Genesis/Megadrive. Start with CHIP-8 or Space Invaders.
Yuck DirectDraw. Noone uses DirectX7 no more. Stick with DirectX8, lock up the memory buffer to write in, write in the memory, and unlock it.
One day I would like to tackle on a Phillips CD-I emulator in VB6. Now that would take some raw talent [EDIT] And I just may have a shot o.O https://github.com/cdifan/cdichips
Last edited by Jacob Roman; Sep 7th, 2021 at 07:31 PM.
-
Sep 7th, 2021, 07:32 PM
#38
Member
Re: Lets make a Sega Genesis Emulator
Originally Posted by Jacob Roman
Yuck DirectDraw. Noone uses DirectX7 no more. Stick with DirectX8, lock up the memory buffer to write in, write in the memory, and unlock it.
Agreed. I think that's actually what I did in my VB emulators. It's been so long I can't even remember.
-
Sep 7th, 2021, 10:13 PM
#39
Lively Member
Re: Lets make a Sega Genesis Emulator
thank yours Miker00lz and Jacob Roman !
very good tips to start with emulators.
if i am if I knew how to do, if i am if I knew another programming language i would translate Emulators in GITHUB from C#, C++ and others to VB6.0.
then I would study the code to create my own emulators.
I wish is to be able to add more features to emulators and games and be able to work on the .ROM files of the games and not have to create emulators
-
Sep 8th, 2021, 05:36 AM
#40
Re: Lets make a Sega Genesis Emulator
Well it shouldnt be too hard to translate to VB6. Besides little syntax differences, youll only need to remove the semicolons. But anywho, use our Nintendo Emulators we wrote in our signatures using VB6 such as this http://www.vbforums.com/showthread.p...31#post4358131
I rewrote it years later in C++, and in doing so, I found a lot of flaws I never noticed when I did it in VB6. So its actually a better version, and the code is more organized. More readable than my VB6 counterpart. Youll find that in my github here: https://github.com/RomanEntertainmen...C/NES-Emulator
Also, if you think thats hard, try actually making a Nintendo game o.O https://www.vbforums.com/showthread....etting-Started
Once you get used to HOW the NES is emulated. You can now gradually jump up to doing the Genesis. The best place to find docs on emulating the Sega Genesis besides Google and open source emulators is Zophars Domain: https://www.zophar.net/documents/genesis.html
Always begin your code at the CPU when writing an emulator. Then Reading and Writing registers of memory, which will go hand in hand with each CPU instruction. Usually each function will pertain to certain registers or within a number of registers as well as mirrors. Assuming you completed this task, you then write code that loads the rom that the CPU can read. Make sure you have a suitable way to print out the outcomes of your CPU as it executes, such as the shift registers, hex code, instruction executions, etc. If everything seems to be in working order, you can then jump to working out the PPU, which can be a daunting task since you will have no idea where to begin. This is when your research skills will come into play. Assuming it semi works, since you will not always one shot it, then it should be time to work on the sound, which should be a lot easier than the graphics. Generally youll have whatever info in the sound registers go through whatever sound api you are using such as DirectSound which is part of DirectX. The last step is testing out multiple games to find what is compatable or what has flaws. That is when you tinker your code until every flaw is flushed out.
[EDIT] Just found out that the Sega Genesis uses 2 CPUs. The Motorola 68000 and the Z80, where the Z80 was originally found in the Sega Master System. So you gotta have 2 CPUs working together simultaneously.
Last edited by Jacob Roman; Sep 8th, 2021 at 09:24 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|