DOSBox-X
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
src/hardware/vga_pc98_dac.cpp
00001 /*
00002  *  Copyright (C) 2018-2020  Jon Campbell
00003  *
00004  *  This program is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  This program is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License along
00015  *  with this program; if not, write to the Free Software Foundation, Inc.,
00016  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  */
00018 
00019 #include "dosbox.h"
00020 #include "setup.h"
00021 #include "video.h"
00022 #include "pic.h"
00023 #include "vga.h"
00024 #include "inout.h"
00025 #include "programs.h"
00026 #include "support.h"
00027 #include "setup.h"
00028 #include "timer.h"
00029 #include "mem.h"
00030 #include "util_units.h"
00031 #include "control.h"
00032 #include "pc98_cg.h"
00033 #include "pc98_dac.h"
00034 #include "pc98_gdc.h"
00035 #include "pc98_gdc_const.h"
00036 #include "mixer.h"
00037 
00038 #include <string.h>
00039 #include <stdlib.h>
00040 #include <string>
00041 #include <stdio.h>
00042 
00043 using namespace std;
00044 
00045 extern bool                 vga_8bit_dac;
00046 
00047 uint32_t                    pc98_text_palette[8];
00048 uint8_t                     pc98_16col_analog_rgb_palette_index = 0;
00049 
00050 uint8_t                     pc98_pal_vga[256*3];    /* G R B    0x0..0xFF */
00051 uint8_t                     pc98_pal_analog[256*3]; /* G R B    0x0..0xF */
00052 uint8_t                     pc98_pal_digital[8];    /* G R B    0x0..0x7 */
00053 
00054 void pc98_update_palette(void) {
00055     if (pc98_gdc_vramop & (1 << VOPBIT_VGA)) {
00056         vga_8bit_dac = true;
00057 
00058         for (unsigned int i=0;i < 256;i++) {
00059             vga.dac.rgb[i].green = pc98_pal_vga[(3*i) + 0]; /* re-use VGA DAC */
00060             vga.dac.rgb[i].red   = pc98_pal_vga[(3*i) + 1]; /* re-use VGA DAC */
00061             vga.dac.rgb[i].blue  = pc98_pal_vga[(3*i) + 2]; /* re-use VGA DAC */
00062             VGA_DAC_UpdateColor(i);
00063         }
00064     }
00065     else if (pc98_gdc_vramop & (1 << VOPBIT_ANALOG)) {
00066         vga_8bit_dac = false;
00067 
00068         for (unsigned int i=0;i < 16;i++) {
00069             vga.dac.rgb[i].green = dac_4to6(pc98_pal_analog[(3*i) + 0]&0xF); /* re-use VGA DAC */
00070             vga.dac.rgb[i].red   = dac_4to6(pc98_pal_analog[(3*i) + 1]&0xF); /* re-use VGA DAC */
00071             vga.dac.rgb[i].blue  = dac_4to6(pc98_pal_analog[(3*i) + 2]&0xF); /* re-use VGA DAC */
00072             VGA_DAC_UpdateColor(i);
00073         }
00074     }
00075     else {
00076         vga_8bit_dac = false;
00077 
00078         for (unsigned int i=0;i < 8;i++) {
00079             pc98_update_digpal(i);
00080             VGA_DAC_UpdateColor(i);
00081         }
00082     }
00083 }
00084 
00085 void pc98_update_digpal(unsigned char ent) {
00086     unsigned char grb = pc98_pal_digital[ent];
00087 
00088     vga.dac.rgb[ent].green = (grb & 4) ? 0x3F : 0x00;
00089     vga.dac.rgb[ent].red =   (grb & 2) ? 0x3F : 0x00;
00090     vga.dac.rgb[ent].blue =  (grb & 1) ? 0x3F : 0x00;
00091     VGA_DAC_UpdateColor(ent);
00092 }
00093 
00094 void pc98_set_digpal_entry(unsigned char ent,unsigned char grb) {
00095     pc98_pal_digital[ent] = grb;
00096 
00097     if (!gdc_analog)
00098         pc98_update_digpal(ent);
00099 }
00100 
00101 void pc98_set_digpal_pair(unsigned char start,unsigned char pair) {
00102     /* assume start 0..3 */
00103     pc98_set_digpal_entry(start,  pair >> 4);
00104     pc98_set_digpal_entry(start+4,pair & 0xF);
00105 }
00106 
00107 unsigned char pc98_get_digpal_pair(unsigned char start) {
00108     return (pc98_pal_digital[start] << 4) + pc98_pal_digital[start+4];
00109 }
00110