Skip to content

Commit

Permalink
add new i2c eeprom (e2prom) device, hook it up in d_coleco and megadrive
Browse files Browse the repository at this point in the history
  • Loading branch information
dinkc64 committed Jan 2, 2025
1 parent 1111159 commit 37b23dd
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 70 deletions.
2 changes: 1 addition & 1 deletion makefile.burn_rules
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ drvsrc = d_akkaarrh.o d_arcadecl.o d_atarig1.o d_badlands.o d_batman.o d_blstro
depobj = burn.o burn_bitmap.o burn_gun.o burn_led.o burn_shift.o burn_memory.o burn_pal.o burn_sound.o burn_sound_c.o cheat.o debug_track.o hiscore.o \
load.o burn_sha1.o tilemap_generic.o tiles_generic.o timer.o vector.o \
\
6821pia.o 6840ptm.o 8255ppi.o 8257dma.o c169.o atariic.o atarijsa.o atarimo.o atarirle.o atarivad.o avgdvg.o bsmt2000.o decobsmt.o ds2404.o dtimer.o earom.o eeprom.o epic12.o gaelco_crypt.o i4x00.o intelfsh.o \
6821pia.o 6840ptm.o 8255ppi.o 8257dma.o c169.o atariic.o atarijsa.o atarimo.o atarirle.o atarivad.o avgdvg.o bsmt2000.o decobsmt.o ds2404.o dtimer.o earom.o eeprom.o epic12.o gaelco_crypt.o i2ceeprom.o i4x00.o intelfsh.o \
joyprocess.o nb1414m4.o nb1414m4_8bit.o nmk004.o nmk112.o k1ge.o kaneko_hit.o kaneko_tmap.o mathbox.o mb87078.o mermaid.o midcsd.o midsat.o midsg.o midcvsd.o midssio.o midtcs.o \
namco_c45.o namcoio.o pandora.o pic8259.o pit8253.o poly.o qs1000.o resnet.o rtc9701.o seibucop.o seibusnd.o serflash.o sknsspr.o slapstic.o st0020.o t5182.o timekpr.o tlc34076.o tms34061.o v3021.o vdc.o \
tms9928a.o watchdog.o x2212.o \
Expand Down
74 changes: 62 additions & 12 deletions src/burn/drv/coleco/d_coleco.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "ay8910.h" // sgm
#include "tms9928a.h"
#include "burn_gun.h" // trackball (Roller & Super Action controllers)
#include "i2ceeprom.h"

static UINT8 *AllMem;
static UINT8 *MemEnd;
Expand Down Expand Up @@ -42,7 +43,11 @@ static UINT32 MegaCartBank; // current Bank
static UINT32 MegaCartBanks; // total banks
static INT32 OCMBanks[4];

static INT32 use_EEPROM = 0;
// for use_I2C (i2c 2-wire 24c02, +)
static INT32 d_sda;
static INT32 d_scl;

static INT32 use_I2C = 0; // i2c eeprom
static INT32 use_SGM = 0;
static INT32 use_SAC = 0; // 1 = SuperAction, 2 = ROLLER
static INT32 use_OCM = 0;
Expand Down Expand Up @@ -472,6 +477,12 @@ static INT32 DrvDoReset()

TMS9928AReset();

if (use_I2C) {
i2c_reset();
d_sda = 1;
d_scl = 1;
}

memset (DrvZ80RAM, 0xff, 0x400); // ram initialized to 0xff
if (!strncmp(BurnDrvGetTextA(DRV_NAME), "cv_heist", 8)) {
bprintf(0, _T("*** The Heist kludge..\n"));
Expand Down Expand Up @@ -528,15 +539,31 @@ static void O_EepScan()
static void __fastcall main_write(UINT16 address, UINT8 data)
{
// maybe we should support bankswitching on writes too?
// bprintf(0, _T("%x %x\t\tfr %d cyc %d\n"), address, data, nCurrentFrame, ZetTotalCycles());
if (use_EEPROM) { // for boxxle
//bprintf(0, _T("%x %x\t\tfr %d cyc %d\n"), address, data, nCurrentFrame, ZetTotalCycles());
if (use_I2C) { // for boxxle, black onyx, space shuttle, etc..
switch (address)
{
case 0xff90:
case 0xffa0:
case 0xffb0:
MegaCartBank = (address >> 4) & 3;
return;
case 0xffc0:
d_scl = 0;
i2c_write_bit(d_sda, d_scl);
return;
case 0xffd0:
d_scl = 1;
i2c_write_bit(d_sda, d_scl);
return;
case 0xffe0:
d_sda = 0;
i2c_write_bit(d_sda, d_scl);
return;
case 0xfff0:
d_sda = 1;
i2c_write_bit(d_sda, d_scl);
return;
}
}

Expand Down Expand Up @@ -621,6 +648,10 @@ static UINT8 __fastcall main_read(UINT16 address)
}
}

if (use_I2C && address == 0xff80) {
return DrvCartROM[i2c_read() ? 0xff80 : 0xbf80];
}

if (address >= 0xffc0/* && address <= 0xffff*/) {
MegaCartBank = (0xffff - address) & (MegaCartBanks - 1);

Expand Down Expand Up @@ -694,10 +725,11 @@ static INT32 DrvInit()
ZetMapMemory(DrvZ80RAM, i + 0x0000, i + 0x03ff, MAP_RAM);
}

if (use_EEPROM) { // similar to MegaCart but with diff. mapper addresses
if (use_I2C) { // similar to MegaCart but with diff. mapper addresses
// Boxxle
MegaCartBanks = MegaCart / 0x4000;
bprintf(0, _T("ColecoVision BoxxleCart mapping.\n"));
i2c_init((use_I2C == 1) ? I2C_24C02 : I2C_24C256);
ZetMapMemory(DrvCartROM, 0x8000, 0xbfff, MAP_ROM);
ZetSetReadHandler(main_read);
ZetSetWriteHandler(main_write);
Expand Down Expand Up @@ -775,10 +807,16 @@ static INT32 DrvInitSGM() // w/SGM
return DrvInit();
}

static INT32 DrvInitEEPROM() // w/EEPROM (boxxle)
static INT32 DrvInitI2CBoxxle() // w/EEPROM (boxxle)
{
// 24cXX e2prom isn't actually supported, but the game works fine (minus highscore saving)
use_EEPROM = 1;
use_I2C = 2;

return DrvInit();
}

static INT32 DrvInitI2C() // w/EEPROM (boxxle)
{
use_I2C = 1;

return DrvInit();
}
Expand All @@ -802,8 +840,12 @@ static INT32 DrvExit()

BurnTrackballExit();

if (use_I2C) {
i2c_exit();
}

use_SGM = 0;
use_EEPROM = 0;
use_I2C = 0;
use_SAC = 0;
use_OCM = 0;

Expand Down Expand Up @@ -960,13 +1002,21 @@ static INT32 DrvScan(INT32 nAction, INT32 *pnMin)
SCAN_VAR(last_state);
SCAN_VAR(MegaCartBank);
SCAN_VAR(SGM_map_24k);
SCAN_VAR(SGM_map_8k);
SCAN_VAR(SGM_map_8k);
if (use_I2C) {
SCAN_VAR(d_scl);
SCAN_VAR(d_sda);
}
}

if (nAction & ACB_NVRAM && use_OCM) {
ScanVar(DrvEEPROM, 0x400, "NV RAM");
}

if (use_I2C) {
i2c_scan(nAction, pnMin);
}

if (nAction & ACB_WRITE) {
if (use_SGM) {
ZetOpen(0);
Expand Down Expand Up @@ -5903,7 +5953,7 @@ struct BurnDriver BurnDrvcv_blackonyx = {
NULL, NULL, NULL, NULL,
BDF_GAME_WORKING | BDF_HOMEBREW, 1, HARDWARE_COLECO, GBF_RPG | GBF_MAZE, 0,
CVGetZipName, cv_blackonyxRomInfo, cv_blackonyxRomName, NULL, NULL, NULL, NULL, ColecoInputInfo, ColecoDIPInfo,
DrvInitEEPROM, DrvExit, DrvFrame, TMS9928ADraw, DrvScan, NULL, TMS9928A_PALETTE_SIZE,
DrvInitI2C, DrvExit, DrvFrame, TMS9928ADraw, DrvScan, NULL, TMS9928A_PALETTE_SIZE,
272, 228, 4, 3
};

Expand Down Expand Up @@ -6055,7 +6105,7 @@ struct BurnDriver BurnDrvcv_boxxle = {
NULL, NULL, NULL, NULL,
BDF_GAME_WORKING | BDF_HOMEBREW, 1, HARDWARE_COLECO, GBF_PUZZLE, 0,
CVGetZipName, cv_boxxleRomInfo, cv_boxxleRomName, NULL, NULL, NULL, NULL, ColecoInputInfo, ColecoDIPInfo,
DrvInitEEPROM, DrvExit, DrvFrame, TMS9928ADraw, DrvScan, NULL, TMS9928A_PALETTE_SIZE,
DrvInitI2CBoxxle, DrvExit, DrvFrame, TMS9928ADraw, DrvScan, NULL, TMS9928A_PALETTE_SIZE,
272, 228, 4, 3
};

Expand Down Expand Up @@ -10003,7 +10053,7 @@ STD_ROM_FN(cv_spaceshuttle)

static INT32 DrvInitSGMEEPROM() // Space Shuttle
{
use_EEPROM = 1;
use_I2C = 1;
use_SGM = 1;
return DrvInit();
}
Expand Down
Loading

0 comments on commit 37b23dd

Please sign in to comment.