2021-07-23 01:16:23 +00:00
|
|
|
//
|
|
|
|
// Chipset.hpp
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 22/07/2021.
|
|
|
|
// Copyright © 2021 Thomas Harte. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef Chipset_hpp
|
|
|
|
#define Chipset_hpp
|
|
|
|
|
|
|
|
#include <cstddef>
|
|
|
|
#include <cstdint>
|
|
|
|
|
|
|
|
#include "../../Processors/68000/68000.hpp"
|
2021-07-26 22:44:20 +00:00
|
|
|
#include "../../Outputs/CRT/CRT.hpp"
|
2021-07-23 01:16:23 +00:00
|
|
|
|
|
|
|
#include "Blitter.hpp"
|
|
|
|
|
|
|
|
namespace Amiga {
|
|
|
|
|
|
|
|
class Chipset {
|
|
|
|
public:
|
|
|
|
Chipset(uint16_t *ram, size_t size);
|
|
|
|
|
2021-07-24 01:24:07 +00:00
|
|
|
struct Changes {
|
|
|
|
int hsyncs = 0;
|
|
|
|
int vsyncs = 0;
|
2021-07-26 20:40:42 +00:00
|
|
|
int interrupt_level = 0;
|
2021-07-27 00:13:06 +00:00
|
|
|
HalfCycles duration;
|
2021-08-09 01:52:28 +00:00
|
|
|
|
|
|
|
Changes &operator += (const Changes &rhs) {
|
|
|
|
hsyncs += rhs.hsyncs;
|
|
|
|
vsyncs += rhs.vsyncs;
|
|
|
|
duration += rhs.duration;
|
|
|
|
return *this;
|
|
|
|
}
|
2021-07-24 01:24:07 +00:00
|
|
|
};
|
|
|
|
|
2021-07-27 20:41:18 +00:00
|
|
|
/// Advances the stated amount of time.
|
|
|
|
Changes run_for(HalfCycles);
|
|
|
|
|
|
|
|
/// Advances to the next available CPU slot.
|
|
|
|
Changes run_until_cpu_slot();
|
2021-07-23 01:16:23 +00:00
|
|
|
|
|
|
|
/// Performs the provided microcycle, which the caller guarantees to be a memory access.
|
|
|
|
void perform(const CPU::MC68000::Microcycle &);
|
|
|
|
|
2021-07-28 23:36:30 +00:00
|
|
|
/// Sets the current state of the CIA interrupt lines.
|
|
|
|
void set_cia_interrupts(bool cia_a, bool cia_b);
|
|
|
|
|
2021-07-26 20:40:42 +00:00
|
|
|
/// Provides the chipset's current interrupt level.
|
|
|
|
int get_interrupt_level() {
|
|
|
|
return interrupt_level_;
|
|
|
|
}
|
|
|
|
|
2021-07-26 22:44:20 +00:00
|
|
|
// The standard CRT set.
|
|
|
|
void set_scan_target(Outputs::Display::ScanTarget *scan_target);
|
|
|
|
Outputs::Display::ScanStatus get_scaled_scan_status() const;
|
|
|
|
void set_display_type(Outputs::Display::DisplayType);
|
|
|
|
Outputs::Display::DisplayType get_display_type() const;
|
|
|
|
|
2021-07-23 01:16:23 +00:00
|
|
|
private:
|
|
|
|
// MARK: - Interrupts.
|
|
|
|
|
|
|
|
uint16_t interrupt_enable_ = 0;
|
|
|
|
uint16_t interrupt_requests_ = 0;
|
2021-07-26 20:40:42 +00:00
|
|
|
int interrupt_level_ = 0;
|
2021-07-23 01:16:23 +00:00
|
|
|
|
2021-07-26 20:40:42 +00:00
|
|
|
void update_interrupts();
|
2021-07-23 01:16:23 +00:00
|
|
|
|
2021-07-27 20:41:18 +00:00
|
|
|
// MARK: - Scheduler.
|
|
|
|
|
2021-08-09 01:52:28 +00:00
|
|
|
template <bool stop_on_cpu> Changes run(HalfCycles duration = HalfCycles::max());
|
2021-07-28 01:59:27 +00:00
|
|
|
template <bool stop_on_cpu> int advance_slots(int, int);
|
2021-07-27 20:41:18 +00:00
|
|
|
template <int cycle, bool stop_if_cpu> bool perform_cycle();
|
2021-07-28 01:33:07 +00:00
|
|
|
template <int cycle> void output();
|
2021-07-27 20:41:18 +00:00
|
|
|
|
|
|
|
// MARK: - DMA Control, Scheduler and Blitter.
|
2021-07-23 01:16:23 +00:00
|
|
|
|
|
|
|
uint16_t dma_control_ = 0;
|
|
|
|
Blitter blitter_;
|
|
|
|
|
|
|
|
// MARK: - Sprites.
|
|
|
|
|
|
|
|
struct Sprite {
|
|
|
|
void set_pointer(int shift, uint16_t value);
|
|
|
|
void set_start_position(uint16_t value);
|
|
|
|
void set_stop_and_control(uint16_t value);
|
|
|
|
void set_image_data(int slot, uint16_t value);
|
|
|
|
} sprites_[8];
|
2021-07-23 01:45:51 +00:00
|
|
|
|
|
|
|
// MARK: - Raster.
|
|
|
|
|
2021-07-27 20:41:18 +00:00
|
|
|
int line_cycle_ = 0, y_ = 0;
|
2021-07-28 01:33:07 +00:00
|
|
|
int line_length_ = 227;
|
2021-07-26 22:44:20 +00:00
|
|
|
int frame_height_ = 312;
|
2021-07-26 22:51:01 +00:00
|
|
|
int vertical_blank_height_ = 29;
|
2021-07-23 02:00:53 +00:00
|
|
|
|
|
|
|
uint16_t display_window_start_[2] = {0, 0};
|
|
|
|
uint16_t display_window_stop_[2] = {0, 0};
|
|
|
|
uint16_t fetch_window_[2] = {0, 0};
|
2021-07-26 22:44:20 +00:00
|
|
|
|
|
|
|
// MARK: - Copper.
|
|
|
|
|
2021-07-27 23:06:16 +00:00
|
|
|
class Copper {
|
|
|
|
public:
|
|
|
|
Copper(Chipset &chipset, uint16_t *ram, size_t size) : chipset_(chipset), ram_(ram), ram_mask_(uint32_t(size - 1)) {}
|
|
|
|
|
|
|
|
/// Offers a DMA slot to the Copper, specifying the current beam position.
|
|
|
|
///
|
|
|
|
/// @returns @c true if the slot was used; @c false otherwise.
|
|
|
|
bool advance(uint16_t position);
|
|
|
|
|
2021-07-28 01:10:14 +00:00
|
|
|
/// Forces a reload of address @c id (i.e. 0 or 1) and restarts the Copper.
|
2021-07-27 23:06:16 +00:00
|
|
|
void reload(int id) {
|
2021-07-28 01:10:14 +00:00
|
|
|
address_ = addresses_[id] >> 1;
|
2021-07-27 23:06:16 +00:00
|
|
|
state_ = State::FetchFirstWord;
|
|
|
|
}
|
|
|
|
|
2021-07-28 01:10:14 +00:00
|
|
|
/// Writes the word @c value to the address register @c id, shifting it by @c shift (0 or 16) first.
|
2021-07-27 23:06:16 +00:00
|
|
|
template <int id, int shift> void set_address(uint16_t value) {
|
2021-07-28 01:10:14 +00:00
|
|
|
addresses_[id] = (addresses_[id] & (0xffff'0000 >> shift)) | uint32_t(value << shift);
|
2021-07-27 23:06:16 +00:00
|
|
|
}
|
|
|
|
|
2021-07-28 01:10:14 +00:00
|
|
|
/// Sets the Copper control word.
|
2021-07-27 23:06:16 +00:00
|
|
|
void set_control(uint16_t c) {
|
|
|
|
control_ = c;
|
|
|
|
}
|
|
|
|
|
2021-07-28 01:10:14 +00:00
|
|
|
/// Forces the Copper into the stopped state.
|
2021-07-27 23:06:16 +00:00
|
|
|
void stop() {
|
|
|
|
state_ = State::Stopped;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
Chipset &chipset_;
|
|
|
|
|
2021-07-28 01:10:14 +00:00
|
|
|
uint32_t address_ = 0;
|
|
|
|
uint32_t addresses_[2]{};
|
2021-07-27 23:06:16 +00:00
|
|
|
uint16_t control_ = 0;
|
|
|
|
|
|
|
|
enum class State {
|
|
|
|
FetchFirstWord, FetchSecondWord, Waiting, Stopped,
|
|
|
|
} state_ = State::Stopped;
|
|
|
|
bool skip_next_ = false;
|
2021-07-28 01:10:14 +00:00
|
|
|
uint16_t instruction_[2]{};
|
|
|
|
uint16_t position_mask_ = 0xffff;
|
2021-07-27 23:06:16 +00:00
|
|
|
|
|
|
|
uint16_t *ram_ = nullptr;
|
|
|
|
uint32_t ram_mask_ = 0;
|
|
|
|
} copper_;
|
2021-07-30 22:24:27 +00:00
|
|
|
|
|
|
|
// MARK: - Serial port.
|
|
|
|
|
|
|
|
class SerialPort {
|
|
|
|
public:
|
|
|
|
void set_control(uint16_t) {}
|
|
|
|
|
|
|
|
private:
|
|
|
|
uint16_t value = 0, reload = 0;
|
|
|
|
uint16_t shift = 0, receive_shift = 0;
|
|
|
|
uint16_t status;
|
|
|
|
} serial_;
|
2021-07-26 22:44:20 +00:00
|
|
|
|
|
|
|
// MARK: - Pixel output.
|
|
|
|
|
|
|
|
Outputs::CRT::CRT crt_;
|
2021-07-26 22:59:11 +00:00
|
|
|
uint16_t palette_[32]{};
|
2021-07-23 01:16:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* Chipset_hpp */
|