'===========================================================================
' Subject: DEFAULT DATA IN DAC & AC           Date: 03-17-99 (13:15)       
'  Author: Jacob Wieles                       Code: QB, QBasic, PDS, PB    
'  Origin: jacwls@worldonline.nl            Packet: EGAVGA.ABC
'===========================================================================
'program      : DACAC12A.BAS  (15-03-99)
'               Shows the default DAC and AC data
'which basic  : PowerBASIC and Q(uick)BASIC
'auteur       : Jacob Wieles

defint a-z
dim dac(63,2),newpal(63),oldpal(15)
cls
color 14
print"  This program give a look in SCREEN 12 for :"
print
print"  A.  Which color-index from the Digital Analog Converter (DAC)"
print"      are assigned to one of the attributes 0 t/m 15 of the"
print"      Attribute Controler (AC).":?
print"  B.  Which color-data is in the Digital Analog Converter.":?:?
print"  For doing like the statement PALETTE USING, there is make a sub"
print"  >> NewPaletteUsing << for using in Power- and in Q(uick)BASIC."
print"  The sub write data direct in the Attribute Controler.":?
print"  After a key hit the program looks for the possibility of SCREEN 12."
print
print"  The program stop if there is an error."
call NextKeyHit(19,31,"next")
cls
on error goto GeenVGA
screen 12

sub GetDacData(dummy())
  out &H3C7,0
  for i=0 to 63
    for j=0 to 2
      dummy(i,j)=inp(&H3C9)
    next j
  next i
end sub

sub GetAttrContr(dummy())
  dummy=inp(&H3DA)
  for i=0 to 15
    out &H3C0,i
    out &H3C0,inp(&H3C1)
    dummy(i)=inp(&H3C1)
  next i
  out &H3C0,32
end sub

sub NewPaletteUsing(dummy(),index)
  dummy=inp(&H3DA)
  for attr=0 to 15
    col=dummy(attr+index)
    if col<>-1 then
      out &H3C0,attr
      out &H3C0,col and 63
    end if
  next attr
  out &H3C0,32
end sub

sub NextKeyHit(r,k,fillup$)
  while inkey$<>"":wend
  locate r,k
  print"Hit a key for ";fillup$;".";
  while inkey$="":wend
  locate r,k
  print"               ";
  print space$(len(fillup$))
end sub
'========================================================================
call GetAttrContr(oldpal()) ' Save the default palette in array oldpal().
if oldpal(15)=15 then
  wbas$=" with Q(uick)BASIC."
else
  wbas$=" with PowerBASIC."
end if
cls
call GetDacData(dac())      ' Save DAC-data in array dac().
w!=timer
while timer<w!+1:wend
' ******> Drawing boxes and show the color-index and attribute <******
ybox=16
for i=0 to 15
  xi=72+i*32
  line(xi,ybox+2)-step(30,2*ybox),15,b
  paint(xi+15,ybox+4),i,15
next i
locate 5,1:print"Attrib. :"
for i=0 to 15
  p=i:gosub NumberStr
  locate 5,11+i*4
  print pr$
next i
locate 6,1:print"Color   :"
for i=0 to 15
  color 15
  p=oldpal(i):gosub NumberStr
  locate 6,11+i*4
  if p<>i then color 14
  print pr$
next i
color 15
locate 8,14
print"The 16 default colors in ";
print"SCREEN 12";wbas$
call NextKeyHit(10,31,"next")
for i=0 to 4
  locate 5+i,1
  print space$(75);
next i
for i=0 to 63
  newpal(i)=i
next i
color(15)
locate 7,1
print"               DAC-INDEX";
print" INTENS.RED INTENS.GREEN";
print" INTENS.BLUE"
'**********************>  Show the DAC data <**************************
for count=0 to 3
  locate 5,1
  print"Color :";
  call NewPaletteUsing(newpal(),count*16) ' New Palette color in AC
  for j=0 to 15
    k=count*16+j
    p=k
    gosub NumberStr
    locate 5,11+j*4:print pr$
    locate 8+j,22:print pr$
    for l=0 to 2
      p=dac(k,l):gosub NumberStr
      locate 8+j,34+12*l:print pr$
    next l
  next j
  call NextKeyHit(1,1,"next")
  locate 5,1:print space$(75);
  for row=0 to 16
    locate 8+row,1
    print space$(75);
  next row
next count
locate 7,1:print space$(75)
call NewPaletteUsing(oldpal(),0) 'Reset Attribute Controler
locate 5,27
print"The Attribute Controler is reset."
endprog:
  call NextKeyHit(7,31,"end")
cls
screen 0
w!=timer  'prevent screen flicker
while timer<w!+1:wend
color 15
print" Thanks for running this program. Hit a key for the source.";
end

NumberStr:
pr$=right$(str$(p),len(str$(p))-1)
if len(pr$)=1 then pr$="0"+pr$
return

GeenVGA:
cls
print"  There is no VGA configuration."
resume endprog
