1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2025-02-05 21:30:52 +00:00

Added MEGA65 DMA.h and a (non-working) test.

This commit is contained in:
jespergravgaard 2020-09-24 08:52:50 +02:00
parent c61ec7370d
commit d4af9d4a41
3 changed files with 172 additions and 14 deletions

View File

@ -0,0 +1,137 @@
// MEGA65 DMA
// Appendix J in https://mega.scryptos.com/sharefolder-link/MEGA/MEGA65+filehost/Docs/MEGA65-Book_draft.pdf
// C65 Manual http://www.zimmers.net/cbmpics/cbm/c65/c65manual.txt
// DMA lists https://raw.githubusercontent.com/MEGA65/c65-specifications/master/c65manualupdated.txt
// DMA lists https://c65gs.blogspot.com/2019/03/auto-detecting-required-revision-of.html
// DMA list options https://c65gs.blogspot.com/2018/01/improving-dmagic-controller-interface.html
// DMAgic VHDL source https://github.com/MEGA65/mega65-core/blob/master/src/vhdl/gs4510.vhdl#L4364
// Xemu emulator source https://github.com/lgblgblgb/xemu/blob/master/xemu/f018_core.c
// Registers of the MEGA65 enchanced F018 DMAgic Controller
struct F018_DMAGIC {
// $D700 ADDRLSBTRIG DMAgic DMA list address LSB, and trigger DMA (when written).
// We also clear out the upper address bits in case an enhanced job had set them.
char ADDRLSBTRIG;
// $D701 ADDRMSB DMA list address high byte (address bits 8 -- 15).
char ADDRMSB;
// $D702 ADDRBANK DMA list address bank (address bits 16 -- 22). Writing clears $D704.
char ADDRBANK;
// $D703 EN018B DMA enable F018B mode (adds sub-command byte )
// bit 0 enable F018B mode.
char EN018B;
// $D704 ADDRMB DMA list address mega-byte
char ADDRMB;
// $D705 ETRIG Set low-order byte of DMA list address, and trigger Enhanced DMA job
// Works like $D700, but enables DMA option lists.
char ETRIG;
// $D706-$D70D Unused
char UNUSED1[8];
// $D70E ADDRLSB DMA list address low byte (address bits 0 -- 7) WITHOUT STARTING A DMA JOB
// (used by Hypervisor for unfreezing DMA-using tasks)
char ADDRLSB;
// $D70F Unused
char UNUSED2;
// $D710 MISC (non-DMA) options
// $D710.0 - MISC:BADLEN Enable badline emulation
// $D710.1 - MISC:SLIEN Enable 6502-style slow (7 cycle) interrupts
// $D710.2 - MISC:VDCSEN Enable VDC interface simulation
char MISC;
};
// F018A DMA list entry
struct DMA_LIST_F018A {
// DMA command
// 0-1 command (00: copy, 01: mix (unsupported) 10: swap (unsupported) 11: fill )
// 2 chain
// 3 allow interrupt (unsupported)
char command;
// Count of bytes to copy/fill
unsigned int count;
// Source address (low byte is used as data for command fill)
char* src;
// Source address bank
// bits
// 7 src I/O
// 6 src direction
// 5 src modulo
// 4 src hold
// 0-3 address bank
char src_bank;
// Destination address
char* dest;
// Destination address bank
// bits
// 7 dest I/O
// 6 dest direction
// 5 dest modulo
// 4 dest hold
// 0-3 address bank
char dest_bank;
// Modulo value (unused)
unsigned int modulo;
};
// F018B DMA list entry
struct DMA_LIST_F018B {
// DMA command (format F018B)
// bits
// 0-1 command (00: copy, 01: mix (unsupported) 10: swap (unsupported) 11: fill )
// 2 chain
// 3 allow interrupt (unsupported)
// 4 src direction
// 5 dest direction
char command;
// Count of bytes to copy/fill
unsigned int count;
// Source address (low byte is used as data for command fill)
char* src;
// Source address bank
// bits
// 7 src I/O
// 0-6 dest address bank
char src_bank;
// Destination address
char* dest;
// Destination address bank
// bits
// 7 dest I/O
// 0-6 dest address bank
char dest_bank;
// Sub-command
// bits
// 0 src modulo (unsupported)
// 1 src hold
// 2 dest modulo (unsupported)
// 3 dest hold
char sub_command;
// Modulo value (unused)
unsigned int modulo;
};
// DMA command copy
const char DMA_COMMAND_COPY = 0x00;
// DMA command fill
const char DMA_COMMAND_FILL = 0x03;
// DMA command fill
const char DMA_COMMAND_CHAIN = 0x04;
// DMA command source direction
const char DMA_COMMAND_SRC_DIR = 0x10;
// DMA command destination direction
const char DMA_COMMAND_DEST_DIR = 0x20;
// Extended DMA Option Prefixes
// $00 = End of options
// $06 = Use $86 $xx transparency value (don't write source bytes to destination, if byte value matches $xx)
// $07 = Disable $86 $xx transparency value.
// $0A = Use F018A list format
// $0B = Use F018B list format
// $80 $xx = Set MB of source address
// $81 $xx = Set MB of destination address
// $82 $xx = Set source skip rate (/256ths of bytes)
// $83 $xx = Set source skip rate (whole bytes)
// $84 $xx = Set destination skip rate (/256ths of bytes)
// $85 $xx = Set destination skip rate (whole bytes)
// $86 $xx = Don't write to destination if byte value = $xx, and option $06 enabled

View File

@ -8,6 +8,7 @@
#include <mos4569.h>
#include <mega65-viciv.h>
#include <mega65-memorymapper.h>
#include <mega65-dma.h>
// I/O Personality selection
volatile char * const IO_KEY = 0xd02f;
@ -33,25 +34,26 @@ const char PROCPORT_KERNEL_IO = 0b00000110;
// BASIC in 0xA000, I/O in 0xD000, KERNEL in 0xE000
const char PROCPORT_BASIC_KERNEL_IO = 0b00000111;
// The address of the CHARGEN character set
char * const CHARGEN = 0xd000;
// The SID MOS 6581/8580
struct MOS6581_SID * const SID = 0xd400;
// The VIC-II MOS 6567/6569
struct MOS6569_VICII* const VICII = 0xd000;
// The VIC III MOS 4567/4569
struct MOS4569_VICIII* const VICIII = 0xd000;
// The VIC IV
struct MEGA65_VICIV* const VICIV = 0xd000;
// Color Ram
char * const COLORRAM = 0xd800;
// The address of the CHARGEN character set
char * const CHARGEN = 0xd000;
// Palette RED
char * const PALETTE_RED = 0xd100;
// Palette GREEN
char * const PALETTE_GREEN = 0xd200;
// Palette BLUE
char * const PALETTE_BLUE = 0xd300;
// The SID MOS 6581/8580
struct MOS6581_SID * const SID = 0xd400;
// DMAgic F018 Controller
struct F018_DMAGIC * const DMA = 0xd700;
// Color Ram
char * const COLORRAM = 0xd800;
// Default address of screen character matrix
#ifdef __MEGA65_C64__

View File

@ -1,8 +1,27 @@
// Tests the MEGA65 DMA
// MEGA65 DMA test
// Appendix J in https://mega.scryptos.com/sharefolder-link/MEGA/MEGA65+filehost/Docs/MEGA65-Book_draft.pdf
// C65 Manual http://www.zimmers.net/cbmpics/cbm/c65/c65manual.txt
// DMA lists https://raw.githubusercontent.com/MEGA65/c65-specifications/master/c65manualupdated.txt
// DMA lists https://c65gs.blogspot.com/2019/03/auto-detecting-required-revision-of.html
// DMA list options https://c65gs.blogspot.com/2018/01/improving-dmagic-controller-interface.html
// DMAgic VHDL source https://github.com/MEGA65/mega65-core/blob/master/src/vhdl/gs4510.vhdl#L4364
#pragma target(mega65)
#include <mega65.h>
void main() {
// Enable enable F018B mode
DMA->EN018B = 1;
// Set address of DMA list
DMA->ADDRMB = 0;
DMA->ADDRBANK = 0;
DMA-> ADDRMSB = >&DMA_SCREEN_UP;
// Trigger the DMA (without option lists)
DMA-> ADDRLSBTRIG = <&DMA_SCREEN_UP;
}
// DMA list entry that scrolls the default screen up
struct DMA_LIST_F018B DMA_SCREEN_UP = {
DMA_COMMAND_COPY, // command
24*80, // count
DEFAULT_SCREEN+80, // source
0, // source bank
DEFAULT_SCREEN, // destination
0, // destination bank
0, // sub-command
0 // modulo-value
};