1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2024-11-26 12:49:21 +00:00

Optimized readability.

This commit is contained in:
jespergravgaard 2021-04-02 10:47:37 +02:00
parent eea4792eca
commit fa53ba3dce
3 changed files with 70 additions and 39 deletions

View File

@ -306,39 +306,53 @@ struct MEGA65_VICIV {
char DEBUGXY;
};
// $D02f KEY register is used for choosing between the different I/O personalities.
// This disables/enables different registers in $D000-$DFFF
// $00: C64 personality
const char VICIV_KEY_C64 = 0x00;
// $A5, $96: C65 personality
const char VICIV_KEY_C65_A = 0xa5;
const char VICIV_KEY_C65_B = 0x96;
// $45, $54: MEGA65 ETHERNET personality
const char VICIV_KEY_ETHERNET_A = 0x45;
const char VICIV_KEY_ETHERNET_B = 0x54;
// $47, $53: MEGA65 personality
const char VICIV_KEY_M65_A = 0x47;
const char VICIV_KEY_M65_B = 0x53;
// $D030 VIC-III Control Register A (ROM banks)
// Bit 20-bit Address 16-bit Address Read-Write
// 0 CRAM2K $1F800 $1FFFF, $D800 $DFFF Y
// $FF80000 $FF807FF
const char VICIII_CRAM2K = 0x01;
const char VICIV_CRAM2K = 0x01;
// 3 ROM8 $38000 $39FFF $8000 $9FFF N
const char VICIII_ROM8 = 0x08;
const char VICIV_ROM8 = 0x08;
// 4 ROMA $3A000 $3BFFF $A000 $BFFF N
const char VICIII_ROMA = 0x10;
const char VICIV_ROMA = 0x10;
// 5 ROMC $2C000 $2CFFF $C000 $CFFF N
const char VICIII_ROMC = 0x20;
const char VICIV_ROMC = 0x20;
// 6 CROM9 $29000 $29FFF $D000 $DFFF N
const char VICIII_CROM9 = 0x40;
const char VICIV_CROM9 = 0x40;
// 7 ROME $3E000 $3FFFF $E000 $FFFF N
const char VICIII_ROME = 0x80;
const char VICIV_ROME = 0x80;
// $D031 VIC-III Control Register B
// 0 INT Enable VIC-III interlaced mode
const char VICIII_INT = 0x01;
const char VICIV_INT = 0x01;
// 1 MONO Enable VIC-III MONO video output (not implemented)
const char VICIII_MONO = 0x02;
const char VICIV_MONO = 0x02;
// 2 H1280 Enable 1280 horizontal pixels (not implemented)
const char VICIII_H1280 = 0x04;
const char VICIV_H1280 = 0x04;
// 3 V400 Enable 400 vertical pixels
const char VICIII_V400 = 0x08;
const char VICIV_V400 = 0x08;
// 4 BPM Bit-Plane Mode
const char VICIII_BPM = 0x10;
const char VICIV_BPM = 0x10;
// 5 ATTR Enable extended attributes and 8 bit colour entries
const char VICIII_ATTR = 0x20;
const char VICIV_ATTR = 0x20;
// 6 FAST Enable C65 FAST mode (3 .5MHz)
const char VICIII_FAST = 0x40;
const char VICIV_FAST = 0x40;
// 7 H640 Enable C64 640 horizontal pixels / 80 column mode
const char VICIII_H640 = 0x80;
const char VICIV_H640 = 0x80;
// $D054 VIC-IV Control register C
// 0 CHR16 enable 16-bit character numbers (two screen bytes per character)

View File

@ -1,12 +1,27 @@
// Test hardware line drawing
// Based on https://github.com/MEGA65/mega65-tools/blob/master/src/tests/test_290.c
#pragma target(mega65_remote)
#pragma target(mega65)
#include <mega65.h>
#include <mega65-dma.h>
#include <6502.h>
// Get the 0th byte of a double value
#define BYTE0(d) <(<(d))
// Get the 1th byte of a double value
#define BYTE1(d) >(<(d))
// Get the 2th byte of a double value
#define BYTE2(d) <(>(d))
// Get the 3th byte of a double value
#define BYTE3(d) >(>(d))
// Get the low byte from a word/int
#define LOBYTE(w) <(w)
// Get the high byte from a word/int
#define HIBYTE(w) >(w)
// Poke a byte value into memory
#define POKE(addr,val) *((char*)(addr)) = val
// Peek a byte value from memory
#define PEEK(addr) *((char*)addr)
// Poke a value directly into memory
@ -22,9 +37,11 @@ void lpoke(__zp unsigned long addr, char val) {
}
// DMA command structure for drawing lines
// Graphics mode is 1 byte per pixel. Addressing is based on columns of 8px * 200px arranged to have linear addressing.
// addr = (x/8) * 64 * 25 + (y*8) + (x&7)
char line_dma_command[] = {
DMA_OPTION_LINE_XSTEP_LO, (25*64 - 8) & 0xff, // Line X step bytes 64x25 = 1600
DMA_OPTION_LINE_XSTEP_HI, (25*64 - 8) >> 8, // Line X step bytes 64x25 = 1600
DMA_OPTION_LINE_XSTEP_LO, (25*64 - 8) & 0xff, // Line X step bytes 64x25
DMA_OPTION_LINE_XSTEP_HI, (25*64 - 8) >> 8, // Line X step bytes 64x25
DMA_OPTION_LINE_SLOPE_LO, 0, // Line Slope
DMA_OPTION_LINE_SLOPE_HI, 0, // Line Slope
DMA_OPTION_LINE_MODE, 0, // Line Mode
@ -59,12 +76,12 @@ void main() {
// Fast CPU, M65 IO
POKE(0, 65);
// Enable MEGA65 features
VICIII->KEY = 0x47;
VICIII->KEY = 0x53;
VICIV->KEY = VICIV_KEY_M65_A;
VICIV->KEY = VICIV_KEY_M65_B;
// No C65 ROMs are mapped
VICIV->CONTROLA = 0;
// Enable 48MHz fast mode
VICIV->CONTROLB |= VICIII_FAST;
VICIV->CONTROLB |= VICIV_FAST;
VICIV->CONTROLC |= VICIV_VFAST;
graphics_mode();
@ -86,7 +103,7 @@ void graphics_mode(void) {
// 16-bit text mode, full-colour text for high chars
VICIV->CONTROLC = VICIV_FCLRHI | VICIV_CHR16;
// H320, fast CPU
VICIV->CONTROLB = VICIII_FAST;
VICIV->CONTROLB = VICIV_FAST;
// 320x200 per char, 16 pixels wide per char
// = 320/8 x 16 bits = 80 bytes per row
VICIV->CHARSTEP_LO = 80;
@ -94,8 +111,8 @@ void graphics_mode(void) {
// Draw 40 chars per row
VICIV->CHRCOUNT = 40;
// Put 2KB screen at $C000
VICIV->SCRNPTR_LOLO = <(SCREEN);
VICIV->SCRNPTR_LOHI = >(SCREEN);
VICIV->SCRNPTR_LOLO = LOBYTE(SCREEN);
VICIV->SCRNPTR_LOHI = HIBYTE(SCREEN);
VICIV->SCRNPTR_HILO = 0x00;
// Layout screen so that graphics data comes from $40000 -- $4FFFF
@ -126,7 +143,6 @@ void graphics_mode(void) {
}
void draw_line(int x1, int y1, int x2, int y2, unsigned char colour) {
// Ignore if we choose to draw a point
if (x2 == x1 && y2 == y1)
@ -169,21 +185,21 @@ void draw_line(int x1, int y1, int x2, int y2, unsigned char colour) {
int slope = *MATH_DIVOUT_FRAC_INT1;
// Put slope into DMA options
line_dma_command[LINE_DMA_COMMAND_SLOPE_OFFSET] = <(slope);
line_dma_command[LINE_DMA_COMMAND_SLOPE_OFFSET + 2] = >(slope);
line_dma_command[LINE_DMA_COMMAND_SLOPE_OFFSET] = LOBYTE(slope);
line_dma_command[LINE_DMA_COMMAND_SLOPE_OFFSET + 2] = HIBYTE(slope);
// Load DMA dest address with the address of the first pixel
long addr = GRAPHICS + (x1/8) * 64 * 25 + (y1*8) + (x1&7);
line_dma_command[LINE_DMA_COMMAND_DEST_OFFSET + 0] = <(<(addr));
line_dma_command[LINE_DMA_COMMAND_DEST_OFFSET + 1] = >(<(addr));
line_dma_command[LINE_DMA_COMMAND_DEST_OFFSET + 2] = <(>(addr));
line_dma_command[LINE_DMA_COMMAND_DEST_OFFSET + 0] = BYTE0(addr);
line_dma_command[LINE_DMA_COMMAND_DEST_OFFSET + 1] = BYTE1(addr);
line_dma_command[LINE_DMA_COMMAND_DEST_OFFSET + 2] = BYTE2(addr);
// Source is the colour
line_dma_command[LINE_DMA_COMMAND_SRC_OFFSET] = colour;
// Count is number of pixels, i.e., dy.
line_dma_command[LINE_DMA_COMMAND_COUNT_OFFSET] = <(dy);
line_dma_command[LINE_DMA_COMMAND_COUNT_OFFSET + 1] = >(dy);
line_dma_command[LINE_DMA_COMMAND_COUNT_OFFSET] = LOBYTE(dy);
line_dma_command[LINE_DMA_COMMAND_COUNT_OFFSET + 1] = HIBYTE(dy);
// Line mode active, major axis is Y
line_dma_command[LINE_DMA_COMMAND_MODE_OFFSET] = DMA_OPTION_LINE_MODE_ENABLE + DMA_OPTION_LINE_MODE_DIRECTION_Y + (((x2 - x1) < 0) ? DMA_OPTION_LINE_MODE_SLOPE_NEGATIVE : 0x00);
@ -223,21 +239,21 @@ void draw_line(int x1, int y1, int x2, int y2, unsigned char colour) {
int slope = *MATH_DIVOUT_FRAC_INT1;
// Put slope into DMA options
line_dma_command[LINE_DMA_COMMAND_SLOPE_OFFSET] = <(slope);
line_dma_command[LINE_DMA_COMMAND_SLOPE_OFFSET + 2] = >(slope);
line_dma_command[LINE_DMA_COMMAND_SLOPE_OFFSET] = LOBYTE(slope);
line_dma_command[LINE_DMA_COMMAND_SLOPE_OFFSET + 2] = HIBYTE(slope);
// Load DMA dest address with the address of the first pixel
long addr = GRAPHICS + (x1/8) * 64 * 25 + (y1*8) + (x1&7);
line_dma_command[LINE_DMA_COMMAND_DEST_OFFSET + 0] = <(<(addr));
line_dma_command[LINE_DMA_COMMAND_DEST_OFFSET + 1] = >(<(addr));
line_dma_command[LINE_DMA_COMMAND_DEST_OFFSET + 2] = <(>(addr));
line_dma_command[LINE_DMA_COMMAND_DEST_OFFSET + 0] = BYTE0(addr);
line_dma_command[LINE_DMA_COMMAND_DEST_OFFSET + 1] = BYTE1(addr);
line_dma_command[LINE_DMA_COMMAND_DEST_OFFSET + 2] = BYTE2(addr);
// Source is the colour
line_dma_command[LINE_DMA_COMMAND_SRC_OFFSET] = colour;
// Count is number of pixels, i.e., dy.
line_dma_command[LINE_DMA_COMMAND_COUNT_OFFSET] = <(dx);
line_dma_command[LINE_DMA_COMMAND_COUNT_OFFSET + 1] = >(dx);
line_dma_command[LINE_DMA_COMMAND_COUNT_OFFSET] = LOBYTE(dx);
line_dma_command[LINE_DMA_COMMAND_COUNT_OFFSET + 1] = HIBYTE(dx);
// Line mode active, major axis is X
line_dma_command[LINE_DMA_COMMAND_MODE_OFFSET] = DMA_OPTION_LINE_MODE_ENABLE + (((y2 - y1) < 0) ? DMA_OPTION_LINE_MODE_SLOPE_NEGATIVE : 0x00);

View File

@ -17,7 +17,8 @@
"mega65-dma.h": "c",
"mega65.h": "c",
"mega65-f018.h": "c",
"mega65-viciv.h": "c"
"mega65-viciv.h": "c",
"6502.h": "c"
},
"kickassembler.assemblerJar": "/Applications/KickAssembler/KickAss.jar"
}