DOSBox-X
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
src/hardware/vga_pc98_dac.cpp
00001 /*
00002  *  Copyright (C) 2018  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
00015  *  along with this program; if not, write to the Free Software
00016  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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 uint32_t                    pc98_text_palette[8];
00046 uint8_t                     pc98_16col_analog_rgb_palette_index = 0;
00047 
00048 uint8_t                     pc98_pal_analog[256*3]; /* G R B    0x0..0xF */
00049 uint8_t                     pc98_pal_digital[8];    /* G R B    0x0..0x7 */
00050 
00051 void pc98_update_palette(void) {
00052     if (pc98_gdc_vramop & (1 << VOPBIT_ANALOG)) {
00053         for (unsigned int i=0;i < 16;i++) {
00054             vga.dac.rgb[i].green = dac_4to6(pc98_pal_analog[(3*i) + 0]&0xF); /* re-use VGA DAC */
00055             vga.dac.rgb[i].red   = dac_4to6(pc98_pal_analog[(3*i) + 1]&0xF); /* re-use VGA DAC */
00056             vga.dac.rgb[i].blue  = dac_4to6(pc98_pal_analog[(3*i) + 2]&0xF); /* re-use VGA DAC */
00057             VGA_DAC_UpdateColor(i);
00058         }
00059     }
00060     else {
00061         for (unsigned int i=0;i < 8;i++) {
00062             pc98_update_digpal(i);
00063             VGA_DAC_UpdateColor(i);
00064         }
00065     }
00066 }
00067 
00068 void pc98_update_digpal(unsigned char ent) {
00069     unsigned char grb = pc98_pal_digital[ent];
00070 
00071     vga.dac.rgb[ent].green = (grb & 4) ? 0x3F : 0x00;
00072     vga.dac.rgb[ent].red =   (grb & 2) ? 0x3F : 0x00;
00073     vga.dac.rgb[ent].blue =  (grb & 1) ? 0x3F : 0x00;
00074     VGA_DAC_UpdateColor(ent);
00075 }
00076 
00077 void pc98_set_digpal_entry(unsigned char ent,unsigned char grb) {
00078     pc98_pal_digital[ent] = grb;
00079 
00080     if (!gdc_analog)
00081         pc98_update_digpal(ent);
00082 }
00083 
00084 void pc98_set_digpal_pair(unsigned char start,unsigned char pair) {
00085     /* assume start 0..3 */
00086     pc98_set_digpal_entry(start,  pair >> 4);
00087     pc98_set_digpal_entry(start+4,pair & 0xF);
00088 }
00089 
00090 unsigned char pc98_get_digpal_pair(unsigned char start) {
00091     return (pc98_pal_digital[start] << 4) + pc98_pal_digital[start+4];
00092 }
00093