Merge pull request #72 from meepingsnesroms/removeOldArmCpu

Remove old arm cpu
This commit is contained in:
meepingsnesroms
2019-04-19 11:02:02 -07:00
committed by GitHub
88 changed files with 2169 additions and 10047 deletions

4
.gitignore vendored
View File

@@ -19,8 +19,8 @@
/tools/palm/muExpansionDriver/*.grc
/tools/palm/muExpansionDriver/*.prc
/tools/palm/muExpansionDriver/muExpDriver
/tools/palm/muExpansionDriver/blobs/m68kCallWithBlob.S68
/tools/palm/muExpansionDriver/blobs/m68kCallWithBlob.L68
/tools/palm/muExpansionDriver/blobs/*.S68
/tools/palm/muExpansionDriver/blobs/*.L68
/tools/desktop/build-BufferGraphViewer-*
/tools/desktop/build-MakePalmBitmap-*
/tools/desktop/export16BitImageProperly/convert

6
bugs/accidentalFinds.txt Normal file
View File

@@ -0,0 +1,6 @@
Bugs in other peoples code I found while writing Mu, haven't followed up on them yet:
(RetroArch)RETRO_ENVIRONMENT_GET_MIDI_INTERFACE states its passed a pointer to a pointer but its just a pointer to a struct
(RetroArch)"led_driver" setting is not exposed to GUI
(RetroArch)retro_set_environment will sometimes be called multiple times and provide invalid values fetching environment variables on the subsequent calls, this will cause function pointers to be corrupted if they are not checked for validity first
Fixed:

View File

@@ -1,87 +0,0 @@
The datasheet states:
When external interrupts INT[3:0], IRQ1, IRQ2, IRQ3, and IRQ6 are programmed as edge-triggered interrupts, they can be cleared by writing a 1 to the corresponding status bit in the interrupt status register in the interrupt controller. When programmed as level-triggered interrupts, these interrupts are cleared at the requesting sources.
But all attempts to use the INT* pins as edge triggered have failed and they continue as level triggered
PDIUSBD12 uses CSA1 and CPU A1 as USB A0
All of the interrupt signals in the table can be used as system wake-up interrupts, except for the edge interrupt on INT[3:0]. Edge interrupts on INT[3:0] can only interrupt the CPU when the system is awake. The INT[3:0] signals are all level 4 interrupts, but IRQx has its own level. Any combination of Port D signals and OR (negative logic) can be selected to generate keyboard (KB) interrupts to the CPU. The KBx signal is an active low, level-sensitive interrupt of the selected pins. Like the other ports, each pin can be configured as an input or output on a bit-by-bit basis. When they are configured as inputs, each pin can generate a CPU interrupt.
CS(A/B/C/D)1 seem to not be connected, only CS*0 is used
PFPUEN has both pull up and pull down on it, the 4 address lines are the pull downs
cmp.* seems like it can only set the Carry flag if the result or one of the parameters is negative
The first argument to a function is the last pushed on the stack(proof below, the 16 bit int is the last argument and its pushed first)
ROM:1003026C move.w d0,-(sp) ; Move Data from Source to Destination
ROM:1003026E move.l a4,-(sp) ; Move Data from Source to Destination
ROM:10030270 move.l d7,-(sp) ; Move Data from Source to Destination
ROM:10030272 trap #$F ; Trap sysTrapStrNCopy
ROM:10030272 dc.w $A2CE
Char * StrNCopy(Char *dst, const Char *src, Int16 n)SYS_TRAP(sysTrapStrNCopy);
HwrIRQ4Handler Interrupt Level 4 Priority(top of the list is checked first):
UART 1 and 2(they have the same priority)
RTC
All Buttons
IVR = 0x18
interrupt vector start = 0x60
vectors starting at level 0(no interrupt) to level 7
0x00000060:0x00000000 (no interrupt, never called)
0x00000064:0x101904BE
0x00000068:0x101904EC
0x0000006C:0x1019051A
0x00000070:0x10190548 (level 4, hardware buttons)
0x00000074:0x10190576 (level 5, seems to be touchscreen)
0x00000078:0x101905A4
0x0000007C:0x10015F34 (level 7, debugging IRQ, not used)
SPI Routine Location:
PrvSetBB7846ChanRef or PrvReadnBB7846PwrDn
0x10081518
SPI Start Chunk(sent once on boot):
12 4 bit delay, 8 bit check battery command, 0x0AE0
5 5 bit receive, continued from last command, 0x0014
Palm OS reads from the touchscreen SPI in 5 accesses:
SPI2 transfer, ENABLE:true, XCH:true, IRQ:false, IRQEN:false, BITCOUNT:16(printed 1 times)
SPI2 transfer, before:0xE01B, after:0x00FF(printed 1 times)
SPI2 transfer, ENABLE:true, XCH:true, IRQ:false, IRQEN:false, BITCOUNT:3(printed 1 times)
SPI2 transfer, before:0x0004, after:0x0026(printed 1 times)
SPI2 transfer, ENABLE:true, XCH:true, IRQ:false, IRQEN:false, BITCOUNT:5(printed 1 times)
SPI2 transfer, before:0x001D, after:0x03BF(printed 1 times)
SPI2 transfer, ENABLE:true, XCH:true, IRQ:false, IRQEN:false, BITCOUNT:12(printed 1 times)
SPI2 transfer, before:0x0E1C, after:0xCE00(printed 1 times)
SPI2 transfer, ENABLE:true, XCH:true, IRQ:false, IRQEN:false, BITCOUNT:16(printed 1 times)
SPI2 transfer, before:0xE01C, after:0xFEFF(printed 1 times)
resync event?{
16 0xE01B
3 only sends 0s, delay or receive, 0x0004
5 only sends 0s, delay or receive, 0x001D
}
12 4 bit delay, 8 bit send command, 0x0E1C
16 0xE01C
TouchScreen Read Order:
//check x
Accessed ADS7846 Ch:5, Normal Mode, Power Save:0, PC:0x1008119E.(printed 1 times)
//don't know why
Accessed ADS7846 Ch:0, Normal Mode, Power Save:3, PC:0x10081208.(printed 1 times)
//don't know why
Accessed ADS7846 Ch:6, Normal Mode, Power Save:3, PC:0x10081208.(printed 1 times)
//...repeat until released
//check battery before returning
Accessed ADS7846 Ch:2, Normal Mode, Power Save:3, PC:0x10081208.(printed 1 times)

View File

@@ -1,4 +1,5 @@
Easter release, 17:00 GMT, hopefully with some good ARM stuff
Cinco De Mayo(May 5th), 17:00 GMT, hopefully with some good ARM stuff
Easter release, 17:00 GMT, hopefully with some good ARM stuff(delayed)
Done:
Release at Christmas 17:00 GMT, 9:00 My time, 12:00 SquirrelJME devs time

View File

@@ -2,6 +2,9 @@ CPU:
sysTrapPceNativeCall, ARM Emulator
VFP(floating point) coprocessor for ARM
Test what bits of IMR are writable
sandbox isnt notified about switches to Thumb mode
function name finders for ARMv5 and Thumb are unimplemented
hardware registers don't have there names printed in sandbox
CPU I/O:
Peripheral Control Register, audio ppm mixing selection
@@ -23,7 +26,6 @@ PLLFSR has a hack that makes busy wait loops finish faster by toggling the CLK32
should also not transfer data to SD card when MOSI, MISO or SPICLK1 are disabled
port d data register INT* bits seem to have there data bits cleared when an edge triggered interrupt is cleared(according to MC68VZ328UM.pdf Page 10-15)
sound plays too long when the category's menu is selected on the home screen and the pen is pressed and held in the middle of the screen(only happens there, other views of the same type don't have this issue)(effected by CPU speed, turning it up reduces the duration of the excess squeal)
ARM CPU state isn't saved
trying to beam anything will lock up the OS
Memory:
@@ -50,8 +52,13 @@ ADS7846 channels can't be read in single reference mode in hwTestSuite
MakePalmBitmap:
Other:
Support for Silkyboard 2 silkscreen:https://archive.org/details/tucows_228076_SILKYBOARD_II
Fixed:
(Feature)need to add FEATURE_DURABLE which will ignore CPU errors, increasing stability at the cost of bugginess
(RetroArch port)set the alarm LED using retro_set_led_state_t on RetroArch
(CPU I/O)SPI1 SPISPC register(this is just a clock divider used to slow transfers to allow the voltages to settle, since the emu has no voltages all transfers are just instant)
(CPU)TCN2 is unimplemented and seems to be used by the same routines that turn the CPU off for sleep mode(it is implemented now and it wasn't the cause of the sleep mode issue)
(CPU)SCR privilege violation doesnt trigger the same as on hardware(likely has to do with not emulating the unused chip selects)(I added those chip selects)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

View File

@@ -875,12 +875,12 @@ enum retro_mod
* types already defined in the libretro API.
*
* The core must pass an array of const struct retro_controller_info which
* is terminated with a blanked out struct. Each element of the
* is terminated with a blanked out struct. Each element of the
* retro_controller_info struct corresponds to the ascending port index
* that is passed to retro_set_controller_port_device() when that function
* is called to indicate to the core that the frontend has changed the
* active device subclass. SEE ALSO: retro_set_controller_port_device()
*
*
* The ascending input port indexes provided by the core in the struct
* are generally presented by frontends as ascending User # or Player #,
* such as Player 1, Player 2, Player 3, etc. Which device subclasses are
@@ -892,7 +892,7 @@ enum retro_mod
* User or Player, beginning with the generic Libretro device that the
* subclasses are derived from. The second inner element of each entry is the
* total number of subclasses that are listed in the retro_controller_description.
*
*
* NOTE: Even if special device types are set in the libretro core,
* libretro should only poll input based on the base input device types.
*/
@@ -1079,10 +1079,19 @@ enum retro_mod
* fastforwarding mode.
*/
#define RETRO_ENVIRONMENT_GET_TARGET_REFRESH_RATE (50 | RETRO_ENVIRONMENT_EXPERIMENTAL)
/* float * --
* Float value that lets us know what target refresh rate
* is curently in use by the frontend.
*
* The core can use the returned value to set an ideal
* refresh rate/framerate.
*/
/* VFS functionality */
/* File paths:
* File paths passed as parameters when using this api shall be well formed unix-style,
* File paths passed as parameters when using this api shall be well formed UNIX-style,
* using "/" (unquoted forward slash) as directory separator regardless of the platform's native separator.
* Paths shall also include at least one forward slash ("game.bin" is an invalid path, use "./game.bin" instead).
* Other than the directory separator, cores shall not make assumptions about path format:
@@ -1100,6 +1109,10 @@ enum retro_mod
* Introduced in VFS API v1 */
struct retro_vfs_file_handle;
/* Opaque directory handle
* Introduced in VFS API v3 */
struct retro_vfs_dir_handle;
/* File open flags
* Introduced in VFS API v1 */
#define RETRO_VFS_FILE_ACCESS_READ (1 << 0) /* Read only mode */
@@ -1119,6 +1132,12 @@ struct retro_vfs_file_handle;
#define RETRO_VFS_SEEK_POSITION_CURRENT 1
#define RETRO_VFS_SEEK_POSITION_END 2
/* stat() result flags
* Introduced in VFS API v3 */
#define RETRO_VFS_STAT_IS_VALID (1 << 0)
#define RETRO_VFS_STAT_IS_DIRECTORY (1 << 1)
#define RETRO_VFS_STAT_IS_CHARACTER_SPECIAL (1 << 2)
/* Get path from opaque handle. Returns the exact same path passed to file_open when getting the handle
* Introduced in VFS API v1 */
typedef const char *(RETRO_CALLCONV *retro_vfs_get_path_t)(struct retro_vfs_file_handle *stream);
@@ -1128,7 +1147,7 @@ typedef const char *(RETRO_CALLCONV *retro_vfs_get_path_t)(struct retro_vfs_file
* Introduced in VFS API v1 */
typedef struct retro_vfs_file_handle *(RETRO_CALLCONV *retro_vfs_open_t)(const char *path, unsigned mode, unsigned hints);
/* Close the file and release its resources. Must be called if open_file returns non-NULL. Returns 0 on succes, -1 on failure.
/* Close the file and release its resources. Must be called if open_file returns non-NULL. Returns 0 on success, -1 on failure.
* Whether the call succeeds ot not, the handle passed as parameter becomes invalid and should no longer be used.
* Introduced in VFS API v1 */
typedef int (RETRO_CALLCONV *retro_vfs_close_t)(struct retro_vfs_file_handle *stream);
@@ -1141,7 +1160,7 @@ typedef int64_t (RETRO_CALLCONV *retro_vfs_size_t)(struct retro_vfs_file_handle
* Introduced in VFS API v2 */
typedef int64_t (RETRO_CALLCONV *retro_vfs_truncate_t)(struct retro_vfs_file_handle *stream, int64_t length);
/* Get the current read / write position for the file. Returns - 1 for error.
/* Get the current read / write position for the file. Returns -1 for error.
* Introduced in VFS API v1 */
typedef int64_t (RETRO_CALLCONV *retro_vfs_tell_t)(struct retro_vfs_file_handle *stream);
@@ -1169,6 +1188,39 @@ typedef int (RETRO_CALLCONV *retro_vfs_remove_t)(const char *path);
* Introduced in VFS API v1 */
typedef int (RETRO_CALLCONV *retro_vfs_rename_t)(const char *old_path, const char *new_path);
/* Stat the specified file. Retruns a bitmask of RETRO_VFS_STAT_* flags, none are set if path was not valid.
* Additionally stores file size in given variable, unless NULL is given.
* Introduced in VFS API v3 */
typedef int (RETRO_CALLCONV *retro_vfs_stat_t)(const char *path, int32_t *size);
/* Create the specified directory. Returns 0 on success, -1 on unknown failure, -2 if already exists.
* Introduced in VFS API v3 */
typedef int (RETRO_CALLCONV *retro_vfs_mkdir_t)(const char *dir);
/* Open the specified directory for listing. Returns the opaque dir handle, or NULL for error.
* Support for the include_hidden argument may vary depending on the platform.
* Introduced in VFS API v3 */
typedef struct retro_vfs_dir_handle *(RETRO_CALLCONV *retro_vfs_opendir_t)(const char *dir, bool include_hidden);
/* Read the directory entry at the current position, and move the read pointer to the next position.
* Returns true on success, false if already on the last entry.
* Introduced in VFS API v3 */
typedef bool (RETRO_CALLCONV *retro_vfs_readdir_t)(struct retro_vfs_dir_handle *dirstream);
/* Get the name of the last entry read. Returns a string on success, or NULL for error.
* The returned string pointer is valid until the next call to readdir or closedir.
* Introduced in VFS API v3 */
typedef const char *(RETRO_CALLCONV *retro_vfs_dirent_get_name_t)(struct retro_vfs_dir_handle *dirstream);
/* Check if the last entry read was a directory. Returns true if it was, false otherwise (or on error).
* Introduced in VFS API v3 */
typedef bool (RETRO_CALLCONV *retro_vfs_dirent_is_dir_t)(struct retro_vfs_dir_handle *dirstream);
/* Close the directory and release its resources. Must be called if opendir returns non-NULL. Returns 0 on success, -1 on failure.
* Whether the call succeeds ot not, the handle passed as parameter becomes invalid and should no longer be used.
* Introduced in VFS API v3 */
typedef int (RETRO_CALLCONV *retro_vfs_closedir_t)(struct retro_vfs_dir_handle *dirstream);
struct retro_vfs_interface
{
/* VFS API v1 */
@@ -1185,6 +1237,14 @@ struct retro_vfs_interface
retro_vfs_rename_t rename;
/* VFS API v2 */
retro_vfs_truncate_t truncate;
/* VFS API v3 */
retro_vfs_stat_t stat;
retro_vfs_mkdir_t mkdir;
retro_vfs_opendir_t opendir;
retro_vfs_readdir_t readdir;
retro_vfs_dirent_get_name_t dirent_get_name;
retro_vfs_dirent_is_dir_t dirent_is_dir;
retro_vfs_closedir_t closedir;
};
struct retro_vfs_interface_info
@@ -1207,6 +1267,7 @@ enum retro_hw_render_interface_type
RETRO_HW_RENDER_INTERFACE_D3D10 = 2,
RETRO_HW_RENDER_INTERFACE_D3D11 = 3,
RETRO_HW_RENDER_INTERFACE_D3D12 = 4,
RETRO_HW_RENDER_INTERFACE_GSKIT_PS2 = 5,
RETRO_HW_RENDER_INTERFACE_DUMMY = INT_MAX
};

View File

@@ -22,12 +22,13 @@
#define SCREEN_HIRES (!(palmFramebufferWidth == 160 && palmFramebufferHeight == 220))
static retro_log_printf_t log_cb;
static retro_video_refresh_t video_cb;
static retro_audio_sample_batch_t audio_cb;
static retro_environment_t environ_cb;
static retro_input_poll_t input_poll_cb;
static retro_input_state_t input_state_cb;
static retro_log_printf_t log_cb = NULL;
static retro_video_refresh_t video_cb = NULL;
static retro_audio_sample_batch_t audio_cb = NULL;
static retro_set_led_state_t led_cb = NULL;
static retro_environment_t environ_cb = NULL;
static retro_input_poll_t input_poll_cb = NULL;
static retro_input_state_t input_state_cb = NULL;
static uint32_t emuFeatures;
static bool useJoystickAsMouse;
@@ -80,26 +81,11 @@ static void check_variables(bool booting){
if(booting){
emuFeatures = FEATURE_ACCURATE;
var.key = "palm_emu_feature_ram_huge";
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
if (!strcmp(var.value, "enabled"))
emuFeatures |= FEATURE_RAM_HUGE;
var.key = "palm_emu_feature_fast_cpu";
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
if (!strcmp(var.value, "enabled"))
emuFeatures |= FEATURE_FAST_CPU;
var.key = "palm_emu_feature_hybrid_cpu";
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
if (!strcmp(var.value, "enabled"))
emuFeatures |= FEATURE_HYBRID_CPU;
var.key = "palm_emu_feature_custom_fb";
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
if (!strcmp(var.value, "enabled"))
emuFeatures |= FEATURE_CUSTOM_FB;
var.key = "palm_emu_feature_synced_rtc";
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
if (!strcmp(var.value, "enabled"))
@@ -110,15 +96,10 @@ static void check_variables(bool booting){
if (!strcmp(var.value, "enabled"))
emuFeatures |= FEATURE_HLE_APIS;
var.key = "palm_emu_feature_emu_honest";
var.key = "palm_emu_feature_durable";
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
if (!strcmp(var.value, "enabled"))
emuFeatures |= FEATURE_EMU_HONEST;
var.key = "palm_emu_feature_ext_keys";
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
if (!strcmp(var.value, "enabled"))
emuFeatures |= FEATURE_EXT_KEYS;
emuFeatures |= FEATURE_DURABLE;
}
var.key = "palm_emu_use_joystick_as_mouse";
@@ -167,53 +148,52 @@ void retro_get_system_av_info(struct retro_system_av_info *info){
info->geometry.base_width = 160;
info->geometry.base_height = 220;
info->geometry.max_width = 480;
info->geometry.max_height = 480;
info->geometry.max_width = 160;
info->geometry.max_height = 220;
info->geometry.aspect_ratio = 160.0 / 220.0;
}
void retro_set_environment(retro_environment_t cb){
struct retro_log_callback logging;
struct retro_vfs_interface_info vfs_getter = { 1, NULL };
struct retro_led_interface led_getter;
struct retro_variable vars[] = {
{ "palm_emu_feature_ram_huge", "128mb RAM; disabled|enabled" },
{ "palm_emu_feature_fast_cpu", "Custom CPU Speeds; disabled|enabled" },
{ "palm_emu_feature_hybrid_cpu", "ARM Instruction Set; disabled|enabled" },
{ "palm_emu_feature_custom_fb", "Custom Resolution; disabled|enabled" },
{ "palm_emu_feature_synced_rtc", "Force Match System Clock; disabled|enabled" },
{ "palm_emu_feature_hle_apis", "HLE API Implementations; disabled|enabled" },
{ "palm_emu_feature_emu_honest", "Is Emulator(for test programs); disabled|enabled" },
{ "palm_emu_feature_ext_keys", "Left, Right, Center Keys; disabled|enabled" },
{ "palm_emu_feature_durable", "Ignore Invalid Behavior; disabled|enabled" },
{ "palm_emu_use_joystick_as_mouse", "Use Left Joystick As Mouse; disabled|enabled" },
{ 0 }
};
struct retro_input_descriptor input_desc[] = {
{ 0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Touchscreen Mouse X" },
{ 0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Touchscreen Mouse Y" },
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2, "Touchscreen Mouse Click" },
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "Dpad Left" },
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "Dpad Up" },
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "Dpad Down" },
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "Dpad Right" },
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "Dpad Middle" },
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Power" },
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "Calender" },
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "Address Book" },
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Todo" },
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Notes" },
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2, "Touchscreen Mouse Click" },
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "Dpad Up" },
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "Dpad Down" },
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Power" },
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "Calender" },
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "Address Book" },
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Todo" },
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Notes" },
{ 0 }
};
environ_cb = cb;
if (environ_cb(RETRO_ENVIRONMENT_GET_LOG_INTERFACE, &logging))
if(environ_cb(RETRO_ENVIRONMENT_GET_LOG_INTERFACE, &logging) && logging.log)
log_cb = logging.log;
else
if(!log_cb)
log_cb = fallback_log;
if(environ_cb(RETRO_ENVIRONMENT_GET_VFS_INTERFACE, &vfs_getter))
filestream_vfs_init(&vfs_getter);
led_getter.set_led_state = NULL;
if(environ_cb(RETRO_ENVIRONMENT_GET_LED_INTERFACE, &led_getter) && led_getter.set_led_state)
led_cb = led_getter.set_led_state;
if(environ_cb(RETRO_ENVIRONMENT_GET_VFS_INTERFACE, &vfs_getter) && vfs_getter.iface)
filestream_vfs_init(&vfs_getter);
environ_cb(RETRO_ENVIRONMENT_SET_VARIABLES, vars);
environ_cb(RETRO_ENVIRONMENT_SET_INPUT_DESCRIPTORS, input_desc);
}
@@ -279,10 +259,7 @@ void retro_run(void){
//dpad
palmInput.buttonUp = input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP);
palmInput.buttonRight = input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT);
palmInput.buttonDown = input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN);
palmInput.buttonLeft = input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT);
palmInput.buttonCenter = input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R);
//app buttons
palmInput.buttonCalendar = input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A);
@@ -302,6 +279,8 @@ void retro_run(void){
video_cb(palmFramebuffer, palmFramebufferWidth, palmFramebufferHeight, palmFramebufferWidth * sizeof(uint16_t));
audio_cb(palmAudio, AUDIO_SAMPLES_PER_FRAME);
if(led_cb)
led_cb(0, palmMisc.powerButtonLed);
}
bool retro_load_game(const struct retro_game_info *info){

View File

@@ -7,7 +7,7 @@ categories = "Emulator"
systemname = "Palm OS"
license = "Non-commercial"
permissions = ""
display_version = "v1.0.0"
display_version = "v1.1.0"
supports_no_game = "false"
firmware_count = 1
firmware0_desc = "bootloader-en-m515.rom (MC68VZ328 UART Bootloader)"

View File

@@ -22,6 +22,8 @@ DEFINES += QT_DEPRECATED_WARNINGS
# You can also select to disable deprecated APIs only up to a certain version of Qt.
DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
CONFIG += support_palm_os5
windows{
RC_ICONS = windows/Mu.ico
*msvc*{
@@ -58,16 +60,13 @@ android{
DEFINES += EMU_MULTITHREADED
}
ios{
# QMAKE_INFO_PLIST = ios/Info.plist
DEFINES += EMU_MULTITHREADED
}
CONFIG(debug, debug|release){
# debug build, be accurate, fail hard, and add logging
DEFINES += EMU_DEBUG EMU_CUSTOM_DEBUG_LOG_HANDLER EMU_SANDBOX
# DEFINES += EMU_SANDBOX_LOG_MEMORY_ACCESSES # checks all reads and writes to memory and logs certain events
DEFINES += EMU_SANDBOX_OPCODE_LEVEL_DEBUG # for breakpoints
DEFINES += EMU_SANDBOX_LOG_JUMPS # log large jumps
DEFINES += EMU_SANDBOX_LOG_APIS # for printing sysTrap* calls, EMU_SANDBOX_OPCODE_LEVEL_DEBUG must be on too
macx|linux-g++{
# also check for any buffer overflows and memory leaks
@@ -81,6 +80,11 @@ CONFIG(debug, debug|release){
DEFINES += EMU_NO_SAFETY
}
support_palm_os5{
DEFINES += EMU_SUPPORT_PALM_OS5 # the Qt build will not be supporting anything too slow to run OS 5
# SOURCES +=
}
CONFIG += c++11
INCLUDEPATH += $$PWD/qt-common/include
@@ -97,8 +101,6 @@ SOURCES += \
../../src/ads7846.c \
../../src/emulator.c \
../../src/flx68000.c \
../../src/hardwareRegisters.c \
../../src/memoryAccess.c \
../../src/pdiUsbD12.c \
../../src/sdCard.c \
../../src/sed1376.c \
@@ -109,11 +111,10 @@ SOURCES += \
../../src/m68k/m68kopdm.c \
../../src/m68k/m68kopnz.c \
../../src/m68k/m68kops.c \
../../src/armv5/CPU.c \
../../src/armv5/icache.c \
../../src/armv5.c \
../../src/expansionHardware.c \
settingsmanager.cpp
settingsmanager.cpp \
../../src/m515Bus.c \
../../src/dbvzRegisters.c
HEADERS += \
debugviewer.h \
@@ -134,10 +135,6 @@ HEADERS += \
../../src/ads7846.h \
../../src/emulator.h \
../../src/flx68000.h \
../../src/hardwareRegisters.h \
../../src/hardwareRegistersAccessors.c.h \
../../src/hardwareRegistersTiming.c.h \
../../src/memoryAccess.h \
../../src/pdiUsbD12.h \
../../src/portability.h \
../../src/sdCard.h \
@@ -148,15 +145,14 @@ HEADERS += \
../../src/specs/pdiUsbD12CommandSpec.h \
../../src/specs/emuFeatureRegisterSpec.h \
../../src/specs/sdCardCommandSpec.h \
../../src/armv5/CPU.h \
../../src/armv5/math64.h \
../../src/armv5/types.h \
../../src/armv5/icache.h \
../../src/armv5.h \
../../src/expansionHardware.h \
../../src/sdCardAccessors.c.h \
../../src/sdCardCrcTables.c.h \
settingsmanager.h
settingsmanager.h \
../../src/m515Bus.h \
../../src/dbvzRegisterAccessors.c.h \
../../src/dbvzTiming.c.h \
../../src/dbvzRegisters.h
FORMS += \
mainwindow.ui \

View File

@@ -342,18 +342,6 @@ void EmuWrapper::setKeyValue(uint8_t key, bool pressed){
emuInput.buttonDown = pressed;
break;
case BUTTON_LEFT:
emuInput.buttonLeft = pressed;
break;
case BUTTON_RIGHT:
emuInput.buttonRight = pressed;
break;
case BUTTON_CENTER:
emuInput.buttonCenter = pressed;
break;
case BUTTON_CALENDAR:
emuInput.buttonCalendar = pressed;
break;
@@ -395,7 +383,7 @@ uint32_t EmuWrapper::installApplication(const QString& path){
appFile.close();
appData.data = (uint8_t*)appDataBuffer.data();
appData.size = appDataBuffer.size();
error = sandboxCommand(SANDBOX_INSTALL_APP, &appData);
error = sandboxCommand(SANDBOX_CMD_DEBUG_INSTALL_APP, &appData);
}
if(!wasPaused)

View File

@@ -32,9 +32,6 @@ public:
enum{
BUTTON_UP = 0,
BUTTON_DOWN,
BUTTON_LEFT,
BUTTON_RIGHT,
BUTTON_CENTER,
BUTTON_CALENDAR,
BUTTON_ADDRESS,
BUTTON_TODO,

View File

@@ -1 +0,0 @@
<svg height="48" width="48" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><radialGradient id="a" cx="24.837" cy="36.421" gradientTransform="matrix(1 0 0 .536723 0 16.87306)" gradientUnits="userSpaceOnUse" r="15.645"><stop offset="0"/><stop offset="1" stop-opacity="0"/></radialGradient><radialGradient id="b" cx="21.929" cy="-3.218" gradientTransform="matrix(3.658819 0 0 2.080782 -62.4164 12.76204)" gradientUnits="userSpaceOnUse" r="13"><stop offset="0" stop-color="#fff"/><stop offset="1" stop-color="#fff" stop-opacity="0"/></radialGradient><radialGradient id="c" cx="22.5" cy="28.116" gradientTransform="matrix(2.365562 0 0 2.202845 -30.72517 -34.23996)" gradientUnits="userSpaceOnUse" r="14.538"><stop offset="0" stop-color="#ef2929"/><stop offset="1" stop-color="#c00"/></radialGradient><linearGradient id="d" gradientUnits="userSpaceOnUse" x1="21.702" x2="21.816" y1="8.912" y2="35.546"><stop offset="0"/><stop offset="1" stop-color="#fff" stop-opacity=".784"/></linearGradient><g fill-rule="evenodd"><path d="m36.5 22a14 13 0 1 1 -28 0 14 13 0 1 1 28 0z" style="opacity:.15;stroke-width:3.136616;stroke-linecap:square;stroke-linejoin:round;stroke:url(#d);fill:url(#c)" transform="matrix(.920697 0 0 .99358 3.679484 1.641236)"/><path d="m40.481863 36.421127a15.644737 8.3968935 0 1 1 -31.2894745 0 15.644737 8.3968935 0 1 1 31.2894745 0z" fill="url(#a)" opacity=".04" transform="matrix(1.150533 0 0 .565685 -4.5765 16.55285)"/><path d="m36.5 22a14 13 0 1 1 -28 0 14 13 0 1 1 28 0z" fill="url(#c)" stroke="#c00" stroke-linecap="square" stroke-linejoin="round" stroke-width="1.076" transform="matrix(.894862 0 0 .9657 3.855776 2.660348)"/></g><path d="m38 24a14 14 0 1 1 -28 0 14 14 0 1 1 28 0z" fill="none" stroke="#f77d7d" stroke-linecap="square" stroke-linejoin="round" stroke-width="1.217" transform="matrix(.821429 0 0 .821429 4.285117 4.191455)"/><path d="m23.84315 11.90574c-6.279532.079595-11.404423 4.992059-11.8125 11.1875 6.117823 2.51678 13.87042-1.451223 23.142005-3.381886-.68841-2.748569-4.55472-7.805614-11.173255-7.805614-.051707 0-.104697-.000653-.15625 0z" fill="url(#b)" fill-rule="evenodd" opacity=".6"/></svg>

Before

Width:  |  Height:  |  Size: 2.1 KiB

View File

@@ -1 +0,0 @@
<svg height="48" width="48" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><radialGradient id="a" cx="25.075571" cy="5.78598" gradientTransform="matrix(-2.046729 0 0 1.55761 67.59375 3.275309)" gradientUnits="userSpaceOnUse" r="17.171415"><stop offset="0" stop-color="#fff"/><stop offset="1" stop-color="#fff" stop-opacity="0"/></radialGradient><radialGradient id="b" cx="24.837126" cy="36.421127" gradientTransform="matrix(1 0 0 .536723 0 16.87306)" gradientUnits="userSpaceOnUse" r="15.644737"><stop offset="0"/><stop offset="1" stop-opacity="0"/></radialGradient><radialGradient id="c" cx="22.291636" cy="32.797512" gradientTransform="matrix(-.843022 0 0 1.020168 43.57646 1.205215)" gradientUnits="userSpaceOnUse" r="16.956199"><stop offset="0" stop-color="#73d216"/><stop offset="1" stop-color="#4e9a06"/></radialGradient><g fill-rule="evenodd"><path d="m40.481863 36.421127a15.644737 8.3968935 0 1 1 -31.2894745 0 15.644737 8.3968935 0 1 1 31.2894745 0z" fill="url(#b)" opacity=".299465" transform="matrix(-1.271186 0 0 1.271186 56.19514 -15.27857)"/><path d="m39.490316 15.496821v16.99442h-12.952563v8.482538l-19.959836-17.000191 19.953646-17.2439979v8.7725349z" fill="url(#c)" stroke="#3a7304" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10"/><path d="m25.988368 7.9779766v8.0564744h12.94217v8.884463c-16.75-6.25-16.133537 5.294712-31.383538-.955288z" fill="url(#a)" opacity=".508021"/></g><path d="m38.475551 16.541365v14.92194h-12.985367v7.301416l-17.321765-14.795691 17.337726-14.9054001v7.4826321z" fill="none" opacity=".481283" stroke="#fff" stroke-miterlimit="10"/></svg>

Before

Width:  |  Height:  |  Size: 1.6 KiB

View File

@@ -1 +0,0 @@
<svg height="48" width="48" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><radialGradient id="a" cx="19.701141" cy="2.896938" gradientTransform="matrix(2.046729 0 0 1.55761 -19.51799 3.452086)" gradientUnits="userSpaceOnUse" r="17.171415"><stop offset="0" stop-color="#fff"/><stop offset="1" stop-color="#fff" stop-opacity="0"/></radialGradient><radialGradient id="b" cx="24.837126" cy="36.421127" gradientTransform="matrix(1 0 0 .536723 0 16.87306)" gradientUnits="userSpaceOnUse" r="15.644737"><stop offset="0"/><stop offset="1" stop-opacity="0"/></radialGradient><radialGradient id="c" cx="22.291636" cy="32.797512" gradientTransform="matrix(.843022 0 0 1.020168 4.499298 1.381992)" gradientUnits="userSpaceOnUse" r="16.9562"><stop offset="0" stop-color="#73d216"/><stop offset="1" stop-color="#4e9a06"/></radialGradient><g fill-rule="evenodd"><path d="m40.481863 36.421127a15.644737 8.3968935 0 1 1 -31.2894745 0 15.644737 8.3968935 0 1 1 31.2894745 0z" fill="url(#b)" opacity=".299465" transform="matrix(1.271186 0 0 1.271186 -8.119376 -15.10179)"/><path d="m8.5541875 15.517348v16.99442h12.9838125v8.545038l19.959835-16.906441-20.078645-17.0252482v8.3975352z" fill="url(#c)" stroke="#3a7304" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10"/><path d="m21.962385 8.2485033v7.8064747h-12.8171699v9.040713c17.7499999 2 16.6335369-7.455288 31.3835369-.955288z" fill="url(#a)" opacity=".508021"/></g><path d="m9.537702 16.561892v14.98444h12.985367v7.395166l17.478014-14.795691-17.493975-14.7804004v7.2013824z" fill="none" opacity=".481283" stroke="#fff" stroke-miterlimit="10"/></svg>

Before

Width:  |  Height:  |  Size: 1.6 KiB

View File

@@ -87,7 +87,7 @@ MainWindow::MainWindow(QWidget* parent) :
settings->setValue("hideOnscreenKeys", true);
#endif
}
hideOnscreenKeys = settings->value("hideOnscreenKeys", "").toBool();
hideOnscreenKeys = settings->value("hideOnscreenKeys", false).toBool();
//this makes the display window and button icons resize properly
ui->centralWidget->installEventFilter(this);
@@ -95,9 +95,6 @@ MainWindow::MainWindow(QWidget* parent) :
ui->up->installEventFilter(this);
ui->down->installEventFilter(this);
ui->left->installEventFilter(this);
ui->right->installEventFilter(this);
ui->center->installEventFilter(this);
ui->calendar->installEventFilter(this);
ui->addressBook->installEventFilter(this);
@@ -107,18 +104,16 @@ MainWindow::MainWindow(QWidget* parent) :
ui->power->installEventFilter(this);
ui->ctrlBtn->installEventFilter(this);
ui->reset->installEventFilter(this);
ui->stateManager->installEventFilter(this);
ui->screenshot->installEventFilter(this);
ui->settings->installEventFilter(this);
ui->install->installEventFilter(this);
ui->debugger->installEventFilter(this);
ui->screenshot->installEventFilter(this);
ui->stateManager->installEventFilter(this);
ui->reset->installEventFilter(this);
//hide onscreen keys if needed
ui->up->setHidden(hideOnscreenKeys);
ui->down->setHidden(hideOnscreenKeys);
ui->left->setHidden(hideOnscreenKeys);
ui->right->setHidden(hideOnscreenKeys);
ui->center->setHidden(hideOnscreenKeys);
ui->calendar->setHidden(hideOnscreenKeys);
ui->addressBook->setHidden(hideOnscreenKeys);
@@ -174,24 +169,10 @@ void MainWindow::createHomeDirectoryTree(const QString& path){
uint32_t MainWindow::getEmuFeatureList(){
uint32_t features = FEATURE_ACCURATE;
features |= settings->value("feature128mbRam", false).toBool() ? FEATURE_RAM_HUGE : 0;
features |= settings->value("featureFastCpu", false).toBool() ? FEATURE_FAST_CPU : 0;
features |= settings->value("featureHybridCpu", false).toBool() ? FEATURE_HYBRID_CPU : 0;
features |= settings->value("featureCustomFb", false).toBool() ? FEATURE_CUSTOM_FB : 0;
features |= settings->value("featureSyncedRtc", false).toBool() ? FEATURE_SYNCED_RTC : 0;
features |= settings->value("featureHleApis", false).toBool() ? FEATURE_HLE_APIS : 0;
features |= settings->value("featureEmuHonest", false).toBool() ? FEATURE_EMU_HONEST : 0;
features |= settings->value("featureExtraKeys", false).toBool() ? FEATURE_EXT_KEYS : 0;
features |= settings->value("featureSoundStreams", false).toBool() ? FEATURE_SND_STRMS : 0;
#if defined(EMU_DEBUG)
features |= FEATURE_DEBUG;
#endif
//lazy debug overrides
//features = FEATURE_EXT_KEYS | FEATURE_EMU_HONEST | FEATURE_FAST_CPU | FEATURE_HYBRID_CPU | FEATURE_CUSTOM_FB | FEATURE_DEBUG | FEATURE_SND_STRMS;
//features = FEATURE_FAST_CPU | FEATURE_HYBRID_CPU | FEATURE_CUSTOM_FB | FEATURE_DEBUG;
//features = FEATURE_FAST_CPU | FEATURE_HYBRID_CPU | FEATURE_DEBUG;
features |= settings->value("featureDurable", false).toBool() ? FEATURE_DURABLE : 0;
return features;
}
@@ -205,15 +186,12 @@ void MainWindow::popupInformationDialog(const QString& info){
}
void MainWindow::redraw(){
bool hideOnscreenKeys = settings->value("hideOnscreenKeys", "").toBool();
bool hideOnscreenKeys = settings->value("hideOnscreenKeys", false).toBool();
QResizeEvent* resizeEvent = new QResizeEvent(ui->centralWidget->size(), ui->centralWidget->size());
//update current keys
ui->up->setHidden(hideOnscreenKeys);
ui->down->setHidden(hideOnscreenKeys);
ui->left->setHidden(hideOnscreenKeys);
ui->right->setHidden(hideOnscreenKeys);
ui->center->setHidden(hideOnscreenKeys);
ui->calendar->setHidden(hideOnscreenKeys);
ui->addressBook->setHidden(hideOnscreenKeys);
@@ -236,7 +214,7 @@ bool MainWindow::eventFilter(QObject* object, QEvent* event){
if(object->objectName() == "centralWidget"){
float smallestRatio;
bool hideOnscreenKeys = settings->value("hideOnscreenKeys", "").toBool();
bool hideOnscreenKeys = settings->value("hideOnscreenKeys", false).toBool();
//update displayContainer first, make the display occupy the top 3/5 of the screen if there are Palm keys or 4/5 if theres not
ui->displayContainer->setFixedHeight(ui->centralWidget->height() * (hideOnscreenKeys ? 0.80 : 0.60));
@@ -336,22 +314,6 @@ void MainWindow::on_down_released(){
emu.setKeyValue(EmuWrapper::BUTTON_DOWN, false);
}
void MainWindow::on_left_pressed(){
emu.setKeyValue(EmuWrapper::BUTTON_LEFT, true);
}
void MainWindow::on_left_released(){
emu.setKeyValue(EmuWrapper::BUTTON_LEFT, false);
}
void MainWindow::on_right_pressed(){
emu.setKeyValue(EmuWrapper::BUTTON_RIGHT, true);
}
void MainWindow::on_right_released(){
emu.setKeyValue(EmuWrapper::BUTTON_RIGHT, false);
}
//emu control
void MainWindow::on_ctrlBtn_clicked(){
if(!emu.isInited()){
@@ -370,12 +332,6 @@ void MainWindow::on_ctrlBtn_clicked(){
ui->power->setEnabled(true);
if(enabledFeatures & FEATURE_EXT_KEYS){
ui->left->setEnabled(true);
ui->right->setEnabled(true);
ui->center->setEnabled(true);
}
ui->screenshot->setEnabled(true);
ui->install->setEnabled(true);
ui->stateManager->setEnabled(true);

View File

@@ -64,10 +64,6 @@ private slots:
void on_up_released();
void on_down_pressed();
void on_down_released();
void on_left_pressed();
void on_left_released();
void on_right_pressed();
void on_right_released();
//frontend buttons
void on_ctrlBtn_clicked();

View File

@@ -2,16 +2,13 @@
<qresource prefix="/buttons">
<file>images/addressBook.svg</file>
<file>images/calendar.svg</file>
<file>images/center.svg</file>
<file>images/debugger.svg</file>
<file>images/down.svg</file>
<file>images/install.svg</file>
<file>images/left.svg</file>
<file>images/notes.svg</file>
<file>images/pause.svg</file>
<file>images/play.svg</file>
<file>images/power.svg</file>
<file>images/right.svg</file>
<file>images/screenshot.svg</file>
<file>images/stateManager.svg</file>
<file>images/stop.svg</file>

View File

@@ -94,8 +94,25 @@
<property name="bottomMargin">
<number>0</number>
</property>
<item row="7" column="1">
<widget class="QPushButton" name="addressBook">
<item row="0" column="0">
<widget class="QPushButton" name="ctrlBtn">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="styleSheet">
<string notr="true"/>
</property>
<property name="icon">
<iconset resource="mainwindow.qrc">
<normaloff>:/buttons/images/play.svg</normaloff>:/buttons/images/play.svg</iconset>
</property>
</widget>
</item>
<item row="6" column="7">
<widget class="QPushButton" name="notes">
<property name="enabled">
<bool>false</bool>
</property>
@@ -107,7 +124,102 @@
</property>
<property name="icon">
<iconset resource="mainwindow.qrc">
<normaloff>:/buttons/images/addressBook.svg</normaloff>:/buttons/images/addressBook.svg</iconset>
<normaloff>:/buttons/images/notes.svg</normaloff>:/buttons/images/notes.svg</iconset>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QPushButton" name="reset">
<property name="enabled">
<bool>false</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="icon">
<iconset resource="mainwindow.qrc">
<normaloff>:/buttons/images/reset.svg</normaloff>:/buttons/images/reset.svg</iconset>
</property>
</widget>
</item>
<item row="0" column="7">
<widget class="QLabel" name="powerButtonLed">
<property name="frameShape">
<enum>QFrame::Box</enum>
</property>
<property name="text">
<string>LED</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item row="0" column="4">
<widget class="QPushButton" name="stateManager">
<property name="enabled">
<bool>false</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="icon">
<iconset resource="mainwindow.qrc">
<normaloff>:/buttons/images/stateManager.svg</normaloff>:/buttons/images/stateManager.svg</iconset>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QPushButton" name="calendar">
<property name="enabled">
<bool>false</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="icon">
<iconset resource="mainwindow.qrc">
<normaloff>:/buttons/images/calendar.svg</normaloff>:/buttons/images/calendar.svg</iconset>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QPushButton" name="settings">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="icon">
<iconset resource="mainwindow.qrc">
<normaloff>:/buttons/images/settingsManager.svg</normaloff>:/buttons/images/settingsManager.svg</iconset>
</property>
</widget>
</item>
<item row="2" column="4">
<widget class="QPushButton" name="up">
<property name="enabled">
<bool>false</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="icon">
<iconset resource="mainwindow.qrc">
<normaloff>:/buttons/images/up.svg</normaloff>:/buttons/images/up.svg</iconset>
</property>
</widget>
</item>
@@ -128,8 +240,8 @@
</property>
</widget>
</item>
<item row="4" column="5">
<widget class="QPushButton" name="right">
<item row="1" column="4">
<widget class="QPushButton" name="debugger">
<property name="enabled">
<bool>false</bool>
</property>
@@ -141,28 +253,45 @@
</property>
<property name="icon">
<iconset resource="mainwindow.qrc">
<normaloff>:/buttons/images/right.svg</normaloff>:/buttons/images/right.svg</iconset>
<normaloff>:/buttons/images/debugger.svg</normaloff>:/buttons/images/debugger.svg</iconset>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QPushButton" name="ctrlBtn">
<item row="6" column="1">
<widget class="QPushButton" name="addressBook">
<property name="enabled">
<bool>false</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="styleSheet">
<string notr="true"/>
</property>
<property name="icon">
<iconset resource="mainwindow.qrc">
<normaloff>:/buttons/images/play.svg</normaloff>:/buttons/images/play.svg</iconset>
<normaloff>:/buttons/images/addressBook.svg</normaloff>:/buttons/images/addressBook.svg</iconset>
</property>
</widget>
</item>
<item row="7" column="5">
<item row="1" column="1">
<widget class="QPushButton" name="install">
<property name="enabled">
<bool>false</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="icon">
<iconset resource="mainwindow.qrc">
<normaloff>:/buttons/images/install.svg</normaloff>:/buttons/images/install.svg</iconset>
</property>
</widget>
</item>
<item row="6" column="5">
<widget class="QPushButton" name="todo">
<property name="enabled">
<bool>false</bool>
@@ -191,105 +320,7 @@
</property>
</widget>
</item>
<item row="0" column="7">
<widget class="QLabel" name="powerButtonLed">
<property name="frameShape">
<enum>QFrame::Box</enum>
</property>
<property name="text">
<string>LED</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item row="7" column="7">
<widget class="QPushButton" name="notes">
<property name="enabled">
<bool>false</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="icon">
<iconset resource="mainwindow.qrc">
<normaloff>:/buttons/images/notes.svg</normaloff>:/buttons/images/notes.svg</iconset>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QPushButton" name="left">
<property name="enabled">
<bool>false</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="icon">
<iconset resource="mainwindow.qrc">
<normaloff>:/buttons/images/left.svg</normaloff>:/buttons/images/left.svg</iconset>
</property>
</widget>
</item>
<item row="0" column="4">
<widget class="QPushButton" name="stateManager">
<property name="enabled">
<bool>false</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="icon">
<iconset resource="mainwindow.qrc">
<normaloff>:/buttons/images/stateManager.svg</normaloff>:/buttons/images/stateManager.svg</iconset>
</property>
</widget>
</item>
<item row="2" column="4">
<widget class="QPushButton" name="up">
<property name="enabled">
<bool>false</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="icon">
<iconset resource="mainwindow.qrc">
<normaloff>:/buttons/images/up.svg</normaloff>:/buttons/images/up.svg</iconset>
</property>
</widget>
</item>
<item row="4" column="4">
<widget class="QPushButton" name="center">
<property name="enabled">
<bool>false</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="icon">
<iconset resource="mainwindow.qrc">
<normaloff>:/buttons/images/center.svg</normaloff>:/buttons/images/center.svg</iconset>
</property>
</widget>
</item>
<item row="7" column="4">
<item row="6" column="4">
<widget class="QPushButton" name="down">
<property name="enabled">
<bool>false</bool>
@@ -306,23 +337,6 @@
</property>
</widget>
</item>
<item row="7" column="0">
<widget class="QPushButton" name="calendar">
<property name="enabled">
<bool>false</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="icon">
<iconset resource="mainwindow.qrc">
<normaloff>:/buttons/images/calendar.svg</normaloff>:/buttons/images/calendar.svg</iconset>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QPushButton" name="power">
<property name="enabled">
@@ -340,71 +354,6 @@
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QPushButton" name="reset">
<property name="enabled">
<bool>false</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="icon">
<iconset resource="mainwindow.qrc">
<normaloff>:/buttons/images/reset.svg</normaloff>:/buttons/images/reset.svg</iconset>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QPushButton" name="settings">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="icon">
<iconset resource="mainwindow.qrc">
<normaloff>:/buttons/images/settingsManager.svg</normaloff>:/buttons/images/settingsManager.svg</iconset>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QPushButton" name="install">
<property name="enabled">
<bool>false</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="icon">
<iconset resource="mainwindow.qrc">
<normaloff>:/buttons/images/install.svg</normaloff>:/buttons/images/install.svg</iconset>
</property>
</widget>
</item>
<item row="1" column="4">
<widget class="QPushButton" name="debugger">
<property name="enabled">
<bool>false</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="icon">
<iconset resource="mainwindow.qrc">
<normaloff>:/buttons/images/debugger.svg</normaloff>:/buttons/images/debugger.svg</iconset>
</property>
</widget>
</item>
</layout>
</widget>
</item>

View File

@@ -21,17 +21,12 @@ SettingsManager::SettingsManager(QWidget* parent) :
//set all GUI items to current config values
ui->homeDirectory->setText(settings->value("resourceDirectory", "").toString());
ui->showOnscreenKeys->setChecked(!settings->value("hideOnscreenKeys", "").toBool());
ui->showOnscreenKeys->setChecked(!settings->value("hideOnscreenKeys", false).toBool());
ui->feature128mbRam->setChecked(settings->value("feature128mbRam", false).toBool());
ui->featureFastCpu->setChecked(settings->value("featureFastCpu", false).toBool());
ui->featureHybridCpu->setChecked(settings->value("featureHybridCpu", false).toBool());
ui->featureCustomFb->setChecked(settings->value("featureCustomFb", false).toBool());
ui->featureSyncedRtc->setChecked(settings->value("featureSyncedRtc", false).toBool());
ui->featureHleApis->setChecked(settings->value("featureHleApis", false).toBool());
ui->featureEmuHonest->setChecked(settings->value("featureEmuHonest", false).toBool());
ui->featureExtraKeys->setChecked(settings->value("featureExtraKeys", false).toBool());
ui->featureSoundStreams->setChecked(settings->value("featureSoundStreams", false).toBool());
ui->featureDurable->setChecked(settings->value("featureDurable", false).toBool());
setKeySelectorState(-1);
updateButtonKeys();
@@ -63,16 +58,13 @@ void SettingsManager::setKeySelectorState(int8_t key){
}
void SettingsManager::updateButtonKeys(){
ui->selectUpKey->setText(QKeySequence(settings->value("palmButton" + QString::number(EmuWrapper::BUTTON_UP) + "Key", "").toInt()).toString());
ui->selectDownKey->setText(QKeySequence(settings->value("palmButton" + QString::number(EmuWrapper::BUTTON_DOWN) + "Key", "").toInt()).toString());
ui->selectLeftKey->setText(QKeySequence(settings->value("palmButton" + QString::number(EmuWrapper::BUTTON_LEFT) + "Key", "").toInt()).toString());
ui->selectRightKey->setText(QKeySequence(settings->value("palmButton" + QString::number(EmuWrapper::BUTTON_RIGHT) + "Key", "").toInt()).toString());
ui->selectCenterKey->setText(QKeySequence(settings->value("palmButton" + QString::number(EmuWrapper::BUTTON_CENTER) + "Key", "").toInt()).toString());
ui->selectCalendarKey->setText(QKeySequence(settings->value("palmButton" + QString::number(EmuWrapper::BUTTON_CALENDAR) + "Key", "").toInt()).toString());
ui->selectAddressBookKey->setText(QKeySequence(settings->value("palmButton" + QString::number(EmuWrapper::BUTTON_ADDRESS) + "Key", "").toInt()).toString());
ui->selectTodoKey->setText(QKeySequence(settings->value("palmButton" + QString::number(EmuWrapper::BUTTON_TODO) + "Key", "").toInt()).toString());
ui->selectNotesKey->setText(QKeySequence(settings->value("palmButton" + QString::number(EmuWrapper::BUTTON_NOTES) + "Key", "").toInt()).toString());
ui->selectPowerKey->setText(QKeySequence(settings->value("palmButton" + QString::number(EmuWrapper::BUTTON_POWER) + "Key", "").toInt()).toString());
ui->selectUpKey->setText(QKeySequence(settings->value("palmButton" + QString::number(EmuWrapper::BUTTON_UP) + "Key", '\0').toInt()).toString());
ui->selectDownKey->setText(QKeySequence(settings->value("palmButton" + QString::number(EmuWrapper::BUTTON_DOWN) + "Key", '\0').toInt()).toString());
ui->selectCalendarKey->setText(QKeySequence(settings->value("palmButton" + QString::number(EmuWrapper::BUTTON_CALENDAR) + "Key", '\0').toInt()).toString());
ui->selectAddressBookKey->setText(QKeySequence(settings->value("palmButton" + QString::number(EmuWrapper::BUTTON_ADDRESS) + "Key", '\0').toInt()).toString());
ui->selectTodoKey->setText(QKeySequence(settings->value("palmButton" + QString::number(EmuWrapper::BUTTON_TODO) + "Key", '\0').toInt()).toString());
ui->selectNotesKey->setText(QKeySequence(settings->value("palmButton" + QString::number(EmuWrapper::BUTTON_NOTES) + "Key", '\0').toInt()).toString());
ui->selectPowerKey->setText(QKeySequence(settings->value("palmButton" + QString::number(EmuWrapper::BUTTON_POWER) + "Key", '\0').toInt()).toString());
}
void SettingsManager::on_showOnscreenKeys_toggled(bool checked){
@@ -98,18 +90,6 @@ void SettingsManager::on_selectDownKey_clicked(){
setKeySelectorState(EmuWrapper::BUTTON_DOWN);
}
void SettingsManager::on_selectLeftKey_clicked(){
setKeySelectorState(EmuWrapper::BUTTON_LEFT);
}
void SettingsManager::on_selectRightKey_clicked(){
setKeySelectorState(EmuWrapper::BUTTON_RIGHT);
}
void SettingsManager::on_selectCenterKey_clicked(){
setKeySelectorState(EmuWrapper::BUTTON_CENTER);
}
void SettingsManager::on_selectCalendarKey_clicked(){
setKeySelectorState(EmuWrapper::BUTTON_CALENDAR);
}
@@ -130,22 +110,19 @@ void SettingsManager::on_selectPowerKey_clicked(){
setKeySelectorState(EmuWrapper::BUTTON_POWER);
}
void SettingsManager::on_feature128mbRam_toggled(bool checked){
settings->setValue("feature128mbRam", checked);
void SettingsManager::on_clearKeyBind_clicked(){
if(waitingOnKeyForButton != -1){
settings->setValue("palmButton" + QString::number(waitingOnKeyForButton) + "Key", '\0');
setKeySelectorState(-1);
updateButtonKeys();
}
}
void SettingsManager::on_featureFastCpu_toggled(bool checked){
settings->setValue("featureFastCpu", checked);
}
void SettingsManager::on_featureHybridCpu_toggled(bool checked){
settings->setValue("featureHybridCpu", checked);
}
void SettingsManager::on_featureCustomFb_toggled(bool checked){
settings->setValue("featureCustomFb", checked);
}
void SettingsManager::on_featureSyncedRtc_toggled(bool checked){
settings->setValue("featureSyncedRtc", checked);
}
@@ -154,14 +131,6 @@ void SettingsManager::on_featureHleApis_toggled(bool checked){
settings->setValue("featureHleApis", checked);
}
void SettingsManager::on_featureEmuHonest_toggled(bool checked){
settings->setValue("featureEmuHonest", checked);
}
void SettingsManager::on_featureExtraKeys_toggled(bool checked){
settings->setValue("featureExtraKeys", checked);
}
void SettingsManager::on_featureSoundStreams_toggled(bool checked){
settings->setValue("featureSoundStreams", checked);
void SettingsManager::on_featureDurable_toggled(bool checked){
settings->setValue("featureDurable", checked);
}

View File

@@ -33,24 +33,17 @@ private slots:
void on_selectUpKey_clicked();
void on_selectDownKey_clicked();
void on_selectLeftKey_clicked();
void on_selectRightKey_clicked();
void on_selectCenterKey_clicked();
void on_selectCalendarKey_clicked();
void on_selectAddressBookKey_clicked();
void on_selectTodoKey_clicked();
void on_selectNotesKey_clicked();
void on_selectPowerKey_clicked();
void on_clearKeyBind_clicked();
void on_feature128mbRam_toggled(bool checked);
void on_featureFastCpu_toggled(bool checked);
void on_featureHybridCpu_toggled(bool checked);
void on_featureCustomFb_toggled(bool checked);
void on_featureSyncedRtc_toggled(bool checked);
void on_featureHleApis_toggled(bool checked);
void on_featureEmuHonest_toggled(bool checked);
void on_featureExtraKeys_toggled(bool checked);
void on_featureSoundStreams_toggled(bool checked);
void on_featureDurable_toggled(bool checked);
private:
Ui::SettingsManager* ui;

View File

@@ -30,8 +30,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>624</width>
<height>411</height>
<width>630</width>
<height>417</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
@@ -59,7 +59,7 @@
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Set Keyboard Keys:</string>
<string>Set Palm m515 Keyboard Map:</string>
</property>
</widget>
</item>
@@ -72,8 +72,8 @@
</sizepolicy>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="2" column="1">
<widget class="QPushButton" name="selectAddressBookKey">
<item row="1" column="4">
<widget class="QPushButton" name="selectNotesKey">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
@@ -85,7 +85,7 @@
</property>
<property name="icon">
<iconset resource="mainwindow.qrc">
<normaloff>:/buttons/images/addressBook.svg</normaloff>:/buttons/images/addressBook.svg</iconset>
<normaloff>:/buttons/images/notes.svg</normaloff>:/buttons/images/notes.svg</iconset>
</property>
</widget>
</item>
@@ -100,7 +100,7 @@
</property>
</widget>
</item>
<item row="2" column="2">
<item row="1" column="2">
<widget class="QPushButton" name="selectDownKey">
<property name="text">
<string>MAXSIZE</string>
@@ -111,24 +111,7 @@
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QPushButton" name="selectCalendarKey">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>MAXSIZE</string>
</property>
<property name="icon">
<iconset resource="mainwindow.qrc">
<normaloff>:/buttons/images/calendar.svg</normaloff>:/buttons/images/calendar.svg</iconset>
</property>
</widget>
</item>
<item row="2" column="3">
<item row="1" column="3">
<widget class="QPushButton" name="selectTodoKey">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
@@ -145,23 +128,6 @@
</property>
</widget>
</item>
<item row="2" column="4">
<widget class="QPushButton" name="selectNotesKey">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>MAXSIZE</string>
</property>
<property name="icon">
<iconset resource="mainwindow.qrc">
<normaloff>:/buttons/images/notes.svg</normaloff>:/buttons/images/notes.svg</iconset>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QPushButton" name="selectPowerKey">
<property name="sizePolicy">
@@ -180,35 +146,36 @@
</widget>
</item>
<item row="1" column="1">
<widget class="QPushButton" name="selectLeftKey">
<widget class="QPushButton" name="selectAddressBookKey">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>MAXSIZE</string>
</property>
<property name="icon">
<iconset resource="mainwindow.qrc">
<normaloff>:/buttons/images/left.svg</normaloff>:/buttons/images/left.svg</iconset>
<normaloff>:/buttons/images/addressBook.svg</normaloff>:/buttons/images/addressBook.svg</iconset>
</property>
</widget>
</item>
<item row="1" column="3">
<widget class="QPushButton" name="selectRightKey">
<item row="1" column="0">
<widget class="QPushButton" name="selectCalendarKey">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>MAXSIZE</string>
</property>
<property name="icon">
<iconset resource="mainwindow.qrc">
<normaloff>:/buttons/images/right.svg</normaloff>:/buttons/images/right.svg</iconset>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QPushButton" name="selectCenterKey">
<property name="text">
<string>MAXSIZE</string>
</property>
<property name="icon">
<iconset resource="mainwindow.qrc">
<normaloff>:/buttons/images/center.svg</normaloff>:/buttons/images/center.svg</iconset>
<normaloff>:/buttons/images/calendar.svg</normaloff>:/buttons/images/calendar.svg</iconset>
</property>
</widget>
</item>
@@ -222,6 +189,13 @@
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="clearKeyBind">
<property name="text">
<string>Clear Key Bind</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_2">
<property name="text">
@@ -232,41 +206,6 @@
<item>
<widget class="QWidget" name="gridWidget_2" native="true">
<layout class="QGridLayout" name="gridLayout_2">
<item row="2" column="0">
<widget class="QCheckBox" name="featureEmuHonest">
<property name="text">
<string>Tell Programs Their Emulated</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QCheckBox" name="featureHleApis">
<property name="text">
<string>HLE APIs(Speed Hack)</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="featureCustomFb">
<property name="text">
<string>Resizeable Display(HiRes Mode)</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QCheckBox" name="featureHybridCpu">
<property name="text">
<string>ARM Instruction Set(OS 5)</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QCheckBox" name="feature128mbRam">
<property name="text">
<string>128MB RAM</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QCheckBox" name="featureFastCpu">
<property name="text">
@@ -274,27 +213,27 @@
</property>
</widget>
</item>
<item row="1" column="1">
<item row="0" column="0">
<widget class="QCheckBox" name="featureHleApis">
<property name="text">
<string>HLE APIs(Speed Hack)</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QCheckBox" name="featureDurable">
<property name="text">
<string>Ignore Invalid Behavior</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QCheckBox" name="featureSyncedRtc">
<property name="text">
<string>Sync Real Time Clock</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QCheckBox" name="featureExtraKeys">
<property name="text">
<string>Extra Dpad Keys(OS 5)</string>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QCheckBox" name="featureSoundStreams">
<property name="text">
<string>PWM Audio Streams(OS 5)</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>

View File

@@ -17,37 +17,11 @@ It is the best Palm brand OS 4 device that has no special hardware builtin(cellp
The Palm keyboard attachment will likely be emulated later on so the PC keyboard can be used on text fields.
## OS improvements
## What about OS 5
If there is something the OS does not support(like an OS 5 API) I may add it manually, this will be in the form of a custom firmware as a ROM image or a .bps patch, not a patch to the emulator with only 1 exception "PceNativeCall" which would require an ARM interpreter, it would also be an option to not apply this patch leaving you with an accurately emulated stock Palm m515.
These patches will not be worked on until the emulator is actually running.
## But you shouldnt waste your time on OS 4, OS 5 can do more.
I have made a video of OS 5 doing that "more", it is extremely incompatible with OS 4 games which most games are, very few games used the ARM CPU and those that did are available on other platforms, some used the 320x320 display mode.
On Clie PEG-SL10:
ArgonV: Normal
Galax: Normal
Zap!20XX: Normal
Invaders: Normal
Platypus: No ARM CPU, Cant Run
On Palm T|X:
ArgonV: Runs At Warpspeed
Galax: Audio Cuts Out
Zap!20XX: Audio Cuts Out
Invaders: Reboots System
Platypus: Normal, Used To Prove Speaker Isnt Defective
Bonus: Has Adware(Addit)
[Palm T|X vs OS 4 Games](https://youtu.be/ithVLI_M6i0)
The lack of ARM CPU will be fixed in my emulator see "OS improvements".
I am planning on adding Tungsten C support eventually.
## Credits
uARM (ARMv5 Core)
Musashi v3.4 (last version that builds outside of MAME)(68k Core)
blip_buf 1.1.0 (Audio Resampler)
http://www.iconarchive.com/show/crystal-clear-icons-by-everaldo/App-palm-icon.html (Desktop Icon)

View File

@@ -5,35 +5,13 @@ The end???
v3.2.0 to v4.0.0(*** ** 2020 - *** ** 2020)
Core:
Add Dragonball OG/EZ/VZ CPU builtin LCD controller support, some Palm OS 1<->3 games write directly to these registers to display their video and they won't work(with the exception of LSSA since the OS monitors that one)
add Dragonball OG/EZ/VZ CPU builtin LCD controller support too muExpDriver, some Palm OS 1<->3 games write directly to these registers to display their video and they won't work(with the exception of LSSA since the OS monitors that one)
------------------------------------------
v2.5.0 to v3.2.0(*** ** 2019 - *** ** 2020)
v1.1.0 to v3.2.0(*** ** 2020 - *** ** 2020)
Core:
*allow direct 320x320 bitmap rendered over the 160x160 framebuffer expanded 2x in both directions, black pixels will be transparent showing what's on the 160x160 framebuffer
Emu Hwr Driver:
*set fake display framebuffer for 320x320 mode
------------------------------------------
v2.0.0 to v2.5.0(*** ** 2019 - *** ** 2019)
Core:
*add single 16 bit PCM sound stream, mixed with PWM1
Emu Hwr Driver:
*OS 5.1.* sound stream API support(possibly can use PRC file dumped from an OS 5.1.1 device as long as I still add the extra sound stream for it to write to)
------------------------------------------
v1.0.0 to v2.0.0(*** ** 2019 - *** ** 2019)
Core:
*ARM opcode support, most apps that use ARM code work, as long as no OS 5.1.* APIs are used
Emu Hwr Driver:
*ARM CPU is exported to OS 4 with custom PceNativeCall
*can set fake version number to prevent tripping compatibility checks
add Palm Tungsten C support
------------------------------------------
v1.0.0 to v1.1.0(Feb 25 2019 - Easter 2019)
@@ -41,4 +19,4 @@ v1.0.0 to v1.1.0(Feb 25 2019 - Easter 2019)
Qt GUI:
*can now set the feature bits
*can now set the resource directory
*keyboard support
*keyboard mapping support

View File

@@ -3,7 +3,7 @@
#include "emulator.h"
#include "portability.h"
#include "hardwareRegisters.h"
#include "dbvzRegisters.h"
bool ads7846PenIrqEnabled;
@@ -33,7 +33,7 @@ void ads7846Reset(void){
ads7846OutputValue = 0x0000;
ads7846ChipSelect = true;
#if !defined(EMU_NO_SAFETY)
refreshTouchState();
m515RefreshTouchState();
#endif
}
@@ -84,7 +84,7 @@ void ads7846SetChipSelect(bool value){
ads7846PenIrqEnabled = true;
ads7846OutputValue = 0x0000;
#if !defined(EMU_NO_SAFETY)
refreshTouchState();
m515RefreshTouchState();
#endif
}
ads7846ChipSelect = value;
@@ -273,7 +273,7 @@ bool ads7846ExchangeBit(bool bitIn){
ads7846PenIrqEnabled = !(powerSave & 0x01);
#if !defined(EMU_NO_SAFETY)
refreshTouchState();
m515RefreshTouchState();
#endif
}

View File

@@ -1,171 +0,0 @@
#include <stdint.h>
#include <stdbool.h>
#include "emulator.h"
#include "hardwareRegisters.h"
#include "memoryAccess.h"
#include "portability.h"
#include "armv5/CPU.h"
#define ARMV5_CYCLES_PER_OPCODE 2
bool armv5ServiceRequest;
static ArmCpu armv5Cpu;
static Boolean armv5MemoryAccess(ArmCpu* cpu, void* buf, UInt32 vaddr, UInt8 size, Boolean write, Boolean privileged, UInt8* fsr){
//ARM only has access to RAM, the OS 4 ROM has no data important to it and it would be wrong to access 68k registers from ARM
vaddr &= chips[CHIP_DX_RAM].mask;
#if !defined(EMU_NO_SAFETY)
if(size & (size - 1) || vaddr & (size - 1))//size is not a power of two or address isnt aligned to size
return false;
#endif
#if defined(EMU_BIG_ENDIAN)
if(write){
switch(size){
case 1:
*(uint8_t*)(palmRam + vaddr) = *(uint8_t*)buf;
return true;
case 2:
*(uint16_t*)(palmRam + vaddr) = SWAP_16(*(uint16_t*)buf);
return true;
case 4:
*(uint32_t*)(palmRam + vaddr) = SWAP_32(*(uint32_t*)buf);
return true;
default:
return false;
}
}
else{
switch(size){
case 1:
*(uint8_t*)buf = *(uint8_t*)(palmRam + vaddr);
return true;
case 2:
*(uint16_t*)buf = SWAP_16(*(uint16_t*)(palmRam + vaddr));
return true;
case 4:
*(uint32_t*)buf = SWAP_32(*(uint32_t*)(palmRam + vaddr));
return true;
default:
return false;
}
}
#else
if(write){
switch(size){
case 1:
*(uint8_t*)(palmRam + (vaddr ^ 1)) = *(uint8_t*)buf;
return true;
case 2:
*(uint16_t*)(palmRam + vaddr) = SWAP_16(*(uint16_t*)buf);
return true;
case 4:
*(uint16_t*)(palmRam + vaddr) = SWAP_16(*(uint32_t*)buf & 0xFFFF);
*(uint16_t*)(palmRam + vaddr + 2) = SWAP_16(*(uint32_t*)buf >> 16);
return true;
default:
return false;
}
}
else{
switch(size){
case 1:
*(uint8_t*)buf = *(uint8_t*)(palmRam + (vaddr ^ 1));
return true;
case 2:
*(uint16_t*)buf = SWAP_16(*(uint16_t*)(palmRam + vaddr));
return true;
case 4:
*(uint32_t*)buf = SWAP_16(*(uint16_t*)(palmRam + vaddr + 2)) << 16 | SWAP_16(*(uint16_t*)(palmRam + vaddr));
return true;
default:
return false;
}
}
#endif
}
static Boolean armv5Hypercall(ArmCpu* cpu){
armv5ServiceRequest = true;
return true;
}
static void armv5EmulErr(ArmCpu* cpu, const char* errStr){
debugLog("%s", errStr);
}
static void armv5SetFaultAddr(struct ArmCpu* cpu, UInt32 adr, UInt8 faultStatus){
//TODO
}
void armv5Reset(void){
cpuInit(&armv5Cpu, 0x00000000/*PC, set by 68k while emulating*/, armv5MemoryAccess, armv5EmulErr, armv5Hypercall, armv5SetFaultAddr);
armv5ServiceRequest = false;
}
uint32_t armv5StateSize(void){
uint32_t size = 0;
//need to add armv5Cpu here
size += sizeof(uint8_t);
return size;
}
void armv5SaveState(uint8_t* data){
uint32_t offset = 0;
//need to add armv5Cpu here
writeStateValue8(data + offset, armv5ServiceRequest);
offset += sizeof(uint8_t);
}
void armv5LoadState(uint8_t* data){
uint32_t offset = 0;
//need to add armv5Cpu here
armv5ServiceRequest = readStateValue8(data + offset);
offset += sizeof(uint8_t);
}
uint32_t armv5GetRegister(uint8_t reg){
return cpuGetRegExternal(&armv5Cpu, reg);
}
void armv5SetRegister(uint8_t reg, uint32_t value){
cpuSetReg(&armv5Cpu, reg, value);
}
int32_t armv5Execute(int32_t cycles){
armv5ServiceRequest = false;
//execution aborts on hypercall to request things from the 68k
while(cycles > 0 && !armv5ServiceRequest){
cpuCycleNoIrqs(&armv5Cpu);
cycles -= ARMV5_CYCLES_PER_OPCODE;
}
return cycles;
}
uint32_t armv5GetPc(void){
return cpuGetRegExternal(&armv5Cpu, 15/*pc*/);
}

View File

@@ -1,20 +0,0 @@
#ifndef ARMV5_H
#define ARMV5_H
#include <stdint.h>
#include <stdbool.h>
extern bool armv5ServiceRequest;
void armv5Reset(void);
uint32_t armv5StateSize(void);
void armv5SaveState(uint8_t* data);
void armv5LoadState(uint8_t* data);
uint32_t armv5GetRegister(uint8_t reg);
void armv5SetRegister(uint8_t reg, uint32_t value);
int32_t armv5Execute(int32_t cycles);//returns cycles left
uint32_t armv5GetPc(void);//only for debugging
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -1,173 +0,0 @@
#ifndef UARM_CPU_H
#define UARM_CPU_H
//#define ARM_V6 //define to allow v6 instructions
//#define THUMB_2 //define to allow Thumb2
#include "types.h"
struct ArmCpu;
#define ARM_SR_N 0x80000000UL
#define ARM_SR_Z 0x40000000UL
#define ARM_SR_C 0x20000000UL
#define ARM_SR_V 0x10000000UL
#define ARM_SR_Q 0x08000000UL
#ifdef ARM_V6 //V6KT2, but without T2 to be exact (we implement things like MLS, but not Thumb2 or ThumbEE)
#define ARM_SR_J 0x01000000UL
#define ARM_SR_E 0x00000200UL
#define ARM_SR_A 0x00000100UL
#define ARM_SR_GE_0 0x00010000UL
#define ARM_SR_GE_1 0x00020000UL
#define ARM_SR_GE_2 0x00040000UL
#define ARM_SR_GE_3 0x00080000UL
#define ARM_SR_GE_MASK 0x000F0000UL
#define ARM_SR_GE_SHIFT 16
#endif
#define ARM_SR_I 0x00000080UL
#define ARM_SR_F 0x00000040UL
#define ARM_SR_T 0x00000020UL
#define ARM_SR_M 0x0000001FUL
#define ARM_SR_MODE_USR 0x00000010UL
#define ARM_SR_MODE_FIQ 0x00000011UL
#define ARM_SR_MODE_IRQ 0x00000012UL
#define ARM_SR_MODE_SVC 0x00000013UL
#define ARM_SR_MODE_ABT 0x00000017UL
#define ARM_SR_MODE_UND 0x0000001BUL
#define ARM_SR_MODE_SYS 0x0000001FUL
#define ARV_VECTOR_OFFT_RST 0x00000000UL
#define ARM_VECTOR_OFFT_UND 0x00000004UL
#define ARM_VECTOR_OFFT_SWI 0x00000008UL
#define ARM_VECTOR_OFFT_P_ABT 0x0000000CUL
#define ARM_VECTOR_OFFT_D_ABT 0x00000010UL
#define ARM_VECTOR_OFFT_UNUSED 0x00000014UL
#define ARM_VECTOR_OFFT_IRQ 0x00000018UL
#define ARM_VECTOR_OFFT_FIQ 0x0000001CUL
#define HYPERCALL_ARM 0xF7BBBBBBUL
#define HYPERCALL_THUMB 0xBBBBUL
//the following are for cpuGetRegExternal() and are generally used for debugging purposes
#define ARM_REG_NUM_CPSR 16
#define ARM_REG_NUM_SPSR 17
struct ArmCpu;
typedef Boolean (*ArmCoprocRegXferF) (struct ArmCpu* cpu, void* userData, Boolean two/* MCR2/MRC2 ? */, Boolean MRC, UInt8 op1, UInt8 Rx, UInt8 CRn, UInt8 CRm, UInt8 op2);
typedef Boolean (*ArmCoprocDatProcF) (struct ArmCpu* cpu, void* userData, Boolean two/* CDP2 ? */, UInt8 op1, UInt8 CRd, UInt8 CRn, UInt8 CRm, UInt8 op2);
typedef Boolean (*ArmCoprocMemAccsF) (struct ArmCpu* cpu, void* userData, Boolean two /* LDC2/STC2 ? */, Boolean N, Boolean store, UInt8 CRd, UInt32 addr, UInt8* option /* NULL if none */);
typedef Boolean (*ArmCoprocTwoRegF) (struct ArmCpu* cpu, void* userData, Boolean MRRC, UInt8 op, UInt8 Rd, UInt8 Rn, UInt8 CRm);
typedef Boolean (*ArmCpuMemF) (struct ArmCpu* cpu, void* buf, UInt32 vaddr, UInt8 size, Boolean write, Boolean priviledged, UInt8* fsr); //read/write
typedef Boolean (*ArmCpuHypercall) (struct ArmCpu* cpu); //return true if handled
typedef void (*ArmCpuEmulErr) (struct ArmCpu* cpu, const char* err_str);
typedef void (*ArmSetFaultAdrF) (struct ArmCpu* cpu, UInt32 adr, UInt8 faultStatus);
#include "icache.h"
/*
coprocessors:
0 - DSP (pxa only)
0, 1 - WMMX (pxa only)
11 - VFP (arm standard)
15 - system control (arm standard)
*/
typedef struct{
ArmCoprocRegXferF regXfer;
ArmCoprocDatProcF dataProcessing;
ArmCoprocMemAccsF memAccess;
ArmCoprocTwoRegF twoRegF;
void* userData;
}ArmCoprocessor;
typedef struct{
UInt32 R13, R14;
UInt32 SPSR; //usr mode doesn't have an SPSR
}ArmBankedRegs;
typedef struct ArmCpu{
UInt32 regs[16]; //current active regs as per current mode
UInt32 CPSR, SPSR;
ArmBankedRegs bank_usr; //usr regs when in another mode
ArmBankedRegs bank_svc; //svc regs when in another mode
ArmBankedRegs bank_abt; //abt regs when in another mode
ArmBankedRegs bank_und; //und regs when in another mode
ArmBankedRegs bank_irq; //irq regs when in another mode
ArmBankedRegs bank_fiq; //fiq regs when in another mode
UInt32 extra_regs[5]; //fiq regs when not in fiq mode, usr regs when in fiq mode. R8-12
UInt16 waitingIrqs;
UInt16 waitingFiqs;
UInt16 CPAR;
ArmCoprocessor coproc[16]; //coprocessors
// various other cpu config options
UInt32 vectorBase; //address of vector base
#ifdef ARM_V6
Boolean EEE; //endianness one exception entry
Boolean impreciseAbtWaiting;
#endif
ArmCpuMemF memF;
ArmCpuEmulErr emulErrF;
ArmCpuHypercall hypercallF;
ArmSetFaultAdrF setFaultAdrF;
icache ic;
void* userData; //shared by all callbacks
}ArmCpu;
Err cpuInit(ArmCpu* cpu, UInt32 pc, ArmCpuMemF memF, ArmCpuEmulErr emulErrF, ArmCpuHypercall hypercallF, ArmSetFaultAdrF setFaultAdrF);
Err cpuDeinit(ArmCpu* cp);
void cpuCycle(ArmCpu* cpu);
void cpuCycleNoIrqs(ArmCpu* cpu);
void cpuIrq(ArmCpu* cpu, Boolean fiq, Boolean raise); //unraise when acknowledged
#ifdef ARM_V6
void cpuSignalImpreciseAbt(ArmCpu* cpu, Boolean raise);
#endif
UInt32 cpuGetRegExternal(ArmCpu* cpu, UInt8 reg);
void cpuSetReg(ArmCpu* cpu, UInt8 reg, UInt32 val);
void cpuCoprocessorRegister(ArmCpu* cpu, UInt8 cpNum, ArmCoprocessor* coproc);
void cpuCoprocessorUnregister(ArmCpu* cpu, UInt8 cpNum);
void cpuSetVectorAddr(ArmCpu* cpu, UInt32 adr);
UInt16 cpuGetCPAR(ArmCpu* cpu);
void cpuSetCPAR(ArmCpu* cpu, UInt16 cpar);
void cpuIcacheInval(ArmCpu* cpu);
void cpuIcacheInvalAddr(ArmCpu* cpu, UInt32 addr);
#endif

View File

@@ -1,140 +0,0 @@
#include "types.h"
#include "CPU.h"
#include "icache.h"
//#define ICACHE_DEBUGGING
#ifdef ICACHE_DEBUGGING
#define _icache_fetch_func icacheFetch_
#define _icache_test_func icacheFetch
#else
#define _icache_fetch_func icacheFetch
#define _icache_test_func icacheFetch_test
#endif
void icacheInval(icache* ic){
UInt8 i, j;
for(i = 0; i < ICACHE_BUCKET_NUM; i++){
for(j = 0; j < ICACHE_BUCKET_SZ; j++) ic->lines[i][j].info = 0;
ic->ptr[i] = 0;
}
}
void icacheInit(icache* ic, ArmCpu* cpu, ArmCpuMemF memF){
ic->cpu = cpu;
ic->memF = memF;
icacheInval(ic);
}
static UInt8 icachePrvHash(UInt32 addr){
addr >>= ICACHE_L;
addr &= (1UL << ICACHE_S) - 1UL;
return addr;
}
void icacheInvalAddr(icache* ic, UInt32 va){
UInt32 off = va % ICACHE_LINE_SZ;
Int8 i, j, bucket;
icacheLine* lines;
va -= off;
bucket = icachePrvHash(va);
lines = ic->lines[bucket];
for(i = 0, j = ic->ptr[bucket]; (UInt8)i < ICACHE_BUCKET_SZ; i++){
if(--j == -1) j = ICACHE_BUCKET_SZ - 1;
if((lines[j].info & (ICACHE_ADDR_MASK | ICACHE_USED_MASK)) == (va | ICACHE_USED_MASK)){ //found it!
lines[j].info = 0;
}
}
}
/*
we cannot have data overlap cachelines since data is self aligned (word on 4-byte boundary, halfwords on2, etc. this is enforced elsewhere
*/
Boolean _icache_fetch_func(icache* ic, UInt32 va, UInt8 sz, Boolean priviledged, UInt8* fsrP, void* buf){
UInt32 off = va % ICACHE_LINE_SZ;
Int8 i, j, bucket;
icacheLine* lines;
icacheLine* line;
va -= off;
bucket = icachePrvHash(va);
lines = ic->lines[bucket];
for(i = 0, j = ic->ptr[bucket]; (UInt8)i < ICACHE_BUCKET_SZ; i++){
if(--j == -1) j = ICACHE_BUCKET_SZ - 1;
if((lines[j].info & (ICACHE_ADDR_MASK | ICACHE_USED_MASK)) == (va | ICACHE_USED_MASK)){ //found it!
if(sz == 4){
*(UInt32*)buf = *(UInt32*)(lines[j].data + off);
}
else if(sz == 2){
*(UInt16*)buf = *(UInt16*)(lines[j].data + off);
}
else __mem_copy(buf, lines[j].data + off, sz);
return priviledged || !(lines[j].info & ICACHE_PRIV_MASK);
}
}
//if we're here, we found nothing - time to populate the cache
j = ic->ptr[bucket]++;
if(ic->ptr[bucket] == ICACHE_BUCKET_SZ) ic->ptr[bucket] = 0;
line = lines + j;
line->info = va | (priviledged ? ICACHE_PRIV_MASK : 0);
if(!ic->memF(ic->cpu, line->data, va, ICACHE_LINE_SZ, false, priviledged, fsrP)){
return false;
}
line->info |= ICACHE_USED_MASK;
if(sz == 4){
*(UInt32*)buf = *(UInt32*)(line->data + off);
}
else if(sz == 2){
*(UInt16*)buf = *(UInt16*)(line->data + off);
}
else __mem_copy(buf, line->data + off, sz);
return true;
}
#include "stdio.h"
Boolean _icache_test_func(icache* ic, UInt32 va, UInt8 sz, Boolean priviledged, UInt8* fsrP, void* buf){
UInt8 fsrO = -1, fsrT = -1;
UInt8 dataO[4] = {0}, dataT[4] = {0};
Boolean retO, retT;
UInt8 i;
retO = _icache_fetch_func(ic, va, sz, priviledged, &fsrO, dataO);
retT = ic->memF(ic->cpu, dataT, va, sz, false, priviledged, &fsrT);
if((retT != retO) || (fsrT != fsrO) || (dataT[0] != dataO[0]) || (dataT[1] != dataO[1]) || (dataT[2] != dataO[2]) || (dataT[3] != dataO[3])){
fprintf(stderr, "icache fail!");
}
for(i = 0; i < sz; i++) ((UInt8*)buf)[i] = dataT[i];
if(retT) *fsrP = fsrT;
return retT;
}

View File

@@ -1,45 +0,0 @@
#ifndef UARM_ICACHE_H
#define UARM_ICACHE_H
#include "types.h"
#include "CPU.h"
#define ICACHE_L 5UL //line size is 2^L bytes
#define ICACHE_S 6UL //number of sets is 2^S
#define ICACHE_A 3UL //set associativity
#define ICACHE_LINE_SZ (1UL << ICACHE_L)
#define ICACHE_BUCKET_NUM (1UL << ICACHE_S)
#define ICACHE_BUCKET_SZ (ICACHE_A)
#define ICACHE_ADDR_MASK ((UInt32)-ICACHE_LINE_SZ)
#define ICACHE_USED_MASK 1UL
#define ICACHE_PRIV_MASK 2UL
typedef struct{
UInt32 info; //addr, masks
UInt8 data[ICACHE_LINE_SZ];
}icacheLine;
typedef struct{
struct ArmCpu* cpu;
ArmCpuMemF memF;
icacheLine lines[ICACHE_BUCKET_NUM][ICACHE_BUCKET_SZ];
UInt8 ptr[ICACHE_BUCKET_NUM];
}icache;
void icacheInit(icache* ic, struct ArmCpu* cpu, ArmCpuMemF memF);
Boolean icacheFetch(icache* ic, UInt32 va, UInt8 sz, Boolean priviledged, UInt8* fsr, void* buf);
void icacheInval(icache* ic);
void icacheInvalAddr(icache* ic, UInt32 addr);
#endif

View File

@@ -1,25 +0,0 @@
#ifndef UARM_MATH_64_H
#define UARM_MATH_64_H
#include "types.h"
static inline UInt64 u64_from_halves(UInt32 hi, UInt32 lo) { return (((UInt64)hi) << 32ULL) | ((UInt64)lo); }
static inline UInt64 u64_32_to_64(UInt32 v) { return (UInt64)v; }
static inline UInt32 u64_64_to_32(UInt64 v) { return (UInt32)v; }
static inline UInt32 u64_get_hi(UInt64 v) { return (UInt32)(v >> 32ULL); }
static inline UInt64 u64_add(UInt64 a, UInt64 b) { return a + b; }
static inline UInt64 u64_add32(UInt64 a, UInt32 b) { return a + (UInt64)b; }
static inline UInt64 u64_umul3232(UInt32 a, UInt32 b) { return ((UInt64)a) * ((UInt64)b); } //sad but true: gcc has no u32xu32->64 multiply
static inline UInt64 u64_smul3232(Int32 a, Int32 b) { return ((Int64)a) * ((Int64)b); } //sad but true: gcc has no s32xs32->64 multiply
static inline UInt64 u64_shr(UInt64 a, unsigned bits) { return a >> (UInt64)bits; }
static inline UInt64 u64_shl(UInt64 a, unsigned bits) { return a << (UInt64)bits; }
static inline UInt64 u64_xtnd32(UInt64 a) { if(a & 0x80000000UL) a |= (((UInt64)-1) << 32ULL); return a; }
static inline Boolean u64_isZero(UInt64 a) { return a == 0; }
static inline UInt64 u64_inc(UInt64 a) { return a + 1ULL; }
static inline UInt64 u64_and(UInt64 a, UInt64 b) { return a & b; }
static inline UInt64 u64_zero(void) { return 0; }
static inline UInt64 u64_sub(UInt64 a, UInt64 b) { return a - b; }
#endif

View File

@@ -1,44 +0,0 @@
#ifndef UARM_TYPES_H
#define UARM_TYPES_H
#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>
#include <string.h>
typedef uint64_t UInt64;
typedef int64_t Int64;
typedef uint32_t UInt32;
typedef int32_t Int32;
typedef uint16_t UInt16;
typedef int16_t Int16;
typedef uint8_t UInt8;
typedef int8_t Int8;
typedef uint8_t Err;
typedef bool Boolean;//may need to be uint8_t, thats its type in the original source
#define errNone 0x00
#define errInternal 0x01
/*
#define _INLINE_ inline __attribute__ ((always_inline))
#define _UNUSED_ __attribute__((unused))
*/
#define _INLINE_ inline
#define _UNUSED_
/* runtime stuffs */
/*
void err_str(const char* str);
void err_hex(UInt32 val);
void err_dec(UInt32 val);
*/
#define err_str(x)
#define err_hex(x)
#define err_dec(x)
#define __mem_zero(mem, len) memset(mem, 0x00, len)
#define __mem_copy(d, s, sz) memcpy(d, s, sz)
#endif

View File

@@ -124,7 +124,7 @@ int32_t pwm1FifoRunSample(int32_t now, int32_t clockOffset){
if(pwm1FifoEntrys() < 2){
//trigger interrupt if enabled
if(pwmc1 & 0x0040)
setIprIsrBit(INT_PWM1);
setIprIsrBit(DBVZ_INT_PWM1);
//checkInterrupts() is run when the clock that called this function is finished
registerArrayWrite16(PWMC1, pwmc1 | 0x0080);//set IRQ bit
@@ -147,18 +147,18 @@ static void pwm1FifoFlush(void){
//register setters
static void setCsa(uint16_t value){
chips[CHIP_A0_ROM].enable = value & 0x0001;
chips[CHIP_A0_ROM].readOnly = !!(value & 0x8000);
chips[CHIP_A0_ROM].lineSize = 0x20000/*128kb*/ << (value >> 1 & 0x0007);
chips[DBVZ_CHIP_A0_ROM].enable = value & 0x0001;
chips[DBVZ_CHIP_A0_ROM].readOnly = !!(value & 0x8000);
chips[DBVZ_CHIP_A0_ROM].lineSize = 0x20000/*128kb*/ << (value >> 1 & 0x0007);
//CSA is now just a normal chip select
if(chips[CHIP_A0_ROM].enable && chips[CHIP_A0_ROM].inBootMode)
chips[CHIP_A0_ROM].inBootMode = false;
if(chips[DBVZ_CHIP_A0_ROM].enable && chips[DBVZ_CHIP_A0_ROM].inBootMode)
chips[DBVZ_CHIP_A0_ROM].inBootMode = false;
chips[CHIP_A1_USB].enable = chips[CHIP_A0_ROM].enable;
chips[CHIP_A1_USB].readOnly = chips[CHIP_A0_ROM].readOnly;
chips[CHIP_A1_USB].start = chips[CHIP_A0_ROM].start + chips[CHIP_A0_ROM].lineSize;
chips[CHIP_A1_USB].lineSize = chips[CHIP_A0_ROM].lineSize;
chips[DBVZ_CHIP_A1_USB].enable = chips[DBVZ_CHIP_A0_ROM].enable;
chips[DBVZ_CHIP_A1_USB].readOnly = chips[DBVZ_CHIP_A0_ROM].readOnly;
chips[DBVZ_CHIP_A1_USB].start = chips[DBVZ_CHIP_A0_ROM].start + chips[DBVZ_CHIP_A0_ROM].lineSize;
chips[DBVZ_CHIP_A1_USB].lineSize = chips[DBVZ_CHIP_A0_ROM].lineSize;
registerArrayWrite16(CSA, value & 0x81FF);
}
@@ -166,25 +166,25 @@ static void setCsa(uint16_t value){
static void setCsb(uint16_t value){
uint16_t csControl1 = registerArrayRead16(CSCTRL1);
chips[CHIP_B0_SED].enable = value & 0x0001;
chips[CHIP_B0_SED].readOnly = !!(value & 0x8000);
chips[CHIP_B0_SED].lineSize = 0x20000/*128kb*/ << (value >> 1 & 0x0007);
chips[DBVZ_CHIP_B0_SED].enable = value & 0x0001;
chips[DBVZ_CHIP_B0_SED].readOnly = !!(value & 0x8000);
chips[DBVZ_CHIP_B0_SED].lineSize = 0x20000/*128kb*/ << (value >> 1 & 0x0007);
//attributes
chips[CHIP_B0_SED].supervisorOnlyProtectedMemory = !!(value & 0x4000);
chips[CHIP_B0_SED].readOnlyForProtectedMemory = !!(value & 0x2000);
chips[DBVZ_CHIP_B0_SED].supervisorOnlyProtectedMemory = !!(value & 0x4000);
chips[DBVZ_CHIP_B0_SED].readOnlyForProtectedMemory = !!(value & 0x2000);
if(csControl1 & 0x4000 && csControl1 & 0x0001)
chips[CHIP_B0_SED].unprotectedSize = chips[CHIP_B0_SED].lineSize / (1 << 7 - ((value >> 11 & 0x0003) | 0x0004));
chips[DBVZ_CHIP_B0_SED].unprotectedSize = chips[DBVZ_CHIP_B0_SED].lineSize / (1 << 7 - ((value >> 11 & 0x0003) | 0x0004));
else
chips[CHIP_B0_SED].unprotectedSize = chips[CHIP_B0_SED].lineSize / (1 << 7 - (value >> 11 & 0x0003));
chips[DBVZ_CHIP_B0_SED].unprotectedSize = chips[DBVZ_CHIP_B0_SED].lineSize / (1 << 7 - (value >> 11 & 0x0003));
chips[CHIP_B1_NIL].enable = chips[CHIP_B0_SED].enable;
chips[CHIP_B1_NIL].readOnly = chips[CHIP_B0_SED].readOnly;
chips[CHIP_B1_NIL].start = chips[CHIP_B0_SED].start + chips[CHIP_B0_SED].lineSize;
chips[CHIP_B1_NIL].lineSize = chips[CHIP_B0_SED].lineSize;
chips[CHIP_B1_NIL].supervisorOnlyProtectedMemory = chips[CHIP_B0_SED].supervisorOnlyProtectedMemory;
chips[CHIP_B1_NIL].readOnlyForProtectedMemory = chips[CHIP_B0_SED].readOnlyForProtectedMemory;
chips[CHIP_B1_NIL].unprotectedSize = chips[CHIP_B0_SED].unprotectedSize;
chips[DBVZ_CHIP_B1_NIL].enable = chips[DBVZ_CHIP_B0_SED].enable;
chips[DBVZ_CHIP_B1_NIL].readOnly = chips[DBVZ_CHIP_B0_SED].readOnly;
chips[DBVZ_CHIP_B1_NIL].start = chips[DBVZ_CHIP_B0_SED].start + chips[DBVZ_CHIP_B0_SED].lineSize;
chips[DBVZ_CHIP_B1_NIL].lineSize = chips[DBVZ_CHIP_B0_SED].lineSize;
chips[DBVZ_CHIP_B1_NIL].supervisorOnlyProtectedMemory = chips[DBVZ_CHIP_B0_SED].supervisorOnlyProtectedMemory;
chips[DBVZ_CHIP_B1_NIL].readOnlyForProtectedMemory = chips[DBVZ_CHIP_B0_SED].readOnlyForProtectedMemory;
chips[DBVZ_CHIP_B1_NIL].unprotectedSize = chips[DBVZ_CHIP_B0_SED].unprotectedSize;
registerArrayWrite16(CSB, value & 0xF9FF);
}
@@ -192,22 +192,22 @@ static void setCsb(uint16_t value){
static void setCsd(uint16_t value){
uint16_t csControl1 = registerArrayRead16(CSCTRL1);
chips[CHIP_DX_RAM].enable = value & 0x0001;
chips[CHIP_DX_RAM].readOnly = !!(value & 0x8000);
chips[DBVZ_CHIP_DX_RAM].enable = value & 0x0001;
chips[DBVZ_CHIP_DX_RAM].readOnly = !!(value & 0x8000);
if(csControl1 & 0x0040 && value & 0x0200)
chips[CHIP_DX_RAM].lineSize = 0x800000/*8mb*/ << (value >> 1 & 0x0001);
chips[DBVZ_CHIP_DX_RAM].lineSize = 0x800000/*8mb*/ << (value >> 1 & 0x0001);
else
chips[CHIP_DX_RAM].lineSize = 0x8000/*32kb*/ << (value >> 1 & 0x0007);
chips[DBVZ_CHIP_DX_RAM].lineSize = 0x8000/*32kb*/ << (value >> 1 & 0x0007);
//attributes
chips[CHIP_DX_RAM].supervisorOnlyProtectedMemory = !!(value & 0x4000);
chips[CHIP_DX_RAM].readOnlyForProtectedMemory = !!(value & 0x2000);
chips[DBVZ_CHIP_DX_RAM].supervisorOnlyProtectedMemory = !!(value & 0x4000);
chips[DBVZ_CHIP_DX_RAM].readOnlyForProtectedMemory = !!(value & 0x2000);
if(csControl1 & 0x4000 && csControl1 & 0x0010)
chips[CHIP_DX_RAM].unprotectedSize = chips[CHIP_DX_RAM].lineSize / (1 << 7 - ((value >> 11 & 0x0003) | 0x0004));
chips[DBVZ_CHIP_DX_RAM].unprotectedSize = chips[DBVZ_CHIP_DX_RAM].lineSize / (1 << 7 - ((value >> 11 & 0x0003) | 0x0004));
else
chips[CHIP_DX_RAM].unprotectedSize = chips[CHIP_DX_RAM].lineSize / (1 << 7 - (value >> 11 & 0x0003));
chips[DBVZ_CHIP_DX_RAM].unprotectedSize = chips[DBVZ_CHIP_DX_RAM].lineSize / (1 << 7 - (value >> 11 & 0x0003));
//debugLog("RAM unprotected size:0x%08X, bits:0x%02X\n", chips[CHIP_DX_RAM].unprotectedSize, ((value >> 11 & 0x0003) | (csControl1 & 0x4000 && csControl1 & 0x0010) * 0x0004));
//debugLog("RAM unprotected size:0x%08X, bits:0x%02X\n", chips[DBVZ_CHIP_DX_RAM].unprotectedSize, ((value >> 11 & 0x0003) | (csControl1 & 0x4000 && csControl1 & 0x0010) * 0x0004));
registerArrayWrite16(CSD, value);
}
@@ -217,11 +217,11 @@ static void setCsgba(uint16_t value){
//add extra address bits if enabled
if(csugba & 0x8000)
chips[CHIP_A0_ROM].start = (csugba >> 12 & 0x0007) << 29 | value >> 1 << 14;
chips[DBVZ_CHIP_A0_ROM].start = (csugba >> 12 & 0x0007) << 29 | value >> 1 << 14;
else
chips[CHIP_A0_ROM].start = value >> 1 << 14;
chips[DBVZ_CHIP_A0_ROM].start = value >> 1 << 14;
chips[CHIP_A1_USB].start = chips[CHIP_A0_ROM].start + chips[CHIP_A0_ROM].lineSize;
chips[DBVZ_CHIP_A1_USB].start = chips[DBVZ_CHIP_A0_ROM].start + chips[DBVZ_CHIP_A0_ROM].lineSize;
registerArrayWrite16(CSGBA, value & 0xFFFE);
}
@@ -231,11 +231,11 @@ static void setCsgbb(uint16_t value){
//add extra address bits if enabled
if(csugba & 0x8000)
chips[CHIP_B0_SED].start = (csugba >> 8 & 0x0007) << 29 | value >> 1 << 14;
chips[DBVZ_CHIP_B0_SED].start = (csugba >> 8 & 0x0007) << 29 | value >> 1 << 14;
else
chips[CHIP_B0_SED].start = value >> 1 << 14;
chips[DBVZ_CHIP_B0_SED].start = value >> 1 << 14;
chips[CHIP_B1_NIL].start = chips[CHIP_B0_SED].start + chips[CHIP_B0_SED].lineSize;
chips[DBVZ_CHIP_B1_NIL].start = chips[DBVZ_CHIP_B0_SED].start + chips[DBVZ_CHIP_B0_SED].lineSize;
registerArrayWrite16(CSGBB, value & 0xFFFE);
}
@@ -245,9 +245,9 @@ static void setCsgbd(uint16_t value){
//add extra address bits if enabled
if(csugba & 0x8000)
chips[CHIP_DX_RAM].start = (csugba & 0x0007) << 29 | value >> 1 << 14;
chips[DBVZ_CHIP_DX_RAM].start = (csugba & 0x0007) << 29 | value >> 1 << 14;
else
chips[CHIP_DX_RAM].start = value >> 1 << 14;
chips[DBVZ_CHIP_DX_RAM].start = value >> 1 << 14;
registerArrayWrite16(CSGBD, value & 0xFFFE);
}
@@ -258,19 +258,19 @@ static void updateCsdAddressLines(void){
if(registerArrayRead16(CSD) & 0x0200 && sdctrl & 0x8000 && dramc & 0x8000 && !(dramc & 0x0400)){
//this register can remap address lines, that behavior is way too CPU intensive and complicated so only the "memory testing" and "correct" behavior is being emulated
chips[CHIP_DX_RAM].mask = 0x003FFFFF;
chips[DBVZ_CHIP_DX_RAM].mask = 0x003FFFFF;
//address line 23 is enabled
if((sdctrl & 0x000C) == 0x0008)
chips[CHIP_DX_RAM].mask |= 0x00800000;
chips[DBVZ_CHIP_DX_RAM].mask |= 0x00800000;
//address line 22 is enabled
if((sdctrl & 0x0030) == 0x0010)
chips[CHIP_DX_RAM].mask |= 0x00400000;
chips[DBVZ_CHIP_DX_RAM].mask |= 0x00400000;
}
else{
//RAM is not enabled properly
chips[CHIP_DX_RAM].mask = 0x00000000;
chips[DBVZ_CHIP_DX_RAM].mask = 0x00000000;
}
}
@@ -294,14 +294,14 @@ static void setScr(uint8_t value){
//clear violations on writing 1 to them
newScr &= ~(value & 0xE0);
chips[CHIP_REGISTERS].supervisorOnlyProtectedMemory = value & 0x08;
chips[DBVZ_CHIP_REGISTERS].supervisorOnlyProtectedMemory = value & 0x08;
registerArrayWrite8(SCR, newScr);//must be written before calling setRegisterFFFFAccessMode
if((newScr & 0x04) != (oldScr & 0x04)){
if(newScr & 0x04)
setRegisterXXFFAccessMode();
dbvzSetRegisterXXFFAccessMode();
else
setRegisterFFFFAccessMode();
dbvzSetRegisterFFFFAccessMode();
}
}
@@ -354,9 +354,9 @@ static void setSpiIntCs(uint16_t value){
//if interrupt state changed update interrupts too, top 8 bits are just the enable bits for the bottom 8
if(!!(newSpiIntCs >> 8 & newSpiIntCs) != !!(oldSpiIntCs >> 8 & oldSpiIntCs)){
if(newSpiIntCs >> 8 & newSpiIntCs)
setIprIsrBit(INT_SPI1);
setIprIsrBit(DBVZ_INT_SPI1);
else
clearIprIsrBit(INT_SPI1);
clearIprIsrBit(DBVZ_INT_SPI1);
checkInterrupts();
}
@@ -425,9 +425,9 @@ static void setSpiCont2(uint16_t value){
//force or clear an interrupt
if((value & 0x00C0) == 0x00C0)
setIprIsrBit(INT_SPI2);
setIprIsrBit(DBVZ_INT_SPI2);
else
clearIprIsrBit(INT_SPI2);
clearIprIsrBit(DBVZ_INT_SPI2);
//do a transfer if enabled(this register write and last) and exchange set
if(value & oldSpiCont2 & 0x0200 && value & 0x0100){
@@ -465,7 +465,7 @@ static void setSpiCont2(uint16_t value){
//IRQEN set, send an interrupt after transfer
if(value & 0x0040)
setIprIsrBit(INT_SPI2);
setIprIsrBit(DBVZ_INT_SPI2);
}
//check for any interrupts from the transfer
@@ -482,7 +482,7 @@ static void setTstat1(uint16_t value){
if(!(newTstat1 & 0x0001) && (oldTstat1 & 0x0001)){
//debugLog("Timer 1 interrupt cleared.\n");
clearIprIsrBit(INT_TMR1);
clearIprIsrBit(DBVZ_INT_TMR1);
checkInterrupts();
}
timerStatusReadAcknowledge[0] &= newTstat1;//clear acknowledged reads cleared bits
@@ -497,7 +497,7 @@ static void setTstat2(uint16_t value){
if(!(newTstat2 & 0x0001) && (oldTstat2 & 0x0001)){
//debugLog("Timer 2 interrupt cleared.\n");
clearIprIsrBit(INT_TMR2);
clearIprIsrBit(DBVZ_INT_TMR2);
checkInterrupts();
}
timerStatusReadAcknowledge[1] &= newTstat2;//clear acknowledged reads for cleared bits
@@ -518,14 +518,14 @@ static void setPwmc1(uint16_t value){
//clear interrupt by write(reading can also clear the interrupt)
if(oldPwmc1 & 0x0080 && !(value & 0x0080)){
clearIprIsrBit(INT_PWM1);
clearIprIsrBit(DBVZ_INT_PWM1);
checkInterrupts();
}
//interrupt enabled and interrupt set
if((value & 0x00C0) == 0x00C0){
//this register also allows forcing an interrupt by writing a 1 to its IRQ bit when IRQEN is enabled
setIprIsrBit(INT_PWM1);
setIprIsrBit(DBVZ_INT_PWM1);
checkInterrupts();
}
@@ -549,19 +549,19 @@ static void setIsr(uint32_t value, bool useTopWord, bool useBottomWord){
//IRQ1 is not edge triggered
if(!(interruptControlRegister & 0x0800))
value &= ~INT_IRQ1;
value &= ~DBVZ_INT_IRQ1;
//IRQ2 is not edge triggered
if(!(interruptControlRegister & 0x0400))
value &= ~INT_IRQ2;
value &= ~DBVZ_INT_IRQ2;
//IRQ3 is not edge triggered
if(!(interruptControlRegister & 0x0200))
value &= ~INT_IRQ3;
value &= ~DBVZ_INT_IRQ3;
//IRQ6 is not edge triggered
if(!(interruptControlRegister & 0x0100))
value &= ~INT_IRQ6;
value &= ~DBVZ_INT_IRQ6;
registerArrayWrite16(IPR, registerArrayRead16(IPR) & ~(value >> 16));
registerArrayWrite16(ISR, registerArrayRead16(ISR) & ~(value >> 16));
@@ -718,7 +718,7 @@ static uint16_t getPwmc1(void){
//clear INT_PWM1 if active
if(returnValue & 0x0080){
clearIprIsrBit(INT_PWM1);
clearIprIsrBit(DBVZ_INT_PWM1);
checkInterrupts();
registerArrayWrite16(PWMC1, returnValue & 0xFF5F);
}
@@ -747,14 +747,14 @@ static void updateSdCardChipSelectStatus(void){
}
static void updateBacklightAmplifierStatus(void){
palmMisc.backlightLevel = (palmMisc.backlightLevel > 0) ? (1 + backlightAmplifierState()) : 0;
palmMisc.backlightLevel = (palmMisc.backlightLevel > 0) ? (1 + m515BacklightAmplifierState()) : 0;
}
static void updateTouchState(void){
if(!(registerArrayRead8(PFSEL) & registerArrayRead8(PFDIR) & 0x02)){
if((ads7846PenIrqEnabled ? !palmInput.touchscreenTouched : true) == !!(registerArrayRead16(ICR) & 0x0080))
setIprIsrBit(INT_IRQ5);
setIprIsrBit(DBVZ_INT_IRQ5);
else
clearIprIsrBit(INT_IRQ5);
clearIprIsrBit(DBVZ_INT_IRQ5);
}
}

View File

@@ -4,8 +4,8 @@
#include "emulator.h"
#include "specs/dragonballVzRegisterSpec.h"
#include "hardwareRegisters.h"
#include "memoryAccess.h"
#include "dbvzRegisters.h"
#include "m515Bus.h"
#include "portability.h"
#include "flx68000.h"
#include "ads7846.h"
@@ -14,25 +14,25 @@
#include "debug/sandbox.h"
chip_t chips[CHIP_END];
int8_t pllSleepWait;
int8_t pllWakeWait;
uint32_t clk32Counter;
double pctlrCpuClockDivider;
double timerCycleCounter[2];
uint16_t timerStatusReadAcknowledge[2];
uint8_t portDInterruptLastValue;//used for edge triggered interrupt timing
uint16_t spi1RxFifo[9];
uint16_t spi1TxFifo[9];
uint8_t spi1RxReadPosition;
uint8_t spi1RxWritePosition;
bool spi1RxOverflowed;
uint8_t spi1TxReadPosition;
uint8_t spi1TxWritePosition;
int32_t pwm1ClocksToNextSample;
uint8_t pwm1Fifo[6];
uint8_t pwm1ReadPosition;
uint8_t pwm1WritePosition;
dbvz_chip_t chips[DBVZ_CHIP_END];
int8_t pllSleepWait;
int8_t pllWakeWait;
uint32_t clk32Counter;
double pctlrCpuClockDivider;
double timerCycleCounter[2];
uint16_t timerStatusReadAcknowledge[2];
uint8_t portDInterruptLastValue;//used for edge triggered interrupt timing
uint16_t spi1RxFifo[9];
uint16_t spi1TxFifo[9];
uint8_t spi1RxReadPosition;
uint8_t spi1RxWritePosition;
bool spi1RxOverflowed;
uint8_t spi1TxReadPosition;
uint8_t spi1TxWritePosition;
int32_t pwm1ClocksToNextSample;
uint8_t pwm1Fifo[6];
uint8_t pwm1ReadPosition;
uint8_t pwm1WritePosition;
static void checkInterrupts(void);
@@ -43,18 +43,18 @@ static int32_t audioGetFramePercentIncrementFromClk32s(int32_t count);
static int32_t audioGetFramePercentIncrementFromSysclks(double count);
static int32_t audioGetFramePercentage(void);
#include "hardwareRegistersAccessors.c.h"
#include "hardwareRegistersTiming.c.h"
#include "dbvzRegisterAccessors.c.h"
#include "dbvzTiming.c.h"
bool pllIsOn(void){
bool dbvzIsPllOn(void){
return !(palmSysclksPerClk32 < 1.0);
}
bool backlightAmplifierState(void){
bool m515BacklightAmplifierState(void){
return !!(getPortKValue() & 0x02);
}
bool registersAreXXFFMapped(void){
bool dbvzAreRegistersXXFFMapped(void){
return !!(registerArrayRead8(SCR) & 0x04);
}
@@ -69,9 +69,9 @@ void ads7846OverridePenState(bool value){
if(value != (ads7846PenIrqEnabled ? !palmInput.touchscreenTouched : true)){
if(!(registerArrayRead8(PFSEL) & registerArrayRead8(PFDIR) & 0x02)){
if(value == !!(registerArrayRead16(ICR) & 0x0080))
setIprIsrBit(INT_IRQ5);
setIprIsrBit(DBVZ_INT_IRQ5);
else
clearIprIsrBit(INT_IRQ5);
clearIprIsrBit(DBVZ_INT_IRQ5);
}
checkInterrupts();
@@ -81,13 +81,13 @@ void ads7846OverridePenState(bool value){
}
}
void refreshTouchState(void){
void m515RefreshTouchState(void){
//called when ads7846PenIrqEnabled is changed
updateTouchState();
checkInterrupts();
}
void refreshInputState(void){
void m515RefreshInputState(void){
//update power button LED state if palmMisc.batteryCharging changed
updatePowerButtonLedStatus();
@@ -115,7 +115,7 @@ int32_t interruptAcknowledge(int32_t intLevel){
return vector;
}
void setBusErrorTimeOut(uint32_t address, bool isWrite){
void dbvzSetBusErrorTimeOut(uint32_t address, bool isWrite){
uint8_t scr = registerArrayRead8(SCR);
debugLog("Bus error timeout at:0x%08X, PC:0x%08X\n", address, flx68000GetPc());
registerArrayWrite8(SCR, scr | 0x80);
@@ -123,7 +123,7 @@ void setBusErrorTimeOut(uint32_t address, bool isWrite){
flx68000BusError(address, isWrite);
}
void setPrivilegeViolation(uint32_t address, bool isWrite){
void dbvzSetPrivilegeViolation(uint32_t address, bool isWrite){
uint8_t scr = registerArrayRead8(SCR);
debugLog("Privilege violation at:0x%08X, PC:0x%08X\n", address, flx68000GetPc());
registerArrayWrite8(SCR, scr | 0x20);
@@ -131,7 +131,7 @@ void setPrivilegeViolation(uint32_t address, bool isWrite){
flx68000BusError(address, isWrite);
}
void setWriteProtectViolation(uint32_t address){
void dbvzSetWriteProtectViolation(uint32_t address){
uint8_t scr = registerArrayRead8(SCR);
debugLog("Write protect violation at:0x%08X, PC:0x%08X\n", address, flx68000GetPc());
registerArrayWrite8(SCR, scr | 0x40);
@@ -143,7 +143,7 @@ static void pllWakeCpuIfOff(void){
const int8_t pllWaitTable[4] = {32, 48, 64, 96};
//PLL is off and not already in the process of waking up
if(!pllIsOn() && pllWakeWait == -1)
if(!dbvzIsPllOn() && pllWakeWait == -1)
pllWakeWait = pllWaitTable[registerArrayRead16(PLLCR) & 0x0003];
}
@@ -157,38 +157,38 @@ static void checkInterrupts(void){
uint8_t intLevel = 0;
//static interrupts
if(activeInterrupts & INT_EMIQ)
if(activeInterrupts & DBVZ_INT_EMIQ)
intLevel = 7;//EMIQ - Emulator IRQ, has nothing to do with emulation, used for debugging on a dev board
if(intLevel < 6 && activeInterrupts & (INT_TMR1 | INT_PWM1 | INT_IRQ6))
if(intLevel < 6 && activeInterrupts & (DBVZ_INT_TMR1 | DBVZ_INT_PWM1 | DBVZ_INT_IRQ6))
intLevel = 6;
if(intLevel < 5 && activeInterrupts & INT_IRQ5)
if(intLevel < 5 && activeInterrupts & DBVZ_INT_IRQ5)
intLevel = 5;
if(intLevel < 4 && activeInterrupts & (INT_SPI2 | INT_UART1 | INT_WDT | INT_RTC | INT_KB | INT_RTI | INT_INT0 | INT_INT1 | INT_INT2 | INT_INT3))
if(intLevel < 4 && activeInterrupts & (DBVZ_INT_SPI2 | DBVZ_INT_UART1 | DBVZ_INT_WDT | DBVZ_INT_RTC | DBVZ_INT_KB | DBVZ_INT_RTI | DBVZ_INT_INT0 | DBVZ_INT_INT1 | DBVZ_INT_INT2 | DBVZ_INT_INT3))
intLevel = 4;
if(intLevel < 3 && activeInterrupts & INT_IRQ3)
if(intLevel < 3 && activeInterrupts & DBVZ_INT_IRQ3)
intLevel = 3;
if(intLevel < 2 && activeInterrupts & INT_IRQ2)
if(intLevel < 2 && activeInterrupts & DBVZ_INT_IRQ2)
intLevel = 2;
if(intLevel < 1 && activeInterrupts & INT_IRQ1)
if(intLevel < 1 && activeInterrupts & DBVZ_INT_IRQ1)
intLevel = 1;
//configureable interrupts
if(intLevel < spi1IrqLevel && activeInterrupts & INT_SPI1)
if(intLevel < spi1IrqLevel && activeInterrupts & DBVZ_INT_SPI1)
intLevel = spi1IrqLevel;
if(intLevel < uart2IrqLevel && activeInterrupts & INT_UART2)
if(intLevel < uart2IrqLevel && activeInterrupts & DBVZ_INT_UART2)
intLevel = uart2IrqLevel;
if(intLevel < pwm2IrqLevel && activeInterrupts & INT_PWM2)
if(intLevel < pwm2IrqLevel && activeInterrupts & DBVZ_INT_PWM2)
intLevel = pwm2IrqLevel;
if(intLevel < timer2IrqLevel && activeInterrupts & INT_TMR2)
if(intLevel < timer2IrqLevel && activeInterrupts & DBVZ_INT_TMR2)
intLevel = timer2IrqLevel;
//even masked interrupts turn off PCTLR, 4.5.4 Power Control Register MC68VZ328UM.pdf
@@ -209,55 +209,55 @@ static void checkPortDInterrupts(void){
uint8_t portDInterruptEdgeTriggered = icrEdgeTriggered | registerArrayRead8(PDIRQEG);
uint8_t portDInterruptEnabled = (~registerArrayRead8(PDSEL) & 0xF0) | registerArrayRead8(PDIRQEN);
uint8_t portDIsInput = ~registerArrayRead8(PDDIR);
uint8_t portDInterruptTriggered = portDInterruptValue & portDInterruptEnabled & portDIsInput & (~portDInterruptEdgeTriggered | ~portDInterruptLastValue & (pllIsOn() ? 0xFF : 0xF0));
uint8_t portDInterruptTriggered = portDInterruptValue & portDInterruptEnabled & portDIsInput & (~portDInterruptEdgeTriggered | ~portDInterruptLastValue & (dbvzIsPllOn() ? 0xFF : 0xF0));
if(portDInterruptTriggered & 0x01)
setIprIsrBit(INT_INT0);
setIprIsrBit(DBVZ_INT_INT0);
else if(!(portDInterruptEdgeTriggered & 0x01))
clearIprIsrBit(INT_INT0);
clearIprIsrBit(DBVZ_INT_INT0);
if(portDInterruptTriggered & 0x02)
setIprIsrBit(INT_INT1);
setIprIsrBit(DBVZ_INT_INT1);
else if(!(portDInterruptEdgeTriggered & 0x02))
clearIprIsrBit(INT_INT1);
clearIprIsrBit(DBVZ_INT_INT1);
if(portDInterruptTriggered & 0x04)
setIprIsrBit(INT_INT2);
setIprIsrBit(DBVZ_INT_INT2);
else if(!(portDInterruptEdgeTriggered & 0x04))
clearIprIsrBit(INT_INT2);
clearIprIsrBit(DBVZ_INT_INT2);
if(portDInterruptTriggered & 0x08)
setIprIsrBit(INT_INT3);
setIprIsrBit(DBVZ_INT_INT3);
else if(!(portDInterruptEdgeTriggered & 0x08))
clearIprIsrBit(INT_INT3);
clearIprIsrBit(DBVZ_INT_INT3);
if(portDInterruptTriggered & 0x10)
setIprIsrBit(INT_IRQ1);
setIprIsrBit(DBVZ_INT_IRQ1);
else if(!(portDInterruptEdgeTriggered & 0x10))
clearIprIsrBit(INT_IRQ1);
clearIprIsrBit(DBVZ_INT_IRQ1);
if(portDInterruptTriggered & 0x20)
setIprIsrBit(INT_IRQ2);
setIprIsrBit(DBVZ_INT_IRQ2);
else if(!(portDInterruptEdgeTriggered & 0x20))
clearIprIsrBit(INT_IRQ2);
clearIprIsrBit(DBVZ_INT_IRQ2);
if(portDInterruptTriggered & 0x40)
setIprIsrBit(INT_IRQ3);
setIprIsrBit(DBVZ_INT_IRQ3);
else if(!(portDInterruptEdgeTriggered & 0x40))
clearIprIsrBit(INT_IRQ3);
clearIprIsrBit(DBVZ_INT_IRQ3);
if(portDInterruptTriggered & 0x80)
setIprIsrBit(INT_IRQ6);
setIprIsrBit(DBVZ_INT_IRQ6);
else if(!(portDInterruptEdgeTriggered & 0x80))
clearIprIsrBit(INT_IRQ6);
clearIprIsrBit(DBVZ_INT_IRQ6);
//active low/off level triggered interrupt(triggers on 0, not a pull down resistor)
//The SELx, POLx, IQENx, and IQEGx bits have no effect on the functionality of KBENx, 10.4.5.8 Port D Keyboard Enable Register MC68VZ328UM.pdf
//the above has finally been verified to be correct!
if(registerArrayRead8(PDKBEN) & ~(getPortDValue() ^ registerArrayRead8(PDPOL)) & portDIsInput)
setIprIsrBit(INT_KB);
setIprIsrBit(DBVZ_INT_KB);
else
clearIprIsrBit(INT_KB);
clearIprIsrBit(DBVZ_INT_KB);
//save to check against next time this function is called
portDInterruptLastValue = portDInterruptTriggered;
@@ -272,19 +272,16 @@ static void printHwRegAccess(uint32_t address, uint32_t value, uint32_t size, bo
debugLog("CPU read %d bits from register 0x%03X, PC:0x%08X.\n", size, address, flx68000GetPc());
}
uint8_t getHwRegister8(uint32_t address){
uint8_t dbvzGetRegister8(uint32_t address){
#if !defined(EMU_NO_SAFETY)
if((address & 0x0000F000) != 0x0000F000){
setBusErrorTimeOut(address, false);
dbvzSetBusErrorTimeOut(address, false);
return 0x00;
}
#endif
address &= 0x00000FFF;
if(sandboxRunning() && address < 0xE00)
printHwRegAccess(address, 0, 8, false);
switch(address){
case PADATA:
return getPortAValue();
@@ -380,25 +377,21 @@ uint8_t getHwRegister8(uint32_t address){
if(address >= 0xE00)
return registerArrayRead8(address);
if(!sandboxRunning())//dont double unknown accesses when sandbox is active
printHwRegAccess(address, 0, 8, false);
printHwRegAccess(address, 0, 8, false);
return 0x00;
}
}
uint16_t getHwRegister16(uint32_t address){
uint16_t dbvzGetRegister16(uint32_t address){
#if !defined(EMU_NO_SAFETY)
if((address & 0x0000F000) != 0x0000F000){
setBusErrorTimeOut(address, false);
dbvzSetBusErrorTimeOut(address, false);
return 0x0000;
}
#endif
address &= 0x00000FFF;
if(sandboxRunning() && address < 0xE00)
printHwRegAccess(address, 0, 16, false);
switch(address){
case TSTAT1:
timerStatusReadAcknowledge[0] |= registerArrayRead16(TSTAT1);//active bits acknowledged
@@ -474,25 +467,21 @@ uint16_t getHwRegister16(uint32_t address){
if(address >= 0xE00)
return registerArrayRead16(address);
if(!sandboxRunning())//dont double unknown accesses when sandbox is active
printHwRegAccess(address, 0, 16, false);
printHwRegAccess(address, 0, 16, false);
return 0x0000;
}
}
uint32_t getHwRegister32(uint32_t address){
uint32_t dbvzGetRegister32(uint32_t address){
#if !defined(EMU_NO_SAFETY)
if((address & 0x0000F000) != 0x0000F000){
setBusErrorTimeOut(address, false);
dbvzSetBusErrorTimeOut(address, false);
return 0x00000000;
}
#endif
address &= 0x00000FFF;
if(sandboxRunning() && address < 0xE00)
printHwRegAccess(address, 0, 32, false);
switch(address){
case ISR:
case IPR:
@@ -507,25 +496,21 @@ uint32_t getHwRegister32(uint32_t address){
if(address >= 0xE00)
return registerArrayRead32(address);
if(!sandboxRunning())//dont double unknown accesses when sandbox is active
printHwRegAccess(address, 0, 32, false);
printHwRegAccess(address, 0, 32, false);
return 0x00000000;
}
}
void setHwRegister8(uint32_t address, uint8_t value){
void dbvzSetRegister8(uint32_t address, uint8_t value){
#if !defined(EMU_NO_SAFETY)
if((address & 0x0000F000) != 0x0000F000){
setBusErrorTimeOut(address, true);
dbvzSetBusErrorTimeOut(address, true);
return;
}
#endif
address &= 0x00000FFF;
if(sandboxRunning() && address < 0xE00)
printHwRegAccess(address, value, 8, true);
switch(address){
case SCR:
setScr(value);
@@ -585,7 +570,7 @@ void setHwRegister8(uint32_t address, uint8_t value){
case PFSEL:
//this register controls the clock output pin for the SED1376 and IRQ line for PENIRQ
registerArrayWrite8(PFSEL, value);
setSed1376Attached(sed1376ClockConnected());
m515SetSed1376Attached(sed1376ClockConnected());
#if !defined(EMU_NO_SAFETY)
updateTouchState();
checkInterrupts();
@@ -677,25 +662,21 @@ void setHwRegister8(uint32_t address, uint8_t value){
return;
}
if(!sandboxRunning())//dont double unknown accesses when sandbox is active
printHwRegAccess(address, value, 8, true);
printHwRegAccess(address, value, 8, true);
return;
}
}
void setHwRegister16(uint32_t address, uint16_t value){
void dbvzSetRegister16(uint32_t address, uint16_t value){
#if !defined(EMU_NO_SAFETY)
if((address & 0x0000F000) != 0x0000F000){
setBusErrorTimeOut(address, true);
dbvzSetBusErrorTimeOut(address, true);
return;
}
#endif
address &= 0x00000FFF;
if(sandboxRunning() && address < 0xE00)
printHwRegAccess(address, value, 16, true);
switch(address){
case RTCIENR:
//missing bits 6 and 7
@@ -744,15 +725,15 @@ void setHwRegister16(uint32_t address, uint16_t value){
//1 must be written to clear INTF
registerArrayWrite16(WATCHDOG, (value & 0x0003) | (registerArrayRead16(WATCHDOG) & (~value & 0x0080)));
if(!(registerArrayRead16(WATCHDOG) & 0x0080))
clearIprIsrBit(INT_WDT);
clearIprIsrBit(DBVZ_INT_WDT);
return;
case RTCISR:
registerArrayWrite16(RTCISR, registerArrayRead16(RTCISR) & ~value);
if(!(registerArrayRead16(RTCISR) & 0xFF00))
clearIprIsrBit(INT_RTI);
clearIprIsrBit(DBVZ_INT_RTI);
if(!(registerArrayRead16(RTCISR) & 0x003F))
clearIprIsrBit(INT_RTC);
clearIprIsrBit(DBVZ_INT_RTC);
checkInterrupts();
return;
@@ -764,7 +745,7 @@ void setHwRegister16(uint32_t address, uint16_t value){
//CLKEN is required for SED1376 operation
registerArrayWrite16(PLLCR, value & 0x3FBB);
palmSysclksPerClk32 = sysclksPerClk32();
setSed1376Attached(sed1376ClockConnected());
m515SetSed1376Attached(sed1376ClockConnected());
if(value & 0x0008)
pllSleepWait = 30;//The PLL shuts down 30 clocks of CLK32 after the DISPLL bit is set in the PLLCR
@@ -804,13 +785,13 @@ void setHwRegister16(uint32_t address, uint16_t value){
case CSA:{
uint16_t oldCsa = registerArrayRead16(CSA);
bool oldBootMode = chips[CHIP_A0_ROM].inBootMode;
bool oldBootMode = chips[DBVZ_CHIP_A0_ROM].inBootMode;
setCsa(value);
//only reset address space if size changed, enabled/disabled or exiting boot mode
if((value & 0x000F) != (oldCsa & 0x000F) || chips[CHIP_A0_ROM].inBootMode != oldBootMode)
resetAddressSpace();
if((value & 0x000F) != (oldCsa & 0x000F) || chips[DBVZ_CHIP_A0_ROM].inBootMode != oldBootMode)
dbvzResetAddressSpace();
}
return;
@@ -821,7 +802,7 @@ void setHwRegister16(uint32_t address, uint16_t value){
//only reset address space if size changed or enabled/disabled
if((value & 0x000F) != (oldCsb & 0x000F))
resetAddressSpace();
dbvzResetAddressSpace();
}
return;
@@ -841,7 +822,7 @@ void setHwRegister16(uint32_t address, uint16_t value){
//only reset address space if size changed, enabled/disabled or DRAM bit changed
if((value & 0x020F) != (oldCsd & 0x020F))
resetAddressSpace();
dbvzResetAddressSpace();
}
return;
@@ -849,7 +830,7 @@ void setHwRegister16(uint32_t address, uint16_t value){
//sets the starting location of ROM(0x10000000) and the PDIUSBD12 chip
if((value & 0xFFFE) != registerArrayRead16(CSGBA)){
setCsgba(value);
resetAddressSpace();
dbvzResetAddressSpace();
}
return;
@@ -857,7 +838,7 @@ void setHwRegister16(uint32_t address, uint16_t value){
//sets the starting location of the SED1376(0x1FF80000)
if((value & 0xFFFE) != registerArrayRead16(CSGBB)){
setCsgbb(value);
resetAddressSpace();
dbvzResetAddressSpace();
}
return;
@@ -869,7 +850,7 @@ void setHwRegister16(uint32_t address, uint16_t value){
//sets the starting location of RAM(0x00000000)
if((value & 0xFFFE) != registerArrayRead16(CSGBD)){
setCsgbd(value);
resetAddressSpace();
dbvzResetAddressSpace();
}
return;
@@ -880,7 +861,7 @@ void setHwRegister16(uint32_t address, uint16_t value){
setCsgba(registerArrayRead16(CSGBA));
setCsgbb(registerArrayRead16(CSGBB));
setCsgbd(registerArrayRead16(CSGBD));
resetAddressSpace();
dbvzResetAddressSpace();
}
return;
@@ -894,7 +875,7 @@ void setHwRegister16(uint32_t address, uint16_t value){
//CSA is not dependent on CSCTRL1
setCsb(registerArrayRead16(CSB));
setCsd(registerArrayRead16(CSD));
resetAddressSpace();
dbvzResetAddressSpace();
}
}
return;
@@ -970,25 +951,21 @@ void setHwRegister16(uint32_t address, uint16_t value){
return;
}
if(!sandboxRunning())//dont double unknown accesses when sandbox is active
printHwRegAccess(address, value, 16, true);
printHwRegAccess(address, value, 16, true);
return;
}
}
void setHwRegister32(uint32_t address, uint32_t value){
void dbvzSetRegister32(uint32_t address, uint32_t value){
#if !defined(EMU_NO_SAFETY)
if((address & 0x0000F000) != 0x0000F000){
setBusErrorTimeOut(address, true);
dbvzSetBusErrorTimeOut(address, true);
return;
}
#endif
address &= 0x00000FFF;
if(sandboxRunning() && address < 0xE00)
printHwRegAccess(address, value, 32, true);
switch(address){
case RTCTIME:
case RTCALRM:
@@ -1022,17 +999,16 @@ void setHwRegister32(uint32_t address, uint32_t value){
return;
}
if(!sandboxRunning())//dont double unknown accesses when sandbox is active
printHwRegAccess(address, value, 32, true);
printHwRegAccess(address, value, 32, true);
return;
}
}
void resetHwRegisters(void){
void dbvzResetRegisters(void){
uint32_t oldRtc = registerArrayRead32(RTCTIME);//preserve RTCTIME
uint16_t oldDayr = registerArrayRead16(DAYR);//preserve DAYR
memset(palmReg, 0x00, REG_SIZE - BOOTLOADER_SIZE);
memset(palmReg, 0x00, DBVZ_REG_SIZE - DBVZ_BOOTLOADER_SIZE);
palmSysclksPerClk32 = 0.0;
clk32Counter = 0;
pctlrCpuClockDivider = 1.0;
@@ -1057,19 +1033,19 @@ void resetHwRegisters(void){
memset(chips, 0x00, sizeof(chips));
//all chip selects are disabled at boot and CSA0 is mapped to 0x00000000 and covers the entire address range until CSA is set enabled
chips[CHIP_A0_ROM].inBootMode = true;
chips[DBVZ_CHIP_A0_ROM].inBootMode = true;
//default sizes
chips[CHIP_A0_ROM].lineSize = 0x20000;
chips[CHIP_A1_USB].lineSize = 0x20000;
chips[CHIP_B0_SED].lineSize = 0x20000;
chips[CHIP_DX_RAM].lineSize = 0x8000;
chips[DBVZ_CHIP_A0_ROM].lineSize = 0x20000;
chips[DBVZ_CHIP_A1_USB].lineSize = 0x20000;
chips[DBVZ_CHIP_B0_SED].lineSize = 0x20000;
chips[DBVZ_CHIP_DX_RAM].lineSize = 0x8000;
//masks for reading and writing
chips[CHIP_A0_ROM].mask = 0x003FFFFF;//4mb
chips[CHIP_A1_USB].mask = 0x00000002;//A1 is used as USB chip A0
chips[CHIP_B0_SED].mask = 0x0001FFFF;
chips[CHIP_DX_RAM].mask = 0x00000000;//16mb, no RAM enabled until the DRAM module is initialized
chips[DBVZ_CHIP_A0_ROM].mask = 0x003FFFFF;//4mb
chips[DBVZ_CHIP_A1_USB].mask = 0x00000002;//A1 is used as USB chip A0
chips[DBVZ_CHIP_B0_SED].mask = 0x0001FFFF;
chips[DBVZ_CHIP_DX_RAM].mask = 0x00000000;//16mb, no RAM enabled until the DRAM module is initialized
//system control
registerArrayWrite8(SCR, 0x1C);
@@ -1180,7 +1156,7 @@ void resetHwRegisters(void){
palmSysclksPerClk32 = sysclksPerClk32();
}
void setRtc(uint16_t days, uint8_t hours, uint8_t minutes, uint8_t seconds){
void dbvzSetRtc(uint16_t days, uint8_t hours, uint8_t minutes, uint8_t seconds){
registerArrayWrite32(RTCTIME, hours << 24 & 0x1F000000 | minutes << 16 & 0x003F0000 | seconds & 0x0000003F);
registerArrayWrite16(DAYR, days & 0x01FF);
}

119
src/dbvzRegisters.h Normal file
View File

@@ -0,0 +1,119 @@
#ifndef DBVZ_REGISTERS_H
#define DBVZ_REGISTERS_H
#include <stdint.h>
#include <stdbool.h>
//interrupt names
#define DBVZ_INT_EMIQ 0x00800000//level 7
#define DBVZ_INT_RTI 0x00400000//level 4
#define DBVZ_INT_SPI1 0x00200000//level 1<->6, configurable, datasheet is contraditory on this one
#define DBVZ_INT_IRQ5 0x00100000//level 5
#define DBVZ_INT_IRQ6 0x00080000//level 6
#define DBVZ_INT_IRQ3 0x00040000//level 3
#define DBVZ_INT_IRQ2 0x00020000//level 2
#define DBVZ_INT_IRQ1 0x00010000//level 1
#define DBVZ_INT_PWM2 0x00002000//level 1<->6, configurable
#define DBVZ_INT_UART2 0x00001000//level 1<->6, configurable
#define DBVZ_INT_INT3 0x00000800//level 4
#define DBVZ_INT_INT2 0x00000400//level 4
#define DBVZ_INT_INT1 0x00000200//level 4
#define DBVZ_INT_INT0 0x00000100//level 4
#define DBVZ_INT_PWM1 0x00000080//level 6
#define DBVZ_INT_KB 0x00000040//level 4
#define DBVZ_INT_TMR2 0x00000020//level 1<->6, configurable
#define DBVZ_INT_RTC 0x00000010//level 4
#define DBVZ_INT_WDT 0x00000008//level 4
#define DBVZ_INT_UART1 0x00000004//level 4
#define DBVZ_INT_TMR1 0x00000002//level 6
#define DBVZ_INT_SPI2 0x00000001//level 4
//reasons a timer is triggered
#define DBVZ_TIMER_REASON_SYSCLK 0x00
#define DBVZ_TIMER_REASON_TIN 0x01
#define DBVZ_TIMER_REASON_CLK32 0x02
//chip names
enum{
DBVZ_CHIP_BEGIN = 0,
DBVZ_CHIP_A0_ROM = 0,
DBVZ_CHIP_A1_USB,
DBVZ_CHIP_B0_SED,
DBVZ_CHIP_B1_NIL,
//DBVZ_CHIP_CX_RAM, //CSC* is owned by CSD during normal operation
DBVZ_CHIP_DX_RAM,
DBVZ_CHIP_00_EMU, //used for EMUCS on hardware, used by the emu registers here
DBVZ_CHIP_REGISTERS,
DBVZ_CHIP_NONE,
DBVZ_CHIP_END
};
//types
typedef struct{
bool enable;
uint32_t start;
uint32_t lineSize;//the size of a single chip select line, multiply by 2 to get the range size for RAM
uint32_t mask;//the address lines the chip responds to, so 0x10000 on an chip with 16 address lines will return the value at 0x0000
//attributes
bool inBootMode;
bool readOnly;
bool readOnlyForProtectedMemory;
bool supervisorOnlyProtectedMemory;
uint32_t unprotectedSize;
}dbvz_chip_t;
//variables
extern dbvz_chip_t chips[];
extern int8_t pllSleepWait;
extern int8_t pllWakeWait;
extern uint32_t clk32Counter;
extern double pctlrCpuClockDivider;
extern double timerCycleCounter[];
extern uint16_t timerStatusReadAcknowledge[];
extern uint8_t portDInterruptLastValue;
extern uint16_t spi1RxFifo[];
extern uint16_t spi1TxFifo[];
extern uint8_t spi1RxReadPosition;
extern uint8_t spi1RxWritePosition;
extern bool spi1RxOverflowed;
extern uint8_t spi1TxReadPosition;
extern uint8_t spi1TxWritePosition;
extern int32_t pwm1ClocksToNextSample;
extern uint8_t pwm1Fifo[];
extern uint8_t pwm1ReadPosition;
extern uint8_t pwm1WritePosition;
//timing
void dbvzBeginClk32(void);
void dbvzEndClk32(void);
void dbvzAddSysclks(double value);//only call between begin/endClk32
//CPU
bool dbvzIsPllOn(void);
bool m515BacklightAmplifierState(void);
bool dbvzAreRegistersXXFFMapped(void);
bool sed1376ClockConnected(void);
void ads7846OverridePenState(bool value);
void m515RefreshTouchState(void);//just refreshes the touchscreen
void m515RefreshInputState(void);//refreshes touchscreen, buttons and docked status
//int32_t interruptAcknowledge(int32_t intLevel);//this is in m68kexternal.h
//memory errors
void dbvzSetBusErrorTimeOut(uint32_t address, bool isWrite);
void dbvzSetPrivilegeViolation(uint32_t address, bool isWrite);
void dbvzSetWriteProtectViolation(uint32_t address);
//memory accessors
uint8_t dbvzGetRegister8(uint32_t address);
uint16_t dbvzGetRegister16(uint32_t address);
uint32_t dbvzGetRegister32(uint32_t address);
void dbvzSetRegister8(uint32_t address, uint8_t value);
void dbvzSetRegister16(uint32_t address, uint16_t value);
void dbvzSetRegister32(uint32_t address, uint32_t value);
//config
void dbvzResetRegisters(void);
void dbvzSetRtc(uint16_t days, uint8_t hours, uint8_t minutes, uint8_t seconds);
#endif

View File

@@ -16,25 +16,25 @@ static void timer1(uint8_t reason, double sysclks){
return;
case 0x0001://SYSCLK / timer prescaler
if(reason != TIMER_REASON_SYSCLK)
if(reason != DBVZ_TIMER_REASON_SYSCLK)
return;
timerCycleCounter[0] += sysclks / timer1Prescaler;
break;
case 0x0002://SYSCLK / 16 / timer prescaler
if(reason != TIMER_REASON_SYSCLK)
if(reason != DBVZ_TIMER_REASON_SYSCLK)
return;
timerCycleCounter[0] += sysclks / 16.0 / timer1Prescaler;
break;
case 0x0003://TIN/TOUT pin / timer prescaler, the other timer can be attached to TIN/TOUT
if(reason != TIMER_REASON_TIN)
if(reason != DBVZ_TIMER_REASON_TIN)
return;
timerCycleCounter[0] += 1.0 / timer1Prescaler;
break;
default://CLK32 / timer prescaler
if(reason != TIMER_REASON_CLK32)
if(reason != DBVZ_TIMER_REASON_CLK32)
return;
timerCycleCounter[0] += 1.0 / timer1Prescaler;
break;
@@ -47,7 +47,7 @@ static void timer1(uint8_t reason, double sysclks){
//interrupt enabled
if(timer1Control & 0x0010)
setIprIsrBit(INT_TMR1);
setIprIsrBit(DBVZ_INT_TMR1);
//checkInterrupts() is run when the clock that called this function is finished
//set timer triggered bit
@@ -56,7 +56,7 @@ static void timer1(uint8_t reason, double sysclks){
//increment other timer if enabled
if(pcrTinToutConfig == 0x03)
timer2(TIMER_REASON_TIN, 0);
timer2(DBVZ_TIMER_REASON_TIN, 0);
//not free running, reset to 0, to prevent loss of ticks after compare event just subtract timerXCompare
if(!(timer1Control & 0x0100))
@@ -83,25 +83,25 @@ static void timer2(uint8_t reason, double sysclks){
return;
case 0x0001://SYSCLK / timer prescaler
if(reason != TIMER_REASON_SYSCLK)
if(reason != DBVZ_TIMER_REASON_SYSCLK)
return;
timerCycleCounter[1] += sysclks / timer2Prescaler;
break;
case 0x0002://SYSCLK / 16 / timer prescaler
if(reason != TIMER_REASON_SYSCLK)
if(reason != DBVZ_TIMER_REASON_SYSCLK)
return;
timerCycleCounter[1] += sysclks / 16.0 / timer2Prescaler;
break;
case 0x0003://TIN/TOUT pin / timer prescaler, the other timer can be attached to TIN/TOUT
if(reason != TIMER_REASON_TIN)
if(reason != DBVZ_TIMER_REASON_TIN)
return;
timerCycleCounter[1] += 1.0 / timer2Prescaler;
break;
default://CLK32 / timer prescaler
if(reason != TIMER_REASON_CLK32)
if(reason != DBVZ_TIMER_REASON_CLK32)
return;
timerCycleCounter[1] += 1.0 / timer2Prescaler;
break;
@@ -114,7 +114,7 @@ static void timer2(uint8_t reason, double sysclks){
//interrupt enabled
if(timer2Control & 0x0010)
setIprIsrBit(INT_TMR2);
setIprIsrBit(DBVZ_INT_TMR2);
//checkInterrupts() is run when the clock that called this function is finished
//set timer triggered bit
@@ -123,7 +123,7 @@ static void timer2(uint8_t reason, double sysclks){
//increment other timer if enabled
if(pcrTinToutConfig == 0x02)
timer1(TIMER_REASON_TIN, 0);
timer1(DBVZ_TIMER_REASON_TIN, 0);
//not free running, reset to 0, to prevent loss of ticks after compare event just subtract timerXCompare
if(!(timer2Control & 0x0100))
@@ -205,7 +205,7 @@ static void rtiInterruptClk32(void){
triggeredRtiInterrupts &= registerArrayRead16(RTCIENR);
if(triggeredRtiInterrupts){
registerArrayWrite16(RTCISR, registerArrayRead16(RTCISR) | triggeredRtiInterrupts);
setIprIsrBit(INT_RTI);
setIprIsrBit(DBVZ_INT_RTI);
}
}
@@ -222,7 +222,7 @@ static void watchdogSecondTickClk32(void){
if(watchdogState & 0x0002){
//interrupt
watchdogState |= 0x0080;
setIprIsrBit(INT_WDT);
setIprIsrBit(DBVZ_INT_WDT);
}
else{
//reset
@@ -291,7 +291,7 @@ static void rtcAddSecondClk32(void){
rtcInterruptEvents &= registerArrayRead16(RTCIENR);
if(rtcInterruptEvents){
registerArrayWrite16(RTCISR, registerArrayRead16(RTCISR) | rtcInterruptEvents);
setIprIsrBit(INT_RTC);
setIprIsrBit(DBVZ_INT_RTC);
}
registerArrayWrite32(RTCTIME, newRtcTime);
@@ -301,11 +301,11 @@ static void rtcAddSecondClk32(void){
watchdogSecondTickClk32();
}
void beginClk32(void){
void dbvzBeginClk32(void){
palmClk32Sysclks = 0.0;
}
void endClk32(void){
void dbvzEndClk32(void){
//currently using toggle on read hack
//registerArrayWrite16(PLLFSR, registerArrayRead16(PLLFSR) ^ 0x8000);
@@ -322,8 +322,8 @@ void endClk32(void){
if(registerArrayRead16(RTCCTL) & 0x0080 || registerArrayRead16(WATCHDOG) & 0x01)
rtiInterruptClk32();
timer1(TIMER_REASON_CLK32, 0);
timer2(TIMER_REASON_CLK32, 0);
timer1(DBVZ_TIMER_REASON_CLK32, 0);
timer2(DBVZ_TIMER_REASON_CLK32, 0);
samplePwm1(true/*forClk32*/, 0.0);
//PLLCR sleep wait
@@ -350,9 +350,9 @@ void endClk32(void){
checkInterrupts();
}
void addSysclks(double count){
timer1(TIMER_REASON_SYSCLK, count);
timer2(TIMER_REASON_SYSCLK, count);
void dbvzAddSysclks(double count){
timer1(DBVZ_TIMER_REASON_SYSCLK, count);
timer2(DBVZ_TIMER_REASON_SYSCLK, count);
samplePwm1(false/*forClk32*/, count);
checkInterrupts();
@@ -370,5 +370,5 @@ static int32_t audioGetFramePercentIncrementFromSysclks(double count){
static int32_t audioGetFramePercentage(void){
//returns how much of the frame has executed
//0% = 0, 100% = AUDIO_END_OF_FRAME
return audioGetFramePercentIncrementFromClk32s(palmFrameClk32s) + (pllIsOn() ? audioGetFramePercentIncrementFromSysclks(palmClk32Sysclks) : 0);
return audioGetFramePercentIncrementFromClk32s(palmFrameClk32s) + (dbvzIsPllOn() ? audioGetFramePercentIncrementFromSysclks(palmClk32Sysclks) : 0);
}

View File

@@ -14,15 +14,21 @@
#include "../m68k/m68kcpu.h"
#include "../emulator.h"
#include "../ads7846.h"
#include "../hardwareRegisters.h"
#include "../dbvzRegisters.h"
#include "../portability.h"
#include "../specs/emuFeatureRegisterSpec.h"
#include "sandbox.h"
#include "trapNames.h"
#define SANDBOX_MAX_UNLOGGED_JUMP_SIZE 0xFFFFFFFF
#define SANDBOX_MAX_WATCH_REGIONS 1000
#define SANDBOX_SECONDS_TO_FRAMES(x) ((x) * EMU_FPS)
typedef struct{
void* hostPointer;
void* hostPointer;
uint32_t emuPointer;
uint64_t bytes;//may be used for strings or structs in the future
}return_pointer_t;
@@ -35,16 +41,37 @@ typedef struct{
uint32_t d0;
}local_cpu_state_t;
typedef struct{
uint32_t address;
uint32_t size;
uint8_t type;
}mem_region_t;
static bool sandboxActive;//used to "log out" of the emulator once a test has finished
static bool sandboxControlHandoff;//used for functions that depend on timing, hands full control to the 68k
static bool sandboxControlHandoff;//used for functions that depend on timing, hands full control to the m68k
static uint8_t sandboxCurrentCpuArch;
static local_cpu_state_t sandboxOldFunctionCpuState;
static uint64_t sandboxFramesRan;
static mem_region_t sandboxWatchRegions[SANDBOX_MAX_WATCH_REGIONS];//code locations in 68k address space to be sandboxed
static uint16_t sandboxWatchRegionsActive;//number of used sandboxWatchRegions entrys
static uint32_t sandboxCallGuestFunction(bool fallthrough, uint32_t address, uint16_t trap, const char* prototype, ...);
#include "sandboxTrapNumToName.c.h"
uint32_t getRandomRange(uint32_t start, uint32_t end){
static bool seeded = false;
if(!seeded){
srand(time(NULL));
seeded = true;
}
return (uint32_t)rand() % (end + 1 - start) + start;
}
static char* takeStackDump(uint32_t bytes){
char* textBytes = malloc(bytes * 2);
uint32_t textBytesOffset = 0;
@@ -61,7 +88,7 @@ static char* takeStackDump(uint32_t bytes){
return textBytes;
}
void patchOsRom(uint32_t address, char* patch){
static void patchOsRom(uint32_t address, char* patch){
uint32_t offset;
uint32_t patchBytes = strlen(patch) / 2;//1 char per nibble
uint32_t swapBegin = address & 0xFFFFFFFE;
@@ -77,6 +104,49 @@ void patchOsRom(uint32_t address, char* patch){
swap16BufferIfLittle(&palmRom[swapBegin], swapSize);
}
static const char* getLowMemGlobalName(uint32_t address){
switch(address){
case 0x00000100:
return "MemTotalCards";
case 0x00000102:
return "MemCard0Start";
case 0x0000010A:
return "MemDebugFlags";
case 0x00000122:
return "TrapTablePtr";
case 0x00000164:
return "ScrStatePtr";
case 0x0000016C:
return "PenStatePtr";
case 0x00000170:
return "EvtStatePtr";
case 0x00000174:
return "SndStatePtr";
case 0x00000178:
return "TimStatePtr";
case 0x0000017C:
return "AlmStatePtr";
case 0x00000180:
return "FtrStatePtr";
case 0x00000184:
return "GrfStatePtr";
default:
return "UNKNOWN";
}
}
static bool ignoreTrap(uint16_t trap){
switch(trap){
case HwrDisableDataWrites:
@@ -94,16 +164,37 @@ static void printTrapInfo(uint16_t trap){
debugLog("name:%s, API:0x%04X, location:0x%08X\n", lookupTrap(trap), trap, m68k_read_memory_32(0x000008CC + (trap & 0x0FFF) * 4));
}
bool validExecutionAddress(uint32_t address){
if(chips[DBVZ_CHIP_A0_ROM].inBootMode || address >= chips[DBVZ_CHIP_A0_ROM].start && address < chips[DBVZ_CHIP_A0_ROM].start + chips[DBVZ_CHIP_A0_ROM].lineSize)
return true;
if(address >= chips[DBVZ_CHIP_DX_RAM].start && address < chips[DBVZ_CHIP_DX_RAM].start + chips[DBVZ_CHIP_DX_RAM].lineSize)
return true;
if(sandboxActive && address >= 0xFFFFFE00)//used to run custom code when in sandbox mode
return true;
return false;
}
void log68kJumps(void){
uint32_t opcodeStartPc = m68k_get_reg(NULL, M68K_REG_PPC);
uint32_t opcodeEndPc = m68k_get_reg(NULL, M68K_REG_PC);
uint32_t difference = llabs((int64_t)opcodeStartPc - (int64_t)opcodeEndPc);
//if invalid always log, otherwise only log if big jump
if(!validExecutionAddress(opcodeEndPc))
debugLog("m68k jumped 0x%08X bytes to invalid address, from 0x%08X to 0x%08X\n", difference, opcodeStartPc, opcodeEndPc);
else if(difference > SANDBOX_MAX_UNLOGGED_JUMP_SIZE)
debugLog("m68k jumped 0x%08X bytes, from 0x%08X to 0x%08X\n", difference, opcodeStartPc, opcodeEndPc);
}
static void logApiCalls(void){
uint32_t programCounter = m68k_get_reg(NULL, M68K_REG_PPC);
uint16_t instruction = m68k_get_reg(NULL, M68K_REG_IR);
uint16_t instruction = m68k_read_memory_16(programCounter);
if(instruction == 0x4E4F){
//Trap F/API call
if(instruction == 0x4E4F/*Trap F/API call opcode*/){
uint16_t trap = m68k_read_memory_16(programCounter + 2);
if(!ignoreTrap(trap)){
if(!ignoreTrap(trap))
debugLog("Trap F API:%s, API number:0x%04X, PC:0x%08X\n", lookupTrap(trap), trap, programCounter);
}
}
}
@@ -115,7 +206,6 @@ static bool isAlphanumeric(char chr){
static bool readable6CharsBack(uint32_t address){
uint8_t count;
for(count = 0; count < 6; count++)
if(!isAlphanumeric(m68k_read_memory_8(address - count)))
return false;
@@ -162,8 +252,8 @@ static uint32_t scanForPrivateFunctionAddress(const char* name){
//function name format [0x**(unknown), string(with null terminator), 0x00, 0x00(if last 0x00 was on an even address, protects opcode alignemnt)]
//this is not 100% accurate, it scans memory for a function address based on a string
//if a duplicate set of stings is found but not encasing a function a fatal error will occur on execution
uint32_t rangeEnd = chips[CHIP_A0_ROM].start + chips[CHIP_A0_ROM].lineSize - 1;
uint32_t address = find68kString(name, chips[CHIP_A0_ROM].start, rangeEnd);
uint32_t rangeEnd = chips[DBVZ_CHIP_A0_ROM].start + chips[DBVZ_CHIP_A0_ROM].lineSize - 1;
uint32_t address = find68kString(name, chips[DBVZ_CHIP_A0_ROM].start, rangeEnd);
while(address < rangeEnd){
uint32_t signatureBegining = address - 3;//last opcode of function being looked for if the string is correct
@@ -201,7 +291,7 @@ static uint32_t scanForPrivateFunctionAddress(const char* name){
}
//call anywhere in a function to get its name, used to determine the location of a crash, must free the pointer after reading the string
static char* getFunctionName(uint32_t address){
static char* getFunctionName68k(uint32_t address){
char* data;
uint32_t offset;
@@ -285,9 +375,8 @@ static bool installResourceToDevice(buffer_t resourceBuffer){
}
*/
//uint32_t palmSideResourceData = callFunction(false, 0x00000000, MemPtrNew, "p(l)", (uint32_t)resourceBuffer.size);
uint32_t palmSideResourceData = sandboxCallGuestFunction(false, 0x00000000, MemChunkNew, "p(wlw)", 1/*heapID, storage RAM*/, resourceBuffer.size, 0x1200/*attr, seems to work without memOwnerID*/);
bool storageRamReadOnly = chips[CHIP_DX_RAM].readOnlyForProtectedMemory;
bool storageRamReadOnly = chips[DBVZ_CHIP_DX_RAM].readOnlyForProtectedMemory;
uint16_t error;
uint32_t count;
@@ -295,10 +384,10 @@ static bool installResourceToDevice(buffer_t resourceBuffer){
if(!palmSideResourceData)
return false;
chips[CHIP_DX_RAM].readOnlyForProtectedMemory = false;//need to unprotect storage RAM
chips[DBVZ_CHIP_DX_RAM].readOnlyForProtectedMemory = false;//need to unprotect storage RAM
for(count = 0; count < resourceBuffer.size; count++)
m68k_write_memory_8(palmSideResourceData + count, resourceBuffer.data[count]);
chips[CHIP_DX_RAM].readOnlyForProtectedMemory = storageRamReadOnly;//restore old protection state
chips[DBVZ_CHIP_DX_RAM].readOnlyForProtectedMemory = storageRamReadOnly;//restore old protection state
error = sandboxCallGuestFunction(false, 0x00000000, DmCreateDatabaseFromImage, "w(p)", palmSideResourceData);//Err DmCreateDatabaseFromImage(MemPtr bufferP);//this looks best
sandboxCallGuestFunction(false, 0x00000000, MemChunkFree, "w(p)", palmSideResourceData);
@@ -309,6 +398,186 @@ static bool installResourceToDevice(buffer_t resourceBuffer){
return true;
}
static void printChunkHeader(uint32_t pointer){
uint32_t address = pointer - 8;
uint32_t headerLong1 = m68k_read_memory_32(address);
uint32_t totalSize = headerLong1 & 0x00FFFFFF;
uint8_t extraBytes = headerLong1 >> 24 & 0x0F;
uint32_t userRequestedSize = totalSize - 8 - extraBytes;
debugLog("Chunk header: address:0x%08X, totalSize:%d(0x%08X), userSize:%d(0x%08X), extraBytes:%d(0x%02X)\n", address, totalSize, totalSize, userRequestedSize, userRequestedSize, extraBytes, extraBytes);
}
static void checkMemoryAlignmentPointer(uint16_t heap){
uint32_t memPtrs[100];
uint8_t index;
uint16_t error;
memset(memPtrs, 0x00, sizeof(memPtrs));
//get randomly sized memory regions
for(index = 0; index < 100; index++){
memPtrs[index] = sandboxCallGuestFunction(false, 0x00000000, MemChunkNew, "p(wlw)", heap, getRandomRange(1, 100), 0x0200/*memNewChunkFlagNonMovable*/);
if(!memPtrs[index]){
debugLog("Memory test: Failed to allocate memory\n");
goto failed;
}
}
//check alignment
for(index = 0; index < 100; index++){
if(memPtrs[index] & 0x00000003){
debugLog("Memory test: Memory allocations are not 32 bit aligned:0x%08X\n", memPtrs[index]);
printChunkHeader(memPtrs[index]);
goto failed;
}
}
//non moveable memory wont resize
//shuffle memory
error = sandboxCallGuestFunction(false, 0x00000000, MemHeapCompact, "w(w)", heap);
if(error != 0x0000/*errNone*/){
debugLog("Memory test: Unable to scramble heap:0x%04X\n", error);
goto failed;
}
//check alignment again
for(index = 0; index < 100; index++){
if(memPtrs[index] & 0x00000003){
debugLog("Memory test: Memory misaligned by defragment:0x%08X\n", memPtrs[index]);
printChunkHeader(memPtrs[index]);
goto failed;
}
}
debugLog("Memory test: Memory aligned correctly\n");
failed:
//free pointers
for(index = 0; index < 100; index++)
if(memPtrs[index])
sandboxCallGuestFunction(false, 0x00000000, MemChunkFree, "w(p)", memPtrs[index]);
}
static void checkMemoryAlignmentHandle(uint16_t heap){
uint32_t memHandles[100];
uint32_t memPtrs[100];
uint8_t index;
uint16_t error;
//a handle is just a pointer with bit 31 set, when the pointer is moved a look up table entry is set to the new address and used for future operations
memset(memHandles, 0x00, sizeof(memHandles));
memset(memPtrs, 0x00, sizeof(memPtrs));
//get randomly sized memory regions
for(index = 0; index < 100; index++){
memHandles[index] = sandboxCallGuestFunction(false, 0x00000000, MemChunkNew, "p(wlw)", heap, getRandomRange(1, 100), 0x0000);
if(!memHandles[index]){
debugLog("Memory test: Failed to allocate memory\n");
goto failed;
}
memHandles[index] |= 0x80000000;//tell the OS this is a handle, this is all MemHandleNew does is allocate memory normally and set that bit
}
//update pointer list
for(index = 0; index < 100; index++){
memPtrs[index] = sandboxCallGuestFunction(false, 0x00000000, MemHandleLock, "p(l)", memHandles[index]);
if(!memPtrs[index]){
debugLog("Memory test: Failed to lock handle\n");
goto failed;
}
error = sandboxCallGuestFunction(false, 0x00000000, MemHandleUnlock, "w(l)", memHandles[index]);
if(error != 0x0000/*errNone*/){
debugLog("Memory test: Failed to unlock handle\n");
goto failed;
}
}
//check alignment
for(index = 0; index < 100; index++){
if(memPtrs[index] & 0x00000003){
debugLog("Memory test: Memory allocations are not 32 bit aligned:0x%08X\n", memPtrs[index]);
printChunkHeader(memPtrs[index]);
goto failed;
}
}
//resize memory
for(index = 0; index < 100; index++){
error = sandboxCallGuestFunction(false, 0x00000000, MemHandleResize, "w(ll)", memHandles[index], getRandomRange(1, 100));
if(error != 0x0000/*errNone*/){
debugLog("Memory test: Failed to resize memory:0x%04X\n", error);
goto failed;
}
}
//update pointer list
for(index = 0; index < 100; index++){
memPtrs[index] = sandboxCallGuestFunction(false, 0x00000000, MemHandleLock, "p(l)", memHandles[index]);
if(!memPtrs[index]){
debugLog("Memory test: Failed to lock handle\n");
goto failed;
}
error = sandboxCallGuestFunction(false, 0x00000000, MemHandleUnlock, "w(l)", memHandles[index]);
if(error != 0x0000/*errNone*/){
debugLog("Memory test: Failed to unlock handle\n");
goto failed;
}
}
//check alignment again
for(index = 0; index < 100; index++){
if(memPtrs[index] & 0x00000003){
debugLog("Memory test: Memory misaligned by resize:0x%08X\n", memPtrs[index]);
printChunkHeader(memPtrs[index]);
goto failed;
}
}
//shuffle memory
error = sandboxCallGuestFunction(false, 0x00000000, MemHeapCompact, "w(w)", heap);
if(error != 0x0000/*errNone*/){
debugLog("Memory test: Unable to scramble heap:0x%04X\n", error);
goto failed;
}
//update pointer list
for(index = 0; index < 100; index++){
memPtrs[index] = sandboxCallGuestFunction(false, 0x00000000, MemHandleLock, "p(l)", memHandles[index]);
if(!memPtrs[index]){
debugLog("Memory test: Failed to lock handle\n");
goto failed;
}
error = sandboxCallGuestFunction(false, 0x00000000, MemHandleUnlock, "w(l)", memHandles[index]);
if(error != 0x0000/*errNone*/){
debugLog("Memory test: Failed to unlock handle\n");
goto failed;
}
}
//check alignment again
for(index = 0; index < 100; index++){
if(memPtrs[index] & 0x00000003){
debugLog("Memory test: Memory misaligned by defragment:0x%08X\n", memPtrs[index]);
printChunkHeader(memPtrs[index]);
goto failed;
}
}
debugLog("Memory test: Memory aligned correctly\n");
failed:
//free handles
for(index = 0; index < 100; index++)
if(memHandles[index])
sandboxCallGuestFunction(false, 0x00000000, MemHandleFree, "w(l)", memHandles[index]);
}
static uint32_t sandboxGetStackFrameSize(const char* prototype){
const char* params = prototype + 2;
uint32_t size = 0;
@@ -508,8 +777,107 @@ static uint32_t sandboxCallGuestFunction(bool fallthrough, uint32_t address, uin
void sandboxInit(void){
//nothing to init yet
}
void sandboxReset(void){
sandboxActive = false;
sandboxControlHandoff = false;
sandboxFramesRan = 0;
memset(sandboxWatchRegions, 0x00, sizeof(sandboxWatchRegions));
sandboxWatchRegionsActive = 0;
//patch OS here if needed
sandboxCommand(SANDBOX_CMD_PATCH_OS, NULL);
//log all register accesses
//sandboxCommand(SANDBOX_CMD_REGISTER_WATCH_ENABLE, NULL);
//monitor for strange jumps
//sandboxSetWatchRegion(0x00000000, 0xFFFFFFFE, SANDBOX_WATCH_CODE);
}
uint32_t sandboxStateSize(void){
uint32_t size = 0;
size += sizeof(uint8_t) * 3;//sandboxActive / sandboxControlHandoff / sandboxCurrentCpuArch
size += sizeof(uint32_t) * 4;//sandboxOldFunctionCpuState.(sp/pc/a0/d0)
size += sizeof(uint16_t);//sandboxOldFunctionCpuState.sr
size += sizeof(uint64_t);//sandboxFramesRan
size += sizeof(uint32_t) * 2 * SANDBOX_MAX_WATCH_REGIONS;//sandboxWatchRegions.(address/size)
size += sizeof(uint8_t) * SANDBOX_MAX_WATCH_REGIONS;//sandboxWatchRegions.type
size += sizeof(uint16_t);//sandboxWatchRegionsActive
return size;
}
void sandboxSaveState(uint8_t* data){
uint32_t offset = 0;
uint16_t index;
writeStateValue8(data + offset, sandboxActive);
offset += sizeof(uint8_t);
writeStateValue8(data + offset, sandboxControlHandoff);
offset += sizeof(uint8_t);
writeStateValue8(data + offset, sandboxCurrentCpuArch);//currently cant be ARMv5 during a frame boundry but that may change
offset += sizeof(uint8_t);
writeStateValue32(data + offset, sandboxOldFunctionCpuState.sp);
offset += sizeof(uint32_t);
writeStateValue32(data + offset, sandboxOldFunctionCpuState.pc);
offset += sizeof(uint32_t);
writeStateValue16(data + offset, sandboxOldFunctionCpuState.sr);
offset += sizeof(uint16_t);
writeStateValue32(data + offset, sandboxOldFunctionCpuState.a0);
offset += sizeof(uint32_t);
writeStateValue32(data + offset, sandboxOldFunctionCpuState.d0);
offset += sizeof(uint32_t);
writeStateValue64(data + offset, sandboxFramesRan);
offset += sizeof(uint64_t);
for(index = 0; index < SANDBOX_MAX_WATCH_REGIONS; index++){
writeStateValue32(data + offset, sandboxWatchRegions[index].address);
offset += sizeof(uint32_t);
writeStateValue32(data + offset, sandboxWatchRegions[index].size);
offset += sizeof(uint32_t);
writeStateValue8(data + offset, sandboxWatchRegions[index].type);
offset += sizeof(uint8_t);
}
writeStateValue16(data + offset, sandboxWatchRegionsActive);
offset += sizeof(uint16_t);
}
void sandboxLoadState(uint8_t* data){
uint32_t offset = 0;
uint16_t index;
sandboxActive = readStateValue8(data + offset);
offset += sizeof(uint8_t);
sandboxControlHandoff = readStateValue8(data + offset);
offset += sizeof(uint8_t);
sandboxCurrentCpuArch = readStateValue8(data + offset);//currently cant be ARMv5 during a frame boundry but that may change
offset += sizeof(uint8_t);
sandboxOldFunctionCpuState.sp = readStateValue32(data + offset);
offset += sizeof(uint32_t);
sandboxOldFunctionCpuState.pc = readStateValue32(data + offset);
offset += sizeof(uint32_t);
sandboxOldFunctionCpuState.sr = readStateValue16(data + offset);
offset += sizeof(uint16_t);
sandboxOldFunctionCpuState.a0 = readStateValue32(data + offset);
offset += sizeof(uint32_t);
sandboxOldFunctionCpuState.d0 = readStateValue32(data + offset);
offset += sizeof(uint32_t);
sandboxFramesRan = readStateValue64(data + offset);
offset += sizeof(uint64_t);
for(index = 0; index < SANDBOX_MAX_WATCH_REGIONS; index++){
sandboxWatchRegions[index].address = readStateValue32(data + offset);
offset += sizeof(uint32_t);
sandboxWatchRegions[index].size = readStateValue32(data + offset);
offset += sizeof(uint32_t);
sandboxWatchRegions[index].type = readStateValue8(data + offset);
offset += sizeof(uint8_t);
}
sandboxWatchRegionsActive = readStateValue16(data + offset);
offset += sizeof(uint16_t);
}
uint32_t sandboxCommand(uint32_t command, void* data){
@@ -522,21 +890,7 @@ uint32_t sandboxCommand(uint32_t command, void* data){
debugLog("Sandbox: Command %d started\n", command);
switch(command){
case SANDBOX_PATCH_OS:{
//this will not be in the v1.0 release
//remove parts of the OS that cause lockups, yeah its bad
//remove ErrDisplayFileLineMsg from HwrIRQ2Handler, device locks on USB polling without this
//this is fixed, leaving it here for reference
//patchOsRom(0x83652, "4E714E71");//nop; nop
//make SysSetTrapAddress/SysGetTrapAddress support traps > ScrDefaultPaletteState 0xA459
//up to final OS 5.3 trap DmSyncDatabase 0xA476
//SysSetTrapAddress_1001AE36:
//SysGetTrapAddress_1001AE7C:
//patchOsRom(0x1AE42, "0C410477");//cmpi.w 0x477, d1
//patchOsRom(0x1AE8A, "0C42A477");//cmpi.w 0xA477, d2
case SANDBOX_CMD_PATCH_OS:{
//double dynamic heap size, verified working
//HwrCalcDynamicRAMSize_10005CC6:
//HwrCalcDynamicRAMSize_10083B0A:
@@ -616,16 +970,6 @@ uint32_t sandboxCommand(uint32_t command, void* data){
ROM:10014914 move.w #$1000,(word_28E).w ; Move Data from Source to Destination
*/
//may be able to use these to set the border colors like in OS 5
/*
RAM:00001758 dc.l UIColorInit_10074672
RAM:0000175C dc.l UIColorGetTableEntryIndex_100746F6
RAM:00001760 dc.l UIColorGetTableEntryRGB_1007472A
RAM:00001760 ; DATA XREF: ROM:101D66A1↓o
RAM:00001764 dc.l UIColorSetTableEntry_10074762
RAM:00001768 off_1768: dc.l UIColorPushTable_100747B0
*/
//another road block surfaces
/*
When a Palm Powered handheld is presented with multiple dynamic heaps,
@@ -638,10 +982,87 @@ uint32_t sandboxCommand(uint32_t command, void* data){
IDs be assigned to these heaps. Subsequent storage heaps would be assigned
IDs in sequential order, as always beginning with RAM heaps, followed by ROM heaps.
*/
//PrvChunkNew alignment code
/*
ROM:10020D04 moveq #1,d0 ; Move Quick
ROM:10020D06 and.l size(a6),d0 ; Check if size is a multiple of 2
ROM:10020D0A addq.w #2,sp ; Add Quick
ROM:10020D0C beq.s loc_10020D16 ; Skip adding extra byte if already aligned
ROM:10020D0E moveq #9,d0 ; Size is not 16 bit aligned, align and add 8 bytes
ROM:10020D10 add.l size(a6),d0 ; Add requested size
ROM:10020D14 bra.s loc_10020D1C ; Branch Always
ROM:10020D16 ; ---------------------------------------------------------------------------
ROM:10020D16
ROM:10020D16 loc_10020D16: ; CODE XREF: PrvChunkNew_10020CBC+50↑j
ROM:10020D16 move.l size(a6),d0 ; Set requested size
ROM:10020D1A addq.l #8,d0 ; Add 8 bytes(currently dont know what there for)
ROM:10020D1C
*/
//PrvPtrResize alignment code
/*
ROM:1002123C moveq #1,d0 ; Move Quick
ROM:1002123E and.l arg_4(a6),d0 ; AND Logical
ROM:10021242 addq.w #8,sp ; Add Quick
ROM:10021244 beq.s loc_1002124E ; Branch if Equal
ROM:10021246 moveq #9,d0 ; Move Quick
ROM:10021248 add.l arg_4(a6),d0 ; Add
ROM:1002124C bra.s loc_10021254 ; Branch Always
ROM:1002124E ; ---------------------------------------------------------------------------
ROM:1002124E
ROM:1002124E loc_1002124E: ; CODE XREF: PrvPtrResize_100211F6+4E↑j
ROM:1002124E move.l arg_4(a6),d0 ; Move Data from Source to Destination
ROM:10021252 addq.l #8,d0 ; Add Quick
ROM:10021254
*/
//PrvMoveChunk alignment code???(not sure yet)
/*
ROM:10021C82 sub.l d0,d7 ; Subtract
ROM:10021C84 move.l d7,d5 ; Move Data from Source to Destination
ROM:10021C86 moveq #1,d0 ; Set bitmask
ROM:10021C88 and.l d7,d0 ; Check if bit 0 of d7 is set
ROM:10021C8A beq.s loc_10021C8E ; If bit 0 of d7 is set add 1 to d5
ROM:10021C8C addq.l #1,d5 ; 16 bit align ???
*/
//size extra bits are not being set when chunks are allocated
//PrvChunkNew derives size extra from total size - requested size, so its already safe, PrvPtrResize does the same
/*
ROM:10020FFA setSizeExtra: ; CODE XREF: PrvChunkNew_10020CBC+312↑j
ROM:10020FFA move.l d3,d0 ; Move Data from Source to Destination
ROM:10020FFC sub.l size(a6),d0 ; Subtract
ROM:10021000 subq.l #8,d0 ; Subtract Quick
ROM:10021002 andi.b #$F,d0 ; AND Immediate
ROM:10021006 andi.b #$F0,(a2) ; AND Immediate
ROM:1002100A or.b d0,(a2) ; Inclusive-OR Logical
*/
//current suspect functions are PrvCreateFreeChunk and PrvUseFreeChunk
//also merging chunks may cause some kind of issue
//PrvPtrResize is likely moving the chunk in front forwards if its small enough and leaving the data in place to save the opcodes needed to copy the data elsewhere
//if this is true then a resize of existing size + 2 will push the next chunk forward by 2 misaligning it
//could also be moving the header backwards by 2 if its willing to shift all the data manualy or corrupt the data
//patch PrvChunkNew to 32 bit alignment, this alone does not fix 32 bit alignment issues
patchOsRom(0x20D04, "202E000AC0BCFFFFFFFCB0AE000A6700000458805080544F");//adds an extra 4 bytes if & 0x00000003 is true
//when moving memory around some 16 bit aligned pointers still show up
//patch PrvPtrResize to 32 bit alignment, this alone does not fix 32 bit alignment issues
patchOsRom(0x2123C, "202E000CC0BCFFFFFFFCB0AE000C6700000458805080504F");//adds an extra 4 bytes if & 0x00000003 is true
//may need to patch 0x7FFFFFFE's to 0x7FFFFFFC's
//other functions that may need to be patched are:
//PrvCompactHeap_10021A12
//PrvMoveChunk_10021C3E
}
break;
case SANDBOX_INSTALL_APP:{
case SANDBOX_CMD_DEBUG_INSTALL_APP:{
buffer_t* app = (buffer_t*)data;
bool success = installResourceToDevice(*app);
@@ -649,6 +1070,23 @@ uint32_t sandboxCommand(uint32_t command, void* data){
result = EMU_ERROR_OUT_OF_MEMORY;
}
break;
case SANDBOX_CMD_REGISTER_WATCH_ENABLE:{
sandboxSetWatchRegion(0xFFFFF000, 0xFFF, SANDBOX_WATCH_DATA);//0x1000 will cause an overflow to 0x00000000 making it never trigger
}
break;
case SANDBOX_CMD_TEST_MEMORY_ALIGNMENT:{
checkMemoryAlignmentPointer(0);//RAM heap
checkMemoryAlignmentPointer(1);//storage heap
checkMemoryAlignmentHandle(0);//RAM heap
checkMemoryAlignmentHandle(1);//storage heap
}
break;
default:
break;
}
debugLog("Sandbox: Command %d finished\n", command);
@@ -656,10 +1094,25 @@ uint32_t sandboxCommand(uint32_t command, void* data){
return result;
}
void sandboxOnFrameRun(void){
//run at the end of every frame
sandboxFramesRan++;
if(sandboxFramesRan == SANDBOX_SECONDS_TO_FRAMES(10)){
sandboxCommand(SANDBOX_CMD_TEST_MEMORY_ALIGNMENT, NULL);
}
}
void sandboxOnOpcodeRun(void){
#if defined(EMU_SANDBOX_LOG_APIS)
logApiCalls();
if(sandboxRunning()){
#if defined(EMU_SANDBOX_LOG_JUMPS)
log68kJumps();
#endif
#if defined(EMU_SANDBOX_LOG_APIS)
logApiCalls();
#endif
}
switch(m68k_get_reg(NULL, M68K_REG_PC)){//switched this from PPC to PC
//case 0x10083652://USB issue location //address based on PPC
//case 0x100846C0://HwrDelay, before mysterious jump //address based on PPC
@@ -720,44 +1173,107 @@ void sandboxOnOpcodeRun(void){
}
void sandboxOnMemoryAccess(uint32_t address, uint8_t size, bool write, uint32_t value){
if(sandboxActive){
static bool isRecursive = false;
static bool isRecursive = false;
//this function can read or write Palm memory, which calls this function, so dont run this function when calling from this function to prevent an infinte loop
if(!isRecursive){
isRecursive = true;
//actual code goes below:vvv
//this function can read or write Palm memory, which calls this function, so dont run this function when calling from this function to prevent an infinte loop
if(!isRecursive){
isRecursive = true;
{//actual code goes below:vvv
bool sandboxedMemory = false;
uint16_t memRegion;
if(write && address >= 0x00000122 && address <= 0x00000125){
//writing the trap table pointer, this should only happen once
char* function = getFunctionName(m68k_get_reg(NULL, M68K_REG_PPC));
for(memRegion = 0; memRegion < sandboxWatchRegionsActive; memRegion++){
if(sandboxWatchRegions[memRegion].type == SANDBOX_WATCH_DATA && address >= sandboxWatchRegions[memRegion].address && address < sandboxWatchRegions[memRegion].address + sandboxWatchRegions[memRegion].size){
sandboxedMemory = true;
break;
}
}
if(sandboxedMemory || sandboxRunning()){
uint32_t pc = m68k_get_reg(NULL, M68K_REG_PPC);
char* function = getFunctionName68k(pc);
bool functionValid = !!function;
if(!functionValid)
function = "NAME NOT FOUND";
debugLog("Writing trap table pointer: size:%d, value:0x%08X, address:0x%08X, function:%s\n", size, value, address, function);
if(address >= chips[DBVZ_CHIP_DX_RAM].start && address < chips[DBVZ_CHIP_DX_RAM].start + 0x10000){
//low mem globals
address &= 0xFFFF;
if(write)
debugLog("Writing low mem global: name:%s/global:0x%08X, size:%d, value:0x%08X, function:%s/PC:0x%08X\n", getLowMemGlobalName(address), address, size, value, function, pc);
else
debugLog("Reading low mem global: name:%s/global:0x%08X, size:%d, function:%s/PC:0x%08X\n", getLowMemGlobalName(address), address, size, function, pc);
}
else if(address >= 0xFFFFF000){
//hardware registers
if(address >= 0xFFFFFE00){
//bootloader area
if(write){
if(address >= 0xFFFFFFC0)
debugLog("Writing bootloader area(valid): address:0x%08X, size:%d, function:%s/PC:0x%08X\n", address, size, function, pc);
else
debugLog("Writing bootloader area(invalid): address:0x%08X, size:%d, function:%s/PC:0x%08X\n", address, size, function, pc);
}
else{
debugLog("Reading bootloader area: address:0x%08X, size:%d, function:%s/PC:0x%08X\n", address, size, function, pc);
}
}
else{
//normal regs
const char* registerName = "UNKNOWN";
//TODO: get register name list
if(write)
debugLog("Writing hardware register: name:%s/address:0x%08X, size:%d, value:0x%08X, function:%s/PC:0x%08X\n", registerName, address, size, value, function, pc);
else
debugLog("Reading hardware register: name:%s/address:0x%08X, size:%d, function:%s/PC:0x%08X\n", registerName, address, size, function, pc);
}
}
else if(address >= chips[DBVZ_CHIP_B0_SED].start && address < chips[DBVZ_CHIP_B0_SED].start + chips[DBVZ_CHIP_B0_SED].lineSize){
//SED1376
if(address & SED1376_MR_BIT){
//SED1376 data
if(write)
debugLog("Writing SED1376 buffer: address:0x%08X, size:%d, value:0x%08X, function:%s/PC:0x%08X\n", address, size, value, function, pc);
else
debugLog("Reading SED1376 buffer: address:0x%08X, size:%d, function:%s/PC:0x%08X\n", address, size, function, pc);
}
else{
//SED1376 register, these are 8 bit only
if(write)
debugLog("Writing SED1376 register: address:0x%08X, value:0x%02X, function:%s/PC:0x%08X\n", address, value & 0xFF, function, pc);
else
debugLog("Reading SED1376 register: address:0x%08X, function:%s/PC:0x%08X\n", address, function, pc);
}
}
else{
//everywhere else
if(write)
debugLog("Writing: address:0x%08X, size:%d, value:0x%08X, function:%s/PC:0x%08X\n", address, size, value, function, pc);
else
debugLog("Reading: address:0x%08X, size:%d, function:%s/PC:0x%08X\n", address, size, function, pc);
}
if(functionValid)
free(function);
}
//actual code goes above:^^^
isRecursive = false;
}
}//actual code goes above:^^^
isRecursive = false;
}
}
bool sandboxRunning(void){
uint32_t pc = m68k_get_reg(NULL, M68K_REG_PC);
uint32_t pc = m68k_get_reg(NULL, M68K_REG_PC);
uint16_t memRegion;
//this is used to capture full logs from certain sections of the ROM
/*
if(pc >= 0x100A07DC && pc <= 0x100ADB3C){
//the SD slot driver
return true;
//this is used to capture full logs when running from specific locations
for(memRegion = 0; memRegion < sandboxWatchRegionsActive; memRegion++){
if(sandboxWatchRegions[memRegion].type == SANDBOX_WATCH_CODE && pc >= sandboxWatchRegions[memRegion].address && pc < sandboxWatchRegions[memRegion].address + sandboxWatchRegions[memRegion].size)
return true;
}
*/
return sandboxActive;
}
@@ -772,11 +1288,72 @@ void sandboxReturn(void){
}
}
uint16_t sandboxSetWatchRegion(uint32_t address, uint32_t size, uint8_t type){
uint16_t index;
//invalid type
if(type == SANDBOX_WATCH_NONE || type >= SANDBOX_WATCH_TOTAL_TYPES)
return 0xFFFF;
//cant watch 0 sized memory area
if(size < 1)
return 0xFFFF;
//try to use old watch region if available
for(index = 0; index < sandboxWatchRegionsActive; index++){
if(sandboxWatchRegions[index].type == SANDBOX_WATCH_NONE){
//found reusable region
sandboxWatchRegions[index].address = address;
sandboxWatchRegions[index].size = size;
sandboxWatchRegions[index].type = type;
//return watch region reference, this doesnt change until the region is deleted
return index;
}
}
//check if new region is available
if(sandboxWatchRegionsActive < SANDBOX_MAX_WATCH_REGIONS){
//use new region
sandboxWatchRegions[sandboxWatchRegionsActive].address = address;
sandboxWatchRegions[sandboxWatchRegionsActive].size = size;
sandboxWatchRegions[sandboxWatchRegionsActive].type = type;
sandboxWatchRegionsActive++;
//return watch region reference, this doesnt change until the region is deleted
return sandboxWatchRegionsActive - 1;
}
//no regions left, error
return 0xFFFF;
}
void sandboxClearWatchRegion(uint16_t index){
if(index < sandboxWatchRegionsActive){
if(index == sandboxWatchRegionsActive - 1)
sandboxWatchRegionsActive--;//remove from end
else
sandboxWatchRegions[index].type = SANDBOX_WATCH_NONE;//mark as empty
}
}
void sandboxSetCpuArch(uint8_t arch){
sandboxCurrentCpuArch = arch;
}
#else
void sandboxInit(void){}
void sandboxReset(void){}
uint32_t sandboxStateSize(void){return 0;}
void sandboxSaveState(uint8_t* data){}
void sandboxLoadState(uint8_t* data){}
uint32_t sandboxCommand(uint32_t command, void* data){return 0;}
void sandboxOnFrameRun(void){}
void sandboxOnOpcodeRun(void){}
void sandboxOnMemoryAccess(uint32_t address, uint8_t size, bool write, uint32_t value){}
bool sandboxRunning(void){return false;}
void sandboxReturn(void){}
uint16_t sandboxSetWatchRegion(uint32_t address, uint32_t size, uint8_t type){return 0;}
void sandboxClearWatchRegion(uint16_t index){}
void sandboxSetCpuArch(uint8_t arch){}
#endif

View File

@@ -5,15 +5,38 @@
#include <stdbool.h>
enum{
SANDBOX_PATCH_OS = 0,
SANDBOX_INSTALL_APP
SANDBOX_CMD_PATCH_OS = 0,
SANDBOX_CMD_DEBUG_INSTALL_APP,
SANDBOX_CMD_REGISTER_WATCH_ENABLE,
SANDBOX_CMD_TEST_MEMORY_ALIGNMENT
};
enum{
SANDBOX_WATCH_NONE = 0,
SANDBOX_WATCH_CODE,
SANDBOX_WATCH_DATA,
SANDBOX_WATCH_TOTAL_TYPES
};
enum{
SANDBOX_CPU_ARCH_M68K = 0,
SANDBOX_CPU_ARCH_ARMV5,
SANDBOX_CPU_ARCH_THUMB
};
void sandboxInit(void);
void sandboxReset(void);
uint32_t sandboxStateSize(void);
void sandboxSaveState(uint8_t* data);
void sandboxLoadState(uint8_t* data);
uint32_t sandboxCommand(uint32_t command, void* data);
void sandboxOnFrameRun(void);
void sandboxOnOpcodeRun(void);
void sandboxOnMemoryAccess(uint32_t address, uint8_t size, bool write, uint32_t value);
bool sandboxRunning(void);
void sandboxReturn(void);//should only be called called by 68k code
uint16_t sandboxSetWatchRegion(uint32_t address, uint32_t size, uint8_t type);
void sandboxClearWatchRegion(uint16_t index);
void sandboxSetCpuArch(uint8_t arch);
#endif

View File

@@ -6,9 +6,9 @@
#include "audio/blip_buf.h"
#include "flx68000.h"
#include "emulator.h"
#include "hardwareRegisters.h"
#include "dbvzRegisters.h"
#include "expansionHardware.h"
#include "memoryAccess.h"
#include "m515Bus.h"
#include "sed1376.h"
#include "ads7846.h"
#include "pdiUsbD12.h"
@@ -32,6 +32,9 @@
static bool emulatorInitialized = false;
#if defined(EMU_SUPPORT_PALM_OS5)
static bool emulatorEmulatingTungstenC;
#endif
uint8_t* palmRam;
uint8_t* palmRom;
@@ -53,64 +56,85 @@ double palmClk32Sysclks;//how many SYSCLKs have happened in the current CLK32
uint32_t emulatorInit(buffer_t palmRomDump, buffer_t palmBootDump, uint32_t enabledEmuFeatures){
//only accept valid non debug features from the user
enabledEmuFeatures &= FEATURE_FAST_CPU | FEATURE_SYNCED_RTC | FEATURE_HLE_APIS | FEATURE_DURABLE;
#if defined(EMU_DEBUG)
//enable debug features if compiled in debug mode
enabledEmuFeatures |= FEATURE_DEBUG;
#endif
if(emulatorInitialized)
return EMU_ERROR_RESOURCE_LOCKED;
if(!palmRomDump.data)
return EMU_ERROR_INVALID_PARAMETER;
//allocate buffers, add 4 to memory regions to prevent SIGSEGV from accessing off the end
palmRam = malloc(((enabledEmuFeatures & FEATURE_RAM_HUGE) ? SUPERMASSIVE_RAM_SIZE : RAM_SIZE) + 4);
palmRom = malloc(ROM_SIZE + 4);
palmReg = malloc(REG_SIZE + 4);
palmFramebuffer = malloc(480 * 480 * sizeof(uint16_t));
palmAudio = malloc(AUDIO_SAMPLES_PER_FRAME * 2 * sizeof(int16_t));
palmAudioResampler = blip_new(AUDIO_SAMPLE_RATE);//have 1 second of samples
if(!palmRam || !palmRom || !palmReg || !palmFramebuffer || !palmAudio || !palmAudioResampler){
free(palmRam);
free(palmRom);
free(palmReg);
free(palmFramebuffer);
free(palmAudio);
blip_delete(palmAudioResampler);
return EMU_ERROR_OUT_OF_MEMORY;
}
#if defined(EMU_SUPPORT_PALM_OS5)
//TODO: need to check for ROMs device type here
emulatorEmulatingTungstenC = false;
//set default values
memset(palmRam, 0x00, enabledEmuFeatures & FEATURE_RAM_HUGE ? SUPERMASSIVE_RAM_SIZE : RAM_SIZE);
memcpy(palmRom, palmRomDump.data, u64Min(palmRomDump.size, ROM_SIZE));
if(palmRomDump.size < ROM_SIZE)
memset(palmRom + palmRomDump.size, 0x00, ROM_SIZE - palmRomDump.size);
swap16BufferIfLittle(palmRom, ROM_SIZE / sizeof(uint16_t));
if(palmBootDump.data){
memcpy(palmReg + REG_SIZE - 1 - BOOTLOADER_SIZE, palmBootDump.data, u64Min(palmBootDump.size, BOOTLOADER_SIZE));
if(palmBootDump.size < BOOTLOADER_SIZE)
memset(palmReg + REG_SIZE - 1 - BOOTLOADER_SIZE + palmBootDump.size, 0x00, BOOTLOADER_SIZE - palmBootDump.size);
swap16BufferIfLittle(palmReg + REG_SIZE - 1 - BOOTLOADER_SIZE, BOOTLOADER_SIZE / sizeof(uint16_t));
if(emulatorEmulatingTungstenC){
//emulating Tungsten C
//TODO!
}
else{
memset(palmReg + REG_SIZE - 1 - BOOTLOADER_SIZE, 0x00, BOOTLOADER_SIZE);
#endif
//emulating Palm m515
//allocate buffers, add 4 to memory regions to prevent SIGSEGV from accessing off the end
palmRam = malloc(M515_RAM_SIZE + 4);
palmRom = malloc(M515_ROM_SIZE + 4);
palmReg = malloc(DBVZ_REG_SIZE + 4);
palmFramebuffer = malloc(160 * 220 * sizeof(uint16_t));
palmAudio = malloc(AUDIO_SAMPLES_PER_FRAME * 2 * sizeof(int16_t));
palmAudioResampler = blip_new(AUDIO_SAMPLE_RATE);//have 1 second of samples
if(!palmRam || !palmRom || !palmReg || !palmFramebuffer || !palmAudio || !palmAudioResampler){
free(palmRam);
free(palmRom);
free(palmReg);
free(palmFramebuffer);
free(palmAudio);
blip_delete(palmAudioResampler);
return EMU_ERROR_OUT_OF_MEMORY;
}
//set default values
memset(palmRam, 0x00, M515_RAM_SIZE);
memcpy(palmRom, palmRomDump.data, u32Min(palmRomDump.size, M515_ROM_SIZE));
if(palmRomDump.size < M515_ROM_SIZE)
memset(palmRom + palmRomDump.size, 0x00, M515_ROM_SIZE - palmRomDump.size);
swap16BufferIfLittle(palmRom, M515_ROM_SIZE / sizeof(uint16_t));
if(palmBootDump.data){
memcpy(palmReg + DBVZ_REG_SIZE - 1 - DBVZ_BOOTLOADER_SIZE, palmBootDump.data, u32Min(palmBootDump.size, DBVZ_BOOTLOADER_SIZE));
if(palmBootDump.size < DBVZ_BOOTLOADER_SIZE)
memset(palmReg + DBVZ_REG_SIZE - 1 - DBVZ_BOOTLOADER_SIZE + palmBootDump.size, 0x00, DBVZ_BOOTLOADER_SIZE - palmBootDump.size);
swap16BufferIfLittle(palmReg + DBVZ_REG_SIZE - 1 - DBVZ_BOOTLOADER_SIZE, DBVZ_BOOTLOADER_SIZE / sizeof(uint16_t));
}
else{
memset(palmReg + DBVZ_REG_SIZE - 1 - DBVZ_BOOTLOADER_SIZE, 0x00, DBVZ_BOOTLOADER_SIZE);
}
memset(palmAudio, 0x00, AUDIO_SAMPLES_PER_FRAME * 2/*channels*/ * sizeof(int16_t));
memset(&palmInput, 0x00, sizeof(palmInput));
memset(&palmMisc, 0x00, sizeof(palmMisc));
memset(&palmSdCard, 0x00, sizeof(palmSdCard));
memset(&palmEmuFeatures, 0x00, sizeof(palmEmuFeatures));
palmFramebufferWidth = 160;
palmFramebufferHeight = 220;
palmMisc.batteryLevel = 100;
palmCycleCounter = 0.0;
palmEmuFeatures.info = enabledEmuFeatures;
//initialize components
blip_set_rates(palmAudioResampler, AUDIO_CLOCK_RATE, AUDIO_SAMPLE_RATE);
flx68000Init();
sandboxInit();
//reset everything
emulatorSoftReset();
dbvzSetRtc(0, 0, 0, 0);//RTCTIME and DAYR are not cleared by reset, clear them manually in case the frontend doesnt set the RTC
#if defined(EMU_SUPPORT_PALM_OS5)
}
memset(palmAudio, 0x00, AUDIO_SAMPLES_PER_FRAME * 2/*channels*/ * sizeof(int16_t));
memset(&palmInput, 0x00, sizeof(palmInput));
memset(&palmMisc, 0x00, sizeof(palmMisc));
memset(&palmSdCard, 0x00, sizeof(palmSdCard));
memset(&palmEmuFeatures, 0x00, sizeof(palmEmuFeatures));
palmMisc.batteryLevel = 100;
palmCycleCounter = 0.0;
palmEmuFeatures.info = enabledEmuFeatures;
//initialize components
blip_set_rates(palmAudioResampler, AUDIO_CLOCK_RATE, AUDIO_SAMPLE_RATE);
flx68000Init();
sandboxInit();
//reset everything
emulatorSoftReset();
setRtc(0, 0, 0, 0);//RTCTIME and DAYR are not cleared by reset, clear them manually in case the frontend doesnt set the RTC
//debug patches
sandboxCommand(SANDBOX_PATCH_OS, NULL);
#endif
emulatorInitialized = true;
@@ -132,16 +156,14 @@ void emulatorExit(void){
void emulatorHardReset(void){
//equivalent to taking the battery out and putting it back in
memset(palmRam, 0x00, palmEmuFeatures.info & FEATURE_RAM_HUGE ? SUPERMASSIVE_RAM_SIZE : RAM_SIZE);
memset(palmRam, 0x00, M515_RAM_SIZE);
emulatorSoftReset();
sdCardReset();
setRtc(0, 0, 0, 0);
dbvzSetRtc(0, 0, 0, 0);
}
void emulatorSoftReset(void){
//equivalent to pushing the reset button on the back of the device
palmFramebufferWidth = 160;
palmFramebufferHeight = 220;
palmEmuFeatures.value = 0x00000000;
palmClockMultiplier = 1.00 - EMU_CPU_PERCENT_WAITING;
sed1376Reset();
@@ -149,11 +171,12 @@ void emulatorSoftReset(void){
pdiUsbD12Reset();
expansionHardwareReset();
flx68000Reset();
sandboxReset();
//sdCardReset() should not be called here, the SD card does not have a reset line and should only be reset by a power cycle
}
void emulatorSetRtc(uint16_t days, uint8_t hours, uint8_t minutes, uint8_t seconds){
setRtc(days, hours, minutes, seconds);
dbvzSetRtc(days, hours, minutes, seconds);
}
uint32_t emulatorGetStateSize(void){
@@ -168,14 +191,12 @@ uint32_t emulatorGetStateSize(void){
size += ads7846StateSize();
size += pdiUsbD12StateSize();
size += expansionHardwareStateSize();
if(palmEmuFeatures.info & FEATURE_RAM_HUGE)
size += SUPERMASSIVE_RAM_SIZE;//system RAM buffer
else
size += RAM_SIZE;//system RAM buffer
size += REG_SIZE;//hardware registers
size += TOTAL_MEMORY_BANKS;//bank handlers
size += sizeof(uint32_t) * 4 * CHIP_END;//chip select states
size += sizeof(uint8_t) * 5 * CHIP_END;//chip select states
size += sandboxStateSize();
size += M515_RAM_SIZE;//system RAM buffer
size += DBVZ_REG_SIZE;//hardware registers
size += DBVZ_TOTAL_MEMORY_BANKS;//bank handlers
size += sizeof(uint32_t) * 4 * DBVZ_CHIP_END;//chip select states
size += sizeof(uint8_t) * 5 * DBVZ_CHIP_END;//chip select states
size += sizeof(uint64_t) * 5;//32.32 fixed point double, timerXCycleCounter and CPU cycle timers
size += sizeof(int8_t);//pllSleepWait
size += sizeof(int8_t);//pllWakeWait
@@ -190,10 +211,10 @@ uint32_t emulatorGetStateSize(void){
size += sizeof(uint8_t) * 6;//pwm1Fifo[6]
size += sizeof(uint8_t) * 2;//pwm1(Read/Write)
size += sizeof(uint8_t) * 7;//palmMisc
size += sizeof(uint32_t) * 4;//palmEmuFeatures.src / palmEmuFeatures.dst / palmEmuFeatures.size / palmEmuFeatures.value
size += sizeof(uint32_t) * 4;//palmEmuFeatures.(src/dst/size/value)
size += sizeof(uint64_t);//palmSdCard.command
size += sizeof(uint8_t) * 8;//palmSdCard.commandBitsRemaining / palmSdCard.runningCommand / palmSdCard.commandIsAcmd /palmSdCard.allowInvalidCrc / palmSdCard.chipSelect / palmSdCard.receivingCommand / palmSdCard.inIdleState / palmSdCard.writeProtectSwitch
size += sizeof(uint16_t) * 2;//palmSdCard.responseReadPosition / palmSdCard.responseWritePosition
size += sizeof(uint8_t) * 8;//palmSdCard.(commandBitsRemaining/runningCommand/commandIsAcmd/allowInvalidCrc/chipSelect/receivingCommand/inIdleState/writeProtectSwitch)
size += sizeof(uint16_t) * 2;//palmSdCard.response(Read/Write)Position
size += sizeof(int8_t);//palmSdCard.responseReadPositionBit
size += sizeof(uint32_t) * 3;//palmSdCard.runningCommandVars
size += SD_CARD_BLOCK_DATA_PACKET_SIZE;//palmSdCard.runningCommandPacket
@@ -240,23 +261,20 @@ bool emulatorSaveState(buffer_t buffer){
expansionHardwareSaveState(buffer.data + offset);
offset += expansionHardwareStateSize();
//sandbox, does nothing when disabled
sandboxSaveState(buffer.data + offset);
offset += sandboxStateSize();
//memory
if(palmEmuFeatures.info & FEATURE_RAM_HUGE){
memcpy(buffer.data + offset, palmRam, SUPERMASSIVE_RAM_SIZE);
swap16BufferIfLittle(buffer.data + offset, SUPERMASSIVE_RAM_SIZE / sizeof(uint16_t));
offset += SUPERMASSIVE_RAM_SIZE;
}
else{
memcpy(buffer.data + offset, palmRam, RAM_SIZE);
swap16BufferIfLittle(buffer.data + offset, RAM_SIZE / sizeof(uint16_t));
offset += RAM_SIZE;
}
memcpy(buffer.data + offset, palmReg, REG_SIZE);
swap16BufferIfLittle(buffer.data + offset, REG_SIZE / sizeof(uint16_t));
offset += REG_SIZE;
memcpy(buffer.data + offset, bankType, TOTAL_MEMORY_BANKS);
offset += TOTAL_MEMORY_BANKS;
for(index = CHIP_BEGIN; index < CHIP_END; index++){
memcpy(buffer.data + offset, palmRam, M515_RAM_SIZE);
swap16BufferIfLittle(buffer.data + offset, M515_RAM_SIZE / sizeof(uint16_t));
offset += M515_RAM_SIZE;
memcpy(buffer.data + offset, palmReg, DBVZ_REG_SIZE);
swap16BufferIfLittle(buffer.data + offset, DBVZ_REG_SIZE / sizeof(uint16_t));
offset += DBVZ_REG_SIZE;
memcpy(buffer.data + offset, dbvzBankType, DBVZ_TOTAL_MEMORY_BANKS);
offset += DBVZ_TOTAL_MEMORY_BANKS;
for(index = DBVZ_CHIP_BEGIN; index < DBVZ_CHIP_END; index++){
writeStateValue8(buffer.data + offset, chips[index].enable);
offset += sizeof(uint8_t);
writeStateValue32(buffer.data + offset, chips[index].start);
@@ -441,23 +459,20 @@ bool emulatorLoadState(buffer_t buffer){
expansionHardwareLoadState(buffer.data + offset);
offset += expansionHardwareStateSize();
//sandbox, does nothing when disabled
sandboxLoadState(buffer.data + offset);
offset += sandboxStateSize();
//memory
if(palmEmuFeatures.info & FEATURE_RAM_HUGE){
memcpy(palmRam, buffer.data + offset, SUPERMASSIVE_RAM_SIZE);
swap16BufferIfLittle(palmRam, SUPERMASSIVE_RAM_SIZE / sizeof(uint16_t));
offset += SUPERMASSIVE_RAM_SIZE;
}
else{
memcpy(palmRam, buffer.data + offset, RAM_SIZE);
swap16BufferIfLittle(palmRam, RAM_SIZE / sizeof(uint16_t));
offset += RAM_SIZE;
}
memcpy(palmReg, buffer.data + offset, REG_SIZE);
swap16BufferIfLittle(palmReg, REG_SIZE / sizeof(uint16_t));
offset += REG_SIZE;
memcpy(bankType, buffer.data + offset, TOTAL_MEMORY_BANKS);
offset += TOTAL_MEMORY_BANKS;
for(index = CHIP_BEGIN; index < CHIP_END; index++){
memcpy(palmRam, buffer.data + offset, M515_RAM_SIZE);
swap16BufferIfLittle(palmRam, M515_RAM_SIZE / sizeof(uint16_t));
offset += M515_RAM_SIZE;
memcpy(palmReg, buffer.data + offset, DBVZ_REG_SIZE);
swap16BufferIfLittle(palmReg, DBVZ_REG_SIZE / sizeof(uint16_t));
offset += DBVZ_REG_SIZE;
memcpy(dbvzBankType, buffer.data + offset, DBVZ_TOTAL_MEMORY_BANKS);
offset += DBVZ_TOTAL_MEMORY_BANKS;
for(index = DBVZ_CHIP_BEGIN; index < DBVZ_CHIP_END; index++){
chips[index].enable = readStateValue8(buffer.data + offset);
offset += sizeof(uint8_t);
chips[index].start = readStateValue32(buffer.data + offset);
@@ -609,29 +624,25 @@ bool emulatorLoadState(buffer_t buffer){
}
uint32_t emulatorGetRamSize(void){
return palmEmuFeatures.info & FEATURE_RAM_HUGE ? SUPERMASSIVE_RAM_SIZE : RAM_SIZE;
return M515_RAM_SIZE;
}
bool emulatorSaveRam(buffer_t buffer){
uint32_t size = palmEmuFeatures.info & FEATURE_RAM_HUGE ? SUPERMASSIVE_RAM_SIZE : RAM_SIZE;
if(buffer.size < size)
if(buffer.size < M515_RAM_SIZE)
return false;
memcpy(buffer.data, palmRam, size);
swap16BufferIfLittle(buffer.data, size / sizeof(uint16_t));
memcpy(buffer.data, palmRam, M515_RAM_SIZE);
swap16BufferIfLittle(buffer.data, M515_RAM_SIZE / sizeof(uint16_t));
return true;
}
bool emulatorLoadRam(buffer_t buffer){
uint32_t size = palmEmuFeatures.info & FEATURE_RAM_HUGE ? SUPERMASSIVE_RAM_SIZE : RAM_SIZE;
if(buffer.size < size)
if(buffer.size < M515_RAM_SIZE)
return false;
memcpy(palmRam, buffer.data, size);
swap16BufferIfLittle(palmRam, size / sizeof(uint16_t));
memcpy(palmRam, buffer.data, M515_RAM_SIZE);
swap16BufferIfLittle(palmRam, M515_RAM_SIZE / sizeof(uint16_t));
return true;
}
@@ -683,8 +694,10 @@ void emulatorEjectSdCard(void){
}
void emulatorRunFrame(void){
uint32_t samples;
//I/O
refreshInputState();
m515RefreshInputState();
//CPU
palmFrameClk32s = 0;
@@ -695,27 +708,17 @@ void emulatorRunFrame(void){
palmCycleCounter -= (double)CRYSTAL_FREQUENCY / EMU_FPS;
//audio
if(palmEmuFeatures.info & FEATURE_SND_STRMS){
expansionHardwareRenderAudio();
}
else{
//direct PWM1 output
uint32_t samples;
blip_end_frame(palmAudioResampler, blip_clocks_needed(palmAudioResampler, AUDIO_SAMPLES_PER_FRAME));
blip_read_samples(palmAudioResampler, palmAudio, AUDIO_SAMPLES_PER_FRAME, true);
MULTITHREAD_LOOP(samples) for(samples = 0; samples < AUDIO_SAMPLES_PER_FRAME * 2; samples += 2)
palmAudio[samples + 1] = palmAudio[samples];
}
blip_end_frame(palmAudioResampler, blip_clocks_needed(palmAudioResampler, AUDIO_SAMPLES_PER_FRAME));
blip_read_samples(palmAudioResampler, palmAudio, AUDIO_SAMPLES_PER_FRAME, true);
MULTITHREAD_LOOP(samples) for(samples = 0; samples < AUDIO_SAMPLES_PER_FRAME * 2; samples += 2)
palmAudio[samples + 1] = palmAudio[samples];
//video
if(palmEmuFeatures.info & FEATURE_CUSTOM_FB){
expansionHardwareRenderDisplay();
}
else{
//direct SED1376 output
sed1376Render();
memcpy(palmFramebuffer, sed1376Framebuffer, 160 * 160 * sizeof(uint16_t));
memcpy(palmFramebuffer + 160 * 160, silkscreen160x60, 160 * 60 * sizeof(uint16_t));
}
sed1376Render();
memcpy(palmFramebuffer, sed1376Framebuffer, 160 * 160 * sizeof(uint16_t));
memcpy(palmFramebuffer + 160 * 160, silkscreen160x60, 160 * 60 * sizeof(uint16_t));
#if defined(EMU_SANDBOX)
sandboxOnFrameRun();
#endif
}

View File

@@ -12,16 +12,19 @@ extern "C" {
#include <stdio.h>
#include "audio/blip_buf.h"
#include "memoryAccess.h"//for size macros
#include "m515Bus.h"//for size macros
#include "specs/emuFeatureRegisterSpec.h"//for feature names
//DEFINE INFO!!!
//define EMU_SUPPORT_PALM_OS5 to compile in Tungsten C support(not reccomended for low power devices)
//define EMU_MULTITHREADED to speed up long loops
//define EMU_NO_SAFETY to remove all safety checks
//define EMU_BIG_ENDIAN on big endian systems
//to enable degguging define EMU_DEBUG, all options below do nothing unless EMU_DEBUG is defined
//to enable sandbox debugging define EMU_SANDBOX
//to enable memory access logging define EMU_SANDBOX_LOG_MEMORY_ACCESSES
//to enable opcode level debugging define EMU_SANDBOX_OPCODE_LEVEL_DEBUG
//to enable flow control logging define EMU_SANDBOX_LOG_JUMPS, EMU_SANDBOX_OPCODE_LEVEL_DEBUG must also be defined for this to work
//to log all API calls define EMU_SANDBOX_LOG_APIS, EMU_SANDBOX_OPCODE_LEVEL_DEBUG must also be defined for this to work
//debug
@@ -87,9 +90,6 @@ typedef struct{
typedef struct{
bool buttonUp;
bool buttonDown;
bool buttonLeft;//only used in hybrid mode
bool buttonRight;//only used in hybrid mode
bool buttonCenter;//only used in hybrid mode
bool buttonCalendar;//hw button 1
bool buttonAddress;//hw button 2

View File

@@ -5,96 +5,32 @@
#include "emulator.h"
#include "portability.h"
#include "specs/emuFeatureRegisterSpec.h"
#include "memoryAccess.h"
#include "hardwareRegisters.h"
#include "m515Bus.h"
#include "dbvzRegisters.h"
#include "silkscreen.h"
#include "sed1376.h"
#include "flx68000.h"
#include "armv5.h"
#include "debug/sandbox.h"
static uint32_t expansionHardwareLcdPointer;
static bool expansionHardwareBufferInRam(uint32_t address, uint32_t size){
if(address >= chips[CHIP_DX_RAM].start && address < chips[CHIP_DX_RAM].start + chips[CHIP_DX_RAM].lineSize)
if(address + size >= chips[CHIP_DX_RAM].start && address + size < chips[CHIP_DX_RAM].start + chips[CHIP_DX_RAM].lineSize)
return true;
return false;
}
void expansionHardwareReset(void){
expansionHardwareLcdPointer = 0x00000000;
if(palmEmuFeatures.info & FEATURE_HYBRID_CPU)
armv5Reset();
}
uint32_t expansionHardwareStateSize(void){
uint32_t size = 0;
size += sizeof(uint32_t);
if(palmEmuFeatures.info & FEATURE_HYBRID_CPU)
size += armv5StateSize();
return size;
}
void expansionHardwareSaveState(uint8_t* data){
uint32_t offset = 0;
writeStateValue32(data + offset, expansionHardwareLcdPointer);
offset += sizeof(uint32_t);
if(palmEmuFeatures.info & FEATURE_HYBRID_CPU){
armv5SaveState(data + offset);
offset += armv5StateSize();
}
}
void expansionHardwareLoadState(uint8_t* data){
uint32_t offset = 0;
expansionHardwareLcdPointer = readStateValue32(data + offset);
offset += sizeof(uint32_t);
if(palmEmuFeatures.info & FEATURE_HYBRID_CPU){
armv5LoadState(data + offset);
offset += armv5StateSize();
}
}
void expansionHardwareRenderAudio(void){
/*audio streams will allow the max amount of Palm OS 5 audio streams + 1 for PWM1, each stream will act like an OS 5 audio stream and PWM1 will be the last stream*/
uint32_t samples;
blip_end_frame(palmAudioResampler, blip_clocks_needed(palmAudioResampler, AUDIO_SAMPLES_PER_FRAME));
blip_read_samples(palmAudioResampler, palmAudio, AUDIO_SAMPLES_PER_FRAME, true);
MULTITHREAD_LOOP(samples) for(samples = 0; samples < AUDIO_SAMPLES_PER_FRAME * 2; samples += 2)
palmAudio[samples + 1] = palmAudio[samples];
//DRIVER NEEDS TO BE WRITTEN STILL
}
void expansionHardwareRenderDisplay(void){
if(palmFramebufferWidth == 160 && palmFramebufferHeight == 220){
//simple render
sed1376Render();
memcpy(palmFramebuffer, sed1376Framebuffer, 160 * 160 * sizeof(uint16_t));
memcpy(palmFramebuffer + 160 * 160, silkscreen160x60, 160 * 60 * sizeof(uint16_t));
}
else{
//advanced render
uint16_t* lcdData = palmRam + expansionHardwareLcdPointer;
//copy over framebuffer
memcpy(palmFramebuffer, lcdData, palmFramebufferWidth * palmFramebufferHeight * sizeof(uint16_t));
//add silkscreen if needed
if(palmFramebufferWidth == 320 && palmFramebufferHeight == 440)
memcpy(palmFramebuffer + 320 * 320, silkscreen320x120, 320 * 120 * sizeof(uint16_t));
}
}
uint32_t expansionHardwareGetRegister(uint32_t address){
@@ -138,44 +74,6 @@ void expansionHardwareSetRegister(uint32_t address, uint32_t value){
palmClockMultiplier = (double)palmEmuFeatures.value / 100.0 * (1.00 - EMU_CPU_PERCENT_WAITING);
return;
case CMD_ARM_SERVICE:
if(palmEmuFeatures.info & FEATURE_HYBRID_CPU)
palmEmuFeatures.value = armv5ServiceRequest;
return;
case CMD_ARM_SET_REG:
if(palmEmuFeatures.info & FEATURE_HYBRID_CPU)
armv5SetRegister(palmEmuFeatures.dst, palmEmuFeatures.value);
return;
case CMD_ARM_GET_REG:
if(palmEmuFeatures.info & FEATURE_HYBRID_CPU)
palmEmuFeatures.value = armv5GetRegister(palmEmuFeatures.src);
return;
case CMD_ARM_RUN:
if(palmEmuFeatures.info & FEATURE_HYBRID_CPU)
palmEmuFeatures.value = armv5Execute(palmEmuFeatures.value);
return;
case CMD_LCD_SET_FB:
if(palmEmuFeatures.info & FEATURE_CUSTOM_FB){
uint16_t width = palmEmuFeatures.value >> 16;
uint16_t height = palmEmuFeatures.value & 0xFFFF;
uint32_t size = width * height * sizeof(uint16_t);
if(expansionHardwareBufferInRam(palmEmuFeatures.src, size) && width > 0 && height > 0 && width <= 480 && height <= 480){
expansionHardwareLcdPointer = palmEmuFeatures.src;
palmFramebufferWidth = width;
palmFramebufferHeight = height;
debugLog("Set LCD to:%dx%d, buffer:0x%08X\n", palmFramebufferWidth, palmFramebufferHeight, expansionHardwareLcdPointer);
}
else{
debugLog("Invalid LCD set command: dimensions:%dx%d, address:0x%08X, size:0x%08X\n", width, height, palmEmuFeatures.src, size);
}
}
return;
case CMD_DEBUG_PRINT:
if(palmEmuFeatures.info & FEATURE_DEBUG){
char tempString[200];
@@ -196,9 +94,13 @@ void expansionHardwareSetRegister(uint32_t address, uint32_t value){
}
return;
case CMD_GET_KEYS:
if(palmEmuFeatures.info & FEATURE_EXT_KEYS)
palmEmuFeatures.value = (palmInput.buttonLeft ? EXT_BUTTON_LEFT : 0) | (palmInput.buttonRight ? EXT_BUTTON_RIGHT : 0) | (palmInput.buttonCenter ? EXT_BUTTON_CENTER : 0);
case CMD_DEBUG_WATCH:
if(palmEmuFeatures.info & FEATURE_DEBUG){
if(palmEmuFeatures.value == SANDBOX_WATCH_NONE)
sandboxClearWatchRegion(palmEmuFeatures.src);
else
palmEmuFeatures.value = sandboxSetWatchRegion(palmEmuFeatures.src, palmEmuFeatures.size, palmEmuFeatures.value);
}
return;
case CMD_DEBUG_EXEC_END:

View File

@@ -3,8 +3,8 @@
#include "emulator.h"
#include "portability.h"
#include "hardwareRegisters.h"
#include "memoryAccess.h"
#include "dbvzRegisters.h"
#include "m515Bus.h"
#include "m68k/m68kcpu.h"
@@ -18,31 +18,31 @@ void flx68000PcLongJump(uint32_t newPc){
uint32_t dataBufferGuest;
uint32_t windowSize;
switch(bankType[START_BANK(newPc)]){
case CHIP_A0_ROM:
switch(dbvzBankType[DBVZ_START_BANK(newPc)]){
case DBVZ_CHIP_A0_ROM:
dataBufferHost = (uintptr_t)palmRom;
dataBufferGuest = chips[CHIP_A0_ROM].start;
windowSize = chips[CHIP_A0_ROM].mask + 1;
dataBufferGuest = chips[DBVZ_CHIP_A0_ROM].start;
windowSize = chips[DBVZ_CHIP_A0_ROM].mask + 1;
break;
case CHIP_DX_RAM:
case DBVZ_CHIP_DX_RAM:
dataBufferHost = (uintptr_t)palmRam;
dataBufferGuest = chips[CHIP_DX_RAM].start;
windowSize = chips[CHIP_DX_RAM].mask + 1;
dataBufferGuest = chips[DBVZ_CHIP_DX_RAM].start;
windowSize = chips[DBVZ_CHIP_DX_RAM].mask + 1;
break;
case CHIP_REGISTERS:
case DBVZ_CHIP_REGISTERS:
//needed for when EMU_NO_SAFETY is set and a function is run in the sandbox
dataBufferHost = (uintptr_t)palmReg;
dataBufferGuest = BANK_ADDRESS(START_BANK(newPc));
windowSize = REG_SIZE;
dataBufferGuest = DBVZ_BANK_ADDRESS(DBVZ_START_BANK(newPc));
windowSize = DBVZ_REG_SIZE;
break;
}
memBase = dataBufferHost - dataBufferGuest - windowSize * ((newPc - dataBufferGuest) / windowSize);
}
//everything must be 16 bit aligned(accept 8 bit accesses) due to m68k unaligned access rules,
//everything must be 16 bit aligned(accept 8 bit accesses) due to 68k unaligned access rules,
//32 bit reads are 2 16 bit reads because on some platforms 32 bit reads that arnt on 32 bit boundrys will crash the program
#if defined(EMU_BIG_ENDIAN)
uint16_t m68k_read_immediate_16(uint32_t address){
@@ -93,8 +93,8 @@ void flx68000Init(void){
}
void flx68000Reset(void){
resetHwRegisters();
resetAddressSpace();//address space must be reset after hardware registers because it is dependent on them
dbvzResetRegisters();
dbvzResetAddressSpace();//address space must be reset after hardware registers because it is dependent on them
m68k_pulse_reset();
}
@@ -252,7 +252,7 @@ void flx68000LoadStateFinished(void){
void flx68000Execute(void){
double cyclesRemaining = palmSysclksPerClk32;
beginClk32();
dbvzBeginClk32();
while(cyclesRemaining >= 1.0){
double sysclks = dMin(cyclesRemaining, EMU_SYSCLK_PRECISION);
@@ -260,12 +260,12 @@ void flx68000Execute(void){
if(cpuCycles > 0)
m68k_execute(cpuCycles);
addSysclks(sysclks);
dbvzAddSysclks(sysclks);
cyclesRemaining -= sysclks;
}
endClk32();
dbvzEndClk32();
}
void flx68000SetIrq(uint8_t irqLevel){
@@ -278,8 +278,10 @@ bool flx68000IsSupervisor(void){
void flx68000BusError(uint32_t address, bool isWrite){
#if !defined(EMU_NO_SAFETY)
//never call outsize of a 68k opcode, behavior is undefined due to longjmp
m68ki_trigger_bus_error(address, isWrite ? MODE_WRITE : MODE_READ, FLAG_S | m68ki_get_address_space());
if(!(palmEmuFeatures.info & FEATURE_DURABLE)){
//never call outsize of a 68k opcode, behavior is undefined due to longjmp
m68ki_trigger_bus_error(address, isWrite ? MODE_WRITE : MODE_READ, FLAG_S | m68ki_get_address_space());
}
#endif
}
@@ -295,7 +297,7 @@ uint64_t flx68000ReadArbitraryMemory(uint32_t address, uint8_t size){
uint64_t data = UINT64_MAX;//invalid access
//reading from a hardware register FIFO will corrupt it!
if(bankType[START_BANK(address)] != CHIP_NONE){
if(dbvzBankType[DBVZ_START_BANK(address)] != DBVZ_CHIP_NONE){
uint16_t m68kSr = m68k_get_reg(NULL, M68K_REG_SR);
m68k_set_reg(M68K_REG_SR, 0x2000);//prevent privilege violations
switch(size){

View File

@@ -1,119 +0,0 @@
#ifndef HARDWARE_REGISTERS_H
#define HARDWARE_REGISTERS_H
#include <stdint.h>
#include <stdbool.h>
//interrupt names
#define INT_EMIQ 0x00800000//level 7
#define INT_RTI 0x00400000//level 4
#define INT_SPI1 0x00200000//level 1<->6, configurable, datasheet is contraditory on this one
#define INT_IRQ5 0x00100000//level 5
#define INT_IRQ6 0x00080000//level 6
#define INT_IRQ3 0x00040000//level 3
#define INT_IRQ2 0x00020000//level 2
#define INT_IRQ1 0x00010000//level 1
#define INT_PWM2 0x00002000//level 1<->6, configurable
#define INT_UART2 0x00001000//level 1<->6, configurable
#define INT_INT3 0x00000800//level 4
#define INT_INT2 0x00000400//level 4
#define INT_INT1 0x00000200//level 4
#define INT_INT0 0x00000100//level 4
#define INT_PWM1 0x00000080//level 6
#define INT_KB 0x00000040//level 4
#define INT_TMR2 0x00000020//level 1<->6, configurable
#define INT_RTC 0x00000010//level 4
#define INT_WDT 0x00000008//level 4
#define INT_UART1 0x00000004//level 4
#define INT_TMR1 0x00000002//level 6
#define INT_SPI2 0x00000001//level 4
//reasons a timer is triggered
#define TIMER_REASON_SYSCLK 0x00
#define TIMER_REASON_TIN 0x01
#define TIMER_REASON_CLK32 0x02
//chip names
enum{
CHIP_BEGIN = 0,
CHIP_A0_ROM = 0,
CHIP_A1_USB,
CHIP_B0_SED,
CHIP_B1_NIL,
//CHIP_CX_RAM, //CSC* is owned by CSD during normal operation
CHIP_DX_RAM,
CHIP_00_EMU, //used for EMUCS on hardware, used by the emu registers here
CHIP_REGISTERS,
CHIP_NONE,
CHIP_END
};
//types
typedef struct{
bool enable;
uint32_t start;
uint32_t lineSize;//the size of a single chip select line, multiply by 2 to get the range size for RAM
uint32_t mask;//the address lines the chip responds to, so 0x10000 on an chip with 16 address lines will return the value at 0x0000
//attributes
bool inBootMode;
bool readOnly;
bool readOnlyForProtectedMemory;
bool supervisorOnlyProtectedMemory;
uint32_t unprotectedSize;
}chip_t;
//variables
extern chip_t chips[];
extern int8_t pllSleepWait;
extern int8_t pllWakeWait;
extern uint32_t clk32Counter;
extern double pctlrCpuClockDivider;
extern double timerCycleCounter[];
extern uint16_t timerStatusReadAcknowledge[];
extern uint8_t portDInterruptLastValue;
extern uint16_t spi1RxFifo[];
extern uint16_t spi1TxFifo[];
extern uint8_t spi1RxReadPosition;
extern uint8_t spi1RxWritePosition;
extern bool spi1RxOverflowed;
extern uint8_t spi1TxReadPosition;
extern uint8_t spi1TxWritePosition;
extern int32_t pwm1ClocksToNextSample;
extern uint8_t pwm1Fifo[];
extern uint8_t pwm1ReadPosition;
extern uint8_t pwm1WritePosition;
//timing
void beginClk32(void);
void endClk32(void);
void addSysclks(double value);//only call between begin/endClk32
//CPU
bool pllIsOn(void);
bool backlightAmplifierState(void);
bool registersAreXXFFMapped(void);
bool sed1376ClockConnected(void);
void ads7846OverridePenState(bool value);
void refreshTouchState(void);//just refreshes the touchscreen
void refreshInputState(void);//refreshes touchscreen, buttons and docked status
//int32_t interruptAcknowledge(int32_t intLevel);//this is in m68kexternal.h
//memory errors
void setBusErrorTimeOut(uint32_t address, bool isWrite);
void setPrivilegeViolation(uint32_t address, bool isWrite);
void setWriteProtectViolation(uint32_t address);
//memory accessors
uint8_t getHwRegister8(uint32_t address);
uint16_t getHwRegister16(uint32_t address);
uint32_t getHwRegister32(uint32_t address);
void setHwRegister8(uint32_t address, uint8_t value);
void setHwRegister16(uint32_t address, uint16_t value);
void setHwRegister32(uint32_t address, uint32_t value);
//config
void resetHwRegisters(void);
void setRtc(uint16_t days, uint8_t hours, uint8_t minutes, uint8_t seconds);
#endif

435
src/m515Bus.c Normal file
View File

@@ -0,0 +1,435 @@
#include <stdint.h>
#include <string.h>
#include "emulator.h"
#include "dbvzRegisters.h"
#include "expansionHardware.h"
#include "m515Bus.h"
#include "portability.h"
#include "flx68000.h"
#include "sed1376.h"
#include "pdiUsbD12.h"
#include "debug/sandbox.h"
uint8_t dbvzBankType[DBVZ_TOTAL_MEMORY_BANKS];
//RAM accesses
static uint8_t ramRead8(uint32_t address){return BUFFER_READ_8(palmRam, address, chips[DBVZ_CHIP_DX_RAM].mask);}
static uint16_t ramRead16(uint32_t address){return BUFFER_READ_16(palmRam, address, chips[DBVZ_CHIP_DX_RAM].mask);}
static uint32_t ramRead32(uint32_t address){return BUFFER_READ_32(palmRam, address, chips[DBVZ_CHIP_DX_RAM].mask);}
static void ramWrite8(uint32_t address, uint8_t value){BUFFER_WRITE_8(palmRam, address, chips[DBVZ_CHIP_DX_RAM].mask, value);}
static void ramWrite16(uint32_t address, uint16_t value){BUFFER_WRITE_16(palmRam, address, chips[DBVZ_CHIP_DX_RAM].mask, value);}
static void ramWrite32(uint32_t address, uint32_t value){BUFFER_WRITE_32(palmRam, address, chips[DBVZ_CHIP_DX_RAM].mask, value);}
//ROM accesses
static uint8_t romRead8(uint32_t address){return BUFFER_READ_8(palmRom, address, chips[DBVZ_CHIP_A0_ROM].mask);}
static uint16_t romRead16(uint32_t address){return BUFFER_READ_16(palmRom, address, chips[DBVZ_CHIP_A0_ROM].mask);}
static uint32_t romRead32(uint32_t address){return BUFFER_READ_32(palmRom, address, chips[DBVZ_CHIP_A0_ROM].mask);}
//SED1376 accesses
static uint8_t sed1376Read8(uint32_t address){
#if !defined(EMU_NO_SAFETY)
if(sed1376PowerSaveEnabled())
return 0x00;
#endif
if(address & SED1376_MR_BIT)
return BUFFER_READ_8_BIG_ENDIAN(sed1376Ram, address, chips[DBVZ_CHIP_B0_SED].mask);
else
return sed1376GetRegister(address & chips[DBVZ_CHIP_B0_SED].mask);
}
static uint16_t sed1376Read16(uint32_t address){
#if !defined(EMU_NO_SAFETY)
if(sed1376PowerSaveEnabled())
return 0x0000;
#endif
if(address & SED1376_MR_BIT)
return BUFFER_READ_16_BIG_ENDIAN(sed1376Ram, address, chips[DBVZ_CHIP_B0_SED].mask);
else
return sed1376GetRegister(address & chips[DBVZ_CHIP_B0_SED].mask);
}
static uint32_t sed1376Read32(uint32_t address){
#if !defined(EMU_NO_SAFETY)
if(sed1376PowerSaveEnabled())
return 0x00000000;
#endif
if(address & SED1376_MR_BIT)
return BUFFER_READ_32_BIG_ENDIAN(sed1376Ram, address, chips[DBVZ_CHIP_B0_SED].mask);
else
return sed1376GetRegister(address & chips[DBVZ_CHIP_B0_SED].mask);
}
static void sed1376Write8(uint32_t address, uint8_t value){
if(address & SED1376_MR_BIT)
BUFFER_WRITE_8_BIG_ENDIAN(sed1376Ram, address, chips[DBVZ_CHIP_B0_SED].mask, value);
else
sed1376SetRegister(address & chips[DBVZ_CHIP_B0_SED].mask, value);
}
static void sed1376Write16(uint32_t address, uint16_t value){
if(address & SED1376_MR_BIT)
BUFFER_WRITE_16_BIG_ENDIAN(sed1376Ram, address, chips[DBVZ_CHIP_B0_SED].mask, value);
else
sed1376SetRegister(address & chips[DBVZ_CHIP_B0_SED].mask, value);
}
static void sed1376Write32(uint32_t address, uint32_t value){
if(address & SED1376_MR_BIT)
BUFFER_WRITE_32_BIG_ENDIAN(sed1376Ram, address, chips[DBVZ_CHIP_B0_SED].mask, value);
else
sed1376SetRegister(address & chips[DBVZ_CHIP_B0_SED].mask, value);
}
static bool probeRead(uint8_t bank, uint32_t address){
if(chips[bank].supervisorOnlyProtectedMemory){
uint32_t index = address - chips[bank].start;
if(index >= chips[bank].unprotectedSize && !flx68000IsSupervisor()){
dbvzSetPrivilegeViolation(address, false);
return false;
}
}
return true;
}
static bool probeWrite(uint8_t bank, uint32_t address){
if(chips[bank].readOnly){
dbvzSetWriteProtectViolation(address);
return false;
}
else if(chips[bank].supervisorOnlyProtectedMemory || chips[bank].readOnlyForProtectedMemory){
uint32_t index = address - chips[bank].start;
if(index >= chips[bank].unprotectedSize){
if(chips[bank].supervisorOnlyProtectedMemory && !flx68000IsSupervisor()){
dbvzSetPrivilegeViolation(address, true);
return false;
}
if(chips[bank].readOnlyForProtectedMemory){
dbvzSetWriteProtectViolation(address);
return false;
}
}
}
return true;
}
uint8_t m68k_read_memory_8(uint32_t address){
uint8_t addressType = dbvzBankType[DBVZ_START_BANK(address)];
#if !defined(EMU_NO_SAFETY)
if(!probeRead(addressType, address))
return 0x00;
#endif
#if defined(EMU_DEBUG) && defined(EMU_SANDBOX) && defined(EMU_SANDBOX_LOG_MEMORY_ACCESSES)
sandboxOnMemoryAccess(address, 8, false, 0);
#endif
switch(addressType){
case DBVZ_CHIP_A0_ROM:
return romRead8(address);
case DBVZ_CHIP_A1_USB:
return pdiUsbD12GetRegister(!!(address & chips[DBVZ_CHIP_A1_USB].mask));
case DBVZ_CHIP_B0_SED:
return sed1376Read8(address);
case DBVZ_CHIP_DX_RAM:
return ramRead8(address);
case DBVZ_CHIP_00_EMU:
return 0x00;
case DBVZ_CHIP_REGISTERS:
return dbvzGetRegister8(address);
case DBVZ_CHIP_B1_NIL:
case DBVZ_CHIP_NONE:
dbvzSetBusErrorTimeOut(address, false);
return 0x00;
default:
debugLog("Unknown bank type:%d\n", dbvzBankType[DBVZ_START_BANK(address)]);
return 0x00;
}
}
uint16_t m68k_read_memory_16(uint32_t address){
uint8_t addressType = dbvzBankType[DBVZ_START_BANK(address)];
#if !defined(EMU_NO_SAFETY)
if(!probeRead(addressType, address))
return 0x0000;
#endif
#if defined(EMU_DEBUG) && defined(EMU_SANDBOX) && defined(EMU_SANDBOX_LOG_MEMORY_ACCESSES)
sandboxOnMemoryAccess(address, 16, false, 0);
#endif
switch(addressType){
case DBVZ_CHIP_A0_ROM:
return romRead16(address);
case DBVZ_CHIP_A1_USB:
return pdiUsbD12GetRegister(!!(address & chips[DBVZ_CHIP_A1_USB].mask));
case DBVZ_CHIP_B0_SED:
return sed1376Read16(address);
case DBVZ_CHIP_DX_RAM:
return ramRead16(address);
case DBVZ_CHIP_00_EMU:
return 0x0000;
case DBVZ_CHIP_REGISTERS:
return dbvzGetRegister16(address);
case DBVZ_CHIP_B1_NIL:
case DBVZ_CHIP_NONE:
dbvzSetBusErrorTimeOut(address, false);
return 0x0000;
default:
debugLog("Unknown bank type:%d\n", dbvzBankType[DBVZ_START_BANK(address)]);
return 0x0000;
}
}
uint32_t m68k_read_memory_32(uint32_t address){
uint8_t addressType = dbvzBankType[DBVZ_START_BANK(address)];
#if !defined(EMU_NO_SAFETY)
if(!probeRead(addressType, address))
return 0x00000000;
#endif
#if defined(EMU_DEBUG) && defined(EMU_SANDBOX) && defined(EMU_SANDBOX_LOG_MEMORY_ACCESSES)
sandboxOnMemoryAccess(address, 32, false, 0);
#endif
switch(addressType){
case DBVZ_CHIP_A0_ROM:
return romRead32(address);
case DBVZ_CHIP_A1_USB:
return pdiUsbD12GetRegister(!!(address & chips[DBVZ_CHIP_A1_USB].mask));
case DBVZ_CHIP_B0_SED:
return sed1376Read32(address);
case DBVZ_CHIP_DX_RAM:
return ramRead32(address);
case DBVZ_CHIP_00_EMU:
return expansionHardwareGetRegister(address);
case DBVZ_CHIP_REGISTERS:
return dbvzGetRegister32(address);
case DBVZ_CHIP_B1_NIL:
case DBVZ_CHIP_NONE:
dbvzSetBusErrorTimeOut(address, false);
return 0x00000000;
default:
debugLog("Unknown bank type:%d\n", dbvzBankType[DBVZ_START_BANK(address)]);
return 0x00000000;
}
}
void m68k_write_memory_8(uint32_t address, uint8_t value){
uint8_t addressType = dbvzBankType[DBVZ_START_BANK(address)];
#if !defined(EMU_NO_SAFETY)
if(!probeWrite(addressType, address))
return;
#endif
#if defined(EMU_DEBUG) && defined(EMU_SANDBOX) && defined(EMU_SANDBOX_LOG_MEMORY_ACCESSES)
sandboxOnMemoryAccess(address, 8, true, value);
#endif
switch(addressType){
case DBVZ_CHIP_A0_ROM:
return;
case DBVZ_CHIP_A1_USB:
pdiUsbD12SetRegister(!!(address & chips[DBVZ_CHIP_A1_USB].mask), value);
return;
case DBVZ_CHIP_B0_SED:
sed1376Write8(address, value);
return;
case DBVZ_CHIP_DX_RAM:
ramWrite8(address, value);
return;
case DBVZ_CHIP_00_EMU:
return;
case DBVZ_CHIP_REGISTERS:
dbvzSetRegister8(address, value);
return;
case DBVZ_CHIP_B1_NIL:
case DBVZ_CHIP_NONE:
dbvzSetBusErrorTimeOut(address, true);
return;
default:
debugLog("Unknown bank type:%d\n", dbvzBankType[DBVZ_START_BANK(address)]);
return;
}
}
void m68k_write_memory_16(uint32_t address, uint16_t value){
uint8_t addressType = dbvzBankType[DBVZ_START_BANK(address)];
#if !defined(EMU_NO_SAFETY)
if(!probeWrite(addressType, address))
return;
#endif
#if defined(EMU_DEBUG) && defined(EMU_SANDBOX) && defined(EMU_SANDBOX_LOG_MEMORY_ACCESSES)
sandboxOnMemoryAccess(address, 16, true, value);
#endif
switch(addressType){
case DBVZ_CHIP_A0_ROM:
return;
case DBVZ_CHIP_A1_USB:
pdiUsbD12SetRegister(!!(address & chips[DBVZ_CHIP_A1_USB].mask), value);
return;
case DBVZ_CHIP_B0_SED:
sed1376Write16(address, value);
return;
case DBVZ_CHIP_DX_RAM:
ramWrite16(address, value);
return;
case DBVZ_CHIP_00_EMU:
return;
case DBVZ_CHIP_REGISTERS:
dbvzSetRegister16(address, value);
return;
case DBVZ_CHIP_B1_NIL:
case DBVZ_CHIP_NONE:
dbvzSetBusErrorTimeOut(address, true);
return;
default:
debugLog("Unknown bank type:%d\n", dbvzBankType[DBVZ_START_BANK(address)]);
return;
}
}
void m68k_write_memory_32(uint32_t address, uint32_t value){
uint8_t addressType = dbvzBankType[DBVZ_START_BANK(address)];
#if !defined(EMU_NO_SAFETY)
if(!probeWrite(addressType, address))
return;
#endif
#if defined(EMU_DEBUG) && defined(EMU_SANDBOX) && defined(EMU_SANDBOX_LOG_MEMORY_ACCESSES)
sandboxOnMemoryAccess(address, 32, true, value);
#endif
switch(addressType){
case DBVZ_CHIP_A0_ROM:
return;
case DBVZ_CHIP_A1_USB:
pdiUsbD12SetRegister(!!(address & chips[DBVZ_CHIP_A1_USB].mask), value);
return;
case DBVZ_CHIP_B0_SED:
sed1376Write32(address, value);
return;
case DBVZ_CHIP_DX_RAM:
ramWrite32(address, value);
return;
case DBVZ_CHIP_00_EMU:
expansionHardwareSetRegister(address, value);
return;
case DBVZ_CHIP_REGISTERS:
dbvzSetRegister32(address, value);
return;
case DBVZ_CHIP_B1_NIL:
case DBVZ_CHIP_NONE:
dbvzSetBusErrorTimeOut(address, true);
return;
default:
debugLog("Unknown bank type:%d\n", dbvzBankType[DBVZ_START_BANK(address)]);
return;
}
}
void m68k_write_memory_32_pd(uint32_t address, uint32_t value){
m68k_write_memory_32(address, value >> 16 | value << 16);
}
//memory access for the disassembler, unused but must be defined
uint8_t m68k_read_disassembler_8(uint32_t address){return m68k_read_memory_8(address);}
uint16_t m68k_read_disassembler_16(uint32_t address){return m68k_read_memory_16(address);}
uint32_t m68k_read_disassembler_32(uint32_t address){return m68k_read_memory_32(address);}
static uint8_t getProperBankType(uint32_t bank){
//registers have first priority, they cover 0xFFFFF000(and 0xXXFFF000 when DMAP enabled in SCR) even if a chip select overlaps this area or DBVZ_CHIP_A0_ROM is in boot mode
//EMUCS also cant be covered by normal chip selects
if(DBVZ_BANK_IN_RANGE(bank, DBVZ_REG_START_ADDRESS, DBVZ_REG_SIZE) || ((bank & 0x00FF) == 0x00FF && dbvzAreRegistersXXFFMapped()))
return DBVZ_CHIP_REGISTERS;
else if(palmEmuFeatures.info != FEATURE_ACCURATE && DBVZ_BANK_IN_RANGE(bank, DBVZ_EMUCS_START_ADDRESS, DBVZ_EMUCS_SIZE))
return DBVZ_CHIP_00_EMU;
else if(chips[DBVZ_CHIP_A0_ROM].inBootMode || (chips[DBVZ_CHIP_A0_ROM].enable && DBVZ_BANK_IN_RANGE(bank, chips[DBVZ_CHIP_A0_ROM].start, chips[DBVZ_CHIP_A0_ROM].lineSize)))
return DBVZ_CHIP_A0_ROM;
else if(chips[DBVZ_CHIP_DX_RAM].enable && DBVZ_BANK_IN_RANGE(bank, chips[DBVZ_CHIP_DX_RAM].start, chips[DBVZ_CHIP_DX_RAM].lineSize * 2))
return DBVZ_CHIP_DX_RAM;
else if(chips[DBVZ_CHIP_B0_SED].enable && DBVZ_BANK_IN_RANGE(bank, chips[DBVZ_CHIP_B0_SED].start, chips[DBVZ_CHIP_B0_SED].lineSize) && sed1376ClockConnected())
return DBVZ_CHIP_B0_SED;
else if(chips[DBVZ_CHIP_A1_USB].enable && DBVZ_BANK_IN_RANGE(bank, chips[DBVZ_CHIP_A1_USB].start, chips[DBVZ_CHIP_A1_USB].lineSize))
return DBVZ_CHIP_A1_USB;
else if(chips[DBVZ_CHIP_B1_NIL].enable && DBVZ_BANK_IN_RANGE(bank, chips[DBVZ_CHIP_B1_NIL].start, chips[DBVZ_CHIP_B1_NIL].lineSize))
return DBVZ_CHIP_B1_NIL;
return DBVZ_CHIP_NONE;
}
void dbvzSetRegisterXXFFAccessMode(void){
uint32_t topByte;
MULTITHREAD_LOOP(topByte) for(topByte = 0; topByte < 0x100; topByte++)
dbvzBankType[DBVZ_START_BANK(topByte << 24 | 0x00FFF000)] = DBVZ_CHIP_REGISTERS;
}
void dbvzSetRegisterFFFFAccessMode(void){
uint32_t topByte;
MULTITHREAD_LOOP(topByte) for(topByte = 0; topByte < 0x100; topByte++){
uint32_t bank = DBVZ_START_BANK(topByte << 24 | 0x00FFF000);
dbvzBankType[bank] = getProperBankType(bank);
}
}
void m515SetSed1376Attached(bool attached){
if(chips[DBVZ_CHIP_B0_SED].enable && dbvzBankType[DBVZ_START_BANK(chips[DBVZ_CHIP_B0_SED].start)] != (attached ? DBVZ_CHIP_B0_SED : DBVZ_CHIP_NONE))
memset(&dbvzBankType[DBVZ_START_BANK(chips[DBVZ_CHIP_B0_SED].start)], attached ? DBVZ_CHIP_B0_SED : DBVZ_CHIP_NONE, DBVZ_END_BANK(chips[DBVZ_CHIP_B0_SED].start, chips[DBVZ_CHIP_B0_SED].lineSize) - DBVZ_START_BANK(chips[DBVZ_CHIP_B0_SED].start) + 1);
}
void dbvzResetAddressSpace(void){
uint32_t bank;
MULTITHREAD_LOOP(bank) for(bank = 0; bank < DBVZ_TOTAL_MEMORY_BANKS; bank++)
dbvzBankType[bank] = getProperBankType(bank);
}

36
src/m515Bus.h Normal file
View File

@@ -0,0 +1,36 @@
#ifndef M515_BUS_H
#define M515_BUS_H
#include <stdint.h>
//address space
//new bank size (0x4000)
#define DBVZ_BANK_SCOOT 14
#define DBVZ_NUM_BANKS(areaSize) (((areaSize) >> DBVZ_BANK_SCOOT) + ((areaSize) & ((1 << DBVZ_BANK_SCOOT) - 1) ? 1 : 0))
#define DBVZ_START_BANK(address) ((address) >> DBVZ_BANK_SCOOT)
#define DBVZ_END_BANK(address, size) (DBVZ_START_BANK(address) + DBVZ_NUM_BANKS(size) - 1)
#define DBVZ_BANK_IN_RANGE(bank, address, size) ((bank) >= DBVZ_START_BANK(address) && (bank) <= DBVZ_END_BANK(address, size))
#define DBVZ_BANK_ADDRESS(bank) ((bank) << DBVZ_BANK_SCOOT)
#define DBVZ_TOTAL_MEMORY_BANKS (1 << (32 - DBVZ_BANK_SCOOT))//0x40000 banks for BANK_SCOOT = 14
//chip addresses and sizes
//after boot RAM is at 0x00000000,
//ROM is at 0x10000000
//and the SED1376 is at 0x1FF80000(+ 0x20000 for framebuffer)
#define DBVZ_EMUCS_START_ADDRESS 0xFFFC0000
#define DBVZ_REG_START_ADDRESS 0xFFFFF000
#define M515_RAM_SIZE (16 * 0x100000)//16mb RAM
#define M515_ROM_SIZE (4 * 0x100000)//4mb ROM
#define DBVZ_EMUCS_SIZE 0x20000
#define DBVZ_REG_SIZE 0x1000//is actually 0xE00 without bootloader
#define DBVZ_BOOTLOADER_SIZE 0x200
#define SED1376_MR_BIT 0x20000
extern uint8_t dbvzBankType[];
void dbvzSetRegisterXXFFAccessMode(void);
void dbvzSetRegisterFFFFAccessMode(void);
void m515SetSed1376Attached(bool attached);
void dbvzResetAddressSpace(void);
#endif

View File

@@ -677,9 +677,6 @@ int32_t m68k_execute(int32_t num_cycles)
m68ki_exception_if_trace(); /* auto-disable (see m68kcpu.h) */
} while(GET_CYCLES() > 0);
/* set previous PC to current PC for the next entry into the loop */
REG_PPC = REG_PC;
/* ASG: update cycles */
USE_CYCLES(CPU_INT_CYCLES);
CPU_INT_CYCLES = 0;

View File

@@ -1,7 +1,7 @@
EMU_DEFINES :=
EMU_SOURCES_C := $(EMU_PATH)/emulator.c \
$(EMU_PATH)/memoryAccess.c \
$(EMU_PATH)/hardwareRegisters.c \
$(EMU_PATH)/m515Bus.c \
$(EMU_PATH)/dbvzRegisters.c \
$(EMU_PATH)/flx68000.c \
$(EMU_PATH)/sed1376.c \
$(EMU_PATH)/ads7846.c \
@@ -16,7 +16,9 @@ EMU_SOURCES_C := $(EMU_PATH)/emulator.c \
$(EMU_PATH)/m68k/m68kopdm.c \
$(EMU_PATH)/m68k/m68kopac.c \
$(EMU_PATH)/m68k/m68kdasm.c \
$(EMU_PATH)/m68k/m68kcpu.c \
$(EMU_PATH)/armv5.c \
$(EMU_PATH)/armv5/CPU.c \
$(EMU_PATH)/armv5/icache.c
$(EMU_PATH)/m68k/m68kcpu.c
ifeq ($(EMU_SUPPORT_PALM_OS5),1)
EMU_DEFINES += -DEMU_SUPPORT_PALM_OS5
# EMU_SOURCES_C +=
endif

View File

@@ -1,434 +0,0 @@
#include <stdint.h>
#include <string.h>
#include "emulator.h"
#include "hardwareRegisters.h"
#include "expansionHardware.h"
#include "memoryAccess.h"
#include "portability.h"
#include "flx68000.h"
#include "sed1376.h"
#include "pdiUsbD12.h"
uint8_t bankType[TOTAL_MEMORY_BANKS];
//RAM accesses
static uint8_t ramRead8(uint32_t address){return BUFFER_READ_8(palmRam, address, chips[CHIP_DX_RAM].mask);}
static uint16_t ramRead16(uint32_t address){return BUFFER_READ_16(palmRam, address, chips[CHIP_DX_RAM].mask);}
static uint32_t ramRead32(uint32_t address){return BUFFER_READ_32(palmRam, address, chips[CHIP_DX_RAM].mask);}
static void ramWrite8(uint32_t address, uint8_t value){BUFFER_WRITE_8(palmRam, address, chips[CHIP_DX_RAM].mask, value);}
static void ramWrite16(uint32_t address, uint16_t value){BUFFER_WRITE_16(palmRam, address, chips[CHIP_DX_RAM].mask, value);}
static void ramWrite32(uint32_t address, uint32_t value){BUFFER_WRITE_32(palmRam, address, chips[CHIP_DX_RAM].mask, value);}
//ROM accesses
static uint8_t romRead8(uint32_t address){return BUFFER_READ_8(palmRom, address, chips[CHIP_A0_ROM].mask);}
static uint16_t romRead16(uint32_t address){return BUFFER_READ_16(palmRom, address, chips[CHIP_A0_ROM].mask);}
static uint32_t romRead32(uint32_t address){return BUFFER_READ_32(palmRom, address, chips[CHIP_A0_ROM].mask);}
//SED1376 accesses
static uint8_t sed1376Read8(uint32_t address){
#if !defined(EMU_NO_SAFETY)
if(sed1376PowerSaveEnabled())
return 0x00;
#endif
if(address & SED1376_MR_BIT)
return BUFFER_READ_8_BIG_ENDIAN(sed1376Ram, address, chips[CHIP_B0_SED].mask);
else
return sed1376GetRegister(address & chips[CHIP_B0_SED].mask);
}
static uint16_t sed1376Read16(uint32_t address){
#if !defined(EMU_NO_SAFETY)
if(sed1376PowerSaveEnabled())
return 0x0000;
#endif
if(address & SED1376_MR_BIT)
return BUFFER_READ_16_BIG_ENDIAN(sed1376Ram, address, chips[CHIP_B0_SED].mask);
else
return sed1376GetRegister(address & chips[CHIP_B0_SED].mask);
}
static uint32_t sed1376Read32(uint32_t address){
#if !defined(EMU_NO_SAFETY)
if(sed1376PowerSaveEnabled())
return 0x00000000;
#endif
if(address & SED1376_MR_BIT)
return BUFFER_READ_32_BIG_ENDIAN(sed1376Ram, address, chips[CHIP_B0_SED].mask);
else
return sed1376GetRegister(address & chips[CHIP_B0_SED].mask);
}
static void sed1376Write8(uint32_t address, uint8_t value){
if(address & SED1376_MR_BIT)
BUFFER_WRITE_8_BIG_ENDIAN(sed1376Ram, address, chips[CHIP_B0_SED].mask, value);
else
sed1376SetRegister(address & chips[CHIP_B0_SED].mask, value);
}
static void sed1376Write16(uint32_t address, uint16_t value){
if(address & SED1376_MR_BIT)
BUFFER_WRITE_16_BIG_ENDIAN(sed1376Ram, address, chips[CHIP_B0_SED].mask, value);
else
sed1376SetRegister(address & chips[CHIP_B0_SED].mask, value);
}
static void sed1376Write32(uint32_t address, uint32_t value){
if(address & SED1376_MR_BIT)
BUFFER_WRITE_32_BIG_ENDIAN(sed1376Ram, address, chips[CHIP_B0_SED].mask, value);
else
sed1376SetRegister(address & chips[CHIP_B0_SED].mask, value);
}
static bool probeRead(uint8_t bank, uint32_t address){
if(chips[bank].supervisorOnlyProtectedMemory){
uint32_t index = address - chips[bank].start;
if(index >= chips[bank].unprotectedSize && !flx68000IsSupervisor()){
setPrivilegeViolation(address, false);
return false;
}
}
return true;
}
static bool probeWrite(uint8_t bank, uint32_t address){
if(chips[bank].readOnly){
setWriteProtectViolation(address);
return false;
}
else if(chips[bank].supervisorOnlyProtectedMemory || chips[bank].readOnlyForProtectedMemory){
uint32_t index = address - chips[bank].start;
if(index >= chips[bank].unprotectedSize){
if(chips[bank].supervisorOnlyProtectedMemory && !flx68000IsSupervisor()){
setPrivilegeViolation(address, true);
return false;
}
if(chips[bank].readOnlyForProtectedMemory){
setWriteProtectViolation(address);
return false;
}
}
}
return true;
}
uint8_t m68k_read_memory_8(uint32_t address){
uint8_t addressType = bankType[START_BANK(address)];
#if !defined(EMU_NO_SAFETY)
if(!probeRead(addressType, address))
return 0x00;
#endif
#if defined(EMU_DEBUG) && defined(EMU_SANDBOX)
sandboxOnMemoryAccess(address, 8, false, 0);
#endif
switch(addressType){
case CHIP_A0_ROM:
return romRead8(address);
case CHIP_A1_USB:
return pdiUsbD12GetRegister(!!(address & chips[CHIP_A1_USB].mask));
case CHIP_B0_SED:
return sed1376Read8(address);
case CHIP_DX_RAM:
return ramRead8(address);
case CHIP_00_EMU:
return 0x00;
case CHIP_REGISTERS:
return getHwRegister8(address);
case CHIP_B1_NIL:
case CHIP_NONE:
setBusErrorTimeOut(address, false);
return 0x00;
default:
debugLog("Unknown bank type:%d\n", bankType[START_BANK(address)]);
return 0x00;
}
}
uint16_t m68k_read_memory_16(uint32_t address){
uint8_t addressType = bankType[START_BANK(address)];
#if !defined(EMU_NO_SAFETY)
if(!probeRead(addressType, address))
return 0x0000;
#endif
#if defined(EMU_DEBUG) && defined(EMU_SANDBOX)
sandboxOnMemoryAccess(address, 16, false, 0);
#endif
switch(addressType){
case CHIP_A0_ROM:
return romRead16(address);
case CHIP_A1_USB:
return pdiUsbD12GetRegister(!!(address & chips[CHIP_A1_USB].mask));
case CHIP_B0_SED:
return sed1376Read16(address);
case CHIP_DX_RAM:
return ramRead16(address);
case CHIP_00_EMU:
return 0x0000;
case CHIP_REGISTERS:
return getHwRegister16(address);
case CHIP_B1_NIL:
case CHIP_NONE:
setBusErrorTimeOut(address, false);
return 0x0000;
default:
debugLog("Unknown bank type:%d\n", bankType[START_BANK(address)]);
return 0x0000;
}
}
uint32_t m68k_read_memory_32(uint32_t address){
uint8_t addressType = bankType[START_BANK(address)];
#if !defined(EMU_NO_SAFETY)
if(!probeRead(addressType, address))
return 0x00000000;
#endif
#if defined(EMU_DEBUG) && defined(EMU_SANDBOX)
sandboxOnMemoryAccess(address, 32, false, 0);
#endif
switch(addressType){
case CHIP_A0_ROM:
return romRead32(address);
case CHIP_A1_USB:
return pdiUsbD12GetRegister(!!(address & chips[CHIP_A1_USB].mask));
case CHIP_B0_SED:
return sed1376Read32(address);
case CHIP_DX_RAM:
return ramRead32(address);
case CHIP_00_EMU:
return expansionHardwareGetRegister(address);
case CHIP_REGISTERS:
return getHwRegister32(address);
case CHIP_B1_NIL:
case CHIP_NONE:
setBusErrorTimeOut(address, false);
return 0x00000000;
default:
debugLog("Unknown bank type:%d\n", bankType[START_BANK(address)]);
return 0x00000000;
}
}
void m68k_write_memory_8(uint32_t address, uint8_t value){
uint8_t addressType = bankType[START_BANK(address)];
#if !defined(EMU_NO_SAFETY)
if(!probeWrite(addressType, address))
return;
#endif
#if defined(EMU_DEBUG) && defined(EMU_SANDBOX)
sandboxOnMemoryAccess(address, 8, true, value);
#endif
switch(addressType){
case CHIP_A0_ROM:
return;
case CHIP_A1_USB:
pdiUsbD12SetRegister(!!(address & chips[CHIP_A1_USB].mask), value);
return;
case CHIP_B0_SED:
sed1376Write8(address, value);
return;
case CHIP_DX_RAM:
ramWrite8(address, value);
return;
case CHIP_00_EMU:
return;
case CHIP_REGISTERS:
setHwRegister8(address, value);
return;
case CHIP_B1_NIL:
case CHIP_NONE:
setBusErrorTimeOut(address, true);
return;
default:
debugLog("Unknown bank type:%d\n", bankType[START_BANK(address)]);
return;
}
}
void m68k_write_memory_16(uint32_t address, uint16_t value){
uint8_t addressType = bankType[START_BANK(address)];
#if !defined(EMU_NO_SAFETY)
if(!probeWrite(addressType, address))
return;
#endif
#if defined(EMU_DEBUG) && defined(EMU_SANDBOX)
sandboxOnMemoryAccess(address, 16, true, value);
#endif
switch(addressType){
case CHIP_A0_ROM:
return;
case CHIP_A1_USB:
pdiUsbD12SetRegister(!!(address & chips[CHIP_A1_USB].mask), value);
return;
case CHIP_B0_SED:
sed1376Write16(address, value);
return;
case CHIP_DX_RAM:
ramWrite16(address, value);
return;
case CHIP_00_EMU:
return;
case CHIP_REGISTERS:
setHwRegister16(address, value);
return;
case CHIP_B1_NIL:
case CHIP_NONE:
setBusErrorTimeOut(address, true);
return;
default:
debugLog("Unknown bank type:%d\n", bankType[START_BANK(address)]);
return;
}
}
void m68k_write_memory_32(uint32_t address, uint32_t value){
uint8_t addressType = bankType[START_BANK(address)];
#if !defined(EMU_NO_SAFETY)
if(!probeWrite(addressType, address))
return;
#endif
#if defined(EMU_DEBUG) && defined(EMU_SANDBOX)
sandboxOnMemoryAccess(address, 32, true, value);
#endif
switch(addressType){
case CHIP_A0_ROM:
return;
case CHIP_A1_USB:
pdiUsbD12SetRegister(!!(address & chips[CHIP_A1_USB].mask), value);
return;
case CHIP_B0_SED:
sed1376Write32(address, value);
return;
case CHIP_DX_RAM:
ramWrite32(address, value);
return;
case CHIP_00_EMU:
expansionHardwareSetRegister(address, value);
return;
case CHIP_REGISTERS:
setHwRegister32(address, value);
return;
case CHIP_B1_NIL:
case CHIP_NONE:
setBusErrorTimeOut(address, true);
return;
default:
debugLog("Unknown bank type:%d\n", bankType[START_BANK(address)]);
return;
}
}
void m68k_write_memory_32_pd(uint32_t address, uint32_t value){
m68k_write_memory_32(address, value >> 16 | value << 16);
}
//memory access for the disassembler, unused but must be defined
uint8_t m68k_read_disassembler_8(uint32_t address){return m68k_read_memory_8(address);}
uint16_t m68k_read_disassembler_16(uint32_t address){return m68k_read_memory_16(address);}
uint32_t m68k_read_disassembler_32(uint32_t address){return m68k_read_memory_32(address);}
static uint8_t getProperBankType(uint32_t bank){
//registers have first priority, they cover 0xFFFFF000(and 0xXXFFF000 when DMAP enabled in SCR) even if a chip select overlaps this area or CHIP_A0_ROM is in boot mode
//EMUCS also cant be covered by normal chip selects
if(BANK_IN_RANGE(bank, REG_START_ADDRESS, REG_SIZE) || ((bank & 0x00FF) == 0x00FF && registersAreXXFFMapped()))
return CHIP_REGISTERS;
else if(palmEmuFeatures.info != FEATURE_ACCURATE && BANK_IN_RANGE(bank, EMUCS_START_ADDRESS, EMUCS_SIZE))
return CHIP_00_EMU;
else if(chips[CHIP_A0_ROM].inBootMode || (chips[CHIP_A0_ROM].enable && BANK_IN_RANGE(bank, chips[CHIP_A0_ROM].start, chips[CHIP_A0_ROM].lineSize)))
return CHIP_A0_ROM;
else if(chips[CHIP_DX_RAM].enable && BANK_IN_RANGE(bank, chips[CHIP_DX_RAM].start, chips[CHIP_DX_RAM].lineSize * 2))
return CHIP_DX_RAM;
else if(chips[CHIP_B0_SED].enable && BANK_IN_RANGE(bank, chips[CHIP_B0_SED].start, chips[CHIP_B0_SED].lineSize) && sed1376ClockConnected())
return CHIP_B0_SED;
else if(chips[CHIP_A1_USB].enable && BANK_IN_RANGE(bank, chips[CHIP_A1_USB].start, chips[CHIP_A1_USB].lineSize))
return CHIP_A1_USB;
else if(chips[CHIP_B1_NIL].enable && BANK_IN_RANGE(bank, chips[CHIP_B1_NIL].start, chips[CHIP_B1_NIL].lineSize))
return CHIP_B1_NIL;
return CHIP_NONE;
}
void setRegisterXXFFAccessMode(void){
uint32_t topByte;
MULTITHREAD_LOOP(topByte) for(topByte = 0; topByte < 0x100; topByte++)
bankType[START_BANK(topByte << 24 | 0x00FFF000)] = CHIP_REGISTERS;
}
void setRegisterFFFFAccessMode(void){
uint32_t topByte;
MULTITHREAD_LOOP(topByte) for(topByte = 0; topByte < 0x100; topByte++){
uint32_t bank = START_BANK(topByte << 24 | 0x00FFF000);
bankType[bank] = getProperBankType(bank);
}
}
void setSed1376Attached(bool attached){
if(chips[CHIP_B0_SED].enable && bankType[START_BANK(chips[CHIP_B0_SED].start)] != (attached ? CHIP_B0_SED : CHIP_NONE))
memset(&bankType[START_BANK(chips[CHIP_B0_SED].start)], attached ? CHIP_B0_SED : CHIP_NONE, END_BANK(chips[CHIP_B0_SED].start, chips[CHIP_B0_SED].lineSize) - START_BANK(chips[CHIP_B0_SED].start) + 1);
}
void resetAddressSpace(void){
uint32_t bank;
MULTITHREAD_LOOP(bank) for(bank = 0; bank < TOTAL_MEMORY_BANKS; bank++)
bankType[bank] = getProperBankType(bank);
}

View File

@@ -1,72 +0,0 @@
#ifndef MEMORY_ACCESS_H
#define MEMORY_ACCESS_H
#include <stdint.h>
//address space
//new bank size (0x4000)
#define BANK_SCOOT 14
#define NUM_BANKS(areaSize) (((areaSize) >> BANK_SCOOT) + ((areaSize) & ((1 << BANK_SCOOT) - 1) ? 1 : 0))
#define START_BANK(address) ((address) >> BANK_SCOOT)
#define END_BANK(address, size) (START_BANK(address) + NUM_BANKS(size) - 1)
#define BANK_IN_RANGE(bank, address, size) ((bank) >= START_BANK(address) && (bank) <= END_BANK(address, size))
#define BANK_ADDRESS(bank) ((bank) << BANK_SCOOT)
#define TOTAL_MEMORY_BANKS (1 << (32 - BANK_SCOOT))//0x40000 banks for BANK_SCOOT = 14
//chip addresses and sizes
//after boot RAM is at 0x00000000,
//ROM is at 0x10000000
//and the SED1376 is at 0x1FF80000(+ 0x20000 for framebuffer)
#define EMUCS_START_ADDRESS 0xFFFC0000
#define REG_START_ADDRESS 0xFFFFF000
#define SUPERMASSIVE_RAM_SIZE (128 * 0x100000)//128mb RAM
#define RAM_SIZE (16 * 0x100000)//16mb RAM
#define ROM_SIZE (4 * 0x100000)//4mb ROM
#define EMUCS_SIZE 0x20000
#define REG_SIZE 0x1000//is actually 0xE00 without bootloader
#define BOOTLOADER_SIZE 0x200
#define SED1376_MR_BIT 0x20000
//the read/write stuff looks messy here but makes the memory access functions alot cleaner
#if defined(EMU_BIG_ENDIAN)
//memory layout is the same as the Palm m515, just cast to pointer and access, 32 bit accesses are split to prevent unaligned access issues
#define BUFFER_READ_8(segment, accessAddress, mask) (*(uint8_t*)(segment + ((accessAddress) & (mask))))
#define BUFFER_READ_16(segment, accessAddress, mask) (*(uint16_t*)(segment + ((accessAddress) & (mask))))
#define BUFFER_READ_32(segment, accessAddress, mask) (*(uint16_t*)(segment + ((accessAddress) & (mask))) << 16 | *(uint16_t*)(segment + ((accessAddress) + 2 & (mask))))
#define BUFFER_WRITE_8(segment, accessAddress, mask, value) (*(uint8_t*)(segment + ((accessAddress) & (mask))) = (value))
#define BUFFER_WRITE_16(segment, accessAddress, mask, value) (*(uint16_t*)(segment + ((accessAddress) & (mask))) = (value))
#define BUFFER_WRITE_32(segment, accessAddress, mask, value) (*(uint16_t*)(segment + ((accessAddress) & (mask))) = (value) >> 16 , *(uint16_t*)(segment + ((accessAddress) + 2 & (mask))) = (value) & 0xFFFF)
#define BUFFER_READ_8_BIG_ENDIAN BUFFER_READ_8
#define BUFFER_READ_16_BIG_ENDIAN BUFFER_READ_16
#define BUFFER_READ_32_BIG_ENDIAN BUFFER_READ_32
#define BUFFER_WRITE_8_BIG_ENDIAN BUFFER_WRITE_8
#define BUFFER_WRITE_16_BIG_ENDIAN BUFFER_WRITE_16
#define BUFFER_WRITE_32_BIG_ENDIAN BUFFER_WRITE_32
#else
//memory layout is different from the Palm m515, optimize for opcode fetches(16 bit reads)
#define BUFFER_READ_8(segment, accessAddress, mask) (*(uint8_t*)(segment + ((accessAddress) & (mask) ^ 1)))
#define BUFFER_READ_16(segment, accessAddress, mask) (*(uint16_t*)(segment + ((accessAddress) & (mask))))
#define BUFFER_READ_32(segment, accessAddress, mask) (*(uint16_t*)(segment + ((accessAddress) & (mask))) << 16 | *(uint16_t*)(segment + ((accessAddress) + 2 & (mask))))
#define BUFFER_WRITE_8(segment, accessAddress, mask, value) (*(uint8_t*)(segment + ((accessAddress) & (mask) ^ 1)) = (value))
#define BUFFER_WRITE_16(segment, accessAddress, mask, value) (*(uint16_t*)(segment + ((accessAddress) & (mask))) = (value))
#define BUFFER_WRITE_32(segment, accessAddress, mask, value) (*(uint16_t*)(segment + ((accessAddress) & (mask))) = (value) >> 16 , *(uint16_t*)(segment + ((accessAddress) + 2 & (mask))) = (value) & 0xFFFF)
#define BUFFER_READ_8_BIG_ENDIAN(segment, accessAddress, mask) (segment[(accessAddress) & (mask)])
#define BUFFER_READ_16_BIG_ENDIAN(segment, accessAddress, mask) (segment[(accessAddress) & (mask)] << 8 | segment[(accessAddress) + 1 & (mask)])
#define BUFFER_READ_32_BIG_ENDIAN(segment, accessAddress, mask) (segment[(accessAddress) & (mask)] << 24 | segment[(accessAddress) + 1 & (mask)] << 16 | segment[(accessAddress) + 2 & (mask)] << 8 | segment[(accessAddress) + 3 & (mask)])
#define BUFFER_WRITE_8_BIG_ENDIAN(segment, accessAddress, mask, value) (segment[(accessAddress) & (mask)] = (value))
#define BUFFER_WRITE_16_BIG_ENDIAN(segment, accessAddress, mask, value) (segment[(accessAddress) & (mask)] = (value) >> 8, segment[(accessAddress) + 1 & (mask)] = (value) & 0xFF)
#define BUFFER_WRITE_32_BIG_ENDIAN(segment, accessAddress, mask, value) (segment[(accessAddress) & (mask)] = (value) >> 24, segment[(accessAddress) + 1 & (mask)] = ((value) >> 16) & 0xFF, segment[(accessAddress) + 2 & (mask)] = ((value) >> 8) & 0xFF, segment[(accessAddress) + 3 & (mask)] = (value) & 0xFF)
#endif
#define SWAP_16(x) ((uint16_t)((((uint16_t)(x) & 0x00FF) << 8) | (((uint16_t)(x) & 0xFF00) >> 8)))
#define SWAP_32(x) ((uint32_t)((((uint32_t)(x) & 0x000000FF) << 24) | (((uint32_t)(x) & 0x0000FF00) << 8) | (((uint32_t)(x) & 0x00FF0000) >> 8) | (((uint32_t)(x) & 0xFF000000) >> 24)))
#define SWAP_64(x) ((((uint64_t)(x) & UINT64_C(0x00000000000000FF)) << 56) | (((uint64_t)(x) & UINT64_C(0x000000000000FF00)) << 40) | (((uint64_t)(x) & UINT64_C(0x0000000000FF0000)) << 24) | (((uint64_t)(x) & UINT64_C(0x00000000FF000000)) << 8) | (((uint64_t)(x) & UINT64_C(0x000000FF00000000)) >> 8) | (((uint64_t)(x) & UINT64_C(0x0000FF0000000000)) >> 24) | (((uint64_t)(x) & UINT64_C(0x00FF000000000000)) >> 40) | (((uint64_t)(x) & UINT64_C(0xFF00000000000000)) >> 56))
extern uint8_t bankType[];
void setRegisterXXFFAccessMode(void);
void setRegisterFFFFAccessMode(void);
void setSed1376Attached(bool attached);
void resetAddressSpace(void);
#endif

View File

@@ -70,10 +70,10 @@ void pdiUsbD12Reset(void){
uint32_t pdiUsbD12StateSize(void){
uint32_t size = 0;
size += sizeof(uint8_t);
size += sizeof(uint64_t);
size += PDIUSBD12_TRANSFER_BUFFER_SIZE * PDIUSBD12_FIFO_TOTAL_FIFOS;
size += sizeof(uint16_t) * PDIUSBD12_FIFO_TOTAL_FIFOS * 2;
size += sizeof(uint8_t);//pdiUsbD12Command
size += sizeof(uint64_t);//pdiUsbD12CommandState
size += PDIUSBD12_TRANSFER_BUFFER_SIZE * PDIUSBD12_FIFO_TOTAL_FIFOS;//pdiUsbD12FifoBuffer
size += sizeof(uint16_t) * PDIUSBD12_FIFO_TOTAL_FIFOS * 2;//pdiUsbD12(Read/Write)Position
return size;
}

View File

@@ -4,10 +4,45 @@
#include <stdint.h>
#include <stdbool.h>
//endian
static inline void swap16BufferIfLittle(uint8_t* buffer, uint32_t count){
#if !defined(EMU_BIG_ENDIAN)
//endian/buffers
//the read/write stuff looks messy here but makes the memory access functions alot cleaner
#if defined(EMU_BIG_ENDIAN)
//memory layout is the same as the Palm m515, just cast to pointer and access, 32 bit accesses are split to prevent unaligned access issues
#define BUFFER_READ_8(segment, accessAddress, mask) (*(uint8_t*)(segment + ((accessAddress) & (mask))))
#define BUFFER_READ_16(segment, accessAddress, mask) (*(uint16_t*)(segment + ((accessAddress) & (mask))))
#define BUFFER_READ_32(segment, accessAddress, mask) (*(uint16_t*)(segment + ((accessAddress) & (mask))) << 16 | *(uint16_t*)(segment + ((accessAddress) + 2 & (mask))))
#define BUFFER_WRITE_8(segment, accessAddress, mask, value) (*(uint8_t*)(segment + ((accessAddress) & (mask))) = (value))
#define BUFFER_WRITE_16(segment, accessAddress, mask, value) (*(uint16_t*)(segment + ((accessAddress) & (mask))) = (value))
#define BUFFER_WRITE_32(segment, accessAddress, mask, value) (*(uint16_t*)(segment + ((accessAddress) & (mask))) = (value) >> 16 , *(uint16_t*)(segment + ((accessAddress) + 2 & (mask))) = (value) & 0xFFFF)
#define BUFFER_READ_8_BIG_ENDIAN BUFFER_READ_8
#define BUFFER_READ_16_BIG_ENDIAN BUFFER_READ_16
#define BUFFER_READ_32_BIG_ENDIAN BUFFER_READ_32
#define BUFFER_WRITE_8_BIG_ENDIAN BUFFER_WRITE_8
#define BUFFER_WRITE_16_BIG_ENDIAN BUFFER_WRITE_16
#define BUFFER_WRITE_32_BIG_ENDIAN BUFFER_WRITE_32
#else
//memory layout is different from the Palm m515, optimize for opcode fetches(16 bit reads)
#define BUFFER_READ_8(segment, accessAddress, mask) (*(uint8_t*)(segment + ((accessAddress) & (mask) ^ 1)))
#define BUFFER_READ_16(segment, accessAddress, mask) (*(uint16_t*)(segment + ((accessAddress) & (mask))))
#define BUFFER_READ_32(segment, accessAddress, mask) (*(uint16_t*)(segment + ((accessAddress) & (mask))) << 16 | *(uint16_t*)(segment + ((accessAddress) + 2 & (mask))))
#define BUFFER_WRITE_8(segment, accessAddress, mask, value) (*(uint8_t*)(segment + ((accessAddress) & (mask) ^ 1)) = (value))
#define BUFFER_WRITE_16(segment, accessAddress, mask, value) (*(uint16_t*)(segment + ((accessAddress) & (mask))) = (value))
#define BUFFER_WRITE_32(segment, accessAddress, mask, value) (*(uint16_t*)(segment + ((accessAddress) & (mask))) = (value) >> 16 , *(uint16_t*)(segment + ((accessAddress) + 2 & (mask))) = (value) & 0xFFFF)
#define BUFFER_READ_8_BIG_ENDIAN(segment, accessAddress, mask) (segment[(accessAddress) & (mask)])
#define BUFFER_READ_16_BIG_ENDIAN(segment, accessAddress, mask) (segment[(accessAddress) & (mask)] << 8 | segment[(accessAddress) + 1 & (mask)])
#define BUFFER_READ_32_BIG_ENDIAN(segment, accessAddress, mask) (segment[(accessAddress) & (mask)] << 24 | segment[(accessAddress) + 1 & (mask)] << 16 | segment[(accessAddress) + 2 & (mask)] << 8 | segment[(accessAddress) + 3 & (mask)])
#define BUFFER_WRITE_8_BIG_ENDIAN(segment, accessAddress, mask, value) (segment[(accessAddress) & (mask)] = (value))
#define BUFFER_WRITE_16_BIG_ENDIAN(segment, accessAddress, mask, value) (segment[(accessAddress) & (mask)] = (value) >> 8, segment[(accessAddress) + 1 & (mask)] = (value) & 0xFF)
#define BUFFER_WRITE_32_BIG_ENDIAN(segment, accessAddress, mask, value) (segment[(accessAddress) & (mask)] = (value) >> 24, segment[(accessAddress) + 1 & (mask)] = ((value) >> 16) & 0xFF, segment[(accessAddress) + 2 & (mask)] = ((value) >> 8) & 0xFF, segment[(accessAddress) + 3 & (mask)] = (value) & 0xFF)
#endif
#define SWAP_16(x) ((uint16_t)((((uint16_t)(x) & 0x00FF) << 8) | (((uint16_t)(x) & 0xFF00) >> 8)))
#define SWAP_32(x) ((uint32_t)((((uint32_t)(x) & 0x000000FF) << 24) | (((uint32_t)(x) & 0x0000FF00) << 8) | (((uint32_t)(x) & 0x00FF0000) >> 8) | (((uint32_t)(x) & 0xFF000000) >> 24)))
#define SWAP_64(x) ((((uint64_t)(x) & UINT64_C(0x00000000000000FF)) << 56) | (((uint64_t)(x) & UINT64_C(0x000000000000FF00)) << 40) | (((uint64_t)(x) & UINT64_C(0x0000000000FF0000)) << 24) | (((uint64_t)(x) & UINT64_C(0x00000000FF000000)) << 8) | (((uint64_t)(x) & UINT64_C(0x000000FF00000000)) >> 8) | (((uint64_t)(x) & UINT64_C(0x0000FF0000000000)) >> 24) | (((uint64_t)(x) & UINT64_C(0x00FF000000000000)) >> 40) | (((uint64_t)(x) & UINT64_C(0xFF00000000000000)) >> 56))
static inline void swap16(uint8_t* buffer, uint32_t count){
uint32_t index;
//count specifys the number of uint16_t's that need to be swapped, the uint8_t* is because of alignment restrictions that crash on some platforms
count *= sizeof(uint16_t);
for(index = 0; index < count; index += 2){
@@ -15,6 +50,17 @@ static inline void swap16BufferIfLittle(uint8_t* buffer, uint32_t count){
buffer[index] = buffer[index + 1];
buffer[index + 1] = temp;
}
}
static inline void swap16BufferIfLittle(uint8_t* buffer, uint32_t count){
#if !defined(EMU_BIG_ENDIAN)
swap16(buffer, count);
#endif
}
static inline void swap16BufferIfBig(uint8_t* buffer, uint32_t count){
#if defined(EMU_BIG_ENDIAN)
swap16(buffer, count);
#endif
}

View File

@@ -3,10 +3,9 @@
#include "emulator.h"
#include "portability.h"
#include "hardwareRegisters.h"
#include "dbvzRegisters.h"
#include "flx68000.h"//for flx68000GetPc()
#include "specs/sed1376RegisterSpec.h"
#include "debug/sandbox.h"
//the SED1376 has only 16 address lines(17 if you count the line that switches between registers and framebuffer) and 16 data lines, the most you can read at once is 16 bits, registers are 8 bits
@@ -178,10 +177,6 @@ bool sed1376PowerSaveEnabled(void){
uint8_t sed1376GetRegister(uint8_t address){
//returning 0x00 on power save mode is done in the sed1376ReadXX functions
if(sandboxRunning())
debugLog("SED1376 register read from 0x%02X, PC 0x%08X.\n", address, flx68000GetPc());
switch(address){
case LUT_READ_LOC:
case LUT_WRITE_LOC:
@@ -217,10 +212,6 @@ uint8_t sed1376GetRegister(uint8_t address){
}
void sed1376SetRegister(uint8_t address, uint8_t value){
if(sandboxRunning())
debugLog("SED1376 register write 0x%02X to 0x%02X, PC 0x%08X.\n", value, address, flx68000GetPc());
switch(address){
case PWR_SAVE_CFG:
//bit 7 must always be set, timing hack
@@ -361,7 +352,7 @@ void sed1376SetRegister(uint8_t address, uint8_t value){
void sed1376Render(void){
//render if LCD on, PLL on, power save off and force blank off, SED1376 clock is provided by the CPU, if its off so is the SED
if(palmMisc.lcdOn && pllIsOn() && !sed1376PowerSaveEnabled() && !(sed1376Registers[DISP_MODE] & 0x80)){
if(palmMisc.lcdOn && dbvzIsPllOn() && !sed1376PowerSaveEnabled() && !(sed1376Registers[DISP_MODE] & 0x80)){
bool color = !!(sed1376Registers[PANEL_TYPE] & 0x40);
bool pictureInPictureEnabled = !!(sed1376Registers[SPECIAL_EFFECT] & 0x10);
uint8_t bitDepth = 1 << (sed1376Registers[DISP_MODE] & 0x07);
@@ -445,6 +436,6 @@ void sed1376Render(void){
else{
//black screen
memset(sed1376Framebuffer, 0x00, 160 * 160 * sizeof(uint16_t));
debugLog("Cant draw screen, LCD on:%s, PLL on:%s, power save on:%s, forced blank on:%s\n", palmMisc.lcdOn ? "true" : "false", pllIsOn() ? "true" : "false", sed1376PowerSaveEnabled() ? "true" : "false", !!(sed1376Registers[DISP_MODE] & 0x80) ? "true" : "false");
debugLog("Cant draw screen, LCD on:%s, PLL on:%s, power save on:%s, forced blank on:%s\n", palmMisc.lcdOn ? "true" : "false", dbvzIsPllOn() ? "true" : "false", sed1376PowerSaveEnabled() ? "true" : "false", !!(sed1376Registers[DISP_MODE] & 0x80) ? "true" : "false");
}
}

View File

@@ -117,5 +117,5 @@ static void selectRenderer(bool color, uint8_t bpp){
//updaters
static void updateLcdStatus(void){
palmMisc.lcdOn = !!(sed1376Registers[GPIO_CONT_0] & sed1376Registers[GPIO_CONF_0] & 0x20);
palmMisc.backlightLevel = !!(sed1376Registers[GPIO_CONT_0] & sed1376Registers[GPIO_CONF_0] & 0x10) ? (1 + backlightAmplifierState()) : 0;
palmMisc.backlightLevel = !!(sed1376Registers[GPIO_CONT_0] & sed1376Registers[GPIO_CONF_0] & 0x10) ? (1 + m515BacklightAmplifierState()) : 0;
}

File diff suppressed because it is too large Load Diff

View File

@@ -4,6 +4,5 @@
#include <stdint.h>
extern const uint16_t silkscreen160x60[];
extern const uint16_t silkscreen320x120[];
#endif

View File

@@ -10,18 +10,18 @@ These registers will do nothing if their corresponding feature bit is not set on
/*features*/
#define FEATURE_ACCURATE 0x00000000/*no hacks/addons*/
#define FEATURE_RAM_HUGE 0x00000001/*128mb RAM*/
/*FEATURE_UNUSED 0x00000001*/
#define FEATURE_FAST_CPU 0x00000002/*allows the emulator to set its CPU speed*/
#define FEATURE_HYBRID_CPU 0x00000004/*allows running ARM opcodes in an OS 4 enviroment*/
#define FEATURE_CUSTOM_FB 0x00000008/*allows rendering from a dynamically sized framebuffer in RAM*/
/*FEATURE_UNUSED 0x00000004*/
/*FEATURE_UNUSED 0x00000008*/
#define FEATURE_SYNCED_RTC 0x00000010/*RTC always equals host system time*/
#define FEATURE_HLE_APIS 0x00000020/*memcpy, memcmp, wait on timer will be replaced with the hosts function*/
#define FEATURE_EMU_HONEST 0x00000040/*tell the OS that its running in an emu, does nothing else*/
#define FEATURE_EXT_KEYS 0x00000080/*enables the OS 5 buttons, left, right and select*/
/*FEATURE_UNUSED 0x00000040*/
/*FEATURE_UNUSED 0x00000080*/
#define FEATURE_DEBUG 0x00000100/*enables the debug commands, used to call Palm OS functions like native C functions*/
/*FEATURE_UNUSED 0x00000200*/
#define FEATURE_DURABLE 0x00000200/*ignore behavior that would crash a real device*/
/*FEATURE_UNUSED 0x00000400*/
#define FEATURE_SND_STRMS 0x00000800/*enables OS 5 audio streams*/
/*FEATURE_UNUSED 0x00000800*/
/*new features go here*/
/*registers*/
@@ -47,20 +47,15 @@ These registers will do nothing if their corresponding feature bit is not set on
#define CMD_SET_CPU_SPEED 0x0000FFF3/*EMU_VALUE = CPU speed percent, 100% = normal*/
#define CMD_IDLE_X_CLK32 0x0000FFF4/*EMU_VALUE = CLK32s to waste, used to remove idle loops*/
#define CMD_SET_CYCLE_COST 0x0000FFF5/*EMU_DST = HLE API number, EMU_VALUE = how many cycles it takes*/
#define CMD_LCD_SET_FB 0x0000FFF6/*EMU_SRC = framebuffer pointer(must be in RAM and word aligned, unused if size is 160x220), EMU_VALUE >> 16 = width, EMU_VALUE & 0xFFFF = height*/
#define CMD_GET_KEYS 0x0000FFF7/*EMU_VALUE = OS 5 keys*/
/*CMD_UNUSED 0x0000FFF6*/
/*CMD_UNUSED 0x0000FFF7*/
#define CMD_DEBUG_PRINT 0x0000FFF8/*EMU_SRC = pointer to string*/
/*CMD_UNUSED 0x0000FFF9*/
#define CMD_SOUND 0x0000FFFA/*needed for OS 5 advanced sound*/
#define CMD_DEBUG_WATCH 0x0000FFF9/*EMU_VALUE = 0/clear watch reference or 1/make code watch reference or 2/make data watch reference, EMU_SRC = address of area(or watch area reference number), EMU_SIZE = size of area(unused if clear operation), EMU_VALUE is set to the watch areas reference number after a set operation*/
/*CMD_UNUSED 0x0000FFFA*/
#define CMD_DEBUG_EXEC_END 0x0000FFFB/*terminates execution, used when a function is called from outside the emulator*/
#define CMD_ARM_SERVICE 0x0000FFFC/*EMU_VALUE = 1 if ARM wants service from 68k routines*/
#define CMD_ARM_SET_REG 0x0000FFFD/*EMU_DST = register number, EMU_VALUE = new value*/
#define CMD_ARM_GET_REG 0x0000FFFE/*EMU_SRC = register number, EMU_VALUE = value after calling*/
#define CMD_ARM_RUN 0x0000FFFF/*EMU_VALUE = cycles, EMU_VALUE = cycles not used on return, 0 if all are used*/
/*buttons*/
#define EXT_BUTTON_LEFT 0x01000000
#define EXT_BUTTON_RIGHT 0x02000000
#define EXT_BUTTON_CENTER 0x04000000
/*CMD_UNUSED 0x0000FFFC*/
/*CMD_UNUSED 0x0000FFFD*/
/*CMD_UNUSED 0x0000FFFE*/
/*CMD_UNUSED 0x0000FFFF*/
#endif

40
tools/desktop/muStyle.xml Normal file
View File

@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorCodeStyle>
<!-- Written by QtCreator 4.8.2, 2019-04-17T12:35:14. -->
<qtcreator>
<data>
<variable>CodeStyleData</variable>
<valuemap type="QVariantMap">
<value type="bool" key="AlignAssignments">false</value>
<value type="bool" key="AutoSpacesForTabs">false</value>
<value type="bool" key="BindStarToIdentifier">false</value>
<value type="bool" key="BindStarToLeftSpecifier">false</value>
<value type="bool" key="BindStarToRightSpecifier">false</value>
<value type="bool" key="BindStarToTypeName">true</value>
<value type="bool" key="ExtraPaddingForConditionsIfConfusingAlign">true</value>
<value type="bool" key="IndentAccessSpecifiers">false</value>
<value type="bool" key="IndentBlockBody">true</value>
<value type="bool" key="IndentBlockBraces">false</value>
<value type="bool" key="IndentBlocksRelativeToSwitchLabels">true</value>
<value type="bool" key="IndentClassBraces">false</value>
<value type="bool" key="IndentControlFlowRelativeToSwitchLabels">true</value>
<value type="bool" key="IndentDeclarationsRelativeToAccessSpecifiers">true</value>
<value type="bool" key="IndentEnumBraces">false</value>
<value type="bool" key="IndentFunctionBody">true</value>
<value type="bool" key="IndentFunctionBraces">false</value>
<value type="bool" key="IndentNamespaceBody">false</value>
<value type="bool" key="IndentNamespaceBraces">false</value>
<value type="int" key="IndentSize">3</value>
<value type="bool" key="IndentStatementsRelativeToSwitchLabels">true</value>
<value type="bool" key="IndentSwitchLabels">true</value>
<value type="int" key="PaddingMode">2</value>
<value type="bool" key="ShortGetterName">true</value>
<value type="bool" key="SpacesForTabs">true</value>
<value type="int" key="TabSize">3</value>
</valuemap>
</data>
<data>
<variable>DisplayName</variable>
<value type="QString">Mu</value>
</data>
</qtcreator>

View File

@@ -19,7 +19,7 @@ These registers will do nothing if their corresponding feature bit is not set on
#define FEATURE_EMU_HONEST 0x00000040/*tell the OS that its running in an emu, does nothing else*/
#define FEATURE_EXT_KEYS 0x00000080/*enables the OS 5 buttons, left, right and select*/
#define FEATURE_DEBUG 0x00000100/*enables the debug commands, used to call Palm OS functions like native C functions*/
/*FEATURE_UNUSED 0x00000200*/
#define FEATURE_DURABLE 0x00000200/*ignore behavior that would crash a real device*/
/*FEATURE_UNUSED 0x00000400*/
#define FEATURE_SND_STRMS 0x00000800/*enables OS 5 audio streams*/
/*new features go here*/
@@ -48,15 +48,15 @@ These registers will do nothing if their corresponding feature bit is not set on
#define CMD_IDLE_X_CLK32 0x0000FFF4/*EMU_VALUE = CLK32s to waste, used to remove idle loops*/
#define CMD_SET_CYCLE_COST 0x0000FFF5/*EMU_DST = HLE API number, EMU_VALUE = how many cycles it takes*/
#define CMD_LCD_SET_FB 0x0000FFF6/*EMU_SRC = framebuffer pointer(must be in RAM and word aligned, unused if size is 160x220), EMU_VALUE >> 16 = width, EMU_VALUE & 0xFFFF = height*/
#define CMD_GET_KEYS 0x0000FFF7/*EMU_VALUE = OS 5 keys*/
#define CMD_GET_KEYS 0x0000FFF7/*EMU_VALUE is set to OS 5 keys value*/
#define CMD_DEBUG_PRINT 0x0000FFF8/*EMU_SRC = pointer to string*/
/*CMD_UNUSED 0x0000FFF9*/
#define CMD_DEBUG_WATCH 0x0000FFF9/*EMU_VALUE = 0/clear watch reference or 1/make code watch reference or 2/make data watch reference, EMU_SRC = address of area(or watch area reference number), EMU_SIZE = size of area(unused if clear operation), EMU_VALUE is set to the watch areas reference number after a set operation*/
#define CMD_SOUND 0x0000FFFA/*needed for OS 5 advanced sound*/
#define CMD_DEBUG_EXEC_END 0x0000FFFB/*terminates execution, used when a function is called from outside the emulator*/
#define CMD_ARM_SERVICE 0x0000FFFC/*EMU_VALUE = 1 if ARM wants service from 68k routines*/
#define CMD_ARM_SERVICE 0x0000FFFC/*EMU_VALUE is set to 1 if ARM wants service from m68k routines*/
#define CMD_ARM_SET_REG 0x0000FFFD/*EMU_DST = register number, EMU_VALUE = new value*/
#define CMD_ARM_GET_REG 0x0000FFFE/*EMU_SRC = register number, EMU_VALUE = value after calling*/
#define CMD_ARM_RUN 0x0000FFFF/*EMU_VALUE = cycles, EMU_VALUE = cycles not used on return, 0 if all are used*/
#define CMD_ARM_GET_REG 0x0000FFFE/*EMU_SRC = register number, EMU_VALUE is set to register value*/
#define CMD_ARM_RUN 0x0000FFFF/*EMU_VALUE = cycles, EMU_VALUE is set to cycles not used on return, 0 if all are used*/
/*buttons*/
#define EXT_BUTTON_LEFT 0x01000000

View File

@@ -1,51 +0,0 @@
#include "sdkPatch/PalmOSPatched.h"
#include <stdint.h>
#include "armv5.h"
#include "palmGlobalDefines.h"
#include "specs/emuFeatureRegisterSpec.h"
void armv5SetStack(uint8_t* location, uint32_t size){
armv5SetRegister(13, (uint32_t)location + size - sizeof(uint32_t));
}
void armv5StackPush(uint32_t value){
uint32_t stackPtr = armv5GetRegister(13);
stackPtr -= sizeof(uint32_t);
writeArbitraryMemory32(stackPtr, EndianSwap32(value));
armv5SetRegister(13, stackPtr);
}
uint32_t armv5StackPop(void){
uint32_t stackPtr = armv5GetRegister(13);
uint32_t value = EndianSwap32(readArbitraryMemory32(stackPtr));
stackPtr += sizeof(uint32_t);
armv5SetRegister(13, stackPtr);
return value;
}
void armv5SetRegister(uint8_t reg, uint32_t value){
writeArbitraryMemory32(EMU_REG_ADDR(EMU_DST), reg);
writeArbitraryMemory32(EMU_REG_ADDR(EMU_VALUE), value);
writeArbitraryMemory32(EMU_REG_ADDR(EMU_CMD), CMD_ARM_SET_REG);
}
uint32_t armv5GetRegister(uint8_t reg){
writeArbitraryMemory32(EMU_REG_ADDR(EMU_SRC), reg);
writeArbitraryMemory32(EMU_REG_ADDR(EMU_CMD), CMD_ARM_GET_REG);
return readArbitraryMemory32(EMU_REG_ADDR(EMU_VALUE));
}
int32_t armv5Execute(int32_t cycles){
writeArbitraryMemory32(EMU_REG_ADDR(EMU_VALUE), cycles);
writeArbitraryMemory32(EMU_REG_ADDR(EMU_CMD), CMD_ARM_RUN);
return readArbitraryMemory32(EMU_REG_ADDR(EMU_VALUE));
}
Boolean armv5NeedsService(void){
writeArbitraryMemory32(EMU_REG_ADDR(EMU_CMD), CMD_ARM_SERVICE);
return readArbitraryMemory32(EMU_REG_ADDR(EMU_VALUE));
}

View File

@@ -1,15 +0,0 @@
#ifndef ARMV5_H
#define ARMV5_H
#include "sdkPatch/PalmOSPatched.h"
#include <stdint.h>
void armv5SetStack(uint8_t* location, uint32_t size);
void armv5StackPush(uint32_t value);
uint32_t armv5StackPop(void);
void armv5SetRegister(uint8_t reg, uint32_t value);
uint32_t armv5GetRegister(uint8_t reg);
int32_t armv5Execute(int32_t cycles);
Boolean armv5NeedsService(void);
#endif

View File

@@ -1,75 +0,0 @@
*-----------------------------------------------------------
* Title :m68kCallWithBlob
* Written by :meepingsnesroms
*-----------------------------------------------------------
ORG $1000
START: ; first instruction of program
;setup fake OS enviroment
lea stack, sp
move.l #$12345678, a0
move.l #$87654321, d0
;setup stack
sub.l #2, sp
move.w #1, (sp)
pea (6)
pea stackBlob
pea functionTest
jsr m68kCallWithBlobFunc
SIMHALT
;uint32_t m68kCallWithBlobFunc(uint32_t functionAddress, uint32_t stackBlob, uint32_t stackBlobSize, uint16_t returnA0);
;Extract:vvv
m68kCallWithBlobFunc:
link a6,#0
movem.l d1-d2/a1-a3,-(sp)
move.l 8(a6), a3 ;function
move.l 12(a6), a1 ;stackBlob
move.l 16(a6), d1 ;stackBlobSize
move.w 20(a6), d2 ;returnA0
move.l sp, a2
sub.l d1, a2
copy:
cmp.l a2, sp
beq done
move.w (a1), (a2)
add.l #2, a1
add.l #2, a2
bra copy
done:
;update SP with new stack
sub.l d1, sp
jsr (a3)
add.l d1, sp
;new stack has been used and removed, SP is safe again
tst.w d2
beq useD0
move.l a0, d0
useD0:
movem.l (sp)+,d1-d2/a1-a3
unlk a6
rts
;Extract:^^^
functionTest:
;test that calling works and the return value respects returnA0
move.l #$10101010, a0
rts
;Stack
ORG $2000
stack:
dc.w $0, $0, $0
;Variables
ORG $3000
stackBlob:
dc.w $1, $2, $3
END START ; last line of source
*~Font name~Courier New~
*~Font size~10~
*~Tab type~1~
*~Tab size~4~

View File

@@ -1,3 +0,0 @@
m68kCallWithBlob.x68 is compiled in EASy68K, after export the code in-between the "Extract:vvv", "Extract:^^^" tags
This is for testing purposes, as I can't debug virtual hardware on a real Palm device.

View File

@@ -11,10 +11,6 @@ static void getConfigDefaults(uint32_t* configFile){
configFile[USER_WARNING_GIVEN] = false;
configFile[DRIVER_ENABLED] = false;
configFile[SAFE_MODE] = false;
configFile[ARM_STACK_SIZE] = 0x1000;
configFile[LCD_WIDTH] = 160;
configFile[LCD_HEIGHT] = 220;
configFile[EXTRA_RAM_MB_DYNAMIC_HEAP] = 10;
configFile[BOOT_CPU_SPEED] = 100;
configFile[PATCH_INCONSISTENT_APIS] = false;
}

View File

@@ -7,20 +7,11 @@
#define APP_NAME "MuExpDriver"
#define APP_ID 'MuDv'
#define FUNCTION_BLOB_TYPE 'func'
#define ARM_EXIT_FUNC_ID 0x0000
#define ARM_CALL_68K_FUNC_ID 0x0001
#define M68K_CALL_WITH_BLOB_FUNC_ID 0x0002
/*config vars*/
enum{
USER_WARNING_GIVEN = 0,
DRIVER_ENABLED,
SAFE_MODE,
ARM_STACK_SIZE,
LCD_WIDTH,
LCD_HEIGHT,
EXTRA_RAM_MB_DYNAMIC_HEAP,
BOOT_CPU_SPEED,
PATCH_INCONSISTENT_APIS,
/*add new entries above*/

View File

@@ -1,4 +1,5 @@
#include "sdkPatch/PalmOSPatched.h"
#include <stdint.h>
#include <stdarg.h>
#include "palmGlobalDefines.h"
@@ -19,3 +20,22 @@ void debugLog(const char* format, ...){
va_end(va);
}
#endif
uint16_t setWatchRegion(uint32_t address, uint32_t size, uint8_t type){
writeArbitraryMemory32(EMU_REG_ADDR(EMU_VALUE), type);
writeArbitraryMemory32(EMU_REG_ADDR(EMU_SRC), address);
writeArbitraryMemory32(EMU_REG_ADDR(EMU_SIZE), size);
writeArbitraryMemory32(EMU_REG_ADDR(EMU_CMD), CMD_DEBUG_WATCH);
return readArbitraryMemory32(EMU_REG_ADDR(EMU_VALUE));
}
void clearWatchRegion(uint16_t index){
writeArbitraryMemory32(EMU_REG_ADDR(EMU_VALUE), 0);
writeArbitraryMemory32(EMU_REG_ADDR(EMU_SRC), index);
writeArbitraryMemory32(EMU_REG_ADDR(EMU_CMD), CMD_DEBUG_WATCH);
}
void watchAppCode(const char* appName){
/*marks app code resources as debug watch areas*/
}

View File

@@ -1,12 +1,23 @@
#ifndef DEBUG_H
#define DEBUG_H
#include <stdint.h>
#include <stdarg.h>
enum{
MEMORY_WATCH_NONE = 0,
MEMORY_WATCH_CODE,
MEMORY_WATCH_DATA
};
#ifdef DEBUG
void debugLog(const char* format, ...);
#else
#define debugLog(...)
#endif
uint16_t setWatchRegion(uint32_t address, uint32_t size, uint8_t type);
void clearWatchRegion(uint16_t index);
void watchAppCode(const char* appName);
#endif

View File

@@ -1,10 +0,0 @@
This project can't use global variables, its executed without being launched so writing to globals will corrupt the currently running application, reading will just retrieve random numbers or crash because of invalid access.
*.func files are binary blobs containing ASM code to perform sensitive functions:
m68kCallWithBlob.func is 68k ASM that copys the stack args blob requested by the armCall68k.func to the 68k stack and executes the function pointer returning A0 or D0
armCall68k.func is ARM asm that sets up a path back to 68k code without ending ARM execution
armExit.func is ARM asm that terminates ARM execution
m68kCallWithBlob.func function prototype is:
uint32_t m68kCallWithBlobFunc(uint32_t functionAddress, uint32_t stackBlob, uint32_t stackBlobSize, uint16_t returnA0);
The smallest type on the 68k stack allowed is uint16_t, this is because of alignment restrictions.

View File

@@ -4,14 +4,7 @@
#include <stdint.h>
enum{
ARM_STACK_START = 0,
ARM_EXIT_FUNC,
ARM_CALL_68K_FUNC,
M68K_CALL_WITH_BLOB_FUNC,
RESOURCE_GLOBALS_INITIALIZED,
TUNGSTEN_W_DRIVERS_INSTALLED,
CURRENT_RESOLUTION,
ORIGINAL_FRAMEBUFFER
EMPTY_LIST = 0
};
uint32_t getGlobalVar(uint16_t id);

View File

@@ -1,196 +0,0 @@
#include "sdkPatch/PalmOSPatched.h"
#include <stdint.h>
#include "debug.h"
#include "globals.h"
#include "traps.h"
#include "palmOsPriv.h"
#include "palmGlobalDefines.h"
#include "specs/emuFeatureRegisterSpec.h"
typedef struct{
BitmapTypeV3 bitmap;
uint16_t* data;
}BitmapTypeV3Indirect;
static Boolean setTungstenWDriverFramebuffer(uint16_t width, uint16_t height){
if(getGlobalVar(TUNGSTEN_W_DRIVERS_INSTALLED)){
BitmapTypeV3Indirect* newBitmap;
int16_t newBitmapWidth;
int16_t newBitmapHeight;
WindowType* driverWindow;
Err error;
/*remove special cases for the presence of a silkscreen, they would waste extra memory*/
if(width == 160 && height == 220){
newBitmapWidth = 160;
newBitmapHeight = 160;
}
else if(width == 320 && height == 440){
newBitmapWidth = 320;
newBitmapHeight = 320;
}
else{
newBitmapWidth = width;
newBitmapHeight = height;
}
driverWindow = WinGetWindowPointer(WinGetDisplayWindow());
newBitmap = MemChunkNew(0, sizeof(BitmapTypeV3Indirect), memNewChunkFlagPreLock | memNewChunkFlagNonMovable | memNewChunkFlagAllowLarge);
if(!newBitmap){
debugLog("Couldnt create new framebuffer bitmap struct!\n");
return false;
}
error = MemSet(newBitmap, sizeof(BitmapTypeV3Indirect), 0x00);
if(error != errNone)
debugLog("Couldnt clear bitmap struct:%d\n", error);
/*build bitmap manually to prevent having to duplicate a V2 bitmap*/
newBitmap->bitmap.width = newBitmapWidth;
newBitmap->bitmap.height = newBitmapHeight;
newBitmap->bitmap.rowBytes = newBitmapWidth * sizeof(uint16_t);
newBitmap->bitmap.flags.indirect = true;
newBitmap->bitmap.flags.forScreen = false;/*this is a lie, it is for the screen, but no screen rendering routines should be used*/
newBitmap->bitmap.flags.directColor = true;
newBitmap->bitmap.size = sizeof(BitmapTypeV3);
newBitmap->bitmap.pixelFormat = pixelFormat565;
newBitmap->bitmap.compressionType = BitmapCompressionTypeNone;
newBitmap->bitmap.density = kDensityDouble;
newBitmap->data = MemChunkNew(0, newBitmapWidth * newBitmapHeight * sizeof(uint16_t), memNewChunkFlagPreLock | memNewChunkFlagNonMovable | memNewChunkFlagAllowLarge);
if(!newBitmap->data){
debugLog("Couldnt create new framebuffer!\n");
return false;
}
/*white out framebuffer*/
/*this dident work?*/
error = MemSet(newBitmap->data, newBitmapWidth * newBitmapHeight * sizeof(uint16_t), 0xFF);
if(error != errNone)
debugLog("Couldnt clear framebuffer:%d\n", error);
/*clean up old framebuffer if its not the original one and set new one*/
/*driverWindow->bitmapP->flags.forScreen = false;*/
/*BmpDelete(driverWindow->bitmapP);*/
driverWindow->bitmapP = (BitmapType*)&newBitmap->bitmap;
/*tell the emu where the framebuffer is*/
writeArbitraryMemory32(EMU_REG_ADDR(EMU_SRC), (uint32_t)newBitmap->data);
writeArbitraryMemory32(EMU_REG_ADDR(EMU_VALUE), (uint32_t)width << 16 | height);
writeArbitraryMemory32(EMU_REG_ADDR(EMU_CMD), CMD_LCD_SET_FB);
return true;
}
/*driver is not loaded, cant set window*/
return false;
}
Boolean installTungstenWLcdDrivers(void){
/*check that all driver files are installed and launch drivers boot entrypoints*/
if(!getGlobalVar(TUNGSTEN_W_DRIVERS_INSTALLED)){
#if 1
LocalID database;
DmOpenRef highDensityDisplay;
MemHandle highDensityDisplayInitHandle;
void (*installHighDensityDisplay)(void);
/*Hi Res Blitter.prc, this is the Tungsten W GPU driver, this will crash the device so dont install it*/
/*PRC ID:bhal hire*/
/*Resource ID:boot0000*/
/*HighDensityFonts.prc, font pack, only need to check if present*/
/*PRC ID:data hidd*/
/*Resource ID:nfnt????*/
database = DmFindDatabase(0, "HighDensityFonts");
if(!database){
/*file does not exist*/
debugLog("HighDensityFonts.prc not installed!\n");
return false;
}
/*HighDensityDisplay.prc, HAL addon, need to jump to exte0000*/
/*PRC ID:extn hidd*/
/*Resource ID:????????*/
database = DmFindDatabase(0, "HighDensityDisplay");
if(!database){
/*file does not exist*/
debugLog("HighDensityDisplay.prc not installed!\n");
return false;
}
highDensityDisplay = DmOpenDatabase(0, database, dmModeReadOnly);
if(!highDensityDisplay){
/*cant open file*/
debugLog("Cant open HighDensityDisplay.prc!\n");
return false;
}
highDensityDisplayInitHandle = DmGetResource('exte', 0x0000);
if(!highDensityDisplayInitHandle){
/*cant open file resource*/
debugLog("Cant open HighDensityDisplay.prc exte0000!\n");
return false;
}
installHighDensityDisplay = (void(*)(void))MemHandleLock(highDensityDisplayInitHandle);
/*backup original LCD window for SED1376*/
setGlobalVar(ORIGINAL_FRAMEBUFFER, (uint32_t)WinGetBitmap(WinGetDisplayWindow()));
debugLog("Attempting Tungsten W driver install!\n");
/*patch HwrDisplayAttributes before running so driver will install*/
SysSetTrapAddress(sysTrapHwrDisplayAttributes, emuHwrDisplayAttributes);
/*remove things that cause crashes*/
SysSetTrapAddress(sysTrapScrDrawChars, emuScrDrawChars);
/*run HighDensityDisplay.prc exte0000*/
installHighDensityDisplay();
debugLog("Tungsten W drivers installed!\n");
/*close everything*/
MemHandleUnlock(highDensityDisplayInitHandle);
DmCloseDatabase(highDensityDisplay);
#endif
/*success*/
setGlobalVar(TUNGSTEN_W_DRIVERS_INSTALLED, true);
return true;
}
debugLog("Tungsten W drivers already installed!\n");
/*already installed*/
return true;
}
Boolean setDeviceResolution(uint16_t width, uint16_t height){
uint32_t oldResolution = getGlobalVar(CURRENT_RESOLUTION);
uint32_t newResolution = (uint32_t)width << 16 | height;
debugLog("Setting custom FB size w:%d, h:%d\n", width, height);
if(newResolution != oldResolution){
if(!setTungstenWDriverFramebuffer(width, height))
return false;
setGlobalVar(CURRENT_RESOLUTION, newResolution);
}
return true;
}
void screenSignalApplicationStart(void){
/*nothing for now*/
}
void screenSignalApplicationExit(void){
/*put back all defaults, apps must signal they support hires before its enabled and its disabled again when the app is closed*/
setDeviceResolution(160, 220);
}

View File

@@ -1,12 +0,0 @@
#ifndef HIRES_H
#define HIRES_H
#include "sdkPatch/PalmOSPatched.h"
#include <stdint.h>
Boolean installTungstenWLcdDrivers(void);
Boolean setDeviceResolution(uint16_t width, uint16_t height);
void screenSignalApplicationStart(void);
void screenSignalApplicationExit(void);
#endif

View File

@@ -11,7 +11,7 @@ if [ "$1" = "clean" ]; then
exit
fi
declare -a FILES=("muExpDriver" "patcher" "hires" "armv5" "soundDriver" "globals" "gui" "traps" "config" "debug" "memalign")
declare -a FILES=("muExpDriver" "patcher" "globals" "gui" "traps" "config" "debug")
CFLAGS="-palmos4 -O3"
if [ "$1" = "debug" ]; then
@@ -23,11 +23,6 @@ for I in "${FILES[@]}"; do
done
m68k-palmos-gcc -o $APP_NAME *.o
# copy ASM blobs
cp ./blobs/armExit.func ./func0000.bin # ARM code
cp ./blobs/armCall68k.func ./func0001.bin # ARM code
cp ./blobs/m68kCallWithBlob.func ./func0002.bin # 68k code
# if possible generate icon trees
if type "MakePalmBitmap" &> /dev/null; then
MakePalmBitmap icon ./appIcon.svg ./

View File

@@ -1,29 +0,0 @@
/*modified from libretro-common*/
#include "sdkPatch/PalmOSPatched.h"
#include <stdint.h>
void* memalign_alloc(uint32_t boundary, uint32_t size){
void** place = NULL;
uint32_t addr = 0;
void* ptr = (void*)MemPtrNew(boundary + size + sizeof(uint32_t));
if(!ptr)
return NULL;
addr = ((uint32_t)ptr + sizeof(uint32_t) + boundary) & ~(boundary - 1);
place = (void**)addr;
place[-1] = ptr;
return (void*)addr;
}
void memalign_free(void* ptr){
void** p = NULL;
if(!ptr)
return;
p = (void**)ptr;
free(p[-1]);
}

View File

@@ -1,10 +0,0 @@
/*modified from libretro-common*/
#ifndef MEMALIGN_H
#define MEMALIGN_H
#include <stdint.h>
void* memalign_alloc(uint32_t boundary, uint32_t size);
void memalign_free(void* ptr);
#endif

View File

@@ -3,10 +3,11 @@
#include <stdint.h>
#define CODE_SECTION(codeSection) __attribute__((section(codeSection)))
#define SECTION(codeSection) __attribute__((section(codeSection)))
#define NO_RETURN __attribute__((noreturn))
#define ALIGN(size) __attribute__((aligned(size)))
#define FIXED_ADDRESS_VAR(a, t) (*((volatile t*)a))
#define PACKED __attribute__((packed))
#define FIXED_ADDRESS_VAR(a, t) (*((t volatile *)a))
#define readArbitraryMemory8(address) (*((volatile uint8_t*)(address)))
#define readArbitraryMemory16(address) (*((volatile uint16_t*)(address)))

View File

@@ -1,6 +1,7 @@
#ifndef PALM_OS_PRIV_H
#define PALM_OS_PRIV_H
#include <stdint.h>
#include "palmGlobalDefines.h"
/*these are all the Palm OS varibles the SDK dosent expose that I have found while decompiling Palm OS*/
@@ -12,6 +13,7 @@
#define ResetVector FIXED_ADDRESS_VAR(0x00000004, void*)
/*OS*/
#define TrapTablePtr FIXED_ADDRESS_VAR(0x00000122, void**)
#define ScrStatePtr FIXED_ADDRESS_VAR(0x00000164, void*)
#endif

View File

@@ -4,10 +4,8 @@
#include "debug.h"
#include "config.h"
#include "traps.h"
#include "armv5.h"
#include "hires.h"
#include "globals.h"
#include "memalign.h"
#include "palmOsPriv.h"
#include "palmGlobalDefines.h"
#include "specs/emuFeatureRegisterSpec.h"
@@ -28,102 +26,6 @@ static void lockCodeXXXX(void){
}
}
static void installResourceGlobals(void){
if(!getGlobalVar(RESOURCE_GLOBALS_INITIALIZED)){
MemHandle funcBlob;
MemPtr funcBlobPtr;
/*ARM_EXIT_FUNC*/
funcBlob = DmGetResource(FUNCTION_BLOB_TYPE, ARM_EXIT_FUNC_ID);
if(!funcBlob)
debugLog("Cant open ARM_EXIT_FUNC!\n");
funcBlobPtr = MemHandleLock(funcBlob);
if(!funcBlobPtr)
debugLog("Cant lock ARM_EXIT_FUNC!\n");
if((uint32_t)funcBlobPtr & 0x00000003)
debugLog("ARM_EXIT_FUNC is unaligned!\n");
setGlobalVar(ARM_EXIT_FUNC, (uint32_t)funcBlobPtr);
/*ARM_CALL_68K_FUNC*/
funcBlob = DmGetResource(FUNCTION_BLOB_TYPE, ARM_CALL_68K_FUNC_ID);
if(!funcBlob)
debugLog("Cant open ARM_CALL_68K_FUNC!\n");
funcBlobPtr = MemHandleLock(funcBlob);
if(!funcBlobPtr)
debugLog("Cant lock ARM_CALL_68K_FUNC!\n");
if((uint32_t)funcBlobPtr & 0x00000003)
debugLog("ARM_CALL_68K_FUNC is unaligned!\n");
setGlobalVar(ARM_CALL_68K_FUNC, (uint32_t)funcBlobPtr);
/*M68K_CALL_WITH_BLOB_FUNC*/
funcBlob = DmGetResource(FUNCTION_BLOB_TYPE, M68K_CALL_WITH_BLOB_FUNC_ID);
if(!funcBlob)
debugLog("Cant open M68K_CALL_WITH_BLOB_FUNC!\n");
funcBlobPtr = MemHandleLock(funcBlob);
if(!funcBlobPtr)
debugLog("Cant lock M68K_CALL_WITH_BLOB_FUNC!\n");
if((uint32_t)funcBlobPtr & 0x00000001)
debugLog("M68K_CALL_WITH_BLOB_FUNC is unaligned!\n");
setGlobalVar(M68K_CALL_WITH_BLOB_FUNC, (uint32_t)funcBlobPtr);
/*dont run this function again*/
setGlobalVar(RESOURCE_GLOBALS_INITIALIZED, true);
}
}
static void install128mbRam(uint8_t mbDynamicHeap){
/*these functions are called by HwrInit, which can be called directly by apps*/
/*PrvGetRAMSize_10002C5E, small ROM*/
/*PrvGetRAMSize_1008442E, big ROM*/
/*HwrPreDebugInit_10002B06, small ROM*/
/*HwrPreDebugInit_100842DC, big ROM, sets up the default RAM card*/
/*HwrCalcDynamicHeapSize_10005D10, small ROM*/
/*HwrCalcDynamicHeapSize_10083B54, big ROM, sets up the heap size*/
/*installs a new virtual card with the extra RAM(128mb - 16mb)*/
/*
Err MemCardFormat(UInt16 cardNo, const Char *cardNameP,
const Char *manufNameP, const Char *ramStoreNameP)
SYS_TRAP(sysTrapMemCardFormat);
*/
/*
Err MemStoreSetInfo(UInt16 cardNo, UInt16 storeNumber,
UInt16 *versionP, UInt16 *flagsP, Char *nameP,
UInt32 *crDateP, UInt32 *bckUpDateP,
UInt32 *heapListOffsetP, UInt32 *initCodeOffset1P,
UInt32 *initCodeOffset2P, LocalID* databaseDirIDP)
SYS_TRAP(sysTrapMemStoreSetInfo);
*/
}
static void installPceNativeCallHandler(uint32_t armStackSize){
uint8_t* oldArmStack = (uint8_t*)getGlobalVar(ARM_STACK_START);
uint8_t* armStackStart;
SysSetTrapAddress(sysTrapPceNativeCall, (void*)emuPceNativeCall);
if(oldArmStack)
memalign_free(oldArmStack);
/*must have 32 bit aligned size and start*/
armStackSize &= 0xFFFFFFFC;
armStackStart = memalign_alloc(sizeof(uint32_t), armStackSize);
armv5SetStack(armStackStart, armStackSize);
setGlobalVar(ARM_STACK_START, (uint32_t)armStackStart);
}
static void installDebugHandlers(void){
void* sysUnimplementedAddress = SysGetTrapAddress(sysTrapSysUnimplemented);
uint16_t index;
@@ -135,101 +37,9 @@ static void installDebugHandlers(void){
/*eventually should remove the NULL check too, the trap list should have no NULL values*/
if(trapAddress == sysUnimplementedAddress || trapAddress == NULL)
SysSetTrapAddress(index, (void*)emuSysUnimplemented);
TrapTablePtr[index - sysTrapBase] = (void*)emuSysUnimplemented;
}
SysSetTrapAddress(sysTrapErrDisplayFileLineMsg, (void*)emuErrDisplayFileLineMsg);
}
static void setProperDeviceId(uint16_t screenWidth, uint16_t screenHeight, Boolean hasArmCpu, Boolean hasDpad){
uint32_t osVer;
uint32_t companyId;
uint32_t deviceId;
uint32_t halId;
if(hasArmCpu){
/*get matching OS 5 device*/
switch((uint32_t)screenWidth << 16 | screenHeight){
case (uint32_t)480 << 16 | 320:
/*Tapwave Zodiac 2*/
osVer = sysMakeROMVersion(5, 4, 0, sysROMStageRelease, 0);/*needs to be verifyed!!!*/
companyId = 'Tpwv';
deviceId = 'Rdog';
halId = 'MX1a';
break;
case (uint32_t)320 << 16 | 440:
/*Tungsten E2*/
osVer = sysMakeROMVersion(5, 4, 0, sysROMStageRelease, 0);/*needs to be verifyed!!!*/
companyId = 'Palm';
deviceId = 'Zir4';
halId = 'hspr';
break;
default:
/*use Palm Z22, has the same resolution as the Palm m515*/
osVer = sysMakeROMVersion(5, 4, 0, sysROMStageRelease, 0);/*needs to be verifyed!!!*/
companyId = 'Palm';
deviceId = 'D051';
halId = 'S051';
break;
}
}
else{
/*get matching OS 4 device*/
switch((uint32_t)screenWidth << 16 | screenHeight){
case (uint32_t)320 << 16 | 440:
/*Tungsten E running OS 4*/
/*there are no 320x320 + digitizer, 16 bit color, OS 4 devices*/
/*this is not a real device, using it may cause issues*/
FtrGet(sysFileCSystem, sysFtrNumROMVersion, &osVer);
companyId = 'Palm';
deviceId = 'Cct1';
halId = 'Ect1';
break;
case (uint32_t)320 << 16 | 320:
/*Tungsten W*/
osVer = sysMakeROMVersion(4, 1, 0, sysROMStageRelease, 0);/*needs to be verifyed!!!*/
companyId = 'palm';
deviceId = 'atc1';
halId = 'atlc';
break;
default:
/*use device defaults*/
FtrGet(sysFileCSystem, sysFtrNumROMVersion, &osVer);
FtrGet(sysFileCSystem, sysFtrNumOEMCompanyID, &companyId);
FtrGet(sysFileCSystem, sysFtrNumOEMDeviceID, &deviceId);
FtrGet(sysFileCSystem, sysFtrNumOEMHALID, &halId);
break;
}
}
/*set CPU ID*/
if(hasArmCpu)
FtrSet(sysFtrCreator, sysFtrNumProcessorID, sysFtrNumProcessorXscale);
else
FtrSet(sysFtrCreator, sysFtrNumProcessorID, sysFtrNumProcessorVZ);
/*enable dpad API*/
if(hasDpad)
FtrSet(navFtrCreator, navFtrVersion, navVersion);
else
FtrUnregister(navFtrCreator, navFtrVersion);
/*no fixed digitizer, enable digitizer APIs*/
if(screenHeight != 220 && screenHeight != 440)
FtrSet(pinCreator, pinFtrAPIVersion, pinAPIVersion1_1);
else
FtrUnregister(pinCreator, pinFtrAPIVersion);
/*later Sony specific stuff may go here to allow running Clie apps*/
/*later Tapwave specific stuff may go here to allow running Zodiac apps*/
FtrSet(sysFileCSystem, sysFtrNumROMVersion, osVer);
FtrSet(sysFileCSystem, sysFtrNumOEMCompanyID, companyId);
FtrSet(sysFileCSystem, sysFtrNumOEMDeviceID, deviceId);
FtrSet(sysFileCSystem, sysFtrNumOEMHALID, halId);
TrapTablePtr[sysTrapErrDisplayFileLineMsg - sysTrapBase] = (void*)emuErrDisplayFileLineMsg;
}
void initBoot(uint32_t* configFile){
@@ -270,24 +80,12 @@ void initBoot(uint32_t* configFile){
if(!thisAppRef)
debugLog("Cant open " APP_NAME "!\n");
/*prevents the code being moved out from underneath its function pointers(in the API trap table), causing crashes*/
lockCodeXXXX();
installResourceGlobals();
if(enabledFeatures & FEATURE_DEBUG)
installDebugHandlers();
if(enabledFeatures & FEATURE_RAM_HUGE)
install128mbRam(configFile[EXTRA_RAM_MB_DYNAMIC_HEAP]);
if(enabledFeatures & FEATURE_HYBRID_CPU)
installPceNativeCallHandler(configFile[ARM_STACK_SIZE]);
if(enabledFeatures & FEATURE_CUSTOM_FB)
if(installTungstenWLcdDrivers())
setDeviceResolution(configFile[LCD_WIDTH], configFile[LCD_HEIGHT]);
setProperDeviceId(configFile[LCD_WIDTH], configFile[LCD_HEIGHT], !!(enabledFeatures & FEATURE_HYBRID_CPU), !!(enabledFeatures & FEATURE_EXT_KEYS));
writeArbitraryMemory32(EMU_REG_ADDR(EMU_VALUE), configFile[BOOT_CPU_SPEED]);
writeArbitraryMemory32(EMU_REG_ADDR(EMU_CMD), CMD_SET_CPU_SPEED);
@@ -296,7 +94,3 @@ void initBoot(uint32_t* configFile){
writeConfigFile(configFile);
}
}
void reinit(uint32_t* configFile){
/*TODO*/
}

View File

@@ -4,6 +4,5 @@
#include <stdint.h>
void initBoot(uint32_t* configFile);
void reinit(uint32_t* configFile);
#endif

View File

@@ -1 +0,0 @@

View File

@@ -1 +0,0 @@

View File

@@ -19,7 +19,7 @@ These registers will do nothing if their corresponding feature bit is not set on
#define FEATURE_EMU_HONEST 0x00000040/*tell the OS that its running in an emu, does nothing else*/
#define FEATURE_EXT_KEYS 0x00000080/*enables the OS 5 buttons, left, right and select*/
#define FEATURE_DEBUG 0x00000100/*enables the debug commands, used to call Palm OS functions like native C functions*/
/*FEATURE_UNUSED 0x00000200*/
#define FEATURE_DURABLE 0x00000200/*ignore behavior that would crash a real device*/
/*FEATURE_UNUSED 0x00000400*/
#define FEATURE_SND_STRMS 0x00000800/*enables OS 5 audio streams*/
/*new features go here*/
@@ -48,15 +48,15 @@ These registers will do nothing if their corresponding feature bit is not set on
#define CMD_IDLE_X_CLK32 0x0000FFF4/*EMU_VALUE = CLK32s to waste, used to remove idle loops*/
#define CMD_SET_CYCLE_COST 0x0000FFF5/*EMU_DST = HLE API number, EMU_VALUE = how many cycles it takes*/
#define CMD_LCD_SET_FB 0x0000FFF6/*EMU_SRC = framebuffer pointer(must be in RAM and word aligned, unused if size is 160x220), EMU_VALUE >> 16 = width, EMU_VALUE & 0xFFFF = height*/
#define CMD_GET_KEYS 0x0000FFF7/*EMU_VALUE = OS 5 keys*/
#define CMD_GET_KEYS 0x0000FFF7/*EMU_VALUE is set to OS 5 keys value*/
#define CMD_DEBUG_PRINT 0x0000FFF8/*EMU_SRC = pointer to string*/
/*CMD_UNUSED 0x0000FFF9*/
#define CMD_DEBUG_WATCH 0x0000FFF9/*EMU_VALUE = 0/clear watch reference or 1/make code watch reference or 2/make data watch reference, EMU_SRC = address of area(or watch area reference number), EMU_SIZE = size of area(unused if clear operation), EMU_VALUE is set to the watch areas reference number after a set operation*/
#define CMD_SOUND 0x0000FFFA/*needed for OS 5 advanced sound*/
#define CMD_DEBUG_EXEC_END 0x0000FFFB/*terminates execution, used when a function is called from outside the emulator*/
#define CMD_ARM_SERVICE 0x0000FFFC/*EMU_VALUE = 1 if ARM wants service from 68k routines*/
#define CMD_ARM_SERVICE 0x0000FFFC/*EMU_VALUE is set to 1 if ARM wants service from m68k routines*/
#define CMD_ARM_SET_REG 0x0000FFFD/*EMU_DST = register number, EMU_VALUE = new value*/
#define CMD_ARM_GET_REG 0x0000FFFE/*EMU_SRC = register number, EMU_VALUE = value after calling*/
#define CMD_ARM_RUN 0x0000FFFF/*EMU_VALUE = cycles, EMU_VALUE = cycles not used on return, 0 if all are used*/
#define CMD_ARM_GET_REG 0x0000FFFE/*EMU_SRC = register number, EMU_VALUE is set to register value*/
#define CMD_ARM_RUN 0x0000FFFF/*EMU_VALUE = cycles, EMU_VALUE is set to cycles not used on return, 0 if all are used*/
/*buttons*/
#define EXT_BUTTON_LEFT 0x01000000

View File

@@ -1,9 +1,8 @@
#include "sdkPatch/PalmOSPatched.h"
#include <stdint.h>
#include "debug.h"
#include "armv5.h"
#include "traps.h"
#include "debug.h"
#include "globals.h"
#include "palmOsPriv.h"
#include "palmGlobalDefines.h"
@@ -13,82 +12,6 @@
/*functions in this file are called directly by the Palm OS trap dispatch, this means they can be called when the app isnt loaded and the globals are just a random data buffer*/
UInt32 emuPceNativeCall(NativeFuncType* nativeFuncP, void* userDataP){
uint8_t* armExitFunc = (uint8_t*)getGlobalVar(ARM_EXIT_FUNC);
uint8_t* armCall68kFunc = (uint8_t*)getGlobalVar(ARM_CALL_68K_FUNC);
uint8_t* m68kCallWithBlobFunc = (uint8_t*)getGlobalVar(M68K_CALL_WITH_BLOB_FUNC);
uint32_t oldArmRegisters[5];
uint32_t returnValue;
/*AAPCS calling convention*/
/*on a function call R0<->R3 store the function arguments if they fit, extras will go on the stack*/
/*first arg goes in R0, second in R1, ..., up to 4 args can go in registers*/
/*on function return R0 and R1 store the return value of the last function, R1 is only used if the return value is 64 bit*/
/*R4<->R7 are always local variables*/
/*My dual CPU calling convention, called when ARM opcode 0xF7BBBBBB is run*/
/*R0 = 0 is execution finished, R0 = 1 is run function*/
/*when R0 = 1, R1 = function to execute, R2 = stack blob, R3 = stack blob size and want A0*/
debugLog("Called ARM function:0x%08lX\n", (uint32_t)nativeFuncP);
/*save old ARM state, needed if this function is called recursively*/
/*(68k(normal mode)->PceNativeCall->...->Call68kFunc->...->PceNativeCall(this could corrupt old args if they arnt backed up!!!))*/
oldArmRegisters[0] = armv5GetRegister(0);
oldArmRegisters[1] = armv5GetRegister(1);
oldArmRegisters[2] = armv5GetRegister(2);
oldArmRegisters[3] = armv5GetRegister(14);
oldArmRegisters[4] = armv5GetRegister(15);
armv5SetRegister(0, 0x0000000);/*emulStateP is unusesd*/
armv5SetRegister(1, (uint32_t)userDataP);
armv5SetRegister(2, (uint32_t)armCall68kFunc);
armv5SetRegister(14, (uint32_t)armExitFunc);/*set link register to return location*/
armv5SetRegister(15, (uint32_t)nativeFuncP);/*set program counter to function*/
while(true){
armv5Execute(100);/*run 100 opcodes, returns instantly with cycles remaining when service is needed*/
if(armv5NeedsService()){
/*ARM tried to call a 68k function or has finished executing*/
if(armv5GetRegister(0)){
/*call function*/
uint32_t function = armv5GetRegister(1);
uint32_t stackBlob = armv5GetRegister(2);
uint32_t stackBlobSizeAndWantA0 = armv5GetRegister(3);
uint32_t (*m68kCallWithBlobFuncPtr)(uint32_t functionAddress, uint32_t stackBlob, uint32_t stackBlobSize, uint16_t returnA0) = (uint32_t (*)(uint32_t, uint32_t, uint32_t, uint16_t))m68kCallWithBlobFunc;
/*API call, convert to address first*/
if(function < 0x1000)
function = (uint32_t)SysGetTrapAddress(0xA000 | function);
/*return whatever the 68k function did*/
armv5SetRegister(0, m68kCallWithBlobFuncPtr(function, stackBlob, stackBlobSizeAndWantA0 & ~kPceNativeWantA0, !!(stackBlobSizeAndWantA0 & kPceNativeWantA0)));
}
else{
/*execution is over*/
break;
}
}
}
returnValue = armv5GetRegister(0);
/*load old register state*/
armv5SetRegister(0, oldArmRegisters[0]);
armv5SetRegister(1, oldArmRegisters[1]);
armv5SetRegister(2, oldArmRegisters[2]);
armv5SetRegister(14, oldArmRegisters[3]);
armv5SetRegister(15, oldArmRegisters[4]);
return returnValue;
}
UInt32 emuKeyCurrentState(void){
/*need to call old KeyCurrentState then | wihth new keys*/
return 0x00000000;
}
void emuErrDisplayFileLineMsg(const Char* const filename, UInt16 lineNo, const Char* const msg){
debugLog("Error at:%s, Line:%d, Msg:%s\n", filename, lineNo, msg);
}
@@ -100,197 +23,3 @@ void emuSysUnimplemented(void){
debugLog("Unimplemented API:0x%04X, called from:0x%08lX\n", apiNum, callLocation);
}
Err emuHwrDisplayAttributes(Boolean set, UInt8 attribute, void* dataPtr){
/*this function is exempt from formatting standards, it is meant as an exact C reconstrution of the Tungsten W HwrDisplayAttributes patched to work on an m515*/
static const char lcdControllerName[] = "MQ11xx LCD Controller";
Err error = errNone;
/*dispErrorClass | 0x01 = Cant Set???, also returned for null pointers*/
/*dispErrorClass | 0x04 = Attribute Doesnt Exist??*/
switch(attribute){
case 0:
/*display controler ID, MediaQ GPU*/
(UInt32*)dataPtr = '12MQ';
break;
case 1:
/*???*/
(UInt16*)dataPtr = 1;
break;
case 2:
/*???*/
(UInt16*)dataPtr = 1;
break;
case 3:
/*???*/
(UInt16*)dataPtr = 0x808B;
break;
case 4:
/*read some random RAM value and fail if 0*/
if(ScrStatePtr)
(UInt16*)dataPtr = 0x10;
else
error = dispErrorClass | 0x04;
break;
case 5:
/*???*/
(UInt16*)dataPtr = 8;
break;
case 6:
/*???*/
(UInt16*)dataPtr = 0x10;
break;
case 7:
/*display size something, width???, PrvDisplaySize(Boolean set, void* dataPtr)*/
/*UNTESTED*/
(UInt16*)dataPtr = 320;
break;
case 8:
/*display size something, height???, PrvDisplaySize(Boolean set, void* dataPtr)*/
/*UNTESTED*/
(UInt16*)dataPtr = 320;
break;
case 9:
/*display chip framebuffer start address*/
(UInt32*)dataPtr = 0x1F000000;
break;
case 10:
/*display chip framebuffer size*/
(UInt32*)dataPtr = 0x3C000;
break;
case 11:
/*???*/
(UInt16*)dataPtr = 1;
break;
case 12:
/*full name of display controller*/
StrCopy((char*)dataPtr, lcdControllerName);
break;
case 13:
/*display base address*/
/*UNTESTED*/
(UInt32*)dataPtr = 0x1F000000;
break;
case 14:
/*display depth*/
/*UNTESTED*/
(UInt16*)dataPtr = 16;
break;
case 15:
/*read some random RAM value and write to dataPtr*/
if(readArbitraryMemory8(0x36C))
(UInt16*)dataPtr = 0x140;
else
(UInt16*)dataPtr = 0xA0;
break;
case 16:
/*read some random RAM value and write to dataPtr*/
if(readArbitraryMemory8(0x36C))
(UInt16*)dataPtr = 0x140;
else
(UInt16*)dataPtr = 0xA0;
break;
case 17:
/*display row bytes*/
/*UNTESTED*/
(UInt16*)dataPtr = 320 * sizeof(uint16_t);
break;
case 18:
/*display backlight*/
/*UNTESTED*/
(UInt8*)dataPtr = 0x01;
break;
case 19:
/*display contrast*/
/*UNTESTED*/
(UInt8*)dataPtr = 0x01;
break;
/*case 20: has no handler*/
case 21:
/*display debug indicator*/
/*TODO, shouldnt be needed*/
break;
case 22:
/*display controller chip framebuffer end address???*/
if(set)
error = dispErrorClass | 0x01;
else
(UInt32*)dataPtr = 0x1F03C000;
break;
/*case 23: has no handler*/
/*case 24: has no handler*/
/*case 25: has no handler*/
/*case 26: has no handler*/
case 27:
/*???*/
(UInt16*)dataPtr = 0x90;
break;
case 28:
/*???*/
(UInt16*)dataPtr = 0x40;
break;
case 29:
/*???*/
(UInt16*)dataPtr = 0x20;
break;
case 30:
/*???*/
(UInt8*)dataPtr = 1;
break;
default:
debugLog("Invalid display attribute requested:%d\n", attribute);
error = dispErrorClass | 0x04;
break;
}
return error;
}
void emuScrDrawChars(WinPtr pWindow, Int16 xLoc, Int16 yLoc, Int16 xExtent, Int16 yExtent, Int16 clipTop, Int16 clipLeft, Int16 clipBottom, Int16 clipRight, Char* chars, UInt16 len, FontPtr fontPtr){
/*do nothing*/
}
/*
may need to set this to change the border color like on OS 5
Boolean UIPickColor(IndexedColorType *indexP, RGBColorType *rgbP,
UIPickColorStartType start, const Char *titleP,
const Char *tipP)
SYS_TRAP(sysTrapUIPickColor);
*/
/*
may need to remove these from trap table:
ScrGetGrayPat
ScrGetColortable
ScrDrawChars
ScrCopyRectangle
*/

View File

@@ -6,9 +6,9 @@
#include "palmGlobalDefines.h"
typedef struct{
typedef struct PACKED{
uint32_t linkSp;
uint32_t pc;
uint32_t sp;
}__return_stack_frame_type;
#define __return_stack_frame register __return_stack_frame_type* __stack_frame asm("a6")
@@ -17,12 +17,7 @@ typedef struct{
#define getCallLocation() (__stack_frame->pc - 4)
#define getCalledApiNum() (readArbitraryMemory16(__stack_frame->pc - 2))
UInt32 emuPceNativeCall(NativeFuncType *nativeFuncP, void *userDataP);
UInt32 emuKeyCurrentState(void);
void emuErrDisplayFileLineMsg(const Char* const filename, UInt16 lineNo, const Char* const msg);
void emuSysUnimplemented(void);
Err emuHwrDisplayAttributes(Boolean set, UInt8 attribute, void* dataPtr);
void emuScrDrawChars(WinPtr pWindow, Int16 xLoc, Int16 yLoc, Int16 xExtent, Int16 yExtent, Int16 clipTop, Int16 clipLeft, Int16 clipBottom, Int16 clipRight, Char* chars, UInt16 len, FontPtr fontPtr);
#endif

View File

@@ -1,16 +1,7 @@
HLE API forwarder
Builtin Dragonball VZ LCD controller emulation
Reading OS 5 keys
Huge RAM support
Unverified OS version strings need to be verified
ARM support
OS 5 audio API
Custom FB mode
Setting window color like OS 5
Tungsten W drivers are corrupting the trap table pointer(and a ton of other low mem globals)
For some reason the new versions of MuExpDriver dont work with Chuzzle anymore
Need to allocate a new trap table and set the global to that, not just write off the end of the existing one
Need to lock the code resources on boot, databases can be shuffled in RAM to free up space and that will corrupt old trap addresses
Need to patch SysGetOSVersionString
Crash on first load when pressing "Emulator", probably caused by accessing the config file wrong(happens after driver is deleted and reinstalled)
Fixed:
GUI