Controller tester working in emulator not on NES

Are you new to 6502, NES, or even programming in general? Post any of your questions here. Remember - the only dumb question is the question that remains unasked.

Moderator: Moderators

Post Reply
The Rook
Posts: 28
Joined: Mon Jul 13, 2015 8:04 am

Controller tester working in emulator not on NES

Post by The Rook » Fri Apr 03, 2020 9:34 pm

I wrote a simple controller test ROM using information from and the "Making Games for the NES" book by Steven Hugg.

The ROM works fine in FCEUX but when I copy the ROM to my Everdrive N8 and try it on my Analogue NT, it freezes up after pressing a few buttons on the controller.

I'm using Visual Studio Code to write and compile my code. My project is setup like the examples from Same folder structures, same use of the compile.bat file. I use the nrom_32k_vert.cfg from's 01_Hello example.

This is my first attempt at writing something for the NES. I'm not sure what I'm missing. Any help would be appreciated.

I've attached a recent build of the ROM and here is the code to my main file, ControllerTest.c:

Code: Select all

#include "LIB/neslib.h"
#include "ControllerTest.h"

#define BLACK 0x0f
#define DK_GY 0x00
#define LT_GY 0x10
#define WHITE 0x30
#define LT_BL 0x3C
#define RED   0x05

#define SPRITE_PAD_LR			0xB4
#define SPRITE_PAD_UD			0xB5
#define SPRITE_B_A				0xB7

#define H_FLIP	0x40
#define V_FLIP	0x80
#define HV_FLIP	0xC0

const unsigned char bg_palette[] = {
	BLACK, DK_GY, LT_GY, WHITE,			// background palette 0
	BLACK, DK_GY, LT_GY, LT_BL,			// background palette 1
	BLACK, DK_GY, LT_GY, RED,			// background palette 2
	BLACK, DK_GY, LT_GY, BLACK			// background palette 3

const unsigned char spr_palette[] = {
	BLACK, WHITE, WHITE, WHITE, 		// sprite palette 0
	BLACK, BLACK, BLACK, BLACK,			// sprite palette 1
	BLACK, BLACK, BLACK, BLACK,			// sprite palette 2
	BLACK, BLACK, BLACK, BLACK			// sprite palette 3

void draw_screen()
	//vram_write(nametable, sizeof(nametable));

void setup_graphics()
	// Screen off.
	// Hide all sprites.
	// Set the palettes.
	// Screen on.

void main (void)
	char pad;			// Controller flags.
	unsigned char i;	// for loop index.
	unsigned char y;	// y offset of the sprites.

	// Draw screen.

  	// Setup graphics.

	while (1)
		// Infinite loop.

		// Clear all sprites from sprite buffer.

		// Check the controllers.
		for (i = 0; i < 2; i++)
			// Poll controller i (0-1)
			pad = pad_poll(i);

			// Update the y offset.
			y = i * 80;

			// Check the D-Pad.
			if (pad & PAD_LEFT) { oam_spr(37, 76 + y, SPRITE_PAD_LR, 0); }
			if (pad & PAD_UP) { oam_spr(44, 69 + y, SPRITE_PAD_UD, 0); }
			if (pad & PAD_RIGHT) { oam_spr(52, 76 + y, SPRITE_PAD_LR, 0); }
			if (pad & PAD_DOWN) { oam_spr(44, 84 + y, SPRITE_PAD_UD, 0); }
			// Check the Select and Start buttons
			if (pad & PAD_SELECT) 
				oam_spr(68, 82 + y, SPRITE_SELECT_START, 0);
				oam_spr(76, 82 + y, SPRITE_SELECT_START, H_FLIP);
			if (pad & PAD_START)
				oam_spr(83, 82 + y, SPRITE_SELECT_START, 0);
				oam_spr(91, 82 + y, SPRITE_SELECT_START, H_FLIP);
			// Check the B and A buttons.
			if (pad & PAD_B)
				oam_spr(105, 78 + y, SPRITE_B_A, 0);
				oam_spr(113, 78 + y, SPRITE_B_A, H_FLIP);
				oam_spr(105, 86 + y, SPRITE_B_A, V_FLIP);
				oam_spr(113, 86 + y, SPRITE_B_A, HV_FLIP);
			if (pad & PAD_A)
				oam_spr(121, 78 + y, SPRITE_B_A, 0);
				oam_spr(129, 78 + y, SPRITE_B_A, H_FLIP);
				oam_spr(121, 86 + y, SPRITE_B_A, V_FLIP);
				oam_spr(129, 86 + y, SPRITE_B_A, HV_FLIP);

		// Wait till beginning of the frame.
Controller Test (2020-03-27).nes
(40.02 KiB) Downloaded 73 times

The Rook
Posts: 28
Joined: Mon Jul 13, 2015 8:04 am

Re: Controller tester working in emulator not on NES

Post by The Rook » Tue Sep 08, 2020 7:11 pm

So I recently purchased a RetroStage Programmer and a couple NROM flashable boards. I flashed my ROM file onto the NROM board, put the board in a cartridge shell and the Controller Test ROM worked!

So there must be an issue with the Everdrive N8 not liking the Controller Test ROM that I created. Now this is not the new Everdrive N8 Pro, this is a regular Everdrive N8. I'll have to check what firmware it is running. But, I'd be curious to see if the ROM works on the Pro version of the Everdrive N8.

Now that I've confirmed that this works I can start doing some more experimenting and work towards a real game. :D

Post Reply