1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-12-25 03:32:01 +00:00

Adds just enough logic to make every host key look like '0' to the MSX.

This commit is contained in:
Thomas Harte 2017-11-29 22:07:30 -05:00
parent ee84f33ab5
commit 54c845b6e2
4 changed files with 104 additions and 3 deletions

14
Machines/MSX/Keyboard.cpp Normal file
View File

@ -0,0 +1,14 @@
//
// Keyboard.cpp
// Clock Signal
//
// Created by Thomas Harte on 29/11/2017.
// Copyright © 2017 Thomas Harte. All rights reserved.
//
#include "Keyboard.hpp"
uint16_t MSX::KeyboardMapper::mapped_key_for_key(Inputs::Keyboard::Key key) {
// TODO: actual keyboard map.
return 0;
}

42
Machines/MSX/Keyboard.hpp Normal file
View File

@ -0,0 +1,42 @@
//
// Keyboard.hpp
// Clock Signal
//
// Created by Thomas Harte on 29/11/2017.
// Copyright © 2017 Thomas Harte. All rights reserved.
//
#ifndef Machines_MSX_Keyboard_hpp
#define Machines_MSX_Keyboard_hpp
#include "../KeyboardMachine.hpp"
namespace MSX {
enum Key: uint16_t {
#define Line(l, k1, k2, k3, k4, k5, k6, k7, k8) \
k1 = (l << 4) | 0x07, k2 = (l << 4) | 0x06, k3 = (l << 4) | 0x05, k4 = (l << 4) | 0x04,\
k5 = (l << 4) | 0x03, k6 = (l << 4) | 0x02, k7 = (l << 4) | 0x01, k8 = (l << 4) | 0x00,
Line(0, Key7, Key6, Key5, Key4, Key3, Key2, Key1, Key0)
Line(1, KeySemicolon, KeyRightSquareBracket, KeyLeftSquareBracket, KeyBackSlash, KeyEquals, KeyMinus, Key9, Key8)
Line(2, KeyB, KeyA, KeyNA, KeyForwardSlash, KeyFullStop, KeyComma, KeyQuote, KeyGrave)
Line(3, KeyJ, KeyI, KeyH, KeyG, KeyF, KeyE, KeyD, KeyC)
Line(4, KeyR, KeyQ, KeyP, KeyO, KeyN, KeyM, KeyL, KeyK)
Line(5, KeyZ, KeyY, KeyX, KeyW, KeyV, KeyU, KeyT, KeyS)
Line(6, KeyF3, KeyF2, KeyF1, KeyCode, KeyCaps, KeyGraph, KeyControl, KeyShift)
Line(7, KeyEnter, KeySelect, KeyBackspace, KeyStop, KeyTab, KeyEscape, KeyF5, KeyF4)
Line(8, KeyRight, KeyDown, KeyUp, KeyLeft, KeyDelete, KeyInsert, KeyHome, KeySpace)
Line(9, KeyNumpad4, KeyNumpad3, KeyNumpad2, KeyNumpad1, KeyNumpad0, KeyNumpadDivide, KeyNumpadAdd, KeyNumpadMultiply)
Line(10, KeyNumpadDecimal, KeyNumpadComma, KeyNumpadSubtract, KeyNumpad9, KeyNumpad8, KeyNumpad7, KeyNumpad6, KeyNumpad5)
#undef Line
};
struct KeyboardMapper: public KeyboardMachine::Machine::KeyboardMapper {
uint16_t mapped_key_for_key(Inputs::Keyboard::Key key);
};
};
#endif /* Machines_MSX_Keyboard_hpp */

View File

@ -8,6 +8,8 @@
#include "MSX.hpp"
#include "Keyboard.hpp"
#include "../../Processors/Z80/Z80.hpp"
#include "../../Components/1770/1770.hpp"
@ -17,6 +19,7 @@
#include "../CRTMachine.hpp"
#include "../ConfigurationTarget.hpp"
#include "../KeyboardMachine.hpp"
namespace MSX {
@ -35,7 +38,8 @@ class ConcreteMachine:
public Machine,
public CPU::Z80::BusHandler,
public CRTMachine::Machine,
public ConfigurationTarget::Machine {
public ConfigurationTarget::Machine,
public KeyboardMachine::Machine {
public:
ConcreteMachine():
z80_(*this),
@ -44,6 +48,7 @@ class ConcreteMachine:
ay_.set_port_handler(&ay_port_handler_);
set_clock_rate(3579545);
std::memset(unpopulated_, 0xff, sizeof(unpopulated_));
clear_all_keys();
}
void setup_output(float aspect_ratio) override {
@ -199,6 +204,28 @@ class ConcreteMachine:
return true;
}
void set_keyboard_line(int line) {
selected_key_line_ = line;
}
uint8_t read_keyboard() {
return key_states_[selected_key_line_];
}
void clear_all_keys() override {
std::memset(key_states_, 0xff, sizeof(key_states_));
}
void set_key_state(uint16_t key, bool is_pressed) override {
int mask = 1 << (key & 7);
int line = key >> 4;
if(is_pressed) key_states_[line] &= ~mask; else key_states_[line] |= mask;
}
KeyboardMapper &get_keyboard_mapper() override {
return keyboard_mapper_;
}
private:
class i8255PortHandler: public Intel::i8255::PortHandler {
public:
@ -208,7 +235,12 @@ class ConcreteMachine:
switch(port) {
case 0: machine_.page_memory(value); break;
case 2:
printf("?? Select keyboard row, etc: %02x\n", value);
// TODO:
// b7 keyboard click
// b6 caps lock LED
// b5 audio output
// b4 cassette motor relay
machine_.set_keyboard_line(value & 0xf);
break;
default: break;
}
@ -216,7 +248,7 @@ class ConcreteMachine:
uint8_t get_value(int port) {
if(port == 1) {
printf("?? Read keyboard\n");
return machine_.read_keyboard();
} else printf("What what?\n");
return 0xff;
}
@ -246,6 +278,11 @@ class ConcreteMachine:
HalfCycles time_since_vdp_update_;
HalfCycles time_until_interrupt_;
uint8_t key_states_[16];
int selected_key_line_ = 0;
MSX::KeyboardMapper keyboard_mapper_;
};
}

View File

@ -137,6 +137,8 @@
4B0E04FB1FC9FA3100F43484 /* 9918.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B0E04F91FC9FA3100F43484 /* 9918.cpp */; };
4B121F951E05E66800BFDA12 /* PCMPatchedTrackTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4B121F941E05E66800BFDA12 /* PCMPatchedTrackTests.mm */; };
4B121F9B1E06293F00BFDA12 /* PCMSegmentEventSourceTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4B121F9A1E06293F00BFDA12 /* PCMSegmentEventSourceTests.mm */; };
4B12C0ED1FCFA98D005BFD93 /* Keyboard.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B12C0EB1FCFA98D005BFD93 /* Keyboard.cpp */; };
4B12C0EE1FCFAD1A005BFD93 /* Keyboard.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B12C0EB1FCFA98D005BFD93 /* Keyboard.cpp */; };
4B1414601B58885000E04248 /* WolfgangLorenzTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B14145F1B58885000E04248 /* WolfgangLorenzTests.swift */; };
4B1414621B58888700E04248 /* KlausDormannTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B1414611B58888700E04248 /* KlausDormannTests.swift */; };
4B1497881EE4A1DA00CE2596 /* ZX80O81P.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B1497861EE4A1DA00CE2596 /* ZX80O81P.cpp */; };
@ -645,6 +647,8 @@
4B0E04F91FC9FA3100F43484 /* 9918.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = 9918.cpp; path = 9918/9918.cpp; sourceTree = "<group>"; };
4B121F941E05E66800BFDA12 /* PCMPatchedTrackTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = PCMPatchedTrackTests.mm; sourceTree = "<group>"; };
4B121F9A1E06293F00BFDA12 /* PCMSegmentEventSourceTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = PCMSegmentEventSourceTests.mm; sourceTree = "<group>"; };
4B12C0EB1FCFA98D005BFD93 /* Keyboard.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = Keyboard.cpp; path = MSX/Keyboard.cpp; sourceTree = "<group>"; };
4B12C0EC1FCFA98D005BFD93 /* Keyboard.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; name = Keyboard.hpp; path = MSX/Keyboard.hpp; sourceTree = "<group>"; };
4B1414501B58848C00E04248 /* ClockSignal-Bridging-Header.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "ClockSignal-Bridging-Header.h"; sourceTree = "<group>"; };
4B14145F1B58885000E04248 /* WolfgangLorenzTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WolfgangLorenzTests.swift; sourceTree = "<group>"; };
4B1414611B58888700E04248 /* KlausDormannTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KlausDormannTests.swift; sourceTree = "<group>"; };
@ -1936,6 +1940,8 @@
children = (
4B79A4FF1FC913C900EEDAD5 /* MSX.cpp */,
4B79A5001FC913C900EEDAD5 /* MSX.hpp */,
4B12C0EB1FCFA98D005BFD93 /* Keyboard.cpp */,
4B12C0EC1FCFA98D005BFD93 /* Keyboard.hpp */,
);
name = MSX;
sourceTree = "<group>";
@ -3207,6 +3213,7 @@
4B055AB61FAE860F0060FFFF /* TapeUEF.cpp in Sources */,
4B055A9D1FAE85DA0060FFFF /* D64.cpp in Sources */,
4B055ABB1FAE86170060FFFF /* Oric.cpp in Sources */,
4B12C0EE1FCFAD1A005BFD93 /* Keyboard.cpp in Sources */,
4B055AE81FAE9B7B0060FFFF /* FIRFilter.cpp in Sources */,
4B055A901FAE85A90060FFFF /* TimedEventLoop.cpp in Sources */,
4B055AAB1FAE85FD0060FFFF /* PCMPatchedTrack.cpp in Sources */,
@ -3370,6 +3377,7 @@
4B71368E1F788112008B8ED9 /* Parser.cpp in Sources */,
4BE77A2E1D84ADFB00BC3827 /* File.cpp in Sources */,
4B14978B1EE4AC5E00CE2596 /* StaticAnalyser.cpp in Sources */,
4B12C0ED1FCFA98D005BFD93 /* Keyboard.cpp in Sources */,
4BA0F68E1EEA0E8400E9489E /* ZX8081.cpp in Sources */,
4BD468F71D8DF41D0084958B /* 1770.cpp in Sources */,
4BD3A30B1EE755C800B5B501 /* Video.cpp in Sources */,