From 9572291866af43e21c70da46b20c0ecfaa32fb1d Mon Sep 17 00:00:00 2001 From: nino-porcino Date: Thu, 23 Dec 2021 15:37:01 +0100 Subject: [PATCH 1/5] add CBM balloon demo --- demos/demo/cbm_balloon.data.h | 65 ++++++++++++++++++ demos/demo/cbm_balloon.h | 7 ++ demos/demo/demo_screen2.h | 55 +++++++++++++++- demos/demo/mk_baloon.js | 120 ++++++++++++++++++++++++++++++++++ 4 files changed, 244 insertions(+), 3 deletions(-) create mode 100644 demos/demo/cbm_balloon.data.h create mode 100644 demos/demo/cbm_balloon.h create mode 100644 demos/demo/mk_baloon.js diff --git a/demos/demo/cbm_balloon.data.h b/demos/demo/cbm_balloon.data.h new file mode 100644 index 0000000..896e7a7 --- /dev/null +++ b/demos/demo/cbm_balloon.data.h @@ -0,0 +1,65 @@ +// file generated automatically by mkfont.js -- do not edit + 0b00001111, + 0b00111111, + 0b01111111, + 0b01111100, + 0b11111011, + 0b11111011, + 0b11111011, + 0b01111100, + 0b01111111, + 0b01111111, + 0b01011111, + 0b00101111, + 0b00100111, + 0b00010011, + 0b00010011, + 0b00001001, + 0b11100000, + 0b11111000, + 0b11111100, + 0b11111100, + 0b00111110, + 0b11111110, + 0b00111110, + 0b11111100, + 0b11111100, + 0b11111100, + 0b11110100, + 0b11101000, + 0b11001000, + 0b10010000, + 0b10010000, + 0b00100000, + 0b00001001, + 0b00000111, + 0b00000111, + 0b00000111, + 0b00000011, + 0b00000000, + 0b00000000, + 0b00000000, + 0b00000000, + 0b00000000, + 0b00000000, + 0b00000000, + 0b00000000, + 0b00000000, + 0b00000000, + 0b00000000, + 0b00100000, + 0b11000000, + 0b11000000, + 0b11000000, + 0b10000000, + 0b00000000, + 0b00000000, + 0b00000000, + 0b00000000, + 0b00000000, + 0b00000000, + 0b00000000, + 0b00000000, + 0b00000000, + 0b00000000, + 0b00000000, diff --git a/demos/demo/cbm_balloon.h b/demos/demo/cbm_balloon.h new file mode 100644 index 0000000..daff455 --- /dev/null +++ b/demos/demo/cbm_balloon.h @@ -0,0 +1,7 @@ +// file generated automatically by mkfont.js -- do not edit +const byte cbm_balloon[] = { + +#include "cbm_balloon.data.h" + +}; + diff --git a/demos/demo/demo_screen2.h b/demos/demo/demo_screen2.h index 542c899..31b8a79 100644 --- a/demos/demo/demo_screen2.h +++ b/demos/demo/demo_screen2.h @@ -1,5 +1,21 @@ #include +#include "cbm_balloon.h" + +void move_balloon(byte x, byte y, byte color) { + tms_sprite spr0,spr1; + spr0.x = x; + spr0.y = y; + spr0.name = 0; + spr0.color = color; + spr1.x = spr0.x; + spr1.y = spr0.y + 32; + spr1.name = spr0.name + 4; + spr1.color = spr0.color; + tms_set_sprite(0, &spr0); + tms_set_sprite(1, &spr1); +} + void demo_screen2() { tms_init_regs(SCREEN2_TABLE); @@ -30,6 +46,7 @@ void demo_screen2() { screen2_plot_mode = PLOT_MODE_SET; +/* // define sprites using bitmap fonts tms_copy_to_vram(&FONT[64*8], 32*8, TMS_SPRITE_PATTERNS); @@ -40,11 +57,43 @@ void demo_screen2() { tms_set_sprite_magnification(1); tms_sprite spr; - for(byte t=0;t<32;t++) { - spr.x = 10 + t*32; + for(byte t=0;t<4;t++) { + spr.x = 200; spr.y = 5 + t*32; - spr.name = t; + spr.name = t*4; spr.color = t+1; tms_set_sprite(t, &spr); } +*/ + + // ballon demo + + // define sprites using bitmap fonts + tms_copy_to_vram(cbm_balloon, 4*8*2, TMS_SPRITE_PATTERNS); + tms_set_sprite_double_size(1); // set 16x16 sprites + tms_set_sprite_magnification(1); // set double pixel sprites + + int x = 200; + int y = 80; + int dx = 1; + int dy = 1; + int delay = 0; + byte sprcolor = COLOR_DARK_BLUE; + + for(;;) { + for(delay=0; delay<800; delay++) { + delay = delay+1; + delay = delay-1; + } + + if(apple1_readkey()==0x0d) break; + + if(x>=228 || x<=0) { dx = -dx; sprcolor++; } + if(y>=148 || y<=0) { dy = -dy; sprcolor++; } + + x += dx; + y += dy; + move_balloon((byte)x,(byte)y, sprcolor); + } } + diff --git a/demos/demo/mk_baloon.js b/demos/demo/mk_baloon.js new file mode 100644 index 0000000..cd6e276 --- /dev/null +++ b/demos/demo/mk_baloon.js @@ -0,0 +1,120 @@ +function e(s) { + let b = 0; + for(let t=0;t Date: Thu, 23 Dec 2021 18:55:56 +0100 Subject: [PATCH 2/5] balloon demo with c64 screen --- demos/demo/demo.c | 3 + demos/demo/demo_balloon.h | 62 +++ demos/demo/demo_screen2.h | 48 --- lib/c64.ascii.txt | 0 lib/c64font.h | 874 ++++++++++++++++++++++++++++++++++++++ lib/tms9918.h | 3 +- 6 files changed, 941 insertions(+), 49 deletions(-) create mode 100644 demos/demo/demo_balloon.h create mode 100644 lib/c64.ascii.txt create mode 100644 lib/c64font.h diff --git a/demos/demo/demo.c b/demos/demo/demo.c index b1f8de0..29d0329 100644 --- a/demos/demo/demo.c +++ b/demos/demo/demo.c @@ -2,6 +2,7 @@ #include "demo_screen1.h" #include "demo_screen2.h" +#include "demo_balloon.h" #include "demo_amiga_hand.h" #include "demo_interrupt.h" #include "demo_extvid.h" @@ -14,6 +15,7 @@ void help() { "=============\r" "1 SCREEN1\r" "2 SCREEN2\r" + "3 BALLOON\r" "A AMIGA HAND\r" "I INTERRUPT\r" "E FLIP EXT VIDEO\r" @@ -34,6 +36,7 @@ void main() { for(;;) { if(key == '1') demo_screen1(); else if(key == '2') demo_screen2(); + else if(key == '3') demo_balloon(); else if(key == 'A') demo_amiga_hand(); else if(key == 'I') demo_interrupt(); else if(key == 'E') flip_external_input(); diff --git a/demos/demo/demo_balloon.h b/demos/demo/demo_balloon.h new file mode 100644 index 0000000..e30d95d --- /dev/null +++ b/demos/demo/demo_balloon.h @@ -0,0 +1,62 @@ +#include + +#include "cbm_balloon.h" + +void move_balloon(byte x, byte y, byte color) { + tms_sprite spr0,spr1; + spr0.x = x; + spr0.y = y; + spr0.name = 0; + spr0.color = color; + spr1.x = spr0.x; + spr1.y = spr0.y + 16*1; + spr1.name = spr0.name + 4; + spr1.color = spr0.color; + tms_set_sprite(0, &spr0); + tms_set_sprite(1, &spr1); +} + +void demo_balloon() { + tms_init_regs(SCREEN2_TABLE); + tms_set_color(COLOR_LIGHT_BLUE); + + byte text_color = FG_BG(COLOR_GREY,COLOR_DARK_BLUE); + + screen2_init_bitmap(text_color); + // 12345678901234567890123456789012 + screen2_puts("*** COMMODORE-APPLE BASIC V2 ***", 0, 0, text_color); + screen2_puts("38911 BASIC BYTES FREE" , 0, 2, text_color); + screen2_puts("READY." , 0, 4, text_color); + screen2_puts(" " , 0, 5, FG_BG(COLOR_DARK_BLUE,COLOR_GREY)); + + // ballon demo + + // define sprites using bitmap fonts + tms_copy_to_vram(cbm_balloon, 4*8*2, TMS_SPRITE_PATTERNS); + tms_set_sprite_double_size(1); // set 16x16 sprites + tms_set_sprite_magnification(0); // set double pixel sprites + + int x = 200; + int y = 80; + int dx = 1; + int dy = 1; + int delay = 0; + byte sprcolor = COLOR_LIGHT_YELLOW; + + for(;;) { + for(delay=0; delay<800; delay++) { + delay = delay+1; + delay = delay-1; + } + + if(apple1_readkey()==0x0d) break; + + if(x>=228 || x<=0) { dx = -dx; sprcolor++; } + if(y>=148 || y<=0) { dy = -dy; sprcolor++; } + + x += dx; + y += dy; + move_balloon((byte)x,(byte)y, COLOR_WHITE); + } +} + diff --git a/demos/demo/demo_screen2.h b/demos/demo/demo_screen2.h index 31b8a79..38df09a 100644 --- a/demos/demo/demo_screen2.h +++ b/demos/demo/demo_screen2.h @@ -1,21 +1,5 @@ #include -#include "cbm_balloon.h" - -void move_balloon(byte x, byte y, byte color) { - tms_sprite spr0,spr1; - spr0.x = x; - spr0.y = y; - spr0.name = 0; - spr0.color = color; - spr1.x = spr0.x; - spr1.y = spr0.y + 32; - spr1.name = spr0.name + 4; - spr1.color = spr0.color; - tms_set_sprite(0, &spr0); - tms_set_sprite(1, &spr1); -} - void demo_screen2() { tms_init_regs(SCREEN2_TABLE); @@ -46,7 +30,6 @@ void demo_screen2() { screen2_plot_mode = PLOT_MODE_SET; -/* // define sprites using bitmap fonts tms_copy_to_vram(&FONT[64*8], 32*8, TMS_SPRITE_PATTERNS); @@ -64,36 +47,5 @@ void demo_screen2() { spr.color = t+1; tms_set_sprite(t, &spr); } -*/ - - // ballon demo - - // define sprites using bitmap fonts - tms_copy_to_vram(cbm_balloon, 4*8*2, TMS_SPRITE_PATTERNS); - tms_set_sprite_double_size(1); // set 16x16 sprites - tms_set_sprite_magnification(1); // set double pixel sprites - - int x = 200; - int y = 80; - int dx = 1; - int dy = 1; - int delay = 0; - byte sprcolor = COLOR_DARK_BLUE; - - for(;;) { - for(delay=0; delay<800; delay++) { - delay = delay+1; - delay = delay-1; - } - - if(apple1_readkey()==0x0d) break; - - if(x>=228 || x<=0) { dx = -dx; sprcolor++; } - if(y>=148 || y<=0) { dy = -dy; sprcolor++; } - - x += dx; - y += dy; - move_balloon((byte)x,(byte)y, sprcolor); - } } diff --git a/lib/c64.ascii.txt b/lib/c64.ascii.txt new file mode 100644 index 0000000..e69de29 diff --git a/lib/c64font.h b/lib/c64font.h new file mode 100644 index 0000000..ec3c798 --- /dev/null +++ b/lib/c64font.h @@ -0,0 +1,874 @@ +#ifndef FONT8X8_H +#define FONT8X8_H + +// C64 FONTS translated into ASCII + +#pragma data_seg(Code) + +byte FONT[768] = { +// char $120 + 0b00000000 + , 0b00000000 + , 0b00000000 + , 0b00000000 + , 0b00000000 + , 0b00000000 + , 0b00000000 + , 0b00000000 +// char $121 + , 0b00011000 + , 0b00011000 + , 0b00011000 + , 0b00011000 + , 0b00000000 + , 0b00000000 + , 0b00011000 + , 0b00000000 +// char $122 + , 0b01100110 + , 0b01100110 + , 0b01100110 + , 0b00000000 + , 0b00000000 + , 0b00000000 + , 0b00000000 + , 0b00000000 +// char $123 + , 0b01100110 + , 0b01100110 + , 0b11111111 + , 0b01100110 + , 0b11111111 + , 0b01100110 + , 0b01100110 + , 0b00000000 +// char $124 + , 0b00011000 + , 0b00111110 + , 0b01100000 + , 0b00111100 + , 0b00000110 + , 0b01111100 + , 0b00011000 + , 0b00000000 +// char $125 + , 0b01100010 + , 0b01100110 + , 0b00001100 + , 0b00011000 + , 0b00110000 + , 0b01100110 + , 0b01000110 + , 0b00000000 +// char $126 + , 0b00111100 + , 0b01100110 + , 0b00111100 + , 0b00111000 + , 0b01100111 + , 0b01100110 + , 0b00111111 + , 0b00000000 +// char $127 + , 0b00000110 + , 0b00001100 + , 0b00011000 + , 0b00000000 + , 0b00000000 + , 0b00000000 + , 0b00000000 + , 0b00000000 +// char $128 + , 0b00001100 + , 0b00011000 + , 0b00110000 + , 0b00110000 + , 0b00110000 + , 0b00011000 + , 0b00001100 + , 0b00000000 +// char $129 + , 0b00110000 + , 0b00011000 + , 0b00001100 + , 0b00001100 + , 0b00001100 + , 0b00011000 + , 0b00110000 + , 0b00000000 +// char $12a + , 0b00000000 + , 0b01100110 + , 0b00111100 + , 0b11111111 + , 0b00111100 + , 0b01100110 + , 0b00000000 + , 0b00000000 +// char $12b + , 0b00000000 + , 0b00011000 + , 0b00011000 + , 0b01111110 + , 0b00011000 + , 0b00011000 + , 0b00000000 + , 0b00000000 +// char $12c + , 0b00000000 + , 0b00000000 + , 0b00000000 + , 0b00000000 + , 0b00000000 + , 0b00011000 + , 0b00011000 + , 0b00110000 +// char $12d + , 0b00000000 + , 0b00000000 + , 0b00000000 + , 0b01111110 + , 0b00000000 + , 0b00000000 + , 0b00000000 + , 0b00000000 +// char $12e + , 0b00000000 + , 0b00000000 + , 0b00000000 + , 0b00000000 + , 0b00000000 + , 0b00011000 + , 0b00011000 + , 0b00000000 +// char $12f + , 0b00000000 + , 0b00000011 + , 0b00000110 + , 0b00001100 + , 0b00011000 + , 0b00110000 + , 0b01100000 + , 0b00000000 +// char $130 + , 0b00111100 + , 0b01100110 + , 0b01101110 + , 0b01110110 + , 0b01100110 + , 0b01100110 + , 0b00111100 + , 0b00000000 +// char $131 + , 0b00011000 + , 0b00011000 + , 0b00111000 + , 0b00011000 + , 0b00011000 + , 0b00011000 + , 0b01111110 + , 0b00000000 +// char $132 + , 0b00111100 + , 0b01100110 + , 0b00000110 + , 0b00001100 + , 0b00110000 + , 0b01100000 + , 0b01111110 + , 0b00000000 +// char $133 + , 0b00111100 + , 0b01100110 + , 0b00000110 + , 0b00011100 + , 0b00000110 + , 0b01100110 + , 0b00111100 + , 0b00000000 +// char $134 + , 0b00000110 + , 0b00001110 + , 0b00011110 + , 0b01100110 + , 0b01111111 + , 0b00000110 + , 0b00000110 + , 0b00000000 +// char $135 + , 0b01111110 + , 0b01100000 + , 0b01111100 + , 0b00000110 + , 0b00000110 + , 0b01100110 + , 0b00111100 + , 0b00000000 +// char $136 + , 0b00111100 + , 0b01100110 + , 0b01100000 + , 0b01111100 + , 0b01100110 + , 0b01100110 + , 0b00111100 + , 0b00000000 +// char $137 + , 0b01111110 + , 0b01100110 + , 0b00001100 + , 0b00011000 + , 0b00011000 + , 0b00011000 + , 0b00011000 + , 0b00000000 +// char $138 + , 0b00111100 + , 0b01100110 + , 0b01100110 + , 0b00111100 + , 0b01100110 + , 0b01100110 + , 0b00111100 + , 0b00000000 +// char $139 + , 0b00111100 + , 0b01100110 + , 0b01100110 + , 0b00111110 + , 0b00000110 + , 0b01100110 + , 0b00111100 + , 0b00000000 +// char $13a + , 0b00000000 + , 0b00000000 + , 0b00011000 + , 0b00000000 + , 0b00000000 + , 0b00011000 + , 0b00000000 + , 0b00000000 +// char $13b + , 0b00000000 + , 0b00000000 + , 0b00011000 + , 0b00000000 + , 0b00000000 + , 0b00011000 + , 0b00011000 + , 0b00110000 +// char $13c + , 0b00001110 + , 0b00011000 + , 0b00110000 + , 0b01100000 + , 0b00110000 + , 0b00011000 + , 0b00001110 + , 0b00000000 +// char $13d + , 0b00000000 + , 0b00000000 + , 0b01111110 + , 0b00000000 + , 0b01111110 + , 0b00000000 + , 0b00000000 + , 0b00000000 +// char $13e + , 0b01110000 + , 0b00011000 + , 0b00001100 + , 0b00000110 + , 0b00001100 + , 0b00011000 + , 0b01110000 + , 0b00000000 +// char $13f + , 0b00111100 + , 0b01100110 + , 0b00000110 + , 0b00001100 + , 0b00011000 + , 0b00000000 + , 0b00011000 + , 0b00000000 +// char $100 + , 0b00111100 + , 0b01100110 + , 0b01101110 + , 0b01101110 + , 0b01100000 + , 0b01100010 + , 0b00111100 + , 0b00000000 +// char $141 + , 0b00011000 + , 0b00111100 + , 0b01100110 + , 0b01111110 + , 0b01100110 + , 0b01100110 + , 0b01100110 + , 0b00000000 +// char $142 + , 0b01111100 + , 0b01100110 + , 0b01100110 + , 0b01111100 + , 0b01100110 + , 0b01100110 + , 0b01111100 + , 0b00000000 +// char $143 + , 0b00111100 + , 0b01100110 + , 0b01100000 + , 0b01100000 + , 0b01100000 + , 0b01100110 + , 0b00111100 + , 0b00000000 +// char $144 + , 0b01111000 + , 0b01101100 + , 0b01100110 + , 0b01100110 + , 0b01100110 + , 0b01101100 + , 0b01111000 + , 0b00000000 +// char $145 + , 0b01111110 + , 0b01100000 + , 0b01100000 + , 0b01111000 + , 0b01100000 + , 0b01100000 + , 0b01111110 + , 0b00000000 +// char $146 + , 0b01111110 + , 0b01100000 + , 0b01100000 + , 0b01111000 + , 0b01100000 + , 0b01100000 + , 0b01100000 + , 0b00000000 +// char $147 + , 0b00111100 + , 0b01100110 + , 0b01100000 + , 0b01101110 + , 0b01100110 + , 0b01100110 + , 0b00111100 + , 0b00000000 +// char $148 + , 0b01100110 + , 0b01100110 + , 0b01100110 + , 0b01111110 + , 0b01100110 + , 0b01100110 + , 0b01100110 + , 0b00000000 +// char $149 + , 0b00111100 + , 0b00011000 + , 0b00011000 + , 0b00011000 + , 0b00011000 + , 0b00011000 + , 0b00111100 + , 0b00000000 +// char $14a + , 0b00011110 + , 0b00001100 + , 0b00001100 + , 0b00001100 + , 0b00001100 + , 0b01101100 + , 0b00111000 + , 0b00000000 +// char $14b + , 0b01100110 + , 0b01101100 + , 0b01111000 + , 0b01110000 + , 0b01111000 + , 0b01101100 + , 0b01100110 + , 0b00000000 +// char $14c + , 0b01100000 + , 0b01100000 + , 0b01100000 + , 0b01100000 + , 0b01100000 + , 0b01100000 + , 0b01111110 + , 0b00000000 +// char $14d + , 0b01100011 + , 0b01110111 + , 0b01111111 + , 0b01101011 + , 0b01100011 + , 0b01100011 + , 0b01100011 + , 0b00000000 +// char $14e + , 0b01100110 + , 0b01110110 + , 0b01111110 + , 0b01111110 + , 0b01101110 + , 0b01100110 + , 0b01100110 + , 0b00000000 +// char $14f + , 0b00111100 + , 0b01100110 + , 0b01100110 + , 0b01100110 + , 0b01100110 + , 0b01100110 + , 0b00111100 + , 0b00000000 +// char $150 + , 0b01111100 + , 0b01100110 + , 0b01100110 + , 0b01111100 + , 0b01100000 + , 0b01100000 + , 0b01100000 + , 0b00000000 +// char $151 + , 0b00111100 + , 0b01100110 + , 0b01100110 + , 0b01100110 + , 0b01100110 + , 0b00111100 + , 0b00001110 + , 0b00000000 +// char $152 + , 0b01111100 + , 0b01100110 + , 0b01100110 + , 0b01111100 + , 0b01111000 + , 0b01101100 + , 0b01100110 + , 0b00000000 +// char $153 + , 0b00111100 + , 0b01100110 + , 0b01100000 + , 0b00111100 + , 0b00000110 + , 0b01100110 + , 0b00111100 + , 0b00000000 +// char $154 + , 0b01111110 + , 0b00011000 + , 0b00011000 + , 0b00011000 + , 0b00011000 + , 0b00011000 + , 0b00011000 + , 0b00000000 +// char $155 + , 0b01100110 + , 0b01100110 + , 0b01100110 + , 0b01100110 + , 0b01100110 + , 0b01100110 + , 0b00111100 + , 0b00000000 +// char $156 + , 0b01100110 + , 0b01100110 + , 0b01100110 + , 0b01100110 + , 0b01100110 + , 0b00111100 + , 0b00011000 + , 0b00000000 +// char $157 + , 0b01100011 + , 0b01100011 + , 0b01100011 + , 0b01101011 + , 0b01111111 + , 0b01110111 + , 0b01100011 + , 0b00000000 +// char $158 + , 0b01100110 + , 0b01100110 + , 0b00111100 + , 0b00011000 + , 0b00111100 + , 0b01100110 + , 0b01100110 + , 0b00000000 +// char $159 + , 0b01100110 + , 0b01100110 + , 0b01100110 + , 0b00111100 + , 0b00011000 + , 0b00011000 + , 0b00011000 + , 0b00000000 +// char $15a + , 0b01111110 + , 0b00000110 + , 0b00001100 + , 0b00011000 + , 0b00110000 + , 0b01100000 + , 0b01111110 + , 0b00000000 +// char $11b + , 0b00111100 + , 0b00110000 + , 0b00110000 + , 0b00110000 + , 0b00110000 + , 0b00110000 + , 0b00111100 + , 0b00000000 +// char $11c + , 0b00001100 + , 0b00010010 + , 0b00110000 + , 0b01111100 + , 0b00110000 + , 0b01100010 + , 0b11111100 + , 0b00000000 +// char $11d + , 0b00111100 + , 0b00001100 + , 0b00001100 + , 0b00001100 + , 0b00001100 + , 0b00001100 + , 0b00111100 + , 0b00000000 +// char $11e + , 0b00000000 + , 0b00011000 + , 0b00111100 + , 0b01111110 + , 0b00011000 + , 0b00011000 + , 0b00011000 + , 0b00011000 +// char $11f + , 0b00000000 + , 0b00010000 + , 0b00110000 + , 0b01111111 + , 0b01111111 + , 0b00110000 + , 0b00010000 + , 0b00000000 +// char $140 + , 0b00000000 + , 0b00000000 + , 0b00000000 + , 0b11111111 + , 0b11111111 + , 0b00000000 + , 0b00000000 + , 0b00000000 +// char $101 + , 0b00000000 + , 0b00000000 + , 0b00111100 + , 0b00000110 + , 0b00111110 + , 0b01100110 + , 0b00111110 + , 0b00000000 +// char $102 + , 0b00000000 + , 0b01100000 + , 0b01100000 + , 0b01111100 + , 0b01100110 + , 0b01100110 + , 0b01111100 + , 0b00000000 +// char $103 + , 0b00000000 + , 0b00000000 + , 0b00111100 + , 0b01100000 + , 0b01100000 + , 0b01100000 + , 0b00111100 + , 0b00000000 +// char $104 + , 0b00000000 + , 0b00000110 + , 0b00000110 + , 0b00111110 + , 0b01100110 + , 0b01100110 + , 0b00111110 + , 0b00000000 +// char $105 + , 0b00000000 + , 0b00000000 + , 0b00111100 + , 0b01100110 + , 0b01111110 + , 0b01100000 + , 0b00111100 + , 0b00000000 +// char $106 + , 0b00000000 + , 0b00001110 + , 0b00011000 + , 0b00111110 + , 0b00011000 + , 0b00011000 + , 0b00011000 + , 0b00000000 +// char $107 + , 0b00000000 + , 0b00000000 + , 0b00111110 + , 0b01100110 + , 0b01100110 + , 0b00111110 + , 0b00000110 + , 0b01111100 +// char $108 + , 0b00000000 + , 0b01100000 + , 0b01100000 + , 0b01111100 + , 0b01100110 + , 0b01100110 + , 0b01100110 + , 0b00000000 +// char $109 + , 0b00000000 + , 0b00011000 + , 0b00000000 + , 0b00111000 + , 0b00011000 + , 0b00011000 + , 0b00111100 + , 0b00000000 +// char $10a + , 0b00000000 + , 0b00000110 + , 0b00000000 + , 0b00000110 + , 0b00000110 + , 0b00000110 + , 0b00000110 + , 0b00111100 +// char $10b + , 0b00000000 + , 0b01100000 + , 0b01100000 + , 0b01101100 + , 0b01111000 + , 0b01101100 + , 0b01100110 + , 0b00000000 +// char $10c + , 0b00000000 + , 0b00111000 + , 0b00011000 + , 0b00011000 + , 0b00011000 + , 0b00011000 + , 0b00111100 + , 0b00000000 +// char $10d + , 0b00000000 + , 0b00000000 + , 0b01100110 + , 0b01111111 + , 0b01111111 + , 0b01101011 + , 0b01100011 + , 0b00000000 +// char $10e + , 0b00000000 + , 0b00000000 + , 0b01111100 + , 0b01100110 + , 0b01100110 + , 0b01100110 + , 0b01100110 + , 0b00000000 +// char $10f + , 0b00000000 + , 0b00000000 + , 0b00111100 + , 0b01100110 + , 0b01100110 + , 0b01100110 + , 0b00111100 + , 0b00000000 +// char $110 + , 0b00000000 + , 0b00000000 + , 0b01111100 + , 0b01100110 + , 0b01100110 + , 0b01111100 + , 0b01100000 + , 0b01100000 +// char $111 + , 0b00000000 + , 0b00000000 + , 0b00111110 + , 0b01100110 + , 0b01100110 + , 0b00111110 + , 0b00000110 + , 0b00000110 +// char $112 + , 0b00000000 + , 0b00000000 + , 0b01111100 + , 0b01100110 + , 0b01100000 + , 0b01100000 + , 0b01100000 + , 0b00000000 +// char $113 + , 0b00000000 + , 0b00000000 + , 0b00111110 + , 0b01100000 + , 0b00111100 + , 0b00000110 + , 0b01111100 + , 0b00000000 +// char $114 + , 0b00000000 + , 0b00011000 + , 0b01111110 + , 0b00011000 + , 0b00011000 + , 0b00011000 + , 0b00001110 + , 0b00000000 +// char $115 + , 0b00000000 + , 0b00000000 + , 0b01100110 + , 0b01100110 + , 0b01100110 + , 0b01100110 + , 0b00111110 + , 0b00000000 +// char $116 + , 0b00000000 + , 0b00000000 + , 0b01100110 + , 0b01100110 + , 0b01100110 + , 0b00111100 + , 0b00011000 + , 0b00000000 +// char $117 + , 0b00000000 + , 0b00000000 + , 0b01100011 + , 0b01101011 + , 0b01111111 + , 0b00111110 + , 0b00110110 + , 0b00000000 +// char $118 + , 0b00000000 + , 0b00000000 + , 0b01100110 + , 0b00111100 + , 0b00011000 + , 0b00111100 + , 0b01100110 + , 0b00000000 +// char $119 + , 0b00000000 + , 0b00000000 + , 0b01100110 + , 0b01100110 + , 0b01100110 + , 0b00111110 + , 0b00001100 + , 0b01111000 +// char $11a + , 0b00000000 + , 0b00000000 + , 0b01111110 + , 0b00001100 + , 0b00011000 + , 0b00110000 + , 0b01111110 + , 0b00000000 +// char $15b + , 0b00011000 + , 0b00011000 + , 0b00011000 + , 0b11111111 + , 0b11111111 + , 0b00011000 + , 0b00011000 + , 0b00011000 +// char $15c + , 0b11000000 + , 0b11000000 + , 0b00110000 + , 0b00110000 + , 0b11000000 + , 0b11000000 + , 0b00110000 + , 0b00110000 +// char $15d + , 0b00011000 + , 0b00011000 + , 0b00011000 + , 0b00011000 + , 0b00011000 + , 0b00011000 + , 0b00011000 + , 0b00011000 +// char $15e + , 0b00110011 + , 0b00110011 + , 0b11001100 + , 0b11001100 + , 0b00110011 + , 0b00110011 + , 0b11001100 + , 0b11001100 +// char $15f + , 0b00110011 + , 0b10011001 + , 0b11001100 + , 0b01100110 + , 0b00110011 + , 0b10011001 + , 0b11001100 + , 0b01100110 +}; + diff --git a/lib/tms9918.h b/lib/tms9918.h index fa03a90..24a003b 100644 --- a/lib/tms9918.h +++ b/lib/tms9918.h @@ -174,7 +174,8 @@ void tms_copy_to_vram(byte *source, word size, word dest) { } #include "apple1.h" -#include "font8x8.h" +//#include "font8x8.h" +#include "c64font.h" #include "sprites.h" #include "screen1.h" #include "screen2.h" From 75b96830b48d1b4f0e620a7516f99ca302ed4258 Mon Sep 17 00:00:00 2001 From: nino-porcino Date: Mon, 27 Dec 2021 13:11:52 +0100 Subject: [PATCH 3/5] improve sprites and balloon demo --- demos/demo/demo_balloon.h | 144 +++++++++++++++++++++++++++++--------- demos/demo/demo_screen2.h | 20 +----- lib/screen1.h | 6 +- lib/screen2.h | 4 +- lib/sprites.h | 30 ++++---- 5 files changed, 128 insertions(+), 76 deletions(-) diff --git a/demos/demo/demo_balloon.h b/demos/demo/demo_balloon.h index e30d95d..e82a8f5 100644 --- a/demos/demo/demo_balloon.h +++ b/demos/demo/demo_balloon.h @@ -1,62 +1,136 @@ #include +// the balloon sprite, manually copied from C64 User's guide #include "cbm_balloon.h" -void move_balloon(byte x, byte y, byte color) { - tms_sprite spr0,spr1; - spr0.x = x; - spr0.y = y; - spr0.name = 0; - spr0.color = color; - spr1.x = spr0.x; - spr1.y = spr0.y + 16*1; - spr1.name = spr0.name + 4; - spr1.color = spr0.color; - tms_set_sprite(0, &spr0); - tms_set_sprite(1, &spr1); +// a balloon is two 16x16 sprites, one above the other +typedef struct { + int x; // x coordinate of the balloon + int y; // y coordinate of the balloon + int dx; // x velocity of the balloon + int dy; // y velocity of the balloon + byte color; // color of the balloon + byte sprite_number; // sprite number (0-31) of the balloon + tms_sprite upper; // the upper sprite portion of the balloon + tms_sprite lower; // the lower sprite portion of the balloon +} balloon; + +// move ballon on the screen by its velocity +// and make it bounce over the borders +void animate_balloon(balloon *b) { + + // use temporary variables as KickC has issues dealing with "->" operator + int x = b->x; + int y = b->y; + int dx = b->dx; + int dy = b->dy; + + // border collision detection + if(x>=240 || x<=0) dx = -dx; + if(y>=172 || y<=0) dy = -dy; + + // move the balloon + x += dx; + y += dy; + + // write back temporary variables + b->x = x; + b->y = y; + b->dx = dx; + b->dy = dy; + + // update the sprite part of the balloon + b->upper.x = (byte) x; + b->upper.y = (signed char) y; + b->upper.name = 0; + b->upper.color = b->color; + b->lower.x = b->upper.x; + b->lower.y = b->upper.y + 16; // 16 pixels below the upper sprite + b->lower.name = b->upper.name + 4; + b->lower.color = b->color; + tms_set_sprite(b->sprite_number, &(b->upper)); + tms_set_sprite(b->sprite_number+1, &(b->lower)); } void demo_balloon() { tms_init_regs(SCREEN2_TABLE); - tms_set_color(COLOR_LIGHT_BLUE); - byte text_color = FG_BG(COLOR_GREY,COLOR_DARK_BLUE); + // we use only 4 sprites, two for each ot the two balloons on the screen + tms_set_total_sprites(4); + + // fake C64 bootup screen colors + tms_set_color(COLOR_LIGHT_BLUE); + byte text_color = FG_BG(COLOR_GREY,COLOR_DARK_BLUE); // alas, COLOR_LIGHT_BLUE doesn't fit well so we use GREY instead screen2_init_bitmap(text_color); - // 12345678901234567890123456789012 + + // C64-like screen text screen2_puts("*** COMMODORE-APPLE BASIC V2 ***", 0, 0, text_color); screen2_puts("38911 BASIC BYTES FREE" , 0, 2, text_color); screen2_puts("READY." , 0, 4, text_color); - screen2_puts(" " , 0, 5, FG_BG(COLOR_DARK_BLUE,COLOR_GREY)); - - // ballon demo - - // define sprites using bitmap fonts + + // copy the ballon graphic to VRAM tms_copy_to_vram(cbm_balloon, 4*8*2, TMS_SPRITE_PATTERNS); - tms_set_sprite_double_size(1); // set 16x16 sprites - tms_set_sprite_magnification(0); // set double pixel sprites - int x = 200; - int y = 80; - int dx = 1; - int dy = 1; - int delay = 0; - byte sprcolor = COLOR_LIGHT_YELLOW; + tms_set_sprite_double_size(1); // set 16x16 sprites + tms_set_sprite_magnification(0); // set single pixel sprites + + // we have two balloons bouncing around the screen + + // first balloon + balloon b1; + b1.x = 20; + b1.y = 20; + b1.dx = 1; + b1.dy = 1; + b1.color = COLOR_LIGHT_YELLOW; + b1.sprite_number = 0; + + // second balloon + balloon b2; + b2.x = 150; + b2.y = 150; + b2.dx = -1; + b2.dy = -1; + b2.color = COLOR_LIGHT_RED; + b2.sprite_number = 2; + + // counter for a fake blinking cursor + byte blink_counter=0; for(;;) { - for(delay=0; delay<800; delay++) { + + // delay the animation + for(int delay=0; delay<400; delay++) { delay = delay+1; delay = delay-1; } + // RETURN key ends the demo if(apple1_readkey()==0x0d) break; - - if(x>=228 || x<=0) { dx = -dx; sprcolor++; } - if(y>=148 || y<=0) { dy = -dy; sprcolor++; } - x += dx; - y += dy; - move_balloon((byte)x,(byte)y, COLOR_WHITE); + // if there's a collision invert the motion of the balloons + if(COLLISION_BIT(TMS_READ_CTRL_PORT)) { + int temp; + temp = b1.dx; b1.dx = -temp; // b1.dx = -b1.dx; // due to KickC issue + temp = b1.dy; b1.dy = -temp; // b1.dy = -b1.dy; // due to KickC issue + temp = b2.dx; b2.dx = -temp; // b2.dx = -b2.dx; // due to KickC issue + temp = b2.dy; b2.dy = -temp; // b2.dy = -b2.dy; // due to KickC issue + } + + // move the two balloons + animate_balloon(&b1); + animate_balloon(&b2); + + // since a balloon is made of two sprites, sometimes they overlap + // by one line during the move, causing a false collision + // so we clear the collision bit by simply reading the status register + tms_clear_collisions(); + + // fake a blinking cursor + blink_counter++; + if(blink_counter == 16) { screen2_puts(" ", 0, 5, FG_BG(COLOR_DARK_BLUE,COLOR_GREY)); } + if(blink_counter == 32) { screen2_puts(" ", 0, 5, FG_BG(COLOR_GREY,COLOR_DARK_BLUE)); blink_counter = 0; } } } diff --git a/demos/demo/demo_screen2.h b/demos/demo/demo_screen2.h index 38df09a..e2f7f95 100644 --- a/demos/demo/demo_screen2.h +++ b/demos/demo/demo_screen2.h @@ -28,24 +28,6 @@ void demo_screen2() { screen2_line(18+5+5, 45,232+5+5,187); screen2_line(18+5+5,187,232+5+5, 45); - screen2_plot_mode = PLOT_MODE_SET; - - // define sprites using bitmap fonts - tms_copy_to_vram(&FONT[64*8], 32*8, TMS_SPRITE_PATTERNS); - - // set 16x16 sprites - tms_set_sprite_double_size(1); - - // set double pixel sprites - tms_set_sprite_magnification(1); - - tms_sprite spr; - for(byte t=0;t<4;t++) { - spr.x = 200; - spr.y = 5 + t*32; - spr.name = t*4; - spr.color = t+1; - tms_set_sprite(t, &spr); - } + screen2_plot_mode = PLOT_MODE_SET; } diff --git a/lib/screen1.h b/lib/screen1.h index 133e561..9f0ffe4 100644 --- a/lib/screen1.h +++ b/lib/screen1.h @@ -48,12 +48,12 @@ void screen1_scroll_up() { } void screen1_prepare() { + // clear all the sprites + tms_set_total_sprites(0); + // fill name table with spaces (32) screen1_cls(); - // clear all the sprites - tms_clear_sprites(); - // fill pattern table with 0 tms_set_vram_write_addr(TMS_PATTERN_TABLE); for(word i=256*8;i!=0;i--) { diff --git a/lib/screen2.h b/lib/screen2.h index 6c3e858..d44a544 100644 --- a/lib/screen2.h +++ b/lib/screen2.h @@ -10,8 +10,8 @@ const word SCREEN2_SIZE = (32*24); // prepare the screen 2 to be used as a bitmap void screen2_init_bitmap(byte color) { - // erases all the sprites - tms_clear_sprites(); + // clear all the sprites + tms_set_total_sprites(0); // fill pattern table with 0 (clear screen) tms_set_vram_write_addr(TMS_PATTERN_TABLE); diff --git a/lib/sprites.h b/lib/sprites.h index 44fe62e..822c836 100644 --- a/lib/sprites.h +++ b/lib/sprites.h @@ -2,13 +2,22 @@ #define SPRITES_H typedef struct { - byte y; + signed char y; byte x; byte name; byte color; } tms_sprite; #define SIZEOF_SPRITE 4 +#define SPRITE_OFF_MARKER 0xD0 +#define EARLY_CLOCK 128 + +void tms_set_total_sprites(byte num) { + // write the value 0xD0 as Y coordinate of the first unused sprite + word addr = TMS_SPRITE_ATTRS + (word) (num * SIZEOF_SPRITE); + tms_set_vram_write_addr(addr); + TMS_WRITE_DATA_PORT(SPRITE_OFF_MARKER); // 0xD0 oi the sprite off indicator +} void tms_set_sprite(byte sprite_num, tms_sprite *s) { word addr = TMS_SPRITE_ATTRS + (word) (sprite_num * SIZEOF_SPRITE); @@ -34,21 +43,8 @@ void tms_set_sprite_magnification(byte m) { tms_write_reg(1, regval); } -// clears all the sprites -void tms_clear_sprites() { - // fills first sprite pattern with 0 - tms_set_vram_write_addr(TMS_SPRITE_PATTERNS); - for(byte i=0;i<8;i++) { - TMS_WRITE_DATA_PORT(0); - } - - // set sprite coordinates to (0,0) and set pattern name 0 - tms_set_vram_write_addr(TMS_SPRITE_ATTRS); - for(byte i=0;i<32;i++) { - TMS_WRITE_DATA_PORT(0); NOP; NOP; NOP; NOP; // y coordinate - TMS_WRITE_DATA_PORT(0); NOP; NOP; NOP; NOP; // x coordinate - TMS_WRITE_DATA_PORT(0); NOP; NOP; NOP; NOP; // name - TMS_WRITE_DATA_PORT(0); NOP; NOP; NOP; NOP; // color - } +// clear the collision flag by reading the status register +inline void tms_clear_collisions() { + asm { lda VDP_REG }; } #endif From 4dbe63d74b95f2b7a72d5bf46b513c70cd9c7f47 Mon Sep 17 00:00:00 2001 From: nino-porcino Date: Sat, 1 Jan 2022 11:18:19 +0100 Subject: [PATCH 4/5] initialize eprom only if jukebox card --- demos/demo/demo.c | 2 +- demos/picshow/picshow.c | 2 +- demos/tetris/tetris.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/demos/demo/demo.c b/demos/demo/demo.c index 29d0329..74d8c05 100644 --- a/demos/demo/demo.c +++ b/demos/demo/demo.c @@ -28,7 +28,7 @@ void help() { void main() { -#ifdef APPLE1 +#ifdef APPLE1_JUKEBOX apple1_eprom_init(); #endif diff --git a/demos/picshow/picshow.c b/demos/picshow/picshow.c index dc0011e..8e9e63c 100644 --- a/demos/picshow/picshow.c +++ b/demos/picshow/picshow.c @@ -10,7 +10,7 @@ void main() { -#ifdef APPLE1 +#ifdef APPLE1_JUKEBOX apple1_eprom_init(); #endif diff --git a/demos/tetris/tetris.c b/demos/tetris/tetris.c index 0988b74..6e14652 100644 --- a/demos/tetris/tetris.c +++ b/demos/tetris/tetris.c @@ -326,7 +326,7 @@ void main() { // install the start-of-frame interrupt detection //install_interrupt(); -#ifdef APPLE1 +#ifdef APPLE1_JUKEBOX apple1_eprom_init(); #endif From 704ee9e3d5c9da7fd30c6db38bc43bf250b9c6c9 Mon Sep 17 00:00:00 2001 From: nino-porcino Date: Sat, 1 Jan 2022 11:19:16 +0100 Subject: [PATCH 5/5] add standard memory model for apple1 --- tools/build.bat | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tools/build.bat b/tools/build.bat index 6bc21b3..9599932 100644 --- a/tools/build.bat +++ b/tools/build.bat @@ -7,12 +7,14 @@ call kickc -includedir %TMS9918%\lib -targetdir %TMS9918%\kickc\ -t vic20_8k %TARGET%.c -o out\%TARGET%_vic20.prg -e copy out\%TARGET%.prg out\%TARGET%_vic20.prg -@echo ======================== APPLE 1 ================================================= +@echo ======================== APPLE 1 JUKEBOX ================================================= call kickc -includedir %TMS9918%\lib -targetdir %TMS9918%\kickc\ -t apple1_jukebox %TARGET%.c -o out\%TARGET%_apple1.prg -e - -@rem builds the apple1 eprom file call node %TMS9918%\tools\mkeprom out out\%TARGET%_apple1.bin +@echo ======================== APPLE 1 JUKEBOX ================================================= +call kickc -includedir %TMS9918%\lib -targetdir %TMS9918%\kickc\ -t apple1 %TARGET%.c -o out\%TARGET%_apple1.prg -e +copy out\%TARGET%.prg out\%TARGET%_apple1.prg + @rem clean up files @del out\apple1_codeseg.bin @del out\apple1_dataseg.bin