    ************************************
    *   TBAR v1.0 was written in 1994  *
    *        by Grzegorz Królik        *
    * This program is FreeWare, it can *
    *  be freely distributed, but you  *
    *        mustn't change it.        *
    ************************************

        incdir  "DEVPAC_ASM_3.02ß:Include/"
        include "exec/exec_lib.i"
        include "libraries/dos_lib.i"
        include "intuition/intuition.i"
        include "intuition/intuition_lib.i"

call    macro
        jsr     _LVO\1(a6)
        endm

        section "TBAR v1.0",code

Start:
	move.l	a0,a5                  ;We save the arguments taken
	move.l	a0,a4                  ;from CLI
	adda.l	d0,a4
        move.l  4.w,a6
	lea	IntuitionName(pc),a1   ;We open needed libraries
        moveq   #0,d0
	call	OpenLibrary            ;This opens the intuition.library
	move.l	d0,d6
	lea	DosName(pc),a1
        moveq   #0,d0
	call	OpenLibrary            ;This opens the dos.library
	move.l	d0,d7

RemSpaces:
        suba.w	#1,a4                  ;This loop removes unneeded spaces
	cmpi.b	#32,-1(a4)             ;given behind the arguments for the
	beq.s	RemSpaces              ;purpose of safety
	move.l	d6,a3
	adda.w	#790,a3                ;Private part of IntuitionBase
	cmpa.l	a5,a4                  ;There is no more arguments in the
	beq.w	SetStandard            ;CLI, so set the standard border
	cmpi.b	#"?",(a5)              ;Check for common '?', if there is
	beq.w	Usage                  ;one, show usage
	cmpi.b	#"-",(a5)              ;Check for '-', if there is one
	beq.s	CheckZ                 ;check for first argument in list
	move.l	a5,a0                  ;A0 = CLI parameters
	move.l	a0,a1
	moveq	#0,d1
	moveq	#0,d2

ReadParams:                            ;This routine reads the CLI
        move.b	(a0)+,d0               ;parameters
	cmpi.b	#",",d0                ;Is there any ',' between the
	beq.s	ReadParams             ;figures ,yes there is, so read
	cmpi.b	#" ",d0                ;the next part of the pattern
	beq.s	ReadParams             ;Else check for ' ' and do the
	cmpa.l	a4,a0                  ;same. If this was the last figure
	bgt.s	SetOwnBorder           ;set the border
	subi.b	#48,d0
	cmpi.b	#9,d0                  ;What is the next, a figure
	ble.s	Figure                 ;or a letter
	subi.b	#7,d0
	cmpi.b	#15,d0
	ble.s	Figure                 ;Jump if this is the capital letter
	subi.b	#32,d0                 ;The difference between a small and
                                       ;a capital letters is 32 (hex $20)
Figure:
        andi.b	#15,d0                 ;We send our bit to D1
	or.b	d0,d1
	tst.b	d2                     ;Are there two bits in D1 yet?
	bne.s	Send                   ;no, so send the next bit
	lsl.b	#4,d1                  ;Make a place for the next bit
	moveq	#1,d2                  ;A message for Sender
	bra.s	ReadParams

Send:
        move.b	d1,(a1)+               ;We send a byte, it's two bits
	moveq	#0,d2                  ;We clear the message for Sender
	moveq	#0,d1                  ;and make a place for the next two
	bra.s	ReadParams             ;bits

SetOwnBorder:	                       ;This sets the border according
        move.l	a5,a0                  ;to given pattern
	bra.s	SetBorder

CheckZ:	                               ;This checks if the option
        adda.w	#1,a5                  ;given by user is '-z'
	cmpi.b	#"z",(a5)
	bne.s	CheckS
	lea	ZebraPattern(pc),a0
	bra.s	SetBorder

CheckS:	                               ;This checks if the option
        cmpi.b	#"s",(a5)              ;given by user is '-s'
	bne.s	CheckO
	lea	StripesPattern(pc),a0
	bra.s	SetBorder

CheckO:	                               ;This cheecks if the option
        cmpi.b	#"o",(a5)              ;given by user is '-o'
	bne.s	CheckH
	lea	OpenPattern(pc),a0
	bra.s	SetBorder

CheckH:	                               ;This checks if the option
        cmpi.b	#"h",(a5)              ;given by user is '-h'
	bne.s	CheckD
	lea	HeartPattern(pc),a0
	bra.s	SetBorder

CheckD:	                               ;This checks if the option
        cmpi.b	#"d",(a5)              ;given by user is '-d'
	bne.s	SetStandard
	lea	DapplePattern(pc),a0
	bra.s	SetBorder

SetStandard:	                       ;This routine sets the standard
        lea	StandardPattern(pc),a0 ;border
	bra.s	SetBorder

Usage:	                               ;This routine displays the text
        move.l	d7,a6
	call	Output                 ;This looks for the handle
	move.l	d0,d1                  ;for the output channel for the
	lea	Use(pc),a0             ;text
	move.l	a0,d2
	moveq	#76,d3
	call	Write                  ;This prints the text in the
	bra.s	End                    ;output found earlier

SetBorder:	                       ;This routine sets the border
        move.l	a3,a1
	moveq	#3,d3
Loop:
        move.l	(a0)+,(a1)+            ;We copy our pattern to A1
	dbf	d3,Loop
	move.l	d6,a6
	move.l	ib_ActiveWindow(a6),a0
	call	RefreshWindowFrame

End:	                               ;We close libraries which
        move.l	4.w,a6                 ;were opened before
	move.l	d6,a1
	call	CloseLibrary
	move.l	d7,a1
	call	CloseLibrary
	rts
	
IntuitionName:	
        dc.b	"intuition.library",0
DosName:
        dc.b	"dos.library",0
Use:
        dc.b    155,"1;33mTBAR",155
        dc.b    "0;32m - by Grzegorz Królik",10
        dc.b    155,"0;31mUsage: TBAR (-zsohd) (hex data)",10

                                       ; Data for program

StandardPattern:
        dc.w    %0000000000000000
        dc.w    %0000000000000000
        dc.w    %1111111111111111
        dc.w    %1111111111111111
        dc.w    %0000000000000000
        dc.w    %0000000000000000
        dc.w    %1111111111111111
        dc.w    %1111111111111111

ZebraPattern:
        dc.w    %0101010101010101
        dc.w    %0101010101010101
        dc.w    %1010101010101010
        dc.w    %1111111111111111
        dc.w    %0011001100110011
        dc.w    %1100110011001100
        dc.w    %1111111111111111
        dc.w    %1010101010101010

StripesPattern:
        dc.w    %1111000011110000
        dc.w    %0011110000111100
        dc.w    %0000111100001111
        dc.w    %1100001111000011
        dc.w    %1111000011110000
        dc.w    %0011110000111100
        dc.w    %0000111100001111
        dc.w    %1100001111000011

OpenPattern:
        dc.w    %1111111111111111
        dc.w    %1111111111111111
        dc.w    %1111111111111111
        dc.w    %1111111111111111
        dc.w    %1111111111111111
        dc.w    %1111111111111111
        dc.w    %1111111111111111
        dc.w    %1111111111111111

HeartPattern:
        dc.w    %1111111111111111
        dc.w    %1111111111111111
        dc.w    %0111110001111100
        dc.w    %1110001110001110
        dc.w    %1110000100001110
        dc.w    %0111100000111100
        dc.w    %0001111011110001
        dc.w    %0000011111000110

DapplePattern:
        dc.w    %1111111111111111
        dc.w    %1111111111111111
        dc.w    %1111111111110000
        dc.w    %1111111100000000
        dc.w    %1111000000000000
        dc.w    %0000000000001111
        dc.w    %0000000011111111
        dc.w    %0000111111111111
        end
