'===========================================================================
' Subject: SPLIT SCREEN COLOR ATTRIBUTE       Date: 08-05-96 (16:52)       
'  Author: Egbert Zijlema                     Code: PB                     
'  Origin: E.Zijlema@uni4nn.iaf.nl          Packet: PB.ABC
'===========================================================================
' SPLITCLR.BAS    - splits the screen color attribute in fore- and background
'                   the demo shows 2 methods, use the 1 you prefer

' Author          : Egbert Zijlema (E.Zijlema@uni4nn.iaf.nl)
' Date            : August 5, 1996
' Copyright status: Public Domain

DEFINT A-Z

CLS
  row = 10
  col = 10
  text$ = " Egbert"
  COLOR 14, 4         ' yellow on red
  LOCATE row, col
  PRINT text$

  ' show result on next row (after 2 seconds)
  SLEEP 2
  FOR action = 1 TO LEN(text$)
    SplitColor row, col, character$, fore, back
    LOCATE row + 1, col
    COLOR fore, back
    PRINT character$
    INCR col
    DELAY .1               ' just for the demo
  NEXT

  COLOR 7, 0
  LOCATE 25, 1
  PRINT "Press any key to proceed";
  DO
  LOOP UNTIL LEN(INKEY$)
  LOCATE 25, 1
  PRINT SPACE$(80);

  ' now let's use the video segment
  VidSeg = &HB800     ' assume color card
  row = 10
  text$ = " Zijlema "
  COLOR 14, 4
  LOCATE row, col
  PRINT text$

  DELAY 2
  FOR action = 1 TO LEN(text$)
    CALL ColorSplit(row, col, character, attri)
    offset = row * 160 + (col - 1) * 2      ' next row!
    DEF SEG = VidSeg
    POKE offset, character
    POKE offset + 1, attri
    DEF SEG
    INCR col
    DELAY .1
  NEXT
  COLOR 7, 0            ' restore default
  LOCATE 10, 10: PRINT SPACE$(16);
END

SUB SplitColor (row, col, character$, fore, back)
  ' using POWER BASIC's SCREEN function
  char = SCREEN(row, col)
  character$ = CHR$(char)
  attri = SCREEN(row, col, 1)
  fore = attri MOD 16
  back = attri \ 16
END SUB

SUB ColorSplit (row, col, character, attri)
  ' using video segment
  SHARED VidSeg
  DEF SEG = VidSeg
  offset = (row - 1) * 160 + (col - 1) * 2
  character = PEEK(offset)
  attri = PEEK(offset + 1)
  DEF SEG
END SUB
