| 1 |
/* |
| 2 |
* Copyright (C) 2002-2010 The DOSBox Team |
| 3 |
* |
| 4 |
* This program is free software; you can redistribute it and/or modify |
| 5 |
* it under the terms of the GNU General Public License as published by |
| 6 |
* the Free Software Foundation; either version 2 of the License, or |
| 7 |
* (at your option) any later version. |
| 8 |
* |
| 9 |
* This program is distributed in the hope that it will be useful, |
| 10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
* GNU General Public License for more details. |
| 13 |
* |
| 14 |
* You should have received a copy of the GNU General Public License |
| 15 |
* along with this program; if not, write to the Free Software |
| 16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 17 |
*/ |
| 18 |
|
| 19 |
/* $Id: int10_char.cpp,v 1.60 2009-10-15 20:36:56 c2woody Exp $ */ |
| 20 |
|
| 21 |
/* Character displaying moving functions */ |
| 22 |
|
| 23 |
#include "dosbox.h" |
| 24 |
#include "bios.h" |
| 25 |
#include "mem.h" |
| 26 |
#include "inout.h" |
| 27 |
#include "int10.h" |
| 28 |
|
| 29 |
static void CGA2_CopyRow(Bit8u cleft,Bit8u cright,Bit8u rold,Bit8u rnew,PhysPt base) { |
| 30 |
Bit8u cheight = real_readb(BIOSMEM_SEG,BIOSMEM_CHAR_HEIGHT); |
| 31 |
PhysPt dest=base+((CurMode->twidth*rnew)*(cheight/2)+cleft); |
| 32 |
PhysPt src=base+((CurMode->twidth*rold)*(cheight/2)+cleft); |
| 33 |
Bitu copy=(cright-cleft); |
| 34 |
Bitu nextline=CurMode->twidth; |
| 35 |
for (Bitu i=0;i<cheight/2U;i++) { |
| 36 |
MEM_BlockCopy(dest,src,copy); |
| 37 |
MEM_BlockCopy(dest+8*1024,src+8*1024,copy); |
| 38 |
dest+=nextline;src+=nextline; |
| 39 |
} |
| 40 |
} |
| 41 |
|
| 42 |
static void CGA4_CopyRow(Bit8u cleft,Bit8u cright,Bit8u rold,Bit8u rnew,PhysPt base) { |
| 43 |
Bit8u cheight = real_readb(BIOSMEM_SEG,BIOSMEM_CHAR_HEIGHT); |
| 44 |
PhysPt dest=base+((CurMode->twidth*rnew)*(cheight/2)+cleft)*2; |
| 45 |
PhysPt src=base+((CurMode->twidth*rold)*(cheight/2)+cleft)*2; |
| 46 |
Bitu copy=(cright-cleft)*2;Bitu nextline=CurMode->twidth*2; |
| 47 |
for (Bitu i=0;i<cheight/2U;i++) { |
| 48 |
MEM_BlockCopy(dest,src,copy); |
| 49 |
MEM_BlockCopy(dest+8*1024,src+8*1024,copy); |
| 50 |
dest+=nextline;src+=nextline; |
| 51 |
} |
| 52 |
} |
| 53 |
|
| 54 |
static void TANDY16_CopyRow(Bit8u cleft,Bit8u cright,Bit8u rold,Bit8u rnew,PhysPt base) { |
| 55 |
Bit8u cheight = real_readb(BIOSMEM_SEG,BIOSMEM_CHAR_HEIGHT); |
| 56 |
PhysPt dest=base+((CurMode->twidth*rnew)*(cheight/4)+cleft)*4; |
| 57 |
PhysPt src=base+((CurMode->twidth*rold)*(cheight/4)+cleft)*4; |
| 58 |
Bitu copy=(cright-cleft)*4;Bitu nextline=CurMode->twidth*4; |
| 59 |
for (Bitu i=0;i<cheight/4U;i++) { |
| 60 |
MEM_BlockCopy(dest,src,copy); |
| 61 |
MEM_BlockCopy(dest+8*1024,src+8*1024,copy); |
| 62 |
MEM_BlockCopy(dest+16*1024,src+16*1024,copy); |
| 63 |
MEM_BlockCopy(dest+24*1024,src+24*1024,copy); |
| 64 |
dest+=nextline;src+=nextline; |
| 65 |
} |
| 66 |
} |
| 67 |
|
| 68 |
static void EGA16_CopyRow(Bit8u cleft,Bit8u cright,Bit8u rold,Bit8u rnew,PhysPt base) { |
| 69 |
PhysPt src,dest;Bitu copy; |
| 70 |
Bit8u cheight = real_readb(BIOSMEM_SEG,BIOSMEM_CHAR_HEIGHT); |
| 71 |
dest=base+(CurMode->twidth*rnew)*cheight+cleft; |
| 72 |
src=base+(CurMode->twidth*rold)*cheight+cleft; |
| 73 |
Bitu nextline=CurMode->twidth; |
| 74 |
/* Setup registers correctly */ |
| 75 |
IO_Write(0x3ce,5);IO_Write(0x3cf,1); /* Memory transfer mode */ |
| 76 |
IO_Write(0x3c4,2);IO_Write(0x3c5,0xf); /* Enable all Write planes */ |
| 77 |
/* Do some copying */ |
| 78 |
Bitu rowsize=(cright-cleft); |
| 79 |
copy=cheight; |
| 80 |
for (;copy>0;copy--) { |
| 81 |
for (Bitu x=0;x<rowsize;x++) mem_writeb(dest+x,mem_readb(src+x)); |
| 82 |
dest+=nextline;src+=nextline; |
| 83 |
} |
| 84 |
/* Restore registers */ |
| 85 |
IO_Write(0x3ce,5);IO_Write(0x3cf,0); /* Normal transfer mode */ |
| 86 |
} |
| 87 |
|
| 88 |
static void VGA_CopyRow(Bit8u cleft,Bit8u cright,Bit8u rold,Bit8u rnew,PhysPt base) { |
| 89 |
PhysPt src,dest;Bitu copy; |
| 90 |
Bit8u cheight = real_readb(BIOSMEM_SEG,BIOSMEM_CHAR_HEIGHT); |
| 91 |
dest=base+8*((CurMode->twidth*rnew)*cheight+cleft); |
| 92 |
src=base+8*((CurMode->twidth*rold)*cheight+cleft); |
| 93 |
Bitu nextline=8*CurMode->twidth; |
| 94 |
Bitu rowsize=8*(cright-cleft); |
| 95 |
copy=cheight; |
| 96 |
for (;copy>0;copy--) { |
| 97 |
for (Bitu x=0;x<rowsize;x++) mem_writeb(dest+x,mem_readb(src+x)); |
| 98 |
dest+=nextline;src+=nextline; |
| 99 |
} |
| 100 |
} |
| 101 |
|
| 102 |
static void TEXT_CopyRow(Bit8u cleft,Bit8u cright,Bit8u rold,Bit8u rnew,PhysPt base) { |
| 103 |
PhysPt src,dest; |
| 104 |
src=base+(rold*CurMode->twidth+cleft)*2; |
| 105 |
dest=base+(rnew*CurMode->twidth+cleft)*2; |
| 106 |
MEM_BlockCopy(dest,src,(cright-cleft)*2); |
| 107 |
} |
| 108 |
|
| 109 |
static void CGA2_FillRow(Bit8u cleft,Bit8u cright,Bit8u row,PhysPt base,Bit8u attr) { |
| 110 |
Bit8u cheight = real_readb(BIOSMEM_SEG,BIOSMEM_CHAR_HEIGHT); |
| 111 |
PhysPt dest=base+((CurMode->twidth*row)*(cheight/2)+cleft); |
| 112 |
Bitu copy=(cright-cleft); |
| 113 |
Bitu nextline=CurMode->twidth; |
| 114 |
attr=(attr & 0x3) | ((attr & 0x3) << 2) | ((attr & 0x3) << 4) | ((attr & 0x3) << 6); |
| 115 |
for (Bitu i=0;i<cheight/2U;i++) { |
| 116 |
for (Bitu x=0;x<copy;x++) { |
| 117 |
mem_writeb(dest+x,attr); |
| 118 |
mem_writeb(dest+8*1024+x,attr); |
| 119 |
} |
| 120 |
dest+=nextline; |
| 121 |
} |
| 122 |
} |
| 123 |
|
| 124 |
static void CGA4_FillRow(Bit8u cleft,Bit8u cright,Bit8u row,PhysPt base,Bit8u attr) { |
| 125 |
Bit8u cheight = real_readb(BIOSMEM_SEG,BIOSMEM_CHAR_HEIGHT); |
| 126 |
PhysPt dest=base+((CurMode->twidth*row)*(cheight/2)+cleft)*2; |
| 127 |
Bitu copy=(cright-cleft)*2;Bitu nextline=CurMode->twidth*2; |
| 128 |
attr=(attr & 0x3) | ((attr & 0x3) << 2) | ((attr & 0x3) << 4) | ((attr & 0x3) << 6); |
| 129 |
for (Bitu i=0;i<cheight/2U;i++) { |
| 130 |
for (Bitu x=0;x<copy;x++) { |
| 131 |
mem_writeb(dest+x,attr); |
| 132 |
mem_writeb(dest+8*1024+x,attr); |
| 133 |
} |
| 134 |
dest+=nextline; |
| 135 |
} |
| 136 |
} |
| 137 |
|
| 138 |
static void TANDY16_FillRow(Bit8u cleft,Bit8u cright,Bit8u row,PhysPt base,Bit8u attr) { |
| 139 |
Bit8u cheight = real_readb(BIOSMEM_SEG,BIOSMEM_CHAR_HEIGHT); |
| 140 |
PhysPt dest=base+((CurMode->twidth*row)*(cheight/4)+cleft)*4; |
| 141 |
Bitu copy=(cright-cleft)*4;Bitu nextline=CurMode->twidth*4; |
| 142 |
attr=(attr & 0xf) | (attr & 0xf) << 4; |
| 143 |
for (Bitu i=0;i<cheight/4U;i++) { |
| 144 |
for (Bitu x=0;x<copy;x++) { |
| 145 |
mem_writeb(dest+x,attr); |
| 146 |
mem_writeb(dest+8*1024+x,attr); |
| 147 |
mem_writeb(dest+16*1024+x,attr); |
| 148 |
mem_writeb(dest+24*1024+x,attr); |
| 149 |
} |
| 150 |
dest+=nextline; |
| 151 |
} |
| 152 |
} |
| 153 |
|
| 154 |
static void EGA16_FillRow(Bit8u cleft,Bit8u cright,Bit8u row,PhysPt base,Bit8u attr) { |
| 155 |
/* Set Bitmask / Color / Full Set Reset */ |
| 156 |
IO_Write(0x3ce,0x8);IO_Write(0x3cf,0xff); |
| 157 |
IO_Write(0x3ce,0x0);IO_Write(0x3cf,attr); |
| 158 |
IO_Write(0x3ce,0x1);IO_Write(0x3cf,0xf); |
| 159 |
/* Write some bytes */ |
| 160 |
Bit8u cheight = real_readb(BIOSMEM_SEG,BIOSMEM_CHAR_HEIGHT); |
| 161 |
PhysPt dest=base+(CurMode->twidth*row)*cheight+cleft; |
| 162 |
Bitu nextline=CurMode->twidth; |
| 163 |
Bitu copy = cheight;Bitu rowsize=(cright-cleft); |
| 164 |
for (;copy>0;copy--) { |
| 165 |
for (Bitu x=0;x<rowsize;x++) mem_writeb(dest+x,0xff); |
| 166 |
dest+=nextline; |
| 167 |
} |
| 168 |
IO_Write(0x3cf,0); |
| 169 |
} |
| 170 |
|
| 171 |
static void VGA_FillRow(Bit8u cleft,Bit8u cright,Bit8u row,PhysPt base,Bit8u attr) { |
| 172 |
/* Write some bytes */ |
| 173 |
Bit8u cheight = real_readb(BIOSMEM_SEG,BIOSMEM_CHAR_HEIGHT); |
| 174 |
PhysPt dest=base+8*((CurMode->twidth*row)*cheight+cleft); |
| 175 |
Bitu nextline=8*CurMode->twidth; |
| 176 |
Bitu copy = cheight;Bitu rowsize=8*(cright-cleft); |
| 177 |
for (;copy>0;copy--) { |
| 178 |
for (Bitu x=0;x<rowsize;x++) mem_writeb(dest+x,attr); |
| 179 |
dest+=nextline; |
| 180 |
} |
| 181 |
} |
| 182 |
|
| 183 |
static void TEXT_FillRow(Bit8u cleft,Bit8u cright,Bit8u row,PhysPt base,Bit8u attr) { |
| 184 |
/* Do some filing */ |
| 185 |
PhysPt dest; |
| 186 |
dest=base+(row*CurMode->twidth+cleft)*2; |
| 187 |
Bit16u fill=(attr<<8)+' '; |
| 188 |
for (Bit8u x=0;x<(cright-cleft);x++) { |
| 189 |
mem_writew(dest,fill); |
| 190 |
dest+=2; |
| 191 |
} |
| 192 |
} |
| 193 |
|
| 194 |
|
| 195 |
void INT10_ScrollWindow(Bit8u rul,Bit8u cul,Bit8u rlr,Bit8u clr,Bit8s nlines,Bit8u attr,Bit8u page) { |
| 196 |
/* Do some range checking */ |
| 197 |
if (CurMode->type!=M_TEXT) page=0xff; |
| 198 |
BIOS_NCOLS;BIOS_NROWS; |
| 199 |
if(rul>rlr) return; |
| 200 |
if(cul>clr) return; |
| 201 |
if(rlr>=nrows) rlr=(Bit8u)nrows-1; |
| 202 |
if(clr>=ncols) clr=(Bit8u)ncols-1; |
| 203 |
clr++; |
| 204 |
|
| 205 |
/* Get the correct page */ |
| 206 |
if(page==0xFF) page=real_readb(BIOSMEM_SEG,BIOSMEM_CURRENT_PAGE); |
| 207 |
PhysPt base=CurMode->pstart+page*real_readw(BIOSMEM_SEG,BIOSMEM_PAGE_SIZE); |
| 208 |
|
| 209 |
/* See how much lines need to be copied */ |
| 210 |
Bit8u start,end;Bits next; |
| 211 |
/* Copy some lines */ |
| 212 |
if (nlines>0) { |
| 213 |
start=rlr-nlines+1; |
| 214 |
end=rul; |
| 215 |
next=-1; |
| 216 |
} else if (nlines<0) { |
| 217 |
start=rul-nlines-1; |
| 218 |
end=rlr; |
| 219 |
next=1; |
| 220 |
} else { |
| 221 |
nlines=rlr-rul+1; |
| 222 |
goto filling; |
| 223 |
} |
| 224 |
while (start!=end) { |
| 225 |
start+=next; |
| 226 |
switch (CurMode->type) { |
| 227 |
case M_TEXT: |
| 228 |
TEXT_CopyRow(cul,clr,start,start+nlines,base);break; |
| 229 |
case M_CGA2: |
| 230 |
CGA2_CopyRow(cul,clr,start,start+nlines,base);break; |
| 231 |
case M_CGA4: |
| 232 |
CGA4_CopyRow(cul,clr,start,start+nlines,base);break; |
| 233 |
case M_TANDY16: |
| 234 |
TANDY16_CopyRow(cul,clr,start,start+nlines,base);break; |
| 235 |
case M_EGA: |
| 236 |
EGA16_CopyRow(cul,clr,start,start+nlines,base);break; |
| 237 |
case M_VGA: |
| 238 |
VGA_CopyRow(cul,clr,start,start+nlines,base);break; |
| 239 |
case M_LIN4: |
| 240 |
if ((machine==MCH_VGA) && (svgaCard==SVGA_TsengET4K) && |
| 241 |
(CurMode->swidth<=800)) { |
| 242 |
// the ET4000 BIOS supports text output in 800x600 SVGA |
| 243 |
EGA16_CopyRow(cul,clr,start,start+nlines,base);break; |
| 244 |
} |
| 245 |
// fall-through |
| 246 |
default: |
| 247 |
LOG(LOG_INT10,LOG_ERROR)("Unhandled mode %d for scroll",CurMode->type); |
| 248 |
} |
| 249 |
} |
| 250 |
/* Fill some lines */ |
| 251 |
filling: |
| 252 |
if (nlines>0) { |
| 253 |
start=rul; |
| 254 |
} else { |
| 255 |
nlines=-nlines; |
| 256 |
start=rlr-nlines+1; |
| 257 |
} |
| 258 |
for (;nlines>0;nlines--) { |
| 259 |
switch (CurMode->type) { |
| 260 |
case M_TEXT: |
| 261 |
TEXT_FillRow(cul,clr,start,base,attr);break; |
| 262 |
case M_CGA2: |
| 263 |
CGA2_FillRow(cul,clr,start,base,attr);break; |
| 264 |
case M_CGA4: |
| 265 |
CGA4_FillRow(cul,clr,start,base,attr);break; |
| 266 |
case M_TANDY16: |
| 267 |
TANDY16_FillRow(cul,clr,start,base,attr);break; |
| 268 |
case M_EGA: |
| 269 |
EGA16_FillRow(cul,clr,start,base,attr);break; |
| 270 |
case M_VGA: |
| 271 |
VGA_FillRow(cul,clr,start,base,attr);break; |
| 272 |
case M_LIN4: |
| 273 |
if ((machine==MCH_VGA) && (svgaCard==SVGA_TsengET4K) && |
| 274 |
(CurMode->swidth<=800)) { |
| 275 |
EGA16_FillRow(cul,clr,start,base,attr);break; |
| 276 |
} |
| 277 |
// fall-through |
| 278 |
default: |
| 279 |
LOG(LOG_INT10,LOG_ERROR)("Unhandled mode %d for scroll",CurMode->type); |
| 280 |
} |
| 281 |
start++; |
| 282 |
} |
| 283 |
} |
| 284 |
|
| 285 |
void INT10_SetActivePage(Bit8u page) { |
| 286 |
Bit16u mem_address; |
| 287 |
if (page>7) LOG(LOG_INT10,LOG_ERROR)("INT10_SetActivePage page %d",page); |
| 288 |
|
| 289 |
if (IS_EGAVGA_ARCH && (svgaCard==SVGA_S3Trio)) page &= 7; |
| 290 |
|
| 291 |
mem_address=page*real_readw(BIOSMEM_SEG,BIOSMEM_PAGE_SIZE); |
| 292 |
/* Write the new page start */ |
| 293 |
real_writew(BIOSMEM_SEG,BIOSMEM_CURRENT_START,mem_address); |
| 294 |
if (IS_EGAVGA_ARCH) { |
| 295 |
if (CurMode->mode<8) mem_address>>=1; |
| 296 |
// rare alternative: if (CurMode->type==M_TEXT) mem_address>>=1; |
| 297 |
} else { |
| 298 |
mem_address>>=1; |
| 299 |
} |
| 300 |
/* Write the new start address in vgahardware */ |
| 301 |
Bit16u base=real_readw(BIOSMEM_SEG,BIOSMEM_CRTC_ADDRESS); |
| 302 |
IO_Write(base,0x0c); |
| 303 |
IO_Write(base+1,(Bit8u)(mem_address>>8)); |
| 304 |
IO_Write(base,0x0d); |
| 305 |
IO_Write(base+1,(Bit8u)mem_address); |
| 306 |
|
| 307 |
// And change the BIOS page |
| 308 |
real_writeb(BIOSMEM_SEG,BIOSMEM_CURRENT_PAGE,page); |
| 309 |
Bit8u cur_row=CURSOR_POS_ROW(page); |
| 310 |
Bit8u cur_col=CURSOR_POS_COL(page); |
| 311 |
// Display the cursor, now the page is active |
| 312 |
INT10_SetCursorPos(cur_row,cur_col,page); |
| 313 |
} |
| 314 |
|
| 315 |
void INT10_SetCursorShape(Bit8u first,Bit8u last) { |
| 316 |
real_writew(BIOSMEM_SEG,BIOSMEM_CURSOR_TYPE,last|(first<<8)); |
| 317 |
if (machine==MCH_CGA) goto dowrite; |
| 318 |
if (IS_TANDY_ARCH) goto dowrite; |
| 319 |
/* Skip CGA cursor emulation if EGA/VGA system is active */ |
| 320 |
if (!(real_readb(BIOSMEM_SEG,BIOSMEM_VIDEO_CTL) & 0x8)) { |
| 321 |
/* Check for CGA type 01, invisible */ |
| 322 |
if ((first & 0x60) == 0x20) { |
| 323 |
first=0x1e; |
| 324 |
last=0x00; |
| 325 |
goto dowrite; |
| 326 |
} |
| 327 |
/* Check if we need to convert CGA Bios cursor values */ |
| 328 |
if (!(real_readb(BIOSMEM_SEG,BIOSMEM_VIDEO_CTL) & 0x1)) { // set by int10 fun12 sub34 |
| 329 |
// if (CurMode->mode>0x3) goto dowrite; //Only mode 0-3 are text modes on cga |
| 330 |
if ((first & 0xe0) || (last & 0xe0)) goto dowrite; |
| 331 |
Bit8u cheight=real_readb(BIOSMEM_SEG,BIOSMEM_CHAR_HEIGHT)-1; |
| 332 |
/* Creative routine i based of the original ibmvga bios */ |
| 333 |
|
| 334 |
if (last<first) { |
| 335 |
if (!last) goto dowrite; |
| 336 |
first=last; |
| 337 |
last=cheight; |
| 338 |
/* Test if this might be a cga style cursor set, if not don't do anything */ |
| 339 |
} else if (((first | last)>=cheight) || !(last==(cheight-1)) || !(first==cheight) ) { |
| 340 |
if (last<=3) goto dowrite; |
| 341 |
if (first+2<last) { |
| 342 |
if (first>2) { |
| 343 |
first=(cheight+1)/2; |
| 344 |
last=cheight; |
| 345 |
} else { |
| 346 |
last=cheight; |
| 347 |
} |
| 348 |
} else { |
| 349 |
first=(first-last)+cheight; |
| 350 |
last=cheight; |
| 351 |
|
| 352 |
if (cheight>0xc) { // vgatest sets 15 15 2x where only one should be decremented to 14 14 |
| 353 |
first--; // implementing int10 fun12 sub34 fixed this. |
| 354 |
last--; |
| 355 |
} |
| 356 |
} |
| 357 |
} |
| 358 |
|
| 359 |
} |
| 360 |
} |
| 361 |
dowrite: |
| 362 |
Bit16u base=real_readw(BIOSMEM_SEG,BIOSMEM_CRTC_ADDRESS); |
| 363 |
IO_Write(base,0xa);IO_Write(base+1,first); |
| 364 |
IO_Write(base,0xb);IO_Write(base+1,last); |
| 365 |
} |
| 366 |
|
| 367 |
void INT10_SetCursorPos(Bit8u row,Bit8u col,Bit8u page) { |
| 368 |
Bit16u address; |
| 369 |
|
| 370 |
if (page>7) LOG(LOG_INT10,LOG_ERROR)("INT10_SetCursorPos page %d",page); |
| 371 |
// Bios cursor pos |
| 372 |
real_writeb(BIOSMEM_SEG,BIOSMEM_CURSOR_POS+page*2,col); |
| 373 |
real_writeb(BIOSMEM_SEG,BIOSMEM_CURSOR_POS+page*2+1,row); |
| 374 |
// Set the hardware cursor |
| 375 |
Bit8u current=real_readb(BIOSMEM_SEG,BIOSMEM_CURRENT_PAGE); |
| 376 |
if(page==current) { |
| 377 |
// Get the dimensions |
| 378 |
BIOS_NCOLS; |
| 379 |
// Calculate the address knowing nbcols nbrows and page num |
| 380 |
// NOTE: BIOSMEM_CURRENT_START counts in colour/flag pairs |
| 381 |
address=(ncols*row)+col+real_readw(BIOSMEM_SEG,BIOSMEM_CURRENT_START)/2; |
| 382 |
// CRTC regs 0x0e and 0x0f |
| 383 |
Bit16u base=real_readw(BIOSMEM_SEG,BIOSMEM_CRTC_ADDRESS); |
| 384 |
IO_Write(base,0x0e); |
| 385 |
IO_Write(base+1,(Bit8u)(address>>8)); |
| 386 |
IO_Write(base,0x0f); |
| 387 |
IO_Write(base+1,(Bit8u)address); |
| 388 |
} |
| 389 |
} |
| 390 |
|
| 391 |
void ReadCharAttr(Bit16u col,Bit16u row,Bit8u page,Bit16u * result) { |
| 392 |
/* Externally used by the mouse routine */ |
| 393 |
PhysPt fontdata; |
| 394 |
Bitu x,y; |
| 395 |
Bit8u cheight = real_readb(BIOSMEM_SEG,BIOSMEM_CHAR_HEIGHT); |
| 396 |
bool split_chr = false; |
| 397 |
switch (CurMode->type) { |
| 398 |
case M_TEXT: |
| 399 |
{ |
| 400 |
// Compute the address |
| 401 |
Bit16u address=page*real_readw(BIOSMEM_SEG,BIOSMEM_PAGE_SIZE); |
| 402 |
address+=(row*real_readw(BIOSMEM_SEG,BIOSMEM_NB_COLS)+col)*2; |
| 403 |
// read the char |
| 404 |
PhysPt where = CurMode->pstart+address; |
| 405 |
*result=mem_readw(where); |
| 406 |
} |
| 407 |
return; |
| 408 |
case M_CGA4: |
| 409 |
case M_CGA2: |
| 410 |
case M_TANDY16: |
| 411 |
split_chr = true; |
| 412 |
/* Fallthrough */ |
| 413 |
default: /* EGA/VGA don't have a split font-table */ |
| 414 |
for(Bit16u chr=0;chr <= 255 ;chr++) { |
| 415 |
if (!split_chr || (chr<128)) fontdata = Real2Phys(RealGetVec(0x43))+chr*cheight; |
| 416 |
else fontdata = Real2Phys(RealGetVec(0x1F))+(chr-128)*cheight; |
| 417 |
|
| 418 |
x=8*col; |
| 419 |
y=cheight*row; |
| 420 |
bool error=false; |
| 421 |
for (Bit8u h=0;h<cheight;h++) { |
| 422 |
Bit8u bitsel=128; |
| 423 |
Bit8u bitline=mem_readb(fontdata++); |
| 424 |
Bit8u res=0; |
| 425 |
Bit8u vidline=0; |
| 426 |
Bit16u tx=(Bit16u)x; |
| 427 |
while (bitsel) { |
| 428 |
//Construct bitline in memory |
| 429 |
INT10_GetPixel(tx,(Bit16u)y,page,&res); |
| 430 |
if(res) vidline|=bitsel; |
| 431 |
tx++; |
| 432 |
bitsel>>=1; |
| 433 |
} |
| 434 |
y++; |
| 435 |
if(bitline != vidline){ |
| 436 |
/* It's not character 'chr', move on to the next */ |
| 437 |
error = true; |
| 438 |
break; |
| 439 |
} |
| 440 |
} |
| 441 |
if(!error){ |
| 442 |
/* We found it */ |
| 443 |
*result = chr; |
| 444 |
return; |
| 445 |
} |
| 446 |
} |
| 447 |
LOG(LOG_INT10,LOG_ERROR)("ReadChar didn't find character"); |
| 448 |
*result = 0; |
| 449 |
break; |
| 450 |
} |
| 451 |
} |
| 452 |
void INT10_ReadCharAttr(Bit16u * result,Bit8u page) { |
| 453 |
if(page==0xFF) page=real_readb(BIOSMEM_SEG,BIOSMEM_CURRENT_PAGE); |
| 454 |
Bit8u cur_row=CURSOR_POS_ROW(page); |
| 455 |
Bit8u cur_col=CURSOR_POS_COL(page); |
| 456 |
ReadCharAttr(cur_col,cur_row,page,result); |
| 457 |
} |
| 458 |
void WriteChar(Bit16u col,Bit16u row,Bit8u page,Bit8u chr,Bit8u attr,bool useattr) { |
| 459 |
/* Externally used by the mouse routine */ |
| 460 |
RealPt fontdata; |
| 461 |
Bitu x,y; |
| 462 |
Bit8u cheight = real_readb(BIOSMEM_SEG,BIOSMEM_CHAR_HEIGHT); |
| 463 |
switch (CurMode->type) { |
| 464 |
case M_TEXT: |
| 465 |
{ |
| 466 |
// Compute the address |
| 467 |
Bit16u address=page*real_readw(BIOSMEM_SEG,BIOSMEM_PAGE_SIZE); |
| 468 |
address+=(row*real_readw(BIOSMEM_SEG,BIOSMEM_NB_COLS)+col)*2; |
| 469 |
// Write the char |
| 470 |
PhysPt where = CurMode->pstart+address; |
| 471 |
mem_writeb(where,chr); |
| 472 |
if (useattr) { |
| 473 |
mem_writeb(where+1,attr); |
| 474 |
} |
| 475 |
} |
| 476 |
return; |
| 477 |
case M_CGA4: |
| 478 |
case M_CGA2: |
| 479 |
case M_TANDY16: |
| 480 |
if (chr<128) |
| 481 |
fontdata=RealGetVec(0x43); |
| 482 |
else { |
| 483 |
chr-=128; |
| 484 |
fontdata=RealGetVec(0x1f); |
| 485 |
} |
| 486 |
fontdata=RealMake(RealSeg(fontdata), RealOff(fontdata) + chr*cheight); |
| 487 |
break; |
| 488 |
default: |
| 489 |
fontdata=RealGetVec(0x43); |
| 490 |
fontdata=RealMake(RealSeg(fontdata), RealOff(fontdata) + chr*cheight); |
| 491 |
break; |
| 492 |
} |
| 493 |
|
| 494 |
if(GCC_UNLIKELY(!useattr)) { //Set attribute(color) to a sensible value |
| 495 |
static bool warned_use = false; |
| 496 |
if(GCC_UNLIKELY(!warned_use)){ |
| 497 |
LOG(LOG_INT10,LOG_ERROR)("writechar used without attribute in non-textmode %c %X",chr,chr); |
| 498 |
warned_use = true; |
| 499 |
} |
| 500 |
switch(CurMode->type) { |
| 501 |
case M_CGA4: |
| 502 |
attr = 0x3; |
| 503 |
break; |
| 504 |
case M_CGA2: |
| 505 |
attr = 0x1; |
| 506 |
break; |
| 507 |
case M_TANDY16: |
| 508 |
case M_EGA: |
| 509 |
default: |
| 510 |
attr = 0xf; |
| 511 |
break; |
| 512 |
} |
| 513 |
} |
| 514 |
|
| 515 |
//Some weird behavior of mode 6 (and 11) |
| 516 |
if ((CurMode->mode == 0x6)/* || (CurMode->mode==0x11)*/) attr = (attr&0x80)|1; |
| 517 |
//(same fix for 11 fixes vgatest2, but it's not entirely correct according to wd) |
| 518 |
|
| 519 |
x=8*col; |
| 520 |
y=cheight*row;Bit8u xor_mask=(CurMode->type == M_VGA) ? 0x0 : 0x80; |
| 521 |
//TODO Check for out of bounds |
| 522 |
if (CurMode->type==M_EGA) { |
| 523 |
/* enable all planes for EGA modes (Ultima 1 colour bug) */ |
| 524 |
/* might be put into INT10_PutPixel but different vga bios |
| 525 |
implementations have different opinions about this */ |
| 526 |
IO_Write(0x3c4,0x2);IO_Write(0x3c5,0xf); |
| 527 |
} |
| 528 |
for (Bit8u h=0;h<cheight;h++) { |
| 529 |
Bit8u bitsel=128; |
| 530 |
Bit8u bitline = mem_readb(Real2Phys( fontdata )); |
| 531 |
fontdata = RealMake( RealSeg( fontdata ), RealOff( fontdata ) + 1); |
| 532 |
Bit16u tx=(Bit16u)x; |
| 533 |
while (bitsel) { |
| 534 |
if (bitline&bitsel) INT10_PutPixel(tx,(Bit16u)y,page,attr); |
| 535 |
else INT10_PutPixel(tx,(Bit16u)y,page,attr & xor_mask); |
| 536 |
tx++; |
| 537 |
bitsel>>=1; |
| 538 |
} |
| 539 |
y++; |
| 540 |
} |
| 541 |
} |
| 542 |
|
| 543 |
void INT10_WriteChar(Bit8u chr,Bit8u attr,Bit8u page,Bit16u count,bool showattr) { |
| 544 |
if (CurMode->type!=M_TEXT) { |
| 545 |
showattr=true; //Use attr in graphics mode always |
| 546 |
switch (machine) { |
| 547 |
case EGAVGA_ARCH_CASE: |
| 548 |
page%=CurMode->ptotal; |
| 549 |
break; |
| 550 |
case MCH_CGA: |
| 551 |
case MCH_PCJR: |
| 552 |
page=0; |
| 553 |
break; |
| 554 |
} |
| 555 |
} |
| 556 |
|
| 557 |
Bit8u cur_row=CURSOR_POS_ROW(page); |
| 558 |
Bit8u cur_col=CURSOR_POS_COL(page); |
| 559 |
BIOS_NCOLS; |
| 560 |
while (count>0) { |
| 561 |
WriteChar(cur_col,cur_row,page,chr,attr,showattr); |
| 562 |
count--; |
| 563 |
cur_col++; |
| 564 |
if(cur_col==ncols) { |
| 565 |
cur_col=0; |
| 566 |
cur_row++; |
| 567 |
} |
| 568 |
} |
| 569 |
} |
| 570 |
|
| 571 |
static void INT10_TeletypeOutputAttr(Bit8u chr,Bit8u attr,bool useattr,Bit8u page) { |
| 572 |
BIOS_NCOLS;BIOS_NROWS; |
| 573 |
Bit8u cur_row=CURSOR_POS_ROW(page); |
| 574 |
Bit8u cur_col=CURSOR_POS_COL(page); |
| 575 |
switch (chr) { |
| 576 |
case 7: |
| 577 |
//TODO BEEP |
| 578 |
break; |
| 579 |
case 8: |
| 580 |
if(cur_col>0) cur_col--; |
| 581 |
break; |
| 582 |
case '\r': |
| 583 |
cur_col=0; |
| 584 |
break; |
| 585 |
case '\n': |
| 586 |
// cur_col=0; //Seems to break an old chess game |
| 587 |
cur_row++; |
| 588 |
break; |
| 589 |
case '\t': |
| 590 |
do { |
| 591 |
INT10_TeletypeOutputAttr(' ',attr,useattr,page); |
| 592 |
cur_row=CURSOR_POS_ROW(page); |
| 593 |
cur_col=CURSOR_POS_COL(page); |
| 594 |
} while(cur_col%8); |
| 595 |
break; |
| 596 |
default: |
| 597 |
/* Draw the actual Character */ |
| 598 |
WriteChar(cur_col,cur_row,page,chr,attr,useattr); |
| 599 |
cur_col++; |
| 600 |
} |
| 601 |
if(cur_col==ncols) { |
| 602 |
cur_col=0; |
| 603 |
cur_row++; |
| 604 |
} |
| 605 |
// Do we need to scroll ? |
| 606 |
if(cur_row==nrows) { |
| 607 |
//Fill with black on non-text modes and with 0x7 on textmode |
| 608 |
Bit8u fill = (CurMode->type == M_TEXT)?0x7:0; |
| 609 |
INT10_ScrollWindow(0,0,(Bit8u)(nrows-1),(Bit8u)(ncols-1),-1,fill,page); |
| 610 |
cur_row--; |
| 611 |
} |
| 612 |
// Set the cursor for the page |
| 613 |
INT10_SetCursorPos(cur_row,cur_col,page); |
| 614 |
} |
| 615 |
|
| 616 |
void INT10_TeletypeOutputAttr(Bit8u chr,Bit8u attr,bool useattr) { |
| 617 |
INT10_TeletypeOutputAttr(chr,attr,useattr,real_readb(BIOSMEM_SEG,BIOSMEM_CURRENT_PAGE)); |
| 618 |
} |
| 619 |
|
| 620 |
void INT10_TeletypeOutput(Bit8u chr,Bit8u attr) { |
| 621 |
INT10_TeletypeOutputAttr(chr,attr,CurMode->type!=M_TEXT); |
| 622 |
} |
| 623 |
|
| 624 |
void INT10_WriteString(Bit8u row,Bit8u col,Bit8u flag,Bit8u attr,PhysPt string,Bit16u count,Bit8u page) { |
| 625 |
Bit8u cur_row=CURSOR_POS_ROW(page); |
| 626 |
Bit8u cur_col=CURSOR_POS_COL(page); |
| 627 |
|
| 628 |
// if row=0xff special case : use current cursor position |
| 629 |
if (row==0xff) { |
| 630 |
row=cur_row; |
| 631 |
col=cur_col; |
| 632 |
} |
| 633 |
INT10_SetCursorPos(row,col,page); |
| 634 |
while (count>0) { |
| 635 |
Bit8u chr=mem_readb(string); |
| 636 |
string++; |
| 637 |
if (flag&2) { |
| 638 |
attr=mem_readb(string); |
| 639 |
string++; |
| 640 |
}; |
| 641 |
INT10_TeletypeOutputAttr(chr,attr,true,page); |
| 642 |
count--; |
| 643 |
} |
| 644 |
if (!(flag&1)) { |
| 645 |
INT10_SetCursorPos(cur_row,cur_col,page); |
| 646 |
} |
| 647 |
} |