File: DABLITFO.LST - Tab length: 1 2 4 8 - Lines: on off - No wrap: on off

' ================================
' Direct adressing blitter test
' The top half of the screen will be the source,
' the bottom half will be the destination
'
' see http://freenet-homepage.de/ray.tscc/blitter.htm
' ======== init screen ========
' this will be used as source
' and target for bitblitting.
'
' this test program use the low resolution
'
CLS
'
' Initialize the blitter direct adressing registers
'
IF NOT @sysreg__blitter__initialize
  PRINT "Could not initialize Blitter"
  ~INP(2)
  END
ENDIF
'
' supervisor mode, watch your steps from here...
'
' Supervisor mode : watch your step !
'
super_mode%=GEMDOS(32,L:0)
IF NOT @sysreg__blitter__initialize
  PRINT "@sysreg__blitter__initialize failed"
  GOTO main_end
ENDIF
'
' ======== prepare some parameters for bitblt ========
'
' we work directly with the screen,
source%=XBIOS(2)
dest%=XBIOS(2)+16000
mode|=12 ! 3 !source + dest combination
hop|=2 !source + halftone combination
'
' copy a 104*64 pixel bloc / test : 96
' xcount& = div(add(104,15),16) + 1 !number of word to copy per bitplan per line + 1
xcount&=6+1 !number of word to copy per bitplan per line + 1
ycount&=64
'
' for a given bitplan, each the next word is at an offset of 8 bytes from the last copied word
' an here, each line is following each other.
' A line is 160 bytes wide
' Source and destination have the same feature, so xinc and yinc will be the same.
xinc&=8
yinc&=160-(2*xcount&*4-xinc&)! (width of line) - ((number of word to copy per bitplan per line + 1)*(size of a word))*(number of bitplan)
'
' ======== here we go ========
'
' constant values during the process
'
sysreg__blitter___hop|=hop|
sysreg__blitter___op|=mode|
sysreg__blitter___src_x_inc&=xinc&
sysreg__blitter___src_y_inc&=yinc&
sysreg__blitter___dest_x_inc&=xinc&
sysreg__blitter___dest_y_inc&=yinc&
'
'
' The source rectangle is at 0,0 -> 103,63 (including)
src_x1&=0
src_y1&=0
src_x2&=95 !103
src_y2&=63
' The destination is at 3,2 -> 106,65 (including) (106 mod 16 = 10)
dest_x1&=0 !3
dest_y1&=0 !2
dest_x2&=95 !106
dest_y2&=63 !65
' setting up finescrolling and masking
src_start_offset&=src_x1& AND 16
dest_start_offset&=dest_x1& AND 16
sysreg__blitter___end_mask_1&=-1 !&x0001111111111111 !00011111 11111111 (do not affect the first three (dest_x1 and 16) pixels)
sysreg__blitter___end_mask_2&=-1
sysreg__blitter___end_mask_3&=-1 !not &x111111 !11111111 11000000 (affect up to the 10th (dest_x2 mod 16) pixels of the last chunk 16 pixels )
IF (dest_start_offset&>=src_start_offset&)
  sysreg__blitter____mode2|=ADD(SUB(dest_start_offset&,src_start_offset&),64)
ELSE
  sysreg__blitter____mode2|=SUB(16,SUB(dest_start_offset&,src_start_offset&))
ENDIF
'
' initial values before copying the first bitplan
FOR bitplan|=0 TO 0
  WHILE @sysreg__blitter__is_busy
    ' wait for blitter available
  WEND
  sysreg__blitter___src_address%=source%+2*bitplan|
  sysreg__blitter___dest_address%=dest%+2*bitplan|
  sysreg__blitter___x_count&=xcount&
  sysreg__blitter___y_count&=ycount&
  @sysreg__blitter__start
  '
  ' next bitplan
  ADD sysreg__blitter___src_address%,2
  ADD sysreg__blitter___dest_address%,2
NEXT bitplan|
'
'
~INP(2)
GOTO main_end
'
'
' ======== the end ========
'
' cleanup
'
main_end:
~GEMDOS(32,L:super_mode%)
END
' ########################################################
' !BEGIN package sysreg__blitter__
'
' Blitter management and direct addressing.
'
' NOTE: direct addressing REQUIRE supervisor mode.
'
' Source for blitter registry :
' http://freenet-homepage.de/ray.tscc/blitter.htm
'
'
' (c)David SPORN
' --------------------------------------------------------
'
' **Finalizer.
' *
' **
PROCEDURE sysreg__blitter__finalize
RETURN
'
' --------------------------------------------------------
'
' **Initializer.
' *
' * Activate the blitter, if necessary, and map package variable names to
' * the blitter registry for enabling direct processing.
' *
' * @return
' *         false if there is no blitter.
' *
' **
FUNCTION sysreg__blitter__initialize
  priv__sysreg__blitter__initial_state%=XBIOS(64,-1)
  IF 0=(priv__sysreg__blitter__initial_state% AND 1)
    ' no blitter
    RETURN FALSE
  ENDIF
  priv__sysreg__blitter__initial_state%=XBIOS(64,1)
  IF 0=(priv__sysreg__blitter__initial_state% AND 1)
    ' could not activate blitter
    RETURN FALSE
  ENDIF
  priv__sysreg__blitter__base_address%=&HFFFF8A00
  priv__sysreg__blitter__halftone%=priv__sysreg__blitter__base_address%
  ABSOLUTE sysreg__blitter___src_x_inc&,priv__sysreg__blitter__base_address%+&H20
  ABSOLUTE sysreg__blitter___src_y_inc&,priv__sysreg__blitter__base_address%+&H22
  ABSOLUTE sysreg__blitter___src_address%,priv__sysreg__blitter__base_address%+&H24
  ABSOLUTE sysreg__blitter___end_mask_1&,priv__sysreg__blitter__base_address%+&H28
  ABSOLUTE sysreg__blitter___end_mask_2&,priv__sysreg__blitter__base_address%+&H2A
  ABSOLUTE sysreg__blitter___end_mask_3&,priv__sysreg__blitter__base_address%+&H2C
  ABSOLUTE sysreg__blitter___dest_x_inc&,priv__sysreg__blitter__base_address%+&H2E
  ABSOLUTE sysreg__blitter___dest_y_inc&,priv__sysreg__blitter__base_address%+&H30
  ABSOLUTE sysreg__blitter___dest_address%,priv__sysreg__blitter__base_address%+&H32
  ABSOLUTE sysreg__blitter___x_count&,priv__sysreg__blitter__base_address%+&H36
  ABSOLUTE sysreg__blitter___y_count&,priv__sysreg__blitter__base_address%+&H38
  ABSOLUTE sysreg__blitter___hop|,priv__sysreg__blitter__base_address%+&H3A
  ABSOLUTE sysreg__blitter___op|,priv__sysreg__blitter__base_address%+&H3B
  ABSOLUTE sysreg__blitter___htsync_hog_busy|,priv__sysreg__blitter__base_address%+&H3C
  ABSOLUTE sysreg__blitter___mode2|,priv__sysreg__blitter__base_address%+&H3D
  RETURN TRUE
ENDFUNC
'
' --------------------------------------------------------
'
' **Check the busy bit of the blitter.
' *
' * This bit indicates that the blitter is blitting.
' *
' * @return
' *        true if the bit is set.
' **
FUNCTION sysreg__blitter__is_busy
  RETURN (sysreg__blitter___htsync_hog_busy| AND (128))>0
ENDFUNC
'
' --------------------------------------------------------
'
' **Set the busy bit to 1 to launch the blitting.
' *
' **
PROCEDURE sysreg__blitter__start
  sysreg__blitter___htsync_hog_busy|=sysreg__blitter___htsync_hog_busy| OR (128)
RETURN
'
' --------------------------------------------------------
' --------------------------------------------------------
' !END package sysreg__blitter__
' ########################################################