1. spencercw
  2. gb_emulator

Commits

spencercw  committed 082fbce

Change I/O port names to match those in the Game Boy Programming Manual.

  • Participants
  • Parent commits a314198
  • Branches default

Comments (0)

Files changed (4)

File gb_emulator/include/gb_emulator/constants.hpp

View file
  • Ignore whitespace
 const uint16_t IE                       = 0xffff;
 
 /* I/O ports */
-const uint8_t  JOYP                     = 0x00;          /* Joypad */
+const uint8_t  P1                       = 0x00;          /* Joypad */
+const uint8_t  SB                       = 0x01;          /* Unknown */
+const uint8_t  SC                       = 0x02;          /* Unknown */
 const uint8_t  DIV                      = 0x04;          /* Divider */
 const uint8_t  TIMA                     = 0x05;          /* Timer counter */
 const uint8_t  TMA                      = 0x06;          /* Timer modulo */
 const uint8_t  NR51                     = 0x25;          /* Sound mode 5; selection of sound output terminal */
 const uint8_t  NR52                     = 0x26;          /* Sound mode 5; sound on/off */
 const uint8_t  LCDC                     = 0x40;          /* LCD control */
-const uint8_t  LCD_STAT                 = 0x41;          /* LCD status */
+const uint8_t  STAT                     = 0x41;          /* LCD status */
 const uint8_t  SCY                      = 0x42;          /* Scroll Y */
 const uint8_t  SCX                      = 0x43;          /* Scroll X */
-const uint8_t  LCDC_Y                   = 0x44;          /* Current draw line */
+const uint8_t  LY                       = 0x44;          /* Current draw line */
 const uint8_t  LYC                      = 0x45;          /* LYC */
 const uint8_t  DMA                      = 0x46;          /* DMA transfer */
 const uint8_t  BGP                      = 0x47;          /* Background and window palette */
 const uint8_t  HDMA4                    = 0x54;          /* GBC DMA destination lo */
 const uint8_t  HDMA5                    = 0x55;          /* GBC DMA transfer */
 const uint8_t  RP                       = 0x56;          /* Infrared communications port */
-const uint8_t  BGPI                     = 0x68;          /* GBC background palette index */
-const uint8_t  BGPD                     = 0x69;          /* GBC background palette data */
-const uint8_t  OBPI                     = 0x6a;          /* GBC sprite palette index */
-const uint8_t  OBPD                     = 0x6b;          /* GBC sprite palette data */
+const uint8_t  BCPS                     = 0x68;          /* GBC background palette index */
+const uint8_t  BCPD                     = 0x69;          /* GBC background palette data */
+const uint8_t  OCPS                     = 0x6a;          /* GBC sprite palette index */
+const uint8_t  OCPD                     = 0x6b;          /* GBC sprite palette data */
 const uint8_t  SVBK                     = 0x70;          /* RAM bank selector */
 
 /* I/O port bits */

File gb_emulator/src/gb_input.cpp

View file
  • Ignore whitespace
 
 void GbInput::translate()
 {
-	gb_.mem_->ioPorts[JOYP] &= 0x30;
-	gb_.mem_->ioPorts[JOYP] |= 0x0f;
+	gb_.mem_->ioPorts[P1] &= 0x30;
+	gb_.mem_->ioPorts[P1] |= 0x0f;
 
-	if (!(gb_.mem_->ioPorts[JOYP] & JOYP_BUTTONS))
+	if (!(gb_.mem_->ioPorts[P1] & JOYP_BUTTONS))
 	{
-		if (keys_ & KEY_A)      gb_.mem_->ioPorts[JOYP] &= ~JOYP_RIGHT_OR_A;
-		if (keys_ & KEY_B)      gb_.mem_->ioPorts[JOYP] &= ~JOYP_LEFT_OR_B;
-		if (keys_ & KEY_START)  gb_.mem_->ioPorts[JOYP] &= ~JOYP_DOWN_OR_START;
-		if (keys_ & KEY_SELECT) gb_.mem_->ioPorts[JOYP] &= ~JOYP_UP_OR_SELECT;
+		if (keys_ & KEY_A)      gb_.mem_->ioPorts[P1] &= ~JOYP_RIGHT_OR_A;
+		if (keys_ & KEY_B)      gb_.mem_->ioPorts[P1] &= ~JOYP_LEFT_OR_B;
+		if (keys_ & KEY_START)  gb_.mem_->ioPorts[P1] &= ~JOYP_DOWN_OR_START;
+		if (keys_ & KEY_SELECT) gb_.mem_->ioPorts[P1] &= ~JOYP_UP_OR_SELECT;
 	}
-	if (!(gb_.mem_->ioPorts[JOYP] & JOYP_DIRECTION))
+	if (!(gb_.mem_->ioPorts[P1] & JOYP_DIRECTION))
 	{
-		if (keys_ & KEY_UP)     gb_.mem_->ioPorts[JOYP] &= ~JOYP_UP_OR_SELECT;
-		if (keys_ & KEY_DOWN)   gb_.mem_->ioPorts[JOYP] &= ~JOYP_DOWN_OR_START;
-		if (keys_ & KEY_LEFT)   gb_.mem_->ioPorts[JOYP] &= ~JOYP_LEFT_OR_B;
-		if (keys_ & KEY_RIGHT)  gb_.mem_->ioPorts[JOYP] &= ~JOYP_RIGHT_OR_A;
+		if (keys_ & KEY_UP)     gb_.mem_->ioPorts[P1] &= ~JOYP_UP_OR_SELECT;
+		if (keys_ & KEY_DOWN)   gb_.mem_->ioPorts[P1] &= ~JOYP_DOWN_OR_START;
+		if (keys_ & KEY_LEFT)   gb_.mem_->ioPorts[P1] &= ~JOYP_LEFT_OR_B;
+		if (keys_ & KEY_RIGHT)  gb_.mem_->ioPorts[P1] &= ~JOYP_RIGHT_OR_A;
 	}
 }

File gb_emulator/src/gb_memory.cpp

View file
  • Ignore whitespace
 	romBank      = 1;
 	extRamBank   = 0;
 
-	ioPorts[JOYP]     = 0x0f;
-	ioPorts[LCDC]     = 0x91;
-	ioPorts[LCD_STAT] = 0x80;
-	ioPorts[BGP]      = 0xfc;
-	ioPorts[OBP0]     = 0xff;
-	ioPorts[OBP1]     = 0xff;
-	ioPorts[VBK]      = 0x01;
-	ioPorts[HDMA5]    = 0xff;
-	ioPorts[SVBK]     = 0x01;
+	ioPorts[P1]    = 0x0f;
+	ioPorts[LCDC]  = 0x91;
+	ioPorts[STAT]  = 0x80;
+	ioPorts[BGP]   = 0xfc;
+	ioPorts[OBP0]  = 0xff;
+	ioPorts[OBP1]  = 0xff;
+	ioPorts[VBK]   = 0x01;
+	ioPorts[HDMA5] = 0xff;
+	ioPorts[SVBK]  = 0x01;
 
 	// Undocumented GBC registers
 	ioPorts[0x6c] = 0xfe;
 		return 0;
 
 	// GBC background palette data
-	case BGPD:
-		return gb_.video_->gbcBgPalette[ioPorts[BGPI] & 0x3f];
+	case BCPD:
+		return gb_.video_->gbcBgPalette[ioPorts[BCPS] & 0x3f];
 
 	// GBC sprite palette data
-	case OBPD:
-		return gb_.video_->gbcSpritePalette[ioPorts[OBPI] & 0x3f];
+	case OCPD:
+		return gb_.video_->gbcSpritePalette[ioPorts[OCPS] & 0x3f];
 
 	// Undocumented GBC registers
 	case 0x6c:
 	switch (ptr)
 	{
 	// Joypad
-	case JOYP:
+	case P1:
 		ioPorts[ptr] = val & 0x30;
 		gb_.input_->translate();
 		break;
 
 	// LCD control
 	case LCDC:
-		if (!(val & 0x80) && (ioPorts[ptr] & 0x80) && ioPorts[LCDC_Y] < 144)
+		if (!(val & 0x80) && (ioPorts[ptr] & 0x80) && ioPorts[LY] < 144)
 		{
 			clog << hex << setfill('0')
 			     << "turning off display outside VBLANK period.. hardware damage! pc=" << setw(4) << gb_.cpu_.pc
 		// Handle switching the display off
 		if ((ioPorts[LCDC] & LCDC_OPERATIONAL) && !(val & LCDC_OPERATIONAL))
 		{
-			ioPorts[LCD_STAT] &= 0xfc;
-			ioPorts[LCDC_Y] = 0;
+			ioPorts[STAT] &= 0xfc;
+			ioPorts[LY] = 0;
 		}
 
 		ioPorts[ptr] = val;
 		break;
 
 	// LCD status
-	case LCD_STAT:
+	case STAT:
 		ioPorts[ptr] &= 0x07;
 		ioPorts[ptr] |= 0x80 | (val & 0x78);
 		break;
 
 	// Current draw line
-	case LCDC_Y:
+	case LY:
 		ioPorts[ptr] = 0;
 		break;
 
 		break;
 
 	// GBC background palette index
-	case BGPI:
+	case BCPS:
 		ioPorts[ptr] = val & 0xbf;
 		break;
 
 	// GBC background palette data
-	case BGPD:
+	case BCPD:
 		// Save the new colour for the GBC background palette data register
-		gb_.video_->gbcBgPalette[ioPorts[BGPI] & 0x3f] = val;
+		gb_.video_->gbcBgPalette[ioPorts[BCPS] & 0x3f] = val;
 
 		// Increment the GBC background palette index if necessary
-		if (ioPorts[BGPI] & 0x80)
+		if (ioPorts[BCPS] & 0x80)
 		{
-			++ioPorts[BGPI];
-			ioPorts[BGPI] &= 0xbf;
+			++ioPorts[BCPS];
+			ioPorts[BCPS] &= 0xbf;
 		}
 		break;
 
 	// GBC sprite palette index
-	case OBPI:
+	case OCPS:
 		ioPorts[ptr] = val & 0xbf;
 		break;
 
 	// GBC sprite palette data
-	case OBPD:
+	case OCPD:
 		// Save the new colour for the GBC sprite palette data register
-		gb_.video_->gbcSpritePalette[ioPorts[OBPI] & 0x3f] = val;
+		gb_.video_->gbcSpritePalette[ioPorts[OCPS] & 0x3f] = val;
 
 		// Increment the GBC sprite palette index if necessary
-		if (ioPorts[OBPI] & 0x80)
+		if (ioPorts[OCPS] & 0x80)
 		{
-			++ioPorts[OBPI];
-			ioPorts[OBPI] &= 0xbf;
+			++ioPorts[OCPS];
+			ioPorts[OCPS] &= 0xbf;
 		}
 		break;
 

File gb_emulator/src/gb_video.cpp

View file
  • Ignore whitespace
 	}
 
 	// Draw a line
-	if (gb_.mem_->ioPorts[LCDC_Y] < VBLANK_START)
+	if (gb_.mem_->ioPorts[LY] < VBLANK_START)
 	{
 		// Emulate reading from video RAM
-		switch (gb_.mem_->ioPorts[LCD_STAT] & 0x03)
+		switch (gb_.mem_->ioPorts[STAT] & 0x03)
 		{
 		// HBLANK -> OAM read
 		case 0x00:
-			gb_.mem_->ioPorts[LCD_STAT] &= 0xfc;
-			gb_.mem_->ioPorts[LCD_STAT] |= 0x02;
-			if (gb_.mem_->ioPorts[LCD_STAT] & LCD_STAT_OAM_READ_INTR)
+			gb_.mem_->ioPorts[STAT] &= 0xfc;
+			gb_.mem_->ioPorts[STAT] |= 0x02;
+			if (gb_.mem_->ioPorts[STAT] & LCD_STAT_OAM_READ_INTR)
 				gb_.mem_->ioPorts[IF] |= LCD_STAT_INTR;
 
 			return OAM_READ_CYCLES;
 
 		// OAM read -> OAM + VRAM read
 		case 0x02:
-			gb_.mem_->ioPorts[LCD_STAT] &= 0xfc;
-			gb_.mem_->ioPorts[LCD_STAT] |= 0x03;
+			gb_.mem_->ioPorts[STAT] &= 0xfc;
+			gb_.mem_->ioPorts[STAT] |= 0x03;
 			return OAM_VRAM_READ_CYCLES;
 
 		// OAM + VRAM read -> draw then HBLANK or VBLANK
 			static const uint16_t gbcWhite = 0x7fff;
 			for (int i = 0; i != 160; ++i)
 			{
-				pixelBuffer_[gb_.mem_->ioPorts[LCDC_Y] * 160 + i] = gb_.gbc_ ? gbcWhite : dmgWhite;
+				pixelBuffer_[gb_.mem_->ioPorts[LY] * 160 + i] = gb_.gbc_ ? gbcWhite : dmgWhite;
 			}
 		}
 		#endif
 		#endif
 
 		if ((gb_.mem_->ioPorts[LCDC] & LCDC_WNDW_DISPLAY) &&
-			gb_.mem_->ioPorts[LCDC_Y] >= gb_.mem_->ioPorts[WY])
+			gb_.mem_->ioPorts[LY] >= gb_.mem_->ioPorts[WY])
 		{
 			drawBgWndw(DRAW_WINDOW);
 		}
 				uint8_t *sprite = &gb_.mem_->oam[i * 4];
 
 				// Check sprite covers this line
-				if (gb_.mem_->ioPorts[LCDC_Y] >= sprite[0] - 16 &&
-				    gb_.mem_->ioPorts[LCDC_Y] <  sprite[0] -
+				if (gb_.mem_->ioPorts[LY] >= sprite[0] - 16 &&
+				    gb_.mem_->ioPorts[LY] <  sprite[0] -
 				   (gb_.mem_->ioPorts[LCDC] & LCDC_SPRITE_SIZE ? 0 : 8))
 				{
 					sprites[spritesCount++] = sprite;
 					spriteIndex += VRAM_BANK_SIZE;
 				uint8_t *tile = &gb_.mem_->vram[spriteIndex];
 
-				unsigned tileLineIndex = gb_.mem_->ioPorts[LCDC_Y] - (sprites[i][0] - 16);
+				unsigned tileLineIndex = gb_.mem_->ioPorts[LY] - (sprites[i][0] - 16);
 				if (sprites[i][3] & 0x40)
 				{
 					if (gb_.mem_->ioPorts[LCDC] & LCDC_SPRITE_SIZE)
 					if (gb_.gbc_)
 					{
 						uint16_t colour = (palette[value * 2 + 1] << 8) | palette[value * 2];
-						pixelBuffer_[gb_.mem_->ioPorts[LCDC_Y] * WIDTH + x] = colour;
+						pixelBuffer_[gb_.mem_->ioPorts[LY] * WIDTH + x] = colour;
 					}
 					else
 					{
 						uint8_t spritePalette =
 							gb_.mem_->ioPorts[sprites[i][3] & 0x10 ? OBP1 : OBP0];
 
-						pixelBuffer_[gb_.mem_->ioPorts[LCDC_Y] * WIDTH + x] =
+						pixelBuffer_[gb_.mem_->ioPorts[LY] * WIDTH + x] =
 							(value << 8) | spritePalette;
 					}
 				}
 	memset(priorityMap, 0, sizeof(priorityMap));
 
 	// Increment the line counter
-	gb_.mem_->ioPorts[LCDC_Y] = (gb_.mem_->ioPorts[LCDC_Y] + 1) % 154;
+	gb_.mem_->ioPorts[LY] = (gb_.mem_->ioPorts[LY] + 1) % 154;
 
 	// Check for HBLANK or VBLANK
 	int cycles;
-	if (gb_.mem_->ioPorts[LCDC_Y] < VBLANK_START)
+	if (gb_.mem_->ioPorts[LY] < VBLANK_START)
 	{
-		gb_.mem_->ioPorts[LCD_STAT] &= 0xfc;
-		if (gb_.mem_->ioPorts[LCD_STAT] & LCD_STAT_HBLANK_INTR)
+		gb_.mem_->ioPorts[STAT] &= 0xfc;
+		if (gb_.mem_->ioPorts[STAT] & LCD_STAT_HBLANK_INTR)
 			gb_.mem_->ioPorts[IF] |= LCD_STAT_INTR;
 		cycles = HBLANK_CYCLES;
 
 			--gb_.mem_->ioPorts[HDMA5];
 		}
 	}
-	else if (gb_.mem_->ioPorts[LCDC_Y] == VBLANK_START)
+	else if (gb_.mem_->ioPorts[LY] == VBLANK_START)
 	{
 		// Redraw the display
 		draw(pixelBuffer_.get(), gb_.gbc_);
 		gb_.mem_->ioPorts[IF] |= VBLANK_INTR;
 
 		// Update the status register
-		gb_.mem_->ioPorts[LCD_STAT] &= 0xfc;
-		gb_.mem_->ioPorts[LCD_STAT] |= 0x01;
-		if (gb_.mem_->ioPorts[LCD_STAT] & LCD_STAT_VBLANK_INTR)
+		gb_.mem_->ioPorts[STAT] &= 0xfc;
+		gb_.mem_->ioPorts[STAT] |= 0x01;
+		if (gb_.mem_->ioPorts[STAT] & LCD_STAT_VBLANK_INTR)
 			gb_.mem_->ioPorts[IF] |= LCD_STAT_INTR;
 
 		cycles = LINE_CYCLES;
 	}
 
 	// Check for LYC-LY coincidence
-	if (gb_.mem_->ioPorts[LYC] == gb_.mem_->ioPorts[LCDC_Y])
+	if (gb_.mem_->ioPorts[LYC] == gb_.mem_->ioPorts[LY])
 	{
-		gb_.mem_->ioPorts[LCD_STAT] |= LCD_STAT_COINCIDENCE;
-		if (gb_.mem_->ioPorts[LCD_STAT] & LCD_STAT_COINC_INTR)
+		gb_.mem_->ioPorts[STAT] |= LCD_STAT_COINCIDENCE;
+		if (gb_.mem_->ioPorts[STAT] & LCD_STAT_COINC_INTR)
 			gb_.mem_->ioPorts[IF] |= LCD_STAT_INTR;
 	}
 	else
-		gb_.mem_->ioPorts[LCD_STAT] &= ~LCD_STAT_COINCIDENCE;
+		gb_.mem_->ioPorts[STAT] &= ~LCD_STAT_COINCIDENCE;
 
 	return cycles;
 }
 	uint8_t *tileMap, *tileAttr;
 	if (type == DRAW_BACKGROUND)
 	{
-		line = (gb_.mem_->ioPorts[LCDC_Y] + gb_.mem_->ioPorts[SCY]) % 256;
+		line = (gb_.mem_->ioPorts[LY] + gb_.mem_->ioPorts[SCY]) % 256;
 		tileMap =  &gb_.mem_->vram[(gb_.mem_->ioPorts[LCDC] & LCDC_BG_TILE_MAP) ? 0x1c00 : 0x1800];
 		tileAttr = &gb_.mem_->vram[(gb_.mem_->ioPorts[LCDC] & LCDC_BG_TILE_MAP) ? 0x3c00 : 0x3800];
 	}
 	else if (type == DRAW_WINDOW)
 	{
-		line = gb_.mem_->ioPorts[LCDC_Y] - gb_.mem_->ioPorts[WY];
+		line = gb_.mem_->ioPorts[LY] - gb_.mem_->ioPorts[WY];
 		tileMap  = &gb_.mem_->vram[(gb_.mem_->ioPorts[LCDC] & LCDC_WNDW_TILE_MAP) ? 0x1c00 : 0x1800];
 		tileAttr = &gb_.mem_->vram[(gb_.mem_->ioPorts[LCDC] & LCDC_WNDW_TILE_MAP) ? 0x3c00 : 0x3800];
 	}
 			if (gb_.gbc_)
 			{
 				uint16_t colour = (palette[value * 2 + 1] << 8) | palette[value * 2];
-				pixelBuffer_[gb_.mem_->ioPorts[LCDC_Y] * WIDTH + x] = colour;
+				pixelBuffer_[gb_.mem_->ioPorts[LY] * WIDTH + x] = colour;
 			}
 			else
 			{
-				pixelBuffer_[gb_.mem_->ioPorts[LCDC_Y] * WIDTH + x] =
+				pixelBuffer_[gb_.mem_->ioPorts[LY] * WIDTH + x] =
 					(value << 8) | gb_.mem_->ioPorts[BGP];
 			}
 		}