2017-06-13 22:02:52 +00:00
|
|
|
/*
|
|
|
|
|
|
|
|
This file is part of Emu-Pizza
|
|
|
|
|
|
|
|
Emu-Pizza is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Emu-Pizza is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Emu-Pizza. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <sys/types.h>
|
2017-06-15 23:00:41 +00:00
|
|
|
#include <emulibc.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#define EXPORT ECL_EXPORT
|
2017-06-13 22:02:52 +00:00
|
|
|
|
|
|
|
#include "cartridge.h"
|
|
|
|
#include "cycles.h"
|
|
|
|
#include "gameboy.h"
|
|
|
|
#include "global.h"
|
|
|
|
#include "gpu.h"
|
|
|
|
#include "input.h"
|
|
|
|
#include "sound.h"
|
|
|
|
#include "serial.h"
|
2017-06-15 23:00:41 +00:00
|
|
|
#include "utils.h"
|
|
|
|
#include "mmu.h"
|
2017-06-13 22:02:52 +00:00
|
|
|
|
|
|
|
/* proto */
|
|
|
|
void cb();
|
|
|
|
void connected_cb();
|
|
|
|
void disconnected_cb();
|
|
|
|
void rumble_cb(uint8_t rumble);
|
|
|
|
void network_send_data(uint8_t v);
|
|
|
|
void *start_thread(void *args);
|
|
|
|
void *start_thread_network(void *args);
|
|
|
|
|
|
|
|
/* frame buffer pointer */
|
|
|
|
uint16_t *fb;
|
|
|
|
|
|
|
|
/* magnify rate */
|
|
|
|
float magnify_rate = 1.f;
|
|
|
|
|
|
|
|
/* cartridge name */
|
|
|
|
char cart_name[64];
|
|
|
|
|
2017-06-15 23:00:41 +00:00
|
|
|
int main(void)
|
2017-06-13 22:02:52 +00:00
|
|
|
{
|
2017-06-15 23:00:41 +00:00
|
|
|
}
|
2017-06-13 22:02:52 +00:00
|
|
|
|
2017-06-15 23:00:41 +00:00
|
|
|
EXPORT int Init(const void *rom, int romlen)
|
|
|
|
{
|
|
|
|
/* init global variables */
|
|
|
|
global_init();
|
2017-06-13 22:02:52 +00:00
|
|
|
|
2017-06-15 23:00:41 +00:00
|
|
|
/* first, load cartridge */
|
|
|
|
char ret = cartridge_load(rom, romlen);
|
2017-06-13 22:02:52 +00:00
|
|
|
|
2017-06-15 23:00:41 +00:00
|
|
|
if (ret != 0)
|
|
|
|
return 0; // failure
|
2017-06-13 22:02:52 +00:00
|
|
|
|
2017-06-15 23:00:41 +00:00
|
|
|
gameboy_init();
|
2017-06-13 22:02:52 +00:00
|
|
|
|
2017-06-15 23:00:41 +00:00
|
|
|
/* init GPU */
|
|
|
|
gpu_init(&cb);
|
2017-06-13 22:02:52 +00:00
|
|
|
|
2017-06-15 23:00:41 +00:00
|
|
|
/* set sound output rate */
|
|
|
|
sound_set_output_rate(44100);
|
2017-06-13 22:02:52 +00:00
|
|
|
|
2017-06-15 23:00:41 +00:00
|
|
|
/* set rumble cb */
|
|
|
|
mmu_set_rumble_cb(&rumble_cb);
|
2017-06-13 22:02:52 +00:00
|
|
|
|
2017-06-15 23:00:41 +00:00
|
|
|
/* get frame buffer reference */
|
|
|
|
fb = gpu_get_frame_buffer();
|
2017-06-13 22:02:52 +00:00
|
|
|
|
2017-06-15 23:00:41 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2017-06-13 22:02:52 +00:00
|
|
|
|
2017-06-15 23:00:41 +00:00
|
|
|
static uint32_t fb32[160 * 144];
|
2017-06-13 22:02:52 +00:00
|
|
|
|
2017-06-15 23:00:41 +00:00
|
|
|
//case (SDLK_d): global_debug ^= 0x01; break;
|
|
|
|
//case (SDLK_s): global_slow_down = 1; break;
|
|
|
|
//case (SDLK_w): global_window ^= 0x01; break;
|
|
|
|
//case (SDLK_n): gameboy_set_pause(0);
|
|
|
|
// global_next_frame = 1; break;
|
2017-06-13 22:02:52 +00:00
|
|
|
|
2017-06-15 23:00:41 +00:00
|
|
|
/* case (SDLK_p): gameboy_set_pause(global_pause ^ 0x01);
|
2017-06-13 22:02:52 +00:00
|
|
|
break;
|
|
|
|
case (SDLK_m): mmu_dump_all(); break;
|
|
|
|
case (SDLK_SPACE): input_set_key_select(1); break;
|
|
|
|
case (SDLK_RETURN): input_set_key_start(1); break;
|
|
|
|
case (SDLK_UP): input_set_key_up(1); break;
|
|
|
|
case (SDLK_DOWN): input_set_key_down(1); break;
|
|
|
|
case (SDLK_RIGHT): input_set_key_right(1); break;
|
|
|
|
case (SDLK_LEFT): input_set_key_left(1); break;
|
|
|
|
case (SDLK_z): input_set_key_b(1); break;
|
|
|
|
case (SDLK_x): input_set_key_a(1); break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SDL_KEYUP:
|
|
|
|
switch (e.key.keysym.sym)
|
|
|
|
{
|
|
|
|
case (SDLK_SPACE): input_set_key_select(0); break;
|
|
|
|
case (SDLK_RETURN): input_set_key_start(0); break;
|
|
|
|
case (SDLK_UP): input_set_key_up(0); break;
|
|
|
|
case (SDLK_DOWN): input_set_key_down(0); break;
|
|
|
|
case (SDLK_RIGHT): input_set_key_right(0); break;
|
|
|
|
case (SDLK_LEFT): input_set_key_left(0); break;
|
|
|
|
case (SDLK_z): input_set_key_b(0); break;
|
|
|
|
case (SDLK_x): input_set_key_a(0); break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-15 23:00:41 +00:00
|
|
|
// join emulation thread
|
2017-06-13 22:02:52 +00:00
|
|
|
pthread_join(thread, NULL);
|
|
|
|
|
2017-06-15 23:00:41 +00:00
|
|
|
// stop network thread!
|
2017-06-13 22:02:52 +00:00
|
|
|
network_stop();
|
|
|
|
|
|
|
|
utils_log("Total cycles %d\n", cycles.cnt);
|
|
|
|
utils_log("Total running seconds %d\n", cycles.seconds);
|
|
|
|
|
|
|
|
return 0;
|
2017-06-15 23:00:41 +00:00
|
|
|
}*/
|
2017-06-13 22:02:52 +00:00
|
|
|
|
2017-06-15 23:00:41 +00:00
|
|
|
typedef struct
|
2017-06-13 22:02:52 +00:00
|
|
|
{
|
2017-06-15 23:00:41 +00:00
|
|
|
uint32_t* vbuff;
|
|
|
|
int32_t clocks; // desired(in) actual(out) time to run; 2MHZ
|
|
|
|
} frameinfo_t;
|
2017-06-13 22:02:52 +00:00
|
|
|
|
2017-06-15 23:00:41 +00:00
|
|
|
|
|
|
|
EXPORT void FrameAdvance(frameinfo_t* frame)
|
|
|
|
{
|
|
|
|
uint64_t current = cycles.sampleclock;
|
|
|
|
gameboy_run(current + frame->clocks);
|
|
|
|
frame->clocks = cycles.sampleclock - current;
|
|
|
|
memcpy(frame->vbuff, fb32, 160 * 144 * sizeof(uint32_t));
|
2017-06-13 22:02:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void cb()
|
|
|
|
{
|
2017-06-15 23:00:41 +00:00
|
|
|
// frame received into fb
|
|
|
|
uint16_t *src = fb;
|
|
|
|
uint8_t *dst = (uint8_t *)fb32;
|
|
|
|
|
|
|
|
for (int i = 0; i < 160 * 144; i++)
|
|
|
|
{
|
|
|
|
uint16_t c = *src++;
|
|
|
|
*dst++ = c << 3 & 0xf8 | c >> 2 & 7;
|
|
|
|
*dst++ = c >> 3 & 0xfa | c >> 9 & 3;
|
|
|
|
*dst++ = c >> 8 & 0xf8 | c >> 13 & 7;
|
|
|
|
*dst++ = 0xff;
|
|
|
|
}
|
2017-06-13 22:02:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void connected_cb()
|
|
|
|
{
|
2017-06-15 23:00:41 +00:00
|
|
|
utils_log("Connected\n");
|
2017-06-13 22:02:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void disconnected_cb()
|
|
|
|
{
|
2017-06-15 23:00:41 +00:00
|
|
|
utils_log("Disconnected\n");
|
2017-06-13 22:02:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void rumble_cb(uint8_t rumble)
|
|
|
|
{
|
2017-06-15 23:00:41 +00:00
|
|
|
if (rumble)
|
|
|
|
printf("RUMBLE\n");
|
2017-06-13 22:02:52 +00:00
|
|
|
}
|