From 52c825f19b96afb853a6c2b00c217b659367f91b Mon Sep 17 00:00:00 2001 From: nino-porcino Date: Sat, 27 Nov 2021 18:12:35 +0100 Subject: [PATCH] KickC port of the library --- .gitignore | 4 + KickC/c.bat | 6 + KickC/env_kickc.bat | 3 + KickC/laser500_font.ascii.c | 856 ++++++++++++++++++++++++++++++++++++ KickC/test.c | 305 +++++++++++++ 5 files changed, 1174 insertions(+) create mode 100644 KickC/c.bat create mode 100644 KickC/env_kickc.bat create mode 100644 KickC/laser500_font.ascii.c create mode 100644 KickC/test.c diff --git a/.gitignore b/.gitignore index f42f235..4d0daf1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,6 @@ *.lst *.prg +*.klog +*.vs +*.dbg +KickC/**.asm diff --git a/KickC/c.bat b/KickC/c.bat new file mode 100644 index 0000000..1d254c1 --- /dev/null +++ b/KickC/c.bat @@ -0,0 +1,6 @@ +@echo *** APPLE 1 *** +call kickc -t asm6502 -D=APPLE1 test.c -o test_apple1.prg -e +copy test.prg test_apple1.prg +@echo *** VIC20 *** +call kickc -t VIC20 -D=VIC20 test.c -o test_vic20.prg -e +copy test.prg test_vic20.prg diff --git a/KickC/env_kickc.bat b/KickC/env_kickc.bat new file mode 100644 index 0000000..93a1bf7 --- /dev/null +++ b/KickC/env_kickc.bat @@ -0,0 +1,3 @@ +path %path%;"c:\Program Files\Java\jdk1.8.0_161\bin" +path %path%;C:\Users\Nino1\Desktop\kickc\bin + diff --git a/KickC/laser500_font.ascii.c b/KickC/laser500_font.ascii.c new file mode 100644 index 0000000..9621711 --- /dev/null +++ b/KickC/laser500_font.ascii.c @@ -0,0 +1,856 @@ +byte FONT[768] = { + 0 +, 0 +, 0 +, 0 +, 0 +, 0 +, 0 +, 0 +, 8 +, 8 + +, 8 +, 8 +, 8 +, 0 +, 8 +, 0 +, 20 +, 20 + +, 20 +, 0 +, 0 +, 0 +, 0 +, 0 +, 20 +, 20 + +, 62 +, 20 +, 62 +, 20 +, 20 +, 0 +, 8 +, 30 + +, 40 +, 28 +, 10 +, 60 +, 8 +, 0 +, 48 +, 50 + +, 4 +, 8 +, 16 +, 38 +, 6 +, 0 +, 16 +, 40 + +, 40 +, 16 +, 42 +, 36 +, 26 +, 0 +, 8 +, 8 + +, 8 +, 0 +, 0 +, 0 +, 0 +, 0 +, 8 +, 16 + +, 32 +, 32 +, 32 +, 16 +, 8 +, 0 + +, 8 +, 4 +, 2 +, 2 +, 2 +, 4 +, 8 +, 0 + +, 8 +, 42 +, 28 +, 8 +, 28 +, 42 +, 8 +, 0 + +, 0 +, 8 +, 8 +, 62 +, 8 +, 8 +, 0 +, 0 + +, 0 +, 0 +, 0 +, 0 +, 8 +, 8 +, 16 +, 0 + +, 0 +, 0 +, 0 +, 62 +, 0 +, 0 +, 0 +, 0 + +, 0 +, 0 +, 0 +, 0 +, 0 +, 0 +, 8 +, 0 + +, 0 +, 2 +, 4 +, 8 +, 16 +, 32 +, 0 +, 0 + +, 28 +, 34 +, 38 +, 42 +, 50 +, 34 +, 28 +, 0 + +, 8 +, 24 +, 8 +, 8 +, 8 +, 8 +, 28 +, 0 + +, 28 +, 34 +, 2 +, 12 +, 16 +, 32 +, 62 +, 0 + +, 62 +, 2 +, 4 +, 12 +, 2 +, 34 +, 28 +, 0 + +, 4 +, 12 +, 20 +, 36 +, 62 +, 4 +, 4 +, 0 + +, 62 +, 32 +, 60 +, 2 +, 2 +, 34 +, 28 +, 0 + +, 14 +, 16 +, 32 +, 60 +, 34 +, 34 +, 28 +, 0 + +, 62 +, 2 +, 4 +, 8 +, 16 +, 32 +, 32 +, 0 + +, 28 +, 34 +, 34 +, 28 +, 34 +, 34 +, 28 +, 0 + +, 28 +, 34 +, 34 +, 30 +, 2 +, 4 +, 56 +, 0 + +, 0 +, 0 +, 8 +, 0 +, 8 +, 0 +, 0 +, 0 + +, 0 +, 0 +, 8 +, 0 +, 8 +, 8 +, 16 +, 0 + +, 4 +, 8 +, 16 +, 32 +, 16 +, 8 +, 4 +, 0 + +, 0 +, 0 +, 62 +, 0 +, 62 +, 0 +, 0 +, 0 + +, 16 +, 8 +, 4 +, 2 +, 4 +, 8 +, 16 +, 0 + +, 28 +, 34 +, 4 +, 8 +, 8 +, 0 +, 8 +, 0 + +, 28 +, 34 +, 42 +, 46 +, 44 +, 32 +, 28 +, 0 + +, 8 +, 20 +, 34 +, 34 +, 62 +, 34 +, 34 +, 0 + +, 60 +, 34 +, 34 +, 60 +, 34 +, 34 +, 60 +, 0 + +, 28 +, 34 +, 32 +, 32 +, 32 +, 34 +, 28 +, 0 + +, 56 +, 36 +, 34 +, 34 +, 34 +, 36 +, 56 +, 0 + +, 62 +, 32 +, 32 +, 56 +, 32 +, 32 +, 62 +, 0 + +, 62 +, 32 +, 32 +, 56 +, 32 +, 32 +, 32 +, 0 + +, 30 +, 32 +, 32 +, 32 +, 38 +, 34 +, 30 +, 0 + +, 34 +, 34 +, 34 +, 62 +, 34 +, 34 +, 34 +, 0 + +, 28 +, 8 +, 8 +, 8 +, 8 +, 8 +, 28 +, 0 + +, 2 +, 2 +, 2 +, 2 +, 2 +, 34 +, 28 +, 0 + +, 34 +, 36 +, 40 +, 48 +, 40 +, 36 +, 34 +, 0 + +, 32 +, 32 +, 32 +, 32 +, 32 +, 32 +, 62 +, 0 + +, 34 +, 54 +, 42 +, 42 +, 34 +, 34 +, 34 +, 0 + +, 34 +, 34 +, 50 +, 42 +, 38 +, 34 +, 34 +, 0 + +, 28 +, 34 +, 34 +, 34 +, 34 +, 34 +, 28 +, 0 + +, 60 +, 34 +, 34 +, 60 +, 32 +, 32 +, 32 +, 0 + +, 28 +, 34 +, 34 +, 34 +, 42 +, 36 +, 26 +, 0 + +, 60 +, 34 +, 34 +, 60 +, 40 +, 36 +, 34 +, 0 + +, 28 +, 34 +, 32 +, 28 +, 2 +, 34 +, 28 +, 0 + +, 62 +, 8 +, 8 +, 8 +, 8 +, 8 +, 8 +, 0 + +, 34 +, 34 +, 34 +, 34 +, 34 +, 34 +, 28 +, 0 + +, 34 +, 34 +, 34 +, 34 +, 34 +, 20 +, 8 +, 0 + +, 34 +, 34 +, 34 +, 42 +, 42 +, 54 +, 34 +, 0 + +, 34 +, 34 +, 20 +, 8 +, 20 +, 34 +, 34 +, 0 + +, 34 +, 34 +, 20 +, 8 +, 8 +, 8 +, 8 +, 0 + +, 62 +, 2 +, 4 +, 8 +, 16 +, 32 +, 62 +, 0 + +, 62 +, 48 +, 48 +, 48 +, 48 +, 48 +, 62 +, 0 + +, 0 +, 32 +, 16 +, 8 +, 4 +, 2 +, 0 +, 0 + +, 62 +, 6 +, 6 +, 6 +, 6 +, 6 +, 62 +, 0 + +, 8 +, 20 +, 34 +, 0 +, 0 +, 0 +, 0 +, 0 + +, 0 +, 0 +, 0 +, 0 +, 0 +, 0 +, 0 +, 62 + +, 16 +, 8 +, 4 +, 0 +, 0 +, 0 +, 0 +, 0 + +, 0 +, 0 +, 28 +, 2 +, 30 +, 34 +, 30 +, 0 + +, 32 +, 32 +, 60 +, 34 +, 34 +, 34 +, 60 +, 0 + +, 0 +, 0 +, 30 +, 32 +, 32 +, 32 +, 30 +, 0 + +, 2 +, 2 +, 30 +, 34 +, 34 +, 34 +, 30 +, 0 + +, 0 +, 0 +, 28 +, 34 +, 62 +, 32 +, 30 +, 0 + +, 12 +, 18 +, 16 +, 60 +, 16 +, 16 +, 16 +, 0 + +, 0 +, 0 +, 28 +, 34 +, 34 +, 30 +, 2 +, 28 + +, 32 +, 32 +, 60 +, 34 +, 34 +, 34 +, 34 +, 0 + +, 8 +, 0 +, 24 +, 8 +, 8 +, 8 +, 28 +, 0 + +, 2 +, 0 +, 6 +, 2 +, 2 +, 2 +, 18 +, 12 + +, 32 +, 32 +, 34 +, 36 +, 56 +, 36 +, 34 +, 0 + +, 24 +, 8 +, 8 +, 8 +, 8 +, 8 +, 28 +, 0 + +, 0 +, 0 +, 52 +, 42 +, 42 +, 42 +, 34 +, 0 + +, 0 +, 0 +, 60 +, 34 +, 34 +, 34 +, 34 +, 0 + +, 0 +, 0 +, 28 +, 34 +, 34 +, 34 +, 28 +, 0 + +, 0 +, 0 +, 60 +, 34 +, 34 +, 60 +, 32 +, 32 + +, 0 +, 0 +, 30 +, 34 +, 34 +, 30 +, 2 +, 2 + +, 0 +, 0 +, 46 +, 48 +, 32 +, 32 +, 32 +, 0 + +, 0 +, 0 +, 30 +, 32 +, 28 +, 2 +, 60 +, 0 + +, 16 +, 16 +, 60 +, 16 +, 16 +, 18 +, 12 +, 0 + +, 0 +, 0 +, 34 +, 34 +, 34 +, 38 +, 26 +, 0 + +, 0 +, 0 +, 34 +, 34 +, 34 +, 20 +, 8 +, 0 + +, 0 +, 0 +, 34 +, 34 +, 42 +, 42 +, 20 +, 0 + +, 0 +, 0 +, 34 +, 20 +, 8 +, 20 +, 34 +, 0 + +, 0 +, 0 +, 34 +, 36 +, 20 +, 24 +, 8 +, 48 + +, 0 +, 0 +, 62 +, 4 +, 8 +, 16 +, 62 +, 0 + +, 6 +, 8 +, 8 +, 48 +, 8 +, 8 +, 6 +, 0 + +, 8 +, 8 +, 8 +, 8 +, 8 +, 8 +, 8 +, 8 + +, 48 +, 8 +, 8 +, 6 +, 8 +, 8 +, 48 +, 0 + +, 26 +, 44 +, 0 +, 0 +, 0 +, 0 +, 0 +, 0 +}; diff --git a/KickC/test.c b/KickC/test.c new file mode 100644 index 0000000..bf0082f --- /dev/null +++ b/KickC/test.c @@ -0,0 +1,305 @@ +#ifdef APPLE1 + // APPLE1 + const word WOZMON = 0xFF1F; // enters monitor + const word ECHO = 0xFFEF; // output ascii character in A (A not destroyed) + const word PRBYTE = 0xFFDC; // print hex byte in A (A destroyed) + const word VDP_DATA = 0xC000; // TMS9918 data port (VRAM) + const word VDP_REG = 0xC001; // TMS9918 register port (write) or status (read) +#else + // VIC20 + const word ECHO = 0xFFD2; // chrout routine in kernal rom + const word VDP_DATA = 0xA000; // TMS9918 data port (VRAM) + const word VDP_REG = 0xA001; // TMS9918 register port (write) or status (read) +#endif + +// typedef unsigned char byte; +// typedef unsigned int word; + +// TMS9918 interface flags +const byte WRITE_TO_REG = 0b10000000; +const byte WRITE_TO_VRAM = 0b01000000; +const byte READ_FROM_VRAM = 0b00000000; + +#define POKE(a,b) (*((byte *)(a))=(byte)(b)) +#define PEEK(a) (*((byte *)(a))) + +// puts a character on the apple1 screen using the WOZMON routine +void woz_putc(byte c) { + asm { + lda c + jsr ECHO + } +} + +// returns to WOZMON prompt +void woz_mon() { + #ifdef APPLE1 + asm { + jmp WOZMON + } + #endif +} + +// sets the VRAM address on the TMS9918 +void set_vram_addr(word addr) { + POKE(VDP_REG,addr & 0b00111111)|WRITE_TO_VRAM); +} + +// sets the VRAM address on the TMS9918 +void set_vram_read_addr(word addr) { + POKE(VDP_REG,addr & 0b00111111)|READ_FROM_VRAM); +} + +// writes a value to a TMS9918 register (0-7) +void write_reg(byte regnum, byte val) { + // nops are not required + POKE(VDP_REG, val); + POKE(VDP_REG, (regnum & 0b00001111)|WRITE_TO_REG); +} + +word tms_cursor; + +#include "laser500_font.ascii.c" + +// SCREEN 1 VALUES + +// sprite patterns: $0000 +// pattern table: $0800 (256*8) +// sprite attributes: $1000 +// unused: $1080 +// name table: $1400 (32*24) +// unused: $1800 +// color table: $2000 (32) +// unused $2020-$3FFF + +const word SCREEN1_PATTERN_TABLE = 0x0800; +const word SCREEN1_NAME_TABLE = 0x1400; +const word SCREEN1_COLOR_TABLE = 0x2000; +const word SCREEN1_SPRITE_PATTERNS = 0x0000; +const word SCREEN1_SPRITE_ATTRS = 0x1000; +const word SCREEN1_SIZE = (32*24); + +byte SCREEN1_TABLE[8] = { + 0x00, 0xc0, 0x05, 0x80, 0x01, 0x20, 0x00, 0x25 +}; + +// loads the Laser 500 font on the pattern table +void SCREEN1_LOAD_FONT() { + + static byte *source = FONT; + static word i; + + // start writing into VRAM from space character + set_vram_addr(SCREEN1_PATTERN_TABLE+(32*8)); + for(i=0;i<768;i++) { + POKE(VDP_DATA, *source++); + } + + // reverse font + source = FONT; + set_vram_addr(SCREEN1_PATTERN_TABLE+((128+32)*8)); + for(i=0;i<768;i++) { + POKE(VDP_DATA, ~(*source++)); + } +} + +// prints character to TMS (SCREEN 1 MODE) +void SCREEN1_PUTCHAR(byte c) { + set_vram_addr(tms_cursor++); + POKE(VDP_DATA, c); +} + +// prints 0 terminated string pointed by YA +void SCREEN1_PUTS(byte *s) { + while(*s) { + SCREEN1_PUTCHAR(*s++); + } +} + +void SCREEN1_HOME() { + tms_cursor = SCREEN1_NAME_TABLE; +} + +void SCREEN1_LOCATEXY(byte x, byte y) { + tms_cursor = SCREEN1_NAME_TABLE + ((word)y)*32 + x; +} + +void SCREEN1_INIT() { + for(byte i=0;i<8;i++) { + write_reg(i, SCREEN1_TABLE[i]); + } +} + +void SCREEN1_FILL() { + // fills name table with spaces (32) + set_vram_addr(SCREEN1_NAME_TABLE); + for(word i=0;i> (x%8); + byte data; + + set_vram_read_addr(paddr); + data = PEEK(VDP_DATA); + set_vram_addr(paddr); + POKE(VDP_DATA,data | pattern); +} + +void screen1_square_sprites() { + // fills first sprite pattern with 255 + set_vram_addr(SCREEN1_SPRITE_PATTERNS); // start writing in the sprite patterns + for(byte i=0;i<8;i++) { + POKE(VDP_DATA, 255); + } + + // set sprite coordinates + set_vram_addr(SCREEN1_SPRITE_ATTRS); // start writing in the sprite attribute + for(byte i=0;i<32;i++) { + POKE(VDP_DATA,(6+i)*8); // y coordinate + POKE(VDP_DATA,(6+i)*8); // x coordinate + POKE(VDP_DATA,0); // name + POKE(VDP_DATA,i); // color + } +} + +void screen2_square_sprites() { + // fills first sprite pattern with 255 + set_vram_addr(SCREEN2_SPRITE_PATTERNS); // start writing in the sprite patterns + for(byte i=0;i<8;i++) { + POKE(VDP_DATA, 0); + } + + // set sprite coordinates + set_vram_addr(SCREEN2_SPRITE_ATTRS); // start writing in the sprite attribute + for(byte i=0;i<32;i++) { + POKE(VDP_DATA,0); // y coordinate + POKE(VDP_DATA,0); // x coordinate + POKE(VDP_DATA,0); // name + POKE(VDP_DATA,i); // color + } +} + +void main() { + if(1) { + SCREEN1_INIT(); + SCREEN1_FILL(); + SCREEN1_LOAD_FONT(); + + SCREEN1_HOME(); SCREEN1_PUTS("*** P-LAB VIDEO CARD SYSTEM ***"); + SCREEN1_LOCATEXY(0, 2); SCREEN1_PUTS("16K VRAM BYTES FREE"); + SCREEN1_LOCATEXY(0, 4); SCREEN1_PUTS("READY."); + + SCREEN1_LOCATEXY(0, 10); + for(word i=0;i<256;i++) SCREEN1_PUTCHAR((byte)i); + + screen1_square_sprites(); + } + + if(0) { + SCREEN2_INIT(); + SCREEN2_FILL(); + screen2_square_sprites(); + //SCREEN2_PUTC(65,1,1,0x1F); + + SCREEN2_PUTS(0,0,0x1F,"*** P-LAB VIDEO CARD SYSTEM ***"); + SCREEN2_PUTS(0,2,0x1F,"16K VRAM BYTES FREE"); + SCREEN2_PUTS(0,4,0x1F,"READY."); + + for(byte i=0;i<16;i++) { + SCREEN2_PUTS(5,(byte)(6+i),(byte)(((15-i)<<4)+i)," COLOR "); + } + + for(byte i=0;i<192;i++) { + SCREEN2_PSET((byte)i ,(byte)i/2); + SCREEN2_PSET((byte)i ,(byte)i); + SCREEN2_PSET((byte)i/2,(byte)i); + } + } + + woz_putc(42); + woz_mon(); +} +