* Tests the SUPER_BITMAP feature of ConMan

         INCLUDE  "exec/types.i"
         INCLUDE  "exec/macros.i"

         STRUCTURE BitMap,0
         WORD     bm_BytesPerRow
         WORD     bm_Rows
         BYTE     bm_Flags
         BYTE     bm_Depth
         WORD     bm_Pad
         STRUCT   bm_Planes,8*4
         LABEL    bm_SIZEOF

         XREF     _AbsExecBase

         XLIB     CloseLibrary
         XLIB     FreeMem
         XLIB     OpenLibrary
         XLIB     AllocMem

         XLIB     AllocRaster
         XLIB     FreeRaster
         XLIB     InitBitMap

         XLIB     Close
         XLIB     Execute
         XLIB     Open

* BitMap parameters
DEPTH    EQU      1
WIDTH    EQU      400
HEIGHT   EQU      300

STACKBF  SET      240
start    movea.l  _AbsExecBase,a6
         lea      -STACKBF(sp),sp

         lea      DOSLib(pc),a1
         moveq    #0,d0
         CALLSYS  OpenLibrary
         movea.l  d0,d5

         lea      GfxLib(pc),a1
         moveq    #0,d0                ; any version
         CALLSYS  OpenLibrary
         movea.l  d0,a5

         moveq    #bm_SIZEOF,d0
         move.l   #1<<16!1<<1,d1       ; MEMF_CLEAR!MEMF_CHIP
         CALLSYS  AllocMem
         tst.l    d0                   ; success?
         beq      CloseGfx             ; no
         movea.l  d0,a2

         ; Initialize the bitmap ...

         movea.l  a2,a0                ; bitmap
         moveq    #DEPTH,d0            ; depth
         move.l   #WIDTH,d1            ; width
         move.l   #HEIGHT,d2           ; height
         exg      a5,a6
         CALLSYS  InitBitMap

         ; Allocate the bit planes ...

         moveq    #0,d2
         move.b   bm_Depth(a2),d2      ; load depth
         subq.w   #1,d2                ; loop count
         lea      bm_Planes(a2),a3     ; array pointer

1$:      move.l   #WIDTH,d0
         move.l   #HEIGHT,d1
         CALLSYS  AllocRaster          ; D0=plane
         move.l   d0,(a3)+             ; install it
         dbeq     d2,1$                ; loop back
         exg      a5,a6
         beq.s    CleanUp              ; ... failure

         ; Build the console window specification ...

         movea.l  sp,a0
         lea      CONName(pc),a1       ; name prefix

2$:      move.b   (a1)+,(a0)+
         bne.s    2$
         subq.l   #1,a0

         move.l   a2,d0                ; bitmap pointer
         bsr      CVx2c                ; A0=scan

         lea      CONSpec(pc),a1
3$:      move.b   (a1)+,(a0)+
         bne.s    3$
         subq.l   #1,a0

         ; Open the console and use it for a CLI ...

         exg      d5,a6
         move.l   sp,d1                ; console name
         move.l   #1005,d2             ; MODE_NEWFILE
         CALLSYS  Open                 ; D0=stream
         move.l   d0,d4                ; success?
         beq.s    4$                   ; no

         lea      NullComm(pc),a1
         move.l   a1,d1                ; null command
         move.l   d4,d2                ; input stream
         moveq    #0,d3
         CALLSYS  Execute

4$:      move.l   d4,d1
         CALLSYS  Close
         exg      d5,a6

CleanUp  lea      bm_Planes(a2),a3
         exg      a5,a6

1$:      move.l   (a3)+,d0             ; a plane?
         beq.s    2$                   ; no
         movea.l  d0,a0
         move.l   #WIDTH,d0
         move.l   #HEIGHT,d1
         CALLSYS  FreeRaster
2$:      subq.b   #1,bm_Depth(a2)      ; any left?
         bhi.s    1$                   ; no
         exg      a5,a6

         ; Release the bitmap ...

         movea.l  a2,a1
         moveq    #bm_SIZEOF,d0
         CALLSYS  FreeMem

CloseGfx movea.l  a5,a1
         CALLSYS  CloseLibrary

CloseDOS movea.l  d5,a1
         CALLSYS  CloseLibrary

         lea      STACKBF(sp),sp
         rts

* ============================     CVx2c     ===========================
* Converts a longword to hex digits.
* Registers:   A0 -- buffer
*              D0 -- value
* Return:      A0 -- updated scan
CVx2c
         lea      8(a0),a1             ; end of buffer

1$:      rol.l    #4,d0                ; shift nibble
         moveq    #$0F,d1              ; nibble mask
         and.b    d0,d1                ; extract nibble
         cmpi.b   #9,d1                ; <= 9?
         bls.s    2$                   ; yes
         addi.b   #'A'-'0'-10,d1       ; add 'A' offset
2$:      addi.b   #'0',d1              ; add '0' offset
         move.b   d1,(a0)+             ; insert digit
         cmpa.l   a0,a1                ; at end?
         bhi.s    1$                   ; no

         rts

DOSLib   dc.b     'dos.library',0
GfxLib   dc.b     'graphics.library',0

CONName  dc.b     'CNC:S*/B',0
CONSpec  dc.b     '/0/0/300/100/SuperBitMap!/c',0
NullComm dc.b     0

         END
