Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3ee3a7e300 | ||
|
|
b2810fa062 | ||
|
|
c9f9121477 | ||
|
|
91ef70fe4e | ||
|
|
69bf418f43 | ||
|
|
540f0dff58 | ||
|
|
17668e2c3c | ||
|
|
3353b8436c
|
||
|
|
e635d0a608
|
||
|
|
558af36cd5
|
||
|
|
5fa6fa0fc0
|
||
|
|
f152ed9df5
|
||
|
|
87217afa6e
|
||
|
|
b9997e3edc | ||
|
|
45c8a69d7b | ||
|
|
2e2163fefb | ||
|
|
995b372f55 | ||
|
|
47c87aac56 | ||
|
|
3a59dedc29 | ||
|
|
7268766cd6 | ||
|
|
2284535b7f | ||
|
|
963526621d | ||
|
|
c317544e7b | ||
|
|
ecd4bbbd9a | ||
|
|
a537328852 | ||
|
|
4975fca506 | ||
|
|
199d96c025 | ||
|
|
0c026e38dd | ||
|
|
5e56627f32 | ||
|
|
67f5e17f78 | ||
|
|
5a25750f46 | ||
|
|
4a8a803472 | ||
|
|
4423623816 | ||
|
|
5df775bbb0 | ||
|
|
d076046f57 | ||
|
|
b725fb5fdd | ||
|
|
9351d785ae | ||
|
|
66a92f4196 | ||
|
|
cda9a218af | ||
|
|
b5a470d3ba | ||
|
|
e210a40639 | ||
|
|
0bad9912ce | ||
|
|
b36b442b14 | ||
|
|
5f8f743f7d | ||
|
|
4ce8bc86de | ||
|
|
4644fe9b55 | ||
|
|
655bbb3ab0 | ||
|
|
e2d31fd39c | ||
|
|
087ba28b82 | ||
|
|
8edca5d595 | ||
|
|
105a09067f | ||
|
|
08efd81be3 | ||
|
|
0aeb97bb56 | ||
|
|
d466a21b3e | ||
|
|
31d1f7c5e1 | ||
|
|
247f2ba2fc | ||
|
|
922810b34b | ||
|
|
9d6791330d | ||
|
|
73c474d606 | ||
|
|
71905fdb19 | ||
|
|
cb918c9906 | ||
|
|
be72c2ff09 | ||
|
|
18ce120984 | ||
|
|
8ffb130300 | ||
|
|
441f7349a0 | ||
|
|
4f27e78940 | ||
|
|
11f61f50a9 | ||
|
|
59f8ff1bc4 | ||
|
|
a9c6d5964f | ||
|
|
faf5d22660 | ||
|
|
3c3aee30a7 | ||
|
|
92f8fe3dd9 | ||
|
|
356822df71 | ||
|
|
f2ced29979 | ||
|
|
2e33756d49 | ||
|
|
079d3dbeae | ||
|
|
96819f1bf7 | ||
|
|
9cdd718e8d | ||
|
|
5554acd29c | ||
|
|
5a2e057e69 | ||
|
|
da88aadda2 | ||
|
|
657b69da6c | ||
|
|
f251e54174 | ||
|
|
fcc57d9be4 | ||
|
|
88eba2cdcb | ||
|
|
0e49b197b3 | ||
|
|
b59fa63b63 | ||
|
|
eff98118d5 | ||
|
|
c599df1cfb | ||
|
|
66c52c8826 | ||
|
|
f3a5dd93ad | ||
|
|
4044458baa | ||
|
|
9ab94b3050 | ||
|
|
9a504adc58 | ||
|
|
57cbff42e7 | ||
|
|
634ea933f1 | ||
|
|
0ca30291cb | ||
|
|
95f85b71b1 | ||
|
|
6b5976be8f | ||
|
|
3530e9e99a | ||
|
|
7a9f9bfd55 | ||
|
|
1e04a52d1b | ||
|
|
7daeb9e978 | ||
|
|
da2750f4ee | ||
|
|
df88c54f90 | ||
|
|
69e1985ec1 | ||
|
|
6267d1d777 | ||
|
|
84e5c5ad56 | ||
|
|
6e8fd40014 | ||
|
|
a4a110dcef | ||
|
|
8335cf5421 | ||
|
|
ae5c5d48b2 | ||
|
|
72ba068beb | ||
|
|
142cb470a0 | ||
|
|
cad3673bd2 | ||
|
|
4796b65390 | ||
|
|
e0d6017d95 | ||
|
|
d6ea21bae4 | ||
|
|
af12039686 | ||
|
|
ed1d5f999b | ||
|
|
c595ff5370 | ||
|
|
e9f662cc17 | ||
|
|
70ab2a6fc2 | ||
|
|
f35fbce38b | ||
|
|
eeb246ebc2 | ||
|
|
e157217f50 | ||
|
|
cc12e8f70a | ||
|
|
a9a1c1aa52 | ||
|
|
742e3a1027 | ||
|
|
45f596e0d4 | ||
|
|
4402a28e2b | ||
|
|
693d1959ac | ||
|
|
792366fddb | ||
|
|
b2670aedf1 | ||
|
|
5d488bbcd2 | ||
|
|
e2a1144c7c | ||
|
|
ac5907691f | ||
|
|
fce0dad2a9 | ||
|
|
0c40cd325c | ||
|
|
22a9207dca | ||
|
|
010c42753f | ||
|
|
7c2a007928 | ||
|
|
194a13d1ac | ||
|
|
66646116cb | ||
|
|
59c6d8e23b | ||
|
|
36615fc70b | ||
|
|
1a1d503abe | ||
|
|
eac387e472 | ||
|
|
bb82db6672 | ||
|
|
f675a6e462 | ||
|
|
ccae8905b3 | ||
|
|
7a215736fe | ||
|
|
c61a63d5bb | ||
|
|
7cb4e1c945 | ||
|
|
3a40d35fdf | ||
|
|
d658cd0ae5 | ||
|
|
6b9295e72d | ||
|
|
004087a742 | ||
|
|
7edbb12f68 | ||
|
|
4bfc196b49 | ||
|
|
b1e1e75555 | ||
|
|
da3015defd | ||
|
|
87b5b77dbf | ||
|
|
2dc0078deb | ||
|
|
ac21b2c126 | ||
|
|
4bb6d55fa2 | ||
|
|
f90516e53c | ||
|
|
fdaeb661d3 | ||
|
|
827e9991d5 | ||
|
|
dc7dfc4b4d | ||
|
|
2217f3831d | ||
|
|
52f4e9a00f | ||
|
|
d7f8045b61 | ||
|
|
222772648d | ||
|
|
bd2337ae65 | ||
|
|
a49c0d40d8 | ||
|
|
44bfbc17ab | ||
|
|
b266a02372 | ||
|
|
72074b9715 | ||
|
|
252ebe0569 | ||
|
|
4a37dd7463 | ||
|
|
cf36f731da | ||
|
|
e01f68a19a | ||
|
|
44151f3a9c | ||
|
|
f5a25b7303 | ||
|
|
14e8ea596c | ||
|
|
8f52e1da1e | ||
|
|
0d0fddc365 | ||
|
|
31fdd87b41 | ||
|
|
9726907317 | ||
|
|
40c5397ed8 | ||
|
|
a7ea60d250 | ||
|
|
1bc8eda38d | ||
|
|
76dcbd712a | ||
|
|
b6cc480919 | ||
|
|
0c5035fc56 | ||
|
|
3d36cd5460 |
No files matched your search
@@ -0,0 +1,36 @@
|
||||
name: Build and Test
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
pull_request:
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: catthehacker/ubuntu:act-latest
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup JDK
|
||||
uses: actions/setup-java@v6
|
||||
with:
|
||||
distribution: temurin
|
||||
java-version: '21'
|
||||
#cache: maven
|
||||
|
||||
- name: Install Maven
|
||||
run: apt-get update && apt-get install -y maven
|
||||
|
||||
- name: Test and package
|
||||
run: mvn -B verify
|
||||
|
||||
- name: Upload jar
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: package
|
||||
path: target/*.jar
|
||||
@@ -0,0 +1,33 @@
|
||||
name: Release
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- 'v*'
|
||||
|
||||
jobs:
|
||||
release:
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: catthehacker/ubuntu:act-latest
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup JDK
|
||||
uses: actions/setup-java@v6
|
||||
with:
|
||||
distribution: temurin
|
||||
java-version: '21'
|
||||
|
||||
- name: Install Maven
|
||||
run: apt-get update && apt-get install -y maven
|
||||
|
||||
- name: Package
|
||||
run: mvn -B verify
|
||||
|
||||
- name: Create release
|
||||
uses: https://gitea.com/actions/gitea-release-action@v1
|
||||
with:
|
||||
files: |-
|
||||
target/symon*.jar
|
||||
@@ -1,6 +1,8 @@
|
||||
*~
|
||||
*.jar
|
||||
*#
|
||||
target
|
||||
.DS_Store
|
||||
.idea
|
||||
symon.iml
|
||||
/dependency-reduced-pom.xml
|
||||
@@ -0,0 +1,5 @@
|
||||
eclipse.preferences.version=1
|
||||
encoding//src/main/java=UTF-8
|
||||
encoding//src/main/resources=UTF-8
|
||||
encoding//src/test/java=UTF-8
|
||||
encoding/<project>=UTF-8
|
||||
@@ -0,0 +1,5 @@
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
|
||||
org.eclipse.jdt.core.compiler.compliance=1.7
|
||||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
|
||||
org.eclipse.jdt.core.compiler.source=1.7
|
||||
@@ -0,0 +1,4 @@
|
||||
activeProfiles=
|
||||
eclipse.preferences.version=1
|
||||
resolveWorkspaceProjects=true
|
||||
version=1
|
||||
@@ -1,6 +1,6 @@
|
||||
The MIT License
|
||||
|
||||
Copyright (c) 2008-2013 Seth J. Morabito <web@loomcom.com>
|
||||
Copyright (c) 2008-2014 Seth J. Morabito <web@loomcom.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
|
||||
@@ -1,18 +1,13 @@
|
||||
SYMON - A 6502 System Simulator
|
||||
kSYMON - A 6502 System Simulator
|
||||
===============================
|
||||
|
||||
**NOTE: THIS SOFTWARE IS UNDER ACTIVE DEVELOPMENT. Feedback is welcome!**
|
||||
**Version:** 1.5.1k
|
||||
|
||||
**Version:** 0.9.0.1
|
||||
|
||||
**Last Updated:** 29 December, 2013
|
||||
|
||||
Copyright (c) 2013 Seth J. Morabito <web@loomcom.com>
|
||||
**Last Updated:** 24 September, 2026
|
||||
|
||||
See the file COPYING for license.
|
||||
|
||||
|
||||
![Symon Simulator in Action] (https://github.com/sethm/symon/raw/master/screenshots/full.jpg)
|
||||

|
||||
|
||||
## 1.0 About
|
||||
|
||||
@@ -21,82 +16,148 @@ Technologies 6502 microprocessor and compatibles. Symon is implemented
|
||||
in Java. Its core goals are accuracy, ease of development, clear
|
||||
documentation, and extensive test suites for validating correctness.
|
||||
|
||||
Symon simulates a complete system with a 1 MHz NMOS 6502, 32KB of RAM,
|
||||
16KB of ROM, a 6551 ACIA, a 6522 VIA, and a 6545 CRTC.
|
||||
Symon simulates a complete system with a 1 MHz NMOS 6502 or CMOS
|
||||
65C02, 32KB of RAM, 16KB of ROM, a MOS 6551 or Motorola 6850 ACIA, a
|
||||
MOS 6522 VIA, and an experimental 6545 CRTC.
|
||||
|
||||
Symon has extensive unit tests to verify correctness, and fully passes
|
||||
Klaus Dormann's 6502 Functional Test Suite as of version 0.8.2
|
||||
(See [this thread on the 6502.org Forums] (http://forum.6502.org/viewtopic.php?f=2&t=2241)
|
||||
(See [this thread on the 6502.org Forums](http://forum.6502.org/viewtopic.php?f=2&t=2241)
|
||||
for more information about this functional test suite).
|
||||
|
||||
Symon is under active maintenance. Feedback and patches are always
|
||||
welcome.
|
||||
|
||||
## 2.0 Requirements
|
||||
|
||||
- Java 1.5 or higher
|
||||
- Maven 2.0.x or higher (for building from source)
|
||||
- Java 10 or higher
|
||||
- Maven 3.0.x or higher (for building from source)
|
||||
- JUnit 4 or higher (for testing)
|
||||
|
||||
## 3.0 Features
|
||||
|
||||
### 3.1 Memory Map
|
||||
Symon can simulate multiple 6502 based architectures. At present, four
|
||||
machines are implemented: Symon (the default), MULTICOMP, BenEater, and
|
||||
a "Simple" machine useful for debugging.
|
||||
|
||||
### 3.1 Memory Maps
|
||||
|
||||
#### 3.1.1 Symon Memory Map
|
||||
|
||||
- `$0000`--`$7FFF`: 32KB RAM
|
||||
- `$8000`--`$800F`: 6522 VIA
|
||||
- `$8800`--`$8803`: 6551 ACIA (Serial Console)
|
||||
- `$9000`--`$9001`: 6545 CRTC
|
||||
- `$8800`--`$8803`: MOS 6551 ACIA (Serial Console)
|
||||
- `$9000`--`$9001`: MOS 6545 CRTC
|
||||
- `$C000`--`$FFFF`: 16KB ROM
|
||||
|
||||
The CRT Controller uses memory address `$7000` as the start of Video memory.
|
||||
The CRT Controller uses memory address `$7000` as the start of Video
|
||||
memory.
|
||||
|
||||
#### 3.1.2 MULTICOMP Memory Map
|
||||
|
||||
- `$0000`--`$DFFF`: 56KB RAM
|
||||
- `$E000`--`$FFFF`: 8KB ROM
|
||||
- `$FFD0`--`$FFD1`: Motorola 6850 ACIA
|
||||
- `$FFD8`--`$FFDF`: Controller for SD cards
|
||||
|
||||
### 3.1.3 Simple Memory Map
|
||||
|
||||
- `$0000`--`$FFFF`: 64KB RAM
|
||||
|
||||
#### 3.1.4 BenEater Memory Map
|
||||
|
||||
- `$0000`--`$3FFF`: 16KB RAM
|
||||
- `$5000`--`$5003`: MOS 6551 ACIA (Serial Console)
|
||||
- `$6000`--`$600F`: 6522 VIA
|
||||
- `$8000`--`$FFFF`: 16KB ROM
|
||||
|
||||
#### 3.1.5 Mike42 Memory Map
|
||||
|
||||
- `$0000`--`$7FFF`: 32KB RAM
|
||||
- `$8000`--`$800F`: 6522 VIA
|
||||
- `$8400`--`$8403`: MOS 6551 ACIA (Serial Console)
|
||||
- `$C000`--`$FFFF`: 16KB ROM
|
||||
|
||||
### 3.2 Serial Console and CPU Status
|
||||
|
||||
![Serial Console] (https://github.com/sethm/symon/raw/master/screenshots/console.png)
|
||||

|
||||
|
||||
The main window of the simulator acts as the primary Input/Output
|
||||
system through a virtual serial terminal. The terminal is attached to
|
||||
a simulated MOS 6551 ACIA, including a programmable baud rate
|
||||
generator that tries to approximate the correct "feel" of the
|
||||
programmed baud rate. (The sample Enhanced BASIC ROM image is
|
||||
programmed for 9600 baud)
|
||||
system through a virtual serial terminal. It also provides CPU status.
|
||||
Contents of the accumulator, index registers, processor status flags,
|
||||
disassembly of the instruction register, and stack pointer are all displayed.
|
||||
|
||||
It also provides CPU status. Contents of the accumulator, index
|
||||
registers, processor status flags, disassembly of the instruction
|
||||
register, and stack pointer are all displayed.
|
||||
The terminal is attached to a simulated MOS 6551 ACIA. It behaves very much
|
||||
as described in the datasheet, with some exceptions:
|
||||
|
||||
![Font Selection] (https://github.com/sethm/symon/raw/master/screenshots/font_selection.png)
|
||||
- The simulated ACIA is permanently connected to the virtual terminal,
|
||||
the Data Carrier Detect and Data Set Ready status bits always indicate
|
||||
a connection is ready.
|
||||
- The parity, stop-bits and bits-per-character settings are ignored. The
|
||||
ACIA always sends and receives 8-bit characters, and parity errors
|
||||
do not occur.
|
||||
- The ACIA tries to honour the configured baud rate, but as a special case
|
||||
the default "16x External Clock" rate is interpreted to mean "as fast as
|
||||
possible" (The sample Enhanced BASIC ROM image is programmed for 9600 baud).
|
||||
- The ACIA ignores the configured state of the Data Terminal Ready pin;
|
||||
it is always ready to receive and transmit.
|
||||
|
||||
For more information on the MOS 6551 ACIA and its programming model,
|
||||
see the official datasheet:
|
||||
|
||||
- [MOS 6551 ACIA](http://archive.6502.org/datasheets/mos_6551_acia.pdf)
|
||||
|
||||

|
||||
|
||||
The console supports font sizes from 10 to 20 points.
|
||||
|
||||
### 3.3 16 KB ROM Loading
|
||||
### 3.3 ROM Loading
|
||||
|
||||
![ROM Loading] (https://github.com/sethm/symon/raw/master/screenshots/load_rom.png)
|
||||

|
||||
|
||||
Symon can load any 16 KB (16384 bytes) ROM image from the "File"
|
||||
menu. The selected ROM will be placed in memory from locations `$C000`
|
||||
to `$FFFF`
|
||||
Symon can load any appropriately sized ROM image. The Symon
|
||||
architecture expects as 16KB (16384 byte) ROM image, while the
|
||||
MULTICOMP architecture expects an 8KB (8192 byte) ROM image. Images
|
||||
are loaded via the "Load ROM..." action in the "File" menu. The
|
||||
selected ROM file will be loaded into memory at the correct ROM base
|
||||
address.
|
||||
|
||||
### 3.4 Memory Window
|
||||
|
||||
![Memory Window] (https://github.com/sethm/symon/raw/master/screenshots/memory_window.png)
|
||||

|
||||
|
||||
Memory contents can be viewed (and edited) one page at a time through the Memory Window.
|
||||
|
||||
### 3.5 Trace Log
|
||||
|
||||
![Trace Log] (https://github.com/sethm/symon/raw/master/screenshots/trace_log.png)
|
||||

|
||||
|
||||
The last 20,000 execution steps are disassembled and logged to the Trace Log Window.
|
||||
The last 20,000 execution steps are disassembled and logged to the Trace Log
|
||||
Window.
|
||||
|
||||
### 3.6 NEW - Experimental 6545 CRTC Video
|
||||
### 3.6 Simulator Speeds
|
||||
|
||||
![Composite Video] (https://github.com/sethm/symon/raw/master/screenshots/video_window.png)
|
||||

|
||||
|
||||
This feature is highly experimental. It's possible to open a video window from the "View" menu.
|
||||
This window simulates the output of a MOS 6545 CRT Controller located at address `$9000` and
|
||||
`$9001`.
|
||||
Simulated speeds may be set from 1MHz to 8MHz.
|
||||
|
||||
By default, the 40 x 25 character display uses video memory located at base address `$7000`.
|
||||
This means that the memory from address `$7000` (28672 decimal) to `$73E8` (29672 decimal)
|
||||
is directly mapped to video.
|
||||
### 3.7 Breakpoints
|
||||
|
||||

|
||||
|
||||
Breakpoints can be set and removed through the Breakpoints window.
|
||||
|
||||
### 3.8 Experimental 6545 CRTC Video
|
||||
|
||||

|
||||
|
||||
This feature is highly experimental. It's possible to open a video window
|
||||
from the "View" menu. This window simulates the output of a MOS 6545 CRT
|
||||
Controller located at address `$9000` and `$9001`.
|
||||
|
||||
By default, the 40 x 25 character display uses video memory located at base
|
||||
address `$7000`. This means that the memory from address `$7000` (28672
|
||||
decimal) to `$73E8` (29672 decimal) is directly mapped to video.
|
||||
|
||||
- Address Register (at address `$9000`)
|
||||
- R1: Horizontal Displayed Columns
|
||||
@@ -109,27 +170,29 @@ is directly mapped to video.
|
||||
- R14: Cursor Position (High Byte)
|
||||
- R15: Cursor Position (Low Byte)
|
||||
|
||||
Although the simulation is pretty good, there are a few key differences between
|
||||
the simulated 6545 and a real 6545:
|
||||
Although the simulation is pretty good, there are a few key differences
|
||||
between the simulated 6545 and a real 6545:
|
||||
|
||||
- The simulated 6545 supports only the straight binary addressing mode of the real 6545,
|
||||
and not the Row/Column addressing mode.
|
||||
- The simulated 6545 has full 16 bit addressing, where the real 6545 has only
|
||||
a 14-bit address bus.
|
||||
- The simulation is done at a whole-frame level, meaning that lots of
|
||||
6545 programming tricks that were achieved by updating the frame address
|
||||
during vertical and horizontal sync times are not achievable. There is no way
|
||||
(for example) to change the Display Start Address (R12 and R13) while a
|
||||
frame is being drawn.
|
||||
- The simulated 6545 supports only the straight binary addressing
|
||||
mode of the real 6545, and not the Row/Column addressing mode.
|
||||
|
||||
- The simulated 6545 has full 16 bit addressing, where the real 6545
|
||||
has only a 14-bit address bus.
|
||||
|
||||
- The simulation is done at a whole-frame level, meaning that lots
|
||||
of 6545 programming tricks that were achieved by updating the
|
||||
frame address during vertical and horizontal sync times are not
|
||||
achievable. There is no way (for example) to change the Display Start
|
||||
Address (R12 and R13) while a frame is being drawn.
|
||||
|
||||
For more information on the 6545 CRTC and its programming model, please see the following resources
|
||||
|
||||
- [CRTC 6545/6845 Information (André Fachat)] (http://6502.org/users/andre/hwinfo/crtc/index.html)
|
||||
- [CRTC Operation (André Fachat)] (http://www.6502.org/users/andre/hwinfo/crtc/crtc.html)
|
||||
- [MOS 6545 Datasheet (PDF)] (http://www.6502.org/users/andre/hwinfo/crtc/crtc.html)
|
||||
- [CRTC 6545/6845 Information (André Fachat)](http://6502.org/users/andre/hwinfo/crtc/index.html)
|
||||
- [CRTC Operation (André Fachat)](http://www.6502.org/users/andre/hwinfo/crtc/crtc.html)
|
||||
- [MOS 6545 Datasheet (PDF)](http://www.6502.org/users/andre/hwinfo/crtc/crtc.html)
|
||||
|
||||
|
||||
#### 3.6.1 Example BASIC Program to test Video
|
||||
#### 3.8.1 Example BASIC Program to test Video
|
||||
|
||||
This program will fill the video screen with all printable characters.
|
||||
|
||||
@@ -152,28 +215,57 @@ Maven will build Symon, run unit tests, and produce a jar file in the
|
||||
`target` directory containing the compiled simulator.
|
||||
|
||||
Symon is meant to be invoked directly from the jar file. To run with
|
||||
Java 1.5 or greater, just type:
|
||||
Java 1.8 or greater, just type:
|
||||
|
||||
$ java -jar symon-0.9.0.jar
|
||||
$ java -jar symon-1.2.0.jar
|
||||
|
||||
When Symon is running, you should be presented with a simple graphical
|
||||
interface.
|
||||
|
||||
### 4.2 ROM images
|
||||
#### 4.1.1 Command Line Options
|
||||
|
||||
The simulator requires a 16KB ROM image loaded at address `$C000` to `$FFFF` to
|
||||
work properly. Without a ROM in memory, the simulator will not be able to
|
||||
reset, since the reset vector for the 6502 is located in this address space.
|
||||
Two command line options may be passed to the JAR file on startup,
|
||||
to specify machine type and CPU type. The options are:
|
||||
|
||||
By default, any 16KB file named `rom.bin` that exists in the same directory
|
||||
where Symon is launched will be loaded as a ROM image. ROM images can also
|
||||
be swapped out at run-time with the "Load ROM Image..." in the File menu.
|
||||
- `-c`,`-cpu 6502`: Use the NMOS 6502 CPU type by default.
|
||||
- `-c`,`-cpu 65c02`: Use the CMOS 65C02 CPU type by default.
|
||||
- `-c`,`-machine symon`: Use the **Symon** machine type by default.
|
||||
- `-c`,`-machine multicomp`: Use the **Multicomp** machine type by default.
|
||||
- `-m`,`-machine simple`: Use the **Simple** machine type by default.
|
||||
- `-m`,`-machine beneater`: Use the **BenEater** machine type by default.
|
||||
- `-r`,`-rom <file>`: Use the specified file as the ROM image.
|
||||
- `-b`,`-brk`: Halt the simulator on a BRK instruction (default is to continue)
|
||||
|
||||
The "samples" directory contains a ROM image named 'ehbasic.rom', containing
|
||||
Lee Davison's Enhanced 6502 BASIC. This serves as a good starting point for
|
||||
exploration.
|
||||
### 4.2 High-DPI UI scaling
|
||||
|
||||
### 4.3 Loading A Program
|
||||
In certain environments with high-DPI (e.g. 4K) displays, the UI may
|
||||
not automatically scale and appear quite tiny. This can be fixed
|
||||
with the command line argument `-Dsun.java2d.uiScale=<factor>`,
|
||||
for example:
|
||||
|
||||
```
|
||||
java -Dsun.java2d.uiScale=2.0 -jar symon-1.5.0.jar
|
||||
```
|
||||
|
||||
### 4.3 ROM images
|
||||
|
||||
The simulator requires a ROM image loaded into memory to work
|
||||
properly. Without a ROM in memory, the simulator will not be able to
|
||||
reset, since the reset vector for the 6502 is located in the ROM
|
||||
address space.
|
||||
|
||||
ROM images can be loaded with the `-rom` argument when running
|
||||
Symon from the command line. ROM images can also be swapped out at
|
||||
run-time with the "Load ROM..." item in the File menu.
|
||||
|
||||
The "samples" directory contains a ROM image for the Symon
|
||||
architecture named 'ehbasic.rom', containing Lee Davison's Enhanced
|
||||
6502 BASIC. This serves as a good starting point for exploration.
|
||||
|
||||
*Note*: Presently, EhBASIC only works with the Symon machine
|
||||
architecture, not with MULTICOMP.
|
||||
|
||||
### 4.4 Loading A Program
|
||||
|
||||
In addition to ROM images, programs in the form of raw binary object files can
|
||||
be loaded directly into memory from "Load Program..." in the File menu.
|
||||
@@ -184,18 +276,73 @@ reset.
|
||||
|
||||
There are two very simple sample program in the "samples" directory,
|
||||
for testing.
|
||||
|
||||
|
||||
- 'echo.prg' will echo back anything typed at the console.
|
||||
|
||||
- 'hello.prg' will continuously print "Hello, 6502 World!" to the console.
|
||||
|
||||
### 4.4 Running
|
||||
### 4.5 Running
|
||||
|
||||
After loading a program or ROM image, clicking "Run" will start the simulator
|
||||
running.
|
||||
|
||||
## 5.0 Revision History
|
||||
|
||||
- **1.5.0:** 30 March 2025 - Fixed a bug that caused some 6502
|
||||
instructions to be disassembled improperly in the trace log
|
||||
(GitHub issue #17).
|
||||
|
||||
Added a new "Step Over" button that allows stepping over the
|
||||
current subroutine. This button only becomes active when the
|
||||
next instruction is a "JSR" while stepping through execution
|
||||
one instruction at a time. It will continue execution until
|
||||
the subroutine returns through a corresponding "RTS" instruction.
|
||||
(GitHub feature request #18).
|
||||
|
||||
- **1.4.0:** 11 November 2023 - Adds a new machine, the Ben Eater
|
||||
machine. Correct handling of 6551 interrupts, and several 6551
|
||||
bug fixes. Fixes power-on status of 6502 status register. Fixes a
|
||||
bug with ASCII backspace character not moving the cursor
|
||||
backwards. Finally, "halt on BRK" is no longer enabled by default,
|
||||
but can be set at runtime or by a command line flag. Thank you to
|
||||
Tim Allen and Chelsea Wilkinson for contributions!
|
||||
|
||||
- **1.3.2:** 8 March 2022 - Minor bug fixes.
|
||||
|
||||
- **1.3.1:** 12 October, 2019 - Add support for new command line
|
||||
option `-cpu <type>` to specify one of `6502` or `65c02` on startup,
|
||||
and new option `-rom <file>` to specify a ROM file to load.
|
||||
|
||||
- **1.3.0:** 24 February, 2018 - Adds support for 65C02 opcodes.
|
||||
|
||||
- **1.2.1:** 8 January, 2016 - Remove dependency on Java 8. Now
|
||||
supports compiling and running under Java 1.7.
|
||||
|
||||
- **1.2.0:** 3 January, 2016 - Add symbolic disassembly to breakpoints
|
||||
window.
|
||||
|
||||
- **1.1.1:** 2 January, 2016 - Minor enhancement: Allows breakpoints
|
||||
to be added with the Enter key.
|
||||
|
||||
- **1.1.0:** 31 December, 2015 - Fixed delay loop to better
|
||||
simulate various clock speeds. Added ability to select clock
|
||||
speed at runtime. Status display now shows the next instruction
|
||||
to be executed, instead of the last instruction executed.
|
||||
Added support for breakpoints.
|
||||
|
||||
- **1.0.0:** 10 August, 2014 - Added "Simple" machine
|
||||
implementation, pure RAM with no IO. Added Klaus Dormann's
|
||||
6502 Functional Tests for further machine verification (these
|
||||
tests must be run in the "Simple" machine).
|
||||
|
||||
- **0.9.9.1:** 27 July, 2014 - Pressing 'Control' while clicking
|
||||
'Reset' now performs a memory clear.
|
||||
|
||||
- **0.9.9:** 26 July, 2014 - MULTICOMP and multi-machine support
|
||||
contributed by Maik Merten <maikmerten@googlemail.com>
|
||||
|
||||
- **0.9.1:** 26 January, 2014 - Support for IRQ and NMI handling.
|
||||
|
||||
- **0.9.0:** 29 December, 2013 - First pass at a 6545 CRTC simulation.
|
||||
|
||||
- **0.8.5:** 30 March, 2013 - ASCII display for memory window.
|
||||
@@ -225,42 +372,62 @@ running.
|
||||
|
||||
- **0.1:** 20 January, 2010
|
||||
|
||||
## 6.0 To Do
|
||||
## 6.0 Roadmap
|
||||
|
||||
- **1.2:** Better breakpoint support. Symbolic debugging of breakpoints.
|
||||
|
||||
- **2.0:** Complete rewrite of the UI in JavaFX instead of Swing. Complete
|
||||
assembler and disassembler built in. Ability to attach source code for
|
||||
symbolic debugging.
|
||||
|
||||
## 7.0 To Do
|
||||
|
||||
- Feedback (in the form of dialogs, status bar, etc).
|
||||
|
||||
- Better debugging tools from the UI, including breakpoints
|
||||
and disassembly.
|
||||
|
||||
- More accurate timing.
|
||||
|
||||
- Smarter interrupt handling.
|
||||
|
||||
- UI needs a ton more polish.
|
||||
|
||||
- More extensive testing.
|
||||
|
||||
- Clean up JavaDoc.
|
||||
|
||||
- Implement CMOS 65C02 instructions and NMOS / CMOS mode flag.
|
||||
|
||||
- Allow displaying ACIA status and dumping ACIA buffers, for
|
||||
debugging.
|
||||
|
||||
## 7.0 Acknowledgements
|
||||
- CRTC emulation is very naive. The whole frame is drawn in one
|
||||
CPU step. This should be improved by drawing scan lines during
|
||||
machine steps to approximate real NTSC/PAL refresh rates.
|
||||
|
||||
- Symbolic debugging.
|
||||
|
||||
- Better / correct disassembly and tracing of 65C02 and 65C816
|
||||
instructions.
|
||||
|
||||
## 8.0 Copyright and Acknowledgements
|
||||
|
||||
**Copyright (c) 2008-2025 Seth J. Morabito <web@loomcom.com>**
|
||||
|
||||
- Portions Copyright (c) 2014 Maik Merten
|
||||
<maikmerten@googlemail.com>
|
||||
- Portions Copyright (c) 2022 Tim Allen
|
||||
<thristian@gmail.com>
|
||||
- Portions Copyright (c) 2023 Chelsea Wilkinson
|
||||
<mail@chelseawilkinson.me>
|
||||
|
||||
Additional components used in this project are copyright their respective owners.
|
||||
|
||||
- Enhanced 6502 BASIC Copyright (c) Lee Davison
|
||||
- 6502 Functional Tests Copyright (c) Klaus Dormann
|
||||
- JTerminal Copyright (c) Graham Edgecombe
|
||||
|
||||
This project would not have been possible without the following resources:
|
||||
|
||||
- [Graham Edgecombe's JTerminal project] (https://github.com/grahamedgecombe/jterminal),
|
||||
which forms the core of Symon's console.
|
||||
|
||||
- [Andrew Jacobs' 6502 Pages] (http://www.obelisk.demon.co.uk/6502/), for
|
||||
- [Andrew Jacobs' 6502 Pages](http://obelisk.me.uk/6502/), for
|
||||
wonderfully detailed information about the 6502
|
||||
|
||||
- [Neil Parker's "The 6502/65C02/65C816 Instruction Set Decoded"] (http://www.llx.com/~nparker/a2/opcodes.html),
|
||||
- [Neil Parker's "The 6502/65C02/65C816 Instruction Set Decoded"](http://www.llx.com/~nparker/a2/opcodes.html),
|
||||
for information about how instructions are coded
|
||||
|
||||
## 8.0 Licensing
|
||||
## 9.0 Licensing
|
||||
|
||||
Symon is free software. It is distributed under the MIT License.
|
||||
Please see the file 'COPYING' for full details of the license.
|
||||
@@ -1,12 +1,13 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<project xmlns="https://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="https://maven.apache.org/POM/4.0.0 https://maven.apache.org/maven-v4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.loomcom.symon</groupId>
|
||||
<artifactId>symon</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>0.9.0.1</version>
|
||||
<version>1.5.1k</version>
|
||||
<name>symon</name>
|
||||
<url>http://www.loomcom.com/symon</url>
|
||||
<url>https://git.loomcom.com/seth/symon</url>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>
|
||||
UTF-8
|
||||
@@ -17,86 +18,80 @@
|
||||
</properties>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>jline</id>
|
||||
<name>JLine Project Repository</name>
|
||||
<url>http://jline.sourceforge.net/m2repo</url>
|
||||
</repository>
|
||||
<!-- Loomcom's Maven2 repository for JTerminal -->
|
||||
<repository>
|
||||
<releases>
|
||||
<enabled>true</enabled>
|
||||
<updatePolicy>always</updatePolicy>
|
||||
<checksumPolicy>fail</checksumPolicy>
|
||||
</releases>
|
||||
<id>com.loomcom</id>
|
||||
<name>Loom Communications Maven2 Repository</name>
|
||||
<url>http://www.loomcom.com/maven2</url>
|
||||
<layout>default</layout>
|
||||
<id>jitpack.io</id>
|
||||
<url>https://jitpack.io</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.11</version>
|
||||
<scope>test</scope>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-classic</artifactId>
|
||||
<version>1.5.34</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.grahamedgecombe.jterminal</groupId>
|
||||
<artifactId>jterminal</artifactId>
|
||||
<version>1.0.2.3-loomcom</version>
|
||||
<groupId>commons-cli</groupId>
|
||||
<artifactId>commons-cli</artifactId>
|
||||
<version>1.5.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.formdev</groupId>
|
||||
<artifactId>flatlaf</artifactId>
|
||||
<version>3.7.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.Dansoftowner</groupId>
|
||||
<artifactId>jSystemThemeDetector</artifactId>
|
||||
<version>3.9.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.13.2</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-all</artifactId>
|
||||
<version>1.9.5</version>
|
||||
<artifactId>mockito-core</artifactId>
|
||||
<version>4.11.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.java.dev.jna</groupId>
|
||||
<artifactId>jna</artifactId>
|
||||
<version>5.14.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-resources-plugin</artifactId>
|
||||
<version>2.6</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>copy-resources</id>
|
||||
<phase>process-resources</phase>
|
||||
<goals>
|
||||
<goal>copy-resources</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<outputDirectory>${basedir}/target/classes/com/loomcom/symon/ui/images</outputDirectory>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/java/com/loomcom/symon/ui/images</directory>
|
||||
</resource>
|
||||
</resources>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<version>2.4</version>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.2.0</version>
|
||||
<configuration>
|
||||
<descriptorRefs>
|
||||
<descriptorRef>jar-with-dependencies</descriptorRef>
|
||||
</descriptorRefs>
|
||||
<appendAssemblyId>false</appendAssemblyId>
|
||||
<archive>
|
||||
<manifest>
|
||||
<mainClass>com.loomcom.symon.Simulator</mainClass>
|
||||
</manifest>
|
||||
</archive>
|
||||
<transformers>
|
||||
<transformer
|
||||
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
|
||||
<mainClass>com.loomcom.symon.Main</mainClass>
|
||||
</transformer>
|
||||
</transformers>
|
||||
<filters>
|
||||
<filter>
|
||||
<artifact>*:*</artifact>
|
||||
<excludes>
|
||||
<exclude>META-INF/*.SF</exclude>
|
||||
<exclude>META-INF/*.DSA</exclude>
|
||||
<exclude>META-INF/*.RSA</exclude>
|
||||
</excludes>
|
||||
</filter>
|
||||
</filters>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>make-assembly</id>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>single</goal>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
@@ -104,11 +99,11 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.1</version>
|
||||
<version>3.7.0</version>
|
||||
<configuration>
|
||||
<compilerArgument>-Xlint:unchecked</compilerArgument>
|
||||
<source>1.6</source>
|
||||
<target>1.6</target>
|
||||
<source>16</source>
|
||||
<target>16</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
@@ -116,7 +111,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>2.4</version>
|
||||
<version>3.2.0</version>
|
||||
<configuration>
|
||||
<archive>
|
||||
<manifest>
|
||||
@@ -148,4 +143,4 @@
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
</project>
|
||||
@@ -6,32 +6,37 @@ Sample Programs
|
||||
When loaded at address $0300, this program will print "Hello, 6502 World!" in
|
||||
infinite loop.
|
||||
|
||||
2. echo.prg
|
||||
2. echo_poll.prg
|
||||
|
||||
When loaded at address $0300, this program will echo back to the console
|
||||
anything typed.
|
||||
|
||||
|
||||
Both hello.prg and echo.prg were assembled with the Ophis assembler:
|
||||
Both hello.prg and echo_poll.prg were assembled with the Ophis assembler:
|
||||
|
||||
https://hkn.eecs.berkeley.edu/~mcmartin/ophis/
|
||||
|
||||
3. echo_irq.rom
|
||||
|
||||
3. ehbasic.rom
|
||||
This is another echo program, and behaves identically to echo_poll.prg,
|
||||
except it is interrupt-driven. This ROM can be loaded either through the
|
||||
"File->Load ROM..." menu in Symon, or by specifying the path to
|
||||
"echo_irq.rom" with the "-jar" command line option when running Symon,
|
||||
for example: `java -jar symon-1.3.2.jar -rom samples/echo_irq.rom`
|
||||
|
||||
4. ehbasic.rom
|
||||
|
||||
This is Lee Davison's Enhanced 6502 BASIC.
|
||||
|
||||
To use this ROM image, just copy the file 'ehbasic.rom' into the directory
|
||||
where you run Symon. Rename the file to 'rom.bin'. When you start Symon,
|
||||
the ROM file will be automatically loaded at address $d000.
|
||||
The EhBASIC ROM can be loaded either through the "File -> Load ROM..."
|
||||
menu in Symon, or by specifying the path to "ehbasic.rom" with
|
||||
the "-jar" command line option when running Symon, for example:
|
||||
`java -jar symon-1.3.2.jar -rom samples/ehbasic.rom`
|
||||
|
||||
Click the "Run" button and EhBASIC should automatically start running.
|
||||
|
||||
Type 'C' to do a cold start.
|
||||
|
||||
Then, type $C000 when prompted for the memory size.
|
||||
|
||||
NOTE: EhBASIC only wants upper-case input. This confused me at first!
|
||||
Then, type '49152' (without the quotes) when prompted for the memory size.
|
||||
|
||||
More information can be found in the 'ehbasic' directory, and by visiting
|
||||
the EhBASIC web page:
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
*.rom
|
||||
*.lst
|
||||
*.map
|
||||
*.o
|
||||
@@ -0,0 +1,13 @@
|
||||
CA=ca65
|
||||
LD=ld65
|
||||
|
||||
all: echo_irq
|
||||
|
||||
echo_irq: echo_irq.o
|
||||
$(LD) -C symon.config -vm -m echo_irq.map -o echo_irq.rom echo_irq.o
|
||||
|
||||
echo_irq.o:
|
||||
$(CA) --listing echo_irq.lst -o echo_irq.o echo_irq.asm
|
||||
|
||||
clean:
|
||||
rm -f *.o *.rom *.map *.lst
|
||||
@@ -0,0 +1,48 @@
|
||||
;;
|
||||
;; Read input from the keyboard, and echo to console.
|
||||
;;
|
||||
|
||||
|
||||
IOBASE = $8800
|
||||
IOSTATUS = IOBASE + 1
|
||||
IOCMD = IOBASE + 2
|
||||
IOCTRL = IOBASE + 3
|
||||
|
||||
.segment "CODE"
|
||||
.org $C000
|
||||
|
||||
START: CLI
|
||||
LDA #$09
|
||||
STA IOCMD ; Set command status
|
||||
LDA #$1A
|
||||
STA IOCTRL ; 0 stop bits, 8 bit word, 2400 baud
|
||||
|
||||
;;
|
||||
;; Infinite idle loop, waiting for interrupt.
|
||||
;;
|
||||
IDLE: LDA #$FF
|
||||
TAX
|
||||
IDLE1: DEX
|
||||
BNE IDLE1
|
||||
JMP IDLE
|
||||
|
||||
;;
|
||||
;; IRQ handler
|
||||
;;
|
||||
IRQ: LDA IOBASE ; Get the character in the ACIA.
|
||||
PHA ; Save accumulator
|
||||
ECHO1: LDA IOSTATUS ; Read the ACIA status
|
||||
AND #$10 ; Is the tx register empty?
|
||||
BEQ ECHO1 ; No, wait for it to empty
|
||||
PLA ; Otherwise, load saved accumulator,
|
||||
STA IOBASE ; write to output,
|
||||
RTI ; and return
|
||||
|
||||
; system vectors
|
||||
|
||||
.segment "VECTORS"
|
||||
.org $FFFA
|
||||
|
||||
.word IRQ ; NMI vector
|
||||
.word START ; RESET vector
|
||||
.word IRQ ; IRQ vector
|
||||
@@ -0,0 +1,16 @@
|
||||
MEMORY {
|
||||
RAM1: start = $0000, size = $8000 - __STACKSIZE__;
|
||||
ROM1: start = $C000, size = $3FFA, fill = yes;
|
||||
ROMV: start = $FFFA, size = $6, file = %O, fill = yes;
|
||||
}
|
||||
|
||||
SEGMENTS {
|
||||
CODE: load = ROM1, type = ro;
|
||||
DATA: load = ROM1, type = ro;
|
||||
VECTORS: load = ROMV, type = ro;
|
||||
}
|
||||
|
||||
SYMBOLS {
|
||||
__STACKSIZE__: type = weak, value = $0300;
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ ehbasic: ehbasic.o
|
||||
$(LD) -C symon.config -vm -m ehbasic.map -o ehbasic.rom ehbasic.o
|
||||
|
||||
ehbasic.o:
|
||||
$(CA) --listing -o ehbasic.o min_mon.asm
|
||||
$(CA) --listing ehbasic.lst -o ehbasic.o min_mon.asm
|
||||
|
||||
clean:
|
||||
rm -f *.o *.rom *.map *.lst
|
||||
@@ -150,7 +150,7 @@ END_CODE
|
||||
; sign on string
|
||||
|
||||
LAB_mess
|
||||
.byte $0D,$0A,"Symon (c) 2008-2013, Seth Morabito"
|
||||
.byte $0D,$0A,"Symon (c) 2008-2014, Seth Morabito"
|
||||
.byte $0D,$0A,"Enhanced 6502 BASIC 2.22 (c) Lee Davison"
|
||||
.byte $0D,$0A,"[C]old/[W]arm ?",$00
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
MEMORY {
|
||||
RAM1: start = $0000, size = $8000;
|
||||
RAM1: start = $0000, size = $8000 - __STACKSIZE__;
|
||||
ROM1: start = $C000, size = $3F00, fill = yes;
|
||||
MONITOR: start = $FF00, size = $FA, fill = yes;
|
||||
ROMV: start = $FFFA, size = $6, file = %O, fill = yes;
|
||||
@@ -13,6 +13,6 @@ VECTORS: load = ROMV, type = ro;
|
||||
}
|
||||
|
||||
SYMBOLS {
|
||||
__STACKSIZE__ = $0300;
|
||||
__STACKSIZE__: type = weak, value = $0300;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
*.rom
|
||||
*.lst
|
||||
*.map
|
||||
*.o
|
||||
@@ -0,0 +1,13 @@
|
||||
CA=ca65
|
||||
LD=ld65
|
||||
|
||||
all: ehbasic
|
||||
|
||||
ehbasic: ehbasic.o
|
||||
$(LD) -C symon.config -vm -m ehbasic.map -o ehbasic.rom ehbasic.o
|
||||
|
||||
ehbasic.o:
|
||||
$(CA) --listing ehbasic.lst -o ehbasic.o min_mon.asm
|
||||
|
||||
clean:
|
||||
rm -f *.o *.rom *.map *.lst
|
||||
@@ -0,0 +1,85 @@
|
||||
This directoy contains a very slightly modified version of EhBASIC 2.22
|
||||
to support the Symon simulator.
|
||||
|
||||
Usage
|
||||
-----
|
||||
|
||||
The pre-assemled ROM image 'ehbasic.rom' in the "samples" directory is all you
|
||||
need unless you want to rebuild this source code.
|
||||
|
||||
Just copy the image 'ehbasic.rom' to the directory where you run Symon, and
|
||||
rename the file to 'rom.bin'. It will be loaded at memory location $D000 when
|
||||
the simulator starts up. Click "Run" and you'll be presented with BASIC.
|
||||
|
||||
At the first prompt, type 'C' for a Cold Start
|
||||
|
||||
When prompted for free memory, type: $C000
|
||||
|
||||
Note that EhBASIC only accepts upper case input, so you'll need to use caps
|
||||
lock (the cruise control for cool) to really make the most of it.
|
||||
|
||||
|
||||
Building
|
||||
--------
|
||||
|
||||
|
||||
To build it, you'll need the CC65 tool chain from http://www.cc65.org/
|
||||
and a suitable version of 'make'. Just typing:
|
||||
|
||||
% make
|
||||
|
||||
in this directory should re-build everything. You'll get a listing,
|
||||
some object files, and the ROM image itself.
|
||||
|
||||
|
||||
Changes from the EhBASIC 2.22
|
||||
-----------------------------
|
||||
|
||||
- Minor syntax changes to allow assembly with the cc65 tool chain.
|
||||
|
||||
- Memory map modified for Symon.
|
||||
|
||||
- At reset, configure the 6551 ACIA for 8-N-1, 2400 baud.
|
||||
|
||||
- Monitor routines 'ACIAin' and 'ACIAout' modified for the 6551 ACIA.
|
||||
Specifically, reading and writing will check the 6551 status register for
|
||||
the status of rx and tx registers before receive or transmit.
|
||||
|
||||
EhBASIC is copyright Lee Davison <leeedavison@googlemail.com>
|
||||
|
||||
My changes are so slight that I hesitate to even say this, but for "CYA"
|
||||
reasons:
|
||||
|
||||
Changes are copyright Seth Morabito <web@loomcom.com> and are distributed under
|
||||
the same license as EhBASIC. I claim no commercial interest whatsoever. Any
|
||||
commercial use must be negotiated directly with Lee Davison.
|
||||
|
||||
|
||||
Original EhBASIC 2.22 README
|
||||
----------------------------
|
||||
|
||||
Enhanced BASIC is a BASIC interpreter for the 6502 family microprocessors. It
|
||||
is constructed to be quick and powerful and easily ported between 6502 systems.
|
||||
It requires few resources to run and includes instructions to facilitate easy
|
||||
low level handling of hardware devices. It also retains most of the powerful
|
||||
high level instructions from similar BASICs.
|
||||
|
||||
EhBASIC is free but not copyright free. For non commercial use there is only one
|
||||
restriction, any derivative work should include, in any binary image distributed,
|
||||
the string "Derived from EhBASIC" and in any distribution that includes human
|
||||
readable files a file that includes the above string in a human readable form
|
||||
e.g. not as a comment in an HTML file.
|
||||
|
||||
For commercial use please contact me, Lee Davison, at leeedavison@googlemail.com
|
||||
for conditions.
|
||||
|
||||
For more information on EhBASIC, other versions of EhBASIC and other projects
|
||||
please visit my site at ..
|
||||
|
||||
http://mycorner.no-ip.org/index.html
|
||||
|
||||
|
||||
P.S. c't magazin, henceforth refered to as "those thieving german bastards", are
|
||||
prohibited from using this or any version of EhBASIC for any of their projects
|
||||
or products. The excuse "we don't charge people for it" doesn't wash, it adds
|
||||
value to your product so you owe me.
|
||||
@@ -0,0 +1,449 @@
|
||||
|
||||
; minimal monitor for EhBASIC and 6502 simulator V1.05
|
||||
|
||||
; To run EhBASIC on the simulator load and assemble [F7] this file, start the simulator
|
||||
; running [F6] then start the code with the RESET [CTRL][SHIFT]R. Just selecting RUN
|
||||
; will do nothing, you'll still have to do a reset to run the code.
|
||||
|
||||
.feature labels_without_colons
|
||||
.include "basic.asm"
|
||||
|
||||
; put the IRQ and MNI code in RAM so that it can be changed
|
||||
|
||||
IRQ_vec = VEC_SV+2 ; IRQ code vector
|
||||
NMI_vec = IRQ_vec+$0A ; NMI code vector
|
||||
|
||||
; setup for the 6502 simulator environment
|
||||
|
||||
IO_AREA = $8800
|
||||
ACIAdata = IO_AREA ; simulated ACIA r/w port
|
||||
ACIAstatus = IO_AREA+1
|
||||
ACIAcommand = IO_AREA+2
|
||||
ACIAcontrol = IO_AREA+3
|
||||
|
||||
CRTC_A = $9000 ; CRTC register select
|
||||
CRTC_C = $9001 ; CRTC register IO
|
||||
CADDR_L = $E0 ; Cursor address (low)
|
||||
CADDR_H = $E1 ; Cursor address (high)
|
||||
C_COL = $E2 ; Cursor column
|
||||
C_ROW = $E3 ; Cursor row
|
||||
COUTC = $E4 ; Temp storage for char out.
|
||||
R_STRT = $E5 ; E5,E6 contains starting address of
|
||||
; current row
|
||||
R_NXT = $E7 ; E7,E8 contains starting address of
|
||||
; next row
|
||||
|
||||
N_ROWS = 24
|
||||
N_COLS = 40
|
||||
|
||||
|
||||
; now the code. all this does is set up the vectors and interrupt code
|
||||
; and wait for the user to select [C]old or [W]arm start. nothing else
|
||||
; fits in less than 128 bytes
|
||||
|
||||
.segment "MONITOR"
|
||||
.org $FC00 ; pretend this is in a 1/8K ROM
|
||||
|
||||
; reset vector points here
|
||||
|
||||
RES_vec:
|
||||
CLD ; clear decimal mode
|
||||
LDX #$FF ; empty stack
|
||||
TXS ; set the stack
|
||||
|
||||
;; Initialize the CRTC
|
||||
LDA #$01
|
||||
STA CRTC_A
|
||||
LDA #N_COLS ; 40 columns
|
||||
STA CRTC_C
|
||||
LDA #$06
|
||||
STA CRTC_A
|
||||
LDA #N_ROWS ; 24 rows
|
||||
STA CRTC_C
|
||||
LDA #$70
|
||||
STA CADDR_H
|
||||
LDA #$00
|
||||
STA CADDR_L
|
||||
STA C_ROW
|
||||
STA C_COL
|
||||
JSR CLRVID
|
||||
;; TODO: Initialize params on CRTC
|
||||
|
||||
; Initialize the ACIA
|
||||
ACIA_init:
|
||||
LDA #$00
|
||||
STA ACIAstatus ; Soft reset
|
||||
LDA #$0B
|
||||
STA ACIAcommand ; Parity disabled, IRQ disabled
|
||||
LDA #$1E
|
||||
STA ACIAcontrol ; Set output for 8-N-1 9600
|
||||
|
||||
; set up vectors and interrupt code, copy them to page 2
|
||||
|
||||
LDY #END_CODE-LAB_vec ; set index/count
|
||||
LAB_stlp:
|
||||
LDA LAB_vec-1,Y ; get byte from interrupt code
|
||||
STA VEC_IN-1,Y ; save to RAM
|
||||
DEY ; decrement index/count
|
||||
BNE LAB_stlp ; loop if more to do
|
||||
|
||||
; now do the signon message, Y = $00 here
|
||||
|
||||
LAB_signon:
|
||||
LDA LAB_mess,Y ; get byte from sign on message
|
||||
BEQ LAB_nokey ; exit loop if done
|
||||
|
||||
JSR V_OUTP ; output character
|
||||
INY ; increment index
|
||||
BNE LAB_signon ; loop, branch always
|
||||
|
||||
LAB_nokey:
|
||||
JSR V_INPT ; call scan input device
|
||||
BCC LAB_nokey ; loop if no key
|
||||
|
||||
AND #$DF ; mask xx0x xxxx, ensure upper case
|
||||
CMP #'W' ; compare with [W]arm start
|
||||
BEQ LAB_dowarm ; branch if [W]arm start
|
||||
|
||||
CMP #'C' ; compare with [C]old start
|
||||
BNE RES_vec ; loop if not [C]old start
|
||||
|
||||
JMP LAB_COLD ; do EhBASIC cold start
|
||||
|
||||
LAB_dowarm:
|
||||
JMP LAB_WARM ; do EhBASIC warm start
|
||||
|
||||
|
||||
ACIAout:
|
||||
|
||||
PHA
|
||||
@loop: LDA ACIAstatus
|
||||
AND #$10
|
||||
BEQ @loop ; Wait for buffer to empty
|
||||
PLA
|
||||
STA ACIAdata
|
||||
RTS
|
||||
|
||||
;;; Byte out to the CRTC
|
||||
;;;
|
||||
;;; 1. Increment cursor position.
|
||||
;;; 2. Scroll if necessary.
|
||||
;;; 3. Store new cursor position in CRTC.
|
||||
|
||||
CRTCout:
|
||||
JSR ACIAout ; Also echo to terminal for debugging.
|
||||
|
||||
;; In parallel, we're maintaining two states:
|
||||
;; - The address of the cursor, and
|
||||
;; - The Column/Row of the cursor.
|
||||
;;
|
||||
;; The latter state is used to handle scrolling and
|
||||
;; for knowing how far to back up the cursor
|
||||
;; for a carriage-return.
|
||||
|
||||
;; Backspace
|
||||
CMP #$08
|
||||
BEQ DO_BS
|
||||
;; Line Feed
|
||||
CMP #$0a
|
||||
BEQ DO_LF
|
||||
;; Carriage Return
|
||||
CMP #$0d
|
||||
BEQ DO_CR
|
||||
;; Any other character...
|
||||
STA COUTC ; Store the character going out
|
||||
JSR COUT1 ; Output it where the cursor is.
|
||||
;; We might need to scroll...
|
||||
LDA C_ROW
|
||||
CMP #N_ROWS-1
|
||||
BNE @noscr
|
||||
LDA C_COL
|
||||
CMP #N_COLS-1
|
||||
BNE @noscr
|
||||
;; ... yup, we DO need to scroll.
|
||||
JSR DO_SCROLL
|
||||
RTS
|
||||
@noscr: JSR INC_CADDR
|
||||
INC C_COL
|
||||
JSR SET_CURSOR
|
||||
RTS
|
||||
|
||||
;; Handle a back-space character.
|
||||
DO_BS: LDA C_COL
|
||||
BNE @l1 ; Skip next bit
|
||||
LDA #N_COLS-1
|
||||
STA C_COL
|
||||
BNE @l2
|
||||
@l1: DEC C_COL
|
||||
@l2: JSR DEC_CADDR ; Back up
|
||||
JSR SET_CURSOR
|
||||
|
||||
@l3: LDA #$20
|
||||
STA COUTC ; Echo a space ($20)
|
||||
JSR COUT1
|
||||
RTS
|
||||
|
||||
DO_LF: RTS ; Just swallow LF. CR emulates it.
|
||||
|
||||
DO_CR: SEC
|
||||
LDA CADDR_L ; 1. Carriage return to start of row.
|
||||
SBC C_COL
|
||||
STA CADDR_L
|
||||
LDA CADDR_H
|
||||
SBC #$00 ; Will decrement H if carry was left
|
||||
; set.
|
||||
STA CADDR_H
|
||||
|
||||
;; 1. Are we on the last row? Scroll.
|
||||
LDA C_ROW
|
||||
CMP #N_ROWS-1
|
||||
BNE @inc
|
||||
JSR DO_SCROLL
|
||||
RTS
|
||||
|
||||
@inc: JSR INCROW
|
||||
|
||||
@lf: CLC
|
||||
LDA CADDR_L
|
||||
ADC #$28 ; Now add $28
|
||||
STA CADDR_L
|
||||
LDA CADDR_H
|
||||
ADC #$00 ; Will increment if carry was set
|
||||
STA CADDR_H
|
||||
|
||||
LDA #$00 ; Reset cursor row to 0
|
||||
STA C_COL
|
||||
JSR SET_CURSOR
|
||||
RTS
|
||||
|
||||
SET_CURSOR:
|
||||
LDA #14
|
||||
STA CRTC_A
|
||||
LDA CADDR_H
|
||||
STA CRTC_C
|
||||
LDA #15
|
||||
STA CRTC_A
|
||||
LDA CADDR_L
|
||||
STA CRTC_C
|
||||
RTS
|
||||
|
||||
;; Increment C_ROW and put new
|
||||
;; line start address in R_STRT,R_STRT+1
|
||||
INCROW: TYA
|
||||
PHA
|
||||
INC C_ROW
|
||||
BNE DECR2 ; Share code with DECROW
|
||||
|
||||
;; Decrement C_ROW and put new
|
||||
;; line start address in R_STRT,R_STRT+1
|
||||
DECROW: TYA
|
||||
PHA
|
||||
DEC C_ROW
|
||||
DECR2: JSR SETRSTRT
|
||||
PLA
|
||||
TAY
|
||||
RTS
|
||||
|
||||
;; Send the cursor home to the start of the line
|
||||
HOME:
|
||||
LDY C_ROW
|
||||
LDA CRA_LO,Y
|
||||
STA CADDR_L
|
||||
LDA CRA_HI,Y
|
||||
STA CADDR_H
|
||||
LDA #$00
|
||||
STA C_COL
|
||||
RTS
|
||||
|
||||
;; Set the start address of the current row
|
||||
SETRSTRT:
|
||||
LDY C_ROW
|
||||
LDA CRA_LO,Y
|
||||
STA R_STRT
|
||||
LDA CRA_HI,Y
|
||||
STA R_STRT+1
|
||||
RTS
|
||||
|
||||
;; Clear the current video line
|
||||
CLRLN: LDA #$20
|
||||
LDY #$00
|
||||
@l1: STA (R_STRT),Y
|
||||
INY
|
||||
CPY #N_COLS
|
||||
BNE @l1
|
||||
RTS
|
||||
|
||||
;; Clear the video window and put the cursor at the home
|
||||
;; position
|
||||
CLRVID:
|
||||
LDA #$20
|
||||
LDX #N_ROWS-1
|
||||
@l1: STX C_ROW
|
||||
JSR SETRSTRT
|
||||
JSR CLRLN
|
||||
DEX
|
||||
BPL @l1
|
||||
RTS
|
||||
|
||||
;; Handle a scroll request.
|
||||
;;
|
||||
;; The cursor could be anywhere on the line when this scroll
|
||||
;; request comes in.
|
||||
DO_SCROLL:
|
||||
PHA
|
||||
TYA
|
||||
PHA
|
||||
TXA
|
||||
PHA
|
||||
|
||||
;; The idea here is to copy each line to the line above it
|
||||
LDX #$00
|
||||
|
||||
@l1: LDA CRA_LO,X
|
||||
STA R_STRT
|
||||
LDA CRA_HI,X
|
||||
STA R_STRT+1
|
||||
|
||||
INX
|
||||
|
||||
LDA CRA_LO,X
|
||||
STA R_NXT
|
||||
LDA CRA_HI,X
|
||||
STA R_NXT+1
|
||||
|
||||
LDY #0
|
||||
@l2: LDA (R_NXT),Y
|
||||
STA (R_STRT),Y
|
||||
INY
|
||||
CPY #N_COLS
|
||||
BNE @l2
|
||||
|
||||
CPX #N_ROWS
|
||||
BNE @l1
|
||||
|
||||
;; Clear the line the cursor occupies.
|
||||
JSR CLRLN
|
||||
|
||||
;; Move the cursor to the beginning of the line
|
||||
JSR HOME
|
||||
JSR SET_CURSOR
|
||||
|
||||
PLA
|
||||
TAX
|
||||
PLA
|
||||
TAY ; Restore Y
|
||||
PLA
|
||||
RTS
|
||||
|
||||
;; Decrement the cursor address
|
||||
INC_CADDR:
|
||||
INC CADDR_L
|
||||
BNE @l1 ; Did we increment to 0?
|
||||
INC CADDR_H ; Yes, also increment high
|
||||
@l1: RTS
|
||||
|
||||
;; Increment the cursor address
|
||||
DEC_CADDR:
|
||||
CMP CADDR_L ; Is low alrady 0?
|
||||
BNE @l1
|
||||
DEC CADDR_H ; Yes, decrement high
|
||||
@l1: DEC CADDR_L
|
||||
RTS
|
||||
|
||||
COUT1:
|
||||
TYA
|
||||
PHA ; Save Y
|
||||
LDY #$00
|
||||
LDA COUTC
|
||||
STA (CADDR_L),Y
|
||||
PLA
|
||||
TAY ; Restore Y
|
||||
RTS
|
||||
|
||||
;;;
|
||||
;;; byte in from ACIA. This subroutine will also force
|
||||
;;; all lowercase letters to be uppercase, because EhBASIC
|
||||
;;; only understands upper-case tokens
|
||||
;;;
|
||||
ACIAin:
|
||||
LDA ACIAstatus ; Read 6551 status
|
||||
AND #$08 ;
|
||||
BEQ LAB_nobyw ; If rx buffer empty, no byte
|
||||
|
||||
LDA ACIAdata ; Read byte from 6551
|
||||
CMP #'a' ; Is it < 'a'?
|
||||
BCC @done ; Yes, we're done
|
||||
CMP #'{' ; Is it >= '{'?
|
||||
BCS @done ; Yes, we're done
|
||||
AND #$5f ; Otherwise, mask to uppercase
|
||||
@done:
|
||||
SEC ; Flag byte received
|
||||
RTS
|
||||
|
||||
LAB_nobyw:
|
||||
CLC ; flag no byte received
|
||||
no_load: ; empty load vector for EhBASIC
|
||||
no_save: ; empty save vector for EhBASIC
|
||||
RTS
|
||||
|
||||
; vector tables
|
||||
|
||||
LAB_vec:
|
||||
.word ACIAin ; byte in from simulated ACIA
|
||||
.word CRTCout ; byte out to simulated ACIA
|
||||
.word no_load ; null load vector for EhBASIC
|
||||
.word no_save ; null save vector for EhBASIC
|
||||
|
||||
; EhBASIC IRQ support
|
||||
|
||||
IRQ_CODE:
|
||||
PHA ; save A
|
||||
LDA IrqBase ; get the IRQ flag byte
|
||||
LSR ; shift the set b7 to b6, and on down ...
|
||||
ORA IrqBase ; OR the original back in
|
||||
STA IrqBase ; save the new IRQ flag byte
|
||||
PLA ; restore A
|
||||
RTI
|
||||
|
||||
; EhBASIC NMI support
|
||||
|
||||
NMI_CODE:
|
||||
PHA ; save A
|
||||
LDA NmiBase ; get the NMI flag byte
|
||||
LSR ; shift the set b7 to b6, and on down ...
|
||||
ORA NmiBase ; OR the original back in
|
||||
STA NmiBase ; save the new NMI flag byte
|
||||
PLA ; restore A
|
||||
RTI
|
||||
|
||||
END_CODE:
|
||||
|
||||
|
||||
;;; CRTC row addresses: HIGH
|
||||
CRA_HI:
|
||||
.byte $70,$70,$70,$70,$70,$70,$70,$71
|
||||
.byte $71,$71,$71,$71,$71,$72,$72,$72
|
||||
.byte $72,$72,$72,$72,$73,$73,$73,$73
|
||||
|
||||
|
||||
;;; CRTC row addresses: LOW
|
||||
CRA_LO:
|
||||
.byte $00,$28,$50,$78,$A0,$C8,$F0,$18
|
||||
.byte $40,$68,$90,$B8,$E0,$08,$30,$58
|
||||
.byte $80,$A8,$D0,$F8,$20,$48,$70,$98
|
||||
|
||||
; sign on string
|
||||
LAB_mess:
|
||||
.byte $0D,$0A,"SYMON (C) 2008-2014, SETH MORABITO"
|
||||
.byte $0D,$0A,"ENHANCED 6502 BASIC 2.22 (C) LEE DAVISON"
|
||||
.byte $0D,$0A,"[C]OLD/[W]ARM ?",$00
|
||||
|
||||
|
||||
; system vectors
|
||||
|
||||
.segment "VECTORS"
|
||||
.org $FFFA
|
||||
|
||||
.word NMI_vec ; NMI vector
|
||||
.word RES_vec ; RESET vector
|
||||
.word IRQ_vec ; IRQ vector
|
||||
@@ -0,0 +1,18 @@
|
||||
MEMORY {
|
||||
RAM1: start = $0000, size = $8000 - __STACKSIZE__;
|
||||
ROM1: start = $C000, size = $3C00, fill = yes;
|
||||
MONITOR: start = $FC00, size = $3FA, fill = yes;
|
||||
ROMV: start = $FFFA, size = $6, file = %O, fill = yes;
|
||||
}
|
||||
|
||||
SEGMENTS {
|
||||
CODE: load = ROM1, type = ro;
|
||||
DATA: load = ROM1, type = ro;
|
||||
MONITOR: load = MONITOR, type = ro;
|
||||
VECTORS: load = ROMV, type = ro;
|
||||
}
|
||||
|
||||
SYMBOLS {
|
||||
__STACKSIZE__: type = weak, value = $0300;
|
||||
}
|
||||
|
||||
|
After Width: | Height: | Size: 27 KiB |
|
Before Width: | Height: | Size: 34 KiB After Width: | Height: | Size: 48 KiB |
|
Before Width: | Height: | Size: 25 KiB After Width: | Height: | Size: 38 KiB |
|
Before Width: | Height: | Size: 239 KiB After Width: | Height: | Size: 259 KiB |
|
Before Width: | Height: | Size: 19 KiB After Width: | Height: | Size: 35 KiB |
|
After Width: | Height: | Size: 42 KiB |
|
Before Width: | Height: | Size: 79 KiB After Width: | Height: | Size: 73 KiB |
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
* Copyright (c) 2008-2025 Seth J. Morabito <web@loomcom.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.loomcom.symon;
|
||||
|
||||
import com.loomcom.symon.exceptions.MemoryAccessException;
|
||||
import com.loomcom.symon.util.Utils;
|
||||
|
||||
import javax.swing.table.AbstractTableModel;
|
||||
import java.util.ArrayList;
|
||||
import java.util.TreeSet;
|
||||
|
||||
public class Breakpoints extends AbstractTableModel {
|
||||
|
||||
private final TreeSet<Integer> breakpoints;
|
||||
private final Simulator simulator;
|
||||
|
||||
public Breakpoints(Simulator simulator) {
|
||||
this.breakpoints = new TreeSet<>();
|
||||
this.simulator = simulator;
|
||||
}
|
||||
|
||||
public boolean contains(int address) {
|
||||
return this.breakpoints.contains(address);
|
||||
}
|
||||
|
||||
public void addBreakpoint(int address) {
|
||||
this.breakpoints .add(address);
|
||||
fireTableDataChanged();
|
||||
}
|
||||
|
||||
public void removeBreakpointAtIndex(int index) {
|
||||
if (index < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
ArrayList<Integer> values = new ArrayList<>(breakpoints);
|
||||
int value = values.get(index);
|
||||
this.breakpoints.remove(value);
|
||||
fireTableDataChanged();
|
||||
}
|
||||
|
||||
public void refresh() {
|
||||
fireTableDataChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getColumnName(int index) {
|
||||
if (index == 0) {
|
||||
return "Address";
|
||||
} else {
|
||||
return "Inst";
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRowCount() {
|
||||
return breakpoints.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getColumnCount() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getValueAt(int rowIndex, int columnIndex) {
|
||||
ArrayList<Integer> values = new ArrayList<>(breakpoints);
|
||||
|
||||
if (columnIndex == 0) {
|
||||
return "$" + Utils.wordToHex(values.get(rowIndex));
|
||||
} else if (columnIndex == 1) {
|
||||
int address = values.get(rowIndex);
|
||||
try {
|
||||
return simulator.disassembleOpAtAddress(address);
|
||||
} catch (MemoryAccessException ex) {
|
||||
return "???";
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2008-2013 Seth J. Morabito <sethm@loomcom.com>
|
||||
* Copyright (c) 2008-2025 Seth J. Morabito <web@loomcom.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
@@ -27,6 +27,12 @@ import com.loomcom.symon.devices.Device;
|
||||
import com.loomcom.symon.exceptions.MemoryAccessException;
|
||||
import com.loomcom.symon.exceptions.MemoryRangeException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import java.util.SortedSet;
|
||||
import java.util.TreeSet;
|
||||
|
||||
@@ -36,24 +42,28 @@ import java.util.TreeSet;
|
||||
public class Bus {
|
||||
|
||||
// The default address at which to load programs
|
||||
public static int DEFAULT_LOAD_ADDRESS = 0x0200;
|
||||
|
||||
public static final int DEFAULT_LOAD_ADDRESS = 0x0200;
|
||||
|
||||
// By default, our bus starts at 0, and goes up to 64K
|
||||
private int startAddress = 0x0000;
|
||||
private int endAddress = 0xffff;
|
||||
private final int startAddress;
|
||||
private final int endAddress;
|
||||
|
||||
// The CPU
|
||||
private Cpu cpu;
|
||||
|
||||
// Ordered list of IO devices.
|
||||
private SortedSet<Device> devices;
|
||||
// Ordered sets of IO devices, associated with their priority
|
||||
private final Map<Integer, SortedSet<Device>> deviceMap;
|
||||
|
||||
// an array for quick lookup of addresses, brute-force style
|
||||
private Device[] deviceAddressArray;
|
||||
|
||||
|
||||
public Bus(int size) {
|
||||
this(0, size - 1);
|
||||
}
|
||||
|
||||
public Bus(int startAddress, int endAddress) {
|
||||
this.devices = new TreeSet<Device>();
|
||||
this.deviceMap = new HashMap<>();
|
||||
this.startAddress = startAddress;
|
||||
this.endAddress = endAddress;
|
||||
}
|
||||
@@ -66,38 +76,67 @@ public class Bus {
|
||||
return endAddress;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a device to the bus. Throws a MemoryRangeException if the device overlaps with any others.
|
||||
*
|
||||
* @param device
|
||||
* @throws MemoryRangeException
|
||||
*/
|
||||
public void addDevice(Device device) throws MemoryRangeException {
|
||||
// Make sure there's no memory overlap.
|
||||
MemoryRange memRange = device.getMemoryRange();
|
||||
for (Device d : devices) {
|
||||
if (d.getMemoryRange().overlaps(memRange)) {
|
||||
throw new MemoryRangeException("The device being added at " +
|
||||
String.format("$%04X", memRange.startAddress()) +
|
||||
" overlaps with an existing " +
|
||||
"device, '" + d + "'");
|
||||
private void buildDeviceAddressArray() {
|
||||
int size = (this.endAddress - this.startAddress) + 1;
|
||||
deviceAddressArray = new Device[size];
|
||||
|
||||
// getDevices() provides an OrderedSet with devices ordered by priorities
|
||||
for (Device device : getDevices()) {
|
||||
MemoryRange range = device.getMemoryRange();
|
||||
for (int address = range.startAddress; address <= range.endAddress; ++address) {
|
||||
deviceAddressArray[address - this.startAddress] = device;
|
||||
}
|
||||
}
|
||||
|
||||
// Add the device
|
||||
device.setBus(this);
|
||||
devices.add(device);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a device to the bus.
|
||||
*
|
||||
* @param device Device to add
|
||||
* @param priority Bus priority.
|
||||
* @throws MemoryRangeException Invalid device address range.
|
||||
*/
|
||||
public void addDevice(Device device, int priority) throws MemoryRangeException {
|
||||
|
||||
MemoryRange range = device.getMemoryRange();
|
||||
|
||||
if (range.startAddress() < this.startAddress || range.startAddress() > this.endAddress) {
|
||||
throw new MemoryRangeException("start address of device " + device.getName() + " does not fall within the address range of the bus");
|
||||
}
|
||||
|
||||
if (range.endAddress() < this.startAddress || range.endAddress() > this.endAddress) {
|
||||
throw new MemoryRangeException("end address of device " + device.getName() + " does not fall within the address range of the bus");
|
||||
}
|
||||
|
||||
SortedSet<Device> deviceSet = deviceMap.computeIfAbsent(priority, k -> new TreeSet<>());
|
||||
|
||||
device.setBus(this);
|
||||
deviceSet.add(device);
|
||||
buildDeviceAddressArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a device to the bus. Throws a MemoryRangeException if the device overlaps with any others.
|
||||
*
|
||||
* @param device Device to add
|
||||
* @throws MemoryRangeException Invalid device memory range.
|
||||
*/
|
||||
public void addDevice(Device device) throws MemoryRangeException {
|
||||
addDevice(device, 0);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove a device from the bus.
|
||||
*
|
||||
* @param device
|
||||
* @param device Device to remove
|
||||
*/
|
||||
public void removeDevice(Device device) {
|
||||
if (devices.contains(device)) {
|
||||
devices.remove(device);
|
||||
for (SortedSet<Device> deviceSet : deviceMap.values()) {
|
||||
deviceSet.remove(device);
|
||||
}
|
||||
buildDeviceAddressArray();
|
||||
}
|
||||
|
||||
public void addCpu(Cpu cpu) {
|
||||
@@ -111,49 +150,79 @@ public class Bus {
|
||||
* device.
|
||||
*/
|
||||
public boolean isComplete() {
|
||||
// Empty maps cannot be complete.
|
||||
if (devices.isEmpty()) {
|
||||
return false;
|
||||
if (deviceAddressArray == null) {
|
||||
buildDeviceAddressArray();
|
||||
}
|
||||
|
||||
// Loop over devices and add their size
|
||||
int filledMemory = 0;
|
||||
for (Device d : devices) {
|
||||
filledMemory += d.getSize();
|
||||
}
|
||||
|
||||
// Returns if the total size of the devices fill the bus' memory space
|
||||
return filledMemory == endAddress - startAddress + 1;
|
||||
}
|
||||
|
||||
public int read(int address) throws MemoryAccessException {
|
||||
for (Device d : devices) {
|
||||
MemoryRange range = d.getMemoryRange();
|
||||
if (range.includes(address)) {
|
||||
// Compute offset into this device's address space.
|
||||
int devAddr = address - range.startAddress();
|
||||
return d.read(devAddr);
|
||||
for (int address = startAddress; address <= endAddress; ++address) {
|
||||
if (deviceAddressArray[address - startAddress] == null) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public int read(int address, boolean cpuAccess) throws MemoryAccessException {
|
||||
Device d = deviceAddressArray[address - this.startAddress];
|
||||
if (d != null) {
|
||||
MemoryRange range = d.getMemoryRange();
|
||||
int devAddr = address - range.startAddress();
|
||||
return d.read(devAddr, cpuAccess) & 0xff;
|
||||
}
|
||||
|
||||
throw new MemoryAccessException("Bus read failed. No device at address " + String.format("$%04X", address));
|
||||
}
|
||||
|
||||
public void write(int address, int value) throws MemoryAccessException {
|
||||
for (Device d : devices) {
|
||||
Device d = deviceAddressArray[address - this.startAddress];
|
||||
if (d != null) {
|
||||
MemoryRange range = d.getMemoryRange();
|
||||
if (range.includes(address)) {
|
||||
// Compute offset into this device's address space.
|
||||
int devAddr = address - range.startAddress();
|
||||
d.write(devAddr, value);
|
||||
return;
|
||||
}
|
||||
int devAddr = address - range.startAddress();
|
||||
d.write(devAddr, value);
|
||||
return;
|
||||
}
|
||||
|
||||
throw new MemoryAccessException("Bus write failed. No device at address " + String.format("$%04X", address));
|
||||
}
|
||||
|
||||
public void assertIrq() {
|
||||
if (cpu != null) {
|
||||
cpu.assertIrq();
|
||||
}
|
||||
}
|
||||
|
||||
public void clearIrq() {
|
||||
if (cpu != null) {
|
||||
cpu.clearIrq();
|
||||
}
|
||||
}
|
||||
|
||||
public void assertNmi() {
|
||||
if (cpu != null) {
|
||||
cpu.assertNmi();
|
||||
}
|
||||
}
|
||||
|
||||
public void clearNmi() {
|
||||
if (cpu != null) {
|
||||
cpu.clearNmi();
|
||||
}
|
||||
}
|
||||
|
||||
public SortedSet<Device> getDevices() {
|
||||
// Expose a copy of the device list, not the original
|
||||
return new TreeSet<Device>(devices);
|
||||
// create an ordered set of devices, ordered by device priorities
|
||||
SortedSet<Device> devices = new TreeSet<>();
|
||||
|
||||
List<Integer> priorities = new ArrayList<>(deviceMap.keySet());
|
||||
Collections.sort(priorities);
|
||||
|
||||
for (int priority : priorities) {
|
||||
SortedSet<Device> deviceSet = deviceMap.get(priority);
|
||||
devices.addAll(deviceSet);
|
||||
}
|
||||
|
||||
return devices;
|
||||
}
|
||||
|
||||
public Cpu getCpu() {
|
||||
|
||||
@@ -0,0 +1,200 @@
|
||||
/*
|
||||
* Copyright (c) 2008-2025 Seth J. Morabito <web@loomcom.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.loomcom.symon;
|
||||
|
||||
import com.loomcom.symon.util.Utils;
|
||||
|
||||
/**
|
||||
* A compact, struct-like representation of CPU state.
|
||||
*/
|
||||
public class CpuState {
|
||||
/**
|
||||
* Accumulator
|
||||
*/
|
||||
public int a;
|
||||
|
||||
/**
|
||||
* X index register
|
||||
*/
|
||||
public int x;
|
||||
|
||||
/**
|
||||
* Y index register
|
||||
*/
|
||||
public int y;
|
||||
|
||||
/**
|
||||
* Stack Pointer
|
||||
*/
|
||||
public int sp;
|
||||
|
||||
/**
|
||||
* Program Counter
|
||||
*/
|
||||
public int pc;
|
||||
|
||||
/**
|
||||
* Last Loaded Instruction Register
|
||||
*/
|
||||
public int ir;
|
||||
|
||||
/**
|
||||
* Peek-Ahead to next IR
|
||||
*/
|
||||
public int nextIr;
|
||||
public int[] args = new int[2];
|
||||
public int[] nextArgs = new int[2];
|
||||
public int instSize;
|
||||
public boolean opTrap;
|
||||
public boolean irqAsserted;
|
||||
public boolean nmiAsserted;
|
||||
public int lastPc;
|
||||
|
||||
/* Status Flag Register bits */
|
||||
public boolean carryFlag;
|
||||
public boolean negativeFlag;
|
||||
public boolean zeroFlag;
|
||||
public boolean irqDisableFlag;
|
||||
public boolean decimalModeFlag;
|
||||
public boolean breakFlag;
|
||||
public boolean overflowFlag;
|
||||
public long stepCounter = 0L;
|
||||
|
||||
public CpuState() {}
|
||||
|
||||
/**
|
||||
* Snapshot a copy of the CpuState. (This is a copy constructor rather than an
|
||||
* implementation of <code>Cloneable</code> based on Josh Bloch's recommendation)
|
||||
*
|
||||
* @param s The CpuState to copy.
|
||||
*/
|
||||
@SuppressWarnings("CopyConstructorMissesField")
|
||||
public CpuState(CpuState s) {
|
||||
this.a = s.a;
|
||||
this.x = s.x;
|
||||
this.y = s.y;
|
||||
this.sp = s.sp;
|
||||
this.pc = s.pc;
|
||||
this.ir = s.ir;
|
||||
this.nextIr = s.nextIr;
|
||||
this.lastPc = s.lastPc;
|
||||
this.args[0] = s.args[0];
|
||||
this.args[1] = s.args[1];
|
||||
this.nextArgs[0] = s.nextArgs[0];
|
||||
this.nextArgs[1] = s.nextArgs[1];
|
||||
this.instSize = s.instSize;
|
||||
this.opTrap = s.opTrap;
|
||||
this.nmiAsserted = s.nmiAsserted;
|
||||
this.irqAsserted = s.irqAsserted;
|
||||
this.carryFlag = s.carryFlag;
|
||||
this.negativeFlag = s.negativeFlag;
|
||||
this.zeroFlag = s.zeroFlag;
|
||||
this.irqDisableFlag = s.irqDisableFlag;
|
||||
this.decimalModeFlag = s.decimalModeFlag;
|
||||
this.breakFlag = s.breakFlag;
|
||||
this.overflowFlag = s.overflowFlag;
|
||||
this.stepCounter = s.stepCounter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string formatted for the trace log.
|
||||
*
|
||||
* @return a string formatted for the trace log.
|
||||
*/
|
||||
public String toTraceEvent() {
|
||||
String opcode = Cpu.disassembleOp(ir, args);
|
||||
return getInstructionByteStatus() + " " +
|
||||
String.format("%-14s", opcode) +
|
||||
"A:" + Utils.byteToHex(a) + " " +
|
||||
"X:" + Utils.byteToHex(x) + " " +
|
||||
"Y:" + Utils.byteToHex(y) + " " +
|
||||
"F:" + Utils.byteToHex(getStatusFlag()) + " " +
|
||||
"S:1" + Utils.byteToHex(sp) + " " +
|
||||
getProcessorStatusString() + "\n";
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The value of the Process Status Register, as a byte.
|
||||
*/
|
||||
public int getStatusFlag() {
|
||||
int status = 0x20;
|
||||
if (carryFlag) {
|
||||
status |= Cpu.P_CARRY;
|
||||
}
|
||||
if (zeroFlag) {
|
||||
status |= Cpu.P_ZERO;
|
||||
}
|
||||
if (irqDisableFlag) {
|
||||
status |= Cpu.P_IRQ_DISABLE;
|
||||
}
|
||||
if (decimalModeFlag) {
|
||||
status |= Cpu.P_DECIMAL;
|
||||
}
|
||||
if (breakFlag) {
|
||||
status |= Cpu.P_BREAK;
|
||||
}
|
||||
if (overflowFlag) {
|
||||
status |= Cpu.P_OVERFLOW;
|
||||
}
|
||||
if (negativeFlag) {
|
||||
status |= Cpu.P_NEGATIVE;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
public String getInstructionByteStatus() {
|
||||
switch (Cpu.instructionSizes[ir]) {
|
||||
case 0:
|
||||
case 1:
|
||||
return Utils.wordToHex(lastPc) + " " +
|
||||
Utils.byteToHex(ir) + " ";
|
||||
case 2:
|
||||
return Utils.wordToHex(lastPc) + " " +
|
||||
Utils.byteToHex(ir) + " " +
|
||||
Utils.byteToHex(args[0]) + " ";
|
||||
case 3:
|
||||
return Utils.wordToHex(lastPc) + " " +
|
||||
Utils.byteToHex(ir) + " " +
|
||||
Utils.byteToHex(args[0]) + " " +
|
||||
Utils.byteToHex(args[1]);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return A string representing the current status register state.
|
||||
*/
|
||||
public String getProcessorStatusString() {
|
||||
return "[" + (negativeFlag ? 'N' : '.') +
|
||||
(overflowFlag ? 'V' : '.') +
|
||||
"-" +
|
||||
(breakFlag ? 'B' : '.') +
|
||||
(decimalModeFlag ? 'D' : '.') +
|
||||
(irqDisableFlag ? 'I' : '.') +
|
||||
(zeroFlag ? 'Z' : '.') +
|
||||
(carryFlag ? 'C' : '.') +
|
||||
"]";
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2008-2012 Seth J. Morabito <sethm@loomcom.com>
|
||||
* Copyright (c) 2008-2025 Seth J. Morabito <web@loomcom.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
@@ -25,53 +25,54 @@ package com.loomcom.symon;
|
||||
|
||||
public interface InstructionTable {
|
||||
|
||||
int BRK = 0x00;
|
||||
int JSR = 0x20;
|
||||
int RTS = 0x60;
|
||||
|
||||
/**
|
||||
* Enumeration of valid CPU behaviors. These determine what behavior and instruction
|
||||
* set will be simulated, depending on desired version of 6502.
|
||||
*
|
||||
* TODO: As of version 0.6, this is still not used! All CPUs are "idealized" NMOS 6502 only.
|
||||
*/
|
||||
public enum CpuBehavior {
|
||||
enum CpuBehavior {
|
||||
/**
|
||||
* The earliest NMOS 6502 includes a bug that causes the ROR instruction
|
||||
* to behave like an ASL that does not affect the carry bit. This version
|
||||
* is very rare in the wild.
|
||||
*
|
||||
* NB: Does NOT implement "unimplemented" NMOS instructions.
|
||||
*/
|
||||
NMOS_WITH_ROR_BUG,
|
||||
|
||||
/**
|
||||
* All NMOS 6502's have a bug with the indirect JMP instruction. If the
|
||||
*
|
||||
* NB: Does NOT implement "unimplemented" NMOS instructions.
|
||||
*/
|
||||
NMOS_WITH_INDIRECT_JMP_BUG,
|
||||
|
||||
/**
|
||||
* Emulate an NMOS 6502 without the indirect JMP bug. This type of 6502
|
||||
* does not actually exist in the wild.
|
||||
*
|
||||
* NB: Does NOT implement "unimplemented" NMOS instructions.
|
||||
*/
|
||||
NMOS_WITHOUT_INDIRECT_JMP_BUG,
|
||||
NMOS_6502,
|
||||
|
||||
/**
|
||||
* Emulate a CMOS 65C02, with all CMOS instructions and addressing modes.
|
||||
*/
|
||||
CMOS
|
||||
CMOS_6502,
|
||||
|
||||
/**
|
||||
* Emulate a CMOS 65C816.
|
||||
*/
|
||||
CMOS_65816
|
||||
}
|
||||
|
||||
/**
|
||||
* Enumeration of Addressing Modes.
|
||||
*/
|
||||
public enum Mode {
|
||||
enum Mode {
|
||||
ACC {
|
||||
public String toString() {
|
||||
return "Accumulator";
|
||||
}
|
||||
},
|
||||
|
||||
AIX {
|
||||
public String toString() {
|
||||
return "Absolute, X-Indexed Indirect";
|
||||
}
|
||||
},
|
||||
|
||||
ABS {
|
||||
public String toString() {
|
||||
return "Absolute";
|
||||
@@ -128,19 +129,31 @@ public interface InstructionTable {
|
||||
|
||||
ZPG {
|
||||
public String toString() {
|
||||
return "Zeropage";
|
||||
return "Zero Page";
|
||||
}
|
||||
},
|
||||
|
||||
ZPR {
|
||||
public String toString() {
|
||||
return "Zero Page, Relative";
|
||||
}
|
||||
},
|
||||
|
||||
ZPX {
|
||||
public String toString() {
|
||||
return "Zeropage, X-indexed";
|
||||
return "Zero Page, X-indexed";
|
||||
}
|
||||
},
|
||||
|
||||
ZPY {
|
||||
public String toString() {
|
||||
return "Zeropage, Y-indexed";
|
||||
return "Zero Page, Y-indexed";
|
||||
}
|
||||
},
|
||||
|
||||
ZPI {
|
||||
public String toString() {
|
||||
return "Zero Page Indirect";
|
||||
}
|
||||
},
|
||||
|
||||
@@ -154,156 +167,188 @@ public interface InstructionTable {
|
||||
// 6502 opcodes. No 65C02 opcodes implemented.
|
||||
|
||||
/**
|
||||
* Instruction opcode names.
|
||||
* Instruction opcode names. This lists all opcodes for
|
||||
* NMOS 6502, CMOS 65C02, and CMOS 65C816.
|
||||
* <p>
|
||||
* TODO (2025-03-14): This table is clearly wrong for 65C816.
|
||||
* TODO (2025-03-14): Rockwell/WDC 65C02 names conflict with 65C816 names.
|
||||
*/
|
||||
public static final String[] opcodeNames = {
|
||||
"BRK", "ORA", null, null, null, "ORA", "ASL", null,
|
||||
"PHP", "ORA", "ASL", null, null, "ORA", "ASL", null,
|
||||
"BPL", "ORA", null, null, null, "ORA", "ASL", null,
|
||||
"CLC", "ORA", null, null, null, "ORA", "ASL", null,
|
||||
"JSR", "AND", null, null, "BIT", "AND", "ROL", null,
|
||||
"PLP", "AND", "ROL", null, "BIT", "AND", "ROL", null,
|
||||
"BMI", "AND", null, null, null, "AND", "ROL", null,
|
||||
"SEC", "AND", null, null, null, "AND", "ROL", null,
|
||||
"RTI", "EOR", null, null, null, "EOR", "LSR", null,
|
||||
"PHA", "EOR", "LSR", null, "JMP", "EOR", "LSR", null,
|
||||
"BVC", "EOR", null, null, null, "EOR", "LSR", null,
|
||||
"CLI", "EOR", null, null, null, "EOR", "LSR", null,
|
||||
"RTS", "ADC", null, null, null, "ADC", "ROR", null,
|
||||
"PLA", "ADC", "ROR", null, "JMP", "ADC", "ROR", null,
|
||||
"BVS", "ADC", null, null, null, "ADC", "ROR", null,
|
||||
"SEI", "ADC", null, null, null, "ADC", "ROR", null,
|
||||
"BCS", "STA", null, null, "STY", "STA", "STX", null,
|
||||
"DEY", null, "TXA", null, "STY", "STA", "STX", null,
|
||||
"BCC", "STA", null, null, "STY", "STA", "STX", null,
|
||||
"TYA", "STA", "TXS", null, null, "STA", null, null,
|
||||
"LDY", "LDA", "LDX", null, "LDY", "LDA", "LDX", null,
|
||||
"TAY", "LDA", "TAX", null, "LDY", "LDA", "LDX", null,
|
||||
"BCS", "LDA", null, null, "LDY", "LDA", "LDX", null,
|
||||
"CLV", "LDA", "TSX", null, "LDY", "LDA", "LDX", null,
|
||||
"CPY", "CMP", null, null, "CPY", "CMP", "DEC", null,
|
||||
"INY", "CMP", "DEX", null, "CPY", "CMP", "DEC", null,
|
||||
"BNE", "CMP", null, null, null, "CMP", "DEC", null,
|
||||
"CLD", "CMP", null, null, null, "CMP", "DEC", null,
|
||||
"CPX", "SBC", null, null, "CPX", "SBC", "INC", null,
|
||||
"INX", "SBC", "NOP", null, "CPX", "SBC", "INC", null,
|
||||
"BEQ", "SBC", null, null, null, "SBC", "INC", null,
|
||||
"SED", "SBC", null, null, null, "SBC", "INC", null
|
||||
String[] opcodeNames = {
|
||||
"BRK", "ORA", "NOP", "NOP", "TSB", "ORA", "ASL", "RMB0", // 0x00-0x07
|
||||
"PHP", "ORA", "ASL", "NOP", "TSB", "ORA", "ASL", "BBR0", // 0x08-0x0f
|
||||
"BPL", "ORA", "ORA", "NOP", "TRB", "ORA", "ASL", "RMB1", // 0x10-0x17
|
||||
"CLC", "ORA", "INC", "NOP", "TRB", "ORA", "ASL", "BBR1", // 0x18-0x1f
|
||||
"JSR", "AND", "NOP", "NOP", "BIT", "AND", "ROL", "RMB2", // 0x20-0x27
|
||||
"PLP", "AND", "ROL", "NOP", "BIT", "AND", "ROL", "BBR2", // 0x28-0x2f
|
||||
"BMI", "AND", "AND", "NOP", "BIT", "AND", "ROL", "RMB3", // 0x30-0x37
|
||||
"SEC", "AND", "DEC", "NOP", "BIT", "AND", "ROL", "BBR3", // 0x38-0x3f
|
||||
"RTI", "EOR", "NOP", "NOP", "NOP", "EOR", "LSR", "RMB4", // 0x40-0x47
|
||||
"PHA", "EOR", "LSR", "NOP", "JMP", "EOR", "LSR", "BBR4", // 0x48-0x4f
|
||||
"BVC", "EOR", "EOR", "NOP", "NOP", "EOR", "LSR", "RMB5", // 0x50-0x57
|
||||
"CLI", "EOR", "PHY", "NOP", "NOP", "EOR", "LSR", "BBR5", // 0x58-0x5f
|
||||
"RTS", "ADC", "NOP", "NOP", "STZ", "ADC", "ROR", "RMB6", // 0x60-0x67
|
||||
"PLA", "ADC", "ROR", "NOP", "JMP", "ADC", "ROR", "BBR6", // 0x68-0x6f
|
||||
"BVS", "ADC", "ADC", "NOP", "STZ", "ADC", "ROR", "RMB7", // 0x70-0x77
|
||||
"SEI", "ADC", "PLY", "NOP", "JMP", "ADC", "ROR", "BBR7", // 0x78-0x7f
|
||||
"BRA", "STA", "NOP", "NOP", "STY", "STA", "STX", "SMB0", // 0x80-0x87
|
||||
"DEY", "BIT", "TXA", "NOP", "STY", "STA", "STX", "BBS0", // 0x88-0x8f
|
||||
"BCC", "STA", "STA", "NOP", "STY", "STA", "STX", "SMB1", // 0x90-0x97
|
||||
"TYA", "STA", "TXS", "NOP", "STZ", "STA", "STZ", "BBS1", // 0x98-0x9f
|
||||
"LDY", "LDA", "LDX", "NOP", "LDY", "LDA", "LDX", "SMB2", // 0xa0-0xa7
|
||||
"TAY", "LDA", "TAX", "NOP", "LDY", "LDA", "LDX", "BBS2", // 0xa8-0xaf
|
||||
"BCS", "LDA", "LDA", "NOP", "LDY", "LDA", "LDX", "SMB3", // 0xb0-0xb7
|
||||
"CLV", "LDA", "TSX", "NOP", "LDY", "LDA", "LDX", "BBS3", // 0xb8-0xbf
|
||||
"CPY", "CMP", "NOP", "NOP", "CPY", "CMP", "DEC", "SMB4", // 0xc0-0xc7
|
||||
"INY", "CMP", "DEX", "NOP", "CPY", "CMP", "DEC", "BBS4", // 0xc8-0xcf
|
||||
"BNE", "CMP", "CMP", "NOP", "NOP", "CMP", "DEC", "SMB5", // 0xd0-0xd7
|
||||
"CLD", "CMP", "PHX", "NOP", "NOP", "CMP", "DEC", "BBS5", // 0xd8-0xdf
|
||||
"CPX", "SBC", "NOP", "NOP", "CPX", "SBC", "INC", "SMB6", // 0xe0-0xe7
|
||||
"INX", "SBC", "NOP", "NOP", "CPX", "SBC", "INC", "BBS6", // 0xe8-0xef
|
||||
"BEQ", "SBC", "SBC", "NOP", "NOP", "SBC", "INC", "SMB7", // 0xf0-0xf7
|
||||
"SED", "SBC", "PLX", "NOP", "NOP", "SBC", "INC", "BBS7" // 0xf8-0xff
|
||||
};
|
||||
|
||||
/**
|
||||
* Instruction addressing modes.
|
||||
* Instruction addressing modes. This table includes sizes
|
||||
* for all instructions for NMOS 6502, CMOS 65C02,
|
||||
* and CMOS 65C816
|
||||
*/
|
||||
public static final Mode[] instructionModes = {
|
||||
Mode[] instructionModes = {
|
||||
Mode.IMP, Mode.XIN, Mode.NUL, Mode.NUL, // 0x00-0x03
|
||||
Mode.NUL, Mode.ZPG, Mode.ZPG, Mode.NUL, // 0x04-0x07
|
||||
Mode.ZPG, Mode.ZPG, Mode.ZPG, Mode.ZPG, // 0x04-0x07
|
||||
Mode.IMP, Mode.IMM, Mode.ACC, Mode.NUL, // 0x08-0x0b
|
||||
Mode.NUL, Mode.ABS, Mode.ABS, Mode.NUL, // 0x0c-0x0f
|
||||
Mode.REL, Mode.INY, Mode.NUL, Mode.NUL, // 0x10-0x13
|
||||
Mode.NUL, Mode.ZPX, Mode.ZPX, Mode.NUL, // 0x14-0x17
|
||||
Mode.IMP, Mode.ABY, Mode.NUL, Mode.NUL, // 0x18-0x1b
|
||||
Mode.NUL, Mode.ABX, Mode.ABX, Mode.NUL, // 0x1c-0x1f
|
||||
Mode.ABS, Mode.ABS, Mode.ABS, Mode.ZPR, // 0x0c-0x0f
|
||||
Mode.REL, Mode.INY, Mode.ZPI, Mode.NUL, // 0x10-0x13
|
||||
Mode.ZPG, Mode.ZPX, Mode.ZPX, Mode.ZPG, // 0x14-0x17
|
||||
Mode.IMP, Mode.ABY, Mode.IMP, Mode.NUL, // 0x18-0x1b
|
||||
Mode.ABS, Mode.ABX, Mode.ABX, Mode.ZPR, // 0x1c-0x1f
|
||||
Mode.ABS, Mode.XIN, Mode.NUL, Mode.NUL, // 0x20-0x23
|
||||
Mode.ZPG, Mode.ZPG, Mode.ZPG, Mode.NUL, // 0x24-0x27
|
||||
Mode.ZPG, Mode.ZPG, Mode.ZPG, Mode.ZPG, // 0x24-0x27
|
||||
Mode.IMP, Mode.IMM, Mode.ACC, Mode.NUL, // 0x28-0x2b
|
||||
Mode.ABS, Mode.ABS, Mode.ABS, Mode.NUL, // 0x2c-0x2f
|
||||
Mode.REL, Mode.INY, Mode.NUL, Mode.NUL, // 0x30-0x33
|
||||
Mode.NUL, Mode.ZPX, Mode.ZPX, Mode.NUL, // 0x34-0x37
|
||||
Mode.IMP, Mode.ABY, Mode.NUL, Mode.NUL, // 0x38-0x3b
|
||||
Mode.NUL, Mode.ABX, Mode.ABX, Mode.NUL, // 0x3c-0x3f
|
||||
Mode.ABS, Mode.ABS, Mode.ABS, Mode.ZPR, // 0x2c-0x2f
|
||||
Mode.REL, Mode.INY, Mode.ZPI, Mode.NUL, // 0x30-0x33
|
||||
Mode.ZPX, Mode.ZPX, Mode.ZPX, Mode.ZPG, // 0x34-0x37
|
||||
Mode.IMP, Mode.ABY, Mode.IMP, Mode.NUL, // 0x38-0x3b
|
||||
Mode.NUL, Mode.ABX, Mode.ABX, Mode.ZPR, // 0x3c-0x3f
|
||||
Mode.IMP, Mode.XIN, Mode.NUL, Mode.NUL, // 0x40-0x43
|
||||
Mode.NUL, Mode.ZPG, Mode.ZPG, Mode.NUL, // 0x44-0x47
|
||||
Mode.NUL, Mode.ZPG, Mode.ZPG, Mode.ZPG, // 0x44-0x47
|
||||
Mode.IMP, Mode.IMM, Mode.ACC, Mode.NUL, // 0x48-0x4b
|
||||
Mode.ABS, Mode.ABS, Mode.ABS, Mode.NUL, // 0x4c-0x4f
|
||||
Mode.REL, Mode.INY, Mode.NUL, Mode.NUL, // 0x50-0x53
|
||||
Mode.NUL, Mode.ZPX, Mode.ZPX, Mode.NUL, // 0x54-0x57
|
||||
Mode.IMP, Mode.ABY, Mode.NUL, Mode.NUL, // 0x58-0x5b
|
||||
Mode.NUL, Mode.ABX, Mode.ABX, Mode.NUL, // 0x5c-0x5f
|
||||
Mode.ABS, Mode.ABS, Mode.ABS, Mode.ZPR, // 0x4c-0x4f
|
||||
Mode.REL, Mode.INY, Mode.ZPI, Mode.NUL, // 0x50-0x53
|
||||
Mode.NUL, Mode.ZPX, Mode.ZPX, Mode.ZPG, // 0x54-0x57
|
||||
Mode.IMP, Mode.ABY, Mode.IMP, Mode.NUL, // 0x58-0x5b
|
||||
Mode.NUL, Mode.ABX, Mode.ABX, Mode.ZPR, // 0x5c-0x5f
|
||||
Mode.IMP, Mode.XIN, Mode.NUL, Mode.NUL, // 0x60-0x63
|
||||
Mode.NUL, Mode.ZPG, Mode.ZPG, Mode.NUL, // 0x64-0x67
|
||||
Mode.ZPG, Mode.ZPG, Mode.ZPG, Mode.ZPG, // 0x64-0x67
|
||||
Mode.IMP, Mode.IMM, Mode.ACC, Mode.NUL, // 0x68-0x6b
|
||||
Mode.IND, Mode.ABS, Mode.ABS, Mode.NUL, // 0x6c-0x6f
|
||||
Mode.REL, Mode.INY, Mode.NUL, Mode.NUL, // 0x70-0x73
|
||||
Mode.NUL, Mode.ZPX, Mode.ZPX, Mode.NUL, // 0x74-0x77
|
||||
Mode.IMP, Mode.ABY, Mode.NUL, Mode.NUL, // 0x78-0x7b
|
||||
Mode.NUL, Mode.ABX, Mode.ABX, Mode.NUL, // 0x7c-0x7f
|
||||
Mode.IND, Mode.ABS, Mode.ABS, Mode.ZPR, // 0x6c-0x6f
|
||||
Mode.REL, Mode.INY, Mode.ZPI, Mode.NUL, // 0x70-0x73
|
||||
Mode.ZPX, Mode.ZPX, Mode.ZPX, Mode.ZPG, // 0x74-0x77
|
||||
Mode.IMP, Mode.ABY, Mode.IMP, Mode.NUL, // 0x78-0x7b
|
||||
Mode.AIX, Mode.ABX, Mode.ABX, Mode.ZPR, // 0x7c-0x7f
|
||||
Mode.REL, Mode.XIN, Mode.NUL, Mode.NUL, // 0x80-0x83
|
||||
Mode.ZPG, Mode.ZPG, Mode.ZPG, Mode.NUL, // 0x84-0x87
|
||||
Mode.IMP, Mode.NUL, Mode.IMP, Mode.NUL, // 0x88-0x8b
|
||||
Mode.ABS, Mode.ABS, Mode.ABS, Mode.NUL, // 0x8c-0x8f
|
||||
Mode.REL, Mode.INY, Mode.NUL, Mode.NUL, // 0x90-0x93
|
||||
Mode.ZPX, Mode.ZPX, Mode.ZPY, Mode.NUL, // 0x94-0x97
|
||||
Mode.ZPG, Mode.ZPG, Mode.ZPG, Mode.ZPG, // 0x84-0x87
|
||||
Mode.IMP, Mode.IMM, Mode.IMP, Mode.NUL, // 0x88-0x8b
|
||||
Mode.ABS, Mode.ABS, Mode.ABS, Mode.ZPR, // 0x8c-0x8f
|
||||
Mode.REL, Mode.INY, Mode.ZPI, Mode.NUL, // 0x90-0x93
|
||||
Mode.ZPX, Mode.ZPX, Mode.ZPY, Mode.ZPG, // 0x94-0x97
|
||||
Mode.IMP, Mode.ABY, Mode.IMP, Mode.NUL, // 0x98-0x9b
|
||||
Mode.NUL, Mode.ABX, Mode.NUL, Mode.NUL, // 0x9c-0x9f
|
||||
Mode.ABS, Mode.ABX, Mode.ABX, Mode.ZPR, // 0x9c-0x9f
|
||||
Mode.IMM, Mode.XIN, Mode.IMM, Mode.NUL, // 0xa0-0xa3
|
||||
Mode.ZPG, Mode.ZPG, Mode.ZPG, Mode.NUL, // 0xa4-0xa7
|
||||
Mode.ZPG, Mode.ZPG, Mode.ZPG, Mode.ZPG, // 0xa4-0xa7
|
||||
Mode.IMP, Mode.IMM, Mode.IMP, Mode.NUL, // 0xa8-0xab
|
||||
Mode.ABS, Mode.ABS, Mode.ABS, Mode.NUL, // 0xac-0xaf
|
||||
Mode.REL, Mode.INY, Mode.NUL, Mode.NUL, // 0xb0-0xb3
|
||||
Mode.ZPX, Mode.ZPX, Mode.ZPY, Mode.NUL, // 0xb4-0xb7
|
||||
Mode.ABS, Mode.ABS, Mode.ABS, Mode.ZPR, // 0xac-0xaf
|
||||
Mode.REL, Mode.INY, Mode.ZPI, Mode.NUL, // 0xb0-0xb3
|
||||
Mode.ZPX, Mode.ZPX, Mode.ZPY, Mode.ZPG, // 0xb4-0xb7
|
||||
Mode.IMP, Mode.ABY, Mode.IMP, Mode.NUL, // 0xb8-0xbb
|
||||
Mode.ABX, Mode.ABX, Mode.ABY, Mode.NUL, // 0xbc-0xbf
|
||||
Mode.ABX, Mode.ABX, Mode.ABY, Mode.ZPR, // 0xbc-0xbf
|
||||
Mode.IMM, Mode.XIN, Mode.NUL, Mode.NUL, // 0xc0-0xc3
|
||||
Mode.ZPG, Mode.ZPG, Mode.ZPG, Mode.NUL, // 0xc4-0xc7
|
||||
Mode.ZPG, Mode.ZPG, Mode.ZPG, Mode.ZPG, // 0xc4-0xc7
|
||||
Mode.IMP, Mode.IMM, Mode.IMP, Mode.NUL, // 0xc8-0xcb
|
||||
Mode.ABS, Mode.ABS, Mode.ABS, Mode.NUL, // 0xcc-0xcf
|
||||
Mode.REL, Mode.INY, Mode.NUL, Mode.NUL, // 0xd0-0xd3
|
||||
Mode.NUL, Mode.ZPX, Mode.ZPX, Mode.NUL, // 0xd4-0xd7
|
||||
Mode.IMP, Mode.ABY, Mode.NUL, Mode.NUL, // 0xd8-0xdb
|
||||
Mode.NUL, Mode.ABX, Mode.ABX, Mode.NUL, // 0xdc-0xdf
|
||||
Mode.ABS, Mode.ABS, Mode.ABS, Mode.ZPR, // 0xcc-0xcf
|
||||
Mode.REL, Mode.INY, Mode.ZPI, Mode.NUL, // 0xd0-0xd3
|
||||
Mode.NUL, Mode.ZPX, Mode.ZPX, Mode.ZPG, // 0xd4-0xd7
|
||||
Mode.IMP, Mode.ABY, Mode.IMP, Mode.NUL, // 0xd8-0xdb
|
||||
Mode.NUL, Mode.ABX, Mode.ABX, Mode.ZPR, // 0xdc-0xdf
|
||||
Mode.IMM, Mode.XIN, Mode.NUL, Mode.NUL, // 0xe0-0xe3
|
||||
Mode.ZPG, Mode.ZPG, Mode.ZPG, Mode.NUL, // 0xe4-0xe7
|
||||
Mode.ZPG, Mode.ZPG, Mode.ZPG, Mode.ZPG, // 0xe4-0xe7
|
||||
Mode.IMP, Mode.IMM, Mode.IMP, Mode.NUL, // 0xe8-0xeb
|
||||
Mode.ABS, Mode.ABS, Mode.ABS, Mode.NUL, // 0xec-0xef
|
||||
Mode.REL, Mode.INY, Mode.NUL, Mode.NUL, // 0xf0-0xf3
|
||||
Mode.NUL, Mode.ZPX, Mode.ZPX, Mode.NUL, // 0xf4-0xf7
|
||||
Mode.IMP, Mode.ABY, Mode.NUL, Mode.NUL, // 0xf8-0xfb
|
||||
Mode.NUL, Mode.ABX, Mode.ABX, Mode.NUL // 0xfc-0xff
|
||||
Mode.ABS, Mode.ABS, Mode.ABS, Mode.ZPR, // 0xec-0xef
|
||||
Mode.REL, Mode.INY, Mode.ZPI, Mode.NUL, // 0xf0-0xf3
|
||||
Mode.NUL, Mode.ZPX, Mode.ZPX, Mode.ZPG, // 0xf4-0xf7
|
||||
Mode.IMP, Mode.ABY, Mode.IMP, Mode.NUL, // 0xf8-0xfb
|
||||
Mode.NUL, Mode.ABX, Mode.ABX, Mode.ZPR // 0xfc-0xff
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Size, in bytes, required for each instruction.
|
||||
* Size, in bytes, required for each instruction. This table
|
||||
* includes sizes for all instructions for NMOS 6502, CMOS 65C02,
|
||||
* and CMOS 65C816
|
||||
*/
|
||||
public static final int[] instructionSizes = {
|
||||
1, 2, 0, 0, 0, 2, 2, 0, 1, 2, 1, 0, 0, 3, 3, 0,
|
||||
2, 2, 0, 0, 0, 2, 2, 0, 1, 3, 0, 0, 0, 3, 3, 0,
|
||||
3, 2, 0, 0, 2, 2, 2, 0, 1, 2, 1, 0, 3, 3, 3, 0,
|
||||
2, 2, 0, 0, 0, 2, 2, 0, 1, 3, 0, 0, 0, 3, 3, 0,
|
||||
1, 2, 0, 0, 0, 2, 2, 0, 1, 2, 1, 0, 3, 3, 3, 0,
|
||||
2, 2, 0, 0, 0, 2, 2, 0, 1, 3, 0, 0, 0, 3, 3, 0,
|
||||
1, 2, 0, 0, 0, 2, 2, 0, 1, 2, 1, 0, 3, 3, 3, 0,
|
||||
2, 2, 0, 0, 0, 2, 2, 0, 1, 3, 0, 0, 0, 3, 3, 0,
|
||||
2, 2, 0, 0, 2, 2, 2, 0, 1, 0, 1, 0, 3, 3, 3, 0,
|
||||
2, 2, 0, 0, 2, 2, 2, 0, 1, 3, 1, 0, 0, 3, 0, 0,
|
||||
2, 2, 2, 0, 2, 2, 2, 0, 1, 2, 1, 0, 3, 3, 3, 0,
|
||||
2, 2, 0, 0, 2, 2, 2, 0, 1, 3, 1, 0, 3, 3, 3, 0,
|
||||
2, 2, 0, 0, 2, 2, 2, 0, 1, 2, 1, 0, 3, 3, 3, 0,
|
||||
2, 2, 0, 0, 0, 2, 2, 0, 1, 3, 0, 0, 0, 3, 3, 0,
|
||||
2, 2, 0, 0, 2, 2, 2, 0, 1, 2, 1, 0, 3, 3, 3, 0,
|
||||
2, 2, 0, 0, 0, 2, 2, 0, 1, 3, 0, 0, 0, 3, 3, 0
|
||||
int[] instructionSizes = {
|
||||
1, 2, 2, 1, 2, 2, 2, 2, 1, 2, 1, 1, 3, 3, 3, 3, // 0x00-0x0f
|
||||
2, 2, 2, 1, 2, 2, 2, 2, 1, 3, 1, 1, 3, 3, 3, 3, // 0x10-0x1f
|
||||
3, 2, 2, 1, 2, 2, 2, 2, 1, 2, 1, 1, 3, 3, 3, 3, // 0x20-0x2f
|
||||
2, 2, 2, 1, 2, 2, 2, 2, 1, 3, 1, 1, 3, 3, 3, 3, // 0x30-0x3f
|
||||
1, 2, 2, 1, 2, 2, 2, 2, 1, 2, 1, 1, 3, 3, 3, 3, // 0x40-0x4f
|
||||
2, 2, 2, 1, 2, 2, 2, 2, 1, 3, 1, 1, 3, 3, 3, 3, // 0x50-0x5f
|
||||
1, 2, 2, 1, 2, 2, 2, 2, 1, 2, 1, 1, 3, 3, 3, 3, // 0x60-0x6f
|
||||
2, 2, 2, 1, 2, 2, 2, 2, 1, 3, 1, 1, 3, 3, 3, 3, // 0x70-0x7f
|
||||
2, 2, 2, 1, 2, 2, 2, 2, 1, 2, 1, 1, 3, 3, 3, 3, // 0x80-0x8f
|
||||
2, 2, 2, 1, 2, 2, 2, 2, 1, 3, 1, 1, 3, 3, 3, 3, // 0x90-0x9f
|
||||
2, 2, 2, 1, 2, 2, 2, 2, 1, 2, 1, 1, 3, 3, 3, 3, // 0xa0-0xaf
|
||||
2, 2, 2, 1, 2, 2, 2, 2, 1, 3, 1, 1, 3, 3, 3, 3, // 0xb0-0xbf
|
||||
2, 2, 2, 1, 2, 2, 2, 2, 1, 2, 1, 1, 3, 3, 3, 3, // 0xc0-0xcf
|
||||
2, 2, 2, 1, 2, 2, 2, 2, 1, 3, 1, 1, 3, 3, 3, 3, // 0xd0-0xdf
|
||||
2, 2, 2, 1, 2, 2, 2, 2, 1, 2, 1, 1, 3, 3, 3, 3, // 0xe0-0xef
|
||||
2, 2, 2, 1, 2, 2, 2, 2, 1, 3, 1, 1, 3, 3, 3, 3 // 0xf0-0xff
|
||||
};
|
||||
|
||||
/**
|
||||
* Number of clock cycles required for each instruction
|
||||
* Number of clock cycles required for each instruction when
|
||||
* in NMOS mode.
|
||||
*/
|
||||
public static final int[] instructionClocks = {
|
||||
7, 6, 0, 0, 0, 3, 5, 0, 3, 2, 2, 0, 0, 4, 6, 0,
|
||||
2, 5, 0, 0, 0, 4, 6, 0, 2, 4, 0, 0, 0, 4, 7, 0,
|
||||
6, 6, 0, 0, 3, 3, 5, 0, 4, 2, 2, 0, 4, 4, 6, 0,
|
||||
2, 5, 0, 0, 0, 4, 6, 0, 2, 4, 0, 0, 0, 4, 7, 0,
|
||||
6, 6, 0, 0, 0, 3, 5, 0, 3, 2, 2, 0, 3, 4, 6, 0,
|
||||
2, 5, 0, 0, 0, 4, 6, 0, 2, 4, 0, 0, 0, 4, 7, 0,
|
||||
6, 6, 0, 0, 0, 3, 5, 0, 4, 2, 2, 0, 5, 4, 6, 0,
|
||||
2, 5, 0, 0, 0, 4, 6, 0, 2, 4, 0, 0, 0, 4, 7, 0,
|
||||
2, 6, 0, 0, 3, 3, 3, 0, 2, 0, 2, 0, 4, 4, 4, 0,
|
||||
2, 6, 0, 0, 4, 4, 4, 0, 2, 5, 2, 0, 0, 5, 0, 0,
|
||||
2, 6, 2, 0, 3, 3, 3, 0, 2, 2, 2, 0, 4, 4, 4, 0,
|
||||
2, 5, 0, 0, 4, 4, 4, 0, 2, 4, 2, 0, 4, 4, 4, 0,
|
||||
2, 6, 0, 0, 3, 3, 5, 0, 2, 2, 2, 0, 4, 4, 6, 0,
|
||||
2, 5, 0, 0, 0, 4, 6, 0, 2, 4, 0, 0, 0, 4, 7, 0,
|
||||
2, 6, 0, 0, 3, 3, 5, 0, 2, 2, 2, 0, 4, 4, 6, 0,
|
||||
2, 5, 0, 0, 0, 4, 6, 0, 2, 4, 0, 0, 0, 4, 7, 0
|
||||
int[] instructionClocksNmos = {
|
||||
7, 6, 1, 8, 3, 3, 5, 5, 3, 2, 2, 2, 4, 4, 6, 6, // 0x00-0x0f
|
||||
2, 5, 1, 8, 4, 4, 6, 6, 2, 4, 2, 7, 4, 4, 7, 7, // 0x10-0x1f
|
||||
6, 6, 1, 8, 3, 3, 5, 5, 4, 2, 2, 2, 4, 4, 6, 6, // 0x20-0x2f
|
||||
2, 5, 1, 8, 4, 4, 6, 6, 2, 4, 2, 7, 4, 4, 7, 7, // 0x30-0x3f
|
||||
6, 6, 1, 8, 3, 3, 5, 5, 3, 2, 2, 2, 3, 4, 6, 6, // 0x40-0x4f
|
||||
2, 5, 1, 8, 4, 4, 6, 6, 2, 4, 2, 7, 4, 4, 7, 7, // 0x50-0x5f
|
||||
6, 6, 1, 8, 3, 3, 5, 5, 4, 2, 2, 2, 5, 4, 6, 6, // 0x60-0x6f
|
||||
2, 5, 1, 8, 4, 4, 6, 6, 2, 4, 2, 7, 4, 4, 7, 7, // 0x70-0x7f
|
||||
2, 6, 2, 6, 3, 3, 3, 3, 2, 2, 2, 2, 4, 4, 4, 4, // 0x80-0x8f
|
||||
2, 6, 1, 6, 4, 4, 4, 4, 2, 5, 2, 5, 5, 5, 5, 5, // 0x90-0x9f
|
||||
2, 6, 2, 6, 3, 3, 3, 3, 2, 2, 2, 2, 4, 4, 4, 4, // 0xa0-0xaf
|
||||
2, 5, 1, 5, 4, 4, 4, 4, 2, 4, 2, 4, 4, 4, 4, 4, // 0xb0-0xbf
|
||||
2, 6, 2, 8, 3, 3, 5, 5, 2, 2, 2, 2, 4, 4, 6, 6, // 0xc0-0xcf
|
||||
2, 5, 1, 8, 4, 4, 6, 6, 2, 4, 2, 7, 4, 4, 7, 7, // 0xd0-0xdf
|
||||
2, 6, 2, 8, 3, 3, 5, 5, 2, 2, 2, 2, 4, 4, 6, 6, // 0xe0-0xef
|
||||
2, 5, 1, 8, 4, 4, 6, 6, 2, 4, 2, 7, 4, 4, 7, 7 // 0xf0-0xff
|
||||
};
|
||||
|
||||
/**
|
||||
* Number of clock cycles required for each instruction when
|
||||
* in CMOS mode
|
||||
*/
|
||||
int[] instructionClocksCmos = {
|
||||
7, 6, 2, 1, 5, 3, 5, 5, 3, 2, 2, 1, 6, 4, 6, 5, // 0x00-0x0f
|
||||
2, 5, 5, 1, 5, 4, 6, 5, 2, 4, 2, 1, 6, 4, 6, 5, // 0x10-0x1f
|
||||
6, 6, 2, 1, 3, 3, 5, 5, 4, 2, 2, 1, 4, 4, 6, 5, // 0x20-0x2f
|
||||
2, 5, 5, 1, 4, 4, 6, 5, 2, 4, 2, 1, 4, 4, 6, 5, // 0x30-0x3f
|
||||
6, 6, 2, 1, 2, 3, 5, 3, 3, 2, 2, 1, 3, 4, 6, 5, // 0x40-0x4f
|
||||
2, 5, 5, 1, 4, 4, 6, 5, 2, 4, 3, 1, 8, 4, 6, 5, // 0x50-0x5f
|
||||
6, 6, 2, 1, 3, 3, 5, 5, 4, 2, 2, 1, 6, 4, 6, 5, // 0x60-0x6f
|
||||
2, 5, 5, 1, 4, 4, 6, 5, 2, 4, 4, 3, 6, 4, 6, 5, // 0x70-0x7f
|
||||
3, 6, 2, 1, 3, 3, 3, 5, 2, 2, 2, 1, 4, 4, 4, 5, // 0x80-0x8f
|
||||
2, 6, 5, 1, 4, 4, 4, 5, 2, 5, 2, 1, 4, 5, 5, 5, // 0x90-0x9f
|
||||
2, 6, 2, 1, 3, 3, 3, 5, 2, 2, 2, 1, 4, 4, 4, 5, // 0xa0-0xaf
|
||||
2, 5, 5, 1, 4, 4, 4, 5, 2, 4, 2, 1, 4, 4, 4, 5, // 0xb0-0xbf
|
||||
2, 6, 2, 1, 3, 3, 5, 5, 2, 2, 2, 3, 4, 4, 6, 5, // 0xc0-0xcf
|
||||
2, 5, 5, 1, 4, 4, 6, 5, 2, 4, 3, 3, 4, 4, 7, 5, // 0xd0-0xdf
|
||||
2, 6, 2, 1, 3, 3, 5, 5, 2, 2, 2, 1, 4, 4, 6, 5, // 0xe0-0xef
|
||||
2, 5, 5, 1, 4, 4, 6, 5, 2, 4, 4, 1, 4, 4, 7, 5 // 0xf0-0xff
|
||||
};
|
||||
|
||||
}
|
||||
@@ -0,0 +1,160 @@
|
||||
/*
|
||||
* Copyright (c) 2008-2025 Seth J. Morabito <web@loomcom.com>
|
||||
* Maik Merten <maikmerten@googlemail.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.loomcom.symon;
|
||||
|
||||
import com.loomcom.symon.machines.*;
|
||||
import com.loomcom.symon.ui.Ui;
|
||||
|
||||
import org.apache.commons.cli.*;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import javax.swing.SwingUtilities;
|
||||
|
||||
public class Main {
|
||||
private final static Logger logger = LoggerFactory.getLogger(Main.class.getName());
|
||||
|
||||
/**
|
||||
* Main entry point to the simulator. Creates a simulator and shows the main
|
||||
* window.
|
||||
*
|
||||
* @param args Program arguments
|
||||
*/
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
Class<?> machineClass = null;
|
||||
|
||||
Options options = new Options();
|
||||
|
||||
options.addOption(new Option("h", "help", false, "Print this message."));
|
||||
options.addOption(new Option("m", "machine", true, "Specify machine type."));
|
||||
options.addOption(new Option("c", "cpu", true, "Specify CPU type."));
|
||||
options.addOption(new Option("r", "rom", true, "Specify ROM file."));
|
||||
options.addOption(new Option("b", "brk", false, "Halt on BRK"));
|
||||
|
||||
CommandLineParser parser = new DefaultParser();
|
||||
|
||||
try {
|
||||
|
||||
CommandLine line = parser.parse(options, args);
|
||||
InstructionTable.CpuBehavior cpuBehavior = null;
|
||||
String romFile = null;
|
||||
boolean haltOnBreak = false;
|
||||
|
||||
if (line.hasOption("help")) {
|
||||
HelpFormatter formatter = new HelpFormatter();
|
||||
formatter.printHelp("symon", options, false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (line.hasOption("machine")) {
|
||||
String machine = line.getOptionValue("machine").toLowerCase(Locale.ENGLISH);
|
||||
switch (machine) {
|
||||
case "multicomp":
|
||||
machineClass = MulticompMachine.class;
|
||||
break;
|
||||
case "simple":
|
||||
machineClass = SimpleMachine.class;
|
||||
break;
|
||||
case "symon":
|
||||
machineClass = SymonMachine.class;
|
||||
break;
|
||||
case "beneater":
|
||||
machineClass = BenEaterMachine.class;
|
||||
break;
|
||||
case "mike42":
|
||||
machineClass = MichaelBillingtonMachine.class;
|
||||
break;
|
||||
default:
|
||||
logger.error("Could not start Symon. Unknown machine type {}", machine);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (line.hasOption("cpu")) {
|
||||
String cpu = line.getOptionValue("cpu").toLowerCase(Locale.ENGLISH);
|
||||
switch (cpu) {
|
||||
case "6502":
|
||||
cpuBehavior = InstructionTable.CpuBehavior.NMOS_6502;
|
||||
break;
|
||||
case "65c02":
|
||||
cpuBehavior = InstructionTable.CpuBehavior.CMOS_6502;
|
||||
break;
|
||||
case "65c816":
|
||||
cpuBehavior = InstructionTable.CpuBehavior.CMOS_65816;
|
||||
break;
|
||||
default:
|
||||
logger.error("Could not start Symon. Unknown cpu type {}", cpu);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (line.hasOption("rom")) {
|
||||
romFile = line.getOptionValue("rom");
|
||||
}
|
||||
|
||||
if (line.hasOption("brk")) {
|
||||
haltOnBreak = true;
|
||||
}
|
||||
|
||||
Ui.initUi();
|
||||
|
||||
while (true) {
|
||||
if (machineClass == null) {
|
||||
machineClass = Ui.showMachineSelectionDialog();
|
||||
}
|
||||
|
||||
if (cpuBehavior == null) {
|
||||
cpuBehavior = InstructionTable.CpuBehavior.NMOS_6502;
|
||||
}
|
||||
|
||||
final Simulator simulator = new Simulator(machineClass, cpuBehavior, romFile, haltOnBreak);
|
||||
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
// Create the main UI window:
|
||||
try {
|
||||
simulator.createAndShowUi();
|
||||
} catch (Exception e) {
|
||||
logger.error("Error during Symon UI initialization: {}", e.getMessage());
|
||||
System.exit(-1);
|
||||
}
|
||||
});
|
||||
|
||||
Simulator.MainCommand cmd = simulator.waitForCommand();
|
||||
|
||||
if (cmd.equals(Simulator.MainCommand.SELECTMACHINE)) {
|
||||
machineClass = null;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (ParseException ex) {
|
||||
logger.error("Could not start Symon. Reason: {}", ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2008-2013 Seth J. Morabito <sethm@loomcom.com>
|
||||
* Copyright (c) 2008-2025 Seth J. Morabito <web@loomcom.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
@@ -27,84 +27,85 @@ import com.loomcom.symon.exceptions.*;
|
||||
|
||||
/**
|
||||
* MemoryRange is a simple container class representing a literal
|
||||
* range of memory, with a staraddress, and an end address. It has
|
||||
* range of memory, with a start address, and an end address. It has
|
||||
* guards against creating impossible memory ranges, and implements
|
||||
* some useful methods for checking address inclusion and range
|
||||
* overlaps.
|
||||
*/
|
||||
public class MemoryRange implements Comparable<MemoryRange> {
|
||||
|
||||
/** The starting address of the memory range. */
|
||||
public int startAddress;
|
||||
/** The ending address of the memory range. */
|
||||
public int endAddress;
|
||||
/**
|
||||
* The starting address of the memory range.
|
||||
*/
|
||||
public int startAddress;
|
||||
/**
|
||||
* The ending address of the memory range.
|
||||
*/
|
||||
public int endAddress;
|
||||
|
||||
public MemoryRange(int startAddress, int endAddress)
|
||||
throws MemoryRangeException {
|
||||
if (startAddress < 0 || endAddress < 0) {
|
||||
throw new MemoryRangeException("Addresses cannot be less than 0.");
|
||||
public MemoryRange(int startAddress, int endAddress)
|
||||
throws MemoryRangeException {
|
||||
if (startAddress < 0 || endAddress < 0) {
|
||||
throw new MemoryRangeException("Addresses cannot be less than 0.");
|
||||
}
|
||||
if (startAddress >= endAddress) {
|
||||
throw new MemoryRangeException("End address must be greater " +
|
||||
"than start address.");
|
||||
}
|
||||
this.startAddress = startAddress;
|
||||
this.endAddress = endAddress;
|
||||
}
|
||||
if (startAddress >= endAddress) {
|
||||
throw new MemoryRangeException("End address must be greater " +
|
||||
"than start address.");
|
||||
|
||||
/**
|
||||
* @return the starting address.
|
||||
*/
|
||||
public int startAddress() {
|
||||
return startAddress;
|
||||
}
|
||||
this.startAddress = startAddress;
|
||||
this.endAddress = endAddress;
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns the starting address.
|
||||
*/
|
||||
public int startAddress() {
|
||||
return startAddress;
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns the ending address.
|
||||
*/
|
||||
public int endAddress() {
|
||||
return endAddress;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks for address inclusion in the range.
|
||||
*
|
||||
* @returns true if the address is included within this range,
|
||||
* false otherwise.
|
||||
*/
|
||||
public boolean includes(int address) {
|
||||
return (address <= endAddress &&
|
||||
address >= startAddress);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks for overlapping memory ranges.
|
||||
*
|
||||
* @returns true if this range overlaps in any way with the other.
|
||||
*/
|
||||
public boolean overlaps(MemoryRange other) {
|
||||
return (this.includes(other.startAddress()) ||
|
||||
other.includes(this.startAddress()));
|
||||
}
|
||||
|
||||
// Implementation of Comparable interface
|
||||
public int compareTo(MemoryRange other) {
|
||||
if (other == null) {
|
||||
throw new NullPointerException("Cannot compare to null.");
|
||||
/**
|
||||
* @return the ending address.
|
||||
*/
|
||||
public int endAddress() {
|
||||
return endAddress;
|
||||
}
|
||||
if (this == other) {
|
||||
return 0;
|
||||
}
|
||||
Integer thisStartAddr = new Integer(this.startAddress());
|
||||
Integer thatStartAddr = new Integer(other.startAddress());
|
||||
return thisStartAddr.compareTo(thatStartAddr);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
StringBuffer desc = new StringBuffer("@");
|
||||
desc.append(String.format("0x%04x", startAddress));
|
||||
desc.append("-");
|
||||
desc.append(String.format("0x%04x", endAddress));
|
||||
return desc.toString();
|
||||
}
|
||||
/**
|
||||
* Checks for address inclusion in the range.
|
||||
*
|
||||
* @return true if the address is included within this range,
|
||||
* false otherwise.
|
||||
*/
|
||||
public boolean includes(int address) {
|
||||
return (address <= endAddress &&
|
||||
address >= startAddress);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks for overlapping memory ranges.
|
||||
*
|
||||
* @return true if this range overlaps in any way with the other.
|
||||
*/
|
||||
public boolean overlaps(MemoryRange other) {
|
||||
return (this.includes(other.startAddress()) ||
|
||||
other.includes(this.startAddress()));
|
||||
}
|
||||
|
||||
// Implementation of Comparable interface
|
||||
public int compareTo(MemoryRange other) {
|
||||
if (other == null) {
|
||||
throw new NullPointerException("Cannot compare to null.");
|
||||
}
|
||||
if (this == other) {
|
||||
return 0;
|
||||
}
|
||||
Integer thisStartAddr = this.startAddress();
|
||||
Integer thatStartAddr = other.startAddress();
|
||||
return thisStartAddr.compareTo(thatStartAddr);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "@" + String.format("0x%04x", startAddress) + "-" +
|
||||
String.format("0x%04x", endAddress);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2008-2013 Seth J. Morabito <sethm@loomcom.com>
|
||||
* Copyright (c) 2008-2025 Seth J. Morabito <web@loomcom.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
@@ -27,15 +27,13 @@ import javax.swing.*;
|
||||
|
||||
public interface Preferences {
|
||||
|
||||
public static final int DEFAULT_PROGRAM_LOAD_ADDRESS = 0x0300;
|
||||
int DEFAULT_PROGRAM_LOAD_ADDRESS = 0x0300;
|
||||
|
||||
public static final boolean DEFAULT_HALT_ON_BREAK = true;
|
||||
JDialog getDialog();
|
||||
|
||||
public JDialog getDialog();
|
||||
int getProgramStartAddress();
|
||||
|
||||
public int getProgramStartAddress();
|
||||
boolean getHaltOnBreak();
|
||||
|
||||
public boolean getHaltOnBreak();
|
||||
|
||||
public void updateUi();
|
||||
void updateUi();
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2008-2013 Seth J. Morabito <sethm@loomcom.com>
|
||||
* Copyright (c) 2008-2025 Seth J. Morabito <web@loomcom.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
@@ -23,169 +23,48 @@
|
||||
|
||||
package com.loomcom.symon.devices;
|
||||
|
||||
import com.loomcom.symon.exceptions.*;
|
||||
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import com.loomcom.symon.exceptions.MemoryRangeException;
|
||||
|
||||
|
||||
/**
|
||||
* This is a simulation of the MOS 6551 ACIA, with limited
|
||||
* functionality. Interrupts are not supported.
|
||||
* <p/>
|
||||
* Unlike a 16550 UART, the 6551 ACIA has only one-byte transmit and
|
||||
* receive buffers. It is the programmer's responsibility to check the
|
||||
* status (full or empty) for transmit and receive buffers before
|
||||
* writing / reading.
|
||||
* Abstract base class for ACIAS such as the 6551 and 6580
|
||||
*/
|
||||
public class Acia extends Device {
|
||||
|
||||
public static final int ACIA_SIZE = 4;
|
||||
public abstract class Acia extends Device {
|
||||
|
||||
static final int DATA_REG = 0;
|
||||
static final int STAT_REG = 1;
|
||||
static final int CMND_REG = 2;
|
||||
static final int CTRL_REG = 3;
|
||||
private final String name;
|
||||
|
||||
/**
|
||||
* Register addresses
|
||||
*/
|
||||
private int baseAddress;
|
||||
int baseAddress;
|
||||
|
||||
/**
|
||||
* Registers. These are ignored in the current implementation.
|
||||
*/
|
||||
private int commandRegister;
|
||||
private int controlRegister;
|
||||
boolean receiveIrqEnabled = false;
|
||||
boolean transmitIrqEnabled = false;
|
||||
boolean overrun = false;
|
||||
boolean interrupt = false;
|
||||
|
||||
private boolean overrun = false;
|
||||
|
||||
private long lastTxWrite = 0;
|
||||
private long lastRxRead = 0;
|
||||
private int baudRate = 0;
|
||||
private long baudRateDelay = 0;
|
||||
long lastTxWrite = 0;
|
||||
long lastRxRead = 0;
|
||||
int baudRate = 0;
|
||||
long baudRateDelay = 0;
|
||||
|
||||
/**
|
||||
* Read/Write buffers
|
||||
*/
|
||||
private int rxChar = 0;
|
||||
private int txChar = 0;
|
||||
int rxChar = 0;
|
||||
int txChar = 0;
|
||||
|
||||
private boolean rxFull = false;
|
||||
private boolean txEmpty = true;
|
||||
boolean rxFull = false;
|
||||
boolean txEmpty = true;
|
||||
|
||||
public Acia(int address) throws MemoryRangeException {
|
||||
super(address, address + ACIA_SIZE - 1, "ACIA");
|
||||
|
||||
public Acia(int address, int size, String name) throws MemoryRangeException {
|
||||
super(address, address + size - 1, name);
|
||||
this.name = name;
|
||||
this.baseAddress = address;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read(int address) throws MemoryAccessException {
|
||||
switch (address) {
|
||||
case DATA_REG:
|
||||
return rxRead();
|
||||
case STAT_REG:
|
||||
return statusReg();
|
||||
case CMND_REG:
|
||||
return commandRegister;
|
||||
case CTRL_REG:
|
||||
return controlRegister;
|
||||
default:
|
||||
throw new MemoryAccessException("No register.");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(int address, int data) throws MemoryAccessException {
|
||||
switch (address) {
|
||||
case 0:
|
||||
txWrite(data);
|
||||
break;
|
||||
case 1:
|
||||
reset();
|
||||
break;
|
||||
case 2:
|
||||
commandRegister = data;
|
||||
break;
|
||||
case 3:
|
||||
setControlRegister(data);
|
||||
break;
|
||||
default:
|
||||
throw new MemoryAccessException("No register.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the control register and associated state.
|
||||
*
|
||||
* @param data
|
||||
*/
|
||||
public void setControlRegister(int data) {
|
||||
this.controlRegister = data;
|
||||
|
||||
// If the value of the data is 0, this is a request to reset,
|
||||
// otherwise it's a control update.
|
||||
|
||||
if (data == 0) {
|
||||
reset();
|
||||
} else {
|
||||
// Mask the lower three bits to get the baud rate.
|
||||
int baudSelector = data & 0x0f;
|
||||
switch (baudSelector) {
|
||||
case 0:
|
||||
baudRate = 0;
|
||||
break;
|
||||
case 1:
|
||||
baudRate = 50;
|
||||
break;
|
||||
case 2:
|
||||
baudRate = 75;
|
||||
break;
|
||||
case 3:
|
||||
baudRate = 110; // Real rate is actually 109.92
|
||||
break;
|
||||
case 4:
|
||||
baudRate = 135; // Real rate is actually 134.58
|
||||
break;
|
||||
case 5:
|
||||
baudRate = 150;
|
||||
break;
|
||||
case 6:
|
||||
baudRate = 300;
|
||||
break;
|
||||
case 7:
|
||||
baudRate = 600;
|
||||
break;
|
||||
case 8:
|
||||
baudRate = 1200;
|
||||
break;
|
||||
case 9:
|
||||
baudRate = 1800;
|
||||
break;
|
||||
case 10:
|
||||
baudRate = 2400;
|
||||
break;
|
||||
case 11:
|
||||
baudRate = 3600;
|
||||
break;
|
||||
case 12:
|
||||
baudRate = 4800;
|
||||
break;
|
||||
case 13:
|
||||
baudRate = 7200;
|
||||
break;
|
||||
case 14:
|
||||
baudRate = 9600;
|
||||
break;
|
||||
case 15:
|
||||
baudRate = 19200;
|
||||
break;
|
||||
}
|
||||
|
||||
// Recalculate the baud rate delay.
|
||||
baudRateDelay = calculateBaudRateDelay();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Calculate the delay in nanoseconds between successive read/write operations, based on the
|
||||
@@ -204,6 +83,7 @@ public class Acia extends Device {
|
||||
/**
|
||||
* @return The simulated baud rate in bps.
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public int getBaudRate() {
|
||||
return baudRate;
|
||||
}
|
||||
@@ -215,48 +95,59 @@ public class Acia extends Device {
|
||||
*/
|
||||
public void setBaudRate(int rate) {
|
||||
this.baudRate = rate;
|
||||
this.baudRateDelay = calculateBaudRateDelay();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The contents of the status register.
|
||||
*/
|
||||
public int statusReg() {
|
||||
// TODO: Overrun, Parity Error, Framing Error, DTR, DSR, and Interrupt flags.
|
||||
int stat = 0;
|
||||
if (rxFull && System.nanoTime() >= (lastRxRead + baudRateDelay)) {
|
||||
stat |= 0x08;
|
||||
}
|
||||
if (txEmpty && System.nanoTime() >= (lastTxWrite + baudRateDelay)) {
|
||||
stat |= 0x10;
|
||||
}
|
||||
return stat;
|
||||
}
|
||||
public abstract int statusReg(boolean cpuAccess);
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ACIA@" + String.format("%04X", baseAddress);
|
||||
return name + "@" + String.format("%04X", baseAddress);
|
||||
}
|
||||
|
||||
public synchronized int rxRead() {
|
||||
lastRxRead = System.nanoTime();
|
||||
rxFull = false;
|
||||
public synchronized int rxRead(boolean cpuAccess) {
|
||||
if (cpuAccess) {
|
||||
lastRxRead = System.nanoTime();
|
||||
overrun = false;
|
||||
rxFull = false;
|
||||
}
|
||||
return rxChar;
|
||||
}
|
||||
|
||||
public synchronized void rxWrite(int data) {
|
||||
if (rxFull) {
|
||||
overrun = true;
|
||||
}
|
||||
|
||||
rxFull = true;
|
||||
|
||||
if (receiveIrqEnabled) {
|
||||
interrupt = true;
|
||||
getBus().assertIrq();
|
||||
}
|
||||
|
||||
rxChar = data;
|
||||
}
|
||||
|
||||
public synchronized int txRead() {
|
||||
txEmpty = true;
|
||||
public synchronized int txRead(boolean cpuAccess) {
|
||||
if (cpuAccess) {
|
||||
txEmpty = true;
|
||||
|
||||
if (transmitIrqEnabled) {
|
||||
interrupt = true;
|
||||
getBus().assertIrq();
|
||||
}
|
||||
}
|
||||
return txChar;
|
||||
}
|
||||
|
||||
public synchronized void txWrite(int data) {
|
||||
lastTxWrite = System.nanoTime();
|
||||
txEmpty = false;
|
||||
txChar = data;
|
||||
txEmpty = false;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -269,15 +160,9 @@ public class Acia extends Device {
|
||||
/**
|
||||
* @return true if there is character data in the RX register.
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public boolean hasRxChar() {
|
||||
return rxFull;
|
||||
}
|
||||
|
||||
private synchronized void reset() {
|
||||
txChar = 0;
|
||||
txEmpty = true;
|
||||
rxChar = 0;
|
||||
rxFull = false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,218 @@
|
||||
/*
|
||||
* Copyright (c) 2008-2025 Seth J. Morabito <web@loomcom.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.loomcom.symon.devices;
|
||||
|
||||
import com.loomcom.symon.exceptions.MemoryAccessException;
|
||||
import com.loomcom.symon.exceptions.MemoryRangeException;
|
||||
|
||||
/**
|
||||
* This is a simulation of the MOS 6551 ACIA, with limited
|
||||
* functionality.
|
||||
* <p/>
|
||||
* Unlike a 16550 UART, the 6551 ACIA has only one-byte transmit and
|
||||
* receive buffers. It is the programmer's responsibility to check the
|
||||
* status (full or empty) for transmit and receive buffers before
|
||||
* writing / reading.
|
||||
*/
|
||||
public class Acia6551 extends Acia {
|
||||
|
||||
public static final int ACIA_SIZE = 4;
|
||||
|
||||
static final int DATA_REG = 0;
|
||||
static final int STAT_REG = 1;
|
||||
static final int CMND_REG = 2;
|
||||
static final int CTRL_REG = 3;
|
||||
|
||||
/**
|
||||
* Registers. These are ignored in the current implementation.
|
||||
*/
|
||||
private int commandRegister;
|
||||
private int controlRegister;
|
||||
|
||||
|
||||
public Acia6551(int address) throws MemoryRangeException {
|
||||
super(address, ACIA_SIZE, "ACIA");
|
||||
|
||||
// Figure 6 in the 6551 ACIA data sheet says the "hardware reset"
|
||||
// state of the Control Register is all zeros.
|
||||
setControlRegister(0b00000000);
|
||||
// Figure 7 of the 6551 ACIA data sheet says the "hardware reset"
|
||||
// state of the Command Register is zeros, but Transmitter Control
|
||||
// is set to "interrupt disabled, ready to send".
|
||||
setCommandRegister(0b00000010);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read(int address, boolean cpuAccess) throws MemoryAccessException {
|
||||
switch (address) {
|
||||
case DATA_REG:
|
||||
return rxRead(cpuAccess);
|
||||
case STAT_REG:
|
||||
return statusReg(cpuAccess);
|
||||
case CMND_REG:
|
||||
return commandRegister;
|
||||
case CTRL_REG:
|
||||
return controlRegister;
|
||||
default:
|
||||
throw new MemoryAccessException("No register.");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(int address, int data) throws MemoryAccessException {
|
||||
switch (address) {
|
||||
case DATA_REG:
|
||||
txWrite(data);
|
||||
break;
|
||||
case STAT_REG:
|
||||
reset();
|
||||
break;
|
||||
case CMND_REG:
|
||||
setCommandRegister(data);
|
||||
break;
|
||||
case CTRL_REG:
|
||||
setControlRegister(data);
|
||||
break;
|
||||
default:
|
||||
throw new MemoryAccessException("No register.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void setCommandRegister(int data) {
|
||||
commandRegister = data;
|
||||
|
||||
// Bit 1 controls receiver IRQ behavior
|
||||
receiveIrqEnabled = (commandRegister & 0x02) == 0;
|
||||
// Bits 2 & 3 controls transmit IRQ behavior
|
||||
transmitIrqEnabled = (commandRegister & 0x08) == 0 && (commandRegister & 0x04) != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the control register and associated state.
|
||||
*
|
||||
* @param data Data to write into the control register
|
||||
*/
|
||||
private void setControlRegister(int data) {
|
||||
controlRegister = data;
|
||||
int rate = 0;
|
||||
|
||||
// Mask the lower four bits to get the baud rate.
|
||||
int baudSelector = data & 0x0f;
|
||||
switch (baudSelector) {
|
||||
case 1:
|
||||
rate = 50;
|
||||
break;
|
||||
case 2:
|
||||
rate = 75;
|
||||
break;
|
||||
case 3:
|
||||
rate = 110; // Real rate is actually 109.92
|
||||
break;
|
||||
case 4:
|
||||
rate = 135; // Real rate is actually 134.58
|
||||
break;
|
||||
case 5:
|
||||
rate = 150;
|
||||
break;
|
||||
case 6:
|
||||
rate = 300;
|
||||
break;
|
||||
case 7:
|
||||
rate = 600;
|
||||
break;
|
||||
case 8:
|
||||
rate = 1200;
|
||||
break;
|
||||
case 9:
|
||||
rate = 1800;
|
||||
break;
|
||||
case 10:
|
||||
rate = 2400;
|
||||
break;
|
||||
case 11:
|
||||
rate = 3600;
|
||||
break;
|
||||
case 12:
|
||||
rate = 4800;
|
||||
break;
|
||||
case 13:
|
||||
rate = 7200;
|
||||
break;
|
||||
case 14:
|
||||
rate = 9600;
|
||||
break;
|
||||
case 15:
|
||||
rate = 19200;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
setBaudRate(rate);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return The contents of the status register.
|
||||
*/
|
||||
@Override
|
||||
public int statusReg(boolean cpuAccess) {
|
||||
// TODO: Parity Error, Framing Error, DTR, and DSR flags.
|
||||
int stat = 0;
|
||||
if (rxFull && System.nanoTime() >= (lastRxRead + baudRateDelay)) {
|
||||
stat |= 0x08;
|
||||
}
|
||||
if (txEmpty && System.nanoTime() >= (lastTxWrite + baudRateDelay)) {
|
||||
stat |= 0x10;
|
||||
}
|
||||
if (overrun) {
|
||||
stat |= 0x04;
|
||||
}
|
||||
if (interrupt) {
|
||||
stat |= 0x80;
|
||||
}
|
||||
|
||||
if (cpuAccess) {
|
||||
interrupt = false;
|
||||
}
|
||||
|
||||
return stat;
|
||||
}
|
||||
|
||||
|
||||
private synchronized void reset() {
|
||||
// Figure 6 in the 6551 ACIA data sheet says the "program reset"
|
||||
// event does not modify the control register.
|
||||
|
||||
// Figure 7 in the 6551 ACIA data sheet says the "program reset"
|
||||
// event keeps the "parity check" configuration in the command
|
||||
// register, but resets the other bits to defaults.
|
||||
setCommandRegister((commandRegister & 0xe0) | 0x02);
|
||||
|
||||
// Figure 8 in the 6551 ACIA data sheet says the "program reset"
|
||||
// event clears the "overrun" flag but otherwise has no effect.
|
||||
overrun = false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
/*
|
||||
* Copyright (c) 2008-2025 Seth J. Morabito <web@loomcom.com>
|
||||
* Maik Merten <maikmerten@googlemail.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.loomcom.symon.devices;
|
||||
|
||||
import com.loomcom.symon.exceptions.MemoryAccessException;
|
||||
import com.loomcom.symon.exceptions.MemoryRangeException;
|
||||
|
||||
|
||||
/**
|
||||
* This is a simulation of the Motorola 6850 ACIA, with limited
|
||||
* functionality.
|
||||
* <p>
|
||||
* Unlike a 16550 UART, the 6850 ACIA has only one-byte transmit and
|
||||
* receive buffers. It is the programmer's responsibility to check the
|
||||
* status (full or empty) for transmit and receive buffers before
|
||||
* writing / reading.
|
||||
*/
|
||||
public class Acia6850 extends Acia {
|
||||
|
||||
public static final int ACIA_SIZE = 2;
|
||||
|
||||
static final int STAT_REG = 0; // read-only
|
||||
static final int CTRL_REG = 0; // write-only
|
||||
|
||||
static final int RX_REG = 1; // read-only
|
||||
static final int TX_REG = 1; // write-only
|
||||
|
||||
public Acia6850(int address) throws MemoryRangeException {
|
||||
super(address, ACIA_SIZE, "ACIA6850");
|
||||
setBaudRate(2400);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read(int address, boolean cpuAccess) throws MemoryAccessException {
|
||||
switch (address) {
|
||||
case RX_REG:
|
||||
return rxRead(cpuAccess);
|
||||
case STAT_REG:
|
||||
return statusReg(cpuAccess);
|
||||
|
||||
default:
|
||||
throw new MemoryAccessException("No register.");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(int address, int data) throws MemoryAccessException {
|
||||
switch (address) {
|
||||
case TX_REG:
|
||||
txWrite(data);
|
||||
break;
|
||||
case CTRL_REG:
|
||||
setCommandRegister(data);
|
||||
break;
|
||||
default:
|
||||
throw new MemoryAccessException("No register.");
|
||||
}
|
||||
}
|
||||
|
||||
private void setCommandRegister(int data) {
|
||||
// Bits 0 & 1 control the master reset
|
||||
if((data & 0x01) != 0 && (data & 0x02) != 0) {
|
||||
reset();
|
||||
}
|
||||
|
||||
// Bit 7 controls receiver IRQ behavior
|
||||
receiveIrqEnabled = (data & 0x80) != 0;
|
||||
// Bits 5 & 6 controls transmit IRQ behavior
|
||||
transmitIrqEnabled = (data & 0x20) != 0 && (data & 0x40) == 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @return The contents of the status register.
|
||||
*/
|
||||
@Override
|
||||
public int statusReg(boolean cpuAccess) {
|
||||
// TODO: Parity Error, Framing Error, DTR, and DSR flags.
|
||||
int stat = 0;
|
||||
if (rxFull && System.nanoTime() >= (lastRxRead + baudRateDelay)) {
|
||||
stat |= 0x01;
|
||||
}
|
||||
if (txEmpty && System.nanoTime() >= (lastTxWrite + baudRateDelay)) {
|
||||
stat |= 0x02;
|
||||
}
|
||||
if (overrun) {
|
||||
stat |= 0x20;
|
||||
}
|
||||
if (interrupt) {
|
||||
stat |= 0x80;
|
||||
}
|
||||
|
||||
if (cpuAccess) {
|
||||
interrupt = false;
|
||||
}
|
||||
|
||||
return stat;
|
||||
}
|
||||
|
||||
|
||||
private synchronized void reset() {
|
||||
overrun = false;
|
||||
rxFull = false;
|
||||
txEmpty = true;
|
||||
interrupt = false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,20 +1,35 @@
|
||||
/*
|
||||
* Copyright (c) 2008-2025 Seth J. Morabito <web@loomcom.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.loomcom.symon.devices;
|
||||
|
||||
import com.loomcom.symon.exceptions.MemoryAccessException;
|
||||
import com.loomcom.symon.exceptions.MemoryRangeException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
|
||||
/**
|
||||
* Simulation of a 6545 CRTC and virtual CRT output.
|
||||
*/
|
||||
public class Crtc extends Device {
|
||||
|
||||
private static final Logger logger = Logger.getLogger(Crtc.class.getName());
|
||||
|
||||
|
||||
// Memory locations in the CRTC address space
|
||||
public static final int REGISTER_SELECT = 0;
|
||||
public static final int REGISTER_RW = 1;
|
||||
@@ -65,9 +80,14 @@ public class Crtc extends Device {
|
||||
|
||||
private int currentRegister = 0;
|
||||
|
||||
private Memory memory;
|
||||
// Status bits
|
||||
private boolean rowColumnAddressing = false;
|
||||
private boolean displayEnableSkew = false;
|
||||
private boolean cursorSkew = false;
|
||||
|
||||
public Crtc(int deviceAddress, Memory memory) throws MemoryRangeException, IOException {
|
||||
private final Memory memory;
|
||||
|
||||
public Crtc(int deviceAddress, Memory memory) throws MemoryRangeException {
|
||||
super(deviceAddress, deviceAddress + 2, "CRTC");
|
||||
this.memory = memory;
|
||||
|
||||
@@ -97,20 +117,18 @@ public class Crtc extends Device {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read(int address) throws MemoryAccessException {
|
||||
switch (address) {
|
||||
case REGISTER_RW:
|
||||
switch (currentRegister) {
|
||||
case CURSOR_POSITION_LOW:
|
||||
return cursorPosition & 0xff;
|
||||
case CURSOR_POSITION_HIGH:
|
||||
return cursorPosition >> 8;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
default:
|
||||
return 0;
|
||||
public int read(int address, boolean cpuAccess) throws MemoryAccessException {
|
||||
if (address == REGISTER_RW) {
|
||||
switch (currentRegister) {
|
||||
case CURSOR_POSITION_LOW:
|
||||
return cursorPosition & 0xff;
|
||||
case CURSOR_POSITION_HIGH:
|
||||
return cursorPosition >> 8;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -118,8 +136,9 @@ public class Crtc extends Device {
|
||||
return null;
|
||||
}
|
||||
|
||||
public int[] getDmaAccess() {
|
||||
return memory.getDmaAccess();
|
||||
public int getCharAtAddress(int address) throws MemoryAccessException {
|
||||
// TODO: Row/Column addressing
|
||||
return memory.read(address, false);
|
||||
}
|
||||
|
||||
public int getHorizontalDisplayed() {
|
||||
@@ -162,6 +181,18 @@ public class Crtc extends Device {
|
||||
return pageSize;
|
||||
}
|
||||
|
||||
public boolean getRowColumnAddressing() {
|
||||
return rowColumnAddressing;
|
||||
}
|
||||
|
||||
public boolean getDisplayEnableSkew() {
|
||||
return displayEnableSkew;
|
||||
}
|
||||
|
||||
public boolean getCursorSkew() {
|
||||
return cursorSkew;
|
||||
}
|
||||
|
||||
private void setCurrentRegister(int registerNumber) {
|
||||
this.currentRegister = registerNumber;
|
||||
}
|
||||
@@ -180,7 +211,9 @@ public class Crtc extends Device {
|
||||
pageSize = horizontalDisplayed * verticalDisplayed;
|
||||
break;
|
||||
case MODE_CONTROL:
|
||||
// TODO: Implement multiple addressing modes and cursor skew.
|
||||
rowColumnAddressing = (data & 0x04) != 0;
|
||||
displayEnableSkew = (data & 0x10) != 0;
|
||||
cursorSkew = (data & 0x20) != 0;
|
||||
break;
|
||||
case SCAN_LINE:
|
||||
scanLinesPerRow = data;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2008-2013 Seth J. Morabito <sethm@loomcom.com>
|
||||
* Copyright (c) 2008-2025 Seth J. Morabito <web@loomcom.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
@@ -45,7 +45,7 @@ public abstract class Device implements Comparable<Device> {
|
||||
/**
|
||||
* The memory range for this device.
|
||||
*/
|
||||
private MemoryRange memoryRange;
|
||||
private final MemoryRange memoryRange;
|
||||
|
||||
/**
|
||||
* The name of the device.
|
||||
@@ -60,24 +60,19 @@ public abstract class Device implements Comparable<Device> {
|
||||
/**
|
||||
* Listeners to notify on update.
|
||||
*/
|
||||
private Set<DeviceChangeListener> deviceChangeListeners;
|
||||
private final Set<DeviceChangeListener> deviceChangeListeners;
|
||||
|
||||
public Device(int startAddress, int endAddress, String name)
|
||||
throws MemoryRangeException {
|
||||
public Device(int startAddress, int endAddress, String name) throws MemoryRangeException {
|
||||
this.memoryRange = new MemoryRange(startAddress, endAddress);
|
||||
this.size = endAddress - startAddress + 1;
|
||||
this.name = name;
|
||||
this.deviceChangeListeners = new HashSet<DeviceChangeListener>();
|
||||
}
|
||||
|
||||
public Device(int startAddress, int endAddress) throws MemoryRangeException {
|
||||
this(startAddress, endAddress, null);
|
||||
this.deviceChangeListeners = new HashSet<>();
|
||||
}
|
||||
|
||||
/* Methods required to be implemented by inheriting classes. */
|
||||
public abstract void write(int address, int data) throws MemoryAccessException;
|
||||
|
||||
public abstract int read(int address) throws MemoryAccessException;
|
||||
public abstract int read(int address, boolean cpuAccess) throws MemoryAccessException;
|
||||
|
||||
public abstract String toString();
|
||||
|
||||
@@ -97,6 +92,7 @@ public abstract class Device implements Comparable<Device> {
|
||||
return memoryRange.endAddress();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public int startAddress() {
|
||||
return memoryRange.startAddress();
|
||||
}
|
||||
@@ -105,6 +101,7 @@ public abstract class Device implements Comparable<Device> {
|
||||
return name;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
@@ -118,8 +115,8 @@ public abstract class Device implements Comparable<Device> {
|
||||
}
|
||||
|
||||
public void notifyListeners() {
|
||||
for (DeviceChangeListener l : deviceChangeListeners) {
|
||||
l.deviceStateChanged();
|
||||
for (DeviceChangeListener listener : deviceChangeListeners) {
|
||||
listener.deviceStateChanged();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2013 Seth J. Morabito <web@loomcom.com>
|
||||
* Copyright (c) 2008-2025 Seth J. Morabito <web@loomcom.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
@@ -24,5 +24,5 @@
|
||||
package com.loomcom.symon.devices;
|
||||
|
||||
public interface DeviceChangeListener {
|
||||
public void deviceStateChanged();
|
||||
void deviceStateChanged();
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2008-2013 Seth J. Morabito <sethm@loomcom.com>
|
||||
* Copyright (c) 2008-2025 Seth J. Morabito <web@loomcom.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
@@ -28,12 +28,10 @@ import java.util.*;
|
||||
|
||||
import com.loomcom.symon.exceptions.*;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public class Memory extends Device {
|
||||
|
||||
private boolean readOnly;
|
||||
private int[] mem;
|
||||
private final boolean readOnly;
|
||||
private final int[] mem;
|
||||
|
||||
/* Initialize all locations to 0x00 (BRK) */
|
||||
private static final int DEFAULT_FILL = 0x00;
|
||||
@@ -57,8 +55,7 @@ public class Memory extends Device {
|
||||
}
|
||||
|
||||
public static Memory makeRAM(int startAddress, int endAddress) throws MemoryRangeException {
|
||||
Memory memory = new Memory(startAddress, endAddress, false);
|
||||
return memory;
|
||||
return new Memory(startAddress, endAddress, false);
|
||||
}
|
||||
|
||||
public void write(int address, int data) throws MemoryAccessException {
|
||||
@@ -97,7 +94,7 @@ public class Memory extends Device {
|
||||
|
||||
}
|
||||
|
||||
public int read(int address) throws MemoryAccessException {
|
||||
public int read(int address, boolean cpuAccess) throws MemoryAccessException {
|
||||
return this.mem[address];
|
||||
}
|
||||
|
||||
@@ -108,8 +105,4 @@ public class Memory extends Device {
|
||||
public String toString() {
|
||||
return "Memory: " + getMemoryRange().toString();
|
||||
}
|
||||
|
||||
public int[] getDmaAccess() {
|
||||
return mem;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2008-2013 Seth J. Morabito <sethm@loomcom.com>
|
||||
* Copyright (c) 2008-2025 Seth J. Morabito <web@loomcom.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
@@ -23,45 +23,19 @@
|
||||
|
||||
package com.loomcom.symon.devices;
|
||||
|
||||
import com.loomcom.symon.exceptions.MemoryAccessException;
|
||||
import com.loomcom.symon.exceptions.MemoryRangeException;
|
||||
|
||||
public class Via extends Device {
|
||||
public static final int VIA_SIZE = 16;
|
||||
public abstract class Pia extends Device {
|
||||
|
||||
private static final int ORB = 0;
|
||||
private static final int ORA = 1;
|
||||
private static final int DDRB = 2;
|
||||
private static final int DDRA = 3;
|
||||
private static final int T1C_L = 4;
|
||||
private static final int T1C_H = 5;
|
||||
private static final int T1L_L = 6;
|
||||
private static final int T1L_H = 7;
|
||||
private static final int T2C_L = 8;
|
||||
private static final int T2C_H = 9;
|
||||
private static final int SR = 10;
|
||||
private static final int ACR = 11;
|
||||
private static final int PCR = 12;
|
||||
private static final int IFR = 13;
|
||||
private static final int IER = 14;
|
||||
private static final int ORA_H = 15;
|
||||
private final String name;
|
||||
|
||||
public Via(int address) throws MemoryRangeException {
|
||||
super(address, address + VIA_SIZE - 1, "VIA");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(int address, int data) throws MemoryAccessException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read(int address) throws MemoryAccessException {
|
||||
return 0;
|
||||
public Pia(int startAddress, int endAddress, String name) throws MemoryRangeException {
|
||||
super(startAddress, endAddress, name);
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return null;
|
||||
return name;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,213 @@
|
||||
/*
|
||||
* Copyright (c) 2008-2025 Seth J. Morabito <web@loomcom.com>
|
||||
* Maik Merten <maikmerten@googlemail.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
package com.loomcom.symon.devices;
|
||||
|
||||
import com.loomcom.symon.exceptions.MemoryAccessException;
|
||||
import com.loomcom.symon.exceptions.MemoryRangeException;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.RandomAccessFile;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* Emulation for the SD-card controller of the MULTICOMP system.
|
||||
* Neiter comlete nor correct.
|
||||
*/
|
||||
public class SdController extends Device {
|
||||
|
||||
private enum Status {
|
||||
IDLE,
|
||||
READ,
|
||||
WRITE
|
||||
}
|
||||
|
||||
public static final int CONTROLLER_SIZE = 8;
|
||||
private final int SECTOR_SIZE = 512;
|
||||
private final static Logger logger = Logger.getLogger(SdController.class.getName());
|
||||
|
||||
private File sdImageFile;
|
||||
private int lba0, lba1, lba2;
|
||||
private int position;
|
||||
private Status status = Status.IDLE;
|
||||
|
||||
private final byte[] readBuffer = new byte[SECTOR_SIZE];
|
||||
private final byte[] writeBuffer = new byte[SECTOR_SIZE];
|
||||
private int readPosition = 0;
|
||||
private int writePosition = 0;
|
||||
|
||||
|
||||
public SdController(int address) throws MemoryRangeException {
|
||||
super(address, address + CONTROLLER_SIZE - 1, "SDCONTROLLER");
|
||||
|
||||
sdImageFile = new File("sd.img");
|
||||
if (!sdImageFile.exists()) {
|
||||
sdImageFile = null;
|
||||
logger.log(Level.INFO, "Could not find SD card image 'sd.img'");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void write(int address, int data) throws MemoryAccessException {
|
||||
switch (address) {
|
||||
case 0:
|
||||
writeData(data);
|
||||
return;
|
||||
case 1:
|
||||
writeCommand(data);
|
||||
return;
|
||||
case 2:
|
||||
this.lba0 = data;
|
||||
return;
|
||||
case 3:
|
||||
this.lba1 = data;
|
||||
return;
|
||||
case 4:
|
||||
this.lba2 = data;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read(int address, boolean cpuAccess) throws MemoryAccessException {
|
||||
switch (address) {
|
||||
case 0:
|
||||
return readData();
|
||||
case 1:
|
||||
return readStatus();
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
private void computePosition() {
|
||||
this.position = lba0 + (lba1 << 8) + (lba2 << 16);
|
||||
// each sector is 512 bytes, so multiply accordingly
|
||||
this.position <<= 9;
|
||||
}
|
||||
|
||||
private void prepareRead() {
|
||||
this.status = Status.READ;
|
||||
this.readPosition = 0;
|
||||
computePosition();
|
||||
|
||||
if (sdImageFile != null) {
|
||||
try {
|
||||
FileInputStream fis = new FileInputStream(sdImageFile);
|
||||
long bytesSkipped = fis.skip(this.position);
|
||||
if (bytesSkipped < this.position) {
|
||||
logger.log(Level.WARNING, "Failed to seek to position " + this.position);
|
||||
}
|
||||
int read = fis.read(readBuffer);
|
||||
if (read < SECTOR_SIZE) {
|
||||
logger.log(Level.WARNING, "not enough data to fill read buffer from SD image file");
|
||||
}
|
||||
fis.close();
|
||||
} catch (IOException ex) {
|
||||
logger.log(Level.WARNING, "could not fill read buffer from SD image file", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void prepareWrite() {
|
||||
this.status = Status.WRITE;
|
||||
this.writePosition = 0;
|
||||
computePosition();
|
||||
}
|
||||
|
||||
|
||||
private int readData() {
|
||||
if (status != Status.READ) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int data = readBuffer[readPosition++];
|
||||
|
||||
if (readPosition >= SECTOR_SIZE) {
|
||||
this.status = Status.IDLE;
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
private void writeData(int data) {
|
||||
if (status != Status.WRITE) {
|
||||
return;
|
||||
}
|
||||
|
||||
writeBuffer[writePosition++] = (byte) data;
|
||||
|
||||
if (writePosition >= SECTOR_SIZE) {
|
||||
if (sdImageFile != null) {
|
||||
try {
|
||||
RandomAccessFile raf = new RandomAccessFile(sdImageFile, "rw");
|
||||
raf.skipBytes(this.position);
|
||||
raf.write(writeBuffer, 0, writeBuffer.length);
|
||||
raf.close();
|
||||
} catch (IOException ex) {
|
||||
logger.log(Level.WARNING, "could not write data back to SD image file!", ex);
|
||||
}
|
||||
}
|
||||
|
||||
this.status = Status.IDLE;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private int readStatus() {
|
||||
switch (this.status) {
|
||||
case IDLE:
|
||||
return 128;
|
||||
case READ:
|
||||
return 224;
|
||||
case WRITE:
|
||||
return 160;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
private void writeCommand(int data) {
|
||||
switch (data) {
|
||||
case 0:
|
||||
prepareRead();
|
||||
return;
|
||||
case 1:
|
||||
prepareWrite();
|
||||
return;
|
||||
default:
|
||||
this.status = Status.IDLE;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getName() + "@" + String.format("%04X", this.getMemoryRange().startAddress);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
/*
|
||||
* Copyright (c) 2008-2025 Seth J. Morabito <web@loomcom.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.loomcom.symon.devices;
|
||||
|
||||
import com.loomcom.symon.exceptions.MemoryAccessException;
|
||||
import com.loomcom.symon.exceptions.MemoryRangeException;
|
||||
import com.loomcom.symon.util.Utils;
|
||||
|
||||
/**
|
||||
* Skeleton for future implementation of a MOS 6522 VIA.
|
||||
*/
|
||||
public class Via6522 extends Pia {
|
||||
public static final int VIA_SIZE = 16;
|
||||
|
||||
|
||||
static final int IOB_REG = 0; // Output Register B / Input Register B
|
||||
static final int IOA_REG = 1; // Output Register A / Input Register A
|
||||
static final int DDRB_REG = 2; // Data Direction Register B
|
||||
static final int DDRA_REG = 3; // Data Direction Register A
|
||||
static final int T1CL_REG = 4; // T1 Low-Order Counter / Latches
|
||||
static final int T1CH_REG = 5; // T1 High-Order Counter
|
||||
static final int T1LL_REG = 6; // T1 Low-Order Latches
|
||||
static final int T1LH_REG = 7; // T1 High-Order Latches
|
||||
static final int T2CL_REG = 8; // T2 Low-Order Counter / Latches
|
||||
static final int T2CH_REG = 9; // T2 High-Order Counter
|
||||
static final int SR_REG = 10; // Shift Register
|
||||
static final int AuxC_REG = 11; // Auxiliary Control Register
|
||||
static final int PerC_REG = 12; // Peripheral Control Register
|
||||
static final int IntF_REG = 13; // Interrupt Flag Register
|
||||
static final int IntE_REG = 14; // Interrupt Enable Register
|
||||
static final int IOANH_REG = 15; // Same as Register 1 (IOA), but no Handshake
|
||||
|
||||
private int outputRegisterB, inputRegisterB;
|
||||
private int outputRegisterA, inputRegisterA;
|
||||
private int dataDirectionB, dataDirectionA;
|
||||
|
||||
public Via6522(int address) throws MemoryRangeException {
|
||||
super(address, address + VIA_SIZE - 1, "MOS 6522 VIA");
|
||||
outputRegisterA = outputRegisterB = 0;
|
||||
dataDirectionA = dataDirectionB = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(int address, int data) throws MemoryAccessException {
|
||||
switch (address) {
|
||||
case IOB_REG -> outputRegisterB = data & 0xFF;
|
||||
case IOA_REG -> outputRegisterA = data & 0xFF;
|
||||
case DDRB_REG -> dataDirectionB = data & 0xFF;
|
||||
case DDRA_REG -> dataDirectionA = data & 0xFF;
|
||||
case IOANH_REG -> outputRegisterA = data & 0xFF;
|
||||
default -> throw new MemoryAccessException("No Register or Not Implemented!");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read(int address, boolean cpuAccess) throws MemoryAccessException {
|
||||
return switch (address) {
|
||||
case IOB_REG -> pbRead();
|
||||
case IOA_REG -> paRead();
|
||||
case DDRB_REG -> dataDirectionB;
|
||||
case DDRA_REG -> dataDirectionA;
|
||||
case IOANH_REG -> paRead();
|
||||
default -> throw new MemoryAccessException("No Register or Not Implemented!");
|
||||
};
|
||||
}
|
||||
|
||||
public void setInputRegisterB(int data) {
|
||||
inputRegisterB = data & 0xFF;
|
||||
}
|
||||
|
||||
public void setInputRegisterA(int data) {
|
||||
inputRegisterA = data & 0xFF;
|
||||
}
|
||||
|
||||
|
||||
public String getPBStatus() {
|
||||
return "%" + Utils.byteToBin(pbRead());
|
||||
}
|
||||
|
||||
public String getPAStatus() {
|
||||
return "%" + Utils.byteToBin(paRead());
|
||||
}
|
||||
|
||||
private int pbRead() {
|
||||
// Return bits of output register where DDRB is 1 and input register where DDRB is 0
|
||||
return (outputRegisterB & dataDirectionB) | (inputRegisterB & ~dataDirectionB);
|
||||
}
|
||||
|
||||
private int paRead() {
|
||||
// Return bits of output register where DDRB is 1 and input register where DDRB is 0
|
||||
return (outputRegisterA & dataDirectionA) | (inputRegisterA & ~dataDirectionA);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2008-2013 Seth J. Morabito <sethm@loomcom.com>
|
||||
* Copyright (c) 2008-2025 Seth J. Morabito <web@loomcom.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2008-2013 Seth J. Morabito <sethm@loomcom.com>
|
||||
* Copyright (c) 2008-2025 Seth J. Morabito <web@loomcom.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2008-2013 Seth J. Morabito <sethm@loomcom.com>
|
||||
* Copyright (c) 2008-2025 Seth J. Morabito <web@loomcom.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2008-2013 Seth J. Morabito <sethm@loomcom.com>
|
||||
* Copyright (c) 2008-2025 Seth J. Morabito <web@loomcom.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
@@ -31,7 +31,4 @@ public class SymonException extends Exception {
|
||||
public SymonException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
public SymonException() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2011 Graham Edgecombe.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to
|
||||
* deal in the Software without restriction, including without limitation the
|
||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
* sell copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.loomcom.symon.jterminal;
|
||||
|
||||
/**
|
||||
* A {@link TerminalModel} which implements some common behaviour.
|
||||
* @author Graham Edgecombe
|
||||
*/
|
||||
public abstract class AbstractTerminalModel implements TerminalModel {
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
int rows = getRows(), columns = getColumns();
|
||||
for (int column = 0; column < columns; column++) {
|
||||
for (int row = 0; row < rows; row++) {
|
||||
setCell(column, row, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void moveCursorBack(int n) {
|
||||
if (n < 0) {
|
||||
throw new IllegalArgumentException("n must be positive");
|
||||
}
|
||||
int cursorColumn = getCursorColumn() - n;
|
||||
if (cursorColumn < 0) {
|
||||
cursorColumn = 0;
|
||||
}
|
||||
setCursorColumn(cursorColumn);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void moveCursorForward(int n) {
|
||||
if (n < 0) {
|
||||
throw new IllegalArgumentException("n must be positive");
|
||||
}
|
||||
int columns = getColumns();
|
||||
int cursorColumn = getCursorColumn() + n;
|
||||
if (cursorColumn >= columns) {
|
||||
cursorColumn = columns - 1;
|
||||
}
|
||||
setCursorColumn(cursorColumn);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void moveCursorDown(int n) {
|
||||
if (n < 0) {
|
||||
throw new IllegalArgumentException("n must be positive");
|
||||
}
|
||||
int bufferSize = getBufferSize();
|
||||
int cursorRow = getCursorRow() + n;
|
||||
if (cursorRow >= bufferSize) {
|
||||
cursorRow = bufferSize - 1;
|
||||
}
|
||||
setCursorRow(cursorRow);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void moveCursorUp(int n) {
|
||||
if (n < 0) {
|
||||
throw new IllegalArgumentException("n must be positive");
|
||||
}
|
||||
int cursorRow = getCursorRow() - n;
|
||||
if (cursorRow < 0) {
|
||||
cursorRow = 0;
|
||||
}
|
||||
setCursorRow(cursorRow);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,178 @@
|
||||
/*
|
||||
* Copyright (c) 2008-2025 Seth J. Morabito <web@loomcom.com>
|
||||
* Portions Copyright (c) 2009-2011 Graham Edgecombe
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.loomcom.symon.jterminal;
|
||||
|
||||
import com.loomcom.symon.jterminal.vt100.Vt100TerminalModel;
|
||||
|
||||
import java.awt.*;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JScrollBar;
|
||||
|
||||
/**
|
||||
* Swing terminal emulation component
|
||||
* @author Seth J. Morabito
|
||||
*
|
||||
*/
|
||||
public class JTerminal extends JComponent {
|
||||
|
||||
private static final long serialVersionUID = 2871625194146986567L;
|
||||
|
||||
private int borderWidth = 0;
|
||||
|
||||
private JScrollBar scrollBar;
|
||||
|
||||
/**
|
||||
* The terminal emulation model
|
||||
*/
|
||||
private TerminalModel model;
|
||||
|
||||
/**
|
||||
* The font this terminal uses
|
||||
*/
|
||||
private Font font;
|
||||
|
||||
/**
|
||||
* The cell width in pixels
|
||||
*/
|
||||
private int cellWidth;
|
||||
|
||||
/**
|
||||
* The cell height in pixels
|
||||
*/
|
||||
private int cellHeight;
|
||||
|
||||
/**
|
||||
* Max descender for font
|
||||
*/
|
||||
private int maxDescender;
|
||||
|
||||
public JTerminal(Font font) {
|
||||
this(new Vt100TerminalModel(), font);
|
||||
}
|
||||
|
||||
public JTerminal(TerminalModel model, Font font) {
|
||||
setModel(model);
|
||||
setFont(font);
|
||||
init();
|
||||
}
|
||||
|
||||
public void setBorderWidth(int borderWidth) {
|
||||
this.borderWidth = borderWidth;
|
||||
revalidate();
|
||||
}
|
||||
|
||||
public void setFont(Font font) {
|
||||
this.font = font;
|
||||
setCellWidthAndHeight(font);
|
||||
revalidate();
|
||||
}
|
||||
|
||||
public Font getFont() {
|
||||
return font;
|
||||
}
|
||||
|
||||
public void setModel(TerminalModel model) {
|
||||
if (model == null) {
|
||||
throw new NullPointerException("model");
|
||||
}
|
||||
this.model = model;
|
||||
}
|
||||
|
||||
public TerminalModel getModel() {
|
||||
return model;
|
||||
}
|
||||
|
||||
public void print(String str) {
|
||||
model.print(str);
|
||||
}
|
||||
|
||||
public Dimension getMinimumSize() {
|
||||
return new Dimension(model.getColumns() * cellWidth + borderWidth * 2,
|
||||
model.getRows() * cellHeight + borderWidth * 2);
|
||||
}
|
||||
|
||||
public Dimension getMaximumSize() {
|
||||
return getMinimumSize();
|
||||
}
|
||||
|
||||
public Dimension getPreferredSize() {
|
||||
return getMinimumSize();
|
||||
}
|
||||
|
||||
public void paint(Graphics g) {
|
||||
g.setFont(font);
|
||||
|
||||
int width = model.getColumns();
|
||||
int height = model.getBufferSize();
|
||||
|
||||
g.setColor(model.getDefaultBackgroundColor());
|
||||
g.fillRect(0, 0, width * cellWidth + borderWidth * 2, height * cellHeight + borderWidth * 2);
|
||||
|
||||
int start = scrollBar == null ? 0 : scrollBar.getValue();
|
||||
for (int y = start; y < height; y++) {
|
||||
for (int x = 0; x < width; x++) {
|
||||
TerminalCell cell = model.getCell(x, y);
|
||||
boolean cursorHere = (model.getCursorRow() == y) && (model.getCursorColumn() == x);
|
||||
|
||||
if ((cursorHere) && (cell == null)) {
|
||||
cell = new TerminalCell(' ', model.getDefaultBackgroundColor(), model.getDefaultForegroundColor());
|
||||
}
|
||||
|
||||
if (cell != null) {
|
||||
int px = x * cellWidth + borderWidth;
|
||||
int py = (y - start) * cellHeight + borderWidth;
|
||||
|
||||
g.setColor(cursorHere ? cell.getForegroundColor() : cell.getBackgroundColor());
|
||||
g.fillRect(px, py, cellWidth, cellHeight);
|
||||
|
||||
g.setColor(cursorHere ? cell.getBackgroundColor() : cell.getForegroundColor());
|
||||
g.drawChars(new char[] { cell.getCharacter() }, 0, 1, px, py + cellHeight - maxDescender);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void init() {
|
||||
setLayout(new BorderLayout(0, 0));
|
||||
|
||||
int rows = model.getRows();
|
||||
int bufferSize = model.getBufferSize();
|
||||
|
||||
if (bufferSize > rows) {
|
||||
scrollBar = new JScrollBar(Adjustable.VERTICAL, 0, rows, 0, bufferSize + 1);
|
||||
scrollBar.addAdjustmentListener(evt -> repaint());
|
||||
add("After", scrollBar);
|
||||
}
|
||||
|
||||
repaint();
|
||||
}
|
||||
|
||||
private void setCellWidthAndHeight(Font font) {
|
||||
FontMetrics metrics = getFontMetrics(font);
|
||||
cellWidth = metrics.charWidth('W');
|
||||
cellHeight = metrics.getHeight();
|
||||
maxDescender = metrics.getMaxDescent();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2011 Graham Edgecombe.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to
|
||||
* deal in the Software without restriction, including without limitation the
|
||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
* sell copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.loomcom.symon.jterminal;
|
||||
|
||||
import java.awt.Color;
|
||||
|
||||
/**
|
||||
* Represents a single terminal cell which contains a character, background
|
||||
* color and foreground color.
|
||||
* @author Graham Edgecombe
|
||||
*/
|
||||
public class TerminalCell {
|
||||
|
||||
/**
|
||||
* The character.
|
||||
*/
|
||||
private final char character;
|
||||
|
||||
/**
|
||||
* The background color.
|
||||
*/
|
||||
private final Color backgroundColor;
|
||||
|
||||
/**
|
||||
* The foreground color.
|
||||
*/
|
||||
private final Color foregroundColor;
|
||||
|
||||
/**
|
||||
* Creates a terminal cell with the specified character, background color
|
||||
* and foreground color.
|
||||
* @param character The character.
|
||||
* @param backgroundColor The background color.
|
||||
* @param foregroundColor The foreground color.
|
||||
* @throws NullPointerException if the background or foreground color(s)
|
||||
* are {@code null}.
|
||||
*/
|
||||
public TerminalCell(char character, Color backgroundColor, Color foregroundColor) {
|
||||
if (backgroundColor == null) {
|
||||
throw new NullPointerException("backgroundColor");
|
||||
}
|
||||
if (foregroundColor == null) {
|
||||
throw new NullPointerException("foregroundColor");
|
||||
}
|
||||
|
||||
this.character = character;
|
||||
this.backgroundColor = backgroundColor;
|
||||
this.foregroundColor = foregroundColor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the character.
|
||||
* @return The character.
|
||||
*/
|
||||
public char getCharacter() {
|
||||
return character;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the background color.
|
||||
* @return The background color.
|
||||
*/
|
||||
public Color getBackgroundColor() {
|
||||
return backgroundColor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the foreground color.
|
||||
* @return The foreground color.
|
||||
*/
|
||||
public Color getForegroundColor() {
|
||||
return foregroundColor;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,161 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2011 Graham Edgecombe.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to
|
||||
* deal in the Software without restriction, including without limitation the
|
||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
* sell copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.loomcom.symon.jterminal;
|
||||
|
||||
import java.awt.Color;
|
||||
|
||||
import com.loomcom.symon.jterminal.bell.BellStrategy;
|
||||
|
||||
/**
|
||||
* Model for terminals - defines methods for getting/setting cells, printing
|
||||
* text to a terminal and getting the size of the terminal and buffer.
|
||||
*/
|
||||
public interface TerminalModel {
|
||||
|
||||
/**
|
||||
* Sets the bell strategy.
|
||||
* @param strategy The bell strategy.
|
||||
* @throws NullPointerException if the strategy is {@code null}.
|
||||
*/
|
||||
void setBellStrategy(BellStrategy strategy);
|
||||
|
||||
/**
|
||||
* Clears the terminal.
|
||||
*/
|
||||
void clear();
|
||||
|
||||
/**
|
||||
* Moves the cursor back n characters.
|
||||
* @param n The number of characters.
|
||||
* @throws IllegalArgumentException if n is not positive.
|
||||
*/
|
||||
void moveCursorBack(int n);
|
||||
|
||||
/**
|
||||
* Moves the cursor forward n characters.
|
||||
* @param n The number of characters.
|
||||
* @throws IllegalArgumentException if n is not positive.
|
||||
*/
|
||||
void moveCursorForward(int n);
|
||||
|
||||
/**
|
||||
* Moves the cursor down n characters.
|
||||
* @param n The number of characters.
|
||||
* @throws IllegalArgumentException if n is not positive.
|
||||
*/
|
||||
void moveCursorDown(int n);
|
||||
|
||||
/**
|
||||
* Moves the cursor up n characters.
|
||||
* @param n The number of characters.
|
||||
* @throws IllegalArgumentException if n is not positive.
|
||||
*/
|
||||
void moveCursorUp(int n);
|
||||
|
||||
/**
|
||||
* Sets a cell.
|
||||
* @param column The column.
|
||||
* @param row The row.
|
||||
* @param cell The cell.
|
||||
* @throws IndexOutOfBoundsException if the column and/or row number(s) are
|
||||
* out of bounds.
|
||||
*/
|
||||
void setCell(int column, int row, TerminalCell cell);
|
||||
|
||||
/**
|
||||
* Gets a cell.
|
||||
* @param column The column.
|
||||
* @param row The row.
|
||||
* @return The cell.
|
||||
* @throws IndexOutOfBoundsException if the column and/or row number(s) are
|
||||
* out of bounds.
|
||||
*/
|
||||
TerminalCell getCell(int column, int row);
|
||||
|
||||
/**
|
||||
* Prints the specified string to the terminal at the cursor position,
|
||||
* interpreting any escape sequences/special ASCII codes the model may
|
||||
* support. Lines will be wrapped if necessary.
|
||||
* @param str The string to print.
|
||||
* @throws NullPointerException if the string is {@code null}.
|
||||
*/
|
||||
void print(String str);
|
||||
|
||||
/**
|
||||
* Gets the number of columns.
|
||||
* @return The number of columns.
|
||||
*/
|
||||
int getColumns();
|
||||
|
||||
/**
|
||||
* Gets the number of rows.
|
||||
* @return The number of rows.
|
||||
*/
|
||||
int getRows();
|
||||
|
||||
/**
|
||||
* Gets the buffer size.
|
||||
* @return The buffer size.
|
||||
*/
|
||||
int getBufferSize();
|
||||
|
||||
/**
|
||||
* Gets the cursor row.
|
||||
* @return The cursor row.
|
||||
*/
|
||||
int getCursorRow();
|
||||
|
||||
/**
|
||||
* Sets the cursor row.
|
||||
* @param row The cursor row.
|
||||
* @throws IllegalArgumentException if the row is out of the valid range.
|
||||
*/
|
||||
void setCursorRow(int row);
|
||||
|
||||
/**
|
||||
* Gets the cursor column.
|
||||
* @return The cursor column.
|
||||
*/
|
||||
int getCursorColumn();
|
||||
|
||||
/**
|
||||
* Sets the cursor column.
|
||||
* @param column The cursor column.
|
||||
* @throws IllegalArgumentException if the column is out of the valid range.
|
||||
*/
|
||||
void setCursorColumn(int column);
|
||||
|
||||
/**
|
||||
* Gets the default background color.
|
||||
* @return The default background color.
|
||||
*/
|
||||
Color getDefaultBackgroundColor();
|
||||
|
||||
/**
|
||||
* Gets the default foreground color.
|
||||
* @return The default foreground color.
|
||||
*/
|
||||
Color getDefaultForegroundColor();
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2011 Graham Edgecombe.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to
|
||||
* deal in the Software without restriction, including without limitation the
|
||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
* sell copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.loomcom.symon.jterminal.bell;
|
||||
|
||||
import java.awt.Toolkit;
|
||||
|
||||
/**
|
||||
* A {@link BellStrategy} which calls {@link Toolkit#beep()}.
|
||||
* @author Graham Edgecombe
|
||||
*/
|
||||
public class BeepBellStrategy implements BellStrategy {
|
||||
|
||||
@Override
|
||||
public void soundBell() {
|
||||
Toolkit.getDefaultToolkit().beep();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2011 Graham Edgecombe.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to
|
||||
* deal in the Software without restriction, including without limitation the
|
||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
* sell copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.loomcom.symon.jterminal.bell;
|
||||
|
||||
/**
|
||||
* A 'strategy' used to sound the bell (US-ASCII character {@code 7}).
|
||||
* @author Graham Edgecombe
|
||||
*/
|
||||
public interface BellStrategy {
|
||||
|
||||
/**
|
||||
* Sounds the bell.
|
||||
*/
|
||||
void soundBell();
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2011 Graham Edgecombe.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to
|
||||
* deal in the Software without restriction, including without limitation the
|
||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
* sell copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.loomcom.symon.jterminal.bell;
|
||||
|
||||
/**
|
||||
* A {@link BellStrategy} which does nothing.
|
||||
* @author Graham Edgecombe
|
||||
*/
|
||||
public class NopBellStrategy implements BellStrategy {
|
||||
|
||||
@Override
|
||||
public void soundBell() {
|
||||
/* ignore */
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2011 Graham Edgecombe.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to
|
||||
* deal in the Software without restriction, including without limitation the
|
||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
* sell copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.loomcom.symon.jterminal.vt100;
|
||||
|
||||
/**
|
||||
* Represents an ANSI control sequence.
|
||||
* @author Graham Edgecombe
|
||||
*/
|
||||
public class AnsiControlSequence {
|
||||
|
||||
/**
|
||||
* The command character.
|
||||
*/
|
||||
private final char command;
|
||||
|
||||
/**
|
||||
* The parameters.
|
||||
*/
|
||||
private final String[] parameters;
|
||||
|
||||
/**
|
||||
* Creates an ANSI control sequence with the specified command and
|
||||
* parameters.
|
||||
* @param command The command character.
|
||||
* @param parameters The parameters array.
|
||||
* @throws NullPointerException if the parameters array is {@code null}.
|
||||
*/
|
||||
public AnsiControlSequence(char command, String[] parameters) {
|
||||
if (parameters == null) {
|
||||
throw new NullPointerException("parameters");
|
||||
}
|
||||
this.command = command;
|
||||
if (parameters.length == 1 && parameters[0].isEmpty()) {
|
||||
this.parameters = new String[0];
|
||||
} else {
|
||||
this.parameters = parameters.clone();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the command character.
|
||||
* @return The command character.
|
||||
*/
|
||||
public char getCommand() {
|
||||
return command;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the parameters array.
|
||||
* @return The parameters array.
|
||||
*/
|
||||
public String[] getParameters() {
|
||||
return parameters;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2011 Graham Edgecombe.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to
|
||||
* deal in the Software without restriction, including without limitation the
|
||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
* sell copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.loomcom.symon.jterminal.vt100;
|
||||
|
||||
/**
|
||||
* An interface which classes may use to listen to events from a
|
||||
* {@link AnsiControlSequenceParser}.
|
||||
*/
|
||||
public interface AnsiControlSequenceListener {
|
||||
|
||||
/**
|
||||
* Called when a control sequence has been parsed.
|
||||
* @param seq The control sequence.
|
||||
*/
|
||||
void parsedControlSequence(AnsiControlSequence seq);
|
||||
|
||||
/**
|
||||
* Called when a string has been parsed.
|
||||
* @param str The string.
|
||||
*/
|
||||
void parsedString(String str);
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,153 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2011 Graham Edgecombe.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to
|
||||
* deal in the Software without restriction, including without limitation the
|
||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
* sell copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.loomcom.symon.jterminal.vt100;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.io.StringReader;
|
||||
|
||||
/**
|
||||
* A class which parses {@link AnsiControlSequence}s from {@link String}(s).
|
||||
* @author Graham Edgecombe
|
||||
*/
|
||||
public class AnsiControlSequenceParser {
|
||||
|
||||
/**
|
||||
* The multibyte control sequence introducer.
|
||||
*/
|
||||
private static final char[] MULTI_CSI = new char[] { 27, '[' };
|
||||
|
||||
/**
|
||||
* The single-byte control sequence introducer.
|
||||
*/
|
||||
private static final char SINGLE_CSI = 155;
|
||||
|
||||
/**
|
||||
* The buffer of data from the last call to "parse()". This is
|
||||
* populated with data if an escape sequence is not complete.
|
||||
*/
|
||||
private StringBuilder buffer = new StringBuilder();
|
||||
|
||||
/**
|
||||
* The ANSI control sequence listener.
|
||||
*/
|
||||
private final AnsiControlSequenceListener listener;
|
||||
|
||||
/**
|
||||
* Creates the ANSI control sequence parser.
|
||||
* @param listener The listener.
|
||||
*/
|
||||
public AnsiControlSequenceParser(AnsiControlSequenceListener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the specified string.
|
||||
* @param str The string to parse.
|
||||
*/
|
||||
public void parse(String str) {
|
||||
if (buffer.length() > 0) {
|
||||
str = buffer.toString().concat(str);
|
||||
buffer = new StringBuilder();
|
||||
}
|
||||
try {
|
||||
try (Reader reader = new StringReader(str)) {
|
||||
parse(reader);
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
/* ignore */
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses characters from the specified character reader.
|
||||
* @param reader The character reader.
|
||||
* @throws IOException if an I/O error occurs.
|
||||
*/
|
||||
private void parse(Reader reader) throws IOException {
|
||||
StringBuilder text = new StringBuilder();
|
||||
int character;
|
||||
while ((character = reader.read()) != -1) {
|
||||
boolean introducedControlSequence = false;
|
||||
if (character == SINGLE_CSI) {
|
||||
introducedControlSequence = true;
|
||||
} else if (character == MULTI_CSI[0]) {
|
||||
int nextCharacter = reader.read();
|
||||
if (nextCharacter == -1) {
|
||||
buffer.append((char) character);
|
||||
break;
|
||||
} else if (nextCharacter == MULTI_CSI[1]) {
|
||||
introducedControlSequence = true;
|
||||
} else {
|
||||
text.append((char) character);
|
||||
text.append((char) nextCharacter);
|
||||
}
|
||||
} else {
|
||||
text.append((char) character);
|
||||
}
|
||||
|
||||
if (introducedControlSequence) {
|
||||
if (text.length() > 0) {
|
||||
listener.parsedString(text.toString());
|
||||
text = new StringBuilder();
|
||||
}
|
||||
parseControlSequence(reader);
|
||||
}
|
||||
}
|
||||
|
||||
if (text.length() > 0) {
|
||||
listener.parsedString(text.toString());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a control sequence.
|
||||
* @param reader The character reader.
|
||||
* @throws IOException if an I/O error occurs.
|
||||
*/
|
||||
private void parseControlSequence(Reader reader) throws IOException {
|
||||
boolean finishedSequence = false;
|
||||
StringBuilder parameters = new StringBuilder();
|
||||
int character;
|
||||
while ((character = reader.read()) != -1) {
|
||||
if ((character >= 'a' && character <= 'z') || (character >= 'A' && character <= 'Z')) {
|
||||
String[] array = parameters.toString().split(";");
|
||||
AnsiControlSequence seq = new AnsiControlSequence((char) character, array);
|
||||
listener.parsedControlSequence(seq);
|
||||
|
||||
finishedSequence = true;
|
||||
break;
|
||||
} else {
|
||||
parameters.append((char) character);
|
||||
}
|
||||
}
|
||||
if (!finishedSequence) {
|
||||
// not an ideal solution if they used the two byte CSI, but it's
|
||||
// easier and cleaner than keeping track of it
|
||||
buffer.append(SINGLE_CSI);
|
||||
buffer.append(parameters);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2011 Graham Edgecombe.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to
|
||||
* deal in the Software without restriction, including without limitation the
|
||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
* sell copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.loomcom.symon.jterminal.vt100;
|
||||
|
||||
import java.awt.Color;
|
||||
|
||||
/**
|
||||
* Contains colors used by the SGR ANSI escape sequence.
|
||||
* @author Graham Edgecombe
|
||||
*/
|
||||
final class SgrColor {
|
||||
|
||||
/**
|
||||
* An array of normal intensity colors.
|
||||
*/
|
||||
public static final Color[] COLOR_NORMAL = new Color[] {
|
||||
new Color(0, 0, 0),
|
||||
new Color(128, 0, 0),
|
||||
new Color(0, 128, 0),
|
||||
new Color(128, 128, 0),
|
||||
new Color(0, 0, 128),
|
||||
new Color(128, 0, 128),
|
||||
new Color(0, 128, 128),
|
||||
new Color(192, 192, 192)
|
||||
};
|
||||
|
||||
/**
|
||||
* An array of bright intensity colors.
|
||||
*/
|
||||
public static final Color[] COLOR_BRIGHT = new Color[] {
|
||||
new Color(128, 128, 128),
|
||||
new Color(255, 0, 0),
|
||||
new Color(0, 255, 0),
|
||||
new Color(255, 255, 0),
|
||||
new Color(0, 0, 255),
|
||||
new Color(0, 0, 255),
|
||||
new Color(255, 0, 255),
|
||||
new Color(0, 255, 255),
|
||||
new Color(255, 255, 255)
|
||||
};
|
||||
|
||||
/**
|
||||
* Default private constructor to prevent instantiation.
|
||||
*/
|
||||
private SgrColor() {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,490 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2011 Graham Edgecombe.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to
|
||||
* deal in the Software without restriction, including without limitation the
|
||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
* sell copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.loomcom.symon.jterminal.vt100;
|
||||
|
||||
import java.awt.Color;
|
||||
|
||||
import com.loomcom.symon.jterminal.AbstractTerminalModel;
|
||||
import com.loomcom.symon.jterminal.TerminalCell;
|
||||
import com.loomcom.symon.jterminal.TerminalModel;
|
||||
import com.loomcom.symon.jterminal.bell.BellStrategy;
|
||||
import com.loomcom.symon.jterminal.bell.NopBellStrategy;
|
||||
|
||||
/**
|
||||
* A VT100/ANSI-compatible terminal model.
|
||||
* @author Graham Edgecombe
|
||||
*/
|
||||
public class Vt100TerminalModel extends AbstractTerminalModel {
|
||||
|
||||
/**
|
||||
* A {@link AnsiControlSequenceListener} which modifies the
|
||||
* {@link TerminalModel} appropriately when an event happens.
|
||||
* @author Graham Edgecombe
|
||||
*/
|
||||
private class Vt100Listener implements AnsiControlSequenceListener {
|
||||
|
||||
/**
|
||||
* The saved cursor row.
|
||||
*/
|
||||
private int savedCursorRow = -1;
|
||||
|
||||
/**
|
||||
* The saved cursor column.
|
||||
*/
|
||||
private int savedCursorColumn = -1;
|
||||
|
||||
@Override
|
||||
public void parsedControlSequence(AnsiControlSequence seq) {
|
||||
char command = seq.getCommand();
|
||||
int n;
|
||||
String[] parameters = seq.getParameters();
|
||||
|
||||
switch (command) {
|
||||
case 'A':
|
||||
case 'B':
|
||||
case 'C':
|
||||
case 'D':
|
||||
n = 1;
|
||||
if (parameters.length == 1) {
|
||||
n = Integer.parseInt(parameters[0]);
|
||||
}
|
||||
if (command == 'A') {
|
||||
moveCursorUp(n);
|
||||
} else if (command == 'B') {
|
||||
moveCursorDown(n);
|
||||
} else if (command == 'C') {
|
||||
moveCursorForward(n);
|
||||
} else {
|
||||
moveCursorBack(n);
|
||||
}
|
||||
break;
|
||||
case 'E':
|
||||
case 'F':
|
||||
n = 1;
|
||||
if (parameters.length == 1) {
|
||||
n = Integer.parseInt(parameters[0]);
|
||||
}
|
||||
if (command == 'E') {
|
||||
moveCursorDown(n);
|
||||
} else {
|
||||
moveCursorUp(n);
|
||||
}
|
||||
setCursorColumn(0);
|
||||
break;
|
||||
case 'G':
|
||||
if (parameters.length == 1) {
|
||||
n = Integer.parseInt(parameters[0]);
|
||||
setCursorColumn(n - 1);
|
||||
}
|
||||
break;
|
||||
case 'H':
|
||||
case 'f':
|
||||
if (parameters.length == 2) {
|
||||
n = 1;
|
||||
int m = 1;
|
||||
if (parameters[0].length() > 0) {
|
||||
n = Integer.parseInt(parameters[0]);
|
||||
}
|
||||
if (parameters[1].length() > 0) {
|
||||
m = Integer.parseInt(parameters[1]);
|
||||
}
|
||||
setCursorRow(n - 1);
|
||||
setCursorColumn(m - 1);
|
||||
}
|
||||
break;
|
||||
case 'J':
|
||||
n = 0;
|
||||
if (parameters.length == 1) {
|
||||
n = Integer.parseInt(parameters[0]);
|
||||
}
|
||||
if (n == 0) {
|
||||
int row = cursorRow;
|
||||
int column = cursorColumn;
|
||||
while(row < rows) {
|
||||
while(column < columns) {
|
||||
cells[row][column] = null;
|
||||
column++;
|
||||
}
|
||||
column = 0;
|
||||
row++;
|
||||
}
|
||||
} else if (n == 1) {
|
||||
int row = cursorRow;
|
||||
int column = cursorColumn;
|
||||
while(row >= 0) {
|
||||
while(column >= 0) {
|
||||
cells[row][column] = null;
|
||||
column--;
|
||||
}
|
||||
column = columns - 1;
|
||||
row--;
|
||||
}
|
||||
} else if (n == 2) {
|
||||
clear();
|
||||
}
|
||||
break;
|
||||
case 'K':
|
||||
n = 0;
|
||||
if (parameters.length == 1) {
|
||||
n = Integer.parseInt(parameters[0]);
|
||||
}
|
||||
if (n == 0) {
|
||||
for (int row = cursorRow; row < rows; row++) {
|
||||
cells[row][cursorColumn] = null;
|
||||
}
|
||||
} else if (n == 1) {
|
||||
for (int row = cursorRow; row >= 0; row--) {
|
||||
cells[row][cursorColumn] = null;
|
||||
}
|
||||
} else if (n == 2) {
|
||||
for (int column = 0; column < columns; column++) {
|
||||
cells[cursorRow][column] = null;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'm':
|
||||
if (parameters.length == 0) {
|
||||
parameters = new String[] { "0" };
|
||||
}
|
||||
for (String parameter : parameters) {
|
||||
if (parameter.equals("0")) {
|
||||
foregroundColor = DEFAULT_FOREGROUND_COLOR;
|
||||
backgroundColor = DEFAULT_BACKGROUND_COLOR;
|
||||
backgroundBold = DEFAULT_BACKGROUND_BOLD;
|
||||
foregroundBold = DEFAULT_FOREGROUND_BOLD;
|
||||
} else if (parameter.equals("2")) {
|
||||
backgroundBold = true;
|
||||
foregroundBold = true;
|
||||
} else if (parameter.equals("22")) {
|
||||
backgroundBold = false;
|
||||
foregroundBold = false;
|
||||
} else if ((parameter.startsWith("3") || parameter.startsWith("4")) && parameter.length() == 2) {
|
||||
int color = Integer.parseInt(parameter.substring(1));
|
||||
if (parameter.startsWith("3")) {
|
||||
foregroundColor = color;
|
||||
} else if (parameter.startsWith("4")) {
|
||||
backgroundColor = color;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'u':
|
||||
if (savedCursorColumn != -1 && savedCursorRow != -1) {
|
||||
cursorColumn = savedCursorColumn;
|
||||
cursorRow = savedCursorRow;
|
||||
}
|
||||
break;
|
||||
case 's':
|
||||
savedCursorColumn = cursorColumn;
|
||||
savedCursorRow = cursorRow;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void parsedString(String str) {
|
||||
for (char ch : str.toCharArray()) {
|
||||
switch (ch) {
|
||||
case '\0':
|
||||
continue;
|
||||
case '\r':
|
||||
cursorColumn = 0;
|
||||
continue;
|
||||
case '\n':
|
||||
cursorRow++;
|
||||
break;
|
||||
case '\t':
|
||||
while ((++cursorColumn % TAB_WIDTH) != 0);
|
||||
continue;
|
||||
case 8: // ASCII Backspace
|
||||
case 127: // ASCII Delete
|
||||
if (cursorColumn > 0) {
|
||||
cells[cursorRow][--cursorColumn] = null;
|
||||
}
|
||||
continue;
|
||||
case 7:
|
||||
bellStrategy.soundBell();
|
||||
continue;
|
||||
}
|
||||
|
||||
if (cursorColumn >= columns) {
|
||||
cursorColumn = 0;
|
||||
cursorRow++;
|
||||
}
|
||||
|
||||
if (cursorRow >= bufferSize) {
|
||||
for (int i = 1; i < bufferSize; i++) {
|
||||
System.arraycopy(cells[i], 0, cells[i - 1], 0, columns);
|
||||
}
|
||||
for (int i = 0; i < columns; i++) {
|
||||
cells[bufferSize - 1][i] = null;
|
||||
}
|
||||
cursorRow--;
|
||||
}
|
||||
|
||||
Color back = backgroundBold ? SgrColor.COLOR_BRIGHT[backgroundColor] : SgrColor.COLOR_NORMAL[backgroundColor];
|
||||
Color fore = foregroundBold ? SgrColor.COLOR_BRIGHT[foregroundColor] : SgrColor.COLOR_NORMAL[foregroundColor];
|
||||
if (ch != '\n') {
|
||||
cells[cursorRow][cursorColumn++] = new TerminalCell(ch, back, fore);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* The default number of columns.
|
||||
*/
|
||||
private static final int DEFAULT_COLUMNS = 80;
|
||||
|
||||
/**
|
||||
* The default number of rows.
|
||||
*/
|
||||
private static final int DEFAULT_ROWS = 25;
|
||||
|
||||
/**
|
||||
* The tab width in characters.
|
||||
*/
|
||||
private static final int TAB_WIDTH = 8;
|
||||
|
||||
/**
|
||||
* The default foreground bold flag.
|
||||
*/
|
||||
private static final boolean DEFAULT_FOREGROUND_BOLD = false;
|
||||
|
||||
/**
|
||||
* The default background bold flag.
|
||||
*/
|
||||
private static final boolean DEFAULT_BACKGROUND_BOLD = false;
|
||||
|
||||
/**
|
||||
* The default foreground color.
|
||||
*/
|
||||
private static final int DEFAULT_FOREGROUND_COLOR = 7;
|
||||
|
||||
/**
|
||||
* The default background color.
|
||||
*/
|
||||
private static final int DEFAULT_BACKGROUND_COLOR = 0;
|
||||
|
||||
/**
|
||||
* The ANSI control sequence listener.
|
||||
*/
|
||||
private final AnsiControlSequenceListener listener = this.new Vt100Listener();
|
||||
|
||||
/**
|
||||
* The ANSI control sequence parser.
|
||||
*/
|
||||
private final AnsiControlSequenceParser parser = new AnsiControlSequenceParser(listener);
|
||||
|
||||
/**
|
||||
* The current bell strategy.
|
||||
*/
|
||||
private BellStrategy bellStrategy = new NopBellStrategy();
|
||||
|
||||
/**
|
||||
* The array of cells.
|
||||
*/
|
||||
private TerminalCell[][] cells;
|
||||
|
||||
/**
|
||||
* The number of columns.
|
||||
*/
|
||||
private int columns;
|
||||
|
||||
/**
|
||||
* The number of rows.
|
||||
*/
|
||||
private int rows;
|
||||
|
||||
/**
|
||||
* The buffer size.
|
||||
*/
|
||||
private int bufferSize;
|
||||
|
||||
/**
|
||||
* The cursor row.
|
||||
*/
|
||||
private int cursorRow = 0;
|
||||
|
||||
/**
|
||||
* The cursor column.
|
||||
*/
|
||||
private int cursorColumn = 0;
|
||||
|
||||
/**
|
||||
* The current foreground bold flag.
|
||||
*/
|
||||
private boolean foregroundBold = DEFAULT_FOREGROUND_BOLD;
|
||||
|
||||
/**
|
||||
* The current background bold flag.
|
||||
*/
|
||||
private boolean backgroundBold = DEFAULT_BACKGROUND_BOLD;
|
||||
|
||||
/**
|
||||
* The current foreground color.
|
||||
*/
|
||||
private int foregroundColor = DEFAULT_FOREGROUND_COLOR;
|
||||
|
||||
/**
|
||||
* The current background color.
|
||||
*/
|
||||
private int backgroundColor = DEFAULT_BACKGROUND_COLOR;
|
||||
|
||||
/**
|
||||
* Creates the terminal model with the default number of columns and rows,
|
||||
* and the default buffer size.
|
||||
*/
|
||||
public Vt100TerminalModel() {
|
||||
this(DEFAULT_COLUMNS, DEFAULT_ROWS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the terminal model with the specified number of columns and
|
||||
* rows. The buffer size is set to the number of rows.
|
||||
* @param columns The number of columns.
|
||||
* @param rows The number of rows.
|
||||
* @throws IllegalArgumentException if the number of rows or columns is
|
||||
* negative.
|
||||
*/
|
||||
public Vt100TerminalModel(int columns, int rows) {
|
||||
this(columns, rows, rows);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the terminal model with the specified number of columns and rows
|
||||
* and the specified buffer size.
|
||||
* @param columns The number of columns.
|
||||
* @param rows The number of rows.
|
||||
* @param bufferSize The buffer size.
|
||||
* @throws IllegalArgumentException if the number of rows or columns is
|
||||
* negative, or if the buffer size is less than the number of rows.
|
||||
*/
|
||||
public Vt100TerminalModel(int columns, int rows, int bufferSize) {
|
||||
if (columns < 0 || rows < 0 || bufferSize < 0) {
|
||||
throw new IllegalArgumentException("Zero or positive values only allowed for columns, rows and buffer size.");
|
||||
}
|
||||
if (bufferSize < rows) {
|
||||
throw new IllegalArgumentException("The buffer is too small");
|
||||
}
|
||||
this.columns = columns;
|
||||
this.rows = rows;
|
||||
this.bufferSize = bufferSize;
|
||||
init();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the terminal model.
|
||||
*/
|
||||
private void init() {
|
||||
cells = new TerminalCell[bufferSize][columns];
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCursorRow() {
|
||||
return cursorRow;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCursorRow(int row) {
|
||||
if (row < 0 || row >= bufferSize) {
|
||||
throw new IllegalArgumentException("row out of range");
|
||||
}
|
||||
cursorRow = row;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCursorColumn() {
|
||||
return cursorColumn;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCursorColumn(int column) {
|
||||
if (column < 0 || column >= columns) {
|
||||
throw new IllegalArgumentException("column out of range");
|
||||
}
|
||||
cursorColumn = column;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TerminalCell getCell(int column, int row) {
|
||||
if (column < 0 || row < 0 || column >= columns || row >= bufferSize) {
|
||||
throw new IndexOutOfBoundsException();
|
||||
}
|
||||
return cells[row][column];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCell(int column, int row, TerminalCell cell) {
|
||||
if (column < 0 || row < 0 || column >= columns || row >= bufferSize) {
|
||||
throw new IndexOutOfBoundsException();
|
||||
}
|
||||
cells[row][column] = cell;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void print(String str) {
|
||||
if (str == null) {
|
||||
throw new NullPointerException("str");
|
||||
}
|
||||
parser.parse(str);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getColumns() {
|
||||
return columns;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRows() {
|
||||
return rows;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBufferSize() {
|
||||
return bufferSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBellStrategy(BellStrategy strategy) {
|
||||
if (strategy == null) {
|
||||
throw new NullPointerException("strategy");
|
||||
}
|
||||
this.bellStrategy = strategy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Color getDefaultBackgroundColor() {
|
||||
final int bg = DEFAULT_BACKGROUND_COLOR;
|
||||
return DEFAULT_BACKGROUND_BOLD ? SgrColor.COLOR_BRIGHT[bg] : SgrColor.COLOR_NORMAL[bg];
|
||||
}
|
||||
|
||||
@Override
|
||||
public Color getDefaultForegroundColor() {
|
||||
final int fg = DEFAULT_FOREGROUND_COLOR;
|
||||
return DEFAULT_FOREGROUND_BOLD ? SgrColor.COLOR_BRIGHT[fg] : SgrColor.COLOR_NORMAL[fg];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,169 @@
|
||||
/*
|
||||
* Copyright (c) 2008-2025 Seth J. Morabito <web@loomcom.com>
|
||||
* Maik Merten <maikmerten@googlemail.com>
|
||||
* Chelsea Wilkinson <mail@chelseawilkinson.me>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.loomcom.symon.machines;
|
||||
|
||||
import com.loomcom.symon.Bus;
|
||||
import com.loomcom.symon.Cpu;
|
||||
import com.loomcom.symon.devices.*;
|
||||
import com.loomcom.symon.exceptions.MemoryRangeException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class BenEaterMachine implements Machine {
|
||||
|
||||
private final static Logger logger = LoggerFactory.getLogger(BenEaterMachine.class.getName());
|
||||
|
||||
// Constants used by the simulated system. These define the memory map.
|
||||
private static final int BUS_BOTTOM = 0x0000;
|
||||
private static final int BUS_TOP = 0xffff;
|
||||
|
||||
// 16K of RAM from $0000 - $3FFF
|
||||
private static final int MEMORY_BASE = 0x0000;
|
||||
private static final int MEMORY_SIZE = 0x4000;
|
||||
|
||||
// VIA at $6000-$600F
|
||||
private static final int PIA_BASE = 0x6000;
|
||||
|
||||
// ACIA at $5000-$5003
|
||||
private static final int ACIA_BASE = 0x5000;
|
||||
|
||||
// CRTC at $4000-$4001
|
||||
private static final int CRTC_BASE = 0x4000;
|
||||
|
||||
// 32KB ROM at $8000-$FFFF
|
||||
private static final int ROM_BASE = 0x8000;
|
||||
private static final int ROM_SIZE = 0x8000;
|
||||
|
||||
|
||||
// The simulated peripherals
|
||||
private final Bus bus;
|
||||
private final Cpu cpu;
|
||||
private final Acia acia;
|
||||
private final Pia pia;
|
||||
private final Crtc crtc;
|
||||
private final Memory ram;
|
||||
private Memory rom;
|
||||
|
||||
|
||||
public BenEaterMachine(String romFile) throws Exception {
|
||||
this.bus = new Bus(BUS_BOTTOM, BUS_TOP);
|
||||
this.cpu = new Cpu();
|
||||
this.ram = new Memory(MEMORY_BASE, MEMORY_BASE + MEMORY_SIZE - 1, false);
|
||||
this.pia = new Via6522(PIA_BASE);
|
||||
this.acia = new Acia6551(ACIA_BASE);
|
||||
this.crtc = new Crtc(CRTC_BASE, ram);
|
||||
|
||||
bus.addCpu(cpu);
|
||||
bus.addDevice(ram);
|
||||
bus.addDevice(pia);
|
||||
bus.addDevice(acia);
|
||||
bus.addDevice(crtc);
|
||||
|
||||
if (romFile != null) {
|
||||
File romImage = new File(romFile);
|
||||
if (romImage.canRead()) {
|
||||
logger.info("Loading ROM image from file {}", romImage);
|
||||
this.rom = Memory.makeROM(ROM_BASE, ROM_BASE + ROM_SIZE - 1, romImage);
|
||||
} else {
|
||||
logger.info("Default ROM file {} not found, loading empty R/W memory image.", romImage);
|
||||
this.rom = Memory.makeRAM(ROM_BASE, ROM_BASE + ROM_SIZE - 1);
|
||||
}
|
||||
} else {
|
||||
logger.info("No ROM file specified, loading empty R/W memory image.");
|
||||
this.rom = Memory.makeRAM(ROM_BASE, ROM_BASE + ROM_SIZE - 1);
|
||||
}
|
||||
|
||||
bus.addDevice(rom);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Bus getBus() {
|
||||
return bus;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Cpu getCpu() {
|
||||
return cpu;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Memory getRam() {
|
||||
return ram;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Acia getAcia() {
|
||||
return acia;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pia getPia() {
|
||||
return pia;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Crtc getCrtc() {
|
||||
return crtc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Memory getRom() {
|
||||
return rom;
|
||||
}
|
||||
|
||||
public void setRom(Memory rom) throws MemoryRangeException {
|
||||
if(this.rom != null) {
|
||||
bus.removeDevice(this.rom);
|
||||
}
|
||||
this.rom = rom;
|
||||
bus.addDevice(this.rom);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRomBase() {
|
||||
return ROM_BASE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRomSize() {
|
||||
return ROM_SIZE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMemorySize() {
|
||||
return MEMORY_SIZE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "benEater";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright (c) 2008-2025 Seth J. Morabito <web@loomcom.com>
|
||||
* Maik Merten <maikmerten@googlemail.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.loomcom.symon.machines;
|
||||
|
||||
import com.loomcom.symon.Bus;
|
||||
import com.loomcom.symon.Cpu;
|
||||
import com.loomcom.symon.devices.Acia;
|
||||
import com.loomcom.symon.devices.Crtc;
|
||||
import com.loomcom.symon.devices.Memory;
|
||||
import com.loomcom.symon.devices.Pia;
|
||||
import com.loomcom.symon.exceptions.MemoryRangeException;
|
||||
|
||||
|
||||
public interface Machine {
|
||||
|
||||
Bus getBus();
|
||||
|
||||
Cpu getCpu();
|
||||
|
||||
Memory getRam();
|
||||
|
||||
Acia getAcia();
|
||||
|
||||
Pia getPia();
|
||||
|
||||
Crtc getCrtc();
|
||||
|
||||
Memory getRom();
|
||||
|
||||
void setRom(Memory rom) throws MemoryRangeException;
|
||||
|
||||
int getRomBase();
|
||||
|
||||
int getRomSize();
|
||||
|
||||
int getMemorySize();
|
||||
|
||||
String getName();
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
package com.loomcom.symon.machines;
|
||||
|
||||
import com.loomcom.symon.Bus;
|
||||
import com.loomcom.symon.Cpu;
|
||||
import com.loomcom.symon.devices.*;
|
||||
import com.loomcom.symon.exceptions.MemoryRangeException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class MichaelBillingtonMachine implements Machine{
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(MichaelBillingtonMachine.class.getName());
|
||||
|
||||
// Constants used by the simulated system
|
||||
private static final int BUS_BOTTOM = 0x0000;
|
||||
private static final int BUS_TOP = 0xffff;
|
||||
|
||||
// 32k of ram, from $0000 to $7fff
|
||||
private static final int MEMORY_BASE = 0x0000;
|
||||
private static final int MEMORY_SIZE = 0x8000;
|
||||
|
||||
// VIA at $8000-$800f
|
||||
private static final int PIA_BASE = 0x8000;
|
||||
|
||||
// ACIA at $8400-$8403
|
||||
private static final int ACIA_BASE = 0x8400;
|
||||
|
||||
// 16k ROM from $c000 to $ffff
|
||||
private static final int ROM_BASE = 0xc000;
|
||||
private static final int ROM_SIZE = 0x4000;
|
||||
|
||||
private final Bus bus;
|
||||
private final Cpu cpu;
|
||||
private final Acia acia;
|
||||
private final Pia pia;
|
||||
private final Memory ram;
|
||||
private Memory rom;
|
||||
|
||||
public MichaelBillingtonMachine(String romFile) throws Exception {
|
||||
this.bus = new Bus(BUS_BOTTOM, BUS_TOP);
|
||||
this.cpu = new Cpu();
|
||||
this.ram = new Memory(MEMORY_BASE, MEMORY_BASE + MEMORY_SIZE - 1);
|
||||
this.pia = new Via6522(PIA_BASE);
|
||||
this.acia = new Acia6551(ACIA_BASE);
|
||||
|
||||
bus.addCpu(cpu);
|
||||
bus.addDevice(ram);
|
||||
bus.addDevice(pia);
|
||||
bus.addDevice(acia);
|
||||
|
||||
if (romFile != null) {
|
||||
File romImage = new File(romFile);
|
||||
if (romImage.canRead()) {
|
||||
logger.info("Loading ROM image from file {}", romImage);
|
||||
this.rom = Memory.makeROM(ROM_BASE, ROM_BASE + ROM_SIZE - 1, romImage);
|
||||
} else {
|
||||
logger.info("Default ROM file {} not found, loading empty R/W memory image.", romImage);
|
||||
this.rom = Memory.makeRAM(ROM_BASE, ROM_BASE + ROM_SIZE - 1);
|
||||
}
|
||||
} else {
|
||||
logger.info("No ROM file specified, loading empty R/W memory image.");
|
||||
this.rom = Memory.makeRAM(ROM_BASE, ROM_BASE + ROM_SIZE - 1);
|
||||
}
|
||||
|
||||
bus.addDevice(rom);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Bus getBus() {
|
||||
return bus;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Cpu getCpu() {
|
||||
return cpu;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Memory getRam() {
|
||||
return ram;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Acia getAcia() {
|
||||
return acia;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pia getPia() {
|
||||
return pia;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Crtc getCrtc() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Memory getRom() {
|
||||
return rom;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRom(Memory rom) throws MemoryRangeException {
|
||||
if (this.rom != null) {
|
||||
bus.removeDevice(this.rom);
|
||||
}
|
||||
this.rom = rom;
|
||||
bus.addDevice(this.rom);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRomBase() {
|
||||
return ROM_BASE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRomSize() {
|
||||
return ROM_SIZE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMemorySize() {
|
||||
return MEMORY_SIZE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "mike42";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,164 @@
|
||||
/*
|
||||
* Copyright (c) 2008-2025 Seth J. Morabito <web@loomcom.com>
|
||||
* Maik Merten <maikmerten@googlemail.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.loomcom.symon.machines;
|
||||
|
||||
import com.loomcom.symon.Bus;
|
||||
import com.loomcom.symon.Cpu;
|
||||
import com.loomcom.symon.devices.Acia;
|
||||
import com.loomcom.symon.devices.Acia6850;
|
||||
import com.loomcom.symon.devices.Crtc;
|
||||
import com.loomcom.symon.devices.Memory;
|
||||
import com.loomcom.symon.devices.Pia;
|
||||
import com.loomcom.symon.devices.SdController;
|
||||
import com.loomcom.symon.exceptions.MemoryRangeException;
|
||||
import java.io.File;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
|
||||
public class MulticompMachine implements Machine {
|
||||
|
||||
private final static Logger logger = Logger.getLogger(MulticompMachine.class.getName());
|
||||
|
||||
// Constants used by the simulated system. These define the memory map.
|
||||
private static final int BUS_BOTTOM = 0x0000;
|
||||
private static final int BUS_TOP = 0xffff;
|
||||
|
||||
// 56K of RAM from $0000 - $DFFF
|
||||
private static final int MEMORY_BASE = 0x0000;
|
||||
private static final int MEMORY_SIZE = 0xE000;
|
||||
|
||||
// ACIA at $FFD0-$FFD1
|
||||
private static final int ACIA_BASE = 0xFFD0;
|
||||
|
||||
// SD controller at $FFD8-$FFDF
|
||||
private static final int SD_BASE = 0xFFD8;
|
||||
|
||||
// 8KB ROM at $E000-$FFFF
|
||||
private static final int ROM_BASE = 0xE000;
|
||||
private static final int ROM_SIZE = 0x2000;
|
||||
|
||||
|
||||
// The simulated peripherals
|
||||
private final Bus bus;
|
||||
private final Cpu cpu;
|
||||
private final Acia acia;
|
||||
private final Memory ram;
|
||||
private Memory rom;
|
||||
|
||||
|
||||
public MulticompMachine(String romFile) throws Exception {
|
||||
this.bus = new Bus(BUS_BOTTOM, BUS_TOP);
|
||||
this.cpu = new Cpu();
|
||||
this.ram = new Memory(MEMORY_BASE, MEMORY_BASE + MEMORY_SIZE - 1, false);
|
||||
this.acia = new Acia6850(ACIA_BASE);
|
||||
this.acia.setBaudRate(0);
|
||||
|
||||
bus.addCpu(cpu);
|
||||
bus.addDevice(ram);
|
||||
bus.addDevice(acia, 1);
|
||||
bus.addDevice(new SdController(SD_BASE), 1);
|
||||
|
||||
if (romFile != null) {
|
||||
File romImage = new File("rom.bin");
|
||||
if (romImage.canRead()) {
|
||||
logger.info("Loading ROM image from file " + romImage);
|
||||
this.rom = Memory.makeROM(ROM_BASE, ROM_BASE + ROM_SIZE - 1, romImage);
|
||||
} else {
|
||||
logger.info("Default ROM file " + romImage +
|
||||
" not found, loading empty R/W memory image.");
|
||||
this.rom = Memory.makeRAM(ROM_BASE, ROM_BASE + ROM_SIZE - 1);
|
||||
}
|
||||
} else {
|
||||
logger.info("No ROM file specified, loading empty R/W memory image.");
|
||||
this.rom = Memory.makeRAM(ROM_BASE, ROM_BASE + ROM_SIZE - 1);
|
||||
}
|
||||
|
||||
bus.addDevice(rom);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Bus getBus() {
|
||||
return bus;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Cpu getCpu() {
|
||||
return cpu;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Memory getRam() {
|
||||
return ram;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Acia getAcia() {
|
||||
return acia;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pia getPia() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Crtc getCrtc() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Memory getRom() {
|
||||
return rom;
|
||||
}
|
||||
|
||||
public void setRom(Memory rom) throws MemoryRangeException {
|
||||
if(this.rom != null) {
|
||||
bus.removeDevice(this.rom);
|
||||
}
|
||||
this.rom = rom;
|
||||
bus.addDevice(this.rom);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRomBase() {
|
||||
return ROM_BASE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRomSize() {
|
||||
return ROM_SIZE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMemorySize() {
|
||||
return MEMORY_SIZE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Multicomp";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
* Copyright (c) 2008-2025 Seth J. Morabito <web@loomcom.com>
|
||||
* Maik Merten <maikmerten@googlemail.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.loomcom.symon.machines;
|
||||
|
||||
import com.loomcom.symon.Bus;
|
||||
import com.loomcom.symon.Cpu;
|
||||
import com.loomcom.symon.devices.Acia;
|
||||
import com.loomcom.symon.devices.Crtc;
|
||||
import com.loomcom.symon.devices.Memory;
|
||||
import com.loomcom.symon.devices.Pia;
|
||||
import com.loomcom.symon.exceptions.MemoryRangeException;
|
||||
|
||||
/**
|
||||
* A SimpleMachine is the simplest 6502 implementation possible - it
|
||||
* consists solely of RAM and a CPU. This machine is primarily useful
|
||||
* for running 6502 functional tests or debugging by hand.
|
||||
*/
|
||||
public class SimpleMachine implements Machine {
|
||||
|
||||
private static final int BUS_BOTTOM = 0x0000;
|
||||
private static final int BUS_TOP = 0xffff;
|
||||
|
||||
private final Bus bus;
|
||||
private final Memory ram;
|
||||
private final Cpu cpu;
|
||||
|
||||
public SimpleMachine(String romFile) throws MemoryRangeException {
|
||||
this.bus = new Bus(BUS_BOTTOM, BUS_TOP);
|
||||
this.ram = new Memory(BUS_BOTTOM, BUS_TOP, false);
|
||||
this.cpu = new Cpu();
|
||||
|
||||
bus.addCpu(cpu);
|
||||
bus.addDevice(ram);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Bus getBus() {
|
||||
return bus;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Cpu getCpu() {
|
||||
return cpu;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Memory getRam() {
|
||||
return ram;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Acia getAcia() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pia getPia() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Crtc getCrtc() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Memory getRom() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRom(Memory rom) {
|
||||
// No-op
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRomBase() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRomSize() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMemorySize() {
|
||||
return BUS_TOP + 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Simple";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,169 @@
|
||||
/*
|
||||
* Copyright (c) 2008-2025 Seth J. Morabito <web@loomcom.com>
|
||||
* Maik Merten <maikmerten@googlemail.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.loomcom.symon.machines;
|
||||
|
||||
import com.loomcom.symon.Bus;
|
||||
import com.loomcom.symon.Cpu;
|
||||
import com.loomcom.symon.devices.*;
|
||||
import com.loomcom.symon.exceptions.MemoryRangeException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class SymonMachine implements Machine {
|
||||
|
||||
private final static Logger logger = LoggerFactory.getLogger(SymonMachine.class.getName());
|
||||
|
||||
// Constants used by the simulated system. These define the memory map.
|
||||
private static final int BUS_BOTTOM = 0x0000;
|
||||
private static final int BUS_TOP = 0xffff;
|
||||
|
||||
// 32K of RAM from $0000 - $7FFF
|
||||
private static final int MEMORY_BASE = 0x0000;
|
||||
private static final int MEMORY_SIZE = 0x8000;
|
||||
|
||||
// PIA at $8000-$800F
|
||||
|
||||
private static final int PIA_BASE = 0x8000;
|
||||
|
||||
// ACIA at $8800-$8803
|
||||
private static final int ACIA_BASE = 0x8800;
|
||||
|
||||
// CRTC at $9000-$9001
|
||||
private static final int CRTC_BASE = 0x9000;
|
||||
|
||||
// 16KB ROM at $C000-$FFFF
|
||||
private static final int ROM_BASE = 0xC000;
|
||||
private static final int ROM_SIZE = 0x4000;
|
||||
|
||||
|
||||
// The simulated peripherals
|
||||
private final Bus bus;
|
||||
private final Cpu cpu;
|
||||
private final Acia acia;
|
||||
private final Pia pia;
|
||||
private final Crtc crtc;
|
||||
private final Memory ram;
|
||||
private Memory rom;
|
||||
|
||||
|
||||
public SymonMachine(String romFile) throws Exception {
|
||||
this.bus = new Bus(BUS_BOTTOM, BUS_TOP);
|
||||
this.cpu = new Cpu();
|
||||
this.ram = new Memory(MEMORY_BASE, MEMORY_BASE + MEMORY_SIZE - 1, false);
|
||||
this.pia = new Via6522(PIA_BASE);
|
||||
this.acia = new Acia6551(ACIA_BASE);
|
||||
this.crtc = new Crtc(CRTC_BASE, ram);
|
||||
|
||||
bus.addCpu(cpu);
|
||||
bus.addDevice(ram);
|
||||
bus.addDevice(pia);
|
||||
bus.addDevice(acia);
|
||||
bus.addDevice(crtc);
|
||||
|
||||
if (romFile != null) {
|
||||
File romImage = new File(romFile);
|
||||
if (romImage.canRead()) {
|
||||
logger.info("Loading ROM image from file {}", romImage);
|
||||
this.rom = Memory.makeROM(ROM_BASE, ROM_BASE + ROM_SIZE - 1, romImage);
|
||||
} else {
|
||||
logger.info("Default ROM file {} not found, loading empty R/W memory image.", romImage);
|
||||
this.rom = Memory.makeRAM(ROM_BASE, ROM_BASE + ROM_SIZE - 1);
|
||||
}
|
||||
} else {
|
||||
logger.info("No ROM file specified, loading empty R/W memory image.");
|
||||
this.rom = Memory.makeRAM(ROM_BASE, ROM_BASE + ROM_SIZE - 1);
|
||||
}
|
||||
|
||||
bus.addDevice(rom);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Bus getBus() {
|
||||
return bus;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Cpu getCpu() {
|
||||
return cpu;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Memory getRam() {
|
||||
return ram;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Acia getAcia() {
|
||||
return acia;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pia getPia() {
|
||||
return pia;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Crtc getCrtc() {
|
||||
return crtc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Memory getRom() {
|
||||
return rom;
|
||||
}
|
||||
|
||||
public void setRom(Memory rom) throws MemoryRangeException {
|
||||
if(this.rom != null) {
|
||||
bus.removeDevice(this.rom);
|
||||
}
|
||||
this.rom = rom;
|
||||
bus.addDevice(this.rom);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRomBase() {
|
||||
return ROM_BASE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRomSize() {
|
||||
return ROM_SIZE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMemorySize() {
|
||||
return MEMORY_SIZE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Symon";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
/*
|
||||
* Copyright (c) 2008-2025 Seth J. Morabito <web@loomcom.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.loomcom.symon.ui;
|
||||
|
||||
import com.loomcom.symon.Breakpoints;
|
||||
import com.loomcom.symon.util.Utils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
/**
|
||||
* Simple window to enter breakpoints.
|
||||
*/
|
||||
public class BreakpointsWindow extends JFrame {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(BreakpointsWindow.class);
|
||||
|
||||
private static final Dimension FRAME_SIZE = new Dimension(240, 280);
|
||||
private static final String EMPTY_STRING = "";
|
||||
|
||||
private final JFrame mainWindow;
|
||||
private final Breakpoints breakpoints;
|
||||
|
||||
public BreakpointsWindow(Breakpoints breakpoints,
|
||||
JFrame mainWindow) {
|
||||
this.breakpoints = breakpoints;
|
||||
this.mainWindow = mainWindow;
|
||||
createUi();
|
||||
}
|
||||
|
||||
private void createUi() {
|
||||
setTitle("Breakpoints");
|
||||
|
||||
JPanel breakpointsPanel = new JPanel();
|
||||
JPanel controlPanel = new JPanel();
|
||||
|
||||
breakpointsPanel.setLayout(new BorderLayout());
|
||||
breakpointsPanel.setBorder(new EmptyBorder(10, 10, 10, 10));
|
||||
|
||||
final JButton addButton = new JButton("Add");
|
||||
final JButton removeButton = new JButton("Del");
|
||||
removeButton.setEnabled(false);
|
||||
|
||||
final JTextField addTextField = new JTextField(4);
|
||||
|
||||
final JTable breakpointsTable = new JTable(breakpoints);
|
||||
breakpointsTable.setShowGrid(true);
|
||||
breakpointsTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
||||
breakpointsTable.getSelectionModel().addListSelectionListener(e -> removeButton.setEnabled(e.getFirstIndex() > -1));
|
||||
|
||||
JScrollPane scrollPane = new JScrollPane(breakpointsTable);
|
||||
scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
|
||||
scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
|
||||
|
||||
breakpointsPanel.add(scrollPane, BorderLayout.CENTER);
|
||||
|
||||
ActionListener addBreakpointListener = e -> {
|
||||
int value;
|
||||
|
||||
String newBreakpoint = addTextField.getText();
|
||||
|
||||
if (newBreakpoint == null || newBreakpoint.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
value = (Integer.parseInt(addTextField.getText(), 16) & 0xffff);
|
||||
} catch (NumberFormatException ex) {
|
||||
logger.warn("Can't parse page number {}", newBreakpoint);
|
||||
return;
|
||||
}
|
||||
|
||||
breakpoints.addBreakpoint(value);
|
||||
|
||||
logger.debug("Added breakpoint ${}", Utils.wordToHex(value));
|
||||
|
||||
addTextField.setText(EMPTY_STRING);
|
||||
};
|
||||
|
||||
addButton.addActionListener(addBreakpointListener);
|
||||
addTextField.addActionListener(addBreakpointListener);
|
||||
|
||||
removeButton.addActionListener(e -> breakpoints.removeBreakpointAtIndex(breakpointsTable.getSelectedRow()));
|
||||
|
||||
controlPanel.add(addTextField);
|
||||
controlPanel.add(addButton);
|
||||
controlPanel.add(removeButton);
|
||||
|
||||
setLayout(new BorderLayout());
|
||||
getContentPane().add(breakpointsPanel, BorderLayout.CENTER);
|
||||
getContentPane().add(controlPanel, BorderLayout.SOUTH);
|
||||
|
||||
setMinimumSize(FRAME_SIZE);
|
||||
setMaximumSize(FRAME_SIZE);
|
||||
setPreferredSize(FRAME_SIZE);
|
||||
|
||||
setLocationRelativeTo(mainWindow);
|
||||
setResizable(false);
|
||||
|
||||
pack();
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2013 Seth J. Morabito <web@loomcom.com>
|
||||
* Copyright (c) 2008-2025 Seth J. Morabito <web@loomcom.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
@@ -23,8 +23,8 @@
|
||||
|
||||
package com.loomcom.symon.ui;
|
||||
|
||||
import com.grahamedgecombe.jterminal.JTerminal;
|
||||
import com.grahamedgecombe.jterminal.vt100.Vt100TerminalModel;
|
||||
import com.loomcom.symon.jterminal.JTerminal;
|
||||
import com.loomcom.symon.jterminal.vt100.Vt100TerminalModel;
|
||||
import com.loomcom.symon.exceptions.FifoUnderrunException;
|
||||
import com.loomcom.symon.util.FifoRingBuffer;
|
||||
|
||||
@@ -44,21 +44,23 @@ import java.awt.event.MouseListener;
|
||||
|
||||
public class Console extends JTerminal implements KeyListener, MouseListener {
|
||||
|
||||
private static final int DEFAULT_COLUMNS = 80;
|
||||
private static final int DEFAULT_ROWS = 24;
|
||||
private static final int DEFAULT_BORDER_WIDTH = 10;
|
||||
private static final long serialVersionUID = 6633818486963338126L;
|
||||
|
||||
private static final int DEFAULT_BORDER_WIDTH = 10;
|
||||
// If true, swap CR and LF characters.
|
||||
private static final boolean SWAP_CR_AND_LF = true;
|
||||
|
||||
// If true, send CRLF (0x0d 0x0a) whenever CR is typed
|
||||
private static final boolean SEND_CR_LF_FOR_CR = false;
|
||||
private final boolean sendCrForLf;
|
||||
private final FifoRingBuffer<Character> typeAheadBuffer;
|
||||
|
||||
private FifoRingBuffer<Character> typeAheadBuffer;
|
||||
|
||||
public Console(int columns, int rows, Font font) {
|
||||
public Console(int columns, int rows, Font font, boolean sendCrForLf) {
|
||||
super(new Vt100TerminalModel(columns, rows), font);
|
||||
//super(new Vt100TerminalModel(columns, rows));
|
||||
// A small type-ahead buffer, as might be found in any real
|
||||
// VT100-style serial terminal.
|
||||
this.typeAheadBuffer = new FifoRingBuffer<Character>(128);
|
||||
this.typeAheadBuffer = new FifoRingBuffer<>(128);
|
||||
this.sendCrForLf = sendCrForLf;
|
||||
setBorderWidth(DEFAULT_BORDER_WIDTH);
|
||||
addKeyListener(this);
|
||||
addMouseListener(this);
|
||||
@@ -83,7 +85,7 @@ public class Console extends JTerminal implements KeyListener, MouseListener {
|
||||
/**
|
||||
* Returns true if a key has been pressed since the last time input was read.
|
||||
*
|
||||
* @return
|
||||
* @return true if the type-ahead buffer has data
|
||||
*/
|
||||
public boolean hasInput() {
|
||||
return !typeAheadBuffer.isEmpty();
|
||||
@@ -105,7 +107,7 @@ public class Console extends JTerminal implements KeyListener, MouseListener {
|
||||
}
|
||||
}
|
||||
|
||||
if (SEND_CR_LF_FOR_CR && keyTyped == 0x0d) {
|
||||
if (sendCrForLf && (keyTyped == 0x0d)) {
|
||||
typeAheadBuffer.push((char) 0x0d);
|
||||
typeAheadBuffer.push((char) 0x0a);
|
||||
} else {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2013 Seth J. Morabito <web@loomcom.com>
|
||||
* Copyright (c) 2008-2025 Seth J. Morabito <web@loomcom.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
@@ -25,7 +25,9 @@ package com.loomcom.symon.ui;
|
||||
|
||||
import com.loomcom.symon.Bus;
|
||||
import com.loomcom.symon.exceptions.MemoryAccessException;
|
||||
import com.loomcom.symon.util.HexUtil;
|
||||
import com.loomcom.symon.util.Utils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
@@ -37,8 +39,7 @@ import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.EventObject;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
|
||||
/**
|
||||
* This Frame displays the contents of a page of memory. The page number to be displayed
|
||||
@@ -46,7 +47,9 @@ import java.util.logging.Logger;
|
||||
*/
|
||||
public class MemoryWindow extends JFrame implements ActionListener {
|
||||
|
||||
private MemoryTableModel memoryTableModel;
|
||||
private static final Logger logger = LoggerFactory.getLogger(MemoryWindow.class);
|
||||
|
||||
private final MemoryTableModel memoryTableModel;
|
||||
private JTable memoryTable;
|
||||
private JTextField pageNumberTextField;
|
||||
private JButton previousPageButton;
|
||||
@@ -104,11 +107,11 @@ public class MemoryWindow extends JFrame implements ActionListener {
|
||||
|
||||
previousPageButton.setEnabled(pageNumber > 0x00);
|
||||
nextPageButton.setEnabled(pageNumber < 0xff);
|
||||
pageNumberTextField.setText(HexUtil.byteToHex(pageNumber));
|
||||
pageNumberTextField.setText(Utils.byteToHex(pageNumber));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set-up the UI.
|
||||
* Set up the UI.
|
||||
*/
|
||||
private void createUi() {
|
||||
setTitle("Memory Contents");
|
||||
@@ -190,14 +193,14 @@ public class MemoryWindow extends JFrame implements ActionListener {
|
||||
if (currentPage > 0x00) {
|
||||
setPageNumber(currentPage - 1);
|
||||
updateControls();
|
||||
memoryTable.updateUI();
|
||||
updateState();
|
||||
}
|
||||
} else if (e.getSource() == nextPageButton) {
|
||||
int currentPage = getPageNumber();
|
||||
if (currentPage < 0xff) {
|
||||
setPageNumber(currentPage + 1);
|
||||
updateControls();
|
||||
memoryTable.updateUI();
|
||||
updateState();
|
||||
}
|
||||
} else if (e.getSource() == pageNumberTextField) {
|
||||
String pageNumberInput = pageNumberTextField.getText();
|
||||
@@ -205,22 +208,29 @@ public class MemoryWindow extends JFrame implements ActionListener {
|
||||
// Try to parse a hex value out of the pageNumber.
|
||||
int newPageNumber = Integer.parseInt(pageNumberInput, 16);
|
||||
setPageNumber(newPageNumber & 0xff);
|
||||
memoryTable.updateUI();
|
||||
updateState();
|
||||
} catch (NumberFormatException ex) {
|
||||
// An invalid number was entered. Log the error, but otherwise
|
||||
// take no action.
|
||||
Logger.getLogger(this.getClass().getName()).log(Level.WARNING, "Can't parse page number " +
|
||||
pageNumberInput);
|
||||
logger.warn("Can't parse page number {}", pageNumberInput);
|
||||
}
|
||||
|
||||
updateControls();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Refresh the view of memory
|
||||
*/
|
||||
public void updateState() {
|
||||
memoryTable.updateUI();
|
||||
}
|
||||
|
||||
/**
|
||||
* A JTable that will automatically select all text in a cell
|
||||
* being edited.
|
||||
*/
|
||||
private class MemoryTable extends JTable {
|
||||
private static class MemoryTable extends JTable {
|
||||
|
||||
public MemoryTable(TableModel tableModel) {
|
||||
super(tableModel);
|
||||
@@ -232,7 +242,7 @@ public class MemoryWindow extends JFrame implements ActionListener {
|
||||
|
||||
final Component editor = getEditorComponent();
|
||||
|
||||
if (editor != null && editor instanceof JTextComponent) {
|
||||
if (editor instanceof JTextComponent) {
|
||||
((JTextComponent) editor).selectAll();
|
||||
}
|
||||
|
||||
@@ -240,7 +250,7 @@ public class MemoryWindow extends JFrame implements ActionListener {
|
||||
}
|
||||
}
|
||||
|
||||
private class MemoryTableCellRenderer extends DefaultTableCellRenderer {
|
||||
private static class MemoryTableCellRenderer extends DefaultTableCellRenderer {
|
||||
|
||||
@Override
|
||||
public Component getTableCellRendererComponent(JTable table, Object value,
|
||||
@@ -262,9 +272,9 @@ public class MemoryWindow extends JFrame implements ActionListener {
|
||||
/**
|
||||
* The model that backs the Memory Table.
|
||||
*/
|
||||
private class MemoryTableModel extends AbstractTableModel {
|
||||
private static class MemoryTableModel extends AbstractTableModel {
|
||||
|
||||
private Bus bus;
|
||||
private final Bus bus;
|
||||
private int pageNumber;
|
||||
|
||||
private static final int COLUMN_COUNT = 17;
|
||||
@@ -318,13 +328,13 @@ public class MemoryWindow extends JFrame implements ActionListener {
|
||||
public Object getValueAt(int row, int column) {
|
||||
try {
|
||||
if (column == 0) {
|
||||
return HexUtil.wordToHex(fullAddress(row, 1));
|
||||
return Utils.wordToHex(fullAddress(row, 1));
|
||||
} else if (column < 9) {
|
||||
// Display hex value of the data
|
||||
return HexUtil.byteToHex(bus.read(fullAddress(row, column)));
|
||||
return Utils.byteToHex(bus.read(fullAddress(row, column), false));
|
||||
} else {
|
||||
// Display the ASCII equivalent (if printable)
|
||||
return HexUtil.byteToAscii(bus.read(fullAddress(row, column - 8)));
|
||||
return Utils.byteToAscii(bus.read(fullAddress(row, column - 8), false));
|
||||
}
|
||||
} catch (MemoryAccessException ex) {
|
||||
return "??";
|
||||
@@ -339,12 +349,8 @@ public class MemoryWindow extends JFrame implements ActionListener {
|
||||
int fullAddress = fullAddress(row, column);
|
||||
int newValue = Integer.parseInt(hexValue, 16) & 0xff;
|
||||
bus.write(fullAddress, newValue);
|
||||
} catch (MemoryAccessException ex) {
|
||||
;
|
||||
} catch (NumberFormatException ex) {
|
||||
;
|
||||
} catch (ClassCastException ex) {
|
||||
;
|
||||
} catch (MemoryAccessException | NumberFormatException | ClassCastException ex) {
|
||||
// Intentionally swallow exception
|
||||
}
|
||||
fireTableCellUpdated(row, column);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2013 Seth J. Morabito <web@loomcom.com>
|
||||
* Copyright (c) 2008-2025 Seth J. Morabito <web@loomcom.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
@@ -42,11 +42,11 @@ public class PreferencesDialog extends Observable implements Preferences {
|
||||
private JTextField programLoadAddressField;
|
||||
|
||||
private int programLoadAddress = DEFAULT_PROGRAM_LOAD_ADDRESS;
|
||||
private boolean haltOnBreak = DEFAULT_HALT_ON_BREAK;
|
||||
private boolean haltOnBreak;
|
||||
|
||||
public PreferencesDialog(Frame parent, boolean modal) {
|
||||
public PreferencesDialog(Frame parent, boolean modal, boolean haltOnBreak) {
|
||||
this.dialog = new JDialog(parent, modal);
|
||||
|
||||
this.haltOnBreak = haltOnBreak;
|
||||
createUi();
|
||||
updateUi();
|
||||
}
|
||||
@@ -98,19 +98,21 @@ public class PreferencesDialog extends Observable implements Preferences {
|
||||
JButton cancelButton = new JButton("Cancel");
|
||||
|
||||
cancelButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent actionEvent) {
|
||||
updateUi();
|
||||
PreferencesDialog.this.updateUi();
|
||||
dialog.setVisible(false);
|
||||
}
|
||||
});
|
||||
|
||||
applyButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent actionEvent) {
|
||||
haltOnBreak = haltOnBreakCheckBox.isSelected();
|
||||
programLoadAddress = hexToInt(programLoadAddressField.getText());
|
||||
updateUi();
|
||||
programLoadAddress = PreferencesDialog.this.hexToInt(programLoadAddressField.getText());
|
||||
PreferencesDialog.this.updateUi();
|
||||
// TODO: Actually check to see if values have changed, don't assume.
|
||||
setChanged();
|
||||
PreferencesDialog.this.setChanged();
|
||||
PreferencesDialog.this.notifyObservers();
|
||||
dialog.setVisible(false);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2013 Seth J. Morabito <web@loomcom.com>
|
||||
* Copyright (c) 2008-2025 Seth J. Morabito <web@loomcom.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
@@ -23,12 +23,20 @@
|
||||
|
||||
package com.loomcom.symon.ui;
|
||||
|
||||
import com.formdev.flatlaf.util.UIScale;
|
||||
import com.loomcom.symon.Cpu;
|
||||
import com.loomcom.symon.CpuState;
|
||||
import com.loomcom.symon.devices.Pia;
|
||||
import com.loomcom.symon.devices.Via6522;
|
||||
import com.loomcom.symon.machines.Machine;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.Border;
|
||||
import javax.swing.border.EtchedBorder;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* UI component that displays the current state of the simulated CPU.
|
||||
@@ -50,7 +58,6 @@ public class StatusPanel extends JPanel {
|
||||
private ImageIcon negativeOn;
|
||||
private ImageIcon negativeOff;
|
||||
|
||||
private JLabel statusFlagsLabel;
|
||||
private JLabel carryFlagLabel;
|
||||
private JLabel zeroFlagLabel;
|
||||
private JLabel irqDisableFlagLabel;
|
||||
@@ -65,28 +72,26 @@ public class StatusPanel extends JPanel {
|
||||
private JTextField aField;
|
||||
private JTextField xField;
|
||||
private JTextField yField;
|
||||
private JTextField piaBField;
|
||||
private JTextField piaAField;
|
||||
|
||||
private JLabel opcodeLabel;
|
||||
private JLabel pcLabel;
|
||||
private JLabel spLabel;
|
||||
private JLabel aLabel;
|
||||
private JLabel xLabel;
|
||||
private JLabel yLabel;
|
||||
private final Machine machine;
|
||||
|
||||
private static final int EMPTY_BORDER = 10;
|
||||
private static final Border LABEL_BORDER = BorderFactory.createEmptyBorder(0, 5, 0, 0);
|
||||
private static final Font LABEL_FONT = new Font(Font.SANS_SERIF, Font.BOLD, 12);
|
||||
private static final Font LABEL_FONT = new Font(Font.SANS_SERIF, Font.BOLD, UIScale.scale(12));
|
||||
private static final Dimension LARGE_TEXT_FIELD_SIZE = new Dimension(134, 22);
|
||||
private static final Dimension SMALL_TEXT_FIELD_SIZE = new Dimension(65, 22);
|
||||
|
||||
public StatusPanel() {
|
||||
public StatusPanel(Machine machine) {
|
||||
super();
|
||||
this.machine = machine;
|
||||
createUi();
|
||||
}
|
||||
|
||||
private void createUi() {
|
||||
Border emptyBorder = BorderFactory.createEmptyBorder(EMPTY_BORDER, EMPTY_BORDER,
|
||||
EMPTY_BORDER, EMPTY_BORDER);
|
||||
EMPTY_BORDER, EMPTY_BORDER);
|
||||
Border etchedBorder = BorderFactory.createEtchedBorder(EtchedBorder.LOWERED);
|
||||
|
||||
setBorder(BorderFactory.createCompoundBorder(emptyBorder, etchedBorder));
|
||||
@@ -99,20 +104,20 @@ public class StatusPanel extends JPanel {
|
||||
JPanel statusFlagsPanel = new JPanel();
|
||||
statusFlagsPanel.setAlignmentX(LEFT_ALIGNMENT);
|
||||
|
||||
carryOn = new ImageIcon(this.getClass().getResource("images/C_on.png"));
|
||||
carryOff = new ImageIcon(this.getClass().getResource("images/C_off.png"));
|
||||
zeroOn = new ImageIcon(this.getClass().getResource("images/Z_on.png"));
|
||||
zeroOff = new ImageIcon(this.getClass().getResource("images/Z_off.png"));
|
||||
irqOn = new ImageIcon(this.getClass().getResource("images/I_on.png"));
|
||||
irqOff = new ImageIcon(this.getClass().getResource("images/I_off.png"));
|
||||
decimalOn = new ImageIcon(this.getClass().getResource("images/D_on.png"));
|
||||
decimalOff = new ImageIcon(this.getClass().getResource("images/D_off.png"));
|
||||
breakOn = new ImageIcon(this.getClass().getResource("images/B_on.png"));
|
||||
breakOff = new ImageIcon(this.getClass().getResource("images/B_off.png"));
|
||||
overflowOn = new ImageIcon(this.getClass().getResource("images/O_on.png"));
|
||||
overflowOff = new ImageIcon(this.getClass().getResource("images/O_off.png"));
|
||||
negativeOn = new ImageIcon(this.getClass().getResource("images/N_on.png"));
|
||||
negativeOff = new ImageIcon(this.getClass().getResource("images/N_off.png"));
|
||||
carryOn = loadScaledIcon("/C_on.png");
|
||||
carryOff = loadScaledIcon("/C_off.png");
|
||||
zeroOn = loadScaledIcon("/Z_on.png");
|
||||
zeroOff = loadScaledIcon("/Z_off.png");
|
||||
irqOn = loadScaledIcon("/I_on.png");
|
||||
irqOff = loadScaledIcon("/I_off.png");
|
||||
decimalOn = loadScaledIcon("/D_on.png");
|
||||
decimalOff = loadScaledIcon("/D_off.png");
|
||||
breakOn = loadScaledIcon("/B_on.png");
|
||||
breakOff = loadScaledIcon("/B_off.png");
|
||||
overflowOn = loadScaledIcon("/O_on.png");
|
||||
overflowOff = loadScaledIcon("/O_off.png");
|
||||
negativeOn = loadScaledIcon("/N_on.png");
|
||||
negativeOff = loadScaledIcon("/N_off.png");
|
||||
|
||||
// Initialize all to off
|
||||
carryFlagLabel = new JLabel(carryOff, JLabel.CENTER);
|
||||
@@ -125,16 +130,15 @@ public class StatusPanel extends JPanel {
|
||||
|
||||
// Add tool-tip text
|
||||
carryFlagLabel.setToolTipText("Carry: The last operation caused an overflow " +
|
||||
"from bit 7 of the result or an underflow from bit 0");
|
||||
"from bit 7 of the result or an underflow from bit 0");
|
||||
zeroFlagLabel.setToolTipText("Zero: The result of the last operation was 0");
|
||||
irqDisableFlagLabel.setToolTipText("Interrupt Disable: Processor will not respond to IRQ");
|
||||
decimalModeFlagLabel.setToolTipText("Decimal Mode");
|
||||
breakFlagLabel.setToolTipText("Break: BRK instruction occurred");
|
||||
overflowFlagLabel.setToolTipText("Overflow: The result of the last operation was " +
|
||||
"an invalid 2's complement result");
|
||||
"an invalid 2's complement result");
|
||||
negativeFlagLabel.setToolTipText("Negative: The result of the last operation set bit 7");
|
||||
|
||||
|
||||
statusFlagsPanel.add(negativeFlagLabel);
|
||||
statusFlagsPanel.add(overflowFlagLabel);
|
||||
statusFlagsPanel.add(breakFlagLabel);
|
||||
@@ -144,25 +148,103 @@ public class StatusPanel extends JPanel {
|
||||
statusFlagsPanel.add(carryFlagLabel);
|
||||
|
||||
// Create and add register and address labels
|
||||
statusFlagsLabel = makeLabel("Flags");
|
||||
opcodeLabel = makeLabel("IR");
|
||||
pcLabel = makeLabel("PC");
|
||||
spLabel = makeLabel("SP");
|
||||
aLabel = makeLabel("A");
|
||||
xLabel = makeLabel("X");
|
||||
yLabel = makeLabel("Y");
|
||||
JLabel statusFlagsLabel = makeLabel("Flags");
|
||||
JLabel opcodeLabel = makeLabel("Next IR");
|
||||
JLabel pcLabel = makeLabel("PC");
|
||||
JLabel spLabel = makeLabel("SP");
|
||||
JLabel aLabel = makeLabel("A");
|
||||
JLabel xLabel = makeLabel("X");
|
||||
JLabel yLabel = makeLabel("Y");
|
||||
|
||||
// PIA/VIA labels
|
||||
JLabel piaBLabel = makeLabel("PB");
|
||||
JLabel piaALabel = makeLabel("PA");
|
||||
|
||||
statusFlagsLabel.setToolTipText("6502 Processor Status Flags");
|
||||
opcodeLabel.setToolTipText("Instruction Register");
|
||||
pcLabel.setToolTipText("Program Counter");
|
||||
spLabel.setToolTipText("Stack Pointer");
|
||||
|
||||
opcodeField = makeTextField(LARGE_TEXT_FIELD_SIZE);
|
||||
pcField = makeTextField(LARGE_TEXT_FIELD_SIZE);
|
||||
spField = makeTextField(SMALL_TEXT_FIELD_SIZE);
|
||||
aField = makeTextField(SMALL_TEXT_FIELD_SIZE);
|
||||
xField = makeTextField(SMALL_TEXT_FIELD_SIZE);
|
||||
yField = makeTextField(SMALL_TEXT_FIELD_SIZE);
|
||||
opcodeField = makeTextField(LARGE_TEXT_FIELD_SIZE, false);
|
||||
pcField = makeTextField(LARGE_TEXT_FIELD_SIZE, true);
|
||||
spField = makeTextField(SMALL_TEXT_FIELD_SIZE, true);
|
||||
aField = makeTextField(SMALL_TEXT_FIELD_SIZE, true);
|
||||
xField = makeTextField(SMALL_TEXT_FIELD_SIZE, true);
|
||||
yField = makeTextField(SMALL_TEXT_FIELD_SIZE, true);
|
||||
|
||||
piaBField = makeTextField(LARGE_TEXT_FIELD_SIZE, false);
|
||||
piaAField = makeTextField(LARGE_TEXT_FIELD_SIZE, false);
|
||||
|
||||
// Make fields editable
|
||||
pcField.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
try {
|
||||
int newVal = StatusPanel.this.getHexVal(pcField) & 0xffff;
|
||||
machine.getCpu().setProgramCounter(newVal);
|
||||
} catch (Exception ex) {
|
||||
// Swallow exception
|
||||
}
|
||||
|
||||
StatusPanel.this.updateState();
|
||||
}
|
||||
});
|
||||
|
||||
spField.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
try {
|
||||
int newVal = StatusPanel.this.getHexVal(spField) & 0xff;
|
||||
machine.getCpu().setStackPointer(newVal);
|
||||
} catch (Exception ex) {
|
||||
// Swallow exception
|
||||
}
|
||||
|
||||
StatusPanel.this.updateState();
|
||||
}
|
||||
});
|
||||
|
||||
aField.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
try {
|
||||
int newVal = StatusPanel.this.getHexVal(aField) & 0xff;
|
||||
machine.getCpu().setAccumulator(newVal);
|
||||
} catch (Exception ex) {
|
||||
// Swallow exception
|
||||
}
|
||||
|
||||
StatusPanel.this.updateState();
|
||||
}
|
||||
});
|
||||
|
||||
xField.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
try {
|
||||
int newVal = StatusPanel.this.getHexVal(xField) & 0xff;
|
||||
machine.getCpu().setXRegister(newVal);
|
||||
} catch (Exception ex) {
|
||||
// Swallow exception
|
||||
}
|
||||
|
||||
StatusPanel.this.updateState();
|
||||
}
|
||||
});
|
||||
|
||||
yField.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
try {
|
||||
int newVal = StatusPanel.this.getHexVal(yField) & 0xff;
|
||||
machine.getCpu().setYRegister(newVal);
|
||||
} catch (Exception ex) {
|
||||
// Swallow exception
|
||||
}
|
||||
|
||||
StatusPanel.this.updateState();
|
||||
}
|
||||
});
|
||||
|
||||
constraints.anchor = GridBagConstraints.LINE_START;
|
||||
constraints.gridwidth = 2;
|
||||
@@ -172,7 +254,6 @@ public class StatusPanel extends JPanel {
|
||||
constraints.gridy = 1;
|
||||
add(statusFlagsPanel, constraints);
|
||||
|
||||
|
||||
constraints.insets = new Insets(5, 0, 0, 0);
|
||||
constraints.gridy = 2;
|
||||
add(opcodeLabel, constraints);
|
||||
@@ -216,18 +297,38 @@ public class StatusPanel extends JPanel {
|
||||
add(xField, constraints);
|
||||
constraints.gridx = 1;
|
||||
add(yField, constraints);
|
||||
|
||||
constraints.insets = new Insets(5, 0, 0, 0);
|
||||
constraints.gridx = 0;
|
||||
constraints.gridwidth = 2;
|
||||
constraints.gridy = 10;
|
||||
add(piaBLabel, constraints);
|
||||
|
||||
constraints.insets = new Insets(2, 2, 2, 2);
|
||||
constraints.gridy = 11;
|
||||
add(piaBField, constraints);
|
||||
|
||||
constraints.insets = new Insets(5, 0, 0, 0);
|
||||
constraints.gridy = 12;
|
||||
add(piaALabel, constraints);
|
||||
|
||||
constraints.insets = new Insets(2, 2, 2, 2);
|
||||
constraints.gridy = 13;
|
||||
add(piaAField, constraints);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the display based on the current state of the CPU.
|
||||
*
|
||||
* @param cpu The simulated 6502 CPU.
|
||||
*/
|
||||
public void updateState(Cpu cpu) {
|
||||
Cpu.CpuState cpuState = cpu.getCpuState();
|
||||
public void updateState() {
|
||||
Cpu cpu = machine.getCpu();
|
||||
CpuState cpuState = cpu.getCpuState();
|
||||
|
||||
Pia pia = machine.getPia();
|
||||
|
||||
// Update the Processor Status Flag display
|
||||
int status = cpu.getCpuState().getStatusFlag();
|
||||
int status = cpuState.getStatusFlag();
|
||||
|
||||
carryFlagLabel.setIcon(iconForFlag(status, 0));
|
||||
zeroFlagLabel.setIcon(iconForFlag(status, 1));
|
||||
@@ -238,13 +339,21 @@ public class StatusPanel extends JPanel {
|
||||
negativeFlagLabel.setIcon(iconForFlag(status, 7));
|
||||
|
||||
// Update the register and address displays
|
||||
opcodeField.setText(cpu.getCpuState().disassembleOp());
|
||||
|
||||
// We always want to show the NEXT instruction that will be executed
|
||||
opcodeField.setText(cpu.disassembleNextOp());
|
||||
pcField.setText(cpu.getProgramCounterStatus());
|
||||
spField.setText(cpu.getStackPointerStatus());
|
||||
aField.setText(cpu.getAccumulatorStatus());
|
||||
xField.setText(cpu.getXRegisterStatus());
|
||||
yField.setText(cpu.getYRegisterStatus());
|
||||
|
||||
// Update the Pia Variables
|
||||
if (pia instanceof Via6522) {
|
||||
piaBField.setText(((Via6522) pia).getPBStatus());
|
||||
piaAField.setText(((Via6522) pia).getPAStatus());
|
||||
}
|
||||
|
||||
repaint();
|
||||
}
|
||||
|
||||
@@ -313,15 +422,31 @@ public class StatusPanel extends JPanel {
|
||||
return label;
|
||||
}
|
||||
|
||||
private JTextField makeTextField(Dimension size) {
|
||||
private JTextField makeTextField(Dimension size, boolean editable) {
|
||||
JTextField textField = new JTextField("");
|
||||
textField.setAlignmentX(LEFT_ALIGNMENT);
|
||||
textField.setEditable(false);
|
||||
textField.setMinimumSize(size);
|
||||
textField.setMaximumSize(size);
|
||||
textField.setPreferredSize(size);
|
||||
textField.setBackground(Color.WHITE);
|
||||
textField.setEditable(editable);
|
||||
|
||||
Dimension scaleSize = UIScale.scale(size);
|
||||
textField.setMinimumSize(scaleSize);
|
||||
textField.setMaximumSize(scaleSize);
|
||||
textField.setPreferredSize(scaleSize);
|
||||
|
||||
return textField;
|
||||
}
|
||||
|
||||
private int getHexVal(JTextField source) throws NumberFormatException {
|
||||
String val = source.getText().replaceAll("[^0-9a-fA-F]", "");
|
||||
return Integer.parseInt(val, 16);
|
||||
}
|
||||
|
||||
private ImageIcon loadScaledIcon(String resourcePath) {
|
||||
ImageIcon icon = new ImageIcon(Objects.requireNonNull(this.getClass().getResource(resourcePath)));
|
||||
|
||||
int scaledWidth = UIScale.scale(icon.getIconWidth());
|
||||
int scaledHeight = UIScale.scale(icon.getIconHeight());
|
||||
|
||||
Image scaleImage = icon.getImage().getScaledInstance(scaledWidth, scaledHeight, Image.SCALE_SMOOTH);
|
||||
return new ImageIcon(scaleImage);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2013 Seth J. Morabito <web@loomcom.com>
|
||||
* Copyright (c) 2008-2025 Seth J. Morabito <web@loomcom.com>
|
||||
* Maik Merten <maikmerten@googlemail.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
@@ -23,7 +24,7 @@
|
||||
|
||||
package com.loomcom.symon.ui;
|
||||
|
||||
import com.loomcom.symon.Cpu;
|
||||
import com.loomcom.symon.CpuState;
|
||||
import com.loomcom.symon.util.FifoRingBuffer;
|
||||
|
||||
import javax.swing.*;
|
||||
@@ -35,15 +36,15 @@ import java.awt.*;
|
||||
*/
|
||||
public class TraceLog extends JFrame {
|
||||
|
||||
private FifoRingBuffer<Cpu.CpuState> traceLog;
|
||||
private JTextArea traceLogTextArea;
|
||||
private final FifoRingBuffer<CpuState> traceLog;
|
||||
private final JTextArea traceLogTextArea;
|
||||
|
||||
private static final Dimension MIN_SIZE = new Dimension(320, 200);
|
||||
private static final Dimension PREFERRED_SIZE = new Dimension(640, 480);
|
||||
private static final int MAX_LOG_LENGTH = 50000;
|
||||
|
||||
public TraceLog() {
|
||||
traceLog = new FifoRingBuffer<Cpu.CpuState>(MAX_LOG_LENGTH);
|
||||
traceLog = new FifoRingBuffer<>(MAX_LOG_LENGTH);
|
||||
setMinimumSize(MIN_SIZE);
|
||||
setPreferredSize(PREFERRED_SIZE);
|
||||
setResizable(true);
|
||||
@@ -67,11 +68,15 @@ public class TraceLog extends JFrame {
|
||||
* call.
|
||||
*/
|
||||
public void refresh() {
|
||||
synchronized (this) {
|
||||
StringBuilder logString = new StringBuilder();
|
||||
for (Cpu.CpuState state : traceLog) {
|
||||
StringBuilder logString = new StringBuilder();
|
||||
|
||||
synchronized(traceLog) {
|
||||
for (CpuState state : traceLog) {
|
||||
logString.append(state.toTraceEvent());
|
||||
}
|
||||
}
|
||||
|
||||
synchronized(traceLogTextArea) {
|
||||
traceLogTextArea.setText(logString.toString());
|
||||
}
|
||||
}
|
||||
@@ -80,8 +85,10 @@ public class TraceLog extends JFrame {
|
||||
* Reset the log area.
|
||||
*/
|
||||
public void reset() {
|
||||
synchronized (this) {
|
||||
synchronized(traceLog) {
|
||||
traceLog.reset();
|
||||
}
|
||||
synchronized(traceLogTextArea) {
|
||||
traceLogTextArea.setText("");
|
||||
traceLogTextArea.setEnabled(true);
|
||||
}
|
||||
@@ -92,9 +99,9 @@ public class TraceLog extends JFrame {
|
||||
*
|
||||
* @param state The CPU State to append.
|
||||
*/
|
||||
public void append(Cpu.CpuState state) {
|
||||
synchronized(this) {
|
||||
traceLog.push(new Cpu.CpuState(state));
|
||||
public void append(CpuState state) {
|
||||
synchronized(traceLog) {
|
||||
traceLog.push(new CpuState(state));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,4 +113,8 @@ public class TraceLog extends JFrame {
|
||||
traceLogTextArea.setEnabled(true);
|
||||
}
|
||||
|
||||
public boolean shouldUpdate() {
|
||||
return isVisible() && traceLogTextArea.isEnabled();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,153 @@
|
||||
/*
|
||||
* Copyright (c) 2008-2025 Seth J. Morabito <web@loomcom.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.loomcom.symon.ui;
|
||||
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.LookAndFeel;
|
||||
import javax.swing.UIManager;
|
||||
import javax.swing.UnsupportedLookAndFeelException;
|
||||
|
||||
import com.loomcom.symon.machines.*;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.formdev.flatlaf.FlatDarkLaf;
|
||||
import com.formdev.flatlaf.FlatLaf;
|
||||
import com.formdev.flatlaf.FlatLightLaf;
|
||||
import com.formdev.flatlaf.util.SystemInfo;
|
||||
import com.jthemedetecor.OsThemeDetector;
|
||||
|
||||
import java.awt.*;
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
public final class Ui {
|
||||
private final static Logger logger = LoggerFactory.getLogger(Ui.class.getName());
|
||||
|
||||
public static void initUi() throws UnsupportedLookAndFeelException {
|
||||
// Location of properties resources for app-specific UI defaults:
|
||||
FlatLaf.registerCustomDefaultsSource("com.loomcom.symon.themes");
|
||||
|
||||
logger.debug("AWT Toolkit class: {}", Toolkit.getDefaultToolkit().getClass().getName());
|
||||
|
||||
// Enable automatic scaling, based on system DPI settings:
|
||||
//System.setProperty("sun.java2d.uiScale.enabled", "true");
|
||||
//System.setProperty("sun.java2d.uiScale", "1x");
|
||||
//System.setProperty("flatlaf.uiScale", "1x");
|
||||
|
||||
applyDetectedUiScale();
|
||||
|
||||
// OS-specific tweaking:
|
||||
|
||||
if (SystemInfo.isLinux) {
|
||||
logger.debug("Adapting UI for Linux.");
|
||||
|
||||
// Enable custom window decorations:
|
||||
JFrame.setDefaultLookAndFeelDecorated(true);
|
||||
JDialog.setDefaultLookAndFeelDecorated(true);
|
||||
}
|
||||
|
||||
else if (SystemInfo.isMacOS) {
|
||||
logger.debug("Adapting UI for MacOS.");
|
||||
|
||||
// Move menu bar from JFrame window to top of screen:
|
||||
System.setProperty("apple.laf.useScreenMenuBar", "true");
|
||||
// Set name used in screen menu bar (first menu after Apple menu):
|
||||
System.setProperty("apple.awt.application.name", "Symon");
|
||||
// Use current macOS appearance (light/dark) for window title bars:
|
||||
System.setProperty("apple.awt.application.appearance", "system");
|
||||
}
|
||||
|
||||
else if (SystemInfo.isWindows) {
|
||||
logger.debug("Adapting UI for Windows.");
|
||||
}
|
||||
|
||||
UIManager.setLookAndFeel(createLookAndFeel());
|
||||
}
|
||||
|
||||
public static Class<?> showMachineSelectionDialog() {
|
||||
Object[] possibilities = { "Symon", "Multicomp", "Simple", "BenEater", "Mike42" };
|
||||
String s = (String) JOptionPane.showInputDialog(
|
||||
null,
|
||||
"Please choose the machine type to be emulated:",
|
||||
"Machine selection",
|
||||
JOptionPane.PLAIN_MESSAGE,
|
||||
null,
|
||||
possibilities,
|
||||
"Symon");
|
||||
|
||||
if (s != null && s.equals("Multicomp")) {
|
||||
return MulticompMachine.class;
|
||||
} else if (s != null && s.equals("Simple")) {
|
||||
return SimpleMachine.class;
|
||||
} else if (s != null && s.equals("BenEater")) {
|
||||
return BenEaterMachine.class;
|
||||
} else if (s != null && s.equals("Mike42")) {
|
||||
return MichaelBillingtonMachine.class;
|
||||
} else {
|
||||
return SymonMachine.class;
|
||||
}
|
||||
}
|
||||
|
||||
private static LookAndFeel createLookAndFeel() {
|
||||
final OsThemeDetector themeDetector = OsThemeDetector.getDetector();
|
||||
final boolean systemThemeIsDark = themeDetector.isDark();
|
||||
|
||||
// Set light/dark mode depending on what can be detected from the system theme:
|
||||
FlatLaf theme;
|
||||
if (systemThemeIsDark) {
|
||||
logger.debug("Using DARK theme.");
|
||||
theme = new FlatDarkLaf();
|
||||
} else {
|
||||
logger.debug("Using LIGHT theme.");
|
||||
theme = new FlatLightLaf();
|
||||
}
|
||||
return theme;
|
||||
}
|
||||
|
||||
private static void applyDetectedUiScale() {
|
||||
Double rawScale = null;
|
||||
|
||||
if (SystemInfo.isLinux) rawScale = X11ResourceReader.readXftDpiScale(); // ex: 1.5, 2.0, 2.5...
|
||||
|
||||
if (rawScale != null && rawScale > 1.0) {
|
||||
// flatlaf.uiScale aceita frações — mantém a precisão original
|
||||
System.setProperty("flatlaf.uiScale", rawScale + "x");
|
||||
|
||||
// sun.java2d.uiScale só aceita inteiros — arredonda para cima
|
||||
int javaScale = (int) Math.ceil(rawScale);
|
||||
//System.setProperty("sun.java2d.uiScale", String.valueOf(javaScale));
|
||||
|
||||
logger.debug("Detected scale {}x, applying flatlaf.uiScale={}x, sun.java2d.uiScale={}x",
|
||||
rawScale, rawScale, javaScale);
|
||||
} else {
|
||||
logger.debug("No X11 HiDPI scale detected, using default.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2013 Seth J. Morabito <web@loomcom.com>
|
||||
* Copyright (c) 2008-2025 Seth J. Morabito <web@loomcom.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
@@ -25,6 +25,7 @@ package com.loomcom.symon.ui;
|
||||
|
||||
import com.loomcom.symon.devices.Crtc;
|
||||
import com.loomcom.symon.devices.DeviceChangeListener;
|
||||
import com.loomcom.symon.exceptions.MemoryAccessException;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
@@ -36,8 +37,11 @@ import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import static java.lang.System.*;
|
||||
|
||||
/**
|
||||
* VideoWindow represents a graphics framebuffer backed by a 6545 CRTC.
|
||||
* Each time the window's VideoPanel is repainted, the video memory is
|
||||
@@ -57,15 +61,16 @@ public class VideoWindow extends JFrame implements DeviceChangeListener {
|
||||
|
||||
private static final Logger logger = Logger.getLogger(VideoWindow.class.getName());
|
||||
|
||||
private static final long WINDOW_REPAINT_INTERVAL = 66; // 30fps rate
|
||||
private static final int CHAR_WIDTH = 8;
|
||||
private static final int CHAR_HEIGHT = 8;
|
||||
private static final String ASCII_ROM = "/ascii.rom";
|
||||
|
||||
private final int scaleX, scaleY;
|
||||
private final boolean shouldScale;
|
||||
|
||||
private BufferedImage image;
|
||||
private int[] charRom;
|
||||
private int[] videoRam;
|
||||
private final int[] charRom;
|
||||
|
||||
private int horizontalDisplayed;
|
||||
private int verticalDisplayed;
|
||||
@@ -74,9 +79,9 @@ public class VideoWindow extends JFrame implements DeviceChangeListener {
|
||||
private boolean hideCursor;
|
||||
|
||||
private Dimension dimensions;
|
||||
private Crtc crtc;
|
||||
private final Crtc crtc;
|
||||
|
||||
private ScheduledExecutorService scheduler;
|
||||
private final ScheduledExecutorService scheduler;
|
||||
private ScheduledFuture<?> cursorBlinker;
|
||||
|
||||
/**
|
||||
@@ -85,17 +90,21 @@ public class VideoWindow extends JFrame implements DeviceChangeListener {
|
||||
private class VideoPanel extends JPanel {
|
||||
@Override
|
||||
public void paintComponent(Graphics g) {
|
||||
for (int i = 0; i < crtc.getPageSize(); i++) {
|
||||
int address = crtc.getStartAddress() + i;
|
||||
int originX = (i % horizontalDisplayed) * CHAR_WIDTH;
|
||||
int originY = (i / horizontalDisplayed) * scanLinesPerRow;
|
||||
image.getRaster().setPixels(originX, originY, CHAR_WIDTH, scanLinesPerRow, getGlyph(address));
|
||||
try {
|
||||
for (int i = 0; i < crtc.getPageSize(); i++) {
|
||||
int address = crtc.getStartAddress() + i;
|
||||
int originX = (i % horizontalDisplayed) * CHAR_WIDTH;
|
||||
int originY = (i / horizontalDisplayed) * scanLinesPerRow;
|
||||
image.getRaster().setPixels(originX, originY, CHAR_WIDTH, scanLinesPerRow, getGlyph(address));
|
||||
}
|
||||
Graphics2D g2d = (Graphics2D) g;
|
||||
if (shouldScale) {
|
||||
g2d.scale(scaleX, scaleY);
|
||||
}
|
||||
g2d.drawImage(image, 0, 0, null);
|
||||
} catch (MemoryAccessException ex) {
|
||||
logger.log(Level.SEVERE, "Memory Access Exception, can't paint video window! " + ex.getMessage());
|
||||
}
|
||||
Graphics2D g2d = (Graphics2D)g;
|
||||
if (shouldScale) {
|
||||
g2d.scale(scaleX, scaleY);
|
||||
}
|
||||
g2d.drawImage(image, 0, 0, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -115,12 +124,19 @@ public class VideoWindow extends JFrame implements DeviceChangeListener {
|
||||
*/
|
||||
private class CursorBlinker implements Runnable {
|
||||
public void run() {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
if (cursorBlinkRate > 0) {
|
||||
hideCursor = !hideCursor;
|
||||
repaint();
|
||||
}
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
if (cursorBlinkRate > 0) {
|
||||
hideCursor = !hideCursor;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private class WindowPainter implements Runnable {
|
||||
public void run() {
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
if (VideoWindow.this.isVisible()) {
|
||||
VideoWindow.this.repaint();
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -131,8 +147,7 @@ public class VideoWindow extends JFrame implements DeviceChangeListener {
|
||||
|
||||
this.scheduler = Executors.newSingleThreadScheduledExecutor();
|
||||
this.crtc = crtc;
|
||||
this.charRom = loadCharRom("/pet.rom");
|
||||
this.videoRam = crtc.getDmaAccess();
|
||||
this.charRom = loadCharRom();
|
||||
this.scaleX = scaleX;
|
||||
this.scaleY = scaleY;
|
||||
this.shouldScale = (scaleX > 1 || scaleY > 1);
|
||||
@@ -145,6 +160,11 @@ public class VideoWindow extends JFrame implements DeviceChangeListener {
|
||||
TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
scheduler.scheduleAtFixedRate(new WindowPainter(),
|
||||
WINDOW_REPAINT_INTERVAL,
|
||||
WINDOW_REPAINT_INTERVAL,
|
||||
TimeUnit.MILLISECONDS);
|
||||
|
||||
// Capture some state from the CRTC that will define the
|
||||
// window size. When these values change, the window will
|
||||
// need to re-pack and redraw.
|
||||
@@ -158,13 +178,6 @@ public class VideoWindow extends JFrame implements DeviceChangeListener {
|
||||
|
||||
}
|
||||
|
||||
public void refreshDisplay() {
|
||||
// TODO: Verify whether this is necessary. Does `repaint()' do anything if the window is not visible?
|
||||
if (isVisible()) {
|
||||
repaint();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by the CRTC on state change.
|
||||
*/
|
||||
@@ -239,15 +252,13 @@ public class VideoWindow extends JFrame implements DeviceChangeListener {
|
||||
* @param address The address of the character being requested.
|
||||
* @return An array of integers representing the pixel data.
|
||||
*/
|
||||
private int[] getGlyph(int address) {
|
||||
int chr = videoRam[address];
|
||||
private int[] getGlyph(int address) throws MemoryAccessException {
|
||||
int chr = crtc.getCharAtAddress(address);
|
||||
int romOffset = (chr & 0xff) * (CHAR_HEIGHT * CHAR_WIDTH);
|
||||
int[] glyph = new int[CHAR_WIDTH * scanLinesPerRow];
|
||||
|
||||
// Populate the character
|
||||
for (int i = 0; i < (CHAR_WIDTH * Math.min(CHAR_HEIGHT, scanLinesPerRow)); i++) {
|
||||
glyph[i] = charRom[romOffset + i];
|
||||
}
|
||||
arraycopy(charRom, romOffset, glyph, 0, CHAR_WIDTH * Math.min(CHAR_HEIGHT, scanLinesPerRow));
|
||||
|
||||
// Overlay the cursor
|
||||
if (!hideCursor && crtc.isCursorEnabled() && crtc.getCursorPosition() == address) {
|
||||
@@ -276,14 +287,17 @@ public class VideoWindow extends JFrame implements DeviceChangeListener {
|
||||
* Since the BufferedImage is a TYPE_BYTE_BINARY, the data must be converted
|
||||
* into a single byte per pixel, 0 for black and 255 for white.
|
||||
|
||||
* @param resource The ROM file resource to load.
|
||||
* @return An array of glyphs, each ready for insertion.
|
||||
* @throws IOException
|
||||
* @throws IOException Failure to load character ROM.
|
||||
*/
|
||||
private int[] loadCharRom(String resource) throws IOException {
|
||||
BufferedInputStream bis = null;
|
||||
try {
|
||||
bis = new BufferedInputStream(this.getClass().getResourceAsStream(resource));
|
||||
private int[] loadCharRom() throws IOException {
|
||||
var resource = this.getClass().getResourceAsStream(ASCII_ROM);
|
||||
|
||||
if (resource == null) {
|
||||
throw new IOException("Resource " + ASCII_ROM + " not found");
|
||||
}
|
||||
|
||||
try (BufferedInputStream bis = new BufferedInputStream(resource)) {
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
while (bis.available() > 0) {
|
||||
bos.write(bis.read());
|
||||
@@ -298,7 +312,7 @@ public class VideoWindow extends JFrame implements DeviceChangeListener {
|
||||
int[] converted = new int[raw.length * CHAR_WIDTH];
|
||||
|
||||
int romIndex = 0;
|
||||
for (int i = 0; i < converted.length;) {
|
||||
for (int i = 0; i < converted.length; ) {
|
||||
byte charRow = raw[romIndex++];
|
||||
|
||||
for (int j = 7; j >= 0; j--) {
|
||||
@@ -306,10 +320,6 @@ public class VideoWindow extends JFrame implements DeviceChangeListener {
|
||||
}
|
||||
}
|
||||
return converted;
|
||||
} finally {
|
||||
if (bis != null) {
|
||||
bis.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package com.loomcom.symon.ui;
|
||||
|
||||
import com.sun.jna.Library;
|
||||
import com.sun.jna.Native;
|
||||
import com.sun.jna.Pointer;
|
||||
import com.sun.jna.ptr.IntByReference;
|
||||
import com.sun.jna.ptr.PointerByReference;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class X11ResourceReader {
|
||||
|
||||
private final static Logger logger = LoggerFactory.getLogger(X11ResourceReader.class.getName());
|
||||
|
||||
|
||||
public interface X11 extends Library {
|
||||
X11 INSTANCE = Native.load("X11", X11.class);
|
||||
|
||||
Pointer XOpenDisplay(String display);
|
||||
Pointer XResourceManagerString(Pointer display);
|
||||
void XCloseDisplay(Pointer display);
|
||||
}
|
||||
|
||||
public static Double readXftDpiScale() {
|
||||
Pointer display = null;
|
||||
try {
|
||||
display = X11.INSTANCE.XOpenDisplay(null);
|
||||
if (display == null) {
|
||||
return null; // não conseguimos ligar ao X server (ex: Wayland puro sem XWayland)
|
||||
}
|
||||
|
||||
Pointer resourceString = X11.INSTANCE.XResourceManagerString(display);
|
||||
if (resourceString == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
String resources = resourceString.getString(0);
|
||||
for (String line : resources.split("\n")) {
|
||||
if (line.startsWith("Xft.dpi:")) {
|
||||
int dpi = Integer.parseInt(line.split(":")[1].trim());
|
||||
return Math.round((dpi / 96.0) * 4) / 4.0;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
} catch (UnsatisfiedLinkError | Exception e) {
|
||||
logger.debug("Could not read X11 resource manager (libX11 unavailable?)", e);
|
||||
return null;
|
||||
} finally {
|
||||
if (display != null) {
|
||||
X11.INSTANCE.XCloseDisplay(display);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Before Width: | Height: | Size: 191 B |
|
Before Width: | Height: | Size: 196 B |
|
Before Width: | Height: | Size: 192 B |
|
Before Width: | Height: | Size: 183 B |
|
Before Width: | Height: | Size: 198 B |
|
Before Width: | Height: | Size: 192 B |
|
Before Width: | Height: | Size: 198 B |
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2008-2013 Seth J. Morabito <sethm@loomcom.com>
|
||||
* Copyright (c) 2008-2025 Seth J. Morabito <web@loomcom.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
@@ -34,11 +34,11 @@ import java.util.Queue;
|
||||
*/
|
||||
public class FifoRingBuffer<E> implements Iterable<E> {
|
||||
|
||||
private Queue<E> fifoBuffer;
|
||||
private int maxLength;
|
||||
private final Queue<E> fifoBuffer;
|
||||
private final int maxLength;
|
||||
|
||||
public FifoRingBuffer(int maxLength) {
|
||||
this.fifoBuffer = new LinkedList<E>();
|
||||
this.fifoBuffer = new LinkedList<>();
|
||||
this.maxLength = maxLength;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2008-2013 Seth J. Morabito <sethm@loomcom.com>
|
||||
* Copyright (c) 2008-2025 Seth J. Morabito <web@loomcom.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
@@ -24,24 +24,9 @@
|
||||
package com.loomcom.symon.util;
|
||||
|
||||
/**
|
||||
* Hex String Utilities.
|
||||
*
|
||||
* <p/>
|
||||
*
|
||||
* But why? Java, after all, has a number of ways to convert an integer into a hex string,
|
||||
* so it may look absurd to go to the trouble of writing yet another conversion! The answer is
|
||||
* performance.
|
||||
*
|
||||
* <p/>
|
||||
*
|
||||
* The most convenient way to get a formatted hex value from an integer is with the <code>String.format</code>
|
||||
* method, but this turns out to be extremely inefficient. Formatting a million integers
|
||||
* with <code>String.format</code> takes something like 1600ms. Formatting the same number of integers
|
||||
* with <code>HexUtil</code> takes only 160ms. This is on par with <code>Integer.toHexString</code>,
|
||||
* but also gives the desired padding.
|
||||
*
|
||||
* Various Utilities
|
||||
*/
|
||||
public class HexUtil {
|
||||
public class Utils {
|
||||
|
||||
static final String NON_PRINTABLE = ".";
|
||||
|
||||
@@ -91,8 +76,19 @@ public class HexUtil {
|
||||
"F0", "F1", "F2", "F3", "F4", "F5", "F6", "F7",
|
||||
"F8", "F9", "FA", "FB", "FC", "FD", "FE", "FF"};
|
||||
|
||||
private static final String[] BIN_CONSTANTS = new String[256];
|
||||
|
||||
static {
|
||||
for (int i = 0; i < 256; i++) {
|
||||
String bin = Integer.toBinaryString(i);
|
||||
// Left-pad to 8 digits with zeros
|
||||
BIN_CONSTANTS[i] = "00000000".substring(bin.length()) + bin;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Very fast 8-bit int to ASCII conversion.
|
||||
*
|
||||
* @param val The value of an ASCII character.
|
||||
* @return A string representing the ASCII character.
|
||||
*/
|
||||
@@ -121,9 +117,23 @@ public class HexUtil {
|
||||
* @return Four digit, zero padded hexadecimal string.
|
||||
*/
|
||||
public static String wordToHex(int val) {
|
||||
StringBuilder sb = new StringBuilder(4);
|
||||
sb.append(HEX_CONSTANTS[(val >> 8) & 0xff]);
|
||||
sb.append(HEX_CONSTANTS[val & 0xff]);
|
||||
return sb.toString();
|
||||
return HEX_CONSTANTS[(val >> 8) & 0xff] + HEX_CONSTANTS[val & 0xff];
|
||||
}
|
||||
|
||||
/**
|
||||
* Given two bytes, return an address.
|
||||
*/
|
||||
public static int address(int lowByte, int hiByte) {
|
||||
return ((hiByte << 8) | lowByte) & 0xffff;
|
||||
}
|
||||
|
||||
/**
|
||||
* Very fast 8-bit int to binary conversion, with zero-padded output.
|
||||
*
|
||||
* @param val The unsigned 8-bit value to convert to a zero padded binary string.
|
||||
* @return Eight digit, zero padded binary string.
|
||||
*/
|
||||
public static String byteToBin(int val) {
|
||||
return BIN_CONSTANTS[val & 0xff];
|
||||
}
|
||||
}
|
||||
|
After Width: | Height: | Size: 220 B |
|
Before Width: | Height: | Size: 191 B After Width: | Height: | Size: 191 B |
|
After Width: | Height: | Size: 232 B |
|
Before Width: | Height: | Size: 196 B After Width: | Height: | Size: 196 B |