1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2024-11-29 18:49:42 +00:00

Implementation of the layers in VERA is working now in text mode!

Added a number of new methods in conio to accommodate this.

screenlayer()
setscreenlayermapbase()
getscreenlayermapbase()
screenlayerenable()
screenlayerdisable()
screenlayerenabled()
This commit is contained in:
FlightControl 2021-01-09 07:43:12 +01:00
parent 218eb1a9db
commit 9fd668bba5
4 changed files with 851 additions and 24 deletions

View File

@ -1497,3 +1497,697 @@ cpy #0
bne {la1}
//FRAGMENT vbuyy=_dec_vbuyy
dey
//FRAGMENT pbuz1=qbuc1_derefidx_vbuz2
ldy {z2}
lda {c1},y
sta {z1}
lda {c1}+1,y
sta {z1}+1
//FRAGMENT vbuz1=pbuc1_derefidx_vbuz2
ldy {z2}
lda {c1},y
sta {z1}
//FRAGMENT vbuz1_ge_vbuz2_then_la1
lda {z1}
cmp {z2}
bcs {la1}
//FRAGMENT vbuz1=vbuz1_minus_vbuz2
lda {z1}
sec
sbc {z2}
sta {z1}
//FRAGMENT pbuz1=qbuc1_derefidx_vbuaa
tay
lda {c1},y
sta {z1}
lda {c1}+1,y
sta {z1}+1
//FRAGMENT pbuz1=qbuc1_derefidx_vbuxx
lda {c1},x
sta {z1}
lda {c1}+1,x
sta {z1}+1
//FRAGMENT pbuz1=qbuc1_derefidx_vbuyy
lda {c1},y
sta {z1}
lda {c1}+1,y
sta {z1}+1
//FRAGMENT vbuaa=pbuc1_derefidx_vbuz1
ldy {z1}
lda {c1},y
//FRAGMENT vbuxx=pbuc1_derefidx_vbuz1
ldy {z1}
ldx {c1},y
//FRAGMENT vbuyy=pbuc1_derefidx_vbuz1
ldx {z1}
ldy {c1},x
//FRAGMENT vbuz1=pbuc1_derefidx_vbuaa
tay
lda {c1},y
sta {z1}
//FRAGMENT vbuaa=pbuc1_derefidx_vbuaa
tay
lda {c1},y
//FRAGMENT vbuxx=pbuc1_derefidx_vbuaa
tay
ldx {c1},y
//FRAGMENT vbuyy=pbuc1_derefidx_vbuaa
tax
ldy {c1},x
//FRAGMENT vbuz1=pbuc1_derefidx_vbuxx
lda {c1},x
sta {z1}
//FRAGMENT vbuaa_ge_vbuz1_then_la1
cmp {z1}
bcs {la1}
//FRAGMENT vbuxx=vbuxx_minus_vbuz1
txa
sec
sbc {z1}
tax
//FRAGMENT vbuz1=vbuz1_minus_vbuaa
eor #$ff
sec
adc {z1}
sta {z1}
//FRAGMENT vbuxx=vbuxx_minus_vbuaa
sta $ff
txa
sec
sbc $ff
tax
//FRAGMENT vbuz1=vbuz1_minus_vbuxx
txa
eor #$ff
sec
adc {z1}
sta {z1}
//FRAGMENT vbuxx=vbuxx_minus_vbuxx
lda #0
tax
//FRAGMENT vbuz1=vbuz1_minus_vbuyy
tya
eor #$ff
sec
adc {z1}
sta {z1}
//FRAGMENT vbuxx=vbuxx_minus_vbuyy
txa
sty $ff
sec
sbc $ff
tax
//FRAGMENT vbuxx_ge_vbuz1_then_la1
cpx {z1}
bcs {la1}
//FRAGMENT vbuz1_ge_vbuxx_then_la1
lda {z1}
stx $ff
cmp $ff
bcs {la1}
//FRAGMENT vbuz1_ge_vbuyy_then_la1
lda {z1}
sty $ff
cmp $ff
bcs {la1}
//FRAGMENT vbuxx_ge_vbuyy_then_la1
sty $ff
cpx $ff
bcs {la1}
//FRAGMENT vbuaa=vbuxx
txa
//FRAGMENT vbuyy=vbuxx
txa
tay
//FRAGMENT vbuyy_ge_vbuz1_then_la1
cpy {z1}
bcs {la1}
//FRAGMENT 0_eq_vbuyy_then_la1
cpy #0
beq {la1}
//FRAGMENT vbuyy_lt_vbuc1_then_la1
cpy #{c1}
bcc {la1}
//FRAGMENT vbuxx=vbuaa
tax
//FRAGMENT pbuz1=_deref_qbuc1
lda {c1}
sta {z1}
lda {c1}+1
sta {z1}+1
//FRAGMENT pbuz1=_ptr_vbuz2
lda {z2}
sta {z1}
lda #0
sta {z1}+1
//FRAGMENT vwuz1=vbuz2_plus_vwuc1
lda {z2}
clc
adc #<{c1}
sta {z1}
lda #>{c1}
adc #0
sta {z1}+1
//FRAGMENT pbuz1=pbuz2_plus_vwuz3
lda {z2}
clc
adc {z3}
sta {z1}
lda {z2}+1
adc {z3}+1
sta {z1}+1
//FRAGMENT pbuz1=_ptr_vbuaa
sta {z1}
lda #0
sta {z1}+1
//FRAGMENT pbuz1=_ptr_vbuxx
stx {z1}
ldx #0
stx {z1}+1
//FRAGMENT pbuz1=_ptr_vbuyy
sty {z1}
ldy #0
sty {z1}+1
//FRAGMENT pbuz1=pbuz2_plus_vwuz1
lda {z1}
clc
adc {z2}
sta {z1}
lda {z1}+1
adc {z2}+1
sta {z1}+1
//FRAGMENT pbuz1=pbuz1_plus_vbuaa
clc
adc {z1}
sta {z1}
bcc !+
inc {z1}+1
!:
//FRAGMENT vwuz1=vbuaa
sta {z1}
lda #0
sta {z1}+1
//FRAGMENT vwuz1=vwuz2_rol_1
lda {z2}
asl
sta {z1}
lda {z2}+1
rol
sta {z1}+1
//FRAGMENT vwuz1=vwuz1_rol_1
asl {z1}
rol {z1}+1
//FRAGMENT _deref_pbuz1=vbuz2
lda {z2}
ldy #0
sta ({z1}),y
//FRAGMENT _deref_pbuz1=vbuxx
txa
ldy #0
sta ({z1}),y
//FRAGMENT _deref_pbuz1=vbuyy
tya
ldy #0
sta ({z1}),y
//FRAGMENT vbuaa=vbuyy
tya
//FRAGMENT vbuz1=vbuz2_rol_7
lda {z2}
asl
asl
asl
asl
asl
asl
asl
sta {z1}
//FRAGMENT vbuaa=vbuz1_rol_7
lda {z1}
asl
asl
asl
asl
asl
asl
asl
//FRAGMENT vbuxx=vbuz1_rol_7
lda {z1}
asl
asl
asl
asl
asl
asl
asl
tax
//FRAGMENT vbuyy=vbuz1_rol_7
lda {z1}
asl
asl
asl
asl
asl
asl
asl
tay
//FRAGMENT vwuz1=_word__deref_pbuz2
ldy #0
lda ({z2}),y
sta {z1}
lda #0
sta {z1}+1
//FRAGMENT vwuz1=vwuz2_rol_5
lda {z2}
asl
sta {z1}
lda {z2}+1
rol
sta {z1}+1
asl {z1}
rol {z1}+1
asl {z1}
rol {z1}+1
asl {z1}
rol {z1}+1
asl {z1}
rol {z1}+1
//FRAGMENT vwuz1=vwuz2_rol_4
lda {z2}
asl
sta {z1}
lda {z2}+1
rol
sta {z1}+1
asl {z1}
rol {z1}+1
asl {z1}
rol {z1}+1
asl {z1}
rol {z1}+1
//FRAGMENT pwuz1=pwuc1
lda #<{c1}
sta {z1}
lda #>{c1}
sta {z1}+1
//FRAGMENT vwuz1=pwuz2_derefidx_vbuz3
ldy {z3}
lda ({z2}),y
sta {z1}
iny
lda ({z2}),y
sta {z1}+1
//FRAGMENT vbuaa_eq_vbuc1_then_la1
cmp #{c1}
beq {la1}
//FRAGMENT vwuz1=pwuz2_derefidx_vbuaa
tay
lda ({z2}),y
sta {z1}
iny
lda ({z2}),y
sta {z1}+1
//FRAGMENT vwuz1=pwuz2_derefidx_vbuxx
txa
tay
lda ({z2}),y
sta {z1}
iny
lda ({z2}),y
sta {z1}+1
//FRAGMENT vwuz1=pwuz2_derefidx_vbuyy
lda ({z2}),y
sta {z1}
iny
lda ({z2}),y
sta {z1}+1
//FRAGMENT vwuz1=_word__deref_pbuz1
ldy #0
lda ({z1}),y
sta {z1}
lda #0
sta {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_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=vwuz2_plus_vwuz3
lda {z2}
clc
adc {z3}
sta {z1}
lda {z2}+1
adc {z3}+1
sta {z1}+1
//FRAGMENT pbuz1=pbuz1_plus_vwuz2
lda {z1}
clc
adc {z2}
sta {z1}
lda {z1}+1
adc {z2}+1
sta {z1}+1
//FRAGMENT vwuz1=vwuz2_plus_vwuz1
lda {z1}
clc
adc {z2}
sta {z1}
lda {z1}+1
adc {z2}+1
sta {z1}+1
//FRAGMENT vbuz1=_hi_vwuz2
lda {z2}+1
sta {z1}
//FRAGMENT vwuz1=vwuz2_plus_vbuz3
lda {z3}
clc
adc {z2}
sta {z1}
lda #0
adc {z2}+1
sta {z1}+1
//FRAGMENT vbuz1=_lo_vwuz2
lda {z2}
sta {z1}
//FRAGMENT vbuz1=vbuz2_bor_vbuc1
lda #{c1}
ora {z2}
sta {z1}
//FRAGMENT vbuaa=_hi_vwuz1
lda {z1}+1
//FRAGMENT vbuxx=_hi_vwuz1
ldx {z1}+1
//FRAGMENT vwuz1=vwuz2_plus_vbuaa
clc
adc {z2}
sta {z1}
lda #0
adc {z2}+1
sta {z1}+1
//FRAGMENT vwuz1=vwuz2_plus_vbuxx
txa
clc
adc {z2}
sta {z1}
lda #0
adc {z2}+1
sta {z1}+1
//FRAGMENT vwuz1=vwuz2_plus_vbuyy
tya
clc
adc {z2}
sta {z1}
lda #0
adc {z2}+1
sta {z1}+1
//FRAGMENT vbuaa=_lo_vwuz1
lda {z1}
//FRAGMENT vbuxx=_lo_vwuz1
ldx {z1}
//FRAGMENT vbuaa=vbuz1_bor_vbuc1
lda #{c1}
ora {z1}
//FRAGMENT vbuxx=vbuz1_bor_vbuc1
lda #{c1}
ora {z1}
tax
//FRAGMENT vbuyy=vbuz1_bor_vbuc1
lda #{c1}
ora {z1}
tay
//FRAGMENT vbuz1=vbuxx_bor_vbuc1
txa
ora #{c1}
sta {z1}
//FRAGMENT vbuaa=vbuxx_bor_vbuc1
txa
ora #{c1}
//FRAGMENT vbuxx=vbuxx_bor_vbuc1
txa
ora #{c1}
tax
//FRAGMENT vbuyy=vbuxx_bor_vbuc1
txa
ora #{c1}
tay
//FRAGMENT vbuz1=vbuyy_bor_vbuc1
tya
ora #{c1}
sta {z1}
//FRAGMENT vbuaa=vbuyy_bor_vbuc1
tya
ora #{c1}
//FRAGMENT vbuxx=vbuyy_bor_vbuc1
tya
ora #{c1}
tax
//FRAGMENT vbuyy=vbuyy_bor_vbuc1
tya
ora #{c1}
tay
//FRAGMENT vbuyy=_lo_vwuz1
ldy {z1}
//FRAGMENT vbuyy=_hi_vwuz1
ldy {z1}+1
//FRAGMENT vwuz1=vwuz1_plus_vwuz2
lda {z1}
clc
adc {z2}
sta {z1}
lda {z1}+1
adc {z2}+1
sta {z1}+1
//FRAGMENT vwuz1=vwuz1_plus_vbuaa
clc
adc {z1}
sta {z1}
bcc !+
inc {z1}+1
!:
//FRAGMENT vwuz1=vbuz2_plus_vwuz3
lda {z2}
clc
adc {z3}
sta {z1}
lda #0
adc {z3}+1
sta {z1}+1
//FRAGMENT vwuz1=vbuaa_plus_vwuz2
clc
adc {z2}
sta {z1}
lda #0
adc {z2}+1
sta {z1}+1
//FRAGMENT vwuz1=vbuxx_plus_vwuz2
txa
clc
adc {z2}
sta {z1}
lda #0
adc {z2}+1
sta {z1}+1
//FRAGMENT vwuz1=vbuyy_plus_vwuz2
tya
clc
adc {z2}
sta {z1}
lda #0
adc {z2}+1
sta {z1}+1
//FRAGMENT vwuz1=vbuaa_plus_vwuz1
clc
adc {z1}
sta {z1}
bcc !+
inc {z1}+1
!:
//FRAGMENT vwuz1=_deref_pbuz2_rol_1
ldy #0
lda ({z2}),y
asl
sta {z1}
lda #0
rol
sta {z1}+1
//FRAGMENT vwuz1=_deref_pbuz1_rol_1
ldy #0
lda ({z1}),y
asl
sta {z1}
lda #0
rol
sta {z1}+1
//FRAGMENT vbuz1=vbuz2_band_vbuc1
lda #{c1}
and {z2}
sta {z1}
//FRAGMENT vbuz1=_deref_pbuc1_band_pbuc2_derefidx_vbuz2
lda {c1}
ldy {z2}
and {c2},y
sta {z1}
//FRAGMENT _deref_pbuc1=_deref_pbuc1_bor__deref_pbuc2
lda {c1}
ora {c2}
sta {c1}
//FRAGMENT vbuz1=_bnot__deref_pbuc1
lda {c1}
eor #$ff
sta {z1}
//FRAGMENT _deref_pbuc1=_deref_pbuc1_band_vbuz1
lda {c1}
and {z1}
sta {c1}
//FRAGMENT vbuaa=vbuz1_band_vbuc1
lda #{c1}
and {z1}
//FRAGMENT vbuxx=vbuz1_band_vbuc1
lda #{c1}
and {z1}
tax
//FRAGMENT vbuyy=vbuz1_band_vbuc1
lda #{c1}
and {z1}
tay
//FRAGMENT vbuz1=vbuaa_band_vbuc1
and #{c1}
sta {z1}
//FRAGMENT vbuaa=vbuaa_band_vbuc1
and #{c1}
//FRAGMENT vbuxx=vbuaa_band_vbuc1
and #{c1}
tax
//FRAGMENT vbuyy=vbuaa_band_vbuc1
and #{c1}
tay
//FRAGMENT vbuz1=vbuxx_band_vbuc1
txa
and #{c1}
sta {z1}
//FRAGMENT vbuaa=vbuxx_band_vbuc1
txa
and #{c1}
//FRAGMENT vbuxx=vbuxx_band_vbuc1
txa
and #{c1}
tax
//FRAGMENT vbuyy=vbuxx_band_vbuc1
txa
and #{c1}
tay
//FRAGMENT vbuz1=vbuyy_band_vbuc1
tya
and #{c1}
sta {z1}
//FRAGMENT vbuaa=vbuyy_band_vbuc1
tya
and #{c1}
//FRAGMENT vbuxx=vbuyy_band_vbuc1
tya
and #{c1}
tax
//FRAGMENT vbuyy=vbuyy_band_vbuc1
tya
and #{c1}
tay
//FRAGMENT vbuz1=_deref_pbuc1_band_pbuc2_derefidx_vbuaa
tay
lda {c1}
and {c2},y
sta {z1}
//FRAGMENT vbuz1=_deref_pbuc1_band_pbuc2_derefidx_vbuxx
lda {c1}
and {c2},x
sta {z1}
//FRAGMENT vbuz1=_deref_pbuc1_band_pbuc2_derefidx_vbuyy
lda {c1}
and {c2},y
sta {z1}
//FRAGMENT vbuaa=_deref_pbuc1_band_pbuc2_derefidx_vbuz1
lda {c1}
ldy {z1}
and {c2},y
//FRAGMENT vbuaa=_deref_pbuc1_band_pbuc2_derefidx_vbuaa
tay
lda {c1}
and {c2},y
//FRAGMENT vbuaa=_deref_pbuc1_band_pbuc2_derefidx_vbuxx
lda {c1}
and {c2},x
//FRAGMENT vbuaa=_deref_pbuc1_band_pbuc2_derefidx_vbuyy
lda {c1}
and {c2},y
//FRAGMENT vbuxx=_deref_pbuc1_band_pbuc2_derefidx_vbuz1
lda {c1}
ldx {z1}
and {c2},x
tax
//FRAGMENT vbuxx=_deref_pbuc1_band_pbuc2_derefidx_vbuaa
tax
lda {c1}
and {c2},x
tax
//FRAGMENT vbuxx=_deref_pbuc1_band_pbuc2_derefidx_vbuxx
lda {c1}
and {c2},x
tax
//FRAGMENT vbuxx=_deref_pbuc1_band_pbuc2_derefidx_vbuyy
lda {c1}
and {c2},y
tax
//FRAGMENT vbuyy=_deref_pbuc1_band_pbuc2_derefidx_vbuz1
lda {c1}
ldy {z1}
and {c2},y
tay
//FRAGMENT vbuyy=_deref_pbuc1_band_pbuc2_derefidx_vbuaa
tay
lda {c1}
and {c2},y
tay
//FRAGMENT vbuyy=_deref_pbuc1_band_pbuc2_derefidx_vbuxx
lda {c1}
and {c2},x
tay
//FRAGMENT vbuyy=_deref_pbuc1_band_pbuc2_derefidx_vbuyy
lda {c1}
and {c2},y
tay
//FRAGMENT vbuaa=_bnot__deref_pbuc1
lda {c1}
eor #$ff
//FRAGMENT vbuxx=_bnot__deref_pbuc1
lda {c1}
eor #$ff
tax
//FRAGMENT vbuyy=_bnot__deref_pbuc1
lda {c1}
eor #$ff
tay
//FRAGMENT _deref_pbuc1=_deref_pbuc1_band_vbuaa
and {c1}
sta {c1}
//FRAGMENT _deref_pbuc1=_deref_pbuc1_band_vbuxx
txa
and {c1}
sta {c1}
//FRAGMENT _deref_pbuc1=_deref_pbuc1_band_vbuyy
tya
and {c1}
sta {c1}

View File

@ -82,14 +82,14 @@ char * const VERA_IRQLINE_L = 0x9f28;
// Bit 2: Chroma Disable Setting 'Chroma Disable' disables output of chroma in NTSC composite mode and will give a better picture on a monochrome display. (Setting this bit will also disable the chroma output on the S-video output.)
// Bit 0-1: Output Mode 0: Video disabled, 1: VGA output, 2: NTSC composite, 3: RGB interlaced, composite sync (via VGA connector)
char * const VERA_DC_VIDEO = 0x9f29;
char VERA_SPRITES_ENABLE = 0x40;
char VERA_LAYER1_ENABLE = 0x20;
char VERA_LAYER0_ENABLE = 0x10;
char VERA_CROMA_DISABLE = 0x04;
char VERA_OUTPUT_DISABLE = 0x00;
char VERA_OUTPUT_VGA = 0x01;
char VERA_OUTPUT_NTSC = 0x02;
char VERA_OUTPUT_RGB = 0x03;
const char VERA_SPRITES_ENABLE = 0x40;
const char VERA_LAYER1_ENABLE = 0x20;
const char VERA_LAYER0_ENABLE = 0x10;
const char VERA_CROMA_DISABLE = 0x04;
const char VERA_OUTPUT_DISABLE = 0x00;
const char VERA_OUTPUT_VGA = 0x01;
const char VERA_OUTPUT_NTSC = 0x02;
const char VERA_OUTPUT_RGB = 0x03;
// $9F2A DC_HSCALE (DCSEL=0) Active Display H-Scale
char * const VERA_DC_HSCALE = 0x9f2a;
// $9F2B DC_VSCALE (DCSEL=0) Active Display V-Scale
@ -132,7 +132,7 @@ char const VERA_L0_CONFIG_HEIGHT_256 = 0xC0;
char const VERA_L0_CONFIG_HEIGHT_MASK = 0xC0;
unsigned int const VERA_L0_CONFIG_HEIGHT[4] = { 32, 64, 128, 256 };
// $9F2E L0_MAPBASE Layer 0 Map Base Address (16:9)
char * const VERA_L0_MAPBASE = 0x9f2e;
unsigned byte * const VERA_L0_MAPBASE = 0x9f2e;
// $9F2F L0_TILEBASE Layer 0 Tile Base
// Bit 2-7: Tile Base Address (16:11)
// Bit 1: Tile Height (0:8 pixels, 1:16 pixels)

View File

@ -6,8 +6,20 @@
#define CONIO_WIDTH conio_screen_width
// The screen height
#define CONIO_HEIGHT conio_screen_height
// The text screen address
char * const CONIO_SCREEN_TEXT = DEFAULT_SCREEN;
// The text screen base address, which is a 16:0 bit value in VERA VRAM.
// That is 128KB addressable space, thus 17 bits in total.
// CONIO_SCREEN_TEXT contains bits 15:0 of the address.
// CONIO_SCREEN_BANK contains bit 16, the the 64K memory bank in VERA VRAM (the upper 17th bit).
// !!! note that these values are not const for the cx16!
// This conio implements the two layers of VERA, which can be layer 0 or layer 1.
// Configuring conio to output to a different layer, will change these fields to the address base
// configured using VERA_L0_MAPBASE = 0x9f2e or VERA_L1_MAPBASE = 0x9f35.
// Using the function setscreenlayer(layer) will re-calculate using CONIO_SCREEN_TEXT and CONIO_SCREEN_BASE
// based on the values of VERA_L0_MAPBASE or VERA_L1_MAPBASE, mapping the base address of the selected layer.
// The function setscreenlayermapbase(layer,mapbase) allows to configure bit 16:9 of the
// 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
@ -24,6 +36,9 @@ void conio_x16_init() {
char * const BASIC_CURSOR_LINE = 0xD6;
char line = *BASIC_CURSOR_LINE;
screensize(&conio_screen_width, &conio_screen_height);
screenlayer(1);
setscreenlayermapbase(0,0x00);
setscreenlayermapbase(1,0x00);
if(line>=CONIO_HEIGHT) line=CONIO_HEIGHT-1;
gotoxy(0, line);
}
@ -88,11 +103,14 @@ __ma unsigned byte conio_scroll_enable = 1;
__ma unsigned byte conio_screen_width = 0;
// Variable holding the screen height;
__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;
char* line_cols = CONIO_SCREEN_COLORS;
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;
@ -103,7 +121,7 @@ void clrscr(void) {
// Set address
*VERA_ADDRX_L = <ch;
*VERA_ADDRX_M = >ch;
*VERA_ADDRX_H = VERA_INC_1;
*VERA_ADDRX_H = CONIO_SCREEN_BANK | VERA_INC_1;
for( char c=0;c<conio_width; c++ ) {
// Set data
*VERA_DATA0 = ' ';
@ -114,12 +132,10 @@ void clrscr(void) {
//line_cols[c] = conio_textcolor;
}
line_text += 256;
line_cols += 256;
}
conio_cursor_x = 0;
conio_cursor_y = 0;
conio_line_text = CONIO_SCREEN_TEXT;
conio_line_color = CONIO_SCREEN_COLORS;
}
// Set the cursor to the specified position
@ -130,15 +146,77 @@ void gotoxy(unsigned byte x, unsigned byte y) {
conio_cursor_y = y;
unsigned int line_offset = (unsigned int)y << 8;
conio_line_text = CONIO_SCREEN_TEXT + line_offset;
conio_line_color = CONIO_SCREEN_COLORS + 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,
// and the value of 64 when 40 columns is used in text mode.
// Basically, 40 columns mode in the VERA is a double scan mode.
// Same for the VERA_DC_VSCALE mode.
// Same for the VERA_DC_VSCALE mode, but then the subdivision is 60 or 30 rows.
// I still need to test the other modes, but this will suffice for now for the pure text modes.
char hscale = (*VERA_DC_HSCALE) >> 7;
*x = 40 << hscale;
@ -171,16 +249,18 @@ inline unsigned byte wherey(void) {
// 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;
conio_addr += conio_cursor_y*256;
conio_addr += conio_cursor_x << 1;
if(c=='\n') {
cputln();
} else {
// Select DATA0
*VERA_CTRL &= ~VERA_ADDRSEL;
// Set address
char lx = conio_cursor_x << 1;
*VERA_ADDRX_L = <(conio_line_text+lx);
*VERA_ADDRX_M = >(conio_line_text+lx);
*VERA_ADDRX_H = VERA_INC_1;
*VERA_ADDRX_L = <conio_addr;
*VERA_ADDRX_M = >conio_addr;
*VERA_ADDRX_H = CONIO_SCREEN_BANK | VERA_INC_1;
*VERA_DATA0 = c;
*VERA_DATA0 = color;

View File

@ -0,0 +1,53 @@
#include <printf.h>
void main() {
textcolor(BLUE);
backcolor(BLACK);
clrscr();
// This statement sets the base of the display layer 1 at VRAM address 0x0200
setscreenlayermapbase(0,0x20);
screenlayer(0);
clrscr();
screenlayer(1);
gotoxy(0,0);
gotoxy(0,16);
textcolor(RED);
unsigned int width = screensizex();
unsigned int height = screensizey();
printf("vera card width = %u; height = %u\n", width, height);
printf("dc video = %x\n", *VERA_DC_VIDEO);
printf("vera card layer 0 enabled = %x\n", screenlayerenabled(0));
printf("vera card mapbase layer 0 = %x\n", getscreenlayermapbase(0));
printf("l0 config = %x\n", *VERA_L0_CONFIG);
printf("l0 tilebase = %x\n", *VERA_L0_TILEBASE);
printf("l0 vscroll l = %x\n", *VERA_L0_HSCROLL_L);
printf("l0 vscroll h = %x\n", *VERA_L0_HSCROLL_H);
printf("vera card layer 1 enabled = %x\n", screenlayerenabled(1));
printf("vera card mapbase layer 1 = %x\n", getscreenlayermapbase(1));
printf("l1 config = %x\n", *VERA_L1_CONFIG);
printf("l1 tilebase = %x\n", *VERA_L1_TILEBASE);
printf("l1 vscroll l = %x\n", *VERA_L1_HSCROLL_L);
printf("l1 vscroll h = %x\n", *VERA_L1_HSCROLL_H);
textcolor(BLUE);
//disablescreenlayer1();
screenlayerenable(0);
printf("dc video = %x\n", *VERA_DC_VIDEO);
printf("vera card layer 0 enabled = %x\n", screenlayerenabled(0));
printf("vera card layer 1 enabled = %x\n", screenlayerenabled(1));
printf("vera card mapbase layer 0 = %x\n", getscreenlayermapbase(0));
printf("vera card mapbase layer 1 = %x\n", getscreenlayermapbase(1));
printf("vera card mapbase layer 1 = %x\n", getscreenlayermapbase(1));
screenlayer(0);
gotoxy(0,0);
textcolor(GREEN);
*VERA_L0_CONFIG = *VERA_L1_CONFIG;
*VERA_L0_TILEBASE = *VERA_L1_TILEBASE;
printf("this is printed on layer 0");
//screenlayerdisable(0);
}