	page    65,132
;SA, fast wie SA aus den NORTON UTILITIES, nur k�rzer
;Matthaei, 17.6.90,29.12.90,25.11.91,13.2.92
dbl     macro   text    ;;define a line
	ifb     <text>
	db      cr
	else
	db      text,cr
	endif
	endm

print_chr macro char	;;1 Zeichen zum
	mov	dl,char ;;Bildschirm
	mov	ah,2
	int	dos
	endm

jmps    macro   to      ;kurzer Sprung
	jmp     short to
	endm

cr	equ	0dh
lf	equ	0ah
esc	equ	1bh


dos	equ	21h
lparm	equ	0080h	;Parameterl„nge

code	segment
	assume	cs:code, ds:code, es:code

	org     100h
start:  cld             ;String-Befehle nach rechts
	jmp     start1
;ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
;Unterprogrammsammlung
;ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
;PRINT MESSAGE FOLLOWING CALL PRMSG AND ENDING WITH 0
PRMSG:  mov     word ptr PRMSG2,si
	POP     si
	CALL	PSTR
	PUSH    si      ;Returnadr.

	mov     si,0    ;mod
PRMSG2	EQU	$-2
	RET

;PRINT MESSAGE ADRESSED BY si, ENDING WITH 0
PSTR:   cld
PSTR1:  lodsb
	cmp     al,0
	jz      pstr99       ;FALLS FERTIG
	mov     dl,al
	mov     ah,02
	int     dos
	jmp     short PSTR1

pstr99: ret

prstr	MACRO	TEXT	;;PRINT STRING
	CALL	PRMSG
	DB	TEXT,0
	ENDM

ucaseg:                 ;Wandlung AL in Groá (deutsch)
	cmp     al,'a'  ;reduziert auf ue
	jb      luue
	cmp     al,'z'
	ja      luue
	sub     al,' '
	ret
;lu:     cmp     al,'„'
;        jne     luoe
;        mov     al,'Ž'
;        ret
;luoe:   cmp     al,'”'
;        jne     luue
;        mov     al, '™'
;        ret
luue:   cmp     al,'�'
	jne	luraus
	mov     al,'š'

luraus: ret
;Attribute
a_blinken equ     87h
a_normal  equ     07
a_hell    equ     0fh
a_invers  equ     70h

;Streuerzeichen f�r Attribute
blinken equ     1
normal  equ     2
hell    equ     3
invers  equ     4

;druckt die mit si adressierte zeichenkette
;die zeichenkette darf keine steuerzeichen auáer CR und Attributen enthalten
;sie beginnt mit einem Attributbyte
;sie endet mit 0h
printa:
	lodsb           ;Steuerzeichen f�r Attribut
	cmp     al,blinken
	jne     printa_a1
	mov     bl,a_blinken
	jmps    printa_a9
printa_a1:
	cmp     al,normal
	jne     printa_a2
	mov     bl,a_normal
	jmps    printa_a9
printa_a2:
	cmp     al,hell
	jne     printa_a3
	mov     bl,a_hell
	jmps    printa_a9
printa_a3:
	cmp     al,invers
	jne     printa_a4
	mov     bl,a_hell
	jmps    printa_a9
printa_a4:
	mov     bl,a_normal     ;wenn kein Attribut zutrifft
printa_a9:
	mov     bh,0
	push    bx
printa5:
	pop	bx
	push	bx
	mov 	cx,1
	lodsb           ;zeichen

	cmp     al,blinken       ;ob Attribut
	jne     printa_b1
	mov     bl,a_blinken
	jmps    printa_b8
printa_b1:
	cmp     al,normal
	jne     printa_b2
	mov     bl,a_normal
	jmps    printa_b8
printa_b2:
	cmp     al,hell
	jne     printa_b3
	mov     bl,a_hell
	jmps    printa_b8
printa_b3:
	cmp     al,invers
	jne     printa_b9       ;kein Attribut
	mov     bl,a_hell
	jmps    printa_b8
printa_b8:                      ;neues Attribut
	pop     ax              ;zum Stack
	push    bx
	jmps    printa5         ;und String weiter einlesen

printa_b9:
	cmp     al,0    ;ob fertig ?
	je	printa7 ;ja
	cmp	al,cr	;cr?
	je	printa8
	mov	ah,9
	int	10h	;zeichenausgabe
	mov	ah,3	;cursorposition ermitteln
	int	10h
	inc	dl	;x-position um 1 erh”hen
	mov	ah,2
	int	10h
	jmps	printa5

printa7:
	pop	bx
	ret

printa8:		;ausgabe crlf
	mov	ah,0eh	;funktion tty-ausgabe
	int	10h
	mov	ah,0eh
	mov	al,lf
	int	10h
	jmps	printa5

;Vergleicht einen im Feld token eingetragenen Token auf den Inhalt AUF
;Wenn Inhalt AUF ist: R�ckkehr mit Flag Equal gesetzt,
ob_auf:
	push	si
ob_auf1:
	lea     si,token
	cmp     byte ptr [si],'A'
	jne	ob_auf5
	inc	si
	cmp     byte ptr [si],'U'
	jne	ob_auf5
	inc	si
	cmp     byte ptr [si],'F'
ob_auf5:
	pop	si
	ret

;Sucht einen im Feld token eingetragenen Token in der Tabelle, deren
;Adresse in DI steht
;Wenn gefunden: R�ckkehr mit Flag Equal gesetzt,
;Di zeigt aufs Attributbyte in der Tabelle
comptok:
	push	si
	push    cx
comptok1:
	mov     cx,3            ;Tokenl„nge
	lea     si,token
comptok2:
	lodsb
	cmp	al,[di]
	jne     comptok5        ;bei ungleich
	inc     di
	loop    comptok2
	mov     ax,0
	cmp     al,ah           ;Zero Flag setzen
	pop     cx              ;hier Ausprung, wenn gefunden
	pop     si
	ret

comptok5:                       ;di �ber Tabelleneintrag hinweg
	inc     di
	loop    comptok5
	inc     di              ;�bers Screen-Attribut
	inc     di
	cmp     byte ptr [di],0
	jne     comptok1
	mov	al,0
	cmp	al,1		;not equal herstellen
	pop	cx
	pop	si
	ret

;bringt den Parameterteil, auf den si zeigt, ins Feld token
movtok:	lea	di,token
	push	cx
	mov	cx,3
movtok2:
	lodsb
	stosb
	loop	movtok2
	pop	cx
	dec     cx
	dec     cx
	dec     cx
	ret


;diverse Programmbeendigungen
ret0:	mov	al,0
	jmps    raus

ret1:	mov	al,1

;Programmende
raus:
	mov     ah,4ch
	int     dos

;Attribute
;F�r Intensit„t,Vordergrund, Hintergrund
sa_int:  db     'NOR00FET01HEL01MAT02BLI05INV07UNT04',0
sa_forg: db     'SCH30WEI37ROT31GRš32GEL33BLA34VIO35KOB36',0
sa_back: db     'SCH40WEI47ROT41GRš42GEL43BLA44VIO45KOB46',0
;Ausgabetexte,maximal 3 Parameter
s0:     db      esc,'['
p1:     db      0,0,';'     ;0 kennzeichnet gleichzeitig "leer"
p2:     db      0,0,';'
p3:     db      0,0,'m',0
token:	db	0,0,0	;Eintrag eines Tokens
;ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
start1: mov     si,lparm        ;L„nge des Parameters
	xor     ch,ch
	mov     cl,[si]
start2: inc     si      ;1 Zeichen
	cmp     byte ptr[si],' '        ;igno f�hrender Spaces
	jne     start3
	loop    start2

start3: cmp     cx,3    ;mindestens 3 Zeichen Parameterl„nge inkl. Space
	jc      hilfe   ;Ausstieg, wenn zu kurz
;       dec     cx      ;Groáschrift erzeugen
	push    cx
	push    si

start4:
	mov     al,[si]
	call    ucaseg
	mov     [si],al
	inc     si
	loop    start4

	pop     si
	pop     cx
	jmp     parm1

;Hilfstextanzeige wenn Aufruf ohne Parameter oder nur Spaces als Parameter
hilfe:  lea     si,ht1
	call    printa
	jmp     ret1

ht1:    db      hell,cr,'SA-Screen Attributes f�r'
	db      blinken,' ANSI.SYS',cr
	db      normal,'Aufruf:',cr
	db      'SA [intensity][foreground][[AUF background]',cr,cr
	db      normal,'intensity:',cr
	db      hell,  'Nor'
	db      normal,'mal  '
	db      hell,  'Fet'
	db      normal,'t  '
	db      hell,  'Hel'
	db      normal,'l  '
	db      hell,  'Mat'
	db      normal,'t  '
	db      hell,  'Bli'
	db      normal,'nkend  '
	db      hell,  'Inv'
	db      normal,'ers  '
	db      hell,  'Unt'
	db      normal,'erstrichen',cr,cr
	db      'forground and background:',cr
	db      hell,  'Sch'
	db      normal,'warz '
	db      hell,  'Wei'
	db      normal,'á    '
	db      hell,  'Rot      Gr�'
	db      normal,'n',cr
	db      hell,  'Gel'
	db      normal,'b    '
	db      hell,  'Bla'
	db      normal,'u    '
	db      hell,  'Vio'
	db      normal,'lett  '
	db      hell,  'Kob'
	db      normal,'altblau',cr,cr
	db      'Die ersten 3 Zeichen sind signifikant',cr
	db      hell,'normal GELB ist BRAUN',normal,cr
	db      0
;ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
parm1:
	cmp     cx,2            ;Mindestl„nge des 1. Parameters
	jnc     parm2
	jmp     hilfe

parm2:  call    movtok          ;token zum Feld token
	call    ob_auf          ;ist es das Schl�sselwort 'AUF' ?
	jne     parm3           ;nein
	jmp     parmauf3

parm3:  lea     di,sa_int       ;Intensit„tsparameter ?
	call    comptok
	je      parm4           ;ja
	jmp     parmvor3        ;nein, sollte Vordergrundfarbparameter sein

parm4:  push    si              ;Screen-Attribut nach P1
	lea     si,p1           ;2 Bytes!
	mov     ax,[di]
	mov     [si],ax
	pop     si

;vorlesen bis zum n„chsten Parameter
	cmp     cx,2
	jnc     parm5
	jmp     ausgabe1        ;wenn keiner vorhanden oder zu kurz
parm5:
	dec	si
parm6:  inc	si		;vorlesen bis zum n„chsten Parameter
	cmp     byte ptr[si],' '
	je	parm7
	loop	parm6
	jmp     ausgabe1        ;kein weiterer Parameter vorhanden

parm7:	inc	si	
	cmp     byte ptr[si],' '
	jne     parmvor1	;Beginn des (vermutlich) Vordergrundparameters
	loop	parm7
	jmp     ausgabe1        ;kein weiterer Parameter vorhanden
;ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ

parmvor1:
	cmp     cx,2            ;Mindestl„nge des Parameters
	jnc     parmvor2
	jmp     hilfe

parmvor2:
	call    movtok          ;token zum Feld token
	call    ob_auf          ;ist es das Schl�sselwort 'AUF' ?
	jne     parmvor3        ;nein
	jmp     parmauf3
	
parmvor3:
	lea     di,sa_forg      ;Vordergrundfarbenparameter suchen
	call    comptok
	je      parmvor4        ;ja
	jmp     hilfe           ;nein, er sollte sollte immerhin richtig sein!

parmvor4:
	push    si              ;Vordergrundparameter nach p1 oder p2
	lea     si,p1           ;2 Bytes
	cmp     byte ptr [si],0
	je      parmvor5
	lea     si,p2
parmvor5:
	mov     ax,[di]
	mov     [si],ax
	pop	si

;vorlesen bis zum n„chsten Parameter
	cmp	cx,2
	jc      ausgabe1        ;wenn keiner vorhanden oder zu kurz

	dec	si
parmvor6:
	inc     si              ;vorlesen bis zum n„chsten Parameter
	cmp     byte ptr[si],' '
	je      parmvor7
	loop    parmvor6
	jmp     ausgabe1        ;kein weiterer Parameter vorhanden

parmvor7:
	inc     si
	cmp     byte ptr[si],' '
	jne     parmauf1        ;Beginn des (vermutlich) Wortes AUF
	loop    parmvor7
	jmp     ausgabe1        ;kein weiterer Parameter vorhanden
;ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
parmauf1:
;vorlesen bis zum n„chsten Parameter
	cmp	cx,2
	jc      ausgabe1        ;wenn keiner vorhanden oder zu kurz

parmauf2:
	inc     si              ;vorlesen bis zum n„chsten Parameter
	cmp     byte ptr[si],' '
	je      parmauf3
	loop    parmauf2
	jmp     ausgabe1        ;kein weiterer Parameter vorhanden

parmauf3:
	inc     si
	cmp     byte ptr[si],' '
	jne     parmauf5        ;Beginn des (vermutlich)
	loop    parmauf3        ;Hintergrundfarbparameters
	jmp     ausgabe1        ;kein weiterer Parameter vorhanden

parmauf5:
	cmp     cx,2            ;Mindestl„nge des Parameters
	jnc     parmauf12
	jmp     hilfe

parmauf12:
	call    movtok          ;token zum Feld token
	
parmauf13:
	lea     di,sa_back      ;Hintergrundfarbenparameter suchen
	call    comptok
	je      parmauf14       ;ja
	jmp     hilfe           ;nein, er sollte sollte immerhin richtig sein!

parmauf14:
	push    si              ;Hintergrundparameter nach p1, p2 oder p3
	lea     si,p1           ;2 Bytes!
	cmp     byte ptr [si],0
	je      parmauf15
	lea     si,p2
	cmp     byte ptr [si],0
	je      parmauf15
	lea     si,p3
parmauf15:
	mov     ax,[di]
	mov     [si],ax

ausgabe1:
	lea     di,p2           ;Ausgabeparameter anpassen, da u.U.
	cmp     byte ptr [di],0 ;nicht alle Parameter besetzt worden sind
	je      ausgabe3
	lea     di,p3
	cmp     byte ptr [di],0
	jne     ausgabe5
ausgabe3:
	dec     di              ;Semikolon im Ausgabestring durch m ersetzen
	mov     byte ptr [di],'m'
ausgabe5:
	lea     si,s0           ;Beginn Parametertext
	call    pstr            ;Stringausgabe

ausg99: jmp     ret0

code    ends
	end	start

