Skip to content

Commit

Permalink
[DMG] Add IR Noise option. Useful for fusions in the SMT Devil Childr…
Browse files Browse the repository at this point in the history
…en games.
  • Loading branch information
shonumi committed Aug 28, 2024
1 parent 0ef1563 commit 659488c
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/common/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1207,7 +1207,7 @@ bool parse_ini_file()
if(!parse_ini_number(ini_item, "#sio_device", config::sio_device, ini_opts, x, 0, 20)) { return false; }

//Emulated IR device
if(!parse_ini_number(ini_item, "#ir_device", config::ir_device, ini_opts, x, 0, 7)) { return false; }
if(!parse_ini_number(ini_item, "#ir_device", config::ir_device, ini_opts, x, 0, 8)) { return false; }

//Emulated Slot1 device
if(!parse_ini_number(ini_item, "#slot1_device", config::nds_slot1_device, ini_opts, x, 0, 1)) { return false; }
Expand Down
9 changes: 9 additions & 0 deletions src/dmg/mmu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,15 @@ u8 DMG_MMU::read_u8(u16 address)
sio_stat->shifts_left = 1;
}

//Change IR light status randomly for IR Noise option
if(sio_stat->ir_type == GBC_IR_NOISE)
{
u8 noise = (rand() & 0x1);

if(noise) { memory_map[address] &= ~0x2; }
else { memory_map[address] |= 0x2; }
}

//If Bits 6 and 7 are not set, treat Bit 1 as HIGH
if((memory_map[address] & 0xC0) == 0) { return memory_map[address] | 0x2; }

Expand Down
5 changes: 5 additions & 0 deletions src/dmg/sio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,11 @@ void DMG_SIO::reset()
sio_stat.ir_type = GBC_LIGHT_SOURCE;
break;

//IR Noise
case 8:
sio_stat.ir_type = GBC_IR_NOISE;
break;

//Use standard GBC IR port communication as the default (GBE+ will ignore it for DMG games)
//Also, any invalid types are ignored
default:
Expand Down
1 change: 1 addition & 0 deletions src/dmg/sio_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ enum ir_types
GBC_POCKET_SAKURA,
GBC_TV_REMOTE,
GBC_LIGHT_SOURCE,
GBC_IR_NOISE,
};

enum printer_state
Expand Down
2 changes: 1 addition & 1 deletion src/gbe.ini
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
//Emulated infrared device
//0 - GBC IR port (or nothing for DMG games), 1 - Full Changer (Zok Zok Heroes), 2 - Pokemon Pikachu 2
//3 - Pocket Sakura, 4 - TV Remote, 5 - Constant Light Source (Chee Chai Alien)
//6 - Zoids CDZ Model, 7 - NTR-027 Activity Meter
//6 - Zoids CDZ Model, 7 - NTR-027 Activity Meter, 8 - IR Noise
[#ir_device:0]

//Emulated NDS Slot1 device
Expand Down

1 comment on commit 659488c

@shonumi
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should fix Issue #168. In my testing, it allows the fusions + mutations in SMT:DC. Mutations are not always successful (since the input is randomized), but I have observed at least 4 different types of mutation from the same fusion using save states.

Unlike the current TV Remote option (which randomizes a fixed set of ON/OFF pulses for a number of CPU cycles), IR Noise randomizes the status of IR input each time the CPU reads the RP register.

Please sign in to comment.