Skip to content

Commit

Permalink
The new SNES2Atari scheme for the 7800 is supported. Choose this as a…
Browse files Browse the repository at this point in the history
… controller type for the few games that utilize it. Hopefully more will follow!
  • Loading branch information
wavemotion-dave committed Nov 17, 2022
1 parent 4abfabf commit 455e2d2
Show file tree
Hide file tree
Showing 11 changed files with 150 additions and 90 deletions.
Binary file modified A7800DS.nds
Binary file not shown.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION=4.4
VERSION=4.4a
TARGNAME=A7800DS

#---------------------------------------------------------------------------------
Expand Down
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,22 @@ Controls :
* B : Fire button 2
* SELECT : SELECT Button
* START : PAUSE Button
* X : FPS Display
* Y : Fire Button 1 (for those that prefer not using A)
* X : Fire button 2
* Y : Fire Button 1
* L/R + DPAD : Used to Shift Offsets and Scale Screen to desired ratio

Use stylus on buttons for other actions on bottom screen.

The new SNES2Atari adaptor is supported as a controller type for the few new games
that utilize it. This allows all of the DS buttons to map into the game - exactly
as labeled (D-Pad plus ABXY, Left Shoulder, Right Shoulder and Start, Select).

High Score Saving works if you have highscore.rom (exact name and case) in your
roms directory where you load your games... also, you MUST press the HSC button
if you want to snap the Saved Scores out to the flash card. It's not something
I want to do as the game runs... so you must do it... the high scores will also
auto-save if you quit the emulator or select a new game.

Configuration :
----------
Generally you would use this to select a bankswitching scheme if the proper type wasn't auto-detected.
Expand Down Expand Up @@ -140,6 +144,9 @@ Updates by wavemotion-dave: https://github.com/wavemotion-dave/A7800DS
--------------------------------------------------------------------------------
History :
--------------------------------------------------------------------------------
V4.4a : XX-YYYY-2022 by wavemotion-dave
* SNES2Atari adaptor supported.

V4.4 : 14-Nov-2022 by wavemotion-dave
* New palette options from the Trebor 'Pro Pack' of colors. COOL, WARM (default), and HOT allow you to shift the color temperature slightly on a per-game basis.
* Improved sound channel mixing so as not to halve the volume when mixing POKEY + TIA.
Expand Down
86 changes: 56 additions & 30 deletions arm9/source/a7800utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ u16 bEmulatorRun __attribute__((section(".dtcm"))) = 1;
extern u32 tiaBufIdx;
char fpsbuf[33];

u32 snes_adaptor __attribute__((section(".dtcm")))=0x0000FFFF;

// -----------------------------------------------------------------
// Some vars for listing filenames of ROMs... 1K of ROMs is plenty
// -----------------------------------------------------------------
Expand Down Expand Up @@ -896,11 +898,15 @@ ITCM_CODE void dsMainLoop(void)
if (dsWaitOnQuit()) emu_state=A7800_QUITSTDS;
else SoundUnPause();
}
else if ((iTx>240) && (iTx<256) && (iTy>0) && (iTy<20)) { // Full Speed Toggle ... upper corner...
else if ((iTx>240) && (iTx<256) && (iTy>0) && (iTy<20)) { // Full Speed Toggle ... upper right corner...
full_speed = 1-full_speed;
if (full_speed) dsPrintValue(30,0,0,"FS"); else dsPrintValue(30,0,0," ");
dampen=60;
}
else if ((iTx>=0) && (iTx<16) && (iTy>0) && (iTy<20)) { // FPS Toggle ... upper left corner...
fpsDisplay = 1-fpsDisplay; gTotalAtariFrames=0; if (!fpsDisplay) dsPrintValue(0,0,0," ");
dampen=60;
}
else if ((iTx>63) && (iTx<105) && (iTy>154) && (iTy<171)) { // 72,160 -> 105,168 PAUSE
if (keys_touch == 0) mmEffect(SFX_KEYCLICK); // Play short key click for feedback...
tchepres(10);
Expand Down Expand Up @@ -950,11 +956,13 @@ ITCM_CODE void dsMainLoop(void)
if (keys_pressed != last_keys_pressed)
{
last_keys_pressed = keys_pressed;
if ( (keys_pressed & KEY_SELECT) ) { tchepres(11); } // BUTTON SELECT
if (myCartInfo.cardctrl1 != TWIN)
if ((myCartInfo.cardctrl1 != SNES))
{
if ( (keys_pressed & KEY_SELECT) ) { tchepres(11); } // BUTTON SELECT
}
if ((myCartInfo.cardctrl1 != TWIN) && (myCartInfo.cardctrl1 != SNES))
{
if ( (keys_pressed & KEY_START) ) {tchepres(10);} // BUTTON PAUSE
if ( (keys_pressed & KEY_X) ) { fpsDisplay = 1-fpsDisplay; gTotalAtariFrames=0; if (!fpsDisplay) dsPrintValue(0,0,0," ");}
}
if (myCartInfo.cardctrl1 == SOTA)
{
Expand All @@ -965,11 +973,13 @@ ITCM_CODE void dsMainLoop(void)
}
} else dampen--;

snes_adaptor = 0x0000FFFF; // Nothing pressed to start

// manage a7800 pad
if ( (keys_pressed & KEY_UP) ) { tchepres(0); } // UP
if ( (keys_pressed & KEY_DOWN) ) { tchepres(1); } // DOWN
if ( (keys_pressed & KEY_RIGHT) ) { tchepres(3); } // RIGHT
if ( (keys_pressed & KEY_LEFT) ) { tchepres(2); } // LEFT
if ( (keys_pressed & KEY_UP) ) { tchepres(0); snes_adaptor &= 0xFFEF;} // UP
if ( (keys_pressed & KEY_DOWN) ) { tchepres(1); snes_adaptor &= 0xFFDF;} // DOWN
if ( (keys_pressed & KEY_LEFT) ) { tchepres(2); snes_adaptor &= 0xFFBF;} // LEFT
if ( (keys_pressed & KEY_RIGHT) ) { tchepres(3); snes_adaptor &= 0xFF7F;} // RIGHT

if (myCartInfo.cardctrl1 == TWIN)
{
Expand All @@ -979,35 +989,51 @@ ITCM_CODE void dsMainLoop(void)
if ( (keys_pressed & KEY_Y) ) { tchepres(14); } // Left Joystick Left
if ( (keys_pressed & KEY_START) ) { tchepres(4); } // Fire Button (mainly to enter high scores and start game)
}
else
else if (myCartInfo.cardctrl1 == SNES)
{
if ( (keys_pressed & KEY_A) ) { snes_adaptor &= 0xFEFF;} // SNES BUTTON A
if ( (keys_pressed & KEY_B) ) { snes_adaptor &= 0xFFFE;} // SNES BUTTON B
if ( (keys_pressed & KEY_Y) ) { snes_adaptor &= 0xFFFD;} // SNES BUTTON Y
if ( (keys_pressed & KEY_X) ) { snes_adaptor &= 0xFDFF;} // SNES BUTTON X

if ( (keys_pressed & KEY_L) ) {snes_adaptor &= 0xFBFF;} // SNES Left Shoulder
if ( (keys_pressed & KEY_R) ) {snes_adaptor &= 0xF7FF;} // SNES Right Shoulder
if ( (keys_pressed & KEY_START) ) {snes_adaptor &= 0xFFF7;} // SNES Start
if ( (keys_pressed & KEY_SELECT) ) {snes_adaptor &= 0xFFFB;} // SNES Select
}
else // Just normal Proline Joystick handling
{
if ( (keys_pressed & KEY_A) ) { tchepres(4); } // BUTTON #1
if ( (keys_pressed & KEY_B) ) { tchepres(5); } // BUTTON #2
if ( (keys_pressed & KEY_Y) ) { tchepres(4); } // BUTTON #1
if ( (keys_pressed & KEY_A) ) { tchepres(4); snes_adaptor &= 0xFEFF;} // BUTTON #1
if ( (keys_pressed & KEY_B) ) { tchepres(5); snes_adaptor &= 0xFFFE;} // BUTTON #2
if ( (keys_pressed & KEY_Y) ) { tchepres(4); snes_adaptor &= 0xFFFD;} // BUTTON #1
if ( (keys_pressed & KEY_X) ) { tchepres(5); snes_adaptor &= 0xFDFF;} // BUTTON #2
}

if ((keys_pressed & KEY_R) || (keys_pressed & KEY_L))
{
if ((keys_pressed & KEY_R) && (keys_pressed & KEY_L))
if (myCartInfo.cardctrl1 != SNES)
{
if (++lcd_swap_counter == 30)
if ((keys_pressed & KEY_R) && (keys_pressed & KEY_L))
{
if (keys_pressed & KEY_A) lcdSwap();
}
}
if (scale_screen_dampen > 5)
{
if ((keys_pressed & KEY_R) && (keys_pressed & KEY_UP)) { myCartInfo.yOffset++; bRefreshXY = true; }
if ((keys_pressed & KEY_R) && (keys_pressed & KEY_DOWN)) { myCartInfo.yOffset--; bRefreshXY = true; }
if ((keys_pressed & KEY_R) && (keys_pressed & KEY_LEFT)) { myCartInfo.xOffset++; bRefreshXY = true; }
if ((keys_pressed & KEY_R) && (keys_pressed & KEY_RIGHT)) { myCartInfo.xOffset--; bRefreshXY = true; }

if ((keys_pressed & KEY_L) && (keys_pressed & KEY_UP)) if (myCartInfo.yScale <= 256) { myCartInfo.yScale++; bRefreshXY = true; }
if ((keys_pressed & KEY_L) && (keys_pressed & KEY_DOWN)) if (myCartInfo.yScale > 192) { myCartInfo.yScale--; bRefreshXY = true; }
if ((keys_pressed & KEY_L) && (keys_pressed & KEY_RIGHT)) if (myCartInfo.xScale < 320) { myCartInfo.xScale++; bRefreshXY = true; }
if ((keys_pressed & KEY_L) && (keys_pressed & KEY_LEFT)) if (myCartInfo.xScale > 192) { myCartInfo.xScale--; bRefreshXY = true; }
scale_screen_dampen=0;
} else scale_screen_dampen++;
if (++lcd_swap_counter == 30)
{
if (keys_pressed & KEY_A) lcdSwap();
}
}
if (scale_screen_dampen > 5)
{
if ((keys_pressed & KEY_R) && (keys_pressed & KEY_UP)) { myCartInfo.yOffset++; bRefreshXY = true; }
if ((keys_pressed & KEY_R) && (keys_pressed & KEY_DOWN)) { myCartInfo.yOffset--; bRefreshXY = true; }
if ((keys_pressed & KEY_R) && (keys_pressed & KEY_LEFT)) { myCartInfo.xOffset++; bRefreshXY = true; }
if ((keys_pressed & KEY_R) && (keys_pressed & KEY_RIGHT)) { myCartInfo.xOffset--; bRefreshXY = true; }

if ((keys_pressed & KEY_L) && (keys_pressed & KEY_UP)) if (myCartInfo.yScale <= 256) { myCartInfo.yScale++; bRefreshXY = true; }
if ((keys_pressed & KEY_L) && (keys_pressed & KEY_DOWN)) if (myCartInfo.yScale > 192) { myCartInfo.yScale--; bRefreshXY = true; }
if ((keys_pressed & KEY_L) && (keys_pressed & KEY_RIGHT)) if (myCartInfo.xScale < 320) { myCartInfo.xScale++; bRefreshXY = true; }
if ((keys_pressed & KEY_L) && (keys_pressed & KEY_LEFT)) if (myCartInfo.xScale > 192) { myCartInfo.xScale--; bRefreshXY = true; }
scale_screen_dampen=0;
} else scale_screen_dampen++;
}
} else lcd_swap_counter=0;

// -------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions arm9/source/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ const struct options_t Game_Option_Table[] =
{"LEFT DIFF", 0, {"A", "B"}, &myCartInfo.diff1, 2},
{"RIGHT DIFF", 0, {"A", "B"}, &myCartInfo.diff2, 2},
{"PALETTE", 0, {"CRT V2 COOL", "CRT V2 WARM", "CRT V2 HOT"}, &myCartInfo.palette, 3},
{"LEFT JOY", 0, {"NONE", "JOYSTICK", "LIGHTGUN", "PADDLES", "TWIN STICKS", "SOTA"}, &myCartInfo.cardctrl1, 6},
{"RIGHT JOY", 0, {"NONE", "JOYSTICK", "LIGHTGUN", "PADDLES", "TWIN STICKS", "SOTA"}, &myCartInfo.cardctrl2, 6},
{"LEFT JOY", 0, {"NONE", "JOYSTICK", "LIGHTGUN", "PADDLES", "TWIN STICKS", "SOTA", "SNES2ATARI"}, &myCartInfo.cardctrl1, 7},
{"RIGHT JOY", 0, {"NONE", "JOYSTICK", "LIGHTGUN", "PADDLES", "TWIN STICKS", "SOTA", "SNES2ATARI"}, &myCartInfo.cardctrl2, 7},
{"X OFFSET", 2, {"-50", "+50"}, (u8*)&myCartInfo.xOffset, 2},
{"Y OFFSET", 2, {"-50", "+50"}, (u8*)&myCartInfo.yOffset, 2},
{"X SCALE", 2, {"+200", "+320"}, (u8*)&myCartInfo.xScale, 2},
Expand Down
56 changes: 53 additions & 3 deletions arm9/source/emu/Cartridge.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,59 @@ static void cartridge_ReadHeader(const byte* header) {
if (cardtype & 0x0040) myCartInfo.pokeyType = POKEY_AT_450;
if (cardtype & 0x8000) myCartInfo.pokeyType = POKEY_AT_800;
if (cardtype & 0x0001) myCartInfo.pokeyType = POKEY_AT_4000;

myCartInfo.cardctrl1 = header[55];
myCartInfo.cardctrl2 = header[56];

// ========================
// 0 = none
// 1 = 7800 joystick
// 2 = lightgun
// 3 = paddle
// 4 = trakball
// 5 = 2600 joystick
// 6 = 2600 driving
// 7 = 2600 keypad
// 8 = ST mouse
// 9 = Amiga mouse
// 10 = AtariVox/SaveKey
// 11 = SNES2Atari
// ========================
switch(header[55])
{
case 1:
myCartInfo.cardctrl1 = CARTRIDGE_CONTROLLER_JOYSTICK;
break;
case 2:
myCartInfo.cardctrl1 = CARTRIDGE_CONTROLLER_LIGHTGUN;
break;
case 3:
myCartInfo.cardctrl1 = CARTRIDGE_CONTROLLER_PADDLES;
break;
case 11:
myCartInfo.cardctrl1 = CARTRIDGE_CONTROLLER_SNES2ATARI;
break;
default:
myCartInfo.cardctrl1 = CARTRIDGE_CONTROLLER_JOYSTICK;
break;
}

switch(header[56])
{
case 1:
myCartInfo.cardctrl2 = CARTRIDGE_CONTROLLER_JOYSTICK;
break;
case 2:
myCartInfo.cardctrl2 = CARTRIDGE_CONTROLLER_LIGHTGUN;
break;
case 3:
myCartInfo.cardctrl2 = CARTRIDGE_CONTROLLER_PADDLES;
break;
case 11:
myCartInfo.cardctrl2 = CARTRIDGE_CONTROLLER_SNES2ATARI;
break;
default:
myCartInfo.cardctrl2 = CARTRIDGE_CONTROLLER_JOYSTICK;
break;
}

myCartInfo.region = header[57] & 1;
myCartInfo.hsc = (header[58]&1 ? HSC_YES:HSC_NO);
myCartInfo.dma_adjust = 0;
Expand Down
2 changes: 2 additions & 0 deletions arm9/source/emu/Cartridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,14 @@
#define CARTRIDGE_CONTROLLER_PADDLES 3
#define CARTRIDGE_CONTROLLER_TWIN_STICKS 4
#define CARTRIDGE_CONTROLLER_SOTA 5
#define CARTRIDGE_CONTROLLER_SNES2ATARI 6

#define JOY CARTRIDGE_CONTROLLER_JOYSTICK
#define LGN CARTRIDGE_CONTROLLER_LIGHTGUN
#define PAD CARTRIDGE_CONTROLLER_PADDLES
#define TWIN CARTRIDGE_CONTROLLER_TWIN_STICKS
#define SOTA CARTRIDGE_CONTROLLER_SOTA
#define SNES CARTRIDGE_CONTROLLER_SNES2ATARI

#define CARTRIDGE_CYCLE_STEALING_MASK 0x01
#define CARTRIDGE_WSYNC_MASK 0x02
Expand Down
3 changes: 1 addition & 2 deletions arm9/source/emu/Database.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ Database_Entry game_list[] = {
{"07342c78619ba6ffcc61c10e907e3b50", "Asteroids", CT_NORMAL, POKEY_NONE, JOY, JOY, DIFF_A, DIFF_A, NTSC, HSC_YES, 0, 0, 17, 256, 230, 0}, // title=Asteroids
{"3d38281ed8a8d8c7cd457a18c92c8604", "Astro Blaster", CT_NORMAL, POKEY_NONE, JOY, JOY, DIFF_B, DIFF_B, NTSC, HSC_YES, 0, 30, 9, 320, 210, 0}, // title=Astro Blaster
{"a51e5df28a0fe8c52e9d28fb5f8e44a6", "Astro Fighter", CT_NORMAL, POKEY_NONE, JOY, JOY, DIFF_A, DIFF_A, NTSC, HSC_YES, 0, 32, 9, 320, 210, 0}, // title=Astro Fighter
{"22e9fd9233348a572d49d80186af5d7f", "Petscii Robots", CT_BANKSHALT,POKEY_AT_800,JOY, JOY, DIFF_A, DIFF_A, NTSC, HSC_NO, 0, 0, 10, 256, 214, 0}, // title=Attack of the Petscii Robots (full)
{"0a5ccd326307024a2012e8d9272101b0", "Petscii Robots", CT_BANKSHALT,POKEY_AT_800,JOY, JOY, DIFF_A, DIFF_A, NTSC, HSC_NO, 0, 0, 10, 256, 214, 0}, // title=Attack of the Petscii Robots (shareware)
{"22e9fd9233348a572d49d80186af5d7f", "Petscii Robots", CT_BANKSHALT,POKEY_AT_800,SNES,JOY, DIFF_A, DIFF_A, NTSC, HSC_NO, 0, 0, 10, 256, 214, 0}, // title=Attack of the Petscii Robots (full)
{"7cdfbe37634e7dcd4dc67db7edbcd3ba", "Baby Pac-Man", CT_NORMAL, POKEY_NONE, JOY, JOY, DIFF_A, DIFF_A, NTSC, HSC_NO, 0, 32, 12, 320, 221, 0}, // title=Baby Pac Man
{"8fc3a695eaea3984912d98ed4a543376", "Ballblazer", CT_NORMAL, POKEY_AT_4000, JOY, JOY, DIFF_A, DIFF_A, NTSC, HSC_NO, 0, 6, 12, 262, 220, 0}, // title=Ballblazer
{"42682415906c21c6af80e4198403ffda", "Barnyard Blaster", CT_SUPCAR, POKEY_AT_4000, JOY, JOY, DIFF_A, DIFF_A, NTSC, HSC_NO, 0, 0, 12, 256, 220, 0}, // title=Barnyard Blaster
Expand Down
24 changes: 24 additions & 0 deletions arm9/source/emu/Memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

byte memory_ram[MEMORY_SIZE] ALIGN(32) = {0};
u8 *is_memory_writable = (u8*)0x06820000;
u32 snes_bit_pos = 0;

extern bool ram_dirty[];
extern bool write_only_pokey_at_4000;
Expand All @@ -47,6 +48,8 @@ void memory_Reset( )
for(index = 0; index < 16384/2; index++) {
ptr[index] = 0xFFFF;
}

snes_bit_pos = 0;
}


Expand Down Expand Up @@ -212,6 +215,27 @@ ITCM_CODE void memory_Write(word address, byte data)
riot_SetDRB(data);
break;
case SWCHA:
if (myCartInfo.cardctrl1 == SNES)
{
extern byte riot_dra;
if ((data & 0x20) != (riot_dra & 0x20)) // Change of Latch state
{
snes_bit_pos = 0;
if (snes_adaptor & (1 << snes_bit_pos)) memory_ram[INPT4] |= 0x80; else memory_ram[INPT4] &= 0x7F;
}
if ((data & 0x10) != (riot_dra & 0x10)) // Change of Clock state
{
if (data & 0x10) // Clock going High
{
snes_bit_pos++;
}
else // Clock going low
{
if (snes_bit_pos >= 17) snes_bit_pos=0;
if (snes_adaptor & (1 << snes_bit_pos)) memory_ram[INPT4] |= 0x80; else memory_ram[INPT4] &= 0x7F;
}
}
}
riot_SetDRA(data);
break;
case TIM1T:
Expand Down
Loading

0 comments on commit 455e2d2

Please sign in to comment.