1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2024-09-29 03:56:15 +00:00

Worked out a demo for panning the visible screen over the tile map.

Worked out functions to set the dimensions of the tile map width and height.

When in conio, scrolling is disabled (by calling scroll(0)), then printf will print beyond the visible screen borders and will print until the tile map border is reached.

I still need to add the scrolling functions, but that is not too much.

I have stolen your irq routine to pan the screen smoothly!

When all the characters are drawn, you can still type or move the cursor :-).
This commit is contained in:
FlightControl 2021-01-12 22:10:17 +01:00
parent 21df8c6557
commit 69d3f2f395
7 changed files with 859 additions and 91 deletions

View File

@ -4248,3 +4248,633 @@ sta {c1},x
//FRAGMENT pbuc1_derefidx_vbuyy=vbuc2
lda #{c2}
sta {c1},y
//FRAGMENT _deref_pbuz1=_deref_pbuz1_bor__deref_pbuc1
lda {c1}
ldy #0
ora ({z1}),y
ldy #0
sta ({z1}),y
//FRAGMENT vbuz1=_deref_pbuz2_band_vbuz3
lda {z3}
ldy #0
and ({z2}),y
sta {z1}
//FRAGMENT vbuaa=_deref_pbuz1_band_vbuz2
lda {z2}
ldy #0
and ({z1}),y
//FRAGMENT vbuxx=_deref_pbuz1_band_vbuz2
lda {z2}
ldy #0
and ({z1}),y
tax
//FRAGMENT vbuyy=_deref_pbuz1_band_vbuz2
lda {z2}
ldy #0
and ({z1}),y
tay
//FRAGMENT vbuz1=_deref_pbuz2_band_vbuaa
ldy #0
and ({z2}),y
sta {z1}
//FRAGMENT vbuaa=_deref_pbuz1_band_vbuaa
ldy #0
and ({z1}),y
//FRAGMENT vbuxx=_deref_pbuz1_band_vbuaa
ldy #0
and ({z1}),y
tax
//FRAGMENT vbuyy=_deref_pbuz1_band_vbuaa
ldy #0
and ({z1}),y
tay
//FRAGMENT vbuz1=_deref_pbuz2_band_vbuxx
txa
ldy #0
and ({z2}),y
sta {z1}
//FRAGMENT vbuaa=_deref_pbuz1_band_vbuxx
txa
ldy #0
and ({z1}),y
//FRAGMENT vbuxx=_deref_pbuz1_band_vbuxx
txa
ldy #0
and ({z1}),y
tax
//FRAGMENT vbuyy=_deref_pbuz1_band_vbuxx
txa
ldy #0
and ({z1}),y
tay
//FRAGMENT vbuz1=_deref_pbuz2_band_vbuyy
tya
ldy #0
and ({z2}),y
sta {z1}
//FRAGMENT vbuaa=_deref_pbuz1_band_vbuyy
tya
ldy #0
and ({z1}),y
//FRAGMENT vbuxx=_deref_pbuz1_band_vbuyy
tya
ldy #0
and ({z1}),y
tax
//FRAGMENT vbuyy=_deref_pbuz1_band_vbuyy
tya
ldy #0
and ({z1}),y
tay
//FRAGMENT vwuz1_neq_vwuz2_then_la1
lda {z1}+1
cmp {z2}+1
bne {la1}
lda {z1}
cmp {z2}
bne {la1}
//FRAGMENT vbuxx=vbuyy_bor_vbuaa
sty $ff
ora $ff
tax
//FRAGMENT vbuyy=vbuyy_bor_vbuaa
sty $ff
ora $ff
tay
//FRAGMENT vwuz1=vwuz2_ror_4
lda {z2}+1
lsr
sta {z1}+1
lda {z2}
ror
sta {z1}
lsr {z1}+1
ror {z1}
lsr {z1}+1
ror {z1}
lsr {z1}+1
ror {z1}
//FRAGMENT vwuz1=vwuc1_rol_vbuz2
ldy {z2}
lda #<{c1}
sta {z1}
lda #>{c1}+1
sta {z1}+1
cpy #0
beq !e+
!:
asl {z1}
rol {z1}+1
dey
bne !-
!e:
//FRAGMENT vwuz1=vbuz2_rol_vbuz3
lda {z2}
ldy {z3}
sta {z1}
lda #0
sta {z1}+1
cpy #0
beq !e+
!:
asl {z1}
rol {z1}+1
dey
bne !-
!e:
//FRAGMENT vbuz1=vbuz2_rol_vbuz3
lda {z2}
ldy {z3}
cpy #0
beq !e+
!:
asl
dey
bne !-
!e:
sta {z1}
//FRAGMENT vwuz1=vbuaa_rol_vbuz2
ldy {z2}
sta {z1}
lda #0
sta {z1}+1
cpy #0
beq !e+
!:
asl {z1}
rol {z1}+1
dey
bne !-
!e:
//FRAGMENT vwuz1=vbuxx_rol_vbuz2
ldy {z2}
txa
sta {z1}
lda #0
sta {z1}+1
cpy #0
beq !e+
!:
asl {z1}
rol {z1}+1
dey
bne !-
!e:
//FRAGMENT vwuz1=vbuyy_rol_vbuz2
tya
ldy {z2}
sta {z1}
lda #0
sta {z1}+1
cpy #0
beq !e+
!:
asl {z1}
rol {z1}+1
dey
bne !-
!e:
//FRAGMENT vbuaa=vbuz1_rol_vbuz2
lda {z1}
ldy {z2}
cpy #0
beq !e+
!:
asl
dey
bne !-
!e:
//FRAGMENT vbuxx=vbuz1_rol_vbuz2
lda {z1}
ldx {z2}
cpx #0
beq !e+
!:
asl
dex
bne !-
!e:
tax
//FRAGMENT vbuyy=vbuz1_rol_vbuz2
lda {z1}
ldy {z2}
cpy #0
beq !e+
!:
asl
dey
bne !-
!e:
tay
//FRAGMENT pbuz1=pbuz1_plus_vbuz2
lda {z2}
clc
adc {z1}
sta {z1}
bcc !+
inc {z1}+1
!:
//FRAGMENT pbuz1=pbuz1_plus_vbuxx
txa
clc
adc {z1}
sta {z1}
bcc !+
inc {z1}+1
!:
//FRAGMENT pbuz1=pbuz1_plus_vbuyy
tya
clc
adc {z1}
sta {z1}
bcc !+
inc {z1}+1
!:
//FRAGMENT vwuz1=vwuz2_rol_vbuz3
lda {z2}
sta {z1}
lda {z2}+1
sta {z1}+1
ldy {z3}
beq !e+
!:
asl {z1}
rol {z1}+1
dey
bne !-
!e:
//FRAGMENT vwuz1=vwuz1_rol_vbuz2
ldy {z2}
beq !e+
!:
asl {z1}
rol {z1}+1
dey
bne !-
!e:
//FRAGMENT vbuz1=vbuz2_bor__deref_pbuc1
lda {c1}
ora {z2}
sta {z1}
//FRAGMENT _deref_pbuz1=_deref_pbuz1_band_vbuz2
lda {z2}
ldy #0
and ({z1}),y
ldy #0
sta ({z1}),y
//FRAGMENT vbuaa=vbuz1_bor__deref_pbuc1
lda {c1}
ora {z1}
//FRAGMENT vbuxx=vbuz1_bor__deref_pbuc1
lda {c1}
ora {z1}
tax
//FRAGMENT vbuyy=vbuz1_bor__deref_pbuc1
lda {c1}
ora {z1}
tay
//FRAGMENT vbuz1=vbuaa_bor__deref_pbuc1
ora {c1}
sta {z1}
//FRAGMENT vbuaa=vbuaa_bor__deref_pbuc1
ora {c1}
//FRAGMENT vbuxx=vbuaa_bor__deref_pbuc1
ora {c1}
tax
//FRAGMENT vbuyy=vbuaa_bor__deref_pbuc1
ora {c1}
tay
//FRAGMENT vbuz1=vbuxx_bor__deref_pbuc1
txa
ora {c1}
sta {z1}
//FRAGMENT vbuaa=vbuxx_bor__deref_pbuc1
txa
ora {c1}
//FRAGMENT vbuxx=vbuxx_bor__deref_pbuc1
txa
ora {c1}
tax
//FRAGMENT vbuyy=vbuxx_bor__deref_pbuc1
txa
ora {c1}
tay
//FRAGMENT vbuz1=vbuyy_bor__deref_pbuc1
tya
ora {c1}
sta {z1}
//FRAGMENT vbuaa=vbuyy_bor__deref_pbuc1
tya
ora {c1}
//FRAGMENT vbuxx=vbuyy_bor__deref_pbuc1
tya
ora {c1}
tax
//FRAGMENT vbuyy=vbuyy_bor__deref_pbuc1
tya
ora {c1}
tay
//FRAGMENT _deref_pbuz1=_deref_pbuz1_band_vbuaa
ldy #0
and ({z1}),y
ldy #0
sta ({z1}),y
//FRAGMENT _deref_pbuz1=_deref_pbuz1_band_vbuxx
txa
ldy #0
and ({z1}),y
ldy #0
sta ({z1}),y
//FRAGMENT _deref_pbuz1=_deref_pbuz1_band_vbuyy
tya
ldy #0
and ({z1}),y
ldy #0
sta ({z1}),y
//FRAGMENT _deref_pbuz1=_deref_pbuz1_band_vbuc1
lda #{c1}
ldy #0
and ({z1}),y
ldy #0
sta ({z1}),y
//FRAGMENT vbuz1=_deref_pbuz2_band_vbuc1
lda #{c1}
ldy #0
and ({z2}),y
sta {z1}
//FRAGMENT vbuaa=_deref_pbuz1_band_vbuc1
lda #{c1}
ldy #0
and ({z1}),y
//FRAGMENT vbuxx=_deref_pbuz1_band_vbuc1
lda #{c1}
ldy #0
and ({z1}),y
tax
//FRAGMENT vbuyy=_deref_pbuz1_band_vbuc1
lda #{c1}
ldy #0
and ({z1}),y
tay
//FRAGMENT _deref_pbuz1=_deref_pbuz1_bor_vbuc1
lda #{c1}
ldy #0
ora ({z1}),y
ldy #0
sta ({z1}),y
//FRAGMENT vwuz1_eq_vwuc1_then_la1
lda {z1}
cmp #<{c1}
bne !+
lda {z1}+1
cmp #>{c1}
beq {la1}
!:
//FRAGMENT vwuz1_eq_vbuc1_then_la1
lda #{c1}
cmp {z1}
bne !+
lda {z1}+1
bne !+
jmp {la1}
!:
//FRAGMENT vwuz1_eq_0_then_la1
lda {z1}
ora {z1}+1
beq {la1}
//FRAGMENT vwuz1_neq_0_then_la1
lda {z1}
ora {z1}+1
bne {la1}
//FRAGMENT vwuz1=vwuz1_plus_vwsz2
lda {z1}
clc
adc {z2}
sta {z1}
lda {z1}+1
adc {z2}+1
sta {z1}+1
//FRAGMENT vwsz1=vwsz1_plus_vwsz2
lda {z1}
clc
adc {z2}
sta {z1}
lda {z1}+1
adc {z2}+1
sta {z1}+1
//FRAGMENT vwsz1_gt_0_then_la1
lda {z1}+1
bne !+
lda {z1}
beq !e+
lsr
!:
bpl {la1}
!e:
//FRAGMENT vbuz1=_lo_vwsz2
lda {z2}
sta {z1}
//FRAGMENT vbuz1=_hi_vwsz2
lda {z2}+1
sta {z1}
//FRAGMENT vbuaa=_lo_vwsz1
lda {z1}
//FRAGMENT vbuxx=_lo_vwsz1
ldx {z1}
//FRAGMENT vbuaa=_hi_vwsz1
lda {z1}+1
//FRAGMENT vbuxx=_hi_vwsz1
ldx {z1}+1
//FRAGMENT vbuyy=_lo_vwsz1
ldy {z1}
//FRAGMENT vbuyy=_hi_vwsz1
ldy {z1}+1
//FRAGMENT vwsz1_neq_vwsc1_then_la1
lda {z1}+1
cmp #>{c1}
bne {la1}
lda {z1}
cmp #<{c1}
bne {la1}
//FRAGMENT vwsz1_neq_vbsc1_then_la1
NO_SYNTHESIS
//FRAGMENT vwsz1_neq_vwuc1_then_la1
lda {z1}+1
cmp #>{c1}
bne {la1}
lda {z1}
cmp #<{c1}
bne {la1}
//FRAGMENT vwsz1_le_vwsc1_then_la1
lda #<{c1}
cmp {z1}
lda #>{c1}
sbc {z1}+1
bvc !+
eor #$80
!:
bpl {la1}
//FRAGMENT vwsz1_ge_0_then_la1
lda {z1}+1
bpl {la1}
//FRAGMENT vwsz1=_neg_vwsz2
sec
lda #0
sbc {z2}
sta {z1}
lda #0
sbc {z2}+1
sta {z1}+1
//FRAGMENT qbuc1_derefidx_vbuz1=pbuz2
ldy {z1}
lda {z2}
sta {c1},y
lda {z2}+1
sta {c1}+1,y
//FRAGMENT vbuz1=pbuc1_derefidx_vbuz2_rol_1
ldy {z2}
lda {c1},y
asl
sta {z1}
//FRAGMENT pbuc1_derefidx_vbuz1=_inc_pbuc1_derefidx_vbuz1
ldx {z1}
inc {c1},x
//FRAGMENT vwuz1=_word_pbuc1_derefidx_vbuz2
ldy {z2}
lda {c1},y
sta {z1}
lda #0
sta {z1}+1
//FRAGMENT pbuc1_derefidx_vbuz1_neq_vbuz2_then_la1
lda {z2}
ldy {z1}
cmp {c1},y
bne {la1}
//FRAGMENT pbuc1_derefidx_vbuz1_lt_vbuz2_then_la1
ldy {z1}
lda {c1},y
cmp {z2}
bcc {la1}
//FRAGMENT 0_neq_pbuc1_derefidx_vbuz1_then_la1
ldy {z1}
lda {c1},y
cmp #0
bne {la1}
//FRAGMENT pbuc1_derefidx_vbuz1_lt_vwuz2_then_la1
ldy {z1}
lda {c1},y
ldy {z2}+1
bne {la1}
cmp {z2}
bcc {la1}
//FRAGMENT qbuc1_derefidx_vbuaa=pbuz1
tay
lda {z1}
sta {c1},y
lda {z1}+1
sta {c1}+1,y
//FRAGMENT qbuc1_derefidx_vbuxx=pbuz1
lda {z1}
sta {c1},x
lda {z1}+1
sta {c1}+1,x
//FRAGMENT qbuc1_derefidx_vbuyy=pbuz1
lda {z1}
sta {c1},y
lda {z1}+1
sta {c1}+1,y
//FRAGMENT pbuc1_derefidx_vbuz1=vbuaa
ldy {z1}
sta {c1},y
//FRAGMENT vbuaa=pbuc1_derefidx_vbuz1_rol_1
ldy {z1}
lda {c1},y
asl
//FRAGMENT vbuxx=pbuc1_derefidx_vbuz1_rol_1
ldx {z1}
lda {c1},x
asl
tax
//FRAGMENT vbuyy=pbuc1_derefidx_vbuz1_rol_1
ldy {z1}
lda {c1},y
asl
tay
//FRAGMENT pwuc1_derefidx_vbuz1=vwuz2
ldy {z1}
lda {z2}
sta {c1},y
lda {z2}+1
sta {c1}+1,y
//FRAGMENT pwuc1_derefidx_vbuz1=vbuc2
lda #{c2}
ldy {z1}
sta {c1},y
lda #0
sta {c1}+1,y
//FRAGMENT pbuz1=pbuz2_plus_pwuc1_derefidx_vbuz3
ldy {z3}
clc
lda {z2}
adc {c1},y
sta {z1}
lda {z2}+1
adc {c1}+1,y
sta {z1}+1
//FRAGMENT pwuc1_derefidx_vbuaa=vwuz1
tay
lda {z1}
sta {c1},y
lda {z1}+1
sta {c1}+1,y
//FRAGMENT pwuc1_derefidx_vbuxx=vwuz1
lda {z1}
sta {c1},x
lda {z1}+1
sta {c1}+1,x
//FRAGMENT pwuc1_derefidx_vbuyy=vwuz1
lda {z1}
sta {c1},y
lda {z1}+1
sta {c1}+1,y
//FRAGMENT pwuc1_derefidx_vbuaa=vbuc2
tay
lda #{c2}
sta {c1},y
lda #0
sta {c1}+1,y
//FRAGMENT pwuc1_derefidx_vbuxx=vbuc2
lda #{c2}
sta {c1},x
lda #0
sta {c1}+1,x
//FRAGMENT pwuc1_derefidx_vbuyy=vbuc2
lda #{c2}
sta {c1},y
lda #0
sta {c1}+1,y
//FRAGMENT pbuz1=pbuz2_plus_pwuc1_derefidx_vbuaa
tay
clc
lda {z2}
adc {c1},y
sta {z1}
lda {z2}+1
adc {c1}+1,y
sta {z1}+1
//FRAGMENT pbuz1=pbuz2_plus_pwuc1_derefidx_vbuxx
clc
lda {z2}
adc {c1},x
sta {z1}
lda {z2}+1
adc {c1}+1,x
sta {z1}+1
//FRAGMENT pbuz1=pbuz2_plus_pwuc1_derefidx_vbuyy
clc
lda {z2}
adc {c1},y
sta {z1}
lda {z2}+1
adc {c1}+1,y
sta {z1}+1

View File

@ -122,6 +122,25 @@ char * const VERA_DC_HSTOP = 0x9f2a;
char * const VERA_DC_VSTART = 0x9f2b;
// $9F2C DC_VSTOP (DCSEL=1) Active Display V-Stop (8:1)
char * const VERA_DC_VSTOP = 0x9f2c;
// Configuration work tables
unsigned int const VERA_CONFIG_WIDTH[4] = { 32, 64, 128, 256 };
unsigned int const VERA_CONFIG_HEIGHT[4] = { 32, 64, 128, 256 };
// Bit 4-5. Map Width (0:32 tiles, 1:64 tiles, 2:128 tiles, 3:256 tiles)
char const VERA_LAYER_CONFIG_WIDTH_32 = 0x00;
char const VERA_LAYER_CONFIG_WIDTH_64 = 0x10;
char const VERA_LAYER_CONFIG_WIDTH_128 = 0x20;
char const VERA_LAYER_CONFIG_WIDTH_256 = 0x30;
char const VERA_LAYER_CONFIG_WIDTH_MASK = 0x30;
// Bit 6-7: Map Height (0:32 tiles, 1:64 tiles, 2:128 tiles, 3:256 tiles)
char const VERA_LAYER_CONFIG_HEIGHT_32 = 0x00;
char const VERA_LAYER_CONFIG_HEIGHT_64 = 0x40;
char const VERA_LAYER_CONFIG_HEIGHT_128 = 0x80;
char const VERA_LAYER_CONFIG_HEIGHT_256 = 0xC0;
char const VERA_LAYER_CONFIG_HEIGHT_MASK = 0xC0;
// $9F2D L0_CONFIG Layer 0 Configuration
char * const VERA_L0_CONFIG = 0x9f2d;
// Bit 0-1: Color Depth (0: 1 bpp, 1: 2 bpp, 2: 4 bpp, 3: 8 bpp)
@ -135,20 +154,6 @@ char const VERA_L0_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;
// Bit 4-5. Map Width (0:32 tiles, 1:64 tiles, 2:128 tiles, 3:256 tiles)
char const VERA_L0_CONFIG_WIDTH_32 = 0x00;
char const VERA_L0_CONFIG_WIDTH_64 = 0x10;
char const VERA_L0_CONFIG_WIDTH_128 = 0x20;
char const VERA_L0_CONFIG_WIDTH_256 = 0x30;
char const VERA_L0_CONFIG_WIDTH_MASK = 0x30;
unsigned int const VERA_L0_CONFIG_WIDTH[4] = { 32, 64, 128, 256 };
// Bit 6-7: Map Height (0:32 tiles, 1:64 tiles, 2:128 tiles, 3:256 tiles)
char const VERA_L0_CONFIG_HEIGHT_32 = 0x00;
char const VERA_L0_CONFIG_HEIGHT_64 = 0x40;
char const VERA_L0_CONFIG_HEIGHT_128 = 0x80;
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)
unsigned byte * const VERA_L0_MAPBASE = 0x9f2e;
// $9F2F L0_TILEBASE Layer 0 Tile Base
@ -177,20 +182,6 @@ 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;
// Bit 4-5. Map Width (0:32 tiles, 1:64 tiles, 2:128 tiles, 3:256 tiles)
char const VERA_L1_CONFIG_WIDTH_32 = 0x00;
char const VERA_L1_CONFIG_WIDTH_64 = 0x10;
char const VERA_L1_CONFIG_WIDTH_128 = 0x20;
char const VERA_L1_CONFIG_WIDTH_256 = 0x30;
char const VERA_L1_CONFIG_WIDTH_MASK = 0x30;
unsigned int const VERA_L1_CONFIG_WIDTH[4] = { 32, 64, 128, 256 };
// Bit 6-7: Map Height (0:32 tiles, 1:64 tiles, 2:128 tiles, 3:256 tiles)
char const VERA_L1_CONFIG_HEIGHT_32 = 0x00;
char const VERA_L1_CONFIG_HEIGHT_64 = 0x40;
char const VERA_L1_CONFIG_HEIGHT_128 = 0x80;
char const VERA_L1_CONFIG_HEIGHT_256 = 0xC0;
char const VERA_L1_CONFIG_HEIGHT_MASK = 0xC0;
unsigned int const VERA_L1_CONFIG_HEIGHT[4] = { 32, 64, 128, 256 };
// $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

@ -17,6 +17,20 @@ void vera_set_layer_config(unsigned byte layer, unsigned byte config);
// - config: Specifies the modes which are specified using T256C / 'Bitmap Mode' / 'Color Depth'.
unsigned byte vera_get_layer_config(unsigned byte layer);
// Set the map width or height of the layer.
// - layer: Value of 0 or 1.
inline void vera_set_layer_map_width_32(unsigned byte layer);
inline void vera_set_layer_map_width_64(unsigned byte layer);
inline void vera_set_layer_map_width_128(unsigned byte layer);
inline void vera_set_layer_map_width_256(unsigned byte layer);
inline void vera_set_layer_map_height_32(unsigned byte layer);
inline void vera_set_layer_map_height_64(unsigned byte layer);
inline void vera_set_layer_map_height_128(unsigned byte layer);
inline void vera_set_layer_map_height_256(unsigned byte layer);
// Enable the layer to be displayed on the screen.
// - layer: 0 or 1.
void vera_show_layer(unsigned byte layer);

View File

@ -109,16 +109,16 @@ unsigned char bordercolor(unsigned char color) {
#define CONIO_BYTES CONIO_HEIGHT*CONIO_WIDTH
// The current cursor x-position
__ma unsigned byte conio_cursor_x = 0;
__ma unsigned byte conio_cursor_x[2] = {0,0};
// The current cursor y-position
__ma unsigned byte conio_cursor_y = 0;
__ma unsigned byte conio_cursor_y[2] = {0,0};
// The current text cursor line start
__ma unsigned byte *conio_line_text = CONIO_SCREEN_TEXT;
__ma unsigned word conio_line_text[2] = {0x0000,0x0000};
// 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).
// If disabled the cursor just moves back to (0,0) instead
__ma unsigned byte conio_scroll_enable = 1;
__ma unsigned byte conio_scroll_enable[2] = {1,1};
// Variable holding the screen width;
__ma unsigned byte conio_screen_width = 0;
// Variable holding the screen height;
@ -126,11 +126,15 @@ __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;
// Variables holding the current map width and map height of the layer.
__ma word conio_width = 0;
__ma word conio_height = 0;
__ma byte conio_skip = 0;
// 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 ];
word skip = (word)((word)1<<conio_skip);
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;
@ -141,29 +145,24 @@ void clrscr(void) {
*VERA_ADDRX_M = >ch;
*VERA_ADDRX_H = CONIO_SCREEN_BANK | VERA_INC_1;
for( char c=0;c<conio_width; c++ ) {
// Set data
*VERA_DATA0 = ' ';
*VERA_DATA0 = color;
//vpoke(0,ch++,' ');
//vpoke(0,ch++,0x61);
//line_text[c] = ' ';
//line_cols[c] = conio_textcolor;
}
line_text += 256;
line_text += skip;
}
conio_cursor_x = 0;
conio_cursor_y = 0;
conio_line_text = CONIO_SCREEN_TEXT;
conio_cursor_x[conio_screen_layer] = 0;
conio_cursor_y[conio_screen_layer] = 0;
conio_line_text[conio_screen_layer] = 0;
}
// Set the cursor to the specified position
void gotoxy(unsigned byte x, unsigned byte y) {
if(y>CONIO_HEIGHT) y = 0;
if(x>=CONIO_WIDTH) x = 0;
conio_cursor_x = x;
conio_cursor_y = y;
unsigned int line_offset = (unsigned int)y << 8;
conio_line_text = CONIO_SCREEN_TEXT + line_offset;
conio_cursor_x[conio_screen_layer] = x;
conio_cursor_y[conio_screen_layer] = y;
unsigned int line_offset = (unsigned int)y << conio_skip;
conio_line_text[conio_screen_layer] = line_offset;
}
// Return the current screen size.
@ -192,21 +191,21 @@ inline unsigned byte screensizey() {
// Return the X position of the cursor
inline unsigned byte wherex(void) {
return conio_cursor_x;
return conio_cursor_x[conio_screen_layer];
}
// Return the Y position of the cursor
inline unsigned byte wherey(void) {
return conio_cursor_y;
return conio_cursor_y[conio_screen_layer];
}
// Output one character at the current cursor position
// Moves the cursor forward. Scrolls the entire screen if needed
void cputc(char c) {
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;
char* conio_addr = CONIO_SCREEN_TEXT + conio_line_text[conio_screen_layer];
conio_addr += conio_cursor_x[conio_screen_layer] << 1;
if(c=='\n') {
cputln();
} else {
@ -219,30 +218,36 @@ void cputc(char c) {
*VERA_DATA0 = c;
*VERA_DATA0 = color;
//conio_line_text[conio_cursor_x] = c;
//conio_line_color[conio_cursor_x] = conio_textcolor;
if(++conio_cursor_x==CONIO_WIDTH)
cputln();
conio_cursor_x[conio_screen_layer]++;
byte scroll_enable = conio_scroll_enable[conio_screen_layer];
if(scroll_enable) {
if(conio_cursor_x[conio_screen_layer] == CONIO_WIDTH)
cputln();
} else {
if((unsigned int)conio_cursor_x[conio_screen_layer] == conio_width)
cputln();
}
}
}
// Print a newline
void cputln() {
//conio_line_text += CONIO_WIDTH;
conio_line_text += 256;
conio_cursor_x = 0;
conio_cursor_y++;
// TODO: This needs to be optimized! other variations don't compile because of sections not available!
word temp = conio_line_text[conio_screen_layer];
temp += (word)((word)1<<conio_skip);
conio_line_text[conio_screen_layer] = temp;
conio_cursor_x[conio_screen_layer] = 0;
conio_cursor_y[conio_screen_layer]++;
cscroll();
}
void clearline() {
// Select DATA0
unsigned byte* conio_addr = CONIO_SCREEN_TEXT;
conio_addr += conio_cursor_y*256;
*VERA_CTRL &= ~VERA_ADDRSEL;
// Set address
*VERA_ADDRX_L = <conio_addr;
*VERA_ADDRX_M = >conio_addr;
byte* addr = CONIO_SCREEN_TEXT + conio_line_text[conio_screen_layer];
*VERA_ADDRX_L = <addr;
*VERA_ADDRX_M = >addr;
*VERA_ADDRX_H = VERA_INC_1;
char color = vera_get_layer_color( conio_screen_layer);
for( unsigned int c=0;c<CONIO_WIDTH; c++ ) {
@ -250,42 +255,44 @@ void clearline() {
*VERA_DATA0 = ' ';
*VERA_DATA0 = color;
}
conio_cursor_x = 0;
conio_cursor_x[conio_screen_layer] = 0;
}
// Insert a new line, and scroll the lower part of the screen down.
void insertdown() {
unsigned byte cy = CONIO_HEIGHT - conio_cursor_y;
unsigned byte cy = CONIO_HEIGHT - conio_cursor_y[conio_screen_layer];
cy -= 1;
unsigned byte width = CONIO_WIDTH * 2;
for(unsigned byte i=cy; i>0; i--) {
unsigned int line = (conio_cursor_y + i - 1) << 8;
unsigned int line = (conio_cursor_y[conio_screen_layer] + i - 1) << conio_skip;
unsigned char* start = CONIO_SCREEN_TEXT + line;
vram_to_vram(width, 0, start, VERA_INC_1, 0, start+256, VERA_INC_1);
vram_to_vram(width, 0, start, VERA_INC_1, 0, start+((word)1<<conio_skip), VERA_INC_1);
}
clearline();
}
// Insert a new line, and scroll the upper part of the screen up.
void insertup() {
unsigned byte cy = conio_cursor_y;
unsigned byte cy = conio_cursor_y[conio_screen_layer];
unsigned byte width = CONIO_WIDTH * 2;
for(unsigned byte i=1; i<=cy; i++) {
unsigned int line = (i-1) << 8;
unsigned int line = (i-1) << conio_skip;
unsigned char* start = CONIO_SCREEN_TEXT + line;
vram_to_vram(width, 0, start+256, VERA_INC_1, 0, start, VERA_INC_1);
vram_to_vram(width, 0, start+((word)1<<conio_skip), VERA_INC_1, 0, start, VERA_INC_1);
}
clearline();
}
// Scroll the entire screen if the cursor is beyond the last line
void cscroll() {
if(conio_cursor_y>=CONIO_HEIGHT) {
if(conio_scroll_enable) {
if(conio_cursor_y[conio_screen_layer]>=CONIO_HEIGHT) {
if(conio_scroll_enable[conio_screen_layer]) {
insertup();
gotoxy( 0, CONIO_HEIGHT-1);
} else {
gotoxy(0,0);
if(conio_cursor_y[conio_screen_layer]>=conio_height) {
//gotoxy(0,0);
}
}
}
}
@ -325,8 +332,8 @@ unsigned byte cursor(unsigned byte onoff) {
// If onoff is 0, scrolling is disabled and the cursor instead moves to (0,0)
// The function returns the old scroll setting.
unsigned byte scroll(unsigned byte onoff) {
char old = conio_scroll_enable;
conio_scroll_enable = onoff;
char old = conio_scroll_enable[conio_screen_layer];
conio_scroll_enable[conio_screen_layer] = onoff;
return old;
}
@ -343,6 +350,9 @@ void screenlayer(unsigned byte layer) {
unsigned int addr_i = addr << 1;
CONIO_SCREEN_BANK = >addr_i;
CONIO_SCREEN_TEXT = addr_i << 8;
conio_width = vera_get_layer_map_width(conio_screen_layer);
conio_skip = (byte)(conio_width >> 4);
conio_height = vera_get_layer_map_height(conio_screen_layer);
}

View File

@ -9,14 +9,16 @@
// --- VERA function 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 byte* vera_layer_config[2] = {VERA_L0_CONFIG, VERA_L1_CONFIG};
__ma byte vera_layer_enable[2] = { VERA_LAYER0_ENABLE, VERA_LAYER1_ENABLE };
__ma byte* vera_layer_mapbase[2] = {VERA_L0_MAPBASE, VERA_L1_MAPBASE};
__ma byte* vera_layer_tilebase[2] = {VERA_L0_TILEBASE, VERA_L1_TILEBASE};
__ma byte vera_layer_textcolor[2] = {WHITE, WHITE};
__ma byte vera_layer_backcolor[2] = {BLUE, BLUE};
__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 addressing ---
@ -62,18 +64,75 @@ char vera_get_layer_config(char layer) {
return *config;
}
// Set the map width or height of the layer.
// - layer: Value of 0 or 1.
inline void vera_set_layer_map_width_32(unsigned byte layer) {
byte* addr = vera_layer_config[layer];
*addr &= ~VERA_LAYER_CONFIG_WIDTH_MASK;
*addr |= VERA_LAYER_CONFIG_WIDTH_32;
}
inline void vera_set_layer_map_width_64(unsigned byte layer) {
byte* addr = vera_layer_config[layer];
//*addr &= (~VERA_LAYER_CONFIG_WIDTH_MASK) | VERA_LAYER_CONFIG_WIDTH_64;
*addr &= ~VERA_LAYER_CONFIG_WIDTH_MASK;
*addr |= VERA_LAYER_CONFIG_WIDTH_64;
}
inline void vera_set_layer_map_width_128(unsigned byte layer) {
byte* addr = vera_layer_config[layer];
*addr &= ~VERA_LAYER_CONFIG_WIDTH_MASK;
*addr |= VERA_LAYER_CONFIG_WIDTH_128;
}
inline void vera_set_layer_map_width_256(unsigned byte layer) {
byte* addr = vera_layer_config[layer];
*addr &= ~VERA_LAYER_CONFIG_WIDTH_MASK;
*addr |= VERA_LAYER_CONFIG_WIDTH_256;
}
inline void vera_set_layer_map_height_32(unsigned byte layer) {
byte* addr = vera_layer_config[layer];
*addr &= ~VERA_LAYER_CONFIG_HEIGHT_MASK;
*addr |= VERA_LAYER_CONFIG_HEIGHT_32;
}
inline void vera_set_layer_map_height_64(unsigned byte layer) {
byte* addr = vera_layer_config[layer];
*addr &= ~VERA_LAYER_CONFIG_HEIGHT_MASK;
*addr |= VERA_LAYER_CONFIG_HEIGHT_64;
}
inline void vera_set_layer_map_height_128(unsigned byte layer) {
byte* addr = vera_layer_config[layer];
*addr &= ~VERA_LAYER_CONFIG_HEIGHT_MASK;
*addr |= VERA_LAYER_CONFIG_HEIGHT_128;
}
inline void vera_set_layer_map_height_256(unsigned byte layer) {
byte* addr = vera_layer_config[layer];
*addr &= ~VERA_LAYER_CONFIG_HEIGHT_MASK;
*addr |= VERA_LAYER_CONFIG_HEIGHT_256;
}
// Get the map width or height of the layer.
// - layer: Value of 0 or 1.
word vera_get_layer_map_width(unsigned byte layer) {
byte* config = vera_layer_config[layer];
byte mask = (byte)VERA_LAYER_CONFIG_WIDTH_MASK;
return VERA_CONFIG_WIDTH[ (*config & mask) >> 4];
}
word vera_get_layer_map_height(unsigned byte layer) {
byte* config = vera_layer_config[layer];
byte mask = VERA_LAYER_CONFIG_HEIGHT_MASK;
return VERA_CONFIG_HEIGHT[ (*config & mask) >> 6];
}
// Enable the layer to be displayed on the screen.
// - layer: 0 or 1.
void vera_show_layer(char layer) {
layer &= $1;
inline void vera_show_layer(char layer) {
*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;
inline void vera_hide_layer(char layer) {
*VERA_DC_VIDEO &= ~vera_layer_enable[layer];
}

View File

@ -9,22 +9,29 @@
#include <veralib.h>
#include <printf.h>
#include <6502.h>
void main() {
textcolor(WHITE);
bgcolor(GREEN);
scroll(0); // Scrolling on conio is deactivated, so conio will output beyond the borders of the visible screen.
clrscr();
dword tilebase = vera_get_layer_tilebase_address(1);
dword tilecolumn = tilebase;
dword tilerow = tilebase;
for(byte y:0..6) {
// Now we set the tile map width and height.
vera_set_layer_map_width_128(1);
vera_set_layer_map_height_128(1);
clrscr();
for(byte y:0..15) {
tilerow = tilebase;
for(byte r:0..7) {
tilecolumn = tilerow;
for(byte x:0..9) {
for(byte x:0..15) {
vera_vram_address0(tilecolumn,VERA_INC_0);
byte data = *VERA_DATA0;
byte bit = data;
@ -38,6 +45,65 @@ void main() {
//printf("\n");
tilerow += 1;
}
tilebase += 8*10;
tilebase += 8*16;
}
// Enable VSYNC IRQ (also set line bit 8 to 0)
SEI();
*KERNEL_IRQ = &irq_vsync;
*VERA_IEN = VERA_VSYNC;
CLI();
}
// X sine index
volatile int scroll_x = 0;
volatile int scroll_y = 0;
volatile int delta_x = 2;
volatile int delta_y = 0;
volatile int speed = 2;
// VSYNC Interrupt Routine
__interrupt(rom_sys_cx16) void irq_vsync() {
scroll_x += delta_x;
scroll_y += delta_y;
if( scroll_x>(128*8-80*8)) {
delta_x = 0;
delta_y = speed;
scroll_x = (128*8-80*8);
}
if( scroll_y>(128*8-60*8)) {
delta_x = -speed;
delta_y = 0;
scroll_y = (128*8-60*8);
}
if(scroll_x<0) {
delta_x = 0;
delta_y = -speed;
scroll_x = 0;
}
if(scroll_y<0) {
delta_x = speed;
delta_y = 0;
scroll_y = 0;
}
*VERA_L1_HSCROLL_L = <scroll_x;
*VERA_L1_HSCROLL_H = >scroll_x;
*VERA_L1_VSCROLL_L = <scroll_y;
*VERA_L1_VSCROLL_H = >scroll_y;
// Reset the VSYNC interrupt
*VERA_ISR = VERA_VSYNC;
// Exit CX16 KERNAL IRQ
asm {
// soft exit (keep kernal running)
jmp $e034
}
}

View File

@ -86,8 +86,6 @@ void main() {
gotoxy(19,6);
printf(" ");
gotoxy(0,40);
screenlayer(1); // Now we ask conio again to output to layer 1!
// Wait for a keypress and after clear the line!