;
; =====================================
; GMUSIK.TXT 851012 19.15
; Bo Engborg,GRAFIKLOOP
; =====================================
;
;
PGMSTRT  ORG 55260
;
         LD HL,0
         ADD HL,SP
         LD (MSTACK),HL
         JP GMUSIK
;
ASCBIN0A LD A,(ASCBIN0)
         CP 126
         JP Z,ASCBIN0
         JP ASCBIN0-2
;
ASCBIN1A LD A,(ASCBIN1)
         CP 223
         JP Z,ASCBIN1
         JP ASCBIN1-2
;
BINASCA  LD A,(BINASC)
         CP 175
         JP Z,BINASC
         JP BINASC-2
;
;
; =====================================
; MUSIK.TXT
; Bo Engborg 850831 03.30
; Evalds Sportdata,0591-12160,71200 H{llefors
; Zn=Tidsintervall helnot,1 sekund=10, Xn=Oktavbyte H=Oktav1
; Skala CDEFGAH=1 oktav,0=helnot,1=halvnot osv... '#',upph|jd not
; Ex Z10(helnot 1sek) A0A1C(helnot,halvnot,halvnot)
; "Kommentarer inom "" " ex. styckets namn p} rad 17
; Styckets text inom <..>,">" ger ny rad chr$(13,10)
; =====================================
;
;
GMUSIK   LD B,69
         LD C,11110010B                ; E$
         CALL FIND
         RET C                         ; Ej hittad
         LD BC,SLUT
         LD (RETADR),BC
         CALL INFIL
         LD A,0
         LD (MODER+4),A                ; Playmode
         JR LOPSTART
;
FIND     PUSH IX
         LD IX,(VAROT)
FIND1    LD L,(IX+2)
         LD H,(IX+3)
         LD A,(IX+1)
         CP B
         JR NZ,FIND2
         LD A,(IX)
         CP C
         JR NZ,FIND2
         LD C,(IX+8)
         LD B,(IX+9)
         LD L,(IX+6)
         LD H,(IX+7)
         JR FOUND
FIND2    PUSH HL
         POP IX
         LD A,L
         OR H
         SCF
         JR Z,NOFOUND
         JR FIND1
FOUND    AND A
NOFOUND  POP IX
         RET
;
LOPSTART CALL MUSIKRAM
         LD HL,MSBUF2                  ; Musikinterruptadata
         LD (HL),0
         LD (BR[KN4),HL
         CALL BSCOUNT
         LD HL,(BR[KN4)
         LD (HL),57
         CALL BSCOUNT
         CALL BSCOUNT
         LD DE,FREKVC
         LD A,0
         LD B,4
         CALL STRING
         LD HL,(BR[KN2)
         LD DE,10000
         ADD HL,DE
         LD DE,BKONST19
         PUSH DE
         CALL BINASCA
         POP DE
         LD A,40
         LD (DE),A
         CALL BCOUNT
         LD B,25                       ; 2.5sek delay
         CALL DELAY
         PUSH IX
         PUSH IY
         LD IY,MODER
         LD IX,MBUFF1
         LD HL,0
         ADD HL,SP
         LD (MSTACK),HL
         CALL MODWR
;
MLOOP    XOR A                         ; Musiksnurra
         LD (BKONST1),A
         LD (BKONST2),A
         LD A,(IX)
         CP 13
         JP Z,MSLUT
         CP 34
         JP Z,NAMN
         CP 60                         ; '<'
         JP Z,TEXTEN
         CP 90            ; Zn=Tidbyte helnot
         JP Z,MTIME
         CP 88            ; Xn=Oktavbyte
         JP Z,OKTA
         LD (IY+8),0
         CP 35
         JR Z,MLOOPP1
         JR MLOOP1
MLOOPP1  LD (BKONST1),A                  ; #upph|jd not
         INC IX
         CALL BCOUNT
         LD (IY+8),1                   ; upph|jd not
MLOOP1   LD A,(IX)
         LD (IY),A
         LD (BKONST2),A                  ; Aktuell not
         CALL TIDSET
MLOOP4   LD A,(IY)
         CP 95                   ; Paus
         JR NZ,MLOOP3
         CALL PAUSWR
         LD HL,0
         LD (FREKV1),HL
         LD (TIDDEL),HL
         LD (FREKV1+2),HL
         LD (TIDDEL+2),HL
         CALL TIDDELW
         CALL FREKVWR                  ; Skriv frekvens+tidsenhet
         LD HL,(BR[KN4)
         LD (HL),255
         CALL BSCOUNT
         CALL MSTIDA
         LD BC,(TID1)
MLOOP4A  PUSH BC
         LD B,1
         CALL DELAY
         POP BC
         DEC BC
         LD A,B
         OR C
         JR NZ,MLOOP4A
         JP MLOOPON
;
MLOOP3   CALL NOTWR                    ;
         CALL FREKVS
         JP MLOOP66A
;
OKTAVRZ  LD A,(IY+2)                   ; Aktuell oktav att spela
         LD (BKONST3),A
         SUB 63                        ; Ta bort @-1
         RET
;
NOTWR    CALL OKTAVRZ
         LD C,4
NOTWRZ   SUB C
         JR NC,NOTWRZ
         ADD A,C
         PUSH AF
         ADD A,A
         LD B,0
         LD C,A
         POP AF
         JR NZ,NOTW4N1                 ; Oktav 0
         LD HL,TONETXT+5
         LD BC,8
         CPIR
         PUSH AF
         LD A,C
         SUB 8
         LD C,A
         POP AF
         JR Z,NOTW4N1
         LD BC,2
         JR NOTW4N1
NOTW4N   CP 3
         LD A,(IY)
         CP 68                         ; 'C'
         JR NZ,NOTW4N1
         LD BC,8
NOTW4N1  LD HL,OKTAB                   ; Oktavtabell bildadresser
         ADD HL,BC
         LD E,(HL)
         INC HL
         LD D,(HL)
         LD (MADR3),DE                  ; Bildsk{rmss|king ton att spela
         EX DE,HL
         LD A,(IY)
         OR 32
         SET 7,A
         LD BC,35
         CPIR
         RET Z
         LD A,(IY)
         OR 32
         LD HL,(MADR3)
         LD BC,35
         CPIR
         JP NZ,FEL7                   ; Hittar ej tonen p} sk{rmen
NOTW5Z   DEC HL
         LD DE,(MADR2)
         LD (MADR2),HL
         SET 7,(HL)
         EX DE,HL
         RES 7,(HL)
         RET
;
;
TIMEWR   LD HL,(TID)
         LD DE,BKONST5
         CALL TIMEWRX
TIMEWR1  LD HL,(TID1)
         LD DE,BKONST6
         CALL TIMEWRX
         RET
;
TIMEWRX  PUSH DE
         LD DE,10000
         ADD HL,DE
         POP DE
         PUSH DE
         CALL BINASCA
         POP DE
         LD A,58
         LD (DE),A
         RET
;
FREKVWR  LD DE,BKONST7
         LD A,(FREKV1+2)
         LD H,0
         LD L,A
         CALL BINASCA
         LD A,58
         LD (DE),A
         INC DE
         LD HL,(FREKV1)
         CALL BINASCA
         LD HL,BKONST7A
FREKVWR1 AND A
         SBC HL,DE
         LD B,L
         LD A,46
         CALL STRING
         RET
;
TIDDELW  LD DE,BKONST8
         LD A,(TIDDEL+2)
         LD H,0
         LD L,A
         CALL BINASCA
         LD A,58
         LD (DE),A
         INC DE
         LD HL,(TIDDEL)
         CALL BINASCA
         LD HL,BKONST8A
         JR FREKVWR1
;
FREKVS   LD HL,TONETXT
         LD BC,13
         LD A,(IY)
         CPIR
         JP NZ,FEL5                    ; Notskriftfel
         LD A,12
         SUB C
         LD D,0
         LD E,A
         LD HL,SKALTXT
         ADD HL,DE
         DEC (IY+8)
         JR NZ,FREKVS1N
         INC HL                        ; \ka HL om upph|jd ton
FREKVS1N LD (MADR6),HL                  ; Spara adress till frekvens
         PUSH HL
         LD HL,(FREKVC)
         LD (MR[KN1),HL
         LD A,0
         LD (MR[KN1+2),A
         POP HL
         LD C,(HL)                     ; Frekv ber{kningsvariable
         LD B,0
         CALL ADDITION
         LD HL,120
         LD (MR[KN1),HL
         LD A,0
         LD (MR[KN1+2),A
         CALL MINUUS
;
         LD HL,(MR[KN3)
         LD (FREKV1),HL
         LD A,(MR[KN3+2)
         LD (FREKV1+2),A
         CALL FREKVWR                  ; Frekvensen p} sk{rmen
         LD HL,(FREKV1)
         LD (MR[KN1),HL
         LD A,(FREKV1+2)
         LD (MR[KN1+2),A
         LD HL,7812
         LD (MR[KN2),HL
         LD A,0
         LD (MR[KN2+2),A
         CALL MINUUS
;
         LD A,(MR[KN3)
         LD HL,(BR[KN4)
         LD (HL),A
         CALL BSCOUNT
         CALL MSTIDA
         LD HL,(FREKV1)
         LD (MR[KN1),HL
         LD A,(FREKV1+2)
         LD (MR[KN1+2),A
;
         LD HL,16960
         LD (MR[KN2),HL                ; HL=50000
         LD A,15
         LD (MR[KN2+2),A
         CALL MINUUS
;
         LD HL,(MR[KN3)
         LD (MR[KN2),HL
         LD A,(MR[KN3+2)
         LD (MR[KN2+2),A
;
         LD DE,FKONST1
         LD HL,(MR[KN2)
         AND A
         SBC HL,DE
         LD (MR[KN2),HL
         LD DE,FKONST2
         LD (MR[KN1),DE
         LD A,0
         LD (MR[KN1+2),A
         CALL MINUUS
;
         LD HL,(MR[KN3)
         LD (TIDDEL),HL
         LD A,(MR[KN3+2)
         LD (TIDDEL+2),A
         CALL TIDDELW                  ; Tidsdelayen p} sk{rmen
;
;
         LD HL,(FREKV1)
         LD (MR[KN1),HL
         LD A,(FREKV1+2)
         LD (MR[KN1+2),A
         LD BC,(TID1)
         CALL ADDITION
         LD HL,10
         LD (MR[KN1),HL
         LD A,0
         LD (MR[KN1+2),A
         CALL MINUUS
;
         LD HL,(MR[KN3)
         LD (FREKV1),HL
         LD A,(MR[KN3+2)
         LD (FREKV1+2),A
         LD HL,(FREKV1)
         LD (TID3),HL
         LD A,(FREKV1+2)
         LD (TID3+2),A
         RET
;
;
;
MODWR    LD A,(IY+4)
         LD C,A
         ADD A,A
         ADD A,A
         ADD A,C                       ; A=A*5
         LD B,0
         LD C,A
         LD HL,MODETXT
         ADD HL,BC
         LD DE,BKONST9
         LD BC,5
         LDIR
         RET
;
TIDSET   LD A,(IX+1)
         CP 48
         RET C
         CP 58
         RET NC
         LD DE,(TID)
         LD (BKONST12),A               ; Ladda bild tidsiffra
         SUB 48
         JR Z,TIDS4A
         LD B,A
TIDS5    SRL D
         RR E
         DJNZ,TIDS5
TIDS4A   INC IX
         CALL BCOUNT
TIDS4B   LD (TID1),DE
         CALL TIMEWR1
         RET
;
;
MLOOP66A NOP
;
;
MLOOP6A  LD A,0                        ; Musikloop            7T
         OUT (6),A                     ;                     11T
         LD A,(LJUD)                   ;                     13T
         OUT (6),A                     ;                     11T
;
; Summa:42T
;
;
;
MLOOP7   LD HL,(TIDDEL)                ; 16T
;
;Summa:16T
;
;
;
         LD A,36                       ; 7T
         LD DE,BKONST11+2              ; 10T
         LD (DE),A                     ; 7T
;
;Summa:24T
;
;
MLOOP7A  LD A,H            ; 4T
         OR L              ; 4T
         JR Z,MLOOP7B      ; 1=12T,0=7T
         DEC HL            ; 6T
         JR MLOOP7A        ; 7T
MLOOP7B  LD A,(TIDDEL+2)   ; 13T
         CP 0              ; 7T
         JR Z,MLOOP7C      ; 1=12T,0=7T
         DEC A             ; 4T
         LD (TIDDEL+2),A   ; 13T
         JR MLOOP7A        ; 7T
MLOOP7C  NOP               ; 4T
;
;Summa:Tiddel*28+56
;
;
         LD A,32                       ; 7T
         LD DE,BKONST11+2              ; 10T
         LD (DE),A                     ; 7T
;
;Summa:24T
;
;
;
MLOOP8   LD BC,(TID3)      ; 16T
         LD A,B            ; 4T
         OR C              ; 4T
         JR Z,MLOOP8A      ; 1=12T,0=7T
         DEC BC            ; 6T
         LD (TID3),BC      ; 20T
         JR MLOOP6A        ; 7T
MLOOP8A  DEC BC            ; 4T
         LD (TID3),BC      ; 20T
         LD A,(TID3+2)     ; 13T
         CP 0              ; 7T
         JR Z,MLOOP8B      ; 1=12T,0=7T
         DEC A             ; 4T
         LD (TID3+2),A     ; 13T
         JR MLOOP6A        ; 7T
MLOOP8B  NOP               ; 4T
;
;Summa:64T
;
;
;
;
;
MLOOPON  LD A,(LJUD)
         OUT (6),A
         LD A,(IY)
         CP 95
         CALL Z,PAUSRES                ; Reset paustxt
MLOOP9   INC IX
         CALL BCOUNT
         JP MLOOP
;
PAUSWR   NOP                           ; Pausloop
         LD DE,BKONST11
         LD HL,PAUSTX
         LD BC,4
         LDIR
         LD A,0
         LD (LJUD),A                   ; ladda ljud med 0
         RET
;
PAUSRES  LD DE,BKONST11
         LD B,4
         LD A,32
         CALL STRING
         LD A,57
         LD (LJUD),A
         RET
;
MTIME    PUSH IX
         POP HL
         PUSH HL
         CALL ASCBIN1A
         POP BC
         PUSH HL
         POP IX
         AND A
         SBC HL,BC
         LD B,L
MTIME1   CALL BCOUNT
         DJNZ,MTIME1
         LD (TID),DE
         LD (TID1),DE
         CALL TIMEWR
         JP MLOOP
;
MSTIDA   LD HL,781
         LD (MR[KN1),HL
         LD A,0
         LD (MR[KN1+2),A
         LD BC,(TID1)
         CALL ADDITION
         LD A,(MR[KN2)
         LD HL,(BR[KN4)
         LD (HL),A
         CALL BSCOUNT
         LD A,(MR[KN2+1)
         LD HL,(BR[KN4)
         LD (HL),A
         CALL BSCOUNT
         RET
;
;
TEXTEN   INC IX                        ; Iy+6=rad
         CALL BCOUNT
         CALL TEXTEN44
         LD B,34
TEXTEN1  LD A,(IX)
         CP 62                         ; '>'
         JR Z,RADBROT                  ; Slut p} texten
         LD (DE),A
         INC DE
         INC IX
         CALL BCOUNT
         INC (IY+7)
         DJNZ TEXTEN1
RADBROT  INC (IY+6)
         LD (IY+7),3
         LD A,(IY+6)                   ; Rad
         CP 19
         JR C,TEXTENE
         LD (IY+6),8
TEXTENE  CALL TEXTEN44
         JP MLOOP9
;
TEXTEN44 LD A,(IY+6)                   ; iy+7=kolumn
         LD (65011),A
         LD A,(IY+7)
         LD (65012),A
         PUSH IX
         CALL VIDEOW                   ; Get bildadress
         POP IX
         PUSH DE
         RET
;
OKTA     INC IX
         CALL BCOUNT
         LD A,(IX)
         LD (IY+2),A                       ; Aktuell oktav att spela
         LD HL,BKONST4
         LD BC,35
         CPIR
         JP NZ,MLOOP9
         DEC HL
         SET 7,(HL)
         LD DE,(MADR1)
         LD (MADR1),HL
         EX DE,HL
         RES 7,(HL)
;
         LD A,(IY+2)
;
FREVSE   LD DE,33
         SUB 69
         CALL GGR
         JP MLOOP9
;
GGR      LD B,A
         CP 0
         JR Z,GGR2
         AND A
GGR1     SLA E
         RL D
         DJNZ GGR1
GGR2     LD (FREKVC),DE
         RET
;
NAMN     INC IX
         CALL BCOUNT
         LD DE,BKONST13
         LD B,23
NAMN1    LD A,(IX)
         CP 34
         JR Z,NAMN3
         LD (DE),A
         INC DE
         INC IX
         CALL BCOUNT
         DEC B
         JR Z,NAMN5
         JR NAMN1
NAMN3    LD A,32
NAMN4    LD (DE),A
         INC DE
         DJNZ NAMN4
NAMN5    LD (IY+6),8                   ; Rad 19,r{knare
         LD (IY+7),3                   ; Kolumn 3,r{knare
         JP MLOOP9
;
;
;
MINUUS   PUSH IX
         LD HL,0
         LD (MR[KN3),HL
         LD (MR[KN3+2),HL
         LD IX,MR[KN3
         LD (IX+3),3
         LD DE,(MR[KN1)
         LD HL,(MR[KN2)
MINUUS1  AND A
         SBC HL,DE
         CALL Z,NOLL
         LD A,(MR[KN1+2)
         LD C,A
         LD A,(MR[KN2+2)
         SBC A,C
         LD (MR[KN2+2),A
         CALL Z,NOLL
         JR C,MINUUSE
         LD (IX+3),3
         INC (IX)
         JR NZ,MINUUS1
         INC (IX+1)
         JR NZ,MINUUS1
         INC (IX+2)
         JR NZ,MINUUS1
MINUUSE  DEC (IX+3)
         JR NZ,MINEND
         LD A,255
         DEC (IX)
         CP (IX)
         JR NZ,MINEND
         DEC (IX+1)
         CP (IX+1)
         JR NZ,MINEND
         DEC (IX+2)
MINEND   POP IX
         RET
;
NOLL     PUSH AF
         DEC (IX+3)
         POP AF
         RET
;
ADDITION LD HL,0
         LD DE,(MR[KN1)
         LD (MR[KN2+2),HL
ADDI1    ADD HL,DE
         JR NC,ADDI2
         LD A,(MR[KN2+2)
         INC A
         LD (MR[KN2+2),A
ADDI2    DEC BC
         LD A,B
         OR C
         JR NZ,ADDI1
         LD (MR[KN2),HL
         RET
;
;
;
MSLUT    LD HL,(BR[KN4)
         LD (HL),1
         CALL BSCOUNT
         LD DE,MSBUF2
         LD HL,(BR[KN4)
         LD (HL),E
         CALL BSCOUNT
         LD HL,(BR[KN4)
         LD (HL),D
         CALL BSCOUNT
         LD HL,(MSTACK)
         LD SP,HL
         POP IY
         POP IX
SLUT     RET
;
;
;
STRING   LD (DE),A
         INC DE
         DJNZ STRING
         RET
;
BSCOUNT  PUSH HL
         PUSH DE
         PUSH BC
         PUSH AF
         LD DE,BKONST22
         LD HL,(BR[KN4)
         INC HL
         LD (BR[KN4),HL
         CALL BINASCA
         POP AF
         POP BC
         POP DE
         POP HL
         RET
;
BCOUNT   PUSH HL
         PUSH DE
         PUSH BC
         PUSH AF
         LD HL,(BR[KN1)
         LD DE,10000
         ADD HL,DE
         LD DE,BKONST20
         PUSH DE
         CALL BINASCA
         POP DE
         LD A,58
         LD (DE),A
         LD HL,(BR[KN1)
         DEC HL
         LD (BR[KN1),HL
         POP AF
         POP BC
         POP DE
         POP HL
         RET
;
;
FEL1     LD A,1
         JR FEL
;
FEL2     LD A,2
         JR FEL
;
FEL3     LD A,3
         JR FEL
;
FEL4     LD A,4
         JR FEL
;
FEL5     LD A,5
         LD BC,MLOOPON
         LD (RETADR),BC
         JR FEL
;
FEL6     LD A,6
         JR FEL
;
FEL7     LD A,7
         LD BC,MLOOPON
         LD (RETADR),BC
         JR FEL
;
FEL8     LD A,8
         JR FEL
;
FEL9     LD A,9
         JR FEL
;
FEL10    LD A,10
         JR FEL
FEL12    LD A,12
         JR FEL
;
;
FILCONTR EXX                           ; Rutinadress i DE
         LD HL,0
         LD (MIY14),HL                 ; Run Mode
         LD HL,FELJMP
         LD (MIY30),HL                 ; Onerrorgoto
         LD HL,FELKOD
         PUSH HL
         LD HL,0
         ADD HL,SP
         LD (RUNSTACK),HL              ; Run time stack
         LD HL,FILCTR1
         PUSH HL
         EXX
         PUSH DE
         RET
FILCTR1  POP HL
         RET                           ; Inga fel
FELJMP   DEFB 10
         DEFB 0
         DEFB 1
         DEFB 145                      ; Basic-return
FELKOD   LD HL,(MSTACK)
         LD SP,HL
         LD A,(MIY34)
         AND 127
         LD DE,FELTXT+32*11+16
         LD H,0
         LD L,A
         LD BC,100
         ADD HL,BC
         PUSH DE
         CALL BINASCA
         POP DE
         LD A,58
         LD (DE),A
         LD A,11
;
FEL      LD B,A
         LD HL,0
         LD DE,32
         CP 0
         JR Z,FEL]
FELZ     ADD HL,DE
         DJNZ FELZ
FEL]     LD A,19
         OUT (6),A
         PUSH HL
         LD DE,FELTXT
         LD BC,32
         LD HL,BKONST21
         LDIR
         POP HL
         LD BC,FELTXT
         ADD HL,BC
         LD BC,30
         LD DE,BKONST21
         LD A,7
         LD (DE),A
         INC DE
         LDIR
         LD A,23
         LD (DE),A
         LD B,35
         CALL DELAY
         LD A,0
         OUT (6),A
         LD DE,BKONST21
         LD BC,32
         LD HL,FELTXT
         LDIR
         LD BC,(RETADR)
         PUSH BC
         RET
;
;
; =====================================
; MUSIKRAM.TXT..850903..04.46.. Bo Engborg
; Evalds Sportdata,0591-12160,60000
; Ram till musikprogram
; =====================================
;
MUSIKRAM LD A,3
         IN A,(3)
RAMM     PUSH IX
         LD A,(590)
         SUB 40
         LD (VARTKN),A
RAM1B    LD IX,RAD0
RAM1     LD B,(IX)
         INC IX
         LD L,(IX)
         INC IX
         LD H,(IX)           ; (bildadress)
         INC IX
RAM1A    PUSH IX
         LD E,(HL)          ; HL bildadress
         INC HL
         LD D,(HL)
         INC HL
RAM2     LD A,(IX)
         CP 9
         JR NZ,RAM3
         INC IX
         PUSH BC
         LD A,(VARTKN)
         LD C,A
         LD A,(IX)
         BIT 7,A
         JR Z,RAM2E
         RES 7,A
         ADD A,C
RAM2E    LD B,A
         INC IX
         LD A,(IX)
         CALL STRING
         INC IX
         POP BC
RAM3     LD A,(IX)
         CP 13
         JR Z,RAM4
         LD (DE),A
         INC DE
         INC IX
         JR RAM2
RAM4     DEC B
         JR NZ,RAM4A
         POP DE
         INC IX
         LD A,(IX)
         CP 141
         JR Z,RAMEND
         JR RAM1
RAM4A    POP IX
         JR RAM1A
RAMEND   POP IX
         RET
;
; =====================================
; OPEN,PREPARE,CLOSE
; HL-->filnamn avsluta med CR
; =====================================
;
;
INFIL    PUSH IX
         LD IX,FILBESK
         LD (IX+2),127
         LD A,0                        ; Open
         LD DE,OPENCMD
         CALL FILCONTR
         LD HL,MBUFF1
         LD (MBUFADR),HL
;
INFIL1   LD HL,(MBUFADR)
         LD BC,119
         PUSH HL
         LD DE,INPUTFIL
         CALL FILCONTR
         POP HL
         JR C,INFIL1A
         LD BC,0
         LD A,13
         CPIR
         DEC HL
         LD (MBUFADR),HL
         JR INFIL1
INFIL1A  AND A
         JR Z,INFIL2                   ; Slut p} filen
         LD (MIY30),A
         JP FELKOD                     ; Felkod i A (Basic)
;
INFIL2   LD A,13
         INC HL
         LD (HL),A
         LD (MBUFADR),HL
         LD DE,MBUFF1
         AND A
         SBC HL,DE
         DEC HL
         LD (BR[KN2),HL
         LD (BR[KN1),HL
         LD (IX+5),0
         LD DE,2192                    ; Closefile
         CALL FILCONTR
         POP IX
         RET
;
;
;
;
DELAY    NOP                           ; B=antal 10/sekunder,Tidsf|rdr
DELAY2A  PUSH BC                       ; 11 T
         LD B,2                        ; 7 T;N
DELAY2   LD HL,9216                    ; 10 T;H/256
DELAY1   DEC L                         ; 4 T
         JR NZ,DELAY1                  ; 0=7 T,1=12 T
         DEC H                         ; 4 T
         JR NZ,DELAY1                  ; 0=7 T,1=12 T
         DJNZ DELAY2                   ; b<>0=13T,b=0,8 T
         POP BC                        ; 10 T
         DJNZ DELAY2A                  ; B<>0=13T,B=0=8 T
         RET               ; T=250 000=N*(30+H*4103)+49
;
;
;
;
;
; =====================================
; TEXT
; =====================================
;
;
;
OKTAB    DEFW BKONST14                 ; fgah
         DEFW BKONST15                 ; cdefgah
         DEFW BKONST16                 ; cdefgah
         DEFW BKONST17                 ; cdefgah c
         DEFW BKONST18                 ;         c
;
;
;
MODETXT  DEFB 80+128                   ; Playmodetxt
         DEFB 76+128
         DEFB 65+128
         DEFB 89+128
         DEFB 32
;
;
SKALTXT  DEFB 120                      ; C
         DEFB 130                      ;#C
         DEFB 135                      ; D
         DEFB 144                      ;#D
         DEFB 150                      ; E
         DEFB 160                      ; F
         DEFB 173                      ;#F
         DEFB 180                      ; G
         DEFB 192                      ;#G
         DEFB 200                      ; A
         DEFB 216                      ;#A
         DEFB 225                      ; H
         DEFB 240                      ; C,n{sta oktav
;
;
RAD0     DEFB 1
         DEFW 884
         DEFB 151
         DEFB 55
         DEFB 9
         DEFB KONST1
         DEFB 35
         DEFB 107
         DEFB 13
RAD1     DEFB 1
         DEFW 886
         DEFB 151
         DEFB 53
         DEFB 135
         DEFM "Oktav:   0123"
         DEFB 9
         DEFB 8
         DEFB 32
         DEFM "Grundoktav:   "
         DEFB 151
         DEFB 106
         DEFB 13
RAD2     DEFB 1
         DEFW 888
         DEFB 151
         DEFB 53
         DEFB 135
         DEFM "  @ABCDEFGHIJKLM"
         DEFM "OPQRSTUVWXYZ]\[^"
         DEFM "   "
         DEFB 151
         DEFB 106
         DEFB 13
RAD3     DEFB 1
         DEFW 890
         DEFB 151
         DEFB 53
         DEFB 135
         DEFM "Helnot:    ."
         DEFM "Not:    ."
         DEFM "Hz           ."
         DEFB 151
         DEFB 106
         DEFB 13
RAD4     DEFB 1
         DEFW 892
         DEFB 151
         DEFB 53
         DEFB 135
         DEFM "Ton:   .    ."
         DEFM "Delay:         "
         DEFM "  ....."
         DEFB 151
         DEFB 106
         DEFB 13
RAD5     DEFB 1
         DEFW 894
         DEFB 151
         DEFB 53
         DEFB 135
         DEFM "fgah   cdefgah  "
         DEFM " cdefgah   cdefg"
         DEFM "ahc"
         DEFB 151
         DEFB 106
         DEFB 13
RAD6     DEFB 1
         DEFW 896
         DEFB 151
         DEFB 53
         DEFB 135
         DEFM "MODE:     ."
         DEFB 9
         DEFB 24
         DEFB 32
         DEFB 151
         DEFB 106
         DEFB 13
RAD7     DEFB 1
         DEFW 898
         DEFB 151
         DEFB 61
         DEFB 9
         DEFB KONST1
         DEFB 44
         DEFB 110
         DEFB 13
RAD8     DEFB 12
         DEFW 900
         DEFB 151
         DEFB 53
         DEFB 135
         DEFB 9
         DEFB KONST2
         DEFB 32
         DEFB 151
         DEFB 106
         DEFB 13
RAD20    DEFB 1
         DEFW 924
         DEFB 151
         DEFB 53
         DEFB 135
         DEFM "MSBuf(     ):   "
         DEFM "   .MBuf(    ): "
         DEFM "   "
         DEFB 151
         DEFB 106
         DEFB 13
RAD21    DEFB 1
         DEFW 926
         DEFB 151
         DEFB 61
         DEFB 9
         DEFB KONST1
         DEFB 44
         DEFB 110
         DEFB 13
RAD22    DEFB 1
         DEFW 928
         DEFB 151
         DEFB 53
         DEFB 135
         DEFB 9
         DEFB KONST2
         DEFB 32
         DEFB 151
         DEFB 106
         DEFB 13
RAD23    DEFB 1
         DEFW 930
         DEFB 151
         DEFB 117
         DEFB 9
         DEFB KONST1
         DEFB 112
         DEFB 122
         DEFB 13
         DEFB 141
;
;
FELTXT   DEFM "                "
         DEFM "                "
         DEFM "End of media!!  "
         DEFM "                "       ; Error1
         DEFM "CRC fel!!       "
         DEFM "                "       ; Error2
         DEFM "Ingen funktion d"
         DEFM "etta kommando!  "       ; Error3
         DEFM "AM fel!!        "
         DEFM "                "       ; Error4
         DEFM "Notskriftfel!!  "
         DEFM "                "       ; Error5
         DEFM "Hittar ej str{ng"
         DEFM "variabeln!!     "       ; Error6
         DEFM "Hittar ej tonen "
         DEFM "p} sk{rmen!!    "       ; Error7
         DEFM "Skrivskyddad ski"
         DEFM "va!!            "       ; Error8
         DEFM "Offline!!       "
         DEFM "                "       ; Error9
         DEFM "Ok{nt fel!!     "
         DEFM "                "       ; Error10
         DEFM "Fel,Errorkode nr"
         DEFM ":               "       ; Errorkod
         DEFM "Fel data till ko"
         DEFM "mmando!!        "       ; Error12
;
;
PAUSTX   DEFB 80+128
         DEFB 97+128
         DEFB 117+128
         DEFB 115+128
;
CDURTXT  DEFM "XGZ100C0DEFGAHC"
         DEFB 13
;
TONETXT  DEFM "CCDDEFFGGAAHC"
;
;
; =====================================
; VARIABLER I RAMAREA
; =====================================
;
;
VASTRT   DEFB 255
;
MR[KN1   DEFS 4
MR[KN2   DEFS 4
MR[KN3   DEFS 4                        ; Resultatr{knare
FREKVC   DEFS 4
FILBESK  DEFS 16                       ; Filbeskrivning
MBUFADR  DEFS 2                        ; Musikbuffertadress
RETADR   DEFS 2                        ; Sparad returnadress
BR[KN1   DEFS 2                        ; Buffertr{knare
BR[KN2   DEFS 2                        ; Buffertfyllnad
BR[KN4   DEFS 2
MODER    DEFS 20
VARTKN   DEFS 1
MADR1    DEFW 32387                    ; Starts|kning oktav:
MADR2    DEFW 32169                    ; Pekare till bildoktavs|kning
MADR3    DEFW 32387                    ; Oktavbildadress sparad
MADR6    DEFS 2                        ; Adress till aktuell frekvens
LJUD     DEFB 57                       ; Defult ljud
FREKV1   DEFS 4                        ; Modifierad frekvens
TIDDEL   DEFS 4                        ; Tedsdelayenhet
TID      DEFW 10          ; Tid f|r helnot
TID1     DEFW 10          ; Aktuell tid
TID2     DEFS 4                        ; Ursprunglig tidsnedr{kn
TID3     DEFS 4                        ; Aktuell tidsnedr{kn
MSTACK   DEFS 2
VAEND    DEFB 255
PGMEND   DEFB 255
;
; VARIABELEND
; =====================================
;
;
; =====================================
; KONSTANTER :::::------>
; =====================================
;
MBUFF1   EQU 58500                     ; Startbuffert
MBUFF1E  EQU 61000                     ; Slutbuffert
MSBUF2   EQU 61000                     ; Skapa musikbuff
MSBUF2E  EQU 62258                     ; Slutbuffert
FKONST1  EQU 91                        ; 226T/2.5
FKONST2  EQU 12                        ; 28T/2.5
BKONST1  EQU 32263                     ; Ton:'#',upph|jd not
BKONST2  EQU 32264                     ; Ton: ' ',ton
BKONST3  EQU 31907                     ; Grundoktav:' '
BKONST4  EQU 32003                     ; Rad 2,3' ',Starts|kning oktav
BKONST5  EQU 32137                     ; Helnot:'1000'
BKONST6  EQU 32146                     ; Not:'1000'
BKONST7  EQU 32155                     ; Frekvens:'1000'
BKONST7A EQU 32166
BKONST8  EQU 32278                     ; Tidsdelayenhet:'65535'....
BKONST8A EQU 32294
BKONST9  EQU 32520                     ; Mode:''
BKONST11 EQU 32267                     ; 'Paus'
BKONST12 EQU 32265                     ; Ton:__' ',tidskod
BKONST13 EQU 32526                     ; "?musikstycke"
BKONST14 EQU 32386                     ; s|k i oktav 0
BKONST15 EQU 32392                     ; s|k i oktav 1
BKONST16 EQU 32402                     ; s|k i oktav 2
BKONST17 EQU 32412                     ; s|k i oktav 3
BKONST18 EQU 32419                     ; till sista c i oktav 3
BKONST19 EQU 32363                     ; Bildadress buffertfyllnad
BKONST20 EQU 32369                     ; Bildadress buffertr{knare
BKONST21 EQU 32722                     ; Felmeddelande start
BKONST22 EQU 32345                     ; Buffertskapare
BKONST23 EQU 32352                     ; Buffertpekare skapande
KONST1   EQU 37+128
KONST2   EQU 35+128
TOLKCTXT EQU 2592                      ; Tolkens kommandotabell
ADR1     EQU 65019                     ; -->alternativ input vid -->(9)
ASCBIN0  EQU 6174                      ; ascii-bin{rt utan INC HL
ASCBIN1  EQU 6173                      ; ascii-bin{rt med INC HL
BASRADS  EQU 3897                      ; Basicradsearch
BASRADL  EQU 4501                      ; Basicradbuffertl{gg,tillbakalistad
WRILIN   EQU 11                        ; Writeline
OUTLIN   EQU 27                        ; Skriv p} buffert om full ,wr fil
CLOSBL   EQU 35                        ; Skriv slutblock p} fil
ALLHEAP  EQU 13172                     ; Allokera antal bytes i DE p} HEAP
CLOSEF   EQU 8384                      ; Close file i HLnummer
OPNFIL   EQU 45                        ; \ppna fil HL-->namn,BC=antal tecken
OPENCMD  EQU 62                        ; HL-->filnamn
                                       ; Fixa IX-reg 3 f|rsta bytes
FIXNAMN  EQU 65                        ; HL->filnamn,BC=n,=>DE->filnamnextdev
CRLF     EQU 1858                      ; CrLf
CP8I     EQU 859                       ; <--,inputlin
CP9I     EQU 840                       ; -->,inputlin
VIDEOW   EQU 659                       ; Bildadress enl 65011,12
RADBRED  EQU 590                       ; 40/80 tkn
NEW      EQU 2672
CLEAR    EQU 2688
CRLFTX   EQU 1837                      ; -->13,10
MIY14    EQU 65060                     ; IY+14
MIY34    EQU 65080                     ; IY+34
MIY30    EQU 65076                     ; Errhoppadress
ONERRW   EQU 65076                     ; Onerrorgotoadress
BOFAW    EQU 65052                     ; -->BOFA
STACK    EQU 65063                     ; -->STACK
RUNSTACK EQU 65078                     ; Runtimestackpointer
DEVRT    EQU 65034                     ; Devicerot
EOFA     EQU 65054                     ; End of file (??=1)
HEAP     EQU 65056                     ; Ledigt f|r tolken vid exekverbasic
VAROT    EQU 65065                     ; Variabelrot
IOKORTN  EQU 65067                     ; Senast valda I/O-kort
FILROT   EQU 65074                     ; -->lista |ppna filer
CTRLC?   EQU 830                       ; Z=0 om Ctrl-C tangentnedslagen
CMDSEAR  EQU 68                        ; Leta i tolken efter kommando
INSORT   EQU 1872                      ; Sorterar in basicrad i minnet
TXTBUF3  EQU 65208                     ; Radcompilebuffert
FIXLINE  EQU 3754                      ; Fyll i adresser i Compil.basrad
EXECUTE  EQU 3474                      ; Exekvera basicrad
FORMFILL EQU 630                       ; CHR$(12)
BINASC   EQU 6242                      ; Bin{rt till ascii
FILS\K   EQU 2300                      ; Leta efter filnummer i (IY+13
PRINTFIL EQU 2198                      ; HL->txtarea,BC=n,filbeskr.IX
INPUTFIL EQU 2195                      ; Input BC=antal tecken,HL->>txtarea
IMUL     EQU 14196                     ; (HL)*(DE)=HL,Carry=fel
IDIV     EQU 14216                     ; (HL)/(DE)=HL,Carry=fel
DOSBUF0  EQU 62720                     ; Dosbuf 0
DOSBUF0A EQU 62967                     ; 9 sista byten i Dosbuf0
WRITESK  EQU 24675                     ; Skriv sektor
READSK   EQU 24678                     ; Read sektor
DIRREAD  EQU 28668                     ; Direktaccess l{sning post db2
DIRWRIT  EQU 28670                     ; Direktaccess skriv post dosbuf2
DIRRES   EQU 28666                     ; St{ll pekare direktaccess
DRIVEN   EQU 64769                     ; Drive nummeradress
DRERROR  EQU 64789                     ; Adress errorkod vid l{sning,skr
;
; =====================================
; KONSTANTER END
; =====================================
; ---->>>>>>
;
         END
