Skip to content

Commit

Permalink
Partial support of GFX and SFX condacts
Browse files Browse the repository at this point in the history
  • Loading branch information
nataliapc committed Dec 3, 2019
1 parent 61a7fb1 commit f87c03b
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 46 deletions.
Binary file modified assets/FONT.IM6
Binary file not shown.
34 changes: 17 additions & 17 deletions bin/imgwizard.php
Original file line number Diff line number Diff line change
Expand Up @@ -397,27 +397,27 @@ function checkPalettedColors($in, $scr)
if ($scr!=8) {
if ($colors[0]>0) {
echo "WARNING: PAPER Color (index 0) is used in the image!\n";
$unused = firstUnusedColor($colors);
/* $unused = firstUnusedColor($colors);
if ($unused===FALSE) {
echo "ERROR: PAPER Color is used and not unused colors to switch them!\n\n";
exit;
}
$in = swapColors($in, 0, $unused, $bpp);
$paper = $unused;
$colors[$paper] = $colors[0];
$colors[0] = 0;
$colors[0] = 0;*/
}
if ($colors[$mask]>0) {
echo "WARNING: INK Color (index $mask) is used in the image!\n";
$unused = firstUnusedColor($colors);
/* $unused = firstUnusedColor($colors);
if ($unused===FALSE) {
echo "ERROR: INK Color is used and not unused colors to switch them!\n\n";
exit;
}
$in = swapColors($in, $mask, $unused, $bpp);
$ink = $unused;
$colors[$ink] = $colors[$mask];
$colors[$mask] = 0;
$colors[$mask] = 0;*/
}
}
return array($in, $paper, $ink);
Expand Down Expand Up @@ -496,18 +496,18 @@ function compressRectangle($file, $x, $y, $w, $h, $transparent=-1, $in=NULL, $pa
exit;
}

// Add CHUNK_CLS if not transparent image
if ($transparent<0) {
$out .= pack("cvv", CHUNK_CLS, 0, 0);
echo " #CHUNK ".strpad($id++,2)." CMD CLS (clear window)\n";
}

// Add palette to paletted screen modes
if ($scr < 8 && $scr!='C') {
list($in, $paper, $ink) = checkPalettedColors($in, $scr);
$out .= addPalette($file, $scr, $pal);
}

// Add CHUNK_CLS if not transparent image
if ($transparent<0) {
$out .= pack("cvv", CHUNK_CLS, 0, 0);
echo " #CHUNK ".strpad($id++,2)." CMD CLS (clear window)\n";
}

// Bytes each Row in screen modes
$pixelsByte = array(0,0,0,0,0,2,4,2,1,'C'=>1);
$bytesLine = array(0,0,0,0,0,128,128,256,256,'C'=>256);
Expand Down Expand Up @@ -571,18 +571,18 @@ function compressChunks($file, $lines, $comp, $transparent=-1, $in=NULL, $pal=NU
exit;
}

// Add CHUNK_CLS if not transparent image
if ($transparent<0) {
$out .= pack("cvv", CHUNK_CLS, 0, 0);
echo " #CHUNK ".strpad($id++,2)." CMD CLS (clear window)\n";
}

// Add palette to paletted screen modes
if ($scr < 8 && $scr!='C') {
list($in, $paper, $ink) = checkPalettedColors($in, $scr);
$out .= addPalette($file, $scr, $pal);
}

// Add CHUNK_CLS if not transparent image
if ($transparent<0) {
$out .= pack("cvv", CHUNK_CLS, 0, 0);
echo " #CHUNK ".strpad($id++,2)." CMD CLS (clear window)\n";
}

$pos = 0;

$fullSize = strlen($in);
Expand Down Expand Up @@ -727,4 +727,4 @@ function strpad($text, $len, $character=' ')
return str_pad($text, $len, $character, STR_PAD_LEFT);
}

?>
?>
Binary file modified dsk/FONT.IM6
Binary file not shown.
Binary file modified dsk/FONT.IMC
Binary file not shown.
6 changes: 6 additions & 0 deletions include/daad_platform_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#define ADDR_POINTER_BYTE(X) (*((uint8_t*)X))
#define ADDR_POINTER_WORD(X) (*((uint16_t*)X))


// System functions
bool checkPlatformSystem();
uint16_t getFreeMemory();
Expand All @@ -44,14 +45,17 @@ uint16_t checkKeyboardBuffer();
void clearKeyboardBuffer();
void waitingForInput();


// Filesystem
void loadFilesBin(int argc, char **argv);
uint16_t loadFile(char *filename, uint8_t *destaddress, uint16_t size);
uint16_t fileSize(char *filename);


// External texts
void printXMES(uint16_t address);


// GFX functions
void gfxSetScreen();
void gfxSetScreenModeFlags();
Expand All @@ -65,12 +69,14 @@ void gfxSetBorderCol(uint8_t col);
void gfxPutChWindow(uint8_t c);
void gfxPutChPixels(uint8_t c, uint16_t dx, uint16_t dy);
void gfxPutInputEcho(char c, bool keepPos);
void gfxSetPalette(uint8_t index, uint8_t red, uint8_t green, uint8_t blue);
bool gfxPicturePrepare(uint8_t location);
bool gfxPictureShow();


// SFX functions
void sfxInit();
void sfxWriteRegister(uint8_t reg, uint8_t value);
void sfxTone(uint8_t value1, uint8_t value2);


Expand Down
17 changes: 9 additions & 8 deletions src/daad_condacts.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ printf("\n");
#ifdef VERBOSE
printf(" ======================> VERB+NOUN OK\n");
#endif
//lastIsDone = isDone; //Fixed issue#13 ????
lastIsDone = isDone; //Fixed issue#13 ????
isDone = false;
checkEntry = true;
}
Expand Down Expand Up @@ -2349,8 +2349,9 @@ void do_CALL() // address(dword)
#ifndef DISABLE_SFX
void do_SFX() // value1 value2
{
//TODO: SFX not implemented yet
do_NOT_USED();
uint16_t value = (uint16_t)getValueOrIndirection();
uint8_t reg = *pPROC++;
sfxWriteRegister(reg, value);
}
#endif

Expand Down Expand Up @@ -2398,18 +2399,18 @@ void do_GFX() // pa routine
switch (routine) {
//=================== SET PALETTE
case 9:
//TODO: not implemented yet
break;
gfxSetPalette(flags[value], flags[value+1], flags[value+2], flags[value+3]);
break;
//=================== GET PALETTE
case 10:
//TODO: not implemented yet
break;
//TODO: not implemented
break;
}
}
#endif

// =============================================================================
// Actions for show pictures [2 condacts]
// Actions to show pictures [2 condacts]
// =============================================================================

/* Will load into the picture buffer the given picture. If there no corresponding
Expand Down
106 changes: 85 additions & 21 deletions src/daad_platform_msx2.c
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,11 @@ void loadFilesBin(int argc, char **argv)

// Load image FONT (old DMG) to VRAM 2nd page
memcpy(FILE_IMG, FILE_FONT, 13);
posVRAM = 0x10000;
#if SCREEN==5 || SCREEN==6
posVRAM = 0x8000;
#else
posVRAM = 0x10000;
#endif
gfxPictureShow();
// Restore & free
memcpy(FILE_IMG, aux, 13);
Expand Down Expand Up @@ -349,25 +353,27 @@ void printXMES(uint16_t address)
// GRAPHICS (GFX)
//=========================================================

#if SCREEN == 6
#define COLOR_INK 3
#define COLOR_PAPER 0
#elif SCREEN == 8
#define COLOR_INK (cw->ink)
#define COLOR_PAPER (cw->paper)
#elif SCREEN > 8
#if SCREEN==12
#define COLOR_INK 0xff
#define COLOR_PAPER 0x00
#elif SCREEN < 8
#define COLOR_INK 15
#define COLOR_PAPER 0
#else
#define COLOR_INK (cw->ink)
#define COLOR_PAPER (cw->paper)
#endif

#if SCREEN == 8 //SCREEN 8 fixed colors
const uint8_t colorTranslation[] = { // EGA Palette -> MSX SC8 Palette (GGGRRRBB)
// 000 006 600 606 060 066 260 666 222 447 733 737 373 377 773 777 (GGGRRRBBB) 9bits color guide
0x00, 0x02, 0xc0, 0xc3, 0x18, 0x1b, 0x58, 0xdb, 0x49, 0x93, 0xed, 0xef, 0x7d, 0x7f, 0xfd, 0xff // (GGGRRRBB) 8bits real color used
};
#elif SCREEN == 6 //SCREEN 6 paletted colors
const uint16_t colorTranslation[] = { // Amber Palette -> MSX grb
0x000, // 0: 000 black
0x230, // 1: 320 dark amber
0x450, // 2: 540 medium amber
0x670, // 3_ 760 light amber
0,0,0,0, 0,0,0,0, 0,0,0,0
};
#else //Paletted colors
const uint16_t colorTranslation[] = { // EGA Palette -> MSX grb
0x000, // 0: 000 black
Expand Down Expand Up @@ -433,6 +439,11 @@ void gfxSetScreen()
//Set screen adjust
setRegVDP8(18, ADDR_POINTER_BYTE(0xFFF1));

//Set Palette
#if SCREEN < 8
setPalette(colorTranslation);
#endif

//Disable keys typing sound
ADDR_POINTER_BYTE(CLIKSW) = 0;

Expand Down Expand Up @@ -579,9 +590,14 @@ void gfxSetPaperCol(uint8_t col)
{
col;
#if SCREEN == 8
COLOR_PAPER = colorTranslation[col % 16];
col %= 16;
COLOR_PAPER = colorTranslation[col];
#elif SCREEN == 6
col %= 4;
COLOR_PAPER = col | (col << 2) | (col << 4) | (col << 6);
#elif SCREEN < 8
setColorPal(COLOR_PAPER, colorTranslation[col] % 16);
col %= 16;
COLOR_PAPER = col | (col << 4);
#else
// No PAPER color change
#endif
Expand All @@ -599,9 +615,14 @@ void gfxSetInkCol(uint8_t col)
{
col;
#if SCREEN == 8
COLOR_INK = colorTranslation[col % 16];
col %= 16;
COLOR_INK = colorTranslation[col];
#elif SCREEN == 6
col %= 4;
COLOR_INK = col | (col << 2) | (col << 4) | (col << 6);
#elif SCREEN < 8
setColorPal(COLOR_INK, colorTranslation[col]);
col %= 16;
COLOR_INK = col | (col << 4);
#else
// No INK color change
#endif
Expand Down Expand Up @@ -636,25 +657,25 @@ void gfxPutChPixels(uint8_t c, uint16_t dx, uint16_t dy)
c -= 16;
uint16_t sx = (c*8)%SCREEN_WIDTH,
sy = (c/(SCREEN_WIDTH/FONTHEIGHT)*FONTHEIGHT)+256;
#if SCREEN==8
#if SCREEN <= 8
#ifdef DISABLE_GFXCHAR_COLOR
if (c>=128-16) {
bitBlt(sx, sy, dx, dy, FONTWIDTH, FONTHEIGHT, 0x00, 0, CMD_LMMM|LOG_IMP);
} else
#endif
if (COLOR_PAPER==0) {
bitBlt(sx, sy, dx, dy, FONTWIDTH, FONTHEIGHT, 0x00, 0, CMD_HMMM); // Paint char in white
bitBlt(sx, sy, dx, dy, FONTWIDTH, FONTHEIGHT, 0x00, 0, CMD_LMMM|LOG_IMP); // Paint char in white
bitBlt(sx, sy, dx, dy, FONTWIDTH, FONTHEIGHT, COLOR_INK, 0, CMD_LMMV|LOG_TAND); // Paint char INK foreground
} else {
//Use VRAM 2nd page like TEMP working space to avoid glitches
if (COLOR_INK==0) {
bitBlt( 0, 0, dx, 256+64, FONTWIDTH, FONTHEIGHT, 255, 0, CMD_HMMV); // Paint white background destination
bitBlt( 0, 0, dx, 256+64, FONTWIDTH, FONTHEIGHT, 255, 0, CMD_LMMV|LOG_IMP); // Paint white background destination
bitBlt(sx, sy, dx, 256+64, FONTWIDTH, FONTHEIGHT, 0, 0, CMD_LMMM|LOG_XOR); // Paint char in black
bitBlt( 0, 0, dx, 256+64, FONTWIDTH, FONTHEIGHT, COLOR_PAPER, 0, CMD_LMMV|LOG_AND);// Paint PAPER background destination
bitBlt(dx, 256+64, dx, dy, FONTWIDTH, FONTHEIGHT, 0x00, 0, CMD_HMMM); // Copy TEMP char to destination
bitBlt(dx, 256+64, dx, dy, FONTWIDTH, FONTHEIGHT, 0x00, 0, CMD_LMMM|LOG_IMP); // Copy TEMP char to destination
} else {
bitBlt( 0, 0, dx, dy, FONTWIDTH, FONTHEIGHT, COLOR_PAPER, 0, CMD_HMMV); // Paint PAPER background destination
bitBlt(sx, sy, dx, 256+64, FONTWIDTH, FONTHEIGHT, 0x00, 0, CMD_HMMM); // Paint TEMP char in white
bitBlt( 0, 0, dx, dy, FONTWIDTH, FONTHEIGHT, COLOR_PAPER, 0, CMD_LMMV|LOG_IMP); // Paint PAPER background destination
bitBlt(sx, sy, dx, 256+64, FONTWIDTH, FONTHEIGHT, 0x00, 0, CMD_LMMM|LOG_IMP); // Paint TEMP char in white
bitBlt(sx, sy, dx, 256+64, FONTWIDTH, FONTHEIGHT, COLOR_INK, 0, CMD_LMMV|LOG_TAND); // Paint TEMP INK color foreground
bitBlt(dx, 256+64, dx, dy, FONTWIDTH, FONTHEIGHT, 0x00, 0, CMD_LMMM|LOG_TIMP); // Copy TEMP char to destination
}
Expand Down Expand Up @@ -697,6 +718,22 @@ void gfxPutInputEcho(char c, bool keepPos)
printChar(c);
}

/*
* Function: gfxSetPalette
* --------------------------------
* Set palette RGB to color index.
*
* @param index Color index to change.
* @param red Red component.
* @param green Green component.
* @param blue Blue component.
* @return none.
*/
void gfxSetPalette(uint8_t index, uint8_t red, uint8_t green, uint8_t blue)
{
setColorPal(index%16, (((uint16_t)red & 0b11100000)<<3) | ((green & 0b11100000)>>1) | ((blue & 0b11100000)>>5));
}

/*
* Function: gfxPicturePrepare
* --------------------------------
Expand Down Expand Up @@ -829,6 +866,33 @@ void sfxInit() __naked
#endif//DISABLE_BEEP
}

/*
* Function: sfxWriteRegister
* --------------------------------
* Value is written to register 'reg' of the sound chip on 8 bit machines.
*
* @param reg Register to set value.
* @param value Value to write.
* @return none.
*/
void sfxWriteRegister(uint8_t reg, uint8_t value) __naked
{
#ifndef DISABLE_SFX
__asm
pop af
pop bc
push bc
push af

ld a,c
out (0xa0),a
ld a,b
out (0xa1),a
ret
__endasm;
#endif
}

/*
* Function: sfxSound
* --------------------------------
Expand Down

0 comments on commit f87c03b

Please sign in to comment.