     1                                  ; ****************************************************************************
     2                                  ; tmodplay.s (for TRDOS 386)
     3                                  ; ----------------------------------------------------------------------------
     4                                  ; TMODPLAY.PRG ! SOUND BLASTER 16 MOD PLAYER & VGA DEMO program by Erdogan TAN
     5                                  ;
     6                                  ; 21/10/2017
     7                                  ;
     8                                  ; [ Last Modification: 28/10/2017 ]  !!! STEREO MOD PLAYING !!!
     9                                  ;
    10                                  ; For 640x480x16 display, 'TNYPL211' source code ('EX1A.ASM' and 'EX1B.ASM'
    11                                  ; by Carlos Hasan, 1994) is modified in order to use previous ('modplay7.s')
    12                                  ; scope method as stereo. (Track/channel scope method -in TNYPL211 files- 
    13                                  ; is/was not applied because TRDOS 386 adaption of the tiny mod player uses 
    14                                  ; dma buffer for immediate -synchronized- displaying of sound waves.
    15                                  ; So, stereo wave display -two waves, two scopes- is normally applicable.)
    16                                  ;
    17                                  ; Modified from 'modplay7.s' (MODPLAY7.PRG) source code by Erdogan Tan
    18                                  ; (20/10/2017). ((Stereo mod playing with TRDOS 386 audio system calls...))
    19                                  ;
    20                                  ; Derived from source code of 'PLAY.EXE' (TINYPLAY) by Carlos Hasan (1993)
    21                                  ;          PLAY.EXE: PLAY.ASM, MODLOAD.ASM, MODPLAY.ASM, SB.ASM
    22                                  ;
    23                                  ; Stereophonic mod playing code prototype: 
    24                                  ;		'modplay6.s' (AC97) by Erdogan Tan (18/10/2017)
    25                                  ;
    26                                  ; Modified by using the source code of 'tinyply3.s' ('TINYPLY3.PRG') 
    27                                  ; by Erdogan Tan (07/10/2017)
    28                                  ;
    29                                  ; Modified from 'playwav3.s' (13/06/2017)
    30                                  ;
    31                                  ; Modified from 'PLAYMOD.PRG' ('playmod.s') source code by Erdogan Tan
    32                                  ;			                     (23/06/2017)
    33                                  ;
    34                                  ; Derived from source code of 'TINYPLAY.COM' ('TINYPLAY.ASM') by Erdogan Tan
    35                                  ;				      (04/03/2017) 
    36                                  ; Assembler: NASM 2.11
    37                                  ; ----------------------------------------------------------------------------
    38                                  ;	   nasm  tmodplay.s -l tmodplay.txt -o TMODPLAY.PRG	
    39                                  ; ****************************************************************************
    40                                  ; PLAYMOD.ASM by Erdogan Tan (for MSDOS) (15/02/2017)
    41                                  ; TMODPLAY.ASM by Erdogan Tan (for MSDOS) (01/10/2017)
    42                                  
    43                                  ; 01/03/2017
    44                                  ; 16/10/2016
    45                                  ; 29/04/2016
    46                                  ; TRDOS 386 system calls (temporary list!)
    47                                  _ver 	equ 0
    48                                  _exit 	equ 1
    49                                  _fork 	equ 2
    50                                  _read 	equ 3
    51                                  _write	equ 4
    52                                  _open	equ 5
    53                                  _close 	equ 6
    54                                  _wait 	equ 7
    55                                  _creat 	equ 8
    56                                  _link 	equ 9
    57                                  _unlink	equ 10
    58                                  _exec	equ 11
    59                                  _chdir	equ 12
    60                                  _time 	equ 13
    61                                  _mkdir 	equ 14
    62                                  _chmod	equ 15
    63                                  _chown	equ 16
    64                                  _break	equ 17
    65                                  _stat	equ 18
    66                                  _seek	equ 19
    67                                  _tell 	equ 20
    68                                  _mount	equ 21
    69                                  _umount	equ 22
    70                                  _setuid	equ 23
    71                                  _getuid	equ 24
    72                                  _stime	equ 25
    73                                  _quit	equ 26	
    74                                  _intr	equ 27
    75                                  _fstat	equ 28
    76                                  _emt 	equ 29
    77                                  _mdate 	equ 30
    78                                  _video 	equ 31
    79                                  _audio	equ 32
    80                                  _timer	equ 33
    81                                  _sleep	equ 34
    82                                  _msg    equ 35
    83                                  _geterr	equ 36
    84                                  _fpsave	equ 37
    85                                  _pri	equ 38
    86                                  _rele	equ 39
    87                                  _fff	equ 40
    88                                  _fnf	equ 41
    89                                  _alloc	equ 42
    90                                  _dalloc equ 43
    91                                  _calbac equ 44		
    92                                  
    93                                  %macro sys 1-4
    94                                      ; 29/04/2016 - TRDOS 386 (TRDOS v2.0)	
    95                                      ; 03/09/2015	
    96                                      ; 13/04/2015
    97                                      ; Retro UNIX 386 v1 system call.	
    98                                      %if %0 >= 2   
    99                                          mov ebx, %2
   100                                          %if %0 >= 3    
   101                                              mov ecx, %3
   102                                              %if %0 = 4
   103                                                 mov edx, %4   
   104                                              %endif
   105                                          %endif
   106                                      %endif
   107                                      mov eax, %1
   108                                      ;int 30h
   109                                      int 40h ; TRDOS 386 (TRDOS v2.0)	   
   110                                  %endmacro
   111                                  
   112                                  ; TRDOS 386 (and Retro UNIX 386 v1) system call format:
   113                                  ; sys systemcall (eax) <arg1 (ebx)>, <arg2 (ecx)>, <arg3 (edx)>
   114                                  
   115                                  ; 19/06/2017
   116                                  BUFFERSIZE equ 32768
   117                                  
   118                                  ; ----------------------------------------------------------------------------
   119                                  ; Tiny MOD Player v0.1b by Carlos Hasan.
   120                                  ;	July 14th, 1993.
   121                                  
   122                                  ;=============================================================================
   123                                  ;  
   124                                  ;=============================================================================
   125                                  
   126                                  [BITS 32]
   127                                  [org 0]
   128                                  
   129                                  Start:
   130                                  	; clear bss
   131 00000000 B9[00000900]            	mov	ecx, EOF
   132 00000005 BF[79500000]            	mov	edi, bss_start
   133 0000000A 29F9                    	sub	ecx, edi
   134 0000000C D1E9                    	shr	ecx, 1
   135 0000000E 31C0                    	xor	eax, eax
   136 00000010 F366AB                  	rep	stosw
   137                                  
   138                                  	; Detect (& Enable) Sound Blaster 16 Audio Device
   139 00000013 E82D020000              	call    DetectSB16
   140 00000018 731B                    	jnc     short GetFileName
   141                                  
   142                                  _dev_not_ready:
   143                                  ; couldn't find the audio device!
   144                                  	sys	_msg, MsgNotFound, 255, 0Fh
   144                              <1> 
   144                              <1> 
   144                              <1> 
   144                              <1> 
   144                              <1>  %if %0 >= 2
   144 0000001A BB[E64F0000]        <1>  mov ebx, %2
   144                              <1>  %if %0 >= 3
   144 0000001F B9FF000000          <1>  mov ecx, %3
   144                              <1>  %if %0 = 4
   144 00000024 BA0F000000          <1>  mov edx, %4
   144                              <1>  %endif
   144                              <1>  %endif
   144                              <1>  %endif
   144 00000029 B823000000          <1>  mov eax, %1
   144                              <1> 
   144 0000002E CD40                <1>  int 40h
   145 00000030 E9EF010000                      jmp     Exit
   146                                  
   147                                  GetFileName:
   148                                  	;cmp	ah, 1 ; SB16 Sound card
   149                                  	;jne	_dev_not_ready	
   150                                  	  
   151 00000035 89E6                    	mov	esi, esp
   152 00000037 AD                      	lodsd
   153 00000038 83F802                  	cmp	eax, 2 ; two arguments 
   154                                  		; (program file name & mod file name)
   155 0000003B 0F82EC010000            	jb	pmsg_usage ; nothing to do
   156                                  
   157 00000041 AD                      	lodsd ; program file name address 
   158 00000042 AD                      	lodsd ; mod file name address (file to be read)
   159 00000043 89C6                    	mov	esi, eax
   160 00000045 BF[D0DD0000]            	mov	edi, mod_file_name
   161                                  ScanName:       
   162 0000004A AC                      	lodsb
   163 0000004B 84C0                    	test	al, al
   164 0000004D 0F84DA010000            	je	pmsg_usage
   165 00000053 3C20                    	cmp	al, 20h
   166 00000055 74F3                    	je	short ScanName	; scan start of name.
   167 00000057 AA                      	stosb
   168 00000058 B4FF                    	mov	ah, 0FFh
   169                                  a_0:	
   170 0000005A FEC4                    	inc	ah
   171                                  a_1:
   172 0000005C AC                      	lodsb
   173 0000005D AA                      	stosb
   174 0000005E 3C2E                    	cmp	al, '.'
   175 00000060 74F8                    	je	short a_0	
   176 00000062 20C0                    	and	al, al
   177 00000064 75F6                    	jnz	short a_1
   178                                  
   179 00000066 08E4                    	or	ah, ah		 ; if period NOT found,
   180 00000068 750B                    	jnz	short PrintPMesg ; then add a .MOD extension.
   181                                  SetExt:
   182 0000006A 4F                      	dec	edi
   183 0000006B C7072E4D4F44            	mov	dword [edi], '.MOD'
   184 00000071 C6470400                	mov	byte [edi+4], 0
   185                                  PrintPMesg:      
   186                                  	; Prints the Credits Text.
   187                                  	sys	_msg, Credits, 255, 0Fh
   187                              <1> 
   187                              <1> 
   187                              <1> 
   187                              <1> 
   187                              <1>  %if %0 >= 2
   187 00000075 BB[954F0000]        <1>  mov ebx, %2
   187                              <1>  %if %0 >= 3
   187 0000007A B9FF000000          <1>  mov ecx, %3
   187                              <1>  %if %0 = 4
   187 0000007F BA0F000000          <1>  mov edx, %4
   187                              <1>  %endif
   187                              <1>  %endif
   187                              <1>  %endif
   187 00000084 B823000000          <1>  mov eax, %1
   187                              <1> 
   187 00000089 CD40                <1>  int 40h
   188                                  _1:
   189                                  	; 19/06/2017
   190                                  	; Allocate Audio Buffer (for user)
   191                                  	sys	_audio, 0200h, BUFFERSIZE, Audio_Buffer
   191                              <1> 
   191                              <1> 
   191                              <1> 
   191                              <1> 
   191                              <1>  %if %0 >= 2
   191 0000008B BB00020000          <1>  mov ebx, %2
   191                              <1>  %if %0 >= 3
   191 00000090 B900800000          <1>  mov ecx, %3
   191                              <1>  %if %0 = 4
   191 00000095 BA[00E00000]        <1>  mov edx, %4
   191                              <1>  %endif
   191                              <1>  %endif
   191                              <1>  %endif
   191 0000009A B820000000          <1>  mov eax, %1
   191                              <1> 
   191 0000009F CD40                <1>  int 40h
   192 000000A1 0F8226010000            	jc	error_exit
   193                                  _2:
   194                                  	;; Initialize Audio Device (bl = 1 -> Interrupt method)
   195                                  	;sys	_audio, 0301h, 0, sb16_int_handler 
   196                                  	;jc	error_exit
   197                                  	
   198                                  	; 20/10/2017
   199                                  	; Initialize Audio Device (bl = 0 -> SRB method)
   200                                  	sys	_audio, 0300h, 1, srb 
   200                              <1> 
   200                              <1> 
   200                              <1> 
   200                              <1> 
   200                              <1>  %if %0 >= 2
   200 000000A7 BB00030000          <1>  mov ebx, %2
   200                              <1>  %if %0 >= 3
   200 000000AC B901000000          <1>  mov ecx, %3
   200                              <1>  %if %0 = 4
   200 000000B1 BA[9D500000]        <1>  mov edx, %4
   200                              <1>  %endif
   200                              <1>  %endif
   200                              <1>  %endif
   200 000000B6 B820000000          <1>  mov eax, %1
   200                              <1> 
   200 000000BB CD40                <1>  int 40h
   201 000000BD 0F820A010000            	jc	error_exit
   202                                  
   203                                  LoadMod:  
   204 000000C3 BF[D0DD0000]            	mov	edi, mod_file_name
   205 000000C8 E83D020000              	call    LoadModule		; Load the MODule...
   206                                  	; 08/10/2017
   207 000000CD 731B                    	jnc	short _3		; any error loading?
   208                                  
   209                                  	; yes, print error and Exit.
   210                                  
   211                                  	sys	_msg, ErrorMesg, 255, 0Fh
   211                              <1> 
   211                              <1> 
   211                              <1> 
   211                              <1> 
   211                              <1>  %if %0 >= 2
   211 000000CF BB[C94F0000]        <1>  mov ebx, %2
   211                              <1>  %if %0 >= 3
   211 000000D4 B9FF000000          <1>  mov ecx, %3
   211                              <1>  %if %0 = 4
   211 000000D9 BA0F000000          <1>  mov edx, %4
   211                              <1>  %endif
   211                              <1>  %endif
   211                              <1>  %endif
   211 000000DE B823000000          <1>  mov eax, %1
   211                              <1> 
   211 000000E3 CD40                <1>  int 40h
   212 000000E5 E93A010000              	jmp     Exit
   213                                  _3:
   214                                  	; 24/06/2017
   215                                  	sys	_audio, 0E00h ; get audio controller info
   215                              <1> 
   215                              <1> 
   215                              <1> 
   215                              <1> 
   215                              <1>  %if %0 >= 2
   215 000000EA BB000E0000          <1>  mov ebx, %2
   215                              <1>  %if %0 >= 3
   215                              <1>  mov ecx, %3
   215                              <1>  %if %0 = 4
   215                              <1>  mov edx, %4
   215                              <1>  %endif
   215                              <1>  %endif
   215                              <1>  %endif
   215 000000EF B820000000          <1>  mov eax, %1
   215                              <1> 
   215 000000F4 CD40                <1>  int 40h
   216 000000F6 0F82D1000000            	jc	error_exit
   217                                  
   218                                  	; EAX = IRQ Number in AL
   219                                  	;	Audio Device Number in AH 
   220                                  	; EBX = DEV/VENDOR ID
   221                                  	;       (DDDDDDDDDDDDDDDDVVVVVVVVVVVVVVVV)
   222                                  	; ECX = BUS/DEV/FN 
   223                                  	;       (00000000BBBBBBBBDDDDDFFF00000000)
   224                                  	; EDX = Base IO Addr (DX) for SB16 & VT8233
   225                                  	; EDX = NABMBAR/NAMBAR (for AC97)
   226                                  	;      (Low word, DX = NAMBAR address)
   227                                  
   228 000000FC 668915[61500000]        	mov	[SbAddr], dx
   229 00000103 A2[63500000]            	mov	[SbIrq], al
   230                                  
   231                                  	; Print Sucessful message.
   232                                  	;mov	dx, [SbAddr]
   233                                  	;mov	al, [SbIrq]
   234 00000108 C0EA04                  	shr     dl, 4
   235 0000010B 80C230                  	add     dl, '0'
   236 0000010E 8815[2E500000]          	mov     [PortText], dl
   237 00000114 0430                    	add     al, '0'
   238 00000116 A2[37500000]            	mov     [IrqText], al
   239                                  
   240                                  	sys	_msg, MsgFound, 255, 0Fh
   240                              <1> 
   240                              <1> 
   240                              <1> 
   240                              <1> 
   240                              <1>  %if %0 >= 2
   240 0000011B BB[0E500000]        <1>  mov ebx, %2
   240                              <1>  %if %0 >= 3
   240 00000120 B9FF000000          <1>  mov ecx, %3
   240                              <1>  %if %0 = 4
   240 00000125 BA0F000000          <1>  mov edx, %4
   240                              <1>  %endif
   240                              <1>  %endif
   240                              <1>  %endif
   240 0000012A B823000000          <1>  mov eax, %1
   240                              <1> 
   240 0000012F CD40                <1>  int 40h
   241                                  
   242                                  PlayNow: 
   243 00000131 E8AD090000              	call    StartPlaying
   244                                  
   245                                          ; load 32768 bytes into audio buffer
   246 00000136 BF[00E00000]            	mov	edi, Audio_Buffer
   247                                  	; 19/10/2017
   248                                  	;mov	ebx, BUFFERSIZE
   249 0000013B BB00200000              	mov	ebx, BUFFERSIZE/4  ; 16 bits, stereo sound buffer
   250 00000140 E84C080000              	call	GetSamples
   251 00000145 0F8282000000            	jc	error_exit
   252                                  
   253                                  ;	;mov	ecx, 128	; Make a lookup table
   254                                  ;	mov	cl, 128
   255                                  ;	xor     ebx, ebx	; for fastest pixel
   256                                  ;	mov     edx, 320*(100-64)	; addressing.
   257                                  ;MakeOfs:        
   258                                  ;	mov     [RowOfs+ebx], dx
   259                                  ;	mov     [RowOfs+ebx+2], dx
   260                                  ;	add     dx, 320
   261                                  ;	add     ebx, 4
   262                                  ;	loop    MakeOfs
   263                                  
   264                                  ;	; 23/10/2017
   265                                  ;	mov	ebx, 64
   266                                  ;	mov	edi, RowOfs
   267                                  ;	xor	eax, eax 
   268                                  ;MakeOfs:
   269                                  ;	mov	cl, 4
   270                                  ;	rep	stosw
   271                                  ;	add	ax, 80 ; 640 pixels (80*8 bits)
   272                                  ;	dec	ebx
   273                                  ;	jnz	short MakeOfs
   274                                  
   275                                  	; 27/10/2017
   276 0000014B 66B90001                	mov	cx, 256
   277 0000014F 31DB                    	xor	ebx, ebx
   278 00000151 BF[D0D30000]            	mov	edi, RowOfs
   279                                  MakeOfs:
   280 00000156 66B88000                	mov	ax, 128
   281 0000015A 66F7E3                  	mul	bx
   282 0000015D 88E0                    	mov	al, ah
   283 0000015F B450                    	mov	ah, 80
   284 00000161 F6E4                    	mul	ah
   285 00000163 66AB                    	stosw
   286 00000165 43                      	inc	ebx
   287 00000166 E2EE                    	loop	MakeOfs
   288                                  	
   289                                  	; 23/06/2017
   290                                  	; Map DMA buffer to user's memory space
   291                                  	sys	_audio, 0D00h, 65536, DMA_Buffer
   291                              <1> 
   291                              <1> 
   291                              <1> 
   291                              <1> 
   291                              <1>  %if %0 >= 2
   291 00000168 BB000D0000          <1>  mov ebx, %2
   291                              <1>  %if %0 >= 3
   291 0000016D B900000100          <1>  mov ecx, %3
   291                              <1>  %if %0 = 4
   291 00000172 BA[00000200]        <1>  mov edx, %4
   291                              <1>  %endif
   291                              <1>  %endif
   291                              <1>  %endif
   291 00000177 B820000000          <1>  mov eax, %1
   291                              <1> 
   291 0000017C CD40                <1>  int 40h
   292                                  	;jc	error_exit
   293                                  
   294                                  	; 24/06/2017
   295                                  	; Set Master Volume Level (BL=0 or 80h)
   296                                  	; 	 	for next playing (BL>=80h)
   297                                  	sys	_audio, 0B80h, 1D1Dh
   297                              <1> 
   297                              <1> 
   297                              <1> 
   297                              <1> 
   297                              <1>  %if %0 >= 2
   297 0000017E BB800B0000          <1>  mov ebx, %2
   297                              <1>  %if %0 >= 3
   297 00000183 B91D1D0000          <1>  mov ecx, %3
   297                              <1>  %if %0 = 4
   297                              <1>  mov edx, %4
   297                              <1>  %endif
   297                              <1>  %endif
   297                              <1>  %endif
   297 00000188 B820000000          <1>  mov eax, %1
   297                              <1> 
   297 0000018D CD40                <1>  int 40h
   298                                  
   299                                  	; 20/10/2017
   300 0000018F C605[21DE0000]1D        	mov	byte [volume_level], 1Dh
   301                                  
   302                                  	;mov	word [MixSpeed], 22050	; Mixing at 22.050 kHz
   303                                  	
   304                                  	; Start	to play
   305 00000196 A0[65500000]            	mov	al, [bps]
   306 0000019B C0E804                  	shr	al, 4 ; 8 -> 0, 16 -> 1
   307 0000019E D0E0                    	shl	al, 1 ; 16 -> 2, 8 -> 0
   308 000001A0 8A1D[64500000]          	mov	bl, [stmo]
   309 000001A6 FECB                    	dec	bl
   310 000001A8 08C3                    	or	bl, al
   311 000001AA 668B0D[66500000]        	mov	cx, [MixSpeed] ; [Sample_Rate] ; Hz 
   312 000001B1 B704                    	mov	bh, 4 ; start to play	
   313                                  	sys	_audio
   313                              <1> 
   313                              <1> 
   313                              <1> 
   313                              <1> 
   313                              <1>  %if %0 >= 2
   313                              <1>  mov ebx, %2
   313                              <1>  %if %0 >= 3
   313                              <1>  mov ecx, %3
   313                              <1>  %if %0 = 4
   313                              <1>  mov edx, %4
   313                              <1>  %endif
   313                              <1>  %endif
   313                              <1>  %endif
   313 000001B3 B820000000          <1>  mov eax, %1
   313                              <1> 
   313 000001B8 CD40                <1>  int 40h
   314                                      
   315                                  	;; SETUP SIGNAL RESPONSE BYTE
   316                                  	;; 06/03/2017
   317                                  	;mov	bl, [ac97_int_ln_reg] ; IRQ number
   318                                  	;mov	bh, 1 ; Link IRQ to user for Signal Response Byte
   319                                  	;mov	edx, srb  ; Signal Response/Return Byte address  
   320                                  	;mov	ecx, 0FFh ; Signal Response/Return Byte value  
   321                                  	;sys	_calbac
   322                                  	;jc	short error_exit
   323                                  
   324                                  	; DIRECT VGA MEMORY ACCESS
   325                                  	; bl = 0, bh = 5
   326                                  	; Direct access/map to VGA memory (0A0000h)
   327                                  
   328                                  	sys	_video, 0500h
   328                              <1> 
   328                              <1> 
   328                              <1> 
   328                              <1> 
   328                              <1>  %if %0 >= 2
   328 000001BA BB00050000          <1>  mov ebx, %2
   328                              <1>  %if %0 >= 3
   328                              <1>  mov ecx, %3
   328                              <1>  %if %0 = 4
   328                              <1>  mov edx, %4
   328                              <1>  %endif
   328                              <1>  %endif
   328                              <1>  %endif
   328 000001BF B81F000000          <1>  mov eax, %1
   328                              <1> 
   328 000001C4 CD40                <1>  int 40h
   329 000001C6 3D00000A00              	cmp	eax, 0A0000h
   330 000001CB 7418                    	je	short _a3
   331                                  error_exit:
   332                                  	sys	_msg, trdos386_err_msg, 255, 0Eh
   332                              <1> 
   332                              <1> 
   332                              <1> 
   332                              <1> 
   332                              <1>  %if %0 >= 2
   332 000001CD BB[3C500000]        <1>  mov ebx, %2
   332                              <1>  %if %0 >= 3
   332 000001D2 B9FF000000          <1>  mov ecx, %3
   332                              <1>  %if %0 = 4
   332 000001D7 BA0E000000          <1>  mov edx, %4
   332                              <1>  %endif
   332                              <1>  %endif
   332                              <1>  %endif
   332 000001DC B823000000          <1>  mov eax, %1
   332                              <1> 
   332 000001E1 CD40                <1>  int 40h
   333 000001E3 EB3F                    	jmp	short Exit
   334                                  
   335                                  ; Note: Normally IRQ 0 calls the ModPlay Polling at 18.2Hz thru
   336                                  ;       the software interrupt 1Ch. If the IRQ 0 is disabled, then
   337                                  ;       the INT 1Ch MUST BE CALLED at least MixSpeed/1024 times per
   338                                  ;       second, or the module will sound "looped".
   339                                  ;       Because we need better sync with the ModPlayer to draw the scope,
   340                                  ;       the polling is called from my routine, and then the irq 0 must be
   341                                  ;       disabled. The [DmaBuffer] points to the current buffer of 8-bit
   342                                  ;       samples played by the Sound Blaster. Note that some samples are
   343                                  ;       discarded in the next code, just for fun!
   344                                  
   345                                  _a3:
   346                                  	;mov     ax, 0013h	; Set Mode 320x200x256
   347                                  	;int     31h
   348                                  
   349                                  	; 21/10/2017
   350                                  	;mov	ax, 0012h	; Set Mode 640x480x16
   351                                  	;int	31h
   352                                  
   353                                  	; 22/10/2017
   354 000001E5 E8DA090000              	call	setgraphmode	; Set video mode to 640*480x16
   355                                  
   356                                  	; 22/10/2017
   357                                  	;call	loadlbm
   358                                  	;jc	short loadlbm_err
   359                                  
   360 000001EA BE[F40D0000]            	mov	esi, LOGO_ADDRESS
   361 000001EF E8C60A0000              	call	putlbm
   362                                  	;jnc	short loadlbm_ok
   363 000001F4 731F                    	jnc	short _a4 ; 
   364                                  
   365                                  	;mov	byte [error_color], 0Eh ; Yellow
   366                                  
   367                                  loadlbm_err:
   368                                  	; 21/10/2017
   369                                  	;mov	ax, 0003h	; Set Text Mode 80x25x16
   370                                  	;int	31h
   371                                  	; 22/10/2017
   372 000001F6 E8E6090000              	call	settextmode
   373                                  
   374                                  	sys	_msg, LOGO_ERROR_MSG, 255, [error_color]
   374                              <1> 
   374                              <1> 
   374                              <1> 
   374                              <1> 
   374                              <1>  %if %0 >= 2
   374 000001FB BB[C80D0000]        <1>  mov ebx, %2
   374                              <1>  %if %0 >= 3
   374 00000200 B9FF000000          <1>  mov ecx, %3
   374                              <1>  %if %0 = 4
   374 00000205 8B15[14020000]      <1>  mov edx, %4
   374                              <1>  %endif
   374                              <1>  %endif
   374                              <1>  %endif
   374 0000020B B823000000          <1>  mov eax, %1
   374                              <1> 
   374 00000210 CD40                <1>  int 40h
   375 00000212 EB10                    	jmp	short Exit
   376                                  
   377                                  	; 21/10/2017
   378                                  error_color:
   379 00000214 0C                      	db	0Ch  ; Light Red
   380                                  	
   381                                  loadlbm_ok: 
   382                                  	; 21/10/2017
   383                                  _a4:
   384                                  	; 24/06/2017
   385 00000215 E838000000              	call	PlayMod ; 13/02/2017 (ModPlay)
   386                                  
   387                                  _s_exit:
   388 0000021A E874090000              	call	StopPlaying	; STOP!
   389                                  	
   390                                  	; 22/10/2017
   391                                  	;mov	ax, 0003h	; Set Text Mode 80x25x16
   392                                  	;int	31h
   393 0000021F E8BD090000              	call	settextmode
   394                                  Exit:           
   395                                  	;call	FreeModule	; Free MODule core.
   396                                  	
   397                                  	sys 	_exit	; Bye !
   397                              <1> 
   397                              <1> 
   397                              <1> 
   397                              <1> 
   397                              <1>  %if %0 >= 2
   397                              <1>  mov ebx, %2
   397                              <1>  %if %0 >= 3
   397                              <1>  mov ecx, %3
   397                              <1>  %if %0 = 4
   397                              <1>  mov edx, %4
   397                              <1>  %endif
   397                              <1>  %endif
   397                              <1>  %endif
   397 00000224 B801000000          <1>  mov eax, %1
   397                              <1> 
   397 00000229 CD40                <1>  int 40h
   398                                  here:
   399 0000022B EBFE                    	jmp	short here
   400                                  
   401                                  pmsg_usage:
   402                                  	sys	_msg, msg_usage, 255, 0Fh
   402                              <1> 
   402                              <1> 
   402                              <1> 
   402                              <1> 
   402                              <1>  %if %0 >= 2
   402 0000022D BB[2C4F0000]        <1>  mov ebx, %2
   402                              <1>  %if %0 >= 3
   402 00000232 B9FF000000          <1>  mov ecx, %3
   402                              <1>  %if %0 = 4
   402 00000237 BA0F000000          <1>  mov edx, %4
   402                              <1>  %endif
   402                              <1>  %endif
   402                              <1>  %endif
   402 0000023C B823000000          <1>  mov eax, %1
   402                              <1> 
   402 00000241 CD40                <1>  int 40h
   403 00000243 EBDF                    	jmp	short Exit
   404                                  
   405                                  DetectSB16:
   406                                  	; 24/06/2017
   407                                  	; Detect (BH=1) SB16 (BL=1) Sound Card
   408                                          sys	_audio, 0101h
   408                              <1> 
   408                              <1> 
   408                              <1> 
   408                              <1> 
   408                              <1>  %if %0 >= 2
   408 00000245 BB01010000          <1>  mov ebx, %2
   408                              <1>  %if %0 >= 3
   408                              <1>  mov ecx, %3
   408                              <1>  %if %0 = 4
   408                              <1>  mov edx, %4
   408                              <1>  %endif
   408                              <1>  %endif
   408                              <1>  %endif
   408 0000024A B820000000          <1>  mov eax, %1
   408                              <1> 
   408 0000024F CD40                <1>  int 40h
   409 00000251 C3                      	retn
   410                                  
   411                                  ;sb16_int_handler:
   412                                  ;	; 24/06/2017
   413                                  ;	mov	byte [srb], 1 ; interrupt (or signal response byte)
   414                                  ;
   415                                  ;	sys	_rele ; return from callback service 
   416                                  ;	; we must not come here !
   417                                  ;	sys	_exit
   418                                  
   419                                  ;=============================================================================
   420                                  ;      
   421                                  ;=============================================================================
   422                                  
   423                                  PlayMod:
   424                                  	; 19/10/2017
   425                                  	; 23/06/2017   
   426                                  	; 21/06/2017
   427                                  	; 19/06/2017
   428                                  
   429                                  	; 05/03/2017 (TRDOS 386)
   430                                  	; 14/02/2017
   431                                  	; 13/02/2017
   432                                  	; 08/12/2016
   433                                  	; 28/11/2016
   434                                  
   435 00000252 EB10                         	jmp	short modp_gs ; 23/06/2017
   436                                  p_loop:
   437 00000254 803D[9D500000]00        	cmp	byte [srb], 0
   438 0000025B 761C                    	jna	short q_loop
   439 0000025D C605[9D500000]00        	mov	byte [srb], 0
   440                                  modp_gs:
   441 00000264 BF[00E00000]            	mov	edi, Audio_Buffer
   442                                  	; 19/10/2017
   443                                  	;mov	ebx, BUFFERSIZE ; 32768 bytes ; 14/03/2017
   444 00000269 BB00200000              	mov	ebx, BUFFERSIZE/4  ; 16 bits, stereo sound buffer
   445 0000026E E81E070000              	call	GetSamples
   446 00000273 0F8254FFFFFF            	jc	error_exit
   447                                  q_loop:
   448 00000279 B401                    	mov     ah, 1		; any key pressed?
   449 0000027B CD32                    	int     32h		; no, Loop.
   450 0000027D 745C                    	jz	short r_loop
   451                                  
   452 0000027F B400                    	mov     ah, 0		; flush key buffer...
   453 00000281 CD32                    	int     32h
   454                                  
   455                                  	; 19/10/2017 (modplay6.s)
   456 00000283 3C20                    	cmp	al, 20h
   457 00000285 740E                    	je	short change_pan
   458                                  	; 09/10/2017 (playmod5.s)
   459 00000287 3C2B                    	cmp	al, '+' ; increase sound volume
   460 00000289 741D                    	je	short inc_volume_level
   461 0000028B 3C2D                    	cmp	al, '-'
   462 0000028D 743C                    	je	short dec_volume_level
   463                                  
   464                                  	; 19/10/2017 (modplay6.s)
   465 0000028F 24DF                    	and	al, 0DFh
   466 00000291 3C50                    	cmp	al, 'P'
   467 00000293 7545                    	jne	short q_return
   468                                  
   469                                  change_pan:
   470                                  	; 19/10/2017 (modplay6.s)
   471 00000295 8A0D[20DE0000]          	mov	cl, [pan_shift]
   472 0000029B FEC1                    	inc	cl
   473 0000029D 80E103                  	and	cl, 3
   474 000002A0 880D[20DE0000]          	mov	[pan_shift], cl
   475 000002A6 EB33                    	jmp	short r_loop
   476                                  
   477                                  	; 09/10/2017 (playmod5.s)
   478                                  	; 24/06/2017 (wavplay2.s)
   479                                  inc_volume_level:
   480 000002A8 8A0D[21DE0000]          	mov	cl, [volume_level]
   481 000002AE 80F91F                  	cmp	cl, 1Fh ; 31
   482 000002B1 7328                    	jnb	short r_loop
   483 000002B3 FEC1                    	inc	cl
   484                                  change_volume_level:
   485 000002B5 880D[21DE0000]          	mov	[volume_level], cl
   486 000002BB 88CD                    	mov	ch, cl
   487                                  	; Set Master Volume Level
   488                                  	sys	_audio, 0B00h
   488                              <1> 
   488                              <1> 
   488                              <1> 
   488                              <1> 
   488                              <1>  %if %0 >= 2
   488 000002BD BB000B0000          <1>  mov ebx, %2
   488                              <1>  %if %0 >= 3
   488                              <1>  mov ecx, %3
   488                              <1>  %if %0 = 4
   488                              <1>  mov edx, %4
   488                              <1>  %endif
   488                              <1>  %endif
   488                              <1>  %endif
   488 000002C2 B820000000          <1>  mov eax, %1
   488                              <1> 
   488 000002C7 CD40                <1>  int 40h
   489 000002C9 EB10                    	jmp	short r_loop
   490                                  dec_volume_level:
   491 000002CB 8A0D[21DE0000]          	mov	cl, [volume_level]
   492 000002D1 80F901                  	cmp	cl, 1 ; 1
   493 000002D4 7605                    	jna	short r_loop
   494 000002D6 FEC9                    	dec	cl
   495 000002D8 EBDB                    	jmp	short change_volume_level
   496                                  
   497                                  q_return:
   498 000002DA C3                      	retn
   499                                  r_loop:
   500                                  	; 28/10/2017
   501                                  	; Get Current DMA buffer Pointer 
   502                                  	; 23/06/2017
   503                                  	; bh = 15, get current pointer (DMA buffer offset)
   504                                  	; bl = 0, for PCM OUT
   505                                  	; ecx = 0
   506                                  	;
   507                                  	sys	_audio, 0F00h, 0
   507                              <1> 
   507                              <1> 
   507                              <1> 
   507                              <1> 
   507                              <1>  %if %0 >= 2
   507 000002DB BB000F0000          <1>  mov ebx, %2
   507                              <1>  %if %0 >= 3
   507 000002E0 B900000000          <1>  mov ecx, %3
   507                              <1>  %if %0 = 4
   507                              <1>  mov edx, %4
   507                              <1>  %endif
   507                              <1>  %endif
   507                              <1>  %endif
   507 000002E5 B820000000          <1>  mov eax, %1
   507                              <1> 
   507 000002EA CD40                <1>  int 40h
   508                                  	
   509                                  	; Get Current Sound Data (in DMA buffer) ((320 bytes)) 
   510                                  	; 25/06/2017
   511                                  	; 22/06/2017
   512                                  	; bh = 15, get current sound data/samples
   513                                  	; bl = 0, for PCM OUT
   514                                  	; ecx = count of sample/data bytes (1 to 4096)
   515                                  	; edx = destination buffer address 
   516                                  	;	(page aligned address is better)
   517                                  	;
   518                                  	;sys	_audio, 0F00h, 256*4, g_buff ; 23/10/2017 (256*4)
   519                                  
   520                                  	; 28/10/2017
   521 000002EC 24FC                    	and	al, 0FCh  ; dword alignment (stereo, 16 bit)	
   522                                  	; 23/06/2017
   523 000002EE BE[00000200]            	mov     esi, DMA_Buffer
   524 000002F3 01C6                    	add     esi, eax	; add offset value
   525                                  	; 24/06/2017
   526 000002F5 B9[00FC0200]            	mov	ecx, DMA_Buffer + (65536 - (256*4))
   527 000002FA 39CE                    	cmp	esi, ecx 
   528 000002FC 7602                    	jna	short _4
   529 000002FE 89CE                    	mov	esi, ecx
   530                                  _4:
   531                                  	; 23/10/2017
   532 00000300 E8E3080000              	call	drawscopes
   533                                  
   534 00000305 E94AFFFFFF              	jmp	p_loop
   535                                  
   536                                  ;=============================================================================
   537                                  ;               MODLOAD.ASM
   538                                  ;=============================================================================
   539                                  
   540                                  ; Amiga Module Loader v0.1b by Carlos Hasan.
   541                                  ;	July 10th, 1993.
   542                                  
   543                                  ; STRUCTURES
   544                                  
   545                                  struc ModSample
   546 00000000 <res 00000016>          .msName:	resb 22
   547 00000016 <res 00000002>          .msLength:	resw 1
   548 00000018 <res 00000001>          .msFinetune:	resb 1
   549 00000019 <res 00000001>          .msVolume:	resb 1
   550 0000001A <res 00000002>          .msRepeat:	resw 1
   551 0000001C <res 00000002>          .msRepLen:	resw 1
   552                                  .size:		; 30 bytes
   553                                  endstruc
   554                                  
   555                                  struc ModHeader
   556 00000000 <res 00000014>          .mhName:	resb 20
   557 00000014 <res 000003A2>          .mhSamples:	resb ModSample.size*31
   558 000003B6 <res 00000001>          .mhOrderLen:	resb 1
   559 000003B7 <res 00000001>          .mhReStart:	resb 1
   560 000003B8 <res 00000080>          .mhOrder:	resb 128
   561 00000438 <res 00000004>          .mhSign:	resw 2
   562                                  .size:		; 1084 bytes
   563                                  endstruc
   564                                  
   565                                  struc ModInfoRec
   566 00000000 <res 00000001>          .OrderLen:	resb 1
   567 00000001 <res 00000001>          .ReStart:	resb 1
   568 00000002 <res 00000080>          .Order:		resb 128
   569 00000082 <res 00000004>          .Patterns:	resd 1
   570 00000086 <res 0000003E>          .SampOfs:	resw 31
   571 000000C4 <res 0000003E>          .SampSeg:	resw 31
   572 00000102 <res 0000003E>          .SampLen:	resw 31
   573 00000140 <res 0000003E>          .SampRep:	resw 31
   574 0000017E <res 0000003E>          .SampRepLen:	resw 31
   575 000001BC <res 0000003E>          .SampVol:	resw 31
   576                                  .size:		; 506 bytes	
   577                                  endstruc
   578                                  
   579                                  ; CODE
   580                                  
   581                                  ; modplay5.s
   582                                  ; 07/10/2017
   583                                  ; tinyply3.s
   584                                  ; 06/10/2017
   585                                  ; 04/10/2017
   586                                  ; /* MOD FileFormat */
   587                                  
   588                                  ID_MK	equ 2E4B2E4Dh ; "M.K."
   589                                  ID_FLT4 equ 34544C46h ; "FLT4"
   590                                  ID_8CHN equ 4E484338h ; "8CHN"
   591                                  ID_FLT8 equ 34544C46h ; "FLT8"
   592                                  
   593                                  ; CODE
   594                                  
   595                                  LoadModule:
   596                                  	; edi = file name address
   597                                  
   598 0000030A 60                      	pushad
   599                                  
   600 0000030B E878010000              	call    ClearModInfo
   601                                  OpenFile:       
   602                                  	; ebx = ASCIIZ file name address
   603                                  	; ecx = open mode (0 = open for read)	
   604                                  	sys	_open, edi, 0 ; open for reading
   604                              <1> 
   604                              <1> 
   604                              <1> 
   604                              <1> 
   604                              <1>  %if %0 >= 2
   604 00000310 89FB                <1>  mov ebx, %2
   604                              <1>  %if %0 >= 3
   604 00000312 B900000000          <1>  mov ecx, %3
   604                              <1>  %if %0 = 4
   604                              <1>  mov edx, %4
   604                              <1>  %endif
   604                              <1>  %endif
   604                              <1>  %endif
   604 00000317 B805000000          <1>  mov eax, %1
   604                              <1> 
   604 0000031C CD40                <1>  int 40h
   605 0000031E 0F8262010000            	jc	Failed
   606 00000324 A3[9E500000]            	mov     [FileHandle], eax
   607                                  ReadHeader:
   608                                  	; ebx = File handle
   609                                  	; ecx = Buffer address
   610                                  	; edx = Byte count
   611                                  	sys	_read, [FileHandle], Header, ModHeader.size
   611                              <1> 
   611                              <1> 
   611                              <1> 
   611                              <1> 
   611                              <1>  %if %0 >= 2
   611 00000329 8B1D[9E500000]      <1>  mov ebx, %2
   611                              <1>  %if %0 >= 3
   611 0000032F B9[A2500000]        <1>  mov ecx, %3
   611                              <1>  %if %0 = 4
   611 00000334 BA3C040000          <1>  mov edx, %4
   611                              <1>  %endif
   611                              <1>  %endif
   611                              <1>  %endif
   611 00000339 B803000000          <1>  mov eax, %1
   611                              <1> 
   611 0000033E CD40                <1>  int 40h
   612 00000340 0F8231010000            	jc      CloseFile
   613                                  CheckMK:  
   614                                  	; 04/10/2017
   615 00000346 A1[DA540000]            	mov	eax, [Header+ModHeader.mhSign]
   616                                        
   617 0000034B 3D4D2E4B2E              	cmp	eax, ID_MK   ; cmp eax, '.K.M'
   618                                  	;je	short Is4chnMod
   619 00000350 742B                    	je	short IsModFile
   620                                  CheckFLT4:
   621 00000352 3D464C5434              	cmp	eax, ID_FLT4 ; cmp eax, '4TLF'
   622                                  	;je	short Is4chnMod
   623 00000357 7424                    	je	short IsModFile
   624                                  Check8CHN:
   625 00000359 3D3843484E              	cmp	eax, ID_8CHN ; cmp eax,	'NHC8'
   626 0000035E 740D                    	je	short Is8chnMod
   627                                  CheckFLT8:
   628 00000360 3D464C5434              	cmp	eax, ID_FLT8 ; cmp eax, '8TLF'
   629                                  	; 06/10/2017
   630 00000365 7406                    	je	short Is8chnMod
   631 00000367 F9                      	stc
   632 00000368 E90A010000              	jmp	CloseFile
   633                                  Is8chnMod:
   634 0000036D C605[5D500000]08        	mov	byte [numtracks], 8	; 8-CHANNEL-MOD
   635 00000374 C605[5C500000]0B        	mov	byte [pattern_shift], 11 ; Pattern Size = 2048 bytes
   636 0000037B EB00                    	jmp	short IsModFile
   637                                  ;Is4chnMod:
   638                                  ;	mov	byte [numtracks], 4	; 4-CHANNEL-MOD
   639                                  ;	mov	byte [pattern_shift], 11 ; Pattern Size = 1024 bytes
   640                                  
   641                                  IsModFile:
   642 0000037D A0[58540000]            	mov     al, [Header+ModHeader.mhOrderLen]
   643 00000382 A2[DE540000]            	mov     [ModInfo.OrderLen], al
   644                                  
   645 00000387 A0[59540000]            	mov     al, [Header+ModHeader.mhReStart]
   646 0000038C 3A05[58540000]          	cmp     al, [Header+ModHeader.mhOrderLen]
   647 00000392 7202                    	jb      short SetReStart
   648 00000394 B07F                    	mov     al, 7Fh
   649                                  SetReStart:
   650 00000396 A2[DF540000]            	mov     [ModInfo.ReStart], al
   651                                  
   652                                  	;mov	ecx, 128
   653 0000039B 66B98000                	mov	cx, 128
   654 0000039F 31D2                    	xor     edx, edx
   655 000003A1 31DB                    	xor     ebx, ebx
   656                                  CopyOrder:
   657 000003A3 8AB3[5A540000]          	mov     dh, [Header+ModHeader.mhOrder+ebx]
   658 000003A9 88B3[E0540000]          	mov     [ModInfo.Order+ebx], dh
   659 000003AF 38D6                    	cmp     dh, dl
   660 000003B1 7202                    	jb      short NextOrder
   661 000003B3 88F2                    	mov     dl, dh ; Max. pattern number ; 04/10/2017
   662                                  NextOrder:
   663 000003B5 43                      	inc     ebx
   664 000003B6 E2EB                    	loop    CopyOrder
   665                                  AllocPatterns:  
   666 000003B8 81E2FF000000            	and	edx, 0FFh
   667                                  	; 04/10/2017
   668                                  	;inx	dx  ; 12/03/2017
   669 000003BE FEC2                    	inc	dl
   670                                  	; dl = number of patterns (04/07/2017)
   671 000003C0 8A0D[5C500000]          	mov	cl, [pattern_shift] ; 10 for 4 channels, 11 for 8 channels
   672 000003C6 D3E2                    	shl	edx, cl ; 10 ; *1024 ; (byte count of patterns *64*4*4)
   673                                  		     	     ; *2048 ; (byte count of patterns *64*8*4)
   674                                  	;
   675 000003C8 89D5                    	mov	ebp, edx ; offset of samples (04/07/2017)
   676                                  	;mov	ecx, 10000h ; next 64K (4096*16)
   677 000003CA B9[00000300]            	mov	ecx, file_buffer ; 12/03/2017
   678                                  	;
   679 000003CF 890D[60550000]          	mov	[ModInfo.Patterns], ecx
   680                                  	;
   681 000003D5 01CD                    	add	ebp, ecx ; next offset for samples
   682                                  ReadPatterns:  
   683                                  	;mov	ebx, [FileHandle] 
   684                                  	; ebx = File handle
   685                                  	; ecx = Buffer address
   686                                  	; edx = Byte count
   687                                  	sys	_read, [FileHandle]
   687                              <1> 
   687                              <1> 
   687                              <1> 
   687                              <1> 
   687                              <1>  %if %0 >= 2
   687 000003D7 8B1D[9E500000]      <1>  mov ebx, %2
   687                              <1>  %if %0 >= 3
   687                              <1>  mov ecx, %3
   687                              <1>  %if %0 = 4
   687                              <1>  mov edx, %4
   687                              <1>  %endif
   687                              <1>  %endif
   687                              <1>  %endif
   687 000003DD B803000000          <1>  mov eax, %1
   687                              <1> 
   687 000003E2 CD40                <1>  int 40h
   688 000003E4 0F828D000000            	jc      CloseFile
   689                                  
   690                                  	; patterns have been loaded here... (04/07/2017)
   691                                  
   692 000003EA BE[B6500000]            	mov	esi, Header+ModHeader.mhSamples
   693 000003EF 31FF                    	xor     edi, edi
   694                                  CopySamples:
   695 000003F1 668B4616                	mov     ax, [esi+ModSample.msLength]
   696 000003F5 86C4                    	xchg    al, ah
   697 000003F7 66D1E0                  	shl     ax, 1
   698 000003FA 668987[E0550000]        	mov     [ModInfo.SampLen+edi], ax
   699 00000401 8A4619                  	mov     al, [esi+ModSample.msVolume]
   700 00000404 30E4                    	xor     ah, ah
   701 00000406 668987[9A560000]        	mov     [ModInfo.SampVol+edi], ax
   702 0000040D 668B461A                	mov     ax, [esi+ModSample.msRepeat]
   703 00000411 86C4                    	xchg    al, ah
   704 00000413 66D1E0                  	shl     ax, 1
   705 00000416 668987[1E560000]        	mov     [ModInfo.SampRep+edi], ax
   706 0000041D 668B461C                	mov     ax, [esi+ModSample.msRepLen]
   707 00000421 86C4                    	xchg    al, ah
   708 00000423 66D1E0                  	shl     ax, 1
   709 00000426 668987[5C560000]        	mov     [ModInfo.SampRepLen+edi], ax
   710 0000042D 83C61E                  	add     esi, ModSample.size
   711 00000430 6683C702                	add     di, 2
   712 00000434 6683FF3E                	cmp     di, 2*31
   713 00000438 72B7                    	jb      short CopySamples
   714                                  
   715 0000043A 31F6                    	xor     esi, esi
   716                                  AllocSamples:
   717 0000043C 0FB796[E0550000]        	movzx	edx, word [ModInfo.SampLen+esi]
   718                                  	; 07/10/2017
   719                                  	;shr	dx, 4 ; ***
   720 00000443 21D2                    	and	edx, edx
   721 00000445 7426                    	jz      short NextSample
   722                                  	;inc	dx  ; number of paragraphs ; ***
   723                                  	;shl	dx, 4 ; ***
   724 00000447 89E8                    	mov	eax, ebp
   725 00000449 668986[64550000]        	mov	[ModInfo.SampOfs+esi], ax
   726 00000450 C1E810                  	shr	eax, 16
   727 00000453 668986[A2550000]        	mov	[ModInfo.SampSeg+esi], ax
   728 0000045A 89E9                    	mov	ecx, ebp
   729 0000045C 01D5                    	add	ebp, edx ; next offset for sample 
   730                                  ReadSample:
   731                                  	;mov	ebx, [FileHandle]
   732                                  	;movzx  edx, [ModInfo.SampLen+esi]
   733                                  	;mov    ecx, [ModInfo.SampOfs+esi]
   734                                  
   735                                  	; ebx = File handle
   736                                  	; ecx = Buffer address
   737                                  	; edx = Byte count
   738                                  	sys	_read, [FileHandle]
   738                              <1> 
   738                              <1> 
   738                              <1> 
   738                              <1> 
   738                              <1>  %if %0 >= 2
   738 0000045E 8B1D[9E500000]      <1>  mov ebx, %2
   738                              <1>  %if %0 >= 3
   738                              <1>  mov ecx, %3
   738                              <1>  %if %0 = 4
   738                              <1>  mov edx, %4
   738                              <1>  %endif
   738                              <1>  %endif
   738                              <1>  %endif
   738 00000464 B803000000          <1>  mov eax, %1
   738                              <1> 
   738 00000469 CD40                <1>  int 40h
   739 0000046B 720A                    	jc      short CloseFile
   740                                  
   741                                  NextSample:
   742 0000046D 6683C602                	add     si, 2
   743 00000471 6683FE3E                	cmp     si, 2*31
   744 00000475 72C5                    	jb      short AllocSamples
   745                                  CloseFile:      
   746 00000477 9C                      	pushf
   747                                  	sys	_close, [FileHandle]
   747                              <1> 
   747                              <1> 
   747                              <1> 
   747                              <1> 
   747                              <1>  %if %0 >= 2
   747 00000478 8B1D[9E500000]      <1>  mov ebx, %2
   747                              <1>  %if %0 >= 3
   747                              <1>  mov ecx, %3
   747                              <1>  %if %0 = 4
   747                              <1>  mov edx, %4
   747                              <1>  %endif
   747                              <1>  %endif
   747                              <1>  %endif
   747 0000047E B806000000          <1>  mov eax, %1
   747                              <1> 
   747 00000483 CD40                <1>  int 40h
   748 00000485 9D                      	popf
   749                                  Failed:       
   750 00000486 61                      	popad
   751 00000487 C3                      	retn
   752                                  
   753                                  FreeModule:
   754                                  	; Erdogan Tan (13/02/2017)
   755                                  	; nothing to do here for memory de-allocation
   756                                  ClearModInfo:
   757 00000488 57                      	push	edi
   758 00000489 BF[DE540000]            	mov	edi, ModInfo
   759 0000048E B9FA010000              	mov     ecx, ModInfoRec.size
   760                                  	;cld
   761 00000493 30C0                    	xor     al, al
   762 00000495 F3AA                    	rep     stosb
   763 00000497 5F                      	pop	edi
   764 00000498 C3                      	retn
   765                                  
   766                                  ;=============================================================================
   767                                  ;               MODPLAY.ASM
   768                                  ;=============================================================================
   769                                  
   770                                  ; Amiga Module Loader v0.3b by Carlos Hasan.
   771                                  ;	July 23th, 1993.
   772                                  
   773                                  ; EQUATES
   774                                  
   775                                  ;NumTracks	equ 4 ; 07/10/2017 ([numtracks])
   776                                  DefTempo        equ 6
   777                                  DefBpm          equ 125
   778                                  MidCRate        equ 8448
   779                                  MixBufSize	equ 4096
   780                                  ;MixBufSize	equ 7680 ; 17/10/2017 ; ((48000/50)*8)
   781                                  
   782                                  ; STRUCTURES
   783                                  
   784                                  struc TrackInfo  ; 01/10/2017 (TMODPLAY.ASM) modif. by Erdogan Tan
   785 00000000 <res 00000004>          .Samples:	resd 1
   786                                  ;.Position:	resw 1
   787 00000004 <res 00000004>          .Position:	resd 1 ; 01/10/2017 - TRDOS 386 modification ! 
   788 00000008 <res 00000002>          .Len:		resw 1
   789 0000000A <res 00000002>          .Repeat:	resw 1
   790 0000000C <res 00000002>          .RepLen:	resw 1
   791 0000000E <res 00000001>          .Volume: 	resb 1 ; Volume
   792 0000000F <res 00000001>          .VolDiff:	resb 1 ; 01/10/2017 ; Volume difference (Tremolo)
   793                                  ;.Error:	resb 1
   794                                  ;.Reserved:	resb 1 ; 01/10/2017
   795 00000010 <res 00000002>          .Period:	resw 1 ; Period
   796 00000012 <res 00000002>          .Pitch:		resw 1 
   797 00000014 <res 00000002>          .Effect:	resw 1 ; Effect
   798 00000016 <res 00000002>          .PortTo:	resw 1 ; Toneporta wanted period
   799 00000018 <res 00000001>          .PortParm:	resb 1 ; Toneporta speed
   800 00000019 <res 00000001>          .VibPos:	resb 1 ; Vibrato wave position 
   801 0000001A <res 00000001>          .VibParm:	resb 1 ; Vibrato depth/rate
   802 0000001B <res 00000001>          .TremPos:	resb 1 ; 01/10/2017 ; Tremolo wave position
   803 0000001C <res 00000001>          .TremParm:	resb 1 ; 01/10/2017 ; Tremolo depth/rate
   804                                  ;.OldSampOfs:	resb 1 ; ******* ; 01/10/2017
   805 0000001D <res 00000001>          .Error:		resb 1 ; 01/10/2017
   806 0000001E <res 00000006>          .Arp:		resw 3
   807 00000024 <res 00000002>          .ArpIndex:	resw 1
   808                                  .size:		; 38 bytes ; 01/10/2017 -  TRDOS 386
   809                                  endstruc
   810                                  
   811                                  ; CODE
   812                                  
   813                                  ;--------------------------------------------------------------------------
   814                                  ; updatechannel - update the track using the current effect
   815                                  ;--------------------------------------------------------------------------
   816                                  ; 
   817                                  ;--------------------------------------------------------------------------
   818                                  ; 	Track:  Process the next 	 in one track.
   819                                  ;  In:
   820                                  ;    ds:di -  Track info Address.
   821                                  ;--------------------------------------------------------------------------
   822                                  
   823                                  ; edi = Track info address
   824                                  
   825                                  updatechannel:
   826                                  BeatTrack:	; updatechannel ; 01/10/2017 (TMODPLAY.ASM)
   827                                  
   828 00000499 668B5714                	mov     dx, [edi+TrackInfo.Effect]
   829                                  
   830                                  	;test   dx, dx
   831                                  	;je     short None
   832                                  	;cmp    dh, 00h
   833                                  	;je     short Arpeggio
   834                                  	;cmp    dh, 01h
   835                                  	;je     short PortUp
   836                                  	;cmp    dh, 02h
   837                                  	;je     short PortDown
   838                                  	;cmp    dh, 03h
   839                                  	;je     TonePort
   840                                  	;cmp    dh, 04h
   841                                  	;je     Vibrato
   842                                  	;cmp    dh, 05h
   843                                  	;je     PortSlide
   844                                  	;cmp    dh, 06h
   845                                  	;je     VibSlide
   846                                  	;cmp    dh, 0Ah
   847                                  	;je     VolSlide
   848                                  	;retn
   849                                  
   850 0000049D 0FB6C6                  	movzx	eax, dh
   851 000004A0 240F                    	and	al, 0Fh
   852 000004A2 FF2485[244E0000]        	jmp	dword [4*eax+efxtable2] ; TRDOS 386 ! (32 bits)
   853                                  efxnull:
   854                                  None:           
   855 000004A9 C3                      	retn
   856                                  efxarpeggio2:
   857                                  	; 01/10/2017
   858 000004AA 84D2                    	test    dl, dl
   859 000004AC 74FB                    	jz      short efxnull
   860                                  Arpeggio:
   861 000004AE 0FB75F24                	movzx   ebx, word [edi+TrackInfo.ArpIndex]
   862 000004B2 668B441F1E              	mov     ax, [edi+TrackInfo.Arp+ebx]
   863 000004B7 66894712                	mov     [edi+TrackInfo.Pitch], ax
   864 000004BB 6683C302                	add     bx, 2
   865 000004BF 6683FB06                	cmp     bx, 6
   866 000004C3 7202                    	jb      short SetArpIndex
   867 000004C5 31DB                    	xor     ebx, ebx
   868                                  SetArpIndex:
   869 000004C7 66895F24                	mov     [edi+TrackInfo.ArpIndex], bx
   870 000004CB C3                      	retn
   871                                  efxportaup:
   872                                  PortUp:
   873 000004CC 30F6                    	xor     dh, dh
   874                                  	;mov	bx, [edi+TrackInfo.Period]
   875 000004CE 0FB75F10                	movzx	ebx, word [edi+TrackInfo.Period] ; 02/10/2017
   876 000004D2 6629D3                  	sub     bx, dx
   877                                  	;cmp	bx, 113
   878 000004D5 6683FB1C                	cmp	bx, 28 ; 01/10/2017 
   879 000004D9 7D04                    	jge     short NotSmall
   880                                  	;mov	bx, 113
   881 000004DB 66BB1C00                	mov	bx, 28 ; 01/10/2017
   882                                  NotSmall:
   883 000004DF 66895F10                	mov     [edi+TrackInfo.Period], bx
   884 000004E3 6601DB                  	add     bx, bx
   885                                  	;mov	ax, [PitchTable+bx]
   886 000004E6 668B83[D8560000]        	mov	ax, [PitchTable+ebx]  ; 02/10/2017
   887 000004ED 66894712                	mov     [edi+TrackInfo.Pitch], ax
   888 000004F1 C3                      	retn
   889                                  efxportadown:
   890                                  PortDown:
   891 000004F2 30F6                    	xor     dh, dh
   892                                  	;mov	bx, [edi+TrackInfo.Period]
   893 000004F4 0FB75F10                	movzx	ebx, word [edi+TrackInfo.Period] ; 02/10/2017
   894 000004F8 6601D3                  	add     bx, dx
   895 000004FB 6681FB600D              	cmp	bx, 3424 ; 01/10/2017 
   896                                  	;cmp	bx, 856
   897 00000500 7E04                    	jle     short NotBig
   898                                  	;mov	bx, 856
   899 00000502 66BB600D                	mov	bx, 3424 ; 01/10/2017
   900                                  NotBig:         
   901 00000506 66895F10                	mov     [edi+TrackInfo.Period], bx
   902 0000050A 6601DB                  	add     bx, bx
   903                                  	;mov	ax, [PitchTable+bx]
   904 0000050D 668B83[D8560000]        	mov	ax, [PitchTable+ebx]  ; 02/10/2017
   905 00000514 66894712                	mov     [edi+TrackInfo.Pitch], ax
   906 00000518 C3                      	retn
   907                                  efxtoneporta2:
   908                                  TonePort:
   909 00000519 30F6                    	xor     dh, dh
   910 0000051B 668B4716                	mov     ax, [edi+TrackInfo.PortTo]
   911                                  	;mov	bx, [edi+TrackInfo.Period]
   912 0000051F 0FB75F10                	movzx	ebx, word [edi+TrackInfo.Period] ; 02/10/2017
   913 00000523 6639C3                  	cmp     bx, ax
   914 00000526 7429                    	je      short NoPort
   915 00000528 7F0D                    	jg      short PortToUp
   916                                  PortToDown:     
   917 0000052A 6601D3                  	add     bx, dx
   918 0000052D 6639C3                  	cmp     bx, ax
   919 00000530 7E0D                    	jle     short SetPort
   920                                  FixPort:        
   921 00000532 6689C3                  	mov     bx, ax
   922 00000535 EB08                    	jmp     short SetPort
   923                                  PortToUp:
   924 00000537 6629D3                  	sub     bx, dx
   925 0000053A 6639C3                  	cmp     bx, ax
   926 0000053D 7CF3                    	jl      short FixPort
   927                                  SetPort:        
   928 0000053F 66895F10                	mov     [edi+TrackInfo.Period], bx
   929 00000543 6601DB                  	add     bx, bx
   930                                  	;mov	ax, [PitchTable+bx]
   931 00000546 668B83[D8560000]        	mov	ax, [PitchTable+ebx]  ; 02/10/2017
   932 0000054D 66894712                	mov     [edi+TrackInfo.Pitch], ax
   933                                  NoPort:         
   934 00000551 C3                      	retn
   935                                  efxvibrato2:
   936                                  	; 01/10/2017
   937                                  Vibrato:
   938 00000552 88D6                    	mov     dh, dl
   939                                  	;and	dl, 0Fh
   940                                  	;shr	dh, 4
   941                                  	;shl	dh, 2
   942 00000554 6681E20FF0              	and     dx, 0F00Fh
   943 00000559 C0EE02                  	shr     dh, 2
   944                                  	;add	[edi+TrackInfo.VibPos], dh
   945                                  	;mov	dh, [edi+TrackInfo.VibPos]
   946                                  	;mov	bl, dh
   947 0000055C 8A5F19                  	mov	bl, [edi+TrackInfo.VibPos]  ; 01/10/2017
   948 0000055F 007719                  	add	[edi+TrackInfo.VibPos], dh
   949 00000562 88DE                    	mov	dh, bl ; 01/10/2017
   950 00000564 C0EB02                  	shr     bl, 2
   951                                  	;and	bx, 1Fh
   952                                  	;mov	al, [SinTable+bx]
   953 00000567 83E31F                  	and	ebx, 1Fh
   954 0000056A 8A83[0C4F0000]          	mov	al, [SinTable+ebx]
   955 00000570 F6E2                    	mul     dl
   956                                  	;rol	ax, 1
   957                                  	;xchg	al, ah
   958                                  	;and	ah, 1
   959 00000572 66C1E807                	shr	ax, 7
   960 00000576 84F6                    	test    dh, dh
   961 00000578 7903                    	jns     short VibUp
   962 0000057A 66F7D8                  	neg     ax
   963                                  VibUp:          
   964 0000057D 66034710                	add     ax, [edi+TrackInfo.Period]
   965 00000581 6689C3                  	mov	bx, ax
   966                                  	;movzx	ebx, ax
   967 00000584 6683FB71                	cmp     bx, 113
   968                                  	;cmp	bx, 113
   969 00000588 6683FB1C                	cmp	bx, 28  ; 01/10/2017
   970 0000058C 7D06                    	jge     short NoLoVib
   971                                  	;mov	bx, 113
   972 0000058E 66BB1C00                	mov	bx, 28	; 01/10/2017
   973 00000592 EB0B                    	jmp	short NoHiVib ; 01/10/2017	
   974                                  NoLoVib:        
   975 00000594 6681FB600D              	cmp	bx, 3424 ; 01/10/2017 
   976                                  	;cmp	bx, 856
   977 00000599 7E04                    	jle     short NoHiVib
   978                                  	;mov	bx, 856
   979 0000059B 66BB600D                	mov	bx, 3424 ; 01/10/2017
   980                                  NoHiVib:        
   981 0000059F 6601DB                  	add     bx, bx
   982                                  	;mov	ax, [PitchTable+bx]
   983 000005A2 668B83[D8560000]        	mov	ax, [PitchTable+ebx] ; 01/10/2017
   984 000005A9 66894712                	mov     [edi+TrackInfo.Pitch], ax
   985 000005AD C3                      	retn
   986                                  efxtoneslide:
   987                                  PortSlide:
   988 000005AE E812000000              	call    VolSlide
   989 000005B3 8A5718                  	mov     dl, [edi+TrackInfo.PortParm]  ; .tonespeed
   990 000005B6 E95EFFFFFF              	jmp     TonePort  ; efxtoneporta2
   991                                  efxvibslide:
   992                                  VibSlide:
   993 000005BB E805000000              	call    VolSlide
   994 000005C0 8A571A                  	mov     dl, [edi+TrackInfo.VibParm]
   995 000005C3 EB8D                    	jmp     short Vibrato  ; efxvibrato2
   996                                  efxvolslide:
   997                                  VolSlide:
   998 000005C5 88D6                    	mov     dh, dl
   999 000005C7 80E20F                  	and     dl, 0Fh
  1000 000005CA C0EE04                  	shr     dh, 4
  1001 000005CD 8A470E                  	mov     al, [edi+TrackInfo.Volume]
  1002 000005D0 28D0                    	sub     al, dl
  1003 000005D2 7D02                    	jge     short NoLoVol
  1004 000005D4 30C0                    	xor     al, al
  1005                                  NoLoVol:        
  1006 000005D6 00F0                    	add     al, dh
  1007 000005D8 3C40                    	cmp     al, 64
  1008 000005DA 7602                    	jbe     short NoHiVol
  1009 000005DC B040                    	mov     al, 64
  1010                                  NoHiVol:        
  1011 000005DE 88470E                  	mov     [edi+TrackInfo.Volume], al
  1012 000005E1 C3                      	retn
  1013                                  
  1014                                  efxtremolo2:
  1015                                  	; 01/10/2017 (TMODPLAY.ASM)
  1016                                  Tremolo:
  1017 000005E2 88D6                    	mov     dh, dl
  1018 000005E4 6681E20FF0              	and     dx, 0F00Fh
  1019 000005E9 C0EE02                  	shr     dh, 2
  1020 000005EC 8A5F1B                  	mov	bl, [edi+TrackInfo.TremPos]
  1021 000005EF 00771B                  	add	[edi+TrackInfo.TremPos], dh
  1022 000005F2 88DE                    	mov	dh, bl
  1023 000005F4 C0EB02                  	shr     bl, 2
  1024                                  	; 01/10/2017 - TRDOS 386
  1025                                  	;and	bx, 1Fh
  1026 000005F7 83E31F                  	and	ebx, 1Fh 
  1027                                  	;mov	al, [SinTable+bx]
  1028 000005FA 8A83[0C4F0000]          	mov     al, [SinTable+ebx]
  1029 00000600 F6E2                    	mul     dl
  1030 00000602 66C1E806                	shr	ax, 6
  1031 00000606 84F6                    	test    dh, dh
  1032 00000608 7D03                    	jge	short Tremolo_1 ; efxtremolof2
  1033 0000060A 66F7D8                  	neg     ax
  1034                                  efxtremolof2:
  1035                                  Tremolo_1:      
  1036 0000060D 8A670E                  	mov	ah, [edi+TrackInfo.Volume]    
  1037 00000610 00E0                    	add     al, ah
  1038 00000612 7D02                    	jge     short Tremolo_2 ; efxtremolof3
  1039 00000614 30C0                    	xor     al, al
  1040                                  efxtremolof3:
  1041                                  Tremolo_2:       
  1042 00000616 3C40                    	cmp     al, 64 ; 40h
  1043 00000618 7E02                    	jle     short Tremolo_3 ; efxtremolof4
  1044 0000061A B040                    	mov     al, 64 ; 40h
  1045                                  efxtremolof4:
  1046                                  Tremolo_3:       
  1047 0000061C 28E0                    	sub	al, ah  ; ****** 
  1048 0000061E 88470F                  	mov     [edi+TrackInfo.VolDiff], al
  1049 00000621 C3                      	retn	
  1050                                  
  1051                                  ;--------------------------------------------------------------------------
  1052                                  ; readchannel - read the next note event from the pattern sheet
  1053                                  ;--------------------------------------------------------------------------
  1054                                  ;
  1055                                  ;--------------------------------------------------------------------------
  1056                                  ; GetTrack:   Get the next Note from a pattern.
  1057                                  ;  In:
  1058                                  ;    ds:di -  Track info Address.
  1059                                  ;    es:si -  Pattern Note Address.
  1060                                  ; Out:
  1061                                  ;    es:si -  The Next Pattern Note address.
  1062                                  ;--------------------------------------------------------------------------
  1063                                  
  1064                                  ; esi = Pattern note address
  1065                                  ; edi = Track info address
  1066                                  
  1067                                  readchannel:
  1068                                  GetTrack: 	; readchannel ; 01/10/2017 (TMODPLAY.ASM)
  1069 00000622 66AD                    	lodsw
  1070 00000624 86C4                    	xchg    al, ah
  1071 00000626 88E3                    	mov	bl, ah
  1072 00000628 80E40F                  	and     ah, 0Fh
  1073 0000062B 6689C1                  	mov     cx, ax
  1074 0000062E 66AD                    	lodsw
  1075 00000630 86C4                    	xchg    al, ah
  1076 00000632 88E7                    	mov     bh, ah
  1077 00000634 80E40F                  	and     ah, 0Fh
  1078 00000637 6689C2                  	mov     dx, ax
  1079 0000063A 66895714                	mov     [edi+TrackInfo.Effect], dx
  1080                                  	; 01/10/2017 - TRDOS 386
  1081                                  	;and	bl, 0F0h
  1082 0000063E 81E3F0FF0000            	and	ebx, 0FFF0h
  1083 00000644 C0EF04                  	shr     bh, 4
  1084 00000647 08FB                    	or      bl, bh
  1085 00000649 7446                    	jz      short SetPeriod
  1086                                  SetSample:
  1087 0000064B 30FF                    	xor	bh, bh
  1088                                  	;and	ebx, 0FFh
  1089 0000064D FECB                    	dec     bl
  1090 0000064F 01DB                    	add     ebx, ebx
  1091 00000651 668B83[9A560000]        	mov     ax, [ModInfo.SampVol+ebx]
  1092 00000658 88470E                  	mov     [edi+TrackInfo.Volume], al
  1093 0000065B 668B83[64550000]        	mov     ax, [ModInfo.SampOfs+ebx]
  1094 00000662 668907                  	mov     [edi+TrackInfo.Samples], ax
  1095 00000665 668B83[A2550000]        	mov     ax, [ModInfo.SampSeg+ebx]
  1096 0000066C 66894702                	mov     [edi+TrackInfo.Samples+2], ax
  1097 00000670 668B83[E0550000]        	mov     ax, [ModInfo.SampLen+ebx]
  1098 00000677 66894708                	mov     [edi+TrackInfo.Len], ax
  1099 0000067B 668B83[1E560000]        	mov     ax, [ModInfo.SampRep+ebx]
  1100 00000682 6689470A                	mov     [edi+TrackInfo.Repeat], ax
  1101 00000686 668B83[5C560000]        	mov     ax, [ModInfo.SampRepLen+ebx]
  1102 0000068D 6689470C                	mov     [edi+TrackInfo.RepLen], ax
  1103                                  SetPeriod:      
  1104 00000691 6685C9                  	test    cx, cx
  1105 00000694 7425                    	jz      short SetEffect
  1106                                  
  1107 00000696 66894F16                	mov     [edi+TrackInfo.PortTo], cx ; *
  1108                                  	
  1109 0000069A 80FE03                  	cmp     dh, 03h
  1110                                  	;je	short SetEffect
  1111 0000069D 7428                    	je	short efxtoneporta ; 01/10/2017
  1112                                  
  1113 0000069F 66894F10                	mov     [edi+TrackInfo.Period], cx
  1114                                  	;movzx	ebx, cx
  1115 000006A3 6689CB                  	mov     bx, cx
  1116 000006A6 6601DB                  	add     bx, bx
  1117                                  	;mov	ax, [PitchTable+bx]
  1118 000006A9 668B83[D8560000]        	mov	ax, [PitchTable+ebx] ; 01/10/2017
  1119 000006B0 66894712                	mov     [edi+TrackInfo.Pitch], ax
  1120 000006B4 C7470400000000          	mov     dword [edi+TrackInfo.Position], 0
  1121                                  SetEffect:
  1122                                  	;test	dx, dx
  1123                                  	;je	short InitNone
  1124                                  	;cmp	dh, 00h
  1125                                  	;je	InitArpeggio
  1126                                  	;cmp	dh, 03h
  1127                                  	;je	short InitTonePort
  1128                                  	;cmp	dh, 04h
  1129                                  	;je	short InitVibrato
  1130                                  	;cmp	dh, 09h
  1131                                  	;je	short SampleOfs
  1132                                  	;cmp	dh, 0Bh
  1133                                  	;je	short PosJump
  1134                                  	;cmp	dh, 0Ch
  1135                                  	;je	short SetVolume
  1136                                  	;cmp	dh, 0Dh
  1137                                  	;je	short Break
  1138                                  	;cmp	dh, 0Fh
  1139                                  	;je	SetSpeed
  1140                                  	;retn
  1141                                  
  1142                                  	; 01/10/2017 (TMODPLAY.ASM)
  1143                                  	
  1144                                  	; dx = [di+TrackInfo.Effect]
  1145                                  	
  1146 000006BB 0FB6C6                  	movzx	eax, dh
  1147 000006BE 240F                    	and	al, 0Fh
  1148 000006C0 FF2485[E44D0000]        	jmp	dword [4*eax+efxtable] ; TRDOS 386 ! (32 bits)
  1149                                  ;efxnull:
  1150                                  ;InitNone:
  1151                                  ;	retn
  1152                                  efxtoneporta:
  1153                                  	; 01/10/2017
  1154                                  	; cx = period
  1155                                  	;mov	[edi+TrackInfo.PortTo], cx ; *
  1156                                  InitTonePort:
  1157 000006C7 84D2                    	test    dl, dl
  1158 000006C9 7503                    	jnz     short SetPortParm
  1159 000006CB 8A5718                  	mov     dl, [edi+TrackInfo.PortParm] ; .tonespeed
  1160                                  SetPortParm:    
  1161 000006CE 885718                  	mov     [edi+TrackInfo.PortParm], dl
  1162 000006D1 66895714                	mov     [edi+TrackInfo.Effect], dx
  1163 000006D5 C3                      	retn
  1164                                  efxvibrato:
  1165                                  InitVibrato:
  1166 000006D6 8A471A                  	mov     al, [edi+TrackInfo.VibParm]
  1167 000006D9 88C4                    	mov     ah, al
  1168                                  	;and	al, 0Fh
  1169                                  	;and	ah, 0F0h
  1170 000006DB 66250FF0                	and	ax, 0F00Fh
  1171 000006DF F6C20F                  	test    dl, 0Fh
  1172 000006E2 7502                    	jne     short OkDepth
  1173 000006E4 08C2                    	or      dl, al
  1174                                  OkDepth:        
  1175 000006E6 F6C2F0                  	test    dl, 0F0h
  1176 000006E9 7502                    	jnz     short OkRate
  1177 000006EB 08E2                    	or      dl, ah
  1178                                  OkRate:         
  1179 000006ED 88571A                  	mov     [edi+TrackInfo.VibParm], dl
  1180 000006F0 66895714                	mov     [edi+TrackInfo.Effect], dx
  1181 000006F4 6685C9                  	test    cx, cx
  1182 000006F7 7404                    	jz      short OkPos
  1183 000006F9 C6471900                	mov     byte [edi+TrackInfo.VibPos], 0
  1184                                  OkPos:          
  1185 000006FD C3                      	retn
  1186                                  efxsampoffset:
  1187                                  	; 01/10/2017 ; *******
  1188                                  SampleOfs:         
  1189                                  ;	test    dl, dl
  1190                                  ;	jnz     short SetSampleOfs
  1191                                  ;	mov     dl, [edi+TrackInfo.OldSampOfs]
  1192                                  ;SetSampleOfs:
  1193                                  ;	mov     [edi+TrackInfo.OldSampOfs], dl
  1194 000006FE 88D6                    	mov     dh, dl
  1195 00000700 81E200FF0000            	and 	edx, 0FF00h ; 05/03/2017
  1196 00000706 895704                  	mov     [edi+TrackInfo.Position], edx
  1197 00000709 C3                      	retn
  1198                                  efxpattjump:
  1199                                  PosJump:
  1200 0000070A 8815[86D20000]          	mov     [OrderPos], dl
  1201 00000710 C605[8AD20000]40        	mov     byte [Row], 64
  1202 00000717 C3                      	retn
  1203                                  efxsetvolume:
  1204                                  SetVolume:
  1205 00000718 80FA40                  	cmp     dl, 64
  1206 0000071B 7602                    	jbe     short OkVol
  1207 0000071D B240                    	mov     dl, 64
  1208                                  OkVol:
  1209                                  	; 01/10/2017 (TrackInfo.VolDiff, tremolo effect)
  1210 0000071F 30F6                    	xor	dh, dh ; reset TrackInfo.VolDiff ; Not necessary !?
  1211                                  	;mov	[edi+TrackInfo.Volume], dl
  1212 00000721 6689570E                	mov	[edi+TrackInfo.Volume], dx 
  1213 00000725 C3                      	retn
  1214                                  efxbreak:
  1215                                  Break:
  1216 00000726 88D6                    	mov     dh, dl
  1217 00000728 80E20F                  	and     dl, 0Fh
  1218 0000072B C0EE04                  	shr     dh, 4
  1219 0000072E 00F6                    	add     dh, dh
  1220 00000730 00F2                    	add     dl, dh
  1221 00000732 C0E602                  	shl     dh, 2
  1222 00000735 00F2                    	add     dl, dh
  1223 00000737 8815[8BD20000]          	mov     [BreakRow], dl
  1224 0000073D C605[8AD20000]40        	mov     byte [Row], 64
  1225 00000744 C3                      	retn
  1226                                  efxsetspeed:
  1227                                  SetSpeed:
  1228 00000745 84D2                    	test    dl,dl
  1229 00000747 7432                    	je      Skip
  1230 00000749 80FA1F                  	cmp     dl,31
  1231 0000074C 770D                    	ja      short SetBpm
  1232                                  SetTempo:       
  1233 0000074E 8815[87D20000]          	mov     [Tempo], dl
  1234 00000754 8815[88D20000]          	mov     [TempoWait], dl
  1235 0000075A C3                      	retn
  1236                                  SetBpm:
  1237 0000075B 8815[89D20000]          	mov     [Bpm], dl
  1238 00000761 B067                    	mov     al, 103
  1239 00000763 F6E2                    	mul     dl
  1240 00000765 88E3                    	mov     bl, ah
  1241 00000767 30FF                    	xor     bh, bh
  1242 00000769 66A1[66500000]          	mov     ax, [MixSpeed]
  1243 0000076F 6631D2                  	xor     dx, dx
  1244 00000772 66F7F3                  	div     bx
  1245 00000775 66A3[8CD20000]          	mov     [BpmSamples], ax
  1246                                  Skip:           
  1247 0000077B C3                      	retn
  1248                                  efxarpeggio:
  1249                                  	; 01/10/2017
  1250 0000077C 84D2                    	test    dl, dl
  1251                                  	;je	efxnull
  1252 0000077E 74FB                    	je	short Skip
  1253                                  InitArpeggio:
  1254 00000780 88D6                    	mov     dh, dl
  1255 00000782 80E20F                  	and     dl, 0Fh
  1256 00000785 C0EE04                  	shr     dh, 4
  1257                                  	; 01/10/2017
  1258                                  	;mov	cx, 36
  1259 00000788 66B95400                	mov	cx, 84 ; 84 notes/periods
  1260 0000078C 31DB                    	xor     ebx, ebx
  1261 0000078E 668B4710                	mov     ax, [edi+TrackInfo.Period]
  1262                                  gt_ScanPeriod:
  1263                                  	;cmp	ax, [PeriodTable+bx]
  1264 00000792 663B83[644E0000]        	cmp	ax, [PeriodTable+ebx]
  1265 00000799 7306                    	jae     short SetArp
  1266 0000079B 6683C302                	add     bx, 2
  1267 0000079F E2F1                    	loop    gt_ScanPeriod
  1268                                  SetArp:         
  1269 000007A1 6601D2                  	add     dx, dx
  1270 000007A4 00DE                    	add     dh, bl
  1271 000007A6 00DA                    	add     dl, bl
  1272                                  	; 01/10/2017
  1273                                  	;mov	bx, [PeriodTable+bx]
  1274 000007A8 668B9B[644E0000]        	mov	bx, [PeriodTable+ebx]
  1275                                  	;add	bx, bx
  1276 000007AF 01DB                    	add	ebx, ebx
  1277                                  	;mov	ax, [PitchTable+bx]
  1278 000007B1 668B83[D8560000]        	mov	ax, [PitchTable+ebx]
  1279 000007B8 6689471E                	mov     [edi+TrackInfo.Arp], ax
  1280 000007BC 88F3                    	mov     bl, dh
  1281 000007BE 30FF                    	xor     bh, bh
  1282 000007C0 668B9B[644E0000]        	mov	bx, [PeriodTable+ebx]
  1283                                  	;add	bx, bx
  1284 000007C7 01DB                    	add	ebx, ebx
  1285                                  	;mov	ax, [PitchTable+bx]
  1286 000007C9 668B83[D8560000]        	mov	ax, [PitchTable+ebx]
  1287 000007D0 66894720                	mov     [edi+TrackInfo.Arp+2], ax
  1288 000007D4 88D3                    	mov     bl, dl
  1289 000007D6 30FF                    	xor     bh, bh
  1290 000007D8 668B9B[644E0000]        	mov	bx, [PeriodTable+ebx]
  1291                                  	;add	bx, bx
  1292 000007DF 01DB                    	add	ebx, ebx
  1293                                  	;mov	ax, [PitchTable+bx]
  1294 000007E1 668B83[D8560000]        	mov	ax, [PitchTable+ebx]
  1295 000007E8 66894722                	mov     [edi+TrackInfo.Arp+4], ax
  1296 000007EC 66C747240000            	mov     word [edi+TrackInfo.ArpIndex], 0
  1297 000007F2 C3                      	retn
  1298                                  
  1299                                  efxtremolo:
  1300                                  	; 01/10/2017 (TMODPLAY.ASM)
  1301                                  InitTremolo:
  1302 000007F3 8A471C                  	mov     al, [edi+TrackInfo.TremParm]
  1303 000007F6 88C4                    	mov     ah, al
  1304 000007F8 66250FF0                	and     ax, 0F00Fh
  1305 000007FC F6C20F                  	test    dl, 0Fh
  1306 000007FF 7502                    	jnz     short InitTremolo_1 ; efxtremolof0
  1307 00000801 08C2                    	or      dl, al
  1308                                  efxtremolof0:
  1309                                  InitTremolo_1: 
  1310 00000803 F6C2F0                  	test    dl, 0F0h
  1311 00000806 7502                    	jnz     short InitTremolo_2 ; efxtremolof1
  1312 00000808 08E2                    	or      dl, ah
  1313                                  efxtremolof1:
  1314                                  InitTremolo_2:
  1315 0000080A 88571C                  	mov     [edi+TrackInfo.TremParm], dl
  1316 0000080D 66895714                	mov     [edi+TrackInfo.Effect], dx
  1317 00000811 C3                      	retn
  1318                                  
  1319                                  ;--------------------------------------------------------------------------
  1320                                  ; pollmodule - polls the module player
  1321                                  ;--------------------------------------------------------------------------
  1322                                  ;--------------------------------------------------------------------------
  1323                                  ; UpdateTracks:  Main code to process the next tick to be played.
  1324                                  ;--------------------------------------------------------------------------
  1325                                  
  1326                                  pollmodule:
  1327                                  UpdateTracks:	; polmodule ; 01/10/2017 (TMODPLAY.ASM)
  1328 00000812 FE0D[88D20000]          	dec     byte [TempoWait]
  1329 00000818 7417                    	jz      short GetTracks
  1330                                  
  1331                                  	;mov	ecx, NumTracks
  1332 0000081A 0FB70D[5D500000]        	movzx	ecx, word [numtracks] ; 06/10/2017
  1333 00000821 BF[9CD20000]            	mov	edi, Tracks
  1334                                  BeatTracks:
  1335 00000826 E86EFCFFFF              	call	BeatTrack	
  1336 0000082B 83C726                  	add	edi, TrackInfo.size
  1337 0000082E E2F6                    	loop	BeatTracks
  1338 00000830 C3                      	retn
  1339                                  GetTracks:
  1340 00000831 A0[87D20000]            	mov     al, [Tempo]
  1341 00000836 A2[88D20000]            	mov     [TempoWait], al
  1342                                  
  1343 0000083B 8B35[98D20000]          	mov	esi, [Note]
  1344 00000841 803D[8AD20000]40        	cmp     byte [Row], 64
  1345 00000848 7268                    	jb      short NoPattWrap
  1346                                  
  1347 0000084A 8B35[60550000]          	mov	esi, [ModInfo.Patterns]
  1348 00000850 8A1D[86D20000]          	mov     bl, [OrderPos]
  1349 00000856 3A1D[DE540000]          	cmp     bl, [ModInfo.OrderLen]
  1350 0000085C 7214                    	jb      short NoOrderWrap
  1351 0000085E 8A1D[DF540000]          	mov     bl, [ModInfo.ReStart]
  1352 00000864 881D[86D20000]          	mov     [OrderPos], bl
  1353 0000086A 3A1D[DE540000]          	cmp     bl, [ModInfo.OrderLen]
  1354 00000870 7364                    	jae     short NoUpdate
  1355                                  NoOrderWrap:    
  1356                                  	;xor	bh, bh
  1357 00000872 81E3FF000000            	and	ebx, 0FFh
  1358 00000878 8A9B[E0540000]          	mov     bl, [ModInfo.Order+ebx]
  1359                                  	; 05/10/2017
  1360                                  	;shl	ebx, 10 ; *1024
  1361 0000087E 8A0D[5C500000]          	mov	cl, [pattern_shift] ; 10 or 11
  1362 00000884 D3E3                    	shl	ebx, cl ; *1024 or *2048
  1363                                  	;
  1364 00000886 01DE                    	add     esi, ebx
  1365 00000888 8A1D[8BD20000]          	mov     bl, [BreakRow]
  1366 0000088E 881D[8AD20000]          	mov     [Row], bl
  1367                                  	;xor	bh, bh
  1368 00000894 81E3FF000000            	and	ebx, 0FFh
  1369 0000089A 883D[8BD20000]          	mov     [BreakRow], bh ; 0
  1370 000008A0 66C1E304                	shl     bx, 4
  1371 000008A4 01DE                    	add     esi, ebx
  1372 000008A6 8935[98D20000]          	mov     [Note], esi
  1373 000008AC FE05[86D20000]          	inc     byte [OrderPos]
  1374                                  NoPattWrap:     
  1375 000008B2 FE05[8AD20000]          	inc     byte [Row]
  1376                                  
  1377                                  	;cld
  1378                                  	;mov	ecx, NumTracks
  1379 000008B8 0FB70D[5D500000]        	movzx	ecx, word [numtracks] ; 06/10/2017
  1380 000008BF BF[9CD20000]            	mov	edi, Tracks
  1381                                  GetTracks_next:
  1382 000008C4 51                      	push	ecx	
  1383 000008C5 E858FDFFFF              	call	GetTrack ; readchannel
  1384 000008CA 59                      	pop	ecx
  1385 000008CB 83C726                  	add	edi, TrackInfo.size
  1386 000008CE E2F4                    	loop	GetTracks_next
  1387                                  
  1388 000008D0 8935[98D20000]          	mov     [Note], esi
  1389                                  NoUpdate:
  1390 000008D6 C3                      	retn
  1391                                  
  1392                                  ;--------------------------------------------------------------------------
  1393                                  ; MixTrack:  Mixes one track into a CLEAN buffer.
  1394                                  ;  In:
  1395                                  ;   ds:si -  Track Info Address.
  1396                                  ;   ds:di -  Buffer Address.
  1397                                  ;    cx   -  Buffer Size.
  1398                                  ;--------------------------------------------------------------------------
  1399                                  
  1400                                  ; esi = Track info address
  1401                                  ; edi = Buffer address
  1402                                  ; ecx = Buffer size
  1403                                  
  1404                                  MixTrack:
  1405 000008D7 66837E0C02              	cmp     word [esi+TrackInfo.RepLen], 2
  1406 000008DC 7757                    	ja      short MixLooped
  1407                                  MixNonLooped:   
  1408 000008DE 8B16                    	mov	edx, [esi+TrackInfo.Samples]
  1409 000008E0 8B5E04                  	mov	ebx, [esi+TrackInfo.Position]
  1410 000008E3 0FB76E08                	movzx   ebp, word [esi+TrackInfo.Len]
  1411 000008E7 52                      	push    edx
  1412 000008E8 56                      	push    esi
  1413 000008E9 01D3                    	add     ebx, edx
  1414 000008EB 01D5                    	add     ebp, edx
  1415 000008ED 668B5612                	mov     dx, [esi+TrackInfo.Pitch]
  1416                                  	; 01/10/2017
  1417                                  	;mov	al, [esi+TrackInfo.Volume]
  1418 000008F1 668B460E                	mov	ax, [esi+TrackInfo.Volume]
  1419                                  	; ah = [esi+TrackInfo.VolDiff]
  1420 000008F5 00E0                    	add	al, ah ; ****** 
  1421 000008F7 C6460F00                	mov	byte [esi+TrackInfo.VolDiff], 0
  1422 000008FB 8A661D                  	mov     ah, [esi+TrackInfo.Error]
  1423 000008FE 89DE                    	mov     esi, ebx
  1424 00000900 31DB                    	xor	ebx, ebx ; 01/10/2017 ; *
  1425 00000902 88C7                    	mov     bh, al
  1426 00000904 88D0                    	mov     al, dl
  1427 00000906 88F2                    	mov     dl, dh
  1428                                  	;xor	dh, dh
  1429 00000908 81E2FF000000            	and	edx, 0FFh
  1430                                  nlMixSamp:      
  1431 0000090E 39EE                    	cmp     esi, ebp
  1432 00000910 7316                    	jae     short nlMixBye
  1433 00000912 8A1E                    	mov     bl, [esi]
  1434                                  	;mov	bl, [VolTable+bx]
  1435 00000914 8A9B[9A710000]          	mov	bl, [VolTable+ebx] ; 01/10/2017 ; *	
  1436                                  	; 17/10/2017
  1437 0000091A 001F                    	add     [edi], bl
  1438                                  	; 18/10/2017
  1439 0000091C 00C4                    	add     ah, al
  1440 0000091E 11D6                    	adc     esi, edx
  1441 00000920 033D[5D500000]          	add	edi, [numtracks]
  1442 00000926 E2E6                    	loop    nlMixSamp
  1443                                  nlMixBye:       
  1444 00000928 89F3                    	mov     ebx, esi
  1445 0000092A 5E                      	pop     esi
  1446 0000092B 5A                      	pop     edx
  1447 0000092C 29D3                    	sub     ebx, edx
  1448 0000092E 895E04                  	mov     [esi+TrackInfo.Position], ebx
  1449 00000931 88661D                  	mov     [esi+TrackInfo.Error], ah
  1450 00000934 C3                      	retn
  1451                                  MixLooped:
  1452 00000935 8B16                    	mov	edx, [esi+TrackInfo.Samples]
  1453 00000937 8B5E04                  	mov	ebx, [esi+TrackInfo.Position]
  1454 0000093A 0FB76E0C                	movzx	ebp, word [esi+TrackInfo.RepLen]
  1455 0000093E 892D[94D20000]          	mov     [BufRep], ebp
  1456                                  	;add	ebp, [esi+TrackInfo.Repeat] ; BUG !
  1457 00000944 66036E0A                	add     bp, [esi+TrackInfo.Repeat] ; 07/10/2017 (BUGfix!)
  1458 00000948 52                      	push    edx
  1459 00000949 56                      	push    esi
  1460 0000094A 01D3                    	add     ebx, edx
  1461 0000094C 01D5                    	add     ebp, edx
  1462 0000094E 668B5612                	mov     dx, [esi+TrackInfo.Pitch]
  1463                                  	; 01/10/2017
  1464                                  	;mov	al, [esi+TrackInfo.Volume]
  1465 00000952 668B460E                	mov	ax, [esi+TrackInfo.Volume]
  1466                                  	; ah = [esi+TrackInfo.VolDiff]
  1467 00000956 00E0                    	add	al, ah ; ****** 
  1468 00000958 C6460F00                	mov	byte [esi+TrackInfo.VolDiff], 0
  1469 0000095C 8A661D                  	mov     ah, [esi+TrackInfo.Error]
  1470                                  	;mov	si, bx
  1471 0000095F 89DE                    	mov	esi, ebx ; 04/09/2017
  1472 00000961 31DB                    	xor	ebx, ebx ; 01/10/2017 ; *
  1473 00000963 88C7                    	mov     bh, al
  1474 00000965 88D0                    	mov     al, dl
  1475 00000967 88F2                    	mov     dl, dh
  1476                                  	;xor	dh, dh
  1477 00000969 81E2FF000000            	and	edx, 0FFh
  1478                                  lpMixSamp:      
  1479 0000096F 39EE                    	cmp     esi, ebp
  1480 00000971 7206                    	jb      short lpMixNow
  1481 00000973 2B35[94D20000]          	sub     esi, [BufRep]
  1482                                  lpMixNow:       
  1483 00000979 8A1E                    	mov     bl, [esi]
  1484                                  	;mov	bl, [VolTable+bx]
  1485 0000097B 8A9B[9A710000]          	mov	bl, [VolTable+ebx] ; 01/10/2017 ; *
  1486                                  	; 17/10/2017
  1487 00000981 001F                    	add     [edi], bl
  1488                                  	; 18/10/2017
  1489 00000983 00C4                    	add     ah, al
  1490 00000985 11D6                    	adc     esi, edx
  1491 00000987 033D[5D500000]          	add	edi, [numtracks]
  1492 0000098D E2E0                    	loop    lpMixSamp
  1493                                  lpMixBye:       
  1494                                  ;	mov     ebx, esi
  1495                                  ;	pop     esi
  1496                                  ;	pop     edx
  1497                                  ;	sub     ebx, edx
  1498                                  ;	mov     [esi+TrackInfo.Position], ebx
  1499                                  ;	mov     [esi+TrackInfo.Error], ah
  1500                                  ;	retn
  1501 0000098F EB97                    	jmp	short nlMixBye
  1502                                  
  1503                                  ;--------------------------------------------------------------------------
  1504                                  ; mixpoll - updates the output buffer
  1505                                  ;--------------------------------------------------------------------------
  1506                                  ;
  1507                                  ;--------------------------------------------------------------------------
  1508                                  ; GetSamples:  Returns the next chunk of samples to be played.
  1509                                  ;  In:
  1510                                  ;    Buffer  - Buffer Address.
  1511                                  ;    Count   - Buffer Size.
  1512                                  ;--------------------------------------------------------------------------
  1513                                  
  1514                                  mixpoll:
  1515                                  GetSamples:	; mixpoll ; 01/10/2017 (TMODPLAY.ASM)
  1516                                  	; edi = buffer address
  1517                                  	; ebx = count
  1518                                  
  1519 00000991 60                      	pushad
  1520                                  
  1521                                  	;cld
  1522                                  NextChunk:      
  1523 00000992 66833D[92D20000]00      	cmp     word [BufLen], 0
  1524 0000099A 756B                    	jne     short CopyChunk
  1525                                  
  1526 0000099C 53                      	push    ebx
  1527 0000099D 57                      	push    edi
  1528                                  MixChunk:       
  1529 0000099E BF[9AB20000]            	mov	edi, MixBuffer
  1530                                  
  1531                                  	; 17/10/2017
  1532 000009A3 0FB70D[8CD20000]        	movzx	ecx, word [BpmSamples]
  1533                                  	;mov	cx, [BpmSamples]
  1534 000009AA 893D[8ED20000]          	mov     [BufPtr], edi
  1535 000009B0 66890D[92D20000]        	mov	[BufLen], cx
  1536                                  
  1537 000009B7 803D[5D500000]04        	cmp	byte [numtracks], 4
  1538 000009BE 7603                    	jna	short ch_silence
  1539 000009C0 66D1E1                  	shl	cx, 1 
  1540                                  ch_silence:
  1541 000009C3 B880808080              	mov	eax, 80808080h
  1542 000009C8 F3AB                    	rep	stosd
  1543                                  
  1544                                  	;mov	cx, NumTracks
  1545                                  	;mov	cl, NumTracks ; 01/10/2017
  1546 000009CA 8A0D[5D500000]          	mov	cl, [numtracks] ; 06/10/2017
  1547 000009D0 BE[76D20000]            	mov	esi, Tracks - TrackInfo.size
  1548                                  GetSamples_next:
  1549 000009D5 51                      	push	ecx
  1550 000009D6 83C626                  	add	esi, TrackInfo.size
  1551 000009D9 668B0D[92D20000]        	mov	cx, [BufLen]
  1552 000009E0 8B3D[8ED20000]          	mov	edi, [BufPtr]
  1553 000009E6 E8ECFEFFFF              	call	MixTrack
  1554 000009EB 59                      	pop	ecx
  1555 000009EC FF05[8ED20000]          	inc	dword [BufPtr] ; 18/10/2017
  1556 000009F2 E2E1                    	loop	GetSamples_next
  1557                                  
  1558                                   	; 18/10/2017	
  1559 000009F4 8B1D[5D500000]          	mov	ebx, [numtracks]
  1560 000009FA 291D[8ED20000]          	sub	dword [BufPtr], ebx
  1561                                  
  1562 00000A00 E80DFEFFFF              	call    UpdateTracks
  1563                                  
  1564 00000A05 5F                      	pop     edi
  1565 00000A06 5B                      	pop     ebx
  1566                                  CopyChunk:      
  1567                                  	;mov	cx, [BufLen]
  1568 00000A07 0FB70D[92D20000]        	movzx	ecx, word [BufLen]
  1569 00000A0E 39D9                    	cmp	ecx, ebx
  1570                                  	;cmp	cx, bx
  1571 00000A10 7602                    	jbe     short MoveChunk
  1572                                  	;mov	cx, bx
  1573 00000A12 89D9                    	mov     ecx, ebx
  1574                                  MoveChunk:
  1575 00000A14 8B35[8ED20000]          	mov     esi, [BufPtr]
  1576 00000A1A 010D[8ED20000]          	add     [BufPtr], ecx
  1577 00000A20 66290D[92D20000]        	sub     [BufLen], cx
  1578 00000A27 29CB                    	sub     ebx, ecx
  1579                                  	; 17/10/2017 ; STEREO MIXING
  1580                                  	;rep	movsb
  1581                                  	; 18/10/2017
  1582 00000A29 803D[5D500000]04        	cmp	byte [numtracks], 4
  1583                                  	;jna	short _4_channels_mix
  1584 00000A30 762F                    	jna	_4_channels_mix
  1585                                  	
  1586                                  _8_channels_mix:
  1587                                  	; 18/10/2017
  1588 00000A32 AD                      	lodsd 
  1589 00000A33 89C2                    	mov	edx, eax ; ch1 (al), ch2 (ah)
  1590 00000A35 C1EA10                  	shr	edx, 16 ; ch3 (dl), ch4 (dh)
  1591 00000A38 00C6                    	add	dh, al ; ch1 + ch4
  1592 00000A3A 00E2                    	add	dl, ah ; ch2 + ch3
  1593                                  
  1594 00000A3C AD                      	lodsd
  1595 00000A3D 00C6                    	add	dh, al ; ch1 + ch4 + ch5
  1596 00000A3F 00E2                    	add	dl, ah ; ch2 + ch3 + ch6
  1597 00000A41 C1E810                  	shr	eax, 16 ; ch7 (al), ch8 (ah)
  1598                                  	; 19/10/2017
  1599 00000A44 00E6                    	add	dh, ah ; ch1 + ch4 + ch5 + ch8
  1600 00000A46 00C2                    	add	dl, al ; ch2 + ch3 + ch6 + ch7
  1601                                  
  1602                                  	; L = ch1 + ch4 + ch5 + ch8
  1603                                  	; R = ch2 + ch3 + ch6 + ch7
  1604                                  
  1605 00000A48 6681C28080              	add	dx, 8080h
  1606                                  
  1607                                  	; 19/10/2017
  1608 00000A4D 88F4                    	mov	ah, dh
  1609 00000A4F 80EC80                  	sub	ah, 80h
  1610 00000A52 30C0                    	xor	al, al
  1611 00000A54 66AB                    	stosw ; Left Channel
  1612 00000A56 88D4                    	mov	ah, dl
  1613 00000A58 80EC80                  	sub	ah, 80h
  1614 00000A5B 66AB                    	stosw ; Right Channel
  1615                                  
  1616 00000A5D E2D3                    	loop	_8_channels_mix
  1617                                  	
  1618 00000A5F EB21                    	jmp	short channel_mix_ok
  1619                                  	
  1620                                  _4_channels_mix:
  1621                                  	; 18/10/2017
  1622 00000A61 AD                      	lodsd 
  1623 00000A62 89C2                    	mov	edx, eax ; ch1 (al), ch2 (ah)
  1624                                  	; 19/10/2017
  1625 00000A64 C1E810                  	shr	eax, 16 ; ch3 (al), ch4 (ah)
  1626 00000A67 00E2                    	add	dl, ah ; ch1 + ch4
  1627 00000A69 00C6                    	add	dh, al ; ch2 + ch3
  1628                                  
  1629                                  	; L = ch1 + ch4
  1630                                  	; R = ch2 + ch3
  1631                                  
  1632                                  	; 19/10/2017
  1633 00000A6B 6681C28080              	add	dx, 8080h
  1634                                  
  1635                                  	; 19/10/2017
  1636 00000A70 88D4                    	mov	ah, dl
  1637 00000A72 80EC80                  	sub	ah, 80h
  1638 00000A75 30C0                    	xor	al, al
  1639 00000A77 66AB                    	stosw ; Left Channel
  1640 00000A79 88F4                    	mov	ah, dh
  1641 00000A7B 80EC80                  	sub	ah, 80h
  1642 00000A7E 66AB                    	stosw ; Right Channel
  1643                                  	
  1644 00000A80 E2DF                    	loop	_4_channels_mix
  1645                                  
  1646                                  channel_mix_ok:
  1647 00000A82 85DB                    	test    ebx, ebx
  1648                                  	;jnz	short NextChunk
  1649 00000A84 0F8508FFFFFF            	jnz	NextChunk ; 17/10/2017
  1650                                  
  1651                                  	; 20/10/2017
  1652                                  	; 19/10/2017
  1653                                  	; Pan Control
  1654 00000A8A 8A0D[20DE0000]          	mov	cl, [pan_shift]
  1655 00000A90 08C9                    	or	cl, cl
  1656 00000A92 744D                    	jz	short c_smpl_2
  1657                                  
  1658                                  	; 20/10/2017
  1659 00000A94 BB00200000              	mov	ebx, BUFFERSIZE/4 ; 8192
  1660 00000A99 BF[00E00000]            	mov	edi, Audio_Buffer
  1661                                  
  1662 00000A9E B508                    	mov	ch, 8
  1663 00000AA0 D2E5                    	shl	ch, cl
  1664                                  c_smpl_1:
  1665 00000AA2 8B17                    	mov	edx, [edi]
  1666 00000AA4 6689D0                  	mov	ax, dx
  1667 00000AA7 80FC80                  	cmp	ah, 80h
  1668 00000AAA 7208                    	jb	short _cs1	
  1669 00000AAC 00EC                    	add	ah, ch
  1670 00000AAE 730A                    	jnc	short _cs2
  1671 00000AB0 B4FF                    	mov	ah, 255
  1672 00000AB2 EB06                    	jmp	short _cs2
  1673                                  _cs1:
  1674 00000AB4 28EC                    	sub	ah, ch
  1675 00000AB6 7302                    	jnc	short _cs2
  1676 00000AB8 B400                    	mov	ah, 0
  1677                                  _cs2:
  1678 00000ABA C1CA10                  	ror	edx, 16 ; dx = [edi+2]
  1679 00000ABD 00F4                    	add	ah, dh
  1680 00000ABF 6692                    	xchg	dx, ax ; xchg [edi+2], ax
  1681 00000AC1 80FC80                  	cmp	ah, 80h
  1682 00000AC4 7208                    	jb	short _cs3	
  1683 00000AC6 00EC                    	add	ah, ch
  1684 00000AC8 730A                    	jnc	short _cs4
  1685 00000ACA B4FF                    	mov	ah, 255
  1686 00000ACC EB06                    	jmp	short _cs4
  1687                                  _cs3:
  1688 00000ACE 28EC                    	sub	ah, ch
  1689 00000AD0 7302                    	jnc	short _cs4
  1690 00000AD2 B400                    	mov	ah, 0
  1691                                  _cs4:
  1692 00000AD4 C1CA10                  	ror	edx, 16 ; dx = [edi]
  1693 00000AD7 00E6                    	add	dh, ah
  1694 00000AD9 8917                    	mov	[edi], edx
  1695                                  _cs5:
  1696                                  	; 20/10/2017
  1697 00000ADB 83C704                  	add	edi, 4
  1698 00000ADE 4B                      	dec	ebx
  1699 00000ADF 75C1                    	jnz	short c_smpl_1	
  1700                                  c_smpl_2:
  1701 00000AE1 61                      	popad	
  1702 00000AE2 C3                      	retn
  1703                                  
  1704                                  ;--------------------------------------------------------------------------
  1705                                  ; StartPlaying: Initializes the Sound System.
  1706                                  ;  In:
  1707                                  ;   Module Information Resources.
  1708                                  ;--------------------------------------------------------------------------
  1709                                  
  1710                                  StartPlaying:
  1711 00000AE3 60                      	pushad
  1712                                  SetModParms:    
  1713 00000AE4 C605[86D20000]00        	mov     byte [OrderPos], 0
  1714 00000AEB C605[87D20000]06        	mov     byte [Tempo], DefTempo
  1715 00000AF2 C605[88D20000]06        	mov     byte [TempoWait], DefTempo
  1716 00000AF9 C605[89D20000]7D        	mov     byte [Bpm], DefBpm
  1717 00000B00 C605[8AD20000]40        	mov     byte [Row], 64
  1718 00000B07 C605[8BD20000]00        	mov     byte [BreakRow], 0
  1719 00000B0E 66A1[66500000]          	mov     ax, [MixSpeed]
  1720 00000B14 31D2                    	xor     edx, edx
  1721 00000B16 66BB3200                	mov     bx, 24*DefBpm/60
  1722 00000B1A 66F7F3                  	div     bx
  1723 00000B1D 66A3[8CD20000]          	mov     [BpmSamples], ax
  1724                                  ClearTracks:    
  1725 00000B23 BF[9CD20000]            	mov     edi, Tracks
  1726                                  	; 07/10/2017
  1727                                  	;mov	ecx, NumTracks*TrackInfo.size
  1728 00000B28 B826000000              	mov	eax, TrackInfo.size
  1729 00000B2D 0FB70D[5D500000]        	movzx	ecx, word [numtracks]
  1730 00000B34 F7E1                    	mul	ecx
  1731 00000B36 89C1                    	mov	ecx, eax
  1732 00000B38 31C0                    	xor     eax, eax
  1733                                  	;cld
  1734 00000B3A F3AA                    	rep     stosb
  1735                                  
  1736 00000B3C A3[8ED20000]            	mov     [BufPtr], eax
  1737 00000B41 66A3[92D20000]          	mov     [BufLen], ax
  1738                                  MakePitch:
  1739 00000B47 66B80021                	mov     ax, MidCRate
  1740 00000B4B 66BBAC01                	mov     bx, 428
  1741 00000B4F 66F7E3                  	mul     bx
  1742 00000B52 66F735[66500000]        	div     word [MixSpeed]
  1743 00000B59 30F6                    	xor     dh, dh
  1744 00000B5B 88E2                    	mov     dl, ah
  1745 00000B5D 88C4                    	mov     ah, al
  1746 00000B5F 30C0                    	xor     al, al
  1747                                  	;mov	cx, 857
  1748 00000B61 66B9610D                	mov	cx, 3425  ; 01/10/2017 (TMODPLAY.ASM)
  1749 00000B65 31DB                    	xor     ebx, ebx
  1750 00000B67 BF[D8560000]            	mov     edi, PitchTable
  1751                                  PitchLoop:      
  1752 00000B6C 50                      	push    eax
  1753 00000B6D 52                      	push    edx
  1754 00000B6E 6639DA                  	cmp     dx, bx
  1755 00000B71 7303                    	jae     short NoDiv
  1756 00000B73 66F7F3                  	div     bx
  1757                                  NoDiv:          
  1758 00000B76 66AB                    	stosw
  1759 00000B78 5A                      	pop     edx
  1760 00000B79 58                      	pop     eax
  1761                                  	;inc	bx
  1762 00000B7A 43                      	inc	ebx
  1763 00000B7B E2EF                    	loop    PitchLoop
  1764                                  MakeVolume:     
  1765 00000B7D 66B90041                	mov     cx, 16640
  1766 00000B81 89CB                    	mov     ebx, ecx
  1767                                  VolLoop:
  1768 00000B83 664B                    	dec     bx
  1769 00000B85 88D8                    	mov     al, bl
  1770 00000B87 F6EF                    	imul    bh
  1771                                  	;mov	[VolTable+bx], ah
  1772 00000B89 88A3[9A710000]          	mov     [VolTable+ebx], ah
  1773 00000B8F E2F2                    	loop    VolLoop
  1774                                  
  1775 00000B91 61                      	popad
  1776 00000B92 C3                      	retn
  1777                                  
  1778                                  ;--------------------------------------------------------------------------
  1779                                  ; StopPlaying: ShutDown the Sound System.
  1780                                  ;--------------------------------------------------------------------------
  1781                                  
  1782                                  StopPlaying:
  1783                                  	; 19/06/2017
  1784                                  	; Stop Playing
  1785                                  	sys	_audio, 0700h
  1785                              <1> 
  1785                              <1> 
  1785                              <1> 
  1785                              <1> 
  1785                              <1>  %if %0 >= 2
  1785 00000B93 BB00070000          <1>  mov ebx, %2
  1785                              <1>  %if %0 >= 3
  1785                              <1>  mov ecx, %3
  1785                              <1>  %if %0 = 4
  1785                              <1>  mov edx, %4
  1785                              <1>  %endif
  1785                              <1>  %endif
  1785                              <1>  %endif
  1785 00000B98 B820000000          <1>  mov eax, %1
  1785                              <1> 
  1785 00000B9D CD40                <1>  int 40h
  1786                                  	; Cancel callback service (for user)
  1787                                  	sys	_audio, 0900h
  1787                              <1> 
  1787                              <1> 
  1787                              <1> 
  1787                              <1> 
  1787                              <1>  %if %0 >= 2
  1787 00000B9F BB00090000          <1>  mov ebx, %2
  1787                              <1>  %if %0 >= 3
  1787                              <1>  mov ecx, %3
  1787                              <1>  %if %0 = 4
  1787                              <1>  mov edx, %4
  1787                              <1>  %endif
  1787                              <1>  %endif
  1787                              <1>  %endif
  1787 00000BA4 B820000000          <1>  mov eax, %1
  1787                              <1> 
  1787 00000BA9 CD40                <1>  int 40h
  1788                                  	; Deallocate Audio Buffer (for user)
  1789                                  	sys	_audio, 0A00h
  1789                              <1> 
  1789                              <1> 
  1789                              <1> 
  1789                              <1> 
  1789                              <1>  %if %0 >= 2
  1789 00000BAB BB000A0000          <1>  mov ebx, %2
  1789                              <1>  %if %0 >= 3
  1789                              <1>  mov ecx, %3
  1789                              <1>  %if %0 = 4
  1789                              <1>  mov edx, %4
  1789                              <1>  %endif
  1789                              <1>  %endif
  1789                              <1>  %endif
  1789 00000BB0 B820000000          <1>  mov eax, %1
  1789                              <1> 
  1789 00000BB5 CD40                <1>  int 40h
  1790                                  	; Disable Audio Device
  1791                                  	sys	_audio, 0C00h
  1791                              <1> 
  1791                              <1> 
  1791                              <1> 
  1791                              <1> 
  1791                              <1>  %if %0 >= 2
  1791 00000BB7 BB000C0000          <1>  mov ebx, %2
  1791                              <1>  %if %0 >= 3
  1791                              <1>  mov ecx, %3
  1791                              <1>  %if %0 = 4
  1791                              <1>  mov edx, %4
  1791                              <1>  %endif
  1791                              <1>  %endif
  1791                              <1>  %endif
  1791 00000BBC B820000000          <1>  mov eax, %1
  1791                              <1> 
  1791 00000BC1 CD40                <1>  int 40h
  1792                                  
  1793 00000BC3 C3                      	retn
  1794                                  
  1795                                  
  1796                                  ;=============================================================================
  1797                                  ;	gfx.asm - draw scopes in VGA 640x480x16 mode      
  1798                                  ;=============================================================================
  1799                                  
  1800                                  ; EX1A.ASM (21/6/1994, Carlos Hasan; MSDOS, 'RUNME.EXE', 'TNYPL211')
  1801                                  
  1802                                  ;-----------------------------------------------------------------------------
  1803                                  ; setgraphmode - setup the VGA 640x480x16 graphics mode
  1804                                  ;-----------------------------------------------------------------------------
  1805                                  	; 22/10/2017
  1806                                  setgraphmode:
  1807                                  	;pushad
  1808 00000BC4 66B81200                	mov	ax,0012h
  1809                                  	;int	10h
  1810 00000BC8 CD31                    	int 	31h
  1811 00000BCA 66BAC003                	mov	dx,3C0h
  1812 00000BCE 30C0                    	xor	al,al
  1813                                  setgraphmodel0:
  1814                                  	;out	dx,al
  1815 00000BD0 B401                    	mov	ah, 1 ; outb
  1816 00000BD2 CD34                    	int	34h
  1817                                  	;out	dx, al
  1818                                  	;mov	ah, 1
  1819 00000BD4 CD34                    	int	34h
  1820 00000BD6 FEC0                    	inc	al
  1821 00000BD8 3C10                    	cmp	al, 10h
  1822 00000BDA 72F4                    	jb	short setgraphmodel0
  1823 00000BDC B020                    	mov	al, 20h
  1824                                  	;out	dx, al
  1825                                  	;mov	ah, 1
  1826 00000BDE CD34                    	int	34h
  1827                                  	;popad
  1828 00000BE0 C3                      	retn
  1829                                  
  1830                                  ;-----------------------------------------------------------------------------
  1831                                  ; settextmode - restore the VGA 80x25x16 text mode
  1832                                  ;-----------------------------------------------------------------------------
  1833                                  	; 22/10/2017
  1834                                  settextmode:
  1835                                  	;pushad
  1836 00000BE1 66B80300                	mov	ax, 0003h
  1837                                  	;int	10h
  1838 00000BE5 CD31                    	int	31h
  1839                                  	;popad
  1840 00000BE7 C3                      	retn
  1841                                  
  1842                                  ;-----------------------------------------------------------------------------
  1843                                  ; drawscopes - draw the track voices sample scopes
  1844                                  ; In:
  1845                                  ;  EDX = (current) sample buffer
  1846                                  ;-----------------------------------------------------------------------------
  1847                                  	; 28/10/2017
  1848                                  	; (ESI = Current DMA buffer offset)
  1849                                  	; 27/10/2017
  1850                                  	; 26/10/2017
  1851                                  	; 23/10/2017
  1852                                  drawscopes:
  1853                                  	;pushad
  1854                                    	;mov	esi, g_buff
  1855                                  	;mov	esi, edx
  1856 00000BE8 31C9                    	xor     ecx, ecx	
  1857 00000BEA 31D2                    	xor     edx, edx
  1858 00000BEC 31FF                    	xor	edi, edi
  1859                                  drawscope0:
  1860 00000BEE 66AD                    	lodsw
  1861 00000BF0 80F480                  	xor	ah, 80h
  1862 00000BF3 0FB6DC                  	movzx	ebx, ah  ; Left Channel
  1863 00000BF6 66D1E3                  	shl	bx, 1
  1864 00000BF9 668B83[D0D30000]        	mov	ax, [RowOfs+ebx]
  1865 00000C00 668987[D0D50000]        	mov	[NewScope_L+edi], ax
  1866 00000C07 30FF                    	xor	bh, bh
  1867 00000C09 66AD                    	lodsw
  1868 00000C0B 80F480                  	xor	ah, 80h
  1869 00000C0E 88E3                    	mov	bl, ah	; Right Channel
  1870 00000C10 66D1E3                  	shl	bx, 1
  1871 00000C13 668B83[D0D30000]        	mov	ax, [RowOfs+ebx]
  1872 00000C1A 668987[D0D70000]        	mov	[NewScope_R+edi], ax
  1873 00000C21 6683C702                	add	di, 2
  1874 00000C25 FEC1                    	inc	cl
  1875 00000C27 75C5                    	jnz	short drawscope0	
  1876                                  
  1877 00000C29 66BAC403                        mov	dx, 3C4h
  1878                                          ;mov	ax, 0802h
  1879                                          ;out	dx, ax
  1880 00000C2D 66BB0208                        mov	bx, 0802h
  1881 00000C31 B403                    	mov	ah, 3 ; outw
  1882 00000C33 CD34                    	int	34h
  1883 00000C35 66BACE03                	mov	dx, 3CEh
  1884 00000C39 B008                            mov	al, 08h
  1885                                         ;out	dx, al
  1886 00000C3B B401                            mov	ah, 1 ; outb
  1887 00000C3D CD34                    	int	34h
  1888 00000C3F 6642                    	inc	dx
  1889                                  
  1890                                  	; 26/10/2017
  1891 00000C41 31F6                            xor	esi, esi
  1892 00000C43 31FF                            xor	edi, edi
  1893 00000C45 BB45060A00                      mov     ebx, 0A0645h
  1894                                  drawscopel4:
  1895 00000C4A B080                            mov     al, 80h
  1896                                  drawscopel2:
  1897 00000C4C 50                              push    eax ; *
  1898 00000C4D 52                              push    edx ; **
  1899                                  	;out	dx, al
  1900 00000C4E B401                    	mov	ah, 1 ; outb
  1901 00000C50 CD34                    	int	34h
  1902                                  
  1903 00000C52 B4FF                            mov	ah, 0FFh
  1904                                          ;mov	ecx, 32
  1905 00000C54 66B92000                	mov	cx, 32
  1906 00000C58 28C0                            sub     al, al
  1907                                  drawscopel3:
  1908                                  	; 23/10/2017
  1909 00000C5A 668B96[D0D90000]                mov	dx, [OldScope_L+esi]
  1910 00000C61 663B96[D0D50000]                cmp	dx, [NewScope_L+esi]
  1911 00000C68 7414                            je	short drawscopef3
  1912 00000C6A 88041A                          mov	[edx+ebx], al ; L
  1913 00000C6D 668B96[D0D50000]                mov     dx, [NewScope_L+esi]
  1914 00000C74 88241A                  	mov	[edx+ebx], ah ; L
  1915 00000C77 668996[D0D90000]                mov     [OldScope_L+esi], dx
  1916                                  drawscopef3:
  1917                                  	; 27/10/2017
  1918 00000C7E 668B96[D0DB0000]                mov	dx, [OldScope_R+esi]
  1919 00000C85 663B96[D0D70000]                cmp	dx, [NewScope_R+esi]
  1920 00000C8C 7416                            je	short drawscopef4
  1921 00000C8E 88441A26                	mov	[edx+ebx+38], al ; R
  1922 00000C92 668B96[D0D70000]                mov     dx, [NewScope_R+esi]
  1923 00000C99 88641A26                        mov	[edx+ebx+38], ah ; R
  1924 00000C9D 668996[D0DB0000]                mov     [OldScope_R+esi], dx
  1925                                  drawscopef4:
  1926 00000CA4 83C610                          add	esi, 2*8
  1927 00000CA7 43                              inc	ebx
  1928 00000CA8 E2B0                            loop    drawscopel3
  1929                                  
  1930 00000CAA 5A                              pop     edx ; **
  1931 00000CAB 58                              pop     eax ; *
  1932 00000CAC 81EEFE010000                    sub	esi, 2*256-2
  1933 00000CB2 83EB20                          sub	ebx, 32
  1934 00000CB5 D0E8                            shr     al, 1
  1935 00000CB7 7593                            jnz	short drawscopel2
  1936                                  	;popad
  1937 00000CB9 C3                              retn
  1938                                  
  1939                                  ;=============================================================================
  1940                                  ;	Load IFF/ILBM files for VGA 640x480x16 graphics mode       
  1941                                  ;=============================================================================
  1942                                  
  1943                                  ; EX1B.ASM (21/6/1994, Carlos Hasan; MSDOS, 'RUNME.EXE', 'TNYPL211')
  1944                                  
  1945                                  ; 21/10/2017 (TRDOS 386, 'tmodplay.s', Erdogan Tan, NASM syntax)
  1946                                  
  1947                                  ;-----------------------------------------------------------------------------
  1948                                  ; EQUATES AND STRUCTURES
  1949                                  ;-----------------------------------------------------------------------------
  1950                                  
  1951                                  ID_FORM equ 4D524F46h		; IFF/ILBM chunk IDs
  1952                                  ID_ILBM equ 4D424C49h
  1953                                  ID_BMHD equ 44484D42h
  1954                                  ID_CMAP equ 50414D43h
  1955                                  ID_BODY equ 59444F42h
  1956                                  
  1957                                  struc Form			; IFF/ILBM header file format
  1958 00000000 <res 00000004>            .ID:		resd 1
  1959 00000004 <res 00000004>            .Length:	resd 1
  1960 00000008 <res 00000004>            .Type:	resd 1
  1961                                    .size:
  1962                                  endstruc
  1963                                  
  1964                                  struc Chunk			; IFF/ILBM header chunk format
  1965 00000000 <res 00000004>            .ID:		resd 1
  1966 00000004 <res 00000004>            .Length:	resd 1
  1967                                    .size:	
  1968                                  endstruc
  1969                                  
  1970                                  struc BMHD			; IFF/ILBM BMHD chunk format
  1971 00000000 <res 00000002>            .Width: 	resw 1
  1972 00000002 <res 00000002>            .Height:	resw 1
  1973 00000004 <res 00000002>            .PosX:	resw 1
  1974 00000006 <res 00000002>            .PosY:	resw 1
  1975 00000008 <res 00000001>            .Planes:	resb 1
  1976 00000009 <res 00000001>            .Masking:	resb 1
  1977 0000000A <res 00000001>            .Compression:	resb 1
  1978 0000000B <res 00000001>            .Pad:		resb 1
  1979 0000000C <res 00000002>            .Transparent:	resw 1
  1980 0000000E <res 00000001>            .AspectX	resb 1
  1981 0000000F <res 00000001>            .AspectY:	resb 1
  1982 00000010 <res 00000002>            .PageWidth:	resw 1
  1983 00000012 <res 00000002>            .PageHeight:	resw 1
  1984                                    .size:	
  1985                                  endstruc
  1986                                  
  1987                                  struc CMAP			; IFF/ILBM CMAP chunk format
  1988 00000000 <res 00000300>            .Colors:	resb 768
  1989                                    .size:	
  1990                                  endstruc
  1991                                  
  1992                                  ;LOGO_ADDRESS	equ 100000h	; virtual address at the end of the 1st 1MB
  1993                                  
  1994                                  ;------------------------------------------------------------------------------
  1995                                  ; bswap - macro to reverse the byte order of a 32-bit register, converting
  1996                                  ;         a value in little/big endian form to big/little endian form.
  1997                                  ;------------------------------------------------------------------------------
  1998                                  %macro	bswap   1
  1999                                          xchg    al, ah
  2000                                          rol     eax, 16
  2001                                          xchg    al, ah
  2002                                  %endmacro
  2003                                  
  2004                                  ;------------------------------------------------------------------------------
  2005                                  ; putlbm - draw the IFF/ILBM picture on VGA 640x480x16 graphics mode
  2006                                  ; In:
  2007                                  ;  ESI = IFF/ILBM image file address
  2008                                  ;------------------------------------------------------------------------------
  2009                                  putlbm:
  2010 00000CBA 60                              pushad
  2011                                  
  2012                                  ; check if this is a valid IFF/ILBM Deluxe Paint file
  2013                                  
  2014 00000CBB 813E464F524D                    cmp     dword [esi+Form.ID], ID_FORM
  2015 00000CC1 7551                            jne     short putlbmd0
  2016 00000CC3 817E08494C424D                  cmp     dword [esi+Form.Type], ID_ILBM
  2017 00000CCA 7548                            jne     short putlbmd0
  2018                                  
  2019                                  ; get the IFF/ILBM file length in bytes
  2020                                  
  2021 00000CCC 8B4604                          mov     eax, [esi+Form.Length]
  2022                                          bswap   eax
  2022 00000CCF 86C4                <1>  xchg al, ah
  2022 00000CD1 C1C010              <1>  rol eax, 16
  2022 00000CD4 86C4                <1>  xchg al, ah
  2023 00000CD6 89C1                            mov     ecx, eax
  2024                                  
  2025                                  ; decrease the file length and updates the file pointer
  2026                                  
  2027 00000CD8 83E904                          sub     ecx, 4
  2028 00000CDB 83C60C                          add     esi, Form.size
  2029                                  
  2030                                  ; IFF/ILBM main parser body loop
  2031                                  
  2032                                  putlbml0:
  2033 00000CDE 85C9                            test    ecx, ecx
  2034 00000CE0 7E64                            jle     short putlbmd1
  2035                                  
  2036                                  ; get the next chunk ID and length in bytes
  2037                                  
  2038 00000CE2 8B1E                            mov     ebx, [esi+Chunk.ID]
  2039 00000CE4 8B4604                          mov     eax, [esi+Chunk.Length]
  2040                                          bswap   eax
  2040 00000CE7 86C4                <1>  xchg al, ah
  2040 00000CE9 C1C010              <1>  rol eax, 16
  2040 00000CEC 86C4                <1>  xchg al, ah
  2041 00000CEE 93                              xchg    ebx, eax
  2042 00000CEF 83C608                          add     esi, Chunk.size
  2043                                  
  2044                                  ; word align the chunk length and decrease the file length counter
  2045                                  
  2046 00000CF2 43                              inc     ebx
  2047 00000CF3 80E3FE                          and     bl, 0FEh ; ~1
  2048 00000CF6 83E908                          sub     ecx, Chunk.size
  2049 00000CF9 29D9                            sub     ecx, ebx
  2050                                  
  2051                                  ; check for the BMHD/CMAP/BODY chunk headers
  2052                                  
  2053 00000CFB 3D424D4844                      cmp     eax, ID_BMHD
  2054 00000D00 7415                            je      short putlbmf0
  2055 00000D02 3D434D4150                      cmp     eax, ID_CMAP
  2056 00000D07 7440                            je      short putlbmf1
  2057 00000D09 3D424F4459                      cmp     eax, ID_BODY
  2058 00000D0E 7455                            je      short putlbmf2
  2059                                  
  2060                                  ; advance to the next IFF/ILBM chunk structure
  2061                                  
  2062                                  putlbmc0:
  2063 00000D10 01DE                            add     esi, ebx
  2064 00000D12 EBCA                            jmp     short putlbml0
  2065                                  
  2066                                  putlbmd0:
  2067 00000D14 F9                              stc
  2068 00000D15 61                              popad
  2069 00000D16 C3                              retn
  2070                                  
  2071                                  ; process the BMHD bitmap header chunk
  2072                                  
  2073                                  putlbmf0:
  2074 00000D17 807E0804                        cmp     byte [esi+BMHD.Planes], 4
  2075 00000D1B 75F7                            jne     short putlbmd0
  2076 00000D1D 807E0A01                        cmp     byte [esi+BMHD.Compression], 1
  2077 00000D21 75F1                            jne     short putlbmd0
  2078 00000D23 807E0B00                        cmp     byte [esi+BMHD.Pad], 0
  2079 00000D27 75EB                            jne     short putlbmd0
  2080 00000D29 0FB706                          movzx   eax, word [esi+BMHD.Width]
  2081 00000D2C 86C4                            xchg    al, ah
  2082 00000D2E 83C007                          add     eax, 7
  2083 00000D31 C1E803                          shr     eax, 3
  2084 00000D34 A3[84500000]                    mov     [picture.width], eax
  2085 00000D39 0FB74602                        movzx   eax, word [esi+BMHD.Height]
  2086 00000D3D 86C4                            xchg    al, ah
  2087 00000D3F A3[88500000]                    mov     [picture.height], eax
  2088 00000D44 EBCA                            jmp     short putlbmc0
  2089                                  
  2090                                  putlbmd1:
  2091 00000D46 F8                              clc
  2092 00000D47 61                              popad
  2093 00000D48 C3                              retn
  2094                                  
  2095                                  ; process the CMAP colormap chunk
  2096                                  
  2097                                  putlbmf1:
  2098 00000D49 66BAC803                        mov     dx, 3C8h
  2099 00000D4D 30C0                            xor     al, al
  2100                                          ;out	dx, al
  2101 00000D4F B401                    	mov	ah, 1 ; outb
  2102 00000D51 CD34                    	int	34h
  2103 00000D53 6642                            inc     dx
  2104                                  putlbml1:
  2105 00000D55 8A06                            mov     al, [esi]
  2106 00000D57 C0E802                          shr     al, 2
  2107                                          ;out	dx, al
  2108                                  	;mov	ah, 1 ; outb
  2109 00000D5A CD34                    	int	34h ; IOCTL interrupt (IN/OUT)
  2110 00000D5C 46                              inc     esi
  2111 00000D5D 4B                              dec     ebx
  2112 00000D5E 7FF5                            jg      short putlbml1
  2113 00000D60 E979FFFFFF                      jmp     putlbml0
  2114                                  
  2115                                  ; process the BODY bitmap body chunk
  2116                                  
  2117                                  putlbmf2:
  2118 00000D65 60                              pushad
  2119 00000D66 BF00000A00                      mov     edi, 0A0000h
  2120                                          ;cld
  2121 00000D6B 66BACE03                        mov     dx, 3CEh
  2122                                          ;mov	ax, 0FF08h
  2123                                          ;out	dx, ax
  2124 00000D6F 66BB08FF                	mov	bx, 0FF08h
  2125 00000D73 B403                    	mov	ah, 3 ; outw
  2126 00000D75 CD34                    	int	34h ; IOCTL interrupt (IN/OUT)
  2127 00000D77 66BAC403                        mov     dx, 3C4h
  2128 00000D7B B002                            mov     al, 02h
  2129                                          ;out	dx, al
  2130 00000D7D B401                    	mov	ah, 1 ; outb
  2131 00000D7F CD34                    	int	34h ; IOCTL interrupt (IN/OUT)
  2132 00000D81 6642                            inc     dx
  2133 00000D83 8B0D[88500000]                  mov     ecx, [picture.height]
  2134                                  putlbml2:
  2135 00000D89 51                              push    ecx
  2136 00000D8A B011                            mov     al, 11h
  2137                                  putlbml3:
  2138 00000D8C 50                              push    eax
  2139 00000D8D 57                              push    edi
  2140                                          ;out	dx, al
  2141 00000D8E B401                    	mov	ah, 1 ; outb
  2142 00000D90 CD34                    	int	34h ; IOCTL interrupt (IN/OUT)
  2143 00000D92 8B1D[84500000]                  mov     ebx, [picture.width]
  2144                                  putlbml4:
  2145 00000D98 AC                              lodsb
  2146 00000D99 84C0                            test    al, al
  2147 00000D9B 7C0A                            jl      short putlbmf3
  2148 00000D9D 0FB6C8                          movzx   ecx, al
  2149 00000DA0 41                              inc     ecx
  2150 00000DA1 29CB                            sub     ebx, ecx
  2151 00000DA3 F3A4                            rep     movsb
  2152 00000DA5 EB0B                            jmp     short putlbmc4
  2153                                  putlbmf3:
  2154 00000DA7 F6D8                            neg     al
  2155 00000DA9 0FB6C8                          movzx   ecx, al
  2156 00000DAC 41                              inc     ecx
  2157 00000DAD 29CB                            sub     ebx, ecx
  2158 00000DAF AC                              lodsb
  2159 00000DB0 F3AA                            rep     stosb
  2160                                  putlbmc4:
  2161 00000DB2 85DB                            test    ebx, ebx
  2162 00000DB4 7FE2                            jg      short putlbml4
  2163 00000DB6 5F                              pop     edi
  2164 00000DB7 58                              pop     eax
  2165 00000DB8 00C0                            add     al, al
  2166 00000DBA 73D0                            jnc     short putlbml3
  2167 00000DBC 83C750                          add     edi, 80
  2168 00000DBF 59                              pop     ecx
  2169 00000DC0 E2C7                            loop    putlbml2
  2170 00000DC2 61                      	popad
  2171 00000DC3 E948FFFFFF                      jmp	putlbmc0
  2172                                  
  2173                                  ; EX1.C (Carlos Hasan, 21/06/1994)
  2174                                  ;------------------------------------------------------------------------------
  2175                                  ; loadlbm - load the IFF/ILBM image file ("LOGO.LBM") at memory
  2176                                  ;  ESI = IFF/ILBM image file address
  2177                                  ;------------------------------------------------------------------------------
  2178                                  
  2179                                  ;if ((Logo = loadlbm("LOGO.LBM")) == NULL) {
  2180                                  ;       printf("Error loading the IFF/ILBM logo picture\n");
  2181                                  ;       MODStopModule();
  2182                                  ;       MODFreeModule(Song);
  2183                                  ;       return;
  2184                                  ;   }
  2185                                  ;   setgraphmode();
  2186                                  ;   putlbm(Logo);
  2187                                  ;   while (!kbhit())
  2188                                  ;       drawscopes(Song->NumTracks);
  2189                                  ;   settextmode();
  2190                                  ;   free(Logo);
  2191                                  ;   MODStopModule();
  2192                                  ;   MODFreeModule(Song);
  2193                                  
  2194                                  ;loadlbm:
  2195                                  ;	; ebx = ASCIIZ file name address
  2196                                  ;	; ecx = open mode (0 = open for read)	
  2197                                  ;	sys	_open, LOGO_FILE_NAME, 0 ; open for reading
  2198                                  ;	jc	short loadlbm_retn
  2199                                  ;
  2200                                  ;	mov     [LBM_FileHandle], eax
  2201                                  ;
  2202                                  ;	; get file size by moving file pointer to the end of file
  2203                                  ;	; ebx = file handle/number
  2204                                  ;	; ecx : offset = 0
  2205                                  ;	; edx : switch = 2 (move fp to end of file + offset)
  2206                                  ;	sys	_seek, eax, 0, 2
  2207                                  ;	jc	short loadlbm_cf
  2208                                  ;
  2209                                  ;	mov	[LBM_FileSize], eax
  2210                                  ;
  2211                                  ;	; move file pointer to the beginning of the file
  2212                                  ;	; ecx = 0
  2213                                  ;	; edx = 0
  2214                                  ;	;xor	ecx, ecx
  2215                                  ; 	xor	dl, dl
  2216                                  ;	; ebx = [LBM_FileHandle]
  2217                                  ;	sys	_seek
  2218                                  ;	;jc	short loadlbm_cf
  2219                                  ;
  2220                                  ;	; ebx = File handle
  2221                                  ;	; ecx = Buffer address
  2222                                  ;	; edx = Byte count
  2223                                  ;	;sys	_read, [LBM_FileHandle], LOGO_ADDRESS, [LBM_FileSize]
  2224                                  ;	mov	ecx, LOGO_ADDRESS
  2225                                  ;	mov	edx, [LBM_FileSize]
  2226                                  ;	sys	_read
  2227                                  ;	jc	short loadlbm_cf
  2228                                  ;
  2229                                  ;	cmp	eax, edx  ; read count = file size ?
  2230                                  ;	;jb	short loadlbm_cf		 
  2231                                  ;loadlbm_cf:
  2232                                  ;	pushf
  2233                                  ;	sys	_close, [LBM_FileHandle]	
  2234                                  ;	popf
  2235                                  ;loadlbm_retn:
  2236                                  ;	retn	
  2237                                  ;
  2238                                  ;LOGO_FILE_NAME:
  2239                                  ;	db	"LOGO.LBM", 0
  2240                                  
  2241                                  LOGO_ERROR_MSG:
  2242 00000DC8 4572726F72206C6F61-     	db	"Error loading the IFF/ILBM logo picture !", 0Dh, 0Ah, 0 
  2242 00000DD1 64696E672074686520-
  2242 00000DDA 4946462F494C424D20-
  2242 00000DE3 6C6F676F2070696374-
  2242 00000DEC 75726520210D0A00   
  2243                                  
  2244                                  align 2
  2245                                  ; 22/10/2017
  2246                                  LOGO_ADDRESS:
  2247                                  ;incbin "LOGO.LBM"	  	 
  2248                                  ; 27/10/2017
  2249 00000DF4 <incbin>                incbin "TINYPLAY.LBM"
  2250                                  
  2251                                  ;=============================================================================
  2252                                  ;               preinitialized data
  2253                                  ;=============================================================================
  2254                                  
  2255                                  ;=============================================================================
  2256                                  ; Protracker effects stuff
  2257                                  ;=============================================================================
  2258                                  
  2259                                  ;-----------------------------------------------------------------------------
  2260                                  ; Effect jump tables
  2261                                  ;-----------------------------------------------------------------------------
  2262                                  
  2263                                  align 4
  2264                                  
  2265                                  efxtable:
  2266 00004DE4 [7C070000]              	dd      efxarpeggio	; 0 - arpeggio
  2267 00004DE8 [A9040000]              	dd      efxnull		; 1 - porta up
  2268 00004DEC [A9040000]              	dd      efxnull		; 2 - porta down
  2269 00004DF0 [C7060000]              	dd      efxtoneporta	; 3 - tone porta
  2270 00004DF4 [D6060000]              	dd      efxvibrato	; 4 - vibrato
  2271 00004DF8 [A9040000]              	dd      efxnull		; 5 - tone+slide
  2272 00004DFC [A9040000]              	dd      efxnull		; 6 - vibrato+slide
  2273 00004E00 [F3070000]              	dd      efxtremolo	; 7 - tremolo
  2274 00004E04 [A9040000]              	dd      efxnull		; 8 - unused
  2275 00004E08 [FE060000]              	dd      efxsampoffset	; 9 - sample offset
  2276 00004E0C [A9040000]              	dd      efxnull		; A - volume slide
  2277 00004E10 [0A070000]              	dd      efxpattjump	; B - pattern jump
  2278 00004E14 [18070000]              	dd      efxsetvolume	; C - set volume
  2279 00004E18 [26070000]              	dd      efxbreak	; D - break pattern
  2280 00004E1C [A9040000]              	dd      efxnull		; E - extra effects
  2281 00004E20 [45070000]              	dd      efxsetspeed	; F - set speed
  2282                                  
  2283                                  efxtable2:
  2284 00004E24 [AA040000]              	dd      efxarpeggio2	; 0 - arpeggio
  2285 00004E28 [CC040000]              	dd      efxportaup	; 1 - porta up
  2286 00004E2C [F2040000]              	dd      efxportadown	; 2 - porta down
  2287 00004E30 [19050000]              	dd      efxtoneporta2	; 3 - tone porta
  2288 00004E34 [52050000]              	dd      efxvibrato2	; 4 - vibrato
  2289 00004E38 [AE050000]              	dd      efxtoneslide	; 5 - tone+slide
  2290 00004E3C [BB050000]              	dd      efxvibslide	; 6 - vibrato+slide
  2291 00004E40 [E2050000]              	dd      efxtremolo2	; 7 - tremolo
  2292 00004E44 [A9040000]              	dd      efxnull		; 8 - unused
  2293 00004E48 [A9040000]              	dd      efxnull		; 9 - sample offset
  2294 00004E4C [C5050000]              	dd      efxvolslide	; A - volume slide
  2295 00004E50 [A9040000]              	dd      efxnull		; B - pattern jump
  2296 00004E54 [A9040000]              	dd      efxnull		; C - set volume
  2297 00004E58 [A9040000]              	dd      efxnull		; D - break pattern
  2298 00004E5C [A9040000]              	dd      efxnull		; E - extra effects
  2299 00004E60 [A9040000]              	dd      efxnull		; F - set speed
  2300                                  
  2301                                  ;-----------------------------------------------------------------------------
  2302                                  ; Amiga period table
  2303                                  ;-----------------------------------------------------------------------------
  2304                                  
  2305                                  ;PeriodTable0:	
  2306                                  ;	dw	0
  2307                                  PeriodTable:
  2308 00004E64 600DA00CE80B400B98-     	dw	3424,3232,3048,2880,2712,2560,2416,2280,2152,2032,1920,1812
  2308 00004E6D 0A000A7009E8086808-
  2308 00004E76 F00780071407       
  2309 00004E7C B0065006F405A0054C-     	dw	1712,1616,1524,1440,1356,1280,1208,1140,1076,1016,960,906
  2309 00004E85 050005B80474043404-
  2309 00004E8E F803C0038A03       
  2310 00004E94 58032803FA02D002A6-     	dw	856,808,762,720,678,640,604,570,538,508,480,453
  2310 00004E9D 0280025C023A021A02-
  2310 00004EA6 FC01E001C501       
  2311 00004EAC AC0194017D01680153-     	dw	428,404,381,360,339,320,302,285,269,254,240,226
  2311 00004EB5 0140012E011D010D01-
  2311 00004EBE FE00F000E200       
  2312 00004EC4 D600CA00BE00B400AA-     	dw	214,202,190,180,170,160,151,143,135,127,120,113
  2312 00004ECD 00A00097008F008700-
  2312 00004ED6 7F0078007100       
  2313 00004EDC 6B0065005F005A0055-     	dw	107,101,95,90,85,80,75,71,67,63,60,56
  2313 00004EE5 0050004B0047004300-
  2313 00004EEE 3F003C003800       
  2314 00004EF4 350032002F002D002A-     	dw	53,50,47,45,42,40,37,35,33,31,30,28
  2314 00004EFD 002800250023002100-
  2314 00004F06 1F001E001C00       
  2315                                  
  2316                                  ;-----------------------------------------------------------------------------
  2317                                  ; Sinus wave table
  2318                                  ;-----------------------------------------------------------------------------
  2319                                  
  2320                                  SinTable:
  2321 00004F0C 0019324A62788EA2B4-     	db	0,25,50,74,98,120,142,162,180,197,212,225
  2321 00004F15 C5D4E1             
  2322 00004F18 ECF4FAFEFFFEFAF4EC-     	db	236,244,250,254,255,254,250,244,236,225
  2322 00004F21 E1                 
  2323 00004F22 D4C5B4A28E78624A32-     	db	212,197,180,162,142,120,98,74,50,25
  2323 00004F2B 19                 
  2324                                  
  2325                                  ;=============================================================================
  2326                                  ;               PLAY.ASM - DATA
  2327                                  ;=============================================================================
  2328                                  
  2329                                  msg_usage:
  2330 00004F2C 54696E79204D4F4420-     		db 'Tiny MOD Player for TRDOS 386 by Erdogan Tan. '
  2330 00004F35 506C6179657220666F-
  2330 00004F3E 72205452444F532033-
  2330 00004F47 383620627920457264-
  2330 00004F50 6F67616E2054616E2E-
  2330 00004F59 20                 
  2331 00004F5A 4F63746F6265722032-     		db 'October 2017.',10,13
  2331 00004F63 3031372E0A0D       
  2332 00004F69 75736167653A20746D-     		db 'usage: tmodplay filename.mod', 10,13,0
  2332 00004F72 6F64706C6179206669-
  2332 00004F7B 6C656E616D652E6D6F-
  2332 00004F84 640A0D00           
  2333 00004F88 32382F31302F323031-     		db '28/10/2017',10,13,0
  2333 00004F91 370A0D00           
  2334                                  
  2335 00004F95 54696E79204D4F4420-     Credits:	db 'Tiny MOD Player v0.1b by Carlos Hasan. July 1993.'
  2335 00004F9E 506C61796572207630-
  2335 00004FA7 2E3162206279204361-
  2335 00004FB0 726C6F732048617361-
  2335 00004FB9 6E2E204A756C792031-
  2335 00004FC2 3939332E           
  2336 00004FC6 0A0D00                  		db 10,13,0
  2337 00004FC9 4572726F72206C6F61-     ErrorMesg:	db 'Error loading Module file.',10,13,0
  2337 00004FD2 64696E67204D6F6475-
  2337 00004FDB 6C652066696C652E0A-
  2337 00004FE4 0D00               
  2338 00004FE6 536F756E6420426C61-     MsgNotFound:	db 'Sound Blaster not found or IRQ error.',10,13,0
  2338 00004FEF 73746572206E6F7420-
  2338 00004FF8 666F756E64206F7220-
  2338 00005001 495251206572726F72-
  2338 0000500A 2E0A0D00           
  2339 0000500E 536F756E6420426C61-     MsgFound:	db 'Sound Blaster found at Address 2'
  2339 00005017 7374657220666F756E-
  2339 00005020 642061742041646472-
  2339 00005029 6573732032         
  2340 0000502E 7830682C2049525120      PortText:	db 'x0h, IRQ '
  2341 00005037 782E0A0D00              IrqText:	db 'x.',10,13,0
  2342                                  
  2343                                  trdos386_err_msg:
  2344 0000503C 5452444F5320333836-     		db 'TRDOS 386 System call error !', 10, 13,0
  2344 00005045 2053797374656D2063-
  2344 0000504E 616C6C206572726F72-
  2344 00005057 20210A0D00         
  2345                                  
  2346                                  ; 07/10/2017
  2347 0000505C 0A                      pattern_shift:	db 10
  2348                                  ;numtracks:	dw 4
  2349                                  ; 18/10/2017
  2350 0000505D 04000000                numtracks:	dd 4
  2351                                  
  2352                                  ;=============================================================================
  2353                                  ;               SB.ASM - DATA
  2354                                  ;=============================================================================
  2355                                  
  2356 00005061 2002                    SbAddr:		dw 220h
  2357 00005063 07                      SbIrq:		db 7
  2358                                  
  2359                                  ;=============================================================================
  2360                                  ;               PLAYER.ASM - DATA
  2361                                  ;=============================================================================
  2362                                  
  2363                                  ;stmo:		db 1 ; stereo (2) or mono (1)  
  2364                                  ;bps:		db 8 ; bits per sample (8 or 16)
  2365                                  
  2366                                  ;19/10/2017
  2367 00005064 02                      stmo:		db 2 ; stereo (2) or mono (1)  
  2368 00005065 10                      bps:		db 16 ; bits per sample (8 or 16)
  2369                                  
  2370                                  Sample_Rate:
  2371 00005066 2256                    MixSpeed:	dw 22050 ; Hz ; 19/10/2017
  2372                                  ;MixSpeed:	dw 22222 ; Hz ; 07/10/2017
  2373                                  
  2374                                  ; 13/11/2016
  2375 00005068 303132333435363738-     hex_chars:	db "0123456789ABCDEF", 0
  2375 00005071 3941424344454600   
  2376                                  ;
  2377                                  ;; 13/11/2016 - Erdogan Tan (Ref: KolibriOS, codec.inc)
  2378                                  ;codec_id:	   dd 0
  2379                                  ;codec_chip_id:	   dd 0
  2380                                  ;codec_vendor_ids: dw 0
  2381                                  ;codec_chip_ids:   dw 0
  2382                                  
  2383                                  ;dword_str:	dd 30303030h, 30303030h
  2384                                  ;	 	db 'h', 0Dh, 0Ah, 0
  2385                                  
  2386                                  ;=============================================================================
  2387                                  ;        	uninitialized data
  2388                                  ;=============================================================================
  2389                                  
  2390                                  bss_start:
  2391                                  
  2392                                  ABSOLUTE bss_start
  2393                                  
  2394 00005079 <res 00000003>          alignb 4
  2395                                  
  2396                                  ;------------------------------------------------------------------------------
  2397                                  ; IFF/ILBM DATA
  2398                                  ;------------------------------------------------------------------------------
  2399                                  
  2400 0000507C <res 00000004>          LBM_FileHandle:	resd 1
  2401 00005080 <res 00000004>          LBM_FileSize:	resd 1
  2402                                  ;
  2403 00005084 <res 00000004>          picture.width:	resd 1 		; current picture width and height
  2404 00005088 <res 00000004>          picture.height:	resd 1
  2405                                  
  2406                                  ;------------------------------------------------------------------------------
  2407                                  
  2408 0000508C <res 00000004>          dev_vendor:	resd 1
  2409 00005090 <res 00000004>          bus_dev_fn:	resd 1
  2410 00005094 <res 00000004>          stats_cmd:	resd 1
  2411 00005098 <res 00000002>          ac97_NamBar:	resw 1
  2412 0000509A <res 00000002>          ac97_NabmBar:	resw 1
  2413 0000509C <res 00000001>          ac97_int_ln_reg: resb 1
  2414 0000509D <res 00000001>          srb:		resb 1
  2415                                  
  2416                                  ; MODLOAD.ASM
  2417 0000509E <res 00000004>          FileHandle:	resd 1
  2418 000050A2 <res 0000043C>          Header:		resb ModHeader.size
  2419                                  
  2420                                  ; MODPLAY.ASM
  2421                                  ;MixSpeed:	    resw 1
  2422                                  
  2423                                  ModInfo:
  2424 000054DE <res 00000001>          ModInfo.OrderLen:   resb 1
  2425 000054DF <res 00000001>          ModInfo.ReStart:    resb 1
  2426 000054E0 <res 00000080>          ModInfo.Order:	    resb 128
  2427 00005560 <res 00000004>          ModInfo.Patterns:   resd 1
  2428                                  
  2429 00005564 <res 0000003E>          ModInfo.SampOfs:    resw 31
  2430 000055A2 <res 0000003E>          ModInfo.SampSeg:    resw 31
  2431 000055E0 <res 0000003E>          ModInfo.SampLen:    resw 31
  2432 0000561E <res 0000003E>          ModInfo.SampRep:    resw 31
  2433 0000565C <res 0000003E>          ModInfo.SampRepLen: resw 31
  2434 0000569A <res 0000003E>          ModInfo.SampVol:    resw 31
  2435                                  
  2436                                  ; MODPLAY.ASM
  2437                                  PitchTable:	;resw 857
  2438 000056D8 <res 00001AC2>          		resw 3425 ; 01/10/2017 (TMODPLAY.ASM)
  2439 0000719A <res 00004100>          VolTable:	resb 16640
  2440 0000B29A <res 00001FEC>          MixBuffer       resb 8172 ; MixBufSize ; 7680 (960*8) ; 18/10/2017
  2441                                  
  2442                                  ; MODPLAY.ASM
  2443 0000D286 <res 00000001>          OrderPos:	resb 1
  2444 0000D287 <res 00000001>          Tempo:		resb 1
  2445 0000D288 <res 00000001>          TempoWait:	resb 1
  2446 0000D289 <res 00000001>          Bpm:		resb 1
  2447 0000D28A <res 00000001>          Row:		resb 1
  2448 0000D28B <res 00000001>          BreakRow:	resb 1
  2449 0000D28C <res 00000002>          BpmSamples:	resw 1
  2450 0000D28E <res 00000004>          BufPtr:		resd 1
  2451 0000D292 <res 00000002>          BufLen:		resw 1
  2452 0000D294 <res 00000004>          BufRep:		resd 1
  2453 0000D298 <res 00000004>          Note:		resd 1
  2454                                  ;Tracks:	resb TrackInfo.size*NumTracks
  2455                                  ; 07/10/2017
  2456 0000D29C <res 00000130>          Tracks:		resb TrackInfo.size*8
  2457                                  
  2458 0000D3CC <res 00000004>          alignb 16
  2459                                  
  2460                                  ; PLAY.ASM
  2461                                  ;Scope:		resw 320
  2462 0000D3D0 <res 00000200>          RowOfs:		resw 256
  2463                                  
  2464                                  ; 23/10/2017
  2465 0000D5D0 <res 00000200>          NewScope_L:	resw 256 ; ?
  2466 0000D7D0 <res 00000200>          NewScope_R:	resw 256 ; ?
  2467 0000D9D0 <res 00000200>          OldScope_L:	resw 256 ; ?
  2468 0000DBD0 <res 00000200>          OldScope_R:	resw 256 ; ?
  2469                                  
  2470                                  mod_file_name:
  2471 0000DDD0 <res 00000050>          		resb 80
  2472                                  
  2473                                  ; 20/10/2017 (modplay7.s, SB16)
  2474                                  ; 19/10/2017 (modplay6.s, AC97)
  2475 0000DE20 <res 00000001>          pan_shift:	resb 1
  2476 0000DE21 <res 00000001>          volume_level:	resb 1
  2477                                  
  2478 0000DE22 <res 000001DE>          alignb 4096
  2479                                  
  2480                                  Audio_Buffer:
  2481 0000E000 <res 00008000>          		resb BUFFERSIZE ; DMA Buffer Size / 2  (32768)
  2482                                  ; 28/10/2017
  2483                                  ;g_buff:
  2484                                  ;		resb 256 * 4 ; 23/10/2017 (stereo, 16 bits)
  2485                                  
  2486 00016000 <res 0000A000>          alignb 65536
  2487                                  
  2488                                  DMA_Buffer:
  2489 00020000 <res 00010000>          		resb 65536	
  2490                                  file_buffer:
  2491 00030000 <res 00060000>          		resb 65536*6
  2492                                  EOF:
