
        BR      START
        .ASCIZ  "(c) GID prod."
        .EVEN
START:  EMT     14
        CALL    INSET
        EMT     26
        MOV     R1,V156B
        MOV     R2,V160B
        MOV     R1,V156
        MOV     R2,V160
        CLR     (PC)+
NOSCR:  .WORD   0
        CMP     #100466,@#120170
        BEQ     0BEGIN
        JSR     R1,OUTS
        .ASCII  "? А теперь попробуйте запустить эту программу"
        .ASCIZ  " из ANDOS'а..."
        .EVEN
        CALL    WAITK
        HALT

EQ:     .ASCII  "*CAROLINE*"
        .EVEN
V156B:  .WORD   0
V160B:  .WORD   0
V156:   .WORD   0
V160:   .WORD   0
LENP:   .WORD   0


LOADDR: .WORD   EOF
BATS:   .WORD   0
EATS:   .WORD   0
PR:     .WORD   0

B0:     .BYTE   0
B1:     .BYTE   0
B2:     .BYTE   0
B3:     .BYTE   0

FDLIT:  .BYTE   0
FVOLUM: .BYTE   0
FSAMPL: .BYTE   0
FV:     .BYTE   0

PRSAM:  .BYTE   0
PRVOL:  .BYTE   0
PRDLT:  .BYTE   0
PRVP:   .BYTE   0
        .EVEN

0BEGIN: MOV     #100,@#177660
        CALL    CLS
        JSR     R2,HEAD
.ASCIZ  "Декомпилятор SONG'ов BY ROCK MONITOR by (c) GID prod."
        .EVEN

NEXT:5: MOV     #1000,SP
        MOV     V156,R1
        MOV     V160,R2
        EMT     24
        JSR     R1,OUTS
        .ASCIZ  <232>"Имя файла:"
        .EVEN
        CALL    NAME
        MOV     #320,R1
        EMT     36
        TSTB    1(R1)
        BEQ     17
        JSR     R1,OUTS
        .ASCIZ  "Файл не прочелся..."<12>
        .EVEN
        CALL    WAITK
        MOV     #14,R0
        EMT     16
        BR      5

17:     CALL    RENAME
        EMT     26
        MOV     R1,V156
        MOV     R2,V160
        MOV     #76000,@#177716
        MOV     #140000,@#177662
        MOV     V156B,R1
        MOV     V160B,R2
        EMT     24
        CALL    CLS
        CALL    INFO
        CALL    CLS
        MOV     #76000,R1
        MOV     R1,R3
        CALL    FORMAT
        MOV     LOADDR,R1
        ADD     #3006,R1
        MOV     R1,R5
        MOV     (R1)+,@#74772
        MOV     (R1)+,R0
        ADD     R5,R0
        MOV     R0,R4
        MOV     (R1)+,R0
        ADD     R5,R0
        MOV     R0,BATS
        MOV     R4,-(SP)
        SUB     #20,(SP)

        MOV     #12,R5
        MOV     LOADDR,R4
        ADD     #1104,R4
        MOV     #EQ,R2
L24:    CMPB    (R4)+,(R2)+
        BEQ     25
        CALL    INSET
        JSR     R1,OUTS
        .BYTE   12
        .ASCII  "? Хочу вас огорчить. Это не ROCK MONITOR'ный"
        .ASCIZ  " файл."
        .EVEN
        JMP     NEXT

25:     SOB     R5,L24
        MOV     (SP)+,R5
        CALL    MOVE
        CLR     R2
        MOV     BATS,R1
        MOV     #40000,R4
        MOV     #73000,R3
        MOV     R1,R0
        ADD     (R0),R0
        MOV     R0,EATS

30:     INC     R2
        MOV     (R1),R5
        ADD     BATS,R5
        MOV     R4,(R3)+
        CALL    MAIN
        MOV     R4,(R3)
        SUB     -2(R3),(R3)+
        ADD     #40000,-4(R3)
        CALL    MAIN
        CALL    MAIN
        ADD     #6,R1
        CMP     R1,EATS
        BLO     30
        MOV     R2,@#74774
32:     BIT     #100,@#177716
        BNE     32
        MOV     #320,R1
        MOV     R1,R0
        MOV     #2,(R0)+
        MOV     #40000,(R0)
        MOV     (R0)+,(R0)+
        MOV     @#120150,-(SP)
;        MOV     @#121322,-(SP)
;        MOV     @#121324,-(SP)
;        MOV     #12705,@#121322
;        MOV     #120,@#121324
        MOV     #SND,@#120150
31:     EMT     36
        TSTB    1(R1)
        BNE     31
;        MOV     (SP)+,@#121324
;        MOV     (SP)+,@#121322
        MOV     (SP)+,@#120150
        CALL    INSET
        JMP     NEXT

INSET:  MOV     #16000,@#177716
        MOV     #40000,@#177662
        RETURN

SND:    MOV     R2,-(SP)
        MOV     R3,-(SP)
        MOV     #10,R2
        MOV     #100,R3
        CALL    @#102062
        MOV     (SP)+,R3
        MOV     (SP)+,R2
        DEC     (PC)+
CNTS:   .WORD   10
        BNE     NULL
        MOV     #10,CNTS
        MOV     #NULL,@#120150
NULL:   RETURN

KEYT:   MOV     R0,-(SP)
        MOV     R1,-(SP)
        MOV     R2,-(SP)
        MOV     @#160,-(SP)
        MOV     @#156,-(SP)
        CLR     @#156
        MOV     #52030,@#160
        JSR     R1,OUTS
        .BYTE   232
        .ASCII  "┌═══════════════┐"<25>
        .ASCII  "║ ВЫХОД ? (Д/Н) ║"<25>
        .ASCIZ  "└═══════════════┘"
        .EVEN
        CALL    WAITK
        MOV     R3,-(SP)
        CALL    @#102052
        MOV     (SP)+,R3
        BIC     #240,R0
        CMPB    #'D,R0
        BEQ     000
        CMPB    #'Y,R0
        BEQ     000
        MOV     #52030,R0
        MOV     #36,R1
001:    MOV     #11,R2
004:    CLR     (R0)+
        SOB     R2,004
        ADD     #56,R0
        SOB     R1,001
        CLR     @#56
        MOV     (SP)+,@#156
        MOV     (SP)+,@#160
        MOV     (SP)+,R2
        MOV     (SP)+,R1
        MOV     (SP)+,R0
        RETURN
000:    JMP     @#100000

CLS:    MOV     #40000,R0
1:      CLR     (R0)+
        TST     R0
        BPL     1
        MOV     #377,@#56
        MOV     #1330,@#177664
        RETURN

HEAD:   CLR     R0
        EMT     22
        CLR     R1
3:      MOVB    (R2)+,R0
        BEQ     2
        EMT     22
        INC     R1
        BR      3
2:      INC     R2
        BIC     #1,R2
        RTS     R2

NAME:   TST     @#177662
        MOV     #320,R0
        MOV     #3,(R0)+
        MOV     LOADDR,(R0)+
        CLR     (R0)+
        MOV     #10,R1
        MOV     R0,R4
        MOV     R0,R3
6:      MOV     #20040,(R0)+
        SOB     R1,6
        MOV     R0,R5
14:     CALL    WAITK
        MOV     R3,-(SP)
        CALL    @#102052
        MOV     (SP)+,R3
        CMP     R0,#3
        BNE     20
        CALL    KEYT
        BR      14
20:     CMP     R0,#12
        BEQ     10
        CMP     R0,#30
        BEQ     11
        CMP     R0,#10
        BEQ     12
        CMP     R0,#31
        BEQ     13
        CMP     R0,#40
        BLO     14
        CMP     R0,#200
        BLO     15
        CMP     R0,#240
        BLO     14
15:     MOVB    R0,(R3)+
        EMT     16
        CMP     R3,R5
        BEQ     10
        BR      14
11:     CMP     R3,R4
        BEQ     14
        MOVB    #40,-(R3)
16:     EMT     16
        BR      14
12:     CMP     R3,R4
        BEQ     14
        DEC     R3
        BR      16
13:     INC     R3
        CMP     R3,R5
        BLO     16
        DEC     R3
        BR      14
10:     MOV     R4,R3
        ADD     #10,R3
102:    CMPB    #'.,(R4)+
        BEQ     101
        CMP     R4,R5
        BLO     102
103:    MOVB    (PC)+,(R3)+
        .BYTE   '.,'N
        MOVB    (PC)+,(R3)+
        .BYTE   'S,'D
        INC     PC
        BR      103
104:    MOVB    #40,(R3)+
        CMP     R3,R5
        BLO     104
101:    MOV     (PC)+,R0
        .BYTE   232,12
        EMT     16
        SWAB    R0
        EMT     16
        RETURN

RENAME: CLR     R1
        MOV     #326,R2
        CMP     #20040,(R2)
        BNE     19
        MOV     R2,R5
        MOV     #120114,R4
        MOV     #10,R0
17:     MOVB    (R4)+,(R5)+
        SOB     R0,17
        MOVB    #'.,(R5)+
        MOVB    (R4)+,(R5)+
        MOVB    (R4)+,(R5)+
        MOVB    (R4)+,(R5)+
19:     CMPB    (R2),#'.
        BEQ     18
        CMPB    (R2),#40
        BEQ     18
        BITB    (R2),#100
        BEQ     0NOCH
        BICB    #40,(R2)
0NOCH:  BITB    (R2)+,(R1)+
        CMP     #10,R1
        BNE     19
18:     MOVB    (PC)+,(R2)+
        .BYTE   '.,'S
        MOVB    (PC)+,(R2)+
        .BYTE   'T,'N
        INC     PC
        BR      18
        BIT     (R1)+,(R1)+
21:     CMP     R1,#20
        BHI     20
        MOVB    #40,(R2)+
        INC     R1
        BR      21
20:     RETURN

FORMAT: MOV     #20,R0
        MOV     #7417,R2
22:     MOV     R2,(R1)
        MOV     R2,2(R1)
        MOV     R2,10(R1)
        ADD     #100,R1
        SOB     R0,22
        RETURN

MOVE:25:MOV     (R1)+,(R3)+
        CMP     R1,R5
        BLO     25
        CLR     R3
        ADD     #20,R5
        MOV     #75000,R4
27:     CMP     (R5),#-1
        BEQ     26
        MOV     (R5)+,(R4)+
        INC     R3
        BR      27
26:     DEC     R3
        MOV     R3,@#74776
        RETURN

MAIN:   MOV     #-1,R0
        MOVB    R0,PRSAM
        MOVB    R0,PRVOL
        MOVB    R0,PRDLT
        MOVB    R0,PRVP
        MOV     #400,PR
        CLR     NIL
        CLR     FDLIT
        CLR     FSAMPL
        MOV     #60200,B0
        CLR     B2

        CLR     LENP

M2:     CLR     R0
        BISB    (R5)+,R0
        CMP     #377,R0
        BNE     0
        TST     NOSCR
        BNE     0I1
        MOV     #-1,(R4)
        MOV     (R4)+,(R4)+
0I1:    RETURN
0:      TSTB    R0
        BNE     1
M4:     BICB    #177,B0
        BISB    R0,B0
        TSTB    FDLIT
        BEQ     30
        BICB    #200,B0
        BR      31
30:     BISB    #200,B0
31:     TSTB    FVOLUM
        BEQ     32
        BICB    #100,B1
        BR      33
32:     BISB    #100,B1
        BICB    #17,B2
33:     TSTB    FSAMPL
        BEQ     34
        BICB    #40,B1
        BR      35
34:     BISB    #40,B1
        BICB    #360,B2
35:     TSTB    FV
        BEQ     36
        BICB    #200,B1
        BR      37
36:     BISB    #200,B1
37:     TST     NOSCR
        BNE     0I2
        MOV     B0,(R4)+
        MOV     B2,(R4)+
        BR      0I3
0I2:    INC     LENP
        MOV     LENP,R3
        CALL    DECOUT
0I3:    MOV     (PC)+,R0
NIL:    .WORD   0
        BEQ     22
23:     TST     NOSCR
        BNE     0I4
        MOV     #160376,(R4)+
        CLR     (R4)+
        BR      0I5
0I4:    INC     LENP
        MOV     LENP,R3
        CALL    DECOUT
0I5:    SOB     R0,23
22:     CLR     FDLIT
        CLR     FSAMPL
0GOTO:  BR      M2

1:      CMP     #376,R0
        BNE     3
        MOV     #176,R0
        BR      M4

3:      DEC     R0
        CMP     R0,#140
        BHIS    5
        INC     R0
        BR      M4

5:      CMP     R0,#160
        BHIS    6
        BIC     #177760,R0
        CMPB    R0,PRSAM
        BEQ     0GOTO
        MOVB    R0,PRSAM
        INCB    FSAMPL
        ASL     R0
        ASL     R0
        ASL     R0
        ASL     R0
        BICB    #360,B2
        BISB    R0,B2
        BR      0GOTO

6:      CMP     R0,#200
        BHIS    7
        BIC     #177760,R0
        CMPB    R0,PRVOL
        BEQ     0GOTO
        MOVB    R0,PRVOL
        INCB    FVOLUM
        BICB    #17,B2
        BISB    R0,B2
        BR      0GOTO

7:      CMP     R0,#220
        BHIS    8
        BIC     #177760,R0
        CMPB    R0,PRDLT
        BEQ     0GOTO
        MOVB    R0,PRDLT
        INCB    FDLIT
        MOVB    R0,B3
        BR      0GOTO

8:      CMP     R0,#240
        BHIS    9
        BIC     #177760,R0
        CMPB    R0,PRVP
        BEQ     0G
        MOVB    R0,PRVP
        INCB    FVOLUM
        BICB    #17,B2
        BISB    R0,B2
0G:     INCB    FV
        CLR     R0
        BISB    (R5)+,R0
        CMP     R0,PR
        BEQ     21
        MOV     R0,PR
        INCB    FDLIT
        BR      24

21:     CLRB    FDLIT
24:     MOVB    PR,B3
        BR      0GOTO

9:      SUB     #240,R0
        MOV     R0,NIL
        BR      0GOTO


OUTS:   MOV     R0,-(SP)
        MOV     R2,-(SP)
        MOV     @#160,R2
003:    MOVB    (R1)+,R0
        BEQ     002
        CMPB    #25,R0
        BNE     001
        ADD     #1200,R2
        MOV     R2,@#160
        BR      003
001:    EMT     16
        BR      003
002:    MOV     (SP)+,R2
        MOV     (SP)+,R0
        INC     R1
        BIC     #1,R1
        RTS     R1

WAITK:  BIT     #100,@#177716
        BEQ     WAITK
000:    BIT     #100,@#177716
        BNE     000
        RETURN

;вывод атрибутов:
INFO:   MOV     PC,NOSCR
        MOV     LOADDR,R4
        ADD     #3006,R4
        MOV     R4,R5
        JSR     R1,OUTS
        .ASCIZ  "Темп: "
        .EVEN
        MOV     (R4)+,R3
        CALL    DECOUT
        JSR     R1,OUTS
        .ASCIZ  <12>"Количество сэмплов: "
        .EVEN
        MOV     (R4)+,R0
        ADD     R5,R0   ;адрес списка разделов
        ADD     (R4)+,R5 ;адрес таблицы смещений
        MOV     R0,R3
        SUB     #20,R3
        SUB     R4,R3
        ASL     R3
        ASL     R3
        CLRB    R3
        SWAB    R3
        CALL    DECOUT
        JSR     R1,OUTS
        .ASCIZ  <12>"Количество разделов: "
        .EVEN
        MOV     R0,R1
        MOV     #-1,R3
0:      INC     R3
        CALL    DECOUT
        CMP     (R1)+,#-1
        BNE     0
        JSR     R1,OUTS
        .ASCIZ  <12>"Количество паттернов: "
        .EVEN
        MOV     R5,R4
        MOV     R5,BATS
        ADD     (R4),R4
        MOV     R4,EATS
        CLR     R3
1:      INC     R3
        CALL    DECOUT
        ADD     #6,R5
        CMP     R5,EATS
        BLO     1
        JSR     R1,OUTS
        .ASCIZ  <12>"Длины паттернов:"
        .EVEN
        CLR     -(SP)
        MOV     BATS,R1
2:      MOV     (R1),R5
        ADD     BATS,R5
        JSR     R1,OUTS
        .ASCIZ  <12>"Паттерн #"
        .EVEN
        INC     (SP)
        MOV     (SP),R3
        CALL    DECOUT
        CALL    LOC
        JSR     R1,OUTS
        .ASCIZ  ": "
        .EVEN
        CALL    MAIN
        CALL    LOC
        CALL    MAIN
        CALL    LOC
        CALL    MAIN
        ADD     #6,R1
        CMP     R1,EATS
        BLO     2
        CLR     (SP)+
        CALL    WAITK
        CLR     NOSCR
        RETURN

LOC:    MOV     R1,-(SP)
        EMT     26
        CMP     (R1)+,(R1)+
        EMT     24
        MOV     (SP)+,R1
        RETURN


;вход:  R3 - число
DECOUT: JSR     R5,@#154512
        EMT     26
        MOV     R1,-(SP)
        MOV     R2,-(SP)
        MOV     PC,R1
        MOV     #10,R2
6:      MOV     #60,R0
1:      CMP     R3,L10530(R2)
        BLT     0
        INC     R0
        SUB     L10530(R2),R3
        BR      1

0:      CMP     #60,R0
        BNE     2
        TST     R1
        BEQ     3
        TST     R2
        BNE     4
2:      CLR     R1
3:      EMT     16
4:      TST     R2
        BEQ     5
        TST     -(R2)
        BR      6
5:      MOV     #40,R0
        EMT     16
        MOV     (SP)+,R2
        MOV     (SP)+,R1
        EMT     24
        RETURN
L10530: .WORD   1,10.,100.,1000.,10000.

EOF:    .END




