Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions Documents/CORE_MIGRATION_SCOPE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# XM8 Core Migration Scope (UI-Preserved)

This document defines how to migrate from `common_source_project` into XM8 without changing files under `Source/UI`.

## Rules

1. Keep `Source/UI` unchanged.
2. Prefer same-path/same-name files from `common_source_project/src`.
3. Do not import features that are not used by current XM8 UX/settings unless needed for build or correctness.
4. Keep existing XM8 runtime behavior first, then add optional features deliberately.

## Required Compatibility Surface

The core must continue to provide the interfaces used by XM8 UI:

- `VM::frame_rate()`
- `VM::open_disk()`, `VM::close_disk()`
- `VM::play_tape()`, `VM::rec_tape()`, `VM::close_tape()`
- `VM::save_state()`, `VM::load_state()`
- `VM::get_device(id)` with current ID assumptions used by UI
- `EMU::set_key_buffer()`, `EMU::set_joy_buffer()`
- `config` fields used by UI (`dipswitch`, `sound_device_type`, `scan_line`, `ignore_crc`, etc.)

## Out of Scope by Default

The following should not be migrated unless explicitly required:

- Non-PC-8801 machine features
- Win32-only OSD/frontend pieces (`win32/osd.*`, `winmain.cpp`)
- UI feature sets not exposed in XM8 UI (extra media/device options)
- Optional peripherals not required by current XM8 workflow

## Migration Order

1. Compatibility helpers (no behavior change)
2. Small common components (`fifo`, selected device helpers)
3. Medium components (`event`, `disk`, `upd765a`, `z80`)
4. PC-8801 core (`pc88`, `pc8801`) with XM8 behavior preserved

## Acceptance per Step

- `cmake --build build -j8` succeeds
- XM8 launches
- Disk mount/eject works
- Tape play/rec works
- Save/load state works
- No UI source changes

## Progress Notes

- 2026-02-12:
- Added `DEVICE` compatibility aliases used by common-source style code:
`process_state()`, `initialize_output_signals()`, event/clock alias methods,
interrupt alias methods, and `set_device_name()/get_device_name()`.
- Added `DISK` compatibility wrappers:
`open(const _TCHAR*)`, `process_state()`, and utility aliases
(`set_data_crc_error()`, `get_usec_per_track()`, `get_bytes_per_usec()`).
- Added `UPD765A` compatibility wrappers:
`open_disk(const _TCHAR*)`, `process_state()`,
`is_disk_inserted()`, `is_disk_protected()`, `get_media_type()`,
and safer `get_disk_handler()` bounds check.
- Verified with `cmake --build build -j8` (success, warnings only).
52 changes: 34 additions & 18 deletions Source/ePC-8801MA/emu.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,24 +54,40 @@ class EMU
// ----------------------------------------

// input device
uint8* key_buffer()
{
return key_status;
}
uint32* joy_buffer()
{
return joy_status;
}
int* mouse_buffer()
{
return mouse_status;
}

// screen
scrntype* screen_buffer(int y);
#ifdef USE_CRT_FILTER
bool screen_skip_line;
#endif
uint8* key_buffer()
{
return key_status;
}
uint8* get_key_buffer()
{
return key_buffer();
}
uint32* joy_buffer()
{
return joy_status;
}
uint32* get_joy_buffer()
{
return joy_buffer();
}
int* mouse_buffer()
{
return mouse_status;
}
int* get_mouse_buffer()
{
return mouse_buffer();
}

// screen
scrntype* screen_buffer(int y);
scrntype* get_screen_buffer(int y)
{
return screen_buffer(y);
}
#ifdef USE_CRT_FILTER
bool screen_skip_line;
#endif

// timer
void get_host_time(cur_time_t* time);
Expand Down
48 changes: 34 additions & 14 deletions Source/ePC-8801MA/fifo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,28 @@ int FIFO::read()
}
return val;
}
int FIFO::read_not_remove(int pt)
{
if(pt >= 0 && pt < cnt) {
pt += rpt;
int FIFO::read_not_remove(int pt)
{
if(pt >= 0 && pt < cnt) {
pt += rpt;
if(pt >= size) {
pt -= size;
}
return buf[pt];
}
return 0;
}
}
return 0;
}

void FIFO::write_not_push(int pt, int d)
{
if(pt >= 0 && pt < cnt) {
pt += wpt;
if(pt >= size) {
pt -= size;
}
buf[pt] = d;
}
}
int FIFO::count()
{
return cnt;
Expand Down Expand Up @@ -89,9 +100,9 @@ void FIFO::save_state(void *f)
state_fio->FputInt32(wpt);
}

bool FIFO::load_state(void *f)
{
FILEIO *state_fio = (FILEIO *)f;
bool FIFO::load_state(void *f)
{
FILEIO *state_fio = (FILEIO *)f;

if(state_fio->FgetUint32() != STATE_VERSION) {
return false;
Expand All @@ -101,8 +112,17 @@ bool FIFO::load_state(void *f)
}
state_fio->Fread(buf, size * sizeof(int), 1);
cnt = state_fio->FgetInt32();
rpt = state_fio->FgetInt32();
wpt = state_fio->FgetInt32();
return true;
}
rpt = state_fio->FgetInt32();
wpt = state_fio->FgetInt32();
return true;
}

bool FIFO::process_state(void *f, bool loading)
{
if(loading) {
return load_state(f);
}
save_state(f);
return true;
}

40 changes: 21 additions & 19 deletions Source/ePC-8801MA/fifo.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,27 @@

#include "common.h"

class FIFO
{
private:
int size;
int* buf;
int cnt, rpt, wpt;
public:
FIFO(int s);
void release();
void clear();
void write(int val);
int read();
int read_not_remove(int pt);
int count();
bool full();
bool empty();
void save_state(void *f);
bool load_state(void *f);
};
class FIFO
{
private:
int size;
int* buf;
int cnt, rpt, wpt;
public:
FIFO(int s);
void release();
void clear();
void write(int val);
int read();
int read_not_remove(int pt);
void write_not_push(int pt, int d);
int count();
bool full();
bool empty();
void save_state(void *f);
bool load_state(void *f);
bool process_state(void *f, bool loading);
};

#endif

Loading