I've got something now which acts as a minimal BBC model B emulator, and may be good enough for my immediate purposes:
Code:
$ ./minimal
Reading ROM.PRG
WARP FACTOR 5
BBC Computer 16K
BASIC
>PRINT PI
3.14159265
This is great for me: thanks for all the groundwork in the k2 emulator! (I've also borrowed from Ian Piumarta's run6502/lib6502 emulator of course, although you'll notice I haven't gone to the trouble of porting the nice command line interface.)
To trap the OS calls I made a couple of changes to lib65816 - there may well be better ways of doing this, but I'm no expert:
Code:
*** lib65816/cpu.h 2009-03-21 14:44:40.000000000 +0000
--- lib65816/cpu.h~ 2009-02-28 10:37:34.000000000 +0000
***************
*** 127,133 ****
*/
#define M_READ(a) MEM_readMem(a, cpu_cycle_count)
- #define M_FETCH(a) MEM_fetchMem(a, cpu_cycle_count)
#define M_WRITE(a,v) MEM_writeMem((a),(v), cpu_cycle_count)
--- 127,132 ----
Code:
*** src/dispatch.c 2009-03-21 14:43:13.000000000 +0000
--- src/dispatch.c~ 2009-02-28 10:37:34.000000000 +0000
***************
*** 181,187 ****
if (cpu_irq) goto irq;
irq_return:
if (cpu_wait) { cpu_cycle_count++; goto dispatch; }
! opcode = M_FETCH(PC.A); // will be M_READ except where we trap for emulation
PC.W.PC++;
#ifdef OLDCYCLES
--- 181,187 ----
if (cpu_irq) goto irq;
irq_return:
if (cpu_wait) { cpu_cycle_count++; goto dispatch; }
! opcode = M_READ(PC.A);
PC.W.PC++;
#ifdef OLDCYCLES
with a corresponding routine in the machine emulation (which you'll notice I've hard coded):
Code:
byte MEM_fetchMem(word32 address, word32 timestamp)
{
if( address == 0x00FFEE || address == 0x00E0A4 ) { // oswrch and nvwrch
return oswrch( address, timestamp );
}
if( address == 0x00FFF1 ) {
return osword( address, timestamp );
}
if( address == 0x00FFF4 ) {
return osbyte( address, timestamp );
}
return MEM_readMem( address, timestamp );
}