;**********************
;* OCTAVIA BY XAVSNAP *
;**********************

ORG +16514

B8 "N" "D" " " 
A9 "R" "V"
76
76
@TOCARD=+9999

@TEMPO
FF 00

@OCT
00 ;OCTET OCTAVE.

@NOT
00 ;OCTET NOTE.

@CARN
00 ; NOTE.

@LINEL
00 00 ;TAILLE LINE.

@RECHE 
LD HL,(+16400)
@RET1
LD A,(HL)
CP 80
JP Z EXIT1

LD A,(HL)
INC HL
CP "S"
JP NZ RET1

LD A,(HL)
CP "N"
INC HL
JP NZ RET1

LD A,(HL)
CP "D"
INC HL
JP NZ RET1

LD D,H
LD E,L
PUSH HL
LD HL,DE
LD DE,0005   ;save
SBC HL,DE    ;z$
LD A,(HL)
LD C,A
inc HL
Ld A,(HL)
LD B,A
ADD HL,BC
INC HL
LD (LINEL),HL ; len
POP HL

@PHONEA
INC HL ; /

;Main loop
@PHONE

;Lenght test.
LD D,H
LD E,L
PUSH HL
LD HL,DE
LD BC,(LINEL)
SBC HL,BC
JP P EXIT1
POP HL

;BREAK
LD A,(4025)
SUB 7F
jp z exit1

LD BC,0

; Reset note
LD a,0F
LD (NOT),a
LD A,(HL)
LD B,A
LD (CARN),A
CP 80
JP Z exit1
CP "+"
JP Z PHONEA
CP "0"
JP Z T0
CP "1"
JP Z T1
CP "2"
JP Z T2
CP "3"
JP Z T3
CP "4"
JP Z T4
CP "5"
JP Z T5
CP "6"
JP Z T6
CP "7"
JP Z T7
CP "8"
JP Z T8
CP "9"
JP Z T9
CP "A"
JP Z BN1
CP "B"
JP Z BN2
CP "C"
JP Z BN3
CP "D"
JP Z BN4
CP "E"
JP Z BN5
CP "F"
JP Z BN6
CP "G"
JP Z BN7
CP "O"
JP Z OCTAVE
CP "P"
JR Z PAUSE
CP "L"
Jp Z RECHE
JP PhoneA

@PAUSE

LD A,0F
LD (Tocard),A
JR RETSCB

@RETSCA
CALL PLAY
@RETSCB
CALL TIME

LD A,(4025)
CP FF
JP NZ EXIT1

LD A,0F
LD (TOCARD),A
LD A,(4025)
LD B,A
CP 7F
JP Z EXIT1
JP PHONEA

@BN1
; A A+ DO
LD A,+7
LD (NOT),A
JP ISDIE

@BN2
; B B+ RE
LD A,+13
LD (NOT),A
JP ISDIE

@BN3
; C    MI
LD A,+23
LD (NOT),A
JP RETSCA

@BN4
; D D+ FA
LD A,1B
LD (NOT),A
JP ISDIE

@BN5
; E E+ SOL
LD A,1E
LD (NOT),A
; E+ +10
JP ISDIE

@BN6
; F F+ LA
LD A,2B
LD (NOT),A
JP ISDIE

@BN7
; G    SI
LD A,2E
LD (NOT),A
JP RETSCA

@ISDIE
INC HL
LD A,(HL)
DEC HL
CP "+"
JP nZ RETSCA
INC HL
LD A,(CARN)
;debug
CP "A"
JP Z ADI
CP "B"
JP Z BDI
CP "D"
JP Z DDI
CP "E"
JP Z EDI
CP "F"
JP Z FDI
DEC HL
JP RETSCA

@ADI
LD B,4
JP ADDI

@BDI
LD B,1
JP ADDI


@DDI
LD B,2
JP ADDI


@EDI
LD B,9
JP ADDI


@FDI
LD B,2
JP ADDI

@ADDI
LD A,(NOT)
ADD A,B
LD (NOT),A
JP RETSCA

@T0
LD B,+1
LD (TEMPO),BC
JP PHONEA

@T1
LD B,+3
LD (TEMPO),BC
JP PHONEA

@T2
LD B,+6
LD (TEMPO),BC
JP PHONEA

@T3
LD B,+12
LD (TEMPO),BC
JP PHONEA

@T4
LD B,+24
LD (TEMPO),BC
JP PHONEA

@T5
LD B,+32
LD (TEMPO),BC
JP PHONEA

@T6
LD B,+48
LD (TEMPO),BC
JP PHONEA

@T7
LD B,+60
LD (TEMPO),BC
JP PHONEA

@T8
LD B,+72
LD (TEMPO),BC
JP PHONEA

@T9
LD B,+84
LD (TEMPO),BC
JP PHONEA

@OCTAVE 
INC HL
LD A,(HL)
LD B,A
CP "1"
JP Z O1
CP "2"
JP Z O2
CP "3"
JP Z O3
CP "4"
JP Z O4
CP "5"
JP Z O5
JP PHONE

@O1
LD A,0
LD (OCT),A
JP PHONEA

@O2
LD A,40
LD (OCT),A
JP PHONEA

@O3
LD A,80
LD (OCT),A
JP PHONEA

@O4
LD A,C0
LD (OCT),A
JP PHONEA

@O5
LD A,E0
LD (OCT),A
JP PHONEA

;TIMER
@TIME
LD BC,(TEMPO)
JP TB
@TA
LD A,(+16421)
CP FF
JR NZ EXIT1
LD C,FF
@TB
DEC C
JR NZ TB
DEC B
JR NZ TA 
RET

@PLAY
;Note + octave
LD A,(NOT)
LD B,A
LD A,(OCT)
ADD A,B
LD (TOCARD),A
RET

@EXIT1 
LD A,0F
LD HL,TOCARD
LD (HL),A
LD DE,0
LD BC,1
RET















