Skip to content

Commit 6010599

Browse files
committed
WIP getting sms emulator to compile and run (init / deinit is fine now, but frame fails)
1 parent 937d32d commit 6010599

File tree

16 files changed

+208
-386
lines changed

16 files changed

+208
-386
lines changed

components/sms/teensysms/emuapi.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@
55

66
#include <cstdio>
77

8-
extern "C" {
9-
#include "emuapi.h"
10-
#include "iopins.h"
11-
}
8+
#include "emuapi.h"
9+
#include "iopins.h"
1210

1311
// #include "bmpjoy.h"
1412
// #include "bmpvbar.h"
1513

1614
// #include "esp_event.h"
1715

18-
void emu_init(void)
16+
extern "C" {
17+
18+
void sms_emu_init(void)
1919
{
2020
}
2121

@@ -31,7 +31,7 @@ void emu_printi(int val)
3131
printf("%d\n",val);
3232
}
3333

34-
void * emu_Malloc(int size)
34+
void * emu_Malloc(unsigned int size)
3535
{
3636
void * retval = malloc(size);
3737
if (!retval) {
@@ -47,6 +47,7 @@ void * emu_Malloc(int size)
4747
void emu_Free(void * pt)
4848
{
4949
free(pt);
50+
printf("freed memory\n");
5051
}
5152

5253
static unsigned short palette16[PALETTE_SIZE];
@@ -55,14 +56,12 @@ static int fskip=0;
5556
void emu_SetPaletteEntry(unsigned char r, unsigned char g, unsigned char b, int index)
5657
{
5758
if (index<PALETTE_SIZE) {
58-
//printf("%d: %d %d %d\n", index, r,g,b);
59-
palette16[index] = RGBVAL16(r,g,b);
59+
palette16[index] = RGBVAL16(r,g,b);
6060
}
6161
}
6262

6363
void emu_DrawVsync(void)
6464
{
65-
//printf("sync %d\n",skip);
6665
fskip += 1;
6766
fskip &= VID_FRAME_SKIP;
6867
}
@@ -95,6 +94,8 @@ void * emu_LineBuffer(int line)
9594
return nullptr;
9695
}
9796

97+
}
98+
9899
#include "AudioPlaySystem.h"
99100
extern AudioPlaySystem audio;
100101

components/sms/teensysms/emuapi.h

Lines changed: 64 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
#ifndef EMUAPI_H
2-
#define EMUAPI_H
1+
#pragma once
32

4-
#include "platform_config.h"
5-
#include "emucfg.h"
3+
#define PALETTE_SIZE 32
4+
#define VID_FRAME_SKIP 0x0
65

76
#define ACTION_NONE 0
87
#define ACTION_RUN1 1
@@ -30,76 +29,72 @@
3029

3130
#ifdef __cplusplus
3231
extern "C" {
33-
extern void emu_init(int hires=0);
34-
extern void emu_start(int vblms, void * callback, int forcetimervsync=0);
32+
void sms_emu_init();
33+
void emu_start(int vblms, void * callback, int forcetimervsync=0);
3534
#endif
36-
extern void emu_printf(const char * text);
37-
extern void emu_printi(int val);
38-
extern void emu_printh(int val);
3935
void * emu_Malloc(unsigned int size);
40-
extern void * emu_MallocI(unsigned int size);
36+
void * emu_MallocI(unsigned int size);
4137
void emu_Free(void * pt);
42-
extern void * emu_SMalloc(unsigned int size);
43-
extern void emu_SFree(void * pt);
44-
45-
extern int emu_FileOpen(const char * filepath, const char * mode);
46-
extern int emu_FileRead(void * buf, int size, int handler);
47-
extern int emu_FileWrite(void * buf, int size, int handler);
48-
extern int emu_FileGetc(int handler);
49-
extern int emu_FileSeek(int handler, int seek, int origin);
50-
extern int emu_FileTell(int handler);
51-
extern void emu_FileClose(int handler);
52-
53-
extern unsigned int emu_FileSize(const char * filepath);
54-
extern unsigned int emu_LoadFile(const char * filepath, void * buf, int size);
55-
extern unsigned int emu_LoadFileSeek(const char * filepath, void * buf, int size, int seek);
56-
57-
extern void emu_SetPaletteEntry(unsigned char r, unsigned char g, unsigned char b, int index);
58-
extern void emu_DrawLinePal16(unsigned char * VBuf, int width, int height, int line);
59-
extern void emu_DrawLine16(unsigned short * VBuf, int width, int height, int line);
60-
extern void emu_DrawScreenPal16(unsigned char * VBuf, int width, int height, int stride);
61-
extern void emu_DrawLine8(unsigned char * VBuf, int width, int height, int line);
62-
extern void emu_DrawVsync(void);
63-
extern int emu_FrameSkip(void);
64-
extern int emu_IsVga(void);
65-
extern int emu_IsVgaHires(void);
66-
67-
extern int menuActive(void);
68-
extern char * menuSelection(void);
69-
extern char * menuSecondSelection(void);
70-
extern void toggleMenu(int on);
71-
extern int handleMenu(unsigned short bClick);
72-
73-
extern int handleOSKB(void);
74-
extern void toggleOSKB(int forceon);
75-
76-
extern void emu_InitJoysticks(void);
77-
extern int emu_SwapJoysticks(int statusOnly);
78-
extern unsigned short emu_DebounceLocalKeys(void);
79-
extern int emu_ReadKeys(void);
80-
extern int emu_GetPad(void);
81-
extern int emu_GetMouse(int *x, int *y, int *buts);
82-
extern int emu_MouseDetected(void);
83-
extern int emu_GetJoystick(void);
84-
extern int emu_KeyboardDetected(void);
85-
extern int emu_ReadAnalogJoyX(int min, int max);
86-
extern int emu_ReadAnalogJoyY(int min, int max);
87-
extern int emu_ReadI2CKeyboard(void);
88-
extern unsigned char emu_ReadI2CKeyboard2(int row);
89-
extern void emu_KeyboardOnUp(int keymodifer, int key);
90-
extern void emu_KeyboardOnDown(int keymodifer, int key);
91-
extern void emu_MidiOnDataReceived(unsigned char data);
92-
93-
extern void emu_sndPlaySound(int chan, int volume, int freq);
94-
extern void emu_sndPlayBuzz(int size, int val);
95-
extern void emu_sndInit();
96-
extern void emu_resetus(void);
97-
extern int emu_us(void);
98-
99-
extern int emu_setKeymap(int index);
38+
void * emu_SMalloc(unsigned int size);
39+
void emu_SFree(void * pt);
40+
41+
int emu_FileOpen(const char * filepath, const char * mode);
42+
int emu_FileRead(void * buf, int size, int handler);
43+
int emu_FileWrite(void * buf, int size, int handler);
44+
int emu_FileGetc(int handler);
45+
int emu_FileSeek(int handler, int seek, int origin);
46+
int emu_FileTell(int handler);
47+
void emu_FileClose(int handler);
48+
49+
unsigned int emu_FileSize(const char * filepath);
50+
unsigned int emu_LoadFile(const char * filepath, void * buf, int size);
51+
unsigned int emu_LoadFileSeek(const char * filepath, void * buf, int size, int seek);
52+
53+
void emu_SetPaletteEntry(unsigned char r, unsigned char g, unsigned char b, int index);
54+
void emu_DrawLinePal16(unsigned char * VBuf, int width, int height, int line);
55+
void emu_DrawLine16(unsigned short * VBuf, int width, int height, int line);
56+
void emu_DrawScreenPal16(unsigned char * VBuf, int width, int height, int stride);
57+
void emu_DrawLine8(unsigned char * VBuf, int width, int height, int line);
58+
void emu_DrawVsync(void);
59+
int emu_FrameSkip(void);
60+
int emu_IsVga(void);
61+
int emu_IsVgaHires(void);
62+
63+
int menuActive(void);
64+
char * menuSelection(void);
65+
char * menuSecondSelection(void);
66+
void toggleMenu(int on);
67+
int handleMenu(unsigned short bClick);
68+
69+
int handleOSKB(void);
70+
void toggleOSKB(int forceon);
71+
72+
void emu_InitJoysticks(void);
73+
int emu_SwapJoysticks(int statusOnly);
74+
unsigned short emu_DebounceLocalKeys(void);
75+
int emu_ReadKeys(void);
76+
int emu_GetPad(void);
77+
int emu_GetMouse(int *x, int *y, int *buts);
78+
int emu_MouseDetected(void);
79+
int emu_GetJoystick(void);
80+
int emu_KeyboardDetected(void);
81+
int emu_ReadAnalogJoyX(int min, int max);
82+
int emu_ReadAnalogJoyY(int min, int max);
83+
int emu_ReadI2CKeyboard(void);
84+
unsigned char emu_ReadI2CKeyboard2(int row);
85+
void emu_KeyboardOnUp(int keymodifer, int key);
86+
void emu_KeyboardOnDown(int keymodifer, int key);
87+
void emu_MidiOnDataReceived(unsigned char data);
88+
89+
void emu_sndPlaySound(int chan, int volume, int freq);
90+
void emu_sndPlayBuzz(int size, int val);
91+
void emu_sndInit();
92+
void emu_resetus(void);
93+
int emu_us(void);
94+
95+
int emu_setKeymap(int index);
10096

10197
#ifdef __cplusplus
10298
}
10399
#endif
104100

105-
#endif

components/sms/teensysms/emucfg.h

Lines changed: 0 additions & 115 deletions
This file was deleted.

components/sms/teensysms/fmopl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,7 @@ static void init_timetables( FM_OPL *OPL , int ARRATE , int DRRATE )
566566
OPL->AR_TABLE[i] = rate / ARRATE;
567567
OPL->DR_TABLE[i] = rate / DRRATE;
568568
}
569-
for (i = 60;i < 76;i++)
569+
for (i = 60;i < 75;i++)
570570
{
571571
OPL->AR_TABLE[i] = EG_AED-1;
572572
OPL->DR_TABLE[i] = OPL->DR_TABLE[60];

components/sms/teensysms/memory.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@
33

44
uint8 * cache;
55

6-
7-
86
void mem_init(void) {
9-
cache = emu_Malloc(CACHE_SIZE);
7+
cache = emu_Malloc(CACHE_SIZE);
108
}
119

1210

@@ -17,6 +15,10 @@ int mem_test(void) {
1715
return 1;
1816
}
1917

18+
void mem_deinit(void) {
19+
emu_Free(cache);
20+
}
21+
2022
void memcpy_rom(int dst, int src, int size) {
2123
while (size > 0) {
2224
write_rom(dst++, read_rom(src++));

components/sms/teensysms/memory.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
extern uint8 * cache;
1010

1111

12-
extern void mem_init(void);
12+
extern void mem_init(void);
13+
extern void mem_deinit(void);
1314
extern int mem_test(void);
1415
extern uint8 rom_version(void);
1516
extern uint8 read_rom(int address);

0 commit comments

Comments
 (0)