-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How can I use this on my project #4
Comments
Yes. It's very easy. The The following example emulates a fictional machine. A linear video framebuffer is assumed to be located at address #define MACHINE_SCREEN_WIDTH 352
#define MACHINE_SCREEN_HEIGHT 296
#define MACHINE_VISIBLE_SCANLINES MACHINE_SCREEN_HEIGHT
#define MACHINE_VBLANK_SCANLINES 16
#define MACHINE_VRAM_ADDRESS 0xF000
#define MACHINE_CYCLES_PER_FRAME 69888
#define MACHINE_CYCLES_PER_IRQ 32
#define MACHINE_CYCLES_PER_SCANLINE \
(MACHINE_CYCLES_PER_FRAME / (MACHINE_VISIBLE_SCANLINES + MACHINE_VBLANK_SCANLINES))
#define MACHINE_CYCLES_PER_VBLANK \
(MACHINE_CYCLES_PER_SCANLINE * MACHINE_VBLANK_SCANLINES)
#define MACHINE_CYCLES_AT_IRQ 24
#define MACHINE_CYCLES_AT_IRQ_END (MACHINE_CYCLES_AT_IRQ + MACHINE_CYCLES_PER_IRQ)
#define MACHINE_CYCLES_AT_VISIBLE_SCANLINES MACHINE_CYCLES_PER_VBLANK
#define RGBA(r, g, b) 0x##FF##b##g##r
zuint32 const color_palette[16] = {
RGBA(00, 00, 00), RGBA(00, 00, D7), RGBA(D7, 00, 00), RGBA(D7, 00, D7),
RGBA(00, D7, 00), RGBA(00, D7, D7), RGBA(D7, D7, 00), RGBA(D7, D7, D7),
RGBA(00, 00, 00), RGBA(00, 00, FF), RGBA(FF, 00, 00), RGBA(FF, 00, FF),
RGBA(00, FF, 00), RGBA(00, FF, FF), RGBA(FF, FF, 00), RGBA(FF, FF, FF)
};
typedef struct {
M6502 cpu;
zuint8 memory[65535];
zusize frame_cycles;
zuint32 *video_output_buffer;
} Machine;
zuint8 cpu_read(Machine *self, zuint16 address)
{return self->memory[address];}
void cpu_write(Machine *self, zuint16 address, zuint8 value)
{self->memory[address] = value;}
void machine_initialize(Machine *self, zuint32 *video_output_buffer)
{
self->cpu.context = self;
self->cpu.read = cpu_read;
self->cpu.write = cpu_write;
m6502_power(&self->cpu, TRUE);
memset(self->memory, 0, 65535);
self->video_output_buffer = video_output_buffer;
self->cycles = 0;
}
void machine_run_frame(Machine *self)
{
zuint y, x;
zuint8* vram_input = &self->memory[MACHINE_VRAM_ADDRESS];
zuint32* video_output = self->video_output_buffer;
/* VBLANK before IRQ */
self->cycles += m6502_run(&self->cpu, MACHINE_CYCLES_AT_IRQ - self->cycles);
/* IRQ */
m6502_irq(&self->cpu, TRUE);
self->cycles += m6502_irq(&self->cpu, MACHINE_CYCLES_AT_IRQ_END - self->cycles);
m6502_irq(&self->cpu, FALSE);
/* VBLANK after IRQ */
self->cycles += m6502_run(&self->cpu, MACHINE_CYCLES_AT_VISIBLE_SCANLINES - self->cycles);
/* Visible scanlines */
for (y = 0; y < MACHINE_VISIBLE_SCANLINES; y++)
{
self->cycles = m6502_run(
&self->cpu,
MACHINE_CYCLES_AT_VISIBLE_SCANLINES +
((y + 1) * MACHINE_CYCLES_PER_SCANLINE) -
self->cycles);
/* Draw scanline pixels in the output buffer */
for (x = 0; x < MACHINE_SCREEN_WIDTH; x++)
*video_output++ = color_palette[*vram_input++];
}
self->cycles -= MACHINE_CYCLES_PER_FRAME;
}
int main(int argc, char *argv)
{
zuint32 video_buffer[MACHINE_SCREEN_WIDTH * MACHINE_SCREEN_HEIGHT];
Machine machine;
machine_initialize(&machine, video_buffer);
while (1)
{
machine_run_frame(&machine);
/* Draw frame */
...
}
return 0;
} |
If you have more doubts, feel free to join my Discord server: |
main.c:35:15: error: invalid operands to binary expression ('size_t' (aka 'unsigned long') and 'void')
self->cycles += m6502_irq(&self->cpu, MACHINE_CYCLES_AT_IRQ_END - self->cycles);
~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
This code could indeed use a "simple emulator" framework that can be used with the CPU backend. Possibly this could also be used for the Z80 backend, as they function similarly. |
I have another example for the Z80 documentation: https://zxe.io/software/Z80/documentation/latest/Usage.html The documentation is not finished yet, but it will be soon. |
I have another example for the Z80 documentation: https://zxe.io/software/Z80/documentation/latest/Usage.html
Yep, saw that.
The documentation is not finished yet, but it will be soon.
The standard thing with most projects :P
Fred
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you commented.Message ID: ***@***.***>
|
Hi, I'm making a emulator for my hobby computer using the 6502 CPU. I'm using this library for my emulator CPU emulation. The only thing is, I don't know how to use this. Do I need to power the CPU on and then run the CPU with specified cycles?
The text was updated successfully, but these errors were encountered: