MCUME/MCUME_pico/picoo2em/picoo2em.cpp

154 wiersze
3.2 KiB
C++

#include "pico.h"
#include "pico/stdlib.h"
extern "C" {
#include "iopins.h"
#include "emuapi.h"
}
#include "keyboard_osd.h"
extern "C" {
#include "Oddemu.h"
}
#include <stdio.h>
#ifdef USE_VGA
#include "vga_t_dma.h"
#else
#include "tft_t_dma.h"
#endif
TFT_T_DMA tft;
static int skip=0;
int main(void) {
stdio_init_all();
#ifdef USE_VGA
// tft.begin(VGA_MODE_400x240);
tft.begin(VGA_MODE_320x240);
#else
tft.begin();
#endif
emu_init();
while (true) {
if (menuActive()) {
uint16_t bClick = emu_DebounceLocalKeys();
int action = handleMenu(bClick);
char * filename = menuSelection();
if (action == ACTION_RUNTFT) {
toggleMenu(false);
emu_start();
emu_Init(filename);
tft.fillScreenNoDma( RGBVAL16(0x00,0x00,0x00) );
tft.startDMA();
}
tft.waitSync();
}
else {
emu_Step();
uint16_t bClick = emu_DebounceLocalKeys();
emu_Input(bClick);
}
//int c = getchar_timeout_us(0);
//switch (c) {
// case ' ':
// printf("test: %d\n", 1);
// break;
//}
}
}
static unsigned char palette8[PALETTE_SIZE];
static unsigned short palette16[PALETTE_SIZE];
void emu_SetPaletteEntry(unsigned char r, unsigned char g, unsigned char b, int index)
{
if (index<PALETTE_SIZE) {
palette8[index] = RGBVAL8(r,g,b);
palette16[index] = RGBVAL16(r,g,b);
}
}
void emu_DrawVsync(void)
{
skip += 1;
skip &= VID_FRAME_SKIP;
//tft.waitSync();
}
void emu_DrawLine(unsigned char * VBuf, int width, int height, int line)
{
if (skip == 0) {
#ifdef USE_VGA
tft.writeLine(width,height,line, VBuf, palette8);
#else
tft.writeLine(width,height,line, VBuf, palette16);
#endif
}
}
void emu_DrawLine8(unsigned char * VBuf, int width, int height, int line)
{
if (skip == 0) {
#ifdef USE_VGA
tft.writeLine(width,height,line, VBuf);
#endif
}
}
void emu_DrawLine16(unsigned short * VBuf, int width, int height, int line)
{
if (skip == 0) {
#ifdef USE_VGA
tft.writeLine16(width,height,line, VBuf);
#endif
}
}
void emu_DrawScreen(unsigned char * VBuf, int width, int height, int stride)
{
if (skip == 0) {
#ifdef USE_VGA
tft.writeScreen(width,height-TFT_VBUFFER_YCROP,stride, VBuf+(TFT_VBUFFER_YCROP/2)*stride, palette8);
#else
tft.writeScreen(width,height-TFT_VBUFFER_YCROP,stride, VBuf+(TFT_VBUFFER_YCROP/2)*stride, palette16);
#endif
}
}
int emu_FrameSkip(void)
{
return skip;
}
void * emu_LineBuffer(int line)
{
return (void*)tft.getLineBuffer(line);
}
#ifdef HAS_SND
#include "AudioPlaySystem.h"
AudioPlaySystem mymixer;
void emu_sndInit() {
tft.begin_audio(256, mymixer.snd_Mixer);
mymixer.start();
}
void emu_sndPlaySound(int chan, int volume, int freq)
{
if (chan < 6) {
mymixer.sound(chan, freq, volume);
}
}
void emu_sndPlayBuzz(int size, int val) {
mymixer.buzz(size,val);
}
#endif