1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2025-04-10 13:38:18 +00:00

progress with vera encapsulation.

- vera layers
- vera layer config
- vera layer mapbase
- vera layer tilebase
- vera layer color

now conio is using the new vera functions. conio is cleaned from exotic functions, except screenlayer, which i believe should be part of conio to indicate to which layer conio is outputting.
This commit is contained in:
FlightControl 2021-01-11 22:58:00 +01:00
parent f9f7eec372
commit d24ca095dd
7 changed files with 897 additions and 147 deletions

View File

@ -2315,3 +2315,545 @@ tay
sta {z1}
lda #0
sta {z1}+1
//FRAGMENT pbuc1_derefidx_vbuz1=vbuz2
lda {z2}
ldy {z1}
sta {c1},y
//FRAGMENT pbuc1_derefidx_vbuz1=vbuxx
ldy {z1}
txa
sta {c1},y
//FRAGMENT pbuc1_derefidx_vbuz1=vbuyy
tya
ldy {z1}
sta {c1},y
//FRAGMENT pbuc1_derefidx_vbuaa=vbuz1
tay
lda {z1}
sta {c1},y
//FRAGMENT pbuc1_derefidx_vbuaa=vbuxx
tay
txa
sta {c1},y
//FRAGMENT pbuc1_derefidx_vbuaa=vbuyy
tax
tya
sta {c1},x
//FRAGMENT pbuc1_derefidx_vbuxx=vbuz1
lda {z1}
sta {c1},x
//FRAGMENT pbuc1_derefidx_vbuxx=vbuxx
txa
sta {c1},x
//FRAGMENT pbuc1_derefidx_vbuxx=vbuyy
tya
sta {c1},x
//FRAGMENT pbuc1_derefidx_vbuyy=vbuz1
lda {z1}
sta {c1},y
//FRAGMENT pbuc1_derefidx_vbuyy=vbuxx
txa
sta {c1},y
//FRAGMENT pbuc1_derefidx_vbuyy=vbuyy
tya
sta {c1},y
//FRAGMENT vbuz1=vbuaa_rol_4
asl
asl
asl
asl
sta {z1}
//FRAGMENT vbuz1=vbuxx_rol_4
txa
asl
asl
asl
asl
sta {z1}
//FRAGMENT vbuz1=vbuyy_rol_4
tya
asl
asl
asl
asl
sta {z1}
//FRAGMENT vbuaa=vbuaa_rol_4
asl
asl
asl
asl
//FRAGMENT vbuaa=vbuxx_rol_4
txa
asl
asl
asl
asl
//FRAGMENT vbuaa=vbuyy_rol_4
tya
asl
asl
asl
asl
//FRAGMENT vbuxx=vbuaa_rol_4
asl
asl
asl
asl
tax
//FRAGMENT vbuxx=vbuxx_rol_4
txa
asl
asl
asl
asl
tax
//FRAGMENT vbuxx=vbuyy_rol_4
tya
asl
asl
asl
asl
tax
//FRAGMENT vbuyy=vbuaa_rol_4
asl
asl
asl
asl
tay
//FRAGMENT vbuyy=vbuxx_rol_4
txa
asl
asl
asl
asl
tay
//FRAGMENT vbuyy=vbuyy_rol_4
tya
asl
asl
asl
asl
tay
//FRAGMENT vbuz1=vbuz2_bor_vbuaa
ora {z2}
sta {z1}
//FRAGMENT vbuaa=vbuz1_bor_vbuaa
ora {z1}
//FRAGMENT vbuxx=vbuz1_bor_vbuaa
ora {z1}
tax
//FRAGMENT vbuyy=vbuz1_bor_vbuaa
ora {z1}
tay
//FRAGMENT vbuz1=vbuz2_bor_vbuxx
txa
ora {z2}
sta {z1}
//FRAGMENT vbuaa=vbuz1_bor_vbuxx
txa
ora {z1}
//FRAGMENT vbuxx=vbuz1_bor_vbuxx
txa
ora {z1}
tax
//FRAGMENT vbuyy=vbuz1_bor_vbuxx
txa
ora {z1}
tay
//FRAGMENT vbuz1=vbuz2_bor_vbuyy
tya
ora {z2}
sta {z1}
//FRAGMENT vbuaa=vbuz1_bor_vbuyy
tya
ora {z1}
//FRAGMENT vbuxx=vbuz1_bor_vbuyy
tya
ora {z1}
tax
//FRAGMENT vbuyy=vbuz1_bor_vbuyy
tya
ora {z1}
tay
//FRAGMENT vbuz1=vbuaa_bor_vbuaa
sta {z1}
//FRAGMENT vbuz1=pbuc1_derefidx_vbuyy
lda {c1},y
sta {z1}
//FRAGMENT vbuaa=pbuc1_derefidx_vbuxx
lda {c1},x
//FRAGMENT vbuaa=pbuc1_derefidx_vbuyy
lda {c1},y
//FRAGMENT vbuz1=vbuxx_bor_vbuaa
stx $ff
ora $ff
sta {z1}
//FRAGMENT vbuxx=vbuxx_bor_vbuaa
stx $ff
ora $ff
tax
//FRAGMENT vbuyy=vbuxx_bor_vbuaa
stx $ff
ora $ff
tay
//FRAGMENT vbuz1=vbuxx_bor_vbuxx
stx {z1}
//FRAGMENT vbuxx=pbuc1_derefidx_vbuxx
lda {c1},x
tax
//FRAGMENT vbuxx=pbuc1_derefidx_vbuyy
ldx {c1},y
//FRAGMENT vbuyy=pbuc1_derefidx_vbuxx
ldy {c1},x
//FRAGMENT vbuyy=pbuc1_derefidx_vbuyy
lda {c1},y
tay
//FRAGMENT vbuz1=vbuyy_bor_vbuaa
sty $ff
ora $ff
sta {z1}
//FRAGMENT vbuz1=vbuz1_bor_vbuaa
ora {z1}
sta {z1}
//FRAGMENT vbuz1=pbuc1_derefidx_vbuz2_rol_4
ldy {z2}
lda {c1},y
asl
asl
asl
asl
sta {z1}
//FRAGMENT vbuz1=vbuz2_bor_pbuc1_derefidx_vbuz3
lda {z2}
ldy {z3}
ora {c1},y
sta {z1}
//FRAGMENT vbuz1=pbuc1_derefidx_vbuaa_rol_4
tay
lda {c1},y
asl
asl
asl
asl
sta {z1}
//FRAGMENT vbuz1=pbuc1_derefidx_vbuxx_rol_4
lda {c1},x
asl
asl
asl
asl
sta {z1}
//FRAGMENT vbuz1=pbuc1_derefidx_vbuyy_rol_4
lda {c1},y
asl
asl
asl
asl
sta {z1}
//FRAGMENT vbuaa=pbuc1_derefidx_vbuz1_rol_4
ldy {z1}
lda {c1},y
asl
asl
asl
asl
//FRAGMENT vbuaa=pbuc1_derefidx_vbuaa_rol_4
tay
lda {c1},y
asl
asl
asl
asl
//FRAGMENT vbuaa=pbuc1_derefidx_vbuxx_rol_4
lda {c1},x
asl
asl
asl
asl
//FRAGMENT vbuaa=pbuc1_derefidx_vbuyy_rol_4
lda {c1},y
asl
asl
asl
asl
//FRAGMENT vbuxx=pbuc1_derefidx_vbuz1_rol_4
ldx {z1}
lda {c1},x
asl
asl
asl
asl
tax
//FRAGMENT vbuxx=pbuc1_derefidx_vbuaa_rol_4
tax
lda {c1},x
asl
asl
asl
asl
tax
//FRAGMENT vbuxx=pbuc1_derefidx_vbuxx_rol_4
lda {c1},x
asl
asl
asl
asl
tax
//FRAGMENT vbuxx=pbuc1_derefidx_vbuyy_rol_4
lda {c1},y
asl
asl
asl
asl
tax
//FRAGMENT vbuyy=pbuc1_derefidx_vbuz1_rol_4
ldy {z1}
lda {c1},y
asl
asl
asl
asl
tay
//FRAGMENT vbuyy=pbuc1_derefidx_vbuaa_rol_4
tay
lda {c1},y
asl
asl
asl
asl
tay
//FRAGMENT vbuyy=pbuc1_derefidx_vbuxx_rol_4
lda {c1},x
asl
asl
asl
asl
tay
//FRAGMENT vbuyy=pbuc1_derefidx_vbuyy_rol_4
lda {c1},y
asl
asl
asl
asl
tay
//FRAGMENT vbuz1=vbuz2_bor_pbuc1_derefidx_vbuxx
lda {c1},x
ora {z2}
sta {z1}
//FRAGMENT vbuz1=vbuz2_bor_pbuc1_derefidx_vbuyy
lda {c1},y
ora {z2}
sta {z1}
//FRAGMENT vbuaa=vbuz1_bor_pbuc1_derefidx_vbuz2
lda {z1}
ldy {z2}
ora {c1},y
//FRAGMENT vbuaa=vbuz1_bor_pbuc1_derefidx_vbuxx
lda {c1},x
ora {z1}
//FRAGMENT vbuaa=vbuz1_bor_pbuc1_derefidx_vbuyy
lda {c1},y
ora {z1}
//FRAGMENT vbuxx=vbuz1_bor_pbuc1_derefidx_vbuz2
lda {z1}
ldx {z2}
ora {c1},x
tax
//FRAGMENT vbuxx=vbuz1_bor_pbuc1_derefidx_vbuxx
lda {c1},x
ora {z1}
tax
//FRAGMENT vbuxx=vbuz1_bor_pbuc1_derefidx_vbuyy
lda {c1},y
ora {z1}
tax
//FRAGMENT vbuyy=vbuz1_bor_pbuc1_derefidx_vbuz2
lda {z1}
ldy {z2}
ora {c1},y
tay
//FRAGMENT vbuyy=vbuz1_bor_pbuc1_derefidx_vbuxx
lda {c1},x
ora {z1}
tay
//FRAGMENT vbuyy=vbuz1_bor_pbuc1_derefidx_vbuyy
lda {c1},y
ora {z1}
tay
//FRAGMENT vbuz1=vbuaa_bor_pbuc1_derefidx_vbuz2
ldy {z2}
ora {c1},y
sta {z1}
//FRAGMENT vbuz1=vbuaa_bor_pbuc1_derefidx_vbuxx
ora {c1},x
sta {z1}
//FRAGMENT vbuz1=vbuaa_bor_pbuc1_derefidx_vbuyy
ora {c1},y
sta {z1}
//FRAGMENT vbuaa=vbuaa_bor_pbuc1_derefidx_vbuz1
ldy {z1}
ora {c1},y
//FRAGMENT vbuaa=vbuaa_bor_pbuc1_derefidx_vbuxx
ora {c1},x
//FRAGMENT vbuaa=vbuaa_bor_pbuc1_derefidx_vbuyy
ora {c1},y
//FRAGMENT vbuxx=vbuaa_bor_pbuc1_derefidx_vbuz1
ldx {z1}
ora {c1},x
tax
//FRAGMENT vbuxx=vbuaa_bor_pbuc1_derefidx_vbuxx
ora {c1},x
tax
//FRAGMENT vbuxx=vbuaa_bor_pbuc1_derefidx_vbuyy
ora {c1},y
tax
//FRAGMENT vbuyy=vbuaa_bor_pbuc1_derefidx_vbuz1
ldy {z1}
ora {c1},y
tay
//FRAGMENT vbuyy=vbuaa_bor_pbuc1_derefidx_vbuxx
ora {c1},x
tay
//FRAGMENT vbuyy=vbuaa_bor_pbuc1_derefidx_vbuyy
ora {c1},y
tay
//FRAGMENT vbuz1=vbuxx_bor_pbuc1_derefidx_vbuz2
ldy {z2}
txa
ora {c1},y
sta {z1}
//FRAGMENT vbuz1=vbuxx_bor_pbuc1_derefidx_vbuxx
txa
ora {c1},x
sta {z1}
//FRAGMENT vbuz1=vbuxx_bor_pbuc1_derefidx_vbuyy
txa
ora {c1},y
sta {z1}
//FRAGMENT vbuaa=vbuxx_bor_pbuc1_derefidx_vbuz1
ldy {z1}
txa
ora {c1},y
//FRAGMENT vbuaa=vbuxx_bor_pbuc1_derefidx_vbuxx
txa
ora {c1},x
//FRAGMENT vbuaa=vbuxx_bor_pbuc1_derefidx_vbuyy
txa
ora {c1},y
//FRAGMENT vbuxx=vbuxx_bor_pbuc1_derefidx_vbuz1
txa
ldx {z1}
ora {c1},x
tax
//FRAGMENT vbuxx=vbuxx_bor_pbuc1_derefidx_vbuxx
txa
ora {c1},x
tax
//FRAGMENT vbuxx=vbuxx_bor_pbuc1_derefidx_vbuyy
txa
ora {c1},y
tax
//FRAGMENT vbuyy=vbuxx_bor_pbuc1_derefidx_vbuz1
ldy {z1}
txa
ora {c1},y
tay
//FRAGMENT vbuyy=vbuxx_bor_pbuc1_derefidx_vbuxx
txa
ora {c1},x
tay
//FRAGMENT vbuyy=vbuxx_bor_pbuc1_derefidx_vbuyy
txa
ora {c1},y
tay
//FRAGMENT vbuz1=vbuyy_bor_pbuc1_derefidx_vbuz2
tya
ldy {z2}
ora {c1},y
sta {z1}
//FRAGMENT vbuz1=vbuyy_bor_pbuc1_derefidx_vbuxx
tya
ora {c1},x
sta {z1}
//FRAGMENT vbuz1=vbuyy_bor_pbuc1_derefidx_vbuyy
tya
ora {c1},y
sta {z1}
//FRAGMENT vbuaa=vbuyy_bor_pbuc1_derefidx_vbuz1
tya
ldy {z1}
ora {c1},y
//FRAGMENT vbuaa=vbuyy_bor_pbuc1_derefidx_vbuxx
tya
ora {c1},x
//FRAGMENT vbuaa=vbuyy_bor_pbuc1_derefidx_vbuyy
tya
ora {c1},y
//FRAGMENT vbuxx=vbuyy_bor_pbuc1_derefidx_vbuz1
ldx {z1}
tya
ora {c1},x
tax
//FRAGMENT vbuxx=vbuyy_bor_pbuc1_derefidx_vbuxx
tya
ora {c1},x
tax
//FRAGMENT vbuxx=vbuyy_bor_pbuc1_derefidx_vbuyy
tya
ora {c1},y
tax
//FRAGMENT vbuyy=vbuyy_bor_pbuc1_derefidx_vbuz1
tya
ldy {z1}
ora {c1},y
tay
//FRAGMENT vbuyy=vbuyy_bor_pbuc1_derefidx_vbuxx
tya
ora {c1},x
tay
//FRAGMENT vbuyy=vbuyy_bor_pbuc1_derefidx_vbuyy
tya
ora {c1},y
tay
//FRAGMENT vbuz1=_deref_pbuc1_band__deref_pbuc2
lda {c1}
and {c2}
sta {z1}
//FRAGMENT vbuaa=_deref_pbuc1_band__deref_pbuc2
lda {c1}
and {c2}
//FRAGMENT vbuxx=_deref_pbuc1_band__deref_pbuc2
lda {c1}
and {c2}
tax
//FRAGMENT vbuyy=_deref_pbuc1_band__deref_pbuc2
lda {c1}
and {c2}
tay
//FRAGMENT vwuz1=vbuz2_rol_1
lda {z2}
asl
sta {z1}
lda #0
rol
sta {z1}+1
//FRAGMENT vwuz1=vbuaa_rol_1
asl
sta {z1}
lda #0
rol
sta {z1}+1
//FRAGMENT vwuz1=vbuxx_rol_1
txa
asl
sta {z1}
lda #0
rol
sta {z1}+1
//FRAGMENT vwuz1=vbuyy_rol_1
tya
asl
sta {z1}
lda #0
rol
sta {z1}+1

View File

@ -43,10 +43,10 @@ void cputs(const char* s);
void cputsxy(unsigned byte x, unsigned byte y, const char* s);
// Set the color for text output. The old color setting is returned.
unsigned byte textcolor(unsigned byte color);
char textcolor(char color);
// Set the color for the background. The old color setting is returned.
unsigned byte bgcolor(unsigned byte color);
char bgcolor(char color);
// Set the color for the border. The old color setting is returned.
unsigned byte bordercolor(unsigned byte color);

View File

@ -1,6 +1,24 @@
// Commander X16 VERA (Versatile Embedded Retro Adapter) Video and Audio Processor
// https://github.com/commanderx16/x16-docs/blob/master/VERA%20Programmer's%20Reference.md
// The colors of the CX16
const char BLACK = 0x0;
const char WHITE = 0x1;
const char RED = 0x2;
const char CYAN = 0x3;
const char PURPLE = 0x4;
const char GREEN = 0x5;
const char BLUE = 0x6;
const char YELLOW = 0x7;
const char ORANGE = 0x8;
const char BROWN = 0x9;
const char PINK = 0xa;
const char DARK_GREY= 0xb;
const char GREY = 0xc;
const char LIGHT_GREEN = 0xd;
const char LIGHT_BLUE = 0xe;
const char LIGHT_GREY = 0xf;
// To access the VRAM (which is 128kB in size) an indirection mechanism is used.
// First the address to be accessed needs to be set (ADDRx_L/ADDRx_M/ADDRx_H) and
// then the data on that VRAM address can be read from or written to via the DATA0/1 register.
@ -242,3 +260,91 @@ struct VERA_SPRITE {
// 8BPP sprite mode (add to VERA_SPRITE.ADDR to enable)
const unsigned int VERA_SPRITE_8BPP = 0x8000;
// --- VERA encapsulation ---
// 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_set_layer_config(char layer, char config);
// 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'.
char vera_get_layer_config(char layer);
// Enable the layer to be displayed on the screen.
// - layer: 0 or 1.
void vera_show_layer(char layer);
// Disable the layer to be displayed on the screen.
// - layer: 0 or 1.
void vera_hide_layer(char layer);
// Is the layer shown on the screen?
// - returns: 1 if layer is displayed on the screen, 0 if not.
char vera_is_layer_shown(char layer);
// Set the base of the map for the layer with which the conio will interact.
// - layer: Value of 0 or 1.
// - mapbase: Specifies the base address of the tile map.
// 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.
void vera_set_layer_mapbase(unsigned byte layer, unsigned byte mapbase);
// Get the base of the map for the layer with which the conio will interact.
// - layer: Value of 0 or 1.
// - return: Returns the base address of the tile map.
// Note that the register is a byte, specifying only bits 16:9 of the address,
// so the resulting address in the VERA VRAM is always aligned to a multiple of 512 bytes!
unsigned byte vera_get_layer_mapbase(unsigned byte layer);
// Set the base of the tiles for the layer with which the conio will interact.
// - layer: Value of 0 or 1.
// - tilebase: Specifies the base address of the tile map.
// Note that the register 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!
void vera_set_layer_tilebase(unsigned byte layer, unsigned byte tilebase);
// Get the base of the tiles for the layer with which the conio will interact.
// - layer: Value of 0 or 1.
// - return: Specifies the base address of the tile map.
// Note that the register 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!
unsigned byte vera_get_layer_tilebase(unsigned 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!
// Note that on the VERA, the transparent color has value 0.
unsigned byte vera_set_layer_textcolor(unsigned byte layer, unsigned byte color);
// Get the front color for text output. The old front text color setting is returned.
// - layer: Value of 0 or 1.
// - return: a 4 bit value ( decimal between 0 and 15).
// This will only work when the VERA is in 16 color mode!
// Note that on the VERA, the transparent color has value 0.
unsigned byte vera_get_layer_textcolor(unsigned byte layer);
// Set the back color for text output. The old back 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!
// Note that on the VERA, the transparent color has value 0.
unsigned byte vera_set_layer_backcolor(unsigned byte layer, unsigned byte color);
// Get the back color for text output. The old back text color setting is returned.
// - layer: Value of 0 or 1.
// - return: a 4 bit value ( decimal between 0 and 15).
// This will only work when the VERA is in 16 color mode!
// Note that on the VERA, the transparent color has value 0.
unsigned byte vera_get_layer_backcolor(unsigned byte layer);
// Get the text and back color for text output in 16 color mode.
// - layer: Value of 0 or 1.
// - return: an 8 bit value with bit 7:4 containing the back color and bit 3:0 containing the front color.
// This will only work when the VERA is in 16 color mode!
// Note that on the VERA, the transparent color has value 0.
unsigned byte vera_get_layer_color(unsigned byte layer);

View File

@ -74,23 +74,3 @@ void memcpy_to_vram(char vbank, void* vdest, void* src, unsigned int num );
// - iput: the increment indicator, VERA needs this because addressing increment is automated by VERA at each access.
void vram_to_vram(unsigned int num, char bget, void *vget, char iget, char bput, void *vput, char iput );
// Color Ram
char * const COLORRAM = 0xd800;
// The colors of the C64
const char BLACK = 0x0;
const char WHITE = 0x1;
const char RED = 0x2;
const char CYAN = 0x3;
const char PURPLE = 0x4;
const char GREEN = 0x5;
const char BLUE = 0x6;
const char YELLOW = 0x7;
const char ORANGE = 0x8;
const char BROWN = 0x9;
const char PINK = 0xa;
const char DARK_GREY= 0xb;
const char GREY = 0xc;
const char LIGHT_GREEN = 0xd;
const char LIGHT_BLUE = 0xe;
const char LIGHT_GREY = 0xf;

View File

@ -20,8 +20,6 @@
// mapbase address of the time map in VRAM of the selected layer VERA_L0_MAPBASE or VERA_L1_MAPBASE.
char* CONIO_SCREEN_TEXT = DEFAULT_SCREEN;
byte CONIO_SCREEN_BANK = 0; // Default screen of the CX16 emulator uses memory bank 0 for text.
// The color screen address
char* const CONIO_SCREEN_COLORS = COLORRAM;
// The default text color
const char CONIO_TEXTCOLOR_DEFAULT = WHITE;
// The default back color
@ -37,8 +35,10 @@ void conio_x16_init() {
char line = *BASIC_CURSOR_LINE;
screensize(&conio_screen_width, &conio_screen_height);
screenlayer(1);
setscreenlayermapbase(0,0x00);
setscreenlayermapbase(1,0x00);
vera_set_layer_textcolor(1, WHITE);
vera_set_layer_backcolor(1, BLUE);
vera_set_layer_mapbase(0,0x20);
vera_set_layer_mapbase(1,0x00);
if(line>=CONIO_HEIGHT) line=CONIO_HEIGHT-1;
gotoxy(0, line);
}
@ -87,15 +87,6 @@ unsigned char kbhit(void) {
return ch;
}
// Set the color for the background. The old color setting is returned.
unsigned char bgcolor(unsigned char color) {
// The background color register address
char * const CONIO_BGCOLOR = 0xd021;
char old = *CONIO_BGCOLOR;
*CONIO_BGCOLOR = color;
return old;
}
// Set the color for the border. The old color setting is returned.
unsigned char bordercolor(unsigned char color) {
// The border color register address
@ -123,11 +114,6 @@ __ma unsigned byte conio_cursor_x = 0;
__ma unsigned byte conio_cursor_y = 0;
// The current text cursor line start
__ma unsigned byte *conio_line_text = CONIO_SCREEN_TEXT;
// The current color cursor line start
__ma unsigned byte *conio_line_color = CONIO_SCREEN_COLORS;
// The current text color
__ma unsigned byte conio_textcolor = CONIO_TEXTCOLOR_DEFAULT;
__ma unsigned byte conio_backcolor = CONIO_BACKCOLOR_DEFAULT; // only for text 16 color mode;
// Is a cursor whown when waiting for input (0: no, other: yes)
__ma unsigned byte conio_display_cursor = 0;
// Is scrolling enabled when outputting beyond the end of the screen (1: yes, 0: no).
@ -139,15 +125,13 @@ __ma unsigned byte conio_screen_width = 0;
__ma unsigned byte conio_screen_height = 0;
// Variable holding the screen layer on the VERA card with which conio interacts;
__ma unsigned byte conio_screen_layer = 1;
//
__ma unsigned byte* conio_screen_layer_mapbase[2] = {VERA_L0_MAPBASE, VERA_L1_MAPBASE};
// clears the screen and moves the cursor to the upper left-hand corner of the screen.
void clrscr(void) {
char* line_text = CONIO_SCREEN_TEXT;
unsigned int conio_width = VERA_L1_CONFIG_WIDTH[ ( (*VERA_L1_CONFIG) & VERA_L1_CONFIG_WIDTH_MASK ) >> 4 ];
unsigned int conio_height = VERA_L1_CONFIG_HEIGHT[ ( (*VERA_L1_CONFIG) & VERA_L1_CONFIG_HEIGHT_MASK ) >> 6 ];
char color = ( conio_backcolor << 4 ) | conio_textcolor;
char color = ( vera_get_layer_backcolor(conio_screen_layer) << 4 ) | vera_get_layer_textcolor(conio_screen_layer);
for( char l=0;l<conio_height; l++ ) {
char *ch = line_text;
// Select DATA0
@ -182,69 +166,6 @@ void gotoxy(unsigned byte x, unsigned byte y) {
conio_line_text = CONIO_SCREEN_TEXT + line_offset;
}
// Set the layer with which the conio will interact.
// - layer: value of 0 or 1.
void screenlayer(unsigned byte layer) {
if(layer > 1)
layer = 1;
conio_screen_layer = layer;
unsigned byte* addr = conio_screen_layer_mapbase[layer];
unsigned int addr_i = *addr << 1;
CONIO_SCREEN_BANK = >addr_i;
CONIO_SCREEN_TEXT = addr_i << 8;
}
// Set the base of the map layer with which the conio will interact.
// - layer: Value of 0 or 1.
// - mapbase: Specifies the base address of the tile map.
// 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.
void setscreenlayermapbase(unsigned byte layer, unsigned byte mapbase) {
if(layer > 1)
layer = 1;
unsigned byte* addr = conio_screen_layer_mapbase[layer];
*addr = mapbase;
}
// Get the base of the map layer with which the conio will interact.
// - layer: Value of 0 or 1.
// - return: Returns the base address of the tile map.
// Note that the register is a byte, specifying only bits 16:9 of the address,
// so the resulting address in the VERA VRAM is always aligned to a multiple of 512 bytes.
unsigned byte getscreenlayermapbase(unsigned byte layer) {
if(layer > 1)
layer = 1;
unsigned byte* mapbase = conio_screen_layer_mapbase[layer];
return *mapbase;
}
// Enable the layer to be displayed on the screen.
// - layer: 0 or 1.
void screenlayerenable(unsigned byte layer) {
unsigned char enable[2] = { VERA_LAYER0_ENABLE, VERA_LAYER1_ENABLE };
layer &= $1;
*VERA_DC_VIDEO |= enable[layer];
}
// Disable the layer to be displayed on the screen.
// - layer: 0 or 1.
void screenlayerdisable(unsigned byte layer) {
const unsigned byte disable[2] = { VERA_LAYER0_ENABLE, VERA_LAYER1_ENABLE };
layer &= $1;
*VERA_DC_VIDEO &= ~disable[layer];
}
// Is the layer displayed on the screen?
// - returns: 1 if layer is displayed on the screen, 0 if not.
unsigned byte screenlayerenabled(unsigned byte layer) {
const unsigned byte enabled[2] = { VERA_LAYER0_ENABLE, VERA_LAYER1_ENABLE };
layer &= $1;
return *VERA_DC_VIDEO & enabled[layer];
}
// Return the current screen size.
void screensize(unsigned byte* x, unsigned byte* y) {
// VERA returns in VERA_DC_HSCALE the value of 128 when 80 columns is used in text mode,
@ -282,8 +203,8 @@ inline unsigned byte wherey(void) {
// Output one character at the current cursor position
// Moves the cursor forward. Scrolls the entire screen if needed
void cputc(char c) {
char color = ( conio_backcolor << 4 ) | conio_textcolor;
unsigned byte* conio_addr = CONIO_SCREEN_TEXT;
char color = vera_get_layer_color( conio_screen_layer);
char* conio_addr = CONIO_SCREEN_TEXT;
conio_addr += conio_cursor_y*256;
conio_addr += conio_cursor_x << 1;
if(c=='\n') {
@ -308,8 +229,7 @@ void cputc(char c) {
// Print a newline
void cputln() {
//conio_line_text += CONIO_WIDTH;
conio_line_text += 256;
conio_line_color += CONIO_WIDTH;
conio_line_text += 256;
conio_cursor_x = 0;
conio_cursor_y++;
cscroll();
@ -324,7 +244,7 @@ void clearline() {
*VERA_ADDRX_L = <conio_addr;
*VERA_ADDRX_M = >conio_addr;
*VERA_ADDRX_H = VERA_INC_1;
char color = ( conio_backcolor << 4 ) | conio_textcolor;
char color = vera_get_layer_color( conio_screen_layer);
for( unsigned int c=0;c<CONIO_WIDTH; c++ ) {
// Set data
*VERA_DATA0 = ' ';
@ -392,20 +312,6 @@ void cputsxy(unsigned byte x, unsigned byte y, const char* s) {
cputs(s);
}
// Set the color for text output. The old color setting is returned.
unsigned byte textcolor(unsigned byte color) {
char old = conio_textcolor;
conio_textcolor = color;
return old;
}
// Set the color for back output. The old color setting is returned.
unsigned byte backcolor(unsigned byte color) {
char old = conio_backcolor;
conio_backcolor = color;
return old;
}
// If onoff is 1, a cursor is displayed when waiting for keyboard input.
// If onoff is 0, the cursor is hidden when waiting for keyboard input.
// The function returns the old cursor setting.
@ -423,3 +329,37 @@ unsigned byte scroll(unsigned byte onoff) {
conio_scroll_enable = onoff;
return old;
}
// --- Defined in cx16.c and cx16-vera.h ---
// --- layer management in VERA ---
// Set the layer with which the conio will interact.
// - layer: value of 0 or 1.
void screenlayer(unsigned byte layer) {
layer &= $1;
conio_screen_layer = layer;
unsigned byte addr = vera_get_layer_mapbase(layer);
unsigned int addr_i = addr << 1;
CONIO_SCREEN_BANK = >addr_i;
CONIO_SCREEN_TEXT = addr_i << 8;
}
// Set the front color for text output. The old front text color setting is returned.
// - color: a 4 bit value ( decimal between 0 and 15).
// This will only work when the VERA is in 16 color mode!
// Note that on the VERA, the transparent color has value 0.
inline char textcolor(char color) {
return vera_set_layer_textcolor(conio_screen_layer, color);
}
// Set the back color for text output. The old back text color setting is returned.
// - color: a 4 bit value ( decimal between 0 and 15).
// This will only work when the VERA is in 16 color mode!
// Note that on the VERA, the transparent color has value 0.
inline char bgcolor(char color) {
return vera_set_layer_backcolor(conio_screen_layer, color);
}

View File

@ -3,7 +3,7 @@
// https://github.com/commanderx16/x16-docs/blob/master/Commander%20X16%20Programmer's%20Reference%20Guide.md
#include <cx16.h>
#include <printf.h>
// Put a single byte into VRAM.
// Uses VERA DATA0
// - bank: Which 64K VRAM bank to put data into (0/1)
@ -81,3 +81,158 @@ void vram_to_vram(unsigned int num, char bget, void *vget, char iget, char bput,
*VERA_DATA1 = *VERA_DATA0;
}
}
// --- VERA encapsulation ---
// --- VERA layer management ---
__ma unsigned byte* vera_layer_config[2] = {VERA_L0_CONFIG, VERA_L1_CONFIG};
__ma unsigned byte vera_layer_enable[2] = { VERA_LAYER0_ENABLE, VERA_LAYER1_ENABLE };
__ma unsigned byte* vera_layer_mapbase[2] = {VERA_L0_MAPBASE, VERA_L1_MAPBASE};
__ma unsigned byte* vera_layer_tilebase[2] = {VERA_L0_TILEBASE, VERA_L1_TILEBASE};
__ma unsigned byte vera_layer_textcolor[2] = {WHITE, WHITE};
__ma unsigned byte vera_layer_backcolor[2] = {BLUE, BLUE};
// --- 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_set_layer_config(char layer, char config) {
layer &= $1;
char* addr = vera_layer_config[layer];
*addr = config;
}
// 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'.
char vera_get_layer_config(char layer) {
layer &= $1;
char* config = vera_layer_config[layer];
return *config;
}
// Enable the layer to be displayed on the screen.
// - layer: 0 or 1.
void vera_show_layer(char layer) {
layer &= $1;
*VERA_DC_VIDEO |= vera_layer_enable[layer];
}
// Disable the layer to be displayed on the screen.
// - layer: 0 or 1.
void vera_hide_layer(char layer) {
layer &= $1;
*VERA_DC_VIDEO &= ~vera_layer_enable[layer];
}
// Is the layer shown on the screen?
// - returns: 1 if layer is displayed on the screen, 0 if not.
char vera_is_layer_shown(char layer) {
layer &= $1;
return *VERA_DC_VIDEO & vera_layer_enable[layer];
}
// Set the base of the map layer with which the conio will interact.
// - layer: Value of 0 or 1.
// - mapbase: Specifies the base address of the tile map.
// 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.
void vera_set_layer_mapbase(unsigned byte layer, unsigned byte mapbase) {
layer &= $1;
unsigned byte* addr = vera_layer_mapbase[layer];
*addr = mapbase;
}
// Get the base of the map layer with which the conio will interact.
// - layer: Value of 0 or 1.
// - return: Returns the base address of the tile map.
// Note that the register is a byte, specifying only bits 16:9 of the address,
// so the resulting address in the VERA VRAM is always aligned to a multiple of 512 bytes.
unsigned byte vera_get_layer_mapbase(unsigned byte layer) {
layer &= $1;
unsigned byte* mapbase = vera_layer_mapbase[layer];
return *mapbase;
}
// Set the base of the tiles for the layer with which the conio will interact.
// - layer: Value of 0 or 1.
// - tilebase: Specifies the base address of the tile map.
// Note that the register 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!
void vera_set_layer_tilebase(unsigned byte layer, unsigned byte tilebase) {
layer &= $1;
unsigned byte* addr = vera_layer_tilebase[layer];
*addr = tilebase;
}
// Get the base of the tiles for the layer with which the conio will interact.
// - layer: Value of 0 or 1.
// - return: Specifies the base address of the tile map.
// Note that the register 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!
unsigned byte vera_get_layer_tilebase(unsigned byte layer) {
layer &= $1;
unsigned byte* tilebase = vera_layer_tilebase[layer];
return *tilebase;
}
// --- VERA color management ---
// 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!
// Note that on the VERA, the transparent color has value 0.
unsigned byte vera_set_layer_textcolor(unsigned byte layer, unsigned byte color) {
layer &= $1;
unsigned byte old = vera_layer_textcolor[layer];
vera_layer_textcolor[layer] = color;
return old;
}
// Get the front color for text output. The old front text color setting is returned.
// - layer: Value of 0 or 1.
// - return: a 4 bit value ( decimal between 0 and 15).
// This will only work when the VERA is in 16 color mode!
// Note that on the VERA, the transparent color has value 0.
unsigned byte vera_get_layer_textcolor(unsigned byte layer) {
layer &= $1;
return vera_layer_textcolor[layer];
}
// Set the back color for text output. The old back 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!
// Note that on the VERA, the transparent color has value 0.
unsigned byte vera_set_layer_backcolor(unsigned byte layer, unsigned byte color) {
layer &= $1;
unsigned byte old = vera_layer_backcolor[layer];
vera_layer_backcolor[layer] = color;
return old;
}
// Get the back color for text output. The old back text color setting is returned.
// - layer: Value of 0 or 1.
// - return: a 4 bit value ( decimal between 0 and 15).
// This will only work when the VERA is in 16 color mode!
// Note that on the VERA, the transparent color has value 0.
unsigned byte vera_get_layer_backcolor(unsigned byte layer) {
layer &= $1;
return vera_layer_backcolor[layer];
}
// Get the text and back color for text output in 16 color mode.
// - layer: Value of 0 or 1.
// - return: an 8 bit value with bit 7:4 containing the back color and bit 3:0 containing the front color.
// This will only work when the VERA is in 16 color mode!
// Note that on the VERA, the transparent color has value 0.
unsigned byte vera_get_layer_color(unsigned byte layer) {
layer &= $1;
return ((vera_layer_backcolor[layer] << 4) | vera_layer_textcolor[layer]);
}

View File

@ -3,9 +3,15 @@
void main() {
textcolor(WHITE);
backcolor(BLACK);
bgcolor(BLACK);
clrscr();
// Wait for a keypress and after clear the line!
textcolor(YELLOW);
printf("press a key");
while(!kbhit());
clearline();
screenlayer(1);
gotoxy(0,16);
@ -19,11 +25,15 @@ void main() {
// This is the content of the main controller registers of the VERA of layer 1.
// Layer 1 is the default layer that is activated in the CX16 at startup.
// It displays the characters in 1BPP 16x16 color mode!
printf("\nvera dc video = %x\n", *VERA_DC_VIDEO);
printf("\nvera layer 1 config = %x\n", *VERA_L1_CONFIG);
printf("vera layer 1 enabled = %x\n", screenlayerenabled(1));
printf("vera layer 1 mapbase = %x, tilebase = %x\n", getscreenlayermapbase(1), *VERA_L1_TILEBASE);
printf("vera layer 1 vscroll high = %x, low = %x\n", *VERA_L1_HSCROLL_H, *VERA_L1_HSCROLL_L);
unsigned byte dcvideo = *VERA_DC_VIDEO;
printf("\nvera dc video = %x\n", dcvideo);
unsigned byte config = vera_get_layer_config(1);
printf("\nvera layer 1 config = %x\n", config);
unsigned byte layershown = vera_is_layer_shown(1);
printf("vera layer 1 shown = %c\n", layershown);
unsigned byte mapbase = vera_get_layer_mapbase(1);
unsigned byte tilebase = vera_get_layer_tilebase(1);
printf("vera layer 1 mapbase = %hhx, tilebase = %hhx\n", mapbase, tilebase);
// Wait for a keypress and after clear the line!
textcolor(YELLOW);
@ -40,21 +50,25 @@ void main() {
// But first, we also print the layer 0 VERA configuration.
// This statement sets the base of the display layer 1 at VRAM address 0x0200
setscreenlayermapbase(0,0x20); // Set the map base to address 0x04000
*VERA_L0_CONFIG = *VERA_L1_CONFIG;
*VERA_L0_TILEBASE = *VERA_L1_TILEBASE;
vera_set_layer_mapbase(0,0x80); // Set the map base to address 0x10000 in VERA VRAM!
vera_set_layer_config(0, vera_get_layer_config(1));
vera_set_layer_tilebase(0, vera_get_layer_tilebase(1));
printf("\nvera layer 0 config = %x\n", *VERA_L0_CONFIG);
printf("vera layer 0 enabled = %x\n", screenlayerenabled(0));
printf("vera layer 0 mapbase = %x, tilebase = %x\n", getscreenlayermapbase(0), *VERA_L0_TILEBASE);
printf("vera layer 0 vscroll high = %x, low = %x\n", *VERA_L0_HSCROLL_H, *VERA_L0_HSCROLL_L);
textcolor(WHITE);
config = vera_get_layer_config(0);
printf("\nvera layer 0 config = %x\n", vera_get_layer_config(0));
layershown = vera_is_layer_shown(0);
printf("vera layer 0 shown = %x\n", layershown);
mapbase = vera_get_layer_mapbase(0);
tilebase = vera_get_layer_tilebase(0);
printf("vera layer 0 mapbase = %x, tilebase = %x\n", mapbase, tilebase);
// Now we print the layer 0 text on the layer 0!
screenlayer(0); // We set conio to output to layer 0 instead of layer 1!
clrscr(); // We clear the screen of layer 0!
textcolor(BLUE);
backcolor(WHITE);
bgcolor(BLACK);
clrscr(); // We clear the screen of layer 0!
bgcolor(WHITE);
gotoxy(19,4);
printf(" ");
gotoxy(19,5);
@ -68,26 +82,39 @@ void main() {
// Wait for a keypress and after clear the line!
textcolor(YELLOW);
backcolor(BLACK);
bgcolor(BLACK);
printf("press a key to show layer 0 and show the text!");
while(!kbhit());
clearline();
// Now we activate layer 0.
screenlayerenable(0);
vera_show_layer(0);
textcolor(WHITE);
bgcolor(BLACK);
printf("vera layer 0 shown = %x. ", vera_is_layer_shown(0));
// Wait for a keypress and after clear the line!
textcolor(YELLOW);
backcolor(BLACK);
bgcolor(BLACK);
printf("press a key to hide layer 0 and hide the text again");
while(!kbhit());
clearline();
screenlayerdisable(0);
vera_hide_layer(0);
textcolor(WHITE);
bgcolor(BLACK);
printf("vera layer 0 shown = %x. ", vera_is_layer_shown(0));
// Wait for a keypress and after clear the line!
textcolor(YELLOW);
bgcolor(BLACK);
printf("press a key to finish");
while(!kbhit());
clearline();
clrscr();
textcolor(RED);
backcolor(WHITE);
bgcolor(WHITE);
gotoxy(19,10);
printf(" ");
gotoxy(19,11);