1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2025-04-14 10:37:36 +00:00

Bitmap mode

This commit is contained in:
FlightControl 2021-01-20 09:02:35 +01:00
parent 6c8654fbc8
commit cf185d539b
7 changed files with 293 additions and 33 deletions

View File

@ -4713,3 +4713,212 @@ lda {z1}
cmp #<{c1}
bcc {la1}
!:
//FRAGMENT pbuc1_derefidx_vbuz1_eq_vbuz2_then_la1
ldy {z1}
lda {c1},y
cmp {z2}
beq {la1}
//FRAGMENT vwuz1=vwuz2_ror_2
lda {z2}+1
lsr
sta {z1}+1
lda {z2}
ror
sta {z1}
lsr {z1}+1
ror {z1}
//FRAGMENT vwuz1=_deref_pwuz2_plus__deref_pwuz3
ldy #0
clc
lda ({z2}),y
adc ({z3}),y
sta {z1}
iny
lda ({z2}),y
adc ({z3}),y
sta {z1}+1
//FRAGMENT vbuz1=_deref_pbuc1_bor__deref_pbuz2
lda {c1}
ldy #0
ora ({z2}),y
sta {z1}
//FRAGMENT _deref_pbuc1_neq_pbuc2_derefidx_vbuz1_then_la1
lda {c1}
ldy {z1}
cmp {c2},y
bne {la1}
//FRAGMENT pbuc1_derefidx_vbuz1_eq_vbuaa_then_la1
ldx {z1}
tay
lda {c1},x
tax
sty $ff
cpx $ff
beq {la1}
//FRAGMENT pbuc1_derefidx_vbuz1_eq_vbuxx_then_la1
ldy {z1}
lda {c1},y
tay
sty $ff
cpx $ff
beq {la1}
//FRAGMENT pbuc1_derefidx_vbuz1_eq_vbuyy_then_la1
ldx {z1}
lda {c1},x
tax
sty $ff
cpx $ff
beq {la1}
//FRAGMENT pbuc1_derefidx_vbuaa_eq_vbuz1_then_la1
tay
lda {c1},y
cmp {z1}
beq {la1}
//FRAGMENT pbuc1_derefidx_vbuaa_eq_vbuaa_then_la1
tax
lda {c1},x
tay
sty $ff
cpx $ff
beq {la1}
//FRAGMENT pbuc1_derefidx_vbuaa_eq_vbuxx_then_la1
tay
lda {c1},y
tay
sty $ff
cpx $ff
beq {la1}
//FRAGMENT pbuc1_derefidx_vbuaa_eq_vbuyy_then_la1
tax
lda {c1},x
tax
sty $ff
cpx $ff
beq {la1}
//FRAGMENT pbuc1_derefidx_vbuxx_eq_vbuz1_then_la1
lda {c1},x
cmp {z1}
beq {la1}
//FRAGMENT pbuc1_derefidx_vbuxx_eq_vbuaa_then_la1
tay
lda {c1},x
tax
sty $ff
cpx $ff
beq {la1}
//FRAGMENT pbuc1_derefidx_vbuxx_eq_vbuxx_then_la1
lda {c1},x
tay
sty $ff
cpx $ff
beq {la1}
//FRAGMENT pbuc1_derefidx_vbuxx_eq_vbuyy_then_la1
lda {c1},x
tax
sty $ff
cpx $ff
beq {la1}
//FRAGMENT pbuc1_derefidx_vbuyy_eq_vbuz1_then_la1
lda {c1},y
cmp {z1}
beq {la1}
//FRAGMENT pbuc1_derefidx_vbuyy_eq_vbuaa_then_la1
tax
lda {c1},y
tay
sty $ff
cpx $ff
beq {la1}
//FRAGMENT pbuc1_derefidx_vbuyy_eq_vbuxx_then_la1
lda {c1},y
tay
sty $ff
cpx $ff
beq {la1}
//FRAGMENT pbuc1_derefidx_vbuyy_eq_vbuyy_then_la1
lda {c1},y
tax
sty $ff
cpx $ff
beq {la1}
//FRAGMENT vbuaa=_deref_pbuc1_bor__deref_pbuz1
lda {c1}
ldy #0
ora ({z1}),y
//FRAGMENT vbuxx=_deref_pbuc1_bor__deref_pbuz1
lda {c1}
ldy #0
ora ({z1}),y
tax
//FRAGMENT vbuyy=_deref_pbuc1_bor__deref_pbuz1
lda {c1}
ldy #0
ora ({z1}),y
tay
//FRAGMENT _deref_pbuc1_neq_pbuc2_derefidx_vbuaa_then_la1
tay
lda {c1}
cmp {c2},y
bne {la1}
//FRAGMENT _deref_pbuc1_neq_pbuc2_derefidx_vbuxx_then_la1
lda {c2},x
cmp {c1}
bne {la1}
//FRAGMENT _deref_pbuc1_neq_pbuc2_derefidx_vbuyy_then_la1
lda {c1}
cmp {c2},y
bne {la1}
//FRAGMENT pbuz1=pbuc1_plus_vwuz1
clc
lda {z1}
adc #<{c1}
sta {z1}
lda {z1}+1
adc #>{c1}
sta {z1}+1
//FRAGMENT vwuz1=_deref_pwuz2_plus__deref_pwuz1
ldy #0
clc
lda ({z1}),y
adc ({z2}),y
pha
iny
lda ({z1}),y
adc ({z2}),y
sta {z1}+1
pla
sta {z1}
//FRAGMENT vwuz1=vwuz2_rol_7
lda {z2}+1
lsr
lda {z2}
ror
sta {z1}+1
lda #0
ror
sta {z1}
//FRAGMENT vwuz1=vwuz2_bxor_vwuz3
lda {z2}
eor {z3}
sta {z1}
lda {z2}+1
eor {z3}+1
sta {z1}+1
//FRAGMENT vwuz1=vwuz2_ror_9
lda {z2}+1
lsr
sta {z1}
lda #0
sta {z1}+1
//FRAGMENT vwuz1=vwuz2_rol_8
lda {z2}
sta {z1}+1
lda #0
sta {z1}
//FRAGMENT vwuz1=vwuz1_bxor_vwuz2
lda {z1}
eor {z2}
sta {z1}
lda {z1}+1
eor {z2}+1
sta {z1}+1

View File

@ -2,7 +2,7 @@
// Currently it can only plot on the first 256 x-positions.
// Initialize the bitmap plotter tables for a specific bitmap
void bitmap_init(word bitmap_address);
void bitmap_init(byte layer, word address);
// Clear all graphics on the bitmap
void bitmap_clear();

View File

@ -35,6 +35,14 @@ byte* vera_layer_hscroll_h[2] = {VERA_L0_HSCROLL_H, VERA_L1_HSCROLL_H};
byte vera_layer_textcolor[2] = {WHITE, WHITE};
byte vera_layer_backcolor[2] = {BLUE, BLUE};
// --- VERA active display management ---
void vera_display_set_scale_none();
void vera_display_set_scale_double();
void vera_display_set_scale_triple();
byte vera_display_get_hscale();
byte vera_display_get_vscale();
// --- VERA LAYERS ---
// Set the configuration of the layer.

View File

@ -18,6 +18,7 @@ const char bitmap_plot_bit[256];
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;
@ -31,7 +32,7 @@ void bitmap_init(char* gfx, char* screen) {
bitmap_plot_ylo[y] = y&$7 | <yoffs;
bitmap_plot_yhi[y] = >yoffs;
if((y&$7)==7) {
yoffs = yoffs + 40*8;
yoffs = yoffs + 480 >> hscale;
}
}
}

View File

@ -5,38 +5,54 @@
#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];
const word bitmap_plot_x[640];
const word bitmap_plot_y[480];
const byte bitmap_plot_bit[640];
__ma word bitmap_address = 0;
__ma byte bitmap_layer = 0;
word bitmap = 0;
// Initialize the bitmap plotter tables for a specific bitmap
void bitmap_init(word bitmap_address) {
bitmap = bitmap_address;
word yoffs = $0;
void bitmap_init(byte layer, word address) {
bitmap_address = address;
bitmap_layer = layer;
byte color_depth = vera_layer_get_color_depth(bitmap_layer);
word vdeltas[4] = {0, 80, 40, 20};
byte hscale = vera_display_get_hscale(); // Returns 1 when 640 and 2 when 320.
byte bit = $80;
for(word x : 0..7) {
for(word x : 0..639) {
if(color_depth==1) bitmap_plot_x[x] = (x >> 3);
if(color_depth==2) bitmap_plot_x[x] = (x >> 2);
if(color_depth==4) bitmap_plot_x[x] = (x >> 1);
if(color_depth==8) {}
bitmap_plot_bit[x] = bit;
bit >>= 1;
if(bit==0)
bit=$80;
}
for(word y : 0..600) {
// This sets the right delta to skip a whole line based on the scale, depending on the color depth.
word vdelta = vdeltas[hscale];
// We start at the bitmap address; The plot_y contains the bitmap address embedded so we know where a line starts.
word yoffs = bitmap_address;
for(word y : 0..479) {
bitmap_plot_y[y] = yoffs;
yoffs = yoffs + 80;
yoffs = yoffs + vdelta;
}
}
// Clear all graphics on the bitmap
void bitmap_clear() {
memset_vram(0,bitmap,0,80*60*8);
memset_vram(0,bitmap_address,0,80*60*8);
}
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;
word plotter = bitmap_plot_x[x]+bitmap_plot_y[y];
vera_vram_bank_offset(0,(word)plotter,VERA_INC_0);
*VERA_DATA0 = *VERA_DATA0 | bitmap_plot_bit[x&$07];
*VERA_DATA0 = *VERA_DATA0 | bitmap_plot_bit[x];
}

View File

@ -60,6 +60,32 @@ void vera_display_set_scale_triple() {
*VERA_DC_HSCALE = 32;
*VERA_DC_VSCALE = 32;
}
byte vera_display_get_hscale() {
byte hscale[4] = {0,128,64,32};
byte scale = 0;
for(byte s:1..3) {
if(*VERA_DC_HSCALE==hscale[s]) {
scale = s;
break;
}
}
return scale;
}
byte vera_display_get_vscale() {
byte vscale[4] = {0,128,64,32};
byte scale = 0;
for(byte s:1..3) {
if(*VERA_DC_VSCALE==vscale[s]) {
scale = s;
break;
}
}
return scale;
}
// --- VERA layer management ---
// Set the configuration of the layer.
@ -187,7 +213,7 @@ inline void vera_layer_set_color_depth_8BPP(byte layer) {
// Get the map width or height of the layer.
// - layer: Value of 0 or 1.
// - return: 1, 2, 4 or 8.
word vera_layer_get_color_depth(byte layer) {
byte vera_layer_get_color_depth(byte layer) {
byte* config = vera_layer_config[layer];
byte mask = (byte)VERA_LAYER_COLOR_DEPTH_MASK;
return VERA_LAYER_COLOR_DEPTH[(*config & mask)];
@ -602,7 +628,6 @@ void vera_layer_mode_bitmap(byte layer, dword bitmap_address, word mapwidth, wor
break;
}
config = config | VERA_LAYER_CONFIG_MODE_BITMAP;
vera_layer_set_config(layer, config);
// tilebase
vera_tilebase_offset[layer] = <bitmap_address;
@ -616,13 +641,17 @@ void vera_layer_mode_bitmap(byte layer, dword bitmap_address, word mapwidth, wor
// mapwidth
switch(mapwidth) {
case 320:
vera_display_set_scale_double();
tilebase |= VERA_TILEBASE_WIDTH_8;
break;
case 640:
vera_display_set_scale_none();
tilebase |= VERA_TILEBASE_WIDTH_16;
break;
}
vera_layer_set_tilebase(layer,tilebase);
vera_layer_set_config(layer, config);
}
// --- TILE FUNCTIONS ---

View File

@ -11,6 +11,7 @@
#include <conio.h>
#include <printf.h>
#include <bitmap-draw.h>
#include <stdlib.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 };
@ -23,32 +24,28 @@ void lines() {
}
void main() {
vera_layer_mode_bitmap(0, (dword)0x04000, 640, 1);
vera_display_set_scale_none();
vera_layer_mode_bitmap(0, (dword)0x04000, 320, 1);
screenlayer(1);
textcolor(RED);
bgcolor(BLACK);
clrscr();
gotoxy(0,50);
printf("vera in bitmap mode, color depth 8 bits per pixel.\n");
gotoxy(0,20);
printf("vera in bitmap mode,\n");
printf("color depth 8 bits per pixel.\n");
printf("in this mode, it is possible to display graphics in 256 colors.\n\n");
printf("in this mode, it is possible to display\n\n");
printf("graphics in 256 colors.\n\n");
vera_layer_show(0);
bitmap_init(0x4000);
bitmap_init(0, 0x4000);
bitmap_clear();
bitmap_plot( 2, 2);
bitmap_plot( 10, 2);
bitmap_plot( 10, 10);
lines();
while(!kbhit());
while(!kbhit()) {
bitmap_line(rand()&$00FF, rand()&$00FF, rand()&$007F, rand()&$007F);
};
screenlayer(1);
textcolor(WHITE);