;ББББББББББББББББББББББББББББББББББББББББББББББББББББББББББББББББББББББББББББББ
;
; SHOCK! PLAY 32BIT VERSION BY TSC/SHOCK! [S3M]
;
;ББББББББББББББББББББББББББББББББББББББББББББББББББББББББББББББББББББББББББББББ

.386
.MODEL FLAT,C
.CODE

;ББББББББББББББББББББББББББББББББББББББББББББББББББББББББББББББББББББББББББББББ

SN_OFF		DD	1308
VL_OFF		DD	1468
OR_OFF		DD	1628
ON_OFF		DD	1636
LI_OFF		DD	1788
TP_OFF		DD	1948
SP_OFF		DD	2108
BP_OFF		DD	((14*80)+19)*2
VO_OFF		DD	((8*80)+61)*2
VN_OFF		DD	((8*80)+58)*2
EF_OFF		DD	((8*80)+40)*2
MV_OFF		DD	((9*80)+13)*2
SS_OFF          DD      ((18*80)+14)*2
DM_OFF          DD      ((21*80)+14)*2
FM_OFF          DD      ((22*80)+14)*2
S3MNAMEPUFFER	DB	13 DUP (0)
VOLDECC 	DW	100
SP_GUSBASEHEX   DW      0
DOSMEMSIZE      DW      640
FREEDOSMEMSIZE  DW      319
VOLUMES         DB      32 DUP (0)
LASTVOLSLIDES   DB      32 DUP (0)
COLOR		DB	8
SAFE		DB	5  DUP (0)
TEMP		DB	10 DUP (0)
INSNUM		DW	0
VOLUMEBAR	DB	'ў',09,'ў',09,'ў',09,'ў',09,'ў',09,'ў',09,'ў',09,'ў',09
		DB	'ў',07,'ў',07,'ў',07,'ў',07,'ў',07,'ў',15,'ў',15,'ў',15
NOBAR		DB	'ў',8,'ў',8,'ў',8,'ў',8,'ў',8,'ў',8,'ў',8,'ў',8,'ў',8,'ў',8
		DB	'ў',8,'ў',8,'ў',8,'ў',8,'ў',8,'ў',8

EFFECT1 	DB	'             ' ; 0
		DB	'SET SPEED    ' ; 1
		DB	'JUMP ORDER   ' ; 2
		DB	'BREAK PATTERN' ; 3
		DB	'VOLUME SLIDE ' ; 4
		DB	'PORTA DOWN   ' ; 5
		DB	'PORTA UP     ' ; 6
		DB	'PORTA TO NOTE' ; 7
		DB	'VIBRATO      ' ; 8
		DB	'TREMOR       ' ; 9
		DB	'ARPEGGIO     ' ; A
		DB	'VOLSL+VIBRATO' ; B
		DB	'VOLSL+PORTA  ' ; C
		DB	'             ' ; D
		DB	'             ' ; E
		DB	'SAMPLE OFFSET' ; F
		DB	'             ' ; 10
		DB	'RETRIG NOTE  ' ; 11
		DB	'TREMOLO      ' ; 12
		DB	'SPECIAL EFF. ' ; 13
		DB	'SET TEMPO    ' ; 14
		DB	'FINE VIBRATO ' ; 15
		DB	'GLOBAL VOLUME' ; 16
		DB	'             ' ; 17
		DB	'DMP PAN      ' ; 18

SPECIAL_EFFECTS DB	'SET FILTER   ' ; 0
		DB	'GLISSANDO    ' ; 1
		DB	'SET FINETUNE ' ; 2
		DB	'SET VIBRATO  ' ; 3
		DB	'SET TREMOLO  ' ; 4
		DB	'             ' ; 5
		DB	'             ' ; 6
		DB	'             ' ; 7
		DB	'SET PAN      ' ; 8
		DB	'             ' ; 9
		DB	'OLD STEREO EF' ; A
		DB	'LOOP PATTERN ' ; B
		DB	'NOTE CUT     ' ; C
		DB	'NOTE DELAY   ' ; D
		DB	'PATTERN DELAY' ; E
		DB	'FUNK REPEAT  ' ; F

VOLSLIDES	DB	'VOLSLIDE DOWN' ; D0Y
		DB	'VOLSLIDE UP  ' ; DX0
		DB	'FINE VOL. DWN' ; DFY
		DB	'FINE VOL. UP ' ; DXF

;ББББББББББББББББББББББББББББББББББББББББББББББББББББББББББББББББББББББББББББББ

PUBLIC	PLAYER

EXTRN	SP_EFFECTPAR:	BYTE
EXTRN	SP_EFFECTNUM:	BYTE
EXTRN	GUSVOLUMES:	BYTE
EXTRN	SP_CHANNELS:	DWORD
EXTRN	SP_SPEEDDEFAULT:BYTE
EXTRN	SP_TEMPODEFAULT:BYTE
EXTRN	SP_GUSBASE:	WORD
EXTRN	SP_MASTERVOLUME:BYTE
EXTRN	SP_ACTORDER:	BYTE
EXTRN	SP_ACTROW:	BYTE
EXTRN	SP_SONGLENGTH:	BYTE
EXTRN   SP_SAMPLESSIZE: DWORD
EXTRN	MODPLACE:	DWORD
EXTRN	SP_NOTE:	WORD

PLAYER: PUSHAD
REDO:	LEA	ESI,SPSCREEN
        CALL    BASECONVERTER           ; WOW, LOOK AT THIS LAME ROUTINE
	CALL	SP_WRITE_BSAVE
	CALL	SP_WRITEMAINSCR
	CALL	HIDECURSOR

MAIN:	CALL	SP_REWRITE
	MOV	AX,0100H
	INT	16H
	JZ	MAIN
	CALL	CLEARBUFFER
        CMP     AL,1BH                  ; ESC
        JE      ENDPLAY
        CMP     AH,51H                  ; PG DOWN
	JE	NEXTO
        CMP     AH,4DH                  ; ->
        JE      NEXTO
        CMP     AH,49H                  ; PG UP
	JE	PREVO
        CMP     AH,4BH                  ; <-
        JE      PREVO
        CMP     AL,2BH                  ; +
	JE	VOLUP
        CMP     AL,2DH                  ; -
	JE	VOLDWN
        CMP     AH,3BH                  ; F1
	JE	HELPSC
        CMP     AL,13                   ; ENTA
	JE	SAMPLES
	JMP	MAIN

NEXTO:	MOVZX	AX,SP_SONGLENGTH
	CMP	SP_ACTORDER,AL
	JNB	MAIN
	INC	SP_ACTORDER	    ;JUMP TO NEXT ORDER
	MOV	SP_ACTROW,0
	JMP	MAIN

PREVO:	CMP	SP_ACTORDER,0
	JE	MAIN
	DEC	SP_ACTORDER	    ;JUMP TO PREVIOUS ORDER
	MOV	SP_ACTROW,0
	JMP	MAIN

VOLUP:	CMP	SP_MASTERVOLUME,64	; INCREASE VOLUME
	JAE	MAIN
	INC	SP_MASTERVOLUME
	JMP	MAIN

VOLDWN: CMP	SP_MASTERVOLUME,0	; DECREASE VOLUME
	JE	MAIN
	DEC	SP_MASTERVOLUME
	JMP	MAIN
HELPSC: LEA	ESI,F1SCREEN
	CALL	SP_WRITE_BSAVE
KEYIN1: MOV	AX,0100H
	INT	16H
	JZ	KEYIN1
	CALL	CLEARBUFFER
	CMP	AL,1BH
	JE	ENDPLAY
	CMP	AH,3BH
	JNE	KEYIN1
	JMP	REDO

SAMPLES:CALL	SAMPLEINFOMAPWRITER
	JMP	REDO

ENDPLAY:MOV	AX,3
	INT	10H
	POPAD
	RET

;ББББББББББББББББББББББББББББББББББББББББББББББББББББББББББББББББББББББББББББББ

BASECONVERTER:
        CMP     SP_GUSBASE,210H
        JNE     NO210
        MOV     SP_GUSBASEHEX,0D2H
NO210:
        CMP     SP_GUSBASE,220H
        JNE     NO220
        MOV     SP_GUSBASEHEX,0DCH
NO220:
        CMP     SP_GUSBASE,230H
        JNE     NO230
        MOV     SP_GUSBASEHEX,0E6H
NO230:
        CMP     SP_GUSBASE,240H
        JNE     NO240
        MOV     SP_GUSBASEHEX,0F0H
NO240:
        CMP     SP_GUSBASE,250H
        JNE     NO250
        MOV     SP_GUSBASEHEX,0FAH
NO250:
        CMP     SP_GUSBASE,260H
        JNE     NO260
        MOV     SP_GUSBASEHEX,104H
NO260:
        CMP     SP_GUSBASE,270H
        JNE     NO270
        MOV     SP_GUSBASEHEX,10EH
NO270:
        RET

SP_VOLUMEFUCKER:
	PUSHAD
	CMP	VOLDECC,0
	JA	NEMVOLDEC
	MOV	VOLDECC,100		 ; KELL DELAY, VAGY IGEN GYORS LESZ!
	LEA	ESI,VOLUMES
	LEA	EDI,VOLUMES
	MOV	CX,32
VFCK1:	LODSB
	CMP	AL,0
	JE	ALREADY0		 ; LECSOKKENTGETJUK 1-EL
	DEC	AL
ALREADY0:
	STOSB
	DEC	CX
	JNZ	VFCK1
NEMVOLDEC:
	DEC	VOLDECC
        MOV     EBP,0                      ; HA VAN NOTE AKKOR FRISSITJUK A
NOTEEX: CMP     WORD PTR SP_NOTE[EBP*2],0  ; VOLUME INFOT
        JE      NONOTE
	MOV	AL,GUSVOLUMES[EBP]
	MOV	VOLUMES[EBP],AL
NONOTE: INC	EBP
	CMP	EBP,32
	JNE	NOTEEX
	POPAD
	RET

SP_WRITEMAINSCR:
	PUSHAD
	MOV	ESI,MODPLACE
	MOV	CX,23
	MOV	EDI,SN_OFF	       ; WRITE SONGNAME
	MOV	COLOR,8
	CALL	WRITE16
        MOV     AX,SP_GUSBASEHEX
	MOV	DX,0
	LEA	EDI,TEMP+2
	CALL	ASCII
	LEA	ESI,TEMP
	MOV	EDI,BP_OFF
	MOV	CX,3
	MOV	COLOR,8
	CALL	WRITE16
	CALL	DELTEMP

        MOV     ESI,0
	MOVZX	AX,SP_SONGLENGTH      ; WRITE MAX. ORDER
        INC     AX
	MOV	DX,0
	LEA	EDI,TEMP+2
	CALL	ASCII
        LEA     ESI,TEMP
	MOV	EDI,ON_OFF
	MOV	CX,3
	MOV	COLOR,8
	CALL	WRITE16
	CALL	DELTEMP

        MOV     ESI,0
        MOV     AX,DOSMEMSIZE         ; WRITE DOS MEMORY SIZE
	MOV	DX,0
	LEA	EDI,TEMP+2
	CALL	ASCII
        LEA     ESI,TEMP
        MOV     EDI,DM_OFF
	MOV	CX,3
	MOV	COLOR,8
	CALL	WRITE16
	CALL	DELTEMP

        MOV     ESI,0
        MOV     AX,FREEDOSMEMSIZE         ; WRITE FREE DOS MEMORY SIZE
	MOV	DX,0
	LEA	EDI,TEMP+2
	CALL	ASCII
        LEA     ESI,TEMP
        MOV     EDI,FM_OFF
	MOV	CX,3
	MOV	COLOR,8
	CALL	WRITE16
	CALL	DELTEMP

        MOV     ESI,0
        MOV     EAX,SP_SAMPLESSIZE        ; WRITE SAMPLESSIZE
        SHR     EAX,10
	MOV	DX,0
	LEA	EDI,TEMP+2
	CALL	ASCII
        LEA     ESI,TEMP
        MOV     EDI,SS_OFF
	MOV	CX,3
	MOV	COLOR,8
	CALL	WRITE16
	CALL	DELTEMP
        
        POPAD
	RET

SP_REWRITE:
	PUSHAD
	MOV	COLOR,8
	MOVZX	AX,SP_ACTORDER
	INC	AX
	MOV	EDX,0
	LEA	EDI,TEMP+2
	CALL	ASCII
	LEA	ESI,TEMP
	MOV	EDI,OR_OFF
	MOV	ECX,3
	CALL	WRITE16
	CALL	DELTEMP
	MOVZX	AX,SP_ACTROW   ; WRITE SP_ACTROW
	MOV	EDX,0
	LEA	EDI,TEMP+1
	CALL	ASCII
	LEA	ESI,TEMP
	MOV	EDI,LI_OFF
	MOV	ECX,2
	CALL	WRITE16
	CALL	DELTEMP

	MOVZX	AX,BYTE PTR SP_TEMPODEFAULT   ; WRITE TEMPO
	MOV	EDX,0
	LEA	EDI,TEMP+2
	CALL	ASCII
	LEA	ESI,TEMP
	MOV	EDI,TP_OFF
	MOV	ECX,3
	CALL	WRITE16
	CALL	DELTEMP

	MOVZX	AX,BYTE PTR SP_MASTERVOLUME  ; WRITE VOLUME
	MOV	EDX,0
	LEA	EDI,TEMP+2
	CALL	ASCII
	LEA	ESI,TEMP
	MOV	EDI,MV_OFF
	MOV	ECX,3
	CALL	WRITE16
	CALL	DELTEMP

	MOVZX	AX,BYTE PTR SP_SPEEDDEFAULT; WRITE SPEED
	MOV	EDX,0
	LEA	EDI,TEMP
	CALL	ASCII
	LEA	ESI,TEMP
	MOV	EDI,SP_OFF
	MOV	ECX,1
	CALL	WRITE16
	CALL	DELTEMP


	PUSH	VO_OFF
        CALL    SP_VOLUMEFUCKER
	MOV	EBP,0
BARWR:
	MOVZX	ECX,BYTE PTR VOLUMES[EBP]	 ; WRITE VOLUME BARS
        PUSH    EBP
	MOV	DX,0
	SHR	ECX,2
        PUSH    ECX
	MOV	EDI,VO_OFF
	LEA	ESI,VOLUMEBAR
	CALL	WRITE16NC
	POP	EAX
        MOV     ECX,16
	SUB	ECX,EAX
	MOV	EDI,VO_OFF
	SHL	EAX,1
	ADD	EDI,EAX
        LEA     ESI,NOBAR
	CALL	WRITE16NC
	POP	EBP
        ADD     VO_OFF,160
	INC	EBP
	MOV	EAX,SP_CHANNELS
	CMP	EBP,EAX
	JB	BARWR
	POP	VO_OFF
        MOV     EBP,0
	PUSH	VN_OFF
VN_WRITER:
        MOVZX   EAX,BYTE PTR GUSVOLUMES[EBP]        ; WRITE VOLUME NUMBERS
	MOV	COLOR,0FH
	CMP	AX,48
	JAE	COLOREND
	MOV	COLOR,0BH
	CMP	AX,32
	JAE	COLOREND
	MOV	COLOR,3
	CMP	AX,16
	JAE	COLOREND
	MOV	COLOR,8
COLOREND:
	PUSH	EBP
	MOV	EDX,0
	LEA	EDI,TEMP+1
	CALL	ASCII
	LEA	ESI,TEMP
	MOV	EDI,VN_OFF
	MOV	ECX,2
	CALL	WRITE16
	CALL	DELTEMP
	POP	EBP
	ADD	VN_OFF,160
	INC	EBP
	MOV	EAX,SP_CHANNELS
	CMP	EBP,EAX
	JB	VN_WRITER
	POP	VN_OFF

	MOV	COLOR,3
	MOV	EBP,0
	PUSH	EF_OFF
EF_WRITER:
	MOVZX	EAX,BYTE PTR SP_EFFECTNUM[EBP]	      ; WRITE EFFECTS
	CMP	EAX,19
	JNE	NEMEXTRA
	MOVZX	EAX,BYTE PTR SP_EFFECTPAR[EBP]
	SHR	EAX,4
        PUSH    EBP
	MOV	EDX,0
	MOV	EBX,13
	MUL	BX
	LEA	ESI,SPECIAL_EFFECTS
	ADD	ESI,EAX
	JMP	CONTEF
NEMEXTRA:
	CMP	AX,4
	JNE	NEMVSLIDE
	PUSH	EBP
	CMP	BYTE PTR SP_EFFECTPAR[EBP],0
	JNE	VANOPERATOR
	MOV	AL,BYTE PTR LASTVOLSLIDES[EBP]
	JMP	NINCSSP_EFFECTPAR
VANOPERATOR:
	MOV	AL,BYTE PTR SP_EFFECTPAR[EBP]
NINCSSP_EFFECTPAR:
	MOV	BYTE PTR LASTVOLSLIDES[EBP],AL
	CMP	AL,0F0H
	JE	VOLSUP
	SHR	AL,4
	OR	AL,AL
	JZ	VOLDN
	CMP	AL,0FH
	JE	FINEVD
	JMP	VOLSUP
VOLDN:	LEA	ESI,VOLSLIDES
	JMP	CONTEF
FINEVD: LEA	ESI,VOLSLIDES+26
	JMP	CONTEF
VOLSUP: MOV	AL,BYTE PTR LASTVOLSLIDES[EBP]
	TEST	AL,0FH
	JNE	FINVUP
	LEA	ESI,VOLSLIDES+13
	JMP	CONTEF
FINVUP: LEA	ESI,VOLSLIDES+39
	JMP	CONTEF
NEMVSLIDE:
	PUSH	EBP
	MOV	EDX,0
	MOV	EBX,13
	MUL	BX
	LEA	ESI,EFFECT1
	MOVZX	EAX,AX
	ADD	ESI,EAX
CONTEF: MOV	EDI,EF_OFF
	MOV	ECX,13
	CALL	WRITE16
	CALL	DELTEMP
	POP	EBP
	ADD	EF_OFF,160
	INC	EBP
	MOV	EAX,SP_CHANNELS
	CMP	EBP,EAX
	JB	EF_WRITER
	POP	EF_OFF
	POPAD
	RET

SP_WRITE_BSAVE:
	PUSHAD
	MOV	EDI,0B8000H
	MOV	ECX,2000
	REP	MOVSW
	POPAD
	RET

WRITE16:PUSHAD
	CMP	CX,0
	JE	NOWRITE
	ADD	EDI,0B8000H
WR16LP: MOVSB
	MOV	AL,COLOR
	STOSB
	DEC	CX
	JNZ	WR16LP
NOWRITE:POPAD
	RET

WRITE16NC:
	PUSHAD
	CMP	CX,0
	JE	NOWRITENC
	ADD	EDI,0B8000H
WR16NCLP:
	MOVSB
	MOVSB
	DEC	CX
	JNZ	WR16NCLP
NOWRITENC:
	POPAD
	RET

DELTEMP:PUSHAD
	LEA	EDI,TEMP
	MOV	ECX,5
	MOV	AX,0
	REP	STOSW
	POPAD
	RET

SAMPLEINFOMAPWRITER:
	PUSHAD
	MOV	EDI,0B8000H
	ADD	EDI,(8*160)+6
	MOV	CX,16
SIMFL1: PUSH	CX
	MOV	CX,76
	MOV	AX,0
	REP	STOSW
	ADD	EDI,8
	POP	CX
	LOOP	SIMFL1
	MOV	EDI,0B8000H
	ADD	EDI,(8*160)+10
	MOV	EBX,MODPLACE
	ADD	EBX,22H
	MOVZX	EBX,WORD PTR [EBX]
	MOV	INSNUM,BX
	MOV	EBX,MODPLACE
	ADD	EBX,20H
	MOVZX	EBX,WORD PTR [EBX]
	ADD	EBX,62H
	AND	EBX,254
	ADD	EBX,MODPLACE
	MOVZX	ESI,WORD PTR [EBX]
	SHL	ESI,4
        SUB     ESI,32
        ADD     ESI,MODPLACE
	CMP	INSNUM,15
	JBE	OKESAM1
	MOV	ECX,15
	SUB	INSNUM,15
	JMP	SAMPLELOOP0
OKESAM1:MOVZX	ECX,WORD PTR INSNUM
	MOV	INSNUM,0
SAMPLELOOP0:
	PUSH	ECX
	MOV	ECX,28
SAMPLELOOP1:
	MOV	BL,BYTE PTR [ESI]
	MOV	[EDI],BL
	MOV	BL,8
	MOV	[EDI+1],BL
	ADD	EDI,2
	INC	ESI
	LOOP	SAMPLELOOP1
	ADD	EDI,104
	ADD	ESI,80-28
	POP	ECX
	LOOP	SAMPLELOOP0
	CMP	INSNUM,0
	JE	KEYIN2
	MOV	EDI,0B8000H
	ADD	EDI,(8*160)+88
	CMP	INSNUM,15
	JBE	OKSAM2
	SUB	INSNUM,15
	MOV	ECX,15
	JMP	SAMPLELOOP0
OKSAM2: MOVZX	ECX,WORD PTR INSNUM
	MOV	INSNUM,0
	JMP	SAMPLELOOP0
KEYIN2: MOV	AX,0100H
	INT	16H
	JZ	KEYIN2
	CALL	CLEARBUFFER
	CMP	AL,1BH
	JE	ENDPLAY
	CMP	AL,13
	JNE	KEYIN2
	POPAD
	RET

;БББББББББББББББББББББББББ CLEAR KEYBOARD BUFFER ББББББББББББББББББББББББББББББ

CLEARBUFFER:
	PUSH	AX
	MOV	AL,0
	MOV	AH,0CH
	INT	21H
	POP	AX
	RET
;БББББББББББББББББББББББББББ HIDING THE CURSOR ББББББББББББББББББББББББББББББББ

HIDECURSOR:
	PUSHAD
	MOV	AH,2
	MOV	BH,0
	MOV	DH,100
	MOV	DL,100
	INT	10H
	POPAD
	RET

;БББББББББББББББББББББББББ HEX -> ASCII CONVERTER БББББББББББББББББББББББББББББ

ASCII:	MOV	BP,0
	PUSH	BX
	XCHG	BP,DX		      ;SAVE HiGH WORD
	MOV	BX,0AH		      ;DiViSOR
	MOV	CL,30H		      ;CONVERSiON FOR ASCii
RPT1:	CMP	BP,0		      ;ARE WE DONE WiTH HiGH WORDS
	JZ	RPT2		      ;YES
	XCHG	AX,BP		      ;NO-GET HiGH WORD
	XOR	DX,DX		      ;CLEAR DX
	DiV	BX
	XCHG	BP,AX		      ;THiS WiLL BE THE NEW HiGH WORD
	DiV	BX		      ;DiViDE LOW WORD + REMAiNDER
	OR	DL,CL		      ;CONVERT HEX VALUE TO ASCii
	MOV	[EDi],DL	      ;QUOTiENT iNTO STORAGE
	DEC	EDi		      ;STEP BACK ONE BYTE
	JMP	RPT1		      ;GO AGAiN
RPT2:	XOR	DX,DX		      ;CLEAR DX
	DiV	BX
	OR	DL,CL		      ;CONVERT HEX VALUE TO ASCii
	MOV	[EDi],DL	      ;QUOTiENT iNTO STORAGE
	DEC	Di		      ;STEP BACK ONE BYTE
	CMP	AX,0		      ;ARE WE DONE?
	JNZ	RPT2		      ;NO
	POP	BX
	RET			      ;YES

SPSCREEN:
iNCLUDE SP.INC
F1SCREEN:
iNCLUDE F1.INC

END
