mic_ wrote:I got that GB emulator compiling and running... I notice that it currently only accepts 1 rom - probably because the GUI isn't complete. When I compiled with 3 roms, it didn't work. It took my a while to figure out it wasn't that it wasn't compiling, it was that I could only use one rom.
Sort of. The GB roms are compiled into the SH2 binary, which is loaded into SDRAM. So the roms must have a maximum combined size of 256kB, minus the size of the SH2 code/data and the reserved stack size.
Ah! That makes sense... I thought the roms stayed in the rom area. Copying to SDRAM makes it faster, but limits you quite a bit on what roms you can use. No wonder no 512K roms worked!
As long as that condition is met you should be able to add as many roms as you want, but it'll only load one of them right now (the "load_rom(0)" call in fuboy.c, which loads the first rom in the rom table). Only two kinds of memory bank controllers are emulated at the moment though; MBC1 and MBC2, so a rom using something else won't run properly.
I'm only partly interested in working on this... I was mostly just testing my development environment to see if it was working right.
However, I did try adding controller support...
In 32x.h, add
Code: Select all
#define MARS_SYS_COMM7 (*(vu16*)0x2000402E)
In memory.c, alter the mem_read_8_F000 as follows
Code: Select all
if (address==0xFF00) {
u16 pad = MARS_SYS_COMM7;
keys = (pad & 0xF0) | ((pad & 0x03) <<2) | ((pad & 0x04) >> 1) | ((pad & 0x08) >> 3);
if ((IOREGS[0]&0x30)==0x10)
return (IOREGS[0]&0xF0)|((keys>>4)&0xF);
else if ((IOREGS[0]&0x30)==0x20)
return (IOREGS[0]&0xF0)|(keys&0xF);
else
return IOREGS[0];
And in 32x_68k_crt0.s, add the following at main:
Code: Select all
* init joyports
move.b #0x40,0xA10009
move.b #0x40,0xA1000B
move.b #0x40,0xA1000D
forever:
* wait on vsync
*vshloop:
* move.w 0xC00004,d0
* andi.w #0x0008,d0
* bne vshloop
*vslloop:
* move.w 0xC00004,d0
* andi.w #0x0008,d0
* beq vslloop
move.l #400000,d0
dloop:
dbra d0,dloop
* read 3-button controller
move.b #0x40,0xA10003
nop
nop
move.b 0xA10003,d0
move.b #0x00,0xA10003
nop
nop
move.b 0xA10003,d1
andi.w #0x3F,d0
andi.w #0x30,d1
lsl.w #2,d1
or.w d1,d0 /* /St /C /B /A /R /L /D /U */
move.w d0,0xA1512E /* set comm port 7 to controller value */
jmp forever
Note that the wait on vsync is commented out... for some reason, it doesn't work with gens (what I've been using for testing this). I just stuck a busy loop in instead and that works with gens. I figured the 68000 wasn't doing anything other than jmp forever, so why not have it poll the joystick once a frame (you're only supposed to read the stick once per frame on real hardware or the stick won't/may not return proper data). I then stick the controller value in one of the comm registers where the SH2 running the emu can use it to set the key variable. Works like a charm, but I'm still a bit puzzled over the wait for vsync failure.