#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
// 1. Create emulator instance
SyncEmu* emu = emu_create();
if (!emu) {
fprintf(stderr, "Failed to create emulator\n");
return 1;
}
// 2. Load ROM data
uint8_t* rom_data = load_rom_file("TI-84-CE.rom", &rom_size);
int result = emu_load_rom(emu, rom_data, rom_size);
if (result != 0) {
fprintf(stderr, "Failed to load ROM: %d\n", result);
emu_destroy(emu);
return 1;
}
// 3. (Optional) Send files to calculator
uint8_t* program = load_file("program.8xp", &program_size);
int entries = emu_send_file(emu, program, program_size);
if (entries < 0) {
fprintf(stderr, "Failed to send file: %d\n", entries);
}
// 4. Power on the calculator
emu_power_on(emu);
// 5. Main emulation loop
while (running) {
// Run emulation (15 MHz = 15,000,000 cycles/sec)
// For 60 FPS: 15,000,000 / 60 = 250,000 cycles per frame
emu_run_cycles(emu, 250000);
// Get framebuffer and render
int32_t width, height;
const uint32_t* fb = emu_framebuffer(emu, &width, &height);
render_display(fb, width, height);
// Handle input
if (key_pressed(KEY_ENTER)) {
emu_set_key(emu, 6, 0, 1); // Press ENTER
}
if (key_released(KEY_ENTER)) {
emu_set_key(emu, 6, 0, 0); // Release ENTER
}
}
// 6. Cleanup
emu_destroy(emu);