1
0
mirror of https://github.com/sethm/symon.git synced 2024-06-03 07:29:30 +00:00
Commit Graph

62 Commits

Author SHA1 Message Date
Tim Allen
5df775bbb0 Make the emulated 6551's soft ("program") reset state match the MOS datasheet.
The only description of the effects of "program reset" in the original MOS
datasheet is in the section for each register. The W65C51S and W65C51N
datasheets have a heading "PROGRAM RESET OPERATION", but it amounts to:

- internal registers are modified as described in the section for each register
- changes to the DTR, DCD, and DSR pins which Symon does not emulate
- the overrun flag is cleared

...which is what this new implementation does.

It would make *sense* for the reset to do things like "cancel transmission or
reception in progress" and stop asserting an interrupt, as the old code did,
but I can't find any evidence of such behaviour in the datasheets.
2023-06-11 08:21:37 -07:00
Tim Allen
d076046f57 Make the emulated 6551's hardware reset state match the MOS datasheet. 2023-06-11 08:21:37 -07:00
Tim Allen
b5a470d3ba Make the Processor Status register match a real 6502 at power-on.
When describing the CPU's reset pin, the W65C02S data sheet says:

> All Registers are initialized by software except the Decimal and Interrupt
> disable mode select bits of the Processor Status Register (P) are initialized
> by hardware.

It then has a diagram of the power-on state of the processor status register:

>     7 6 5 4 3 2 1 0
>     * * 1 1 0 1 * *
>     N V - B D I Z C
>
> * = software initialized

Confusingly the text indicates that only the D and I flags are initialised by
hardware, while the diagram indicates that the B flag is initialised too.

Meanwhile, https://www.nesdev.org/wiki/CPU_power_up_state says that
the power-on state of the NES CPU is $34 (exactly matching the diagram above)
but https://www.nesdev.org/wiki/Status_flags#The_B_flag says that the B flag
does not physically exist within P register, it's only relevant in the copy
of P that gets pushed to the stack by BRK (set), PHP (set), or an interrupt
signal (cleared).

As a result, the most sensible power-on state for the processor status register
is with the "interrupt disable" flag set and everything else cleared.
2023-02-03 18:16:57 +11:00
Seth Morabito
e210a40639 Use correct Mockito package 2023-01-12 16:56:28 -08:00
ccureau
be72c2ff09 implement jterminal in source 2017-08-30 10:34:50 -05:00
Matt Harlum
a9c6d5964f * Add Support for All 65C02 Opcodes and all Rockwell/WDC opcodes except WAI/STP
* Add 65C02 Opcode tests
* All tests pass, Klaus' 6502_functional_tests pass & Klaus' 65C02_extended_opcodes_test also all pass
2017-06-06 19:59:01 +10:00
Matt Harlum
faf5d22660 * Add ACIA Interrupt tests.
* Fix ACIA6850 Interrupt behavior, Interrupt should be cleared on status register read.
* Remove unneeded cpuAccess if statement from Acia6850 write that was preventing build completion
* Fix ACIA6850 Tests so they run.
2017-06-06 12:55:35 +10:00
Matt Harlum
96819f1bf7 Issue #16: Memory window should not reset device registers 2017-05-26 17:01:41 +10:00
Seth Morabito
da88aadda2 Merge pull request #15 from LIV2/master
Correct BRK/IRQ behavior
2016-03-20 11:43:42 -07:00
Matt Harlum
657b69da6c Cleanup my comments 2016-03-20 17:05:48 +11:00
Seth Morabito
634ea933f1 Add disassembled instructions to breakpoints 2016-01-02 19:05:38 -08:00
Matt Harlum
8335cf5421 Correct BRK behaviour
IRQ/NMI clear the BRK flag
BRK is Non-Maskable
2015-06-01 08:58:17 +10:00
Seth Morabito
eeb246ebc2 CRTC refactoring 2014-08-14 10:53:48 -07:00
Seth Morabito
22a9207dca Fix for GitHub Issue #9 2014-08-11 13:36:08 -07:00
Maik Merten
52f4e9a00f enforce that the address range of devices falls within the address range of the bus. Turned out that the CPU tests instantiate memory with the last parameter as memory size, not end address (fixed now). Also make sure that the address lookup array takes the offset caused by non-zero starting addresses into account. 2014-07-25 21:24:16 +02:00
Maik Merten
d7f8045b61 rework bus. Don't throw an Exception any more with overlapping device addresses - this is normal for some machines. Introduce the concept of priorities to ensure that device overlap in the correct order. 2014-07-25 19:32:00 +02:00
Maik Merten
252ebe0569 implement overrun status flag for the 6551 ACIA 2014-07-19 17:30:23 +02:00
Maik Merten
8f52e1da1e implement overrun flag for 6850 ACIA 2014-07-16 22:26:06 +02:00
Maik Merten
0d0fddc365 tests for the 6850 ACIA and fixes in ACIA behavior 2014-07-16 21:51:34 +02:00
Maik Merten
31fdd87b41 turn Acia into an abstract class so that the 6551 and 6850 ACIAs can reuse code and an unified interface. 2014-07-15 21:35:19 +02:00
Seth Morabito
1bc8eda38d ACIA interrupt handling 2014-01-26 01:25:12 -08:00
Seth Morabito
76dcbd712a IRQ and NMI handling at CPU level. 2014-01-25 20:45:39 -08:00
Seth Morabito
b6cc480919 Add NMI flag to CPU 2014-01-25 20:02:17 -08:00
Seth Morabito
0c5035fc56 Add interrupt flag to CPU 2014-01-25 19:53:53 -08:00
Seth Morabito
4a510b635e README updates, CRTC tests.
- Added more CRTC information to the README file.
- Added unit tests for the CRTC.
- Implemented register read for cursor position in the CRTC.
- Bundling a new version of jterminal that has correct backspace
  behavior.
2013-12-29 18:18:48 -08:00
Max840
1c9c742477 Unit test updated with devices' start/end address 2013-12-23 23:38:38 -05:00
Seth Morabito
da8250778e Bug Fixes and Copyright Date Change
The simulator now passes Klaus Dormann's 6502 Functional Test suite for
the first time.

Bug Fixes:

- PHP was not correctly setting the Break bit on the stack copy of the
  processor status, so subsequent PLA's would not set the Break status
  flag.

- The CPU had swapped NMI and IRQ reset vectors, so RTI was failing.

- BRK was pushing PC + 2 onto the stack, instead of PC + 1

- (Zero Page,X) addressing mode did not correctly wrap on zero page
  boundaries.

- The instruction table used for disassembly had addressing modes
  of LDA $B9 and $BD reversed. This did not affect behavior, only
  disassembly of these instructions.

Other:

- Updated copyright date for 2013.

- Started migrating old JUnit 3 style tests to JUnit 4 annotations.
2013-01-01 17:03:16 -08:00
Seth Morabito
0215e2e3d8 Cleaner simulator startup and run-loop exiting
- If a default ROM image ("rom.bin") isn't available at startup, the
  simulator will now create and load a 16KB R/W memory at the ROM
  location, so resets will work even without a ROM loaded.

- Cleaned up the way simulator UI state is updated when the run loop
  exits.
2012-12-10 21:53:01 -08:00
Seth Morabito
807a43ce6f Faster byte and word to hex string
I was alarmed to discover just how slow `String.format()` is for doing
integer to hex conversions. Now that a trace window has been added to
Symon, it became especially clear that I needed a more efficient way to
handle it.

I looked into using `Integer.toHexString()`, but I would have had to
wrap it to do zero-padding, so I decided to just bite the bullet and do
my own with a lookup table. The implementation in `HexUtil` is just as
fast as `Integer.toHexString()`, but also zero-pads appropriately.
Combined with Java's `+` String concatenation, it seems perfectly
adequate.

For yet better performance with the trace window, it would make a lot of
sense to special-case stepping so that it just pops the top line off the
log, and appends to the bottom, rather than re-stringifying the entire
trace log each time. This will be a future enhancement.
2012-12-09 21:02:11 -08:00
Seth Morabito
bc3de80892 Execution Trace Log
Introduces an execution trace window that will keep track of the most
recent 10000 execution steps. I'm not entirely happy with the
implementation, yet.
2012-12-09 17:04:31 -08:00
Seth Morabito
2ebdd254b3 Work In Progress: CPU behavior, UI changes
This is something of a "Work in Progress" checkpoint of several features
that are all half baked:

1. Allow loading of 16KB ROM files at address $C000 at run-time, not
   just at startup. See the "Load ROM..." File menu item.

2. Introduces the notion of "CPU Behaviors", so the core 6502 CPU
   implementation can match the behavior of either an early NMOS 6502, late
   NMOS 6502, or CMOS 65C02. Very little of this is actually implemented so
   far.

3. Adds a completely bogus implementation of the 6522 VIA (it
   does absolutely nothing right now).

4. Changes the address of the ACIA in the simulated system to match a
   real hardware implementation I put together.
2012-11-25 22:49:21 -08:00
Seth Morabito
795ccfde5d CPU bug fixes and Simulator enhancements.
Bug Fixes:

- Fixed several bugs in the CPU that caused processor status flags to
  be set incorrectly.  Instructions affected were: STA, STX, STY, CMP,
  CPX, CPY, BIT.

- Made some internal-use-only methods on the CPU class private.

- Fixed incorrect disassembly of (Indirect,X) and (Indirect),Y
  instructions. Although this didn't affect behavior, it certainly
  caused me some confusion in debugging.

- Added missing "BCS" instruction to instruction table.

Enhancements:

- Now includes a full version of Lee Davison's Enhanced 6502 BASIC
  bundled as source code and a ROM image. Get that REAL COMPUTER
  EXPERIENCE!(tm)

- If a file named "rom.bin" exists in the same directory where the
  simulator is executed, it will be loaded at addresses $d000-$ffff.

- Gave the CPU an idle loop to make simulated timing a little more
  realistic (but this is still an area needing major improvement)

- Changed the CPU's toString() method to give better debugging output.

- Added a small typeahead buffer to the Console.

- Better exception messaging.

Misc:

- Bumped version to 0.5, updated README.
2012-10-21 20:05:05 -07:00
Seth Morabito
c1caf8c6b4 Timing and UI enhancements.
This change introduces simulated baud rates in the ACIA. Baud rate is controlled just as in the real 6551, by writing to the ACIA's control register. Baud rates between 50 and 19,200 baud are selectable. A baud rate of 0 has special meaning, and turns off all simulated baud rate delays (on a real 6551, this means to use an external clock instead of the internal baud rate generator)

A busy-wait loop between steps in the simulator control program has also been added. This uses the high-resolution 'System.nanoTime()' call to wait a specific number of nanoseconds before continuing. Symon now waits at least 1uS between clock cycles, trying to approach a real 1MHz 6502 in performance. It is far from perfect, but it's better than it was.

 Also refactored the status panel to use a BoxLayout, and DRY-up some of the code.
2012-10-14 17:56:19 -07:00
Seth Morabito
c214cc9b43 Fixes and enhancements.
- Added ability to change inner border width of console window.
- Fixed a nasty bug that prevented key press handling.
- Reset now clears the accumulator and index registers.
2012-10-14 00:25:03 -07:00
Seth Morabito
ed36690e9e Checkpoint of my Swing UI refactoring. Usable for output-only programs, but only barely. 2012-05-28 22:18:35 -07:00
Seth Morabito
a1d07bf223 First work toward moving to a Swing UI for the simulator. 2012-04-22 20:49:18 -07:00
Seth J. Morabito
00ab8cd9ff Simulator is just about ready for real-world testing now. Added a simulated
MOS6551 ACIA at address $C000 which does buffered input and output via the
console. Updated the README with a bit more documentation, and bumped the
version number to 0.1 because I'm impatient.
2010-01-20 18:19:39 -08:00
sethm
a3e57274a2 - Major overhaul of the Simulator control class (where 'main' lives).
- Removed the CommandParser class entirely, as the weird dependency between
  Simulator and CommandParser never made me comfortable.
- Added a Command inner class to Simulator that handles some of the
  command line tokenizing.
2010-01-16 19:22:22 -08:00
Seth Morabito
f174f0312f * Correct implementation of Indirect Indexed and Indexed Indirect addressing modes.
* Unit tests for Indirect Indexed and Indexed Indirect.
* Updated copyright dates.
* Started moving to JUnit 4.
2010-01-15 08:20:03 +00:00
sethm
4104d6212e Added Indirect X Mode Tests 2010-01-10 01:18:45 -08:00
Seth J. Morabito
ac88786df7 - Continued refactoring of address decoding.
- Device read and write may now throw MemoryAccessException, and appropriate
  throws clauses have been added throughout the code.
2010-01-09 16:53:04 -08:00
Seth Morabito
ed943687bf Implemented Relative mode (branch) instructions and unit tests. Fixed
a bug in the instruction size table.
2009-01-07 18:26:11 -08:00
Seth Morabito
f21a0d76e9 Implemented Absolute,Y addressing mode and unit tests. 2009-01-07 16:50:36 -08:00
Seth Morabito
dccf73a6b7 Implemented instructions using the Absolute,X addressing mode. There's
light at the end of the tunnel now!
2008-12-29 21:47:19 -08:00
Seth Morabito
107aca7777 Implemented Zero Page,X, Zero Page,Y, and Indirect addressing mode instructions, along with unit tests. 2008-12-29 20:46:48 -08:00
Seth Morabito
4b28ab4808 Implemented Absolute addressing mode instructions. All unit tests pass. 2008-12-28 23:11:16 -08:00
Seth J. Morabito
24458da79e Implemented Accumulator mode instructions. Grouped all unimplemented (65C02 and 65816 only) instructions together in a single fall-through area of the instruction decoding switch statement. Added an unimpelmented instruction trap member variable. 2008-12-28 17:55:02 -08:00
Seth J. Morabito
8bcd8a4a75 Whitespace and indentation canonicalization. That's what I get for using two editors. 2008-12-27 21:09:47 -08:00
Seth J. Morabito
d54ad18b17 All zero page instructions implemented. Tests passing. 2008-12-27 20:59:10 -08:00
Seth J. Morabito
ecde55c6b8 Started on Zero Page opcodes and tests. 2008-12-27 13:01:07 -08:00