More cleanup as we get ready for the 1.0 release.

This commit is contained in:
Dave Bernazzani 2025-05-09 06:20:51 -04:00
parent 6f82a1d8ab
commit f61553c874
7 changed files with 88 additions and 69 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 44 KiB

After

Width:  |  Height:  |  Size: 45 KiB

View File

@ -61,6 +61,8 @@ uint8 myRAM1541[DRIVE_RAM_SIZE] __attribute__((section(".dtcm")));
uint8 bTurboWarp __attribute__((section(".dtcm"))) = 0;
uint8 cart_in __attribute__((section(".dtcm"))) = 0;
MOS6510 myCPU __attribute__((section(".dtcm"))); // Put the entire CPU object into fast memory...
C64 *gTheC64 = nullptr;
u8 CompressBuffer[0x20000]; //128K more than enough
@ -93,7 +95,8 @@ C64::C64()
ROM1541 = new uint8[DRIVE_ROM_SIZE];
// Create the chips
TheCPU = new MOS6510(this, RAM, Basic, Kernal, Char, Color);
TheCPU = &myCPU;
TheCPU->Init(this, RAM, Basic, Kernal, Char, Color);
TheJob1541 = new Job1541(RAM1541);
TheCPU1541 = new MOS6502_1541(this, TheJob1541, TheDisplay, RAM1541, ROM1541);
@ -175,7 +178,7 @@ C64::~C64()
delete TheSID;
delete TheVIC;
delete TheCPU1541;
delete TheCPU;
//delete TheCPU; -- this is now in 'fast memory' and reused
delete TheDisplay;
delete[] Char;

View File

@ -34,6 +34,7 @@ const int DRIVE_ROM_SIZE = 0x4000;
#define CIA_CYCLES_PER_LINE 63
#define BAD_CYCLES_PER_LINE 23
#define FLOPPY_CYCLES_PER_LINE 64
#define CPU_CYCLES_PER_LINE 63
#define MEM_TYPE_RAM 0x01
#define MEM_TYPE_KERNAL 0x02

View File

@ -93,9 +93,20 @@ uint8 *MemMap[0x10] __attribute__((section(".dtcm"))) ;
* 6510 constructor: Initialize registers
*/
MOS6510::MOS6510(C64 *c64, uint8 *Ram, uint8 *Basic, uint8 *Kernal, uint8 *Char, uint8 *Color)
: the_c64(c64), ram(Ram), basic_rom(Basic), kernal_rom(Kernal), char_rom(Char), color_ram(Color)
MOS6510::MOS6510()
{
// Most of init done in Init() so we can keep the constructor simple and allocate the object in the 'fast memory'
}
void MOS6510::Init(C64 *c64, uint8 *Ram, uint8 *Basic, uint8 *Kernal, uint8 *Char, uint8 *Color)
{
the_c64 = c64;
ram = Ram;
basic_rom = Basic;
kernal_rom = Kernal;
char_rom = Char;
color_ram = Color;
a = x = y = 0;
sp = 0xff;
n_flag = z_flag = 0;
@ -113,7 +124,6 @@ MOS6510::MOS6510(C64 *c64, uint8 *Ram, uint8 *Basic, uint8 *Kernal, uint8 *Char,
dfff_byte = 0x55;
}
/*
* Reset CPU asynchronously
*/
@ -351,7 +361,7 @@ inline void MOS6510::write_zp(uint16 adr, uint8 byte)
* Adc instruction
*/
ITCM_CODE void MOS6510::do_adc(uint8 byte)
void MOS6510::do_adc(uint8 byte)
{
if (!d_flag) {
uint16 tmp = a + (byte) + (c_flag ? 1 : 0);

View File

@ -64,8 +64,9 @@ struct MOS6510State;
// 6510 emulation (C64)
class MOS6510 {
public:
MOS6510(C64 *c64, uint8 *Ram, uint8 *Basic, uint8 *Kernal, uint8 *Char, uint8 *Color);
MOS6510();
void Init(C64 *c64, uint8 *Ram, uint8 *Basic, uint8 *Kernal, uint8 *Char, uint8 *Color);
int EmulateLine(int cycles_left); // Emulate until cycles_left underflows
void IntNMI(void);
void Reset(void);

View File

@ -1325,35 +1325,51 @@
set_nz(a = read_byte_imm() & x & (a | 0xee));
ENDOP(2);
case 0x93: // SHA (ind),Y
tmp2 = read_zp(read_byte(pc) + 1);
write_byte(read_adr_ind_y(), a & x & (tmp2+1));
ENDOP(6);
case 0x93: // SHA (ind),Y
tmp2 = read_zp(read_byte(pc) + 1);
adr = read_adr_ind_y();
if ((adr & 0xff) < y) { // Page crossed?
adr &= ((a & x) << 8) | 0xff;
}
write_byte(adr, a & x & (tmp2 + 1));
ENDOP(6);
case 0x9b: // SHS abs,Y
tmp2 = read_byte(pc+1);
adr = read_adr_abs_y();
if ((adr & 0xff) < y) { // Page crossed?
adr &= ((a & x) << 8) | 0xff;
}
write_byte(adr, a & x & (tmp2 + 1));
sp = a & x;
ENDOP(5);
case 0x9b: // SHS abs,Y
tmp2 = read_byte(pc + 1);
adr = read_adr_abs_y();
if ((adr & 0xff) < y) { // Page crossed?
adr &= ((a & x) << 8) | 0xff;
}
write_byte(adr, a & x & (tmp2 + 1));
sp = a & x;
ENDOP(5);
case 0x9c: // SHY abs,X
tmp2 = read_byte(pc+1);
write_byte(read_adr_abs_x(), y & (tmp2+1));
ENDOP(5);
case 0x9c: // SHY abs,X
tmp2 = read_byte(pc + 1);
adr = read_adr_abs_x();
if ((adr & 0xff) < x) { // Page crossed?
adr &= (y << 8) | 0xff;
}
write_byte(adr, y & (tmp2 + 1));
ENDOP(5);
case 0x9e: // SHX abs,Y
tmp2 = read_byte(pc+1);
write_byte(read_adr_abs_y(), x & (tmp2+1));
ENDOP(5);
case 0x9e: // SHX abs,Y
tmp2 = read_byte(pc + 1);
adr = read_adr_abs_y();
if ((adr & 0xff) < y) { // Page crossed?
adr &= (x << 8) | 0xff;
}
write_byte(adr, x & (tmp2 + 1));
ENDOP(5);
case 0x9f: // SHA abs,Y
tmp2 = read_byte(pc+1);
write_byte(read_adr_abs_y(), a & x & (tmp2+1));
ENDOP(5);
case 0x9f: // SHA abs,Y
tmp2 = read_byte(pc + 1);
adr = read_adr_abs_y();
if ((adr & 0xff) < y) { // Page crossed?
adr &= ((a & x) << 8) | 0xff;
}
write_byte(adr, a & x & (tmp2+1));
ENDOP(5);
case 0xab: // LXA #imm
set_nz(a = x = (a | 0xee) & read_byte_imm());

View File

@ -1019,7 +1019,8 @@ void MOS6569::el_std_idle(uint8 *p, uint8 *r)
uint32 conv0 = TextColorTable[0][b0c][data>>4].b;
uint32 conv1 = TextColorTable[0][b0c][data&0xf].b;
for (int i=0; i<40; i++) {
for (int i=0; i<40; i++)
{
*lp++ = conv0;
*lp++ = conv1;
*r++ = data;
@ -1040,7 +1041,8 @@ void MOS6569::el_mc_idle(uint8 *p, uint8 *r)
uint16 conv0 = (lookup[(data >> 6) & 3] << 16) | lookup[(data >> 4) & 3];
uint16 conv1 = (lookup[(data >> 2) & 3] << 16) | lookup[(data >> 0) & 3];
for (int i=0; i<40; i++) {
for (int i=0; i<40; i++)
{
*++lp = conv0;
*++lp = conv1;
*++r = data;
@ -1385,7 +1387,7 @@ spr_off:
int MOS6569::EmulateLine(void)
{
int cycles_left = 63 + CycleDeltas[myConfig.cpuCycles]; // Cycles left for CPU
int cycles_left = CPU_CYCLES_PER_LINE + CycleDeltas[myConfig.cpuCycles]; // Cycles left for CPU
bool is_bad_line = false;
// Get raster counter into local variable for faster access and increment
@ -1416,7 +1418,7 @@ int MOS6569::EmulateLine(void)
if (raster >= FIRST_DMA_LINE && raster <= LAST_DMA_LINE && ((raster & 7) == y_scroll) && bad_lines_enabled)
{
is_bad_line = true;
cycles_left = BAD_CYCLES_PER_LINE;
cycles_left = BAD_CYCLES_PER_LINE + CycleDeltas[myConfig.cpuCycles];
}
goto VIC_nop;
}
@ -1437,19 +1439,18 @@ int MOS6569::EmulateLine(void)
{
// Turn on display
display_state = is_bad_line = true;
cycles_left = BAD_CYCLES_PER_LINE;
cycles_left = BAD_CYCLES_PER_LINE + CycleDeltas[myConfig.cpuCycles];
rc = 0;
// Read and latch 40 bytes from video matrix and color RAM
uint8 *mp = matrix_line - 1;
uint8 *cp = color_line - 1;
int vc1 = vc - 1;
uint8 *mbp = matrix_base + vc1;
uint8 *crp = color_ram + vc1;
uint8 *mp = matrix_line;
uint8 *cp = color_line;
uint8 *mbp = matrix_base + vc;
uint8 *crp = color_ram + vc;
for (int i=0; i<40; i++)
{
*++mp = *++mbp;
*++cp = *++crp;
*mp++ = *mbp++;
*cp++ = *crp++;
}
}
@ -1464,9 +1465,6 @@ int MOS6569::EmulateLine(void)
// Display window contents
uint8 *p = chunky_ptr + COL40_XSTART; // Pointer in chunky display buffer
uint8 *r = fore_mask_buf + COL40_XSTART/8; // Pointer in foreground mask buffer
#ifdef ALIGNMENT_CHECK
uint8 *use_p = ((((int)p) & 3) == 0) ? p : text_chunky_buf;
#endif
{
p--;
uint8 b0cc = b0c_color;
@ -1560,39 +1558,29 @@ int MOS6569::EmulateLine(void)
case 0: // Standard text
case 1: // Multicolor text
case 4: // ECM text
#ifndef CAN_ACCESS_UNALIGNED
#ifdef ALIGNMENT_CHECK
el_std_idle(use_p, r);
if (use_p != p) {memcpy(p, use_p, 8*40);}
#else
if (x_scroll & 3) {
if (x_scroll & 3)
{
el_std_idle(text_chunky_buf, r);
// Experimentally, this is slightly faster than memcpy()
u32 *dest=(u32*)p; u32 *src=(u32*)text_chunky_buf; for (int i=0; i<80; i++) *dest++ = *src++;
} else
}
else
{
el_std_idle(p, r);
#endif
#else
el_std_idle(p, r);
#endif
}
break;
case 3: // Multicolor bitmap
#ifndef CAN_ACCESS_UNALIGNED
#ifdef ALIGNMENT_CHECK
el_mc_idle(use_p, r);
if (use_p != p) {memcpy(p, use_p, 8*40);}
#else
if (x_scroll & 3) {
if (x_scroll & 3)
{
el_mc_idle(text_chunky_buf, r);
// Experimentally, this is slightly faster than memcpy()
u32 *dest=(u32*)p; u32 *src=(u32*)text_chunky_buf; for (int i=0; i<80; i++) *dest++ = *src++;
} else
}
else
{
el_mc_idle(p, r);
#endif
#else
el_mc_idle(p, r);
#endif
}
break;
default: // Invalid mode (all black)