diff --git a/presets/coleco/common.c b/presets/coleco/common.c index 5c82fb4e..41877c4c 100644 --- a/presets/coleco/common.c +++ b/presets/coleco/common.c @@ -1,4 +1,3 @@ - #include #include #include @@ -6,6 +5,11 @@ #include "common.h" +/* Unified common code for libcv platforms (coleco, msx-libcv, sms-sg1000-libcv, + sms-sms-libcv, sms-gg-libcv). Differences are selected by the CV_CV / CV_MSX / + CV_SMS defines (set by the platform) plus CV_MODE4 for SMS/GG mode-4 builds. + Keep this file identical across those preset directories. */ + volatile uint_fast8_t vint_counter; void vint_handler(void) { @@ -22,16 +26,20 @@ byte reverse_bits(byte n) { void flip_sprite_patterns(word dest, const byte* patterns, word len) { word i; for (i=0; i -#include -#include -#include - -#include "common.h" - -volatile uint_fast8_t vint_counter; - -void vint_handler(void) { - vint_counter++; -} - -const unsigned char reverse_lookup[16] = { -0x0, 0x8, 0x4, 0xc, 0x2, 0xa, 0x6, 0xe, 0x1, 0x9, 0x5, 0xd, 0x3, 0xb, 0x7, 0xf, }; - -byte reverse_bits(byte n) { - return (reverse_lookup[n&0b1111] << 4) | reverse_lookup[n>>4]; -} - -void flip_sprite_patterns(word dest, const byte* patterns, word len) { - word i; - for (i=0; i>= 4; - } -} - -// add two 16-bit BCD values -word bcd_add(word a, word b) __naked { - a; b; // to avoid warning -__asm - push ix - ld ix,#0 - add ix,sp - ld a,4 (ix) - add a, 6 (ix) - daa - ld c,a - ld a,5 (ix) - adc a, 7 (ix) - daa - ld b,a - ld l, c - ld h, b - pop ix - ret -__endasm; -} - -void vdp_setup() { - cv_set_screen_active(false); - cv_set_screen_mode(CV_SCREENMODE_4_224); - cv_set_character_pattern_t(PATTERN | 0x3000); - cv_set_image_table(IMAGE | 0x400); -// cv_set_color_table(COLOR | 0xfff); -// cv_set_sprite_pattern_table(SPRITE_PATTERNS | 0x1800); - cv_set_sprite_attribute_table(SPRITES); - cv_set_sprite_big(true); -} - -void set_shifted_pattern(const byte* src, word dest, byte shift) { - byte y; - for (y=0; y<8; y++) { - byte a = src[y+8]; - byte b = src[y]; - cvu_voutb(a>>shift, dest); - cvu_voutb(b>>shift | a<<(8-shift), dest+8); - cvu_voutb(b<<(8-shift), dest+16); - dest++; - } -} diff --git a/presets/sms-sms-libcv/common.c b/presets/sms-sms-libcv/common.c new file mode 120000 index 00000000..ce249516 --- /dev/null +++ b/presets/sms-sms-libcv/common.c @@ -0,0 +1 @@ +../coleco/common.c \ No newline at end of file diff --git a/presets/sms-sms-libcv/common.h b/presets/sms-sms-libcv/common.h deleted file mode 100644 index c87ad62f..00000000 --- a/presets/sms-sms-libcv/common.h +++ /dev/null @@ -1,68 +0,0 @@ - -#ifndef _CV_COMMON_H -#define _CV_COMMON_H - -/* VRAM map - 0x0000 - 0x3fff character pattern table - 0x3000 - 0x36ff image table - 0x3c00 - 0x3fff sprite attribute table -*/ - -#define PATTERN ((const cv_vmemp)0x0000) -#define IMAGE ((const cv_vmemp)0x3000) -#define SPRITES ((const cv_vmemp)0x3c00) - -#define COLS 32 -#define ROWS 28 - -typedef unsigned char byte; -typedef signed char sbyte; -typedef unsigned short word; - -#ifndef CV_SMS -uintptr_t __at(0x6a) font_bitmap_a; -uintptr_t __at(0x6c) font_bitmap_0; -#else -extern char font_bitmap_a[]; -extern char font_bitmap_0[]; -#endif - -#define COLOR_FGBG(fg,bg) (((fg)<<4)|(bg)) -#define COLOR_FG(fg) (((fg)<<4)) - -#define LOCHAR 0x20 -#define HICHAR 0xff - -#define CHAR(ch) (ch-LOCHAR) - -#define wait_vsync() __asm__("halt") - -extern volatile uint_fast8_t vint_counter; - -extern void vint_handler(void); -extern byte reverse_bits(byte n); -extern void flip_sprite_patterns(word dest, const byte* patterns, word len); - -extern char cursor_x; -extern char cursor_y; - -extern void clrscr(); - -extern word getimageaddr(byte x, byte y); -extern byte getchar(byte x, byte y); -extern void putchar(byte x, byte y, byte attr); -extern void putstring(byte x, byte y, const char* string); -extern void delay(byte i); -extern byte rndint(byte a, byte b); - -extern void memset_safe(void* _dest, char ch, word size); -extern char in_rect(byte x, byte y, byte x0, byte y0, byte w, byte h); -// print 4-digit BCD value -extern void draw_bcd_word(byte x, byte y, word bcd); -// add two 16-bit BCD values -extern word bcd_add(word a, word b); - -extern void vdp_setup(); -extern void set_shifted_pattern(const byte* src, word dest, byte shift); - -#endif diff --git a/presets/sms-sms-libcv/common.h b/presets/sms-sms-libcv/common.h new file mode 120000 index 00000000..d69f50fa --- /dev/null +++ b/presets/sms-sms-libcv/common.h @@ -0,0 +1 @@ +../coleco/common.h \ No newline at end of file diff --git a/src/tools/nodemock.ts b/src/tools/nodemock.ts index 9a158cab..54c62ca2 100644 --- a/src/tools/nodemock.ts +++ b/src/tools/nodemock.ts @@ -29,6 +29,7 @@ export function mockAudio() { writeRegister() { } writeRegisterSN() { } writeRegisterAY() { } + readRegister() { return 0; } } class NullMasterChannel { addChannel() { } diff --git a/src/worker/platforms.ts b/src/worker/platforms.ts index 08f4d96d..a337ec49 100644 --- a/src/worker/platforms.ts +++ b/src/worker/platforms.ts @@ -410,6 +410,8 @@ export var PLATFORM_PARAMS = { }, }; - PLATFORM_PARAMS['sms-sms-libcv'] = PLATFORM_PARAMS['sms-sg1000-libcv']; + // SMS/GG mode-4 variants of the shared libcv common.[ch] (2 bytes per tile, 32x28) + PLATFORM_PARAMS['sms-sms-libcv'] = { ...PLATFORM_PARAMS['sms-sg1000-libcv'], + extra_preproc_args: ['-I', '.', '-D', 'CV_SMS', '-D', 'CV_MODE4'] }; PLATFORM_PARAMS['sms-gg-libcv'] = PLATFORM_PARAMS['sms-sms-libcv']; \ No newline at end of file