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:
  1. Option Explicit
  2.  
  3. Public CPU_Paused As Boolean
  4. Public CPU_Running As Boolean
  5. Public Instruction(256) As Long 'Dont know how many instructions yet so keep it 256 for now
  6. Public Cycles(256) As Long
  7.  
  8. Public Opcode As Long
  9. Public PC As Long
  10. Public Tick_Count As Long
  11.  
  12.  
  13. Public Function ReadMemory(ByVal Address As Long) As Long
  14.     ReadMemory = 0
  15. End Function
  16.  
  17.  
  18. Public Sub Execute_68000()
  19.     If CPU_Paused = True Then
  20.         Do Until CPU_Paused = False And CPU_Running = True
  21.             DoEvents
  22.         Loop
  23.     End If
  24.  
  25.     Opcode = ReadMemory(PC)  ' Fetch Next Operation
  26.     PC = PC + 1
  27.     Tick_Count = Tick_Count + Cycles(Opcode)
  28.    
  29.     Select Case Instruction(Opcode)
  30.  
  31.     End Select
  32.    
  33.     DoEvents
  34. End Sub

vb.net Code:
  1. Option Explicit On
  2. Option Strict On
  3.  
  4. Public Module mod68000
  5.  
  6.     Public CPU_Paused As Boolean
  7.     Public CPU_Running As Boolean
  8.     Public Instruction(256) As Integer 'Dont know how many instructions yet so keep it 256 for now
  9.     Public Cycles(256) As Integer ''Dont know how many instructions yet so keep it 256 for now
  10.  
  11.     Public Opcode As Integer
  12.     Public PC As Integer
  13.     Public Tick_Count As Integer
  14.  
  15.  
  16.     Public Function ReadMemory(ByVal Address As Integer) As Integer
  17.         Return 0
  18.     End Function
  19.  
  20.  
  21.     Public Sub Execute_68000()
  22.         If CPU_Paused = True Then
  23.             Do Until CPU_Paused = False And CPU_Running = True
  24.                 Application.DoEvents()
  25.             Loop
  26.         End If
  27.  
  28.         Opcode = ReadMemory(PC)  ' Fetch Next Operation
  29.         PC = PC + 1
  30.         Tick_Count = Tick_Count + Cycles(Opcode)
  31.  
  32.         Select Case Instruction(Opcode)
  33.  
  34.         End Select
  35.  
  36.         Application.DoEvents()
  37.     End Sub
  38.  
  39. 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