dosbox-wii/src/ints/int10_put_pixel.cpp

180 lines
4.9 KiB
C++
Raw Normal View History

2009-05-02 23:03:37 +02:00
/*
2009-05-03 00:28:34 +02:00
* Copyright (C) 2002-2007 The DOSBox Team
2009-05-02 23:03:37 +02:00
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2009-05-03 00:02:15 +02:00
* GNU General Public License for more details.
2009-05-02 23:03:37 +02:00
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "dosbox.h"
#include "mem.h"
#include "inout.h"
#include "int10.h"
2009-05-03 00:37:32 +02:00
static Bit8u cga_masks[4]={0x3f,0xcf,0xf3,0xfc};
static Bit8u cga_masks2[8]={0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe};
2009-05-02 23:03:37 +02:00
void INT10_PutPixel(Bit16u x,Bit16u y,Bit8u page,Bit8u color) {
2009-05-02 23:43:00 +02:00
switch (CurMode->type) {
case M_CGA4:
2009-05-02 23:03:37 +02:00
{
2009-05-03 00:18:08 +02:00
if (real_readb(BIOSMEM_SEG,BIOSMEM_CURRENT_MODE)<=5) {
Bit16u off=(y>>1)*80+(x>>2);
if (y&1) off+=8*1024;
Bit8u old=real_readb(0xb800,off);
if (color & 0x80) {
color&=3;
old^=color << (2*(3-(x&3)));
} else {
old=old&cga_masks[x&3]|((color&3) << (2*(3-(x&3))));
}
real_writeb(0xb800,off,old);
2009-05-02 23:35:44 +02:00
} else {
2009-05-03 00:18:08 +02:00
Bit16u off=(y>>2)*160+((x>>2)&(~1));
off+=(8*1024) * (y & 3);
Bit16u old=real_readw(0xb800,off);
if (color & 0x80) {
old^=(color&1) << (7-(x&7));
old^=((color&2)>>1) << ((7-(x&7))+8);
} else {
old=old&(~(0x101<<(7-(x&7)))) | ((color&1) << (7-(x&7))) | (((color&2)>>1) << ((7-(x&7))+8));
}
real_writew(0xb800,off,old);
2009-05-02 23:35:44 +02:00
}
}
break;
2009-05-02 23:43:00 +02:00
case M_CGA2:
2009-05-02 23:35:44 +02:00
{
Bit16u off=(y>>1)*80+(x>>3);
if (y&1) off+=8*1024;
Bit8u old=real_readb(0xb800,off);
if (color & 0x80) {
color&=1;
old^=color << ((7-(x&7)));
} else {
old=old&cga_masks2[x&7]|((color&1) << ((7-(x&7))));
}
real_writeb(0xb800,off,old);
2009-05-02 23:03:37 +02:00
}
break;
2009-05-02 23:53:27 +02:00
case M_TANDY16:
{
2009-05-03 00:18:08 +02:00
IO_Write(0x3d4,0x09);
Bit8u scanlines_m1=IO_Read(0x3d5);
Bit16u off=(y>>((scanlines_m1==1)?1:2))*(CurMode->swidth>>1)+(x>>1);
off+=(8*1024) * (y & scanlines_m1);
2009-05-02 23:53:27 +02:00
Bit8u old=real_readb(0xb800,off);
Bit8u p[2];
p[1] = (old >> 4) & 0xf;
p[0] = old & 0xf;
Bitu ind = 1-(x & 0x1);
if (color & 0x80) {
2009-05-03 00:18:08 +02:00
p[ind]^=(color & 0x7f);
2009-05-02 23:53:27 +02:00
} else {
p[ind]=color;
}
old = (p[1] << 4) | p[0];
real_writeb(0xb800,off,old);
}
break;
2009-05-03 00:18:08 +02:00
case M_EGA:
2009-05-02 23:03:37 +02:00
{
/* Set the correct bitmask for the pixel position */
IO_Write(0x3ce,0x8);Bit8u mask=128>>(x&7);IO_Write(0x3cf,mask);
/* Set the color to set/reset register */
IO_Write(0x3ce,0x0);IO_Write(0x3cf,color);
/* Enable all the set/resets */
IO_Write(0x3ce,0x1);IO_Write(0x3cf,0xf);
2009-05-02 23:20:05 +02:00
/* test for xorring */
if (color & 0x80) { IO_Write(0x3ce,0x3);IO_Write(0x3cf,0x18); }
2009-05-02 23:03:37 +02:00
//Perhaps also set mode 1
/* Calculate where the pixel is in video memory */
2009-05-02 23:43:00 +02:00
PhysPt off=0xa0000+CurMode->plength*page+((y*CurMode->swidth+x)>>3);
2009-05-02 23:03:37 +02:00
/* Bitmask and set/reset should do the rest */
mem_readb(off);
mem_writeb(off,0xff);
2009-05-02 23:20:05 +02:00
/* Restore bitmask */
IO_Write(0x3ce,0x8);IO_Write(0x3cf,0xff);
2009-05-02 23:35:44 +02:00
IO_Write(0x3ce,0x1);IO_Write(0x3cf,0);
2009-05-02 23:20:05 +02:00
/* Restore write operating if changed */
if (color & 0x80) { IO_Write(0x3ce,0x3);IO_Write(0x3cf,0x0); }
2009-05-02 23:03:37 +02:00
break;
}
2009-05-02 23:53:27 +02:00
2009-05-02 23:43:00 +02:00
case M_VGA:
2009-05-02 23:53:27 +02:00
mem_writeb(PhysMake(0xa000,y*320+x),color);
2009-05-02 23:20:05 +02:00
break;
2009-05-03 00:18:08 +02:00
case M_LIN8: {
PhysPt off=S3_LFB_BASE+y*CurMode->swidth+x;
mem_writeb(off,color);
break;
}
2009-05-02 23:03:37 +02:00
default:
2009-05-02 23:43:00 +02:00
LOG(LOG_INT10,LOG_ERROR)("PutPixel unhandled mode type %d",CurMode->type);
2009-05-02 23:03:37 +02:00
break;
}
}
void INT10_GetPixel(Bit16u x,Bit16u y,Bit8u page,Bit8u * color) {
2009-05-02 23:43:00 +02:00
switch (CurMode->type) {
case M_CGA4:
2009-05-02 23:03:37 +02:00
{
Bit16u off=(y>>1)*80+(x>>2);
if (y&1) off+=8*1024;
Bit8u val=real_readb(0xb800,off);
2009-05-02 23:35:44 +02:00
*color=(val>>(((3-x&3))*2)) & 3 ;
}
break;
2009-05-02 23:43:00 +02:00
case M_CGA2:
2009-05-02 23:35:44 +02:00
{
Bit16u off=(y>>1)*80+(x>>3);
if (y&1) off+=8*1024;
Bit8u val=real_readb(0xb800,off);
*color=(val>>(((7-x&7)))) & 1 ;
2009-05-02 23:03:37 +02:00
}
break;
2009-05-03 00:18:08 +02:00
case M_EGA:
2009-05-02 23:20:05 +02:00
{
/* Calculate where the pixel is in video memory */
2009-05-02 23:43:00 +02:00
PhysPt off=0xa0000+CurMode->plength*page+((y*CurMode->swidth+x)>>3);
2009-05-02 23:20:05 +02:00
Bitu shift=7-(x & 7);
/* Set the read map */
*color=0;
IO_Write(0x3ce,0x4);IO_Write(0x3cf,0);
*color|=((mem_readb(off)>>shift) & 1) << 0;
IO_Write(0x3ce,0x4);IO_Write(0x3cf,1);
*color|=((mem_readb(off)>>shift) & 1) << 1;
IO_Write(0x3ce,0x4);IO_Write(0x3cf,2);
*color|=((mem_readb(off)>>shift) & 1) << 2;
IO_Write(0x3ce,0x4);IO_Write(0x3cf,3);
*color|=((mem_readb(off)>>shift) & 1) << 3;
break;
}
2009-05-02 23:43:00 +02:00
case M_VGA:
2009-05-02 23:20:05 +02:00
*color=mem_readb(PhysMake(0xa000,320*y+x));
break;
2009-05-03 00:18:08 +02:00
case M_LIN8: {
PhysPt off=S3_LFB_BASE+y*CurMode->swidth+x;
*color = mem_readb(off);
break;
}
2009-05-02 23:03:37 +02:00
default:
2009-05-02 23:43:00 +02:00
LOG(LOG_INT10,LOG_ERROR)("GetPixel unhandled mode type %d",CurMode->type);
2009-05-02 23:03:37 +02:00
break;
}
}