From 40bc8e42d61d0783aac763de5cdcc4d12013d218 Mon Sep 17 00:00:00 2001 From: FlightControl Date: Sun, 17 Jan 2021 22:29:27 +0100 Subject: [PATCH] Got all the vera tile demos working now. First versions ... --- .../cache/fragment-cache-wdc65c02.asm | 48 ++++++++++ src/main/kc/include/veralib.h | 28 +++++- src/main/kc/lib/conio-cx16.c | 2 - src/main/kc/lib/veralib.c | 67 +++++++------ .../kc/examples/cx16/tilemap_2bpp_16_x_16.c | 2 +- .../kc/examples/cx16/tilemap_8bpp_16_x_16.c | 93 +++++++++---------- 6 files changed, 155 insertions(+), 85 deletions(-) diff --git a/src/main/fragment/cache/fragment-cache-wdc65c02.asm b/src/main/fragment/cache/fragment-cache-wdc65c02.asm index d1413b3da..b33f864d7 100644 --- a/src/main/fragment/cache/fragment-cache-wdc65c02.asm +++ b/src/main/fragment/cache/fragment-cache-wdc65c02.asm @@ -2511,3 +2511,51 @@ tax sty $ff ora $ff tay +//FRAGMENT vbuz1=vbuz1_plus_1 +inc {z1} +//FRAGMENT vwuz1_lt_vwuc1_then_la1 +lda {z1}+1 +cmp #>{c1} +bcc {la1} +bne !+ +lda {z1} +cmp #<{c1} +bcc {la1} +!: +//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=_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} +//FRAGMENT pbuc1_derefidx_vbuz1=vbuaa +ldy {z1} +sta {c1},y +//FRAGMENT pbuc1_derefidx_vbuxx=vbuaa +sta {c1},x +//FRAGMENT pbuc1_derefidx_vbuyy=vbuaa +sta {c1},y diff --git a/src/main/kc/include/veralib.h b/src/main/kc/include/veralib.h index f91639272..37aa8ec61 100644 --- a/src/main/kc/include/veralib.h +++ b/src/main/kc/include/veralib.h @@ -86,12 +86,12 @@ unsigned byte vera_layer_get_mapbase(unsigned byte layer); // Set the base of the map layer with which the conio will interact. // - layer: Value of 0 or 1. -// - dw_mapbase: a dword typed address (4 bytes), that specifies the full address of the map base. +// - mapbase_address: A dword typed address (4 bytes), that specifies the full address of the map base. // The function does the translation from the dword that contains the 17 bit address, // to the respective mapbase vera register. // 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_layer_set_mapbase_address(byte layer, dword dw_mapbase); +void vera_layer_set_mapbase_address(byte layer, dword mapbase_address); // Get the map base address of the tiles for the layer. // - layer: Value of 0 or 1. @@ -109,12 +109,12 @@ void vera_layer_set_tilebase(byte layer, byte tilebase); // Set the base of the tiles for the layer with which the conio will interact. // - layer: Value of 0 or 1. -// - dw_tilebase: a dword typed address (4 bytes), that specifies the base address of the tile map. +// - tilebase_address: A dword typed address (4 bytes), that specifies the base address of the tile map. // The function does the translation from the dword that contains the 17 bit address, // to the respective tilebase vera register. // Note that the resulting vera register holds 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_layer_set_tilebase_address(byte layer, dword dw_tilebase); +void vera_layer_set_tilebase_address(byte layer, dword tilebase_address); // Get the base of the tiles for the layer with which the conio will interact. // - layer: Value of 0 or 1. @@ -169,4 +169,22 @@ inline void vera_layer_set_horizontal_scroll(byte layer, word scroll); // - scroll: A value between 0 and 4096. inline void vera_layer_set_vertical_scroll(byte layer, word scroll); -void vera_layer_mode_tile(byte layer, dword mapbase_address, dword dw_tilebase, word mapwidth, word mapheight, byte tilewidth, byte tileheight, byte color_depth ); +// Set a vera layer in tile mode and configure the: +// - layer: Value of 0 or 1. +// - mapbase_address: A dword typed address (4 bytes), that specifies the full address of the map base. +// The function does the translation from the dword that contains the 17 bit address, +// to the respective mapbase vera register. +// 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. +// - tilebase_address: A dword typed address (4 bytes), that specifies the base address of the tile map. +// The function does the translation from the dword that contains the 17 bit address, +// to the respective tilebase vera register. +// Note that the resulting vera register holds 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! +// - mapwidth: The width of the map in number of tiles. +// - mapheight: The height of the map in number of tiles. +// - tilewidth: The width of a tile, which can be 8 or 16 pixels. +// - tileheight: The height of a tile, which can be 8 or 16 pixels. +// - color_depth: The color depth in bits per pixel (BPP), which can be 1, 2, 4 or 8. +void vera_layer_mode_tile(byte layer, dword mapbase_address, dword tilebase_address, word mapwidth, word mapheight, byte tilewidth, byte tileheight, byte color_depth ); + diff --git a/src/main/kc/lib/conio-cx16.c b/src/main/kc/lib/conio-cx16.c index 11cd42c3b..e4fd185f2 100644 --- a/src/main/kc/lib/conio-cx16.c +++ b/src/main/kc/lib/conio-cx16.c @@ -72,8 +72,6 @@ void conio_x16_init() { char * const BASIC_CURSOR_LINE = 0xD6; char line = *BASIC_CURSOR_LINE; vera_layer_mode_tile(1,0x00000,0x0F800,128,64,8,8,1); - vera_layer_rowskip[1] = 256; - vera_layer_rowshift[1] = 8; screensize(&conio_screen_width, &conio_screen_height); screenlayer(1); vera_layer_set_textcolor(1, WHITE); diff --git a/src/main/kc/lib/veralib.c b/src/main/kc/lib/veralib.c index 5c96eb854..579c607c0 100644 --- a/src/main/kc/lib/veralib.c +++ b/src/main/kc/lib/veralib.c @@ -176,22 +176,22 @@ void vera_layer_set_mapbase(unsigned byte layer, unsigned byte mapbase) { // Set the base of the map layer with which the conio will interact. // - layer: Value of 0 or 1. -// - dw_mapbase: a dword typed address (4 bytes), that specifies the full address of the map base. +// - mapbase_address: a dword typed address (4 bytes), that specifies the full address of the map base. // The function does the translation from the dword that contains the 17 bit address, // to the respective mapbase vera register. // 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_layer_set_mapbase_address(byte layer, dword dw_mapbase) { +void vera_layer_set_mapbase_address(byte layer, dword mapbase_address) { - dw_mapbase = dw_mapbase & 0x1FF00; // Aligned to 2048 bit zones. - byte bank_mapbase = (byte)>dw_mapbase; - word offset_mapbase = mapbase_address; + word offset_mapbase = (<(dw_mapbase>>1)); + byte mapbase = >(<(mapbase_address>>1)); vera_layer_set_mapbase(layer,mapbase); } @@ -250,23 +250,23 @@ byte vera_layer_get_tilebase(byte layer) { // Set the base address of the tiles for the layer with which the conio will interact. // - layer: Value of 0 or 1. -// - dw_tilebase: a dword typed address (4 bytes), that specifies the base address of the tile map. +// - tilebase_address: a dword typed address (4 bytes), that specifies the base address of the tile map. // The function does the translation from the dword that contains the 17 bit address, // to the respective tilebase vera register. // Note that the resulting vera register holds 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_layer_set_tilebase_address(byte layer, dword dw_tilebase) { +void vera_layer_set_tilebase_address(byte layer, dword tilebase_address) { - dw_tilebase = dw_tilebase & 0x1FC00; // Aligned to 2048 bit zones. - byte bank_tilebase = (byte)>dw_tilebase; - word word_tilebase = tilebase_address; + word word_tilebase = (<(dw_tilebase>>1)); + byte tilebase = >(<(tilebase_address>>1)); tilebase &= VERA_LAYER_TILEBASE_MASK; // Ensure that only tilebase is blanked, but keep the rest! //printf("tilebase = %x\n",tilebase); //while(!kbhit()); @@ -376,7 +376,24 @@ word vera_layer_get_rowskip(byte layer) { } -void vera_layer_mode_tile(byte layer, dword mapbase_address, dword dw_tilebase, word mapwidth, word mapheight, byte tilewidth, byte tileheight, byte color_depth ) { +// Set a vera layer in tile mode and configure the: +// - layer: Value of 0 or 1. +// - mapbase_address: A dword typed address (4 bytes), that specifies the full address of the map base. +// The function does the translation from the dword that contains the 17 bit address, +// to the respective mapbase vera register. +// 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. +// - tilebase_address: A dword typed address (4 bytes), that specifies the base address of the tile map. +// The function does the translation from the dword that contains the 17 bit address, +// to the respective tilebase vera register. +// Note that the resulting vera register holds 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! +// - mapwidth: The width of the map in number of tiles. +// - mapheight: The height of the map in number of tiles. +// - tilewidth: The width of a tile, which can be 8 or 16 pixels. +// - tileheight: The height of a tile, which can be 8 or 16 pixels. +// - color_depth: The color depth in bits per pixel (BPP), which can be 1, 2, 4 or 8. +void vera_layer_mode_tile(byte layer, dword mapbase_address, dword tilebase_address, word mapwidth, word mapheight, byte tilewidth, byte tileheight, byte color_depth ) { // config byte config = 0x00; switch(color_depth) { @@ -441,20 +458,13 @@ void vera_layer_mode_tile(byte layer, dword mapbase_address, dword dw_tilebase, byte mapbase = >(tilebase_address; + vera_tilebase_address[layer] = tilebase_address; - //printf("%lx\n",dw_mapbase); - - // tilebase - vera_tilebase_offset[layer] = dw_tilebase; - vera_tilebase_address[layer] = dw_tilebase; - - //printf("tilebase word = %x\n",vera_tilebase_offset[layer]); - //printf("tilebase bank = %x\n",vera_tilebase_bank[layer]); - //printf("tilebase dword = %lx\n",vera_tilebase_address[layer]); - - dw_tilebase = dw_tilebase >> 1; - byte tilebase = >(> 1; + byte tilebase = >(