-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added C64 keyboard simulator part and added some initial mapping.
- Loading branch information
1 parent
a31093d
commit ad7e653
Showing
9 changed files
with
212 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#ifndef __AMIGA_KEYB_CODES_H__ | ||
#define __AMIGA_KEYB_CODES_H__ | ||
|
||
enum AmigaKey { | ||
AmigaKey_A = 0x20, | ||
AmigaKey_B = 0x35, | ||
AmigaKey_P = 0x19, | ||
AmigaKey_Space = 0x40, | ||
AmigaKey_Return = 0x44, | ||
|
||
//Special | ||
AmigaKey_ResetWarning = 0x78, | ||
AmigaKey_LastKeyCodeBad = 0xf9, | ||
AmigaKey_OutputBufferOverflow = 0xfa, | ||
AmigaKey_SelftestFailed = 0xfc, | ||
AmigaKey_InitiatePowerUpStream = 0xfd, | ||
AmigaKey_TerminatePowerUpStream = 0xfe, | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#include <avr/io.h> | ||
#include <avr/interrupt.h> | ||
#include <util/delay.h> | ||
#include <stdbool.h> | ||
|
||
#define KEYB_IN PIND | ||
#define KEYB_OUT PORTD | ||
#define KEYB_DDR DDRD | ||
#define KEYB_CLK PIND2 | ||
#define KEYB_DAT PIND3 | ||
#define KEYB_MASK (_BV(KEYB_DAT) | _BV(KEYB_CLK)) | ||
|
||
static volatile uint8_t keyboardData = 0xff; | ||
static void (*changeCallback)(uint8_t, bool) = 0; | ||
|
||
ISR (PCINT3_vect) { | ||
static uint8_t tmpData = 0x00; | ||
static uint8_t bitPos = 6; | ||
|
||
if (bit_is_clear(KEYB_IN, KEYB_CLK)) { | ||
tmpData |= ((bit_is_clear(KEYB_IN, KEYB_DAT) ? 1 : 0) << bitPos); | ||
if(7 == bitPos) { | ||
keyboardData = tmpData; | ||
if(0 != changeCallback) { | ||
changeCallback(tmpData & 0x7f, tmpData & 0x80); | ||
} | ||
tmpData = 0x00; | ||
} | ||
bitPos--; | ||
bitPos &= 7; // Wrap -> 7 | ||
} | ||
else { | ||
if (6 == bitPos) { | ||
KEYB_OUT &= ~_BV(KEYB_DAT); // Disable pull-up and set to zero/low if used for output | ||
KEYB_DDR |= _BV(KEYB_DAT); // Set to output | ||
_delay_us(85); | ||
KEYB_DDR &= ~_BV(KEYB_DAT); // Set to input | ||
KEYB_OUT |= _BV(KEYB_DAT); // Enable pull-up | ||
} | ||
} | ||
} | ||
|
||
void amiga_keyb_if_init() { | ||
KEYB_DDR &= ~KEYB_MASK; | ||
KEYB_OUT |= KEYB_MASK; //Pullup | ||
|
||
PCICR |= _BV(PCIE3); | ||
PCMSK3 |= _BV(PCINT26); | ||
sei(); | ||
} | ||
|
||
uint8_t amiga_keyb_if_getKey() { | ||
return keyboardData; | ||
} | ||
|
||
void amiga_keyb_if_registerChangeCallback(void (*newChangeCallback)(uint8_t, bool)) { | ||
changeCallback = newChangeCallback; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#ifndef __AMIGA_KEYB_IF_H__ | ||
#define __AMIGA_KEYB_IF_H__ | ||
|
||
void amiga_keyb_if_init(); | ||
uint8_t amiga_keyb_if_getKey(); | ||
void amiga_keyb_if_registerChangeCallback(void (*)(uint8_t, bool)); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#ifndef __C64_KEYB_CODES_H__ | ||
#define __C64_KEYB_CODES_H__ | ||
|
||
enum C64Key { | ||
C64Key_A = 0x12, | ||
C64Key_B = 0x34, | ||
C64Key_P = 0x51, | ||
C64Key_Space = 0x74, | ||
C64Key_Return = 0x01, | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#include <avr/io.h> | ||
#include <avr/interrupt.h> | ||
#include <stdbool.h> | ||
|
||
#define KEYB_COLS_IN PINA | ||
#define KEYB_COLS_OUT PINA | ||
#define KEYB_COLS_DDR DDRA | ||
#define KEYB_ROWS_IN PINC | ||
#define KEYB_ROWS_OUT PORTC | ||
#define KEYB_ROWS_DDR DDRC | ||
|
||
static uint8_t rowState[256] = {0}; | ||
|
||
ISR (PCINT0_vect) { | ||
KEYB_ROWS_DDR = rowState[KEYB_COLS_IN]; | ||
} | ||
|
||
void c64_keyb_sim_init() { | ||
KEYB_COLS_DDR = 0x00; //Input | ||
KEYB_COLS_OUT = 0xff; //Pullup | ||
|
||
KEYB_ROWS_DDR = 0x00; //Input | ||
KEYB_ROWS_OUT = 0x00; //Output zero whenever set to output | ||
|
||
PCICR |= _BV(PCIE0); | ||
PCMSK0 = 0xff; // Generate input on all COLS | ||
sei(); | ||
} | ||
|
||
void c64_keyb_sim_setKey(uint8_t c64Key, bool up) { | ||
const uint8_t column = c64Key >> 4; | ||
const uint8_t rowData = 1 << (c64Key & 0x7); | ||
uint16_t i; | ||
|
||
for(i = 0; i < 256; i++) { | ||
if(i & (1 << column)) { | ||
if(up) { | ||
rowState[(uint8_t)~i] &= ~rowData; | ||
} | ||
else { | ||
rowState[(uint8_t)~i] |= rowData; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#ifndef __C64_KEYBOARD_SIMULATOR__ | ||
#define __C64_KEYBOARD_SIMULATOR__ | ||
|
||
void c64_keyb_sim_init(); | ||
void c64_keyb_sim_setKey(uint8_t c64Key, bool up); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#include <avr/io.h> | ||
#include <stdio.h> | ||
#define BAUD 115200 | ||
#include <util/setbaud.h> | ||
|
||
void uart_init(void) { | ||
UBRR0H = UBRRH_VALUE; | ||
UBRR0L = UBRRL_VALUE; | ||
|
||
#if USE_2X | ||
UCSR0A |= _BV(U2X0); | ||
#else | ||
UCSR0A &= ~(_BV(U2X0)); | ||
#endif | ||
|
||
UCSR0C = _BV(UCSZ01) | _BV(UCSZ00); /* 8-bit data */ | ||
UCSR0B = _BV(RXEN0) | _BV(TXEN0); /* Enable RX and TX */ | ||
} | ||
|
||
int uart_putchar(char c, FILE *stream) { | ||
if (c == '\n') { | ||
uart_putchar('\r', stream); | ||
} | ||
loop_until_bit_is_set(UCSR0A, UDRE0); | ||
UDR0 = c; | ||
return 0; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#ifndef __UART_H__ | ||
#define __UART_H__ | ||
|
||
void uart_init(void); | ||
int uart_putchar(char c, FILE *stream); | ||
|
||
#endif |