:
 ; online april 2013 by zantaz
 ;
 ; @ @@@@@    #  ###   ###
 ; @      @     #   # #
 ;  @@@   @      ###   ###
 ;     @  @         # #   #
 ;   @ @@@  @    ###   ###
 ;
 ; 7th test  code35.a
 ; added alpha table, added dayofweek display and set mode
 ; add SubRoutine list, added new display dayom,month,year & dayow
 ; 21aug96 22aug96 XD.
 ;
 ; 8th test  code34.a
 ; added chronograph on NMI routine, re-enabled sixty on NMI routine
 ; CTC3 count = 1, modified INDEC2, modified cronograph key routine
 ; 20aug96 21aug96 XD.
 ;
 ; 9th test  code33.a
 ; added IX dayofweek,dayofmonth,month,year & set mode
 ; improved INDEC2
 ; 12aug96 14aug96 15aug96 XD.
 ;
 ; 7th test
 ; set of command to draw on emu six DSP 7 segment
 ; 26jul96 XD.
 ; i) a byte with hi nibble = DSP number 0-5
 ;		  lo nibble = 0-7 as seg a-p
 ; 050602,151011121317
 ; ii) a two byte hi = DSP number 012345
 ;                lo = segment  abcdefgp
 ; 0f0g0c,1f1a1b1c1d1p
 ;
 ;   a0       a1
 ; f0  b0   f1  b1
 ;   g0       g1
 ; e0  c0   e1  c1
 ;   d0  p0   d1  p1
 ;
 ; 	ORG 0
 ;	SET 0,(IY+0)
 ;	SET 1,(IY+1)
 ;	SET 2,(IY+2)
 ;	SET 3,(IY+3)
 ;	SET 4,(IY+4)
 ;	SET 5,(IY+5)
 ;	SET 6,(IY+6)
 ; 	SET 7,(IY+7)
 ;
 ; 2nd test
 ; demo of features DSP 7segment
 ; Z80 CTC clock with
 ; emulator DSP 7 segment on LCD user chr
 ; added set mode
 ; 24jul96 25jul96 26jul96 XD.
 ;
 ; 0AAA0 0 ; FAAAB
 ; F000B 1 ; F000B
 ; F000B 2 ; F000B
 ; 0GGG0 3 ; 0GGG0
 ; E000C 4 ; E000C
 ; E000C 5 ; E000C
 ; 0DDD0 6 ; EDDDC
 ; 0000P 7 ; 0000P
 ;
 ;  "Equates del CTC"
 ; /CE CTC = A4
CTC0	EQU 11101100B
CTC1	EQU 11101101B
CTC2	EQU 11101110B
CTC3	EQU 11101111B
 ;
SIOBD   EQU 0xDE
SIOBC   EQU 0xDF
P1BD    EQU 0FAH
 ;
DTFLG   EQU 0x4000
REG     EQU 0x4040
LCDB    EQU 0x4080
DIV10	EQU 0x146
WRTC6   EQU 0x982
WRTD6   EQU 0x98C
PRXCH2  EQU 0x997
BLCDB2  EQU 0x9BA
WRLCD2  EQU 0x9CD
DL587M  EQU 0x9F1
LCDMT2  EQU 0x9FC
LCDMT3  EQU 0xA09
DREG    EQU 0xA16
 ;
	ORG 4100H
 ;
SIXTY	EQU 0
SEC	EQU 1
MIN	EQU 2
HOUR	EQU 3
DAYOW	EQU 4
DAYOM	EQU 5
MONTH	EQU 6
YEAR	EQU 7
 ;
CFLAG	EQU 9
 ;
CHOUR	EQU 4020H
CMIN	EQU 4021H
CSEC	EQU 4022H
CSIXTY	EQU 4023H
 ;
SETK	EQU 2
PLUSK	EQU 0
MINUSK	EQU 4
 ;
 ; start now & here
 ;
	DI
 ;
	LD A,2
	OUT (SIOBC),A
	LD A,10H ; lo byte VECT ***
	OUT (SIOBC),A
 ;
	JR START
	DEFM "XD.96"
 ;
 ; vector table old SIO new CTC
 ;
VECT:	DEFW 0xAC0
	DEFW 0xAD0
	DEFW 0xAE0
	DEFW 0xAD8
	DEFW 0xB50
	DEFW 0xB50
	DEFW 0xB50
	DEFW 0xB50
	DEFW CTCI0
	DEFW CTCI1
	DEFW CTCI2
	DEFW CTCI3
 ;
START:	LD A,41H ; hi byte VECT ***
	LD I,A
	IM 2
 ;
	LD A,20H ; lo byte VECT ***
	OUT (CTC0),A
 ; VECT table + 10H offset
 ;
 ; reset channel 0 1 2
 ;
	LD A,43H
	OUT (CTC0),A
	OUT (CTC1),A
	OUT (CTC2),A
 ; reset channel 3
	LD A,01001011B
	OUT (CTC3),A
 ;
 ; predisposizione canale 3 CTC
 ; enbl int mode cnt /16 slope neg
 ; cnt down imp ext next byte time
 ; costant no reset control word
 ;
	LD A,11001101B
	OUT (CTC3),A
 ;	LD A,60
	LD A,1
	OUT (CTC3),A
 ;
 ; let's start !
	EI
 ;
	LD HL,MSG
	CALL LCDMT3
	CALL WRLCD2
 ;
	LD IY,LCDU
 ;
	LD IX,PIX
 ;
 ; set user LCD chr 0-5 at start 2nd row
	LD BC,600H
	LD HL,LCDB+16
L00:	LD (HL),C
	INC C
	INC HL
	DJNZ L00
 ;
	CALL WRLCD2
 ;
	CALL CLRCRO
 ;
	LD HL,DSPD
	LD DE,DSPN
	LD BC,6
	LDIR
 ;
	CALL TRANIS
 ;
	CALL EMUDSP
 ;
	CALL DL587M
	CALL DL587M
 ;	CALL DL587M
 ;
	CALL XDLOGO
 ;
LP3:	LD HL,DSPX
	LD DE,DSPB
	LD BC,6
	LDIR
 ;
	CALL EMUDSP
 ;
	CALL DL587M
	CALL DL587M
 ;	CALL DL587M
 ;
	CALL CDSPBE
 ;
 ;	CALL EMUDSP
 ;
	CALL DL587M
 ;
 ;	JR LP3
 ;
LXP:	CALL DSPHMS
 ;
 ;	JR LXP
 ;
 ; '+' display Dayofmonth Month Year
 ; '-' enter chronograph mode
 ; 
	IN A,(P1BD)
	BIT PLUSK,A ; '+' pressed ?
	JR Z,L36
 	BIT MINUSK,A ; '-' pressed ?
 	JR NZ,L38
 ;
L34:	IN A,(P1BD)
	BIT MINUSK,A ; '-' released ?
	JR Z,L34
 ;
 ;	CALL XDLOGO
 ;
L35:	CALL DSPCRO
 ;
	CALL KEYCRO
 ;
	CALL KEYCLC
 ;
	CALL KEYSET
	JR Z,L38
 ;
	JR L35
 ;
 ; now display dayofmonth month year
L36:	CALL DSPDMY
 ;
	CALL DL587M
	CALL DL587M
 ;
	LD A,(IX+DAYOW)
 ;
	CALL DSPDAY
 ;
	CALL DL587M
	CALL DL587M
 ;
	IN A,(P1BD)
	BIT PLUSK,A ; '+' pressed ?
	JR Z,L36
 ;
 ; now wait release of button
L37:	IN A,(P1BD)
	BIT PLUSK,A ; '+' released ?
	JR Z,L37
 ;
 ; bit 2 P1BD -> tasto nero  >enter setup mode<  attivo alto ?
 ; bit 0 P1BD -> tasto rosso ?  >'+' increment value<  attivo basso
 ; bit 4 P1BD -> tasto grigio ?  >'-' decrement value<  attivo basso
 ;
L38:	LD IY,4020H
 ; wait the press of enter setup mode button
	IN A,(P1BD)
	BIT SETK,A ; 'set' not pressed, jump to start
	JR NZ,LXP
 ;
L39:    IN A,(P1BD)
	BIT SETK,A ; loop until 'set' is released
	JR Z,L39
 ;
 ;	LD A,23H
 ;	LD (LCDB+16),A
 ;	CALL WRLCD2
 ;
 ; now we are in set mode
 ;
	CALL XDLOGO
 ;
	CALL DSPDMY
 ;
 ; set YEAR
 ;
	LD A,(IX+YEAR)
 ;	LD (IY+10),A
	LD (IY+11),99
	LD (IY+12),0
	LD HL,DSPN+4
	CALL INDEC2
 ;	LD A,(IY+10)
	LD (IX+YEAR),A
 ;
L42:    IN A,(P1BD)
	BIT SETK,A
	JR Z,L42
 ;
 ; set MONTH
 ;
	LD A,(IX+MONTH)
 ;	LD (IY+10),A
	LD (IY+11),12
	LD (IY+12),1
	LD HL,DSPN+2
	CALL INDEC2
 ;	LD A,(IY+10)
	LD (IX+MONTH),A
 ;
L43:    IN A,(P1BD)
	BIT SETK,A
	JR Z,L43
 ;
 ; set DAYOM
 ;
	PUSH HL
	LD HL,MLEN-1
	LD A,(IX+MONTH)
	ADD A,L
	LD L,A
	LD A,(HL)
 ;	INC A
	POP HL
 ;
	LD (IY+11),A
	LD (IY+12),1
	LD A,(IX+DAYOM)
 ;	LD (IY+10),A
	LD HL,DSPN
	CALL INDEC2
 ;	LD A,(IY+10)
	LD (IX+DAYOM),A
 ;
L44:    IN A,(P1BD)
	BIT SETK,A
	JR Z,L44
 ;
	CALL XDLOGO
 ;
 ; set DAYOW
 ;
 ;	CALL CDSPBE
 ;
	LD HL,3A3AH
	LD (DSPN),HL
	LD (DSPN+4),HL
 ;
	LD A,(IX+DAYOW)
 ;	LD (IY+10),A
	LD (IY+11),7
	LD (IY+12),1
	LD HL,DSPN+2
	CALL INDEC2
 ;	LD A,(IY+10)
	LD (IX+DAYOW),A
 ;
 ; in A dayofweek
	CALL DSPDAY
 ;
	CALL DL587M
	CALL DL587M
	CALL DL587M
 ;
L45:    IN A,(P1BD)
	BIT SETK,A
	JR Z,L45
 ;
	CALL XDLOGO
 ;
	LD (IX+SEC),0 ; reset secs
 ;
	CALL DSPHMS
 ;
 ; set HOUR
 ;
	LD A,(IX+HOUR)
 ;	LD (IY+10),A
	LD (IY+11),23
	LD (IY+12),0
	LD HL,DSPN
	CALL INDEC2
 ;	LD A,(IY+10)
	LD (IX+HOUR),A
 ;
L40:    IN A,(P1BD)
	BIT SETK,A
	JR Z,L40
 ;
 ; set MIN
 ;
	LD A,(IX+MIN)
 ;	LD (IY+10),A
	LD (IY+11),59
	LD (IY+12),0
	LD HL,DSPN+2
	CALL INDEC2
 ;	LD A,(IY+10)
	LD (IX+MIN),A
 ;
L41:    IN A,(P1BD)
	BIT SETK,A
	JR Z,L41
 ;
 ; reset SEC
 ;	XOR A
	LD (IX+SEC),0
 ; reset channel 3
	LD A,01001011B
	OUT (CTC3),A
 ;
 ; predisposizione canale 3 CTC
 ; enbl int mode cnt /16 slope neg
 ; cnt down imp ext next byte time
 ; costant no reset control word
 ;
	LD A,11001101B
	OUT (CTC3),A
 ;	LD A,60
	LD A,1
	OUT (CTC3),A
 ;
	JP LXP
 ;
 ; DiSPlay DAY of week (letter)
 ; in:  reg A DAYOW (1-7)
 ; out: 
 ; usd:
 ;
 ; trash AF
DSPDAY:	PUSH BC
	PUSH DE
	PUSH HL
 ; reg A = 1 to 7
	LD C,A  ; store A
	ADD A,A ; *2
	ADD A,A ; *4
	ADD A,C ; *5
	ADD A,C ; *6
 ; a*6
	LD HL,DAYN-6
 ;
	ADD A,L ; > ! <
	LD L,A  ; > ! <
 ; hl-6+(a*6)
	LD DE,DSPN
	LD BC,6
	LDIR
 ;
	CALL TRALIS
 ;
	CALL EMUDSP
 ;
	POP HL
	POP DE
	POP BC
 ;
	RET
 ;
 ; KEY CLear Cronograph locations:
 ; if '-' key is pressed clear the locations,
 ; wait the release of key
 ; trash AF
 ;
KEYCLC:	IN A,(P1BD)
	BIT MINUSK,A ; '-' pressed ?
	RET NZ  ; return if not
 ;
	BIT 0,(IX+CFLAG)
	JR NZ,CLC0
 ;
	CALL CLRCRO
 ;
CLC0:	IN A,(P1BD)
	BIT MINUSK,A ; '-' released ?
	JR Z,CLC0
 ;
	RET
 ;
 ; KEY SET pressed ? if yes wait key release
 ; return A = 00H if 'set' is pressed
 ; trash AF
KEYSET:	IN A,(P1BD)
	BIT SETK,A ; 'set' pressed ?
	RET NZ  ; return if not
 ;
SET0:	IN A,(P1BD)
	BIT SETK,A ; 'set' released ?
	JR Z,SET0
 ;
	XOR A
 ;
	RET
 ;
 ; CLeaR CROnograph locations
 ; trash AF
CLRCRO:	XOR A
	LD (CHOUR),A
 	LD (CMIN),A
 	LD (CSEC),A
	LD (CSIXTY),A
 ;
	RET
 ;
 ; KEY CROnograph:
 ; if '+' key is pressed toggle the bit 0 of CFLAG,
 ; wait the release of key
 ; trash AF
 ;
KEYCRO:	IN A,(P1BD)
	BIT PLUSK,A ; '+' pressed ?
	RET NZ  ; return if not
 ;
	BIT 0,(IX+CFLAG) ; test  cronograph
 ;
	JR NZ,PLUS0 ; jump if not zero
 ;
	SET 0,(IX+CFLAG) ; start cronograph
	JR PLUS1
 ;
PLUS0:	RES 0,(IX+CFLAG) ; stop  cronograph
 ;
PLUS1:	IN A,(P1BD)
	BIT PLUSK,A ; '+' released ?
	JR Z,PLUS1
 ;
	RET
 ;
 ; DiSPlay Hour Min Sec
 ; trash AF
 ;
DSPHMS:	PUSH HL
 ;
	LD HL,DSPN
 ;
	LD A,(IX+HOUR)
	CALL PRDCH7
 ;
	LD A,(IX+MIN)
	CALL PRDCH7
 ;
	LD A,(IX+SEC)
	CALL PRDCH7
 ;
	CALL TRANIS
 ;
 ; add section of p DSP 2 & 4 blink 1/2 sec 
	LD A,(IX+SIXTY)
	CP 29
	JR NC,HMS0
	SET 7,(IX+17) ; DSP 2
	SET 7,(IX+19) ; DSP 4
 ;
HMS0:	CALL EMUDSP
 ;
	POP HL
 ;
	RET
 ;
 ; DiSPlay Dayofmonth Month Year
 ; trash AF
 ;
DSPDMY:	PUSH HL
 ;
	LD HL,DSPN
 ;
	LD A,(IX+DAYOM)
	CALL PRDCH7
 ;
	LD A,(IX+MONTH)
	CALL PRDCH7
 ;
	LD A,(IX+YEAR)
	CALL PRDCH7
 ;
	CALL TRANIS
 ;
 ; add section of p DSP 2 & 4
	SET 7,(IX+17) ; DSP 2
	SET 7,(IX+19) ; DSP 4
 ;
	CALL EMUDSP
 ;
	POP HL
 ;
	RET
 ;
 ; DiSPlay CROnograph
 ; trash AF
 ;
DSPCRO:	PUSH HL
 ;
	LD HL,DSPN
 ;
	LD A,(CHOUR)
	CALL PRDCH7
 ;
	LD A,(CMIN)
	CALL PRDCH7
 ;
	LD A,(CSEC)
	CALL PRDCH7
 ;
	CALL TRANIS
 ;
	SET 7,(IX+17) ; DSP 2
	LD A,(CSIXTY)
 ;	CP 29
 ;	JR NC,CRO0
	CP 30
	JR C,CRO0
	SET 7,(IX+19) ; DSP 4
 ;
CRO0:	CALL EMUDSP
 ;
	POP HL
 ;
	RET
 ;
 ; INDEC2 inc & dec (IY+10)
 ;
 ; in:  reg A actual value
 ;      reg HL point to DSPB position
 ;      (IY+11) upper limit
 ;      (IY+12) lower limit
 ; out:  reg A desidered value
 ;       reg HL = HL +2
 ; usd: (IY+10) actual value/desidered value
 ; trash AF
INDEC2: LD (IY+10),A
	PUSH BC
 ;
INDEC3:	LD B,0
 ;
	IN A,(P1BD)
	BIT PLUSK,A ; '+' pressed ?
	JR NZ,ID0
	INC (IY+10)
 ;
	LD B,1
 ;
	LD A,(IY+11)
	INC A
	CP (IY+10)
	JR NZ,ID0
	LD A,(IY+12)
	LD (IY+10),A
 ;
ID0:	IN A,(P1BD)
	BIT MINUSK,A ; '-' pressed ?
	JR NZ,ID1
	DEC (IY+10)
 ;
	LD B,1
 ;
	LD A,(IY+12)
	DEC A
	CP (IY+10)
	JR NZ,ID1
	LD A,(IY+11)
	LD (IY+10),A
 ;
ID1:	BIT 0,B
	JR NZ,BLN0
 ;
	LD A,(IX+SIXTY)
	CP 29
	JR NC,BLN0
	LD A,3AH
	LD (HL),A
	INC HL
	LD (HL),A
	DEC HL
	JR BLN1
BLN0:	LD A,(IY+10)
	CALL PRDCH7
	DEC HL
	DEC HL
 ;
BLN1:	CALL TRANIS
 ;
	CALL EMUDSP
 ;
	LD BC,6500H
W00:	DEC BC
	LD A,B
	OR C
	JR NZ,W00
 ;	JR SET
 ;
 ; wait 10 50th of sec
 ;WAI:	IN A,(CTC3)
 ;	CP 9
 ;	JR NC,WAI0
 ;	ADD A,50
 ;	JR WAI1
 ;WAI0:	SUB 10
 ;WAI1:	LD C,A
 ;WAI10:IN A,(CTC3)
 ;	CP C
 ;	JR NC,WAI10
 ;
SET:	IN A,(P1BD)
	BIT SETK,A ; 'set' released ? !?
	JR NZ,INDEC3
 ;
	LD A,(IY+10)
	LD C,A
	CALL PRDCH7
 ;
	LD A,C
	POP BC
	RET
 ;
 ; print XD. LOGO on emu DSP with user LCD
 ; trash AF
XDLOGO:	PUSH HL
 ;
	CALL CDSPBE
 ;
 ;	CALL EMUDSP
 ;
	CALL DL210M
 ;
 ; reset flags
	XOR A
	LD (DSPB+7),A
 ;
	LD HL,XDEM
 ;
LPC:	CALL CALSEG
 ;
	CALL EMUDSP
 ;
	CALL DL293M
 ;
 ;	BIT 7,(IY+7)
	LD A,(DSPB+7)
	BIT 7,A
	JR Z,LPC
 ;
	CALL CDSPBE
 ;
 ;	CALL EMUDSP
 ;
	CALL DL210M
 ;
	POP HL
 ;
	RET
 ;
 ; auto-modify code
 ; SET X,(IY+Y)
 ; FD CB YY 11XX X110
 ;	DEFB "a","g","p","x"
 ;           61H 67H 70H 78H
 ;
 ; CALcolate SEGment to turn on in DSPB
 ; in:  (HL+0) segment "abcdefgp"
 ;	 "x" set bit 7 (IY+7) & ret
 ;      (HL+1) display "012345"
 ; out: HL = HL + 2
 ; jump at ERR if segment or display not allowed  
 ; trash AF
CALSEG:	PUSH IY
 ;
	LD IY,DSPB
 ;
	LD A,(HL)
 ;
	CP 78H ; x
	JR NZ,L12
 ;
	SET 7,(IY+7)
	JR L13
 ;
L12:	CP 70H ; p
	JR NZ,L10
 ;
	LD A,0FEH
	JR L11
 ;
L10:	CP 61H ; a
	JR C,ERR
 ;
	CP 68H ; g+1
	JR NC,ERR
 ;
	SUB 61H ; a
	RLCA
	RLCA
	RLCA
	ADD A,0C6H
L11:	LD (AMD+3),A
 ;
	INC HL
 ;
	LD A,(HL)
 ;
	CP 30H ; 0
	JR C,ERR
 ;
	CP 3AH ; 9+1
	JR NC,ERR
 ;
	SUB 30H ;0
	LD (AMD+2),A
 ;
	INC HL
 ;
AMD:	SET 0,(IY+0) ; automodify instruction
 ;
L13:	POP IY
 ;
	RET
 ; error routine  write # on LCD
ERR:	LD A,23H
	LD (LCDB+24),A
 ;
	CALL WRLCD2
 ;
	RET
 ;
 ; Clear DiSPlay Buffer and call EMUDSP
 ; trash AF
CDSPBE:	PUSH BC
	PUSH DE
	PUSH HL
 ;
	LD HL,DSPB
	LD DE,DSPB+1
	LD BC,6
	LD (HL),0
	LDIR
 ;
	CALL EMUDSP
 ;
	POP HL
	POP DE
	POP BC
 ;
	RET
 ;
 ; DL293M delay 293 msec @2456700Hz
 ;
DL293M: PUSH HL
	LD HL,8000H
	JR DEL
 ;
 ; DL210M delay 210 msec @2456700Hz
 ;
DL210M: PUSH HL
	LD HL,6000H
	JR DEL
 ;
 ; DL147M delay 147 msec @2456700Hz
 ;
DL147M: PUSH HL
	LD HL,4000H
 ;
DEL:	DEC HL
	LD A,H
	OR L
	JR NZ,DEL
	POP HL
	RET
 ;
 ; PRint Decimal CHar 7 segment
 ; in:  reg A  dec numb 0-99
 ;	reg HL point DSP buffer
 ; out: reg HL = HL + 2
 ; trash AF
 ; this routine is the same of PRDCH !
PRDCH7:	PUSH BC
	CALL DIV10
	LD B,A
	LD A,C
	ADD A,"0"
	LD (HL),A
	INC HL
	LD A,B
	ADD A,"0"
	LD (HL),A
	INC HL
	POP BC
	RET
 ;
 ; TRaslate six Number In 7 Segment DSP
 ; (DSPN+0/5) -traslate-> (DSPB+0/5)
 ; trash AF
 ;
TRANIS:	PUSH BC
	PUSH DE
	PUSH HL
 ;
	LD B,6
	LD HL,DSPN
	LD DE,DSPB
 ;
TR2:	LD A,(HL)
 ;
	CP 30H
	JR C,TR0
 ;
	CP 3AH
	JR NC,TR0
 ;
	PUSH HL
	LD HL,DGTM
	SUB 30H
	ADD A,L ; > ! <
	LD L,A  ; > ! <
	LD A,(HL)
	POP HL
	JR TR1
 ;
TR0:	LD A,80H
 ;
TR1:	EX DE,HL
	LD (HL),A
	EX DE,HL
 ;
	INC HL
	INC DE
 ;
	DJNZ TR2
 ;
	POP HL
	POP DE
	POP BC
 ;
	RET
 ;
 ; ONLY lower case string >!<
 ; TRaslate six Letter alpha chr In 7 Segment DSP
 ; (DSPN+0/5) -traslate-> (DSPB+0/5)
 ; trash AF
 ;
TRALIS:	PUSH BC
	PUSH DE
	PUSH HL
 ;
	LD B,6
	LD HL,DSPN
	LD DE,DSPB
 ;
TL2:	LD A,(HL)
 ;
	CP 61H ; 'a'
	JR C,TL0
 ;
	CP 7BH ; 'z'+1
	JR NC,TL0
 ;
	PUSH HL
	LD HL,DGTA
	SUB 61H
	ADD A,L ; > ! <
	LD L,A  ; > ! <
	LD A,(HL)
	POP HL
	JR TL1
 ;
TL0:	LD A,80H ; point
 ;
TL1:	EX DE,HL
	LD (HL),A
	EX DE,HL
 ;
	INC HL
	INC DE
 ;
	DJNZ TL2
 ;
	POP HL
	POP DE
	POP BC
 ;
	RET
 ;
 ; EMUlate six DSP 7 segment on LCD user chr 0-5
 ; in:  (DSPB+0) - (DSPB+5)
 ;       six digit in segment form
 ; out: ?
 ; trash AF
 ;
EMUDSP:	PUSH BC
	PUSH HL
 ;
	LD B,6
	LD HL,DSPB
 ;
 	LD A,40H
 	CALL WRTC6
 ;
EMU0:	LD A,(HL)
	CALL EMUSEG
 ;
	PUSH BC
	PUSH HL
 ;
	LD B,8
	LD HL,LCDU
EMU1:	LD A,(HL)
 ;
	CALL WRTD6
 ;	
	INC HL
	DJNZ EMU1
 ;
	POP HL
	POP BC
 ;
	INC HL
 ;
	DJNZ EMU0
 ;
	POP HL
	POP BC
 ;
	RET
 ;	
 ; mark II
 ; emulate DSP 7 segment on LCD user chr
 ; replace OUT (SEG),A with CALL EMUSEG
 ; in:  reg A dsp segment mask
 ; out: buffer ? with data for user LCD chr
 ; trash AF
 ;
EMUSEG:	PUSH BC
	PUSH DE
	PUSH HL
 ;
	PUSH IY
 ;
 ; this simple routine have a little bug !
 ;	LD B,8
 ;	LD HL,LCDU
 ;EMD0:	LD (HL),0
 ;	INC HL    ;*
 ;	DJNZ EMD0
 ;
 ; replace routine
	LD HL,LCDU
	LD DE,LCDU+1
	LD BC,8
	LD (HL),0
	LDIR
 ;
 	LD IY,LCDU
 ;
	LD C,A
	BIT 0,C ; segment A
	JR Z,SGB
 ;
	LD (IY+0),0EH
 ;
SGB:	BIT 1,C ; segment B
	JR Z,SGC
 ;
	SET 0,(IY+1)
	SET 0,(IY+2)
 ;
SGC:	BIT 2,C ; segment C
	JR Z,SGD
 ;
	SET 0,(IY+4)
	SET 0,(IY+5)
 ;
SGD:	BIT 3,C ; segment D
	JR Z,SGE
 ;
	LD (IY+6),0EH
 ;
SGE:	BIT 4,C ; segment E
	JR Z,SGF
 ;
	SET 4,(IY+4)
	SET 4,(IY+5)
 ;
SGF:	BIT 5,C ; segment F
	JR Z,SGG
 ;
	SET 4,(IY+1)
	SET 4,(IY+2)
 ;
SGG:	BIT 6,C ; segment G
	JR Z,SGP
 ;
	LD (IY+3),0EH
 ;
SGP:	BIT 7,C ; dec point
	JR Z,SGX
 ;
	LD (IY+7),01H
 ;
SGX:	POP IY
 ;
	POP HL
	POP DE
	POP BC
 ;
	RET
 ;
 ; mark II
 ; gestione interrupt counter 3
 ;
CTCI3:	EX AF,AF
 ;
 	INC (IX+SIXTY)
 	LD A,60
 	CP (IX+SIXTY)
 	JR NZ,NMI0
 	LD (IX+SIXTY),0 ; +1 sec
	INC (IX+SEC)
	LD A,60
	CP (IX+SEC)
	JR NZ,NMI0
	LD (IX+SEC),0   ; +1 min
	INC (IX+MIN)
	LD A,60
	CP (IX+MIN)
	JR NZ,NMI0
	LD (IX+MIN),0   ; +1 hour
	INC (IX+HOUR)
	LD A,24
	CP (IX+HOUR)
	JR NZ,NMI0
	LD (IX+HOUR),0  ; +1 day
	INC (IX+DAYOW)
	LD A,8
	CP (IX+DAYOW)
	JR NZ,NMI1
	LD (IX+DAYOW),1 ; +1 week (not useful)
NMI1:	PUSH HL
	LD HL,MLEN-1
	LD A,(IX+MONTH)
	ADD A,L
	LD L,A
	LD A,(HL)
	INC A
	POP HL
	INC (IX+DAYOM)
	CP (IX+DAYOM)
	JR NZ,NMI0
	LD (IX+DAYOM),1 ; +1 month
	INC (IX+MONTH)
	LD A,13
	CP (IX+MONTH)
	JR NZ,NMI0
	LD (IX+MONTH),1 ; +1 year
	INC (IX+YEAR)
	LD A,100
	CP (IX+YEAR)
	JR NZ,NMI0
	LD (IX+YEAR),0  ; +1 century !?!
 ;
NMI0:	BIT 0,(IX+CFLAG)
	JR Z,NMI2
 ;	
	LD A,(CSIXTY)
	INC A
	CP 60
	JR NZ,CT3
	LD A,(CSEC)
	INC A
	CP 60
	JR NZ,CT2
	LD A,(CMIN)
	INC A
	CP 60
	JR NZ,CT1
	LD A,(CHOUR)
	INC A
	CP 24
	JR NZ,CT0
	XOR A
CT0:	LD (CHOUR),A
	XOR A
CT1:	LD (CMIN),A
	XOR A
CT2:	LD (CSEC),A
	XOR A
CT3:	LD (CSIXTY),A
 ;
NMI2:	EX AF,AF
CTCI0:
CTCI1:
CTCI2:	EI
	RETI
 ;
	DEFM "XD.'96"
 ;
 ; demo data of XD. logo
 ;XDEM:	DEFM "f0g0c0f1a1b1c1d1p1xx" ; 1st trial
XDEM:	DEFM "f0g0c0d1c1b1a1f1p1xx" ; 2nd trial
 ;	
 ; bit      7 6 5 4 3 2 1 0
 ; segment  p g f e d c b a
 ;
 ; demo data XD.
DSPX:	DEFB 01100100B,10101111B
	DEFB 01100100B,10101111B
	DEFB 01100100B,10101111B
 ;
 ; demo data
DSPD:	DEFM "012345"
 ;
PIX:	DEFB 0,0,59,6,1,12,8,96,0,0
 ;
 ; DSP Nunber buffer (6bytes)
DSPN:	DEFW 0
	DEFW 0
	DEFW 0
 ;
 ; DSP Buffer (6bytes)
DSPB:	DEFW 0
	DEFW 0
	DEFW 0
 ; optional flags
OPTF:	DEFW 0
 ;
 ; buffer in RAM for user LCD chr
LCDU:	DEFW 0
	DEFW 0
	DEFW 0
	DEFW 0
 ;
	DEFB 3FH ;
 ;	
 ; bit      7 6 5 4 3 2 1 0
 ; segment  p g f e d c b a
 ;
DGTM:	DEFM 0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f
 ;             0  , 1  , 2  , 3  , 4  , 5  , 6  , 7  , 8  , 9
 ;
	DEFB 77H ;
 ;
DGTA:	DEFM 0x77,0x7c,0x39,0x5e,0x79,0x71,0x3d,0x76,0x30,0x1e
 ;	       A  , b  , C  , d  , E  , F  , G  , H  , I  , J
 ;
	DEFM 0x74,0x38,0x37,0x54,0x5c,0x73,0x67,0x50,0x6d,0x78
 ;	       k  , L  , M  , n  , o  , P  , q  , r  , S  , t
 ;
	DEFM 0x3e,0x1c,0x7e,0x36,0x6e,0x1b
 ;	       U  , v  , W  , X  , y  , Z
 ;
	DEFB 31 ;
 ;
MLEN:	DEFM 31,28,31,30,31,30,31,31,30,31,31,31
 ;
 ;                      111111 
 ;            0123456789012345
MSG:	DEFM "emu DSP 7segment"
	DEFM "          XD.'96"
 ;
DAYN:	DEFM "lunedi"
	DEFM "marted"
	DEFM "mercol"
	DEFM "gioved"
	DEFM "venerd"
	DEFM "sabato"
	DEFM "domeni"
 ;
 ; List of SubRoutine present in the code35.a
 ;
 ; DSPDAY:  DiSPlay DAY of week (letter)
 ; KEYCLC:  KEY CLear Cronograph locations
 ; KEYSET:  KEY SET pressed ? if yes wait key release
 ; CLRCRO:  CLeaR CROnograph locations
 ; KEYCRO:  KEY CROnograph
 ; DSPHMS:  DiSPlay Hour Min Sec
 ; DSPDMY:  DiSPlay Dayofmonth Month Year
 ; DSPCRO:  DiSPlay CROnograph
 ; INDEC2:  INDEC2 inc & dec (IY+10)
 ; XDLOGO:  print XD. LOGO on emu DSP with user LCD
 ; CALSEG:  CALcolate SEGment to turn on in DSPB
 ; CDSPBE:  Clear DiSPlay Buffer and call EMUDSP
 ; DL293M:  DL293M delay 293 msec @2456700Hz
 ; DL210M:  DL210M delay 210 msec @2456700Hz
 ; DL147M:  DL147M delay 147 msec @2456700Hz
 ; PRDCH7:  PRint Decimal CHar 7 segment
 ; TRANIS:  TRaslate six Number In 7 Segment DSP  
 ; TRALIS:  TRaslate six Letter alpha chr In 7 Segment DSP
 ; EMUDSP:  EMUlate six DSP 7 segment on LCD user chr 0-5
 ; EMUSEG:  emulate DSP 7 segment on LCD user chr
 ;
 ; CTCI3:   gestione interrupt counter 3  markII
 ;