1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2025-01-10 12:31:09 +00:00

Bitmap mode

This commit is contained in:
FlightControl 2021-01-19 22:30:51 +01:00
parent 5daa045271
commit 6b690f860b
15 changed files with 3476 additions and 277 deletions

File diff suppressed because it is too large Load Diff

View File

@ -2,12 +2,12 @@
// Currently it can only plot on the first 256 x-positions.
// Initialize the bitmap plotter tables for a specific bitmap
void bitmap_init(char* bitmap);
void bitmap_init(word bitmap_address);
// Clear all graphics on the bitmap
void bitmap_clear();
void bitmap_plot(char x, char y);
void bitmap_plot(word x, word y);
// Draw a line on the bitmap
void bitmap_line(char x0, char x1, char y0, char y1);
void bitmap_line(word x0, word x1, word y0, word y1);

View File

@ -164,15 +164,14 @@ byte const VERA_LAYER_COLOR_DEPTH_8BPP = 0x03;
byte const VERA_LAYER_COLOR_DEPTH_MASK = 0x03;
byte const VERA_LAYER_COLOR_DEPTH[4] = {1, 2, 4, 8};
// $9F2D L0_CONFIG Layer 0 Configuration
char * const VERA_L0_CONFIG = 0x9f2d;
// Bit 2: Bitmap Mode (0:tile mode, 1: bitmap mode)
char const VERA_L0_CONFIG_MODE_TILE = 0x00;
char const VERA_L0_CONFIG_MODE_BITMAP = 0x04;
char const VERA_LAYER_CONFIG_MODE_TILE = 0x00;
char const VERA_LAYER_CONFIG_MODE_BITMAP = 0x04;
// Bit 3: T256C (0: tiles use a 16-color foreground and background color, 1: tiles use a 256-color foreground color) (only relevant in 1bpp modes)
char const VERA_L0_CONFIG_16C = 0x00;
char const VERA_L0_CONFIG_256C = 0x08;
char const VERA_LAYER_CONFIG_16C = 0x00;
char const VERA_LAYER_CONFIG_256C = 0x08;
// $9F2E L0_MAPBASE Layer 0 Map Base Address (16:9)
char * const VERA_L0_MAPBASE = 0x9f2e;
// $9F2F L0_TILEBASE Layer 0 Tile Base
@ -197,12 +196,6 @@ char * const VERA_L0_VSCROLL_L = 0x9f32;
char * const VERA_L0_VSCROLL_H = 0x9f33;
// $9F34 L1_CONFIG Layer 1 Configuration
char * const VERA_L1_CONFIG = 0x9f34;
// Bit 2: Bitmap Mode (0:tile mode, 1: bitmap mode)
char const VERA_L1_CONFIG_MODE_TILE = 0x00;
char const VERA_L1_CONFIG_MODE_BITMAP = 0x04;
// Bit 3: T256C (0: tiles use a 16-color foreground and background color, 1: tiles use a 256-color foreground color) (only relevant in 1bpp modes)
char const VERA_L1_CONFIG_16C = 0x00;
char const VERA_L1_CONFIG_256C = 0x08;
// $9F35 L1_MAPBASE Layer 1 Map Base Address (16:9)
char * const VERA_L1_MAPBASE = 0x9f35;
// $9F36 L1_TILEBASE Layer 1 Tile Base

View File

@ -0,0 +1,111 @@
// Simple single-color (320x200) bitmap routines
#include <bitmap2.h>
#include <string.h>
// The adddress of the bitmap screen (used for colors)
char* bitmap_screen;
// The adddress of the bitmap graphics (used for pixels)
char* bitmap_gfx;
// Tables for the plotter - initialized by calling bitmap_init();
const char bitmap_plot_ylo[256];
const char bitmap_plot_yhi[256];
const char bitmap_plot_bit[256];
// Initialize bitmap plotting tables
void bitmap_init(char* gfx, char* screen) {
bitmap_gfx = gfx;
bitmap_screen = screen;
char bits = $80;
for(char x : 0..255) {
bitmap_plot_bit[x] = bits;
bits >>= 1;
if(bits==0) {
bits = $80;
}
}
char* yoffs = gfx;
for(char y : 0..255) {
bitmap_plot_ylo[y] = y&$7 | <yoffs;
bitmap_plot_yhi[y] = >yoffs;
if((y&$7)==7) {
yoffs = yoffs + 40*8;
}
}
}
// Clear all graphics on the bitmap
// bgcol - the background color to fill the screen with
// fgcol - the foreground color to fill the screen with
void bitmap_clear(char bgcol, char fgcol) {
char col = fgcol*0x10 + bgcol;
memset(bitmap_screen, col, 1000uw);
memset(bitmap_gfx, 0, 8000uw);
}
// Plot a single dot in the bitmap
void bitmap_plot(unsigned int x, char y) {
char* plotter = (char*) { bitmap_plot_yhi[y], bitmap_plot_ylo[y] };
plotter += ( x & $fff8 );
*plotter |= bitmap_plot_bit[<x];
}
// Draw a line on the bitmap using bresenhams algorithm
void bitmap_line(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2) {
unsigned int x = x1;
unsigned int y = y1;
unsigned int dx = abs_u16(x2-x1);
unsigned int dy = abs_u16(y2-y1);
if(dx==0 && dy==0) {
bitmap_plot(x,(char)y);
return;
}
unsigned int sx = sgn_u16(x2-x1);
unsigned int sy = sgn_u16(y2-y1);
if(dx > dy) {
// X is the driver
unsigned int e = dy/2;
do {
bitmap_plot(x,(char)y);
x += sx;
e += dy;
if(dx < e) {
y += sy;
e -= dx;
}
} while (x != x2);
} else {
// Y is the driver
unsigned int e = dx/2;
do {
bitmap_plot(x,(char)y);
y += sy;
e += dx;
if(dy<e) {
x += sx;
e -= dy;
}
} while (y != y2);
}
bitmap_plot(x,(char)y);
}
// Get the absolute value of a 16-bit unsigned number treated as a signed number.
unsigned int abs_u16(unsigned int w) {
if(>w&0x80) {
return -w;
} else {
return w;
}
}
// Get the sign of a 16-bit unsigned number treated as a signed number.
// Returns unsigned -1 if the number is
unsigned int sgn_u16(unsigned int w) {
if(>w&0x80) {
return -1;
} else {
return 1;
}
}

View File

@ -0,0 +1,112 @@
// Simple single-color (320x200) bitmap routines
#include <bitmap2.h>
#include <string.h>
#include <veralib.h>
#include <printf.h> // TODO
// The adddress of the bitmap screen (used for colors)
char* bitmap_screen;
// The adddress of the bitmap graphics (used for pixels)
char* bitmap_gfx;
// Tables for the plotter - initialized by calling bitmap_init();
const char bitmap_plot_ylo[256];
const char bitmap_plot_yhi[256];
const char bitmap_plot_bit[256];
// Initialize bitmap plotting tables
void bitmap_init(char* gfx, char* screen) {
bitmap_gfx = gfx;
bitmap_screen = screen;
char bits = $80;
for(char x : 0..255) {
bitmap_plot_bit[x] = bits;
bits >>= 1;
if(bits==0) {
bits = $80;
}
}
char* yoffs = gfx;
for(char y : 0..255) {
bitmap_plot_ylo[y] = y&$7 | <yoffs;
bitmap_plot_yhi[y] = >yoffs;
if((y&$7)==7) {
yoffs = yoffs + 40*8;
}
}
}
// Clear all graphics on the bitmap
// bgcol - the background color to fill the screen with
// fgcol - the foreground color to fill the screen with
void bitmap_clear(char bgcol, char fgcol) {
memset_vram(0,bitmap_gfx,0, 320*4);
printf("done");
}
// Plot a single dot in the bitmap
void bitmap_plot(unsigned int x, char y) {
char* plotter = (char*) { bitmap_plot_yhi[y], bitmap_plot_ylo[y] };
plotter += ( x & $fff8 );
*plotter |= bitmap_plot_bit[<x];
}
// Draw a line on the bitmap using bresenhams algorithm
void bitmap_line(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2) {
unsigned int x = x1;
unsigned int y = y1;
unsigned int dx = abs_u16(x2-x1);
unsigned int dy = abs_u16(y2-y1);
if(dx==0 && dy==0) {
bitmap_plot(x,(char)y);
return;
}
unsigned int sx = sgn_u16(x2-x1);
unsigned int sy = sgn_u16(y2-y1);
if(dx > dy) {
// X is the driver
unsigned int e = dy/2;
do {
bitmap_plot(x,(char)y);
x += sx;
e += dy;
if(dx < e) {
y += sy;
e -= dx;
}
} while (x != x2);
} else {
// Y is the driver
unsigned int e = dx/2;
do {
bitmap_plot(x,(char)y);
y += sy;
e += dx;
if(dy<e) {
x += sx;
e -= dy;
}
} while (y != y2);
}
bitmap_plot(x,(char)y);
}
// Get the absolute value of a 16-bit unsigned number treated as a signed number.
unsigned int abs_u16(unsigned int w) {
if(>w&0x80) {
return -w;
} else {
return w;
}
}
// Get the sign of a 16-bit unsigned number treated as a signed number.
// Returns unsigned -1 if the number is
unsigned int sgn_u16(unsigned int w) {
if(>w&0x80) {
return -1;
} else {
return 1;
}
}

View File

@ -0,0 +1,147 @@
// Plot and line drawing routines for HIRES bitmaps
// Currently it can only plot on the first 256 x-positions.
#include <bitmap-draw.h>
// Tables for the plotter - initialized by calling bitmap_draw_init();
const char bitmap_plot_xlo[256];
const char bitmap_plot_xhi[256];
const char bitmap_plot_ylo[256];
const char bitmap_plot_yhi[256];
const char bitmap_plot_bit[256];
// Initialize the bitmap plotter tables for a specific bitmap
void bitmap_init(char* bitmap) {
char bits = $80;
for(char x : 0..255) {
bitmap_plot_xlo[x] = x&$f8;
bitmap_plot_xhi[x] = >bitmap;
bitmap_plot_bit[x] = bits;
bits = bits>>1;
if(bits==0) {
bits = $80;
}
}
char* yoffs = $0;
for(char y : 0..255) {
bitmap_plot_ylo[y] = y&$7 | <yoffs;
bitmap_plot_yhi[y] = >yoffs;
if((y&$7)==7) {
yoffs = yoffs + 40*8;
}
}
}
// Clear all graphics on the bitmap
void bitmap_clear() {
char* bitmap = (char*) { bitmap_plot_xhi[0], bitmap_plot_xlo[0] };
for( char y: 0..39 ) {
for( char x: 0..199 ) {
*bitmap++ = 0;
}
}
}
void bitmap_plot(char x, char y) {
// Needs unsigned int arrays arranged as two underlying char arrays to allow char* plotter_x = plot_x[x]; - and eventually - char* plotter = plot_x[x] + plot_y[y];
unsigned int plotter_x = { bitmap_plot_xhi[x], bitmap_plot_xlo[x] };
unsigned int plotter_y = { bitmap_plot_yhi[y], bitmap_plot_ylo[y] };
char* plotter = plotter_x+plotter_y;
*plotter = *plotter | bitmap_plot_bit[x];
}
// Draw a line on the bitmap
void bitmap_line(char x0, char x1, char y0, char y1) {
char xd;
char yd;
if(x0<x1) {
xd = x1-x0;
if(y0<y1) {
yd = y1-y0;
if(yd<xd) {
bitmap_line_xdyi(x0, y0, x1, xd, yd);
} else {
bitmap_line_ydxi(y0, x0, y1, yd, xd);
}
} else {
yd = y0-y1;
if(yd<xd) {
bitmap_line_xdyd(x0, y0, x1, xd, yd);
} else {
bitmap_line_ydxd(y1, x1, y0, yd, xd);
}
}
} else {
xd = x0-x1;
if(y0<y1) {
yd = y1-y0;
if(yd<xd) {
bitmap_line_xdyd(x1, y1, x0, xd, yd);
} else {
bitmap_line_ydxd(y0, x0, y1, yd, xd);
}
} else {
yd = y0-y1;
if(yd<xd) {
bitmap_line_xdyi(x1, y1, x0, xd, yd);
} else {
bitmap_line_ydxi(y1, x1, y0, yd, xd);
}
}
}
}
void bitmap_line_xdyi(char x, char y, char x1, char xd, char yd) {
char e = yd>>1;
do {
bitmap_plot(x,y);
x++;
e = e+yd;
if(xd<e) {
y++;
e = e - xd;
}
} while (x!=(x1+1));
}
void bitmap_line_xdyd(char x, char y, char x1, char xd, char yd) {
char e = yd>>1;
do {
bitmap_plot(x,y);
x++;
e = e+yd;
if(xd<e) {
y--;
e = e - xd;
}
} while (x!=(x1+1));
}
void bitmap_line_ydxi(char y, char x, char y1, char yd, char xd) {
char e = xd>>1;
do {
bitmap_plot(x,y);
y++;
e = e+xd;
if(yd<e) {
x++;
e = e - yd;
}
} while (y!=(y1+1));
}
void bitmap_line_ydxd(char y, char x, char y1, char yd, char xd) {
char e = xd>>1;
do {
bitmap_plot(x,y);
y = y++;
e = e+xd;
if(yd<e) {
x--;
e = e - yd;
}
} while (y!=(y1+1));
}

View File

@ -0,0 +1,143 @@
// Plot and line drawing routines for HIRES bitmaps
// Currently it can only plot on the first 256 x-positions.
#include <bitmap-draw.h>
#include <veralib.h>
// Tables for the plotter - initialized by calling bitmap_draw_init();
const word bitmap_plot_y[640];
const byte bitmap_plot_bit[8];
word bitmap = 0;
// Initialize the bitmap plotter tables for a specific bitmap
void bitmap_init(word bitmap_address) {
bitmap = bitmap_address;
word yoffs = $0;
byte bit = $80;
for(word x : 0..7) {
bitmap_plot_bit[x] = bit;
bit >>= 1;
}
for(word y : 0..600) {
bitmap_plot_y[y] = yoffs;
yoffs = yoffs + 80;
}
}
// Clear all graphics on the bitmap
void bitmap_clear() {
word bitmap_address = bitmap;
for( word y: 0..600 ) {
for( word x: 0..40 ) {
vera_vram_bank_offset(0,(word)bitmap_address,VERA_INC_0);
*VERA_DATA0 = 0;
bitmap_address++;
}
}
}
void bitmap_plot(word x, word y) {
// Needs unsigned int arrays arranged as two underlying char arrays to allow char* plotter_x = plot_x[x]; - and eventually - char* plotter = plot_x[x] + plot_y[y];
word plotter_x = x>>3;
word plotter_y = bitmap_plot_y[y];
word plotter = bitmap+plotter_x+plotter_y;
vera_vram_bank_offset(0,(word)plotter,VERA_INC_0);
*VERA_DATA0 = *VERA_DATA0 | bitmap_plot_bit[x&$07];
}
// Draw a line on the bitmap
void bitmap_line(word x0, word x1, word y0, word y1) {
word xd;
word yd;
if(x0<x1) {
xd = x1-x0;
if(y0<y1) {
yd = y1-y0;
if(yd<xd) {
bitmap_line_xdyi(x0, y0, x1, xd, yd);
} else {
bitmap_line_ydxi(y0, x0, y1, yd, xd);
}
} else {
yd = y0-y1;
if(yd<xd) {
bitmap_line_xdyd(x0, y0, x1, xd, yd);
} else {
bitmap_line_ydxd(y1, x1, y0, yd, xd);
}
}
} else {
xd = x0-x1;
if(y0<y1) {
yd = y1-y0;
if(yd<xd) {
bitmap_line_xdyd(x1, y1, x0, xd, yd);
} else {
bitmap_line_ydxd(y0, x0, y1, yd, xd);
}
} else {
yd = y0-y1;
if(yd<xd) {
bitmap_line_xdyi(x1, y1, x0, xd, yd);
} else {
bitmap_line_ydxi(y1, x1, y0, yd, xd);
}
}
}
}
void bitmap_line_xdyi(word x, word y, word x1, word xd, word yd) {
word e = yd>>1;
do {
bitmap_plot(x,y);
x++;
e = e+yd;
if(xd<e) {
y++;
e = e - xd;
}
} while (x!=(x1+1));
}
void bitmap_line_xdyd(word x, word y, word x1, word xd, word yd) {
word e = yd>>1;
do {
bitmap_plot(x,y);
x++;
e = e+yd;
if(xd<e) {
y--;
e = e - xd;
}
} while (x!=(x1+1));
}
void bitmap_line_ydxi(word y, word x, word y1, word yd, word xd) {
word e = xd>>1;
do {
bitmap_plot(x,y);
y++;
e = e+xd;
if(yd<e) {
x++;
e = e - yd;
}
} while (y!=(y1+1));
}
void bitmap_line_ydxd(word y, word x, word y1, word yd, word xd) {
word e = xd>>1;
do {
bitmap_plot(x,y);
y = y++;
e = e+xd;
if(yd<e) {
x--;
e = e - yd;
}
} while (y!=(y1+1));
}

View File

@ -1,147 +1,11 @@
// Plot and line drawing routines for HIRES bitmaps
// Currently it can only plot on the first 256 x-positions.
// Provides provide bitmap output
// Currently C64/PLUS4/VIC20/CX16 platforms are supported
#include <bitmap-draw.h>
// Tables for the plotter - initialized by calling bitmap_draw_init();
const char bitmap_plot_xlo[256];
const char bitmap_plot_xhi[256];
const char bitmap_plot_ylo[256];
const char bitmap_plot_yhi[256];
const char bitmap_plot_bit[256];
// Initialize the bitmap plotter tables for a specific bitmap
void bitmap_init(char* bitmap) {
char bits = $80;
for(char x : 0..255) {
bitmap_plot_xlo[x] = x&$f8;
bitmap_plot_xhi[x] = >bitmap;
bitmap_plot_bit[x] = bits;
bits = bits>>1;
if(bits==0) {
bits = $80;
}
}
char* yoffs = $0;
for(char y : 0..255) {
bitmap_plot_ylo[y] = y&$7 | <yoffs;
bitmap_plot_yhi[y] = >yoffs;
if((y&$7)==7) {
yoffs = yoffs + 40*8;
}
}
}
// Clear all graphics on the bitmap
void bitmap_clear() {
char* bitmap = (char*) { bitmap_plot_xhi[0], bitmap_plot_xlo[0] };
for( char y: 0..39 ) {
for( char x: 0..199 ) {
*bitmap++ = 0;
}
}
}
void bitmap_plot(char x, char y) {
// Needs unsigned int arrays arranged as two underlying char arrays to allow char* plotter_x = plot_x[x]; - and eventually - char* plotter = plot_x[x] + plot_y[y];
unsigned int plotter_x = { bitmap_plot_xhi[x], bitmap_plot_xlo[x] };
unsigned int plotter_y = { bitmap_plot_yhi[y], bitmap_plot_ylo[y] };
char* plotter = plotter_x+plotter_y;
*plotter = *plotter | bitmap_plot_bit[x];
}
// Draw a line on the bitmap
void bitmap_line(char x0, char x1, char y0, char y1) {
char xd;
char yd;
if(x0<x1) {
xd = x1-x0;
if(y0<y1) {
yd = y1-y0;
if(yd<xd) {
bitmap_line_xdyi(x0, y0, x1, xd, yd);
} else {
bitmap_line_ydxi(y0, x0, y1, yd, xd);
}
} else {
yd = y0-y1;
if(yd<xd) {
bitmap_line_xdyd(x0, y0, x1, xd, yd);
} else {
bitmap_line_ydxd(y1, x1, y0, yd, xd);
}
}
} else {
xd = x0-x1;
if(y0<y1) {
yd = y1-y0;
if(yd<xd) {
bitmap_line_xdyd(x1, y1, x0, xd, yd);
} else {
bitmap_line_ydxd(y0, x0, y1, yd, xd);
}
} else {
yd = y0-y1;
if(yd<xd) {
bitmap_line_xdyi(x1, y1, x0, xd, yd);
} else {
bitmap_line_ydxi(y1, x1, y0, yd, xd);
}
}
}
}
void bitmap_line_xdyi(char x, char y, char x1, char xd, char yd) {
char e = yd>>1;
do {
bitmap_plot(x,y);
x++;
e = e+yd;
if(xd<e) {
y++;
e = e - xd;
}
} while (x!=(x1+1));
}
void bitmap_line_xdyd(char x, char y, char x1, char xd, char yd) {
char e = yd>>1;
do {
bitmap_plot(x,y);
x++;
e = e+yd;
if(xd<e) {
y--;
e = e - xd;
}
} while (x!=(x1+1));
}
void bitmap_line_ydxi(char y, char x, char y1, char yd, char xd) {
char e = xd>>1;
do {
bitmap_plot(x,y);
y++;
e = e+xd;
if(yd<e) {
x++;
e = e - yd;
}
} while (y!=(y1+1));
}
void bitmap_line_ydxd(char y, char x, char y1, char yd, char xd) {
char e = xd>>1;
do {
bitmap_plot(x,y);
y = y++;
e = e+xd;
if(yd<e) {
x--;
e = e - yd;
}
} while (y!=(y1+1));
}
#if defined(__CX16__)
#include "bitmap-draw-cx16.c"
#elif defined(__C64__)
#include "bitmap-draw-c64.c"
#else
#error "Target platform does not support bitmap-draw.h"
#endif

View File

@ -1,111 +1,11 @@
// Simple single-color (320x200) bitmap routines
// Provides provide bitmap output
// Currently C64/PLUS4/VIC20/CX16 platforms are supported
#include <bitmap2.h>
#include <string.h>
// The adddress of the bitmap screen (used for colors)
char* bitmap_screen;
// The adddress of the bitmap graphics (used for pixels)
char* bitmap_gfx;
// Tables for the plotter - initialized by calling bitmap_init();
const char bitmap_plot_ylo[256];
const char bitmap_plot_yhi[256];
const char bitmap_plot_bit[256];
// Initialize bitmap plotting tables
void bitmap_init(char* gfx, char* screen) {
bitmap_gfx = gfx;
bitmap_screen = screen;
char bits = $80;
for(char x : 0..255) {
bitmap_plot_bit[x] = bits;
bits >>= 1;
if(bits==0) {
bits = $80;
}
}
char* yoffs = gfx;
for(char y : 0..255) {
bitmap_plot_ylo[y] = y&$7 | <yoffs;
bitmap_plot_yhi[y] = >yoffs;
if((y&$7)==7) {
yoffs = yoffs + 40*8;
}
}
}
// Clear all graphics on the bitmap
// bgcol - the background color to fill the screen with
// fgcol - the foreground color to fill the screen with
void bitmap_clear(char bgcol, char fgcol) {
char col = fgcol*0x10 + bgcol;
memset(bitmap_screen, col, 1000uw);
memset(bitmap_gfx, 0, 8000uw);
}
// Plot a single dot in the bitmap
void bitmap_plot(unsigned int x, char y) {
char* plotter = (char*) { bitmap_plot_yhi[y], bitmap_plot_ylo[y] };
plotter += ( x & $fff8 );
*plotter |= bitmap_plot_bit[<x];
}
// Draw a line on the bitmap using bresenhams algorithm
void bitmap_line(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2) {
unsigned int x = x1;
unsigned int y = y1;
unsigned int dx = abs_u16(x2-x1);
unsigned int dy = abs_u16(y2-y1);
if(dx==0 && dy==0) {
bitmap_plot(x,(char)y);
return;
}
unsigned int sx = sgn_u16(x2-x1);
unsigned int sy = sgn_u16(y2-y1);
if(dx > dy) {
// X is the driver
unsigned int e = dy/2;
do {
bitmap_plot(x,(char)y);
x += sx;
e += dy;
if(dx < e) {
y += sy;
e -= dx;
}
} while (x != x2);
} else {
// Y is the driver
unsigned int e = dx/2;
do {
bitmap_plot(x,(char)y);
y += sy;
e += dx;
if(dy<e) {
x += sx;
e -= dy;
}
} while (y != y2);
}
bitmap_plot(x,(char)y);
}
// Get the absolute value of a 16-bit unsigned number treated as a signed number.
unsigned int abs_u16(unsigned int w) {
if(>w&0x80) {
return -w;
} else {
return w;
}
}
// Get the sign of a 16-bit unsigned number treated as a signed number.
// Returns unsigned -1 if the number is
unsigned int sgn_u16(unsigned int w) {
if(>w&0x80) {
return -1;
} else {
return 1;
}
}
#if defined(__CX16__)
#include "bitmap-cx16.c"
#elif defined(__C64__)
#include "bitmap-c64.c"
#else
#error "Target platform does not support bitmap.h"
#endif

View File

@ -71,7 +71,7 @@ void conio_x16_init() {
// Position cursor at current line
char * const BASIC_CURSOR_LINE = 0xD6;
char line = *BASIC_CURSOR_LINE;
vera_layer_mode_tile(1,(dword)0x00000,(dword)0x0F800,128,64,8,8,1);
vera_layer_mode_text(1,(dword)0x00000,(dword)0x0F800,128,64,8,8,16);
screensize(&conio_screen_width, &conio_screen_height);
screenlayer(1);
vera_layer_set_textcolor(1, WHITE);

View File

@ -55,6 +55,24 @@ void memcpy_to_vram(char vbank, void* vdest, void* src, unsigned int num ) {
*VERA_DATA0 = *s;
}
// Set block of memory to a value in VRAM.
// Sets num bytes to a value to the memory block pointed to by destination in VRAM.
// - vbank: Which 64K VRAM bank to put data into (0/1)
// - vdest: The destination address in VRAM
// - data: The value to set the vram with.
// - num: The number of bytes to copy
void memset_vram(char vbank, void* vdest, byte data, word num ) {
// Select DATA0
*VERA_CTRL &= ~VERA_ADDRSEL;
// Set address
*VERA_ADDRX_L = <vdest;
*VERA_ADDRX_M = >vdest;
*VERA_ADDRX_H = VERA_INC_1 | vbank;
// Transfer the data
for(word i = 0; i<num; i++)
*VERA_DATA0 = data;
}
// Copy block of memory (from VRAM to VRAM)
// Copies the values from the location pointed by src to the location pointed by dest.
// The method uses the VERA access ports 0 and 1 to copy data from and to in VRAM.

View File

@ -13,6 +13,15 @@
// --- VERA addressing ---
void vera_vram_bank_offset(byte bank, word offset, byte incr) {
// Select DATA0
*VERA_CTRL &= ~VERA_ADDRSEL;
// Set address
*VERA_ADDRX_L = <(offset);
*VERA_ADDRX_M = >(offset);
*VERA_ADDRX_H = bank | incr;
}
void vera_vram_address0(dword bankaddr, byte incr) {
word* word_l = &(<bankaddr);
word* word_h = &(>bankaddr);
@ -35,13 +44,28 @@ void vera_vram_address1(dword bankaddr, byte incr) {
*VERA_ADDRX_H = <(*word_h) | incr;
}
// --- VERA active display management ---
void vera_display_set_scale_none() {
*VERA_DC_HSCALE = 128;
*VERA_DC_VSCALE = 128;
}
void vera_display_set_scale_double() {
*VERA_DC_HSCALE = 64;
*VERA_DC_VSCALE = 64;
}
void vera_display_set_scale_triple() {
*VERA_DC_HSCALE = 32;
*VERA_DC_VSCALE = 32;
}
// --- VERA layer management ---
// Set the configuration of the layer.
// - layer: Value of 0 or 1.
// - config: Specifies the modes which are specified using T256C / 'Bitmap Mode' / 'Color Depth'.
void vera_layer_set_config(byte layer, byte config) {
layer &= $1;
byte* addr = vera_layer_config[layer];
*addr = config;
}
@ -54,6 +78,31 @@ byte vera_layer_get_config(byte layer) {
return *config;
}
// Set the configuration of the layer.
// - layer: Value of 0 or 1.
// - color_mode: Specifies the color mode to be VERA_LAYER_CONFIG_16 or VERA_LAYER_CONFIG_256 for text mode.
void vera_layer_set_text_color_mode( byte layer, byte color_mode ) {
byte* addr = vera_layer_config[layer];
*addr &= ~VERA_LAYER_CONFIG_256C;
*addr |= color_mode;
}
// Set the configuration of the layer to bitmap mode.
// - layer: Value of 0 or 1.
void vera_layer_set_bitmap_mode( byte layer ) {
byte* addr = vera_layer_config[layer];
*addr &= ~VERA_LAYER_CONFIG_MODE_BITMAP;
*addr |= VERA_LAYER_CONFIG_MODE_BITMAP;
}
// Set the configuration of the layer to tilemap mode.
// - layer: Value of 0 or 1.
void vera_layer_set_tilemap_mode( byte layer ) {
byte* addr = vera_layer_config[layer];
*addr &= ~VERA_LAYER_CONFIG_MODE_BITMAP;
*addr |= VERA_LAYER_CONFIG_MODE_TILE;
}
// Set the map width or height of the layer.
// - layer: Value of 0 or 1.
inline void vera_layer_set_width_32(byte layer) {
@ -293,8 +342,8 @@ dword vera_layer_get_tilebase_address(byte layer) {
// Set the front color for text output. The old front text color setting is returned.
// - layer: Value of 0 or 1.
// - color: a 4 bit value ( decimal between 0 and 15).
// This will only work when the VERA is in 16 color mode!
// - color: a 4 bit value ( decimal between 0 and 15) when the VERA works in 16x16 color text mode.
// An 8 bit value (decimal between 0 and 255) when the VERA works in 256 text mode.
// Note that on the VERA, the transparent color has value 0.
byte vera_layer_set_textcolor(byte layer, byte color) {
byte old = vera_layer_textcolor[layer];
@ -308,7 +357,6 @@ byte vera_layer_set_textcolor(byte layer, byte color) {
// This will only work when the VERA is in 16 color mode!
// Note that on the VERA, the transparent color has value 0.
byte vera_layer_get_textcolor(byte layer) {
layer &= $1;
return vera_layer_textcolor[layer];
}
@ -318,7 +366,6 @@ byte vera_layer_get_textcolor(byte layer) {
// This will only work when the VERA is in 16 color mode!
// Note that on the VERA, the transparent color has value 0.
byte vera_layer_set_backcolor(byte layer, byte color) {
layer &= $1;
byte old = vera_layer_backcolor[layer];
vera_layer_backcolor[layer] = color;
return old;
@ -330,7 +377,6 @@ byte vera_layer_set_backcolor(byte layer, byte color) {
// This will only work when the VERA is in 16 color mode!
// Note that on the VERA, the transparent color has value 0.
byte vera_layer_get_backcolor(byte layer) {
layer &= $1;
return vera_layer_backcolor[layer];
}
@ -340,8 +386,11 @@ byte vera_layer_get_backcolor(byte layer) {
// This will only work when the VERA is in 16 color mode!
// Note that on the VERA, the transparent color has value 0.
byte vera_layer_get_color(byte layer) {
layer &= $1;
return ((vera_layer_backcolor[layer] << 4) | vera_layer_textcolor[layer]);
byte* addr = vera_layer_config[layer];
if( *addr & VERA_LAYER_CONFIG_256C )
return (vera_layer_textcolor[layer]);
else
return ((vera_layer_backcolor[layer] << 4) | vera_layer_textcolor[layer]);
}
@ -376,6 +425,7 @@ word vera_layer_get_rowskip(byte layer) {
}
// Set a vera layer in tile mode and configure the:
// - layer: Value of 0 or 1.
// - mapbase_address: A dword typed address (4 bytes), that specifies the full address of the map base.
@ -485,6 +535,96 @@ void vera_layer_mode_tile(byte layer, dword mapbase_address, dword tilebase_addr
vera_layer_set_tilebase(layer,tilebase);
}
// Set a vera layer in text mode and configure the:
// - layer: Value of 0 or 1.
// - mapbase_address: A dword typed address (4 bytes), that specifies the full address of the map base.
// The function does the translation from the dword that contains the 17 bit address,
// to the respective mapbase vera register.
// Note that the register only specifies bits 16:9 of the address,
// so the resulting address in the VERA VRAM is always aligned to a multiple of 512 bytes.
// - tilebase_address: A dword typed address (4 bytes), that specifies the base address of the tile map.
// The function does the translation from the dword that contains the 17 bit address,
// to the respective tilebase vera register.
// Note that the resulting vera register holds only specifies bits 16:11 of the address,
// so the resulting address in the VERA VRAM is always aligned to a multiple of 2048 bytes!
// - mapwidth: The width of the map in number of tiles.
// - mapheight: The height of the map in number of tiles.
// - tilewidth: The width of a tile, which can be 8 or 16 pixels.
// - tileheight: The height of a tile, which can be 8 or 16 pixels.
// - color_mode: The color mode, which can be 16 or 256.
void vera_layer_mode_text(byte layer, dword mapbase_address, dword tilebase_address, word mapwidth, word mapheight, byte tilewidth, byte tileheight, word color_mode ) {
vera_layer_mode_tile( layer, mapbase_address, tilebase_address, mapwidth, mapheight, tilewidth, tileheight, 1 );
switch(color_mode) {
case 16:
vera_layer_set_text_color_mode( layer, VERA_LAYER_CONFIG_16C );
break;
case 256:
vera_layer_set_text_color_mode( layer, VERA_LAYER_CONFIG_256C );
break;
}
}
// Set a vera layer in bitmap mode and configure the:
// - layer: Value of 0 or 1.
// - mapbase_address: A dword typed address (4 bytes), that specifies the full address of the map base.
// The function does the translation from the dword that contains the 17 bit address,
// to the respective mapbase vera register.
// Note that the register only specifies bits 16:9 of the address,
// so the resulting address in the VERA VRAM is always aligned to a multiple of 512 bytes.
// - tilebase_address: A dword typed address (4 bytes), that specifies the base address of the tile map.
// The function does the translation from the dword that contains the 17 bit address,
// to the respective tilebase vera register.
// Note that the resulting vera register holds only specifies bits 16:11 of the address,
// so the resulting address in the VERA VRAM is always aligned to a multiple of 2048 bytes!
// - mapwidth: The width of the map in number of tiles.
// - mapheight: The height of the map in number of tiles.
// - tilewidth: The width of a tile, which can be 8 or 16 pixels.
// - tileheight: The height of a tile, which can be 8 or 16 pixels.
// - color_mode: The color mode, which can be 16 or 256.
void vera_layer_mode_bitmap(byte layer, dword bitmap_address, word mapwidth, word color_depth ) {
// config
byte config = 0x00;
switch(color_depth) {
case 1:
config |= VERA_LAYER_COLOR_DEPTH_1BPP;
break;
case 2:
config |= VERA_LAYER_COLOR_DEPTH_2BPP;
break;
case 4:
config |= VERA_LAYER_COLOR_DEPTH_4BPP;
break;
case 8:
config |= VERA_LAYER_COLOR_DEPTH_8BPP;
break;
}
config = config | VERA_LAYER_CONFIG_MODE_BITMAP;
vera_layer_set_config(layer, config);
// tilebase
vera_tilebase_offset[layer] = <bitmap_address;
vera_tilebase_bank[layer] = (byte)>bitmap_address;
vera_tilebase_address[layer] = bitmap_address;
bitmap_address = bitmap_address >> 1;
byte tilebase = >(<bitmap_address);
tilebase &= VERA_LAYER_TILEBASE_MASK;
// mapwidth
switch(mapwidth) {
case 320:
tilebase |= VERA_TILEBASE_WIDTH_8;
break;
case 640:
tilebase |= VERA_TILEBASE_WIDTH_16;
break;
}
vera_layer_set_tilebase(layer,tilebase);
}
// --- TILE FUNCTIONS ---
void vera_tile_area(byte layer, word tileindex, byte x, byte y, byte w, byte h, byte hflip, byte vflip, byte offset) {

View File

@ -0,0 +1,58 @@
// Example program for the Commander X16.
// Demonstrates the usage of the VERA tile map modes and layering.
// Author: Sven Van de Velde
// The default layer of the CX16 is layer 1, but the tiles are written on layer 0.
// An explanation is given how this mode is organized, and how the tiles display and coloring works.
// Pälette offsets are explained also.
#include <conio.h>
#include <printf.h>
#include <bitmap-draw.h>
char lines_x[] = { 60, 80, 110, 80, 60, 40, 10, 40, 60 };
char lines_y[] = { 10, 40, 60, 80, 110, 80, 60, 40, 10 };
char lines_cnt = 8;
void lines() {
for(char l=0; l<lines_cnt;l++) {
bitmap_line(lines_x[l], lines_x[l+1], lines_y[l], lines_y[l+1]);
}
}
void main() {
vera_layer_mode_bitmap(0, (dword)0x04000, 640, 1);
vera_display_set_scale_none();
screenlayer(1);
textcolor(RED);
bgcolor(BLACK);
clrscr();
gotoxy(0,50);
printf("vera in bitmap mode, color depth 8 bits per pixel.\n");
printf("in this mode, it is possible to display graphics in 256 colors.\n\n");
vera_layer_show(0);
bitmap_init(0x4000);
bitmap_clear();
bitmap_plot( 2, 2);
bitmap_plot( 10, 2);
bitmap_plot( 10, 10);
lines();
while(!kbhit());
screenlayer(1);
textcolor(WHITE);
bgcolor(BLUE);
clrscr();
}

View File

@ -0,0 +1,47 @@
// Example program for the Commander X16.
// Demonstrates the usage of the VERA tile map modes and layering.
// Author: Sven Van de Velde
// The default layer of the CX16 is layer 1, but the tiles are written on layer 0.
// The CX16 starts in tile map mode, 1BPP in 16 color mode, and uses 8x8 tiles.
// An explanation is given how this mode is organized, and how the tiles display and coloring works.
// Pälette offsets are explained also.
#include <veralib.h>
#include <printf.h>
void main() {
textcolor(WHITE);
bgcolor(BLACK);
clrscr();
// Configure the VERA card to work in text, 16x16 mode.
// The color mode is here 16 colors, indicating 16x16 color mode, (16 foreground and 16 background colors).
vera_layer_set_text_color_mode( 1, VERA_LAYER_CONFIG_16C );
// or you can use the below statement, but that includes setting a "mode", including
// layer, map base address, tile base address, map width, map height, tile width, tile height, color mode.
//vera_layer_mode_text(1, 0x00000, 0x0F800, 128, 128, 8, 8, 16);
for(byte c:0..255) {
bgcolor(c);
printf(" ****** ");
}
vera_layer_show(1);
gotoxy(0,50);
textcolor(WHITE);
bgcolor(BLACK);
printf("vera in text mode 8 x 8, color depth 1 bits per pixel.\n");
printf("in this mode, tiles are 8 pixels wide and 8 pixels tall.\n");
printf("each character can have a variation of 16 foreground colors and 16 background colors.\n");
printf("here we display 6 stars (******) each with a different color.\n");
printf("however, the first color will always be transparent (black).\n");
printf("in this mode, the background color cannot be set and is always transparent.\n");
while(!kbhit());
}

View File

@ -0,0 +1,47 @@
// Example program for the Commander X16.
// Demonstrates the usage of the VERA tile map modes and layering.
// Author: Sven Van de Velde
// The default layer of the CX16 is layer 1, but the tiles are written on layer 0.
// The CX16 starts in tile map mode, 1BPP in 16 color mode, and uses 8x8 tiles.
// An explanation is given how this mode is organized, and how the tiles display and coloring works.
// Pälette offsets are explained also.
#include <veralib.h>
#include <printf.h>
void main() {
textcolor(WHITE);
bgcolor(BLACK);
clrscr();
// Configure the VERA card to work in text, 256 mode.
// The color mode is here 256 colors, (256 foreground on a black transparent background).
vera_layer_mode_text( 1, 0x00000, 0x0F800, 128, 128, 8, 8, 256 );
// or you can use the below statement, but that includes setting a "mode", including
// layer, map base address, tile base address, map width, map height, tile width, tile height, color mode.
//vera_layer_mode_text(1, 0x00000, 0x0F800, 128, 128, 8, 8, 256);
for(byte c:0..255) {
textcolor(c);
printf(" ****** ");
}
vera_layer_show(1);
gotoxy(0,50);
textcolor(WHITE);
bgcolor(BLACK);
printf("vera in text mode 8 x 8, color depth 1 bits per pixel.\n");
printf("in this mode, tiles are 8 pixels wide and 8 pixels tall.\n");
printf("each character can have a variation of 256 foreground colors.\n");
printf("here we display 6 stars (******) each with a different color.\n");
printf("however, the first color will always be transparent (black).\n");
printf("in this mode, the background color cannot be set and is always transparent.\n");
while(!kbhit());
}