kopia lustrzana https://github.com/Jean-MarcHarvengt/MCUME
text, black and distorted
rodzic
5397743cbb
commit
5494503e51
|
@ -21,9 +21,7 @@ extern "C" {
|
|||
|
||||
#define WIDTH 320
|
||||
#define HEIGHT 200
|
||||
#define CYCLES_PER_FRAME 79872 //79872 //19968
|
||||
#define NBLINES 312
|
||||
#define CYCLES_PER_SCANLINE CYCLES_PER_FRAME/NBLINES
|
||||
#define LOWER_ROM_END 0x4000
|
||||
#define UPPER_ROM_BEGIN 0xC000
|
||||
|
||||
|
@ -34,10 +32,36 @@ unsigned char* bitstream = 0; // 16k video ram to be used by PIO.
|
|||
static z80_t CPU;
|
||||
uint64_t pins;
|
||||
bool interrupt_generated = false;
|
||||
int sline = 0;
|
||||
int position = 0;
|
||||
int width_count = 0;
|
||||
int x, y = 0;
|
||||
|
||||
// Helper functions
|
||||
|
||||
void write_to_bitstream(char pixel)
|
||||
{
|
||||
// this populates the bitstream.
|
||||
x = position % WIDTH;
|
||||
y = position / WIDTH;
|
||||
|
||||
|
||||
bitstream[x + WIDTH * y] = pixel;
|
||||
|
||||
position++;
|
||||
|
||||
if(position == WIDTH * HEIGHT)
|
||||
{
|
||||
position = 0;
|
||||
vsync_wait = true;
|
||||
}
|
||||
}
|
||||
|
||||
static void display_screen()
|
||||
{
|
||||
emu_DrawScreen(bitstream, WIDTH, HEIGHT, WIDTH);
|
||||
emu_DrawVsync();
|
||||
}
|
||||
|
||||
char read_z80(uint16_t Addr)
|
||||
{
|
||||
if(Addr <= LOWER_ROM_END && ga_config.lower_rom_enable)
|
||||
|
@ -89,12 +113,11 @@ uint8_t in_z80(uint16_t Port)
|
|||
*/
|
||||
void cpc_Init(void)
|
||||
{
|
||||
|
||||
for(int i = 0; i < PALETTE_SIZE; i++)
|
||||
{
|
||||
emu_SetPaletteEntry(firmware_palette[i].R, firmware_palette[i].G, firmware_palette[i].B, i);
|
||||
emu_SetPaletteEntry(firmware_palette[hardware_colours[i]].R, firmware_palette[hardware_colours[i]].G, firmware_palette[hardware_colours[i]].B, hardware_colours[i]);
|
||||
}
|
||||
if (bitstream == 0) bitstream = (unsigned char *)emu_Malloc(WIDTH*HEIGHT); //*HEIGHT
|
||||
if (bitstream == 0) bitstream = (unsigned char *)emu_Malloc(WIDTH*HEIGHT);
|
||||
|
||||
pins = z80_init(&CPU);
|
||||
memset(RAM, 0, sizeof(RAM));
|
||||
|
@ -163,11 +186,13 @@ void cpc_Step(void)
|
|||
{
|
||||
// printf("Waiting in the next cycle.\n");
|
||||
pins = pins | Z80_WAIT;
|
||||
} else
|
||||
}
|
||||
else
|
||||
{
|
||||
// printf("Not waiting in the next cycle.\n");
|
||||
pins = pins & ~Z80_WAIT;
|
||||
}
|
||||
|
||||
if(interrupt_generated)
|
||||
{
|
||||
// To request an interrupt, or inject a wait state just set the respective pin
|
||||
|
@ -186,15 +211,10 @@ void cpc_Step(void)
|
|||
ga_config.interrupt_counter &= 0x1f;
|
||||
}
|
||||
|
||||
if(is_hsync_active() && !vsync_wait)
|
||||
if(!vsync_wait)
|
||||
{
|
||||
if(sline + 1 == NBLINES)
|
||||
{
|
||||
emu_DrawVsync();
|
||||
vsync_wait = true;
|
||||
}
|
||||
sline = (sline + 1) % NBLINES;
|
||||
emu_DrawLine8(bitstream, WIDTH, HEIGHT, sline);
|
||||
display_screen();
|
||||
vsync_wait = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ extern unsigned char* bitstream;
|
|||
extern struct GAConfig ga_config;
|
||||
extern bool vsync_wait;
|
||||
|
||||
extern void write_to_bitstream(char pixel);
|
||||
extern void draw_vsync();
|
||||
extern void cpc_Init(void);
|
||||
extern void cpc_Step(void);
|
||||
|
|
|
@ -86,7 +86,7 @@ uint16_t crtc_generate_addr()
|
|||
|
||||
bool is_within_display()
|
||||
{
|
||||
return horizontal_count < registers[0] && scanline_count < registers[6];
|
||||
return horizontal_count < registers[2] && scanline_count < registers[6];
|
||||
}
|
||||
|
||||
bool is_hsync_active()
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
#define emu_Step(x) {cpc_Step();}
|
||||
#define emu_Input(x) {cpc_Input(x);}
|
||||
|
||||
#define PALETTE_SIZE 27
|
||||
#define PALETTE_SIZE 32
|
||||
#define VID_FRAME_SKIP 0x0
|
||||
#define TFT_VBUFFER_YCROP 0
|
||||
|
||||
|
|
|
@ -49,7 +49,6 @@ uint8_t hardware_colours[32] = {
|
|||
12,
|
||||
14
|
||||
};
|
||||
|
||||
struct RGB firmware_palette[27] = {
|
||||
{0, 0, 0},
|
||||
{0, 0, 128},
|
||||
|
@ -131,14 +130,7 @@ void address_to_pixels()
|
|||
vsync_wait = false;
|
||||
}
|
||||
|
||||
// When HSYNC is active Gate-Array outputs the palette colour black
|
||||
if(ga_config.hsync_active)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// border
|
||||
if(ga_config.vsync_active || ga_config.hsync_active)
|
||||
if(ga_config.hsync_active || ga_config.vsync_active)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -168,15 +160,12 @@ void address_to_pixels()
|
|||
|
||||
for(int pixelIdx = 0; pixelIdx < 2; pixelIdx++)
|
||||
{
|
||||
bitstream[address + pixelIdx - 0xC000] = ga_rgb_to_vga(firmware_palette[hardware_colours[ga_config.pen_colours[pixels[pixelIdx]]]].R,
|
||||
firmware_palette[hardware_colours[ga_config.pen_colours[pixels[pixelIdx]]]].G,
|
||||
firmware_palette[hardware_colours[ga_config.pen_colours[pixels[pixelIdx]]]].B);
|
||||
// for(int color = 0; color < 4; color++)
|
||||
// {
|
||||
// bitstream[address + color - 0xC000] = ga_rgb_to_vga(ga_config.pen_colours[pixels[pixelIdx]].R,
|
||||
// ga_config.pen_colours[pixels[pixelIdx]].G,
|
||||
// ga_config.pen_colours[pixels[pixelIdx]].B);
|
||||
// }
|
||||
for(int color = 0; color < 4; color++)
|
||||
{
|
||||
write_to_bitstream(ga_rgb_to_vga(firmware_palette[hardware_colours[ga_config.pen_colours[pixels[pixelIdx]]]].R,
|
||||
firmware_palette[hardware_colours[ga_config.pen_colours[pixels[pixelIdx]]]].G,
|
||||
firmware_palette[hardware_colours[ga_config.pen_colours[pixels[pixelIdx]]]].B));
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
|
@ -195,15 +184,12 @@ void address_to_pixels()
|
|||
|
||||
for(int pixelIdx = 0; pixelIdx < 4; pixelIdx++)
|
||||
{
|
||||
bitstream[address + pixelIdx - 0xC000] = ga_rgb_to_vga(firmware_palette[hardware_colours[ga_config.pen_colours[pixels[pixelIdx]]]].R,
|
||||
firmware_palette[hardware_colours[ga_config.pen_colours[pixels[pixelIdx]]]].G,
|
||||
firmware_palette[hardware_colours[ga_config.pen_colours[pixels[pixelIdx]]]].B);
|
||||
// for(int color = 0; color < 2; color++)
|
||||
// {
|
||||
// bitstream[address + color - 0xC000] = ga_rgb_to_vga(ga_config.pen_colours[pixels[pixelIdx]].R,
|
||||
// ga_config.pen_colours[pixels[pixelIdx]].G,
|
||||
// ga_config.pen_colours[pixels[pixelIdx]].B);
|
||||
// }
|
||||
for(int color = 0; color < 2; color++)
|
||||
{
|
||||
write_to_bitstream(ga_rgb_to_vga(firmware_palette[hardware_colours[ga_config.pen_colours[pixels[pixelIdx]]]].R,
|
||||
firmware_palette[hardware_colours[ga_config.pen_colours[pixels[pixelIdx]]]].G,
|
||||
firmware_palette[hardware_colours[ga_config.pen_colours[pixels[pixelIdx]]]].B));
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
|
@ -211,9 +197,9 @@ void address_to_pixels()
|
|||
for (int color = 0; color < 8; color++)
|
||||
{
|
||||
pixel = (encodedByte >> 7 - color) & 1;
|
||||
bitstream[address + color - 0xC000] = ga_rgb_to_vga(firmware_palette[hardware_colours[ga_config.pen_colours[pixel]]].R,
|
||||
firmware_palette[hardware_colours[ga_config.pen_colours[pixel]]].G,
|
||||
firmware_palette[hardware_colours[ga_config.pen_colours[pixel]]].B);
|
||||
write_to_bitstream(ga_rgb_to_vga(firmware_palette[hardware_colours[ga_config.pen_colours[pixel]]].R,
|
||||
firmware_palette[hardware_colours[ga_config.pen_colours[pixel]]].G,
|
||||
firmware_palette[hardware_colours[ga_config.pen_colours[pixel]]].B));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -90,6 +90,7 @@ void emu_SetPaletteEntry(unsigned char r, unsigned char g, unsigned char b, int
|
|||
palette8[index] = RGBVAL8(r,g,b);
|
||||
palette16[index] = RGBVAL16(r,g,b);
|
||||
}
|
||||
printf("index: %d palette[8]: %d\n", index, palette8[index]);
|
||||
}
|
||||
|
||||
void emu_DrawVsync(void)
|
||||
|
|
Ładowanie…
Reference in New Issue