29 February 2008

Galaksija real video

Last two days I was working on implementing real video emulation for Galaksija, since there was a hack used for it till now.

Hardware for it is simple, video output is generated by shift register.
There is a clock generator at 6144000Hz (when divided by 2 is used as clock for Z80 CPU) which is used to shift register for video signal generator.

Width of line is 384 ticks and each horizontal line beginning is shifted by some number of ticks (9 * 8 ticks for Galaksija ROM1), this shift is configurable and ROM2 and Glaksija plus change this value. Also there are two empty lines in beginning of video info.

Idea for implementing this is to do exact thing what real hardware do. We will first make periodic interrupt:


And in it’s body we will generate image :
UINT8 *gfx = memory_region(REGION_GFX1);
unsigned int dat = (gal_latch_value & 0x3c) >> 2; // char line displaying
y = p / 384; // new line each 384 ticks
x = p - (y * 384); // this is horizontal pos
if ((gal_cnt % 8)==0) { //fetch code only on char beginning
// Take address refreshing in latch there is A7 status
addr = (((unsigned) cpunum_get_reg(0, Z80_I)) << 8) + (unsigned) cpunum_get_reg(0, Z80_R) + ((gal_latch_value & 0x80) ^ 0x80);
// Read video memory location
code = program_read_byte(addr) & 0xbf;
code += (code & 0x80) >> 1;
// take line from char gen
code = gfx[(code & 0x7f) +(dat << 7 )];
// display and shift
*BITMAP_ADDR16(tmpbitmap, y, x) = (code >> (p & 7)) & 1;

This one is working, only problem is implementation of Z80 CPU since it will set value of latch in wrong moment (on the beginning of executing instruction LD (HL),A , since on real one it is done at the end), that is why we now have first char in line displayed twice, and some minor glitches in 13th lines of char.

Now have to think how to solve that. Idea is not to change Z80 CPU implementation, but also it should be as much as possible like in real life.

1 comment:

Justin Kerk said...

If the Z80 emulation is in the wrong, then update it. Often the CPU cores are designed for arcade games in MAME and home computers often make much more fiendish use of the CPU out of necessity. The whole idea of running everything off the same CPU code is to get that code as accurate as possible using edge cases from many systems.

Also, there's a MESSDEV IRC channel at EFNet #messdev where you can get help with stuff.