Sdl Version Of Visual Boy Advanced


I have the main code compiling on my linux box (takes about 3 min) but I have not looked at the core code section yet so this looks encouraging. Right now I have the MMU hack and allocating a 16 mb rom in the upper 32 mb's but it keeps crashing in the SDL_JOYSTICK init code and I am not sure why. I have cut over 200 mb of code and dropped the size of the data structures considerably but without getting in further I am not sure if efforts will work. My debug environment is not working the way it used to so I could have screwed the environment up while doing other work. I am using the insight debugger running on my laptop connect over TCP/IP to the gp2x running the gdbserver connected to the stripped VisualBoyAdvanced code. I was able to set break points and do other stuff but the connection to the gdbserver is working but the handshake appears to be failing.

To reduce the side I made it so when compiling without gba appliction debugging all of the instruction printing and other debug support is not compiled in (all this is not needed to run gba code). The version I am using was based on the 1.8.0 version of the VisualBoyAdvanced (fixed and debugging enhanced) so I test to make sure it still works on other platforms as I change.
 
Gary Miller posted on Oct 29 2006 at 06:24 PM said:
I have the main code compiling on my linux box (takes about 3 min) but I have not looked at the core code section yet so this looks encouraging. Right now I have the MMU hack and allocating a 16 mb rom in the upper 32 mb's but it keeps crashing in the SDL_JOYSTICK init code and I am not sure why. I have cut over 200 mb of code and dropped the size of the data structures considerably but without getting in further I am not sure if efforts will work. My debug environment is not working the way it used to so I could have screwed the environment up while doing other work. I am using the insight debugger running on my laptop connect over TCP/IP to the gp2x running the gdbserver connected to the stripped VisualBoyAdvanced code. I was able to set break points and do other stuff but the connection to the gdbserver is working but the handshake appears to be failing.

To reduce the side I made it so when compiling without gba appliction debugging all of the instruction printing and other debug support is not compiled in (all this is not needed to run gba code). The version I am using was based on the 1.8.0 version of the VisualBoyAdvanced (fixed and debugging enhanced) so I test to make sure it still works on other platforms as I change.
I use -O3 so that may be why its so slow compiling. I had it crashing when I used one of the more recent versions of Paeryn's SDL libs cause I think he started to make use of the first 16MB of the upper mem.
I also noticed that there is a big slow down when the gp2x network is connected to the pc via usb even though I did not switch on debugging features.
 
Last edited by a moderator:
So can things like this be further optimized?
Code:
/*#define OP_EORS \
	  reg[dest].I = reg[(opcode>>16)&15].I ^ value;\
	  \
	  N_FLAG = (reg[dest].I & 0x80000000) ? true : false;\
	  Z_FLAG = (reg[dest].I) ? false : true;\
	  C_FLAG = C_OUT;
*/
#define OP_EORS \
	  asm("eor %0, %1, %2\n": "=r" (reg[dest].I):"r" (reg[(opcode>>16)&15].I), "r" (value) : "r0","r1","r2","r3" ); \
	  N_FLAG = (reg[dest].I & 0x80000000) ? true : false;\
	  Z_FLAG = (reg[dest].I) ? false : true;\
	  C_FLAG = C_OUT;

what about this?
Code:
#define NEG(i) ((i) >> 31)
#define POS(i) ((~(i)) >> 31)
#define ADDCARRY(a, b, c) \
  C_FLAG = ((NEG(a) & NEG(b)) |\
			(NEG(a) & POS(c)) |\
			(NEG(b) & POS(c))) ? true : false;
#define ADDOVERFLOW(a, b, c) \
  V_FLAG = ((NEG(a) & NEG(b) & POS(c)) |\
			(POS(a) & POS(b) & NEG(c))) ? true : false;
#define SUBCARRY(a, b, c) \
  C_FLAG = ((NEG(a) & POS(b)) |\
			(NEG(a) & POS(c)) |\
			(POS(b) & POS(c))) ? true : false;
#define SUBOVERFLOW(a, b, c)\
  V_FLAG = ((NEG(a) & POS(b) & POS(c)) |\
			(POS(a) & NEG(b) & NEG(c))) ? true : false;

//#define OP_SUB {reg[dest].I = reg[base].I - value;}
#define OP_SUB {asm("sub %0, %1, %2\n": "=r" (reg[dest].I):"r" (reg[base].I), "r" (value) : "r0","r1","r2","r3" );}

#define OP_SUBS \
   {\
	 u32 lhs = reg[base].I;\
	 u32 rhs = value;\
	 u32 res = lhs - rhs;\
	 reg[dest].I = res;\
	 Z_FLAG = (res == 0) ? true : false;\
	 N_FLAG = NEG(res) ? true : false;\
	 SUBCARRY(lhs, rhs, res);\
	 SUBOVERFLOW(lhs, rhs, res);\
   }
 
and these

Code:
#define LOGICAL_LSL_REG \
   {\
	 u32 v = reg[opcode & 0x0f].I;\
	 C_OUT = (v >> (32 - shift)) & 1 ? true : false;\
	 value = v << shift;\
   }
 
#define ARITHMETIC_RRX_REG \
   {\
	 u32 v = reg[opcode & 0x0f].I;\
	 shift = (int)C_FLAG;\
	 value = ((v >> 1) |\
			  (shift << 31));\
   }

#define OP_TST \
	  u32 res = reg[base].I & value;\
	  N_FLAG = (res & 0x80000000) ? true : false;\
	  Z_FLAG = (res) ? false : true;\
	  C_FLAG = C_OUT;
 
Which of the SDL library archives is used generally by developers. The problems I am having with the vba emulator seem to be related to the SDL code doing some strange things.
 
Gary Miller posted on Oct 30 2006 at 09:46 PM said:
Which of the SDL library archives is used generally by developers. The problems I am having with the vba emulator seem to be related to the SDL code doing some strange things.
the one by guy fawkes works for me. SDL libs v211006
 
Last edited by a moderator:
Any suggestions how to improve this? Would it be better if the flags could be stored and restored as one 32bit value rather than separately? Is it better to set the flags in C or to change to assembler?

Code:
#define OP_AND asm("and %0, %1, %2\n": "=r" (reg[dest].I):"r" (reg[(opcode>>16)&15].I), "r" (value) : "r0","r1","r2","r3" );

#define OP_ANDS asm("and %0, %1, %2\n": "=r" (reg[dest].I):"r" (reg[(opcode>>16)&15].I), "r" (value) : "r0","r1","r2","r3" );\
	  N_FLAG = (reg[dest].I & 0x80000000) ? true : false;\
	  Z_FLAG = (reg[dest].I) ? false : true;\
	  C_FLAG = C_OUT;

#define OP_EOR asm("eor %0, %1, %2\n": "=r" (reg[dest].I):"r" (reg[(opcode>>16)&15].I), "r" (value) : "r0","r1","r2","r3" );

#define OP_EORS \
	  asm("eor %0, %1, %2\n": "=r" (reg[dest].I):"r" (reg[(opcode>>16)&15].I), "r" (value) : "r0","r1","r2","r3" ); \
	  N_FLAG = (reg[dest].I & 0x80000000) ? true : false;\
	  Z_FLAG = (reg[dest].I) ? false : true;\
	  C_FLAG = C_OUT;

#define NEG(i) ((i) >> 31)
#define POS(i) ((~(i)) >> 31)
#define ADDCARRY(a, b, c) \
  C_FLAG = ((NEG(a) & NEG(b)) |\
			(NEG(a) & POS(c)) |\
			(NEG(b) & POS(c))) ? true : false;
#define ADDOVERFLOW(a, b, c) \
  V_FLAG = ((NEG(a) & NEG(b) & POS(c)) |\
			(POS(a) & POS(b) & NEG(c))) ? true : false;
#define SUBCARRY(a, b, c) \
  C_FLAG = ((NEG(a) & POS(b)) |\
			(NEG(a) & POS(c)) |\
			(POS(b) & POS(c))) ? true : false;
#define SUBOVERFLOW(a, b, c)\
  V_FLAG = ((NEG(a) & POS(b) & POS(c)) |\
			(POS(a) & NEG(b) & NEG(c))) ? true : false;

#define OP_SUB {asm("sub %0, %1, %2\n": "=r" (reg[dest].I):"r" (reg[base].I), "r" (value) : "r0","r1","r2","r3" );}

#define OP_SUBS \
	{\
	  asm("subs %0, %5, %6\n" \
	  "mrs r0,cpsr\n"\
	  "mov r1,r0,lsr#30\n"\
	  "and %1,r1,#1\n"\
	  "mov r1,r0,lsr#31\n"\
	  "and %2,r1,#1\n"\
	  "mov r1,r0,lsr#29\n"\
	  "and %3,r1,#1\n"\
	  "mov r1,r0,lsr#28\n"\
	  "and %4,r1,#1\n"\
	  :"=r" (reg[dest].I),"=r" (Z_FLAG),"=r"(N_FLAG), "=r"(C_FLAG),"=r" (V_FLAG)\
	  :"r" (reg[base].I), "r" (value) : "r0","r1","r2","r3" );}

#define OP_RSB {asm("rsb %0, %1, %2\n": "=r" (reg[dest].I):"r" (reg[base].I), "r" (value) : "r0","r1","r2","r3" );}

#define OP_RSBS \
	{\
	  asm("rsbs %0, %5, %6\n" \
	  "mrs r0,cpsr\n"\
	  "mov r1,r0,lsr#30\n"\
	  "and %1,r1,#1\n"\
	  "mov r1,r0,lsr#31\n"\
	  "and %2,r1,#1\n"\
	  "mov r1,r0,lsr#29\n"\
	  "and %3,r1,#1\n"\
	  "mov r1,r0,lsr#28\n"\
	  "and %4,r1,#1\n"\
	  :"=r" (reg[dest].I),"=r" (Z_FLAG),"=r"(N_FLAG), "=r"(C_FLAG),"=r" (V_FLAG)\
	  :"r" (reg[base].I), "r" (value) : "r0","r1","r2","r3" );}   

#define OP_ADD {asm("add %0, %1, %2\n": "=r" (reg[dest].I):"r" (reg[base].I), "r" (value) : "r0","r1","r2","r3" );}

#define OP_ADDS \
	{\
	  asm("adds %0, %5, %6\n" \
	  "mrs r0,cpsr\n"\
	  "mov r1,r0,lsr#30\n"\
	  "and %1,r1,#1\n"\
	  "mov r1,r0,lsr#31\n"\
	  "and %2,r1,#1\n"\
	  "mov r1,r0,lsr#29\n"\
	  "and %3,r1,#1\n"\
	  "mov r1,r0,lsr#28\n"\
	  "and %4,r1,#1\n"\
	  :"=r" (reg[dest].I),"=r" (Z_FLAG),"=r"(N_FLAG), "=r"(C_FLAG),"=r" (V_FLAG)\
	  :"r" (reg[base].I), "r" (value) : "r0","r1","r2","r3" );}   

#define OP_ADC {reg[dest].I = reg[base].I + value + (u32)C_FLAG;}

#define OP_ADCS \
   {\
	 u32 lhs = reg[base].I;\
	 u32 rhs = value;\
	 u32 res = lhs + rhs + (u32)C_FLAG;\
	 reg[dest].I = res;\
	 Z_FLAG = (res == 0) ? true : false;\
	 N_FLAG = NEG(res) ? true : false;\
	 ADDCARRY(lhs, rhs, res);\
	 ADDOVERFLOW(lhs, rhs, res);\
   }

#define OP_SBC {reg[dest].I = reg[base].I - value - !((u32)C_FLAG);}

#define OP_SBCS {\
	 u32 lhs = reg[base].I;\
	 u32 rhs = value;\
	 u32 res = lhs - rhs - !((u32)C_FLAG);\
	 reg[dest].I = res;\
	 Z_FLAG = (res == 0) ? true : false;\
	 N_FLAG = NEG(res) ? true : false;\
	 SUBCARRY(lhs, rhs, res);\
	 SUBOVERFLOW(lhs, rhs, res);\
   }
#define OP_RSC {reg[dest].I = value - reg[base].I - !((u32)C_FLAG);}

#define OP_RSCS \
   {\
	 u32 lhs = reg[base].I;\
	 u32 rhs = value;\
	 u32 res = rhs - lhs - !((u32)C_FLAG);\
	 reg[dest].I = res;\
	 Z_FLAG = (res == 0) ? true : false;\
	 N_FLAG = NEG(res) ? true : false;\
	 SUBCARRY(rhs, lhs, res);\
	 SUBOVERFLOW(rhs, lhs, res);\
   }

#define OP_CMP \
	{\
	  asm("cmp %4, %5\n" \
	  "mrs r0,cpsr\n"\
	  "mov r1,r0,lsr#30\n"\
	  "and %0,r1,#1\n"\
	  "mov r1,r0,lsr#31\n"\
	  "and %1,r1,#1\n"\
	  "mov r1,r0,lsr#29\n"\
	  "and %2,r1,#1\n"\
	  "mov r1,r0,lsr#28\n"\
	  "and %3,r1,#1\n"\
	  :"=r" (Z_FLAG),"=r"(N_FLAG), "=r"(C_FLAG),"=r" (V_FLAG)\
	  :"r" (reg[base].I), "r" (value) : "r0","r1","r2","r3" );}  

#define OP_CMN \
	{\
	  asm("cmn %4, %5\n" \
	  "mrs r0,cpsr\n"\
	  "mov r1,r0,lsr#30\n"\
	  "and %0,r1,#1\n"\
	  "mov r1,r0,lsr#31\n"\
	  "and %1,r1,#1\n"\
	  "mov r1,r0,lsr#29\n"\
	  "and %2,r1,#1\n"\
	  "mov r1,r0,lsr#28\n"\
	  "and %3,r1,#1\n"\
	  :"=r" (reg[dest].I),"=r" (Z_FLAG),"=r"(N_FLAG), "=r"(C_FLAG),"=r" (V_FLAG)\
	  :"r" (reg[base].I), "r" (value) : "r0","r1","r2","r3" );}  

#define LOGICAL_LSL_REG \
   {\
	 u32 v = reg[opcode & 0x0f].I;\
	 C_OUT = (v >> (32 - shift)) & 1 ? true : false;\
	 value = v << shift;\
   }
#define LOGICAL_LSR_REG \
   {\
	 u32 v = reg[opcode & 0x0f].I;\
	 C_OUT = (v >> (shift - 1)) & 1 ? true : false;\
	 value = v >> shift;\
   }
#define LOGICAL_ASR_REG \
   {\
	 u32 v = reg[opcode & 0x0f].I;\
	 C_OUT = ((s32)v >> (int)(shift - 1)) & 1 ? true : false;\
	 value = (s32)v >> (int)shift;\
   }
#define LOGICAL_ROR_REG \
   {\
	 u32 v = reg[opcode & 0x0f].I;\
	 C_OUT = (v >> (shift - 1)) & 1 ? true : false;\
	 value = ((v << (32 - shift)) | (v >> shift));\
   }
#define LOGICAL_RRX_REG \
   {\
	 u32 v = reg[opcode & 0x0f].I;\
	 shift = (int)C_FLAG;\
	 C_OUT = (v  & 1) ? true : false;\
	 value = ((v >> 1) |\
			  (shift << 31));\
   }
#define LOGICAL_ROR_IMM \
   {\
	 u32 v = opcode & 0xff;\
	 C_OUT = (v >> (shift - 1)) & 1 ? true : false;\
	 value = ((v << (32 - shift)) |\
			  (v >> shift));\
   }
#define ARITHMETIC_LSL_REG \
   {\
	 u32 v = reg[opcode & 0x0f].I;\
	 value = v << shift;\
   }
#define ARITHMETIC_LSR_REG \
   {\
	 u32 v = reg[opcode & 0x0f].I;\
	 value = v >> shift;\
   }
#define ARITHMETIC_ASR_REG \
   {\
	 u32 v = reg[opcode & 0x0f].I;\
	 value = (s32)v >> (int)shift;\
   }
#define ARITHMETIC_ROR_REG \
   {\
	 u32 v = reg[opcode & 0x0f].I;\
	 value = ((v << (32 - shift)) |(v >> shift));\
   }
#define ARITHMETIC_RRX_REG \
   {\
	 u32 v = reg[opcode & 0x0f].I;\
	 shift = (int)C_FLAG;\
	 value = ((v >> 1) |\
			  (shift << 31));\
   }
#define ARITHMETIC_ROR_IMM \
   {\
	 u32 v = opcode & 0xff;\
	 value = ((v << (32 - shift)) |\
			  (v >> shift));\
   }
#define ROR_IMM_MSR \
   {\
	 u32 v = opcode & 0xff;\
	 value = ((v << (32 - shift)) |\
			  (v >> shift));\
   }
#define ROR_VALUE {value = ((value << (32 - shift)) |  (value >> shift));}

#define RCR_VALUE \
   {\
	 shift = (int)C_FLAG;\
	 value = ((value >> 1) |\
			  (shift << 31));\
   }
#define OP_TST \
	  u32 res = reg[base].I & value;\
	  N_FLAG = (res & 0x80000000) ? true : false;\
	  Z_FLAG = (res) ? false : true;\
	  C_FLAG = C_OUT;

#define OP_TEQ \
	  u32 res = reg[base].I ^ value;\
	  N_FLAG = (res & 0x80000000) ? true : false;\
	  Z_FLAG = (res) ? false : true;\
	  C_FLAG = C_OUT;

#define OP_ORR {asm("orr %0, %1, %2\n": "=r" (reg[dest].I):"r" (reg[base].I), "r" (value) :"r0","r1","r2","r3");}

#define OP_ORRS {asm("orr %0, %1, %2\n": "=r" (reg[dest].I):"r" (reg[base].I), "r" (value) :"r0","r1","r2","r3");}\
	N_FLAG = (reg[dest].I & 0x80000000) ? true : false;\
	Z_FLAG = (reg[dest].I) ? false : true;\
	C_FLAG = C_OUT;

#define OP_MOV asm("mov %0, %1\n":"=r" (reg[dest].I): "r" (value) : "r0","r1","r2","r3"); 

#define OP_MOVS asm("mov %0, %1\n":"=r" (reg[dest].I): "r" (value) : "r0","r1","r2","r3"); \
	N_FLAG = (reg[dest].I & 0x80000000) ? true : false;\
	Z_FLAG = (reg[dest].I) ? false : true;\
	C_FLAG = C_OUT;

#define OP_BIC {asm("bic %0, %1, %2\n": "=r" (reg[dest].I):"r" (reg[base].I), "r" (value) : "r0","r1","r2","r3" );}

#define OP_BICS {asm("bic %0, %1, %2\n": "=r" (reg[dest].I):"r" (reg[base].I), "r" (value) : "r0","r1","r2","r3" );} \
	N_FLAG = (reg[dest].I & 0x80000000) ? true : false;\
	Z_FLAG = (reg[dest].I) ? false : true;\
	C_FLAG = C_OUT;

#define OP_MVN {asm("mvn %0, %1\n":"=r" (reg[dest].I): "r" (value) : "r0","r1","r2","r3" );}

#define OP_MVNS {asm("mvn %0, %1\n":"=r" (reg[dest].I): "r" (value) : "r0","r1","r2","r3" );}\
	N_FLAG = (reg[dest].I & 0x80000000) ? true : false;\
	Z_FLAG = (reg[dest].I) ? false : true;\
	C_FLAG = C_OUT;
 
pcklee123 posted on Oct 30 2006 at 06:18 PM said:
Gary Miller posted on Oct 30 2006 at 09:46 PM said:
Which of the SDL library archives is used generally by developers. The problems I am having with the vba emulator seem to be related to the SDL code doing some strange things.
the one by guy fawkes works for me. SDL libs v211006

Thanks I try that.
 
Last edited by a moderator:
Gary Miller posted on Oct 31 2006 at 07:56 AM said:
pcklee123 posted on Oct 30 2006 at 06:18 PM said:
Gary Miller posted on Oct 30 2006 at 09:46 PM said:
Which of the SDL library archives is used generally by developers. The problems I am having with the vba emulator seem to be related to the SDL code doing some strange things.
the one by guy fawkes works for me. SDL libs v211006

Thanks I try that.

I have tried just about every set that is out there and I just prefer the Official version of the sdk if you haven't tried that out yet it works very well with with everything except the HW surfaces. Overclocking and the mmu hack works great with it.

Hope this helps.
 
Last edited by a moderator:
GP2X_Coder posted on Oct 31 2006 at 08:25 AM said:
I have tried just about every set that is out there and I just prefer the Official version of the sdk if you haven't tried that out yet it works very well with with everything except the HW surfaces. Overclocking and the mmu hack works great with it.

Hope this helps.

Thanks ... this give me an alternate.
 
Last edited by a moderator:
If anyone has this compiling with the official SDK for windows can someone upload either the makefile or the project for Dev-c++
 
If anyone has this compiling with the official SDK for windows can someone upload either the makefile or the project for Dev-c++
I am trying it out now. I made a new project, closed the main.cpp which dev-c++ made automatically. copied all the source code files have to be careful with the parameter e.g. -DC_CORE -DSDL etc
 
Last edited by a moderator:
If anyone has this compiling with the official SDK for windows can someone upload either the makefile or the project for Dev-c++
I am trying it out now. I made a new project, closed the main.cpp which dev-c++ made automatically. copied all the source code files have to be careful with the parameter e.g. -DC_CORE -DSDL etc

`SDL_GP2X_Display' was not declared in this scope
`SDL_GP2X_MiniDisplay' was not declared in this scope
these are from Paeryn's libs. should comment them out if you dont use PAeryn's libs
problem with memgzio.c
 
Last edited by a moderator:
If anyone has this compiling with the official SDK for windows can someone upload either the makefile or the project for Dev-c++
I am trying it out now. I made a new project, closed the main.cpp which dev-c++ made automatically. copied all the source code files have to be careful with the parameter e.g. -DC_CORE -DSDL etc

`SDL_GP2X_Display' was not declared in this scope
`SDL_GP2X_MiniDisplay' was not declared in this scope
these are from Paeryn's libs. should comment them out if you dont use PAeryn's libs
problem with memgzio.c
manually change makefile.gp2x created by dev-c++ to be compiled by CC rather than CPP. It should complete.
If you want I can zip and send to you by e-mail.
 
Last edited by a moderator:
manually change makefile.gp2x created by dev-c++ to be compiled by CC rather than CPP. It should complete.
If you want I can zip and send to you by e-mail.
if you do rebuild all, you need to change the makefile again as dev-c++ will redo the makefile
 
just had to mention i had to change the sdl video settings to use the software renderer as the hardware one made the images look like shit, and wouldnt the software one be quicker anyway seeing as there is alot of pixel changes to the surface every second?
 
great. I think you are right unless you do fullscreen stretching in c. with hardware, this is done without any appreciable effort. I guess I can stop now cause I seem to be causing more problems with the recent changes than I am solving.
 
Back
Top