Electronics Yet another game boy thread

Discussion in 'Modding' started by kobaj, 30 Oct 2004.

  1. kobaj

    kobaj Banned

    Joined:
    4 Jul 2004
    Posts:
    837
    Likes Received:
    0
    Now before you all think I'm going to ask if I can use my gameboy lcd as somthing or other I'm not, I'm asking How does the game boy acualy work.I'm doing a report on them And I'm a little confused,Ive found these. http://home1.stofanet.dk/hvaba/gameboy/mbc5cpld/cpldcart.html http://geocities.com/vjkemp/gbcam.htm [​IMG] [​IMG] [​IMG] [​IMG] [​IMG] [​IMG]
    Pin - Name -Description
    1 -VCC -+5 VDC
    2 -? -? Connected on Gameboy, but not used on GamePaks.
    3 -/RESET -Reset
    4 -/WR -Write
    5 -? -? Used by paging PAL on high capacity GamePaks.
    6 -A0 -Address 0
    7 -A1 -Address 1
    8 -A2 -Address 2
    9 -A3 -Address 3
    10 -A4 -Address 4
    11 -A5 -Address 5
    12 -A6 -Address 6
    13 -A7 -Address 7
    14 -A8 -Address 8
    15 -A9 -Address 9
    16 -A10 -Address 10
    17 -A11 -Address 11
    18 -A12 -Address 12
    19 -A13 -Address 13
    20 -A14 -Address 14
    21 -/CS -Chip Select
    22 -D0 -Data 0
    23 -D1 -Data 1
    24 -D2 -Data 2
    25 -D3 -Data 3
    26 -D4 -Data 4
    27 -D5 -Data 5
    28 -D6 -Data 6
    29 -D7 -Data 7
    30 -/RD -Read
    31 -? -? Connected on Gameboy, but not used on Game-Paks.
    32 -GND -Ground
    And unfortunutly I dont understand a bit of it,I was hopping to make my own game some how but instead uf eeprom will a pic work. And whats it mean by data and address. wich pins controll the buttons and sound and screen.Eny help is appreciated.
     
  2. bigal

    bigal Fetch n Execute

    Joined:
    8 Oct 2004
    Posts:
    609
    Likes Received:
    0
    ok, WTH is this all about... :confused: :eyebrow:
    whats the project and whats all those schematics for? You hack nintendos network? :rolleyes:
     
  3. kobaj

    kobaj Banned

    Joined:
    4 Jul 2004
    Posts:
    837
    Likes Received:
    0
    Sorry The project is called explorer were the kids get to choose somthing they get to reserch on and I chose gameboy.And the schematics I found on the web. I am tyring to make a game. But taking a shortcut I am wondering If eny one knows how to make one with pics. caouse I dont understand a bit of this kind of program.
    Code:
    //
    // Title      : CPLDTEST.C
    //              Menudriven testprogram to test the MBC5 part and the i/o
    //		in the Xilinx CPLD.
    // Compiler   : GBDK 2.1.0. Needs additional MBC5CPLD.H.
    // References :
    // Author     : claus.bjerre@private.dk
    // Version    : 0.1
    
    #define ROM_TEST		// Include ROM bank switch test.
    //#define EMULATOR           	// Undefine to run on the real thing
    
    #include <gb.h>
    #include <console.h>
    #include <drawing.h>
    #include <stdio.h>
    #include <stdarg.h>
    
    #define CPLD_CONF_1
    #include "mbc5cpld.h"      	// Non-GBDK header
    
    
    UBYTE cpx, cpy;
    UBYTE ubPortAMode;
    
    
    #ifdef ROM_TEST_ENABLED
    void rom_bank_1( void );
    void rom_bank_2( void );
    void rom_bank_3( void );
    #endif
    
    
    
    void CenterText( int row, char *txt )
    {
      gotogxy(3,row);
      gprintf("%s", txt );
      cpx = 10 + strlen( txt )/2;
    }
    /* CenterText */
    
    
    #define NEWLINE -1
    
    void Text( int x, int y, char *txt )
    {
      if( y == NEWLINE )
        gotogxy(x,++cpy);
      else
        gotogxy(x,y);
    
      gprintf("%s", txt );
      cpx = x + strlen( txt );
      cpy = y;
    }
    /* Text */
    
    
    void TextAttr( int x, int y, char *txt, UBYTE a, UBYTE b, UBYTE c  )
    {
      if( y == NEWLINE )
        gotogxy(x,++cpy);
      else
        gotogxy(x,y);
    
      color( a,b,c );
      gprintf("%s", txt );
      color( BLACK, WHITE, SOLID );
      cpx = x + strlen( txt );
      cpy = y;
    }
    /* TextAttr */
    
    
    void DispBinary( UBYTE bte )
    {
      char txt[2];
      UBYTE i;
    
      for( i=0x80; i>=0x01; i>>=1 )
      {
        sprintf( txt, "%c", bte & i ? '1' : '0' );
        Text( cpx, cpy, txt );
      }
    }
    /* DispBinary */
    
    
    void DispBinaryCursor( UBYTE bte, UBYTE index, UBYTE nof_bits )
    {
      char txt[2];
      int i;
    
      bte <<= 8-nof_bits;
    
      for( i=nof_bits-1; i>=0; i-- )
      {
        if( index == i )
          color(WHITE, BLACK, SOLID);
        sprintf( txt, "%c", bte & 0x80 ? '1' : '0' );
        bte <<= 1;
        Text( cpx, cpy, txt );
        color(BLACK, WHITE, SOLID);
      }
    }
    /* DispBinaryCursor */
    
    
    #define SET_BIT   1
    #define CLEAR_BIT 0
    
    void SetBit( UBYTE *dat, UBYTE ubIndex, UBYTE ubSet )
    {
      UBYTE ubVal;
    
      ubVal = 1;
      for( ; ubIndex > 0; ubIndex-- ) ubVal *= 2;
    
      if( ubSet == SET_BIT )
        *dat |=  ubVal;
      else
        *dat &= ~ubVal;
    }
    /* SetBit */
    
    #define XMIN  0
    #define XMAX  159
    #define YMIN  0
    #define YMAX  143
    
    
    void ClearScreen( void )
    // Rediculus. Gotta find the function...
    {
      UBYTE ubI;
    
      color(WHITE, WHITE, SOLID);
    
      for( ubI = 0; ubI <= YMAX; ubI++)
        line( 0, ubI, XMAX, ubI);
    
      color( BLACK, WHITE, SOLID );
    }
    /* ClearScreen */
    
    
    
    
    void DispAddr( UWORD uwI, UBYTE ubBank )
    {
      Text(2,7,"Bank ");
      gprintn( ubBank, 10, 0 );
    
      Text(2,8,"Addr ");
      gprintln( uwI, 16, 0 );
    
      Text(13,7,"(");
      gprintln( ubBank*8 + (1+uwI-0xA000)/1024, 10, 0 );
      gprintf("k)");
    
    }
    /* DispAddr */
    
    
    
    void RamTest( void )
    {
      UWORD uwI;
      UBYTE ubError, ubPresc, ubBank;
      char txt[10];
    
      ubError = 0;
      ubPresc = 1;
    
      ClearScreen();
    
      Text(1,3,"Testing cart RAM");
    
      Text(1,5,"Zeroing");
    
      for( ubBank = 0; ubBank < 128/8; ubBank++ )
      {
        SWITCH_RAM_MBC5(ubBank);
    
        if( ubBank & 0x01 ) Text(cpx,cpy,".");
        for( uwI = 0xA000; uwI <= 0xBFFF; uwI+=2 )
        {
          *(UWORD *)uwI = 0x0000;
        }
      }
    
    
      for( ubBank = 0; ubBank < 128/8 && !ubError; ubBank++)
      {
    
        SWITCH_RAM_MBC5(ubBank);
    
        for( uwI = 0xA000; uwI <= 0xBFFF && !ubError; uwI++ )
        {
          if( *(UBYTE *) uwI != 0x00 )
    	ubError = 1;
    
          *(UBYTE *)uwI = 0x55;
          if( *(UBYTE *) uwI != 0x55 )
    	ubError = 2;
    
          *(UBYTE *)uwI = 0xAA;
          if( *(UBYTE *) uwI != 0xAA )
    	ubError = 3;
    
    
          if( !--ubPresc || ubError || uwI == 0xBFFF )
          {
    	ubPresc = 252;
    
    	DispAddr( uwI, ubBank );
          }
        }
      }
    
      if( ubError )
      {
        if( ubError == 1 )
          Text( 2, 11, "FAIL (not zero)" );
        else if( ubError == 2 )
          Text( 2, 11, "FAIL (not 0x55)" );
        else if( ubError == 3 )
          Text( 2, 11, "FAIL (not 0xAA)" );
      }
      else
      {
        Text( 2, 11, "PASS");
      }
    
      do {} while( !joypad() );
      ClearScreen();
    }
    // RamTest
    
    
    #ifdef ROM_TEST
    void RomTest( void )
    {
      UWORD uwI;
      UBYTE ubError, ubPresc, ubBank;
      char txt[10];
    
      ubError = 0;
      ubPresc = 1;
    
      ClearScreen();
    
      Text(1,3,"Testing cart ROM");
    
      Text(0,5,"Switching 4000-7FFF");
    
      cpy += 2;
    
      SWITCH_ROM_MBC5((UWORD) 1);
      rom_bank_1();
    
      SWITCH_ROM_MBC5((UWORD) 2);
      rom_bank_2();
    
      SWITCH_ROM_MBC5((UWORD) 3);
      rom_bank_3();
    
      SWITCH_ROM_MBC5((UWORD) 0);
    
      Text( 2, 11, "Ready...");
    
      do {} while( !joypad() );
      ClearScreen();
    }
    // RamTest
    #endif
    
    
    
    
    void LatchTest( void )
    {
      UBYTE ubDummy;
      UWORD uwCnt;
    
      uwCnt = 0;
    
      ClearScreen();
    
      Text(1,3,"Testing AA & RA");
    
      Text(1,5,"Running...");
    
      do {
        ++uwCnt;
          // Set AA12..15
        SWITCH_RAM_MBC5( uwCnt );
          // Set RA13..21
        SWITCH_ROM_MBC5( uwCnt );
        ubDummy = *(UBYTE *) 0x4000;
      } while( !joypad() );
    
      Text(1,7,"Stopped...");
    
      do {} while( !joypad() );
    
      ClearScreen();
    }
    // LatchTest()
    
    
    
    UBYTE ubCPLD_READ( UBYTE port )
    {
      return CPLD_READ(port);
    }
    // ubCPLD_READ
    
    
    
    void ubCPLD_WRITE( UBYTE port, UBYTE data )
    {
      CPLD_WRITE(port,data);
    }
    // ubCPLD_WRITE
    
    
    
    void SetPortAMode( UBYTE mode )
    {
      CPLD_WRITE( PORTA_DDR, mode );
    }
    // SetPortAMode
    
    
    
    void TogglePortAMode( void )
    {
      ubPortAMode = (ubPortAMode == PORTA_INPUT ? PORTA_OUTPUT : PORTA_INPUT);
    
      SetPortAMode( ubPortAMode );
    }
    // TogglePortAMode
    
    
    
    
    
    enum { SCOPE_PORTB, SCOPE_RAM, SCOPE_LATCHES, SCOPE_PORTA_MODE, SCOPE_ROM };
    
    
    
    void main()
    {
      UBYTE  a,b,c,d,e, pos;
      int i, iPassDir;
      UBYTE data, ubOutData, ubIndex, ubKey, ubKeyScope, ubPass, ubLedPresc;
      UBYTE ubPAOutData, ubPAIndex;
      UBYTE mask;
      char Str[20];
    
      /* Coldstart asignments */
      c=0;
      ubIndex = 8;
      ubPAIndex = 4;
      ubPAOutData = 0x12;
      ubKeyScope = SCOPE_PORTB;
      ubPass = 10;
      iPassDir = 1;
      ubLedPresc = 0;
    
      mask = RAM_ENABLE + IO_ENABLE;
      CPLD_RAMG_REGISTER( mask );
    
      // GLobals
      ubPortAMode = PORTA_INPUT;
    
      do
      {
        if( ++ubLedPresc & 0x04 )
        {
          if( mask & LED_ENABLE )
          {
    	ubLedPresc = 0;
    	mask = RAM_ENABLE + IO_ENABLE;
    	CPLD_RAMG_REGISTER( mask );
          }
          else
          {
    	ubLedPresc = 0x02;
    	mask = RAM_ENABLE + IO_ENABLE + LED_ENABLE;
    	CPLD_RAMG_REGISTER( mask );
          }
        }
    
        ubKey = joypad();
    
        CenterText( 1, "MBC5/CPLD Test" );
    
        /* I'm alive bar */
        #define LEN 30
        #define AIR 10
        if( (ubPass+=iPassDir) > YMAX-(LEN+AIR) ) iPassDir = -1;
        if( ubPass <= AIR ) iPassDir = 1;
        line( ubPass, 19, ubPass+LEN, 19 );
        color(WHITE, WHITE, SOLID);
        plot_point( ubPass-1, 19 );
        plot_point( ubPass+LEN+1, 19 );
        color(BLACK, WHITE, SOLID);
    
        SetPortAMode( ubPortAMode );
    
        pos = 3;
    
        Text( 0, pos++, "I/O input ports" );
    
    
          // Display PortA 8 bit input
          // Not selectable
        TextAttr( 0, pos++, "PORTA ", BLACK, WHITE, SOLID );
        #ifndef EMULATOR
          data = ubCPLD_READ(PORTA);
        #else
          data++;
        #endif
        DispBinary( data );
    
          // Display PortA 4 bit output if enabled
        if( ubKeyScope == SCOPE_PORTA_MODE &&
    		(ubPAIndex == 4 || ubPortAMode == PORTA_INPUT ))
          TextAttr( 0, pos++, "PORTA ", WHITE, BLACK, SOLID );
        else
          TextAttr( 0, pos++, "PORTA ", BLACK, LTGREY, SOLID );
    
        if( ubPortAMode == PORTA_INPUT )
          Text( cpx, cpy, "    ----");
        else
        {
          Text( cpx, cpy, "    ");
          DispBinaryCursor( ubPAOutData, ubPAIndex, 4 );
        }
    
    
          // Display PortC 8 bit input
        Text( 0, pos++, "PORTC ");
        #ifndef EMULATOR
          data = ubCPLD_READ(PORTC);
        #else
          ;
        #endif
        DispBinary( data );
    
    
    
        switch( ubKeyScope )
        {
    
          case SCOPE_PORTA_MODE :
          {
    	if( ubKey & J_UP )
    	{
    	  if( ubPAIndex == 4 )
    	    TogglePortAMode();
    	  else
    	    SetBit( &ubPAOutData, ubPAIndex, SET_BIT );
    	}
    	else if( ubKey & J_DOWN )
    	{
    	  if( ubPAIndex == 4 )
    	    ubKeyScope = SCOPE_PORTB;
    	  else
    	    SetBit( &ubPAOutData, ubPAIndex, CLEAR_BIT );
    	}
    	else if( ubKey & J_RIGHT && ubPortAMode == PORTA_OUTPUT )
    	{
    	  if( ubPAIndex-- == 0 )
    	    ubPAIndex = 4;
    	}
    	else if( ubKey & J_LEFT && ubPortAMode == PORTA_OUTPUT )
    	{
    	  if( ++ubPAIndex == 5 )
    	    ubPAIndex = 0;
    	}
    	break;
          }
    
          case SCOPE_PORTB :
          {
    	if( ubKey & J_UP )
    	{
    	  if( ubIndex == 8 )
    	    ubKeyScope = SCOPE_PORTA_MODE;
    	  else
    	    SetBit( &ubOutData, ubIndex, SET_BIT );
    	}
    	else if(ubKey & J_DOWN)
    	{
    	  if( ubIndex == 8 )
    	  {
    	    ubKeyScope = SCOPE_RAM;
    	  }
    	  else
    	    SetBit( &ubOutData, ubIndex, CLEAR_BIT );
    	}
    	else if( ubKey & J_LEFT )
    	{
    	  if( ++ubIndex > 8 )
    	    ubIndex = 0;
    	}
    	else if( ubKey & J_RIGHT )
    	{
    	  if( ubIndex-- == 0 )
    	    ubIndex = 8;
    	}
    
    	break;
          }
    
          case SCOPE_RAM :
          {
    	if( ubKey & J_UP )
    	{
    	  ubKeyScope = SCOPE_PORTB;
    	  ubIndex = 8;
    	}
    	else if( ubKey & J_DOWN )
    	{
    	  ubKeyScope = SCOPE_ROM;
    	}
    	else if( ubKey & J_RIGHT )
    	{
    	  RamTest();
    	}
    	break;
          }
    
          case SCOPE_ROM :
          {
    	if( ubKey & J_UP )
    	{
    	  ubKeyScope = SCOPE_RAM;
    	  ubIndex = 8;
    	}
    	else if( ubKey & J_DOWN )
    	{
    	  ubKeyScope = SCOPE_LATCHES;
    	}
    	else if( ubKey & J_RIGHT )
    	{
    	  #ifdef ROM_TEST
    	    RomTest();
    	  #endif
    	}
    
    And thats not even all of it.
     
    Last edited: 30 Oct 2004
  4. kobaj

    kobaj Banned

    Joined:
    4 Jul 2004
    Posts:
    837
    Likes Received:
    0
    Could eny one explain what the program is doing.I know its the first half but It would give me an understanding.
     
  5. madmodder

    madmodder What's a Dremel?

    Joined:
    28 Sep 2004
    Posts:
    554
    Likes Received:
    0
    Errrrrrrrrrrrrrrrrrr :worried: :eeek:

    Try a nintendo forum possibly, maybe the geeks there could help you out.. :thumb:

    It's all geek, I mean greek to me... :p
     
  6. foxx

    foxx What's a Dremel?

    Joined:
    5 Sep 2004
    Posts:
    785
    Likes Received:
    0
    The program is in C but I cant translate it. I see were your getting with this ,seeing what pins do what and the such, I hope it works out for you.
     
  7. the harlequin

    the harlequin What's a Dremel?

    Joined:
    31 Oct 2004
    Posts:
    41
    Likes Received:
    0
    This is what the program does:
    Menu Driven Test Program to test the MBC5 part and the I/O in the Xilinx CPLD.

    As for the pics:
    The top one looks like it's the main GB hardware.
    The second looks like the I/O interfaces to the CPU, how the cartridge is processed, how the power is inputed, how the button presses are processed, and how the audio is outputed.
    The third looks like how the power is supplied.
    The fourth is how the LCD display is hooked up.
    The fifth is how the memory is connected.
    The sixth is how the logic is implemented.
     
  8. TheAnimus

    TheAnimus Banned

    Joined:
    25 Dec 2003
    Posts:
    3,214
    Likes Received:
    8
    aye,

    What your best bet is, is to read up on computer systems.

    You need to get you're head round ideas such as buses, then ideas like fetch execute. Google should be able to help you there. You can't dive straight into hacking something without doing background research.
     
  9. foxx

    foxx What's a Dremel?

    Joined:
    5 Sep 2004
    Posts:
    785
    Likes Received:
    0
    You should learn c.
     
    Last edited: 31 Oct 2004
  10. kobaj

    kobaj Banned

    Joined:
    4 Jul 2004
    Posts:
    837
    Likes Received:
    0
    After plaing around I just realized that the gameboys cartrige ports have the same connecters as normal lcd.the data ports ,But I dont have my gameboy with me right at the moment could someone who has a bunch of extra time connect the data, wright,ect ports and see if that does enything.thanks.

    Edit: and program it.
     
    Last edited: 7 Nov 2004
  11. FuzzyOne

    FuzzyOne

    Joined:
    19 Sep 2002
    Posts:
    1,823
    Likes Received:
    32

    errrrrrrr yeah ok i'll do it :eyebrow:
     
  12. kobaj

    kobaj Banned

    Joined:
    4 Jul 2004
    Posts:
    837
    Likes Received:
    0
    I also notest the md0-7 in/outputs look the same.
     
  13. jgrade

    jgrade What's a Dremel?

    Joined:
    2 Mar 2004
    Posts:
    534
    Likes Received:
    0
    Take the advice and use Google. Search for a compiler for Gameboy. You will notice most compilers and hardware are for GBA. You can purchase a 256-1GB flash cart. for the GBA from $100-250(US). If you are trying to make a cart, don't waste your time, just buy one but good luck finding one for the GB. Programming for the GBA is not that difficult, but you have to know how to program. If your pressed for money, you can make a GBA to USB cable and run the program from the MultiBoot feature on the GBA. Two versions exist: one with a PIC and a dumb cable that runs from DOS. Again use Google.

    I would stop asking for someone to decipher the above schematic for you. Get a good electronics book and do some research. No one is going to take the time to do it for you. :rolleyes:
     

Share This Page