How to implement DMG (Game boy) cpu’s register using OOP patterns/principles to max code reusability?

  softwareengineering

I looking to learn better use of OOP principles/patterns so I decided to start implementing at least the basics of a GB emulator (technical part is widely covered on diff sites).

So I started with an empty CPU class, then decided to try to implement the 8bit registers A,B,C,D,E,F,H,L we also have pseudo 16bit registers AF,CD and HL (seen in GB registers), I was about to use just a dictionary and make some methods to implement them but that goes against the purpose of my initial motivation.

So, I’m wondering if a Factory Pattern is suitable to implement the registers or how would you tackle this in such a way that allow me to have some flexible code to create as many registers as I need of any type (8bit, pseudo 16bits or real 16bits) as I would like the code to be re-usable for let’s say another CPU emulation, this code/class will be somehow loosely couple to my CPU class (currently empty).

Please consider this more like an abstraction learning project than actually building a fully functional DMG emulator, but pursuing a DMG emulator seems quite suitable for learning actually adv OOP concepts and implementing them.

LEAVE A COMMENT