Page 2 of 2

Posted: Thu Jan 15, 2009 9:47 pm
by ptorric
thank you all for your hints, i found and fix the real problem.

first of all my wrong cast wasn't the real problem, because of other cast that make an implicit correction.

the main problem is that the fopen in the save function miss the 'b' option, so when you try to save a block of memory, 0x0d is extended in cr+lf, corrupting the memory block.

infact, if you try to join the two roms in one by hand, the emulation works fine.

a big thanx to BigEd for another fix.

i just tryed to compile and use the original apple1 figforth and it seems work fine, but i dont complete the i/o routines till now.

i'm not sure if lib6502 is a good (accurate) emulation library, but in my opinion can be a good start point for who like to develop 6502 code, it's simple and easy to use.

Posted: Fri Jan 16, 2009 1:49 am
by usotsuki
I've used Marat Fayzullin's M6502 on a bunch of my projects (in the form of M65C02, a hack I made on it which supports up as far as the 65SC02 opcodes). Might find it if you can dig up an old version of Dapple (I think it was in the 1.0x time I replaced it with Dapple Core), or it's prolly still on the sf project page with Dapple...

lib65816 emulator library

Posted: Sun Mar 01, 2009 4:10 pm
by BigEd
kc5tja wrote:
I maintain a 65816 emulator library, called "lib65816", for the Linux platform. ... However, I'd be happy to help anyone willing to write a simple console emulator using it.
I finally got around to having a look at lib65816, as found in your k2 emulator. I had some trouble getting it to work: the SDL_SetVideoMode call consistently fails on two ubuntu systems I have, but sprung into life on a third. So I did get to type .CREDITS into the Forth interpreter! Excellent!

For my purposes, I'd very much like to have a console version: ideally very much like lib6502's run6502 program, which allows interception of the ROM read and write routines to the console's stdin/stdout. (I'd also want to make the SDL gui optional, ideally optional at build time too.)

So, I'll see if I can get anywhere with that project, and may ask for help!

(For my purposes, the model B emulation is pertinent, because I'm working on a joint project to fit a 65816 into a model B. But the implementation is just 4 OS hooks and support for the banked memory hardware - it is a very minimal emulation.)

Cheers
Ed

Code: Select all

lib6502 1.0 Copyright (c) 2005 Ian Piumarta
please send bug reports to: firstName (at) lastName (dot) com

usage: ./run6502 [option ...]
       ./run6502 [option ...] -B [image ...]
  -B                -- minimal Acorn 'BBC Model B' compatibility
  -d addr last      -- dump memory between addr and last
  -G addr           -- emulate getchar(3) at addr
  -h                -- help (print this message)
  -I addr           -- set IRQ vector
  -l addr file      -- load file at addr
  -M addr           -- emulate memory-mapped stdio at addr
  -N addr           -- set NMI vector
  -P addr           -- emulate putchar(3) at addr
  -R addr           -- set RST vector
  -s addr last file -- save memory from addr to last in file
  -v                -- print version number then exit
  -X addr           -- terminate emulation if PC reaches addr
  -x                -- exit wihout further ado
  image             -- '-l 8000 image' in available ROM slot

'last' can be an address (non-inclusive) or '+size' (in bytes)

Posted: Sun Mar 01, 2009 4:20 pm
by kc5tja
I'd be happy to help whereever I can. Please note that lib65816 assumes no specific I/O infrastructure; K2 is an emulator that uses lib65816, but the latter doesn't imply any specific ties to the Kestrel concept.

lib65816-based console mode emulation

Posted: Sat Mar 21, 2009 5:12 pm
by BigEd
I've got something now which acts as a minimal BBC model B emulator, and may be good enough for my immediate purposes:

Code: Select all

$ ./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: Select all

*** 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: Select all

*** 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: Select all

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 );
}

Posted: Sat Mar 21, 2009 5:29 pm
by kc5tja
You've probably noticed in the K2 emulator that I use the WDM opcode to trap to the emulator for various things. That's the route I personally would have taken, but it obviously requires hot-patching the BBC ROM image at run-time.

Posted: Sat Mar 21, 2009 5:52 pm
by BigEd
Ah - I didn't notice that, but thanks for the pointer! (I need a way to work with tracing)

Posted: Sat Mar 28, 2009 8:36 pm
by BigEd
I've added a few more features from run6502 into my run65816.c - it now correctly reports 32k memory and allows loading of multiple mappable ROM images.

I had another thought about my MEM_FetchMem API change: would it be preferable to pass one or more flags to the MEM_ReadMem function, in effect the VP and VPA pin values, so that the MEM_ReadMem can emulate VP-detecting hardware, and also can trap OS calls by trapping selected instruction addresses?

Ed

Code: Select all

$ ./run65816
usage: ./run65816 [option ...] -B [image ...]
  -B                -- (mandatory) minimal Acorn 'BBC Model B' compatibility
  -h                -- help (print this message)
  -l addr file      -- load file at addr
  image             -- '-l 8000 image' in available ROM slot

'last' can be an address (non-inclusive) or '+size' (in bytes)

Code: Select all

$ ./run65816 -B -l c000 OS12.ROM BASIC2.ROM VIEW21.ROM
loading ROM file OS12.ROM
loading ROM file BASIC2.ROM
loading ROM file VIEW21.ROM
WARP FACTOR 5

BBC Computer 32K
         
BASIC

>*HELP

VIEW A2.1 
  Stored
  Cmode

OS 1.20
>

Posted: Sat Mar 28, 2009 9:30 pm
by kc5tja
It should be doable; I haven't done it because I don't need it personally. I can't imagine why it wouldn't be possible though.

I'm not sure the best way to implement it though. Understand that the core of lib65816 was taken from the abandonware "xgs" project. I didn't write the bulk of the code, and thus, really am not totally sure how it works inside.

Posted: Fri Apr 03, 2009 2:29 pm
by BigEd
I've sent you a patch!

Cheers
Ed

Posted: Sat Apr 04, 2009 2:05 am
by kc5tja
Just FYI -- I got the patch, but haven't applied it yet. I'm busy with my startup at the moment, but I will get to it as quickly as time permits.

Re: Linux console-based 6502 emulator anywhere?

Posted: Sun Jan 20, 2013 12:08 pm
by BigEd
I've published my minimal run65816 wrapper to lib65816 - see viewtopic.php?p=23982#p23982

Cheers
Ed

Re: Linux console-based 6502 emulator anywhere?

Posted: Tue Nov 14, 2023 8:27 am
by dwesti
anyone tried to compile source for windows? got a lot of errors.

Re: Linux console-based 6502 emulator anywhere?

Posted: Tue Nov 14, 2023 7:13 pm
by fachat
My xcbm console-based emulator has got some serious updates in the meantime...
https://github.com/fachat/xcbm

Re: Linux console-based 6502 emulator anywhere?

Posted: Tue Nov 14, 2023 8:44 pm
by 6502inside
Excellent!