From 1d1512453d8cf62cfa048baa7ba73fc68ff2ac2e Mon Sep 17 00:00:00 2001 From: Steven Hugg Date: Thu, 29 Nov 2018 18:55:20 -0500 Subject: [PATCH] coleco: update presets, stars.c; __MAIN__ define for main file --- presets/coleco/climber.c | 10 ++-- presets/coleco/common.h | 1 - presets/coleco/shoot.c | 35 +++++++----- presets/coleco/siegegame.c | 4 ++ presets/coleco/stars.c | 107 ++++++++++++++----------------------- presets/coleco/stars.h | 6 +++ src/worker/workermain.ts | 4 +- 7 files changed, 79 insertions(+), 88 deletions(-) create mode 100644 presets/coleco/stars.h diff --git a/presets/coleco/climber.c b/presets/coleco/climber.c index f7130f4d..9b7d52cf 100644 --- a/presets/coleco/climber.c +++ b/presets/coleco/climber.c @@ -10,12 +10,14 @@ #define XOFS 12 // sprite horiz. offset +#define BGCOL CV_COLOR_BLUE + #define CH_BORDER 64 #define CH_FLOOR 65 #define CH_LADDER 66 const byte char_table[8][8] = { - /*{w:8,h:8,count:8}*/ + /*{w:8,h:8,brev:1,count:8}*/ {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}, {0xFF,0xBF,0xBF,0x00,0xFF,0xFB,0xFB,0x00}, {0x81,0xFF,0x81,0x81,0x81,0xFF,0x81,0x81}, @@ -27,7 +29,7 @@ const byte char_table[8][8] = { }; const byte static_sprite_table[2][16*2] = { - /*{w:16,h:16,remap:[-5,0,1,2,3,5,6,7,8,9],count:4}*/ + /*{w:16,h:16,brev:1,remap:[4,0,1,2,3,5,6,7,8,9],count:4}*/ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x02, 0x3F, 0x35, 0x2A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x3F, @@ -126,10 +128,6 @@ const byte sprite_table[NUM_SPRITE_PATTERNS*2][16*2] = { /// -#define BGCOL CV_COLOR_BLUE - -/// - typedef struct Level { byte ypos; byte height; // TODO: why does bitmask not work? diff --git a/presets/coleco/common.h b/presets/coleco/common.h index cfe28f59..bbdb2125 100644 --- a/presets/coleco/common.h +++ b/presets/coleco/common.h @@ -41,7 +41,6 @@ extern char font_bitmap_0[]; #define wait_vsync() __asm__("halt") -extern volatile bool vint; extern volatile uint_fast8_t vint_counter; extern void vint_handler(void); diff --git a/presets/coleco/shoot.c b/presets/coleco/shoot.c index 4aa83575..d1fac1a7 100644 --- a/presets/coleco/shoot.c +++ b/presets/coleco/shoot.c @@ -7,18 +7,25 @@ #include "common.h" //#link "common.c" +#include "stars.h" +//#link "stars.c" + +#ifdef CV_SMS +//#link "fonts.s" +#endif + #define NSPRITES 16 #define NMISSILES 8 #define YOFFSCREEN 239 static byte pattern_table[8*2] = { - /*{w:16,h:8,remap:[3,0,1,2]}*/ + /*{w:16,h:8,brev:1,remap:[-4,0,1,2]}*/ 0xCC, 0xF2, 0xD0, 0xFC, 0xF3, 0xE8, 0xC4, 0x03, 0x0C, 0x13, 0x02, 0x0F, 0x33, 0x05, 0x08, 0x30, }; static byte sprite_table[][16*2] = { - /*{w:16,h:16,remap:[-5,0,1,2,3,5,6,7,8,9],count:15}*/ + /*{w:16,h:16,brev:1,remap:[4,0,1,2,3,5,6,7,8,9],count:15}*/ { 0x01, 0x03, 0x02, 0x01, 0x01, 0x01, 0x01, 0x01, 0x03, 0x86, 0xCD, 0xBE, 0x9F, 0xB1, 0xC0, 0x80, @@ -205,30 +212,28 @@ void setup_formation() { #define BLANK 0 void draw_row(byte row) { - byte i; + byte i,j; byte x = formation_offset_x / 8; byte xd = (formation_offset_x & 7) * 3; byte y = 3 + row * 2; - //vcolumns[y].attrib = 0x2; - //vcolumns[y].scroll = formation_offset_x; for (i=0; i -#include #include #include -#define PATTERN ((const cv_vmemp)0x0000) -#define COLOR ((const cv_vmemp)0x2000) -#define IMAGE ((const cv_vmemp)0x1c00) +#include "common.h" -volatile bool vint; -volatile uint_fast8_t vint_counter; -uint_fast8_t oldcounter; +char starfield_base_char = 240; -void vint_handler(void) -{ - vint = true; - vint_counter++; +const char star_yoffsets[32] = { + 31, 11, 25, 10, 21, 1, 9, 6, + 22, 3, 7, 14, 15, 18, 0, 29, + 30, 5, 16, 28, 20, 12, 24, 17, + 13, 8, 26, 19, 23, 27, 2, 4 +}; + +byte starfield_get_tile_xy(byte x, byte y) { + return ((star_yoffsets[x] + y) & 15) + starfield_base_char; } -void update_stars(void) -{ - uint_fast8_t j; - uint_fast8_t tmp = vint_counter; - tmp %= (16 * 8); - - for(j = 0; j < 3; j++) - { - cvu_voutb(0x00, PATTERN + j * 256 * 8 + oldcounter); - cvu_voutb(0x10, PATTERN + j * 256 * 8 + tmp); - } - - oldcounter = tmp; +void starfield_setup() { + for (byte x=0; x<32; x++) { + for (byte y=0; y<28; y++) { + putchar(x, y, starfield_get_tile_xy(x, y)); + } + cvu_voutb(COLOR_FG(CV_COLOR_WHITE), + COLOR+((starfield_base_char+x)>>3)); + } } -void init_stars(void) -{ - uint_fast8_t i, j, r; - - for(j = 0; j < 32; j += rand() % 2) - { - r = rand() % 16; - for(i = 0; i < 24; i++) - { - cvu_voutb(r++, IMAGE + j + i * 32); - r %= 16; - } - } - - for(j = 0; j < 3; j++) - cvu_vmemset(COLOR + j * 256 * 8, (CV_COLOR_WHITE << 4) | CV_COLOR_BLACK, 16 * 8); - - cvu_voutb(0x10, PATTERN); - oldcounter = 0; - vint_counter = 0; +void starfield_update() { + static byte oldcounter; + const byte mask = 0x7f; // 128 star bytes + byte counter = vint_counter; + word base = PATTERN + starfield_base_char * 8; + // erase old star, create new star in pattern table + cvu_voutb(0, base + (oldcounter & mask)); + cvu_voutb(8, base + (counter & mask)); + oldcounter = counter; } -void main(void) -{ - cv_set_screen_active(false); - cv_set_image_table(IMAGE); - cv_set_color_table(0x3fff); - cv_set_character_pattern_t(0x1fff); - cv_set_screen_mode(CV_SCREENMODE_BITMAP); - cv_set_vint_handler(&vint_handler); - - cvu_vmemset(PATTERN, 0, 8 * 256 * 3); - cvu_vmemset(COLOR, 0, 8 * 256 * 3); - cvu_vmemset(IMAGE, 0xff, 32 * 24); +#ifdef __MAIN__ - init_stars(); +//#link "common.c" - cv_set_screen_active(true); - - for(;;) - { - while(!vint); - update_stars(); - vint = false; - } +void main() { + vdp_setup(); + cv_set_vint_handler(&vint_handler); + starfield_setup(); + cv_set_screen_active(true); + while(1) { + wait_vsync(); + starfield_update(); + } } + +#endif diff --git a/presets/coleco/stars.h b/presets/coleco/stars.h new file mode 100644 index 00000000..0241797d --- /dev/null +++ b/presets/coleco/stars.h @@ -0,0 +1,6 @@ + +extern unsigned char starfield_base_char; +extern unsigned char starfield_get_tile_xy(unsigned char x, unsigned char y); +extern void starfield_setup(); +extern void starfield_update(); + diff --git a/src/worker/workermain.ts b/src/worker/workermain.ts index 79e4b90b..693df21e 100644 --- a/src/worker/workermain.ts +++ b/src/worker/workermain.ts @@ -1214,10 +1214,12 @@ function preprocessMCPP(step:BuildStep) { "-D", "__8BITWORKSHOP__", "-D", "__SDCC_z80", "-D", makeCPPSafe(platform.toUpperCase()), - "-D", "FILE__" + makeCPPSafe(step.path+""), "-I", "/share/include", "-Q", step.path, "main.i"]; + if (step.mainfile) { + args.unshift.apply(args, ["-D", "__MAIN__"]); + } if (params.extra_preproc_args) { args.push.apply(args, params.extra_preproc_args); }