mirror of
https://gitlab.com/camelot/kickc.git
synced 2024-12-28 01:29:44 +00:00
Bitmap mode - wip
This commit is contained in:
parent
cf185d539b
commit
843c6c91c0
227
src/main/fragment/cache/fragment-cache-wdc65c02.asm
vendored
227
src/main/fragment/cache/fragment-cache-wdc65c02.asm
vendored
@ -4922,3 +4922,230 @@ sta {z1}
|
||||
lda {z1}+1
|
||||
eor {z2}+1
|
||||
sta {z1}+1
|
||||
//FRAGMENT vbuz1=vbuz1_ror_2
|
||||
lda {z1}
|
||||
lsr
|
||||
lsr
|
||||
sta {z1}
|
||||
//FRAGMENT vbuz1=vbuz1_ror_4
|
||||
lda {z1}
|
||||
lsr
|
||||
lsr
|
||||
lsr
|
||||
lsr
|
||||
sta {z1}
|
||||
//FRAGMENT vbuxx=vbuxx_ror_2
|
||||
txa
|
||||
lsr
|
||||
lsr
|
||||
tax
|
||||
//FRAGMENT vduz1=vduz1_rol_2
|
||||
asl {z1}
|
||||
rol {z1}+1
|
||||
rol {z1}+2
|
||||
rol {z1}+3
|
||||
asl {z1}
|
||||
rol {z1}+1
|
||||
rol {z1}+2
|
||||
rol {z1}+3
|
||||
//FRAGMENT vduz1=vduz1_rol_3
|
||||
ldy #3
|
||||
!:
|
||||
asl {z1}
|
||||
rol {z1}+1
|
||||
rol {z1}+2
|
||||
rol {z1}+3
|
||||
dey
|
||||
bne !-
|
||||
//FRAGMENT vduz1=_dword_vwuz2
|
||||
lda {z2}
|
||||
sta {z1}
|
||||
lda {z2}+1
|
||||
sta {z1}+1
|
||||
lda #0
|
||||
sta {z1}+2
|
||||
sta {z1}+3
|
||||
//FRAGMENT vwuz1_neq_0_then_la1
|
||||
lda {z1}
|
||||
ora {z1}+1
|
||||
bne {la1}
|
||||
//FRAGMENT vbuz1_eq_0_then_la1
|
||||
lda {z1}
|
||||
cmp #0
|
||||
beq {la1}
|
||||
//FRAGMENT vduz1=vduz1_plus_vduz2
|
||||
lda {z1}
|
||||
clc
|
||||
adc {z2}
|
||||
sta {z1}
|
||||
lda {z1}+1
|
||||
adc {z2}+1
|
||||
sta {z1}+1
|
||||
lda {z1}+2
|
||||
adc {z2}+2
|
||||
sta {z1}+2
|
||||
lda {z1}+3
|
||||
adc {z2}+3
|
||||
sta {z1}+3
|
||||
//FRAGMENT vwuz1=vwuz1_ror_1
|
||||
lsr {z1}+1
|
||||
ror {z1}
|
||||
//FRAGMENT vbuaa_eq_0_then_la1
|
||||
cmp #0
|
||||
beq {la1}
|
||||
//FRAGMENT vbuxx_eq_0_then_la1
|
||||
cpx #0
|
||||
beq {la1}
|
||||
//FRAGMENT vbuyy_eq_0_then_la1
|
||||
cpy #0
|
||||
beq {la1}
|
||||
//FRAGMENT vwuz1=_word_vduz2
|
||||
lda {z2}
|
||||
sta {z1}
|
||||
lda {z2}+1
|
||||
sta {z1}+1
|
||||
//FRAGMENT vwuz1=vwuz1_rol_6
|
||||
lda {z1}+1
|
||||
lsr
|
||||
sta $ff
|
||||
lda {z1}
|
||||
ror
|
||||
sta {z1}+1
|
||||
lda #0
|
||||
ror
|
||||
sta {z1}
|
||||
lsr $ff
|
||||
ror {z1}+1
|
||||
ror {z1}
|
||||
//FRAGMENT vwuz1=vwuz1_rol_5
|
||||
asl {z1}
|
||||
rol {z1}+1
|
||||
asl {z1}
|
||||
rol {z1}+1
|
||||
asl {z1}
|
||||
rol {z1}+1
|
||||
asl {z1}
|
||||
rol {z1}+1
|
||||
asl {z1}
|
||||
rol {z1}+1
|
||||
//FRAGMENT vwuz1=vwuz1_rol_4
|
||||
asl {z1}
|
||||
rol {z1}+1
|
||||
asl {z1}
|
||||
rol {z1}+1
|
||||
asl {z1}
|
||||
rol {z1}+1
|
||||
asl {z1}
|
||||
rol {z1}+1
|
||||
//FRAGMENT vwuz1=vwuz1_rol_3
|
||||
asl {z1}
|
||||
rol {z1}+1
|
||||
asl {z1}
|
||||
rol {z1}+1
|
||||
asl {z1}
|
||||
rol {z1}+1
|
||||
//FRAGMENT vwuz1=vwuz1_rol_2
|
||||
asl {z1}
|
||||
rol {z1}+1
|
||||
asl {z1}
|
||||
rol {z1}+1
|
||||
//FRAGMENT vwuz1_lt_pwuc1_derefidx_vbuz2_then_la1
|
||||
ldy {z2}
|
||||
lda {z1}+1
|
||||
cmp {c1}+1,y
|
||||
bcc {la1}
|
||||
bne !+
|
||||
lda {z1}
|
||||
cmp {c1},y
|
||||
bcc {la1}
|
||||
!:
|
||||
//FRAGMENT vwuz1_lt_pwuc1_derefidx_vbuxx_then_la1
|
||||
lda {z1}+1
|
||||
cmp {c1}+1,x
|
||||
bcc {la1}
|
||||
bne !+
|
||||
lda {z1}
|
||||
cmp {c1},x
|
||||
bcc {la1}
|
||||
!:
|
||||
//FRAGMENT vwuz1_lt_pwuc1_derefidx_vbuyy_then_la1
|
||||
lda {z1}+1
|
||||
cmp {c1}+1,y
|
||||
bcc {la1}
|
||||
bne !+
|
||||
lda {z1}
|
||||
cmp {c1},y
|
||||
bcc {la1}
|
||||
!:
|
||||
//FRAGMENT vwuz1_lt_pwuc1_derefidx_vbuaa_then_la1
|
||||
tay
|
||||
lda {z1}+1
|
||||
cmp {c1}+1,y
|
||||
bcc {la1}
|
||||
bne !+
|
||||
lda {z1}
|
||||
cmp {c1},y
|
||||
bcc {la1}
|
||||
!:
|
||||
//FRAGMENT vbuz1=_deref_pbuc1_minus__deref_pbuc2
|
||||
lda {c1}
|
||||
sec
|
||||
sbc {c2}
|
||||
sta {z1}
|
||||
//FRAGMENT vwuz1=vwuz1_ror_2
|
||||
lsr {z1}+1
|
||||
ror {z1}
|
||||
lsr {z1}+1
|
||||
ror {z1}
|
||||
//FRAGMENT vbuaa=_deref_pbuc1_minus__deref_pbuc2
|
||||
lda {c1}
|
||||
sec
|
||||
sbc {c2}
|
||||
//FRAGMENT vbuxx=_deref_pbuc1_minus__deref_pbuc2
|
||||
lda {c1}
|
||||
sec
|
||||
sbc {c2}
|
||||
tax
|
||||
//FRAGMENT vbuyy=_deref_pbuc1_minus__deref_pbuc2
|
||||
lda {c1}
|
||||
sec
|
||||
sbc {c2}
|
||||
tay
|
||||
//FRAGMENT vwuz1=_word_vbuaa
|
||||
sta {z1}
|
||||
lda #0
|
||||
sta {z1}+1
|
||||
//FRAGMENT vduz1=vwuz2
|
||||
lda {z2}
|
||||
sta {z1}
|
||||
lda {z2}+1
|
||||
sta {z1}+1
|
||||
lda #0
|
||||
sta {z1}+2
|
||||
sta {z1}+3
|
||||
//FRAGMENT vduz1_lt_vduz2_then_la1
|
||||
lda {z1}+3
|
||||
cmp {z2}+3
|
||||
bcc {la1}
|
||||
bne !+
|
||||
lda {z1}+2
|
||||
cmp {z2}+2
|
||||
bcc {la1}
|
||||
bne !+
|
||||
lda {z1}+1
|
||||
cmp {z2}+1
|
||||
bcc {la1}
|
||||
bne !+
|
||||
lda {z1}
|
||||
cmp {z2}
|
||||
bcc {la1}
|
||||
!:
|
||||
//FRAGMENT vduz1=_inc_vduz1
|
||||
inc {z1}
|
||||
bne !+
|
||||
inc {z1}+1
|
||||
bne !+
|
||||
inc {z1}+2
|
||||
bne !+
|
||||
inc {z1}+3
|
||||
!:
|
||||
|
@ -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(byte layer, word address);
|
||||
void bitmap_init(byte layer, dword address);
|
||||
|
||||
// Clear all graphics on the bitmap
|
||||
void bitmap_clear();
|
||||
|
@ -3,55 +3,97 @@
|
||||
|
||||
#include <bitmap-draw.h>
|
||||
#include <veralib.h>
|
||||
#include <multiply.h>
|
||||
|
||||
// Tables for the plotter - initialized by calling bitmap_draw_init();
|
||||
const word bitmap_plot_x[640];
|
||||
const word bitmap_plot_y[480];
|
||||
const dword bitmap_plot_y[480];
|
||||
const byte bitmap_plot_bit[640];
|
||||
|
||||
__ma word bitmap_address = 0;
|
||||
__ma dword bitmap_address = 0;
|
||||
__ma byte bitmap_layer = 0;
|
||||
|
||||
const word hdeltas[4] = {0, 80, 40, 20};
|
||||
const word vdeltas[4] = {0, 60, 30, 15};
|
||||
const byte bitmasks[5] = {0, $80, $C0, $F0, $FF};
|
||||
|
||||
// Initialize the bitmap plotter tables for a specific bitmap
|
||||
void bitmap_init(byte layer, word address) {
|
||||
void bitmap_init(byte layer, dword 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 vscale = vera_display_get_vscale(); // Returns 1 when 480 and 2 when 240.
|
||||
byte bitmask = bitmasks[color_depth];
|
||||
|
||||
|
||||
byte bit = $80;
|
||||
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;
|
||||
if(color_depth==1) {
|
||||
bitmap_plot_x[x] = (x >> 3);
|
||||
bitmap_plot_bit[x] = bitmask;
|
||||
bitmask >>= 1;
|
||||
}
|
||||
if(color_depth==2) {
|
||||
bitmap_plot_x[x] = (x >> 2);
|
||||
bitmap_plot_bit[x] = bitmask;
|
||||
bitmask >>= 2;
|
||||
}
|
||||
if(color_depth==4) {
|
||||
bitmap_plot_x[x] = (x >> 1);
|
||||
bitmap_plot_bit[x] = bitmask;
|
||||
bitmask >>= 4;
|
||||
}
|
||||
if(color_depth==8) {
|
||||
bitmap_plot_x[x] = x;
|
||||
bitmap_plot_bit[x] = bitmask;
|
||||
}
|
||||
if(bitmask==0) {
|
||||
bitmask = bitmasks[color_depth];
|
||||
}
|
||||
}
|
||||
|
||||
// This sets the right delta to skip a whole line based on the scale, depending on the color depth.
|
||||
word vdelta = vdeltas[hscale];
|
||||
word hdelta = hdeltas[hscale];
|
||||
if(color_depth==8) hdelta = hdelta << 3;
|
||||
if(color_depth==4) hdelta = hdelta << 2;
|
||||
if(color_depth==2) hdelta = hdelta << 1;
|
||||
|
||||
// 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;
|
||||
dword yoffs = bitmap_address;
|
||||
for(word y : 0..479) {
|
||||
bitmap_plot_y[y] = yoffs;
|
||||
yoffs = yoffs + vdelta;
|
||||
//bitmap_plot_y[y] = yoffs;
|
||||
yoffs = yoffs + hdelta;
|
||||
}
|
||||
}
|
||||
|
||||
// Clear all graphics on the bitmap
|
||||
void bitmap_clear() {
|
||||
memset_vram(0,bitmap_address,0,80*60*8);
|
||||
byte color_depth = vera_layer_get_color_depth(bitmap_layer);
|
||||
byte bitmask = bitmasks[color_depth];
|
||||
byte hscale = vera_display_get_hscale(); // Returns 1 when 640 and 2 when 320.
|
||||
byte vscale = vera_display_get_vscale(); // Returns 1 when 480 and 2 when 240.
|
||||
word count = hdeltas[hscale];
|
||||
if(color_depth==8) count = count << 6;
|
||||
if(color_depth==4) count = count << 5;
|
||||
if(color_depth==2) count = count << 4;
|
||||
if(color_depth==1) count = count << 3;
|
||||
word lines = vera_display_get_height();
|
||||
dword address = bitmap_address;
|
||||
word hdelta = hdeltas[hscale];
|
||||
if(color_depth==8) hdelta = hdelta << 3;
|
||||
if(color_depth==4) hdelta = hdelta << 2;
|
||||
if(color_depth==2) hdelta = hdelta << 1;
|
||||
for(word line=0; line<lines; line++) {
|
||||
memset_vram_address(address,0,count);
|
||||
address+=hdelta;
|
||||
}
|
||||
}
|
||||
|
||||
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 = bitmap_plot_x[x]+bitmap_plot_y[y];
|
||||
vera_vram_bank_offset(0,(word)plotter,VERA_INC_0);
|
||||
dword plot_x = bitmap_plot_x[x];
|
||||
dword plot_y = bitmap_plot_y[y];
|
||||
dword plotter = plot_x+plot_y;
|
||||
vera_vram_address0(plotter,VERA_INC_0);
|
||||
*VERA_DATA0 = *VERA_DATA0 | bitmap_plot_bit[x];
|
||||
}
|
||||
|
||||
|
@ -73,6 +73,25 @@ void memset_vram(char vbank, void* vdest, byte data, word num ) {
|
||||
*VERA_DATA0 = data;
|
||||
}
|
||||
|
||||
// Set block of dword 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_address(dword vdest_address, byte data, dword num ) {
|
||||
// Select DATA0
|
||||
*VERA_CTRL &= ~VERA_ADDRSEL;
|
||||
// Set address
|
||||
*VERA_ADDRX_L = <(<vdest_address);
|
||||
*VERA_ADDRX_M = >(<vdest_address);
|
||||
*VERA_ADDRX_H = <(>vdest_address);
|
||||
*VERA_ADDRX_H |= VERA_INC_1;
|
||||
// Transfer the data
|
||||
for(dword 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.
|
||||
|
@ -85,6 +85,20 @@ byte vera_display_get_vscale() {
|
||||
return scale;
|
||||
}
|
||||
|
||||
word vera_display_get_height() {
|
||||
byte scale = vera_display_get_vscale();
|
||||
word height = (word)(*VERA_DC_VSTOP - *VERA_DC_VSTART);
|
||||
switch( scale ) {
|
||||
case 2:
|
||||
height = height >> 1;
|
||||
break;
|
||||
case 3:
|
||||
height = height >> 2;
|
||||
break;
|
||||
}
|
||||
return height<<1;
|
||||
}
|
||||
|
||||
|
||||
// --- VERA layer management ---
|
||||
|
||||
|
@ -24,7 +24,7 @@ void lines() {
|
||||
}
|
||||
void main() {
|
||||
|
||||
vera_layer_mode_bitmap(0, (dword)0x04000, 320, 1);
|
||||
vera_layer_mode_bitmap(0, (dword)0x04000, 640, 1);
|
||||
|
||||
screenlayer(1);
|
||||
textcolor(RED);
|
||||
|
Loading…
Reference in New Issue
Block a user