     1                                  ; ****************************************************************************
     2                                  ; playmod.s (for TRDOS 386)
     3                                  ; ----------------------------------------------------------------------------
     4                                  ; PLAYMOD.PRG ! VIA VT8237 MOD PLAYER & VGA DEMO program by Erdogan TAN
     5                                  ;
     6                                  ; 05/03/2017
     7                                  ;
     8                                  ; [ Last Modification: 17/03/2017 ]
     9                                  ;
    10                                  ; Derived from source code of 'PLAY.EXE' (TINYPLAY) by Carlos Hasan (1993)
    11                                  ;          PLAY.EXE: PLAY.ASM, MODLOAD.ASM, MODPLAY.ASM, SB.ASM
    12                                  ;
    13                                  ; Modified from 'TINYPLAY.PRG' ('tinyplay.s') source code by Erdogan Tan
    14                                  ;			                     (05/03/2017)
    15                                  ;
    16                                  ; Derived from source code of 'TINYPLAY.COM' ('TINYPLAY.ASM') by Erdogan Tan
    17                                  ;				      (04/03/2017) 
    18                                  ; Assembler: NASM 2.11
    19                                  ; ----------------------------------------------------------------------------
    20                                  ;	   nasm  playmod.s -l playmod.txt -o PLAYMOD.PRG	
    21                                  ; ****************************************************************************
    22                                  ; PLAYMOD.ASM by Erdogan Tan (for MSDOS) (15/02/2017)
    23                                  
    24                                  ; 01/03/2017
    25                                  ; 16/10/2016
    26                                  ; 29/04/2016
    27                                  ; TRDOS 386 system calls (temporary list!)
    28                                  _ver 	equ 0
    29                                  _exit 	equ 1
    30                                  _fork 	equ 2
    31                                  _read 	equ 3
    32                                  _write	equ 4
    33                                  _open	equ 5
    34                                  _close 	equ 6
    35                                  _wait 	equ 7
    36                                  _creat 	equ 8
    37                                  _link 	equ 9
    38                                  _unlink	equ 10
    39                                  _exec	equ 11
    40                                  _chdir	equ 12
    41                                  _time 	equ 13
    42                                  _mkdir 	equ 14
    43                                  _chmod	equ 15
    44                                  _chown	equ 16
    45                                  _break	equ 17
    46                                  _stat	equ 18
    47                                  _seek	equ 19
    48                                  _tell 	equ 20
    49                                  _mount	equ 21
    50                                  _umount	equ 22
    51                                  _setuid	equ 23
    52                                  _getuid	equ 24
    53                                  _stime	equ 25
    54                                  _quit	equ 26	
    55                                  _intr	equ 27
    56                                  _fstat	equ 28
    57                                  _emt 	equ 29
    58                                  _mdate 	equ 30
    59                                  _video 	equ 31
    60                                  _audio	equ 32
    61                                  _timer	equ 33
    62                                  _sleep	equ 34
    63                                  _msg    equ 35
    64                                  _geterr	equ 36
    65                                  _fpsave	equ 37
    66                                  _pri	equ 38
    67                                  _rele	equ 39
    68                                  _fff	equ 40
    69                                  _fnf	equ 41
    70                                  _alloc	equ 42
    71                                  _dalloc equ 43
    72                                  _calbac equ 44		
    73                                  
    74                                  %macro sys 1-4
    75                                      ; 29/04/2016 - TRDOS 386 (TRDOS v2.0)	
    76                                      ; 03/09/2015	
    77                                      ; 13/04/2015
    78                                      ; Retro UNIX 386 v1 system call.	
    79                                      %if %0 >= 2   
    80                                          mov ebx, %2
    81                                          %if %0 >= 3    
    82                                              mov ecx, %3
    83                                              %if %0 = 4
    84                                                 mov edx, %4   
    85                                              %endif
    86                                          %endif
    87                                      %endif
    88                                      mov eax, %1
    89                                      ;int 30h
    90                                      int 40h ; TRDOS 386 (TRDOS v2.0)	   
    91                                  %endmacro
    92                                  
    93                                  ; TRDOS 386 (and Retro UNIX 386 v1) system call format:
    94                                  ; sys systemcall (eax) <arg1 (ebx)>, <arg2 (ecx)>, <arg3 (edx)>
    95                                  
    96                                  ; ----------------------------------------------------------------------------
    97                                  ; Tiny MOD Player v0.1b by Carlos Hasan.
    98                                  ;	July 14th, 1993.
    99                                  
   100                                  ;=============================================================================
   101                                  ;               PLAYER.ASM
   102                                  ;=============================================================================
   103                                  ; Audio controller, codec & PCI functions are derived from '.wav file player 
   104                                  ; for DOS' source code by Jeff Leyda (PLAYER.EXE), Sep 02, 2002 .
   105                                  
   106                                  [BITS 32]
   107                                  [org 0]
   108                                  
   109                                  Start:
   110                                  	; clear bss
   111 00000000 B9[00000800]            	mov	ecx, EOF
   112 00000005 BF[20140000]            	mov	edi, bss_start
   113 0000000A 29F9                    	sub	ecx, edi
   114 0000000C D1E9                    	shr	ecx, 1
   115 0000000E 31C0                    	xor	eax, eax
   116 00000010 F366AB                  	rep	stosw
   117                                  
   118 00000013 E8CF010000              	call    DetectVT8233	; Detect the VT8233 Audio Device
   119                                  GetFileName:  
   120 00000018 89E6                    	mov	esi, esp
   121 0000001A AD                      	lodsd
   122 0000001B 83F802                  	cmp	eax, 2 ; two arguments 
   123                                  		; (program file name & mod file name)
   124 0000001E 0F82AB010000            	jb	pmsg_2017 ; nothing to do
   125                                  
   126 00000024 AD                      	lodsd ; program file name address 
   127 00000025 AD                      	lodsd ; mod file name address (file to be read)
   128 00000026 89C6                    	mov	esi, eax
   129 00000028 BF[08900000]            	mov	edi, mod_file_name
   130                                  ScanName:       
   131 0000002D AC                      	lodsb
   132 0000002E 84C0                    	test	al, al
   133 00000030 0F8499010000            	je	pmsg_2017
   134 00000036 3C20                    	cmp	al, 20h
   135 00000038 74F3                    	je	short ScanName	; scan start of name.
   136 0000003A AA                      	stosb
   137 0000003B B4FF                    	mov	ah, 0FFh
   138                                  a_0:	
   139 0000003D FEC4                    	inc	ah
   140                                  a_1:
   141 0000003F AC                      	lodsb
   142 00000040 AA                      	stosb
   143 00000041 3C2E                    	cmp	al, '.'
   144 00000043 74F8                    	je	short a_0	
   145 00000045 20C0                    	and	al, al
   146 00000047 75F6                    	jnz	short a_1
   147                                  
   148 00000049 08E4                    	or	ah, ah		; if period NOT found,
   149 0000004B 750B                    	jnz	short PrintMesg	; then add a .MOD extension.
   150                                  SetExt:
   151 0000004D 4F                      	dec	edi
   152 0000004E C7072E4D4F44            	mov	dword [edi], '.MOD'
   153 00000054 C6470400                	mov	byte [edi+4], 0
   154                                  PrintMesg:      
   155                                  	; Prints the Credits Text.
   156                                  	sys	_msg, Credits, 255, 0Fh
   156                              <1> 
   156                              <1> 
   156                              <1> 
   156                              <1> 
   156                              <1>  %if %0 >= 2
   156 00000058 BB[70120000]        <1>  mov ebx, %2
   156                              <1>  %if %0 >= 3
   156 0000005D B9FF000000          <1>  mov ecx, %3
   156                              <1>  %if %0 = 4
   156 00000062 BA0F000000          <1>  mov edx, %4
   156                              <1>  %endif
   156                              <1>  %endif
   156                              <1>  %endif
   156 00000067 B823000000          <1>  mov eax, %1
   156                              <1> 
   156 0000006C CD40                <1>  int 40h
   157                                  
   158                                  init_codec:
   159                                  	; init AC97 codec
   160                                  _a1:
   161 0000006E B041                    	mov	al, VIA_ACLINK_CTRL  ; AC link interface control (41h)
   162 00000070 E8E9020000              	call	pciRegRead8
   163                                  
   164 00000075 B040                    	mov	al, VIA_ACLINK_STAT  ; AC Link interface status (40h)
   165 00000077 E8E2020000              	call	pciRegRead8
   166                                  	
   167                                  	;movzx	eax, dl
   168                                  	;test	al, VIA_ACLINK_C00_READY  ; 1 ; primary codec ready ?
   169                                  	;jnz	short _a2
   170                                  
   171 0000007C E88C040000              	call	reset_codec
   172 00000081 732E                    	jnc	short _a2 ; EAX = 1
   173                                  
   174                                  	;test	al, VIA_ACLINK_C00_READY 	
   175                                          ;jnz     short _a2
   176                                  
   177                                  _codec_err:
   178                                  	sys	_msg, CodecErrMsg, 255, 0Fh
   178                              <1> 
   178                              <1> 
   178                              <1> 
   178                              <1> 
   178                              <1>  %if %0 >= 2
   178 00000083 BB[9E000000]        <1>  mov ebx, %2
   178                              <1>  %if %0 >= 3
   178 00000088 B9FF000000          <1>  mov ecx, %3
   178                              <1>  %if %0 = 4
   178 0000008D BA0F000000          <1>  mov edx, %4
   178                              <1>  %endif
   178                              <1>  %endif
   178                              <1>  %endif
   178 00000092 B823000000          <1>  mov eax, %1
   178                              <1> 
   178 00000097 CD40                <1>  int 40h
   179 00000099 E928010000                      jmp     Exit
   180                                  
   181 0000009E 436F64656320457272-     CodecErrMsg db "Codec Error #"
   181 000000A7 6F722023           
   182 000000AB 3020210D0A00            ErrNo	db	"0 !", CR,LF,0
   183                                  
   184                                  _a2:
   185                                  	; eax = 1
   186 000000B1 E8CB040000              	call	codec_io_w16 ; w32
   187                                  	
   188                                  	;call	detect_codec
   189                                  
   190 000000B6 E894050000              	call	channel_reset
   191                                  
   192 000000BB E8C90F0000              	call	write_ac97_dev_info 
   193                                  
   194                                  ; setup the Codec (actually mixer registers) 
   195 000000C0 E871030000                      call    codecConfig                     ; unmute codec, set rates.
   196 000000C5 7309                    	jnc	short LoadMod
   197                                  
   198 000000C7 0430                    	add	al, '0'
   199 000000C9 A2[AB000000]            	mov	[ErrNo], al
   200 000000CE EBB3                    	jmp	short _codec_err
   201                                  
   202                                  LoadMod:  
   203 000000D0 BF[08900000]            	mov	edi, mod_file_name
   204 000000D5 E8BD070000              	call    LoadModule		; Load the MODule...
   205                                  
   206 000000DA 66833D[37140000]00      	cmp     word [ErrorInfo], 0	; any error loading?
   207 000000E2 741B                    	je      short short PlayNow
   208                                  
   209                                  	; yes, print error and Exit.
   210                                  
   211                                  	sys	_msg, ErrorMesg, 255, 0Fh
   211                              <1> 
   211                              <1> 
   211                              <1> 
   211                              <1> 
   211                              <1>  %if %0 >= 2
   211 000000E4 BB[A4120000]        <1>  mov ebx, %2
   211                              <1>  %if %0 >= 3
   211 000000E9 B9FF000000          <1>  mov ecx, %3
   211                              <1>  %if %0 = 4
   211 000000EE BA0F000000          <1>  mov edx, %4
   211                              <1>  %endif
   211                              <1>  %endif
   211                              <1>  %endif
   211 000000F3 B823000000          <1>  mov eax, %1
   211                              <1> 
   211 000000F8 CD40                <1>  int 40h
   212                                  
   213 000000FA E9C7000000              	jmp     Exit
   214                                  
   215                                  PlayNow: 
   216                                  	; DIRECT MEMORY ACCESS (for Audio Controller)
   217                                  	; ebx = BDL buffer address (virtual, user)
   218                                  	; ecx = buffer size (in bytes)
   219                                  	; edx = upper limit = 0 = no limit
   220                                  
   221                                  	sys	_alloc, BdlBuffer, 4096, 0 
   221                              <1> 
   221                              <1> 
   221                              <1> 
   221                              <1> 
   221                              <1>  %if %0 >= 2
   221 000000FF BB[00800000]        <1>  mov ebx, %2
   221                              <1>  %if %0 >= 3
   221 00000104 B900100000          <1>  mov ecx, %3
   221                              <1>  %if %0 = 4
   221 00000109 BA00000000          <1>  mov edx, %4
   221                              <1>  %endif
   221                              <1>  %endif
   221                              <1>  %endif
   221 0000010E B82A000000          <1>  mov eax, %1
   221                              <1> 
   221 00000113 CD40                <1>  int 40h
   222 00000115 0F8283000000            	jc	error_exit
   223                                  
   224 0000011B A3[00900000]            	mov	[BDL_phy_buff], eax	; physical address
   225                                  					; of the buffer
   226                                  					; (which is needed
   227                                  					; for Audio controller)
   228                                  
   229                                  	; DIRECT MEMORY ACCESS (for Audio Controller)
   230                                  	; ebx = DMA buffer address (virtual, user)
   231                                  	; ecx = buffer size (in bytes)
   232                                  	; edx = upper limit = 0 = no limit
   233                                  
   234                                  	sys	_alloc, DmaBuffer, 65536, 0 
   234                              <1> 
   234                              <1> 
   234                              <1> 
   234                              <1> 
   234                              <1>  %if %0 >= 2
   234 00000120 BB[00000100]        <1>  mov ebx, %2
   234                              <1>  %if %0 >= 3
   234 00000125 B900000100          <1>  mov ecx, %3
   234                              <1>  %if %0 = 4
   234 0000012A BA00000000          <1>  mov edx, %4
   234                              <1>  %endif
   234                              <1>  %endif
   234                              <1>  %endif
   234 0000012F B82A000000          <1>  mov eax, %1
   234                              <1> 
   234 00000134 CD40                <1>  int 40h
   235 00000136 7266                    	jc	short error_exit
   236                                  
   237 00000138 A3[04900000]            	mov	[DMA_phy_buff], eax	; physical address
   238                                  					; of the buffer
   239                                  					; (which is needed
   240                                  					; for Audio controller)
   241                                      
   242 0000013D 66C705[75180000]22-     	mov     word [MixSpeed], 22050	; Mixing at 22.050 kHz
   242 00000145 56                 
   243                                  
   244 00000146 E83F0E0000              	call    StartPlaying
   245                                  
   246                                  	; SETUP INTERRUPT CALLBACK SERVICE
   247                                  	; 05/03/2017
   248 0000014B 8A1D[25140000]          	mov	bl, [ac97_int_ln_reg] ; IRQ number
   249 00000151 B702                    	mov	bh, 2 ; Link IRQ to user for callback service
   250 00000153 BA[C1020000]            	mov	edx, ac97_int_handler
   251                                  	sys	_calbac
   251                              <1> 
   251                              <1> 
   251                              <1> 
   251                              <1> 
   251                              <1>  %if %0 >= 2
   251                              <1>  mov ebx, %2
   251                              <1>  %if %0 >= 3
   251                              <1>  mov ecx, %3
   251                              <1>  %if %0 = 4
   251                              <1>  mov edx, %4
   251                              <1>  %endif
   251                              <1>  %endif
   251                              <1>  %endif
   251 00000158 B82C000000          <1>  mov eax, %1
   251                              <1> 
   251 0000015D CD40                <1>  int 40h
   252 0000015F 723D                    	jc	short error_exit
   253                                  
   254                                  	;; SETUP SIGNAL RESPONSE BYTE
   255                                  	;; 06/03/2017
   256                                  	;mov	bl, [ac97_int_ln_reg] ; IRQ number
   257                                  	;mov	bh, 1 ; Link IRQ to user for Signal Response Byte
   258                                  	;mov	edx, s_r_b ; Signal Response/Return Byte address  
   259                                  	;mov	ecx, 0FFh ; Signal Response/Return Byte value  
   260                                  	;sys	_calbac
   261                                  	;jc	short error_exit
   262                                  
   263 00000161 66B81300                	mov     ax, 0013h	; Set Mode 320x200x256
   264 00000165 CD31                    	int     31h
   265                                  
   266 00000167 B980000000              	mov     ecx, 128	; Make a lookup table
   267 0000016C 31DB                    	xor     ebx, ebx	; for fastest pixel
   268 0000016E BA002D0000              	mov     edx, 320*(100-64)	; addressing.
   269                                  MakeOfs:        
   270 00000173 668993[50750000]        	mov     [RowOfs+ebx], dx
   271 0000017A 668993[52750000]        	mov     [RowOfs+ebx+2], dx
   272 00000181 6681C24001              	add     dx, 320
   273 00000186 83C304                  	add     ebx, 4
   274 00000189 E2E8                    	loop    MakeOfs
   275                                  
   276                                  	; DIRECT VGA MEMORY ACCESS
   277                                  	; bl = 0, bh = 5
   278                                  	; Direct access/map to VGA memory (0A0000h)
   279                                  
   280                                  	sys	_video, 0500h
   280                              <1> 
   280                              <1> 
   280                              <1> 
   280                              <1> 
   280                              <1>  %if %0 >= 2
   280 0000018B BB00050000          <1>  mov ebx, %2
   280                              <1>  %if %0 >= 3
   280                              <1>  mov ecx, %3
   280                              <1>  %if %0 = 4
   280                              <1>  mov edx, %4
   280                              <1>  %endif
   280                              <1>  %endif
   280                              <1>  %endif
   280 00000190 B81F000000          <1>  mov eax, %1
   280                              <1> 
   280 00000195 CD40                <1>  int 40h
   281 00000197 3D00000A00              	cmp	eax, 0A0000h
   282 0000019C 7418                    	je	short _a3
   283                                  error_exit:
   284                                  	sys	_msg, trdos386_err_msg, 255, 0Eh
   284                              <1> 
   284                              <1> 
   284                              <1> 
   284                              <1> 
   284                              <1>  %if %0 >= 2
   284 0000019E BB[C1120000]        <1>  mov ebx, %2
   284                              <1>  %if %0 >= 3
   284 000001A3 B9FF000000          <1>  mov ecx, %3
   284                              <1>  %if %0 = 4
   284 000001A8 BA0E000000          <1>  mov edx, %4
   284                              <1>  %endif
   284                              <1>  %endif
   284                              <1>  %endif
   284 000001AD B823000000          <1>  mov eax, %1
   284                              <1> 
   284 000001B2 CD40                <1>  int 40h
   285 000001B4 EB10                    	jmp	short Exit
   286                                  
   287                                  ; Note: Normally IRQ 0 calls the ModPlay Polling at 18.2Hz thru
   288                                  ;       the software interrupt 1Ch. If the IRQ 0 is disabled, then
   289                                  ;       the INT 1Ch MUST BE CALLED at least MixSpeed/1024 times per
   290                                  ;       second, or the module will sound "looped".
   291                                  ;       Because we need better sync with the ModPlayer to draw the scope,
   292                                  ;       the polling is called from my routine, and then the irq 0 must be
   293                                  ;       disabled. The [DmaBuffer] points to the current buffer of 8-bit
   294                                  ;       samples played by the Sound Blaster. Note that some samples are
   295                                  ;       discarded in the next code, just for fun!
   296                                  
   297                                  _a3:
   298 000001B6 E8DA040000              	call	ModPlay ; 13/02/2017
   299                                  
   300                                  _s_exit:
   301 000001BB E8700E0000              	call	StopPlaying	; STOP!
   302                                  
   303 000001C0 66B80300                	mov     ax, 0003h	; Set Text Mode 80x25x16
   304 000001C4 CD31                    	int     31h
   305                                  Exit:           
   306                                  	;call    FreeModule	; Free MODule core.
   307                                  	
   308                                  	sys 	_exit	; Bye !
   308                              <1> 
   308                              <1> 
   308                              <1> 
   308                              <1> 
   308                              <1>  %if %0 >= 2
   308                              <1>  mov ebx, %2
   308                              <1>  %if %0 >= 3
   308                              <1>  mov ecx, %3
   308                              <1>  %if %0 = 4
   308                              <1>  mov edx, %4
   308                              <1>  %endif
   308                              <1>  %endif
   308                              <1>  %endif
   308 000001C6 B801000000          <1>  mov eax, %1
   308                              <1> 
   308 000001CB CD40                <1>  int 40h
   309                                  here:
   310 000001CD EBFE                    	jmp	short here
   311                                  
   312                                  pmsg_2017:
   313                                  	sys	_msg, msg_2017, 255, 0Fh
   313                              <1> 
   313                              <1> 
   313                              <1> 
   313                              <1> 
   313                              <1>  %if %0 >= 2
   313 000001CF BB[0A120000]        <1>  mov ebx, %2
   313                              <1>  %if %0 >= 3
   313 000001D4 B9FF000000          <1>  mov ecx, %3
   313                              <1>  %if %0 = 4
   313 000001D9 BA0F000000          <1>  mov edx, %4
   313                              <1>  %endif
   313                              <1>  %endif
   313                              <1>  %endif
   313 000001DE B823000000          <1>  mov eax, %1
   313                              <1> 
   313 000001E3 CD40                <1>  int 40h
   314 000001E5 EBDF                    	jmp	short Exit
   315                                  
   316                                  DetectVT8233:
   317 000001E7 B806115930              	mov     eax, (VT8233_DID << 16) + VIA_VID
   318 000001EC E815020000                      call    pciFindDevice
   319 000001F1 734F                            jnc     short _1
   320                                  
   321                                  ; couldn't find the audio device!
   322                                  	sys	_msg, noDevMsg, 255, 0Fh
   322                              <1> 
   322                              <1> 
   322                              <1> 
   322                              <1> 
   322                              <1>  %if %0 >= 2
   322 000001F3 BB[0B020000]        <1>  mov ebx, %2
   322                              <1>  %if %0 >= 3
   322 000001F8 B9FF000000          <1>  mov ecx, %3
   322                              <1>  %if %0 = 4
   322 000001FD BA0F000000          <1>  mov edx, %4
   322                              <1>  %endif
   322                              <1>  %endif
   322                              <1>  %endif
   322 00000202 B823000000          <1>  mov eax, %1
   322                              <1> 
   322 00000207 CD40                <1>  int 40h
   323 00000209 EBBB                            jmp     short Exit
   324                                  
   325                                  noDevMsg:
   326 0000020B 4572726F723A20556E-     	db "Error: Unable to find VIA VT8233 based audio device!",CR,LF,0
   326 00000214 61626C6520746F2066-
   326 0000021D 696E64205649412056-
   326 00000226 543832333320626173-
   326 0000022F 656420617564696F20-
   326 00000238 646576696365210D0A-
   326 00000241 00                 
   327                                  
   328                                  _1:
   329                                  	; 05/03/2017 (TRDOS 386)
   330                                  	; 12/11/2016
   331                                  	; Erdogan Tan - 8/11/2016
   332                                  	; References: Kolibrios - vt823x.asm (2016)
   333                                  	;	      VIA VT8235 V-Link South Bridge (VT8235-VIA.PDF)(2002)
   334                                  	;	      lowlevel.eu - AC97 (2016)
   335                                  	;	      .wav player for DOS by Jeff Leyda (2002) -this file-
   336                                  	;	      Linux kernel - via82xx.c (2016)
   337                                  
   338                                  	; eax = BUS/DEV/FN
   339                                  	;	00000000BBBBBBBBDDDDDFFF00000000
   340                                  	; edx = DEV/VENDOR
   341                                  	;	DDDDDDDDDDDDDDDDVVVVVVVVVVVVVVVV
   342                                  
   343 00000242 A3[27140000]            	mov	[bus_dev_fn], eax
   344 00000247 8915[2B140000]          	mov	[dev_vendor], edx
   345                                  
   346                                  	; init controller
   347 0000024D B004                    	mov	al, PCI_CMD_REG ; command register (04h)
   348 0000024F E81D010000              	call	pciRegRead32
   349                                  
   350                                  	; eax = BUS/DEV/FN/REG
   351                                  	; edx = STATUS/COMMAND
   352                                  	; 	SSSSSSSSSSSSSSSSCCCCCCCCCCCCCCCC
   353 00000254 8915[2F140000]          	mov	[stats_cmd], edx
   354                                  
   355 0000025A B010                    	mov	al, PCI_IO_BASE ; IO base address register (10h)
   356 0000025C E810010000              	call	pciRegRead32
   357                                  
   358 00000261 6683E2C0                	and     dx, 0FFC0h	; IO_ADDR_MASK (0FFFE) ?
   359 00000265 668915[33140000]                mov     [ac97_io_base], dx
   360                                  
   361 0000026C B03C                    	mov	al, AC97_INT_LINE ; Interrupt line register (3Ch)
   362 0000026E E8FE000000              	call	pciRegRead32
   363                                  
   364 00000273 81E2FF000000            	and 	edx, 0FFh
   365 00000279 8815[25140000]            	mov     [ac97_int_ln_reg], dl
   366                                  
   367                                  	; 05/03/2017 (TRDOS 386, INT 34h, IOCTL Interrupt)
   368                                  	; (Note: Interrupts are already enabled by TRDOS 386 kernel!)
   369                                  	; 28/11/2016
   370 0000027F 6689D1                  	mov	cx, dx
   371                                  
   372                                  	;in	al, 0A1h ; irq 8-15
   373 00000282 B2A1                    	mov	dl, 0A1h
   374 00000284 28E4                    	sub	ah, ah ; 0 ; inb
   375 00000286 CD34                    	int	34h
   376                                  
   377                                  	;mov	ah, al
   378 00000288 88C3                    	mov	bl, al
   379                                  
   380                                  	;in	al, 21h  ; irq 0-7 
   381 0000028A B221                    	mov	dl, 21h	
   382                                  	;mov	ah, 0 ; inb
   383 0000028C CD34                    	int	34h	
   384                                  
   385 0000028E 88DC                    	mov	ah, bl
   386 00000290 660FB3C8                 	btr	ax, cx	 ; unmask ; 17/03/2017
   387 00000294 88E3                    	mov	bl, ah
   388                                  
   389                                  	;out	21h, al  ; enable interrupt (if irq <= 7)
   390 00000296 B401                    	mov	ah, 1 ; outb
   391 00000298 CD34                    	int	34h
   392                                  
   393                                  	;mov	al, ah
   394 0000029A 88D8                    	mov	al, bl
   395                                  	;out	0A1h, al ; enable interrupt (if irq > 7)
   396 0000029C B2A1                    	mov	dl, 0A1h
   397                                  	;mov	ah, 1 ; outb
   398 0000029E CD34                    	int	34h		
   399                                  
   400 000002A0 66BAD104                	mov	dx, 4D1h	; 8259 ELCR1
   401                                        	;in	al, dx
   402 000002A4 FECC                    	dec	ah ; 0 ; inb
   403 000002A6 CD34                    	int	34h
   404                                  
   405                                  	;mov	ah, al
   406 000002A8 88C3                    	mov	bl, al
   407                                  	
   408                                  	;mov	dx, 4D0h 
   409 000002AA FECA                    	dec	dl
   410                                  	;in	al, dx
   411                                  	;mov	ah, 0 ; inb
   412 000002AC CD34                    	int	34h
   413                                  
   414 000002AE 88DC                    	mov	ah, bl
   415 000002B0 660FABC8                	bts	ax, cx
   416 000002B4 88E3                    	mov	bl, ah
   417                                  
   418                                  	;mov	dx, 4D0h
   419                                  	;out	dx, al		; set level-triggered mode
   420 000002B6 B401                    	mov	ah, 1 ; outb	
   421 000002B8 CD34                    	int	34h
   422                                  
   423                                  	;mov	al, ah
   424 000002BA 88D8                    	mov	al, bl
   425                                  	;mov	dx, 4D1h
   426 000002BC FEC2                    	inc	dl
   427                                  	;out	dx, al		; set level-triggered mode
   428                                  	;mov	ah, 1 ; outb	
   429 000002BE CD34                    	int	34h
   430                                  
   431 000002C0 C3                      	retn
   432                                  
   433                                  ac97_int_handler:
   434                                  	; 14/03/2017
   435                                  	; 06/03/2017 (Signal Response Byte Check)
   436                                  	; 05/03/2017 (Modified for TRDOS 386 IRQ callback method)
   437                                  
   438 000002C1 803D[23140000]01        	cmp	byte [uLVI], 1
   439 000002C8 7337                    	jnb	short _busy
   440                                  
   441 000002CA C605[23140000]01        	mov	byte [uLVI], 1
   442                                  
   443 000002D1 C605[22140000]00        	mov	byte [irq_status], 0
   444                                  
   445 000002D8 66BA0000                        mov     dx, VIADEV_PLAYBACK + VIA_REG_OFFSET_STATUS
   446 000002DC E8D2020000                      call    ctrl_io_r8
   447                                  
   448 000002E1 A880                    	test    al, VIA_REG_STAT_ACTIVE
   449 000002E3 740E                            jz      short _callback_retn
   450                                  
   451 000002E5 2407                            and     al, VIA_REG_STAT_EOL + VIA_REG_STAT_FLAG + VIA_REG_STAT_STOPPED
   452 000002E7 A2[22140000]            	mov	[irq_status], al
   453 000002EC 7405                            jz	short _callback_retn
   454                                  
   455                                  	; 28/11/2016 - Erdogan Tan
   456 000002EE E8F7040000              	call	tuneLoop
   457                                  _callback_retn:
   458 000002F3 C605[23140000]00        	mov	byte [uLVI], 0 ; 14/03/2017
   459                                  _callback_bsy_retn:
   460                                  	sys	_rele ; return from callback service
   460                              <1> 
   460                              <1> 
   460                              <1> 
   460                              <1> 
   460                              <1>  %if %0 >= 2
   460                              <1>  mov ebx, %2
   460                              <1>  %if %0 >= 3
   460                              <1>  mov ecx, %3
   460                              <1>  %if %0 = 4
   460                              <1>  mov edx, %4
   460                              <1>  %endif
   460                              <1>  %endif
   460                              <1>  %endif
   460 000002FA B827000000          <1>  mov eax, %1
   460                              <1> 
   460 000002FF CD40                <1>  int 40h
   461                                  _busy:
   462                                  	; 28/11/2016 - Erdogan Tan
   463 00000301 A0[22140000]                    mov     al, [irq_status]   ;; ack ;;
   464 00000306 66BA0000                        mov     dx, VIADEV_PLAYBACK + VIA_REG_OFFSET_STATUS
   465 0000030A E898020000                      call    ctrl_io_w8
   466                                  
   467                                  	;jmp	short _callback_bsy_retn ; 14/03/2017
   468 0000030F EBE2                    	jmp	short _callback_retn ; 17/03/2017
   469                                  
   470                                  
   471                                  ;=============================================================================
   472                                  ;               PCI.ASM
   473                                  ;=============================================================================
   474                                  
   475                                  ; EQUATES
   476                                  
   477                                  ;constants of stuff that seem hard to remember at times.
   478                                  
   479                                  TRUE  EQU 1
   480                                  FALSE EQU 0
   481                                  
   482                                  ENABLED  EQU 1
   483                                  DISABLED EQU 0
   484                                  
   485                                  BIT0  EQU 1
   486                                  BIT1  EQU 2
   487                                  BIT2  EQU 4
   488                                  BIT3  EQU 8
   489                                  BIT4  EQU 10h
   490                                  BIT5  EQU 20h
   491                                  BIT6  EQU 40h
   492                                  BIT7  EQU 80h
   493                                  BIT8  EQU 100h
   494                                  BIT9  EQU 200h
   495                                  BIT10 EQU 400h
   496                                  BIT11 EQU 800h
   497                                  BIT12 EQU 1000h
   498                                  BIT13 EQU 2000h
   499                                  BIT14 EQU 4000h
   500                                  BIT15 EQU 8000h
   501                                  BIT16 EQU 10000h
   502                                  BIT17 EQU 20000h
   503                                  BIT18 EQU 40000h
   504                                  BIT19 EQU 80000h
   505                                  BIT20 EQU 100000h
   506                                  BIT21 EQU 200000h
   507                                  BIT22 EQU 400000h
   508                                  BIT23 EQU 800000h
   509                                  BIT24 EQU 1000000h
   510                                  BIT25 EQU 2000000h
   511                                  BIT26 EQU 4000000h
   512                                  BIT27 EQU 8000000h
   513                                  BIT28 EQU 10000000h
   514                                  BIT29 EQU 20000000h
   515                                  BIT30 EQU 40000000h
   516                                  BIT31 EQU 80000000h
   517                                  
   518                                  ;special characters
   519                                  NUL     EQU 0
   520                                  NULL    EQU 0
   521                                  BELL    EQU 07
   522                                  BS      EQU 08
   523                                  TAB     EQU 09
   524                                  LF      EQU 10
   525                                  CR      EQU 13
   526                                  ESCAPE  EQU 27           ;ESC is a reserved word....
   527                                  
   528                                  
   529                                  ;file stuff
   530                                  READONLY  EQU   BIT0
   531                                  HIDDEN    EQU   BIT1
   532                                  SYSTEM    EQU   BIT2
   533                                  VOLUME    EQU   BIT3         ;ignored for file access
   534                                  DIRECTORY EQU   BIT4         ;must be 0 for file access
   535                                  ARCHIVE   EQU   BIT5
   536                                  SHAREABLE EQU   BIT7         ;for novell networks
   537                                  OPEN	EQU	2	; open existing file
   538                                  CREATE	EQU	1	; create new file
   539                                  
   540                                  
   541                                  ; PCI equates
   542                                  ; PCI function address (PFA)
   543                                  ; bit 31 = 1
   544                                  ; bit 23:16 = bus number     (0-255)
   545                                  ; bit 15:11 = device number  (0-31)
   546                                  ; bit 10:8 = function number (0-7)
   547                                  ; bit 7:0 = register number  (0-255)
   548                                  
   549                                  IO_ADDR_MASK    EQU     0FFFEh          ; mask off bit 0 for reading BARs
   550                                  PCI_INDEX_PORT  EQU     0CF8h
   551                                  PCI_DATA_PORT   EQU     0CFCh
   552                                  PCI32           EQU     BIT31           ; bitflag to signal 32bit access
   553                                  PCI16           EQU     BIT30           ; bitflag for 16bit access
   554                                  
   555                                  PCI_FN0         EQU     0 << 8
   556                                  PCI_FN1         EQU     1 << 8
   557                                  PCI_FN2         EQU     2 << 8
   558                                  PCI_FN3         EQU     3 << 8
   559                                  PCI_FN4         EQU     4 << 8
   560                                  PCI_FN5         EQU     5 << 8
   561                                  PCI_FN6         EQU     6 << 8
   562                                  PCI_FN7         EQU     7 << 8
   563                                  
   564                                  PCI_CMD_REG	EQU	04h	; reg 04, command reg
   565                                   IO_ENA		EQU	BIT0	; i/o decode enable
   566                                   MEM_ENA	EQU	BIT1	; memory decode enable
   567                                   BM_ENA                 EQU     BIT2	; bus master enable
   568                                  
   569                                  ; CODE
   570                                  
   571                                  ; PCI device register reader/writers.
   572                                  
   573                                  ; 05/03/2017 (TRDOS 386, INT 34h, IOCTL interrupt modifications)
   574                                  ; NASM version: Erdogan Tan (29/11/2016)
   575                                  
   576                                  ;===============================================================
   577                                  ; 8/16/32bit PCI reader
   578                                  ;
   579                                  ; Entry: EAX=PCI Bus/Device/fn/register number
   580                                  ;           BIT30 set if 32 bit access requested
   581                                  ;           BIT29 set if 16 bit access requested
   582                                  ;           otherwise defaults to 8bit read
   583                                  ;
   584                                  ; Exit:  DL,DX,EDX register data depending on requested read size
   585                                  ;
   586                                  ; Note: this routine is meant to be called via pciRegRead8, pciRegread16,
   587                                  ;	or pciRegRead32, listed below.
   588                                  ;
   589                                  ; Note2: don't attempt to read 32bits of data from a non dword aligned reg
   590                                  ;	 number.  Likewise, don't do 16bit reads from non word aligned reg #
   591                                  ; 
   592                                  pciRegRead:
   593 00000311 53                      	push	ebx
   594 00000312 51                      	push	ecx
   595 00000313 89C3                            mov     ebx, eax		; save eax, dh
   596 00000315 88F1                            mov     cl, dh
   597                                  
   598 00000317 25FFFFFFBF                      and     eax, (~PCI32)+PCI16	; clear out data size request
   599 0000031C 0D00000080                      or      eax, BIT31		; make a PCI access request
   600 00000321 24FC                            and     al, ~3 ; NOT 3		; force index to be dword
   601                                  
   602 00000323 66BAF80C                        mov     dx, PCI_INDEX_PORT
   603                                          ;out	dx, eax			; write PCI selector
   604 00000327 53                      	push	ebx
   605 00000328 89C3                    	mov	ebx, eax ; Data dword		
   606 0000032A B405                    	mov	ah, 5	; outd (32 bit write)
   607 0000032C CD34                    	int	34h	
   608 0000032E 5B                      	pop	ebx
   609                                  
   610 0000032F 66BAFC0C                        mov     dx, PCI_DATA_PORT
   611 00000333 88D8                            mov     al, bl
   612 00000335 2403                            and     al, 3			; figure out which port to
   613 00000337 00C2                            add     dl, al			; read to
   614                                  
   615                                  	;in     eax, dx			; do 32bit read
   616 00000339 B404                            mov	ah, 4	; ind (32 bit read)
   617 0000033B CD34                    	int	34h
   618                                  
   619 0000033D F7C300000080            	test    ebx, PCI32
   620 00000343 7402                            jz      short _pregr1
   621                                  
   622 00000345 89C2                            mov     edx, eax		; return 32bits of data
   623                                  _pregr1:
   624 00000347 6689C2                  	mov     dx, ax			; return 16bits of data
   625 0000034A F7C3000000C0                    test    ebx, PCI32+PCI16
   626 00000350 7502                            jnz     short _pregr2
   627 00000352 88CE                            mov     dh, cl			; restore dh for 8 bit read
   628                                  _pregr2:
   629 00000354 89D8                            mov     eax, ebx		; restore eax
   630 00000356 25FFFFFFBF                      and     eax, (~PCI32)+PCI16	; clear out data size request
   631 0000035B 59                      	pop	ecx
   632 0000035C 5B                      	pop	ebx
   633 0000035D C3                      	retn
   634                                  
   635                                  pciRegRead8:
   636 0000035E 25FFFFFF3F                      and     eax, (~PCI16)+PCI32	; set up 8 bit read size
   637 00000363 EBAC                            jmp     short pciRegRead	; call generic PCI access
   638                                  
   639                                  pciRegRead16:
   640 00000365 25FFFFFF3F                      and     eax, (~PCI16)+PCI32	; set up 16 bit read size
   641 0000036A 0D00000040                      or      eax, PCI16		; call generic PCI access
   642 0000036F EBA0                            jmp     short pciRegRead
   643                                  
   644                                  pciRegRead32:
   645 00000371 25FFFFFF3F                      and     eax, (~PCI16)+PCI32	; set up 32 bit read size
   646 00000376 0D00000080                      or      eax, PCI32		; call generic PCI access
   647 0000037B EB94                            jmp     short pciRegRead
   648                                  
   649                                  ;===============================================================
   650                                  ; 8/16/32bit PCI writer
   651                                  ;
   652                                  ; Entry: EAX=PCI Bus/Device/fn/register number
   653                                  ;           BIT31 set if 32 bit access requested
   654                                  ;           BIT30 set if 16 bit access requested
   655                                  ;           otherwise defaults to 8bit read
   656                                  ;        DL/DX/EDX data to write depending on size
   657                                  ;
   658                                  ;
   659                                  ; note: this routine is meant to be called via pciRegWrite8, pciRegWrite16,
   660                                  ; 	or pciRegWrite32 as detailed below.
   661                                  ;
   662                                  ; Note2: don't attempt to write 32bits of data from a non dword aligned reg
   663                                  ;	 number.  Likewise, don't do 16bit writes from non word aligned reg #
   664                                  ;
   665                                  pciRegWrite:
   666 0000037D 53                      	push	ebx
   667 0000037E 51                      	push	ecx
   668 0000037F 89C3                            mov     ebx, eax		; save eax, dx
   669 00000381 89D1                            mov     ecx, edx
   670 00000383 0D00000080                      or      eax, BIT31		; make a PCI access request
   671 00000388 25FFFFFFBF                      and     eax, ~PCI16 ; NOT PCI16	; clear out data size request
   672 0000038D 24FC                            and     al, ~3 ; NOT 3		; force index to be dword
   673                                  
   674 0000038F 66BAF80C                        mov     dx, PCI_INDEX_PORT
   675                                          ;out	dx, eax			; write PCI selector
   676 00000393 53                      	push	ebx
   677 00000394 89C3                    	mov	ebx, eax ; Data dword		
   678 00000396 B405                    	mov	ah, 5	; outd (32 bit write)
   679 00000398 CD34                    	int	34h	
   680 0000039A 8B1C24                  	mov	ebx, [esp]
   681                                  
   682 0000039D 66BAFC0C                        mov     dx, PCI_DATA_PORT
   683 000003A1 88D8                            mov     al, bl
   684 000003A3 2403                            and     al, 3			; figure out which port to
   685 000003A5 00C2                            add     dl, al			; write to
   686                                  
   687                                  	; ? (05/03/2017)
   688 000003A7 89D0                            mov     eax, edx		; put data into eax 
   689 000003A9 6689C8                          mov     ax, cx
   690                                  
   691                                  	;out	dx, al
   692 000003AC 6689C3                  	mov	bx, ax
   693 000003AF B401                    	mov	ah, 1 ; outb (8 bit write)
   694 000003B1 CD34                    	int	34h		
   695 000003B3 6689D8                  	mov 	ax, bx
   696 000003B6 5B                      	pop	ebx
   697                                  		
   698 000003B7 F7C3000000C0                    test    ebx, PCI16+PCI32	; only 8bit access? bail
   699 000003BD 7419                            jz      short _pregw1
   700                                  
   701                                  	;out	dx, ax			; write 16 bit value
   702 000003BF 53                              push	ebx
   703 000003C0 6689C3                  	mov	bx, ax
   704 000003C3 B403                    	mov	ah, 3 ; outw (16 bit write)
   705 000003C5 CD34                    	int	34h
   706 000003C7 5B                      	pop	ebx        
   707                                  
   708 000003C8 F7C300000040            	test    ebx, PCI16		; 16bit requested?  bail
   709 000003CE 7508                            jnz     short _pregw1
   710                                  
   711                                          ;out	dx, eax			; write full 32bit
   712 000003D0 53                      	push	ebx
   713 000003D1 89C3                    	mov	ebx, eax
   714 000003D3 B405                    	mov	ah, 5 ; outd (32 bit write)
   715 000003D5 CD34                    	int	34h
   716 000003D7 5B                      	pop	ebx      
   717                                  
   718                                  _pregw1:
   719 000003D8 89D8                            mov     eax, ebx		; restore eax
   720 000003DA 25FFFFFFBF                      and     eax, (~PCI32)+PCI16	; clear out data size request
   721 000003DF 89CA                            mov     edx, ecx		; restore dx
   722 000003E1 59                      	pop	ecx
   723 000003E2 5B                      	pop	ebx
   724 000003E3 C3                      	retn
   725                                  
   726                                  pciRegWrite8:
   727 000003E4 25FFFFFF3F                      and     eax, (~PCI16)+PCI32	; set up 8 bit write size
   728 000003E9 EB92                            jmp	short pciRegWrite	; call generic PCI access
   729                                  
   730                                  pciRegWrite16:
   731 000003EB 25FFFFFF3F                      and     eax, (~PCI16)+PCI32	; set up 16 bit write size
   732 000003F0 0D00000040                      or      eax, PCI16		; call generic PCI access
   733 000003F5 EB86                            jmp	short pciRegWrite
   734                                  
   735                                  pciRegWrite32:
   736 000003F7 25FFFFFF3F                      and     eax, (~PCI16)+PCI32	; set up 32 bit write size
   737 000003FC 0D00000080                      or      eax, PCI32		; call generic PCI access
   738 00000401 E977FFFFFF                      jmp	pciRegWrite
   739                                  
   740                                  ;===============================================================
   741                                  ; PCIFindDevice: scan through PCI space looking for a device+vendor ID
   742                                  ;
   743                                  ; Entry: EAX=Device+Vendor ID
   744                                  ;
   745                                  ;  Exit: EAX=PCI address if device found
   746                                  ;	 EDX=Device+Vendor ID
   747                                  ;        CY clear if found, set if not found. EAX invalid if CY set.
   748                                  ;
   749                                  ; [old stackless] Destroys: ebx, esi, edi, cl
   750                                  ;
   751                                  pciFindDevice:
   752                                  	;push	ecx
   753 00000406 50                      	push	eax
   754                                  	;push	esi
   755                                  	;push	edi
   756                                  
   757 00000407 89C6                            mov     esi, eax                ; save off vend+device ID
   758 00000409 BF00FFFF7F                      mov     edi, (80000000h - 100h) ; start with bus 0, dev 0 func 0
   759                                  
   760                                  nextPCIdevice:
   761 0000040E 81C700010000                    add     edi, 100h
   762 00000414 81FF00F8FF80                    cmp     edi, 80FFF800h	; scanned all devices?
   763 0000041A F9                              stc
   764 0000041B 740C                            je      short PCIScanExit       ; not found
   765                                  
   766 0000041D 89F8                            mov     eax, edi                ; read PCI registers
   767 0000041F E84DFFFFFF                      call    pciRegRead32
   768 00000424 39F2                            cmp     edx, esi                ; found device?
   769 00000426 75E6                            jne     short nextPCIdevice
   770 00000428 F8                              clc
   771                                  
   772                                  PCIScanExit:
   773 00000429 9C                      	pushf
   774 0000042A B800000080              	mov	eax, BIT31
   775 0000042F F7D0                    	not	eax
   776 00000431 21F8                    	and	eax, edi	; return only bus/dev/fn #
   777 00000433 9D                      	popf
   778                                  
   779                                  	;pop	edi
   780                                  	;pop	esi
   781 00000434 5A                      	pop	edx
   782                                  	;pop	ecx
   783 00000435 C3                      	retn
   784                                  
   785                                  ;=============================================================================
   786                                  ;               CODEC.ASM
   787                                  ;=============================================================================
   788                                  
   789                                  ; EQUATES
   790                                  
   791                                  ;Codec registers.
   792                                  ;
   793                                  ;Not all codecs are created equal. Refer to the spec for your specific codec.
   794                                  ;
   795                                  ;All registers are 16bits wide.  Access to codec registers over the AC97 link
   796                                  ;is defined by the OEM.  
   797                                  ;
   798                                  ;Secondary codec's are accessed by ORing in BIT7 of all register accesses.
   799                                  ;
   800                                  
   801                                  ; each codec/mixer register is 16bits
   802                                  
   803                                  CODEC_RESET_REG                 equ     00      ; reset codec
   804                                  CODEC_MASTER_VOL_REG            equ     02      ; master volume
   805                                  CODEC_HP_VOL_REG                equ     04      ; headphone volume
   806                                  CODEC_MASTER_MONO_VOL_REG       equ     06      ; master mono volume
   807                                  CODEC_MASTER_TONE_REG           equ     08      ; master tone (R+L)
   808                                  CODEC_PCBEEP_VOL_REG            equ     0ah     ; PC beep volume
   809                                  CODEC_PHONE_VOL_REG             equ     0bh     ; phone volume
   810                                  CODEC_MIC_VOL_REG               equ     0eh     ; MIC volume
   811                                  CODEC_LINE_IN_VOL_REG           equ     10h     ; line input volume
   812                                  CODEC_CD_VOL_REG                equ     12h     ; CD volume
   813                                  CODEC_VID_VOL_REG               equ     14h     ; video volume
   814                                  CODEC_AUX_VOL_REG               equ     16h     ; aux volume
   815                                  CODEC_PCM_OUT_REG               equ     18h     ; PCM output volume
   816                                  CODEC_RECORD_SELECT_REG         equ     1ah     ; record select input
   817                                  CODEC_RECORD_VOL_REG            equ     1ch     ; record volume
   818                                  CODEC_RECORD_MIC_VOL_REG        equ     1eh     ; record mic volume
   819                                  CODEC_GP_REG                    equ     20h     ; general purpose
   820                                  CODEC_3D_CONTROL_REG            equ     22h     ; 3D control
   821                                  ; 24h is reserved
   822                                  CODEC_POWER_CTRL_REG            equ     26h     ; powerdown control
   823                                  CODEC_EXT_AUDIO_REG             equ     28h     ; extended audio
   824                                  CODEC_EXT_AUDIO_CTRL_REG        equ     2ah     ; extended audio control
   825                                  CODEC_PCM_FRONT_DACRATE_REG     equ     2ch     ; PCM out sample rate
   826                                  CODEC_PCM_SURND_DACRATE_REG     equ     2eh     ; surround sound sample rate
   827                                  CODEC_PCM_LFE_DACRATE_REG       equ     30h     ; LFE sample rate
   828                                  CODEC_LR_ADCRATE_REG            equ     32h     ; PCM in sample rate
   829                                  CODEC_MIC_ADCRATE_REG           equ     34h     ; mic in sample rate
   830                                  
   831                                  ; registers 36-7a are reserved on the ICH
   832                                  
   833                                  CODEC_VENDORID1_REG             equ     7ch     ; codec vendor ID 1
   834                                  CODEC_VENDORID2_REG             equ     7eh     ; codec vendor ID 2
   835                                  
   836                                  ; Mixer registers 0 through 51h reside in the ICH and are not forwarded over
   837                                  ; the AC97 link to the codec, which I think is a little weird.  Looks like
   838                                  ; the ICH makes it so you don't need a fully functional codec to play audio?
   839                                  ;
   840                                  ; whenever 2 codecs are present in the system, use BIT7 to access the 2nd
   841                                  ; set of registers, ie 80h-feh
   842                                  
   843                                  PRIMARY_CODEC		equ     0       ; 0-7F for primary codec
   844                                  SECONDARY_CODEC		equ     BIT7    ; 80-8f registers for 2ndary
   845                                  
   846                                  SAMPLE_RATE_441khz	equ     44100   ; 44.1Khz (cd quality) rate
   847                                  
   848                                  ; each buffer descriptor BAR holds a pointer which has entries to the buffer
   849                                  ; contents of the .WAV file we're going to play.  Each entry is 8 bytes long
   850                                  ; (more on that later) and can contain 32 entries total, so each BAR is
   851                                  ; 256 bytes in length, thus:
   852                                  
   853                                  BDL_SIZE                equ     32*8    ; Buffer Descriptor List size
   854                                  INDEX_MASK              equ     31      ; indexes must be 0-31
   855                                  
   856                                  ;
   857                                  ; Buffer Descriptors List
   858                                  ; As stated earlier, each buffer descriptor list is a set of (up to) 32 
   859                                  ; descriptors, each 8 bytes in length.  Bytes 0-3 of a descriptor entry point
   860                                  ; to a chunk of memory to either play from or record to.  Bytes 4-7 of an
   861                                  ; entry describe various control things detailed below.
   862                                  ; 
   863                                  ; Buffer pointers must always be aligned on a Dword boundry.
   864                                  ;
   865                                  ;
   866                                  
   867                                  IOC                     equ     BIT31   ; Fire an interrupt whenever this
   868                                                                          ; buffer is complete.
   869                                  
   870                                  BUP                     equ     BIT30   ; Buffer Underrun Policy.
   871                                                                          ; if this buffer is the last buffer
   872                                                                          ; in a playback, fill the remaining
   873                                                                          ; samples with 0 (silence) or not.
   874                                                                          ; It's a good idea to set this to 1
   875                                                                          ; for the last buffer in playback,
   876                                                                          ; otherwise you're likely to get a lot
   877                                                                          ; of noise at the end of the sound.
   878                                  
   879                                  ;
   880                                  ; Bits 15:0 contain the length of the buffer, in number of samples, which
   881                                  ; are 16 bits each, coupled in left and right pairs, or 32bits each.
   882                                  ; Luckily for us, that's the same format as .wav files.
   883                                  ;
   884                                  ; A value of FFFF is 65536 samples.  Running at 44.1Khz, that's just about
   885                                  ; 1.5 seconds of sample time.  FFFF * 32bits is 1FFFFh bytes or 128k of data.
   886                                  ;
   887                                  ; A value of 0 in these bits means play no samples.
   888                                  ;
   889                                  
   890                                  ;VIA VT8233 (VT8235) AC97 Codec equates 
   891                                  ;(edited by Erdogan Tan, 7/11/2016)
   892                                  
   893                                  ; PCI stuff
   894                                  
   895                                  VIA_VID		equ 1106h	; VIA's PCI vendor ID
   896                                  VT8233_DID      equ 3059h	; VT8233 (VT8235) device ID
   897                                  		
   898                                  PCI_IO_BASE          equ 10h
   899                                  AC97_INT_LINE        equ 3Ch
   900                                  VIA_ACLINK_CTRL      equ 41h
   901                                  VIA_ACLINK_STAT      equ 40h
   902                                  VIA_ACLINK_C00_READY equ 01h ; primary codec ready
   903                                  	
   904                                  VIA_REG_AC97	     equ 80h ; dword
   905                                  
   906                                  VIA_ACLINK_CTRL_ENABLE	equ   80h ; 0: disable, 1: enable
   907                                  VIA_ACLINK_CTRL_RESET	equ   40h ; 0: assert, 1: de-assert
   908                                  VIA_ACLINK_CTRL_SYNC	equ   20h ; 0: release SYNC, 1: force SYNC hi
   909                                  VIA_ACLINK_CTRL_VRA	equ   08h ; 0: disable VRA, 1: enable VRA
   910                                  VIA_ACLINK_CTRL_PCM	equ   04h ; 0: disable PCM, 1: enable PCM
   914                                  VIA_ACLINK_CTRL_INIT	equ  (VIA_ACLINK_CTRL_ENABLE +                               VIA_ACLINK_CTRL_RESET +                               VIA_ACLINK_CTRL_PCM +                               VIA_ACLINK_CTRL_VRA)
   915                                  
   916                                  CODEC_AUX_VOL		equ   04h
   917                                  VIA_REG_AC97_BUSY	equ   01000000h ;(1<<24) 
   918                                  VIA_REG_AC97_CMD_SHIFT	equ   10h ; 16
   919                                  VIA_REG_AC97_PRIMARY_VALID equ 02000000h ;(1<<25)
   920                                  VIA_REG_AC97_READ	equ   00800000h ;(1<<23)
   921                                  VIA_REG_AC97_CODEC_ID_SHIFT   equ  1Eh ; 30
   922                                  VIA_REG_AC97_CODEC_ID_PRIMARY equ  0
   923                                  VIA_REG_AC97_DATA_SHIFT equ   0
   924                                  VIADEV_PLAYBACK         equ   0
   925                                  VIA_REG_OFFSET_STATUS   equ   0    ;; byte - channel status
   926                                  VIA_REG_OFFSET_CONTROL  equ   01h  ;; byte - channel control
   927                                  VIA_REG_CTRL_START	equ   80h  ;; WO
   928                                  VIA_REG_CTRL_TERMINATE  equ   40h  ;; WO
   929                                  VIA_REG_CTRL_PAUSE      equ   08h  ;; RW
   930                                  VIA_REG_CTRL_RESET      equ   01h  ;; RW - probably reset? undocumented
   931                                  VIA_REG_OFFSET_STOP_IDX equ   08h  ;; dword - stop index, channel type, sample rate
   932                                  VIA8233_REG_TYPE_16BIT  equ   200000h ;; RW
   933                                  VIA8233_REG_TYPE_STEREO equ   100000h ;; RW
   934                                  VIA_REG_OFFSET_CURR_INDEX equ 0Fh ;; byte - channel current index (for via8233 only)
   935                                  VIA_REG_OFFSET_TABLE_PTR equ  04h  ;; dword - channel table pointer
   936                                  VIA_REG_OFFSET_CURR_PTR equ   04h  ;; dword - channel current pointer
   937                                  VIA_REG_OFS_PLAYBACK_VOLUME_L equ  02h ;; byte
   938                                  VIA_REG_OFS_PLAYBACK_VOLUME_R equ  03h ;; byte
   939                                  VIA_REG_CTRL_AUTOSTART	equ   20h
   940                                  VIA_REG_CTRL_INT_EOL	equ   02h
   941                                  VIA_REG_CTRL_INT_FLAG	equ   01h
   944                                  VIA_REG_CTRL_INT	equ  (VIA_REG_CTRL_INT_FLAG +                               VIA_REG_CTRL_INT_EOL +                               VIA_REG_CTRL_AUTOSTART)
   945                                  ; 24/11/2016
   946                                  VIA_REG_STAT_STOPPED	equ   04h    ;; RWC
   947                                  VIA_REG_STAT_EOL	equ   02h    ;; RWC
   948                                  VIA_REG_STAT_FLAG	equ   01h    ;; RWC
   949                                  VIA_REG_STAT_ACTIVE	equ   80h    ;; RO
   950                                  ; 28/11/2016
   951                                  VIA_REG_STAT_LAST	equ   40h    ;; RO
   952                                  VIA_REG_STAT_TRIGGER_QUEUED equ 08h  ;; RO
   953                                  VIA_REF_CTRL_INT_STOP	equ   04h  ; Interrupt on Current Index = Stop Index
   954                                  		   ; and End of Block
   955                                  
   956                                  ; 14/03/2017
   957                                  VIA_REG_OFFSET_CURR_COUNT equ 0Ch ;; dword - channel current count, index
   958                                  
   959                                  ; CODE
   960                                  
   961                                  ; codec configuration code.  Not much here really.
   962                                  ; NASM version: Erdogan Tan (29/11/2016)
   963                                  
   964                                  ; enable codec, unmute stuff, set output rate to 44.1
   965                                  ; entry: ax = desired sample rate
   966                                  ;
   967                                  codecConfig:
   968                                  	; 15/11/2016
   969                                  	; 14/11/2016
   970                                  	; 12/11/2016 - Erdogan Tan (Ref: KolibriOS, 'setup_codec', codec.inc)
   971                                  
   972                                  	; 14/11/2016 - Erdogan Tan	
   973                                  	; (Ref: Mpxplay, PDSoft, Attila Padar, SC_VIA82.C)
   974                                  ;;;	call	channel_reset
   975                                  
   976 00000436 C605[26140000]00        	mov	byte [err_num], 0
   977                                  
   978 0000043D B802020000              	mov     eax, 0202h
   979 00000442 BA02000000              	mov	edx, CODEC_MASTER_VOL_REG ; 02h ; Line Out
   980 00000447 E8C8010000              	call	codec_write
   981                                  	;jc	cconfig_error
   982                                  
   983 0000044C C605[26140000]01        	mov	byte [err_num], 1
   984                                  
   985 00000453 B802020000              	mov     eax, 0202h
   986 00000458 BA18000000              	mov	edx, CODEC_PCM_OUT_REG ; 18h ; Wave Output (Stereo)
   987 0000045D E8B2010000              	call	codec_write
   988                                  	;jc	cconfig_error
   989                                        
   990 00000462 C605[26140000]02        	mov	byte [err_num], 2
   991                                  
   992                                   	;xor    eax, eax
   993 00000469 B802020000              	mov	eax, 0202h
   994 0000046E BA04000000              	mov	edx, CODEC_AUX_VOL ; 04h ; CODEC_HP_VOL_REG ; HeadPhone
   995 00000473 E89C010000              	call	codec_write
   996                                  	;jc	cconfig_error
   997                                  
   998 00000478 C605[26140000]03        	mov	byte [err_num], 3
   999                                  
  1000 0000047F 66B80800                        mov     ax,  08h
  1001 00000483 BA0C000000                      mov	edx, 0Ch  ; AC97_PHONE_VOL ; TAD Input (Mono)
  1002 00000488 E887010000              	call	codec_write
  1003                                  	;jc	short cconfig_error
  1004                                  
  1005 0000048D C605[26140000]04        	mov	byte [err_num], 4
  1006                                  
  1007 00000494 66B80808                        mov     ax,  0808h
  1008 00000498 BA10000000                      mov	edx, CODEC_LINE_IN_VOL_REG ; 10h ; Line Input (Stereo)	
  1009 0000049D E872010000              	call	codec_write
  1010                                  	;jc	short cconfig_error
  1011                                  
  1012 000004A2 C605[26140000]05        	mov	byte [err_num], 5
  1013                                  
  1014 000004A9 66B80808                	mov     ax,  0808h
  1015 000004AD BA12000000                      mov	edx, CODEC_CD_VOL_REG ; 12h ; CR Input (Stereo)
  1016 000004B2 E85D010000              	call	codec_write
  1017                                  	;jc	short cconfig_error
  1018                                  
  1019 000004B7 C605[26140000]06        	mov	byte [err_num], 6
  1020                                  
  1021 000004BE 66B80808                	mov     ax,  0808h
  1022 000004C2 BA16000000                      mov	edx, CODEC_AUX_VOL_REG ; 16h ; Aux Input (Stereo)
  1023 000004C7 E848010000              	call	codec_write
  1024                                  	;jc	short cconfig_error
  1025                                  
  1026 000004CC C605[26140000]07        	mov	byte [err_num], 7
  1027                                  
  1028                                  	; Extended Audio Status (2Ah)
  1029 000004D3 B82A000000              	mov	eax, CODEC_EXT_AUDIO_CTRL_REG ; 2Ah 
  1030 000004D8 E8FE000000              	call	codec_read
  1031 000004DD 25FDFF0000                      and     eax, 0FFFFh - 2 ; clear DRA (BIT1)
  1032                                          ;or     eax, 1		; set VRA (BIT0)
  1033 000004E2 83C805                  	or	eax, 5  	; VRA (BIT0) & S/PDIF (BIT2) ; 14/11/2016
  1034 000004E5 BA2A000000              	mov	edx, CODEC_EXT_AUDIO_CTRL_REG
  1035 000004EA E825010000              	call	codec_write
  1036                                  	;jc	short cconfig_error
  1037                                  
  1038 000004EF C605[26140000]08        	mov	byte [err_num], 8
  1039                                  set_sample_rate:
  1040 000004F6 0FB705[75180000]                movzx	eax, word [sample_rate]
  1041 000004FD BA2C000000              	mov	edx, CODEC_PCM_FRONT_DACRATE_REG ; 2Ch ; PCM Front DAC Rate
  1042                                          ;call	codec_write
  1043                                          ;retn
  1044 00000502 E90D010000              	jmp	codec_write
  1045                                  	
  1046                                  cconfig_error:
  1047 00000507 A0[26140000]            	mov	al, [err_num]
  1048 0000050C C3                              retn
  1049                                  
  1050                                  reset_codec:
  1051                                  	; 12/11/2016 - Erdogan Tan (Ref: KolibriOS, vt823x.asm)
  1052 0000050D A1[27140000]            	mov	eax, [bus_dev_fn]
  1053 00000512 B041                     	mov	al, VIA_ACLINK_CTRL
  1054 00000514 B2E0                           	mov	dl, VIA_ACLINK_CTRL_ENABLE + VIA_ACLINK_CTRL_RESET + VIA_ACLINK_CTRL_SYNC
  1055                                  
  1056 00000516 E8C9FEFFFF              	call	pciRegWrite8
  1057                                  
  1058 0000051B E852000000              	call	delay_100ms 	; wait 100 ms
  1059                                  _rc_cold:
  1060 00000520 E80A000000                      call    cold_reset
  1061 00000525 7303                            jnc     short _reset_codec_ok
  1062                                  
  1063 00000527 31C0                            xor     eax, eax         ; timeout error
  1064 00000529 C3                              retn
  1065                                  
  1066                                  _reset_codec_ok:
  1067 0000052A 31C0                            xor     eax, eax
  1068                                          ;mov	al, VIA_ACLINK_C00_READY ; 1
  1069 0000052C FEC0                            inc	al
  1070 0000052E C3                      	retn
  1071                                  
  1072                                  cold_reset:
  1073                                  	; 12/11/2016 - Erdogan Tan (Ref: KolibriOS, vt823x.asm)
  1074                                  	;mov	eax, [bus_dev_fn]
  1075                                  	;mov	al, VIA_ACLINK_CTRL
  1076 0000052F 30D2                    	xor	dl, dl ; 0
  1077 00000531 E8AEFEFFFF              	call	pciRegWrite8
  1078                                  
  1079 00000536 E837000000              	call	delay_100ms 	; wait 100 ms
  1080                                  
  1081                                  	;; ACLink on, deassert ACLink reset, VSR, SGD data out
  1082                                          ;; note - FM data out has trouble with non VRA codecs !!
  1083                                          
  1084                                  	;mov	eax, [bus_dev_fn]
  1085                                  	;mov	al, VIA_ACLINK_CTRL
  1086                                  
  1087 0000053B B2CC                    	mov	dl, VIA_ACLINK_CTRL_INIT
  1088                                  
  1089 0000053D E8A2FEFFFF              	call	pciRegWrite8
  1090                                  
  1091 00000542 B910000000              	mov	ecx, 16	; total 2s
  1092                                  
  1093                                  _crst_wait:
  1094 00000547 51                      	push	ecx
  1095                                  
  1096                                  	;mov	eax, [bus_dev_fn]
  1097 00000548 B040                    	mov	al, VIA_ACLINK_STAT
  1098 0000054A E80FFEFFFF              	call	pciRegRead8	
  1099                                  
  1100 0000054F F6C201                          test    dl, VIA_ACLINK_C00_READY
  1101 00000552 750B                            jnz     short _crst_ok
  1102                                  
  1103 00000554 E819000000              	call	delay_100ms
  1104                                  
  1105 00000559 59                      	pop	ecx
  1106                                  
  1107 0000055A 49                              dec     ecx
  1108 0000055B 75EA                            jnz     short _crst_wait
  1109                                  
  1110                                  _crst_fail:
  1111 0000055D F9                              stc
  1112 0000055E C3                              retn
  1113                                  
  1114                                  _crst_ok:
  1115 0000055F 59                      	pop	ecx
  1116                                  
  1117                                  	; are these necessary ? - 14/11/2016 - Erdogan Tan
  1118                                  
  1119                                  	;mov	eax, [bus_dev_fn]
  1120                                  	;mov	al, VIA_ACLINK_CTRL
  1121 00000560 E8F9FDFFFF              	call	pciRegRead8
  1122                                  
  1123                                  	;mov	eax, [bus_dev_fn]
  1124                                  	;mov	al, VIA_ACLINK_STAT
  1125 00000565 E8F4FDFFFF              	call	pciRegRead8
  1126                                  
  1127 0000056A 0FB6C2                  	movzx	eax, dl
  1128 0000056D 2401                    	and     al, VIA_ACLINK_C00_READY ; 1
  1129 0000056F 74EC                    	jz	short _crst_fail
  1130                                  
  1131 00000571 C3                      	retn
  1132                                  
  1133                                  delay_100ms:
  1134                                  	; wait 100 ms
  1135 00000572 B919000000              	mov	ecx, 25
  1136                                  _delay_x_ms:
  1137 00000577 51                      	push	ecx
  1138 00000578 E8E50A0000              	call	delay1_4ms
  1139 0000057D 59                      	pop	ecx
  1140 0000057E E2F7                            loop	_delay_x_ms
  1141 00000580 C3                      	retn
  1142                                  
  1143                                  codec_io_w16: ;w32
  1144 00000581 668B15[33140000]                mov	dx, [ac97_io_base]
  1145 00000588 6681C28000                      add     dx, VIA_REG_AC97
  1146                                  	;out	dx, eax
  1147                                  	; 05/03/2017
  1148 0000058D 53                      	push	ebx
  1149 0000058E 89C3                    	mov	ebx, eax
  1150 00000590 B405                    	mov	ah, 5 ; outd
  1151 00000592 CD34                    	int	34h
  1152 00000594 5B                      	pop	ebx
  1153 00000595 C3                              retn
  1154                                  
  1155                                  codec_io_r16: ;r32
  1156 00000596 668B15[33140000]                mov     dx, [ac97_io_base]
  1157 0000059D 6681C28000                      add     dx, VIA_REG_AC97
  1158                                          ;in	eax, dx
  1159                                  	; 05/03/2017
  1160 000005A2 B404                    	mov	ah, 4 ; ind
  1161 000005A4 CD34                    	int	34h
  1162 000005A6 C3                              retn
  1163                                  
  1164                                  ctrl_io_w8:
  1165 000005A7 660315[33140000]                add     dx, [ac97_io_base]
  1166                                          ;out	dx, al
  1167                                  	; 05/03/2017
  1168 000005AE B401                    	mov	ah, 1 ; outb
  1169 000005B0 CD34                    	int	34h
  1170 000005B2 C3                              retn
  1171                                  
  1172                                  ctrl_io_r8:
  1173 000005B3 660315[33140000]                add     dx, [ac97_io_base]
  1174                                          ;in	al, dx
  1175                                  	; 05/03/2017
  1176 000005BA B400                    	mov	ah, 0 ; inb
  1177 000005BC CD34                    	int	34h
  1178 000005BE C3                              retn
  1179                                  
  1180                                  ctrl_io_w32:
  1181 000005BF 660315[33140000]                add     dx, [ac97_io_base]
  1182                                          ;out	dx, eax
  1183                                  	; 05/03/2017
  1184 000005C6 53                      	push	ebx
  1185 000005C7 89C3                    	mov	ebx, eax
  1186 000005C9 B405                    	mov	ah, 5 ; outd
  1187 000005CB CD34                    	int	34h
  1188 000005CD 5B                      	pop	ebx
  1189 000005CE C3                              retn
  1190                                  
  1191                                  ctrl_io_r32:
  1192 000005CF 660315[33140000]                add	dx, [ac97_io_base]
  1193                                  	;in	eax, dx
  1194                                  	; 05/03/2017
  1195 000005D6 B404                    	mov	ah, 4 ; ind
  1196 000005D8 CD34                    	int	34h
  1197 000005DA C3                              retn
  1198                                  
  1199                                  codec_read:
  1200                                  	; 12/11/2016 - Erdogan Tan (Ref: KolibriOS, vt823x.asm)
  1201                                          ; Use only primary codec.
  1202                                          ; eax = register
  1203 000005DB C1E010                          shl     eax, VIA_REG_AC97_CMD_SHIFT
  1204 000005DE 0D00008002                      or      eax, VIA_REG_AC97_PRIMARY_VALID + VIA_REG_AC97_READ
  1205                                  
  1206 000005E3 E899FFFFFF              	call    codec_io_w16
  1207                                  
  1208                                        	; codec_valid
  1209 000005E8 E83E000000              	call	codec_check_ready
  1210 000005ED 7301                            jnc	short _cr_ok
  1211                                  
  1212 000005EF C3                      	retn
  1213                                  
  1214                                  _cr_ok:
  1215                                  	; wait 25 ms
  1216 000005F0 E86D0A0000              	call	delay1_4ms
  1217 000005F5 E8680A0000              	call	delay1_4ms
  1218 000005FA E8630A0000              	call	delay1_4ms
  1219 000005FF E85E0A0000              	call	delay1_4ms
  1220 00000604 E8590A0000              	call	delay1_4ms
  1221                                  
  1222 00000609 E888FFFFFF                      call    codec_io_r16
  1223 0000060E 25FFFF0000                      and     eax, 0FFFFh
  1224 00000613 C3                              retn
  1225                                  
  1226                                  codec_write:
  1227                                  	; 12/11/2016 - Erdogan Tan (Ref: KolibriOS, vt823x.asm)
  1228                                          ; Use only primary codec.
  1229                                          
  1230                                  	; eax = data (volume)
  1231                                  	; edx = register (mixer register)
  1232                                  	
  1233 00000614 C1E210                  	shl     edx, VIA_REG_AC97_CMD_SHIFT
  1234                                  
  1235 00000617 C1E000                          shl     eax, VIA_REG_AC97_DATA_SHIFT ; shl eax, 0
  1236 0000061A 09C2                            or      edx, eax
  1237                                  
  1238 0000061C B800000000                      mov     eax, VIA_REG_AC97_CODEC_ID_PRIMARY
  1239 00000621 C1E01E                          shl     eax, VIA_REG_AC97_CODEC_ID_SHIFT
  1240 00000624 09D0                            or      eax, edx
  1241                                  
  1242 00000626 E856FFFFFF                      call    codec_io_w16
  1243                                          ;mov    [codec.regs+esi], ax
  1244                                  
  1245                                          ;call	codec_check_ready
  1246                                         	;retn
  1247                                  	;jmp	short _codec_check_ready	
  1248                                  
  1249                                  codec_check_ready:
  1250                                  	; 12/11/2016 - Erdogan Tan (Ref: KolibriOS, vt823x.asm)
  1251                                  
  1252                                  _codec_check_ready:
  1253 0000062B B914000000              	mov	ecx, 20	; total 2s
  1254                                  _ccr_wait:
  1255 00000630 51                      	push	ecx
  1256                                  
  1257 00000631 E860FFFFFF                      call    codec_io_r16
  1258 00000636 A900000001                      test    eax, VIA_REG_AC97_BUSY
  1259 0000063B 740B                            jz      short _ccr_ok
  1260                                  
  1261 0000063D E830FFFFFF              	call	delay_100ms
  1262                                  
  1263 00000642 59                      	pop	ecx
  1264                                  
  1265 00000643 49                      	dec     ecx
  1266 00000644 75EA                            jnz     short _ccr_wait
  1267                                  
  1268 00000646 F9                              stc
  1269 00000647 C3                              retn
  1270                                  
  1271                                  _ccr_ok:
  1272 00000648 59                      	pop	ecx
  1273 00000649 25FFFF0000              	and     eax, 0FFFFh
  1274 0000064E C3                              retn
  1275                                  
  1276                                  channel_reset:
  1277                                  	; 14/11/2016 - Erdogan Tan
  1278                                  	; 12/11/2016 - Erdogan Tan (Ref: KolibriOS, vt823x.asm)
  1279 0000064F BA01000000                      mov	edx, VIA_REG_OFFSET_CONTROL
  1280 00000654 B849000000                      mov     eax, VIA_REG_CTRL_PAUSE + VIA_REG_CTRL_TERMINATE + VIA_REG_CTRL_RESET
  1281 00000659 E849FFFFFF                      call    ctrl_io_w8
  1282                                  
  1283                                          ;mov	edx, VIA_REG_OFFSET_CONTROL
  1284                                          ;call   ctrl_io_r8
  1285                                  
  1286 0000065E B90C000000              	mov	ecx, 12 ; 50 ms	
  1287                                  _ch_rst_wait:
  1288 00000663 51                      	push	ecx
  1289 00000664 E8F9090000              	call	delay1_4ms
  1290 00000669 59                      	pop	ecx
  1291 0000066A 49                      	dec	ecx
  1292 0000066B 75F6                    	jnz	short _ch_rst_wait     
  1293                                  
  1294                                          ; disable interrupts
  1295 0000066D BA01000000                      mov	edx, VIA_REG_OFFSET_CONTROL
  1296 00000672 31C0                            xor     eax, eax
  1297 00000674 E82EFFFFFF                      call    ctrl_io_w8
  1298                                  
  1299                                          ; clear interrupts
  1300 00000679 BA00000000                      mov	edx, VIA_REG_OFFSET_STATUS
  1301                                  	;mov	eax, 3
  1302 0000067E B8FF000000                      mov     eax, 0FFh ; 14/11/2016 - SC_VIA82.C (Attila Padar)
  1303 00000683 E81FFFFFFF                      call	ctrl_io_w8
  1304                                  
  1305                                  	; 14/11/2016 (Ref: Attila Padar, Mpxplay, SC_VIA82.C)
  1306 00000688 BA04000000              	mov	edx, VIA_REG_OFFSET_CURR_PTR
  1307 0000068D 31C0                    	xor	eax, eax
  1308 0000068F E82BFFFFFF              	call	ctrl_io_w32
  1309                                  
  1310 00000694 C3                              retn
  1311                                  
  1312                                  ;=============================================================================
  1313                                  ;               VIA_WAV.ASM
  1314                                  ;=============================================================================
  1315                                  
  1316                                  ; DOS based .WAV player using AC'97 and codec interface.
  1317                                  ; ---------------------------------------------------------------
  1318                                  ; VIA VT8233 Modification & NASM version: Erdogan Tan (29/11/2016)
  1319                                  ; Last Update: 08/12/2016 (by Erdogan Tan)
  1320                                  
  1321                                  ; player internal variables and other equates.
  1322                                  BUFFERSIZE      equ     32768	; 32K half buffer size. ; 14/03/2017
  1323                                  ENDOFFILE       equ     BIT0	; flag for knowing end of file
  1324                                  
  1325                                  ;===========================================================================
  1326                                  ; entry: none.  File is already open and [filehandle] filled.
  1327                                  ; exit:  not until the song is finished or the user aborts.
  1328                                  ;
  1329                                  	; 14/03/2017
  1330                                  	; 05/03/2017 (32 bit buffer addresses)
  1331                                  ModPlay: ; 13/02/2017  ; ModPlay Polling!
  1332                                  	;cld
  1333                                  	; clear (half) buffer 2
  1334 00000695 BF[00000100]                   	mov     edi, DmaBuffer
  1335                                  	;add	edi, BUFFERSIZE
  1336 0000069A BB00800000              	mov	ebx, BUFFERSIZE
  1337 0000069F 01DF                    	add	edi, ebx
  1338 000006A1 6629C0                  	sub	ax, ax
  1339 000006A4 B900400000              	mov	ecx, (BUFFERSIZE/2)
  1340 000006A9 F366AB                  	rep	stosw
  1341                                  	
  1342                                         ; load 32768 bytes into buffer 1
  1343                                  
  1344 000006AC BF[00000100]                    mov     edi, DmaBuffer
  1345                                  	;mov	ebx, BUFFERSIZE
  1346 000006B1 E857080000              	call    GetSamples
  1347                                  
  1348                                         ; load 32768 bytes into buffer 2
  1349                                  
  1350                                          ;mov	edi, Dma Buffer
  1351                                  	;;mov	ebx, BUFFERSIZE
  1352                                  	;add	edi, ebx
  1353                                  	;call	GetSamples
  1354                                  
  1355                                  ; write last valid index to 31 to start with.
  1356                                  ; The Last Valid Index register tells the DMA engine when to stop playing.
  1357                                  ; 
  1358                                  ; As we progress through the song we change the last valid index to always be
  1359                                  ; something other than the index we're currently playing.  
  1360                                  ;
  1361                                          ;;mov   al, 1
  1362                                          ;mov	al, 31
  1363                                  	;call   setLastValidIndex
  1364                                  
  1365                                  ; create Buffer Descriptor List
  1366                                  ;
  1367                                  ; A buffer descriptor list is a list of pointers and control bits that the
  1368                                  ; DMA engine uses to know where to get the .wav data and how to play it.
  1369                                  ;
  1370                                  ; I set it up to use only 2 buffers of .wav data, and whenever 1 buffer is
  1371                                  ; playing, I refresh the other one with good data.
  1372                                  ;
  1373                                  ;
  1374                                  ; For the control bits, you can specify that the DMA engine fire an interrupt
  1375                                  ; after a buffer has been processed, but I poll the current index register
  1376                                  ; to know when it's safe to update the other buffer.
  1377                                  ;
  1378                                  ; I set the BUP bit, which tells the DMA engine to just play 0's (silence)
  1379                                  ; if it ever runs out of data to play.  Good for safety.
  1380                                  ;
  1381                                  	; 05/03/2017 (32 bit buffer addresses)
  1382                                  
  1383                                  	; 14/02/2017
  1384 000006B6 BF[00800000]                    mov     edi, BdlBuffer		; get BDL address
  1385 000006BB 66B91000                        mov     cx, 32 / 2		; make 32 entries in BDL
  1386                                  _0:
  1387                                  
  1388                                  ; set buffer descriptor 0 to start of data file in memory
  1389                                  
  1390 000006BF A1[04900000]                    mov	eax, [DMA_phy_buff]	; Physical address of DMA buffer
  1391 000006C4 AB                              stosd				; store dmabuffer1 address
  1392                                  
  1393 000006C5 89C2                    	mov	edx, eax ; 05/03/2017
  1394                                  
  1395                                  ;
  1396                                  ; set length to 32k samples.  1 sample is 16bits or 2bytes.
  1397                                  ; Set control (bits 31:16) to BUP, bits 15:0=number of samples.
  1398                                  ; 
  1399                                  
  1400                                  ; VIA VT8235.PDF: (Page 110) (Erdogan Tan, 29/11/2016)
  1401                                  	;
  1402                                  	; 	Audio SGD Table Format
  1403                                  	;	-------------------------------
  1404                                  	;	63   62    61-56    55-32  31-0
  1405                                  	;	--   --   --------  -----  ----
  1406                                  	;	EOL FLAG -reserved- Base   Base
  1407                                  	;		    	    Count  Address
  1408                                  	;		            [23:0] [31:0]
  1409                                  	;	EOL: End Of Link. 
  1410                                  	;	     1 indicates this block is the last of the link.
  1411                                  	;	     If the channel Interrupt on EOL bit is set, then
  1412                                  	;	     an interrupt is generated at the end of the transfer.
  1413                                  	;
  1414                                  	;	FLAG: Block Flag. If set, transfer pauses at the end of this
  1415                                  	;	      block. If the channel Interrupt on FLAG bit is set,
  1416                                  	;	      then an interrupt is generated at the end of this block.
  1417                                  
  1418                                  	FLAG	EQU BIT30
  1419                                  	EOL	EQU BIT31
  1420                                  
  1421                                  	; 08/12/2016 - Erdogan Tan
  1422 000006C7 B800800000              	mov	eax, BUFFERSIZE
  1423 000006CC 01C2                    	add	edx, eax ; 05/03/2017
  1424 000006CE 0D00000040              	or	eax, FLAG
  1425                                  	;or	eax, EOL
  1426 000006D3 AB                      	stosd
  1427                                  
  1428                                  ; 2nd buffer:
  1429                                  
  1430 000006D4 89D0                            mov	eax, edx ; Physical address of the 2nd half of DMA buffer	
  1431 000006D6 AB                      	stosd				; store dmabuffer2 address
  1432                                  
  1433                                  ; set length to 64k (32k of two 16 bit samples)
  1434                                  ; Set control (bits 31:16) to BUP, bits 15:0=number of samples
  1435                                  ; 
  1436                                  	; 08/12/2016 - Erdogan Tan
  1437 000006D7 B800800000              	mov	eax, BUFFERSIZE
  1438 000006DC 0D00000080              	or	eax, EOL
  1439                                  	;or	eax, FLAG
  1440 000006E1 AB                      	stosd
  1441                                  
  1442 000006E2 E2DB                            loop    _0
  1443                                  
  1444                                  ;
  1445                                  ; tell the DMA engine where to find our list of Buffer Descriptors.
  1446                                  ; this 32bit value is a flat mode memory offset (ie no segment:offset)
  1447                                  ;
  1448                                  ; write buffer descriptor list address
  1449                                  ;
  1450 000006E4 A1[00900000]                    mov	eax, [BDL_phy_buff] ; Physical address of the BDL
  1451                                  	
  1452                                  	; 12/11/2016 - Erdogan Tan 
  1453                                  	; (Ref: KolibriOS, vt823x.asm, 'create_primary_buff')
  1454 000006E9 BA04000000              	mov     edx, VIADEV_PLAYBACK + VIA_REG_OFFSET_TABLE_PTR
  1455 000006EE E8CCFEFFFF                      call    ctrl_io_w32
  1456                                  
  1457 000006F3 E833FFFFFF              	call	codec_check_ready
  1458                                  
  1459 000006F8 66BA0200                  	mov     dx, VIADEV_PLAYBACK + VIA_REG_OFS_PLAYBACK_VOLUME_L
  1460 000006FC B802000000                      mov     eax, 2   ;31
  1461 00000701 E8A1FEFFFF                      call    ctrl_io_w8
  1462                                  
  1463 00000706 E820FFFFFF              	call	codec_check_ready
  1464                                  
  1465 0000070B 66BA0300                        mov     dx, VIADEV_PLAYBACK + VIA_REG_OFS_PLAYBACK_VOLUME_R
  1466 0000070F 66B80200                        mov     ax, 2   ;31
  1467 00000713 E88FFEFFFF                      call    ctrl_io_w8
  1468                                  
  1469 00000718 E80EFFFFFF              	call	codec_check_ready
  1470                                  ;
  1471                                  ;
  1472                                  ; All set.  Let's play some music.
  1473                                  ;
  1474                                  ;
  1475                                         	;mov    dx, VIADEV_PLAYBACK + VIA_REG_OFFSET_STOP_IDX
  1476                                          ;mov    ax, VIA8233_REG_TYPE_16BIT or VIA8233_REG_TYPE_STEREO or 0xfffff or 0xff000000
  1477                                          ;call   ctrl_io_w32
  1478                                  
  1479                                  	;call	codec_check_ready
  1480                                  
  1481                                  	; 14/03/2017
  1482                                  	;mov	byte [stmo], 1 ; mono
  1483                                  	;mov	byte [bps], 8 ; 8 bit
  1484                                  
  1485                                  	; 08/12/2016
  1486                                  	; 07/10/2016
  1487                                          ;mov    al, 1
  1488 0000071D B01F                            mov	al, 31
  1489 0000071F E82B010000              	call    setLastValidIndex
  1490                                  
  1491 00000724 C605[24140000]01        	mov	byte [tLoop], 1 ; 30/11/2016
  1492                                  
  1493 0000072B B823000000                      mov	eax, VIA_REG_CTRL_INT ; 14/03/2017
  1494 00000730 0D80000000                     	or	eax, VIA_REG_CTRL_START
  1495                                          ;mov	ax, VIA_REG_CTRL_AUTOSTART + VIA_REG_CTRL_START
  1496                                  	; 28/11/2016
  1497                                  	;mov	ax, VIA_REG_CTRL_AUTOSTART + VIA_REG_CTRL_START + VIA_REG_CTRL_INT_FLAG
  1498 00000735 66BA0100                	mov     dx, VIADEV_PLAYBACK + VIA_REG_OFFSET_CONTROL
  1499 00000739 E869FEFFFF                      call    ctrl_io_w8
  1500                                  
  1501 0000073E E8E8FEFFFF              	call	codec_check_ready
  1502                                  
  1503                                  ; while DMA engine is running, examine current index and wait until it hits 1
  1504                                  ; as soon as it's 1, we need to refresh the data in wavbuffer1 with another
  1505                                  ; 64k.  Likewise when it's playing buffer 2, refresh buffer 1 and repeat.
  1506                                     
  1507                                  	; 05/03/2017 (TRDOS 386)
  1508                                  	; 14/02/2017
  1509                                  	; 13/02/2017
  1510                                  	; 08/12/2016
  1511                                  	; 28/11/2016
  1512                                  
  1513 00000743 BD[00000100]            	mov	ebp, DmaBuffer ; 14/02/2017
  1514                                  p_loop:
  1515 00000748 B401                    	mov     ah, 1		; any key pressed?
  1516 0000074A CD32                    	int     32h		; no, Loop.
  1517 0000074C 740C                    	jz	short q_loop
  1518                                  
  1519 0000074E B400                    	mov     ah, 0		; flush key buffer...
  1520 00000750 CD32                    	int     32h
  1521                                  p_return:
  1522 00000752 C605[24140000]00        	mov	byte [tLoop], 0	; 13/02/2017
  1523 00000759 C3                      	retn
  1524                                  q_loop:
  1525 0000075A 6631C0                  	xor	ax, ax
  1526 0000075D 8605[49130000]          	xchg	al, [tBuff] ; AL = [tBuff], [tBuff] = 0
  1527 00000763 3C01                    	cmp	al, 1
  1528 00000765 7709                    	ja	short r_loop
  1529 00000767 721E                    	jb	short ScopeLoop
  1530                                  	; 05/03/2017
  1531 00000769 BF[00000100]                 	mov	edi, DmaBuffer ; [tBuff]=1 (from tuneLoop)
  1532 0000076E EB0B                           	jmp	short s_loop 
  1533                                  r_loop:
  1534                                  	; 05/03/2017
  1535 00000770 BF[00000100]                    mov     edi, DmaBuffer ; [tBuff]=2 (from tuneLoop)
  1536 00000775 81C700800000            	add	edi, BUFFERSIZE
  1537                                  s_loop:
  1538                                  	; 05/03/2017
  1539 0000077B 89FD                    	mov	ebp, edi ; save current buffer addres in bp register
  1540 0000077D BB00800000              	mov	ebx, BUFFERSIZE ; 32768 bytes ; 14/03/2017
  1541 00000782 E886070000              	call    GetSamples
  1542                                  	;
  1543                                  ScopeLoop:
  1544 00000787 BF00000A00              	mov	edi, 0A0000h	; VGA display memory address
  1545 0000078C 89EE                    	mov     esi, ebp	; get current samples
  1546                                  	; 14/03/2017
  1547 0000078E BA0C000000              	mov	edx, VIA_REG_OFFSET_CURR_COUNT
  1548 00000793 E837FEFFFF              	call	ctrl_io_r32
  1549 00000798 BBFF7F0000              	mov	ebx, 07FFFh 	; 32767
  1550 0000079D 21D8                    	and	eax, ebx	; remain count (<= 32767)
  1551 0000079F 29C3                    	sub	ebx, eax
  1552 000007A1 6681EBA000              	sub	bx, 160
  1553 000007A6 6601DE                  	add	si, bx	
  1554 000007A9 31C9                    	xor     ecx, ecx	; to be drawed ...
  1555 000007AB 31D2                    	xor     edx, edx
  1556                                  DrawLoop:       
  1557 000007AD 89D3                    	mov     ebx, edx	; (save Index)
  1558 000007AF 668BBB[D0720000]        	mov     di, [Scope+ebx]	; get old SCOPE pixel address
  1559 000007B6 C60700                  	mov     byte [edi], 0	; erase it!
  1560                                  	;lodsb
  1561                                  	;mov	bl, al
  1562 000007B9 8A1E                    	mov	bl, [esi]	; get a sample (8-bit)
  1563 000007BB 6646                    	inc	si		; calc new pixel address...
  1564 000007BD 30FF                    	xor     bh, bh
  1565 000007BF 66D1E3                  	shl     bx, 1
  1566 000007C2 668BBB[50750000]        	mov     di, [RowOfs+ebx]
  1567 000007C9 6601CF                  	add     di, cx
  1568 000007CC 6689D3                  	mov     bx, dx		; (restore Index)
  1569 000007CF 6689BB[D0720000]        	mov     [Scope+ebx], di	; save new address...
  1570 000007D6 C6070A                  	mov     byte [edi], 10	; and DRAW.
  1571 000007D9 6683C202                	add     dx, 2		; the next pixel...
  1572 000007DD 41                      	inc     ecx
  1573 000007DE 6681F94001              	cmp     cx, 320		; 320 pixels drawed?
  1574 000007E3 72C8                    	jb      short DrawLoop
  1575 000007E5 E95EFFFFFF              	jmp	p_loop
  1576                                  
  1577                                  tuneLoop:
  1578                                  	; 14/03/2017
  1579                                  	; 05/03/2017 (TRDOS 386)
  1580                                  	; 08/12/2016
  1581                                  	; 28/11/2016 - Erdogan Tan
  1582                                  	
  1583 000007EA 803D[24140000]01        	cmp	byte [tLoop], 1
  1584 000007F1 7245                    	jb	short _exit_
  1585                                  
  1586 000007F3 C605[49130000]01        	mov	byte [tBuff], 1 ; Buffer 1
  1587                                  
  1588 000007FA F605[22140000]02        	test	byte [irq_status], VIA_REG_STAT_EOL 
  1589 00000801 7406                    	jz	short _tlp1 ; FLAG
  1590                                  	
  1591                                  	; EOL
  1592 00000803 FE05[49130000]          	inc	byte [tBuff] ; Buffer 2
  1593                                  _tlp1: 
  1594 00000809 F605[22140000]01        	test	byte [irq_status], VIA_REG_STAT_FLAG 
  1595 00000810 7417                    	jz	short _tlp2
  1596                                  
  1597 00000812 B823000000              	mov	eax, VIA_REG_CTRL_INT
  1598 00000817 660D8000                       	or	ax, VIA_REG_CTRL_START
  1599 0000081B 66BA0100                       	mov     dx, VIADEV_PLAYBACK + VIA_REG_OFFSET_CONTROL
  1600 0000081F E883FDFFFF                      call    ctrl_io_w8
  1601                                  
  1602 00000824 E802FEFFFF              	call	codec_check_ready
  1603                                  _tlp2:	
  1604 00000829 A0[22140000]                    mov     al, [irq_status]   ;; ack ;;
  1605 0000082E 66BA0000                        mov     dx, VIADEV_PLAYBACK + VIA_REG_OFFSET_STATUS
  1606 00000832 E870FDFFFF                      call    ctrl_io_w8
  1607 00000837 C3                      	retn
  1608                                  _exit_:
  1609                                          ; finished with song, stop everything
  1610 00000838 66B82300                	mov     ax, VIA_REG_CTRL_INT
  1611 0000083C 6683C840                        or      ax, VIA_REG_CTRL_TERMINATE
  1612 00000840 66BA0100                	mov     dx, VIADEV_PLAYBACK + VIA_REG_OFFSET_CONTROL
  1613 00000844 E85EFDFFFF                      call    ctrl_io_w8
  1614                                  
  1615 00000849 E801FEFFFF                      call	channel_reset
  1616                                  _return:
  1617 0000084E C3                      	retn
  1618                                  
  1619                                  ;input AL = index # to stop on
  1620                                  setLastValidIndex:
  1621                                  	; 05/03/2017 (TRDOS 386)
  1622                                  	; 19/11/2016
  1623                                  	; 14/11/2016 - Erdogan Tan (Ref: VIA VT8235.PDF, Page 110)
  1624                                  	; 12/11/2016 - Erdogan Tan
  1625                                  	; (Ref: KolibriOS, vt823x.asm, 'create_primary_buff')
  1626                                  	;push	edx
  1627 0000084F 50                      	push	eax
  1628                                  	;push	ecx
  1629 00000850 0FB705[75180000]        	movzx	eax, word [sample_rate] ; Hertz
  1630 00000857 BA00001000              	mov	edx, 100000h ; 2^20 = 1048576
  1631 0000085C F7E2                    	mul	edx
  1632 0000085E B980BB0000              	mov	ecx, 48000	
  1633 00000863 F7F1                    	div	ecx
  1634                                  	;and	eax, 0FFFFFh
  1635                                  	;pop	ecx
  1636 00000865 5A                      	pop	edx 
  1637 00000866 C1E218                  	shl	edx, 24  ; STOP Index Setting: Bit 24 to 31
  1638 00000869 09D0                    	or	eax, edx
  1639                                  	; 19/11/2016
  1640 0000086B 803D[21140000]10        	cmp	byte [bps], 16
  1641 00000872 7505                    	jne	short sLVI_1
  1642 00000874 0D00002000              	or	eax, VIA8233_REG_TYPE_16BIT
  1643                                  sLVI_1:
  1644 00000879 803D[20140000]02        	cmp	byte [stmo], 2
  1645 00000880 7505                    	jne	short sLVI_2
  1646 00000882 0D00001000              	or	eax, VIA8233_REG_TYPE_STEREO
  1647                                  sLVI_2:
  1648 00000887 BA08000000              	mov     edx, VIADEV_PLAYBACK + VIA_REG_OFFSET_STOP_IDX
  1649 0000088C E82EFDFFFF                      call    ctrl_io_w32
  1650 00000891 E895FDFFFF              	call	codec_check_ready
  1651                                  	;pop	edx
  1652 00000896 C3                      	retn
  1653                                  
  1654                                  ;=============================================================================
  1655                                  ;               MODLOAD.ASM
  1656                                  ;=============================================================================
  1657                                  
  1658                                  ; Amiga Module Loader v0.1b by Carlos Hasan.
  1659                                  ;	July 10th, 1993.
  1660                                  
  1661                                  ; STRUCTURES
  1662                                  
  1663                                  struc ModSample
  1664 00000000 <res 00000016>          .msName:	resb 22
  1665 00000016 <res 00000002>          .msLength:	resw 1
  1666 00000018 <res 00000001>          .msFinetune:	resb 1
  1667 00000019 <res 00000001>          .msVolume:	resb 1
  1668 0000001A <res 00000002>          .msRepeat:	resw 1
  1669 0000001C <res 00000002>          .msRepLen:	resw 1
  1670                                  .size:
  1671                                  endstruc
  1672                                  
  1673                                  struc ModHeader
  1674 00000000 <res 00000014>          .mhName:	resb 20
  1675 00000014 <res 000003A2>          .mhSamples:	resb ModSample.size*31
  1676 000003B6 <res 00000001>          .mhOrderLen:	resb 1
  1677 000003B7 <res 00000001>          .mhReStart:	resb 1
  1678 000003B8 <res 00000080>          .mhOrder:	resb 128
  1679 00000438 <res 00000004>          .mhSign:	resw 2
  1680                                  .size:	
  1681                                  endstruc
  1682                                  
  1683                                  struc ModInfoRec
  1684 00000000 <res 00000001>          .OrderLen:	resb 1
  1685 00000001 <res 00000001>          .ReStart:	resb 1
  1686 00000002 <res 00000080>          .Order:	resb 128
  1687 00000082 <res 00000004>          .Patterns:	resd 1
  1688 00000086 <res 0000003E>          .SampOfs:	resw 31
  1689 000000C4 <res 0000003E>          .SampSeg:	resw 31
  1690 00000102 <res 0000003E>          .SampLen:	resw 31
  1691 00000140 <res 0000003E>          .SampRep:	resw 31
  1692 0000017E <res 0000003E>          .SampRepLen:	resw 31
  1693 000001BC <res 0000003E>          .SampVol:	resw 31
  1694                                  .size:	
  1695                                  endstruc
  1696                                  
  1697                                  ; CODE
  1698                                  
  1699                                  LoadModule:
  1700                                  	; edi = file name address
  1701                                  
  1702 00000897 60                      	pushad
  1703                                  
  1704 00000898 66C705[37140000]01-     	mov	word [ErrorInfo], 1
  1704 000008A0 00                 
  1705                                  
  1706 000008A1 E88F010000              	call    ClearModInfo
  1707                                  OpenFile:       
  1708                                  	; ebx = ASCIIZ file name address
  1709                                  	; ecx = open mode (0 = open for read)	
  1710                                  	sys	_open, edi, 0 ; open for reading
  1710                              <1> 
  1710                              <1> 
  1710                              <1> 
  1710                              <1> 
  1710                              <1>  %if %0 >= 2
  1710 000008A6 89FB                <1>  mov ebx, %2
  1710                              <1>  %if %0 >= 3
  1710 000008A8 B900000000          <1>  mov ecx, %3
  1710                              <1>  %if %0 = 4
  1710                              <1>  mov edx, %4
  1710                              <1>  %endif
  1710                              <1>  %endif
  1710                              <1>  %endif
  1710 000008AD B805000000          <1>  mov eax, %1
  1710                              <1> 
  1710 000008B2 CD40                <1>  int 40h
  1711 000008B4 0F8279010000            	jc	Failed
  1712 000008BA A3[35140000]            	mov     [FileHandle], eax
  1713                                  ReadHeader:
  1714                                  	; ebx = File handle
  1715                                  	; ecx = Buffer address
  1716                                  	; edx = Byte count
  1717                                  	sys	_read, [FileHandle], Header, ModHeader.size
  1717                              <1> 
  1717                              <1> 
  1717                              <1> 
  1717                              <1> 
  1717                              <1>  %if %0 >= 2
  1717 000008BF 8B1D[35140000]      <1>  mov ebx, %2
  1717                              <1>  %if %0 >= 3
  1717 000008C5 B9[39140000]        <1>  mov ecx, %3
  1717                              <1>  %if %0 = 4
  1717 000008CA BA3C040000          <1>  mov edx, %4
  1717                              <1>  %endif
  1717                              <1>  %endif
  1717                              <1>  %endif
  1717 000008CF B803000000          <1>  mov eax, %1
  1717                              <1> 
  1717 000008D4 CD40                <1>  int 40h
  1718 000008D6 0F824A010000            	jc      CloseFile
  1719                                  CheckMK:        
  1720 000008DC 813D[71180000]4D2E-     	cmp     dword [Header+ModHeader.mhSign], 'M.K.'
  1720 000008E4 4B2E               
  1721 000008E6 7440                    	je      short IsModFile
  1722                                  CheckFLT4:
  1723 000008E8 813D[71180000]464C-     	cmp     dword [Header+ModHeader.mhSign], 'FLT4'
  1723 000008F0 5434               
  1724 000008F2 7434                    	je      short IsModFile
  1725                                  Is15Inst:
  1726 000008F4 BE[0F160000]            	mov     esi, (Header+ModHeader.mhSamples) + (15*ModSample.size)
  1727 000008F9 BF[EF170000]            	mov     edi, Header+ModHeader.mhOrderLen
  1728                                  	;cld
  1729                                  	;mov	ecx, 130
  1730 000008FE 66B98200                	mov	cx, 130
  1731 00000902 F3A4                    	rep     movsb
  1732 00000904 BF[0F160000]            	mov     edi, Header+ModHeader.mhSamples + (15*ModSample.size)
  1733 00000909 30C0                    	xor     al, al
  1734 0000090B 66B9E001                	mov     cx, 16*ModSample.size
  1735 0000090F F3AA                    	rep     stosb
  1736                                  SeekPatterns:   
  1737                                  	; ebx = [FileHandle]
  1738                                  	; ecx = offset
  1739                                  	; edx = switch (0 = from beginning)
  1740                                  	sys	_seek, [FileHandle], 600, 0
  1740                              <1> 
  1740                              <1> 
  1740                              <1> 
  1740                              <1> 
  1740                              <1>  %if %0 >= 2
  1740 00000911 8B1D[35140000]      <1>  mov ebx, %2
  1740                              <1>  %if %0 >= 3
  1740 00000917 B958020000          <1>  mov ecx, %3
  1740                              <1>  %if %0 = 4
  1740 0000091C BA00000000          <1>  mov edx, %4
  1740                              <1>  %endif
  1740                              <1>  %endif
  1740                              <1>  %endif
  1740 00000921 B813000000          <1>  mov eax, %1
  1740                              <1> 
  1740 00000926 CD40                <1>  int 40h
  1741                                  IsModFile:
  1742 00000928 A0[EF170000]            	mov     al, [Header+ModHeader.mhOrderLen]
  1743 0000092D A2[77180000]            	mov     [ModInfo.OrderLen], al
  1744                                  
  1745 00000932 A0[F0170000]            	mov     al, [Header+ModHeader.mhReStart]
  1746 00000937 3A05[EF170000]          	cmp     al, [Header+ModHeader.mhOrderLen]
  1747 0000093D 7202                    	jb      short SetReStart
  1748 0000093F B07F                    	mov     al, 7Fh
  1749                                  SetReStart:
  1750 00000941 A2[78180000]            	mov     [ModInfo.ReStart], al
  1751                                  
  1752                                  	;mov	ecx, 128
  1753 00000946 66B98000                	mov	cx, 128
  1754 0000094A 31D2                    	xor     edx, edx
  1755 0000094C 31DB                    	xor     ebx, ebx
  1756                                  CopyOrder:
  1757 0000094E 8AB3[F1170000]          	mov     dh, [Header+ModHeader.mhOrder+ebx]
  1758 00000954 88B3[79180000]          	mov     [ModInfo.Order+ebx], dh
  1759 0000095A 38D6                    	cmp     dh, dl
  1760 0000095C 7202                    	jb      short NextOrder
  1761 0000095E 88F2                    	mov     dl, dh
  1762                                  NextOrder:
  1763 00000960 43                      	inc     ebx
  1764 00000961 E2EB                    	loop    CopyOrder
  1765                                  AllocPatterns:  
  1766 00000963 81E2FF000000            	and	edx, 0FFh
  1767 00000969 6642                    	inc	dx ; 14/03/2017
  1768                                  	; dl = count of 1024 bytes
  1769 0000096B C1E20A                  	shl	edx, 10 ; *1024
  1770                                  
  1771 0000096E 89D5                    	mov	ebp, edx
  1772                                  	;mov	ecx, 10000h ; next 64K (4096*16)
  1773 00000970 B9[00000200]            	mov	ecx, file_buffer ; 12/03/2017
  1774                                  	;
  1775 00000975 890D[F9180000]          	mov	[ModInfo.Patterns], ecx
  1776                                  	;
  1777 0000097B 01CD                    	add	ebp, ecx ; next offset for samples
  1778                                  ReadPatterns:  
  1779                                  	;mov	ebx, [FileHandle] 
  1780                                  	; ebx = File handle
  1781                                  	; ecx = Buffer address
  1782                                  	; edx = Byte count
  1783                                  	sys	_read, [FileHandle]
  1783                              <1> 
  1783                              <1> 
  1783                              <1> 
  1783                              <1> 
  1783                              <1>  %if %0 >= 2
  1783 0000097D 8B1D[35140000]      <1>  mov ebx, %2
  1783                              <1>  %if %0 >= 3
  1783                              <1>  mov ecx, %3
  1783                              <1>  %if %0 = 4
  1783                              <1>  mov edx, %4
  1783                              <1>  %endif
  1783                              <1>  %endif
  1783                              <1>  %endif
  1783 00000983 B803000000          <1>  mov eax, %1
  1783                              <1> 
  1783 00000988 CD40                <1>  int 40h
  1784 0000098A 0F8296000000            	jc      CloseFile
  1785                                  
  1786 00000990 BE[4D140000]            	mov	esi, Header+ModHeader.mhSamples
  1787 00000995 31FF                    	xor     edi, edi
  1788                                  CopySamples:
  1789 00000997 668B4616                	mov     ax, [esi+ModSample.msLength]
  1790 0000099B 86C4                    	xchg    al, ah
  1791 0000099D 66D1E0                  	shl     ax, 1
  1792 000009A0 668987[79190000]        	mov     [ModInfo.SampLen+edi], ax
  1793 000009A7 8A4619                  	mov     al, [esi+ModSample.msVolume]
  1794 000009AA 30E4                    	xor     ah, ah
  1795 000009AC 668987[331A0000]        	mov     [ModInfo.SampVol+edi], ax
  1796 000009B3 668B461A                	mov     ax, [esi+ModSample.msRepeat]
  1797 000009B7 86C4                    	xchg    al, ah
  1798 000009B9 66D1E0                  	shl     ax, 1
  1799 000009BC 668987[B7190000]        	mov     [ModInfo.SampRep+edi], ax
  1800 000009C3 668B461C                	mov     ax, [esi+ModSample.msRepLen]
  1801 000009C7 86C4                    	xchg    al, ah
  1802 000009C9 66D1E0                  	shl     ax, 1
  1803 000009CC 668987[F5190000]        	mov     [ModInfo.SampRepLen+edi], ax
  1804 000009D3 83C61E                  	add     esi, ModSample.size
  1805 000009D6 6683C702                	add     di, 2
  1806 000009DA 6683FF3E                	cmp     di, 2*31
  1807 000009DE 72B7                    	jb      short CopySamples
  1808                                  
  1809 000009E0 31F6                    	xor     esi, esi
  1810                                  AllocSamples:
  1811 000009E2 0FB796[79190000]        	movzx	edx, word [ModInfo.SampLen+esi]
  1812 000009E9 09D2                    	or	edx, edx ; byte count
  1813 000009EB 7426                    	jz      short NextSample
  1814 000009ED 89E8                    	mov	eax, ebp
  1815 000009EF 668986[FD180000]        	mov	[ModInfo.SampOfs+esi], ax
  1816 000009F6 C1E810                  	shr	eax, 16
  1817 000009F9 668986[3B190000]        	mov	[ModInfo.SampSeg+esi], ax
  1818 00000A00 89E9                    	mov	ecx, ebp
  1819 00000A02 01D5                    	add	ebp, edx ; next offset for sample 
  1820                                  ReadSample:
  1821                                  	;mov	ebx, [FileHandle]
  1822                                  	;movzx  edx, [ModInfo.SampLen+esi]
  1823                                  	;mov    ecx, [ModInfo.SampOfs+esi]
  1824                                  
  1825                                  	; ebx = File handle
  1826                                  	; ecx = Buffer address
  1827                                  	; edx = Byte count
  1828                                  	sys	_read, [FileHandle]
  1828                              <1> 
  1828                              <1> 
  1828                              <1> 
  1828                              <1> 
  1828                              <1>  %if %0 >= 2
  1828 00000A04 8B1D[35140000]      <1>  mov ebx, %2
  1828                              <1>  %if %0 >= 3
  1828                              <1>  mov ecx, %3
  1828                              <1>  %if %0 = 4
  1828                              <1>  mov edx, %4
  1828                              <1>  %endif
  1828                              <1>  %endif
  1828                              <1>  %endif
  1828 00000A0A B803000000          <1>  mov eax, %1
  1828                              <1> 
  1828 00000A0F CD40                <1>  int 40h
  1829 00000A11 7213                    	jc      short CloseFile
  1830                                  
  1831                                  NextSample:
  1832 00000A13 6683C602                	add     si, 2
  1833 00000A17 6683FE3E                	cmp     si, 2*31
  1834 00000A1B 72C5                    	jb      short AllocSamples
  1835                                  
  1836 00000A1D 66C705[37140000]00-     	mov     word [ErrorInfo], 0
  1836 00000A25 00                 
  1837                                  CloseFile:      
  1838                                  	sys	_close, [FileHandle]
  1838                              <1> 
  1838                              <1> 
  1838                              <1> 
  1838                              <1> 
  1838                              <1>  %if %0 >= 2
  1838 00000A26 8B1D[35140000]      <1>  mov ebx, %2
  1838                              <1>  %if %0 >= 3
  1838                              <1>  mov ecx, %3
  1838                              <1>  %if %0 = 4
  1838                              <1>  mov edx, %4
  1838                              <1>  %endif
  1838                              <1>  %endif
  1838                              <1>  %endif
  1838 00000A2C B806000000          <1>  mov eax, %1
  1838                              <1> 
  1838 00000A31 CD40                <1>  int 40h
  1839                                  Failed:         
  1840 00000A33 61                      	popad
  1841                                  
  1842 00000A34 C3                      	retn
  1843                                  
  1844                                  FreeModule:
  1845                                  	; Erdogan Tan (13/02/2017)
  1846                                  	; nothing to do here for memory de-allocation
  1847                                  ClearModInfo:
  1848 00000A35 57                      	push	edi
  1849 00000A36 BF[77180000]            	mov	edi, ModInfo
  1850 00000A3B B9FA010000              	mov     ecx, ModInfoRec.size
  1851                                  	;cld
  1852 00000A40 30C0                    	xor     al, al
  1853 00000A42 F3AA                    	rep     stosb
  1854 00000A44 5F                      	pop	edi
  1855 00000A45 C3                      	retn
  1856                                  
  1857                                  ;=============================================================================
  1858                                  ;               MODPLAY.ASM
  1859                                  ;=============================================================================
  1860                                  
  1861                                  ; Amiga Module Loader v0.3b by Carlos Hasan.
  1862                                  ;	July 23th, 1993.
  1863                                  
  1864                                  ; EQUATES
  1865                                  
  1866                                  NumTracks       equ 4
  1867                                  DefTempo        equ 6
  1868                                  DefBpm          equ 125
  1869                                  MidCRate        equ 8448
  1870                                  MixBufSize      equ 4096
  1871                                  
  1872                                  ; STRUCTURES
  1873                                  
  1874                                  struc TrackInfo
  1875 00000000 <res 00000004>          .Samples:	resd 1
  1876 00000004 <res 00000004>          .Position:	resd 1
  1877 00000008 <res 00000002>          .Len:	resw 1
  1878 0000000A <res 00000002>          .Repeat:	resw 1
  1879 0000000C <res 00000002>          .RepLen:	resw 1
  1880 0000000E <res 00000001>          .Volume: 	resb 1
  1881 0000000F <res 00000001>          .Error:	resb 1
  1882 00000010 <res 00000002>          .Period:	resw 1
  1883 00000012 <res 00000002>          .Pitch:	resw 1
  1884 00000014 <res 00000002>          .Effect:	resw 1
  1885 00000016 <res 00000002>          .PortTo:	resw 1
  1886 00000018 <res 00000001>          .PortParm:	resb 1
  1887 00000019 <res 00000001>          .VibPos:	resb 1
  1888 0000001A <res 00000001>          .VibParm:	resb 1
  1889 0000001B <res 00000001>          .OldSampOfs:	resb 1
  1890 0000001C <res 00000006>          .Arp:	resw 3
  1891 00000022 <res 00000002>          .ArpIndex:	resw 1
  1892                                  .size:
  1893                                  endstruc
  1894                                  
  1895                                  ; CODE
  1896                                  
  1897                                  ;--------------------------------------------------------------------------
  1898                                  ; BeatTrack:  Process the next beat in one track.
  1899                                  ;  In:
  1900                                  ;    ds:di -  Track info Address.
  1901                                  ;--------------------------------------------------------------------------
  1902                                  
  1903                                  ; edi = Track info address
  1904                                  
  1905                                  BeatTrack:
  1906 00000A46 668B5714                	mov     dx, [edi+TrackInfo.Effect]
  1907 00000A4A 6685D2                  	test    dx, dx
  1908 00000A4D 743C                    	je      short None
  1909 00000A4F 80FE00                  	cmp     dh, 00h
  1910 00000A52 7438                    	je      short Arpeggio
  1911 00000A54 80FE01                  	cmp     dh, 01h
  1912 00000A57 7451                    	je      short PortUp
  1913 00000A59 80FE02                  	cmp     dh, 02h
  1914 00000A5C 7471                    	je      short PortDown
  1915 00000A5E 80FE03                  	cmp     dh, 03h
  1916 00000A61 0F848E000000            	je      TonePort
  1917 00000A67 80FE04                  	cmp     dh, 04h
  1918 00000A6A 0F84BD000000            	je      Vibrato
  1919 00000A70 80FE05                  	cmp     dh, 05h
  1920 00000A73 0F840E010000            	je      PortSlide
  1921 00000A79 80FE06                  	cmp     dh, 06h
  1922 00000A7C 0F8412010000            	je      VibSlide
  1923 00000A82 80FE0A                  	cmp     dh, 0Ah
  1924 00000A85 0F8413010000            	je      VolSlide
  1925                                  None:           
  1926 00000A8B C3                      	retn
  1927                                  Arpeggio:
  1928 00000A8C 0FB75F22                	movzx   ebx, word [edi+TrackInfo.ArpIndex]
  1929 00000A90 668B441F1C              	mov     ax, [edi+TrackInfo.Arp+ebx]
  1930 00000A95 66894712                	mov     [edi+TrackInfo.Pitch], ax
  1931 00000A99 6683C302                	add     bx, 2
  1932 00000A9D 6683FB06                	cmp     bx, 6
  1933 00000AA1 7202                    	jb      short SetArpIndex
  1934 00000AA3 31DB                    	xor     ebx, ebx
  1935                                  SetArpIndex:
  1936 00000AA5 66895F22                	mov     [edi+TrackInfo.ArpIndex], bx
  1937 00000AA9 C3                      	retn
  1938                                  PortUp:
  1939 00000AAA 30F6                    	xor     dh, dh
  1940 00000AAC 668B5F10                	mov     bx, [edi+TrackInfo.Period]
  1941 00000AB0 6629D3                  	sub     bx, dx
  1942 00000AB3 6683FB71                	cmp     bx, 113
  1943 00000AB7 7D04                    	jge     short NotSmall
  1944 00000AB9 66BB7100                	mov     bx, 113
  1945                                  NotSmall:
  1946 00000ABD 66895F10                	mov     [edi+TrackInfo.Period], bx
  1947 00000AC1 6601DB                  	add     bx, bx
  1948 00000AC4 66678B87[711A]          	mov     ax, [PitchTable+bx]
  1949 00000ACA 66894712                	mov     [edi+TrackInfo.Pitch], ax
  1950 00000ACE C3                      	retn
  1951                                  PortDown:
  1952 00000ACF 30F6                    	xor     dh, dh
  1953 00000AD1 668B5F10                	mov     bx, [edi+TrackInfo.Period]
  1954 00000AD5 6601D3                  	add     bx, dx
  1955 00000AD8 6681FB5803              	cmp     bx, 856
  1956 00000ADD 7E04                    	jle     short NotBig
  1957 00000ADF 66BB5803                	mov     bx, 856
  1958 00000AE3 66895F10                NotBig:         mov     [edi+TrackInfo.Period], bx
  1959 00000AE7 6601DB                  	add     bx, bx
  1960 00000AEA 66678B87[711A]          	mov     ax, [PitchTable+bx]
  1961 00000AF0 66894712                	mov     [edi+TrackInfo.Pitch], ax
  1962 00000AF4 C3                      	retn
  1963                                  TonePort:
  1964 00000AF5 30F6                    	xor     dh, dh
  1965 00000AF7 668B4716                	mov     ax, [edi+TrackInfo.PortTo]
  1966 00000AFB 668B5F10                	mov     bx, [edi+TrackInfo.Period]
  1967 00000AFF 6639C3                  	cmp     bx, ax
  1968 00000B02 7428                    	je      short NoPort
  1969 00000B04 7F0D                    	jg      short PortToUp
  1970                                  PortToDown:     
  1971 00000B06 6601D3                  	add     bx, dx
  1972 00000B09 6639C3                  	cmp     bx, ax
  1973 00000B0C 7E0D                    	jle     short SetPort
  1974                                  FixPort:        
  1975 00000B0E 6689C3                  	mov     bx, ax
  1976 00000B11 EB08                    	jmp     short SetPort
  1977                                  PortToUp:
  1978 00000B13 6629D3                  	sub     bx, dx
  1979 00000B16 6639C3                  	cmp     bx, ax
  1980 00000B19 7CF3                    	jl      short FixPort
  1981                                  SetPort:        
  1982 00000B1B 66895F10                	mov     [edi+TrackInfo.Period], bx
  1983 00000B1F 6601DB                  	add     bx, bx
  1984 00000B22 66678B87[711A]          	mov     ax, [PitchTable+bx]
  1985 00000B28 66894712                	mov     [edi+TrackInfo.Pitch], ax
  1986                                  NoPort:         
  1987 00000B2C C3                      	retn
  1988                                  Vibrato:
  1989 00000B2D 88D6                    	mov     dh, dl
  1990 00000B2F 80E20F                  	and     dl, 0Fh
  1991 00000B32 C0EE04                  	shr     dh, 4
  1992 00000B35 C0E602                  	shl     dh, 2
  1993 00000B38 007719                  	add     [edi+TrackInfo.VibPos], dh
  1994 00000B3B 8A7719                  	mov     dh, [edi+TrackInfo.VibPos]
  1995 00000B3E 88F3                    	mov     bl, dh
  1996 00000B40 C0EB02                  	shr     bl, 2
  1997 00000B43 6683E31F                	and     bx, 1Fh
  1998 00000B47 678A87[E112]            	mov     al, [SinTable+bx]
  1999 00000B4C F6E2                    	mul     dl
  2000 00000B4E 66D1C0                  	rol     ax, 1
  2001 00000B51 86C4                    	xchg    al, ah
  2002 00000B53 80E401                  	and     ah, 1
  2003 00000B56 84F6                    	test    dh, dh
  2004 00000B58 7903                    	jns     short VibUp
  2005 00000B5A 66F7D8                  	neg     ax
  2006                                  VibUp:          
  2007 00000B5D 66034710                	add     ax, [edi+TrackInfo.Period]
  2008 00000B61 6689C3                  	mov     bx, ax
  2009 00000B64 6683FB71                	cmp     bx, 113
  2010 00000B68 7D04                    	jge     short NoLoVib
  2011 00000B6A 66BB7100                	mov     bx, 113
  2012                                  NoLoVib:        
  2013 00000B6E 6681FB5803              	cmp     bx, 856
  2014 00000B73 7E04                    	jle     short NoHiVib
  2015 00000B75 66BB5803                	mov     bx, 856
  2016                                  NoHiVib:        
  2017 00000B79 6601DB                  	add     bx, bx
  2018 00000B7C 66678B87[711A]          	mov     ax, [PitchTable+bx]
  2019 00000B82 66894712                	mov     [edi+TrackInfo.Pitch], ax
  2020 00000B86 C3                      	retn
  2021                                  PortSlide:
  2022 00000B87 E812000000              	call    VolSlide
  2023 00000B8C 8A5718                  	mov     dl, [edi+TrackInfo.PortParm]
  2024 00000B8F E961FFFFFF              	jmp     TonePort
  2025                                  VibSlide:
  2026 00000B94 E805000000              	call    VolSlide
  2027 00000B99 8A571A                  	mov     dl, [edi+TrackInfo.VibParm]
  2028 00000B9C EB8F                    	jmp     short Vibrato
  2029                                  VolSlide:
  2030 00000B9E 88D6                    	mov     dh, dl
  2031 00000BA0 80E20F                  	and     dl, 0Fh
  2032 00000BA3 C0EE04                  	shr     dh, 4
  2033 00000BA6 8A470E                  	mov     al, [edi+TrackInfo.Volume]
  2034 00000BA9 28D0                    	sub     al, dl
  2035 00000BAB 7D02                    	jge     short NoLoVol
  2036 00000BAD 30C0                    	xor     al, al
  2037                                  NoLoVol:        
  2038 00000BAF 00F0                    	add     al, dh
  2039 00000BB1 3C40                    	cmp     al, 64
  2040 00000BB3 7602                    	jbe     short NoHiVol
  2041 00000BB5 B040                    	mov     al, 64
  2042                                  NoHiVol:        
  2043 00000BB7 88470E                  	mov     [edi+TrackInfo.Volume], al
  2044 00000BBA C3                      	retn
  2045                                  
  2046                                  ;--------------------------------------------------------------------------
  2047                                  ; GetTrack:   Get the next Note from a pattern.
  2048                                  ;  In:
  2049                                  ;    ds:di -  Track info Address.
  2050                                  ;    es:si -  Pattern Note Address.
  2051                                  ; Out:
  2052                                  ;    es:si -  The Next Pattern Note address.
  2053                                  ;--------------------------------------------------------------------------
  2054                                  
  2055                                  ; esi = Pattern note address
  2056                                  ; edi = Track info address
  2057                                  
  2058                                  GetTrack:
  2059 00000BBB 66AD                    	lodsw
  2060 00000BBD 86C4                    	xchg    al, ah
  2061 00000BBF 88E3                    	mov	bl, ah
  2062 00000BC1 80E40F                  	and     ah, 0Fh
  2063 00000BC4 6689C1                  	mov     cx, ax
  2064 00000BC7 66AD                    	lodsw
  2065 00000BC9 86C4                    	xchg    al, ah
  2066 00000BCB 88E7                    	mov     bh, ah
  2067 00000BCD 80E40F                  	and     ah, 0Fh
  2068 00000BD0 6689C2                  	mov     dx, ax
  2069 00000BD3 66895714                	mov     [edi+TrackInfo.Effect], dx
  2070 00000BD7 80E3F0                  	and     bl, 0F0h
  2071 00000BDA C0EF04                  	shr     bh, 4
  2072 00000BDD 08FB                    	or      bl, bh
  2073 00000BDF 7449                    	je      short SetPeriod
  2074                                  SetSample:
  2075                                  	;xor    bh, bh
  2076 00000BE1 81E3FF000000            	and	ebx, 0FFh
  2077 00000BE7 4B                      	dec     ebx
  2078 00000BE8 01DB                    	add     ebx, ebx
  2079 00000BEA 668B83[331A0000]        	mov     ax, [ModInfo.SampVol+ebx]
  2080 00000BF1 88470E                  	mov     [edi+TrackInfo.Volume], al
  2081 00000BF4 668B83[FD180000]        	mov     ax, [ModInfo.SampOfs+ebx]
  2082 00000BFB 668907                  	mov     [edi+TrackInfo.Samples], ax
  2083 00000BFE 668B83[3B190000]        	mov     ax, [ModInfo.SampSeg+ebx]
  2084 00000C05 66894702                	mov     [edi+TrackInfo.Samples+2], ax
  2085 00000C09 668B83[79190000]        	mov     ax, [ModInfo.SampLen+ebx]
  2086 00000C10 66894708                	mov     [edi+TrackInfo.Len], ax
  2087 00000C14 668B83[B7190000]        	mov     ax, [ModInfo.SampRep+ebx]
  2088 00000C1B 6689470A                	mov     [edi+TrackInfo.Repeat], ax
  2089 00000C1F 668B83[F5190000]        	mov     ax, [ModInfo.SampRepLen+ebx]
  2090 00000C26 6689470C                	mov     [edi+TrackInfo.RepLen], ax
  2091                                  SetPeriod:      
  2092 00000C2A 6685C9                  	test    cx, cx
  2093 00000C2D 7424                    	jz      short SetEffect
  2094                                  
  2095 00000C2F 66894F16                	mov     [edi+TrackInfo.PortTo], cx
  2096 00000C33 80FE03                  	cmp     dh, 03h
  2097 00000C36 741B                    	je      short SetEffect
  2098                                  
  2099 00000C38 66894F10                	mov     [edi+TrackInfo.Period], cx
  2100 00000C3C 6689CB                  	mov     bx, cx
  2101 00000C3F 6601DB                  	add     bx, bx
  2102 00000C42 66678B87[711A]          	mov     ax, [PitchTable+bx]
  2103 00000C48 66894712                	mov     [edi+TrackInfo.Pitch], ax
  2104 00000C4C C7470400000000          	mov     dword [edi+TrackInfo.Position], 0
  2105                                  SetEffect:
  2106 00000C53 6685D2                  	test    dx, dx
  2107 00000C56 7430                    	jz      short InitNone
  2108 00000C58 80FE00                  	cmp     dh, 00h
  2109 00000C5B 0F84E5000000            	je      InitArpeggio
  2110 00000C61 80FE03                  	cmp     dh, 03h
  2111 00000C64 7423                    	je      short InitTonePort
  2112 00000C66 80FE04                  	cmp     dh, 04h
  2113 00000C69 742D                    	je      short InitVibrato
  2114 00000C6B 80FE09                  	cmp     dh, 09h
  2115 00000C6E 7451                    	je      short SampleOfs
  2116 00000C70 80FE0B                  	cmp     dh, 0Bh
  2117 00000C73 7462                    	je      short PosJump
  2118 00000C75 80FE0C                  	cmp     dh, 0Ch
  2119 00000C78 746B                    	je      short SetVolume
  2120 00000C7A 80FE0D                  	cmp     dh, 0Dh
  2121 00000C7D 7471                    	je      short Break
  2122 00000C7F 80FE0F                  	cmp     dh, 0Fh
  2123 00000C82 0F8487000000            	je      SetSpeed
  2124                                  InitNone:
  2125 00000C88 C3                      	retn
  2126                                  InitTonePort:
  2127 00000C89 84D2                    	test    dl, dl
  2128 00000C8B 7503                    	jnz     short SetPortParm
  2129 00000C8D 8A5718                  	mov     dl, [edi+TrackInfo.PortParm]
  2130                                  SetPortParm:    
  2131 00000C90 885718                  	mov     [edi+TrackInfo.PortParm], dl
  2132 00000C93 66895714                	mov     [edi+TrackInfo.Effect], dx
  2133 00000C97 C3                      	retn
  2134                                  InitVibrato:
  2135 00000C98 8A471A                  	mov     al, [edi+TrackInfo.VibParm]
  2136 00000C9B 88C4                    	mov     ah, al
  2137 00000C9D 240F                    	and     al, 0Fh
  2138 00000C9F 80E4F0                  	and     ah, 0F0h
  2139 00000CA2 F6C20F                  	test    dl, 0Fh
  2140 00000CA5 7502                    	jne     short OkDepth
  2141 00000CA7 08C2                    	or      dl, al
  2142                                  OkDepth:        
  2143 00000CA9 F6C2F0                  	test    dl, 0F0h
  2144 00000CAC 7502                    	jnz     short OkRate
  2145 00000CAE 08E2                    	or      dl, ah
  2146                                  OkRate:         
  2147 00000CB0 88571A                  	mov     [edi+TrackInfo.VibParm], dl
  2148 00000CB3 66895714                	mov     [edi+TrackInfo.Effect], dx
  2149 00000CB7 6685C9                  	test    cx, cx
  2150 00000CBA 7404                    	jz      short OkPos
  2151 00000CBC C6471900                	mov     byte [edi+TrackInfo.VibPos], 0
  2152                                  OkPos:          
  2153 00000CC0 C3                      	retn
  2154                                  SampleOfs:      
  2155 00000CC1 84D2                    	test    dl, dl
  2156 00000CC3 7503                    	jnz     short SetSampleOfs
  2157 00000CC5 8A571B                  	mov     dl, [edi+TrackInfo.OldSampOfs]
  2158                                  SetSampleOfs:
  2159 00000CC8 88571B                  	mov     [edi+TrackInfo.OldSampOfs], dl
  2160 00000CCB 88D6                    	mov     dh, dl
  2161 00000CCD 81E200FF0000            	and 	edx, 0FF00h ; 05/03/2017
  2162 00000CD3 895704                  	mov     [edi+TrackInfo.Position], edx
  2163 00000CD6 C3                      	retn
  2164                                  PosJump:
  2165 00000CD7 8815[23720000]          	mov     [OrderPos], dl
  2166 00000CDD C605[27720000]40        	mov     byte [Row], 64
  2167 00000CE4 C3                      	retn
  2168                                  SetVolume:
  2169 00000CE5 80FA40                  	cmp     dl, 64
  2170 00000CE8 7602                    	jbe     short OkVol
  2171 00000CEA B240                    	mov     dl, 64
  2172                                  OkVol:
  2173 00000CEC 88570E                  	mov     [edi+TrackInfo.Volume], dl
  2174 00000CEF C3                      	retn
  2175                                  Break:
  2176 00000CF0 88D6                    	mov     dh, dl
  2177 00000CF2 80E20F                  	and     dl, 0Fh
  2178 00000CF5 C0EE04                  	shr     dh, 4
  2179 00000CF8 00F6                    	add     dh, dh
  2180 00000CFA 00F2                    	add     dl, dh
  2181 00000CFC C0E602                  	shl     dh, 2
  2182 00000CFF 00F2                    	add     dl, dh
  2183 00000D01 8815[28720000]          	mov     [BreakRow], dl
  2184 00000D07 C605[27720000]40        	mov     byte [Row], 64
  2185 00000D0E C3                      	retn
  2186                                  SetSpeed:
  2187 00000D0F 84D2                    	test    dl,dl
  2188 00000D11 7432                    	je      Skip
  2189 00000D13 80FA1F                  	cmp     dl,31
  2190 00000D16 770D                    	ja      short SetBpm
  2191                                  SetTempo:       
  2192 00000D18 8815[24720000]          	mov     [Tempo], dl
  2193 00000D1E 8815[25720000]          	mov     [TempoWait], dl
  2194 00000D24 C3                      	retn
  2195                                  SetBpm:
  2196 00000D25 8815[26720000]          	mov     [Bpm], dl
  2197 00000D2B B067                    	mov     al, 103
  2198 00000D2D F6E2                    	mul     dl
  2199 00000D2F 88E3                    	mov     bl, ah
  2200 00000D31 30FF                    	xor     bh, bh
  2201 00000D33 66A1[75180000]          	mov     ax, [MixSpeed]
  2202 00000D39 6631D2                  	xor     dx, dx
  2203 00000D3C 66F7F3                  	div     bx
  2204 00000D3F 66A3[29720000]          	mov     [BpmSamples], ax
  2205                                  Skip:           
  2206 00000D45 C3                      	retn
  2207                                  InitArpeggio:
  2208 00000D46 88D6                    	mov     dh, dl
  2209 00000D48 80E20F                  	and     dl, 0Fh
  2210 00000D4B C0EE04                  	shr     dh, 4
  2211 00000D4E 66B92400                	mov     cx, 36
  2212 00000D52 31DB                    	xor     ebx, ebx
  2213 00000D54 668B4710                	mov     ax, [edi+TrackInfo.Period]
  2214                                  gt_ScanPeriod:
  2215 00000D58 66673B87[0113]          	cmp     ax, [PeriodTable+bx]
  2216 00000D5E 7306                    	jae     short SetArp
  2217 00000D60 6683C302                	add     bx, 2
  2218 00000D64 E2F2                    	loop    gt_ScanPeriod
  2219                                  SetArp:         
  2220 00000D66 6601D2                  	add     dx, dx
  2221 00000D69 00DE                    	add     dh, bl
  2222 00000D6B 00DA                    	add     dl, bl
  2223 00000D6D 66678B9F[0113]          	mov     bx, [PeriodTable+bx]
  2224 00000D73 6601DB                  	add     bx, bx
  2225 00000D76 66678B87[711A]          	mov     ax, [PitchTable+bx]
  2226 00000D7C 6689471C                	mov     [edi+TrackInfo.Arp], ax
  2227 00000D80 88F3                    	mov     bl, dh
  2228 00000D82 30FF                    	xor     bh, bh
  2229 00000D84 66678B9F[0113]          	mov     bx, [PeriodTable+bx]
  2230 00000D8A 6601DB                  	add     bx, bx
  2231 00000D8D 66678B87[711A]          	mov     ax, [PitchTable+bx]
  2232 00000D93 6689471E                	mov     [edi+TrackInfo.Arp+2], ax
  2233 00000D97 88D3                    	mov     bl, dl
  2234 00000D99 30FF                    	xor     bh, bh
  2235 00000D9B 66678B9F[0113]          	mov     bx, [PeriodTable+bx]
  2236 00000DA1 6601DB                  	add     bx, bx
  2237 00000DA4 66678B87[711A]          	mov     ax, [PitchTable+bx]
  2238 00000DAA 66894720                	mov     [edi+TrackInfo.Arp+4], ax
  2239 00000DAE 66C747220000            	mov     word [edi+TrackInfo.ArpIndex], 0
  2240 00000DB4 C3                      	retn
  2241                                  
  2242                                  ;--------------------------------------------------------------------------
  2243                                  ; UpdateTracks:  Main code to process the next tick to be played.
  2244                                  ;--------------------------------------------------------------------------
  2245                                  
  2246                                  UpdateTracks:
  2247 00000DB5 FE0D[25720000]          	dec     byte [TempoWait]
  2248 00000DBB 7415                    	jz      short GetTracks
  2249                                  
  2250 00000DBD B904000000              	mov	ecx, NumTracks
  2251 00000DC2 BF[39720000]            	mov	edi, Tracks
  2252                                  BeatTracks:
  2253 00000DC7 E87AFCFFFF              	call	BeatTrack	
  2254 00000DCC 83C724                  	add	edi, TrackInfo.size
  2255 00000DCF E2F6                    	loop	BeatTracks
  2256 00000DD1 C3                      	retn
  2257                                  GetTracks:
  2258 00000DD2 A0[24720000]            	mov     al, [Tempo]
  2259 00000DD7 A2[25720000]            	mov     [TempoWait], al
  2260                                  
  2261 00000DDC 8B35[35720000]          	mov	esi, [Note]
  2262 00000DE2 803D[27720000]40        	cmp     byte [Row], 64
  2263 00000DE9 7263                    	jb      short NoPattWrap
  2264                                  
  2265 00000DEB 8B35[F9180000]          	mov	esi, [ModInfo.Patterns]
  2266 00000DF1 8A1D[23720000]          	mov     bl, [OrderPos]
  2267 00000DF7 3A1D[77180000]          	cmp     bl, [ModInfo.OrderLen]
  2268 00000DFD 7214                    	jb      short NoOrderWrap
  2269 00000DFF 8A1D[78180000]          	mov     bl, [ModInfo.ReStart]
  2270 00000E05 881D[23720000]          	mov     [OrderPos], bl
  2271 00000E0B 3A1D[77180000]          	cmp     bl, [ModInfo.OrderLen]
  2272 00000E11 735D                    	jae     short NoUpdate
  2273                                  NoOrderWrap:    
  2274                                  	;xor	bh, bh
  2275 00000E13 81E3FF000000            	and	ebx, 0FFh
  2276 00000E19 8A9B[79180000]          	mov     bl, [ModInfo.Order+ebx]
  2277 00000E1F C1E30A                  	shl     ebx, 10 ; *1024
  2278 00000E22 01DE                    	add     esi, ebx
  2279 00000E24 8A1D[28720000]          	mov     bl, [BreakRow]
  2280 00000E2A 881D[27720000]          	mov     [Row], bl
  2281                                  	;xor     bh, bh
  2282 00000E30 81E3FF000000            	and	ebx, 0FFh
  2283 00000E36 883D[28720000]          	mov     [BreakRow], bh ; 0
  2284 00000E3C 66C1E304                	shl     bx, 4
  2285 00000E40 01DE                    	add     esi, ebx
  2286 00000E42 8935[35720000]          	mov     [Note], esi
  2287 00000E48 FE05[23720000]          	inc     byte [OrderPos]
  2288                                  NoPattWrap:     
  2289 00000E4E FE05[27720000]          	inc     byte [Row]
  2290                                  
  2291                                  	;cld
  2292 00000E54 B904000000              	mov	ecx, NumTracks
  2293 00000E59 BF[39720000]            	mov	edi, Tracks
  2294                                  GetTracks_next:
  2295 00000E5E 51                      	push	ecx	
  2296 00000E5F E857FDFFFF              	call	GetTrack
  2297 00000E64 59                      	pop	ecx
  2298 00000E65 83C724                  	add	edi, TrackInfo.size
  2299 00000E68 E2F4                    	loop	GetTracks_next
  2300                                  
  2301 00000E6A 8935[35720000]          	mov     [Note], esi
  2302                                  NoUpdate:
  2303 00000E70 C3                      	retn
  2304                                  
  2305                                  ;--------------------------------------------------------------------------
  2306                                  ; MixTrack:  Mixes one track into a CLEAN buffer.
  2307                                  ;  In:
  2308                                  ;   ds:si -  Track Info Address.
  2309                                  ;   ds:di -  Buffer Address.
  2310                                  ;    cx   -  Buffer Size.
  2311                                  ;--------------------------------------------------------------------------
  2312                                  
  2313                                  ; esi = Track info address
  2314                                  ; edi = Buffer address
  2315                                  ; ecx = Buffer size
  2316                                  
  2317                                  MixTrack:
  2318 00000E71 66837E0C02              	cmp     word [esi+TrackInfo.RepLen], 2
  2319 00000E76 7748                    	ja      short MixLooped
  2320                                  MixNonLooped:   
  2321 00000E78 8B16                    	mov	edx, [esi+TrackInfo.Samples]
  2322 00000E7A 8B5E04                  	mov	ebx, [esi+TrackInfo.Position]
  2323 00000E7D 0FB76E08                	movzx   ebp, word [esi+TrackInfo.Len]
  2324 00000E81 52                      	push    edx
  2325 00000E82 56                      	push    esi
  2326 00000E83 01D3                    	add     ebx, edx
  2327 00000E85 01D5                    	add     ebp, edx
  2328 00000E87 668B5612                	mov     dx, [esi+TrackInfo.Pitch]
  2329 00000E8B 8A460E                  	mov     al, [esi+TrackInfo.Volume]
  2330 00000E8E 8A660F                  	mov     ah, [esi+TrackInfo.Error]
  2331 00000E91 89DE                    	mov     esi, ebx
  2332 00000E93 88C7                    	mov     bh, al
  2333 00000E95 88D0                    	mov     al, dl
  2334 00000E97 88F2                    	mov     dl, dh
  2335                                  	;xor	dh, dh
  2336 00000E99 81E2FF000000            	and	edx, 0FFh
  2337                                  nlMixSamp:      
  2338 00000E9F 39EE                    	cmp     esi, ebp
  2339 00000EA1 7310                    	jae     short nlMixBye
  2340 00000EA3 8A1E                    	mov     bl, [esi]
  2341 00000EA5 678A9F[2321]            	mov     bl, [VolTable+bx]
  2342 00000EAA 001F                    	add     [edi], bl
  2343 00000EAC 47                      	inc     edi
  2344 00000EAD 00C4                    	add     ah, al
  2345 00000EAF 11D6                    	adc     esi, edx
  2346 00000EB1 E2EC                    	loop    nlMixSamp
  2347                                  nlMixBye:       
  2348 00000EB3 89F3                    	mov     ebx, esi
  2349 00000EB5 5E                      	pop     esi
  2350 00000EB6 5A                      	pop     edx
  2351 00000EB7 29D3                    	sub     ebx, edx
  2352 00000EB9 895E04                  	mov     [esi+TrackInfo.Position], ebx
  2353 00000EBC 88660F                  	mov     [esi+TrackInfo.Error], ah
  2354 00000EBF C3                      	retn
  2355                                  MixLooped:
  2356 00000EC0 8B16                    	mov	edx, [esi+TrackInfo.Samples]
  2357 00000EC2 8B5E04                  	mov	ebx, [esi+TrackInfo.Position]
  2358 00000EC5 0FB76E0C                	movzx	ebp, word [esi+TrackInfo.RepLen]
  2359 00000EC9 892D[31720000]          	mov     [BufRep], ebp
  2360 00000ECF 036E0A                  	add     ebp, [esi+TrackInfo.Repeat]
  2361 00000ED2 52                      	push    edx
  2362 00000ED3 56                      	push    esi
  2363 00000ED4 01D3                    	add     ebx, edx
  2364 00000ED6 01D5                    	add     ebp, edx
  2365 00000ED8 668B5612                	mov     dx, [esi+TrackInfo.Pitch]
  2366 00000EDC 8A460E                  	mov     al, [esi+TrackInfo.Volume]
  2367 00000EDF 8A660F                  	mov     ah, [esi+TrackInfo.Error]
  2368 00000EE2 6689DE                  	mov     si, bx
  2369 00000EE5 88C7                    	mov     bh, al
  2370 00000EE7 88D0                    	mov     al, dl
  2371 00000EE9 88F2                    	mov     dl, dh
  2372                                  	;xor	dh, dh
  2373 00000EEB 81E2FF000000            	and	edx, 0FFh
  2374                                  lpMixSamp:      
  2375 00000EF1 39EE                    	cmp     esi, ebp
  2376 00000EF3 7206                    	jb      short lpMixNow
  2377 00000EF5 2B35[31720000]          	sub     esi, [BufRep]
  2378                                  lpMixNow:       
  2379 00000EFB 8A1E                    	mov     bl, [esi]
  2380 00000EFD 678A9F[2321]            	mov     bl, [VolTable+bx]
  2381 00000F02 001F                    	add     [edi], bl
  2382 00000F04 47                      	inc     edi
  2383 00000F05 00C4                    	add     ah, al
  2384 00000F07 11D6                    	adc	esi, edx
  2385 00000F09 E2E6                    	loop    lpMixSamp
  2386                                  lpMixBye:       
  2387                                  ;	mov     ebx, esi
  2388                                  ;	pop     esi
  2389                                  ;	pop     edx
  2390                                  ;	sub     ebx, edx
  2391                                  ;	mov     [esi+TrackInfo.Position], ebx
  2392                                  ;	mov     [esi+TrackInfo.Error], ah
  2393                                  ;	retn
  2394 00000F0B EBA6                    	jmp	short nlMixBye
  2395                                  
  2396                                  ;--------------------------------------------------------------------------
  2397                                  ; GetSamples:  Returns the next chunk of samples to be played.
  2398                                  ;  In:
  2399                                  ;    Buffer  - Buffer Address.
  2400                                  ;    Count   - Buffer Size.
  2401                                  ;--------------------------------------------------------------------------
  2402                                  
  2403                                  GetSamples:
  2404                                  	; edi = buffer address
  2405                                  	; ebx = count
  2406                                  
  2407 00000F0D 60                      	pushad
  2408                                  
  2409                                  	;cld
  2410                                  NextChunk:      
  2411 00000F0E 66833D[2F720000]00      	cmp     word [BufLen], 0
  2412 00000F16 7548                    	jne     short CopyChunk
  2413                                  
  2414 00000F18 53                      	push    ebx
  2415 00000F19 57                      	push    edi
  2416                                  MixChunk:       
  2417 00000F1A BF[23620000]            	mov	edi, MixBuffer
  2418 00000F1F 0FB70D[29720000]        	movzx	ecx, word [BpmSamples]
  2419 00000F26 893D[2B720000]          	mov     [BufPtr], edi
  2420 00000F2C 66890D[2F720000]        	mov     [BufLen], cx
  2421                                  
  2422 00000F33 B080                    	mov     al, 80h
  2423 00000F35 F3AA                    	rep     stosb
  2424                                  
  2425 00000F37 66B90400                	mov	cx, NumTracks
  2426 00000F3B BE[15720000]            	mov	esi, Tracks - TrackInfo.size
  2427                                  GetSamples_next:
  2428 00000F40 51                      	push	ecx
  2429 00000F41 83C624                  	add	esi, TrackInfo.size
  2430 00000F44 668B0D[2F720000]        	mov	cx, [BufLen]
  2431 00000F4B 8B3D[2B720000]          	mov	edi, [BufPtr]
  2432 00000F51 E81BFFFFFF              	call	MixTrack
  2433 00000F56 59                      	pop	ecx
  2434 00000F57 E2E7                    	loop	GetSamples_next	
  2435                                  
  2436 00000F59 E857FEFFFF              	call    UpdateTracks
  2437                                  
  2438 00000F5E 5F                      	pop     edi
  2439 00000F5F 5B                      	pop     ebx
  2440                                  CopyChunk:      
  2441                                  	;mov	cx, [BufLen]
  2442 00000F60 0FB70D[2F720000]        	movzx	ecx, word [BufLen]
  2443 00000F67 39D9                    	cmp	ecx, ebx
  2444                                  	;cmp	cx, bx
  2445 00000F69 7602                    	jbe     short MoveChunk
  2446                                  	;mov	cx, bx
  2447 00000F6B 89D9                    	mov     ecx, ebx
  2448                                  MoveChunk:
  2449 00000F6D 8B35[2B720000]          	mov     esi, [BufPtr]
  2450 00000F73 010D[2B720000]          	add     [BufPtr], ecx
  2451 00000F79 66290D[2F720000]        	sub     [BufLen], cx
  2452 00000F80 29CB                    	sub     ebx, ecx
  2453 00000F82 F3A4                    	rep     movsb
  2454 00000F84 85DB                    	test    ebx, ebx
  2455 00000F86 7586                    	jnz     short NextChunk
  2456                                  
  2457 00000F88 61                      	popad
  2458 00000F89 C3                      	retn
  2459                                  
  2460                                  ;--------------------------------------------------------------------------
  2461                                  ; StartPlaying: Initializes the Sound System.
  2462                                  ;  In:
  2463                                  ;   Module Information Resources.
  2464                                  ;--------------------------------------------------------------------------
  2465                                  
  2466                                  StartPlaying:
  2467 00000F8A 60                      	pushad
  2468                                  SetModParms:    
  2469 00000F8B C605[23720000]00        	mov     byte [OrderPos], 0
  2470 00000F92 C605[24720000]06        	mov     byte [Tempo], DefTempo
  2471 00000F99 C605[25720000]06        	mov     byte [TempoWait], DefTempo
  2472 00000FA0 C605[26720000]7D        	mov     byte [Bpm], DefBpm
  2473 00000FA7 C605[27720000]40        	mov     byte [Row], 64
  2474 00000FAE C605[28720000]00        	mov     byte [BreakRow], 0
  2475 00000FB5 66A1[75180000]          	mov     ax, [MixSpeed]
  2476 00000FBB 31D2                    	xor     edx, edx
  2477 00000FBD 66BB3200                	mov     bx, 24*DefBpm/60
  2478 00000FC1 66F7F3                  	div     bx
  2479 00000FC4 66A3[29720000]          	mov     [BpmSamples], ax
  2480                                  ClearTracks:    
  2481 00000FCA BF[39720000]            	mov     edi, Tracks
  2482 00000FCF B990000000              	mov     ecx, NumTracks*TrackInfo.size
  2483 00000FD4 31C0                    	xor     eax, eax
  2484                                  	;cld
  2485 00000FD6 F3AA                    	rep     stosb
  2486                                  
  2487 00000FD8 A3[2B720000]            	mov     [BufPtr], eax
  2488 00000FDD 66A3[2F720000]          	mov     [BufLen], ax
  2489                                  MakePitch:
  2490 00000FE3 66B80021                	mov     ax, MidCRate
  2491 00000FE7 66BBAC01                	mov     bx, 428
  2492 00000FEB 66F7E3                  	mul     bx
  2493 00000FEE 66F735[75180000]        	div     word [MixSpeed]
  2494 00000FF5 30F6                    	xor     dh, dh
  2495 00000FF7 88E2                    	mov     dl, ah
  2496 00000FF9 88C4                    	mov     ah, al
  2497 00000FFB 30C0                    	xor     al, al
  2498 00000FFD 66B95903                	mov     cx, 857
  2499 00001001 31DB                    	xor     ebx, ebx
  2500 00001003 BF[711A0000]            	mov     edi, PitchTable
  2501                                  PitchLoop:      
  2502 00001008 50                      	push    eax
  2503 00001009 52                      	push    edx
  2504 0000100A 6639DA                  	cmp     dx, bx
  2505 0000100D 7303                    	jae     short NoDiv
  2506 0000100F 66F7F3                  	div     bx
  2507                                  NoDiv:          
  2508 00001012 66AB                    	stosw
  2509 00001014 5A                      	pop     edx
  2510 00001015 58                      	pop     eax
  2511 00001016 6643                    	inc     bx
  2512 00001018 E2EE                    	loop    PitchLoop
  2513                                  MakeVolume:     
  2514 0000101A 66B90041                	mov     cx, 16640
  2515 0000101E 89CB                    	mov     ebx, ecx
  2516                                  VolLoop:
  2517 00001020 664B                    	dec     bx
  2518 00001022 88D8                    	mov     al, bl
  2519 00001024 F6EF                    	imul    bh
  2520 00001026 88A3[23210000]          	mov     [VolTable+ebx], ah
  2521 0000102C E2F2                    	loop    VolLoop
  2522                                  
  2523 0000102E 61                      	popad
  2524 0000102F C3                      	retn
  2525                                  
  2526                                  ;--------------------------------------------------------------------------
  2527                                  ; StopPlaying: ShutDown the Sound System.
  2528                                  ;--------------------------------------------------------------------------
  2529                                  
  2530                                  StopPlaying:
  2531                                  	; 05/03/2017
  2532                                  
  2533 00001030 8A1D[25140000]          	mov     bl, [ac97_int_ln_reg] ; Audio IRQ number
  2534 00001036 28FF                    	sub	bh, bh ; 0 = Unlink IRQ from user
  2535                                  	sys	_calbac 
  2535                              <1> 
  2535                              <1> 
  2535                              <1> 
  2535                              <1> 
  2535                              <1>  %if %0 >= 2
  2535                              <1>  mov ebx, %2
  2535                              <1>  %if %0 >= 3
  2535                              <1>  mov ecx, %3
  2535                              <1>  %if %0 = 4
  2535                              <1>  mov edx, %4
  2535                              <1>  %endif
  2535                              <1>  %endif
  2535                              <1>  %endif
  2535 00001038 B82C000000          <1>  mov eax, %1
  2535                              <1> 
  2535 0000103D CD40                <1>  int 40h
  2536                                  
  2537                                  	; Deallocate BDL buffer (not necessary just before exit!)
  2538                                  	sys	_dalloc, BdlBuffer, 4096
  2538                              <1> 
  2538                              <1> 
  2538                              <1> 
  2538                              <1> 
  2538                              <1>  %if %0 >= 2
  2538 0000103F BB[00800000]        <1>  mov ebx, %2
  2538                              <1>  %if %0 >= 3
  2538 00001044 B900100000          <1>  mov ecx, %3
  2538                              <1>  %if %0 = 4
  2538                              <1>  mov edx, %4
  2538                              <1>  %endif
  2538                              <1>  %endif
  2538                              <1>  %endif
  2538 00001049 B82B000000          <1>  mov eax, %1
  2538                              <1> 
  2538 0000104E CD40                <1>  int 40h
  2539                                  	; Deallocate DMA buffer (not necessary just before exit!)
  2540                                  	sys	_dalloc, DmaBuffer, 65536  ; 14/03/2017
  2540                              <1> 
  2540                              <1> 
  2540                              <1> 
  2540                              <1> 
  2540                              <1>  %if %0 >= 2
  2540 00001050 BB[00000100]        <1>  mov ebx, %2
  2540                              <1>  %if %0 >= 3
  2540 00001055 B900000100          <1>  mov ecx, %3
  2540                              <1>  %if %0 = 4
  2540                              <1>  mov edx, %4
  2540                              <1>  %endif
  2540                              <1>  %endif
  2540                              <1>  %endif
  2540 0000105A B82B000000          <1>  mov eax, %1
  2540                              <1> 
  2540 0000105F CD40                <1>  int 40h
  2541                                  
  2542 00001061 C3                      	retn
  2543                                  
  2544                                  ;=============================================================================
  2545                                  ;               PLAYER.ASM
  2546                                  ;=============================================================================
  2547                                  
  2548                                  ; UTILS.ASM
  2549                                  ;----------------------------------------------------------------------------
  2550                                  ;       delay1_4ms - Delay for 1/4 millisecond.
  2551                                  ;	    1mS = 1000us
  2552                                  ;       Entry:
  2553                                  ;         None
  2554                                  ;       Exit:
  2555                                  ;	  None
  2556                                  ;
  2557                                  ;       Modified:
  2558                                  ;         None
  2559                                  ;
  2560                                  PORTB		EQU	061h
  2561                                  REFRESH_STATUS	EQU	010h	; Refresh signal status
  2562                                  
  2563                                  	; 05/03/2017 (TRDOS 386)
  2564                                  delay1_4ms:
  2565 00001062 50                              push    eax 
  2566 00001063 51                              push    ecx
  2567                                          ;mov	cl, 16		; close enough.
  2568 00001064 B10C                    	mov	cl, 12 ; + INT 34h delay	
  2569                                  
  2570                                  	;in	al, PORTB
  2571                                  	
  2572 00001066 66BA6100                	mov	dx,  PORTB
  2573 0000106A 28E4                    	sub	ah, ah ; 0 ; inb
  2574 0000106C CD34                    	int	34h
  2575                                  	
  2576 0000106E 2410                    	and	al, REFRESH_STATUS
  2577 00001070 88C5                    	mov	ch, al		; Start toggle state
  2578 00001072 08C9                    	or	cl, cl
  2579 00001074 7402                    	jz	short _d4ms1
  2580 00001076 FEC1                    	inc	cl		; Throwaway first toggle
  2581                                  _d4ms1:	
  2582                                  	;in	al, PORTB	; Read system control port
  2583                                  	
  2584                                  	;mov	ah, 0 ; inb
  2585                                  	;mov	dx, PORTB
  2586 00001078 CD34                    	int	34h
  2587                                  	
  2588 0000107A 2410                    	and	al, REFRESH_STATUS ; Refresh toggles 15.085 microseconds
  2589 0000107C 38C5                    	cmp	ch, al
  2590 0000107E 74F8                    	je	short _d4ms1	; Wait for state change
  2591                                  
  2592 00001080 88C5                    	mov	ch, al		; Update with new state
  2593 00001082 FEC9                    	dec	cl
  2594 00001084 75F2                    	jnz	short _d4ms1
  2595                                  
  2596 00001086 59                              pop     ecx
  2597 00001087 58                              pop     eax
  2598 00001088 C3                              retn
  2599                                  
  2600                                  ;dword2str:
  2601                                  ;	; 13/11/2016 - Erdogan Tan 
  2602                                  ;	; eax = dword value
  2603                                  ;	;
  2604                                  ;	call	dwordtohex
  2605                                  ;	mov	[dword_str], edx
  2606                                  ;	mov	[dword_str+4], eax
  2607                                  ;	mov	si, dword_str
  2608                                  ;	retn
  2609                                  
  2610                                  	; 05/03/2017 (TRDOS 386)
  2611                                  	; trdos386.s (unix386.s) - 10/05/2015
  2612                                  	; Convert binary number to hexadecimal string
  2613                                  
  2614                                  ;bytetohex:
  2615                                  ;	; INPUT ->
  2616                                  ;	; 	AL = byte (binary number)
  2617                                  ;	; OUTPUT ->
  2618                                  ;	;	AX = hexadecimal string
  2619                                  ;	;
  2620                                  ;	push	ebx
  2621                                  ;	movzx	ebx, al
  2622                                  ;	shr	bl, 4
  2623                                  ;	mov	bl, [ebx+hex_chars] 	 	
  2624                                  ;	xchg	bl, al
  2625                                  ;	and	bl, 0Fh
  2626                                  ;	mov	ah, [ebx+hex_chars] 
  2627                                  ;	pop	ebx	
  2628                                  ;	retn
  2629                                  
  2630                                  ;wordtohex:
  2631                                  ;	; INPUT ->
  2632                                  ;	; 	AX = word (binary number)
  2633                                  ;	; OUTPUT ->
  2634                                  ;	;	EAX = hexadecimal string
  2635                                  ;	;
  2636                                  ;	push	ebx
  2637                                  ;	xor	ebx, ebx
  2638                                  ;	xchg	ah, al
  2639                                  ;	push	eax
  2640                                  ;	mov	bl, ah
  2641                                  ;	shr	bl, 4
  2642                                  ;	mov	al, [ebx+hex_chars] 	 	
  2643                                  ;	mov	bl, ah
  2644                                  ;	and	bl, 0Fh
  2645                                  ;	mov	ah, [ebx+hex_chars]
  2646                                  ;	shl	eax, 16
  2647                                  ;	pop	eax
  2648                                  ;	pop	ebx
  2649                                  ;	jmp	short bytetohex
  2650                                  
  2651                                  ;dwordtohex:
  2652                                  ;	; INPUT ->
  2653                                  ;	; 	EAX = dword (binary number)
  2654                                  ;	; OUTPUT ->
  2655                                  ;	;	EDX:EAX = hexadecimal string
  2656                                  ;	;
  2657                                  ;	push	eax
  2658                                  ;	shr	eax, 16
  2659                                  ;	call	wordtohex
  2660                                  ;	mov	edx, eax
  2661                                  ;	pop	eax
  2662                                  ;	call	wordtohex
  2663                                  ;	retn
  2664                                  
  2665                                  	; 05/03/2017 (TRDOS 386)
  2666                                  	; 13/11/2016 - Erdogan Tan
  2667                                  write_ac97_dev_info:
  2668                                  	; BUS/DEV/FN
  2669                                  	;	00000000BBBBBBBBDDDDDFFF00000000
  2670                                  	; DEV/VENDOR
  2671                                  	;	DDDDDDDDDDDDDDDDVVVVVVVVVVVVVVVV
  2672                                  
  2673 00001089 8B35[2B140000]          	mov	esi, [dev_vendor]
  2674 0000108F 6689F0                  	mov	ax, si
  2675 00001092 0FB6D8                  	movzx	ebx, al
  2676 00001095 88DA                    	mov	dl, bl
  2677 00001097 80E30F                  	and	bl, 0Fh
  2678 0000109A 8A83[4A130000]          	mov	al, [ebx+hex_chars]
  2679 000010A0 A2[8D130000]            	mov	[msgVendorId+3], al
  2680 000010A5 88D3                    	mov	bl, dl
  2681 000010A7 C0EB04                  	shr	bl, 4
  2682 000010AA 8A83[4A130000]          	mov	al, [ebx+hex_chars]
  2683 000010B0 A2[8C130000]            	mov	[msgVendorId+2], al
  2684 000010B5 88E3                    	mov	bl, ah
  2685 000010B7 88DA                    	mov	dl, bl
  2686 000010B9 80E30F                  	and	bl, 0Fh
  2687 000010BC 8A83[4A130000]          	mov	al, [ebx+hex_chars]
  2688 000010C2 A2[8B130000]            	mov	[msgVendorId+1], al
  2689 000010C7 88D3                    	mov	bl, dl
  2690 000010C9 C0EB04                  	shr	bl, 4
  2691 000010CC 8A83[4A130000]          	mov	al, [ebx+hex_chars]
  2692 000010D2 A2[8A130000]            	mov	[msgVendorId], al
  2693 000010D7 C1EE10                  	shr	esi, 16
  2694 000010DA 6689F0                  	mov	ax, si
  2695 000010DD 88C3                    	mov	bl, al
  2696 000010DF 88DA                    	mov	dl, bl
  2697 000010E1 80E30F                  	and	bl, 0Fh
  2698 000010E4 8A83[4A130000]          	mov	al, [ebx+hex_chars]
  2699 000010EA A2[9E130000]            	mov	[msgDevId+3], al
  2700 000010EF 88D3                    	mov	bl, dl
  2701 000010F1 C0EB04                  	shr	bl, 4
  2702 000010F4 8A83[4A130000]          	mov	al, [ebx+hex_chars]
  2703 000010FA A2[9D130000]            	mov	[msgDevId+2], al
  2704 000010FF 88E3                    	mov	bl, ah
  2705 00001101 88DA                    	mov	dl, bl
  2706 00001103 80E30F                  	and	bl, 0Fh
  2707 00001106 8A83[4A130000]          	mov	al, [ebx+hex_chars]
  2708 0000110C A2[9C130000]            	mov	[msgDevId+1], al
  2709 00001111 88D3                    	mov	bl, dl
  2710 00001113 C0EB04                  	shr	bl, 4
  2711 00001116 8A83[4A130000]          	mov	al, [ebx+hex_chars]
  2712 0000111C A2[9B130000]            	mov	[msgDevId], al
  2713                                  
  2714 00001121 8B35[27140000]          	mov	esi, [bus_dev_fn]
  2715 00001127 C1EE08                  	shr	esi, 8
  2716 0000112A 6689F0                  	mov	ax, si
  2717 0000112D 88C3                    	mov	bl, al
  2718 0000112F 88DA                    	mov	dl, bl
  2719 00001131 80E307                  	and	bl, 7 ; bit 0,1,2
  2720 00001134 8A83[4A130000]          	mov	al, [ebx+hex_chars]
  2721 0000113A A2[C2130000]            	mov	[msgFncNo+1], al
  2722 0000113F 88D3                    	mov	bl, dl
  2723 00001141 C0EB03                  	shr	bl, 3
  2724 00001144 88DA                    	mov	dl, bl
  2725 00001146 80E30F                  	and	bl, 0Fh
  2726 00001149 8A83[4A130000]          	mov	al, [ebx+hex_chars]
  2727 0000114F A2[B4130000]            	mov	[msgDevNo+1], al
  2728 00001154 88D3                    	mov	bl, dl
  2729 00001156 C0EB04                  	shr	bl, 4
  2730 00001159 8A83[4A130000]          	mov	al, [ebx+hex_chars]
  2731 0000115F A2[B3130000]            	mov	[msgDevNo], al
  2732 00001164 88E3                    	mov	bl, ah
  2733 00001166 88DA                    	mov	dl, bl
  2734 00001168 80E30F                  	and	bl, 0Fh
  2735 0000116B 8A83[4A130000]          	mov	al, [ebx+hex_chars]
  2736 00001171 A2[A8130000]            	mov	[msgBusNo+1], al
  2737 00001176 88D3                    	mov	bl, dl
  2738 00001178 C0EB04                  	shr	bl, 4
  2739 0000117B 8A83[4A130000]          	mov	al, [ebx+hex_chars]
  2740 00001181 A2[A7130000]            	mov	[msgBusNo], al
  2741                                  
  2742 00001186 66A1[33140000]          	mov	ax, [ac97_io_base]
  2743 0000118C 88C3                    	mov	bl, al
  2744 0000118E 88DA                    	mov	dl, bl
  2745 00001190 80E30F                  	and	bl, 0Fh
  2746 00001193 8A83[4A130000]          	mov	al, [ebx+hex_chars]
  2747 00001199 A2[DB130000]            	mov	[msgIOBaseAddr+3], al
  2748 0000119E 88D3                    	mov	bl, dl
  2749 000011A0 C0EB04                  	shr	bl, 4
  2750 000011A3 8A83[4A130000]          	mov	al, [ebx+hex_chars]
  2751 000011A9 A2[DA130000]            	mov	[msgIOBaseAddr+2], al
  2752 000011AE 88E3                    	mov	bl, ah
  2753 000011B0 88DA                    	mov	dl, bl
  2754 000011B2 80E30F                  	and	bl, 0Fh
  2755 000011B5 8A83[4A130000]          	mov	al, [ebx+hex_chars]
  2756 000011BB A2[D9130000]            	mov	[msgIOBaseAddr+1], al
  2757 000011C0 88D3                    	mov	bl, dl
  2758 000011C2 C0EB04                  	shr	bl, 4
  2759 000011C5 8A83[4A130000]          	mov	al, [ebx+hex_chars]
  2760 000011CB A2[D8130000]            	mov	[msgIOBaseAddr], al
  2761                                  
  2762                                  	; 24/11/2016
  2763 000011D0 30E4                    	xor	ah, ah
  2764 000011D2 A0[25140000]            	mov	al, [ac97_int_ln_reg]
  2765 000011D7 B10A                    	mov	cl, 10
  2766 000011D9 F6F1                    	div	cl
  2767 000011DB 660105[E3130000]        	add	[msgIRQ], ax
  2768 000011E2 20C0                    	and	al, al
  2769 000011E4 750D                    	jnz	short _pmi
  2770 000011E6 A0[E4130000]            	mov	al, [msgIRQ+1]
  2771 000011EB B420                    	mov	ah, ' '
  2772 000011ED 66A3[E3130000]          	mov	[msgIRQ], ax
  2773                                  _pmi:
  2774                                  	; EBX = Message address
  2775                                  	; ECX = Max. message length (or stop on ZERO character)
  2776                                  	;	(1 to 255)
  2777                                  	; DL  = Message color (07h = light gray, 0Fh = white) 
  2778                                       	sys 	_msg, msgAC97Info, 255, 07h
  2778                              <1> 
  2778                              <1> 
  2778                              <1> 
  2778                              <1> 
  2778                              <1>  %if %0 >= 2
  2778 000011F3 BB[5B130000]        <1>  mov ebx, %2
  2778                              <1>  %if %0 >= 3
  2778 000011F8 B9FF000000          <1>  mov ecx, %3
  2778                              <1>  %if %0 = 4
  2778 000011FD BA07000000          <1>  mov edx, %4
  2778                              <1>  %endif
  2778                              <1>  %endif
  2778                              <1>  %endif
  2778 00001202 B823000000          <1>  mov eax, %1
  2778                              <1> 
  2778 00001207 CD40                <1>  int 40h
  2779 00001209 C3                              retn
  2780                                  
  2781                                  ;=============================================================================
  2782                                  ;               preinitialized data
  2783                                  ;=============================================================================
  2784                                  
  2785                                  ;=============================================================================
  2786                                  ;               PLAY.ASM - DATA
  2787                                  ;=============================================================================
  2788                                  
  2789                                  msg_2017:
  2790 0000120A 54696E79204D4F4420-     	db	'Tiny MOD Player for TRDOS 386 by Erdogan Tan. '
  2790 00001213 506C6179657220666F-
  2790 0000121C 72205452444F532033-
  2790 00001225 383620627920457264-
  2790 0000122E 6F67616E2054616E2E-
  2790 00001237 20                 
  2791 00001238 4D6172636820323031-     	db	'March 2017.',10,13
  2791 00001241 372E0A0D           
  2792 00001245 75736167653A20706C-     	db	'usage: playmod filename.mod', 10,13,0
  2792 0000124E 61796D6F642066696C-
  2792 00001257 656E616D652E6D6F64-
  2792 00001260 0A0D00             
  2793 00001263 31372F30332F323031-     	db	'17/03/2017',10,13,0
  2793 0000126C 370A0D00           
  2794                                  
  2795 00001270 54696E79204D4F4420-     Credits:	db	'Tiny MOD Player v0.1b by Carlos Hasan. July 1993.'
  2795 00001279 506C61796572207630-
  2795 00001282 2E3162206279204361-
  2795 0000128B 726C6F732048617361-
  2795 00001294 6E2E204A756C792031-
  2795 0000129D 3939332E           
  2796 000012A1 0A0D00                  		db	10,13,0
  2797 000012A4 4572726F72206C6F61-     ErrorMesg:	db	'Error loading Module file.',10,13,0
  2797 000012AD 64696E67204D6F6475-
  2797 000012B6 6C652066696C652E0A-
  2797 000012BF 0D00               
  2798                                  ;MsgNotFound:	db	'Sound Blaster not found or IRQ error.',10,13,0
  2799                                  ;MsgFound:	db	'Sound Blaster found at Address 2'
  2800                                  ;PortText:	db	'x0h, IRQ '
  2801                                  ;IrqText:	db	'x.',10,13,0
  2802                                  
  2803                                  trdos386_err_msg:
  2804 000012C1 5452444F5320333836-     		db	'TRDOS 386 System call error !', 10, 13,0
  2804 000012CA 2053797374656D2063-
  2804 000012D3 616C6C206572726F72-
  2804 000012DC 20210A0D00         
  2805                                  
  2806                                  ;=============================================================================
  2807                                  ;               MODPLAY.ASM - DATA
  2808                                  ;=============================================================================
  2809                                  
  2810                                  ;Credits:	db	'Amiga Module Player v0.3b by Carlos Hasan.'
  2811                                  
  2812 000012E1 0019324A62788EA2B4-     SinTable:	db	0,25,50,74,98,120,142,162,180,197,212,225
  2812 000012EA C5D4E1             
  2813 000012ED ECF4FAFEFFFEFAF4EC-     		db	236,244,250,254,255,254,250,244,236,225
  2813 000012F6 E1                 
  2814 000012F7 D4C5B4A28E78624A32-     		db	212,197,180,162,142,120,98,74,50,25
  2814 00001300 19                 
  2815                                  
  2816 00001301 58032803FA02D002A6-     PeriodTable:	dw	856,808,762,720,678,640,604,570,538,508,480,453
  2816 0000130A 0280025C023A021A02-
  2816 00001313 FC01E001C501       
  2817 00001319 AC0194017D01680153-     		dw	428,404,381,360,339,320,302,285,269,254,240,226
  2817 00001322 0140012E011D010D01-
  2817 0000132B FE00F000E200       
  2818 00001331 D600CA00BE00B400AA-     		dw	214,202,190,180,170,160,151,143,135,127,120,113
  2818 0000133A 00A00097008F008700-
  2818 00001343 7F0078007100       
  2819                                  
  2820                                  ;=============================================================================
  2821                                  ;               PLAYER.ASM - DATA
  2822                                  ;=============================================================================
  2823                                  
  2824 00001349 02                      tBuff:		db 2 ; 08/12/2016
  2825                                  
  2826                                  ; 13/11/2016
  2827 0000134A 303132333435363738-     hex_chars:	db "0123456789ABCDEF", 0
  2827 00001353 3941424344454600   
  2828 0000135B 414339372041756469-     msgAC97Info:	db "AC97 Audio Controller & Codec Info", 0Dh, 0Ah 
  2828 00001364 6F20436F6E74726F6C-
  2828 0000136D 6C6572202620436F64-
  2828 00001376 656320496E666F0D0A 
  2829 0000137F 56656E646F72204944-     		db "Vendor ID: "
  2829 00001388 3A20               
  2830 0000138A 303030306820446576-     msgVendorId:	db "0000h Device ID: "
  2830 00001393 6963652049443A20   
  2831 0000139B 30303030680D0A          msgDevId:	db "0000h", 0Dh, 0Ah
  2832 000013A2 4275733A20              		db "Bus: "
  2833 000013A7 303068204465766963-     msgBusNo:	db "00h Device: "
  2833 000013B0 653A20             
  2834 000013B3 3030682046756E6374-     msgDevNo:	db "00h Function: "
  2834 000013BC 696F6E3A20         
  2835 000013C1 303068                  msgFncNo:	db "00h"
  2836 000013C4 0D0A                    		db 0Dh, 0Ah
  2837 000013C6 492F4F204261736520-     		db "I/O Base Address: "
  2837 000013CF 416464726573733A20 
  2838 000013D8 303030306820495251-     msgIOBaseAddr:	db "0000h IRQ: "
  2838 000013E1 3A20               
  2839 000013E3 3030                    msgIRQ:		dw 3030h
  2840 000013E5 0D0A00                  		db 0Dh, 0Ah, 0
  2841 000013E8 53616D706C65205261-     msgSampleRate:	db "Sample Rate: "
  2841 000013F1 74653A20           
  2842 000013F5 303030303020487A20-     msgHertz:	db "00000 Hz ", 0
  2842 000013FE 00                 
  2843 000013FF 3820626974732000        msg8Bits:	db "8 bits ", 0
  2844 00001407 4D6F6E6F0D0A00          msgMono:	db "Mono", 0Dh, 0Ah, 0
  2845 0000140E 313620626974732024      msg16Bits:	db "16 bits ", "$" 
  2846 00001417 53746572656F0D0A00      msgStereo:	db "Stereo", 0Dh, 0Ah, 0
  2847                                  
  2848                                  ;; 13/11/2016 - Erdogan Tan (Ref: KolibriOS, codec.inc)
  2849                                  ;codec_id:	   dd 0
  2850                                  ;codec_chip_id:	   dd 0
  2851                                  ;codec_vendor_ids: dw 0
  2852                                  ;codec_chip_ids:   dw 0
  2853                                  
  2854                                  ;dword_str:	dd 30303030h, 30303030h
  2855                                  ;	 	db 'h', 0Dh, 0Ah, 0
  2856                                  
  2857                                  ;=============================================================================
  2858                                  ;        	uninitialized data
  2859                                  ;=============================================================================
  2860                                  
  2861                                  bss_start:
  2862                                  
  2863                                  ABSOLUTE bss_start
  2864                                  
  2865                                  alignb 4
  2866                                  
  2867 00001420 <res 00000001>          stmo	resb	1 ; stereo or mono  
  2868 00001421 <res 00000001>          bps	resb	1 ; bits per sample (16)
  2869                                  
  2870 00001422 <res 00000001>          irq_status:	resb 	1
  2871                                  
  2872 00001423 <res 00000001>          uLVI:	resb	1 
  2873 00001424 <res 00000001>          tLoop:	resb 	1
  2874                                  
  2875                                  ; 12/11/2016 - Erdogan Tan
  2876                                  
  2877 00001425 <res 00000001>          ac97_int_ln_reg: resb 1 
  2878 00001426 <res 00000001>          err_num:	resb 1
  2879                                  ;s_r_b:		resb 1 ; 06/03/2017		
  2880                                  
  2881 00001427 <res 00000004>          bus_dev_fn:	resd 1
  2882 0000142B <res 00000004>          dev_vendor:	resd 1
  2883 0000142F <res 00000004>          stats_cmd:	resd 1
  2884 00001433 <res 00000002>          ac97_io_base:	resw 1
  2885                                  
  2886                                  ; MODLOAD.ASM
  2887 00001435 <res 00000002>          FileHandle:	resw	1
  2888 00001437 <res 00000002>          ErrorInfo:	resw	1
  2889 00001439 <res 0000043C>          Header:	resb	ModHeader.size
  2890                                  
  2891                                  sample_rate: ; PLAYER.ASM (22050Hz)
  2892                                  ; MODPLAY.ASM
  2893 00001875 <res 00000002>          MixSpeed:	    resw 1
  2894                                  
  2895                                  ModInfo:
  2896 00001877 <res 00000001>          ModInfo.OrderLen:   resb 1
  2897 00001878 <res 00000001>          ModInfo.ReStart:    resb 1
  2898 00001879 <res 00000080>          ModInfo.Order:	    resb 128
  2899 000018F9 <res 00000004>          ModInfo.Patterns:   resd 1
  2900                                  
  2901 000018FD <res 0000003E>          ModInfo.SampOfs:    resw 31
  2902 0000193B <res 0000003E>          ModInfo.SampSeg:    resw 31
  2903 00001979 <res 0000003E>          ModInfo.SampLen:    resw 31
  2904 000019B7 <res 0000003E>          ModInfo.SampRep:    resw 31
  2905 000019F5 <res 0000003E>          ModInfo.SampRepLen: resw 31
  2906 00001A33 <res 0000003E>          ModInfo.SampVol:    resw 31
  2907                                  
  2908                                  ; MODPLAY.ASM
  2909 00001A71 <res 000006B2>          PitchTable:	resw	857
  2910 00002123 <res 00004100>          VolTable:	resb	16640
  2911 00006223 <res 00001000>          MixBuffer       resb	MixBufSize
  2912                                  
  2913                                  ; MODPLAY.ASM
  2914 00007223 <res 00000001>          OrderPos:	resb 1
  2915 00007224 <res 00000001>          Tempo:		resb 1
  2916 00007225 <res 00000001>          TempoWait:	resb 1
  2917 00007226 <res 00000001>          Bpm:		resb 1
  2918 00007227 <res 00000001>          Row:		resb 1
  2919 00007228 <res 00000001>          BreakRow:	resb 1
  2920 00007229 <res 00000002>          BpmSamples:	resw 1
  2921 0000722B <res 00000004>          BufPtr:		resd 1
  2922 0000722F <res 00000002>          BufLen:		resw 1
  2923 00007231 <res 00000004>          BufRep:		resd 1
  2924 00007235 <res 00000004>          Note:		resd 1
  2925 00007239 <res 00000090>          Tracks:		resb TrackInfo.size*NumTracks
  2926                                  
  2927 000072C9 <res 00000007>          alignb 16
  2928                                  
  2929                                  ; PLAY.ASM
  2930 000072D0 <res 00000280>          Scope:		resw	320
  2931 00007550 <res 00000200>          RowOfs:		resw	256
  2932                                  
  2933                                  ; 05/03/2017
  2934 00007750 <res 000008B0>          alignb 4096
  2935                                  
  2936 00008000 <res 00001000>          BdlBuffer:	resb	4096 ; BDL_SIZE (round up to 1 page)
  2937                                  
  2938                                  ; 14/03/2017
  2939 00009000 <res 00000004>          BDL_phy_buff:	resd 1
  2940 00009004 <res 00000004>          DMA_phy_buff:	resd 1
  2941                                  mod_file_name:
  2942 00009008 <res 00000010>          		resb 16
  2943                                  
  2944 00009018 <res 00006FE8>          alignb 65536
  2945                                  
  2946                                  DmaBuffer:
  2947 00010000 <res 00010000>          DoubleBuffer:	resb 65536 ; DmaBufSize
  2948                                  file_buffer:
  2949 00020000 <res 00060000>          		resb 65536*6
  2950                                  EOF:
