     1                                  ; ****************************************************************************
     2                                  ; tmodply2.s (for TRDOS 386)
     3                                  ; ----------------------------------------------------------------------------
     4                                  ; TMODPLY2.PRG ! AC'97 (ICH) MOD PLAYER & VGA DEMO program by Erdogan TAN
     5                                  ;
     6                                  ; 27/10/2017
     7                                  ;
     8                                  ; [ Last Modification: 29/10/2017 ]  !!! STEREO MOD PLAYING !!!
     9                                  ;
    10                                  ; Derived from 'tmodplay.s' (TMODPLAY.PRG, SB16) source code by Erdogan Tan
    11                                  ; (27/10/2017). ((Stereo mod playing with TRDOS 386 audio system calls...))
    12                                  ;
    13                                  ; <tmodplay.s> note:
    14                                  ;
    15                                  ; For 640x480x16 display, 'TNYPL211' source code ('EX1A.ASM' and 'EX1B.ASM'
    16                                  ; by Carlos Hasan, 1994) is modified in order to use previous ('modplay7.s')
    17                                  ; scope method as stereo. (Track/channel scope method -in TNYPL211 files- 
    18                                  ; is/was not applied because TRDOS 386 adaption of the tiny mod player uses 
    19                                  ; dma buffer for immediate -synchronized- displaying of sound waves.
    20                                  ; So, stereo wave display -two waves, two scopes- is normally applicable.)
    21                                  ;
    22                                  ; Derived from source code of 'PLAY.EXE' (TINYPLAY) by Carlos Hasan (1993)
    23                                  ;          PLAY.EXE: PLAY.ASM, MODLOAD.ASM, MODPLAY.ASM, SB.ASM
    24                                  ;
    25                                  ; Stereophonic mod playing code prototype: 
    26                                  ;		'modplay6.s' (AC97) by Erdogan Tan (20/10/2017)
    27                                  ;
    28                                  ; Modified by using the source code of 'tinyply3.s' ('TINYPLY3.PRG') 
    29                                  ; by Erdogan Tan (07/10/2017)
    30                                  ;
    31                                  ; Modified from 'playwav3.s' (13/06/2017)
    32                                  ;
    33                                  ; Modified from 'PLAYMOD.PRG' ('playmod.s') source code by Erdogan Tan
    34                                  ;			                     (23/06/2017)
    35                                  ;
    36                                  ; Derived from source code of 'TINYPLAY.COM' ('TINYPLAY.ASM') by Erdogan Tan
    37                                  ;				      (04/03/2017) 
    38                                  ; Assembler: NASM 2.11
    39                                  ; ----------------------------------------------------------------------------
    40                                  ;	   nasm  tmodplay.s -l tmodplay.txt -o TMODPLAY.PRG	
    41                                  ; ****************************************************************************
    42                                  ; PLAYMOD.ASM by Erdogan Tan (for MSDOS) (15/02/2017)
    43                                  ; TMODPLAY.ASM by Erdogan Tan (for MSDOS) (01/10/2017)
    44                                  
    45                                  ; 01/03/2017
    46                                  ; 16/10/2016
    47                                  ; 29/04/2016
    48                                  ; TRDOS 386 system calls (temporary list!)
    49                                  _ver 	equ 0
    50                                  _exit 	equ 1
    51                                  _fork 	equ 2
    52                                  _read 	equ 3
    53                                  _write	equ 4
    54                                  _open	equ 5
    55                                  _close 	equ 6
    56                                  _wait 	equ 7
    57                                  _creat 	equ 8
    58                                  _link 	equ 9
    59                                  _unlink	equ 10
    60                                  _exec	equ 11
    61                                  _chdir	equ 12
    62                                  _time 	equ 13
    63                                  _mkdir 	equ 14
    64                                  _chmod	equ 15
    65                                  _chown	equ 16
    66                                  _break	equ 17
    67                                  _stat	equ 18
    68                                  _seek	equ 19
    69                                  _tell 	equ 20
    70                                  _mount	equ 21
    71                                  _umount	equ 22
    72                                  _setuid	equ 23
    73                                  _getuid	equ 24
    74                                  _stime	equ 25
    75                                  _quit	equ 26	
    76                                  _intr	equ 27
    77                                  _fstat	equ 28
    78                                  _emt 	equ 29
    79                                  _mdate 	equ 30
    80                                  _video 	equ 31
    81                                  _audio	equ 32
    82                                  _timer	equ 33
    83                                  _sleep	equ 34
    84                                  _msg    equ 35
    85                                  _geterr	equ 36
    86                                  _fpsave	equ 37
    87                                  _pri	equ 38
    88                                  _rele	equ 39
    89                                  _fff	equ 40
    90                                  _fnf	equ 41
    91                                  _alloc	equ 42
    92                                  _dalloc equ 43
    93                                  _calbac equ 44		
    94                                  
    95                                  %macro sys 1-4
    96                                      ; 29/04/2016 - TRDOS 386 (TRDOS v2.0)	
    97                                      ; 03/09/2015	
    98                                      ; 13/04/2015
    99                                      ; Retro UNIX 386 v1 system call.	
   100                                      %if %0 >= 2   
   101                                          mov ebx, %2
   102                                          %if %0 >= 3    
   103                                              mov ecx, %3
   104                                              %if %0 = 4
   105                                                 mov edx, %4   
   106                                              %endif
   107                                          %endif
   108                                      %endif
   109                                      mov eax, %1
   110                                      ;int 30h
   111                                      int 40h ; TRDOS 386 (TRDOS v2.0)	   
   112                                  %endmacro
   113                                  
   114                                  ; TRDOS 386 (and Retro UNIX 386 v1) system call format:
   115                                  ; sys systemcall (eax) <arg1 (ebx)>, <arg2 (ecx)>, <arg3 (edx)>
   116                                  
   117                                  ; 19/06/2017
   118                                  BUFFERSIZE equ 32768
   119                                  
   120                                  ; ----------------------------------------------------------------------------
   121                                  ; Tiny MOD Player v0.1b by Carlos Hasan.
   122                                  ;	July 14th, 1993.
   123                                  
   124                                  ;=============================================================================
   125                                  ;  
   126                                  ;=============================================================================
   127                                  
   128                                  [BITS 32]
   129                                  [org 0]
   130                                  
   131                                  Start:
   132                                  	; clear bss
   133 00000000 B9[00000900]            	mov	ecx, EOF
   134 00000005 BF[93520000]            	mov	edi, bss_start
   135 0000000A 29F9                    	sub	ecx, edi
   136 0000000C D1E9                    	shr	ecx, 1
   137 0000000E 31C0                    	xor	eax, eax
   138 00000010 F366AB                  	rep	stosw
   139                                  
   140                                  	; Detect (& Enable) AC'97 (ICH) Audio Device
   141 00000013 E814020000              	call    DetectICH
   142 00000018 731B                    	jnc     short GetFileName
   143                                  
   144                                  _dev_not_ready:
   145                                  ; couldn't find the audio device!
   146                                  	sys	_msg, noDevMsg, 255, 0Fh
   147                              <1> 
   148                              <1> 
   149                              <1> 
   150                              <1> 
   151                              <1>  %if %0 >= 2
   152 0000001A BB[39020000]        <1>  mov ebx, %2
   153                              <1>  %if %0 >= 3
   154 0000001F B9FF000000          <1>  mov ecx, %3
   155                              <1>  %if %0 = 4
   156 00000024 BA0F000000          <1>  mov edx, %4
   157                              <1>  %endif
   158                              <1>  %endif
   159                              <1>  %endif
   160 00000029 B823000000          <1>  mov eax, %1
   161                              <1> 
   162 0000002E CD40                <1>  int 40h
   163 00000030 E9D6010000                      jmp     Exit
   164                                  
   165                                  GetFileName:
   166                                  	;cmp	ah, 1 ; SB16 Sound card
   167                                  	;jne	_dev_not_ready	
   168                                  	  
   169 00000035 89E6                    	mov	esi, esp
   170 00000037 AD                      	lodsd
   171 00000038 83F802                  	cmp	eax, 2 ; two arguments 
   172                                  		; (program file name & mod file name)
   173 0000003B 0F82D3010000            	jb	pmsg_usage ; nothing to do
   174                                  
   175 00000041 AD                      	lodsd ; program file name address 
   176 00000042 AD                      	lodsd ; mod file name address (file to be read)
   177 00000043 89C6                    	mov	esi, eax
   178 00000045 BF[F0DF0000]            	mov	edi, mod_file_name
   179                                  ScanName:       
   180 0000004A AC                      	lodsb
   181 0000004B 84C0                    	test	al, al
   182 0000004D 0F84C1010000            	je	pmsg_usage
   183 00000053 3C20                    	cmp	al, 20h
   184 00000055 74F3                    	je	short ScanName	; scan start of name.
   185 00000057 AA                      	stosb
   186 00000058 B4FF                    	mov	ah, 0FFh
   187                                  a_0:	
   188 0000005A FEC4                    	inc	ah
   189                                  a_1:
   190 0000005C AC                      	lodsb
   191 0000005D AA                      	stosb
   192 0000005E 3C2E                    	cmp	al, '.'
   193 00000060 74F8                    	je	short a_0	
   194 00000062 20C0                    	and	al, al
   195 00000064 75F6                    	jnz	short a_1
   196                                  
   197 00000066 08E4                    	or	ah, ah		 ; if period NOT found,
   198 00000068 750B                    	jnz	short PrintPMesg ; then add a .MOD extension.
   199                                  SetExt:
   200 0000006A 4F                      	dec	edi
   201 0000006B C7072E4D4F44            	mov	dword [edi], '.MOD'
   202 00000071 C6470400                	mov	byte [edi+4], 0
   203                                  PrintPMesg:      
   204                                  	; Prints the Credits Text.
   205                                  	sys	_msg, Credits, 255, 0Fh
   206                              <1> 
   207                              <1> 
   208                              <1> 
   209                              <1> 
   210                              <1>  %if %0 >= 2
   211 00000075 BB[72510000]        <1>  mov ebx, %2
   212                              <1>  %if %0 >= 3
   213 0000007A B9FF000000          <1>  mov ecx, %3
   214                              <1>  %if %0 = 4
   215 0000007F BA0F000000          <1>  mov edx, %4
   216                              <1>  %endif
   217                              <1>  %endif
   218                              <1>  %endif
   219 00000084 B823000000          <1>  mov eax, %1
   220                              <1> 
   221 00000089 CD40                <1>  int 40h
   222                                  _1:
   223                                  	; 19/06/2017
   224                                  	; Allocate Audio Buffer (for user)
   225                                  	sys	_audio, 0200h, BUFFERSIZE, Audio_Buffer
   226                              <1> 
   227                              <1> 
   228                              <1> 
   229                              <1> 
   230                              <1>  %if %0 >= 2
   231 0000008B BB00020000          <1>  mov ebx, %2
   232                              <1>  %if %0 >= 3
   233 00000090 B900800000          <1>  mov ecx, %3
   234                              <1>  %if %0 = 4
   235 00000095 BA[00F00000]        <1>  mov edx, %4
   236                              <1>  %endif
   237                              <1>  %endif
   238                              <1>  %endif
   239 0000009A B820000000          <1>  mov eax, %1
   240                              <1> 
   241 0000009F CD40                <1>  int 40h
   242 000000A1 0F820D010000            	jc	error_exit
   243                                  _2:
   244                                  	;; Initialize Audio Device (bl = 1 -> Interrupt method)
   245                                  	;sys	_audio, 0301h, 0, sb16_int_handler 
   246                                  	;jc	error_exit
   247                                  	
   248                                  	; 20/10/2017
   249                                  	; Initialize Audio Device (bl = 0 -> SRB method)
   250                                  	sys	_audio, 0300h, 1, srb 
   251                              <1> 
   252                              <1> 
   253                              <1> 
   254                              <1> 
   255                              <1>  %if %0 >= 2
   256 000000A7 BB00030000          <1>  mov ebx, %2
   257                              <1>  %if %0 >= 3
   258 000000AC B901000000          <1>  mov ecx, %3
   259                              <1>  %if %0 = 4
   260 000000B1 BA[B5520000]        <1>  mov edx, %4
   261                              <1>  %endif
   262                              <1>  %endif
   263                              <1>  %endif
   264 000000B6 B820000000          <1>  mov eax, %1
   265                              <1> 
   266 000000BB CD40                <1>  int 40h
   267 000000BD 0F82F1000000            	jc	error_exit
   268                                  
   269                                  LoadMod:  
   270 000000C3 BF[F0DF0000]            	mov	edi, mod_file_name
   271 000000C8 E84F020000              	call    LoadModule		; Load the MODule...
   272                                  	; 08/10/2017
   273 000000CD 731B                    	jnc	short _3		; any error loading?
   274                                  
   275                                  	; yes, print error and Exit.
   276                                  
   277                                  	sys	_msg, ErrorMesg, 255, 0Fh
   278                              <1> 
   279                              <1> 
   280                              <1> 
   281                              <1> 
   282                              <1>  %if %0 >= 2
   283 000000CF BB[A6510000]        <1>  mov ebx, %2
   284                              <1>  %if %0 >= 3
   285 000000D4 B9FF000000          <1>  mov ecx, %3
   286                              <1>  %if %0 = 4
   287 000000D9 BA0F000000          <1>  mov edx, %4
   288                              <1>  %endif
   289                              <1>  %endif
   290                              <1>  %endif
   291 000000DE B823000000          <1>  mov eax, %1
   292                              <1> 
   293 000000E3 CD40                <1>  int 40h
   294 000000E5 E921010000              	jmp     Exit
   295                                  _3:
   296                                  	; 10/06/2017
   297                                  	sys	_audio, 0E00h ; get audio controller info
   298                              <1> 
   299                              <1> 
   300                              <1> 
   301                              <1> 
   302                              <1>  %if %0 >= 2
   303 000000EA BB000E0000          <1>  mov ebx, %2
   304                              <1>  %if %0 >= 3
   305                              <1>  mov ecx, %3
   306                              <1>  %if %0 = 4
   307                              <1>  mov edx, %4
   308                              <1>  %endif
   309                              <1>  %endif
   310                              <1>  %endif
   311 000000EF B820000000          <1>  mov eax, %1
   312                              <1> 
   313 000000F4 CD40                <1>  int 40h
   314 000000F6 0F82B8000000            	jc	error_exit
   315                                  
   316                                  	;cmp	ah, 2 ; AC'97 (Intel ICH) Audio Controller
   317                                  	;jne	_dev_not_ready	
   318                                  
   319                                  	; EAX = IRQ Number in AL
   320                                  	;	Audio Device Number in AH 
   321                                  	; EBX = DEV/VENDOR ID
   322                                  	;       (DDDDDDDDDDDDDDDDVVVVVVVVVVVVVVVV)
   323                                  	; ECX = BUS/DEV/FN 
   324                                  	;       (00000000BBBBBBBBDDDDDFFF00000000)
   325                                  	; EDX = Base IO Addr (DX) for SB16 & VT8233
   326                                  	; EDX = NABMBAR/NAMBAR (for AC97)
   327                                  	;      (Low word, DX = NAMBAR address)
   328                                  
   329 000000FC A2[B4520000]            	mov	[ac97_int_ln_reg], al
   330 00000101 891D[A4520000]          	mov	[dev_vendor], ebx
   331 00000107 890D[A8520000]          	mov	[bus_dev_fn], ecx
   332 0000010D 668915[B0520000]        	mov	[ac97_NamBar], dx
   333                                  	;mov	[ac97_NamBar], dx
   334                                  	;shr	dx, 16
   335                                  	;mov	[ac97_NabmBar], dx
   336 00000114 8915[B0520000]          	mov	[ac97_NamBar], edx	
   337                                    
   338 0000011A E8B70A0000              	call	write_audio_dev_info 
   339                                  
   340                                  PlayNow: 
   341 0000011F E8D1090000              	call    StartPlaying
   342                                  
   343                                          ; load 32768 bytes into audio buffer
   344 00000124 BF[00F00000]            	mov	edi, Audio_Buffer
   345                                  	; 19/10/2017
   346                                  	;mov	ebx, BUFFERSIZE
   347 00000129 BB00200000              	mov	ebx, BUFFERSIZE/4  ; 16 bits, stereo sound buffer
   348 0000012E E870080000              	call	GetSamples
   349 00000133 727F                    	jc	error_exit
   350                                  
   351                                  ;	;mov	ecx, 128	; Make a lookup table
   352                                  ;	mov	cl, 128
   353                                  ;	xor     ebx, ebx	; for fastest pixel
   354                                  ;	mov     edx, 320*(100-64)	; addressing.
   355                                  ;MakeOfs:        
   356                                  ;	mov     [RowOfs+ebx], dx
   357                                  ;	mov     [RowOfs+ebx+2], dx
   358                                  ;	add     dx, 320
   359                                  ;	add     ebx, 4
   360                                  ;	loop    MakeOfs
   361                                  
   362                                  	; 27/10/2017
   363 00000135 66B90001                	mov	cx, 256
   364 00000139 31DB                    	xor	ebx, ebx
   365 0000013B BF[F0D50000]            	mov	edi, RowOfs
   366                                  MakeOfs:
   367                                  	; 29/10/2017
   368                                  	;mov	ax, 128
   369                                  	;mul	bx
   370                                  	;mov	al, ah
   371                                  	;mov	ah, 80
   372                                  	;mul	ah
   373 00000140 89D8                    	mov	eax, ebx
   374 00000142 66C1E007                	shl	ax, 7 ; * 128
   375 00000146 B050                    	mov	al, 80
   376 00000148 F6E4                    	mul	ah
   377 0000014A 66AB                    	stosw
   378 0000014C 43                      	inc	ebx
   379 0000014D E2F1                    	loop	MakeOfs
   380                                  	
   381                                  	; 23/06/2017
   382                                  	; Map DMA buffer to user's memory space
   383                                  	sys	_audio, 0D00h, 65536, DMA_Buffer
   384                              <1> 
   385                              <1> 
   386                              <1> 
   387                              <1> 
   388                              <1>  %if %0 >= 2
   389 0000014F BB000D0000          <1>  mov ebx, %2
   390                              <1>  %if %0 >= 3
   391 00000154 B900000100          <1>  mov ecx, %3
   392                              <1>  %if %0 = 4
   393 00000159 BA[00000200]        <1>  mov edx, %4
   394                              <1>  %endif
   395                              <1>  %endif
   396                              <1>  %endif
   397 0000015E B820000000          <1>  mov eax, %1
   398                              <1> 
   399 00000163 CD40                <1>  int 40h
   400                                  	;jc	error_exit
   401                                  
   402                                  	; 24/06/2017
   403                                  	; Set Master Volume Level (BL=0 or 80h)
   404                                  	; 	 	for next playing (BL>=80h)
   405                                  	sys	_audio, 0B80h, 1D1Dh
   406                              <1> 
   407                              <1> 
   408                              <1> 
   409                              <1> 
   410                              <1>  %if %0 >= 2
   411 00000165 BB800B0000          <1>  mov ebx, %2
   412                              <1>  %if %0 >= 3
   413 0000016A B91D1D0000          <1>  mov ecx, %3
   414                              <1>  %if %0 = 4
   415                              <1>  mov edx, %4
   416                              <1>  %endif
   417                              <1>  %endif
   418                              <1>  %endif
   419 0000016F B820000000          <1>  mov eax, %1
   420                              <1> 
   421 00000174 CD40                <1>  int 40h
   422                                  
   423                                  	; 20/10/2017
   424 00000176 C605[41E00000]1D        	mov	byte [volume_level], 1Dh
   425                                  
   426                                  	;mov	word [MixSpeed], 22050	; Mixing at 22.050 kHz
   427                                  	
   428                                  	; Start	to play
   429 0000017D A0[E9510000]            	mov	al, [bps]
   430 00000182 C0E804                  	shr	al, 4 ; 8 -> 0, 16 -> 1
   431 00000185 D0E0                    	shl	al, 1 ; 16 -> 2, 8 -> 0
   432 00000187 8A1D[E8510000]          	mov	bl, [stmo]
   433 0000018D FECB                    	dec	bl
   434 0000018F 08C3                    	or	bl, al
   435 00000191 668B0D[EA510000]        	mov	cx, [MixSpeed] ; [Sample_Rate] ; Hz 
   436 00000198 B704                    	mov	bh, 4 ; start to play	
   437                                  	sys	_audio
   438                              <1> 
   439                              <1> 
   440                              <1> 
   441                              <1> 
   442                              <1>  %if %0 >= 2
   443                              <1>  mov ebx, %2
   444                              <1>  %if %0 >= 3
   445                              <1>  mov ecx, %3
   446                              <1>  %if %0 = 4
   447                              <1>  mov edx, %4
   448                              <1>  %endif
   449                              <1>  %endif
   450                              <1>  %endif
   451 0000019A B820000000          <1>  mov eax, %1
   452                              <1> 
   453 0000019F CD40                <1>  int 40h
   454                                      
   455                                  	;; SETUP SIGNAL RESPONSE BYTE
   456                                  	;; 06/03/2017
   457                                  	;mov	bl, [ac97_int_ln_reg] ; IRQ number
   458                                  	;mov	bh, 1 ; Link IRQ to user for Signal Response Byte
   459                                  	;mov	edx, srb  ; Signal Response/Return Byte address  
   460                                  	;mov	ecx, 0FFh ; Signal Response/Return Byte value  
   461                                  	;sys	_calbac
   462                                  	;jc	short error_exit
   463                                  
   464                                  	; DIRECT VGA MEMORY ACCESS
   465                                  	; bl = 0, bh = 5
   466                                  	; Direct access/map to VGA memory (0A0000h)
   467                                  
   468                                  	sys	_video, 0500h
   469                              <1> 
   470                              <1> 
   471                              <1> 
   472                              <1> 
   473                              <1>  %if %0 >= 2
   474 000001A1 BB00050000          <1>  mov ebx, %2
   475                              <1>  %if %0 >= 3
   476                              <1>  mov ecx, %3
   477                              <1>  %if %0 = 4
   478                              <1>  mov edx, %4
   479                              <1>  %endif
   480                              <1>  %endif
   481                              <1>  %endif
   482 000001A6 B81F000000          <1>  mov eax, %1
   483                              <1> 
   484 000001AB CD40                <1>  int 40h
   485 000001AD 3D00000A00              	cmp	eax, 0A0000h
   486 000001B2 7418                    	je	short _a3
   487                                  error_exit:
   488                                  	sys	_msg, trdos386_err_msg, 255, 0Eh
   489                              <1> 
   490                              <1> 
   491                              <1> 
   492                              <1> 
   493                              <1>  %if %0 >= 2
   494 000001B4 BB[C3510000]        <1>  mov ebx, %2
   495                              <1>  %if %0 >= 3
   496 000001B9 B9FF000000          <1>  mov ecx, %3
   497                              <1>  %if %0 = 4
   498 000001BE BA0E000000          <1>  mov edx, %4
   499                              <1>  %endif
   500                              <1>  %endif
   501                              <1>  %endif
   502 000001C3 B823000000          <1>  mov eax, %1
   503                              <1> 
   504 000001C8 CD40                <1>  int 40h
   505 000001CA EB3F                    	jmp	short Exit
   506                                  
   507                                  ; Note: Normally IRQ 0 calls the ModPlay Polling at 18.2Hz thru
   508                                  ;       the software interrupt 1Ch. If the IRQ 0 is disabled, then
   509                                  ;       the INT 1Ch MUST BE CALLED at least MixSpeed/1024 times per
   510                                  ;       second, or the module will sound "looped".
   511                                  ;       Because we need better sync with the ModPlayer to draw the scope,
   512                                  ;       the polling is called from my routine, and then the irq 0 must be
   513                                  ;       disabled. The [DmaBuffer] points to the current buffer of 8-bit
   514                                  ;       samples played by the Sound Blaster. Note that some samples are
   515                                  ;       discarded in the next code, just for fun!
   516                                  
   517                                  _a3:
   518                                  	;mov     ax, 0013h	; Set Mode 320x200x256
   519                                  	;int     31h
   520                                  
   521                                  	; 21/10/2017
   522                                  	;mov	ax, 0012h	; Set Mode 640x480x16
   523                                  	;int	31h
   524                                  
   525                                  	; 22/10/2017
   526 000001CC E8D00B0000              	call	setgraphmode	; Set video mode to 640*480x16
   527                                  
   528                                  	; 22/10/2017
   529                                  	;call	loadlbm
   530                                  	;jc	short loadlbm_err
   531                                  
   532 000001D1 BE[CE0F0000]            	mov	esi, LOGO_ADDRESS
   533 000001D6 E8B80C0000              	call	putlbm
   534                                  	;jnc	short loadlbm_ok
   535 000001DB 731F                    	jnc	short _a4 ; 
   536                                  
   537                                  	;mov	byte [error_color], 0Eh ; Yellow
   538                                  
   539                                  loadlbm_err:
   540                                  	; 21/10/2017
   541                                  	;mov	ax, 0003h	; Set Text Mode 80x25x16
   542                                  	;int	31h
   543                                  	; 22/10/2017
   544 000001DD E8DC0B0000              	call	settextmode
   545                                  
   546                                  	sys	_msg, LOGO_ERROR_MSG, 255, [error_color]
   547                              <1> 
   548                              <1> 
   549                              <1> 
   550                              <1> 
   551                              <1>  %if %0 >= 2
   552 000001E2 BB[A10F0000]        <1>  mov ebx, %2
   553                              <1>  %if %0 >= 3
   554 000001E7 B9FF000000          <1>  mov ecx, %3
   555                              <1>  %if %0 = 4
   556 000001EC 8B15[FB010000]      <1>  mov edx, %4
   557                              <1>  %endif
   558                              <1>  %endif
   559                              <1>  %endif
   560 000001F2 B823000000          <1>  mov eax, %1
   561                              <1> 
   562 000001F7 CD40                <1>  int 40h
   563 000001F9 EB10                    	jmp	short Exit
   564                                  
   565                                  	; 21/10/2017
   566                                  error_color:
   567 000001FB 0C                      	db	0Ch  ; Light Red
   568                                  	
   569                                  loadlbm_ok: 
   570                                  	; 21/10/2017
   571                                  _a4:
   572                                  	; 24/06/2017
   573 000001FC E863000000              	call	PlayMod ; 13/02/2017 (ModPlay)
   574                                  
   575                                  _s_exit:
   576 00000201 E89F090000              	call	StopPlaying	; STOP!
   577                                  	
   578                                  	; 22/10/2017
   579                                  	;mov	ax, 0003h	; Set Text Mode 80x25x16
   580                                  	;int	31h
   581 00000206 E8B30B0000              	call	settextmode
   582                                  Exit:           
   583                                  	;call	FreeModule	; Free MODule core.
   584                                  	
   585                                  	sys 	_exit	; Bye !
   586                              <1> 
   587                              <1> 
   588                              <1> 
   589                              <1> 
   590                              <1>  %if %0 >= 2
   591                              <1>  mov ebx, %2
   592                              <1>  %if %0 >= 3
   593                              <1>  mov ecx, %3
   594                              <1>  %if %0 = 4
   595                              <1>  mov edx, %4
   596                              <1>  %endif
   597                              <1>  %endif
   598                              <1>  %endif
   599 0000020B B801000000          <1>  mov eax, %1
   600                              <1> 
   601 00000210 CD40                <1>  int 40h
   602                                  here:
   603 00000212 EBFE                    	jmp	short here
   604                                  
   605                                  pmsg_usage:
   606                                  	sys	_msg, msg_usage, 255, 0Fh
   607                              <1> 
   608                              <1> 
   609                              <1> 
   610                              <1> 
   611                              <1>  %if %0 >= 2
   612 00000214 BB[09510000]        <1>  mov ebx, %2
   613                              <1>  %if %0 >= 3
   614 00000219 B9FF000000          <1>  mov ecx, %3
   615                              <1>  %if %0 = 4
   616 0000021E BA0F000000          <1>  mov edx, %4
   617                              <1>  %endif
   618                              <1>  %endif
   619                              <1>  %endif
   620 00000223 B823000000          <1>  mov eax, %1
   621                              <1> 
   622 00000228 CD40                <1>  int 40h
   623 0000022A EBDF                    	jmp	short Exit
   624                                  
   625                                  DetectICH:
   626                                  	; 24/06/2017
   627                                  	; Detect (BH=1) AC97 (BL=2) Audio Controller
   628                                          sys	_audio, 0102h
   629                              <1> 
   630                              <1> 
   631                              <1> 
   632                              <1> 
   633                              <1>  %if %0 >= 2
   634 0000022C BB02010000          <1>  mov ebx, %2
   635                              <1>  %if %0 >= 3
   636                              <1>  mov ecx, %3
   637                              <1>  %if %0 = 4
   638                              <1>  mov edx, %4
   639                              <1>  %endif
   640                              <1>  %endif
   641                              <1>  %endif
   642 00000231 B820000000          <1>  mov eax, %1
   643                              <1> 
   644 00000236 CD40                <1>  int 40h
   645 00000238 C3                      	retn
   646                                  
   647                                  noDevMsg:
   648 00000239 4572726F723A20556E-     	db "Error: Unable to find AC97 audio device!",13,10,0
   649 00000242 61626C6520746F2066-
   650 0000024B 696E64204143393720-
   651 00000254 617564696F20646576-
   652 0000025D 696365210D0A00     
   653                                  
   654                                  ;ac97_int_handler:
   655                                  ;	; 19/06/2017
   656                                  ;	mov	byte [srb], 1 ; interrupt (or signal response byte)
   657                                  ;
   658                                  ;	sys	_rele ; return from callback service 
   659                                  ;	; we must not come here !
   660                                  ;	sys	_exit
   661                                  
   662                                  ;=============================================================================
   663                                  ;      
   664                                  ;=============================================================================
   665                                  
   666                                  PlayMod:
   667                                  	; 27/10/2017
   668                                  	; 19/10/2017
   669                                  	; 23/06/2017   
   670                                  	; 21/06/2017
   671                                  	; 19/06/2017
   672                                  
   673                                  	; 05/03/2017 (TRDOS 386)
   674                                  	; 14/02/2017
   675                                  	; 13/02/2017
   676                                  	; 08/12/2016
   677                                  	; 28/11/2016
   678                                  
   679 00000264 EB10                         	jmp	short modp_gs ; 23/06/2017
   680                                  p_loop:
   681 00000266 803D[B5520000]00        	cmp	byte [srb], 0
   682 0000026D 761C                    	jna	short q_loop
   683 0000026F C605[B5520000]00        	mov	byte [srb], 0
   684                                  modp_gs:
   685 00000276 BF[00F00000]            	mov	edi, Audio_Buffer
   686                                  	; 19/10/2017
   687                                  	;mov	ebx, BUFFERSIZE ; 32768 bytes ; 14/03/2017
   688 0000027B BB00200000              	mov	ebx, BUFFERSIZE/4  ; 16 bits, stereo sound buffer
   689 00000280 E81E070000              	call	GetSamples
   690 00000285 0F8229FFFFFF            	jc	error_exit
   691                                  q_loop:
   692 0000028B B401                    	mov     ah, 1		; any key pressed?
   693 0000028D CD32                    	int     32h		; no, Loop.
   694 0000028F 745C                    	jz	short r_loop
   695                                  
   696 00000291 B400                    	mov     ah, 0		; flush key buffer...
   697 00000293 CD32                    	int     32h
   698                                  
   699                                  	; 19/10/2017 (modplay6.s)
   700 00000295 3C20                    	cmp	al, 20h
   701 00000297 740E                    	je	short change_pan
   702                                  	; 09/10/2017 (playmod5.s)
   703 00000299 3C2B                    	cmp	al, '+' ; increase sound volume
   704 0000029B 741D                    	je	short inc_volume_level
   705 0000029D 3C2D                    	cmp	al, '-'
   706 0000029F 743C                    	je	short dec_volume_level
   707                                  
   708                                  	; 19/10/2017 (modplay6.s)
   709 000002A1 24DF                    	and	al, 0DFh
   710 000002A3 3C50                    	cmp	al, 'P'
   711 000002A5 7545                    	jne	short q_return
   712                                  
   713                                  change_pan:
   714                                  	; 19/10/2017 (modplay6.s)
   715 000002A7 8A0D[40E00000]          	mov	cl, [pan_shift]
   716 000002AD FEC1                    	inc	cl
   717 000002AF 80E103                  	and	cl, 3
   718 000002B2 880D[40E00000]          	mov	[pan_shift], cl
   719 000002B8 EB33                    	jmp	short r_loop
   720                                  
   721                                  	; 09/10/2017 (playmod5.s)
   722                                  	; 24/06/2017 (wavplay2.s)
   723                                  inc_volume_level:
   724 000002BA 8A0D[41E00000]          	mov	cl, [volume_level]
   725 000002C0 80F91F                  	cmp	cl, 1Fh ; 31
   726 000002C3 7328                    	jnb	short r_loop
   727 000002C5 FEC1                    	inc	cl
   728                                  change_volume_level:
   729 000002C7 880D[41E00000]          	mov	[volume_level], cl
   730 000002CD 88CD                    	mov	ch, cl
   731                                  	; Set Master Volume Level
   732                                  	sys	_audio, 0B00h
   733                              <1> 
   734                              <1> 
   735                              <1> 
   736                              <1> 
   737                              <1>  %if %0 >= 2
   738 000002CF BB000B0000          <1>  mov ebx, %2
   739                              <1>  %if %0 >= 3
   740                              <1>  mov ecx, %3
   741                              <1>  %if %0 = 4
   742                              <1>  mov edx, %4
   743                              <1>  %endif
   744                              <1>  %endif
   745                              <1>  %endif
   746 000002D4 B820000000          <1>  mov eax, %1
   747                              <1> 
   748 000002D9 CD40                <1>  int 40h
   749 000002DB EB10                    	jmp	short r_loop
   750                                  dec_volume_level:
   751 000002DD 8A0D[41E00000]          	mov	cl, [volume_level]
   752 000002E3 80F901                  	cmp	cl, 1 ; 1
   753 000002E6 7605                    	jna	short r_loop
   754 000002E8 FEC9                    	dec	cl
   755 000002EA EBDB                    	jmp	short change_volume_level
   756                                  
   757                                  q_return:
   758 000002EC C3                      	retn
   759                                  r_loop:
   760                                  	; 27/10/2017
   761                                  	; Get Current DMA buffer Pointer 
   762                                  	; 23/06/2017 ('modplay6.s')
   763                                  	; bh = 15, get current pointer (DMA buffer offset)
   764                                  	; bl = 0, for PCM OUT
   765                                  	; ecx = 0
   766                                  	;
   767                                  	sys	_audio, 0F00h, 0
   768                              <1> 
   769                              <1> 
   770                              <1> 
   771                              <1> 
   772                              <1>  %if %0 >= 2
   773 000002ED BB000F0000          <1>  mov ebx, %2
   774                              <1>  %if %0 >= 3
   775 000002F2 B900000000          <1>  mov ecx, %3
   776                              <1>  %if %0 = 4
   777                              <1>  mov edx, %4
   778                              <1>  %endif
   779                              <1>  %endif
   780                              <1>  %endif
   781 000002F7 B820000000          <1>  mov eax, %1
   782                              <1> 
   783 000002FC CD40                <1>  int 40h
   784                                  
   785                                  	; 28/10/2017
   786 000002FE 24FC                    	and	al, 0FCh  ; dword alignment (stereo, 16 bit)	
   787                                  	; 23/06/2017
   788 00000300 BE[00000200]            	mov     esi, DMA_Buffer
   789 00000305 01C6                    	add     esi, eax	; add offset value
   790                                  	; 24/06/2017
   791 00000307 B9[00FC0200]            	mov	ecx, DMA_Buffer + (65536 - (256*4))
   792 0000030C 39CE                    	cmp	esi, ecx 
   793 0000030E 7602                    	jna	short _4
   794 00000310 89CE                    	mov	esi, ecx
   795                                  _4:
   796                                  	; 23/10/2017 ('tmodplay.s')
   797 00000312 E8AE0A0000              	call	drawscopes
   798                                  
   799 00000317 E94AFFFFFF              	jmp	p_loop
   800                                  
   801                                  ;=============================================================================
   802                                  ;               MODLOAD.ASM
   803                                  ;=============================================================================
   804                                  
   805                                  ; Amiga Module Loader v0.1b by Carlos Hasan.
   806                                  ;	July 10th, 1993.
   807                                  
   808                                  ; STRUCTURES
   809                                  
   810                                  struc ModSample
   811 00000000 <res 00000016>          .msName:	resb 22
   812 00000016 <res 00000002>          .msLength:	resw 1
   813 00000018 <res 00000001>          .msFinetune:	resb 1
   814 00000019 <res 00000001>          .msVolume:	resb 1
   815 0000001A <res 00000002>          .msRepeat:	resw 1
   816 0000001C <res 00000002>          .msRepLen:	resw 1
   817                                  .size:		; 30 bytes
   818                                  endstruc
   819                                  
   820                                  struc ModHeader
   821 00000000 <res 00000014>          .mhName:	resb 20
   822 00000014 <res 000003A2>          .mhSamples:	resb ModSample.size*31
   823 000003B6 <res 00000001>          .mhOrderLen:	resb 1
   824 000003B7 <res 00000001>          .mhReStart:	resb 1
   825 000003B8 <res 00000080>          .mhOrder:	resb 128
   826 00000438 <res 00000004>          .mhSign:	resw 2
   827                                  .size:		; 1084 bytes
   828                                  endstruc
   829                                  
   830                                  struc ModInfoRec
   831 00000000 <res 00000001>          .OrderLen:	resb 1
   832 00000001 <res 00000001>          .ReStart:	resb 1
   833 00000002 <res 00000080>          .Order:		resb 128
   834 00000082 <res 00000004>          .Patterns:	resd 1
   835 00000086 <res 0000003E>          .SampOfs:	resw 31
   836 000000C4 <res 0000003E>          .SampSeg:	resw 31
   837 00000102 <res 0000003E>          .SampLen:	resw 31
   838 00000140 <res 0000003E>          .SampRep:	resw 31
   839 0000017E <res 0000003E>          .SampRepLen:	resw 31
   840 000001BC <res 0000003E>          .SampVol:	resw 31
   841                                  .size:		; 506 bytes	
   842                                  endstruc
   843                                  
   844                                  ; CODE
   845                                  
   846                                  ; modplay5.s
   847                                  ; 07/10/2017
   848                                  ; tinyply3.s
   849                                  ; 06/10/2017
   850                                  ; 04/10/2017
   851                                  ; /* MOD FileFormat */
   852                                  
   853                                  ID_MK	equ 2E4B2E4Dh ; "M.K."
   854                                  ID_FLT4 equ 34544C46h ; "FLT4"
   855                                  ID_8CHN equ 4E484338h ; "8CHN"
   856                                  ID_FLT8 equ 34544C46h ; "FLT8"
   857                                  
   858                                  ; CODE
   859                                  
   860                                  LoadModule:
   861                                  	; edi = file name address
   862                                  
   863 0000031C 60                      	pushad
   864                                  
   865 0000031D E878010000              	call    ClearModInfo
   866                                  OpenFile:       
   867                                  	; ebx = ASCIIZ file name address
   868                                  	; ecx = open mode (0 = open for read)	
   869                                  	sys	_open, edi, 0 ; open for reading
   870                              <1> 
   871                              <1> 
   872                              <1> 
   873                              <1> 
   874                              <1>  %if %0 >= 2
   875 00000322 89FB                <1>  mov ebx, %2
   876                              <1>  %if %0 >= 3
   877 00000324 B900000000          <1>  mov ecx, %3
   878                              <1>  %if %0 = 4
   879                              <1>  mov edx, %4
   880                              <1>  %endif
   881                              <1>  %endif
   882                              <1>  %endif
   883 00000329 B805000000          <1>  mov eax, %1
   884                              <1> 
   885 0000032E CD40                <1>  int 40h
   886 00000330 0F8262010000            	jc	Failed
   887 00000336 A3[B6520000]            	mov     [FileHandle], eax
   888                                  ReadHeader:
   889                                  	; ebx = File handle
   890                                  	; ecx = Buffer address
   891                                  	; edx = Byte count
   892                                  	sys	_read, [FileHandle], Header, ModHeader.size
   893                              <1> 
   894                              <1> 
   895                              <1> 
   896                              <1> 
   897                              <1>  %if %0 >= 2
   898 0000033B 8B1D[B6520000]      <1>  mov ebx, %2
   899                              <1>  %if %0 >= 3
   900 00000341 B9[BA520000]        <1>  mov ecx, %3
   901                              <1>  %if %0 = 4
   902 00000346 BA3C040000          <1>  mov edx, %4
   903                              <1>  %endif
   904                              <1>  %endif
   905                              <1>  %endif
   906 0000034B B803000000          <1>  mov eax, %1
   907                              <1> 
   908 00000350 CD40                <1>  int 40h
   909 00000352 0F8231010000            	jc      CloseFile
   910                                  CheckMK:  
   911                                  	; 04/10/2017
   912 00000358 A1[F2560000]            	mov	eax, [Header+ModHeader.mhSign]
   913                                        
   914 0000035D 3D4D2E4B2E              	cmp	eax, ID_MK   ; cmp eax, '.K.M'
   915                                  	;je	short Is4chnMod
   916 00000362 742B                    	je	short IsModFile
   917                                  CheckFLT4:
   918 00000364 3D464C5434              	cmp	eax, ID_FLT4 ; cmp eax, '4TLF'
   919                                  	;je	short Is4chnMod
   920 00000369 7424                    	je	short IsModFile
   921                                  Check8CHN:
   922 0000036B 3D3843484E              	cmp	eax, ID_8CHN ; cmp eax,	'NHC8'
   923 00000370 740D                    	je	short Is8chnMod
   924                                  CheckFLT8:
   925 00000372 3D464C5434              	cmp	eax, ID_FLT8 ; cmp eax, '8TLF'
   926                                  	; 06/10/2017
   927 00000377 7406                    	je	short Is8chnMod
   928 00000379 F9                      	stc
   929 0000037A E90A010000              	jmp	CloseFile
   930                                  Is8chnMod:
   931 0000037F C605[E4510000]08        	mov	byte [numtracks], 8	; 8-CHANNEL-MOD
   932 00000386 C605[E3510000]0B        	mov	byte [pattern_shift], 11 ; Pattern Size = 2048 bytes
   933 0000038D EB00                    	jmp	short IsModFile
   934                                  ;Is4chnMod:
   935                                  ;	mov	byte [numtracks], 4	; 4-CHANNEL-MOD
   936                                  ;	mov	byte [pattern_shift], 11 ; Pattern Size = 1024 bytes
   937                                  
   938                                  IsModFile:
   939 0000038F A0[70560000]            	mov     al, [Header+ModHeader.mhOrderLen]
   940 00000394 A2[F6560000]            	mov     [ModInfo.OrderLen], al
   941                                  
   942 00000399 A0[71560000]            	mov     al, [Header+ModHeader.mhReStart]
   943 0000039E 3A05[70560000]          	cmp     al, [Header+ModHeader.mhOrderLen]
   944 000003A4 7202                    	jb      short SetReStart
   945 000003A6 B07F                    	mov     al, 7Fh
   946                                  SetReStart:
   947 000003A8 A2[F7560000]            	mov     [ModInfo.ReStart], al
   948                                  
   949                                  	;mov	ecx, 128
   950 000003AD 66B98000                	mov	cx, 128
   951 000003B1 31D2                    	xor     edx, edx
   952 000003B3 31DB                    	xor     ebx, ebx
   953                                  CopyOrder:
   954 000003B5 8AB3[72560000]          	mov     dh, [Header+ModHeader.mhOrder+ebx]
   955 000003BB 88B3[F8560000]          	mov     [ModInfo.Order+ebx], dh
   956 000003C1 38D6                    	cmp     dh, dl
   957 000003C3 7202                    	jb      short NextOrder
   958 000003C5 88F2                    	mov     dl, dh ; Max. pattern number ; 04/10/2017
   959                                  NextOrder:
   960 000003C7 43                      	inc     ebx
   961 000003C8 E2EB                    	loop    CopyOrder
   962                                  AllocPatterns:  
   963 000003CA 81E2FF000000            	and	edx, 0FFh
   964                                  	; 04/10/2017
   965                                  	;inx	dx  ; 12/03/2017
   966 000003D0 FEC2                    	inc	dl
   967                                  	; dl = number of patterns (04/07/2017)
   968 000003D2 8A0D[E3510000]          	mov	cl, [pattern_shift] ; 10 for 4 channels, 11 for 8 channels
   969 000003D8 D3E2                    	shl	edx, cl ; 10 ; *1024 ; (byte count of patterns *64*4*4)
   970                                  		     	     ; *2048 ; (byte count of patterns *64*8*4)
   971                                  	;
   972 000003DA 89D5                    	mov	ebp, edx ; offset of samples (04/07/2017)
   973                                  	;mov	ecx, 10000h ; next 64K (4096*16)
   974 000003DC B9[00000300]            	mov	ecx, file_buffer ; 12/03/2017
   975                                  	;
   976 000003E1 890D[78570000]          	mov	[ModInfo.Patterns], ecx
   977                                  	;
   978 000003E7 01CD                    	add	ebp, ecx ; next offset for samples
   979                                  ReadPatterns:  
   980                                  	;mov	ebx, [FileHandle] 
   981                                  	; ebx = File handle
   982                                  	; ecx = Buffer address
   983                                  	; edx = Byte count
   984                                  	sys	_read, [FileHandle]
   985                              <1> 
   986                              <1> 
   987                              <1> 
   988                              <1> 
   989                              <1>  %if %0 >= 2
   990 000003E9 8B1D[B6520000]      <1>  mov ebx, %2
   991                              <1>  %if %0 >= 3
   992                              <1>  mov ecx, %3
   993                              <1>  %if %0 = 4
   994                              <1>  mov edx, %4
   995                              <1>  %endif
   996                              <1>  %endif
   997                              <1>  %endif
   998 000003EF B803000000          <1>  mov eax, %1
   999                              <1> 
  1000 000003F4 CD40                <1>  int 40h
  1001 000003F6 0F828D000000            	jc      CloseFile
  1002                                  
  1003                                  	; patterns have been loaded here... (04/07/2017)
  1004                                  
  1005 000003FC BE[CE520000]            	mov	esi, Header+ModHeader.mhSamples
  1006 00000401 31FF                    	xor     edi, edi
  1007                                  CopySamples:
  1008 00000403 668B4616                	mov     ax, [esi+ModSample.msLength]
  1009 00000407 86C4                    	xchg    al, ah
  1010 00000409 66D1E0                  	shl     ax, 1
  1011 0000040C 668987[F8570000]        	mov     [ModInfo.SampLen+edi], ax
  1012 00000413 8A4619                  	mov     al, [esi+ModSample.msVolume]
  1013 00000416 30E4                    	xor     ah, ah
  1014 00000418 668987[B2580000]        	mov     [ModInfo.SampVol+edi], ax
  1015 0000041F 668B461A                	mov     ax, [esi+ModSample.msRepeat]
  1016 00000423 86C4                    	xchg    al, ah
  1017 00000425 66D1E0                  	shl     ax, 1
  1018 00000428 668987[36580000]        	mov     [ModInfo.SampRep+edi], ax
  1019 0000042F 668B461C                	mov     ax, [esi+ModSample.msRepLen]
  1020 00000433 86C4                    	xchg    al, ah
  1021 00000435 66D1E0                  	shl     ax, 1
  1022 00000438 668987[74580000]        	mov     [ModInfo.SampRepLen+edi], ax
  1023 0000043F 83C61E                  	add     esi, ModSample.size
  1024 00000442 6683C702                	add     di, 2
  1025 00000446 6683FF3E                	cmp     di, 2*31
  1026 0000044A 72B7                    	jb      short CopySamples
  1027                                  
  1028 0000044C 31F6                    	xor     esi, esi
  1029                                  AllocSamples:
  1030 0000044E 0FB796[F8570000]        	movzx	edx, word [ModInfo.SampLen+esi]
  1031                                  	; 07/10/2017
  1032                                  	;shr	dx, 4 ; ***
  1033 00000455 21D2                    	and	edx, edx
  1034 00000457 7426                    	jz      short NextSample
  1035                                  	;inc	dx  ; number of paragraphs ; ***
  1036                                  	;shl	dx, 4 ; ***
  1037 00000459 89E8                    	mov	eax, ebp
  1038 0000045B 668986[7C570000]        	mov	[ModInfo.SampOfs+esi], ax
  1039 00000462 C1E810                  	shr	eax, 16
  1040 00000465 668986[BA570000]        	mov	[ModInfo.SampSeg+esi], ax
  1041 0000046C 89E9                    	mov	ecx, ebp
  1042 0000046E 01D5                    	add	ebp, edx ; next offset for sample 
  1043                                  ReadSample:
  1044                                  	;mov	ebx, [FileHandle]
  1045                                  	;movzx  edx, [ModInfo.SampLen+esi]
  1046                                  	;mov    ecx, [ModInfo.SampOfs+esi]
  1047                                  
  1048                                  	; ebx = File handle
  1049                                  	; ecx = Buffer address
  1050                                  	; edx = Byte count
  1051                                  	sys	_read, [FileHandle]
  1052                              <1> 
  1053                              <1> 
  1054                              <1> 
  1055                              <1> 
  1056                              <1>  %if %0 >= 2
  1057 00000470 8B1D[B6520000]      <1>  mov ebx, %2
  1058                              <1>  %if %0 >= 3
  1059                              <1>  mov ecx, %3
  1060                              <1>  %if %0 = 4
  1061                              <1>  mov edx, %4
  1062                              <1>  %endif
  1063                              <1>  %endif
  1064                              <1>  %endif
  1065 00000476 B803000000          <1>  mov eax, %1
  1066                              <1> 
  1067 0000047B CD40                <1>  int 40h
  1068 0000047D 720A                    	jc      short CloseFile
  1069                                  
  1070                                  NextSample:
  1071 0000047F 6683C602                	add     si, 2
  1072 00000483 6683FE3E                	cmp     si, 2*31
  1073 00000487 72C5                    	jb      short AllocSamples
  1074                                  CloseFile:      
  1075 00000489 9C                      	pushf
  1076                                  	sys	_close, [FileHandle]
  1077                              <1> 
  1078                              <1> 
  1079                              <1> 
  1080                              <1> 
  1081                              <1>  %if %0 >= 2
  1082 0000048A 8B1D[B6520000]      <1>  mov ebx, %2
  1083                              <1>  %if %0 >= 3
  1084                              <1>  mov ecx, %3
  1085                              <1>  %if %0 = 4
  1086                              <1>  mov edx, %4
  1087                              <1>  %endif
  1088                              <1>  %endif
  1089                              <1>  %endif
  1090 00000490 B806000000          <1>  mov eax, %1
  1091                              <1> 
  1092 00000495 CD40                <1>  int 40h
  1093 00000497 9D                      	popf
  1094                                  Failed:       
  1095 00000498 61                      	popad
  1096 00000499 C3                      	retn
  1097                                  
  1098                                  FreeModule:
  1099                                  	; Erdogan Tan (13/02/2017)
  1100                                  	; nothing to do here for memory de-allocation
  1101                                  ClearModInfo:
  1102 0000049A 57                      	push	edi
  1103 0000049B BF[F6560000]            	mov	edi, ModInfo
  1104 000004A0 B9FA010000              	mov     ecx, ModInfoRec.size
  1105                                  	;cld
  1106 000004A5 30C0                    	xor     al, al
  1107 000004A7 F3AA                    	rep     stosb
  1108 000004A9 5F                      	pop	edi
  1109 000004AA C3                      	retn
  1110                                  
  1111                                  ;=============================================================================
  1112                                  ;               MODPLAY.ASM
  1113                                  ;=============================================================================
  1114                                  
  1115                                  ; Amiga Module Loader v0.3b by Carlos Hasan.
  1116                                  ;	July 23th, 1993.
  1117                                  
  1118                                  ; EQUATES
  1119                                  
  1120                                  ;NumTracks	equ 4 ; 07/10/2017 ([numtracks])
  1121                                  DefTempo        equ 6
  1122                                  DefBpm          equ 125
  1123                                  MidCRate        equ 8448
  1124                                  MixBufSize	equ 4096
  1125                                  ;MixBufSize	equ 7680 ; 17/10/2017 ; ((48000/50)*8)
  1126                                  
  1127                                  ; STRUCTURES
  1128                                  
  1129                                  struc TrackInfo  ; 01/10/2017 (TMODPLAY.ASM) modif. by Erdogan Tan
  1130 00000000 <res 00000004>          .Samples:	resd 1
  1131                                  ;.Position:	resw 1
  1132 00000004 <res 00000004>          .Position:	resd 1 ; 01/10/2017 - TRDOS 386 modification ! 
  1133 00000008 <res 00000002>          .Len:		resw 1
  1134 0000000A <res 00000002>          .Repeat:	resw 1
  1135 0000000C <res 00000002>          .RepLen:	resw 1
  1136 0000000E <res 00000001>          .Volume: 	resb 1 ; Volume
  1137 0000000F <res 00000001>          .VolDiff:	resb 1 ; 01/10/2017 ; Volume difference (Tremolo)
  1138                                  ;.Error:	resb 1
  1139                                  ;.Reserved:	resb 1 ; 01/10/2017
  1140 00000010 <res 00000002>          .Period:	resw 1 ; Period
  1141 00000012 <res 00000002>          .Pitch:		resw 1 
  1142 00000014 <res 00000002>          .Effect:	resw 1 ; Effect
  1143 00000016 <res 00000002>          .PortTo:	resw 1 ; Toneporta wanted period
  1144 00000018 <res 00000001>          .PortParm:	resb 1 ; Toneporta speed
  1145 00000019 <res 00000001>          .VibPos:	resb 1 ; Vibrato wave position 
  1146 0000001A <res 00000001>          .VibParm:	resb 1 ; Vibrato depth/rate
  1147 0000001B <res 00000001>          .TremPos:	resb 1 ; 01/10/2017 ; Tremolo wave position
  1148 0000001C <res 00000001>          .TremParm:	resb 1 ; 01/10/2017 ; Tremolo depth/rate
  1149                                  ;.OldSampOfs:	resb 1 ; ******* ; 01/10/2017
  1150 0000001D <res 00000001>          .Error:		resb 1 ; 01/10/2017
  1151 0000001E <res 00000006>          .Arp:		resw 3
  1152 00000024 <res 00000002>          .ArpIndex:	resw 1
  1153                                  .size:		; 38 bytes ; 01/10/2017 -  TRDOS 386
  1154                                  endstruc
  1155                                  
  1156                                  ; CODE
  1157                                  
  1158                                  ;--------------------------------------------------------------------------
  1159                                  ; updatechannel - update the track using the current effect
  1160                                  ;--------------------------------------------------------------------------
  1161                                  ; 
  1162                                  ;--------------------------------------------------------------------------
  1163                                  ; 	Track:  Process the next 	 in one track.
  1164                                  ;  In:
  1165                                  ;    ds:di -  Track info Address.
  1166                                  ;--------------------------------------------------------------------------
  1167                                  
  1168                                  ; edi = Track info address
  1169                                  
  1170                                  updatechannel:
  1171                                  BeatTrack:	; updatechannel ; 01/10/2017 (TMODPLAY.ASM)
  1172                                  
  1173 000004AB 668B5714                	mov     dx, [edi+TrackInfo.Effect]
  1174                                  
  1175                                  	;test   dx, dx
  1176                                  	;je     short None
  1177                                  	;cmp    dh, 00h
  1178                                  	;je     short Arpeggio
  1179                                  	;cmp    dh, 01h
  1180                                  	;je     short PortUp
  1181                                  	;cmp    dh, 02h
  1182                                  	;je     short PortDown
  1183                                  	;cmp    dh, 03h
  1184                                  	;je     TonePort
  1185                                  	;cmp    dh, 04h
  1186                                  	;je     Vibrato
  1187                                  	;cmp    dh, 05h
  1188                                  	;je     PortSlide
  1189                                  	;cmp    dh, 06h
  1190                                  	;je     VibSlide
  1191                                  	;cmp    dh, 0Ah
  1192                                  	;je     VolSlide
  1193                                  	;retn
  1194                                  
  1195 000004AF 0FB6C6                  	movzx	eax, dh
  1196 000004B2 240F                    	and	al, 0Fh
  1197 000004B4 FF2485[00500000]        	jmp	dword [4*eax+efxtable2] ; TRDOS 386 ! (32 bits)
  1198                                  efxnull:
  1199                                  None:           
  1200 000004BB C3                      	retn
  1201                                  efxarpeggio2:
  1202                                  	; 01/10/2017
  1203 000004BC 84D2                    	test    dl, dl
  1204 000004BE 74FB                    	jz      short efxnull
  1205                                  Arpeggio:
  1206 000004C0 0FB75F24                	movzx   ebx, word [edi+TrackInfo.ArpIndex]
  1207 000004C4 668B441F1E              	mov     ax, [edi+TrackInfo.Arp+ebx]
  1208 000004C9 66894712                	mov     [edi+TrackInfo.Pitch], ax
  1209 000004CD 6683C302                	add     bx, 2
  1210 000004D1 6683FB06                	cmp     bx, 6
  1211 000004D5 7202                    	jb      short SetArpIndex
  1212 000004D7 31DB                    	xor     ebx, ebx
  1213                                  SetArpIndex:
  1214 000004D9 66895F24                	mov     [edi+TrackInfo.ArpIndex], bx
  1215 000004DD C3                      	retn
  1216                                  efxportaup:
  1217                                  PortUp:
  1218 000004DE 30F6                    	xor     dh, dh
  1219                                  	;mov	bx, [edi+TrackInfo.Period]
  1220 000004E0 0FB75F10                	movzx	ebx, word [edi+TrackInfo.Period] ; 02/10/2017
  1221 000004E4 6629D3                  	sub     bx, dx
  1222                                  	;cmp	bx, 113
  1223 000004E7 6683FB1C                	cmp	bx, 28 ; 01/10/2017 
  1224 000004EB 7D04                    	jge     short NotSmall
  1225                                  	;mov	bx, 113
  1226 000004ED 66BB1C00                	mov	bx, 28 ; 01/10/2017
  1227                                  NotSmall:
  1228 000004F1 66895F10                	mov     [edi+TrackInfo.Period], bx
  1229 000004F5 6601DB                  	add     bx, bx
  1230                                  	;mov	ax, [PitchTable+bx]
  1231 000004F8 668B83[F0580000]        	mov	ax, [PitchTable+ebx]  ; 02/10/2017
  1232 000004FF 66894712                	mov     [edi+TrackInfo.Pitch], ax
  1233 00000503 C3                      	retn
  1234                                  efxportadown:
  1235                                  PortDown:
  1236 00000504 30F6                    	xor     dh, dh
  1237                                  	;mov	bx, [edi+TrackInfo.Period]
  1238 00000506 0FB75F10                	movzx	ebx, word [edi+TrackInfo.Period] ; 02/10/2017
  1239 0000050A 6601D3                  	add     bx, dx
  1240 0000050D 6681FB600D              	cmp	bx, 3424 ; 01/10/2017 
  1241                                  	;cmp	bx, 856
  1242 00000512 7E04                    	jle     short NotBig
  1243                                  	;mov	bx, 856
  1244 00000514 66BB600D                	mov	bx, 3424 ; 01/10/2017
  1245                                  NotBig:         
  1246 00000518 66895F10                	mov     [edi+TrackInfo.Period], bx
  1247 0000051C 6601DB                  	add     bx, bx
  1248                                  	;mov	ax, [PitchTable+bx]
  1249 0000051F 668B83[F0580000]        	mov	ax, [PitchTable+ebx]  ; 02/10/2017
  1250 00000526 66894712                	mov     [edi+TrackInfo.Pitch], ax
  1251 0000052A C3                      	retn
  1252                                  efxtoneporta2:
  1253                                  TonePort:
  1254 0000052B 30F6                    	xor     dh, dh
  1255 0000052D 668B4716                	mov     ax, [edi+TrackInfo.PortTo]
  1256                                  	;mov	bx, [edi+TrackInfo.Period]
  1257 00000531 0FB75F10                	movzx	ebx, word [edi+TrackInfo.Period] ; 02/10/2017
  1258 00000535 6639C3                  	cmp     bx, ax
  1259 00000538 7429                    	je      short NoPort
  1260 0000053A 7F0D                    	jg      short PortToUp
  1261                                  PortToDown:     
  1262 0000053C 6601D3                  	add     bx, dx
  1263 0000053F 6639C3                  	cmp     bx, ax
  1264 00000542 7E0D                    	jle     short SetPort
  1265                                  FixPort:        
  1266 00000544 6689C3                  	mov     bx, ax
  1267 00000547 EB08                    	jmp     short SetPort
  1268                                  PortToUp:
  1269 00000549 6629D3                  	sub     bx, dx
  1270 0000054C 6639C3                  	cmp     bx, ax
  1271 0000054F 7CF3                    	jl      short FixPort
  1272                                  SetPort:        
  1273 00000551 66895F10                	mov     [edi+TrackInfo.Period], bx
  1274 00000555 6601DB                  	add     bx, bx
  1275                                  	;mov	ax, [PitchTable+bx]
  1276 00000558 668B83[F0580000]        	mov	ax, [PitchTable+ebx]  ; 02/10/2017
  1277 0000055F 66894712                	mov     [edi+TrackInfo.Pitch], ax
  1278                                  NoPort:         
  1279 00000563 C3                      	retn
  1280                                  efxvibrato2:
  1281                                  	; 01/10/2017
  1282                                  Vibrato:
  1283 00000564 88D6                    	mov     dh, dl
  1284                                  	;and	dl, 0Fh
  1285                                  	;shr	dh, 4
  1286                                  	;shl	dh, 2
  1287 00000566 6681E20FF0              	and     dx, 0F00Fh
  1288 0000056B C0EE02                  	shr     dh, 2
  1289                                  	;add	[edi+TrackInfo.VibPos], dh
  1290                                  	;mov	dh, [edi+TrackInfo.VibPos]
  1291                                  	;mov	bl, dh
  1292 0000056E 8A5F19                  	mov	bl, [edi+TrackInfo.VibPos]  ; 01/10/2017
  1293 00000571 007719                  	add	[edi+TrackInfo.VibPos], dh
  1294 00000574 88DE                    	mov	dh, bl ; 01/10/2017
  1295 00000576 C0EB02                  	shr     bl, 2
  1296                                  	;and	bx, 1Fh
  1297                                  	;mov	al, [SinTable+bx]
  1298 00000579 83E31F                  	and	ebx, 1Fh
  1299 0000057C 8A83[E8500000]          	mov	al, [SinTable+ebx]
  1300 00000582 F6E2                    	mul     dl
  1301                                  	;rol	ax, 1
  1302                                  	;xchg	al, ah
  1303                                  	;and	ah, 1
  1304 00000584 66C1E807                	shr	ax, 7
  1305 00000588 84F6                    	test    dh, dh
  1306 0000058A 7903                    	jns     short VibUp
  1307 0000058C 66F7D8                  	neg     ax
  1308                                  VibUp:          
  1309 0000058F 66034710                	add     ax, [edi+TrackInfo.Period]
  1310 00000593 6689C3                  	mov	bx, ax
  1311                                  	;movzx	ebx, ax
  1312 00000596 6683FB71                	cmp     bx, 113
  1313                                  	;cmp	bx, 113
  1314 0000059A 6683FB1C                	cmp	bx, 28  ; 01/10/2017
  1315 0000059E 7D06                    	jge     short NoLoVib
  1316                                  	;mov	bx, 113
  1317 000005A0 66BB1C00                	mov	bx, 28	; 01/10/2017
  1318 000005A4 EB0B                    	jmp	short NoHiVib ; 01/10/2017	
  1319                                  NoLoVib:        
  1320 000005A6 6681FB600D              	cmp	bx, 3424 ; 01/10/2017 
  1321                                  	;cmp	bx, 856
  1322 000005AB 7E04                    	jle     short NoHiVib
  1323                                  	;mov	bx, 856
  1324 000005AD 66BB600D                	mov	bx, 3424 ; 01/10/2017
  1325                                  NoHiVib:        
  1326 000005B1 6601DB                  	add     bx, bx
  1327                                  	;mov	ax, [PitchTable+bx]
  1328 000005B4 668B83[F0580000]        	mov	ax, [PitchTable+ebx] ; 01/10/2017
  1329 000005BB 66894712                	mov     [edi+TrackInfo.Pitch], ax
  1330 000005BF C3                      	retn
  1331                                  efxtoneslide:
  1332                                  PortSlide:
  1333 000005C0 E812000000              	call    VolSlide
  1334 000005C5 8A5718                  	mov     dl, [edi+TrackInfo.PortParm]  ; .tonespeed
  1335 000005C8 E95EFFFFFF              	jmp     TonePort  ; efxtoneporta2
  1336                                  efxvibslide:
  1337                                  VibSlide:
  1338 000005CD E805000000              	call    VolSlide
  1339 000005D2 8A571A                  	mov     dl, [edi+TrackInfo.VibParm]
  1340 000005D5 EB8D                    	jmp     short Vibrato  ; efxvibrato2
  1341                                  efxvolslide:
  1342                                  VolSlide:
  1343 000005D7 88D6                    	mov     dh, dl
  1344 000005D9 80E20F                  	and     dl, 0Fh
  1345 000005DC C0EE04                  	shr     dh, 4
  1346 000005DF 8A470E                  	mov     al, [edi+TrackInfo.Volume]
  1347 000005E2 28D0                    	sub     al, dl
  1348 000005E4 7D02                    	jge     short NoLoVol
  1349 000005E6 30C0                    	xor     al, al
  1350                                  NoLoVol:        
  1351 000005E8 00F0                    	add     al, dh
  1352 000005EA 3C40                    	cmp     al, 64
  1353 000005EC 7602                    	jbe     short NoHiVol
  1354 000005EE B040                    	mov     al, 64
  1355                                  NoHiVol:        
  1356 000005F0 88470E                  	mov     [edi+TrackInfo.Volume], al
  1357 000005F3 C3                      	retn
  1358                                  
  1359                                  efxtremolo2:
  1360                                  	; 01/10/2017 (TMODPLAY.ASM)
  1361                                  Tremolo:
  1362 000005F4 88D6                    	mov     dh, dl
  1363 000005F6 6681E20FF0              	and     dx, 0F00Fh
  1364 000005FB C0EE02                  	shr     dh, 2
  1365 000005FE 8A5F1B                  	mov	bl, [edi+TrackInfo.TremPos]
  1366 00000601 00771B                  	add	[edi+TrackInfo.TremPos], dh
  1367 00000604 88DE                    	mov	dh, bl
  1368 00000606 C0EB02                  	shr     bl, 2
  1369                                  	; 01/10/2017 - TRDOS 386
  1370                                  	;and	bx, 1Fh
  1371 00000609 83E31F                  	and	ebx, 1Fh 
  1372                                  	;mov	al, [SinTable+bx]
  1373 0000060C 8A83[E8500000]          	mov     al, [SinTable+ebx]
  1374 00000612 F6E2                    	mul     dl
  1375 00000614 66C1E806                	shr	ax, 6
  1376 00000618 84F6                    	test    dh, dh
  1377 0000061A 7D03                    	jge	short Tremolo_1 ; efxtremolof2
  1378 0000061C 66F7D8                  	neg     ax
  1379                                  efxtremolof2:
  1380                                  Tremolo_1:      
  1381 0000061F 8A670E                  	mov	ah, [edi+TrackInfo.Volume]    
  1382 00000622 00E0                    	add     al, ah
  1383 00000624 7D02                    	jge     short Tremolo_2 ; efxtremolof3
  1384 00000626 30C0                    	xor     al, al
  1385                                  efxtremolof3:
  1386                                  Tremolo_2:       
  1387 00000628 3C40                    	cmp     al, 64 ; 40h
  1388 0000062A 7E02                    	jle     short Tremolo_3 ; efxtremolof4
  1389 0000062C B040                    	mov     al, 64 ; 40h
  1390                                  efxtremolof4:
  1391                                  Tremolo_3:       
  1392 0000062E 28E0                    	sub	al, ah  ; ****** 
  1393 00000630 88470F                  	mov     [edi+TrackInfo.VolDiff], al
  1394 00000633 C3                      	retn	
  1395                                  
  1396                                  ;--------------------------------------------------------------------------
  1397                                  ; readchannel - read the next note event from the pattern sheet
  1398                                  ;--------------------------------------------------------------------------
  1399                                  ;
  1400                                  ;--------------------------------------------------------------------------
  1401                                  ; GetTrack:   Get the next Note from a pattern.
  1402                                  ;  In:
  1403                                  ;    ds:di -  Track info Address.
  1404                                  ;    es:si -  Pattern Note Address.
  1405                                  ; Out:
  1406                                  ;    es:si -  The Next Pattern Note address.
  1407                                  ;--------------------------------------------------------------------------
  1408                                  
  1409                                  ; esi = Pattern note address
  1410                                  ; edi = Track info address
  1411                                  
  1412                                  readchannel:
  1413                                  GetTrack: 	; readchannel ; 01/10/2017 (TMODPLAY.ASM)
  1414 00000634 66AD                    	lodsw
  1415 00000636 86C4                    	xchg    al, ah
  1416 00000638 88E3                    	mov	bl, ah
  1417 0000063A 80E40F                  	and     ah, 0Fh
  1418 0000063D 6689C1                  	mov     cx, ax
  1419 00000640 66AD                    	lodsw
  1420 00000642 86C4                    	xchg    al, ah
  1421 00000644 88E7                    	mov     bh, ah
  1422 00000646 80E40F                  	and     ah, 0Fh
  1423 00000649 6689C2                  	mov     dx, ax
  1424 0000064C 66895714                	mov     [edi+TrackInfo.Effect], dx
  1425                                  	; 01/10/2017 - TRDOS 386
  1426                                  	;and	bl, 0F0h
  1427 00000650 81E3F0FF0000            	and	ebx, 0FFF0h
  1428 00000656 C0EF04                  	shr     bh, 4
  1429 00000659 08FB                    	or      bl, bh
  1430 0000065B 7446                    	jz      short SetPeriod
  1431                                  SetSample:
  1432 0000065D 30FF                    	xor	bh, bh
  1433                                  	;and	ebx, 0FFh
  1434 0000065F FECB                    	dec     bl
  1435 00000661 01DB                    	add     ebx, ebx
  1436 00000663 668B83[B2580000]        	mov     ax, [ModInfo.SampVol+ebx]
  1437 0000066A 88470E                  	mov     [edi+TrackInfo.Volume], al
  1438 0000066D 668B83[7C570000]        	mov     ax, [ModInfo.SampOfs+ebx]
  1439 00000674 668907                  	mov     [edi+TrackInfo.Samples], ax
  1440 00000677 668B83[BA570000]        	mov     ax, [ModInfo.SampSeg+ebx]
  1441 0000067E 66894702                	mov     [edi+TrackInfo.Samples+2], ax
  1442 00000682 668B83[F8570000]        	mov     ax, [ModInfo.SampLen+ebx]
  1443 00000689 66894708                	mov     [edi+TrackInfo.Len], ax
  1444 0000068D 668B83[36580000]        	mov     ax, [ModInfo.SampRep+ebx]
  1445 00000694 6689470A                	mov     [edi+TrackInfo.Repeat], ax
  1446 00000698 668B83[74580000]        	mov     ax, [ModInfo.SampRepLen+ebx]
  1447 0000069F 6689470C                	mov     [edi+TrackInfo.RepLen], ax
  1448                                  SetPeriod:      
  1449 000006A3 6685C9                  	test    cx, cx
  1450 000006A6 7425                    	jz      short SetEffect
  1451                                  
  1452 000006A8 66894F16                	mov     [edi+TrackInfo.PortTo], cx ; *
  1453                                  	
  1454 000006AC 80FE03                  	cmp     dh, 03h
  1455                                  	;je	short SetEffect
  1456 000006AF 7428                    	je	short efxtoneporta ; 01/10/2017
  1457                                  
  1458 000006B1 66894F10                	mov     [edi+TrackInfo.Period], cx
  1459                                  	;movzx	ebx, cx
  1460 000006B5 6689CB                  	mov     bx, cx
  1461 000006B8 6601DB                  	add     bx, bx
  1462                                  	;mov	ax, [PitchTable+bx]
  1463 000006BB 668B83[F0580000]        	mov	ax, [PitchTable+ebx] ; 01/10/2017
  1464 000006C2 66894712                	mov     [edi+TrackInfo.Pitch], ax
  1465 000006C6 C7470400000000          	mov     dword [edi+TrackInfo.Position], 0
  1466                                  SetEffect:
  1467                                  	;test	dx, dx
  1468                                  	;je	short InitNone
  1469                                  	;cmp	dh, 00h
  1470                                  	;je	InitArpeggio
  1471                                  	;cmp	dh, 03h
  1472                                  	;je	short InitTonePort
  1473                                  	;cmp	dh, 04h
  1474                                  	;je	short InitVibrato
  1475                                  	;cmp	dh, 09h
  1476                                  	;je	short SampleOfs
  1477                                  	;cmp	dh, 0Bh
  1478                                  	;je	short PosJump
  1479                                  	;cmp	dh, 0Ch
  1480                                  	;je	short SetVolume
  1481                                  	;cmp	dh, 0Dh
  1482                                  	;je	short Break
  1483                                  	;cmp	dh, 0Fh
  1484                                  	;je	SetSpeed
  1485                                  	;retn
  1486                                  
  1487                                  	; 01/10/2017 (TMODPLAY.ASM)
  1488                                  	
  1489                                  	; dx = [di+TrackInfo.Effect]
  1490                                  	
  1491 000006CD 0FB6C6                  	movzx	eax, dh
  1492 000006D0 240F                    	and	al, 0Fh
  1493 000006D2 FF2485[C04F0000]        	jmp	dword [4*eax+efxtable] ; TRDOS 386 ! (32 bits)
  1494                                  ;efxnull:
  1495                                  ;InitNone:
  1496                                  ;	retn
  1497                                  efxtoneporta:
  1498                                  	; 01/10/2017
  1499                                  	; cx = period
  1500                                  	;mov	[edi+TrackInfo.PortTo], cx ; *
  1501                                  InitTonePort:
  1502 000006D9 84D2                    	test    dl, dl
  1503 000006DB 7503                    	jnz     short SetPortParm
  1504 000006DD 8A5718                  	mov     dl, [edi+TrackInfo.PortParm] ; .tonespeed
  1505                                  SetPortParm:    
  1506 000006E0 885718                  	mov     [edi+TrackInfo.PortParm], dl
  1507 000006E3 66895714                	mov     [edi+TrackInfo.Effect], dx
  1508 000006E7 C3                      	retn
  1509                                  efxvibrato:
  1510                                  InitVibrato:
  1511 000006E8 8A471A                  	mov     al, [edi+TrackInfo.VibParm]
  1512 000006EB 88C4                    	mov     ah, al
  1513                                  	;and	al, 0Fh
  1514                                  	;and	ah, 0F0h
  1515 000006ED 66250FF0                	and	ax, 0F00Fh
  1516 000006F1 F6C20F                  	test    dl, 0Fh
  1517 000006F4 7502                    	jne     short OkDepth
  1518 000006F6 08C2                    	or      dl, al
  1519                                  OkDepth:        
  1520 000006F8 F6C2F0                  	test    dl, 0F0h
  1521 000006FB 7502                    	jnz     short OkRate
  1522 000006FD 08E2                    	or      dl, ah
  1523                                  OkRate:         
  1524 000006FF 88571A                  	mov     [edi+TrackInfo.VibParm], dl
  1525 00000702 66895714                	mov     [edi+TrackInfo.Effect], dx
  1526 00000706 6685C9                  	test    cx, cx
  1527 00000709 7404                    	jz      short OkPos
  1528 0000070B C6471900                	mov     byte [edi+TrackInfo.VibPos], 0
  1529                                  OkPos:          
  1530 0000070F C3                      	retn
  1531                                  efxsampoffset:
  1532                                  	; 01/10/2017 ; *******
  1533                                  SampleOfs:         
  1534                                  ;	test    dl, dl
  1535                                  ;	jnz     short SetSampleOfs
  1536                                  ;	mov     dl, [edi+TrackInfo.OldSampOfs]
  1537                                  ;SetSampleOfs:
  1538                                  ;	mov     [edi+TrackInfo.OldSampOfs], dl
  1539 00000710 88D6                    	mov     dh, dl
  1540 00000712 81E200FF0000            	and 	edx, 0FF00h ; 05/03/2017
  1541 00000718 895704                  	mov     [edi+TrackInfo.Position], edx
  1542 0000071B C3                      	retn
  1543                                  efxpattjump:
  1544                                  PosJump:
  1545 0000071C 8815[9ED40000]          	mov     [OrderPos], dl
  1546 00000722 C605[A2D40000]40        	mov     byte [Row], 64
  1547 00000729 C3                      	retn
  1548                                  efxsetvolume:
  1549                                  SetVolume:
  1550 0000072A 80FA40                  	cmp     dl, 64
  1551 0000072D 7602                    	jbe     short OkVol
  1552 0000072F B240                    	mov     dl, 64
  1553                                  OkVol:
  1554                                  	; 01/10/2017 (TrackInfo.VolDiff, tremolo effect)
  1555 00000731 30F6                    	xor	dh, dh ; reset TrackInfo.VolDiff ; Not necessary !?
  1556                                  	;mov	[edi+TrackInfo.Volume], dl
  1557 00000733 6689570E                	mov	[edi+TrackInfo.Volume], dx 
  1558 00000737 C3                      	retn
  1559                                  efxbreak:
  1560                                  Break:
  1561 00000738 88D6                    	mov     dh, dl
  1562 0000073A 80E20F                  	and     dl, 0Fh
  1563 0000073D C0EE04                  	shr     dh, 4
  1564 00000740 00F6                    	add     dh, dh
  1565 00000742 00F2                    	add     dl, dh
  1566 00000744 C0E602                  	shl     dh, 2
  1567 00000747 00F2                    	add     dl, dh
  1568 00000749 8815[A3D40000]          	mov     [BreakRow], dl
  1569 0000074F C605[A2D40000]40        	mov     byte [Row], 64
  1570 00000756 C3                      	retn
  1571                                  efxsetspeed:
  1572                                  SetSpeed:
  1573 00000757 84D2                    	test    dl,dl
  1574 00000759 7432                    	je      Skip
  1575 0000075B 80FA1F                  	cmp     dl,31
  1576 0000075E 770D                    	ja      short SetBpm
  1577                                  SetTempo:       
  1578 00000760 8815[9FD40000]          	mov     [Tempo], dl
  1579 00000766 8815[A0D40000]          	mov     [TempoWait], dl
  1580 0000076C C3                      	retn
  1581                                  SetBpm:
  1582 0000076D 8815[A1D40000]          	mov     [Bpm], dl
  1583 00000773 B067                    	mov     al, 103
  1584 00000775 F6E2                    	mul     dl
  1585 00000777 88E3                    	mov     bl, ah
  1586 00000779 30FF                    	xor     bh, bh
  1587 0000077B 66A1[EA510000]          	mov     ax, [MixSpeed]
  1588 00000781 6631D2                  	xor     dx, dx
  1589 00000784 66F7F3                  	div     bx
  1590 00000787 66A3[A4D40000]          	mov     [BpmSamples], ax
  1591                                  Skip:           
  1592 0000078D C3                      	retn
  1593                                  efxarpeggio:
  1594                                  	; 01/10/2017
  1595 0000078E 84D2                    	test    dl, dl
  1596                                  	;je	efxnull
  1597 00000790 74FB                    	je	short Skip
  1598                                  InitArpeggio:
  1599 00000792 88D6                    	mov     dh, dl
  1600 00000794 80E20F                  	and     dl, 0Fh
  1601 00000797 C0EE04                  	shr     dh, 4
  1602                                  	; 01/10/2017
  1603                                  	;mov	cx, 36
  1604 0000079A 66B95400                	mov	cx, 84 ; 84 notes/periods
  1605 0000079E 31DB                    	xor     ebx, ebx
  1606 000007A0 668B4710                	mov     ax, [edi+TrackInfo.Period]
  1607                                  gt_ScanPeriod:
  1608                                  	;cmp	ax, [PeriodTable+bx]
  1609 000007A4 663B83[40500000]        	cmp	ax, [PeriodTable+ebx]
  1610 000007AB 7306                    	jae     short SetArp
  1611 000007AD 6683C302                	add     bx, 2
  1612 000007B1 E2F1                    	loop    gt_ScanPeriod
  1613                                  SetArp:         
  1614 000007B3 6601D2                  	add     dx, dx
  1615 000007B6 00DE                    	add     dh, bl
  1616 000007B8 00DA                    	add     dl, bl
  1617                                  	; 01/10/2017
  1618                                  	;mov	bx, [PeriodTable+bx]
  1619 000007BA 668B9B[40500000]        	mov	bx, [PeriodTable+ebx]
  1620                                  	;add	bx, bx
  1621 000007C1 01DB                    	add	ebx, ebx
  1622                                  	;mov	ax, [PitchTable+bx]
  1623 000007C3 668B83[F0580000]        	mov	ax, [PitchTable+ebx]
  1624 000007CA 6689471E                	mov     [edi+TrackInfo.Arp], ax
  1625 000007CE 88F3                    	mov     bl, dh
  1626 000007D0 30FF                    	xor     bh, bh
  1627 000007D2 668B9B[40500000]        	mov	bx, [PeriodTable+ebx]
  1628                                  	;add	bx, bx
  1629 000007D9 01DB                    	add	ebx, ebx
  1630                                  	;mov	ax, [PitchTable+bx]
  1631 000007DB 668B83[F0580000]        	mov	ax, [PitchTable+ebx]
  1632 000007E2 66894720                	mov     [edi+TrackInfo.Arp+2], ax
  1633 000007E6 88D3                    	mov     bl, dl
  1634 000007E8 30FF                    	xor     bh, bh
  1635 000007EA 668B9B[40500000]        	mov	bx, [PeriodTable+ebx]
  1636                                  	;add	bx, bx
  1637 000007F1 01DB                    	add	ebx, ebx
  1638                                  	;mov	ax, [PitchTable+bx]
  1639 000007F3 668B83[F0580000]        	mov	ax, [PitchTable+ebx]
  1640 000007FA 66894722                	mov     [edi+TrackInfo.Arp+4], ax
  1641 000007FE 66C747240000            	mov     word [edi+TrackInfo.ArpIndex], 0
  1642 00000804 C3                      	retn
  1643                                  
  1644                                  efxtremolo:
  1645                                  	; 01/10/2017 (TMODPLAY.ASM)
  1646                                  InitTremolo:
  1647 00000805 8A471C                  	mov     al, [edi+TrackInfo.TremParm]
  1648 00000808 88C4                    	mov     ah, al
  1649 0000080A 66250FF0                	and     ax, 0F00Fh
  1650 0000080E F6C20F                  	test    dl, 0Fh
  1651 00000811 7502                    	jnz     short InitTremolo_1 ; efxtremolof0
  1652 00000813 08C2                    	or      dl, al
  1653                                  efxtremolof0:
  1654                                  InitTremolo_1: 
  1655 00000815 F6C2F0                  	test    dl, 0F0h
  1656 00000818 7502                    	jnz     short InitTremolo_2 ; efxtremolof1
  1657 0000081A 08E2                    	or      dl, ah
  1658                                  efxtremolof1:
  1659                                  InitTremolo_2:
  1660 0000081C 88571C                  	mov     [edi+TrackInfo.TremParm], dl
  1661 0000081F 66895714                	mov     [edi+TrackInfo.Effect], dx
  1662 00000823 C3                      	retn
  1663                                  
  1664                                  ;--------------------------------------------------------------------------
  1665                                  ; pollmodule - polls the module player
  1666                                  ;--------------------------------------------------------------------------
  1667                                  ;--------------------------------------------------------------------------
  1668                                  ; UpdateTracks:  Main code to process the next tick to be played.
  1669                                  ;--------------------------------------------------------------------------
  1670                                  
  1671                                  pollmodule:
  1672                                  UpdateTracks:	; polmodule ; 01/10/2017 (TMODPLAY.ASM)
  1673 00000824 FE0D[A0D40000]          	dec     byte [TempoWait]
  1674 0000082A 7417                    	jz      short GetTracks
  1675                                  
  1676                                  	;mov	ecx, NumTracks
  1677 0000082C 0FB70D[E4510000]        	movzx	ecx, word [numtracks] ; 06/10/2017
  1678 00000833 BF[B4D40000]            	mov	edi, Tracks
  1679                                  BeatTracks:
  1680 00000838 E86EFCFFFF              	call	BeatTrack	
  1681 0000083D 83C726                  	add	edi, TrackInfo.size
  1682 00000840 E2F6                    	loop	BeatTracks
  1683 00000842 C3                      	retn
  1684                                  GetTracks:
  1685 00000843 A0[9FD40000]            	mov     al, [Tempo]
  1686 00000848 A2[A0D40000]            	mov     [TempoWait], al
  1687                                  
  1688 0000084D 8B35[B0D40000]          	mov	esi, [Note]
  1689 00000853 803D[A2D40000]40        	cmp     byte [Row], 64
  1690 0000085A 7268                    	jb      short NoPattWrap
  1691                                  
  1692 0000085C 8B35[78570000]          	mov	esi, [ModInfo.Patterns]
  1693 00000862 8A1D[9ED40000]          	mov     bl, [OrderPos]
  1694 00000868 3A1D[F6560000]          	cmp     bl, [ModInfo.OrderLen]
  1695 0000086E 7214                    	jb      short NoOrderWrap
  1696 00000870 8A1D[F7560000]          	mov     bl, [ModInfo.ReStart]
  1697 00000876 881D[9ED40000]          	mov     [OrderPos], bl
  1698 0000087C 3A1D[F6560000]          	cmp     bl, [ModInfo.OrderLen]
  1699 00000882 7364                    	jae     short NoUpdate
  1700                                  NoOrderWrap:    
  1701                                  	;xor	bh, bh
  1702 00000884 81E3FF000000            	and	ebx, 0FFh
  1703 0000088A 8A9B[F8560000]          	mov     bl, [ModInfo.Order+ebx]
  1704                                  	; 05/10/2017
  1705                                  	;shl	ebx, 10 ; *1024
  1706 00000890 8A0D[E3510000]          	mov	cl, [pattern_shift] ; 10 or 11
  1707 00000896 D3E3                    	shl	ebx, cl ; *1024 or *2048
  1708                                  	;
  1709 00000898 01DE                    	add     esi, ebx
  1710 0000089A 8A1D[A3D40000]          	mov     bl, [BreakRow]
  1711 000008A0 881D[A2D40000]          	mov     [Row], bl
  1712                                  	;xor	bh, bh
  1713 000008A6 81E3FF000000            	and	ebx, 0FFh
  1714 000008AC 883D[A3D40000]          	mov     [BreakRow], bh ; 0
  1715 000008B2 66C1E304                	shl     bx, 4
  1716 000008B6 01DE                    	add     esi, ebx
  1717 000008B8 8935[B0D40000]          	mov     [Note], esi
  1718 000008BE FE05[9ED40000]          	inc     byte [OrderPos]
  1719                                  NoPattWrap:     
  1720 000008C4 FE05[A2D40000]          	inc     byte [Row]
  1721                                  
  1722                                  	;cld
  1723                                  	;mov	ecx, NumTracks
  1724 000008CA 0FB70D[E4510000]        	movzx	ecx, word [numtracks] ; 06/10/2017
  1725 000008D1 BF[B4D40000]            	mov	edi, Tracks
  1726                                  GetTracks_next:
  1727 000008D6 51                      	push	ecx	
  1728 000008D7 E858FDFFFF              	call	GetTrack ; readchannel
  1729 000008DC 59                      	pop	ecx
  1730 000008DD 83C726                  	add	edi, TrackInfo.size
  1731 000008E0 E2F4                    	loop	GetTracks_next
  1732                                  
  1733 000008E2 8935[B0D40000]          	mov     [Note], esi
  1734                                  NoUpdate:
  1735 000008E8 C3                      	retn
  1736                                  
  1737                                  ;--------------------------------------------------------------------------
  1738                                  ; MixTrack:  Mixes one track into a CLEAN buffer.
  1739                                  ;  In:
  1740                                  ;   ds:si -  Track Info Address.
  1741                                  ;   ds:di -  Buffer Address.
  1742                                  ;    cx   -  Buffer Size.
  1743                                  ;--------------------------------------------------------------------------
  1744                                  
  1745                                  ; esi = Track info address
  1746                                  ; edi = Buffer address
  1747                                  ; ecx = Buffer size
  1748                                  
  1749                                  MixTrack:
  1750 000008E9 66837E0C02              	cmp     word [esi+TrackInfo.RepLen], 2
  1751 000008EE 7757                    	ja      short MixLooped
  1752                                  MixNonLooped:   
  1753 000008F0 8B16                    	mov	edx, [esi+TrackInfo.Samples]
  1754 000008F2 8B5E04                  	mov	ebx, [esi+TrackInfo.Position]
  1755 000008F5 0FB76E08                	movzx   ebp, word [esi+TrackInfo.Len]
  1756 000008F9 52                      	push    edx
  1757 000008FA 56                      	push    esi
  1758 000008FB 01D3                    	add     ebx, edx
  1759 000008FD 01D5                    	add     ebp, edx
  1760 000008FF 668B5612                	mov     dx, [esi+TrackInfo.Pitch]
  1761                                  	; 01/10/2017
  1762                                  	;mov	al, [esi+TrackInfo.Volume]
  1763 00000903 668B460E                	mov	ax, [esi+TrackInfo.Volume]
  1764                                  	; ah = [esi+TrackInfo.VolDiff]
  1765 00000907 00E0                    	add	al, ah ; ****** 
  1766 00000909 C6460F00                	mov	byte [esi+TrackInfo.VolDiff], 0
  1767 0000090D 8A661D                  	mov     ah, [esi+TrackInfo.Error]
  1768 00000910 89DE                    	mov     esi, ebx
  1769 00000912 31DB                    	xor	ebx, ebx ; 01/10/2017 ; *
  1770 00000914 88C7                    	mov     bh, al
  1771 00000916 88D0                    	mov     al, dl
  1772 00000918 88F2                    	mov     dl, dh
  1773                                  	;xor	dh, dh
  1774 0000091A 81E2FF000000            	and	edx, 0FFh
  1775                                  nlMixSamp:      
  1776 00000920 39EE                    	cmp     esi, ebp
  1777 00000922 7316                    	jae     short nlMixBye
  1778 00000924 8A1E                    	mov     bl, [esi]
  1779                                  	;mov	bl, [VolTable+bx]
  1780 00000926 8A9B[B2730000]          	mov	bl, [VolTable+ebx] ; 01/10/2017 ; *	
  1781                                  	; 17/10/2017
  1782 0000092C 001F                    	add     [edi], bl
  1783                                  	; 18/10/2017
  1784 0000092E 00C4                    	add     ah, al
  1785 00000930 11D6                    	adc     esi, edx
  1786 00000932 033D[E4510000]          	add	edi, [numtracks]
  1787 00000938 E2E6                    	loop    nlMixSamp
  1788                                  nlMixBye:       
  1789 0000093A 89F3                    	mov     ebx, esi
  1790 0000093C 5E                      	pop     esi
  1791 0000093D 5A                      	pop     edx
  1792 0000093E 29D3                    	sub     ebx, edx
  1793 00000940 895E04                  	mov     [esi+TrackInfo.Position], ebx
  1794 00000943 88661D                  	mov     [esi+TrackInfo.Error], ah
  1795 00000946 C3                      	retn
  1796                                  MixLooped:
  1797 00000947 8B16                    	mov	edx, [esi+TrackInfo.Samples]
  1798 00000949 8B5E04                  	mov	ebx, [esi+TrackInfo.Position]
  1799 0000094C 0FB76E0C                	movzx	ebp, word [esi+TrackInfo.RepLen]
  1800 00000950 892D[ACD40000]          	mov     [BufRep], ebp
  1801                                  	;add	ebp, [esi+TrackInfo.Repeat] ; BUG !
  1802 00000956 66036E0A                	add     bp, [esi+TrackInfo.Repeat] ; 07/10/2017 (BUGfix!)
  1803 0000095A 52                      	push    edx
  1804 0000095B 56                      	push    esi
  1805 0000095C 01D3                    	add     ebx, edx
  1806 0000095E 01D5                    	add     ebp, edx
  1807 00000960 668B5612                	mov     dx, [esi+TrackInfo.Pitch]
  1808                                  	; 01/10/2017
  1809                                  	;mov	al, [esi+TrackInfo.Volume]
  1810 00000964 668B460E                	mov	ax, [esi+TrackInfo.Volume]
  1811                                  	; ah = [esi+TrackInfo.VolDiff]
  1812 00000968 00E0                    	add	al, ah ; ****** 
  1813 0000096A C6460F00                	mov	byte [esi+TrackInfo.VolDiff], 0
  1814 0000096E 8A661D                  	mov     ah, [esi+TrackInfo.Error]
  1815                                  	;mov	si, bx
  1816 00000971 89DE                    	mov	esi, ebx ; 04/09/2017
  1817 00000973 31DB                    	xor	ebx, ebx ; 01/10/2017 ; *
  1818 00000975 88C7                    	mov     bh, al
  1819 00000977 88D0                    	mov     al, dl
  1820 00000979 88F2                    	mov     dl, dh
  1821                                  	;xor	dh, dh
  1822 0000097B 81E2FF000000            	and	edx, 0FFh
  1823                                  lpMixSamp:      
  1824 00000981 39EE                    	cmp     esi, ebp
  1825 00000983 7206                    	jb      short lpMixNow
  1826 00000985 2B35[ACD40000]          	sub     esi, [BufRep]
  1827                                  lpMixNow:       
  1828 0000098B 8A1E                    	mov     bl, [esi]
  1829                                  	;mov	bl, [VolTable+bx]
  1830 0000098D 8A9B[B2730000]          	mov	bl, [VolTable+ebx] ; 01/10/2017 ; *
  1831                                  	; 17/10/2017
  1832 00000993 001F                    	add     [edi], bl
  1833                                  	; 18/10/2017
  1834 00000995 00C4                    	add     ah, al
  1835 00000997 11D6                    	adc     esi, edx
  1836 00000999 033D[E4510000]          	add	edi, [numtracks]
  1837 0000099F E2E0                    	loop    lpMixSamp
  1838                                  lpMixBye:       
  1839                                  ;	mov     ebx, esi
  1840                                  ;	pop     esi
  1841                                  ;	pop     edx
  1842                                  ;	sub     ebx, edx
  1843                                  ;	mov     [esi+TrackInfo.Position], ebx
  1844                                  ;	mov     [esi+TrackInfo.Error], ah
  1845                                  ;	retn
  1846 000009A1 EB97                    	jmp	short nlMixBye
  1847                                  
  1848                                  ;--------------------------------------------------------------------------
  1849                                  ; mixpoll - updates the output buffer
  1850                                  ;--------------------------------------------------------------------------
  1851                                  ;
  1852                                  ;--------------------------------------------------------------------------
  1853                                  ; GetSamples:  Returns the next chunk of samples to be played.
  1854                                  ;  In:
  1855                                  ;    Buffer  - Buffer Address.
  1856                                  ;    Count   - Buffer Size.
  1857                                  ;--------------------------------------------------------------------------
  1858                                  
  1859                                  mixpoll:
  1860                                  GetSamples:	; mixpoll ; 01/10/2017 (TMODPLAY.ASM)
  1861                                  	; edi = buffer address
  1862                                  	; ebx = count
  1863                                  
  1864 000009A3 60                      	pushad
  1865                                  
  1866                                  	;cld
  1867                                  NextChunk:      
  1868 000009A4 66833D[AAD40000]00      	cmp     word [BufLen], 0
  1869 000009AC 756B                    	jne     short CopyChunk
  1870                                  
  1871 000009AE 53                      	push    ebx
  1872 000009AF 57                      	push    edi
  1873                                  MixChunk:       
  1874 000009B0 BF[B2B40000]            	mov	edi, MixBuffer
  1875                                  
  1876                                  	; 17/10/2017
  1877 000009B5 0FB70D[A4D40000]        	movzx	ecx, word [BpmSamples]
  1878                                  	;mov	cx, [BpmSamples]
  1879 000009BC 893D[A6D40000]          	mov     [BufPtr], edi
  1880 000009C2 66890D[AAD40000]        	mov	[BufLen], cx
  1881                                  
  1882 000009C9 803D[E4510000]04        	cmp	byte [numtracks], 4
  1883 000009D0 7603                    	jna	short ch_silence
  1884 000009D2 66D1E1                  	shl	cx, 1 
  1885                                  ch_silence:
  1886 000009D5 B880808080              	mov	eax, 80808080h
  1887 000009DA F3AB                    	rep	stosd
  1888                                  
  1889                                  	;mov	cx, NumTracks
  1890                                  	;mov	cl, NumTracks ; 01/10/2017
  1891 000009DC 8A0D[E4510000]          	mov	cl, [numtracks] ; 06/10/2017
  1892 000009E2 BE[8ED40000]            	mov	esi, Tracks - TrackInfo.size
  1893                                  GetSamples_next:
  1894 000009E7 51                      	push	ecx
  1895 000009E8 83C626                  	add	esi, TrackInfo.size
  1896 000009EB 668B0D[AAD40000]        	mov	cx, [BufLen]
  1897 000009F2 8B3D[A6D40000]          	mov	edi, [BufPtr]
  1898 000009F8 E8ECFEFFFF              	call	MixTrack
  1899 000009FD 59                      	pop	ecx
  1900 000009FE FF05[A6D40000]          	inc	dword [BufPtr] ; 18/10/2017
  1901 00000A04 E2E1                    	loop	GetSamples_next
  1902                                  
  1903                                   	; 18/10/2017	
  1904 00000A06 8B1D[E4510000]          	mov	ebx, [numtracks]
  1905 00000A0C 291D[A6D40000]          	sub	dword [BufPtr], ebx
  1906                                  
  1907 00000A12 E80DFEFFFF              	call    UpdateTracks
  1908                                  
  1909 00000A17 5F                      	pop     edi
  1910 00000A18 5B                      	pop     ebx
  1911                                  CopyChunk:      
  1912                                  	;mov	cx, [BufLen]
  1913 00000A19 0FB70D[AAD40000]        	movzx	ecx, word [BufLen]
  1914 00000A20 39D9                    	cmp	ecx, ebx
  1915                                  	;cmp	cx, bx
  1916 00000A22 7602                    	jbe     short MoveChunk
  1917                                  	;mov	cx, bx
  1918 00000A24 89D9                    	mov     ecx, ebx
  1919                                  MoveChunk:
  1920 00000A26 8B35[A6D40000]          	mov     esi, [BufPtr]
  1921 00000A2C 010D[A6D40000]          	add     [BufPtr], ecx
  1922 00000A32 66290D[AAD40000]        	sub     [BufLen], cx
  1923 00000A39 29CB                    	sub     ebx, ecx
  1924                                  	; 17/10/2017 ; STEREO MIXING
  1925                                  	;rep	movsb
  1926                                  	; 18/10/2017
  1927 00000A3B 803D[E4510000]04        	cmp	byte [numtracks], 4
  1928                                  	;jna	short _4_channels_mix
  1929 00000A42 762F                    	jna	_4_channels_mix
  1930                                  	
  1931                                  _8_channels_mix:
  1932                                  	; 18/10/2017
  1933 00000A44 AD                      	lodsd 
  1934 00000A45 89C2                    	mov	edx, eax ; ch1 (al), ch2 (ah)
  1935 00000A47 C1EA10                  	shr	edx, 16 ; ch3 (dl), ch4 (dh)
  1936 00000A4A 00C6                    	add	dh, al ; ch1 + ch4
  1937 00000A4C 00E2                    	add	dl, ah ; ch2 + ch3
  1938                                  
  1939 00000A4E AD                      	lodsd
  1940 00000A4F 00C6                    	add	dh, al ; ch1 + ch4 + ch5
  1941 00000A51 00E2                    	add	dl, ah ; ch2 + ch3 + ch6
  1942 00000A53 C1E810                  	shr	eax, 16 ; ch7 (al), ch8 (ah)
  1943                                  	; 19/10/2017
  1944 00000A56 00E6                    	add	dh, ah ; ch1 + ch4 + ch5 + ch8
  1945 00000A58 00C2                    	add	dl, al ; ch2 + ch3 + ch6 + ch7
  1946                                  
  1947                                  	; L = ch1 + ch4 + ch5 + ch8
  1948                                  	; R = ch2 + ch3 + ch6 + ch7
  1949                                  
  1950 00000A5A 6681C28080              	add	dx, 8080h
  1951                                  
  1952                                  	; 19/10/2017
  1953 00000A5F 88F4                    	mov	ah, dh
  1954 00000A61 80EC80                  	sub	ah, 80h
  1955 00000A64 30C0                    	xor	al, al
  1956 00000A66 66AB                    	stosw ; Left Channel
  1957 00000A68 88D4                    	mov	ah, dl
  1958 00000A6A 80EC80                  	sub	ah, 80h
  1959 00000A6D 66AB                    	stosw ; Right Channel
  1960                                  
  1961 00000A6F E2D3                    	loop	_8_channels_mix
  1962                                  	
  1963 00000A71 EB21                    	jmp	short channel_mix_ok
  1964                                  	
  1965                                  _4_channels_mix:
  1966                                  	; 18/10/2017
  1967 00000A73 AD                      	lodsd 
  1968 00000A74 89C2                    	mov	edx, eax ; ch1 (al), ch2 (ah)
  1969                                  	; 19/10/2017
  1970 00000A76 C1E810                  	shr	eax, 16 ; ch3 (al), ch4 (ah)
  1971 00000A79 00E2                    	add	dl, ah ; ch1 + ch4
  1972 00000A7B 00C6                    	add	dh, al ; ch2 + ch3
  1973                                  
  1974                                  	; L = ch1 + ch4
  1975                                  	; R = ch2 + ch3
  1976                                  
  1977                                  	; 19/10/2017
  1978 00000A7D 6681C28080              	add	dx, 8080h
  1979                                  
  1980                                  	; 19/10/2017
  1981 00000A82 88D4                    	mov	ah, dl
  1982 00000A84 80EC80                  	sub	ah, 80h
  1983 00000A87 30C0                    	xor	al, al
  1984 00000A89 66AB                    	stosw ; Left Channel
  1985 00000A8B 88F4                    	mov	ah, dh
  1986 00000A8D 80EC80                  	sub	ah, 80h
  1987 00000A90 66AB                    	stosw ; Right Channel
  1988                                  	
  1989 00000A92 E2DF                    	loop	_4_channels_mix
  1990                                  
  1991                                  channel_mix_ok:
  1992 00000A94 85DB                    	test    ebx, ebx
  1993                                  	;jnz	short NextChunk
  1994 00000A96 0F8508FFFFFF            	jnz	NextChunk ; 17/10/2017
  1995                                  
  1996                                  	; 20/10/2017
  1997                                  	; 19/10/2017
  1998                                  	; Pan Control
  1999 00000A9C 8A0D[40E00000]          	mov	cl, [pan_shift]
  2000 00000AA2 08C9                    	or	cl, cl
  2001 00000AA4 744D                    	jz	short c_smpl_2
  2002                                  
  2003                                  	; 20/10/2017
  2004 00000AA6 BB00200000              	mov	ebx, BUFFERSIZE/4 ; 8192
  2005 00000AAB BF[00F00000]            	mov	edi, Audio_Buffer
  2006                                  
  2007 00000AB0 B508                    	mov	ch, 8
  2008 00000AB2 D2E5                    	shl	ch, cl
  2009                                  c_smpl_1:
  2010 00000AB4 8B17                    	mov	edx, [edi]
  2011 00000AB6 6689D0                  	mov	ax, dx
  2012 00000AB9 80FC80                  	cmp	ah, 80h
  2013 00000ABC 7208                    	jb	short _cs1	
  2014 00000ABE 00EC                    	add	ah, ch
  2015 00000AC0 730A                    	jnc	short _cs2
  2016 00000AC2 B4FF                    	mov	ah, 255
  2017 00000AC4 EB06                    	jmp	short _cs2
  2018                                  _cs1:
  2019 00000AC6 28EC                    	sub	ah, ch
  2020 00000AC8 7302                    	jnc	short _cs2
  2021 00000ACA B400                    	mov	ah, 0
  2022                                  _cs2:
  2023 00000ACC C1CA10                  	ror	edx, 16 ; dx = [edi+2]
  2024 00000ACF 00F4                    	add	ah, dh
  2025 00000AD1 6692                    	xchg	dx, ax ; xchg [edi+2], ax
  2026 00000AD3 80FC80                  	cmp	ah, 80h
  2027 00000AD6 7208                    	jb	short _cs3	
  2028 00000AD8 00EC                    	add	ah, ch
  2029 00000ADA 730A                    	jnc	short _cs4
  2030 00000ADC B4FF                    	mov	ah, 255
  2031 00000ADE EB06                    	jmp	short _cs4
  2032                                  _cs3:
  2033 00000AE0 28EC                    	sub	ah, ch
  2034 00000AE2 7302                    	jnc	short _cs4
  2035 00000AE4 B400                    	mov	ah, 0
  2036                                  _cs4:
  2037 00000AE6 C1CA10                  	ror	edx, 16 ; dx = [edi]
  2038 00000AE9 00E6                    	add	dh, ah
  2039 00000AEB 8917                    	mov	[edi], edx
  2040                                  _cs5:
  2041                                  	; 20/10/2017
  2042 00000AED 83C704                  	add	edi, 4
  2043 00000AF0 4B                      	dec	ebx
  2044 00000AF1 75C1                    	jnz	short c_smpl_1	
  2045                                  c_smpl_2:
  2046 00000AF3 61                      	popad	
  2047 00000AF4 C3                      	retn
  2048                                  
  2049                                  ;--------------------------------------------------------------------------
  2050                                  ; StartPlaying: Initializes the Sound System.
  2051                                  ;  In:
  2052                                  ;   Module Information Resources.
  2053                                  ;--------------------------------------------------------------------------
  2054                                  
  2055                                  StartPlaying:
  2056 00000AF5 60                      	pushad
  2057                                  SetModParms:    
  2058 00000AF6 C605[9ED40000]00        	mov     byte [OrderPos], 0
  2059 00000AFD C605[9FD40000]06        	mov     byte [Tempo], DefTempo
  2060 00000B04 C605[A0D40000]06        	mov     byte [TempoWait], DefTempo
  2061 00000B0B C605[A1D40000]7D        	mov     byte [Bpm], DefBpm
  2062 00000B12 C605[A2D40000]40        	mov     byte [Row], 64
  2063 00000B19 C605[A3D40000]00        	mov     byte [BreakRow], 0
  2064 00000B20 66A1[EA510000]          	mov     ax, [MixSpeed]
  2065 00000B26 31D2                    	xor     edx, edx
  2066 00000B28 66BB3200                	mov     bx, 24*DefBpm/60
  2067 00000B2C 66F7F3                  	div     bx
  2068 00000B2F 66A3[A4D40000]          	mov     [BpmSamples], ax
  2069                                  ClearTracks:    
  2070 00000B35 BF[B4D40000]            	mov     edi, Tracks
  2071                                  	; 07/10/2017
  2072                                  	;mov	ecx, NumTracks*TrackInfo.size
  2073 00000B3A B826000000              	mov	eax, TrackInfo.size
  2074 00000B3F 0FB70D[E4510000]        	movzx	ecx, word [numtracks]
  2075 00000B46 F7E1                    	mul	ecx
  2076 00000B48 89C1                    	mov	ecx, eax
  2077 00000B4A 31C0                    	xor     eax, eax
  2078                                  	;cld
  2079 00000B4C F3AA                    	rep     stosb
  2080                                  
  2081 00000B4E A3[A6D40000]            	mov     [BufPtr], eax
  2082 00000B53 66A3[AAD40000]          	mov     [BufLen], ax
  2083                                  MakePitch:
  2084 00000B59 66B80021                	mov     ax, MidCRate
  2085 00000B5D 66BBAC01                	mov     bx, 428
  2086 00000B61 66F7E3                  	mul     bx
  2087 00000B64 66F735[EA510000]        	div     word [MixSpeed]
  2088 00000B6B 30F6                    	xor     dh, dh
  2089 00000B6D 88E2                    	mov     dl, ah
  2090 00000B6F 88C4                    	mov     ah, al
  2091 00000B71 30C0                    	xor     al, al
  2092                                  	;mov	cx, 857
  2093 00000B73 66B9610D                	mov	cx, 3425  ; 01/10/2017 (TMODPLAY.ASM)
  2094 00000B77 31DB                    	xor     ebx, ebx
  2095 00000B79 BF[F0580000]            	mov     edi, PitchTable
  2096                                  PitchLoop:      
  2097 00000B7E 50                      	push    eax
  2098 00000B7F 52                      	push    edx
  2099 00000B80 6639DA                  	cmp     dx, bx
  2100 00000B83 7303                    	jae     short NoDiv
  2101 00000B85 66F7F3                  	div     bx
  2102                                  NoDiv:          
  2103 00000B88 66AB                    	stosw
  2104 00000B8A 5A                      	pop     edx
  2105 00000B8B 58                      	pop     eax
  2106                                  	;inc	bx
  2107 00000B8C 43                      	inc	ebx
  2108 00000B8D E2EF                    	loop    PitchLoop
  2109                                  MakeVolume:     
  2110 00000B8F 66B90041                	mov     cx, 16640
  2111 00000B93 89CB                    	mov     ebx, ecx
  2112                                  VolLoop:
  2113 00000B95 664B                    	dec     bx
  2114 00000B97 88D8                    	mov     al, bl
  2115 00000B99 F6EF                    	imul    bh
  2116                                  	;mov	[VolTable+bx], ah
  2117 00000B9B 88A3[B2730000]          	mov     [VolTable+ebx], ah
  2118 00000BA1 E2F2                    	loop    VolLoop
  2119                                  
  2120 00000BA3 61                      	popad
  2121 00000BA4 C3                      	retn
  2122                                  
  2123                                  ;--------------------------------------------------------------------------
  2124                                  ; StopPlaying: ShutDown the Sound System.
  2125                                  ;--------------------------------------------------------------------------
  2126                                  
  2127                                  StopPlaying:
  2128                                  	; 19/06/2017
  2129                                  	; Stop Playing
  2130                                  	sys	_audio, 0700h
  2131                              <1> 
  2132                              <1> 
  2133                              <1> 
  2134                              <1> 
  2135                              <1>  %if %0 >= 2
  2136 00000BA5 BB00070000          <1>  mov ebx, %2
  2137                              <1>  %if %0 >= 3
  2138                              <1>  mov ecx, %3
  2139                              <1>  %if %0 = 4
  2140                              <1>  mov edx, %4
  2141                              <1>  %endif
  2142                              <1>  %endif
  2143                              <1>  %endif
  2144 00000BAA B820000000          <1>  mov eax, %1
  2145                              <1> 
  2146 00000BAF CD40                <1>  int 40h
  2147                                  	; Cancel callback service (for user)
  2148                                  	sys	_audio, 0900h
  2149                              <1> 
  2150                              <1> 
  2151                              <1> 
  2152                              <1> 
  2153                              <1>  %if %0 >= 2
  2154 00000BB1 BB00090000          <1>  mov ebx, %2
  2155                              <1>  %if %0 >= 3
  2156                              <1>  mov ecx, %3
  2157                              <1>  %if %0 = 4
  2158                              <1>  mov edx, %4
  2159                              <1>  %endif
  2160                              <1>  %endif
  2161                              <1>  %endif
  2162 00000BB6 B820000000          <1>  mov eax, %1
  2163                              <1> 
  2164 00000BBB CD40                <1>  int 40h
  2165                                  	; Deallocate Audio Buffer (for user)
  2166                                  	sys	_audio, 0A00h
  2167                              <1> 
  2168                              <1> 
  2169                              <1> 
  2170                              <1> 
  2171                              <1>  %if %0 >= 2
  2172 00000BBD BB000A0000          <1>  mov ebx, %2
  2173                              <1>  %if %0 >= 3
  2174                              <1>  mov ecx, %3
  2175                              <1>  %if %0 = 4
  2176                              <1>  mov edx, %4
  2177                              <1>  %endif
  2178                              <1>  %endif
  2179                              <1>  %endif
  2180 00000BC2 B820000000          <1>  mov eax, %1
  2181                              <1> 
  2182 00000BC7 CD40                <1>  int 40h
  2183                                  	; Disable Audio Device
  2184                                  	sys	_audio, 0C00h
  2185                              <1> 
  2186                              <1> 
  2187                              <1> 
  2188                              <1> 
  2189                              <1>  %if %0 >= 2
  2190 00000BC9 BB000C0000          <1>  mov ebx, %2
  2191                              <1>  %if %0 >= 3
  2192                              <1>  mov ecx, %3
  2193                              <1>  %if %0 = 4
  2194                              <1>  mov edx, %4
  2195                              <1>  %endif
  2196                              <1>  %endif
  2197                              <1>  %endif
  2198 00000BCE B820000000          <1>  mov eax, %1
  2199                              <1> 
  2200 00000BD3 CD40                <1>  int 40h
  2201                                  
  2202 00000BD5 C3                      	retn
  2203                                  
  2204                                  ;=============================================================================
  2205                                  ; 
  2206                                  ;=============================================================================
  2207                                  
  2208                                  ;dword2str:
  2209                                  ;	; 13/11/2016 - Erdogan Tan 
  2210                                  ;	; eax = dword value
  2211                                  ;	;
  2212                                  ;	call	dwordtohex
  2213                                  ;	mov	[dword_str], edx
  2214                                  ;	mov	[dword_str+4], eax
  2215                                  ;	mov	si, dword_str
  2216                                  ;	retn
  2217                                  
  2218                                  	; 05/03/2017 (TRDOS 386)
  2219                                  	; trdos386.s (unix386.s) - 10/05/2015
  2220                                  	; Convert binary number to hexadecimal string
  2221                                  
  2222                                  ;bytetohex:
  2223                                  ;	; INPUT ->
  2224                                  ;	; 	AL = byte (binary number)
  2225                                  ;	; OUTPUT ->
  2226                                  ;	;	AX = hexadecimal string
  2227                                  ;	;
  2228                                  ;	push	ebx
  2229                                  ;	movzx	ebx, al
  2230                                  ;	shr	bl, 4
  2231                                  ;	mov	bl, [ebx+hex_chars] 	 	
  2232                                  ;	xchg	bl, al
  2233                                  ;	and	bl, 0Fh
  2234                                  ;	mov	ah, [ebx+hex_chars] 
  2235                                  ;	pop	ebx	
  2236                                  ;	retn
  2237                                  
  2238                                  ;wordtohex:
  2239                                  ;	; INPUT ->
  2240                                  ;	; 	AX = word (binary number)
  2241                                  ;	; OUTPUT ->
  2242                                  ;	;	EAX = hexadecimal string
  2243                                  ;	;
  2244                                  ;	push	ebx
  2245                                  ;	xor	ebx, ebx
  2246                                  ;	xchg	ah, al
  2247                                  ;	push	eax
  2248                                  ;	mov	bl, ah
  2249                                  ;	shr	bl, 4
  2250                                  ;	mov	al, [ebx+hex_chars] 	 	
  2251                                  ;	mov	bl, ah
  2252                                  ;	and	bl, 0Fh
  2253                                  ;	mov	ah, [ebx+hex_chars]
  2254                                  ;	shl	eax, 16
  2255                                  ;	pop	eax
  2256                                  ;	pop	ebx
  2257                                  ;	jmp	short bytetohex
  2258                                  
  2259                                  ;dwordtohex:
  2260                                  ;	; INPUT ->
  2261                                  ;	; 	EAX = dword (binary number)
  2262                                  ;	; OUTPUT ->
  2263                                  ;	;	EDX:EAX = hexadecimal string
  2264                                  ;	;
  2265                                  ;	push	eax
  2266                                  ;	shr	eax, 16
  2267                                  ;	call	wordtohex
  2268                                  ;	mov	edx, eax
  2269                                  ;	pop	eax
  2270                                  ;	call	wordtohex
  2271                                  ;	retn
  2272                                  
  2273                                  	; 24/06/2017
  2274                                  	; 19/06/2017
  2275                                  	; 05/03/2017 (TRDOS 386)
  2276                                  	; 13/11/2016 - Erdogan Tan
  2277                                  write_audio_dev_info:
  2278                                  	; BUS/DEV/FN
  2279                                  	;	00000000BBBBBBBBDDDDDFFF00000000
  2280                                  	; DEV/VENDOR
  2281                                  	;	DDDDDDDDDDDDDDDDVVVVVVVVVVVVVVVV
  2282                                  
  2283 00000BD6 8B35[A4520000]          	mov	esi, [dev_vendor]
  2284 00000BDC 6689F0                  	mov	ax, si
  2285 00000BDF 0FB6D8                  	movzx	ebx, al
  2286 00000BE2 88DA                    	mov	dl, bl
  2287 00000BE4 80E30F                  	and	bl, 0Fh
  2288 00000BE7 8A83[EC510000]          	mov	al, [ebx+hex_chars]
  2289 00000BED A2[31520000]            	mov	[msgVendorId+3], al
  2290 00000BF2 88D3                    	mov	bl, dl
  2291 00000BF4 C0EB04                  	shr	bl, 4
  2292 00000BF7 8A83[EC510000]          	mov	al, [ebx+hex_chars]
  2293 00000BFD A2[30520000]            	mov	[msgVendorId+2], al
  2294 00000C02 88E3                    	mov	bl, ah
  2295 00000C04 88DA                    	mov	dl, bl
  2296 00000C06 80E30F                  	and	bl, 0Fh
  2297 00000C09 8A83[EC510000]          	mov	al, [ebx+hex_chars]
  2298 00000C0F A2[2F520000]            	mov	[msgVendorId+1], al
  2299 00000C14 88D3                    	mov	bl, dl
  2300 00000C16 C0EB04                  	shr	bl, 4
  2301 00000C19 8A83[EC510000]          	mov	al, [ebx+hex_chars]
  2302 00000C1F A2[2E520000]            	mov	[msgVendorId], al
  2303 00000C24 C1EE10                  	shr	esi, 16
  2304 00000C27 6689F0                  	mov	ax, si
  2305 00000C2A 88C3                    	mov	bl, al
  2306 00000C2C 88DA                    	mov	dl, bl
  2307 00000C2E 80E30F                  	and	bl, 0Fh
  2308 00000C31 8A83[EC510000]          	mov	al, [ebx+hex_chars]
  2309 00000C37 A2[42520000]            	mov	[msgDevId+3], al
  2310 00000C3C 88D3                    	mov	bl, dl
  2311 00000C3E C0EB04                  	shr	bl, 4
  2312 00000C41 8A83[EC510000]          	mov	al, [ebx+hex_chars]
  2313 00000C47 A2[41520000]            	mov	[msgDevId+2], al
  2314 00000C4C 88E3                    	mov	bl, ah
  2315 00000C4E 88DA                    	mov	dl, bl
  2316 00000C50 80E30F                  	and	bl, 0Fh
  2317 00000C53 8A83[EC510000]          	mov	al, [ebx+hex_chars]
  2318 00000C59 A2[40520000]            	mov	[msgDevId+1], al
  2319 00000C5E 88D3                    	mov	bl, dl
  2320 00000C60 C0EB04                  	shr	bl, 4
  2321 00000C63 8A83[EC510000]          	mov	al, [ebx+hex_chars]
  2322 00000C69 A2[3F520000]            	mov	[msgDevId], al
  2323                                  
  2324 00000C6E 8B35[A8520000]          	mov	esi, [bus_dev_fn]
  2325 00000C74 C1EE08                  	shr	esi, 8
  2326 00000C77 6689F0                  	mov	ax, si
  2327 00000C7A 88C3                    	mov	bl, al
  2328 00000C7C 88DA                    	mov	dl, bl
  2329 00000C7E 80E307                  	and	bl, 7 ; bit 0,1,2
  2330 00000C81 8A83[EC510000]          	mov	al, [ebx+hex_chars]
  2331 00000C87 A2[66520000]            	mov	[msgFncNo+1], al
  2332 00000C8C 88D3                    	mov	bl, dl
  2333 00000C8E C0EB03                  	shr	bl, 3
  2334 00000C91 88DA                    	mov	dl, bl
  2335 00000C93 80E30F                  	and	bl, 0Fh
  2336 00000C96 8A83[EC510000]          	mov	al, [ebx+hex_chars]
  2337 00000C9C A2[58520000]            	mov	[msgDevNo+1], al
  2338 00000CA1 88D3                    	mov	bl, dl
  2339 00000CA3 C0EB04                  	shr	bl, 4
  2340 00000CA6 8A83[EC510000]          	mov	al, [ebx+hex_chars]
  2341 00000CAC A2[57520000]            	mov	[msgDevNo], al
  2342 00000CB1 88E3                    	mov	bl, ah
  2343 00000CB3 88DA                    	mov	dl, bl
  2344 00000CB5 80E30F                  	and	bl, 0Fh
  2345 00000CB8 8A83[EC510000]          	mov	al, [ebx+hex_chars]
  2346 00000CBE A2[4C520000]            	mov	[msgBusNo+1], al
  2347 00000CC3 88D3                    	mov	bl, dl
  2348 00000CC5 C0EB04                  	shr	bl, 4
  2349 00000CC8 8A83[EC510000]          	mov	al, [ebx+hex_chars]
  2350 00000CCE A2[4B520000]            	mov	[msgBusNo], al
  2351                                  
  2352                                  	; 24/06/2017
  2353 00000CD3 66A1[B0520000]          	mov	ax, [ac97_NamBar]
  2354 00000CD9 88C3                    	mov	bl, al
  2355 00000CDB 88DA                    	mov	dl, bl
  2356 00000CDD 80E30F                  	and	bl, 0Fh
  2357 00000CE0 8A83[EC510000]          	mov	al, [ebx+hex_chars]
  2358 00000CE6 A2[75520000]            	mov	[msgNamBar+3], al
  2359 00000CEB 88D3                    	mov	bl, dl
  2360 00000CED C0EB04                  	shr	bl, 4
  2361 00000CF0 8A83[EC510000]          	mov	al, [ebx+hex_chars]
  2362 00000CF6 A2[74520000]            	mov	[msgNamBar+2], al
  2363 00000CFB 88E3                    	mov	bl, ah
  2364 00000CFD 88DA                    	mov	dl, bl
  2365 00000CFF 80E30F                  	and	bl, 0Fh
  2366 00000D02 8A83[EC510000]          	mov	al, [ebx+hex_chars]
  2367 00000D08 A2[73520000]            	mov	[msgNamBar+1], al
  2368 00000D0D 88D3                    	mov	bl, dl
  2369 00000D0F C0EB04                  	shr	bl, 4
  2370 00000D12 8A83[EC510000]          	mov	al, [ebx+hex_chars]
  2371 00000D18 A2[72520000]            	mov	[msgNamBar], al
  2372                                  
  2373 00000D1D 66A1[B2520000]          	mov	ax, [ac97_NabmBar]
  2374 00000D23 88C3                    	mov	bl, al
  2375 00000D25 88DA                    	mov	dl, bl
  2376 00000D27 80E30F                  	and	bl, 0Fh
  2377 00000D2A 8A83[EC510000]          	mov	al, [ebx+hex_chars]
  2378 00000D30 A2[85520000]            	mov	[msgNabmBar+3], al
  2379 00000D35 88D3                    	mov	bl, dl
  2380 00000D37 C0EB04                  	shr	bl, 4
  2381 00000D3A 8A83[EC510000]          	mov	al, [ebx+hex_chars]
  2382 00000D40 A2[84520000]            	mov	[msgNabmBar+2], al
  2383 00000D45 88E3                    	mov	bl, ah
  2384 00000D47 88DA                    	mov	dl, bl
  2385 00000D49 80E30F                  	and	bl, 0Fh
  2386 00000D4C 8A83[EC510000]          	mov	al, [ebx+hex_chars]
  2387 00000D52 A2[83520000]            	mov	[msgNabmBar+1], al
  2388 00000D57 88D3                    	mov	bl, dl
  2389 00000D59 C0EB04                  	shr	bl, 4
  2390 00000D5C 8A83[EC510000]          	mov	al, [ebx+hex_chars]
  2391 00000D62 A2[82520000]            	mov	[msgNabmBar], al
  2392                                  
  2393                                  	; 24/11/2016
  2394 00000D67 30E4                    	xor	ah, ah
  2395 00000D69 A0[B4520000]            	mov	al, [ac97_int_ln_reg]
  2396 00000D6E B10A                    	mov	cl, 10
  2397 00000D70 F6F1                    	div	cl
  2398 00000D72 660105[8E520000]        	add	[msgIRQ], ax
  2399 00000D79 20C0                    	and	al, al
  2400 00000D7B 750D                    	jnz	short _w_ac97imsg_ ; 19/06/2017
  2401 00000D7D A0[8F520000]            	mov	al, [msgIRQ+1]
  2402 00000D82 B420                    	mov	ah, ' '
  2403 00000D84 66A3[8E520000]          	mov	[msgIRQ], ax
  2404                                  _w_ac97imsg_:
  2405                                  	; EBX = Message address
  2406                                  	; ECX = Max. message length (or stop on ZERO character)
  2407                                  	;	(1 to 255)
  2408                                  	; DL  = Message color (07h = light gray, 0Fh = white) 
  2409                                       	sys 	_msg, msgAC97Info, 255, 07h
  2410                              <1> 
  2411                              <1> 
  2412                              <1> 
  2413                              <1> 
  2414                              <1>  %if %0 >= 2
  2415 00000D8A BB[FD510000]        <1>  mov ebx, %2
  2416                              <1>  %if %0 >= 3
  2417 00000D8F B9FF000000          <1>  mov ecx, %3
  2418                              <1>  %if %0 = 4
  2419 00000D94 BA07000000          <1>  mov edx, %4
  2420                              <1>  %endif
  2421                              <1>  %endif
  2422                              <1>  %endif
  2423 00000D99 B823000000          <1>  mov eax, %1
  2424                              <1> 
  2425 00000D9E CD40                <1>  int 40h
  2426 00000DA0 C3                              retn
  2427                                  
  2428                                  ;=============================================================================
  2429                                  ;	gfx.asm - draw scopes in VGA 640x480x16 mode      
  2430                                  ;=============================================================================
  2431                                  
  2432                                  ; EX1A.ASM (21/6/1994, Carlos Hasan; MSDOS, 'RUNME.EXE', 'TNYPL211')
  2433                                  
  2434                                  ;-----------------------------------------------------------------------------
  2435                                  ; setgraphmode - setup the VGA 640x480x16 graphics mode
  2436                                  ;-----------------------------------------------------------------------------
  2437                                  	; 22/10/2017
  2438                                  setgraphmode:
  2439                                  	;pushad
  2440 00000DA1 66B81200                	mov	ax,0012h
  2441                                  	;int	10h
  2442 00000DA5 CD31                    	int 	31h
  2443 00000DA7 66BAC003                	mov	dx,3C0h
  2444 00000DAB 30C0                    	xor	al,al
  2445                                  setgraphmodel0:
  2446                                  	;out	dx,al
  2447 00000DAD B401                    	mov	ah, 1 ; outb
  2448 00000DAF CD34                    	int	34h
  2449                                  	;out	dx, al
  2450                                  	;mov	ah, 1
  2451 00000DB1 CD34                    	int	34h
  2452 00000DB3 FEC0                    	inc	al
  2453 00000DB5 3C10                    	cmp	al, 10h
  2454 00000DB7 72F4                    	jb	short setgraphmodel0
  2455 00000DB9 B020                    	mov	al, 20h
  2456                                  	;out	dx, al
  2457                                  	;mov	ah, 1
  2458 00000DBB CD34                    	int	34h
  2459                                  	;popad
  2460 00000DBD C3                      	retn
  2461                                  
  2462                                  ;-----------------------------------------------------------------------------
  2463                                  ; settextmode - restore the VGA 80x25x16 text mode
  2464                                  ;-----------------------------------------------------------------------------
  2465                                  	; 22/10/2017
  2466                                  settextmode:
  2467                                  	;pushad
  2468 00000DBE 66B80300                	mov	ax, 0003h
  2469                                  	;int	10h
  2470 00000DC2 CD31                    	int	31h
  2471                                  	;popad
  2472 00000DC4 C3                      	retn
  2473                                  
  2474                                  ;-----------------------------------------------------------------------------
  2475                                  ; drawscopes - draw the track voices sample scopes
  2476                                  ; In:
  2477                                  ;  ESI = (current) sample buffer
  2478                                  ;-----------------------------------------------------------------------------
  2479                                  	; 29/10/2017
  2480                                  	; 28/10/2017
  2481                                  	; (ESI = Current DMA buffer offset)
  2482                                  	; 27/10/2017
  2483                                  	; 26/10/2017
  2484                                  	; 23/10/2017
  2485                                  drawscopes:
  2486                                  	;pushad
  2487                                    	;mov	esi, g_buff
  2488                                  	;mov	esi, edx
  2489 00000DC5 31C9                    	xor     ecx, ecx	
  2490 00000DC7 31D2                    	xor     edx, edx
  2491 00000DC9 31FF                    	xor	edi, edi
  2492                                  drawscope0:
  2493 00000DCB 66AD                    	lodsw
  2494 00000DCD 80F480                  	xor	ah, 80h
  2495 00000DD0 0FB6DC                  	movzx	ebx, ah  ; Left Channel
  2496 00000DD3 66D1E3                  	shl	bx, 1
  2497 00000DD6 668B83[F0D50000]        	mov	ax, [RowOfs+ebx]
  2498 00000DDD 668987[F0D70000]        	mov	[NewScope_L+edi], ax
  2499 00000DE4 30FF                    	xor	bh, bh
  2500 00000DE6 66AD                    	lodsw
  2501 00000DE8 80F480                  	xor	ah, 80h
  2502 00000DEB 88E3                    	mov	bl, ah	; Right Channel
  2503 00000DED 66D1E3                  	shl	bx, 1
  2504 00000DF0 668B83[F0D50000]        	mov	ax, [RowOfs+ebx]
  2505 00000DF7 668987[F0D90000]        	mov	[NewScope_R+edi], ax
  2506 00000DFE 6683C702                	add	di, 2
  2507 00000E02 FEC1                    	inc	cl
  2508 00000E04 75C5                    	jnz	short drawscope0	
  2509                                  
  2510 00000E06 66BAC403                        mov	dx, 3C4h
  2511                                          ;mov	ax, 0802h
  2512                                          ;out	dx, ax
  2513 00000E0A 66BB0208                        mov	bx, 0802h
  2514 00000E0E B403                    	mov	ah, 3 ; outw
  2515 00000E10 CD34                    	int	34h
  2516 00000E12 66BACE03                	mov	dx, 3CEh
  2517 00000E16 B008                            mov	al, 08h
  2518                                         ;out	dx, al
  2519 00000E18 B401                            mov	ah, 1 ; outb
  2520 00000E1A CD34                    	int	34h
  2521 00000E1C 6642                    	inc	dx
  2522                                  
  2523                                  	; 26/10/2017
  2524 00000E1E 31F6                            xor	esi, esi
  2525                                         ;xor	edi, edi
  2526 00000E20 BB45060A00                      mov     ebx, 0A0645h
  2527                                  drawscopel4:
  2528 00000E25 B080                            mov     al, 80h
  2529                                  drawscopel2:
  2530 00000E27 50                              push    eax ; *
  2531 00000E28 52                              push    edx ; **
  2532                                  	;out	dx, al
  2533 00000E29 B401                    	mov	ah, 1 ; outb
  2534 00000E2B CD34                    	int	34h
  2535                                  
  2536 00000E2D B4FF                            mov	ah, 0FFh
  2537                                          ;mov	ecx, 32
  2538 00000E2F B120                    	mov	cl, 32
  2539 00000E31 28C0                    	sub     al, al
  2540                                  drawscopel3:
  2541                                  	; 23/10/2017
  2542 00000E33 668B96[F0DB0000]                mov	dx, [OldScope_L+esi]
  2543 00000E3A 663B96[F0D70000]                cmp	dx, [NewScope_L+esi]
  2544 00000E41 7414                            je	short drawscopef3
  2545 00000E43 88041A                          mov	[edx+ebx], al ; L
  2546 00000E46 668B96[F0D70000]                mov     dx, [NewScope_L+esi]
  2547 00000E4D 88241A                  	mov	[edx+ebx], ah ; L
  2548 00000E50 668996[F0DB0000]                mov     [OldScope_L+esi], dx
  2549                                  drawscopef3:
  2550                                  	; 27/10/2017
  2551 00000E57 668B96[F0DD0000]                mov	dx, [OldScope_R+esi]
  2552 00000E5E 663B96[F0D90000]                cmp	dx, [NewScope_R+esi]
  2553 00000E65 7416                            je	short drawscopef4
  2554 00000E67 88441A26                	mov	[edx+ebx+38], al ; R
  2555 00000E6B 668B96[F0D90000]                mov     dx, [NewScope_R+esi]
  2556 00000E72 88641A26                        mov	[edx+ebx+38], ah ; R
  2557 00000E76 668996[F0DD0000]                mov     [OldScope_R+esi], dx
  2558                                  drawscopef4:
  2559 00000E7D 83C610                  	add	esi, 2*8
  2560 00000E80 43                      	inc	ebx
  2561 00000E81 E2B0                    	loop    drawscopel3
  2562                                  
  2563 00000E83 5A                              pop     edx ; **
  2564 00000E84 58                              pop     eax ; *
  2565 00000E85 81EEFE010000            	sub	esi, 2*256-2
  2566 00000E8B 83EB20                  	sub	ebx, 32
  2567 00000E8E D0E8                            shr     al, 1
  2568 00000E90 7595                            jnz	short drawscopel2
  2569                                  	;popad
  2570 00000E92 C3                              retn
  2571                                  
  2572                                  ;=============================================================================
  2573                                  ;	Load IFF/ILBM files for VGA 640x480x16 graphics mode       
  2574                                  ;=============================================================================
  2575                                  
  2576                                  ; EX1B.ASM (21/6/1994, Carlos Hasan; MSDOS, 'RUNME.EXE', 'TNYPL211')
  2577                                  
  2578                                  ; 21/10/2017 (TRDOS 386, 'tmodplay.s', Erdogan Tan, NASM syntax)
  2579                                  
  2580                                  ;-----------------------------------------------------------------------------
  2581                                  ; EQUATES AND STRUCTURES
  2582                                  ;-----------------------------------------------------------------------------
  2583                                  
  2584                                  ID_FORM equ 4D524F46h		; IFF/ILBM chunk IDs
  2585                                  ID_ILBM equ 4D424C49h
  2586                                  ID_BMHD equ 44484D42h
  2587                                  ID_CMAP equ 50414D43h
  2588                                  ID_BODY equ 59444F42h
  2589                                  
  2590                                  struc Form			; IFF/ILBM header file format
  2591 00000000 <res 00000004>            .ID:		resd 1
  2592 00000004 <res 00000004>            .Length:	resd 1
  2593 00000008 <res 00000004>            .Type:	resd 1
  2594                                    .size:
  2595                                  endstruc
  2596                                  
  2597                                  struc Chunk			; IFF/ILBM header chunk format
  2598 00000000 <res 00000004>            .ID:		resd 1
  2599 00000004 <res 00000004>            .Length:	resd 1
  2600                                    .size:	
  2601                                  endstruc
  2602                                  
  2603                                  struc BMHD			; IFF/ILBM BMHD chunk format
  2604 00000000 <res 00000002>            .Width: 	resw 1
  2605 00000002 <res 00000002>            .Height:	resw 1
  2606 00000004 <res 00000002>            .PosX:	resw 1
  2607 00000006 <res 00000002>            .PosY:	resw 1
  2608 00000008 <res 00000001>            .Planes:	resb 1
  2609 00000009 <res 00000001>            .Masking:	resb 1
  2610 0000000A <res 00000001>            .Compression:	resb 1
  2611 0000000B <res 00000001>            .Pad:		resb 1
  2612 0000000C <res 00000002>            .Transparent:	resw 1
  2613 0000000E <res 00000001>            .AspectX	resb 1
  2614 0000000F <res 00000001>            .AspectY:	resb 1
  2615 00000010 <res 00000002>            .PageWidth:	resw 1
  2616 00000012 <res 00000002>            .PageHeight:	resw 1
  2617                                    .size:	
  2618                                  endstruc
  2619                                  
  2620                                  struc CMAP			; IFF/ILBM CMAP chunk format
  2621 00000000 <res 00000300>            .Colors:	resb 768
  2622                                    .size:	
  2623                                  endstruc
  2624                                  
  2625                                  ;LOGO_ADDRESS	equ 100000h	; virtual address at the end of the 1st 1MB
  2626                                  
  2627                                  ;------------------------------------------------------------------------------
  2628                                  ; bswap - macro to reverse the byte order of a 32-bit register, converting
  2629                                  ;         a value in little/big endian form to big/little endian form.
  2630                                  ;------------------------------------------------------------------------------
  2631                                  %macro	bswap   1
  2632                                          xchg    al, ah
  2633                                          rol     eax, 16
  2634                                          xchg    al, ah
  2635                                  %endmacro
  2636                                  
  2637                                  ;------------------------------------------------------------------------------
  2638                                  ; putlbm - draw the IFF/ILBM picture on VGA 640x480x16 graphics mode
  2639                                  ; In:
  2640                                  ;  ESI = IFF/ILBM image file address
  2641                                  ;------------------------------------------------------------------------------
  2642                                  putlbm:
  2643 00000E93 60                              pushad
  2644                                  
  2645                                  ; check if this is a valid IFF/ILBM Deluxe Paint file
  2646                                  
  2647 00000E94 813E464F524D                    cmp     dword [esi+Form.ID], ID_FORM
  2648 00000E9A 7551                            jne     short putlbmd0
  2649 00000E9C 817E08494C424D                  cmp     dword [esi+Form.Type], ID_ILBM
  2650 00000EA3 7548                            jne     short putlbmd0
  2651                                  
  2652                                  ; get the IFF/ILBM file length in bytes
  2653                                  
  2654 00000EA5 8B4604                          mov     eax, [esi+Form.Length]
  2655                                          bswap   eax
  2656 00000EA8 86C4                <1>  xchg al, ah
  2657 00000EAA C1C010              <1>  rol eax, 16
  2658 00000EAD 86C4                <1>  xchg al, ah
  2659 00000EAF 89C1                            mov     ecx, eax
  2660                                  
  2661                                  ; decrease the file length and updates the file pointer
  2662                                  
  2663 00000EB1 83E904                          sub     ecx, 4
  2664 00000EB4 83C60C                          add     esi, Form.size
  2665                                  
  2666                                  ; IFF/ILBM main parser body loop
  2667                                  
  2668                                  putlbml0:
  2669 00000EB7 85C9                            test    ecx, ecx
  2670 00000EB9 7E64                            jle     short putlbmd1
  2671                                  
  2672                                  ; get the next chunk ID and length in bytes
  2673                                  
  2674 00000EBB 8B1E                            mov     ebx, [esi+Chunk.ID]
  2675 00000EBD 8B4604                          mov     eax, [esi+Chunk.Length]
  2676                                          bswap   eax
  2677 00000EC0 86C4                <1>  xchg al, ah
  2678 00000EC2 C1C010              <1>  rol eax, 16
  2679 00000EC5 86C4                <1>  xchg al, ah
  2680 00000EC7 93                              xchg    ebx, eax
  2681 00000EC8 83C608                          add     esi, Chunk.size
  2682                                  
  2683                                  ; word align the chunk length and decrease the file length counter
  2684                                  
  2685 00000ECB 43                              inc     ebx
  2686 00000ECC 80E3FE                          and     bl, 0FEh ; ~1
  2687 00000ECF 83E908                          sub     ecx, Chunk.size
  2688 00000ED2 29D9                            sub     ecx, ebx
  2689                                  
  2690                                  ; check for the BMHD/CMAP/BODY chunk headers
  2691                                  
  2692 00000ED4 3D424D4844                      cmp     eax, ID_BMHD
  2693 00000ED9 7415                            je      short putlbmf0
  2694 00000EDB 3D434D4150                      cmp     eax, ID_CMAP
  2695 00000EE0 7440                            je      short putlbmf1
  2696 00000EE2 3D424F4459                      cmp     eax, ID_BODY
  2697 00000EE7 7455                            je      short putlbmf2
  2698                                  
  2699                                  ; advance to the next IFF/ILBM chunk structure
  2700                                  
  2701                                  putlbmc0:
  2702 00000EE9 01DE                            add     esi, ebx
  2703 00000EEB EBCA                            jmp     short putlbml0
  2704                                  
  2705                                  putlbmd0:
  2706 00000EED F9                              stc
  2707 00000EEE 61                              popad
  2708 00000EEF C3                              retn
  2709                                  
  2710                                  ; process the BMHD bitmap header chunk
  2711                                  
  2712                                  putlbmf0:
  2713 00000EF0 807E0804                        cmp     byte [esi+BMHD.Planes], 4
  2714 00000EF4 75F7                            jne     short putlbmd0
  2715 00000EF6 807E0A01                        cmp     byte [esi+BMHD.Compression], 1
  2716 00000EFA 75F1                            jne     short putlbmd0
  2717 00000EFC 807E0B00                        cmp     byte [esi+BMHD.Pad], 0
  2718 00000F00 75EB                            jne     short putlbmd0
  2719 00000F02 0FB706                          movzx   eax, word [esi+BMHD.Width]
  2720 00000F05 86C4                            xchg    al, ah
  2721 00000F07 83C007                          add     eax, 7
  2722 00000F0A C1E803                          shr     eax, 3
  2723 00000F0D A3[9C520000]                    mov     [picture.width], eax
  2724 00000F12 0FB74602                        movzx   eax, word [esi+BMHD.Height]
  2725 00000F16 86C4                            xchg    al, ah
  2726 00000F18 A3[A0520000]                    mov     [picture.height], eax
  2727 00000F1D EBCA                            jmp     short putlbmc0
  2728                                  
  2729                                  putlbmd1:
  2730 00000F1F F8                              clc
  2731 00000F20 61                              popad
  2732 00000F21 C3                              retn
  2733                                  
  2734                                  ; process the CMAP colormap chunk
  2735                                  
  2736                                  putlbmf1:
  2737 00000F22 66BAC803                        mov     dx, 3C8h
  2738 00000F26 30C0                            xor     al, al
  2739                                          ;out	dx, al
  2740 00000F28 B401                    	mov	ah, 1 ; outb
  2741 00000F2A CD34                    	int	34h
  2742 00000F2C 6642                            inc     dx
  2743                                  putlbml1:
  2744 00000F2E 8A06                            mov     al, [esi]
  2745 00000F30 C0E802                          shr     al, 2
  2746                                          ;out	dx, al
  2747                                  	;mov	ah, 1 ; outb
  2748 00000F33 CD34                    	int	34h ; IOCTL interrupt (IN/OUT)
  2749 00000F35 46                              inc     esi
  2750 00000F36 4B                              dec     ebx
  2751 00000F37 7FF5                            jg      short putlbml1
  2752 00000F39 E979FFFFFF                      jmp     putlbml0
  2753                                  
  2754                                  ; process the BODY bitmap body chunk
  2755                                  
  2756                                  putlbmf2:
  2757 00000F3E 60                              pushad
  2758 00000F3F BF00000A00                      mov     edi, 0A0000h
  2759                                          ;cld
  2760 00000F44 66BACE03                        mov     dx, 3CEh
  2761                                          ;mov	ax, 0FF08h
  2762                                          ;out	dx, ax
  2763 00000F48 66BB08FF                	mov	bx, 0FF08h
  2764 00000F4C B403                    	mov	ah, 3 ; outw
  2765 00000F4E CD34                    	int	34h ; IOCTL interrupt (IN/OUT)
  2766 00000F50 66BAC403                        mov     dx, 3C4h
  2767 00000F54 B002                            mov     al, 02h
  2768                                          ;out	dx, al
  2769 00000F56 B401                    	mov	ah, 1 ; outb
  2770 00000F58 CD34                    	int	34h ; IOCTL interrupt (IN/OUT)
  2771 00000F5A 6642                            inc     dx
  2772 00000F5C 8B0D[A0520000]                  mov     ecx, [picture.height]
  2773                                  putlbml2:
  2774 00000F62 51                              push    ecx
  2775 00000F63 B011                            mov     al, 11h
  2776                                  putlbml3:
  2777 00000F65 50                              push    eax
  2778 00000F66 57                              push    edi
  2779                                          ;out	dx, al
  2780 00000F67 B401                    	mov	ah, 1 ; outb
  2781 00000F69 CD34                    	int	34h ; IOCTL interrupt (IN/OUT)
  2782 00000F6B 8B1D[9C520000]                  mov     ebx, [picture.width]
  2783                                  putlbml4:
  2784 00000F71 AC                              lodsb
  2785 00000F72 84C0                            test    al, al
  2786 00000F74 7C0A                            jl      short putlbmf3
  2787 00000F76 0FB6C8                          movzx   ecx, al
  2788 00000F79 41                              inc     ecx
  2789 00000F7A 29CB                            sub     ebx, ecx
  2790 00000F7C F3A4                            rep     movsb
  2791 00000F7E EB0B                            jmp     short putlbmc4
  2792                                  putlbmf3:
  2793 00000F80 F6D8                            neg     al
  2794 00000F82 0FB6C8                          movzx   ecx, al
  2795 00000F85 41                              inc     ecx
  2796 00000F86 29CB                            sub     ebx, ecx
  2797 00000F88 AC                              lodsb
  2798 00000F89 F3AA                            rep     stosb
  2799                                  putlbmc4:
  2800 00000F8B 85DB                            test    ebx, ebx
  2801 00000F8D 7FE2                            jg      short putlbml4
  2802 00000F8F 5F                              pop     edi
  2803 00000F90 58                              pop     eax
  2804 00000F91 00C0                            add     al, al
  2805 00000F93 73D0                            jnc     short putlbml3
  2806 00000F95 83C750                          add     edi, 80
  2807 00000F98 59                              pop     ecx
  2808 00000F99 E2C7                            loop    putlbml2
  2809 00000F9B 61                      	popad
  2810 00000F9C E948FFFFFF                      jmp	putlbmc0
  2811                                  
  2812                                  ; EX1.C (Carlos Hasan, 21/06/1994)
  2813                                  ;------------------------------------------------------------------------------
  2814                                  ; loadlbm - load the IFF/ILBM image file ("LOGO.LBM") at memory
  2815                                  ;  ESI = IFF/ILBM image file address
  2816                                  ;------------------------------------------------------------------------------
  2817                                  
  2818                                  ;if ((Logo = loadlbm("LOGO.LBM")) == NULL) {
  2819                                  ;       printf("Error loading the IFF/ILBM logo picture\n");
  2820                                  ;       MODStopModule();
  2821                                  ;       MODFreeModule(Song);
  2822                                  ;       return;
  2823                                  ;   }
  2824                                  ;   setgraphmode();
  2825                                  ;   putlbm(Logo);
  2826                                  ;   while (!kbhit())
  2827                                  ;       drawscopes(Song->NumTracks);
  2828                                  ;   settextmode();
  2829                                  ;   free(Logo);
  2830                                  ;   MODStopModule();
  2831                                  ;   MODFreeModule(Song);
  2832                                  
  2833                                  ;loadlbm:
  2834                                  ;	; ebx = ASCIIZ file name address
  2835                                  ;	; ecx = open mode (0 = open for read)	
  2836                                  ;	sys	_open, LOGO_FILE_NAME, 0 ; open for reading
  2837                                  ;	jc	short loadlbm_retn
  2838                                  ;
  2839                                  ;	mov     [LBM_FileHandle], eax
  2840                                  ;
  2841                                  ;	; get file size by moving file pointer to the end of file
  2842                                  ;	; ebx = file handle/number
  2843                                  ;	; ecx : offset = 0
  2844                                  ;	; edx : switch = 2 (move fp to end of file + offset)
  2845                                  ;	sys	_seek, eax, 0, 2
  2846                                  ;	jc	short loadlbm_cf
  2847                                  ;
  2848                                  ;	mov	[LBM_FileSize], eax
  2849                                  ;
  2850                                  ;	; move file pointer to the beginning of the file
  2851                                  ;	; ecx = 0
  2852                                  ;	; edx = 0
  2853                                  ;	;xor	ecx, ecx
  2854                                  ; 	xor	dl, dl
  2855                                  ;	; ebx = [LBM_FileHandle]
  2856                                  ;	sys	_seek
  2857                                  ;	;jc	short loadlbm_cf
  2858                                  ;
  2859                                  ;	; ebx = File handle
  2860                                  ;	; ecx = Buffer address
  2861                                  ;	; edx = Byte count
  2862                                  ;	;sys	_read, [LBM_FileHandle], LOGO_ADDRESS, [LBM_FileSize]
  2863                                  ;	mov	ecx, LOGO_ADDRESS
  2864                                  ;	mov	edx, [LBM_FileSize]
  2865                                  ;	sys	_read
  2866                                  ;	jc	short loadlbm_cf
  2867                                  ;
  2868                                  ;	cmp	eax, edx  ; read count = file size ?
  2869                                  ;	;jb	short loadlbm_cf		 
  2870                                  ;loadlbm_cf:
  2871                                  ;	pushf
  2872                                  ;	sys	_close, [LBM_FileHandle]	
  2873                                  ;	popf
  2874                                  ;loadlbm_retn:
  2875                                  ;	retn	
  2876                                  ;
  2877                                  ;LOGO_FILE_NAME:
  2878                                  ;	db	"LOGO.LBM", 0
  2879                                  
  2880                                  LOGO_ERROR_MSG:
  2881 00000FA1 4572726F72206C6F61-     	db	"Error loading the IFF/ILBM logo picture !", 0Dh, 0Ah, 0 
  2882 00000FAA 64696E672074686520-
  2883 00000FB3 4946462F494C424D20-
  2884 00000FBC 6C6F676F2070696374-
  2885 00000FC5 75726520210D0A00   
  2886                                  
  2887 00000FCD 90                      align 2
  2888                                  ; 22/10/2017
  2889                                  LOGO_ADDRESS:
  2890                                  ;incbin "LOGO.LBM"	  	 
  2891                                  ; 27/10/2017
  2892 00000FCE <incbin>                incbin "TINYPLAY.LBM"
  2893                                  
  2894                                  ;=============================================================================
  2895                                  ;               preinitialized data
  2896                                  ;=============================================================================
  2897                                  
  2898                                  ;=============================================================================
  2899                                  ; Protracker effects stuff
  2900                                  ;=============================================================================
  2901                                  
  2902                                  ;-----------------------------------------------------------------------------
  2903                                  ; Effect jump tables
  2904                                  ;-----------------------------------------------------------------------------
  2905                                  
  2906 00004FBE 90<rept>                align 4
  2907                                  
  2908                                  efxtable:
  2909 00004FC0 [8E070000]              	dd      efxarpeggio	; 0 - arpeggio
  2910 00004FC4 [BB040000]              	dd      efxnull		; 1 - porta up
  2911 00004FC8 [BB040000]              	dd      efxnull		; 2 - porta down
  2912 00004FCC [D9060000]              	dd      efxtoneporta	; 3 - tone porta
  2913 00004FD0 [E8060000]              	dd      efxvibrato	; 4 - vibrato
  2914 00004FD4 [BB040000]              	dd      efxnull		; 5 - tone+slide
  2915 00004FD8 [BB040000]              	dd      efxnull		; 6 - vibrato+slide
  2916 00004FDC [05080000]              	dd      efxtremolo	; 7 - tremolo
  2917 00004FE0 [BB040000]              	dd      efxnull		; 8 - unused
  2918 00004FE4 [10070000]              	dd      efxsampoffset	; 9 - sample offset
  2919 00004FE8 [BB040000]              	dd      efxnull		; A - volume slide
  2920 00004FEC [1C070000]              	dd      efxpattjump	; B - pattern jump
  2921 00004FF0 [2A070000]              	dd      efxsetvolume	; C - set volume
  2922 00004FF4 [38070000]              	dd      efxbreak	; D - break pattern
  2923 00004FF8 [BB040000]              	dd      efxnull		; E - extra effects
  2924 00004FFC [57070000]              	dd      efxsetspeed	; F - set speed
  2925                                  
  2926                                  efxtable2:
  2927 00005000 [BC040000]              	dd      efxarpeggio2	; 0 - arpeggio
  2928 00005004 [DE040000]              	dd      efxportaup	; 1 - porta up
  2929 00005008 [04050000]              	dd      efxportadown	; 2 - porta down
  2930 0000500C [2B050000]              	dd      efxtoneporta2	; 3 - tone porta
  2931 00005010 [64050000]              	dd      efxvibrato2	; 4 - vibrato
  2932 00005014 [C0050000]              	dd      efxtoneslide	; 5 - tone+slide
  2933 00005018 [CD050000]              	dd      efxvibslide	; 6 - vibrato+slide
  2934 0000501C [F4050000]              	dd      efxtremolo2	; 7 - tremolo
  2935 00005020 [BB040000]              	dd      efxnull		; 8 - unused
  2936 00005024 [BB040000]              	dd      efxnull		; 9 - sample offset
  2937 00005028 [D7050000]              	dd      efxvolslide	; A - volume slide
  2938 0000502C [BB040000]              	dd      efxnull		; B - pattern jump
  2939 00005030 [BB040000]              	dd      efxnull		; C - set volume
  2940 00005034 [BB040000]              	dd      efxnull		; D - break pattern
  2941 00005038 [BB040000]              	dd      efxnull		; E - extra effects
  2942 0000503C [BB040000]              	dd      efxnull		; F - set speed
  2943                                  
  2944                                  ;-----------------------------------------------------------------------------
  2945                                  ; Amiga period table
  2946                                  ;-----------------------------------------------------------------------------
  2947                                  
  2948                                  ;PeriodTable0:	
  2949                                  ;	dw	0
  2950                                  PeriodTable:
  2951 00005040 600DA00CE80B400B98-     	dw	3424,3232,3048,2880,2712,2560,2416,2280,2152,2032,1920,1812
  2952 00005049 0A000A7009E8086808-
  2953 00005052 F00780071407       
  2954 00005058 B0065006F405A0054C-     	dw	1712,1616,1524,1440,1356,1280,1208,1140,1076,1016,960,906
  2955 00005061 050005B80474043404-
  2956 0000506A F803C0038A03       
  2957 00005070 58032803FA02D002A6-     	dw	856,808,762,720,678,640,604,570,538,508,480,453
  2958 00005079 0280025C023A021A02-
  2959 00005082 FC01E001C501       
  2960 00005088 AC0194017D01680153-     	dw	428,404,381,360,339,320,302,285,269,254,240,226
  2961 00005091 0140012E011D010D01-
  2962 0000509A FE00F000E200       
  2963 000050A0 D600CA00BE00B400AA-     	dw	214,202,190,180,170,160,151,143,135,127,120,113
  2964 000050A9 00A00097008F008700-
  2965 000050B2 7F0078007100       
  2966 000050B8 6B0065005F005A0055-     	dw	107,101,95,90,85,80,75,71,67,63,60,56
  2967 000050C1 0050004B0047004300-
  2968 000050CA 3F003C003800       
  2969 000050D0 350032002F002D002A-     	dw	53,50,47,45,42,40,37,35,33,31,30,28
  2970 000050D9 002800250023002100-
  2971 000050E2 1F001E001C00       
  2972                                  
  2973                                  ;-----------------------------------------------------------------------------
  2974                                  ; Sinus wave table
  2975                                  ;-----------------------------------------------------------------------------
  2976                                  
  2977                                  SinTable:
  2978 000050E8 0019324A62788EA2B4-     	db	0,25,50,74,98,120,142,162,180,197,212,225
  2979 000050F1 C5D4E1             
  2980 000050F4 ECF4FAFEFFFEFAF4EC-     	db	236,244,250,254,255,254,250,244,236,225
  2981 000050FD E1                 
  2982 000050FE D4C5B4A28E78624A32-     	db	212,197,180,162,142,120,98,74,50,25
  2983 00005107 19                 
  2984                                  
  2985                                  ;=============================================================================
  2986                                  ;               PLAY.ASM - DATA
  2987                                  ;=============================================================================
  2988 00005108 00                      	db	0
  2989                                  msg_usage:
  2990 00005109 54696E79204D4F4420-     	db	'Tiny MOD Player for TRDOS 386 by Erdogan Tan. '
  2991 00005112 506C6179657220666F-
  2992 0000511B 72205452444F532033-
  2993 00005124 383620627920457264-
  2994 0000512D 6F67616E2054616E2E-
  2995 00005136 20                 
  2996 00005137 4F63746F6265722032-     	db	'October 2017.',10,13
  2997 00005140 3031372E0A0D       
  2998 00005146 75736167653A20746D-     	db	'usage: tmodplay filename.mod', 10,13,0
  2999 0000514F 6F64706C6179206669-
  3000 00005158 6C656E616D652E6D6F-
  3001 00005161 640A0D00           
  3002 00005165 32392F31302F323031-     	db	'29/10/2017',10,13,0
  3003 0000516E 370A0D00           
  3004                                  
  3005                                  Credits:
  3006 00005172 54696E79204D4F4420-     	db	'Tiny MOD Player v0.1b by Carlos Hasan. July 1993.'
  3007 0000517B 506C61796572207630-
  3008 00005184 2E3162206279204361-
  3009 0000518D 726C6F732048617361-
  3010 00005196 6E2E204A756C792031-
  3011 0000519F 3939332E           
  3012 000051A3 0A0D00                  	db	10,13,0
  3013                                  ErrorMesg:    
  3014 000051A6 4572726F72206C6F61-     	db 'Error loading Module file.',10,13,0
  3015 000051AF 64696E67204D6F6475-
  3016 000051B8 6C652066696C652E0A-
  3017 000051C1 0D00               
  3018                                  
  3019                                  ;MsgNotFound: db 'Sound Blaster not found or IRQ error.',10,13,0
  3020                                  ;MsgFound:    db 'Sound Blaster found at Address 2'
  3021                                  ;PortText:    db 'x0h, IRQ '
  3022                                  ;IrqText:     db 'x.',10,13,0
  3023                                  
  3024                                  trdos386_err_msg:
  3025 000051C3 5452444F5320333836-     		db 'TRDOS 386 System call error !', 10, 13,0
  3026 000051CC 2053797374656D2063-
  3027 000051D5 616C6C206572726F72-
  3028 000051DE 20210A0D00         
  3029                                  
  3030                                  ; 07/10/2017
  3031 000051E3 0A                      pattern_shift:	db 10
  3032                                  ;numtracks:	dw 4
  3033                                  ; 18/10/2017
  3034 000051E4 04000000                numtracks:	dd 4
  3035                                  
  3036                                  ;=============================================================================
  3037                                  ;               PLAYER.ASM - DATA
  3038                                  ;=============================================================================
  3039                                  
  3040                                  ;stmo:		db 1 ; stereo (2) or mono (1)  
  3041                                  ;bps:		db 8 ; bits per sample (8 or 16)
  3042                                  
  3043                                  ;19/10/2017
  3044 000051E8 02                      stmo:		db 2 ; stereo (2) or mono (1)  
  3045 000051E9 10                      bps:		db 16 ; bits per sample (8 or 16)
  3046                                  
  3047                                  Sample_Rate:
  3048 000051EA 2256                    MixSpeed:	dw 22050 ; Hz
  3049                                  
  3050                                  ; 13/11/2016
  3051 000051EC 303132333435363738-     hex_chars:	db "0123456789ABCDEF", 0
  3052 000051F5 3941424344454600   
  3053                                  ;
  3054                                  msgAC97Info:	
  3055 000051FD 0D0A                    		db 0Dh, 0Ah
  3056 000051FF 414339372041756469-     		db "AC97 Audio Controller & Codec Info", 0Dh, 0Ah 
  3057 00005208 6F20436F6E74726F6C-
  3058 00005211 6C6572202620436F64-
  3059 0000521A 656320496E666F0D0A 
  3060 00005223 56656E646F72204944-     		db "Vendor ID: "
  3061 0000522C 3A20               
  3062 0000522E 303030306820446576-     msgVendorId:	db "0000h Device ID: "
  3063 00005237 6963652049443A20   
  3064 0000523F 30303030680D0A          msgDevId:	db "0000h", 0Dh, 0Ah
  3065 00005246 4275733A20              		db "Bus: "
  3066 0000524B 303068204465766963-     msgBusNo:	db "00h Device: "
  3067 00005254 653A20             
  3068 00005257 3030682046756E6374-     msgDevNo:	db "00h Function: "
  3069 00005260 696F6E3A20         
  3070 00005265 303068                  msgFncNo	db "00h"
  3071 00005268 0D0A                    		db 0Dh, 0Ah
  3072 0000526A 4E414D4241523A20        		db "NAMBAR: "
  3073 00005272 30303030682020          msgNamBar	db "0000h  "
  3074 00005279 4E41424D4241523A20      		db "NABMBAR: "
  3075 00005282 303030306820204952-     msgNabmBar	db "0000h  IRQ: "
  3076 0000528B 513A20             
  3077 0000528E 3030                    msgIRQ:		dw 3030h
  3078 00005290 0D0A00                  		db 0Dh, 0Ah, 0
  3079                                  ;
  3080                                  ;; 13/11/2016 - Erdogan Tan (Ref: KolibriOS, codec.inc)
  3081                                  ;codec_id:	   dd 0
  3082                                  ;codec_chip_id:	   dd 0
  3083                                  ;codec_vendor_ids: dw 0
  3084                                  ;codec_chip_ids:   dw 0
  3085                                  
  3086                                  ;dword_str:	dd 30303030h, 30303030h
  3087                                  ;	 	db 'h', 0Dh, 0Ah, 0
  3088                                  
  3089                                  ;=============================================================================
  3090                                  ;        	uninitialized data
  3091                                  ;=============================================================================
  3092                                  
  3093                                  bss_start:
  3094                                  
  3095                                  ABSOLUTE bss_start
  3096                                  
  3097 00005293 <res 00000001>          alignb 4
  3098                                  
  3099                                  ;------------------------------------------------------------------------------
  3100                                  ; IFF/ILBM DATA
  3101                                  ;------------------------------------------------------------------------------
  3102                                  
  3103 00005294 <res 00000004>          LBM_FileHandle:	resd 1
  3104 00005298 <res 00000004>          LBM_FileSize:	resd 1
  3105                                  ;
  3106 0000529C <res 00000004>          picture.width:	resd 1 		; current picture width and height
  3107 000052A0 <res 00000004>          picture.height:	resd 1
  3108                                  
  3109                                  ;------------------------------------------------------------------------------
  3110                                  
  3111 000052A4 <res 00000004>          dev_vendor:	resd 1
  3112 000052A8 <res 00000004>          bus_dev_fn:	resd 1
  3113 000052AC <res 00000004>          stats_cmd:	resd 1
  3114 000052B0 <res 00000002>          ac97_NamBar:	resw 1
  3115 000052B2 <res 00000002>          ac97_NabmBar:	resw 1
  3116 000052B4 <res 00000001>          ac97_int_ln_reg: resb 1
  3117 000052B5 <res 00000001>          srb:		resb 1
  3118                                  
  3119                                  ; MODLOAD.ASM
  3120 000052B6 <res 00000004>          FileHandle:	resd 1
  3121 000052BA <res 0000043C>          Header:		resb ModHeader.size
  3122                                  
  3123                                  ; MODPLAY.ASM
  3124                                  ;MixSpeed:	    resw 1
  3125                                  
  3126                                  ModInfo:
  3127 000056F6 <res 00000001>          ModInfo.OrderLen:   resb 1
  3128 000056F7 <res 00000001>          ModInfo.ReStart:    resb 1
  3129 000056F8 <res 00000080>          ModInfo.Order:	    resb 128
  3130 00005778 <res 00000004>          ModInfo.Patterns:   resd 1
  3131                                  
  3132 0000577C <res 0000003E>          ModInfo.SampOfs:    resw 31
  3133 000057BA <res 0000003E>          ModInfo.SampSeg:    resw 31
  3134 000057F8 <res 0000003E>          ModInfo.SampLen:    resw 31
  3135 00005836 <res 0000003E>          ModInfo.SampRep:    resw 31
  3136 00005874 <res 0000003E>          ModInfo.SampRepLen: resw 31
  3137 000058B2 <res 0000003E>          ModInfo.SampVol:    resw 31
  3138                                  
  3139                                  ; MODPLAY.ASM
  3140                                  PitchTable:	;resw 857
  3141 000058F0 <res 00001AC2>          		resw 3425 ; 01/10/2017 (TMODPLAY.ASM)
  3142 000073B2 <res 00004100>          VolTable:	resb 16640
  3143 0000B4B2 <res 00001FEC>          MixBuffer       resb 8172 ; MixBufSize ; 7680 (960*8) ; 18/10/2017
  3144                                  
  3145                                  ; MODPLAY.ASM
  3146 0000D49E <res 00000001>          OrderPos:	resb 1
  3147 0000D49F <res 00000001>          Tempo:		resb 1
  3148 0000D4A0 <res 00000001>          TempoWait:	resb 1
  3149 0000D4A1 <res 00000001>          Bpm:		resb 1
  3150 0000D4A2 <res 00000001>          Row:		resb 1
  3151 0000D4A3 <res 00000001>          BreakRow:	resb 1
  3152 0000D4A4 <res 00000002>          BpmSamples:	resw 1
  3153 0000D4A6 <res 00000004>          BufPtr:		resd 1
  3154 0000D4AA <res 00000002>          BufLen:		resw 1
  3155 0000D4AC <res 00000004>          BufRep:		resd 1
  3156 0000D4B0 <res 00000004>          Note:		resd 1
  3157                                  ;Tracks:	resb TrackInfo.size*NumTracks
  3158                                  ; 07/10/2017
  3159 0000D4B4 <res 00000130>          Tracks:		resb TrackInfo.size*8
  3160                                  
  3161 0000D5E4 <res 0000000C>          alignb 16
  3162                                  
  3163                                  ; PLAY.ASM
  3164                                  ;Scope:		resw 320
  3165 0000D5F0 <res 00000200>          RowOfs:		resw 256
  3166                                  
  3167                                  ; 23/10/2017
  3168 0000D7F0 <res 00000200>          NewScope_L:	resw 256
  3169 0000D9F0 <res 00000200>          NewScope_R:	resw 256
  3170 0000DBF0 <res 00000200>          OldScope_L:	resw 256
  3171 0000DDF0 <res 00000200>          OldScope_R:	resw 256
  3172                                  
  3173                                  mod_file_name:
  3174 0000DFF0 <res 00000050>          		resb 80
  3175                                  
  3176                                  ; 20/10/2017 (modplay7.s, SB16)
  3177                                  ; 19/10/2017 (modplay6.s, AC97)
  3178 0000E040 <res 00000001>          pan_shift:	resb 1
  3179 0000E041 <res 00000001>          volume_level:	resb 1
  3180                                  
  3181 0000E042 <res 00000FBE>          alignb 4096
  3182                                  
  3183                                  Audio_Buffer:
  3184 0000F000 <res 00008000>          		resb BUFFERSIZE ; DMA Buffer Size / 2  (32768)
  3185                                  ;temp_buffer:
  3186                                  ;		;resb BUFFERSIZE / 4 ; 8192
  3187                                  ;		resb BUFFERSIZE / 2 ; 17/10/2017
  3188                                  
  3189 00017000 <res 00009000>          alignb 65536
  3190                                  
  3191                                  DMA_Buffer:
  3192 00020000 <res 00010000>          		resb 65536	
  3193                                  file_buffer:
  3194 00030000 <res 00060000>          		resb 65536*6
  3195                                  EOF:
