@@ 3,7 3,7 @@ include(CTest)
include_directories(${SDL2_INCLUDE_DIRS})
-add_executable(fbemu main.c)
+add_executable(fbemu main.c virtual_kia.c)
target_link_libraries(fbemu lib65816a ${SDL2_LIBRARIES})
add_executable(test_kia test_kia.c virtual_kia.c)
@@ 14,12 14,17 @@
#include <lib65816/cpuevent.h>
#include <SDL2/SDL.h>
+#include "virtual_kia.h"
#define MAX_DISK 8
/* Number of bus clock cycles per 10ms interval */
#define THROTTLE_TICKS 40000
+/* Determines the bank for MVP/MVN-block I/O access */
+
+#define BLOCK_IO_BANK 0xFD
+
static uint32_t cpu_inst_count;
static uint32_t most_recent_insn;
@@ 49,6 54,7 @@ static SDL_Texture *texture;
static uint32_t pixbuf[16384 * 8];
static uint8_t vram[16384];
static uint8_t key;
+static KIA_t *g_kia1;
static void video_shutdown(void)
@@ 92,6 98,34 @@ static int video_init(void)
}
+uint8_t kia_read(KIA_t *pk, uint32_t addr) {
+ int reg = addr & 1;
+
+ switch(reg) {
+ case 0:
+ int is_full = kia_is_full(pk);
+ int is_empty = kia_is_empty(pk);
+ return (is_full << 1) | is_empty;
+
+ case 1:
+ return kia_peek(pk);
+ }
+}
+
+void kia_write(KIA_t *pk, uint32_t addr, uint8_t _unused_value) {
+ int reg = addr & 1;
+
+ switch(reg) {
+ case 0:
+ // does nothing
+ break;
+
+ case 1:
+ kia_pop(pk);
+ break;
+ }
+}
+
void video_write_ram(uint16_t addr, uint8_t val)
{
int i;
@@ 311,10 345,14 @@ uint8_t MEM_readMem(uint32_t addr, uint32_t unused_timestamp, uint32_t emul_flag
most_recent_insn = addr;
cpu_inst_count++;
}
- if ((addr >> 16) == 0xFF)
+
+ if ((addr >> 16) == BLOCK_IO_BANK)
addr = 0xFE00 + dma;
+
if ((addr >> 16) == 0xFE)
return video_read_ram(addr);
+ if(addr >= 0xFFF000 && addr <= 0xFFFFFF)
+ return kia_read(g_kia1, addr);
if (addr >= 0xFE00 && addr < 0xFF00) {
/* Don't cause I/O when using debug trace read */
if (g_debug)
@@ 334,10 372,13 @@ uint8_t MEM_readMem(uint32_t addr, uint32_t unused_timestamp, uint32_t emul_flag
void MEM_writeMem(uint32_t addr, uint8_t value, uint32_t unused_timestamp)
{
- if ((addr >> 16) == 0xFF)
+ if ((addr >> 16) == BLOCK_IO_BANK)
addr = 0xFE00 + dma;
+
if ((addr >> 16) == 0xFE)
video_write_ram(addr, value);
+ else if (addr >= 0xFFF000 && addr <= 0xFFFFFF)
+ kia_write(g_kia1, addr, value);
else if (addr >= 0xFE00 && addr < 0xFF00)
io_write(addr, value);
else if (addr < sizeof(ram))
@@ 486,6 527,12 @@ int main(int argc, char *argv[])
exit(1);
}
+ g_kia1 = kia_new();
+ if(!g_kia1) {
+ perror("kia_new");
+ exit(1);
+ }
+
CPUEvent_initialize();
CPUEvent_schedule(&throttle_event, THROTTLE_TICKS, &emulate_4MHz);
CPU_reset();
@@ 1,3 1,8 @@
+/**
+ * @file Models the core behavior of the Keyboard Interface Adapter
+ * (KIA).
+ */
+
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>