From a15dde0e89f8a97050d073db0e331e6c171808e2 Mon Sep 17 00:00:00 2001 From: Byron Lathi Date: Thu, 7 Apr 2022 10:32:28 -0500 Subject: [PATCH] Add memory mapper software interface Adds functions to read and write mappings, as well as enable and disable the memory mapper. This also moves increases the io space by 16 bytes. --- hw/fpga/addr_decode.sv | 4 ++-- sw/io.inc65 | 3 +++ sw/mapper.h | 12 ++++++++++++ sw/mapper.s | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 sw/mapper.h create mode 100644 sw/mapper.s diff --git a/hw/fpga/addr_decode.sv b/hw/fpga/addr_decode.sv index 2d012d0..32e1aa3 100644 --- a/hw/fpga/addr_decode.sv +++ b/hw/fpga/addr_decode.sv @@ -11,12 +11,12 @@ module addr_decode( ); assign rom_cs = addr >= 16'h8000; -assign sdram_cs = addr < 16'h7ff0; +assign sdram_cs = addr < 16'h7fe0; +assign mm_cs1 = addr >= 16'h7fe0 && addr < 16'h7ff0; assign hex_cs = addr >= 16'h7ff0 && addr < 16'h7ff4; assign uart_cs = addr >= 16'h7ff4 && addr < 16'h7ff6; assign board_io_cs = addr == 16'h7ff6; assign mm_cs2 = addr == 16'h7ff7; -assign mm_cs1 = addr >= 16'h7ff8 && addr < 16'h7ffc; assign irq_cs = addr == 16'h7fff; endmodule diff --git a/sw/io.inc65 b/sw/io.inc65 index 61b079b..5e87bc2 100644 --- a/sw/io.inc65 +++ b/sw/io.inc65 @@ -8,4 +8,7 @@ UART_STATUS = UART + 1 LED = $7ff6 SW = LED +MM_CTRL = $7ff7 +MM_DATA = $7fe0 + IRQ_STATUS = $7fff diff --git a/sw/mapper.h b/sw/mapper.h new file mode 100644 index 0000000..8276b60 --- /dev/null +++ b/sw/mapper.h @@ -0,0 +1,12 @@ +#ifndef _MAPPER_H +#define _MAPPER_H + +#include + +void mapper_enable(uint8_t en); + +uint8_t mapper_read(uint8_t addr); +void mapper_write(uint8_t data, uint8_t addr); + +#endif + diff --git a/sw/mapper.s b/sw/mapper.s new file mode 100644 index 0000000..2ed1bc0 --- /dev/null +++ b/sw/mapper.s @@ -0,0 +1,32 @@ +.include "io.inc65" + +.importzp sp, sreg + +.export _mapper_enable +.export _mapper_read, _mapper_write + +.autoimport on + +.code + + +; void mapper_enable(uint8_t en) +_mapper_enable: + sta MM_CTRL + rts + +_mapper_read: + phx + tax + lda MM_DATA,x + ldx #$00 + rts + +_mapper_write: + phx + tax + jsr popa + sta MM_DATA,x + plx + rts +