Skip to content

Commit

Permalink
Working toward CP/M support.
Browse files Browse the repository at this point in the history
  • Loading branch information
magnetrwn committed Nov 8, 2024
1 parent 43c1eba commit d5c2a0d
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 27 deletions.
2 changes: 1 addition & 1 deletion src/core/bus/bus.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class bus {
inline void insert(card* card, usize slot, bool allow_conflict = false) {
if (!card)
throw std::invalid_argument("cannot insert nullptr");
if (slot >= MAX_BUS_CARDS)
if (slot > MAX_BUS_CARDS)
throw std::out_of_range("slot out of range");
if (cards[slot] != NO_CARD)
throw std::invalid_argument("slot already occupied");
Expand Down
3 changes: 1 addition & 2 deletions src/core/bus/card.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,7 @@ class data_card : public card {
data_card(u16 start_adr, T begin, T end, bool lock = construct_then_write_lock)
: start_adr(start_adr), capacity(std::distance(begin, end)) {

static_assert(std::is_same_v<typename std::iterator_traits<T>::value_type, u8>,
"Iterator value type must be u8.");
static_assert(std::is_same_v<typename std::iterator_traits<T>::value_type, u8>, "Iterator value type must be u8.");

data.reserve(capacity);
std::copy(begin, end, data.begin());
Expand Down
4 changes: 2 additions & 2 deletions src/ux/ux.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class emulator {
}
}

std::string get_bus_map_s() const { return cardbus.bus_map_s(); }
std::string info() const { return cardbus.bus_map_s(); }

emulator(const char* config_filename)
: conf(config_filename),
Expand All @@ -65,7 +65,7 @@ struct terminal_ux {
int main(int argc, char** argv) {
std::cout << "\x1B[33;01m-:-:-:-:- emulator setup -:-:-:-:-\x1B[0m" << std::endl;

std::cout << emu.get_bus_map_s();
std::cout << emu.info();
emu.setup(argc, argv);

std::cout << "\x1B[33;01m-:-:-:-:- emulator run -:-:-:-:-\x1B[0m" << std::endl;
Expand Down
70 changes: 50 additions & 20 deletions static/config.toml
Original file line number Diff line number Diff line change
@@ -1,39 +1,69 @@
# Configuration file for the emulator.
# This file is loaded by the emulator to understand how to configure the system.
############################################################################################################
# Configuration file for the emulator. #
# This file is loaded by the emulator to understand how to configure the system. #
############################################################################################################

# -------------------------------------------- GENERAL SETUP --------------------------------------------- #

[emulator]
pseudo_bdos_enabled = true # Redirect and handle calls that match addresses of BDOS calls.
start_with_pc_at = 0x0100 # Start the program counter at this address. Note that this bypasses the reset vector. 0 to disable.

# List of cards here, make sure to append cards you wish to add. Available parameters are:
# - slot: Slot number of the card [0, 18], which also determines IRQ priority (lower is higher priority).
# - type: Type of the card. Available types are: "ram", "rom", "serial".
# - load: Path to the file to load into the card. Only for "ram" or "rom" type.
# (you can omit this if using range, as it will automatically set the closest bigger power of 2 size)
# - at: Address of the card in the memory space.
# - range: Size or address range (like I/O register count) of the card in bytes.
# (you can omit this if using load)
# - let_collide: Allow the card to have overlapping address range with other cards.
#
# IMPORTANT: cards can be de/activated by the IORQ signal according to them being memory or I/O, so
# you might not need to enable overlapping, as overlap of I/O and memory is expected.
# Only use this in case of overlap of the same type of card (e.g. two RAM cards).
#
# Note: there is (usually) a limit of 18 cards in the system. Lower slot number means higher IRQ priority.
start_with_pc_at = 0x0100 # Start the program counter at this address. Note that this bypasses the reset vector. 0 or comment to disable.

############################################################################################################
# List of cards here, make sure to append cards you wish to add. Available parameters are: #
# - slot: Slot number of the card [0, 18], which also determines IRQ priority (lower is higher priority). #
# - type: Type of the card. Available types are: "ram", "rom", "serial". #
# - load: Path to the file to load into the card. Only for "ram" or "rom" type. #
# (you can omit this if using range, as it will automatically set the closest bigger power of 2 size) #
# - at: Address of the card in the memory space. #
# - range: Size or address range (like I/O register count) of the card in bytes. #
# (you can omit this if using load) #
# - let_collide: Allow the card to have overlapping address range with other cards. #
# #
# IMPORTANT: cards can be de/activated by the IORQ signal according to them being memory or I/O, so #
# you might not need to enable overlapping, as overlap of I/O and memory is expected. #
# Only use this in case of overlap of the same type of card (e.g. two RAM cards). #
# #
# Note: there is (usually) a limit of 18 cards in the system. Lower slot number means higher IRQ priority. #
############################################################################################################

# -------------------------------------------- CP/M ROM CARDS -------------------------------------------- #

# [[card]] # CP/M 2.2 BIOS
# slot = 0
# type = "rom"
# at = 0x0000
# load = "static/bios22.bin"
#
# [[card]] # CP/M 2.2 BDOS
# slot = 1
# type = "rom"
# at = 0x8000
# load = "static/bdos22.bin"
#
# [[card]] # CP/M 2.2 CCP
# slot = 2
# type = "rom"
# at = 0xC000
# load = "static/ccp22.bin"

# ------------------------------------------ I/O HARDWARE CARDS ------------------------------------------ #

[[card]] # 88-SIO serial interface
slot = 10
type = "serial"
at = 0x10

# -------------------------------------------- SOFTWARE CARDS -------------------------------------------- #

[[card]] # Diagnostics II expects to be loaded in RAM
slot = 3
type = "ram"
at = 0x0100
load = "tests/res/diag2.com"

[[card]] # Cover all memory space with RAM just in case
slot = 4
slot = 17
type = "ram"
at = 0x0000
range = 65536
Expand Down
15 changes: 13 additions & 2 deletions tests/test_pty.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
#include "pty.hpp"

constexpr static usize BUFFER_SIZE = 1024;
constexpr static usize ROUNDS = 51;
constexpr static usize ROUNDS = 384;
constexpr static usize USEC_DELAY_SERIAL_PTY = 110;

inline const char* random_string(usize length) {
static std::random_device rd;
Expand Down Expand Up @@ -109,14 +110,24 @@ TEST_CASE("Pseudo-terminal operation test", "[pty]") {
isize bytes_written = write(slave_fd, message, std::strlen(message));
REQUIRE(bytes_written == static_cast<isize>(std::strlen(message)));

usleep(100 * (ROUNDS - i));
usleep(USEC_DELAY_SERIAL_PTY);
REQUIRE(pty_instance.poll());

for (usize j = 0; pty_instance.poll(); ++j)
REQUIRE(message[j] == pty_instance.getch());

REQUIRE(!pty_instance.poll());
}

for (char c = 1; c > 0; ++c) {
isize bytes_written = write(slave_fd, &c, 1);
REQUIRE(bytes_written == 1);

usleep(USEC_DELAY_SERIAL_PTY);
REQUIRE(pty_instance.poll());
REQUIRE(pty_instance.getch() == c);
REQUIRE(!pty_instance.poll());
}
}

close(slave_fd);
Expand Down

0 comments on commit d5c2a0d

Please sign in to comment.