Correctly read addresses

Discussion of programming and development for the original Game Boy and Game Boy Color.
Post Reply
Monster704
Posts: 6
Joined: Tue Dec 03, 2013 11:51 am

Correctly read addresses

Post by Monster704 »

Hello,
it's been a while since my last post.
I have updated my circuit a little bit, but it's still not working as I want it to.
I added a little picture to show you my current circuit. All 16 address lines of the GameBoy are tied together in groups of 8 to two NANDS. The outputs of the NANDS are connected to a NOR.
So basically, if all address lines (A0 - A15) are on VCC (which should happen if I read 0xFFFF), there should be a logical 1 at the output of the NOR.
In the other picture you see the output of the NOR on a oscilloscope while reading OxFFFF in a infinite loop. I put some red circles around the peaks (where it is on VCC).
The problem now is: If I change my program so that it reads e.g. 0x0000 NOTHING changes. The output on the oscilloscope remains exactly the same. So that means, my program for reading the address is not correct.

Code: Select all

#include <gb/gb.h>
#include <stdio.h>
#include <stdlib.h>

void main()
{
	int *adresse;
	int value;
				
	for(;;)
	{
		*address = 0x0000;
		value= *address;						
	}
}
That's my program. If anyone of you has an idea how to correctly read an address so that it changes the address lines, I would very appreciate if he/she would let me know.
Many thanks in advance.
Attachments
Circuit.jpg
Osci.jpg
User avatar
Jarhmander
Formerly ~J-@D!~
Posts: 568
Joined: Sun Mar 12, 2006 12:36 am
Location: Rive nord de Montréal

Re: Correctly read addresses

Post by Jarhmander »

Monster704 wrote:

Code: Select all

#include <gb/gb.h>
#include <stdio.h>
#include <stdlib.h>

void main()
{
	int *adress;
	int value;
	for(;;)
	{
		*address = 0x0000;
		value= *address;						
	}				
}
If I understand correctly, you want to read from some fixed addresses? I guess what you wanted in your for loop is

Code: Select all

	for(;;)
	{
		address = (int *)0x0000;
		value= *address;						
	}
If it's the solution you're after, maybe you should read more about C pointers because you appear not to grasp basic concepts about them.
((λ (x) (x x)) (λ (x) (x x)))
lidnariq
Posts: 11429
Joined: Sun Apr 13, 2008 11:12 am

Re: Correctly read addresses

Post by lidnariq »

Monster704: break it down into parts. What's the output of one of the NAND8s? What does the 'scope show going into its inputs?

Also, I don't know whether SDCC will compile int type to a single byte on the gbz80 target.
nitro2k01
Posts: 252
Joined: Sat Aug 28, 2010 9:01 am

Re: Correctly read addresses

Post by nitro2k01 »

Why do you expect the logic gate to trigger on a read from $0000? A nand gate will be high as soon as of its inputs are low. At least one input is low at all times during the execution of the "read from $0000" variation of our program, and thus nothing will ever happen. Only a read (or write) from (to) $ffff will create a change in the final output. If you did actually change the 8-input NANDs to 8-input NORs etc for the second experiment, then I apologize for sounding rash.

But anyway, I recommend getting BGB since it has a powerful debugger and is accurate enough to pretty much render hardware testing obsolete. (You should still test anything you plan to release on hardware to be sure ) You can enter the debugger by pressing esc in the emulator window. You can now single step and edit different types of breakpoints.

What you want in this case is an access breakpoint. In the debugger, select debug, access breakpoints. Enter the desired address, check write and/or read as desired and finally press add. Run (F9 or run, run in the menu bar) and see if it triggers.
lidnariq wrote:Also, I don't know whether SDCC will compile int type to a single byte on the gbz80 target.
Tis doesn't matter hugely for the purposes of the experiment. If int is bigger than a byte, the code will still read from $0000. It will not read only from $0000, but if the goal is to produce a read from $0000 it's sufficient.

I'd be more worried that the read is optimized away. $ffff might implicitly be classified as volatile, preventing the read from being optimized away, whereas a read from $0000 would not be classified as volatile.
Monster704
Posts: 6
Joined: Tue Dec 03, 2013 11:51 am

Re: Correctly read addresses

Post by Monster704 »

First of all I want to thank all of you for your answers.
Jarhmander wrote:
Monster704 wrote:

Code: Select all

#include <gb/gb.h>
#include <stdio.h>
#include <stdlib.h>

void main()
{
	int *adress;
	int value;
	for(;;)
	{
		*address = 0x0000;
		value= *address;						
	}				
}
If I understand correctly, you want to read from some fixed addresses? I guess what you wanted in your for loop is

Code: Select all

	for(;;)
	{
		address = (int *)0x0000;
		value= *address;						
	}
If it's the solution you're after, maybe you should read more about C pointers because you appear not to grasp basic concepts about them.
That sounds plausible...could be that I mixed something up here! I will try that the next time I am in the laboratory.
lidnariq wrote:Monster704: break it down into parts. What's the output of one of the NAND8s? What does the 'scope show going into its inputs?

Also, I don't know whether SDCC will compile int type to a single byte on the gbz80 target.
Last time I didn't have the time to break it down into parts..will definitely do that the next time!
nitro2k01 wrote:Why do you expect the logic gate to trigger on a read from $0000? A nand gate will be high as soon as of its inputs are low. At least one input is low at all times during the execution of the "read from $0000" variation of our program, and thus nothing will ever happen. Only a read (or write) from (to) $ffff will create a change in the final output. If you did actually change the 8-input NANDs to 8-input NORs etc for the second experiment, then I apologize for sounding rash.

But anyway, I recommend getting BGB since it has a powerful debugger and is accurate enough to pretty much render hardware testing obsolete. (You should still test anything you plan to release on hardware to be sure ) You can enter the debugger by pressing esc in the emulator window. You can now single step and edit different types of breakpoints.

What you want in this case is an access breakpoint. In the debugger, select debug, access breakpoints. Enter the desired address, check write and/or read as desired and finally press add. Run (F9 or run, run in the menu bar) and see if it triggers.
lidnariq wrote:Also, I don't know whether SDCC will compile int type to a single byte on the gbz80 target.
Tis doesn't matter hugely for the purposes of the experiment. If int is bigger than a byte, the code will still read from $0000. It will not read only from $0000, but if the goal is to produce a read from $0000 it's sufficient.

I'd be more worried that the read is optimized away. $ffff might implicitly be classified as volatile, preventing the read from being optimized away, whereas a read from $0000 would not be classified as volatile.
I did not expect the logic gate to trigger on a read from 0x0000. When we first set up our circuit on a test board I wrote a short program (the one in my starting post) which continuously reads from 0xFFFF and that the logic gate is triggering correctly. The picture of the oscilloscope is from the logic output while reading from 0xFFFF. I (and my teacher) thought that the short peaks (in the red circles) are from the 0xFFFF read.
After that I changed the the program so that it reads from 0x0000, to see if something changes. Unfortunately the output remained exactly the same.
The circuit is correct (double checked everything)...

I haven't heard of BGB yet, I will definitely give it a try. Thank you!
Post Reply