Skip to content

Commit

Permalink
Add support for Pagefox cartridge
Browse files Browse the repository at this point in the history
  • Loading branch information
KimJorgensen committed Jul 4, 2022
1 parent 9218431 commit 925b65b
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ The following cartridge types are currently supported:
* Prophet64
* Freeze Frame
* Freeze Machine
* Pagefox
* RGCD, Hucky
* Drean

Expand Down
8 changes: 8 additions & 0 deletions firmware/cartridges/cartridge.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ static u32 freezer_state;
#include "easyflash_3.c"
#include "prophet64.c"
#include "freeze_machine.c"
#include "pagefox.c"
#include "rgcd.c"
#include "c128_normal.c"
#include "kff.c"
Expand Down Expand Up @@ -120,6 +121,9 @@ static void (*crt_get_handler(u32 cartridge_type, bool vic_support)) (void)
case CRT_FREEZE_MACHINE:
return NTSC_OR_PAL_HANDLER(fm);

case CRT_PAGEFOX:
return pagefox_handler;

case CRT_RGCD:
return rgcd_handler;

Expand Down Expand Up @@ -181,6 +185,10 @@ static void crt_init(DAT_CRT_HEADER *crt_header)
fm_init(crt_header);
break;

case CRT_PAGEFOX:
pagefox_init();
break;

case CRT_RGCD:
rgcd_init(crt_header);
break;
Expand Down
87 changes: 87 additions & 0 deletions firmware/cartridges/pagefox.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* Copyright (c) 2022 Kim Jørgensen
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*/

static u8 * const pagefox_mode[8] =
{
CRT_DAT_BANK(0),
CRT_DAT_BANK(1),
CRT_DAT_BANK(2),
CRT_DAT_BANK(3),
CRT_RAM_BANK(0),
CRT_RAM_BANK(2),
NULL,
NULL
};

/*************************************************
* C64 bus read callback
*************************************************/
FORCE_INLINE bool pagefox_read_handler(u32 control, u32 addr)
{
if ((control & (C64_ROML|C64_ROMH)) != (C64_ROML|C64_ROMH) && crt_ptr)
{
C64_DATA_WRITE(crt_ptr[addr & 0x3fff]);
return true;
}

return false;
}

/*************************************************
* C64 bus write callback
*************************************************/
FORCE_INLINE void pagefox_write_handler(u32 control, u32 addr, u32 data)
{
if (!(control & C64_IO1))
{
// Register at $de80-$deff
if (addr & 0x80)
{
u32 mode = (data >> 1) & 0x07;
crt_ptr = pagefox_mode[mode];

if (!(data & 0x10))
{
C64_CRT_CONTROL(STATUS_LED_ON|CRT_PORT_16K);
}
else
{
C64_CRT_CONTROL(STATUS_LED_OFF|CRT_PORT_NONE);
}
}

return;
}

// Ram at $8000-$bfff
if ((addr >> 14) == 0x02 &&
(((u32)crt_ptr >> 15) == ((u32)CRT_RAM_BANK(0) >> 15)))
{
crt_ptr[addr & 0x3fff] = (u8)data;
return;
}
}

static void pagefox_init(void)
{
C64_CRT_CONTROL(STATUS_LED_ON|CRT_PORT_16K);
}

C64_BUS_HANDLER(pagefox)

0 comments on commit 925b65b

Please sign in to comment.