pull/31/head
AlinTigaeru 2023-02-23 16:49:29 +00:00
rodzic 5f43090cb7
commit 972fb619bf
6 zmienionych plików z 33 dodań i 44 usunięć

Wyświetl plik

@ -29,9 +29,11 @@ extern "C" {
uint8_t RAM[0x10000]; // 64k
unsigned char* bitstream = 0; // 16k video ram to be used by PIO.
unsigned char* bitstream_init_pos = 0;
static Z80 CPU;
bool interrupt_generated = false;
int sline = 0;
int cycles_left = 0;
// Implementations of system-specific emuapi Init, Step etc. functions.
@ -45,9 +47,10 @@ void cpc_Init(void)
{
emu_SetPaletteEntry(palette[i].R, palette[i].G, palette[i].B, i);
}
if (bitstream == 0) bitstream = (unsigned char *)emu_Malloc(WIDTH); //*HEIGHT
if (bitstream == 0) bitstream = (unsigned char *)emu_Malloc(WIDTH*HEIGHT); //*HEIGHT
bitstream_init_pos = bitstream;
//ResetZ80(&CPU, CYCLES_PER_FRAME);
ResetZ80(&CPU, CYCLES_PER_FRAME);
memset(RAM, 0, sizeof(RAM));
}
@ -57,7 +60,7 @@ void cpc_Init(void)
void cpc_Start(char* filename)
{
CPU.PC.W = 0x0000;
CPU.IFF = IFF_IM1;
//CPU.IFF = IFF_IM1;
ga_config.lower_rom_enable = true;
ga_config.upper_rom_enable = false;
ga_config.interrupt_counter = 0;
@ -69,40 +72,26 @@ void cpc_Start(char* filename)
*/
void cpc_Step(void)
{
int cycles_taken = 0;
int cycles_total = 0;
while(cycles_total < CYCLES_PER_FRAME)
{
cycles_taken = Cycles[RdZ80(CPU.PC.W)];
ExecZ80(&CPU);
cycles_total += cycles_taken;
for(int i = 0; i < cycles_taken / 4; i++)
{
crtc_step();
interrupt_generated = ga_step();
if(interrupt_generated)
{
printf("Interrupting!\n");
IntZ80(&CPU, INT_IRQ);
}
}
cycles_left = ExecZ80(&CPU, 24); // execute for the duration of 6 NOPs (maximum instruction length)
//printf("Executing %d times.\n", cycles_left/4);
for(int k = 0; k < (24 - cycles_left) / 4; k++)
{
emu_DrawLine8(bitstream, WIDTH, HEIGHT, sline);
crtc_step();
interrupt_generated = ga_step();
if(interrupt_generated)
{
// printf("Interrupting!\n");
IntZ80(&CPU, INT_RST38);
ga_config.interrupt_counter &= 0x1f;
}
if(is_hsync_active())
{
//printf("HSYNC at scanline %d \n", sline);
sline = (sline + 1) % NBLINES;
}
}
// printf("HSYNC at scanline %d \n", sline);
}
emu_DrawLine8(bitstream, WIDTH, HEIGHT, sline);
}
//}
}
/**

Wyświetl plik

@ -106,8 +106,8 @@ void write_crt_controller(unsigned short address, uint8_t value)
{
switch(address & 0xFF00)
{
case 0xBC00: selected_register = value & 0b11111;
case 0xBD00: registers[selected_register] = value;
case 0xBC00: selected_register = value & 0b11111;break;
case 0xBD00: registers[selected_register] = value;break;
}
}

Wyświetl plik

@ -116,12 +116,12 @@ void address_to_pixels()
for(int i = 0; i < 2; i++)
{
uint16_t address = crtc_generate_addr() + i;
// printf("address from CRTC: %x \nRAM data: %x \n", address, RAM[address]);
uint8_t encodedByte = RAM[address];
uint8_t pixel0, pixel1, pixel2, pixel3;
uint8_t* pixels = (uint8_t*) calloc(4, 8*sizeof(uint8_t));
if(address >= 0xC000)
{
//printf("address from CRTC: %x \nRAM data: %x \n", address, RAM[address]);
switch(ga_config.screen_mode)
{
case 0:

Wyświetl plik

@ -71,7 +71,7 @@ int main(void) {
}
else {
emu_Step();
tft.waitSync();
// tft.waitSync();
}
//int c = getchar_timeout_us(0);
//switch (c) {

Wyświetl plik

@ -505,15 +505,15 @@ void ResetZ80(Z80 *R, register int Cycles)
/** negative, and current register values in R. **/
/*************************************************************/
#ifdef EXECZ80
int ExecZ80(register Z80 *R) // , register int RunCycles
int ExecZ80(register Z80 *R, register int RunCycles) //
{
register byte I;
register pair J;
// for(R->ICount=RunCycles;;)
// {
// while(R->ICount>0)
// {
for(R->ICount=RunCycles;;)
{
while(R->ICount>0)
{
#ifdef DEBUG
/* Turn tracing on when reached trap address */
if(R->PC.W==R->Trap) R->Trace=1;
@ -546,8 +546,8 @@ int ExecZ80(register Z80 *R) // , register int RunCycles
R->ICount+=R->IBackup-1;
/* Interrupt CPU if needed */
if((R->IRequest!=INT_NONE)&&(R->IRequest!=INT_QUIT)) IntZ80(R,R->IRequest);
// }
// }
}
}
}
}
#endif /* EXECZ80 */

Wyświetl plik

@ -116,7 +116,7 @@ void ResetZ80(register Z80 *R, register int Cycles);
/** negative, and current register values in R. **/
/*************************************************************/
#ifdef EXECZ80
int ExecZ80(register Z80 *R); // ,register int RunCycles
int ExecZ80(register Z80 *R,register int RunCycles); //
#endif
/** IntZ80() *************************************************/