mirror of
https://gitlab.com/camelot/kickc.git
synced 2024-12-22 21:29:50 +00:00
Test program to print the default tiles of the CX16 on the screen. It demonstrates the tile addressing of the VERA and the vera functions in kickc that can be used for this.
This commit is contained in:
parent
d24ca095dd
commit
51874941a0
1391
src/main/fragment/cache/fragment-cache-wdc65c02.asm
vendored
1391
src/main/fragment/cache/fragment-cache-wdc65c02.asm
vendored
File diff suppressed because it is too large
Load Diff
@ -94,6 +94,36 @@ __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 ---
|
||||
|
||||
void vera_vram_address0(dword bankaddr, byte incr) {
|
||||
word* word_l = &(<bankaddr);
|
||||
word* word_h = &(>bankaddr);
|
||||
//printf("\nword_l = %x", *word_l);
|
||||
//printf("\nword_h = %x", *word_h);
|
||||
//printf("\n<word_l = %x", <(*word_l));
|
||||
//printf("\n>word_l = %x", >(*word_l));
|
||||
//printf("\n<word_h = %x", <(*word_h));
|
||||
//printf("\n>word_h = %x", >(*word_h));
|
||||
// Select DATA0
|
||||
*VERA_CTRL &= ~VERA_ADDRSEL;
|
||||
// Set address
|
||||
*VERA_ADDRX_L = <(*word_l);
|
||||
*VERA_ADDRX_M = >(*word_l);
|
||||
*VERA_ADDRX_H = <(*word_h) | incr;
|
||||
}
|
||||
|
||||
void vera_vram_address1(dword bankaddr, byte incr) {
|
||||
word* word_l = &(<bankaddr);
|
||||
word* word_h = &(>bankaddr);
|
||||
// Select DATA1
|
||||
*VERA_CTRL |= VERA_ADDRSEL;
|
||||
// Set address
|
||||
*VERA_ADDRX_L = <(*word_l);
|
||||
*VERA_ADDRX_M = >(*word_l);
|
||||
*VERA_ADDRX_H = <(*word_h) | incr;
|
||||
}
|
||||
|
||||
// --- VERA layer management ---
|
||||
|
||||
// Set the configuration of the layer.
|
||||
@ -181,6 +211,21 @@ unsigned byte vera_get_layer_tilebase(unsigned byte layer) {
|
||||
return *tilebase;
|
||||
}
|
||||
|
||||
// Get the tile base address of the tiles for the layer.
|
||||
// - layer: Value of 0 or 1.
|
||||
// - return: Specifies the base address of the tile map, which is calculated as an unsigned long int.
|
||||
// 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!
|
||||
dword vera_get_layer_tilebase_address(byte layer) {
|
||||
layer &= $1;
|
||||
byte tilebase = *vera_layer_tilebase[layer];
|
||||
dword address = tilebase;
|
||||
address &= $FC;
|
||||
address <<= 8;
|
||||
address <<= 1;
|
||||
return address;
|
||||
}
|
||||
|
||||
// --- VERA color management ---
|
||||
|
||||
// Set the front color for text output. The old front text color setting is returned.
|
||||
|
42
src/test/kc/examples/cx16/tilemap.c
Normal file
42
src/test/kc/examples/cx16/tilemap.c
Normal file
@ -0,0 +1,42 @@
|
||||
// Example program for the Commander X16.
|
||||
// Demonstrates the usage of the VERA layer 0 and 1.
|
||||
|
||||
// Author: Sven Van de Velde
|
||||
|
||||
// The default layer of the CS16 is layer 1.
|
||||
// The CS16 starts in tile map mode, 1BPP in 16 color mode, and uses 8x8 tiles.
|
||||
// The map base is address 0x00000 in VERA VRAM, the tile map is address 0x1F000.
|
||||
|
||||
#include <printf.h>
|
||||
|
||||
void main() {
|
||||
|
||||
textcolor(WHITE);
|
||||
bgcolor(GREEN);
|
||||
clrscr();
|
||||
|
||||
dword tilebase = vera_get_layer_tilebase_address(1);
|
||||
dword tilecolumn = tilebase;
|
||||
dword tilerow = tilebase;
|
||||
|
||||
for(byte y:0..6) {
|
||||
tilerow = tilebase;
|
||||
for(byte r:0..7) {
|
||||
tilecolumn = tilerow;
|
||||
for(byte x:0..9) {
|
||||
vera_vram_address0(tilecolumn,VERA_INC_0);
|
||||
byte data = *VERA_DATA0;
|
||||
byte bit = data;
|
||||
for(byte b:8..1) {
|
||||
bit = (data >> (b-1)) & $1;
|
||||
printf("%c", (char)((bit)?'*':'.'));
|
||||
}
|
||||
tilecolumn += 8;
|
||||
printf("");
|
||||
}
|
||||
//printf("\n");
|
||||
tilerow += 1;
|
||||
}
|
||||
tilebase += 8*10;
|
||||
}
|
||||
}
|
@ -1,3 +1,12 @@
|
||||
// Example program for the Commander X16.
|
||||
// Demonstrates the usage of the VERA layer 0 and 1.
|
||||
|
||||
// Author: Sven Van de Velde
|
||||
|
||||
// The default layer of the CS16 is layer 1.
|
||||
// The CS16 starts in tile map mode, 1BPP in 16 color mode, and uses 8x8 tiles.
|
||||
// The map base is address 0x00000 in VERA VRAM, the tile map is address 0x1F000.
|
||||
|
||||
#include <printf.h>
|
||||
|
||||
void main() {
|
||||
|
Loading…
Reference in New Issue
Block a user